Skip to content

API : Account

王辰 edited this page Jan 6, 2020 · 3 revisions

<<< Return API Reference

Navigation

Methods

getCryptoByPwd

Create an account

Parameters

* password <string>
  private-key <string>
  key-store <object>

Returns

{
  P2PKH: privK.privKey.toP2PKHAddress,
  P2SH: privK.privKey.toP2SHAddress,
  privateKey,
  cryptoJSON
}

Example

// Create an account by password
await boxdjs.Account.getCryptoByPwd('box1234')

// Import an account by (password + private-key)
await boxdjs.Account.getCryptoByPwd(
      'box1234',
      '40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b'
    )

// Import an account by (password + key-store)
await boxdjs.Account.getCryptoByPwd(
      'box1234',
      await boxdjs.Account.dumpPrivKeyFromCrypto(<key-store>, 'box1234')
    )

dumpAddrFromPrivKey

Dump P2PKH-address from private-key

Parameters

* private-key <string | Buffer>

Returns

P2PKH-address <string>

Example

await boxdjs.Account.dumpAddrFromPrivKey('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b')
await boxdjs.Account.dumpAddrFromPrivKey(Buffer.from('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b', 'hex'))

dumpPubKeyFromPrivKey

Dump public-key from private-key

Parameters

* private-key <string | Buffer>

Returns

public-key <string>

Example

await boxdjs.Account.dumpPubKeyFromPrivKey('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b')
await boxdjs.Account.dumpPubKeyFromPrivKey(Buffer.from('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b', 'hex'))

dumpCryptoFromPrivKey

Dump crypto-json from (private-key + password)

Parameters

* private-key <string | Buffer> 
* password <string>

Returns

crypto-json <object>

Example

await boxdjs.Account.dumpCryptoFromPrivKey('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b', 'box1234')
await boxdjs.Account.dumpCryptoFromPrivKey(Buffer.from('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b', 'hex'), 'box1234')

dumpPubKeyHashFromPrivKey

Dump public-key-hash from private-key

Parameters

* private-key <string | Buffer> 

Returns

public-key-hash <string>

Example

await boxdjs.Account.dumpPubKeyHashFromPrivKey('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b')
await boxdjs.Account.dumpPubKeyHashFromPrivKey(Buffer.from('40b5608b183efc7b1940d09d29cc49c9ebbdaf8fb7d43e0dc079f56025ed6a4b', 'hex'))

dumpPubKeyHashFromAddr

Dump public-key-hash from P2PKH-address

Parameters

* P2PKH-address <string> 

Returns

public-key-hash <string>

Example

await boxdjs.Account.dumpPubKeyHashFromAddr('b1cRrJ9rhksTgaawpJ8B4sANUUMLGgCmsVA')

dumpPrivKeyFromCrypto

Dump private-key from (private-key+password)

Parameters

* key-store <object> 
* password <string>

Returns

private-key <string>

Example

await boxdjs.Account.dumpPrivKeyFromCrypto(<key-store>, 'box1234')

Clone this wiki locally