Skip to content

Commit e7cdfbc

Browse files
authored
Merge pull request #589 from nervosnetwork/rc/v0.103.0
2 parents 66378da + 667595d commit e7cdfbc

File tree

12 files changed

+89
-22
lines changed

12 files changed

+89
-22
lines changed

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)
7+
8+
9+
### Bug Fixes
10+
11+
* fix default code hash/code hash index in toAddressPayload ([e72a29d](https://github.com/nervosnetwork/ckb-sdk-js/commit/e72a29d46615bc09fc9ff726e30abb5f70ac26d7))
12+
13+
14+
15+
16+
617
## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)
718

819
**Note:** Version bump only for package ckb-sdk-js

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
],
55
"npmClient": "yarn",
66
"useWorkspaces": true,
7-
"version": "0.102.3"
7+
"version": "0.103.0"
88
}

packages/ckb-sdk-core/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)
7+
8+
**Note:** Version bump only for package @nervosnetwork/ckb-sdk-core
9+
10+
11+
12+
13+
614
## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)
715

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

packages/ckb-sdk-core/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nervosnetwork/ckb-sdk-core",
3-
"version": "0.102.3",
3+
"version": "0.103.0",
44
"description": "JavaScript SDK for Nervos Network CKB Project",
55
"author": "Nervos <dev@nervos.org>",
66
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
@@ -33,10 +33,10 @@
3333
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
3434
},
3535
"dependencies": {
36-
"@nervosnetwork/ckb-sdk-rpc": "0.102.3",
37-
"@nervosnetwork/ckb-sdk-utils": "0.102.3",
38-
"@nervosnetwork/ckb-types": "0.102.3",
36+
"@nervosnetwork/ckb-sdk-rpc": "0.103.0",
37+
"@nervosnetwork/ckb-sdk-utils": "0.103.0",
38+
"@nervosnetwork/ckb-types": "0.103.0",
3939
"tslib": "2.3.1"
4040
},
41-
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
41+
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
4242
}

packages/ckb-sdk-rpc/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)
7+
8+
**Note:** Version bump only for package @nervosnetwork/ckb-sdk-rpc
9+
10+
11+
12+
13+
614
## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)
715

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

packages/ckb-sdk-rpc/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nervosnetwork/ckb-sdk-rpc",
3-
"version": "0.102.3",
3+
"version": "0.103.0",
44
"description": "RPC module of @nervosnetwork/ckb-sdk-core",
55
"author": "Nervos <dev@nervos.org>",
66
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme",
@@ -33,12 +33,12 @@
3333
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
3434
},
3535
"dependencies": {
36-
"@nervosnetwork/ckb-sdk-utils": "0.102.3",
36+
"@nervosnetwork/ckb-sdk-utils": "0.103.0",
3737
"axios": "0.21.4",
3838
"tslib": "2.3.1"
3939
},
4040
"devDependencies": {
41-
"@nervosnetwork/ckb-types": "0.102.3"
41+
"@nervosnetwork/ckb-types": "0.103.0"
4242
},
43-
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
43+
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
4444
}

packages/ckb-sdk-utils/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)
7+
8+
9+
### Bug Fixes
10+
11+
* fix default code hash/code hash index in toAddressPayload ([e72a29d](https://github.com/nervosnetwork/ckb-sdk-js/commit/e72a29d46615bc09fc9ff726e30abb5f70ac26d7))
12+
13+
14+
15+
16+
617
## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)
718

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

packages/ckb-sdk-utils/__tests__/address/fixtures.json

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
{
22
"toAddressPayload": {
3-
"basic": {
3+
"should have default params for short version address": {
44
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c"],
55
"expected": [1, 0, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
66
},
7-
"full address of new version specifies hash_type = type": {
7+
"should have default secp256k1 code hash index when address type is hash index": {
8+
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x01"],
9+
"expected": [1, 0, 54, 195, 41, 237, 99, 13, 108, 231, 80, 113, 42, 71, 117, 67, 103, 42, 218, 181, 127, 76]
10+
},
11+
"should have default secp256k1 code hash when address type is not hash index": {
12+
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x04", ""],
13+
"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]
14+
},
15+
"should have default hash_type = type when full address of new version with secp256k1 code hash": {
16+
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"],
17+
"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]
18+
},
19+
"full address of new version specifies hash_type = data1": {
820
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176", "data1"],
921
"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]
1022
},
@@ -16,8 +28,8 @@
1628
"params": ["0x36c329ed630d6ce750712a477543672adab57f4c", "0x00", "0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c135"],
1729
"exception": "'0x3419a1c09eb2567f6552ee7a8ecffd64155cffe0f1796e6e61ec088d740c135' is not a valid code hash"
1830
},
19-
"should throw an error when its a full version address identifies the hash_type but hash_type is missing": {
20-
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"],
31+
"should throw an error when its a full version address but hash_type is missing while code hash is not secp256k1 code hash": {
32+
"params": ["0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64", "0x00", "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3ccee"],
2133
"exception": "hashType is required"
2234
}
2335
},

packages/ckb-sdk-utils/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nervosnetwork/ckb-sdk-utils",
3-
"version": "0.102.3",
3+
"version": "0.103.0",
44
"description": "Utils module of @nervosnetwork/ckb-sdk-core",
55
"author": "Nervos <dev@nervos.org>",
66
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
@@ -31,7 +31,7 @@
3131
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
3232
},
3333
"dependencies": {
34-
"@nervosnetwork/ckb-types": "0.102.3",
34+
"@nervosnetwork/ckb-types": "0.103.0",
3535
"bech32": "2.0.0",
3636
"elliptic": "6.5.4",
3737
"jsbi": "3.1.3",
@@ -41,5 +41,5 @@
4141
"@types/bitcoinjs-lib": "5.0.0",
4242
"@types/elliptic": "6.4.12"
4343
},
44-
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
44+
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
4545
}

packages/ckb-sdk-utils/src/address/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ export interface AddressOptions {
8989
* @see https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
9090
* @param {string | Uint8Array} args, use as the identifier of an address, usually the public key hash is used.
9191
* @param {string} type, used to indicate which format is adopted to compose the address.
92-
* @param {string} codeHashOrCodeHashIndex, the referenced code hash or code hash index the address binds to
92+
* @param {string} codeHashOrCodeHashIndex, the referenced code hash or code hash index the address binds to,
93+
* default to be secp256k1 code hash/code hash index
9394
*/
9495
export const toAddressPayload = (
9596
args: string | Uint8Array,
9697
type: AddressType = AddressType.HashIdx,
97-
codeHashOrCodeHashIndex: CodeHashIndex | CKBComponents.Hash256 = '0x00',
98+
codeHashOrCodeHashIndex?: CodeHashIndex | CKBComponents.Hash256,
9899
hashType?: CKBComponents.ScriptHashType,
99100
): Uint8Array => {
100101
if (typeof args === 'string' && !args.startsWith('0x')) {
@@ -108,6 +109,10 @@ export const toAddressPayload = (
108109
)
109110
}
110111

112+
if (!codeHashOrCodeHashIndex) {
113+
codeHashOrCodeHashIndex = type === AddressType.HashIdx ? '0x00' : SECP256K1_BLAKE160.codeHash
114+
}
115+
111116
if (type !== AddressType.FullVersion) {
112117
return new Uint8Array([
113118
...hexToBytes(type),
@@ -116,6 +121,10 @@ export const toAddressPayload = (
116121
])
117122
}
118123

124+
if (!hashType && codeHashOrCodeHashIndex === SECP256K1_BLAKE160.codeHash) {
125+
hashType = SECP256K1_BLAKE160.hashType
126+
}
127+
119128
if (!codeHashOrCodeHashIndex.startsWith('0x') || codeHashOrCodeHashIndex.length !== 66) {
120129
throw new CodeHashException(codeHashOrCodeHashIndex)
121130
}
@@ -142,7 +151,7 @@ export const toAddressPayload = (
142151
*/
143152
export const bech32Address = (
144153
args: Uint8Array | string,
145-
{ prefix = AddressPrefix.Mainnet, type = AddressType.HashIdx, codeHashOrCodeHashIndex = '0x00' }: AddressOptions = {},
154+
{ prefix = AddressPrefix.Mainnet, type = AddressType.HashIdx, codeHashOrCodeHashIndex = '' }: AddressOptions = {},
146155
) => bech32.encode(prefix, bech32.toWords(toAddressPayload(args, type, codeHashOrCodeHashIndex)), MAX_BECH32_LIMIT)
147156

148157
/**

packages/ckb-types/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.103.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.3...v0.103.0) (2022-05-09)
7+
8+
**Note:** Version bump only for package @nervosnetwork/ckb-types
9+
10+
11+
12+
13+
614
## [0.102.3](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.102.2...v0.102.3) (2022-03-24)
715

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

packages/ckb-types/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nervosnetwork/ckb-types",
3-
"version": "0.102.3",
3+
"version": "0.103.0",
44
"description": "Type module of @nervosnetwork/ckb-sdk-core",
55
"author": "Nervos <dev@nervos.org>",
66
"homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme",
@@ -20,5 +20,5 @@
2020
"bugs": {
2121
"url": "https://github.com/nervosnetwork/ckb-sdk-js/issues"
2222
},
23-
"gitHead": "82c6a77b990ccfb70a6a7f3ea1442f2d5c81f334"
23+
"gitHead": "381148346ef0243b12dfcd872ea15d9f59e07a9e"
2424
}

0 commit comments

Comments
 (0)