Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/xrpl/src/utils/hashes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Compute the hash of a ledger.

Compute the hash of an escrow, given the owner's classic address (starting with `r`) and the account sequence number of the `EscrowCreate` escrow transaction.

### hashOracle = (address, documentId): string

Compute the hash of an oracle, given the owner's classic address (starting with `r`) and the OracleDocumentID of the `OracleSet` transaction.

### hashPaymentChannel = (address, dstAddress, sequence): string

Compute the hash of a payment channel, given the owner's classic address (starting with `r`), the classic address of the destination, and the account sequence number of the `PaymentChannelCreate` payment channel transaction.
16 changes: 16 additions & 0 deletions packages/xrpl/src/utils/hashes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ export function hashEscrow(address: string, sequence: number): string {
)
}

/**
* Compute the Hash of an Oracle LedgerEntry.
*
* @param address - Address of the owner of the Oracle.
* @param documentId - OracleDocumentID of the Oracle.
* @returns The hash of the Oracle LedgerEntry.
* @category Utilities
*/
export function hashOracle(address: string, documentId: number): string {
return sha512Half(
ledgerSpaceHex('oracle') +
addressToHex(address) +
documentId.toString(HEX).padStart(BYTE_LENGTH * 2, '0'),
)
}

/**
* Compute the hash of a Payment Channel.
*
Expand Down
1 change: 1 addition & 0 deletions packages/xrpl/src/utils/hashes/ledgerSpaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ledgerSpaces = {
offer: 'o',
// Directory of things owned by an account.
ownerDir: 'O',
oracle: 'R',
// Directory of order books.
bookDir: 'B',
contract: 'c',
Expand Down
2 changes: 2 additions & 0 deletions packages/xrpl/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
hashLedger,
hashLedgerHeader,
hashEscrow,
hashOracle,
hashPaymentChannel,
} from './hashes'
import parseNFTokenID from './parseNFTokenID'
Expand Down Expand Up @@ -178,6 +179,7 @@ const hashes = {
hashLedger,
hashLedgerHeader,
hashEscrow,
hashOracle,
hashPaymentChannel,
}

Expand Down
11 changes: 11 additions & 0 deletions packages/xrpl/test/utils/hashes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
hashTxTree,
hashTrustline,
hashEscrow,
hashOracle,
hashPaymentChannel,
hashSignedTx,
hashAccountRoot,
Expand Down Expand Up @@ -138,6 +139,16 @@ describe('Hashes', function () {
assert.equal(actualEntryHash, expectedEntryHash)
})

it('calcOracleEntryHash', function () {
const account = 'rsNvoAZ9MquZSRhu4cEY9wTv1VqHXpVPPt'
const documentId = 1
const expectedEntryHash =
'D463D13ACF77206306BE891DF410655213FBD2C1F2B58A492E7F556A41A44338'
const actualEntryHash = hashOracle(account, documentId)

assert.equal(actualEntryHash, expectedEntryHash)
})

it('calcPaymentChannelEntryHash', function () {
const account = 'rDx69ebzbowuqztksVDmZXjizTd12BVr4x'
const dstAccount = 'rLFtVprxUEfsH54eCWKsZrEQzMDsx1wqso'
Expand Down