Skip to content

Commit

Permalink
Merge pull request #589 from nervosnetwork/rc/v0.103.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored May 9, 2022
2 parents 66378da + 667595d commit e7cdfbc
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)


### Bug Fixes

* fix default code hash/code hash index in toAddressPayload ([e72a29d](https://github.com/nervosnetwork/ckb-sdk-js/commit/e72a29d46615bc09fc9ff726e30abb5f70ac26d7))





## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)

**Note:** Version bump only for package ckb-sdk-js
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.102.3"
"version": "0.103.0"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core





## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core
Expand Down
10 changes: 5 additions & 5 deletions packages/ckb-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-core",
"version": "0.102.3",
"version": "0.103.0",
"description": "JavaScript SDK for Nervos Network CKB Project",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -33,10 +33,10 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-rpc": "0.102.3",
"@nervosnetwork/ckb-sdk-utils": "0.102.3",
"@nervosnetwork/ckb-types": "0.102.3",
"@nervosnetwork/ckb-sdk-rpc": "0.103.0",
"@nervosnetwork/ckb-sdk-utils": "0.103.0",
"@nervosnetwork/ckb-types": "0.103.0",
"tslib": "2.3.1"
},
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
}
8 changes: 8 additions & 0 deletions packages/ckb-sdk-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc





## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc
Expand Down
8 changes: 4 additions & 4 deletions packages/ckb-sdk-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-rpc",
"version": "0.102.3",
"version": "0.103.0",
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
Expand Down Expand Up @@ -33,12 +33,12 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-sdk-utils": "0.102.3",
"@nervosnetwork/ckb-sdk-utils": "0.103.0",
"axios": "0.21.4",
"tslib": "2.3.1"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.102.3"
"@nervosnetwork/ckb-types": "0.103.0"
},
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
}
11 changes: 11 additions & 0 deletions packages/ckb-sdk-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)


### Bug Fixes

* fix default code hash/code hash index in toAddressPayload ([e72a29d](https://github.com/nervosnetwork/ckb-sdk-js/commit/e72a29d46615bc09fc9ff726e30abb5f70ac26d7))





## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)

**Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils
Expand Down
20 changes: 16 additions & 4 deletions packages/ckb-sdk-utils/__tests__/address/fixtures.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{
"toAddressPayload": {
"basic": {
"should have default params for short version address": {
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c"],
"expected": [1, 0, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
},
"full address of new version specifies hash_type = type": {
"should have default secp256k1 code hash index when address type is hash index": {
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x01"],
"expected": [1, 0, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
},
"should have default secp256k1 code hash when address type is not hash index": {
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x04", ""],
"expected": [4, 155, 215, 224, 111, 62, 207, 75, 224, 242, 252, 210, 24, 139, 35, 241, 185, 252, 200, 142, 93, 75, 101, 168, 99, 123, 23, 114, 59, 189, 163, 204, 232, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
},
"should have default hash_type = type when full address of new version with secp256k1 code hash": {
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"],
"expected": [0, 155, 215, 224, 111, 62, 207, 75, 224, 242, 252, 210, 24, 139, 35, 241, 185, 252, 200, 142, 93, 75, 101, 168, 99, 123, 23, 114, 59, 189, 163, 204, 232, 1, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
},
"full address of new version specifies hash_type = data1": {
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176", "data1"],
"expected": [0, 166, 86, 241, 114, 182, 180, 92, 36, 83, 7, 174, 181, 167, 163, 122, 23, 111, 0, 47, 111, 34, 233, 37, 130, 197, 139, 247, 186, 54, 46, 65, 118, 2, 179, 155, 188, 11, 54, 115, 199, 211, 100, 80, 188, 20, 207, 205, 173, 45, 85, 156, 108, 100]
},
Expand All @@ -16,8 +28,8 @@
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x00", "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c135"],
"exception": "'0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c135' is not a valid code hash"
},
"should throw an error when its a full version address identifies the hash_type but hash_type is missing": {
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"],
"should throw an error when its a full version address but hash_type is missing while code hash is not secp256k1 code hash": {
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3ccee"],
"exception": "hashType is required"
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/ckb-sdk-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-sdk-utils",
"version": "0.102.3",
"version": "0.103.0",
"description": "Utils module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand Down Expand Up @@ -31,7 +31,7 @@
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"dependencies": {
"@nervosnetwork/ckb-types": "0.102.3",
"@nervosnetwork/ckb-types": "0.103.0",
"bech32": "2.0.0",
"elliptic": "6.5.4",
"jsbi": "3.1.3",
Expand All @@ -41,5 +41,5 @@
"@types/bitcoinjs-lib": "5.0.0",
"@types/elliptic": "6.4.12"
},
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
}
15 changes: 12 additions & 3 deletions packages/ckb-sdk-utils/src/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,13 @@ export interface AddressOptions {
* @see https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* @param {string | Uint8Array} args, use as the identifier of an address, usually the public key hash is used.
* @param {string} type, used to indicate which format is adopted to compose the address.
* @param {string} codeHashOrCodeHashIndex, the referenced code hash or code hash index the address binds to
* @param {string} codeHashOrCodeHashIndex, the referenced code hash or code hash index the address binds to,
* default to be secp256k1 code hash/code hash index
*/
export const toAddressPayload = (
args: string | Uint8Array,
type: AddressType = AddressType.HashIdx,
codeHashOrCodeHashIndex: CodeHashIndex | CKBComponents.Hash256 = '0x00',
codeHashOrCodeHashIndex?: CodeHashIndex | CKBComponents.Hash256,
hashType?: CKBComponents.ScriptHashType,
): Uint8Array => {
if (typeof args === 'string' && !args.startsWith('0x')) {
Expand All @@ -108,6 +109,10 @@ export const toAddressPayload = (
)
}

if (!codeHashOrCodeHashIndex) {
codeHashOrCodeHashIndex = type === AddressType.HashIdx ? '0x00' : SECP256K1_BLAKE160.codeHash
}

if (type !== AddressType.FullVersion) {
return new Uint8Array([
...hexToBytes(type),
Expand All @@ -116,6 +121,10 @@ export const toAddressPayload = (
])
}

if (!hashType && codeHashOrCodeHashIndex === SECP256K1_BLAKE160.codeHash) {
hashType = SECP256K1_BLAKE160.hashType
}

if (!codeHashOrCodeHashIndex.startsWith('0x') || codeHashOrCodeHashIndex.length !== 66) {
throw new CodeHashException(codeHashOrCodeHashIndex)
}
Expand All @@ -142,7 +151,7 @@ export const toAddressPayload = (
*/
export const bech32Address = (
args: Uint8Array | string,
{ prefix = AddressPrefix.Mainnet, type = AddressType.HashIdx, codeHashOrCodeHashIndex = '0x00' }: AddressOptions = {},
{ prefix = AddressPrefix.Mainnet, type = AddressType.HashIdx, codeHashOrCodeHashIndex = '' }: AddressOptions = {},
) => bech32.encode(prefix, bech32.toWords(toAddressPayload(args, type, codeHashOrCodeHashIndex)), MAX_BECH32_LIMIT)

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/ckb-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)

**Note:** Version bump only for package @nervosnetwork/ckb-types





## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)

**Note:** Version bump only for package @nervosnetwork/ckb-types
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nervosnetwork/ckb-types",
"version": "0.102.3",
"version": "0.103.0",
"description": "Type module of @nervosnetwork/ckb-sdk-core",
"author": "Nervos <[email protected]>",
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
Expand All @@ -20,5 +20,5 @@
"bugs": {
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
},
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
}

0 comments on commit e7cdfbc

Please sign in to comment.