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,504 @@
|
|
1
|
+
import BigNumber from 'bignumber.js'
|
2
|
+
import { fromSeed } from 'bip32'
|
3
|
+
import { mnemonicToSeedSync, validateMnemonic } from 'bip39'
|
4
|
+
import omitBy from 'lodash/omitBy'
|
5
|
+
import {
|
6
|
+
classicAddressToXAddress,
|
7
|
+
isValidXAddress,
|
8
|
+
xAddressToClassicAddress,
|
9
|
+
encodeSeed,
|
10
|
+
} from 'ripple-address-codec'
|
11
|
+
import {
|
12
|
+
decode,
|
13
|
+
encodeForSigning,
|
14
|
+
encodeForMultisigning,
|
15
|
+
encode,
|
16
|
+
} from 'ripple-binary-codec'
|
17
|
+
import {
|
18
|
+
deriveAddress,
|
19
|
+
deriveKeypair,
|
20
|
+
generateSeed,
|
21
|
+
verify,
|
22
|
+
sign,
|
23
|
+
} from 'ripple-keypairs'
|
24
|
+
|
25
|
+
import ECDSA from '../ECDSA'
|
26
|
+
import { ValidationError } from '../errors'
|
27
|
+
import { Transaction, validate } from '../models/transactions'
|
28
|
+
import { ensureClassicAddress } from '../sugar/utils'
|
29
|
+
import { hashSignedTx } from '../utils/hashes/hashLedger'
|
30
|
+
|
31
|
+
import { rfc1751MnemonicToKey } from './rfc1751'
|
32
|
+
|
33
|
+
const DEFAULT_ALGORITHM: ECDSA = ECDSA.ed25519
|
34
|
+
const DEFAULT_DERIVATION_PATH = "m/44'/144'/0'/0/0"
|
35
|
+
|
36
|
+
function hexFromBuffer(buffer: Buffer): string {
|
37
|
+
return buffer.toString('hex').toUpperCase()
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* A utility for deriving a wallet composed of a keypair (publicKey/privateKey).
|
42
|
+
* A wallet can be derived from either a seed, mnemonic, or entropy (array of random numbers).
|
43
|
+
* It provides functionality to sign/verify transactions offline.
|
44
|
+
*
|
45
|
+
* @example
|
46
|
+
* ```typescript
|
47
|
+
*
|
48
|
+
* // Derive a wallet from a base58 encoded seed.
|
49
|
+
* const seedWallet = Wallet.fromSeed('ssZkdwURFMBXenJPbrpE14b6noJSu')
|
50
|
+
* console.log(seedWallet)
|
51
|
+
* // Wallet {
|
52
|
+
* // publicKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
|
53
|
+
* // privateKey: '00445D0A16DD05EFAF6D5AF45E6B8A6DE4170D93C0627021A0B8E705786CBCCFF7',
|
54
|
+
* // classicAddress: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo',
|
55
|
+
* // seed: 'ssZkdwURFMBXenJPbrpE14b6noJSu'
|
56
|
+
* // }.
|
57
|
+
*
|
58
|
+
* // Sign a JSON Transaction
|
59
|
+
* const signed = seedWallet.signTransaction({
|
60
|
+
* TransactionType: 'Payment',
|
61
|
+
* Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
|
62
|
+
* ...........
|
63
|
+
* }).
|
64
|
+
*
|
65
|
+
* console.log(signed)
|
66
|
+
* // '1200007321......B01BE1DFF3'.
|
67
|
+
* console.log(decode(signed))
|
68
|
+
* // {
|
69
|
+
* // TransactionType: 'Payment',
|
70
|
+
* // SigningPubKey: '02FE9932A9C4AA2AC9F0ED0F2B89302DE7C2C95F91D782DA3CF06E64E1C1216449',
|
71
|
+
* // TxnSignature: '3045022100AAD......5B631ABD21171B61B07D304',
|
72
|
+
* // Account: 'rG88FVLjvYiQaGftSa1cKuE2qNx7aK5ivo'
|
73
|
+
* // ...........
|
74
|
+
* // }
|
75
|
+
* ```
|
76
|
+
*
|
77
|
+
* @category Signing
|
78
|
+
*/
|
79
|
+
export class Wallet {
|
80
|
+
public readonly publicKey: string
|
81
|
+
public readonly privateKey: string
|
82
|
+
public readonly classicAddress: string
|
83
|
+
public readonly seed?: string
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Creates a new Wallet.
|
87
|
+
*
|
88
|
+
* @param publicKey - The public key for the account.
|
89
|
+
* @param privateKey - The private key used for signing transactions for the account.
|
90
|
+
* @param opts - (Optional) Options to initialize a Wallet.
|
91
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
92
|
+
* @param opts.seed - The seed used to derive the account keys.
|
93
|
+
*/
|
94
|
+
public constructor(
|
95
|
+
publicKey: string,
|
96
|
+
privateKey: string,
|
97
|
+
opts: {
|
98
|
+
masterAddress?: string
|
99
|
+
seed?: string
|
100
|
+
} = {},
|
101
|
+
) {
|
102
|
+
this.publicKey = publicKey
|
103
|
+
this.privateKey = privateKey
|
104
|
+
this.classicAddress = opts.masterAddress
|
105
|
+
? ensureClassicAddress(opts.masterAddress)
|
106
|
+
: deriveAddress(publicKey)
|
107
|
+
this.seed = opts.seed
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Alias for wallet.classicAddress.
|
112
|
+
*
|
113
|
+
* @returns The wallet's classic address.
|
114
|
+
*/
|
115
|
+
public get address(): string {
|
116
|
+
return this.classicAddress
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* `generate()` creates a new random Wallet. In order to make this a valid account on ledger, you must
|
121
|
+
* Send XRP to it. On test networks that can be done with "faucets" which send XRP to any account which asks
|
122
|
+
* For it. You can call `client.fundWallet()` in order to generate credentials and fund the account on test networks.
|
123
|
+
*
|
124
|
+
* @example
|
125
|
+
* ```ts
|
126
|
+
* const { Wallet } = require('xrpl')
|
127
|
+
* const wallet = Wallet.generate()
|
128
|
+
* ```
|
129
|
+
*
|
130
|
+
* @param algorithm - The digital signature algorithm to generate an address for.
|
131
|
+
* @returns A new Wallet derived from a generated seed.
|
132
|
+
*
|
133
|
+
* @throws ValidationError when signing algorithm isn't valid
|
134
|
+
*/
|
135
|
+
public static generate(algorithm: ECDSA = DEFAULT_ALGORITHM): Wallet {
|
136
|
+
if (!Object.values(ECDSA).includes(algorithm)) {
|
137
|
+
throw new ValidationError('Invalid cryptographic signing algorithm')
|
138
|
+
}
|
139
|
+
const seed = generateSeed({ algorithm })
|
140
|
+
return Wallet.fromSeed(seed)
|
141
|
+
}
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Derives a wallet from a seed.
|
145
|
+
*
|
146
|
+
* @param seed - A string used to generate a keypair (publicKey/privateKey) to derive a wallet.
|
147
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
148
|
+
* @param opts.algorithm - The digital signature algorithm to generate an address for.
|
149
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
150
|
+
* @returns A Wallet derived from a seed.
|
151
|
+
*/
|
152
|
+
public static fromSeed(
|
153
|
+
seed: string,
|
154
|
+
opts: { masterAddress?: string; algorithm?: ECDSA } = {},
|
155
|
+
): Wallet {
|
156
|
+
return Wallet.deriveWallet(seed, {
|
157
|
+
algorithm: opts.algorithm,
|
158
|
+
masterAddress: opts.masterAddress,
|
159
|
+
})
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Derives a wallet from a secret (AKA a seed).
|
164
|
+
*
|
165
|
+
* @param secret - A string used to generate a keypair (publicKey/privateKey) to derive a wallet.
|
166
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
167
|
+
* @param opts.algorithm - The digital signature algorithm to generate an address for.
|
168
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
169
|
+
* @returns A Wallet derived from a secret (AKA a seed).
|
170
|
+
*/
|
171
|
+
// eslint-disable-next-line @typescript-eslint/member-ordering -- Member is used as a function here
|
172
|
+
public static fromSecret = Wallet.fromSeed
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Derives a wallet from an entropy (array of random numbers).
|
176
|
+
*
|
177
|
+
* @param entropy - An array of random numbers to generate a seed used to derive a wallet.
|
178
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
179
|
+
* @param opts.algorithm - The digital signature algorithm to generate an address for.
|
180
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
181
|
+
* @returns A Wallet derived from an entropy.
|
182
|
+
*/
|
183
|
+
public static fromEntropy(
|
184
|
+
entropy: Uint8Array | number[],
|
185
|
+
opts: { masterAddress?: string; algorithm?: ECDSA } = {},
|
186
|
+
): Wallet {
|
187
|
+
const algorithm = opts.algorithm ?? DEFAULT_ALGORITHM
|
188
|
+
const options = {
|
189
|
+
entropy: Uint8Array.from(entropy),
|
190
|
+
algorithm,
|
191
|
+
}
|
192
|
+
const seed = generateSeed(options)
|
193
|
+
return Wallet.deriveWallet(seed, {
|
194
|
+
algorithm,
|
195
|
+
masterAddress: opts.masterAddress,
|
196
|
+
})
|
197
|
+
}
|
198
|
+
|
199
|
+
/**
|
200
|
+
* Derives a wallet from a bip39 or RFC1751 mnemonic (Defaults to bip39).
|
201
|
+
*
|
202
|
+
* @deprecated since version 2.6.1.
|
203
|
+
* Will be deleted in version 3.0.0.
|
204
|
+
* This representation is currently deprecated in rippled.
|
205
|
+
* You should use another method to represent your keys such as a seed or public/private keypair.
|
206
|
+
*
|
207
|
+
* @param mnemonic - A string consisting of words (whitespace delimited) used to derive a wallet.
|
208
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
209
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
210
|
+
* @param opts.derivationPath - The path to derive a keypair (publicKey/privateKey). Only used for bip39 conversions.
|
211
|
+
* @param opts.mnemonicEncoding - If set to 'rfc1751', this interprets the mnemonic as a rippled RFC1751 mnemonic like
|
212
|
+
* `wallet_propose` generates in rippled. Otherwise the function defaults to bip39 decoding.
|
213
|
+
* @param opts.algorithm - Only used if opts.mnemonicEncoding is 'rfc1751'. Allows the mnemonic to generate its
|
214
|
+
* secp256k1 seed, or its ed25519 seed. By default, it will generate the secp256k1 seed
|
215
|
+
* to match the rippled `wallet_propose` default algorithm.
|
216
|
+
* @returns A Wallet derived from a mnemonic.
|
217
|
+
* @throws ValidationError if unable to derive private key from mnemonic input.
|
218
|
+
*/
|
219
|
+
public static fromMnemonic(
|
220
|
+
mnemonic: string,
|
221
|
+
opts: {
|
222
|
+
masterAddress?: string
|
223
|
+
derivationPath?: string
|
224
|
+
mnemonicEncoding?: 'bip39' | 'rfc1751'
|
225
|
+
algorithm?: ECDSA
|
226
|
+
} = {},
|
227
|
+
): Wallet {
|
228
|
+
if (opts.mnemonicEncoding === 'rfc1751') {
|
229
|
+
return Wallet.fromRFC1751Mnemonic(mnemonic, {
|
230
|
+
masterAddress: opts.masterAddress,
|
231
|
+
algorithm: opts.algorithm,
|
232
|
+
})
|
233
|
+
}
|
234
|
+
// Otherwise decode using bip39's mnemonic standard
|
235
|
+
if (!validateMnemonic(mnemonic)) {
|
236
|
+
throw new ValidationError(
|
237
|
+
'Unable to parse the given mnemonic using bip39 encoding',
|
238
|
+
)
|
239
|
+
}
|
240
|
+
|
241
|
+
const seed = mnemonicToSeedSync(mnemonic)
|
242
|
+
const masterNode = fromSeed(seed)
|
243
|
+
const node = masterNode.derivePath(
|
244
|
+
opts.derivationPath ?? DEFAULT_DERIVATION_PATH,
|
245
|
+
)
|
246
|
+
if (node.privateKey === undefined) {
|
247
|
+
throw new ValidationError(
|
248
|
+
'Unable to derive privateKey from mnemonic input',
|
249
|
+
)
|
250
|
+
}
|
251
|
+
|
252
|
+
const publicKey = hexFromBuffer(node.publicKey)
|
253
|
+
const privateKey = hexFromBuffer(node.privateKey)
|
254
|
+
return new Wallet(publicKey, `00${privateKey}`, {
|
255
|
+
masterAddress: opts.masterAddress,
|
256
|
+
})
|
257
|
+
}
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Derives a wallet from a RFC1751 mnemonic, which is how `wallet_propose` encodes mnemonics.
|
261
|
+
*
|
262
|
+
* @param mnemonic - A string consisting of words (whitespace delimited) used to derive a wallet.
|
263
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
264
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
265
|
+
* @param opts.algorithm - The digital signature algorithm to generate an address for.
|
266
|
+
* @returns A Wallet derived from a mnemonic.
|
267
|
+
*/
|
268
|
+
private static fromRFC1751Mnemonic(
|
269
|
+
mnemonic: string,
|
270
|
+
opts: { masterAddress?: string; algorithm?: ECDSA },
|
271
|
+
): Wallet {
|
272
|
+
const seed = rfc1751MnemonicToKey(mnemonic)
|
273
|
+
let encodeAlgorithm: 'ed25519' | 'secp256k1'
|
274
|
+
if (opts.algorithm === ECDSA.ed25519) {
|
275
|
+
encodeAlgorithm = 'ed25519'
|
276
|
+
} else {
|
277
|
+
// Defaults to secp256k1 since that's the default for `wallet_propose`
|
278
|
+
encodeAlgorithm = 'secp256k1'
|
279
|
+
}
|
280
|
+
const encodedSeed = encodeSeed(seed, encodeAlgorithm)
|
281
|
+
return Wallet.fromSeed(encodedSeed, {
|
282
|
+
masterAddress: opts.masterAddress,
|
283
|
+
algorithm: opts.algorithm,
|
284
|
+
})
|
285
|
+
}
|
286
|
+
|
287
|
+
/**
|
288
|
+
* Derive a Wallet from a seed.
|
289
|
+
*
|
290
|
+
* @param seed - The seed used to derive the wallet.
|
291
|
+
* @param opts - (Optional) Options to derive a Wallet.
|
292
|
+
* @param opts.algorithm - The digital signature algorithm to generate an address for.
|
293
|
+
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account.
|
294
|
+
* @returns A Wallet derived from the seed.
|
295
|
+
*/
|
296
|
+
private static deriveWallet(
|
297
|
+
seed: string,
|
298
|
+
opts: { masterAddress?: string; algorithm?: ECDSA } = {},
|
299
|
+
): Wallet {
|
300
|
+
const { publicKey, privateKey } = deriveKeypair(seed, {
|
301
|
+
algorithm: opts.algorithm ?? DEFAULT_ALGORITHM,
|
302
|
+
})
|
303
|
+
return new Wallet(publicKey, privateKey, {
|
304
|
+
seed,
|
305
|
+
masterAddress: opts.masterAddress,
|
306
|
+
})
|
307
|
+
}
|
308
|
+
|
309
|
+
/**
|
310
|
+
* Signs a transaction offline.
|
311
|
+
*
|
312
|
+
* @example
|
313
|
+
*
|
314
|
+
* ```ts
|
315
|
+
* const { Client, Wallet } = require('xrpl')
|
316
|
+
* const client = new Client('wss://s.altnet.rippletest.net:51233')
|
317
|
+
*
|
318
|
+
* async function signTransaction() {
|
319
|
+
* await client.connect()
|
320
|
+
* const { balance: balance1, wallet: wallet1 } = client.fundWallet()
|
321
|
+
* const { balance: balance2, wallet: wallet2 } = client.fundWallet()
|
322
|
+
*
|
323
|
+
* const transaction = {
|
324
|
+
* TransactionType: 'Payment',
|
325
|
+
* Account: wallet1.address,
|
326
|
+
* Destination: wallet2.address,
|
327
|
+
* Amount: '10'
|
328
|
+
* }
|
329
|
+
*
|
330
|
+
* try {
|
331
|
+
* await client.autofill(transaction)
|
332
|
+
* const { tx_blob: signed_tx_blob, hash} = await wallet1.sign(transaction)
|
333
|
+
* console.log(signed_tx_blob)
|
334
|
+
* } catch (error) {
|
335
|
+
* console.error(`Failed to sign transaction: ${error}`)
|
336
|
+
* }
|
337
|
+
* const result = await client.submit(signed_tx_blob)
|
338
|
+
* await client.disconnect()
|
339
|
+
* }
|
340
|
+
*
|
341
|
+
* signTransaction()
|
342
|
+
* ```
|
343
|
+
* In order for a transaction to be validated, it must be signed by the account sending the transaction to prove
|
344
|
+
* That the owner is actually the one deciding to take that action.
|
345
|
+
*
|
346
|
+
* In this example, we created, signed, and then submitted a transaction to testnet. You may notice that the
|
347
|
+
* Output of `sign` includes a `tx_blob` and a `hash`, both of which are needed to submit & verify the results.
|
348
|
+
* Note: If you pass a `Wallet` to `client.submit` or `client.submitAndWait` it will do signing like this under the hood.
|
349
|
+
*
|
350
|
+
* `tx_blob` is a binary representation of a transaction on the XRP Ledger. It's essentially a byte array
|
351
|
+
* that encodes all of the data necessary to execute the transaction, including the source address, the destination
|
352
|
+
* address, the amount, and any additional fields required for the specific transaction type.
|
353
|
+
*
|
354
|
+
* `hash` is a unique identifier that's generated from the signed transaction data on the XRP Ledger. It's essentially
|
355
|
+
* A cryptographic digest of the signed transaction blob, created using a hash function. The signed transaction hash is
|
356
|
+
* Useful for identifying and tracking specific transactions on the XRP Ledger. It can be used to query transaction
|
357
|
+
* Information, verify the authenticity of a transaction, and detect any tampering with the transaction data.
|
358
|
+
*
|
359
|
+
* @param this - Wallet instance.
|
360
|
+
* @param transaction - A transaction to be signed offline.
|
361
|
+
* @param multisign - Specify true/false to use multisign or actual address (classic/x-address) to make multisign tx request.
|
362
|
+
* @returns A signed transaction.
|
363
|
+
* @throws ValidationError if the transaction is already signed or does not encode/decode to same result.
|
364
|
+
* @throws XrplError if the issued currency being signed is XRP ignoring case.
|
365
|
+
*/
|
366
|
+
// eslint-disable-next-line max-lines-per-function -- introduced more checks to support both string and boolean inputs.
|
367
|
+
public sign(
|
368
|
+
this: Wallet,
|
369
|
+
transaction: Transaction,
|
370
|
+
multisign?: boolean | string,
|
371
|
+
): {
|
372
|
+
tx_blob: string
|
373
|
+
hash: string
|
374
|
+
} {
|
375
|
+
let multisignAddress: boolean | string = false
|
376
|
+
if (typeof multisign === 'string' && multisign.startsWith('X')) {
|
377
|
+
multisignAddress = multisign
|
378
|
+
} else if (multisign) {
|
379
|
+
multisignAddress = this.classicAddress
|
380
|
+
}
|
381
|
+
|
382
|
+
// clean null & undefined valued tx properties
|
383
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- ensure Transaction flows through
|
384
|
+
const tx = omitBy(
|
385
|
+
{ ...transaction },
|
386
|
+
(value) => value == null,
|
387
|
+
) as unknown as Transaction
|
388
|
+
|
389
|
+
if (tx.TxnSignature || tx.Signers) {
|
390
|
+
throw new ValidationError(
|
391
|
+
'txJSON must not contain "TxnSignature" or "Signers" properties',
|
392
|
+
)
|
393
|
+
}
|
394
|
+
|
395
|
+
removeTrailingZeros(tx)
|
396
|
+
|
397
|
+
/*
|
398
|
+
* This will throw a more clear error for JS users if the supplied transaction has incorrect formatting
|
399
|
+
*/
|
400
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- validate does not accept Transaction type
|
401
|
+
validate(tx as unknown as Record<string, unknown>)
|
402
|
+
|
403
|
+
const txToSignAndEncode = { ...tx }
|
404
|
+
|
405
|
+
txToSignAndEncode.SigningPubKey = multisignAddress ? '' : this.publicKey
|
406
|
+
|
407
|
+
if (multisignAddress) {
|
408
|
+
const signer = {
|
409
|
+
Account: multisignAddress,
|
410
|
+
SigningPubKey: this.publicKey,
|
411
|
+
TxnSignature: computeSignature(
|
412
|
+
txToSignAndEncode,
|
413
|
+
this.privateKey,
|
414
|
+
multisignAddress,
|
415
|
+
),
|
416
|
+
}
|
417
|
+
txToSignAndEncode.Signers = [{ Signer: signer }]
|
418
|
+
} else {
|
419
|
+
txToSignAndEncode.TxnSignature = computeSignature(
|
420
|
+
txToSignAndEncode,
|
421
|
+
this.privateKey,
|
422
|
+
)
|
423
|
+
}
|
424
|
+
|
425
|
+
const serialized = encode(txToSignAndEncode)
|
426
|
+
return {
|
427
|
+
tx_blob: serialized,
|
428
|
+
hash: hashSignedTx(serialized),
|
429
|
+
}
|
430
|
+
}
|
431
|
+
|
432
|
+
/**
|
433
|
+
* Verifies a signed transaction offline.
|
434
|
+
*
|
435
|
+
* @param signedTransaction - A signed transaction (hex string of signTransaction result) to be verified offline.
|
436
|
+
* @returns Returns true if a signedTransaction is valid.
|
437
|
+
*/
|
438
|
+
public verifyTransaction(signedTransaction: Transaction | string): boolean {
|
439
|
+
const tx =
|
440
|
+
typeof signedTransaction === 'string'
|
441
|
+
? decode(signedTransaction)
|
442
|
+
: signedTransaction
|
443
|
+
const messageHex: string = encodeForSigning(tx)
|
444
|
+
const signature = tx.TxnSignature
|
445
|
+
return verify(messageHex, signature, this.publicKey)
|
446
|
+
}
|
447
|
+
|
448
|
+
/**
|
449
|
+
* Gets an X-address in Testnet/Mainnet format.
|
450
|
+
*
|
451
|
+
* @param tag - A tag to be included within the X-address.
|
452
|
+
* @param isTestnet - A boolean to indicate if X-address should be in Testnet (true) or Mainnet (false) format.
|
453
|
+
* @returns An X-address.
|
454
|
+
*/
|
455
|
+
public getXAddress(tag: number | false = false, isTestnet = false): string {
|
456
|
+
return classicAddressToXAddress(this.classicAddress, tag, isTestnet)
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
/**
|
461
|
+
* Signs a transaction with the proper signing encoding.
|
462
|
+
*
|
463
|
+
* @param tx - A transaction to sign.
|
464
|
+
* @param privateKey - A key to sign the transaction with.
|
465
|
+
* @param signAs - Multisign only. An account address to include in the Signer field.
|
466
|
+
* Can be either a classic address or an XAddress.
|
467
|
+
* @returns A signed transaction in the proper format.
|
468
|
+
*/
|
469
|
+
function computeSignature(
|
470
|
+
tx: Transaction,
|
471
|
+
privateKey: string,
|
472
|
+
signAs?: string,
|
473
|
+
): string {
|
474
|
+
if (signAs) {
|
475
|
+
const classicAddress = isValidXAddress(signAs)
|
476
|
+
? xAddressToClassicAddress(signAs).classicAddress
|
477
|
+
: signAs
|
478
|
+
|
479
|
+
return sign(encodeForMultisigning(tx, classicAddress), privateKey)
|
480
|
+
}
|
481
|
+
return sign(encodeForSigning(tx), privateKey)
|
482
|
+
}
|
483
|
+
|
484
|
+
/**
|
485
|
+
* Remove trailing insignificant zeros for non-XRP Payment amount.
|
486
|
+
* This resolves the serialization mismatch bug when encoding/decoding a non-XRP Payment transaction
|
487
|
+
* with an amount that contains trailing insignificant zeros; for example, '123.4000' would serialize
|
488
|
+
* to '123.4' and cause a mismatch.
|
489
|
+
*
|
490
|
+
* @param tx - The transaction prior to signing.
|
491
|
+
*/
|
492
|
+
function removeTrailingZeros(tx: Transaction): void {
|
493
|
+
if (
|
494
|
+
tx.TransactionType === 'Payment' &&
|
495
|
+
typeof tx.Amount !== 'string' &&
|
496
|
+
tx.Amount.value.includes('.') &&
|
497
|
+
tx.Amount.value.endsWith('0')
|
498
|
+
) {
|
499
|
+
// eslint-disable-next-line no-param-reassign -- Required to update Transaction.Amount.value
|
500
|
+
tx.Amount = { ...tx.Amount }
|
501
|
+
// eslint-disable-next-line no-param-reassign -- Required to update Transaction.Amount.value
|
502
|
+
tx.Amount.value = new BigNumber(tx.Amount.value).toString()
|
503
|
+
}
|
504
|
+
}
|
@@ -0,0 +1,190 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-magic-numbers -- Doing many bitwise operations which need specific numbers */
|
2
|
+
/* eslint-disable no-bitwise -- Bitwise operators are required for this encoding/decoding */
|
3
|
+
/* eslint-disable id-length -- Bitwise math uses shorthand terms */
|
4
|
+
/*
|
5
|
+
*rfc1751.ts : Converts between 128-bit strings and a human-readable
|
6
|
+
*sequence of words, as defined in RFC1751: "A Convention for
|
7
|
+
*Human-Readable 128-bit Keys", by Daniel L. McDonald.
|
8
|
+
*Ported from rfc1751.py / Python Cryptography Toolkit (public domain).
|
9
|
+
*Copied from https://github.com/bip32/bip32.github.io/blob/master/js/rfc1751.js which
|
10
|
+
*is part of the public domain.
|
11
|
+
*/
|
12
|
+
|
13
|
+
import rfc1751Words from './rfc1751Words.json'
|
14
|
+
|
15
|
+
const rfc1751WordList: string[] = rfc1751Words
|
16
|
+
|
17
|
+
// Added prettier-ignore to allow _BINARY to be on two lines, instead of one entry per line.
|
18
|
+
|
19
|
+
// prettier-ignore
|
20
|
+
const BINARY = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111',
|
21
|
+
'1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111'];
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Convert a number array into a binary string.
|
25
|
+
*
|
26
|
+
* @param key - An array of numbers in base 10.
|
27
|
+
* @returns A binary string.
|
28
|
+
*/
|
29
|
+
function keyToBinary(key: number[]): string {
|
30
|
+
let res = ''
|
31
|
+
for (const num of key) {
|
32
|
+
res += BINARY[num >> 4] + BINARY[num & 0x0f]
|
33
|
+
}
|
34
|
+
return res
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Converts a substring of an encoded secret to its numeric value.
|
39
|
+
*
|
40
|
+
* @param key - The encoded secret.
|
41
|
+
* @param start - The start index to parse from.
|
42
|
+
* @param length - The number of digits to parse after the start index.
|
43
|
+
* @returns The binary value of the substring.
|
44
|
+
*/
|
45
|
+
function extract(key: string, start: number, length: number): number {
|
46
|
+
const subKey = key.substring(start, start + length)
|
47
|
+
let acc = 0
|
48
|
+
for (let index = 0; index < subKey.length; index++) {
|
49
|
+
acc = acc * 2 + subKey.charCodeAt(index) - 48
|
50
|
+
}
|
51
|
+
return acc
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Generates a modified RFC1751 mnemonic in the same way rippled's wallet_propose does.
|
56
|
+
*
|
57
|
+
* @param hex_key - An encoded secret in hex format.
|
58
|
+
* @returns A mnemonic following rippled's modified RFC1751 mnemonic standard.
|
59
|
+
*/
|
60
|
+
function keyToRFC1751Mnemonic(hex_key: string): string {
|
61
|
+
// Remove whitespace and interpret hex
|
62
|
+
const buf = Buffer.from(hex_key.replace(/\s+/gu, ''), 'hex')
|
63
|
+
// Swap byte order and use rfc1751
|
64
|
+
let key: number[] = bufferToArray(swap128(buf))
|
65
|
+
|
66
|
+
// pad to 8 bytes
|
67
|
+
const padding: number[] = []
|
68
|
+
for (let index = 0; index < (8 - (key.length % 8)) % 8; index++) {
|
69
|
+
padding.push(0)
|
70
|
+
}
|
71
|
+
key = padding.concat(key)
|
72
|
+
|
73
|
+
const english: string[] = []
|
74
|
+
for (let index = 0; index < key.length; index += 8) {
|
75
|
+
const subKey = key.slice(index, index + 8)
|
76
|
+
|
77
|
+
// add parity
|
78
|
+
let skbin = keyToBinary(subKey)
|
79
|
+
let parity = 0
|
80
|
+
for (let j = 0; j < 64; j += 2) {
|
81
|
+
parity += extract(skbin, j, 2)
|
82
|
+
}
|
83
|
+
subKey.push((parity << 6) & 0xff)
|
84
|
+
|
85
|
+
skbin = keyToBinary(subKey)
|
86
|
+
for (let j = 0; j < 64; j += 11) {
|
87
|
+
english.push(rfc1751WordList[extract(skbin, j, 11)])
|
88
|
+
}
|
89
|
+
}
|
90
|
+
return english.join(' ')
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Converts an english mnemonic following rippled's modified RFC1751 standard to an encoded hex secret.
|
95
|
+
*
|
96
|
+
* @param english - A mnemonic generated using ripple's modified RFC1751 standard.
|
97
|
+
* @throws Error if the parity after decoding does not match.
|
98
|
+
* @returns A Buffer containing an encoded secret.
|
99
|
+
*/
|
100
|
+
function rfc1751MnemonicToKey(english: string): Buffer {
|
101
|
+
const words = english.split(' ')
|
102
|
+
let key: number[] = []
|
103
|
+
|
104
|
+
for (let index = 0; index < words.length; index += 6) {
|
105
|
+
const { subKey, word }: { subKey: number[]; word: string } = getSubKey(
|
106
|
+
words,
|
107
|
+
index,
|
108
|
+
)
|
109
|
+
|
110
|
+
// check parity
|
111
|
+
const skbin = keyToBinary(subKey)
|
112
|
+
let parity = 0
|
113
|
+
for (let j = 0; j < 64; j += 2) {
|
114
|
+
parity += extract(skbin, j, 2)
|
115
|
+
}
|
116
|
+
const cs0 = extract(skbin, 64, 2)
|
117
|
+
const cs1 = parity & 3
|
118
|
+
if (cs0 !== cs1) {
|
119
|
+
throw new Error(`Parity error at ${word}`)
|
120
|
+
}
|
121
|
+
|
122
|
+
key = key.concat(subKey.slice(0, 8))
|
123
|
+
}
|
124
|
+
|
125
|
+
// This is a step specific to the XRPL's implementation
|
126
|
+
const bufferKey = swap128(Buffer.from(key))
|
127
|
+
return bufferKey
|
128
|
+
}
|
129
|
+
|
130
|
+
function getSubKey(
|
131
|
+
words: string[],
|
132
|
+
index: number,
|
133
|
+
): { subKey: number[]; word: string } {
|
134
|
+
const sublist = words.slice(index, index + 6)
|
135
|
+
let bits = 0
|
136
|
+
const ch = [0, 0, 0, 0, 0, 0, 0, 0, 0]
|
137
|
+
let word = ''
|
138
|
+
for (word of sublist) {
|
139
|
+
const idx = rfc1751WordList.indexOf(word.toUpperCase())
|
140
|
+
if (idx === -1) {
|
141
|
+
throw new TypeError(
|
142
|
+
`Expected an RFC1751 word, but received '${word}'. ` +
|
143
|
+
`For the full list of words in the RFC1751 encoding see https://datatracker.ietf.org/doc/html/rfc1751`,
|
144
|
+
)
|
145
|
+
}
|
146
|
+
const shift = (8 - ((bits + 11) % 8)) % 8
|
147
|
+
const y = idx << shift
|
148
|
+
const cl = y >> 16
|
149
|
+
const cc = (y >> 8) & 0xff
|
150
|
+
const cr = y & 0xff
|
151
|
+
const t = Math.floor(bits / 8)
|
152
|
+
if (shift > 5) {
|
153
|
+
ch[t] |= cl
|
154
|
+
ch[t + 1] |= cc
|
155
|
+
ch[t + 2] |= cr
|
156
|
+
} else if (shift > -3) {
|
157
|
+
ch[t] |= cc
|
158
|
+
ch[t + 1] |= cr
|
159
|
+
} else {
|
160
|
+
ch[t] |= cr
|
161
|
+
}
|
162
|
+
bits += 11
|
163
|
+
}
|
164
|
+
const subKey: number[] = ch.slice()
|
165
|
+
return { subKey, word }
|
166
|
+
}
|
167
|
+
|
168
|
+
function bufferToArray(buf: Buffer): number[] {
|
169
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We know the end type */
|
170
|
+
return Array.prototype.slice.call(buf) as number[]
|
171
|
+
}
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Swap the byte order of a 128-bit buffer.
|
175
|
+
*
|
176
|
+
* @param buf - A 128-bit (16 byte) buffer
|
177
|
+
* @returns A buffer containing the same data with reversed endianness
|
178
|
+
*/
|
179
|
+
function swap128(buf: Buffer): Buffer {
|
180
|
+
// Interprets buffer as an array of (two, in this case) 64-bit numbers and swaps byte order in-place.
|
181
|
+
const reversedBytes = buf.swap64()
|
182
|
+
|
183
|
+
// Swap the two 64-bit numbers since our buffer is 128 bits.
|
184
|
+
return Buffer.concat(
|
185
|
+
[reversedBytes.slice(8, 16), reversedBytes.slice(0, 8)],
|
186
|
+
16,
|
187
|
+
)
|
188
|
+
}
|
189
|
+
|
190
|
+
export { rfc1751MnemonicToKey, keyToRFC1751Mnemonic }
|