Skip to content

Commit

Permalink
fix: fix data2 validation in 'isPayloadValid' method (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Nov 15, 2024
1 parent 7214286 commit 8b7dcb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/ckb-sdk-utils/__tests__/address/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@
"hashType": "data1",
"args": "0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64"
}
},
"full version address identifies hash_type = data2": {
"params": ["ckt1qzn9dutjk669cfznq7httfar0gtk7qp0du3wjfvzck9l0w3k9eqhvp9nnw7qkdnnclfkg59uzn8umtfd2kwxceqskl3c2"],
"expected": {
"codeHash": "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176",
"hashType": "data2",
"args": "0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64"
}
}
},
"scriptToAddress": {
Expand Down Expand Up @@ -302,6 +310,17 @@
],
"expected": "ckt1qzn9dutjk669cfznq7httfar0gtk7qp0du3wjfvzck9l0w3k9eqhvq4nnw7qkdnnclfkg59uzn8umtfd2kwxceq225jvu"
},
"full version testnet address identifies hash_type = data2": {
"params": [
{
"codeHash": "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176",
"hashType": "data2",
"args": "0xb39bbc0b3673c7d36450bc14cfcdad2d559c6c64"
},
false
],
"expected": "ckt1qzn9dutjk669cfznq7httfar0gtk7qp0du3wjfvzck9l0w3k9eqhvp9nnw7qkdnnclfkg59uzn8umtfd2kwxceqskl3c2"
},
"should throw an error when args doesn't start with 0x": {
"params": [
{
Expand Down
7 changes: 6 additions & 1 deletion packages/ckb-sdk-utils/src/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ const isPayloadValid = (payload: Uint8Array, bech32Type: Bech32Type) => {
}

const hashType = parseInt(data[32].toString(), 16)
if (hashType > 2) {

if (
!Object.values(AddressType)
.map(i => +i)
.includes(hashType)
) {
throw new HashTypeException(`0x${hashType.toString(16)}`)
}

Expand Down

0 comments on commit 8b7dcb6

Please sign in to comment.