Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Crypto

A class containing the TurtleCoin cryptographic primitive methods that wraps the Node.js native module, the WASM binary, or native JS implementations into a common interface

Hierarchy

  • Crypto

Index

Constructors

constructor

  • new Crypto(config?: any): Crypto
  • Creates a new wrapper object

    Parameters

    • Optional config: any

    Returns Crypto

Accessors

isNative

  • get isNative(): boolean
  • Returns if the Node.js native library is being used

    Returns boolean

isReady

  • get isReady(): boolean
  • Returns if the wrapper is loaded and ready

    Returns boolean

type

  • get type(): string
  • Returns the type of the cryptographic primitives used by the wrapper

    Returns string

userCryptoFunctions

  • get userCryptoFunctions(): any
  • set userCryptoFunctions(config: any): void
  • Retrieves the array of user-defined cryptographic primitive functions that replace our primitives at runtime

    Returns any

  • Allows for updating the user-defined cryptographic primitive functions that will replace our primitives at runtime.

    Parameters

    • config: any

    Returns void

Static isNative

  • get isNative(): boolean
  • Returns if the Node.js native library is being used

    Returns boolean

Static isReady

  • get isReady(): boolean
  • Returns if the wrapper is loaded and ready

    Returns boolean

Static type

  • get type(): string
  • Returns the type of the cryptographic primitives used by the wrapper

    Returns string

Static userCryptoFunctions

  • get userCryptoFunctions(): any
  • set userCryptoFunctions(config: any): void
  • Retrieves the array of user-defined cryptographic primitive functions that replace our primitives at runtime

    Returns any

  • Allows for updating the user-defined cryptographic primitive functions that will replace our primitives at runtime.

    Parameters

    • config: any

    Returns void

Methods

calculateMultisigPrivateKeys

  • calculateMultisigPrivateKeys(privateSpendKey: string, publicKeys: string[]): Promise<string[]>
  • Calculates the multisignature (m) private keys using our private spend key and the public spend keys of other participants in a M:N scheme

    Parameters

    • privateSpendKey: string

      our private spend key

    • publicKeys: string[]

      an array of the other participants public spend keys

    Returns Promise<string[]>

calculateSharedPrivateKey

  • calculateSharedPrivateKey(privateKeys: string[]): Promise<string>
  • Calculates a shared private key from the private keys supplied

    Parameters

    • privateKeys: string[]

      the array of private keys

    Returns Promise<string>

calculateSharedPublicKey

  • calculateSharedPublicKey(publicKeys: string[]): Promise<string>
  • Calculates a shared public key from the public keys supplied

    Parameters

    • publicKeys: string[]

      the array of public keys

    Returns Promise<string>

checkKey

  • checkKey(key: string): Promise<boolean>
  • Checks whether a given key is a public key

    Parameters

    • key: string

      the public key to check

    Returns Promise<boolean>

checkRingSignature

  • checkRingSignature(hash: string, keyImage: string, inputKeys: string[], signatures: string[]): Promise<boolean>
  • Checks a set of ring signatures to verify that they are valid

    Parameters

    • hash: string

      the hash (often the transaction prefix hash)

    • keyImage: string

      real keyImage used to generate the signatures

    • inputKeys: string[]

      the output keys used during signing (mixins + real)

    • signatures: string[]

      the signatures

    Returns Promise<boolean>

checkRingSignatures

  • checkRingSignatures(hash: string, keyImage: string, inputKeys: string[], signatures: string[]): Promise<boolean>
  • Checks a set of ring signatures to verify that they are valid

    Parameters

    • hash: string

      the hash (often the transaction prefix hash)

    • keyImage: string

      real keyImage used to generate the signatures

    • inputKeys: string[]

      the output keys used during signing (mixins + real)

    • signatures: string[]

      the signatures

    Returns Promise<boolean>

checkScalar

  • checkScalar(privateKey: string): Promise<boolean>
  • Checks whether the given key is a private key

    Parameters

    • privateKey: string

    Returns Promise<boolean>

checkSignature

  • checkSignature(hash: string, publicKey: string, signature: string): Promise<boolean>
  • Checks that the given signature is valid for the hash and public key supplied

    Parameters

    • hash: string

      the hash (message digest) used

    • publicKey: string

      the public key of the private key used to sign

    • signature: string

      the signature

    Returns Promise<boolean>

chukwa_slow_hash

  • chukwa_slow_hash(data: string, version?: number): Promise<string>
  • Calculates the hash of the data supplied using the chukwa_slow_hash method

    Parameters

    • data: string
    • Default value version: number = 1

    Returns Promise<string>

chukwa_slow_hash_base

  • chukwa_slow_hash_base(data: string, iterations: number, memory: number, threads: number): Promise<string>
  • Calculates the hash of the data supplied using the chukwa_slow_hash_base method

    Parameters

    • data: string
    • iterations: number
    • memory: number
    • threads: number

    Returns Promise<string>

chukwa_slow_hash_v1

  • chukwa_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the chukwa_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

chukwa_slow_hash_v2

  • chukwa_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the chukwa_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_lite_slow_hash_v0

  • cn_dark_lite_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_lite_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_lite_slow_hash_v1

  • cn_dark_lite_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_lite_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_lite_slow_hash_v2

  • cn_dark_lite_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_lite_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_slow_hash_v0

  • cn_dark_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_slow_hash_v1

  • cn_dark_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_dark_slow_hash_v2

  • cn_dark_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_dark_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_fast_hash

  • cn_fast_hash(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_fast_hash method

    Parameters

    • data: string

    Returns Promise<string>

cn_lite_slow_hash_v0

  • cn_lite_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_lite_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_lite_slow_hash_v1

  • cn_lite_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_lite_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_lite_slow_hash_v2

  • cn_lite_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_lite_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_slow_hash_v0

  • cn_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_slow_hash_v1

  • cn_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_slow_hash_v2

  • cn_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_soft_shell_slow_hash_v0

  • cn_soft_shell_slow_hash_v0(data: string, height: number): Promise<string>
  • Calculates the hash of the data supplied using the cn_soft_shell_slow_hash_v0 method

    Parameters

    • data: string
    • height: number

      the height of the blockchain

    Returns Promise<string>

cn_soft_shell_slow_hash_v1

  • cn_soft_shell_slow_hash_v1(data: string, height: number): Promise<string>
  • Calculates the hash of the data supplied using the cn_soft_shell_slow_hash_v1 method

    Parameters

    • data: string
    • height: number

      the height of the blockchain

    Returns Promise<string>

cn_soft_shell_slow_hash_v2

  • cn_soft_shell_slow_hash_v2(data: string, height: number): Promise<string>
  • Calculates the hash of the data supplied using the cn_soft_shell_slow_hash_v2 method

    Parameters

    • data: string
    • height: number

      the height of the blockchain

    Returns Promise<string>

cn_turtle_lite_slow_hash_v0

  • cn_turtle_lite_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_lite_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_turtle_lite_slow_hash_v1

  • cn_turtle_lite_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_lite_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_turtle_lite_slow_hash_v2

  • cn_turtle_lite_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_lite_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

cn_turtle_slow_hash_v0

  • cn_turtle_slow_hash_v0(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_slow_hash_v0 method

    Parameters

    • data: string

    Returns Promise<string>

cn_turtle_slow_hash_v1

  • cn_turtle_slow_hash_v1(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_slow_hash_v1 method

    Parameters

    • data: string

    Returns Promise<string>

cn_turtle_slow_hash_v2

  • cn_turtle_slow_hash_v2(data: string): Promise<string>
  • Calculates the hash of the data supplied using the cn_turtle_slow_hash_v2 method

    Parameters

    • data: string

    Returns Promise<string>

completeRingSignatures

  • completeRingSignatures(privateEphemeral: string, realIndex: number, k: string, signatures: string[]): Promise<string[]>
  • Completes a given set of prepared ring signatures using the single privateEphemeral

    Parameters

    • privateEphemeral: string

      private ephemeral of the output being spent

    • realIndex: number

      the position of the signature in the array that belongs to the real output being spent

    • k: string

      the random scalar provided with the prepared ring signatures

    • signatures: string[]

      the prepared ring signatures

    Returns Promise<string[]>

derivationToScalar

  • derivationToScalar(derivation: string, outputIndex: number): Promise<string>
  • Converts a key derivation to its resulting scalar

    Parameters

    • derivation: string

      the key derivation

    • outputIndex: number

      the index of the output in the transaction

    Returns Promise<string>

derivePublicKey

  • derivePublicKey(derivation: string, outputIndex: number, publicKey: string): Promise<string>
  • Derives the public ephemeral from the key derivation, output index, and our public spend key

    Parameters

    • derivation: string

      the key derivation

    • outputIndex: number

      the index of the output in the transaction

    • publicKey: string

      our public spend key

    Returns Promise<string>

deriveSecretKey

  • deriveSecretKey(derivation: string, outputIndex: number, privateKey: string): Promise<string>
  • Derives the private ephemeral from the key derivation, output index, and our private spend key

    Parameters

    • derivation: string

      the key derivation

    • outputIndex: number

      the index of the output in the transaction

    • privateKey: string

      our private spend key

    Returns Promise<string>

forceJSCrypto

  • forceJSCrypto(): boolean
  • Forces the wrapper to use the JS (slow) cryptographic primitives

    Returns boolean

generateDeterministicSubwalletKeys

  • generateDeterministicSubwalletKeys(privateKey: string, walletIndex: number): Promise<IKeyPair>
  • Generates a set of deterministic spend keys for a sub wallet given our root private spend key and the index of the subwallet

    Parameters

    • privateKey: string

      our root private spend key (seed)

    • walletIndex: number

      the index of the subwallet

    Returns Promise<IKeyPair>

generateKeyDerivation

  • generateKeyDerivation(publicKey: string, privateKey: string): Promise<string>
  • Generates a key derivation (aB) given the public key and private key

    Parameters

    • publicKey: string
    • privateKey: string

    Returns Promise<string>

generateKeyDerivationScalar

  • generateKeyDerivationScalar(publicKey: string, privateKey: string, outputIndex: number): Promise<string>
  • Generates a key derivation scalar H_s(aB) given the public key and private key

    Parameters

    • publicKey: string

      the public key

    • privateKey: string

      the private key

    • outputIndex: number

      the output index

    Returns Promise<string>

generateKeyImage

  • generateKeyImage(publicEphemeral: string, privateEphemeral: string): Promise<string>
  • Generates a key image given the public ephemeral and the private ephemeral

    Parameters

    • publicEphemeral: string

      the public ephemeral of the output

    • privateEphemeral: string

      the private ephemeral of the output

    Returns Promise<string>

generateKeys

generatePartialSigningKey

  • generatePartialSigningKey(signature: string, privateKey: string): Promise<string>
  • Generates a partial signing key for a multisig ring signature set

    Parameters

    • signature: string

      the prepared real input signature

    • privateKey: string

      our private spend key (or multisig private key)

    Returns Promise<string>

generatePrivateViewKeyFromPrivateSpendKey

  • generatePrivateViewKeyFromPrivateSpendKey(privateKey: string): Promise<string>
  • Generates a private view key from the private spend key

    Parameters

    • privateKey: string

      the private spend key

    Returns Promise<string>

generateRingSignatures

  • generateRingSignatures(hash: string, keyImage: string, publicKeys: string[], privateEphemeral: string, realIndex: number): Promise<string[]>
  • Generates ring signatures for the supplied values

    Parameters

    • hash: string

      the message digest hash (often the transaction prefix hash)

    • keyImage: string

      the key image of the output being spent

    • publicKeys: string[]

      an array of the output keys used for signing (mixins + our output)

    • privateEphemeral: string

      the private ephemeral of the output being spent

    • realIndex: number

      the array index of the real output being spent in the publicKeys array

    Returns Promise<string[]>

generateSignature

  • generateSignature(hash: string, publicKey: string, privateKey: string): Promise<string>
  • Generates a signature for the given message digest (hash)

    Parameters

    • hash: string

      the hash

    • publicKey: string

      the public key used in signing

    • privateKey: string

      the private key used to sign

    Returns Promise<string>

generateViewKeysFromPrivateSpendKey

  • generateViewKeysFromPrivateSpendKey(privateKey: string): Promise<IKeyPair>
  • Generates a vew key pair from the private spend key

    Parameters

    • privateKey: string

      the private spend key

    Returns Promise<IKeyPair>

hashToEllipticCurve

  • hashToEllipticCurve(hash: string): Promise<string>
  • Converts a hash to an elliptic curve point

    Parameters

    • hash: string

      the hash

    Returns Promise<string>

hashToScalar

  • hashToScalar(hash: string): Promise<string>
  • Converts a hash to a scalar

    Parameters

    • hash: string

      the hash

    Returns Promise<string>

prepareRingSignatures

  • prepareRingSignatures(hash: string, keyImage: string, publicKeys: string[], realIndex: number, k?: undefined | string): Promise<IPreparedRingSignatures>
  • Prepares ring signatures for completion or restoration later

    Parameters

    • hash: string

      the message digest hash (often the transaction prefix hash)

    • keyImage: string

      the key image of the output being spent

    • publicKeys: string[]

      an array of the output keys used for signing (mixins + our output)

    • realIndex: number

      the array index of the real output being spent in the publicKeys array

    • Optional k: undefined | string

      a random scalar (private key)

    Returns Promise<IPreparedRingSignatures>

reloadCrypto

  • reloadCrypto(): Promise<boolean>
  • Re-initializes the underlying cryptographic primitives

    Returns Promise<boolean>

restoreKeyImage

  • restoreKeyImage(publicEphemeral: string, derivation: string, outputIndex: number, partialKeyImages: string[]): Promise<string>
  • Restores a key image from a set of partial key images generated by the other participants in a multisig wallet

    Parameters

    • publicEphemeral: string

      the transaction public ephemeral

    • derivation: string

      the key derivation of the our output

    • outputIndex: number

      the index of our output in the transaction

    • partialKeyImages: string[]

      the array of partial key images from the needed number of participants in the multisig scheme

    Returns Promise<string>

restoreRingSignatures

  • restoreRingSignatures(derivation: string, outputIndex: number, partialSigningKeys: string[], realIndex: number, k: string, signatures: string[]): Promise<string[]>
  • Restores the ring signatures using the previously prepared ring signatures and the necessary number of partial signing keys generated by other participants in the multisig wallet

    Parameters

    • derivation: string

      the key derivation for the output being spent

    • outputIndex: number

      the index of the output being spent in the transaction

    • partialSigningKeys: string[]

      the array of partial signing keys from the necessary number of participants

    • realIndex: number

      the index of the real input in the ring signatures

    • k: string

      the random scalar generated py preparing the ring signatures

    • signatures: string[]

      the prepared ring signatures

    Returns Promise<string[]>

scReduce32

  • scReduce32(data: string): Promise<string>
  • Reduces a value to a scalar (mod q)

    Parameters

    • data: string

    Returns Promise<string>

scalarDerivePublicKey

  • scalarDerivePublicKey(derivationScalar: string, publicKey: string): Promise<string>
  • Derives the public key using the derivation scalar

    Parameters

    • derivationScalar: string

      the derivation scalar

    • publicKey: string

      the public key

    Returns Promise<string>

scalarDeriveSecretKey

  • scalarDeriveSecretKey(derivationScalar: string, privateKey: string): Promise<string>
  • Derives the private key using the derivation scalar

    Parameters

    • derivationScalar: string

      the derivation scalar

    • privateKey: string

      the private key

    Returns Promise<string>

scalarmultKey

  • scalarmultKey(keyImageA: string, keyImageB: string): Promise<string>
  • Multiplies two key images together

    Parameters

    • keyImageA: string
    • keyImageB: string

    Returns Promise<string>

secretKeyToPublicKey

  • secretKeyToPublicKey(privateKey: string): Promise<string>
  • Calculates the public key of a private key

    Parameters

    • privateKey: string

    Returns Promise<string>

tree_branch

  • tree_branch(hashes: string[]): Promise<string[]>
  • Calculates the merkle tree branch of the given hashes

    Parameters

    • hashes: string[]

      the array of hashes

    Returns Promise<string[]>

tree_depth

  • tree_depth(count: number): Promise<number>
  • Calculates the depth of the merkle tree

    Parameters

    • count: number

      the number of hashes in the tree

    Returns Promise<number>

tree_hash

  • tree_hash(hashes: string[]): Promise<string>
  • Calculates the merkle tree hash of the given hashes

    Parameters

    • hashes: string[]

      the array of hashes

    Returns Promise<string>

tree_hash_from_branch

  • tree_hash_from_branch(branches: string[], leaf: string, path: number): Promise<string>
  • Calculates the merkle tree hash from the given branch information

    Parameters

    • branches: string[]

      the merkle tree branches

    • leaf: string

      the leaf on the merkle tree

    • path: number

      the path on the merkle tree

    Returns Promise<string>

underivePublicKey

  • underivePublicKey(derivation: string, outputIndex: number, outputKey: string): Promise<string>
  • Underives a public key instead of deriving it

    Parameters

    • derivation: string

      the key derivation

    • outputIndex: number

      the index of the output in the transaction

    • outputKey: string

      the output key in the transaction

    Returns Promise<string>

Static forceJSCrypto

  • forceJSCrypto(): boolean
  • Forces the wrapper to use the JS (slow) cryptographic primitives

    Returns boolean

Generated using TypeDoc