Options
All
  • Public
  • Public/Protected
  • All
Menu

Package hd

@ckb-lumos/hd

HD & Mnemonic implementation for lumos.

Usage

Create a new HD wallet.

const { mnemonic, ExtendedPrivateKey, Keystore } = require("@ckb-lumos/hd")
const m = mnemonic.generateMnemonic()
const seed = mnemonic.mnemonicToSeedSync(m)
const extendedPrivateKey = ExtendedPrivateKey.fromSeed(seed)
const keystore = Keystore.create(extendedPrivateKey, "Your password")
// save keystore file
keystore.save("you path, only dir")

// load keystore file
const keystore = Keystore.load("you file path, with file name")

XPub support.

const { XPubStore } = require("@ckb-lumos/hd")

// load from xpub file.
const xpub = XPubStore.load("you path")

// to AccountExtendedPublicKey
const accountExtendedPublicKey = xpub.toAccountExtendedPublicKey()

// save xpub file.
xpub.save("your path")

Browsers

This package enforces key management by importing buffer, stream, crypto, fs and path packages, which are not available in browser environment. If you want to use '@lumos/hd' in your front-end project, please include polyfill to your project module bundle. Here is a webpack example:

resolve: {
  ...
  fallback: {
    fs: false,
    buffer: require.resolve('buffer/'),
    stream: require.resolve('stream-browserify'),
    path: require.resolve('path-browserify'),
    crypto: require.resolve('crypto-browserify'),
  },
  plugins: [
    new webpack.ProvidePlugin({
      process: 'process/browser',
      Buffer: ['buffer', 'Buffer'],
    }),
  ],
}

You'll need to install buffer, stream-browserify, path-browserify and crypto-browserify also.

Index

Type aliases

HexStringWithoutPrefix

HexStringWithoutPrefix: string

HexStringWithoutPrefix

HexStringWithoutPrefix: string

Variables

Const CIPHER

CIPHER: "aes-128-ctr" = "aes-128-ctr"

Const CKB_CLI_ORIGIN

CKB_CLI_ORIGIN: "ckb-cli" = "ckb-cli"

Const EMPTY_BUFFER

EMPTY_BUFFER: Buffer = Buffer.from("")

Const ENTROPY_NOT_DIVISIBLE

ENTROPY_NOT_DIVISIBLE: "Entropy should be divisable by 4" = `Entropy should be divisable by 4`

Const ENTROPY_TOO_LONG

ENTROPY_TOO_LONG: string = `Entropy should be shorter than ${MAX_ENTROPY_SIZE + 1}`

Const ENTROPY_TOO_SHORT

ENTROPY_TOO_SHORT: string = `Entropy should be longer than ${MIN_ENTROPY_SIZE - 1}`

Const INVALID_CHECKSUM

INVALID_CHECKSUM: "Invalid checksum" = `Invalid checksum`

Const INVALID_MNEMONIC

INVALID_MNEMONIC: "Invalid mnemonic" = `Invalid mnemonic`

Const KEY_LEN

KEY_LEN: 64 = 64

Const MAX_ENTROPY_SIZE

MAX_ENTROPY_SIZE: 32 = 32

Const MAX_WORDS_SIZE

MAX_WORDS_SIZE: 24 = 24

Const MIN_ENTROPY_SIZE

MIN_ENTROPY_SIZE: 16 = 16

Const MIN_WORDS_SIZE

MIN_WORDS_SIZE: 12 = 12

Const PBKDF2_ROUNDS

PBKDF2_ROUNDS: 2048 = 2048

Const RADIX

RADIX: 2048 = 2048

Const WORDS_TOO_LONG

WORDS_TOO_LONG: string = `Words should be shorter than ${MAX_WORDS_SIZE + 1}`

Const WORDS_TOO_SHORT

WORDS_TOO_SHORT: string = `Words should be longer than ${MIN_WORDS_SIZE - 1}`

Const _default

_default: { entropyToMnemonic: typeof entropyToMnemonic; generateMnemonic: typeof generateMnemonic; mnemonicToEntropy: typeof mnemonicToEntropy; mnemonicToSeed: typeof mnemonicToSeed; mnemonicToSeedSync: typeof mnemonicToSeedSync; validateMnemonic: typeof validateMnemonic }

Type declaration

Const _default

_default: { privateKeyToBlake160: typeof privateKeyToBlake160; privateToPublic: typeof privateToPublic; publicKeyToBlake160: typeof publicKeyToBlake160; recoverFromSignature: typeof recoverFromSignature; signRecoverable: typeof signRecoverable }

Type declaration

Const _default

_default: { AccountExtendedPublicKey: typeof AccountExtendedPublicKey; AddressType: typeof AddressType; ExtendedPrivateKey: typeof ExtendedPrivateKey; ExtendedPublicKey: typeof ExtendedPublicKey; IncorrectPassword: typeof IncorrectPassword; InvalidKeystore: typeof InvalidKeystore; Keychain: typeof Keychain; Keystore: typeof Keystore; UnsupportedCipher: typeof UnsupportedCipher; XPubStore: typeof XPubStore; key: { privateKeyToBlake160: privateKeyToBlake160; privateToPublic: privateToPublic; publicKeyToBlake160: publicKeyToBlake160; recoverFromSignature: recoverFromSignature; signRecoverable: signRecoverable }; mnemonic: { entropyToMnemonic: entropyToMnemonic; generateMnemonic: generateMnemonic; mnemonicToEntropy: mnemonicToEntropy; mnemonicToSeed: mnemonicToSeed; mnemonicToSeedSync: mnemonicToSeedSync; validateMnemonic: validateMnemonic } }

Type declaration

Const _default

_default: string[]

assertHexString

assertHexString: assertHexString

Const ec

ec: ec = new EC("secp256k1")

Const ec

ec: ec = new EC("secp256k1")

Functions

assertChainCode

  • assertChainCode(chainCode: HexString): void
  • Parameters

    Returns void

assertChainCode

  • assertChainCode(chainCode: HexString): void
  • Parameters

    Returns void

assertPrivateKey

  • assertPrivateKey(privateKey: HexString): void
  • Parameters

    Returns void

assertPrivateKey

  • assertPrivateKey(privateKey: HexString): void
  • Parameters

    Returns void

assertPublicKey

  • assertPublicKey(publicKey: HexString, debugPath?: undefined | string): void
  • Parameters

    • publicKey: HexString
    • Optional debugPath: undefined | string

    Returns void

assertPublicKey

  • assertPublicKey(publicKey: HexString, debugPath?: undefined | string): void
  • Parameters

    • publicKey: HexString
    • Optional debugPath: undefined | string

    Returns void

bytesToBinary

  • bytesToBinary(bytes: Buffer): string
  • Parameters

    • bytes: Buffer

    Returns string

deriveChecksumBits

  • deriveChecksumBits(entropyBuffer: Buffer): string
  • Parameters

    • entropyBuffer: Buffer

    Returns string

entropyToMnemonic

  • entropyToMnemonic(entropyStr: HexString): string
  • Parameters

    Returns string

entropyToMnemonic

  • entropyToMnemonic(entropyStr: HexString): string
  • Parameters

    Returns string

generateMnemonic

  • generateMnemonic(): string
  • Returns string

generateMnemonic

  • generateMnemonic(): string
  • Returns string

mnemonicToEntropy

  • mnemonicToEntropy(mnemonic?: undefined | string): HexString
  • Parameters

    • Optional mnemonic: undefined | string

    Returns HexString

mnemonicToEntropy

  • mnemonicToEntropy(mnemonic?: string): HexString
  • Parameters

    • Default value mnemonic: string = ""

    Returns HexString

mnemonicToSeed

  • mnemonicToSeed(mnemonic?: undefined | string, password?: undefined | string): Promise<Buffer>
  • Parameters

    • Optional mnemonic: undefined | string
    • Optional password: undefined | string

    Returns Promise<Buffer>

mnemonicToSeed

  • mnemonicToSeed(mnemonic?: string, password?: string): Promise<Buffer>
  • Parameters

    • Default value mnemonic: string = ""
    • Default value password: string = ""

    Returns Promise<Buffer>

mnemonicToSeedSync

  • mnemonicToSeedSync(mnemonic?: undefined | string, password?: undefined | string): Buffer
  • Parameters

    • Optional mnemonic: undefined | string
    • Optional password: undefined | string

    Returns Buffer

mnemonicToSeedSync

  • mnemonicToSeedSync(mnemonic?: string, password?: string): Buffer
  • Parameters

    • Default value mnemonic: string = ""
    • Default value password: string = ""

    Returns Buffer

privateKeyToBlake160

  • Parameters

    Returns HexString

privateKeyToBlake160

privateToPublic

  • privateToPublic(privateKey: Buffer): Buffer
  • privateToPublic(privateKey: HexString): HexString
  • Parameters

    • privateKey: Buffer

    Returns Buffer

  • Parameters

    Returns HexString

privateToPublic

  • privateToPublic(privateKey: Buffer): Buffer
  • privateToPublic(privateKey: HexString): HexString
  • Parameters

    • privateKey: Buffer

    Returns Buffer

  • Parameters

    Returns HexString

publicKeyToBlake160

publicKeyToBlake160

recoverFromSignature

recoverFromSignature

salt

  • salt(password?: string): string
  • Parameters

    • Default value password: string = ""

    Returns string

signRecoverable

signRecoverable

validateMnemonic

  • validateMnemonic(mnemonic: string): boolean
  • Parameters

    • mnemonic: string

    Returns boolean

validateMnemonic

  • validateMnemonic(mnemonic: string): boolean
  • Parameters

    • mnemonic: string

    Returns boolean

Generated using TypeDoc