mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-04 13:05:49 +00:00
add Memos hex value check in Wallet.sign (#2108)
This commit is contained in:
@@ -4,7 +4,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
|
||||
## Unreleased
|
||||
### Added
|
||||
* Support for ExpandedSignerList amendment that expands the maximum signer list to 32 entries.
|
||||
|
||||
* Addtional check for memos field format, provide more detailed error messages.
|
||||
## 2.4.0 (2022-09-01)
|
||||
### Added
|
||||
* Export `verify` from ripple-keypairs as `verifyKeypairSignature` for use in web-apps.
|
||||
|
||||
@@ -439,14 +439,23 @@ class Wallet {
|
||||
txCopy.Memos?.map((memo) => {
|
||||
const memoCopy = { ...memo }
|
||||
if (memo.Memo.MemoData) {
|
||||
if (!isHex(memo.Memo.MemoData)) {
|
||||
throw new ValidationError('MemoData field must be a hex value')
|
||||
}
|
||||
memoCopy.Memo.MemoData = memo.Memo.MemoData.toUpperCase()
|
||||
}
|
||||
|
||||
if (memo.Memo.MemoType) {
|
||||
if (!isHex(memo.Memo.MemoType)) {
|
||||
throw new ValidationError('MemoType field must be a hex value')
|
||||
}
|
||||
memoCopy.Memo.MemoType = memo.Memo.MemoType.toUpperCase()
|
||||
}
|
||||
|
||||
if (memo.Memo.MemoFormat) {
|
||||
if (!isHex(memo.Memo.MemoFormat)) {
|
||||
throw new ValidationError('MemoFormat field must be a hex value')
|
||||
}
|
||||
memoCopy.Memo.MemoFormat = memo.Memo.MemoFormat.toUpperCase()
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +385,83 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('sign throws when MemoType is not a hex value', async function () {
|
||||
const secret = 'shd2nxpFD6iBRKWsRss2P4tKMWyy9'
|
||||
const lowercaseMemoTx: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Flags: 2147483648,
|
||||
Account: 'rwiZ3q3D3QuG4Ga2HyGdq3kPKJRGctVG8a',
|
||||
Amount: '10000000',
|
||||
LastLedgerSequence: 14000999,
|
||||
Destination: 'rUeEBYXHo8vF86Rqir3zWGRQ84W9efdAQd',
|
||||
Fee: '12',
|
||||
Sequence: 12,
|
||||
SourceTag: 8888,
|
||||
DestinationTag: 9999,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoType: 'not hex value',
|
||||
MemoData: '72656e74',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
assert.throws(() => {
|
||||
Wallet.fromSeed(secret).sign(lowercaseMemoTx)
|
||||
}, /MemoType field must be a hex value/u)
|
||||
})
|
||||
it('sign throws when MemoData is not a hex value', async function () {
|
||||
const secret = 'shd2nxpFD6iBRKWsRss2P4tKMWyy9'
|
||||
const lowercaseMemoTx: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Flags: 2147483648,
|
||||
Account: 'rwiZ3q3D3QuG4Ga2HyGdq3kPKJRGctVG8a',
|
||||
Amount: '10000000',
|
||||
LastLedgerSequence: 14000999,
|
||||
Destination: 'rUeEBYXHo8vF86Rqir3zWGRQ84W9efdAQd',
|
||||
Fee: '12',
|
||||
Sequence: 12,
|
||||
SourceTag: 8888,
|
||||
DestinationTag: 9999,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoData: 'not hex value',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
assert.throws(() => {
|
||||
Wallet.fromSeed(secret).sign(lowercaseMemoTx)
|
||||
}, /MemoData field must be a hex value/u)
|
||||
})
|
||||
it('sign throws when MemoFormat is not a hex value', async function () {
|
||||
const secret = 'shd2nxpFD6iBRKWsRss2P4tKMWyy9'
|
||||
const lowercaseMemoTx: Transaction = {
|
||||
TransactionType: 'Payment',
|
||||
Flags: 2147483648,
|
||||
Account: 'rwiZ3q3D3QuG4Ga2HyGdq3kPKJRGctVG8a',
|
||||
Amount: '10000000',
|
||||
LastLedgerSequence: 14000999,
|
||||
Destination: 'rUeEBYXHo8vF86Rqir3zWGRQ84W9efdAQd',
|
||||
Fee: '12',
|
||||
Sequence: 12,
|
||||
SourceTag: 8888,
|
||||
DestinationTag: 9999,
|
||||
Memos: [
|
||||
{
|
||||
Memo: {
|
||||
MemoFormat: 'not hex value',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
assert.throws(() => {
|
||||
Wallet.fromSeed(secret).sign(lowercaseMemoTx)
|
||||
}, /MemoFormat field must be a hex value/u)
|
||||
})
|
||||
|
||||
it('sign with EscrowFinish', async function () {
|
||||
const result = wallet.sign(REQUEST_FIXTURES.escrow as Transaction)
|
||||
assert.deepEqual(result, {
|
||||
|
||||
Reference in New Issue
Block a user