This package has been deprecated

Author message:

deprecate @nervosnetwork/ckb-sdk-address and bundle it in @nervosnetwork/ckb-sdk-core

@nervosnetwork/ckb-sdk-address
TypeScript icon, indicating that this package has built-in type declarations

0.21.1 • Public • Published

ckb-sdk-address

@nervosnetwork/ckb-sdk-address is the address module of @nervosnetwork/ckb-sdk-core.

Its current responsibility is just to generate an address object, the algorithm will be introduced in an RFC in the near future.

In a nutshell, the address format is similar to BIP-0173

  1. this module takes a private key and then calculates the corresponding public key with secp256k1 algorithm;
  2. use blake160 algorithm to hash the public key and get a blake160-ed string;
  3. bech32 the blake160-ed string with three options(prefix, type, binIndex) to get a bech32-formatted address.

Detailed methods could be found in @nervosnetwork/ckb-sdk-utils

Address configuration

The meanings of the configuration will be explained in the RFC.

  1. Prefix

    • 'ckb' for the mainnet
    • 'ckt' for the testnet
  2. type

    • '0x00' for wallet build-in binary_hash ref id
    • '0x01' for binary_hash
  3. binIndex

    • 'P2PH'

Address Value

The address.value is the address string generated by the private key and address configuration you passed to the constructor.

Address identifier

The address.identifier represents the identity of the address object. It derives from the public key, and used to generate the human readable address value.

address.identifier is calculated by blake160(publicKey), which picks the first 20 bytes of blake2b(publicKey).

And address.identifier is used to generate address.value in bech32(address.identifier, ...AddressConfiguration).

Installation

Install the package with yarn:

$ yarn add @nervosnetwork/ckb-sdk-address

Or install the package with npm:

$ npm install --save @nervosnetwork/ckb-sdk-address

Usage

const Address = require('@nervosnetwork/ckb-sdk-address').default

const privateKey = 'your private key'

const address = new Address(privateKey, { prefix: 'ckt' })
console.log(address.value)
console.log(address.identifier)

Readme

Keywords

Package Sidebar

Install

npm i @nervosnetwork/ckb-sdk-address

Weekly Downloads

0

Version

0.21.1

License

MIT

Unpacked Size

16.8 kB

Total Files

13

Last publish

Collaborators

  • xueping
  • xuejie.nervos
  • nervos_network
  • keith_chen