Utils

Utils

Methods

(static) buildChallengeTx(serverKeypair, clientAccountID, anchorName, timeoutopt, networkPassphraseopt) → {string}

Returns a valid SEP0010 challenge transaction which you can use for Stellar Web Authentication.

Source:
See:
Parameters:
Name Type Attributes Default Description
serverKeypair Keypair

Keypair for server's signing account.

clientAccountID string

The stellar account that the wallet wishes to authenticate with the server.

anchorName string

Anchor's name to be used in the manage_data key.

timeout number <optional>
300

Challenge duration (default to 5 minutes).

networkPassphrase string <optional>

The network passphrase. If you pass this argument then timeout is required.

Returns:
Type:
string

A base64 encoded string of the raw TransactionEnvelope xdr struct for the transaction.

Example
import { Utils, Keypair, Networks }  from 'stellar-sdk'

let serverKeyPair = Keypair.fromSecret("server-secret")
let challenge = Utils.buildChallengeTx(serverKeyPair, "client-stellar-account-id", "SDF", 300, Networks.TESTNET)

(static) verifyChallengeTx(challengeTx, serverAccountID, networkPassphraseopt) → {boolean}

Verifies if a transaction is a valid SEP0010 challenge transaction.

This function performs the following checks:

  1. Verifies that the transaction's source is the same as the server account id.
  2. Verifies that the number of operations in the transaction is equal to one and of type manageData.
  3. Verifies if timeBounds are still valid.
  4. Verifies if the transaction has been signed by the server and the client.
  5. Verifies that the sequenceNumber is equal to zero.
Source:
See:
Parameters:
Name Type Attributes Description
challengeTx string

SEP0010 transaction challenge transaction in base64.

serverAccountID string

The server's stellar account.

networkPassphrase string <optional>

The network passphrase.

Returns:
Type:
boolean
Example
import { Utils, Networks }  from 'stellar-sdk'

let challenge = Utils.verifyChallengeTx("base64tx", "server-account-id", Networks.TESTNET)

(static) verifyTxSignedBy(transaction, accountID) → {boolean}

Verifies if a transaction was signed by the given account id.

Source:
Parameters:
Name Type Description
transaction Transaction
accountID string
Returns:
Type:
boolean

.

Example
let keypair = Keypair.random();
const account = new StellarSdk.Account(keypair.publicKey(), "-1");

const transaction = new TransactionBuilder(account, { fee: 100 })
   .setTimeout(30)
   .build();

transaction.sign(keypair)
Utils.verifyTxSignedBy(transaction, keypair.publicKey())