diff --git a/packages/ripple-binary-codec/HISTORY.md b/packages/ripple-binary-codec/HISTORY.md index e63f5e7c..de145a41 100644 --- a/packages/ripple-binary-codec/HISTORY.md +++ b/packages/ripple-binary-codec/HISTORY.md @@ -1,5 +1,8 @@ # ripple-binary-codec Release History +## Unreleased +- Added a clearer error message for trying to encode an invalid transaction. (Ex. With an incorrect TransactionType) + ## 1.4.0 (2022-04-18) - Updated NFT definitions to match 1.9.0's breaking naming changes diff --git a/packages/ripple-binary-codec/src/types/st-object.ts b/packages/ripple-binary-codec/src/types/st-object.ts index eeb261f1..519dda52 100644 --- a/packages/ripple-binary-codec/src/types/st-object.ts +++ b/packages/ripple-binary-codec/src/types/st-object.ts @@ -127,6 +127,15 @@ class STObject extends SerializedType { const associatedValue = field.associatedType.from( xAddressDecoded[field.name], ) + + if (associatedValue == undefined) { + throw new TypeError( + `Unable to interpret "${field.name}: ${ + xAddressDecoded[field.name] + }".`, + ) + } + if ((associatedValue as unknown as Bytes).name === 'UNLModify') { // triggered when the TransactionType field has a value of 'UNLModify' isUnlModify = true diff --git a/packages/ripple-binary-codec/test/signing-data-encoding.test.js b/packages/ripple-binary-codec/test/signing-data-encoding.test.js index ed260653..eb4cedc8 100644 --- a/packages/ripple-binary-codec/test/signing-data-encoding.test.js +++ b/packages/ripple-binary-codec/test/signing-data-encoding.test.js @@ -1,3 +1,4 @@ +const { throws } = require('assert') const { encodeForSigning, encodeForSigningClaim, @@ -65,6 +66,16 @@ describe('Signing data', function () { ].join(''), ) }) + + test('can fail gracefully for invalid TransactionType', function () { + const invalidTransactionType = { + ...tx_json, + TransactionType: 'NotAPayment', + } + + throws(() => encodeForSigning(invalidTransactionType), /NotAPayment/u) + }) + test('can create multi signing blobs', function () { const signingAccount = 'rJZdUusLDtY9NEsGea7ijqhVrXv98rYBYN' const signingJson = Object.assign({}, tx_json, { SigningPubKey: '' })