xrpl 2.10.0 → 2.12.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +1308 -33
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/client/index.d.ts +2 -1
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/index.d.ts +1 -0
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +3 -1
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +11 -0
- package/dist/npm/models/common/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/models/ledger/AMM.js +3 -0
- package/dist/npm/models/ledger/AMM.js.map +1 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts +2 -0
- package/dist/npm/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +1 -0
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/Bridge.d.ts +17 -0
- package/dist/npm/models/ledger/Bridge.d.ts.map +1 -0
- package/dist/npm/models/ledger/Bridge.js +3 -0
- package/dist/npm/models/ledger/Bridge.js.map +1 -0
- package/dist/npm/models/ledger/LedgerEntry.d.ts +5 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts +16 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.js +3 -0
- package/dist/npm/models/ledger/XChainOwnedClaimID.js.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
- package/dist/npm/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
- package/dist/npm/models/ledger/index.d.ts +4 -1
- package/dist/npm/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.js.map +1 -1
- package/dist/npm/models/methods/accountObjects.d.ts +3 -3
- package/dist/npm/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/models/methods/ammInfo.js +3 -0
- package/dist/npm/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/models/methods/index.d.ts +4 -3
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +27 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMBid.js +56 -0
- package/dist/npm/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMVote.js +32 -0
- package/dist/npm/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js +35 -0
- package/dist/npm/models/transactions/XChainAccountCreateCommit.js.map +1 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
- package/dist/npm/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js +68 -0
- package/dist/npm/models/transactions/XChainAddClaimAttestation.js.map +1 -0
- package/dist/npm/models/transactions/XChainClaim.d.ts +12 -0
- package/dist/npm/models/transactions/XChainClaim.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainClaim.js +39 -0
- package/dist/npm/models/transactions/XChainClaim.js.map +1 -0
- package/dist/npm/models/transactions/XChainCommit.d.ts +11 -0
- package/dist/npm/models/transactions/XChainCommit.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCommit.js +33 -0
- package/dist/npm/models/transactions/XChainCommit.js.map +1 -0
- package/dist/npm/models/transactions/XChainCreateBridge.d.ts +10 -0
- package/dist/npm/models/transactions/XChainCreateBridge.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCreateBridge.js +26 -0
- package/dist/npm/models/transactions/XChainCreateBridge.js.map +1 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts +10 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.js +28 -0
- package/dist/npm/models/transactions/XChainCreateClaimID.js.map +1 -0
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts +17 -0
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts.map +1 -0
- package/dist/npm/models/transactions/XChainModifyBridge.js +27 -0
- package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -0
- package/dist/npm/models/transactions/common.d.ts +3 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +22 -1
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +15 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +7 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +15 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +56 -0
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +18 -21
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/snippets/src/bridgeTransfer.d.ts +2 -0
- package/dist/npm/snippets/src/bridgeTransfer.d.ts.map +1 -0
- package/dist/npm/snippets/src/bridgeTransfer.js +124 -0
- package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -0
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts +7 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.d.ts.map +1 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +27 -0
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -0
- package/dist/npm/src/client/index.d.ts +2 -1
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -0
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +3 -1
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +11 -0
- package/dist/npm/src/models/common/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AMM.d.ts +27 -0
- package/dist/npm/src/models/ledger/AMM.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/AMM.js +3 -0
- package/dist/npm/src/models/ledger/AMM.js.map +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts +2 -0
- package/dist/npm/src/models/ledger/AccountRoot.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +1 -0
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/Bridge.d.ts +17 -0
- package/dist/npm/src/models/ledger/Bridge.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/Bridge.js +3 -0
- package/dist/npm/src/models/ledger/Bridge.js.map +1 -0
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts +5 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts +16 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.js +3 -0
- package/dist/npm/src/models/ledger/XChainOwnedClaimID.js.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts +14 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js +3 -0
- package/dist/npm/src/models/ledger/XChainOwnedCreateAccountClaimID.js.map +1 -0
- package/dist/npm/src/models/ledger/index.d.ts +4 -1
- package/dist/npm/src/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.js.map +1 -1
- package/dist/npm/src/models/methods/accountObjects.d.ts +3 -3
- package/dist/npm/src/models/methods/accountObjects.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ammInfo.d.ts +39 -0
- package/dist/npm/src/models/methods/ammInfo.d.ts.map +1 -0
- package/dist/npm/src/models/methods/ammInfo.js +3 -0
- package/dist/npm/src/models/methods/ammInfo.js.map +1 -0
- package/dist/npm/src/models/methods/index.d.ts +4 -3
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +27 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMBid.d.ts +12 -0
- package/dist/npm/src/models/transactions/AMMBid.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMBid.js +56 -0
- package/dist/npm/src/models/transactions/AMMBid.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts +11 -0
- package/dist/npm/src/models/transactions/AMMCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMCreate.js +32 -0
- package/dist/npm/src/models/transactions/AMMCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts +9 -0
- package/dist/npm/src/models/transactions/AMMDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDelete.js +22 -0
- package/dist/npm/src/models/transactions/AMMDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts +27 -0
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js +51 -0
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts +10 -0
- package/dist/npm/src/models/transactions/AMMVote.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMVote.js +32 -0
- package/dist/npm/src/models/transactions/AMMVote.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +31 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js +50 -0
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts +11 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js +35 -0
- package/dist/npm/src/models/transactions/XChainAccountCreateCommit.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts +18 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js +77 -0
- package/dist/npm/src/models/transactions/XChainAddAccountCreateAttestation.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts +17 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js +68 -0
- package/dist/npm/src/models/transactions/XChainAddClaimAttestation.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainClaim.d.ts +12 -0
- package/dist/npm/src/models/transactions/XChainClaim.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainClaim.js +39 -0
- package/dist/npm/src/models/transactions/XChainClaim.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCommit.d.ts +11 -0
- package/dist/npm/src/models/transactions/XChainCommit.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCommit.js +33 -0
- package/dist/npm/src/models/transactions/XChainCommit.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts +10 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.js +26 -0
- package/dist/npm/src/models/transactions/XChainCreateBridge.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts +10 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js +28 -0
- package/dist/npm/src/models/transactions/XChainCreateClaimID.js.map +1 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts +17 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.js +27 -0
- package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -0
- package/dist/npm/src/models/transactions/common.d.ts +3 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +22 -1
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +15 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +7 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +15 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +56 -0
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +18 -21
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +4 -3
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +4 -3
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/package.json +8 -6
- package/src/ECDSA.ts +6 -0
- package/src/Wallet/defaultFaucets.ts +82 -0
- package/src/Wallet/fundWallet.ts +344 -0
- package/src/Wallet/index.ts +504 -0
- package/src/Wallet/rfc1751.ts +190 -0
- package/src/Wallet/rfc1751Words.json +243 -0
- package/src/Wallet/signer.ts +173 -0
- package/src/Wallet/walletFromSecretNumbers.ts +37 -0
- package/src/client/BroadcastClient.ts +84 -0
- package/src/client/ConnectionManager.ts +40 -0
- package/src/client/ExponentialBackoff.ts +71 -0
- package/src/client/RequestManager.ts +194 -0
- package/src/client/WSWrapper.ts +106 -0
- package/src/client/connection.ts +593 -0
- package/src/client/index.ts +712 -0
- package/src/client/partialPayment.ts +153 -0
- package/src/errors.ts +161 -0
- package/src/index.ts +20 -0
- package/src/models/common/index.ts +156 -0
- package/src/models/index.ts +16 -0
- package/src/models/ledger/AMM.ts +78 -0
- package/src/models/ledger/AccountRoot.ts +217 -0
- package/src/models/ledger/Amendments.ts +45 -0
- package/src/models/ledger/BaseLedgerEntry.ts +3 -0
- package/src/models/ledger/Bridge.ts +84 -0
- package/src/models/ledger/Check.ts +70 -0
- package/src/models/ledger/DepositPreauth.ts +35 -0
- package/src/models/ledger/DirectoryNode.ts +46 -0
- package/src/models/ledger/Escrow.ts +74 -0
- package/src/models/ledger/FeeSettings.ts +52 -0
- package/src/models/ledger/Ledger.ts +65 -0
- package/src/models/ledger/LedgerEntry.ts +40 -0
- package/src/models/ledger/LedgerHashes.ts +24 -0
- package/src/models/ledger/NFTokenOffer.ts +16 -0
- package/src/models/ledger/NFTokenPage.ts +20 -0
- package/src/models/ledger/NegativeUNL.ts +34 -0
- package/src/models/ledger/Offer.ts +52 -0
- package/src/models/ledger/PayChannel.ts +107 -0
- package/src/models/ledger/RippleState.ts +88 -0
- package/src/models/ledger/SignerList.ts +56 -0
- package/src/models/ledger/Ticket.ts +36 -0
- package/src/models/ledger/XChainOwnedClaimID.ts +73 -0
- package/src/models/ledger/XChainOwnedCreateAccountClaimID.ts +60 -0
- package/src/models/ledger/index.ts +64 -0
- package/src/models/methods/accountChannels.ts +93 -0
- package/src/models/methods/accountCurrencies.ts +45 -0
- package/src/models/methods/accountInfo.ts +182 -0
- package/src/models/methods/accountLines.ts +137 -0
- package/src/models/methods/accountNFTs.ts +72 -0
- package/src/models/methods/accountObjects.ts +129 -0
- package/src/models/methods/accountOffers.ts +100 -0
- package/src/models/methods/accountTx.ts +109 -0
- package/src/models/methods/ammInfo.ts +145 -0
- package/src/models/methods/baseMethod.ts +58 -0
- package/src/models/methods/bookOffers.ts +96 -0
- package/src/models/methods/channelVerify.ts +41 -0
- package/src/models/methods/depositAuthorized.ts +56 -0
- package/src/models/methods/fee.ts +91 -0
- package/src/models/methods/gatewayBalances.ts +85 -0
- package/src/models/methods/index.ts +391 -0
- package/src/models/methods/ledger.ts +125 -0
- package/src/models/methods/ledgerClosed.ts +32 -0
- package/src/models/methods/ledgerCurrent.ts +31 -0
- package/src/models/methods/ledgerData.ts +78 -0
- package/src/models/methods/ledgerEntry.ts +202 -0
- package/src/models/methods/manifest.ts +54 -0
- package/src/models/methods/nftBuyOffers.ts +37 -0
- package/src/models/methods/nftHistory.ts +113 -0
- package/src/models/methods/nftInfo.ts +25 -0
- package/src/models/methods/nftSellOffers.ts +37 -0
- package/src/models/methods/norippleCheck.ts +82 -0
- package/src/models/methods/pathFind.ts +116 -0
- package/src/models/methods/ping.ts +21 -0
- package/src/models/methods/random.ts +23 -0
- package/src/models/methods/ripplePathFind.ts +81 -0
- package/src/models/methods/serverInfo.ts +257 -0
- package/src/models/methods/serverState.ts +77 -0
- package/src/models/methods/submit.ts +94 -0
- package/src/models/methods/submitMultisigned.ts +51 -0
- package/src/models/methods/subscribe.ts +435 -0
- package/src/models/methods/transactionEntry.ts +47 -0
- package/src/models/methods/tx.ts +69 -0
- package/src/models/methods/unsubscribe.ts +49 -0
- package/src/models/transactions/AMMBid.ts +140 -0
- package/src/models/transactions/AMMCreate.ts +80 -0
- package/src/models/transactions/AMMDelete.ts +55 -0
- package/src/models/transactions/AMMDeposit.ts +130 -0
- package/src/models/transactions/AMMVote.ts +71 -0
- package/src/models/transactions/AMMWithdraw.ts +126 -0
- package/src/models/transactions/NFTokenAcceptOffer.ts +104 -0
- package/src/models/transactions/NFTokenBurn.ts +48 -0
- package/src/models/transactions/NFTokenCancelOffer.ts +45 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +145 -0
- package/src/models/transactions/NFTokenMint.ts +123 -0
- package/src/models/transactions/UNLModify.ts +20 -0
- package/src/models/transactions/XChainAccountCreateCommit.ts +107 -0
- package/src/models/transactions/XChainAddAccountCreateAttestation.ts +225 -0
- package/src/models/transactions/XChainAddClaimAttestation.ts +198 -0
- package/src/models/transactions/XChainClaim.ts +103 -0
- package/src/models/transactions/XChainCommit.ts +95 -0
- package/src/models/transactions/XChainCreateBridge.ts +78 -0
- package/src/models/transactions/XChainCreateClaimID.ts +78 -0
- package/src/models/transactions/XChainModifyBridge.ts +93 -0
- package/src/models/transactions/accountDelete.ts +50 -0
- package/src/models/transactions/accountSet.ts +228 -0
- package/src/models/transactions/checkCancel.ts +34 -0
- package/src/models/transactions/checkCash.ts +73 -0
- package/src/models/transactions/checkCreate.ts +90 -0
- package/src/models/transactions/clawback.ts +49 -0
- package/src/models/transactions/common.ts +320 -0
- package/src/models/transactions/depositPreauth.ts +68 -0
- package/src/models/transactions/enableAmendment.ts +26 -0
- package/src/models/transactions/escrowCancel.ts +45 -0
- package/src/models/transactions/escrowCreate.ts +100 -0
- package/src/models/transactions/escrowFinish.ts +63 -0
- package/src/models/transactions/index.ts +78 -0
- package/src/models/transactions/metadata.ts +69 -0
- package/src/models/transactions/offerCancel.ts +37 -0
- package/src/models/transactions/offerCreate.ts +144 -0
- package/src/models/transactions/payment.ts +278 -0
- package/src/models/transactions/paymentChannelClaim.ts +165 -0
- package/src/models/transactions/paymentChannelCreate.ts +116 -0
- package/src/models/transactions/paymentChannelFund.ts +65 -0
- package/src/models/transactions/setFee.ts +48 -0
- package/src/models/transactions/setRegularKey.ts +33 -0
- package/src/models/transactions/signerListSet.ts +89 -0
- package/src/models/transactions/ticketCreate.ts +50 -0
- package/src/models/transactions/transaction.ts +370 -0
- package/src/models/transactions/trustSet.ts +146 -0
- package/src/models/utils/flags.ts +103 -0
- package/src/models/utils/index.ts +37 -0
- package/src/sugar/autofill.ts +373 -0
- package/src/sugar/balances.ts +123 -0
- package/src/sugar/getFeeXrp.ts +45 -0
- package/src/sugar/getLedgerIndex.ts +15 -0
- package/src/sugar/getOrderbook.ts +152 -0
- package/src/sugar/index.ts +11 -0
- package/src/sugar/submit.ts +305 -0
- package/src/sugar/utils.ts +29 -0
- package/src/utils/derive.ts +23 -0
- package/src/utils/getBalanceChanges.ts +186 -0
- package/src/utils/getNFTokenID.ts +97 -0
- package/src/utils/hashes/HashPrefix.ts +40 -0
- package/src/utils/hashes/README.md +65 -0
- package/src/utils/hashes/SHAMap/InnerNode.ts +124 -0
- package/src/utils/hashes/SHAMap/LeafNode.ts +69 -0
- package/src/utils/hashes/SHAMap/index.ts +41 -0
- package/src/utils/hashes/SHAMap/node.ts +14 -0
- package/src/utils/hashes/hashLedger.ts +236 -0
- package/src/utils/hashes/index.ts +187 -0
- package/src/utils/hashes/ledgerSpaces.ts +34 -0
- package/src/utils/hashes/sha512Half.ts +19 -0
- package/src/utils/index.ts +223 -0
- package/src/utils/parseNFTokenID.ts +84 -0
- package/src/utils/quality.ts +169 -0
- package/src/utils/signPaymentChannelClaim.ts +27 -0
- package/src/utils/stringConversion.ts +27 -0
- package/src/utils/timeConversion.ts +53 -0
- package/src/utils/verifyPaymentChannelClaim.ts +30 -0
- package/src/utils/xrpConversion.ts +104 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
# XRP Ledger Hashes
|
2
|
+
|
3
|
+
Methods to hash XRP Ledger objects
|
4
|
+
|
5
|
+
## Computing a transaction hash (ID)
|
6
|
+
|
7
|
+
### computeBinaryTransactionHash = (txBlobHex: string): string
|
8
|
+
|
9
|
+
Compute the hash of a binary transaction blob.
|
10
|
+
|
11
|
+
### computeTransactionHash = (txJSON: any): string
|
12
|
+
|
13
|
+
Compute the hash of a transaction in txJSON format.
|
14
|
+
|
15
|
+
## [Hash Prefixes](https://xrpl.org/basic-data-types.html#hash-prefixes)
|
16
|
+
|
17
|
+
In many cases, the XRP Ledger prefixes an object's binary data with a 4-byte code before calculating its hash, so that objects of different types have different hashes even if the binary data is the same. The existing 4-byte codes are structured as 3 alphabetic characters, encoded as ASCII, followed by a zero byte.
|
18
|
+
|
19
|
+
Some types of hashes appear in API requests and responses. Others are only calculated as the first step of signing a certain type of data, or calculating a higher-level hash. Some of following methods internally use some of the 4-byte hash prefixes in order to calculate the appropriate hash.
|
20
|
+
|
21
|
+
### hashTx = (txBlobHex: string): string
|
22
|
+
|
23
|
+
In order to single-sign a transaction, you must perform these steps:
|
24
|
+
|
25
|
+
1. Assuming the transaction is in JSON format (txJSON), `encode` the transaction in the XRP Ledger's binary format.
|
26
|
+
2. Hash the data with the appropriate prefix (`0x53545800` if single-signing, or `0x534D5400` if multi-signing).
|
27
|
+
3. After signing, you must re-serialize the transaction with the `TxnSignature` field included.
|
28
|
+
|
29
|
+
The `hashTx` helps with step 2, automatically using the `0x53545800` prefix needed for single-signing a transaction.
|
30
|
+
|
31
|
+
For details, see [Serialization Format](https://xrpl.org/serialization.html).
|
32
|
+
|
33
|
+
_Removed:_ `computeTransactionSigningHash`, which took txJSON as a parameter. It was part of the deprecated ripple-hashes library. If you have txJSON, `encode` it with [ripple-binary-codec](https://github.com/ripple/ripple-binary-codec) first. Example: `return hashTx(encode(txJSON))`
|
34
|
+
|
35
|
+
### computeAccountLedgerObjectID = (address: string): string
|
36
|
+
|
37
|
+
Compute the hash of an account, given the account's classic address (starting with `r`).
|
38
|
+
|
39
|
+
### computeSignerListLedgerObjectID = (address: string): string
|
40
|
+
|
41
|
+
Compute the hash of an account's SignerList.
|
42
|
+
|
43
|
+
### computeOfferID = (address: string, sequence: number): string
|
44
|
+
|
45
|
+
Compute the hash of an order, given the owner's classic address (starting with `r`) and the account sequence number of the `OfferCreate` order transaction.
|
46
|
+
|
47
|
+
### hashTrustline = (address1: string, address2: string, currency: string): string
|
48
|
+
|
49
|
+
Compute the hash of a trustline, given the two parties' classic addresses (starting with `r`) and the currency code.
|
50
|
+
|
51
|
+
### hashTxTree = (transactions: any[]): string
|
52
|
+
|
53
|
+
### hashStateTree = (entries: any[]): string
|
54
|
+
|
55
|
+
### hashLedger = (ledgerHeader): string
|
56
|
+
|
57
|
+
Compute the hash of a ledger.
|
58
|
+
|
59
|
+
### hashEscrow = (address, sequence): string
|
60
|
+
|
61
|
+
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.
|
62
|
+
|
63
|
+
### hashPaymentChannel = (address, dstAddress, sequence): string
|
64
|
+
|
65
|
+
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.
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import { XrplError } from '../../../errors'
|
2
|
+
import HashPrefix from '../HashPrefix'
|
3
|
+
import sha512Half from '../sha512Half'
|
4
|
+
|
5
|
+
import LeafNode from './LeafNode'
|
6
|
+
import { NodeType, Node } from './node'
|
7
|
+
|
8
|
+
const HEX_ZERO =
|
9
|
+
'0000000000000000000000000000000000000000000000000000000000000000'
|
10
|
+
|
11
|
+
const SLOT_MAX = 15
|
12
|
+
const HEX = 16
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Class for SHAMap InnerNode.
|
16
|
+
*/
|
17
|
+
class InnerNode extends Node {
|
18
|
+
public leaves: { [slot: number]: Node | undefined }
|
19
|
+
public type: NodeType
|
20
|
+
public depth: number
|
21
|
+
public empty: boolean
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Define an Inner (non-leaf) node in a SHAMap tree.
|
25
|
+
*
|
26
|
+
* @param depth - I.e. How many parent inner nodes.
|
27
|
+
*/
|
28
|
+
public constructor(depth = 0) {
|
29
|
+
super()
|
30
|
+
this.leaves = {}
|
31
|
+
this.type = NodeType.INNER
|
32
|
+
this.depth = depth
|
33
|
+
this.empty = true
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Get the hash of a LeafNode.
|
38
|
+
*
|
39
|
+
* @returns Hash of the LeafNode.
|
40
|
+
*/
|
41
|
+
public get hash(): string {
|
42
|
+
if (this.empty) {
|
43
|
+
return HEX_ZERO
|
44
|
+
}
|
45
|
+
let hex = ''
|
46
|
+
for (let iter = 0; iter <= SLOT_MAX; iter++) {
|
47
|
+
const child = this.leaves[iter]
|
48
|
+
const hash: string = child == null ? HEX_ZERO : child.hash
|
49
|
+
hex += hash
|
50
|
+
}
|
51
|
+
|
52
|
+
const prefix = HashPrefix.INNER_NODE.toString(HEX)
|
53
|
+
return sha512Half(prefix + hex)
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Adds an item to the InnerNode.
|
58
|
+
*
|
59
|
+
* @param tag - Equates to a ledger entry `index`.
|
60
|
+
* @param node - Node to add.
|
61
|
+
* @throws If there is a index collision.
|
62
|
+
*/
|
63
|
+
public addItem(tag: string, node: Node): void {
|
64
|
+
const existingNode = this.getNode(parseInt(tag[this.depth], HEX))
|
65
|
+
|
66
|
+
if (existingNode === undefined) {
|
67
|
+
this.setNode(parseInt(tag[this.depth], HEX), node)
|
68
|
+
return
|
69
|
+
}
|
70
|
+
|
71
|
+
// A node already exists in this slot
|
72
|
+
if (existingNode instanceof InnerNode) {
|
73
|
+
// There is an inner node, so we need to go deeper
|
74
|
+
existingNode.addItem(tag, node)
|
75
|
+
} else if (existingNode instanceof LeafNode) {
|
76
|
+
if (existingNode.tag === tag) {
|
77
|
+
// Collision
|
78
|
+
throw new XrplError(
|
79
|
+
'Tried to add a node to a SHAMap that was already in there.',
|
80
|
+
)
|
81
|
+
} else {
|
82
|
+
const newInnerNode = new InnerNode(this.depth + 1)
|
83
|
+
|
84
|
+
// Parent new and existing node
|
85
|
+
newInnerNode.addItem(existingNode.tag, existingNode)
|
86
|
+
newInnerNode.addItem(tag, node)
|
87
|
+
|
88
|
+
// And place the newly created inner node in the slot
|
89
|
+
this.setNode(parseInt(tag[this.depth], HEX), newInnerNode)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Overwrite the node that is currently in a given slot.
|
96
|
+
*
|
97
|
+
* @param slot - A number 0-15.
|
98
|
+
* @param node - To place.
|
99
|
+
* @throws If slot is out of range.
|
100
|
+
*/
|
101
|
+
public setNode(slot: number, node: Node): void {
|
102
|
+
if (slot < 0 || slot > SLOT_MAX) {
|
103
|
+
throw new XrplError('Invalid slot: slot must be between 0-15.')
|
104
|
+
}
|
105
|
+
this.leaves[slot] = node
|
106
|
+
this.empty = false
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Get the node that is currently in a given slot.
|
111
|
+
*
|
112
|
+
* @param slot - A number 0-15.
|
113
|
+
* @returns Node currently in a slot.
|
114
|
+
* @throws If slot is out of range.
|
115
|
+
*/
|
116
|
+
public getNode(slot: number): Node | undefined {
|
117
|
+
if (slot < 0 || slot > SLOT_MAX) {
|
118
|
+
throw new XrplError('Invalid slot: slot must be between 0-15.')
|
119
|
+
}
|
120
|
+
return this.leaves[slot]
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
export default InnerNode
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { XrplError } from '../../../errors'
|
2
|
+
import HashPrefix from '../HashPrefix'
|
3
|
+
import sha512Half from '../sha512Half'
|
4
|
+
|
5
|
+
import { NodeType, Node } from './node'
|
6
|
+
|
7
|
+
const HEX = 16
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Class for SHAMap Leaf Node.
|
11
|
+
*/
|
12
|
+
class LeafNode extends Node {
|
13
|
+
public tag: string
|
14
|
+
public type: NodeType
|
15
|
+
public data: string
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Leaf node in a SHAMap tree.
|
19
|
+
*
|
20
|
+
* @param tag - Equates to a ledger entry `index`.
|
21
|
+
* @param data - Hex of account state, transaction etc.
|
22
|
+
* @param type - One of TYPE_ACCOUNT_STATE, TYPE_TRANSACTION_MD etc.
|
23
|
+
*/
|
24
|
+
public constructor(tag: string, data: string, type: NodeType) {
|
25
|
+
super()
|
26
|
+
this.tag = tag
|
27
|
+
this.type = type
|
28
|
+
this.data = data
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Get the hash of a LeafNode.
|
33
|
+
*
|
34
|
+
* @returns Hash or undefined.
|
35
|
+
* @throws If node is of unknown type.
|
36
|
+
*/
|
37
|
+
public get hash(): string {
|
38
|
+
switch (this.type) {
|
39
|
+
case NodeType.ACCOUNT_STATE: {
|
40
|
+
const leafPrefix = HashPrefix.LEAF_NODE.toString(HEX)
|
41
|
+
return sha512Half(leafPrefix + this.data + this.tag)
|
42
|
+
}
|
43
|
+
case NodeType.TRANSACTION_NO_METADATA: {
|
44
|
+
const txIDPrefix = HashPrefix.TRANSACTION_ID.toString(HEX)
|
45
|
+
return sha512Half(txIDPrefix + this.data)
|
46
|
+
}
|
47
|
+
case NodeType.TRANSACTION_METADATA: {
|
48
|
+
const txNodePrefix = HashPrefix.TRANSACTION_NODE.toString(HEX)
|
49
|
+
return sha512Half(txNodePrefix + this.data + this.tag)
|
50
|
+
}
|
51
|
+
default:
|
52
|
+
throw new XrplError('Tried to hash a SHAMap node of unknown type.')
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Add item to Leaf.
|
58
|
+
*
|
59
|
+
* @param tag - Index of the Node.
|
60
|
+
* @param node - Node to insert.
|
61
|
+
* @throws When called, because LeafNodes cannot addItem.
|
62
|
+
*/
|
63
|
+
public addItem(tag: string, node: Node): void {
|
64
|
+
throw new XrplError('Cannot call addItem on a LeafNode')
|
65
|
+
this.addItem(tag, node)
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
export default LeafNode
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import InnerNode from './InnerNode'
|
2
|
+
import LeafNode from './LeafNode'
|
3
|
+
import { NodeType } from './node'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* SHAMap is the hash structure used to model ledgers.
|
7
|
+
* If the root hash is equivalent, that means all nodes should be equivalent as well.
|
8
|
+
*/
|
9
|
+
class SHAMap {
|
10
|
+
public root: InnerNode
|
11
|
+
|
12
|
+
/**
|
13
|
+
* SHAMap tree constructor.
|
14
|
+
*/
|
15
|
+
public constructor() {
|
16
|
+
this.root = new InnerNode(0)
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Get the hash of the SHAMap.
|
21
|
+
*
|
22
|
+
* @returns The hash of the root of the SHAMap.
|
23
|
+
*/
|
24
|
+
public get hash(): string {
|
25
|
+
return this.root.hash
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Add an item to the SHAMap.
|
30
|
+
*
|
31
|
+
* @param tag - Index of the Node to add.
|
32
|
+
* @param data - Data to insert into the tree.
|
33
|
+
* @param type - Type of the node to add.
|
34
|
+
*/
|
35
|
+
public addItem(tag: string, data: string, type: NodeType): void {
|
36
|
+
this.root.addItem(tag, new LeafNode(tag, data, type))
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
export * from './node'
|
41
|
+
export default SHAMap
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export enum NodeType {
|
2
|
+
INNER = 1,
|
3
|
+
TRANSACTION_NO_METADATA = 2,
|
4
|
+
TRANSACTION_METADATA = 3,
|
5
|
+
ACCOUNT_STATE = 4,
|
6
|
+
}
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Abstract base class for SHAMapNode.
|
10
|
+
*/
|
11
|
+
export abstract class Node {
|
12
|
+
public abstract get hash(): string
|
13
|
+
public abstract addItem(_tag: string, _node: Node): void
|
14
|
+
}
|
@@ -0,0 +1,236 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers -- this file mimics
|
2
|
+
behavior in rippled. Magic numbers are used for lengths and conditions */
|
3
|
+
/* eslint-disable no-bitwise -- this file mimics behavior in rippled. It uses
|
4
|
+
bitwise operators for and-ing numbers with a mask and bit shifting. */
|
5
|
+
|
6
|
+
import BigNumber from 'bignumber.js'
|
7
|
+
import { decode, encode } from 'ripple-binary-codec'
|
8
|
+
|
9
|
+
import { ValidationError, XrplError } from '../../errors'
|
10
|
+
import type { Ledger } from '../../models/ledger'
|
11
|
+
import { LedgerEntry } from '../../models/ledger'
|
12
|
+
import { Transaction, TransactionMetadata } from '../../models/transactions'
|
13
|
+
|
14
|
+
import HashPrefix from './HashPrefix'
|
15
|
+
import sha512Half from './sha512Half'
|
16
|
+
import SHAMap, { NodeType } from './SHAMap'
|
17
|
+
|
18
|
+
const HEX = 16
|
19
|
+
|
20
|
+
interface HashLedgerHeaderOptions {
|
21
|
+
computeTreeHashes?: boolean
|
22
|
+
}
|
23
|
+
|
24
|
+
function intToHex(integer: number, byteLength: number): string {
|
25
|
+
const foo = Number(integer)
|
26
|
+
.toString(HEX)
|
27
|
+
.padStart(byteLength * 2, '0')
|
28
|
+
|
29
|
+
return foo
|
30
|
+
}
|
31
|
+
|
32
|
+
function bytesToHex(bytes: number[]): string {
|
33
|
+
return Buffer.from(bytes).toString('hex')
|
34
|
+
}
|
35
|
+
|
36
|
+
function bigintToHex(
|
37
|
+
integerString: string | number | BigNumber,
|
38
|
+
byteLength: number,
|
39
|
+
): string {
|
40
|
+
const hex = new BigNumber(integerString).toString(HEX)
|
41
|
+
return hex.padStart(byteLength * 2, '0')
|
42
|
+
}
|
43
|
+
|
44
|
+
function addLengthPrefix(hex: string): string {
|
45
|
+
const length = hex.length / 2
|
46
|
+
if (length <= 192) {
|
47
|
+
return bytesToHex([length]) + hex
|
48
|
+
}
|
49
|
+
if (length <= 12480) {
|
50
|
+
const prefix = length - 193
|
51
|
+
return bytesToHex([193 + (prefix >>> 8), prefix & 0xff]) + hex
|
52
|
+
}
|
53
|
+
if (length <= 918744) {
|
54
|
+
const prefix = length - 12481
|
55
|
+
return (
|
56
|
+
bytesToHex([
|
57
|
+
241 + (prefix >>> 16),
|
58
|
+
(prefix >>> 8) & 0xff,
|
59
|
+
prefix & 0xff,
|
60
|
+
]) + hex
|
61
|
+
)
|
62
|
+
}
|
63
|
+
throw new XrplError('Variable integer overflow.')
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Hashes the Transaction object as the ledger does. Throws if the transaction is unsigned.
|
68
|
+
*
|
69
|
+
* @param tx - A transaction to hash. Tx may be in binary blob form. Tx must be signed.
|
70
|
+
* @returns A hash of tx.
|
71
|
+
* @throws ValidationError if the Transaction is unsigned.\
|
72
|
+
* @category Utilities
|
73
|
+
*/
|
74
|
+
export function hashSignedTx(tx: Transaction | string): string {
|
75
|
+
let txBlob: string
|
76
|
+
let txObject: Transaction
|
77
|
+
if (typeof tx === 'string') {
|
78
|
+
txBlob = tx
|
79
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Required until updated in binary codec. */
|
80
|
+
txObject = decode(tx) as unknown as Transaction
|
81
|
+
} else {
|
82
|
+
txBlob = encode(tx)
|
83
|
+
txObject = tx
|
84
|
+
}
|
85
|
+
|
86
|
+
if (txObject.TxnSignature === undefined && txObject.Signers === undefined) {
|
87
|
+
throw new ValidationError('The transaction must be signed to hash it.')
|
88
|
+
}
|
89
|
+
|
90
|
+
const prefix = HashPrefix.TRANSACTION_ID.toString(16).toUpperCase()
|
91
|
+
return sha512Half(prefix.concat(txBlob))
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Compute the hash of a ledger.
|
96
|
+
*
|
97
|
+
* @param ledgerHeader - Ledger to compute the hash of.
|
98
|
+
* @returns The hash of the ledger.
|
99
|
+
* @category Utilities
|
100
|
+
*/
|
101
|
+
export function hashLedgerHeader(ledgerHeader: Ledger): string {
|
102
|
+
const prefix = HashPrefix.LEDGER.toString(HEX).toUpperCase()
|
103
|
+
|
104
|
+
const ledger =
|
105
|
+
prefix +
|
106
|
+
intToHex(Number(ledgerHeader.ledger_index), 4) +
|
107
|
+
bigintToHex(ledgerHeader.total_coins, 8) +
|
108
|
+
ledgerHeader.parent_hash +
|
109
|
+
ledgerHeader.transaction_hash +
|
110
|
+
ledgerHeader.account_hash +
|
111
|
+
intToHex(ledgerHeader.parent_close_time, 4) +
|
112
|
+
intToHex(ledgerHeader.close_time, 4) +
|
113
|
+
intToHex(ledgerHeader.close_time_resolution, 1) +
|
114
|
+
intToHex(ledgerHeader.close_flags, 1)
|
115
|
+
|
116
|
+
return sha512Half(ledger)
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Compute the root hash of the SHAMap containing all transactions.
|
121
|
+
*
|
122
|
+
* @param transactions - List of Transactions.
|
123
|
+
* @returns The root hash of the SHAMap.
|
124
|
+
* @category Utilities
|
125
|
+
*/
|
126
|
+
export function hashTxTree(
|
127
|
+
transactions: Array<Transaction & { metaData?: TransactionMetadata }>,
|
128
|
+
): string {
|
129
|
+
const shamap = new SHAMap()
|
130
|
+
for (const txJSON of transactions) {
|
131
|
+
const txBlobHex = encode(txJSON)
|
132
|
+
const metaHex = encode(txJSON.metaData ?? {})
|
133
|
+
const txHash = hashSignedTx(txBlobHex)
|
134
|
+
const data = addLengthPrefix(txBlobHex) + addLengthPrefix(metaHex)
|
135
|
+
shamap.addItem(txHash, data, NodeType.TRANSACTION_METADATA)
|
136
|
+
}
|
137
|
+
|
138
|
+
return shamap.hash
|
139
|
+
}
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Compute the state hash of a list of LedgerEntries.
|
143
|
+
*
|
144
|
+
* @param entries - List of LedgerEntries.
|
145
|
+
* @returns Hash of SHAMap that consists of all entries.
|
146
|
+
* @category Utilities
|
147
|
+
*/
|
148
|
+
export function hashStateTree(entries: LedgerEntry[]): string {
|
149
|
+
const shamap = new SHAMap()
|
150
|
+
|
151
|
+
entries.forEach((ledgerEntry) => {
|
152
|
+
const data = encode(ledgerEntry)
|
153
|
+
shamap.addItem(ledgerEntry.index, data, NodeType.ACCOUNT_STATE)
|
154
|
+
})
|
155
|
+
|
156
|
+
return shamap.hash
|
157
|
+
}
|
158
|
+
|
159
|
+
function computeTransactionHash(
|
160
|
+
ledger: Ledger,
|
161
|
+
options: HashLedgerHeaderOptions,
|
162
|
+
): string {
|
163
|
+
const { transaction_hash } = ledger
|
164
|
+
|
165
|
+
if (!options.computeTreeHashes) {
|
166
|
+
return transaction_hash
|
167
|
+
}
|
168
|
+
|
169
|
+
if (ledger.transactions == null) {
|
170
|
+
throw new ValidationError('transactions is missing from the ledger')
|
171
|
+
}
|
172
|
+
|
173
|
+
const transactionHash = hashTxTree(ledger.transactions)
|
174
|
+
|
175
|
+
if (transaction_hash !== transactionHash) {
|
176
|
+
throw new ValidationError(
|
177
|
+
'transactionHash in header' +
|
178
|
+
' does not match computed hash of transactions',
|
179
|
+
{
|
180
|
+
transactionHashInHeader: transaction_hash,
|
181
|
+
computedHashOfTransactions: transactionHash,
|
182
|
+
},
|
183
|
+
)
|
184
|
+
}
|
185
|
+
|
186
|
+
return transactionHash
|
187
|
+
}
|
188
|
+
|
189
|
+
function computeStateHash(
|
190
|
+
ledger: Ledger,
|
191
|
+
options: HashLedgerHeaderOptions,
|
192
|
+
): string {
|
193
|
+
const { account_hash } = ledger
|
194
|
+
|
195
|
+
if (!options.computeTreeHashes) {
|
196
|
+
return account_hash
|
197
|
+
}
|
198
|
+
|
199
|
+
if (ledger.accountState == null) {
|
200
|
+
throw new ValidationError('accountState is missing from the ledger')
|
201
|
+
}
|
202
|
+
|
203
|
+
const stateHash = hashStateTree(ledger.accountState)
|
204
|
+
|
205
|
+
if (account_hash !== stateHash) {
|
206
|
+
throw new ValidationError(
|
207
|
+
'stateHash in header does not match computed hash of state',
|
208
|
+
)
|
209
|
+
}
|
210
|
+
|
211
|
+
return stateHash
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Compute the hash of a ledger.
|
216
|
+
*
|
217
|
+
* @param ledger - Ledger to compute the hash for.
|
218
|
+
* @param options - Allow client to recompute Transaction and State Hashes.
|
219
|
+
* @param options.computeTreeHashes - Whether to recompute the Transaction and State Hashes.
|
220
|
+
* @returns The has of ledger.
|
221
|
+
* @category Utilities
|
222
|
+
*/
|
223
|
+
function hashLedger(
|
224
|
+
ledger: Ledger,
|
225
|
+
options: {
|
226
|
+
computeTreeHashes?: boolean
|
227
|
+
} = {},
|
228
|
+
): string {
|
229
|
+
const subhashes = {
|
230
|
+
transaction_hash: computeTransactionHash(ledger, options),
|
231
|
+
account_hash: computeStateHash(ledger, options),
|
232
|
+
}
|
233
|
+
return hashLedgerHeader({ ...ledger, ...subhashes })
|
234
|
+
}
|
235
|
+
|
236
|
+
export default hashLedger
|