How to use the stellar-sdk.Keypair.fromSecret function in stellar-sdk

To help you get started, we’ve selected a few stellar-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github satoshipay / solar / src / pages / create-account.tsx View on Github external
const onCreateAccount = async (formValues: AccountCreationValues) => {
    try {
      const account = await createAccount({
        name: formValues.name,
        keypair: Keypair.fromSecret(formValues.privateKey),
        password: formValues.setPassword ? formValues.password : null,
        testnet: props.testnet
      })

      if (formValues.createNewKey && !props.testnet) {
        setCreatedAccount(account)
      } else {
        router.history.push(routes.account(account.id))
      }
    } catch (error) {
      trackError(error)
    }
  }
github satoshipay / solar / src / components / Dialog / CreateAccount.tsx View on Github external
const createAccount = async (formValues: AccountCreationValues) => {
    try {
      const account = await createAccountInStore({
        name: formValues.name,
        keypair: Keypair.fromSecret(formValues.privateKey),
        password: formValues.setPassword ? formValues.password : null,
        testnet: props.testnet
      })
      props.onClose()
      props.history.push(routes.account(account.id))
    } catch (error) {
      addError(error)
    }
  }
  return (
github satoshipay / solar / src / platform / web / key-store.ts View on Github external
async signTransaction(tx: Transaction, account: Account, password: string): Promise {
      let privateKey: string
      try {
        privateKey = keyStore.getPrivateKeyData(account.id, password).privateKey
      } catch (error) {
        throw WrongPasswordError()
      }

      const keypair = Keypair.fromSecret(privateKey)

      const networkPassphrase = account.testnet ? Networks.TESTNET : Networks.PUBLIC

      const signedTx = new Transaction((tx.toEnvelope().toXDR("base64") as unknown) as string, networkPassphrase)
      signedTx.sign(keypair)

      return signedTx
    }
  }
github satoshipay / solar / electron / src / storage.ts View on Github external
expose(ipcMain, commands.signTransactionCommand, events.signTransactionEvent, function signTransaction(
  txEnvelopeXdr,
  keyID,
  networkPassphrase,
  password
) {
  const transaction = new Transaction(txEnvelopeXdr, networkPassphrase)
  let privateKey
  try {
    privateKey = keystore.getPrivateKeyData(keyID, password).privateKey
  } catch (error) {
    throw Object.assign(new Error("Wrong password."), { name: "WrongPasswordError" })
  }

  transaction.sign(Keypair.fromSecret(privateKey))

  return transaction.toEnvelope().toXDR("base64")
})
github satoshipay / solar / src / platform / ipc.web.ts View on Github external
function signTransaction(internalAccountID: string, transactionXDR: string, password: string) {
    try {
      const account = keyStore.getPublicKeyData(internalAccountID)
      const networkPassphrase = account.testnet ? Networks.TESTNET : Networks.PUBLIC
      const transaction = new Transaction(transactionXDR, networkPassphrase)

      const privateKey = keyStore.getPrivateKeyData(internalAccountID, password).privateKey

      transaction.sign(Keypair.fromSecret(privateKey))

      return transaction
        .toEnvelope()
        .toXDR()
        .toString("base64")
    } catch (error) {
      throw Object.assign(new Error("Wrong password."), { name: "WrongPasswordError" })
    }
  }
github satoshipay / solar / src / components / Form / CreateAccount.tsx View on Github external
function isAccountAlreadyImported(privateKey: string, accounts: Account[]) {
  const publicKey = Keypair.fromSecret(privateKey).publicKey()
  return accounts.some(account => account.publicKey === publicKey)
}