Export hashing functions (#1275)

The now-deprecated ripple-hashes library provided a number of hash
functions for users to compute the hashes/IDs for various XRP Ledger
objects:

* Transactions (to generate transaction hashes, also known as IDs)
* Transaction signing hashes (to sign transactions)
* Ledger Object IDs (to look up specific ledger objects in a ledger's
  state tree; see https://xrpl.org/ledger-object-ids.html)

This commit exports these utility methods from ripple-lib as static
methods. Access them on the RippleAPI class. Example:

import {RippleAPI} from 'ripple-lib'
const hash = RippleAPI.computeBinaryTransactionHash(...)
This commit is contained in:
Elliot Lee
2020-04-28 14:19:36 -07:00
committed by GitHub
parent 5d6af09508
commit 3c13da66b3
5 changed files with 122 additions and 20 deletions

View File

@@ -47,7 +47,7 @@ describe('Ledger', function() {
var account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
var expectedEntryHash =
'2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8'
var actualEntryHash = hashes.computeAccountHash(account)
var actualEntryHash = hashes.computeAccountLedgerObjectID(account)
assert.equal(actualEntryHash, expectedEntryHash)
})
@@ -105,18 +105,18 @@ describe('Ledger', function() {
var sequence = 137
var expectedEntryHash =
'03F0AED09DEEE74CEF85CD57A0429D6113507CF759C597BABB4ADB752F734CE3'
var actualEntryHash = hashes.computeOrderHash(account, sequence)
var actualEntryHash = hashes.computeOrderID(account, sequence)
assert.equal(actualEntryHash, expectedEntryHash)
})
})
describe('computeSignerListHash', function() {
describe('computeSignerListLedgerObjectID', function() {
it('will calculate the SignerList index for r32UufnaCGL82HubijgJGDmdE5hac7ZvLw', function() {
var account = 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh'
var expectedEntryHash =
'778365D5180F5DF3016817D1F318527AD7410D83F8636CF48C43E8AF72AB49BF'
var actualEntryHash = hashes.computeSignerListHash(account)
var actualEntryHash = hashes.computeSignerListLedgerObjectID(account)
assert.equal(actualEntryHash, expectedEntryHash)
})
})