Compare commits

..

2 Commits

Author SHA1 Message Date
tequ
6edc5a4a83 4.1.1 (#72) 2026-07-03 15:54:12 +09:00
tequ
919315ef69 Fix length validation error on HookName deletion (#71) 2026-07-03 14:50:05 +09:00
6 changed files with 70 additions and 4 deletions

2
package-lock.json generated
View File

@@ -16048,7 +16048,7 @@
}
},
"packages/xahau": {
"version": "4.1.0",
"version": "4.1.1",
"license": "ISC",
"dependencies": {
"@scure/bip32": "^1.3.1",

View File

@@ -2,6 +2,11 @@
## Unreleased Changes
### 4.1.1 (2026-07-03)
### Fixed
* Fix HookName validation on HookName deletion
## 4.1.0 (2026-06-23)
### Added

View File

@@ -1,6 +1,6 @@
{
"name": "xahau",
"version": "4.1.0",
"version": "4.1.1",
"license": "ISC",
"description": "A TypeScript/JavaScript API for interacting with the Xahau Network in Node.js and the browser",
"files": [

View File

@@ -79,7 +79,11 @@ export function validateSetHook(tx: Record<string, unknown>): void {
`SetHook: HookNamespace in Hook must be a 256-bit (32-byte) hexadecimal value`,
)
}
if (HookName !== undefined && !HOOKNAME_REGEX.test(HookName)) {
if (
HookName !== undefined &&
HookName.length !== 0 &&
!HOOKNAME_REGEX.test(HookName)
) {
throw new ValidationError(
`SetHook: HookName in Hook must be a hex string of 8-32 hex characters`,
)

View File

@@ -135,4 +135,49 @@ describe('SetHook', function () {
},
TIMEOUT,
)
it('hook name update', async () => {
let setHookTx: SetHook = {
TransactionType: 'SetHook',
Account: wallet.classicAddress,
Hooks: [
{
Hook: {
CreateCode: acceptHook,
HookApiVersion: 0,
HookName: '484F4F4B',
HookOn: '00'.repeat(32),
HookNamespace: '00'.repeat(32),
},
},
],
}
await testTransaction(testContext.client, setHookTx, wallet)
{
const ledgerEntryResponse = await testContext.client.request({
command: 'ledger_entry',
hook: { account: wallet.classicAddress },
})
const node = ledgerEntryResponse.result.node as Hook
const hook = node.Hooks[0].Hook
expect(hook.HookName).toEqual('484F4F4B')
}
// delete HookName
setHookTx = {
TransactionType: 'SetHook',
Account: wallet.classicAddress,
Hooks: [{ Hook: { HookName: '' } }],
}
await testTransaction(testContext.client, setHookTx, wallet)
{
const ledgerEntryResponse = await testContext.client.request({
command: 'ledger_entry',
hook: { account: wallet.classicAddress },
})
const node = ledgerEntryResponse.result.node as Hook
const hook = node.Hooks[0].Hook
expect(hook.HookName).toBeUndefined()
}
})
})

View File

@@ -175,7 +175,7 @@ describe('SetHook', function () {
assert.throws(() => validate(setHookTx), ValidationError, errorMessage)
})
it.each(['', '0'.repeat(7), '0'.repeat(33), 'ZZZZZZZZ'])(
it.each(['00', '0000', '000000', '0'.repeat(7), '0'.repeat(33), 'ZZZZZZZZ'])(
`throws w/ invalid HookName in Hooks: %s`,
function (value: string) {
setHookTx.Hooks = [
@@ -195,4 +195,16 @@ describe('SetHook', function () {
assert.throws(() => validate(setHookTx), ValidationError, errorMessage)
},
)
it(`valid HookName "" (deletion) in Hooks`, function () {
setHookTx.Hooks = [
{
Hook: {
HookName: '',
},
},
]
assert.doesNotThrow(() => validateSetHook(setHookTx))
assert.doesNotThrow(() => validate(setHookTx))
})
})