mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user