mirror of
				https://github.com/Xahau/xahau.js.git
				synced 2025-11-04 04:55:48 +00:00 
			
		
		
		
	fix: add support for pseudo-transactions to hashSignedTx (#2588)
				
					
				
			* add support for pseudo-transactions to hashSignedTx * update changelog * fix tests * fix linter + tests
This commit is contained in:
		
				
					committed by
					
						
						Caleb Kniffen
					
				
			
			
				
	
			
			
			
						parent
						
							9cdb60e26a
						
					
				
				
					commit
					eefb52a9cb
				
			@@ -56,6 +56,7 @@ Bundler configurations are much more simplified. See [../UNIQUE_STEPS](Unique St
 | 
			
		||||
### Fixed
 | 
			
		||||
* Fixed Wallet.generate() ignoring the `algorithm` parameter (Only a problem once binary-codec fix for `derive_keypair` is added)
 | 
			
		||||
* Fixed Wallet.fromSeed() ignoring the `algorithm` parameter
 | 
			
		||||
* Added pseudo-transaction support to hash functions and response types
 | 
			
		||||
 | 
			
		||||
## 2.14.1 (2024-02-01)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -83,7 +83,11 @@ export function hashSignedTx(tx: Transaction | string): string {
 | 
			
		||||
    txObject = tx
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (txObject.TxnSignature === undefined && txObject.Signers === undefined) {
 | 
			
		||||
  if (
 | 
			
		||||
    txObject.TxnSignature === undefined &&
 | 
			
		||||
    txObject.Signers === undefined &&
 | 
			
		||||
    txObject.SigningPubKey === undefined
 | 
			
		||||
  ) {
 | 
			
		||||
    throw new ValidationError('The transaction must be signed to hash it.')
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,12 @@ import path from 'path'
 | 
			
		||||
import { assert } from 'chai'
 | 
			
		||||
import { encode } from 'ripple-binary-codec'
 | 
			
		||||
 | 
			
		||||
import { OfferCreate, Transaction, ValidationError } from '../../src'
 | 
			
		||||
import {
 | 
			
		||||
  EnableAmendment,
 | 
			
		||||
  OfferCreate,
 | 
			
		||||
  Transaction,
 | 
			
		||||
  ValidationError,
 | 
			
		||||
} from '../../src'
 | 
			
		||||
import {
 | 
			
		||||
  hashStateTree,
 | 
			
		||||
  hashTxTree,
 | 
			
		||||
@@ -166,6 +171,7 @@ describe('Hashes', function () {
 | 
			
		||||
  it('Throw an error when hashing an unsigned transaction', function () {
 | 
			
		||||
    const offerCreateWithNoSignature: OfferCreate = {
 | 
			
		||||
      ...(fixtures.tx.OfferCreateSell.result as OfferCreate),
 | 
			
		||||
      SigningPubKey: undefined,
 | 
			
		||||
      TxnSignature: undefined,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -178,6 +184,7 @@ describe('Hashes', function () {
 | 
			
		||||
  it('Throw when hashing an unsigned transaction blob', function () {
 | 
			
		||||
    const encodedOfferCreateWithNoSignature: string = encode({
 | 
			
		||||
      ...fixtures.tx.OfferCreateSell.result,
 | 
			
		||||
      SigningPubKey: undefined,
 | 
			
		||||
      TxnSignature: undefined,
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
@@ -186,4 +193,22 @@ describe('Hashes', function () {
 | 
			
		||||
      ValidationError,
 | 
			
		||||
    )
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  it('hashSignedTx - pseudo-transaction', function () {
 | 
			
		||||
    const transaction: EnableAmendment = {
 | 
			
		||||
      Account: 'rrrrrrrrrrrrrrrrrrrrrhoLvTp',
 | 
			
		||||
      Amendment:
 | 
			
		||||
        'AE35ABDEFBDE520372B31C957020B34A7A4A9DC3115A69803A44016477C84D6E',
 | 
			
		||||
      Fee: '0',
 | 
			
		||||
      LedgerSequence: 84206081,
 | 
			
		||||
      Sequence: 0,
 | 
			
		||||
      SigningPubKey: '',
 | 
			
		||||
      TransactionType: 'EnableAmendment',
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    assert.equal(
 | 
			
		||||
      hashSignedTx(transaction),
 | 
			
		||||
      'CA4562711E4679FE9317DD767871E90A404C7A8B84FAFD35EC2CF0231F1F6DAF',
 | 
			
		||||
    )
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user