@nervosnetwork/ckb-sdk-address
@nervosnetwork/ckb-sdk-address
npm i @nervosnetwork/ckb-sdk-address
Deprecated!
deprecate @nervosnetwork/ckb-sdk-address and bundle it in @nervosnetwork/ckb-sdk-core
@nervosnetwork/ckb-sdk-address

@nervosnetwork/ckb-sdk-address

JavaScript SDK for CKB

by nervosnetwork

0.21.1 (see all)License:MITTypeScript:Not Found
npm i @nervosnetwork/ckb-sdk-address
Readme

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)

Downloads/wk

2

GitHub Stars

40

LAST COMMIT

8mos ago

MAINTAINERS

2

CONTRIBUTORS

16

OPEN ISSUES

4

OPEN PRs

1
VersionTagPublished
0.21.1
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate