How to use the stellar-sdk.Networks.PUBLIC 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 / 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 / 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 / src / lib / transaction.ts View on Github external
export async function createTransaction(operations: Array>, options: TxBlueprint) {
  const { horizon, walletAccount } = options
  const timeout = selectTransactionTimeout(options.accountData)

  const [account, smartTxFee, timebounds] = await Promise.all([
    horizon.loadAccount(walletAccount.publicKey),
    selectTransactionFeeWithFallback(horizon, 1500),
    horizon.fetchTimebounds(timeout)
  ])

  const networkPassphrase = walletAccount.testnet ? Networks.TESTNET : Networks.PUBLIC
  const txFee = Math.max(smartTxFee, options.minTransactionFee || 0)

  const builder = new TransactionBuilder(account, {
    fee: txFee,
    memo: options.memo || undefined,
    timebounds,
    networkPassphrase
  })

  for (const operation of operations) {
    builder.addOperation(operation)
  }

  const tx = builder.build()
  return tx
}
github satoshipay / solar / src / hooks / _horizon.ts View on Github external
export function deserializeTx(txResponse: Horizon.TransactionResponse, testnet: boolean) {
  const networkPassphrase = testnet ? Networks.TESTNET : Networks.PUBLIC
  return Object.assign(new Transaction(txResponse.envelope_xdr, networkPassphrase), {
    created_at: txResponse.created_at
  })
}
github satoshipay / solar / src / subscriptions / recent-txs.ts View on Github external
function deserializeTx(txResponse: ServerApi.TransactionRecord, testnet: boolean) {
  const networkPassphrase = testnet ? Networks.TESTNET : Networks.PUBLIC
  return Object.assign(new Transaction(txResponse.envelope_xdr, networkPassphrase), {
    created_at: txResponse.created_at
  })
}
github satoshipay / solar / src / platform / cordova / key-store.ts View on Github external
async signTransaction(transaction: Transaction, account: Account, password: string) {
      const transactionEnvelope = transaction.toEnvelope().toXDR("base64")
      const event = await sendCommand(commands.keyStore.signTransactionCommand, {
        keyID: account.id,
        networkPassphrase: account.testnet ? networkPassphrases.testnet : networkPassphrases.mainnet,
        password,
        transactionEnvelope
      })
      if (event.data.error === "Wrong password") {
        throw WrongPasswordError()
      } else {
        const signedTransactionEnvelope = event.data.result
        const networkPassphrase = account.testnet ? Networks.TESTNET : Networks.PUBLIC
        return new Transaction(signedTransactionEnvelope, networkPassphrase)
      }
    },
    async removeKey(keyID: string) {
github satoshipay / solar / src / lib / multisig-service.ts View on Github external
export function deserializeSignatureRequest(rawSignatureRequest: Omit): SignatureRequest {
  const { operation, parameters } = parseRequestURI(rawSignatureRequest.request_uri)
  const networkPassphrase = parameters.network_passphrase ? parameters.network_passphrase : Networks.PUBLIC

  return {
    ...rawSignatureRequest,
    meta: {
      operation,
      callbackURL: parameters.callback ? parameters.callback.replace(/^url:/, "") : undefined,
      transaction: new Transaction(parameters.xdr, networkPassphrase)
    }
  }
}