Options
All
  • Public
  • Public/Protected
  • All
Menu

keyvenant

Index

Variables

Const blake2b

blake2b: any = blake.blake2b

Const crypto

crypto: any = isBrowser ? require('crypto-browserify') : require('crypto')

Const isBrowser

isBrowser: boolean = typeof process === 'undefined' || !process.nextTick

Let k

k: Keyvenant = new Keyvenant()

Functions

THash

  • THash(input: Buffer): Buffer

blake2b512

  • blake2b512(input: Buffer, key?: Uint8Array): Uint8Array
  • Parameters

    • input: Buffer
    • Optional key: Uint8Array

    Returns Uint8Array

constructEncrypted

  • constructEncrypted(privateKeyVersion: number, iv: string, ciphertext: string): string
  • construct base58 encoded string for CovenantSQL chain recover privateKeyVersion(1B) + iv(16B) + ciphertext(48B) as concated hex then base58 encoded the concated and return

    Parameters

    • privateKeyVersion: number

      1 btye version

    • iv: string

      generated iv

    • ciphertext: string

      encrypted ciphertext

    Returns string

    base58Encoded concated

constructMac

  • constructMac(secretKey: string, ciphertext: string): string
  • construct Mac for password pre-check secretKey + ciphertext as mac input then THash convert to Mac hex string and return

    Parameters

    • secretKey: string

      derived key hex string

    • ciphertext: string

      encrypted hex string

    Returns string

    mac as hex string

createKeystore

  • createKeystore(password: string, salt: string, addrVersion: number, privateKeyVersion: number): object
  • create CovenantSQL keystore

    Parameters

    • password: string

      master password user typed-in

    • salt: string

      kdf salt

    • addrVersion: number

      address version

    • privateKeyVersion: number

      private key encode version

    Returns object

    keystore object

createPrivateKey

  • createPrivateKey(keySize?: number): string
  • create CovenantSQL private key use ECDS(secp256k1) for private key generation

    Parameters

    • Default value keySize: number = 32

    Returns string

    privateKey hex string

deconstructEncrypted

  • deconstructEncrypted(encrypted: string): object
  • deconstruct base58 encoded string for CovenantSQL chain recover

    Parameters

    • encrypted: string

      base58Encoded concated

    Returns object

    { privateKeyVersion 1 btye version iv generated iv ciphertext encrypted ciphertext }

decrypt

  • decrypt(encrypted: string, key: string, iv: string, algo?: string): string
  • symmetric decryption

    Parameters

    • encrypted: string

      encrypted ciphertext in hex (48 btyes)

    • key: string

      serectKey string in hex (16 btyes)

    • iv: string

      iv string in hex (16 btyes because of AES 128bit blocksize)

    • Default value algo: string = "aes256"

    Returns string

    decrypted text in hex

derive

  • derive(password: string, salt: string): string
  • derive secret key from password user typed-in use sha256x2 as key derivation function(kdf)

    Parameters

    • password: string

      user's password in utf8

    • salt: string

      default salt in hex

    Returns string

    secretKey string in hex (16 bytes because of sha256)

encrypt

  • encrypt(plaintext: string, key: string, iv: string, algo?: string): string
  • symmetric encryption

    Parameters

    • plaintext: string

      input text to be encrypted

    • key: string

      serectKey string in hex (16 btyes)

    • iv: string

      iv string in hex (16 btyes because of AES 128bit blocksize)

    • Default value algo: string = "aes256"

    Returns string

    encrypted ciphertext in hex (48 btyes)

exportToFile

  • exportToFile(keystore: any): string

generateIv

  • generateIv(length?: number): string
  • randomly generate iv

    Parameters

    • Default value length: number = 16

      default length is 16 btyes because of AES 128bit blocksize

    Returns string

    iv in hex

generateKeystoreFilename

  • generateKeystoreFilename(address: string): string

importFromFile

  • importFromFile(filepath: string): any

isBase64

  • isBase64(str: string): Boolean

isCipherAvailable

  • isCipherAvailable(algo: string): Boolean
  • check cipher availablility

    Parameters

    • algo: string

    Returns Boolean

    boolean of cipher availablility

isHex

  • isHex(str: string): Boolean

isPrivateKeyValid

  • isPrivateKeyValid(privateKey: Buffer): Boolean
  • check private key validity

    Parameters

    • privateKey: Buffer

      private key hex string

    Returns Boolean

    boolean of private key validity

marshal

  • marshal(address: string, salt: string, mac: string, ciphertext: string, iv: string, privateKeyVersion: number): object
  • construct keystore json

    Parameters

    • address: string

      wallet address

    • salt: string

      kdf salt

    • mac: string

      mac value

    • ciphertext: string

      encrypted text

    • iv: string

      symmetric iv

    • privateKeyVersion: number

      version hex

    Returns object

    keystore object

privateKeyToPublicKey

  • privateKeyToPublicKey(privateKey: string, compressed?: boolean): string
  • create public key from private key use secp256k1 public key generation with compress enabled

    Parameters

    • privateKey: string

      private key hex string

    • Default value compressed: boolean = true

    Returns string

    publicKey hex string

publicKeyToAddress

  • publicKeyToAddress(publicKey: string, version: number): string
  • convert address from public key

    1. hash public key by THash
    2. base58 encode hasedPubKey to filter out O 0, I i, + /

    Parameters

    • publicKey: string

      public key hex string

    • version: number

      version hex string to differ MainNet & TestNet

    Returns string

    address hex string

recoverFromKeystore

  • recoverFromKeystore(password: string, salt: string, keystore: any): string
  • recover private key from keystore and password

    Parameters

    • password: string
    • salt: string
    • keystore: any

    Returns string

    private key string in hex

sha256

  • sha256(message: any, isHex?: boolean): any
  • Calculate the sha256 digest of a string.

    Example (es imports)

    import { sha256 } from 'typescript-starter'
    sha256('test')
    // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'

    Parameters

    • message: any
    • Default value isHex: boolean = false

    Returns any

    sha256 message digest

sha256Native

  • sha256Native(message: any, isHex?: boolean): any
  • A faster implementation of sha256 which requires the native Node.js module. Browser consumers should use sha256, instead.

    Example (es imports)

    import { sha256Native as sha256 } from 'typescript-starter'
    sha256('test')
    // => '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'

    Parameters

    • message: any
    • Default value isHex: boolean = false

    Returns any

    sha256 message digest

sha256x2

  • sha256x2(message: any, isHex?: boolean): any

string2Buffer

  • string2Buffer(str: string, enc?: string): Buffer

verify

  • verify(password: string, salt: string, secretKey: string): Boolean
  • verify secret key from password and salt

    Parameters

    • password: string

      old password in utf8

    • salt: string

      default salt in hex

    • secretKey: string

      secret key in hex

    Returns Boolean

    boolean of verify success or not

Object literals

Const defaultConfig

defaultConfig: object

isMainNet

isMainNet: boolean = false

secretKey

secretKey: object

salt

salt: string = Buffer.from('auxten-key-salt-auxten', 'utf8').toString('hex')

versions

versions: object

privateKey

privateKey: number = 35

address

address: object

mainNet

mainNet: number = 0

testNet

testNet: number = 111

Generated using TypeDoc