add WalletLocator validation

This commit is contained in:
Omar Khan
2022-06-15 18:45:20 -04:00
parent 1571e30653
commit 993d155cf3
3 changed files with 78 additions and 25 deletions

View File

@@ -28,6 +28,8 @@ export interface SignerListSet extends BaseTransaction {
const MAX_SIGNERS = 32
const HEX_WALLET_LOCATOR_REGEX = /^[0-9A-Fa-f]{64}$/u
/**
* Verify the form and type of an SignerListSet at runtime.
*
@@ -64,4 +66,18 @@ export function validateSignerListSet(tx: Record<string, unknown>): void {
`SignerListSet: maximum of ${MAX_SIGNERS} members allowed in SignerEntries`,
)
}
if (tx.SignerEntries.length > 0) {
for (const entry of tx.SignerEntries) {
const signerEntry = entry.SignerEntry
if (
signerEntry.WalletLocator !== undefined &&
!HEX_WALLET_LOCATOR_REGEX.test(signerEntry.WalletLocator)
) {
throw new ValidationError(
`SignerListSet: WalletLocator in SignerEntry must be a 256-bit (32-byte) hexadecimal value`,
)
}
}
}
}

View File

@@ -36,29 +36,4 @@ describe('SignerListSet', function () {
}
await testTransaction(this.client, tx, this.wallet)
})
it('sign with WalletLocator', async function () {
const tx: SignerListSet = {
TransactionType: 'SignerListSet',
Account: this.wallet.classicAddress,
SignerEntries: [
{
SignerEntry: {
Account: 'r5nx8ZkwEbFztnc8Qyi22DE9JYjRzNmvs',
SignerWeight: 1,
WalletLocator:
'CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE',
},
},
{
SignerEntry: {
Account: 'r3RtUvGw9nMoJ5FuHxuoVJvcENhKtuF9ud',
SignerWeight: 1,
},
},
],
SignerQuorum: 2,
}
await testTransaction(this.client, tx, this.wallet)
})
})

View File

@@ -150,4 +150,66 @@ describe('SignerListSet', function () {
errorMessage,
)
})
it(`verifies valid WalletLocator in SignerEntries`, function () {
signerListSetTx.SignerQuorum = 3
signerListSetTx.SignerEntries = [
{
SignerEntry: {
Account: 'rBFBipte4nAQCTsRxd2czwvSurhCpAf4X6',
SignerWeight: 1,
WalletLocator:
'CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE',
},
},
{
SignerEntry: {
Account: 'r3ijUH32iiy9tYNj3rD7hKWYjy1BFUxngm',
SignerWeight: 1,
},
},
{
SignerEntry: {
Account: 'rpwq8vi4Mn3L5kDJmb8Mg59CanPFPzMCnj',
SignerWeight: 1,
WalletLocator:
'00000000000000000000000000000000000000000000000000000000DEADBEEF',
},
},
]
assert.doesNotThrow(() => validateSignerListSet(signerListSetTx))
assert.doesNotThrow(() => validate(signerListSetTx))
})
it(`throws w/ invalid WalletLocator in SignerEntries`, function () {
signerListSetTx.SignerQuorum = 2
signerListSetTx.SignerEntries = [
{
SignerEntry: {
Account: 'rBFBipte4nAQCTsRxd2czwvSurhCpAf4X6',
SignerWeight: 1,
WalletLocator: 'not_valid',
},
},
{
SignerEntry: {
Account: 'r3ijUH32iiy9tYNj3rD7hKWYjy1BFUxngm',
SignerWeight: 1,
},
},
]
const errorMessage =
'SignerListSet: WalletLocator in SignerEntry must be a 256-bit (32-byte) hexadecimal value'
assert.throws(
() => validateSignerListSet(signerListSetTx),
ValidationError,
errorMessage,
)
assert.throws(
() => validate(signerListSetTx),
ValidationError,
errorMessage,
)
})
})