Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Wallet

A utility for deriving a wallet composed of a keypair (publicKey/privateKey). A wallet can be derived from either a seed, Mnemonic, or entropy (array of random numbers). It provides functionality to sign/verify transactions offline.

// Derive a wallet from a bip38 Mnemonic
const wallet = Wallet.fromMnemonic(
  'jewel insect retreat jump claim horse second chef west gossip bone frown exotic embark laundry'
)
console.log(wallet)
// Wallet {
// publicKey: '02348F89E9A6A3615BA317F8474A3F51D66221562D3CA32BFA8D21348FF67012B2',
// privateKey: '00A8F2E77FC0E05890C1B5088AFE0ECF9D96466A4419B897B1AB383E336E1735A2',
// classicAddress: 'rwZiksrExmVkR64pf87Jor4cYbmff47SUm',
// seed: undefined
// }.

// Derive a wallet from a base58 encoded seed.
const seedWallet = Wallet.fromSeed('ssZkdwURFMBXenJPbrpE14b6noJSu')
console.log(seedWallet)
// Wallet {
// publicKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
// privateKey: '00445D0A16DD05EFAF6D5AF45E6B8A6DE4170D93C0627021A0B8E705786CBCCFF7',
// classicAddress: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo',
// seed: 'ssZkdwURFMBXenJPbrpE14b6noJSu'
// }.

// Sign a JSON Transaction
 const signed = seedWallet.signTransaction({
     TransactionType: 'Payment',
     Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
     ...........
}).

Console.log(signed)
// '1200007321......B01BE1DFF3'.

Console.log(decode(signed))
// {
//   TransactionType: 'Payment',
//   SigningPubKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
//   TxnSignature: '3045022100AAD2B97D9FA2EDCA354AB6E629612F34C33086BE7EC3B1F8B99B909BAC989AB9022072F0C8DDB9400A0F721ADE3C6AEAE026D8E3D641D5B631ABD21171B61B07D304',
//   Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
//   ...........
// }

Hierarchy

  • Wallet

Index

Constructors

constructor

  • new Wallet(publicKey: string, privateKey: string, seed?: string): Wallet
  • Creates a new Wallet.

    Parameters

    • publicKey: string

      The public key for the account.

    • privateKey: string

      The private key used for signing transactions for the account.

    • Optional seed: string

      (Optional) The seed used to derive the account keys.

    Returns Wallet

Properties

Readonly classicAddress

classicAddress: string

This only is correct if this wallet corresponds to your master keypair. If this wallet represents a regular keypair this will provide an incorrect address. TODO: Add support for Regular Keys to Wallet (And their corresponding impact on figuring out classicAddress).

Readonly privateKey

privateKey: string

Readonly publicKey

publicKey: string

Optional Readonly seed

seed: string

Static fromSecret

fromSecret: (seed: string, algorithm?: ECDSA) => Wallet = ...

Derives a wallet from a secret (AKA a seed).

Type declaration

    • (seed: string, algorithm?: ECDSA): Wallet
    • Derives a wallet from a seed.

      Parameters

      • seed: string

        A string used to generate a keypair (publicKey/privateKey) to derive a wallet.

      • algorithm: ECDSA = ...

        The digital signature algorithm to generate an address fro.

      Returns Wallet

      A Wallet derived from a seed.

Methods

Private checkTxSerialization

  • checkTxSerialization(serialized: string, tx: Transaction): void
  • Decode a serialized transaction, remove the fields that are added during the signing process, and verify that it matches the transaction prior to signing. This gives the user a sanity check to ensure that what they try to encode matches the message that will be recieved by rippled.

    throws

    A ValidationError if the transaction does not have a TxnSignature/Signers property, or if the serialized Transaction desn't match the original transaction.

    Parameters

    • serialized: string

      A signed and serialized transaction.

    • tx: Transaction

      The transaction prior to signing.

    Returns void

getClassicAddress

  • getClassicAddress(): string
  • Gets the classic address of the account this wallet represents. This only is correct if this wallet corresponds to your master keypair. If this wallet represents a regular keypair this will provide an incorrect address.

    Returns string

    A classic address.

getXAddress

  • getXAddress(tag?: number | false, isTestnet?: boolean): string
  • Gets an X-address in Testnet/Mainnet format.

    Parameters

    • tag: number | false = false

      A tag to be included within the X-address.

    • isTestnet: boolean = false

      A boolean to indicate if X-address should be in Testnet (true) or Mainnet (false) format.

    Returns string

    An X-address.

signTransaction

  • signTransaction(transaction: Transaction, multisignAddress?: string): string
  • Signs a transaction offline.

    throws

    ValidationError if the transaction is already signed or does not encode/decode to same result.

    Parameters

    • transaction: Transaction

      A transaction to be signed offline.

    • Optional multisignAddress: string

      Multisign only. An account address corresponding to the multi-signature being added. If this wallet represents your master keypair you can get your account address with the Wallet.getClassicAddress() function.

    Returns string

    A signed transaction.

verifyTransaction

  • verifyTransaction(signedTransaction: string): boolean
  • Verifies a signed transaction offline.

    Parameters

    • signedTransaction: string

      A signed transaction (hex string of signTransaction result) to be verified offline.

    Returns boolean

    Returns true if a signedTransaction is valid.

Static Private deriveWallet

  • deriveWallet(seed: string, algorithm?: ECDSA): Wallet
  • Derive a Wallet from a seed.

    Parameters

    • seed: string

      The seed used to derive the wallet.

    • algorithm: ECDSA = ...

      The algorithm used to do the derivation.

    Returns Wallet

    A Wallet derived from the seed.

Static fromEntropy

  • fromEntropy(entropy: Uint8Array | number[], algorithm?: ECDSA): Wallet
  • Derives a wallet from an entropy (array of random numbers).

    Parameters

    • entropy: Uint8Array | number[]

      An array of random numbers to generate a seed used to derive a wallet.

    • algorithm: ECDSA = ...

      The digital signature algorithm to generate an address for.

    Returns Wallet

    A Wallet derived from an entropy.

Static fromMnemonic

  • fromMnemonic(mnemonic: string, derivationPath?: string): Wallet
  • Derives a wallet from a mnemonic.

    throws

    ValidationError if unable to derive private key from mnemonic input.

    Parameters

    • mnemonic: string

      A string consisting of words (whitespace delimited) used to derive a wallet.

    • derivationPath: string = ...

      The path to derive a keypair (publicKey/privateKey) from a seed (that was converted from a mnemonic).

    Returns Wallet

    A Wallet derived from a mnemonic.

Static fromSeed

  • fromSeed(seed: string, algorithm?: ECDSA): Wallet
  • Derives a wallet from a seed.

    Parameters

    • seed: string

      A string used to generate a keypair (publicKey/privateKey) to derive a wallet.

    • algorithm: ECDSA = ...

      The digital signature algorithm to generate an address for.

    Returns Wallet

    A Wallet derived from a seed.

Static generate

  • generate(algorithm?: ECDSA): Wallet
  • Generates a new Wallet using a generated seed.

    Parameters

    • algorithm: ECDSA = ...

      The digital signature algorithm to generate an address for.

    Returns Wallet

    A new Wallet derived from a generated seed.

Generated using TypeDoc