Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Keypair

Keypair represents public (and secret) keys of the account.

Currently Keypair only supports ed25519 but in a future this class can be an abstraction layer for other public-key signature systems.

Copyright (c) 2015-2018 Stellar Development Foundation

Hierarchy

  • Keypair

Index

Constructors

constructor

  • new Keypair(secretKey: Buffer, type?: undefined | "ed25519"): Keypair
  • Constructor

    Parameters

    • secretKey: Buffer

      Raw secret key (32-byte secret seed in ed25519`)

    • Optional type: undefined | "ed25519"

      Public-key signature system name. (currently only ed25519 keys are supported)

    Returns Keypair

Properties

privKey

privKey: Buffer

pubKey

pubKey: Buffer

seed

seed: Buffer

type

type: "ed25519"

Methods

canSign

  • canSign(): boolean
  • Returns true if this Keypair object contains secret key and can sign.

    Returns boolean

decrypt

  • decrypt(ciphertext: Buffer): Buffer
  • Decrypts the given data using a Curve25519 'variant' of the private key.

    Assumes ciphertext includes ephemeral public key and nonce used in original encryption (e.g., via encrypt).

    note

    See https://github.com/dchest/ed2curve-js for conversion details.

    Parameters

    • ciphertext: Buffer

      Data to decrypt

    Returns Buffer

encrypt

  • encrypt(data: Buffer): Buffer
  • Encrypts the given data using a Curve25519 'variant' of the public key.

    The encryption uses an ephemeral private key, which is prepended to the ciphertext, along with a nonce of random bytes.

    note

    See https://github.com/dchest/ed2curve-js for conversion details.

    Parameters

    • data: Buffer

      Data to encrypt

    Returns Buffer

publicKey

  • publicKey(): string
  • Returns base58-encoded public key associated with this Keypair object.

    Returns string

rawPublicKey

  • rawPublicKey(): Buffer

rawSecretKey

  • rawSecretKey(): Buffer

secret

  • secret(): string
  • Returns base58-encoded secret key associated with this Keypair object

    Returns string

sign

  • sign(data: Buffer): Buffer
  • Signs data.

    Parameters

    • data: Buffer

      Data to sign

    Returns Buffer

verify

  • verify(data: Buffer, signature: Buffer): boolean
  • Verifies if signature for data is valid.

    Parameters

    • data: Buffer

      Signed data

    • signature: Buffer

      Signature

    Returns boolean

Static fromRawEd25519Seed

  • fromRawEd25519Seed(rawSeed: Buffer): Keypair
  • Creates a new Keypair object from ed25519 secret key seed raw bytes.

    Parameters

    • rawSeed: Buffer

      Raw 32-byte ed25519 secret key seed

    Returns Keypair

Static fromSecret

  • fromSecret(secret: string): Keypair
  • Creates a new Keypair instance from secret. This can either be secret key or secret seed depending on underlying public-key signature system. Currently Keypair only supports ed25519.

    Parameters

    • secret: string

      secret key (ex. SDAKFNYEIAORZKKCYRILFQKLLOCNPL5SWJ3YY5NM3ZH6GJSZGXHZEPQS)

    Returns Keypair

Static random