feat: allow verifyTransaction to verify transaction objects, not just strings (#2119)

* support Transaction objects in verifyTransaction method

* add test

* edit history
This commit is contained in:
Mayukha Vadari
2022-11-16 12:48:59 -05:00
committed by GitHub
parent 08180cb935
commit 49d40216d5
3 changed files with 20 additions and 3 deletions

View File

@@ -4,6 +4,10 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr
## Unreleased
### Added
* Optional custom amount field to `fundWallet`.
### Changed
* Add support for Transaction objects in `verifyTransaction`
## 2.5.0 (2022-10-13)
### Added
* Support for ExpandedSignerList amendment that expands the maximum signer list to 32 entries.

View File

@@ -375,8 +375,11 @@ class Wallet {
* @param signedTransaction - A signed transaction (hex string of signTransaction result) to be verified offline.
* @returns Returns true if a signedTransaction is valid.
*/
public verifyTransaction(signedTransaction: string): boolean {
const tx = decode(signedTransaction)
public verifyTransaction(signedTransaction: Transaction | string): boolean {
const tx =
typeof signedTransaction === 'string'
? decode(signedTransaction)
: signedTransaction
const messageHex: string = encodeForSigning(tx)
const signature = tx.TxnSignature
return verify(messageHex, signature, this.publicKey)

View File

@@ -1,5 +1,5 @@
import { assert } from 'chai'
import { decode } from 'ripple-binary-codec/dist'
import { decode } from 'ripple-binary-codec'
import { NFTokenMint, Payment, Transaction } from 'xrpl-local'
import ECDSA from 'xrpl-local/ECDSA'
import Wallet from 'xrpl-local/Wallet'
@@ -949,6 +949,16 @@ describe('Wallet', function () {
assert.equal(isVerified, false)
})
it('returns true when verifying a deserialized Transaction object', function () {
const wallet = new Wallet(publicKey, privateKey)
const decodedTransaction = decode(
prepared.signedTransaction,
) as unknown as Transaction
const isVerified: boolean = wallet.verifyTransaction(decodedTransaction)
assert.equal(isVerified, true)
})
})
describe('getXAddress', function () {