Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LedgerDevice

An easy to use interface that uses a Ledger HW transport to communicate with the TurtleCoin application running on a ledger device. Please see. See https://github.com/LedgerHQ/ledgerjs for available transport providers

Hierarchy

  • EventEmitter
    • LedgerDevice

Index

Constructors

constructor

  • new LedgerDevice(transport: Transport<string>, config?: ICoinConfig): LedgerDevice
  • Creates a new instance of the Ledger interface The transport MUST be connected already before passing to this constructor

    Parameters

    Returns LedgerDevice

Properties

Private Readonly m_config

m_config: ICoinRunningConfig = ...

Private Readonly m_transport

m_transport: Transport<string>

Accessors

transport

  • get transport(): Transport<string>
  • Returns the underlying transport

    Returns Transport<string>

Methods

checkIdent

  • checkIdent(): Promise<boolean>
  • Checks to make sure that the application running on the ledger at least claims to be the TurtleCoin ledger application

    Returns Promise<boolean>

checkKey

  • checkKey(key: string): Promise<boolean>
  • Checks to confirm that the key is a valid public key

    Parameters

    • key: string

      the key to check

    Returns Promise<boolean>

checkRingSignatures

  • checkRingSignatures(tx_prefix_hash: string, key_image: string, public_keys: string[], signatures: string[]): Promise<boolean>
  • Checks the ring signatures given for their validity to verify that the proper private key was used for signing purposes

    Parameters

    • tx_prefix_hash: string

      the transaction prefix hash

    • key_image: string

      the key image spent in the input

    • public_keys: string[]

      the ring participant keys

    • signatures: string[]

      the signatures to verify

    Returns Promise<boolean>

checkScalar

  • checkScalar(scalar: string): Promise<boolean>
  • Checks to confirm that the scalar is indeed a scalar value

    Parameters

    • scalar: string

      the scalar to check

    Returns Promise<boolean>

checkSignature

  • checkSignature(message_digest: string, public_key: string, signature: string): Promise<boolean>
  • Checks a given signature using the supplied public key for validity

    Parameters

    • message_digest: string

      the message digest (hash)

    • public_key: string

      the public key of the private key used to sign the transaction

    • signature: string

      the signature to validate

    Returns Promise<boolean>

checkVersion

  • checkVersion(requiredVersion: string): Promise<boolean>
  • Checks to

    Parameters

    • requiredVersion: string

    Returns Promise<boolean>

completeRingSignature

  • completeRingSignature(tx_public_key: string, output_index: number, output_key: string, k: string, signature: string, confirm?: boolean): Promise<string>
  • Completes the given ring signature for using the supplied parameters

    Parameters

    • tx_public_key: string

      the transaction public key of the input used

    • output_index: number

      the index of the given output in the transaction of the input used

    • output_key: string

      the key of the given output in the transaction of the input used

    • k: string

      the random scalar returned by preparing the signatures before completion

    • signature: string

      the incomplete ring signature for the given input

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string>

derivePublicKey

  • derivePublicKey(derivation: string, output_index: number, confirm?: boolean): Promise<KeyPair>
  • Generates the public ephemeral of the given output in a transaction

    Parameters

    • derivation: string

      the key derivation

    • output_index: number

      the index of the output in the transaction

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<KeyPair>

deriveSecretKey

  • deriveSecretKey(derivation: string, output_index: number, confirm?: boolean): Promise<KeyPair>
  • Generates the private ephemeral of the given output in a transaction

    Parameters

    • derivation: string

      the key derivation

    • output_index: number

      the index of the output in the transaction

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<KeyPair>

Private exchange

  • exchange(command: Command, confirm?: boolean, data?: Buffer): Promise<Reader>
  • Exchanges an APDU with the connected device

    Parameters

    • command: Command

      the command to send

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    • Optional data: Buffer

      any data that must be included in the payload for the given command

    Returns Promise<Reader>

finalizeTransactionPrefix

  • finalizeTransactionPrefix(): Promise<void>
  • Finalizes a transaction prefix

    Returns Promise<void>

generateKeyDerivation

  • generateKeyDerivation(tx_public_key: string, confirm?: boolean): Promise<string>
  • Generates the transaction key derivation using the private view key stored on the ledger device

    Parameters

    • tx_public_key: string

      the transactions public key

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string>

generateKeyImage

  • generateKeyImage(tx_public_key: string, output_index: number, output_key: string, confirm?: boolean): Promise<string>
  • Generates a key image on the device using the supplied parameters

    Parameters

    • tx_public_key: string

      the transaction public key

    • output_index: number

      the index of the given output in the transaction

    • output_key: string

      the key of the given output in the transaction

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string>

generateKeyImagePrimitive

  • generateKeyImagePrimitive(derivation: string, output_index: number, output_key: string, confirm?: boolean): Promise<string>
  • Generates a key image on the device using the supplied parameters

    Parameters

    • derivation: string

      the output derivation

    • output_index: number

      the index of the given output in the transaction

    • output_key: string

      the key of the given output in the transaction

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string>

generateRingSignatures

  • generateRingSignatures(tx_public_key: string, output_index: number, output_key: string, tx_prefix_hash: string, input_keys: string[], real_output_index: number, confirm?: boolean): Promise<string[]>
  • Generates the ring signatures for the given inputs on the ledger device without revealing the private spend key

    Parameters

    • tx_public_key: string

      the transaction public key of input being spent

    • output_index: number

      the index of the input being spent in the transaction

    • output_key: string

      the output key of the input being spent

    • tx_prefix_hash: string

      our transaction prefix hash

    • input_keys: string[]

      the ring participant keys (mixins + us)

    • real_output_index: number

      the index of the real output in the input_keys

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string[]>

generateSignature

  • generateSignature(message_digest: string, confirm?: boolean): Promise<string>
  • Generates a signature of the message digest using the private spend key stored on the ledger device without revealing the private spend key

    Parameters

    • message_digest: string

      the message digest (hash)

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<string>

getAddress

  • getAddress(confirm?: boolean): Promise<Address>
  • Gets the public wallet address from the connected device

    Parameters

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<Address>

getIdent

  • getIdent(): Promise<string>
  • Retrieves the current identification bytes of the application running on the ledger device

    Returns Promise<string>

getPrivateSpendKey

  • getPrivateSpendKey(confirm?: boolean): Promise<KeyPair>
  • Retrieves the private spend key from the connected ledger device !! WARNING !! Retrieving the private spend key from the device may result in a complete loss of funds as the private spend key should normally remain on the device and never leave

    Parameters

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<KeyPair>

getPrivateViewKey

  • getPrivateViewKey(confirm?: boolean): Promise<KeyPair>
  • Retrieves the private view key from the connected ledger device

    Parameters

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<KeyPair>

getPublicKeys

  • getPublicKeys(confirm?: boolean): Promise<Keys>
  • Retrieves the public keys from the connected ledger device

    Parameters

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<Keys>

getRandomKeyPair

  • getRandomKeyPair(): Promise<KeyPair>
  • Generates a random key pair on the connected device

    Returns Promise<KeyPair>

getVersion

  • getVersion(): Promise<{ major: number; minor: number; patch: number }>
  • Retrieves the current version of the application running on the ledger device

    Returns Promise<{ major: number; minor: number; patch: number }>

getViewWallet

  • getViewWallet(confirm?: boolean): Promise<Address>
  • Retrieves the the public spend key and private view key from the ledger device which is essentially a view only wallet

    Parameters

    • confirm: boolean = true

      whether the device will prompt the user to confirm their actions (to disable, must be running a DEBUG build)

    Returns Promise<Address>

isDebug

  • isDebug(): Promise<boolean>
  • Returns if the application running on the ledger is a debug build

    Returns Promise<boolean>

loadTransactionInput

  • loadTransactionInput(input_tx_public_key: string, input_output_index: number, amount: number, public_keys: string[], offsets: number[], real_output_index: number): Promise<void>
  • Load a transaction input to the transaction construction process

    Parameters

    • input_tx_public_key: string

      the transaction public key of the input

    • input_output_index: number

      the output index of the transaction of the input

    • amount: number

      the amount of the input

    • public_keys: string[]

      the ring participant keys

    • offsets: number[]

      the RELATIVE offsets of the ring participant keys

    • real_output_index: number

      the index in the public_keys of the real output being spent

    Returns Promise<void>

loadTransactionOutput

  • loadTransactionOutput(amount: number, output_key: string): Promise<void>
  • Load a transaction output to the transaction construction process

    Parameters

    • amount: number

      the amount of the output

    • output_key: string

      the output key

    Returns Promise<void>

on

  • on(event: "send", listener: (data: string) => void): LedgerDevice
  • on(event: "receive", listener: (data: string) => void): LedgerDevice
  • on(event: "user_confirm", listener: () => void): LedgerDevice
  • Event that is emitted right before the raw bytes are sent via the APDU transport

    Parameters

    • event: "send"

      the event name

    • listener: (data: string) => void

      the listener function

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    Returns LedgerDevice

  • Emits the raw bytes received from the APDU transport in response to a request

    Parameters

    • event: "receive"

      the event name

    • listener: (data: string) => void

      the listener function

        • (data: string): void
        • Parameters

          • data: string

          Returns void

    Returns LedgerDevice

  • Emits an event if we have sent a command to the ledger wallet that is likely awaiting manual user confirmation on the device

    Parameters

    • event: "user_confirm"
    • listener: () => void
        • (): void
        • Returns void

    Returns LedgerDevice

privateToPublic

  • privateToPublic(private_key: string): Promise<KeyPair>
  • Calculates the public key for the given private key

    Parameters

    • private_key: string

      the private key

    Returns Promise<KeyPair>

resetKeys

  • resetKeys(confirm?: boolean): Promise<void>
  • Resets the keys on the ledger device the same way that they are first initialized on the device

    Parameters

    • confirm: boolean = true

    Returns Promise<void>

resetTransaction

  • resetTransaction(confirm?: boolean): Promise<void>
  • Resets the transaction state of the transaction construction process on the ledger device

    Parameters

    • confirm: boolean = true

    Returns Promise<void>

retrieveTransaction

  • Exports the completed full transaction that we constructed from the ledger device

    Returns Promise<Transaction>

signTransaction

  • signTransaction(confirm?: boolean): Promise<{ hash: string; size: number }>
  • Instructs the ledger device to sign the transaction we have constructed

    Parameters

    • confirm: boolean = true

    Returns Promise<{ hash: string; size: number }>

startTransaction

  • startTransaction(unlock_time?: number, input_count?: number, output_count?: number, tx_public_key: string, payment_id?: string): Promise<void>
  • Starts a new transaction construction on the ledger device

    Parameters

    • unlock_time: number = 0

      the unlock time (or block) of the transaction

    • input_count: number = 0

      the number of inputs that will be included in the transaction

    • output_count: number = 0

      the number of outputs that will be included in the transaction

    • tx_public_key: string

      the transaction public key

    • Optional payment_id: string

      the transaction payment id if one needs to be included

    Returns Promise<void>

startTransactionInputLoad

  • startTransactionInputLoad(): Promise<void>
  • Signals to the ledger that we are ready to start loading transaction inputs

    Returns Promise<void>

startTransactionOutputLoad

  • startTransactionOutputLoad(): Promise<void>
  • Signals to the ledger that we are ready to start loading transaction outputs

    Returns Promise<void>

transactionState

  • transactionState(): Promise<TransactionState>
  • Retrieves the current state of the transaction construction process on the ledger device

    Returns Promise<TransactionState>

Generated using TypeDoc