xrpl 2.14.0 → 3.0.0-beta.1
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/README.md +2 -2
- package/build/xrpl-latest-min.js +1 -1
- package/build/xrpl-latest-min.js.map +1 -1
- package/build/xrpl-latest.js +15451 -74357
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/authorizeChannel.d.ts +3 -0
- package/dist/npm/Wallet/authorizeChannel.d.ts.map +1 -0
- package/dist/npm/Wallet/authorizeChannel.js +14 -0
- package/dist/npm/Wallet/authorizeChannel.js.map +1 -0
- package/dist/npm/Wallet/defaultFaucets.js +1 -1
- package/dist/npm/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/Wallet/fundWallet.d.ts +17 -3
- package/dist/npm/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/Wallet/fundWallet.js +53 -78
- package/dist/npm/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/Wallet/index.d.ts.map +1 -1
- package/dist/npm/Wallet/index.js +24 -23
- package/dist/npm/Wallet/index.js.map +1 -1
- package/dist/npm/Wallet/rfc1751.d.ts +1 -2
- package/dist/npm/Wallet/rfc1751.d.ts.map +1 -1
- package/dist/npm/Wallet/rfc1751.js +21 -5
- package/dist/npm/Wallet/rfc1751.js.map +1 -1
- package/dist/npm/Wallet/signer.d.ts +2 -4
- package/dist/npm/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/Wallet/signer.js +19 -14
- package/dist/npm/Wallet/signer.js.map +1 -1
- package/dist/npm/Wallet/walletFromSecretNumbers.js +2 -2
- package/dist/npm/Wallet/walletFromSecretNumbers.js.map +1 -1
- package/dist/npm/client/RequestManager.d.ts +3 -2
- package/dist/npm/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/client/RequestManager.js +25 -1
- package/dist/npm/client/RequestManager.js.map +1 -1
- package/dist/npm/client/connection.d.ts +8 -11
- package/dist/npm/client/connection.d.ts.map +1 -1
- package/dist/npm/client/connection.js +11 -57
- package/dist/npm/client/connection.js.map +1 -1
- package/dist/npm/client/index.d.ts +56 -79
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js +155 -42
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/client/partialPayment.d.ts +4 -2
- package/dist/npm/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/client/partialPayment.js.map +1 -1
- package/dist/npm/errors.d.ts.map +1 -1
- package/dist/npm/errors.js +1 -2
- package/dist/npm/errors.js.map +1 -1
- package/dist/npm/index.d.ts +1 -1
- package/dist/npm/index.d.ts.map +1 -1
- package/dist/npm/index.js +1 -3
- package/dist/npm/index.js.map +1 -1
- package/dist/npm/models/ledger/AccountRoot.js +1 -1
- package/dist/npm/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/models/ledger/Ledger.d.ts +2 -2
- package/dist/npm/models/ledger/Ledger.d.ts.map +1 -1
- package/dist/npm/models/ledger/Offer.js +1 -1
- package/dist/npm/models/ledger/Offer.js.map +1 -1
- package/dist/npm/models/ledger/RippleState.js +1 -1
- package/dist/npm/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/models/ledger/SignerList.js +1 -1
- package/dist/npm/models/ledger/SignerList.js.map +1 -1
- package/dist/npm/models/methods/index.d.ts +12 -1
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledger.d.ts +35 -7
- package/dist/npm/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/models/methods/submit.d.ts +2 -2
- package/dist/npm/models/methods/submit.d.ts.map +1 -1
- package/dist/npm/models/methods/subscribe.d.ts +3 -0
- package/dist/npm/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/models/methods/tx.d.ts +2 -3
- package/dist/npm/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMDeposit.js +1 -1
- package/dist/npm/models/transactions/AMMDeposit.js.map +1 -1
- package/dist/npm/models/transactions/AMMWithdraw.js +1 -1
- package/dist/npm/models/transactions/AMMWithdraw.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenAcceptOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenCancelOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.js +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.d.ts +4 -0
- package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.js +1 -1
- package/dist/npm/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/models/transactions/XChainModifyBridge.js +1 -1
- package/dist/npm/models/transactions/XChainModifyBridge.js.map +1 -1
- package/dist/npm/models/transactions/accountSet.js +2 -2
- package/dist/npm/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/models/transactions/enableAmendment.js +1 -1
- package/dist/npm/models/transactions/enableAmendment.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +1 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/metadata.d.ts +9 -1
- package/dist/npm/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/models/transactions/metadata.js.map +1 -1
- package/dist/npm/models/transactions/offerCreate.js +1 -1
- package/dist/npm/models/transactions/offerCreate.js.map +1 -1
- package/dist/npm/models/transactions/payment.d.ts +5 -0
- package/dist/npm/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/models/transactions/payment.js +1 -1
- package/dist/npm/models/transactions/payment.js.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +6 -4
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/transactions/trustSet.js +1 -1
- package/dist/npm/models/transactions/trustSet.js.map +1 -1
- package/dist/npm/snippets/src/bridgeTransfer.js +2 -2
- package/dist/npm/snippets/src/bridgeTransfer.js.map +1 -1
- package/dist/npm/snippets/src/getTransaction.js +1 -1
- package/dist/npm/snippets/src/getTransaction.js.map +1 -1
- package/dist/npm/snippets/src/paths.js +2 -3
- package/dist/npm/snippets/src/paths.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/authorizeChannel.d.ts +3 -0
- package/dist/npm/src/Wallet/authorizeChannel.d.ts.map +1 -0
- package/dist/npm/src/Wallet/authorizeChannel.js +14 -0
- package/dist/npm/src/Wallet/authorizeChannel.js.map +1 -0
- package/dist/npm/src/Wallet/defaultFaucets.js +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.d.ts +17 -3
- package/dist/npm/src/Wallet/fundWallet.d.ts.map +1 -1
- package/dist/npm/src/Wallet/fundWallet.js +53 -78
- package/dist/npm/src/Wallet/fundWallet.js.map +1 -1
- package/dist/npm/src/Wallet/index.d.ts.map +1 -1
- package/dist/npm/src/Wallet/index.js +24 -23
- package/dist/npm/src/Wallet/index.js.map +1 -1
- package/dist/npm/src/Wallet/rfc1751.d.ts +1 -2
- package/dist/npm/src/Wallet/rfc1751.d.ts.map +1 -1
- package/dist/npm/src/Wallet/rfc1751.js +21 -5
- package/dist/npm/src/Wallet/rfc1751.js.map +1 -1
- package/dist/npm/src/Wallet/signer.d.ts +2 -4
- package/dist/npm/src/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/src/Wallet/signer.js +19 -14
- package/dist/npm/src/Wallet/signer.js.map +1 -1
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js +2 -2
- package/dist/npm/src/Wallet/walletFromSecretNumbers.js.map +1 -1
- package/dist/npm/src/client/RequestManager.d.ts +3 -2
- package/dist/npm/src/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/src/client/RequestManager.js +25 -1
- package/dist/npm/src/client/RequestManager.js.map +1 -1
- package/dist/npm/src/client/connection.d.ts +8 -11
- package/dist/npm/src/client/connection.d.ts.map +1 -1
- package/dist/npm/src/client/connection.js +11 -57
- package/dist/npm/src/client/connection.js.map +1 -1
- package/dist/npm/src/client/index.d.ts +56 -79
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js +155 -42
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/client/partialPayment.d.ts +4 -2
- package/dist/npm/src/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/src/client/partialPayment.js.map +1 -1
- package/dist/npm/src/errors.d.ts.map +1 -1
- package/dist/npm/src/errors.js +1 -2
- package/dist/npm/src/errors.js.map +1 -1
- package/dist/npm/src/index.d.ts +1 -1
- package/dist/npm/src/index.d.ts.map +1 -1
- package/dist/npm/src/index.js +1 -3
- package/dist/npm/src/index.js.map +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js +1 -1
- package/dist/npm/src/models/ledger/AccountRoot.js.map +1 -1
- package/dist/npm/src/models/ledger/Ledger.d.ts +2 -2
- package/dist/npm/src/models/ledger/Ledger.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Offer.js +1 -1
- package/dist/npm/src/models/ledger/Offer.js.map +1 -1
- package/dist/npm/src/models/ledger/RippleState.js +1 -1
- package/dist/npm/src/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/src/models/ledger/SignerList.js +1 -1
- package/dist/npm/src/models/ledger/SignerList.js.map +1 -1
- package/dist/npm/src/models/methods/index.d.ts +12 -1
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledger.d.ts +35 -7
- package/dist/npm/src/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/src/models/methods/submit.d.ts +2 -2
- package/dist/npm/src/models/methods/submit.d.ts.map +1 -1
- package/dist/npm/src/models/methods/subscribe.d.ts +3 -0
- package/dist/npm/src/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/src/models/methods/tx.d.ts +2 -3
- package/dist/npm/src/models/methods/tx.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMDeposit.js +1 -1
- package/dist/npm/src/models/transactions/AMMDeposit.js.map +1 -1
- package/dist/npm/src/models/transactions/AMMWithdraw.js +1 -1
- package/dist/npm/src/models/transactions/AMMWithdraw.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenAcceptOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCancelOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.js +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts +4 -0
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/src/models/transactions/XChainModifyBridge.js +1 -1
- package/dist/npm/src/models/transactions/XChainModifyBridge.js.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.js +2 -2
- package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/src/models/transactions/enableAmendment.js +1 -1
- package/dist/npm/src/models/transactions/enableAmendment.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +1 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/metadata.d.ts +9 -1
- package/dist/npm/src/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/metadata.js.map +1 -1
- package/dist/npm/src/models/transactions/offerCreate.js +1 -1
- package/dist/npm/src/models/transactions/offerCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/payment.d.ts +5 -0
- package/dist/npm/src/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/payment.js +1 -1
- package/dist/npm/src/models/transactions/payment.js.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +6 -4
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/transactions/trustSet.js +1 -1
- package/dist/npm/src/models/transactions/trustSet.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts +6 -2
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +9 -28
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/src/sugar/balances.d.ts +2 -17
- package/dist/npm/src/sugar/balances.d.ts.map +1 -1
- package/dist/npm/src/sugar/balances.js +2 -60
- package/dist/npm/src/sugar/balances.js.map +1 -1
- package/dist/npm/src/sugar/getOrderbook.d.ts +19 -5
- package/dist/npm/src/sugar/getOrderbook.d.ts.map +1 -1
- package/dist/npm/src/sugar/getOrderbook.js +72 -53
- package/dist/npm/src/sugar/getOrderbook.js.map +1 -1
- package/dist/npm/src/sugar/index.d.ts +0 -4
- package/dist/npm/src/sugar/index.d.ts.map +1 -1
- package/dist/npm/src/sugar/index.js +0 -13
- package/dist/npm/src/sugar/index.js.map +1 -1
- package/dist/npm/src/sugar/submit.d.ts +7 -11
- package/dist/npm/src/sugar/submit.d.ts.map +1 -1
- package/dist/npm/src/sugar/submit.js +5 -22
- package/dist/npm/src/sugar/submit.js.map +1 -1
- package/dist/npm/src/utils/collections.d.ts +5 -0
- package/dist/npm/src/utils/collections.d.ts.map +1 -0
- package/dist/npm/src/utils/collections.js +24 -0
- package/dist/npm/src/utils/collections.js.map +1 -0
- package/dist/npm/src/utils/getBalanceChanges.d.ts.map +1 -1
- package/dist/npm/src/utils/getBalanceChanges.js +3 -4
- package/dist/npm/src/utils/getBalanceChanges.js.map +1 -1
- package/dist/npm/src/utils/getNFTokenID.d.ts.map +1 -1
- package/dist/npm/src/utils/getNFTokenID.js +8 -8
- package/dist/npm/src/utils/getNFTokenID.js.map +1 -1
- package/dist/npm/src/utils/hashes/SHAMap/node.js +1 -1
- package/dist/npm/src/utils/hashes/SHAMap/node.js.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.d.ts +1 -2
- package/dist/npm/src/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.js +7 -7
- package/dist/npm/src/utils/hashes/hashLedger.js.map +1 -1
- package/dist/npm/src/utils/hashes/index.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/index.js +3 -2
- package/dist/npm/src/utils/hashes/index.js.map +1 -1
- package/dist/npm/src/utils/hashes/sha512Half.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/sha512Half.js +4 -7
- package/dist/npm/src/utils/hashes/sha512Half.js.map +1 -1
- package/dist/npm/src/utils/index.d.ts.map +1 -1
- package/dist/npm/src/utils/index.js +6 -29
- package/dist/npm/src/utils/index.js.map +1 -1
- package/dist/npm/src/utils/parseNFTokenID.d.ts.map +1 -1
- package/dist/npm/src/utils/parseNFTokenID.js +2 -1
- package/dist/npm/src/utils/parseNFTokenID.js.map +1 -1
- package/dist/npm/src/utils/stringConversion.d.ts +1 -2
- package/dist/npm/src/utils/stringConversion.d.ts.map +1 -1
- package/dist/npm/src/utils/stringConversion.js +3 -2
- package/dist/npm/src/utils/stringConversion.js.map +1 -1
- package/dist/npm/src/utils/xrpConversion.d.ts +1 -1
- package/dist/npm/src/utils/xrpConversion.js +1 -1
- package/dist/npm/src/utils/xrpConversion.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts +6 -2
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +9 -28
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/balances.d.ts +2 -17
- package/dist/npm/sugar/balances.d.ts.map +1 -1
- package/dist/npm/sugar/balances.js +2 -60
- package/dist/npm/sugar/balances.js.map +1 -1
- package/dist/npm/sugar/getOrderbook.d.ts +19 -5
- package/dist/npm/sugar/getOrderbook.d.ts.map +1 -1
- package/dist/npm/sugar/getOrderbook.js +72 -53
- package/dist/npm/sugar/getOrderbook.js.map +1 -1
- package/dist/npm/sugar/index.d.ts +0 -4
- package/dist/npm/sugar/index.d.ts.map +1 -1
- package/dist/npm/sugar/index.js +0 -13
- package/dist/npm/sugar/index.js.map +1 -1
- package/dist/npm/sugar/submit.d.ts +7 -11
- package/dist/npm/sugar/submit.d.ts.map +1 -1
- package/dist/npm/sugar/submit.js +5 -22
- package/dist/npm/sugar/submit.js.map +1 -1
- package/dist/npm/utils/collections.d.ts +5 -0
- package/dist/npm/utils/collections.d.ts.map +1 -0
- package/dist/npm/utils/collections.js +24 -0
- package/dist/npm/utils/collections.js.map +1 -0
- package/dist/npm/utils/getBalanceChanges.d.ts.map +1 -1
- package/dist/npm/utils/getBalanceChanges.js +3 -4
- package/dist/npm/utils/getBalanceChanges.js.map +1 -1
- package/dist/npm/utils/getNFTokenID.d.ts.map +1 -1
- package/dist/npm/utils/getNFTokenID.js +8 -8
- package/dist/npm/utils/getNFTokenID.js.map +1 -1
- package/dist/npm/utils/hashes/SHAMap/node.js +1 -1
- package/dist/npm/utils/hashes/SHAMap/node.js.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.d.ts +1 -2
- package/dist/npm/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.js +7 -7
- package/dist/npm/utils/hashes/hashLedger.js.map +1 -1
- package/dist/npm/utils/hashes/index.d.ts.map +1 -1
- package/dist/npm/utils/hashes/index.js +3 -2
- package/dist/npm/utils/hashes/index.js.map +1 -1
- package/dist/npm/utils/hashes/sha512Half.d.ts.map +1 -1
- package/dist/npm/utils/hashes/sha512Half.js +4 -7
- package/dist/npm/utils/hashes/sha512Half.js.map +1 -1
- package/dist/npm/utils/index.d.ts.map +1 -1
- package/dist/npm/utils/index.js +6 -29
- package/dist/npm/utils/index.js.map +1 -1
- package/dist/npm/utils/parseNFTokenID.d.ts.map +1 -1
- package/dist/npm/utils/parseNFTokenID.js +2 -1
- package/dist/npm/utils/parseNFTokenID.js.map +1 -1
- package/dist/npm/utils/stringConversion.d.ts +1 -2
- package/dist/npm/utils/stringConversion.d.ts.map +1 -1
- package/dist/npm/utils/stringConversion.js +3 -2
- package/dist/npm/utils/stringConversion.js.map +1 -1
- package/dist/npm/utils/xrpConversion.d.ts +1 -1
- package/dist/npm/utils/xrpConversion.js +1 -1
- package/dist/npm/utils/xrpConversion.js.map +1 -1
- package/package.json +23 -25
- package/src/Wallet/authorizeChannel.ts +26 -0
- package/src/Wallet/fundWallet.ts +153 -214
- package/src/Wallet/index.ts +28 -25
- package/src/Wallet/rfc1751.ts +45 -16
- package/src/Wallet/signer.ts +34 -44
- package/src/Wallet/walletFromSecretNumbers.ts +1 -1
- package/src/client/RequestManager.ts +40 -14
- package/src/client/connection.ts +26 -93
- package/src/client/index.ts +706 -274
- package/src/client/partialPayment.ts +16 -14
- package/src/errors.ts +1 -3
- package/src/index.ts +1 -3
- package/src/models/ledger/Ledger.ts +3 -9
- package/src/models/methods/index.ts +177 -0
- package/src/models/methods/ledger.ts +149 -20
- package/src/models/methods/submit.ts +2 -2
- package/src/models/methods/subscribe.ts +36 -0
- package/src/models/methods/tx.ts +3 -5
- package/src/models/transactions/NFTokenAcceptOffer.ts +6 -0
- package/src/models/transactions/NFTokenCancelOffer.ts +6 -0
- package/src/models/transactions/NFTokenCreateOffer.ts +6 -0
- package/src/models/transactions/NFTokenMint.ts +6 -0
- package/src/models/transactions/index.ts +1 -0
- package/src/models/transactions/metadata.ts +31 -1
- package/src/models/transactions/payment.ts +6 -0
- package/src/models/transactions/transaction.ts +21 -5
- package/src/sugar/autofill.ts +84 -88
- package/src/sugar/balances.ts +8 -116
- package/src/sugar/getOrderbook.ts +138 -61
- package/src/sugar/index.ts +0 -8
- package/src/sugar/submit.ts +128 -140
- package/src/utils/collections.ts +57 -0
- package/src/utils/getBalanceChanges.ts +2 -3
- package/src/utils/getNFTokenID.ts +18 -16
- package/src/utils/hashes/hashLedger.ts +7 -9
- package/src/utils/hashes/index.ts +3 -2
- package/src/utils/hashes/sha512Half.ts +4 -7
- package/src/utils/index.ts +12 -6
- package/src/utils/parseNFTokenID.ts +2 -1
- package/src/utils/stringConversion.ts +11 -6
- package/src/utils/xrpConversion.ts +2 -2
- package/dist/npm/client/BroadcastClient.d.ts +0 -7
- package/dist/npm/client/BroadcastClient.d.ts.map +0 -1
- package/dist/npm/client/BroadcastClient.js +0 -49
- package/dist/npm/client/BroadcastClient.js.map +0 -1
- package/dist/npm/client/WSWrapper.d.ts +0 -25
- package/dist/npm/client/WSWrapper.d.ts.map +0 -1
- package/dist/npm/client/WSWrapper.js +0 -44
- package/dist/npm/client/WSWrapper.js.map +0 -1
- package/dist/npm/src/client/BroadcastClient.d.ts +0 -7
- package/dist/npm/src/client/BroadcastClient.d.ts.map +0 -1
- package/dist/npm/src/client/BroadcastClient.js +0 -49
- package/dist/npm/src/client/BroadcastClient.js.map +0 -1
- package/dist/npm/src/client/WSWrapper.d.ts +0 -25
- package/dist/npm/src/client/WSWrapper.d.ts.map +0 -1
- package/dist/npm/src/client/WSWrapper.js +0 -44
- package/dist/npm/src/client/WSWrapper.js.map +0 -1
- package/dist/npm/src/sugar/getLedgerIndex.d.ts +0 -3
- package/dist/npm/src/sugar/getLedgerIndex.d.ts.map +0 -1
- package/dist/npm/src/sugar/getLedgerIndex.js +0 -22
- package/dist/npm/src/sugar/getLedgerIndex.js.map +0 -1
- package/dist/npm/sugar/getLedgerIndex.d.ts +0 -3
- package/dist/npm/sugar/getLedgerIndex.d.ts.map +0 -1
- package/dist/npm/sugar/getLedgerIndex.js +0 -22
- package/dist/npm/sugar/getLedgerIndex.js.map +0 -1
- package/src/client/BroadcastClient.ts +0 -84
- package/src/client/WSWrapper.ts +0 -106
- package/src/sugar/getLedgerIndex.ts +0 -15
package/src/Wallet/index.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
import { HDKey } from '@scure/bip32'
|
2
|
+
import { mnemonicToSeedSync, validateMnemonic } from '@scure/bip39'
|
3
|
+
import { wordlist } from '@scure/bip39/wordlists/english'
|
4
|
+
import { bytesToHex } from '@xrplf/isomorphic/utils'
|
1
5
|
import BigNumber from 'bignumber.js'
|
2
|
-
import { fromSeed } from 'bip32'
|
3
|
-
import { mnemonicToSeedSync, validateMnemonic } from 'bip39'
|
4
|
-
import omitBy from 'lodash/omitBy'
|
5
6
|
import {
|
6
7
|
classicAddressToXAddress,
|
7
8
|
isValidXAddress,
|
@@ -9,7 +10,6 @@ import {
|
|
9
10
|
encodeSeed,
|
10
11
|
} from 'ripple-address-codec'
|
11
12
|
import {
|
12
|
-
decode,
|
13
13
|
encodeForSigning,
|
14
14
|
encodeForMultisigning,
|
15
15
|
encode,
|
@@ -18,7 +18,6 @@ import {
|
|
18
18
|
deriveAddress,
|
19
19
|
deriveKeypair,
|
20
20
|
generateSeed,
|
21
|
-
verify,
|
22
21
|
sign,
|
23
22
|
} from 'ripple-keypairs'
|
24
23
|
|
@@ -26,15 +25,28 @@ import ECDSA from '../ECDSA'
|
|
26
25
|
import { ValidationError } from '../errors'
|
27
26
|
import { Transaction, validate } from '../models/transactions'
|
28
27
|
import { ensureClassicAddress } from '../sugar/utils'
|
28
|
+
import { omitBy } from '../utils/collections'
|
29
29
|
import { hashSignedTx } from '../utils/hashes/hashLedger'
|
30
30
|
|
31
31
|
import { rfc1751MnemonicToKey } from './rfc1751'
|
32
|
+
import { verifySignature } from './signer'
|
32
33
|
|
33
34
|
const DEFAULT_ALGORITHM: ECDSA = ECDSA.ed25519
|
34
35
|
const DEFAULT_DERIVATION_PATH = "m/44'/144'/0'/0/0"
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
type ValidHDKey = HDKey & {
|
38
|
+
privateKey: Uint8Array
|
39
|
+
publicKey: Uint8Array
|
40
|
+
}
|
41
|
+
|
42
|
+
function validateKey(node: HDKey): asserts node is ValidHDKey {
|
43
|
+
if (!(node.privateKey instanceof Uint8Array)) {
|
44
|
+
throw new ValidationError('Unable to derive privateKey from mnemonic input')
|
45
|
+
}
|
46
|
+
|
47
|
+
if (!(node.publicKey instanceof Uint8Array)) {
|
48
|
+
throw new ValidationError('Unable to derive publicKey from mnemonic input')
|
49
|
+
}
|
38
50
|
}
|
39
51
|
|
40
52
|
/**
|
@@ -137,7 +149,7 @@ export class Wallet {
|
|
137
149
|
throw new ValidationError('Invalid cryptographic signing algorithm')
|
138
150
|
}
|
139
151
|
const seed = generateSeed({ algorithm })
|
140
|
-
return Wallet.fromSeed(seed)
|
152
|
+
return Wallet.fromSeed(seed, { algorithm })
|
141
153
|
}
|
142
154
|
|
143
155
|
/**
|
@@ -232,25 +244,21 @@ export class Wallet {
|
|
232
244
|
})
|
233
245
|
}
|
234
246
|
// Otherwise decode using bip39's mnemonic standard
|
235
|
-
if (!validateMnemonic(mnemonic)) {
|
247
|
+
if (!validateMnemonic(mnemonic, wordlist)) {
|
236
248
|
throw new ValidationError(
|
237
249
|
'Unable to parse the given mnemonic using bip39 encoding',
|
238
250
|
)
|
239
251
|
}
|
240
252
|
|
241
253
|
const seed = mnemonicToSeedSync(mnemonic)
|
242
|
-
const masterNode =
|
243
|
-
const node = masterNode.
|
254
|
+
const masterNode = HDKey.fromMasterSeed(seed)
|
255
|
+
const node = masterNode.derive(
|
244
256
|
opts.derivationPath ?? DEFAULT_DERIVATION_PATH,
|
245
257
|
)
|
246
|
-
|
247
|
-
throw new ValidationError(
|
248
|
-
'Unable to derive privateKey from mnemonic input',
|
249
|
-
)
|
250
|
-
}
|
258
|
+
validateKey(node)
|
251
259
|
|
252
|
-
const publicKey =
|
253
|
-
const privateKey =
|
260
|
+
const publicKey = bytesToHex(node.publicKey)
|
261
|
+
const privateKey = bytesToHex(node.privateKey)
|
254
262
|
return new Wallet(publicKey, `00${privateKey}`, {
|
255
263
|
masterAddress: opts.masterAddress,
|
256
264
|
})
|
@@ -434,15 +442,10 @@ export class Wallet {
|
|
434
442
|
*
|
435
443
|
* @param signedTransaction - A signed transaction (hex string of signTransaction result) to be verified offline.
|
436
444
|
* @returns Returns true if a signedTransaction is valid.
|
445
|
+
* @throws {Error} Transaction is missing a signature, TxnSignature
|
437
446
|
*/
|
438
447
|
public verifyTransaction(signedTransaction: Transaction | string): boolean {
|
439
|
-
|
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)
|
448
|
+
return verifySignature(signedTransaction, this.publicKey)
|
446
449
|
}
|
447
450
|
|
448
451
|
/**
|
package/src/Wallet/rfc1751.ts
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
*is part of the public domain.
|
11
11
|
*/
|
12
12
|
|
13
|
+
import { hexToBytes, concat } from '@xrplf/isomorphic/utils'
|
14
|
+
|
13
15
|
import rfc1751Words from './rfc1751Words.json'
|
14
16
|
|
15
17
|
const rfc1751WordList: string[] = rfc1751Words
|
@@ -59,7 +61,7 @@ function extract(key: string, start: number, length: number): number {
|
|
59
61
|
*/
|
60
62
|
function keyToRFC1751Mnemonic(hex_key: string): string {
|
61
63
|
// Remove whitespace and interpret hex
|
62
|
-
const buf =
|
64
|
+
const buf = hexToBytes(hex_key.replace(/\s+/gu, ''))
|
63
65
|
// Swap byte order and use rfc1751
|
64
66
|
let key: number[] = bufferToArray(swap128(buf))
|
65
67
|
|
@@ -97,7 +99,7 @@ function keyToRFC1751Mnemonic(hex_key: string): string {
|
|
97
99
|
* @throws Error if the parity after decoding does not match.
|
98
100
|
* @returns A Buffer containing an encoded secret.
|
99
101
|
*/
|
100
|
-
function rfc1751MnemonicToKey(english: string):
|
102
|
+
function rfc1751MnemonicToKey(english: string): Uint8Array {
|
101
103
|
const words = english.split(' ')
|
102
104
|
let key: number[] = []
|
103
105
|
|
@@ -123,7 +125,7 @@ function rfc1751MnemonicToKey(english: string): Buffer {
|
|
123
125
|
}
|
124
126
|
|
125
127
|
// This is a step specific to the XRPL's implementation
|
126
|
-
const bufferKey = swap128(
|
128
|
+
const bufferKey = swap128(Uint8Array.from(key))
|
127
129
|
return bufferKey
|
128
130
|
}
|
129
131
|
|
@@ -165,26 +167,53 @@ function getSubKey(
|
|
165
167
|
return { subKey, word }
|
166
168
|
}
|
167
169
|
|
168
|
-
function bufferToArray(buf:
|
170
|
+
function bufferToArray(buf: Uint8Array): number[] {
|
169
171
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We know the end type */
|
170
172
|
return Array.prototype.slice.call(buf) as number[]
|
171
173
|
}
|
172
174
|
|
175
|
+
function swap(arr: Uint8Array, n: number, m: number): void {
|
176
|
+
const i = arr[n]
|
177
|
+
// eslint-disable-next-line no-param-reassign -- we have to swap
|
178
|
+
arr[n] = arr[m]
|
179
|
+
// eslint-disable-next-line no-param-reassign -- see above
|
180
|
+
arr[m] = i
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Interprets arr as an array of 64-bit numbers and swaps byte order in 64 bit chunks.
|
185
|
+
* Example of two 64 bit numbers 0000000100000002 => 1000000020000000
|
186
|
+
*
|
187
|
+
* @param arr A Uint8Array representation of one or more 64 bit numbers
|
188
|
+
* @returns Uint8Array An array containing the bytes of 64 bit numbers each with reversed endianness
|
189
|
+
*/
|
190
|
+
function swap64(arr: Uint8Array): Uint8Array {
|
191
|
+
const len = arr.length
|
192
|
+
|
193
|
+
for (let i = 0; i < len; i += 8) {
|
194
|
+
swap(arr, i, i + 7)
|
195
|
+
swap(arr, i + 1, i + 6)
|
196
|
+
swap(arr, i + 2, i + 5)
|
197
|
+
swap(arr, i + 3, i + 4)
|
198
|
+
}
|
199
|
+
|
200
|
+
return arr
|
201
|
+
}
|
202
|
+
|
173
203
|
/**
|
174
|
-
* Swap the byte order of a 128-bit
|
204
|
+
* Swap the byte order of a 128-bit array.
|
205
|
+
* Ex. 0000000100000002 => 2000000010000000
|
175
206
|
*
|
176
|
-
* @param
|
177
|
-
* @returns
|
207
|
+
* @param arr - A 128-bit (16 byte) array
|
208
|
+
* @returns An array containing the same data with reversed endianness
|
178
209
|
*/
|
179
|
-
function swap128(
|
180
|
-
// Interprets
|
181
|
-
|
182
|
-
|
183
|
-
//
|
184
|
-
|
185
|
-
|
186
|
-
16,
|
187
|
-
)
|
210
|
+
function swap128(arr: Uint8Array): Uint8Array {
|
211
|
+
// Interprets arr as an array of (two, in this case) 64-bit numbers and swaps byte order in 64 bit chunks.
|
212
|
+
// Ex. 0000000100000002 => 1000000020000000
|
213
|
+
const reversedBytes = swap64(arr)
|
214
|
+
// Further swap the two 64-bit numbers since our buffer is 128 bits.
|
215
|
+
// Ex. 1000000020000000 => 2000000010000000
|
216
|
+
return concat([reversedBytes.slice(8, 16), reversedBytes.slice(0, 8)])
|
188
217
|
}
|
189
218
|
|
190
219
|
export { rfc1751MnemonicToKey, keyToRFC1751Mnemonic }
|
package/src/Wallet/signer.ts
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
+
import { bytesToHex } from '@xrplf/isomorphic/utils'
|
1
2
|
import { BigNumber } from 'bignumber.js'
|
2
|
-
import { flatMap } from 'lodash'
|
3
3
|
import { decodeAccountID } from 'ripple-address-codec'
|
4
|
-
import {
|
5
|
-
|
6
|
-
encode,
|
7
|
-
encodeForSigning,
|
8
|
-
encodeForSigningClaim,
|
9
|
-
} from 'ripple-binary-codec'
|
10
|
-
import { sign as signWithKeypair, verify } from 'ripple-keypairs'
|
4
|
+
import { decode, encode, encodeForSigning } from 'ripple-binary-codec'
|
5
|
+
import { verify } from 'ripple-keypairs'
|
11
6
|
|
12
7
|
import { ValidationError } from '../errors'
|
13
8
|
import { Signer } from '../models/common'
|
14
9
|
import { Transaction, validate } from '../models/transactions'
|
15
10
|
|
16
|
-
import { Wallet } from '.'
|
17
|
-
|
18
11
|
/**
|
19
12
|
* Takes several transactions with Signer fields (in object or blob form) and creates a
|
20
13
|
* single transaction with all Signers that then gets signed and returned.
|
@@ -62,42 +55,40 @@ function multisign(transactions: Array<Transaction | string>): string {
|
|
62
55
|
return encode(getTransactionWithAllSigners(decodedTransactions))
|
63
56
|
}
|
64
57
|
|
65
|
-
/**
|
66
|
-
* Creates a signature that can be used to redeem a specific amount of XRP from a payment channel.
|
67
|
-
*
|
68
|
-
* @param wallet - The account that will sign for this payment channel.
|
69
|
-
* @param channelId - An id for the payment channel to redeem XRP from.
|
70
|
-
* @param amount - The amount in drops to redeem.
|
71
|
-
* @returns A signature that can be used to redeem a specific amount of XRP from a payment channel.
|
72
|
-
* @category Utilities
|
73
|
-
*/
|
74
|
-
function authorizeChannel(
|
75
|
-
wallet: Wallet,
|
76
|
-
channelId: string,
|
77
|
-
amount: string,
|
78
|
-
): string {
|
79
|
-
const signingData = encodeForSigningClaim({
|
80
|
-
channel: channelId,
|
81
|
-
amount,
|
82
|
-
})
|
83
|
-
|
84
|
-
return signWithKeypair(signingData, wallet.privateKey)
|
85
|
-
}
|
86
|
-
|
87
58
|
/**
|
88
59
|
* Verifies that the given transaction has a valid signature based on public-key encryption.
|
89
60
|
*
|
90
61
|
* @param tx - A transaction to verify the signature of. (Can be in object or encoded string format).
|
62
|
+
* @param [publicKey] Specific public key to use to verify. If not specified the `SigningPublicKey` of tx will be used.
|
91
63
|
* @returns Returns true if tx has a valid signature, and returns false otherwise.
|
64
|
+
* @throws Error when transaction is missing TxnSignature
|
65
|
+
* @throws Error when publicKey is not provided and transaction is missing SigningPubKey
|
92
66
|
* @category Utilities
|
93
67
|
*/
|
94
|
-
function verifySignature(
|
68
|
+
function verifySignature(
|
69
|
+
tx: Transaction | string,
|
70
|
+
publicKey?: string,
|
71
|
+
): boolean {
|
95
72
|
const decodedTx: Transaction = getDecodedTransaction(tx)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
73
|
+
let key = publicKey
|
74
|
+
|
75
|
+
// Need a SignedTransaction class where TxnSignature is not optional.
|
76
|
+
if (typeof decodedTx.TxnSignature !== 'string' || !decodedTx.TxnSignature) {
|
77
|
+
throw new Error('Transaction is missing a signature, TxnSignature')
|
78
|
+
}
|
79
|
+
|
80
|
+
if (!key) {
|
81
|
+
// Need a SignedTransaction class where TxnSignature is not optional.
|
82
|
+
if (
|
83
|
+
typeof decodedTx.SigningPubKey !== 'string' ||
|
84
|
+
!decodedTx.SigningPubKey
|
85
|
+
) {
|
86
|
+
throw new Error('Transaction is missing a public key, SigningPubKey')
|
87
|
+
}
|
88
|
+
key = decodedTx.SigningPubKey
|
89
|
+
}
|
90
|
+
|
91
|
+
return verify(encodeForSigning(decodedTx), decodedTx.TxnSignature, key)
|
101
92
|
}
|
102
93
|
|
103
94
|
/**
|
@@ -128,10 +119,9 @@ function getTransactionWithAllSigners(
|
|
128
119
|
transactions: Transaction[],
|
129
120
|
): Transaction {
|
130
121
|
// Signers must be sorted in the combined transaction - See compareSigners' documentation for more details
|
131
|
-
const sortedSigners: Signer[] =
|
132
|
-
|
133
|
-
(
|
134
|
-
).sort(compareSigners)
|
122
|
+
const sortedSigners: Signer[] = transactions
|
123
|
+
.flatMap((tx) => tx.Signers ?? [])
|
124
|
+
.sort(compareSigners)
|
135
125
|
|
136
126
|
return { ...transactions[0], Signers: sortedSigners }
|
137
127
|
}
|
@@ -155,7 +145,7 @@ function compareSigners(left: Signer, right: Signer): number {
|
|
155
145
|
const NUM_BITS_IN_HEX = 16
|
156
146
|
|
157
147
|
function addressToBigNumber(address: string): BigNumber {
|
158
|
-
const hex =
|
148
|
+
const hex = bytesToHex(decodeAccountID(address))
|
159
149
|
return new BigNumber(hex, NUM_BITS_IN_HEX)
|
160
150
|
}
|
161
151
|
|
@@ -170,4 +160,4 @@ function getDecodedTransaction(txOrBlob: Transaction | string): Transaction {
|
|
170
160
|
return decode(txOrBlob) as unknown as Transaction
|
171
161
|
}
|
172
162
|
|
173
|
-
export {
|
163
|
+
export { verifySignature, multisign }
|
@@ -4,9 +4,15 @@ import {
|
|
4
4
|
TimeoutError,
|
5
5
|
XrplError,
|
6
6
|
} from '../errors'
|
7
|
-
import { Response } from '../models/methods'
|
7
|
+
import { Response, RequestResponseMap } from '../models/methods'
|
8
8
|
import { BaseRequest, ErrorResponse } from '../models/methods/baseMethod'
|
9
9
|
|
10
|
+
interface PromiseEntry<T> {
|
11
|
+
resolve: (value: T | PromiseLike<T>) => void
|
12
|
+
reject: (value: Error) => void
|
13
|
+
timer: ReturnType<typeof setTimeout>
|
14
|
+
}
|
15
|
+
|
10
16
|
/**
|
11
17
|
* Manage all the requests made to the websocket, and their async responses
|
12
18
|
* that come in from the WebSocket. Responses come in over the WS connection
|
@@ -17,13 +23,31 @@ export default class RequestManager {
|
|
17
23
|
private nextId = 0
|
18
24
|
private readonly promisesAwaitingResponse = new Map<
|
19
25
|
string | number,
|
20
|
-
|
21
|
-
|
22
|
-
reject: (value: Error) => void
|
23
|
-
timer: ReturnType<typeof setTimeout>
|
24
|
-
}
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Necessary and typed wrapper in addPromise method
|
27
|
+
PromiseEntry<any>
|
25
28
|
>()
|
26
29
|
|
30
|
+
/**
|
31
|
+
* Adds a promise to the collection of promises awaiting response. Handles typing with generics.
|
32
|
+
*
|
33
|
+
* @template T The generic type parameter representing the resolved value type.
|
34
|
+
* @param newId - The identifier for the new promise.
|
35
|
+
* @param timer - The timer associated with the promise.
|
36
|
+
* @returns A promise that resolves to the specified generic type.
|
37
|
+
*/
|
38
|
+
public async addPromise<R extends BaseRequest, T = RequestResponseMap<R>>(
|
39
|
+
newId: string | number,
|
40
|
+
timer: ReturnType<typeof setTimeout>,
|
41
|
+
): Promise<T> {
|
42
|
+
return new Promise<T>((resolve, reject) => {
|
43
|
+
this.promisesAwaitingResponse.set(newId, {
|
44
|
+
resolve,
|
45
|
+
reject,
|
46
|
+
timer,
|
47
|
+
})
|
48
|
+
})
|
49
|
+
}
|
50
|
+
|
27
51
|
/**
|
28
52
|
* Successfully resolves a request.
|
29
53
|
*
|
@@ -87,10 +111,10 @@ export default class RequestManager {
|
|
87
111
|
* @returns Request ID, new request form, and the promise for resolving the request.
|
88
112
|
* @throws XrplError if request with the same ID is already pending.
|
89
113
|
*/
|
90
|
-
public createRequest<
|
91
|
-
request:
|
114
|
+
public createRequest<R extends BaseRequest, T = RequestResponseMap<R>>(
|
115
|
+
request: R,
|
92
116
|
timeout: number,
|
93
|
-
): [string | number, string, Promise<
|
117
|
+
): [string | number, string, Promise<T>] {
|
94
118
|
let newId: string | number
|
95
119
|
if (request.id == null) {
|
96
120
|
newId = this.nextId
|
@@ -129,11 +153,13 @@ export default class RequestManager {
|
|
129
153
|
request,
|
130
154
|
)
|
131
155
|
}
|
132
|
-
const newPromise = new Promise<
|
133
|
-
(
|
134
|
-
|
135
|
-
|
136
|
-
|
156
|
+
const newPromise = new Promise<T>((resolve, reject) => {
|
157
|
+
this.promisesAwaitingResponse.set(newId, {
|
158
|
+
resolve,
|
159
|
+
reject,
|
160
|
+
timer,
|
161
|
+
})
|
162
|
+
})
|
137
163
|
|
138
164
|
return [newId, newRequest, newPromise]
|
139
165
|
}
|
package/src/client/connection.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
/* eslint-disable max-lines -- Connection is a large file w/ lots of imports/exports */
|
2
|
-
import {
|
3
|
-
import { Agent } from 'http'
|
2
|
+
import type { Agent } from 'http'
|
4
3
|
|
5
|
-
import
|
6
|
-
import WebSocket from 'ws'
|
4
|
+
import { bytesToHex, hexToString } from '@xrplf/isomorphic/utils'
|
5
|
+
import WebSocket, { ClientOptions } from '@xrplf/isomorphic/ws'
|
6
|
+
import { EventEmitter } from 'eventemitter3'
|
7
7
|
|
8
8
|
import {
|
9
9
|
DisconnectedError,
|
@@ -11,6 +11,7 @@ import {
|
|
11
11
|
ConnectionError,
|
12
12
|
XrplError,
|
13
13
|
} from '../errors'
|
14
|
+
import type { RequestResponseMap } from '../models'
|
14
15
|
import { BaseRequest } from '../models/methods/baseMethod'
|
15
16
|
|
16
17
|
import ConnectionManager from './ConnectionManager'
|
@@ -26,17 +27,11 @@ const CONNECTION_TIMEOUT = 5
|
|
26
27
|
*/
|
27
28
|
interface ConnectionOptions {
|
28
29
|
trace?: boolean | ((id: string, message: string) => void)
|
29
|
-
|
30
|
-
|
30
|
+
headers?: { [key: string]: string }
|
31
|
+
agent?: Agent
|
31
32
|
authorization?: string
|
32
|
-
trustedCertificates?: string[]
|
33
|
-
key?: string
|
34
|
-
passphrase?: string
|
35
|
-
certificate?: string
|
36
|
-
// request timeout
|
37
|
-
timeout: number
|
38
33
|
connectionTimeout: number
|
39
|
-
|
34
|
+
timeout: number
|
40
35
|
}
|
41
36
|
|
42
37
|
/**
|
@@ -55,52 +50,6 @@ export const INTENTIONAL_DISCONNECT_CODE = 4000
|
|
55
50
|
|
56
51
|
type WebsocketState = 0 | 1 | 2 | 3
|
57
52
|
|
58
|
-
function getAgent(url: string, config: ConnectionOptions): Agent | undefined {
|
59
|
-
if (config.proxy == null) {
|
60
|
-
return undefined
|
61
|
-
}
|
62
|
-
|
63
|
-
const parsedURL = new URL(url)
|
64
|
-
const parsedProxyURL = new URL(config.proxy)
|
65
|
-
|
66
|
-
const proxyOptions = omitBy(
|
67
|
-
{
|
68
|
-
secureEndpoint: parsedURL.protocol === 'wss:',
|
69
|
-
secureProxy: parsedProxyURL.protocol === 'https:',
|
70
|
-
auth: config.proxyAuthorization,
|
71
|
-
ca: config.trustedCertificates,
|
72
|
-
key: config.key,
|
73
|
-
passphrase: config.passphrase,
|
74
|
-
cert: config.certificate,
|
75
|
-
href: parsedProxyURL.href,
|
76
|
-
origin: parsedProxyURL.origin,
|
77
|
-
protocol: parsedProxyURL.protocol,
|
78
|
-
username: parsedProxyURL.username,
|
79
|
-
password: parsedProxyURL.password,
|
80
|
-
host: parsedProxyURL.host,
|
81
|
-
hostname: parsedProxyURL.hostname,
|
82
|
-
port: parsedProxyURL.port,
|
83
|
-
pathname: parsedProxyURL.pathname,
|
84
|
-
search: parsedProxyURL.search,
|
85
|
-
hash: parsedProxyURL.hash,
|
86
|
-
},
|
87
|
-
(value) => value == null,
|
88
|
-
)
|
89
|
-
|
90
|
-
let HttpsProxyAgent: new (opt: typeof proxyOptions) => Agent
|
91
|
-
try {
|
92
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports,
|
93
|
-
node/global-require, global-require, -- Necessary for the `require` */
|
94
|
-
HttpsProxyAgent = require('https-proxy-agent')
|
95
|
-
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports,
|
96
|
-
node/global-require, global-require, */
|
97
|
-
} catch (_error) {
|
98
|
-
throw new Error('"proxy" option is not supported in the browser')
|
99
|
-
}
|
100
|
-
|
101
|
-
return new HttpsProxyAgent(proxyOptions)
|
102
|
-
}
|
103
|
-
|
104
53
|
/**
|
105
54
|
* Create a new websocket given your URL and optional proxy/certificate
|
106
55
|
* configuration.
|
@@ -113,37 +62,20 @@ function createWebSocket(
|
|
113
62
|
url: string,
|
114
63
|
config: ConnectionOptions,
|
115
64
|
): WebSocket | null {
|
116
|
-
const options:
|
117
|
-
|
65
|
+
const options: ClientOptions = {
|
66
|
+
agent: config.agent,
|
67
|
+
}
|
118
68
|
if (config.headers) {
|
119
69
|
options.headers = config.headers
|
120
70
|
}
|
121
71
|
if (config.authorization != null) {
|
122
|
-
const base64 = Buffer.from(config.authorization).toString('base64')
|
123
72
|
options.headers = {
|
124
73
|
...options.headers,
|
125
|
-
Authorization: `Basic ${
|
74
|
+
Authorization: `Basic ${btoa(config.authorization)}`,
|
126
75
|
}
|
127
76
|
}
|
128
|
-
const
|
129
|
-
|
130
|
-
ca: config.trustedCertificates,
|
131
|
-
key: config.key,
|
132
|
-
passphrase: config.passphrase,
|
133
|
-
cert: config.certificate,
|
134
|
-
},
|
135
|
-
(value) => value == null,
|
136
|
-
)
|
137
|
-
const websocketOptions = { ...options, ...optionsOverrides }
|
138
|
-
const websocket = new WebSocket(url, websocketOptions)
|
139
|
-
/*
|
140
|
-
* we will have a listener for each outstanding request,
|
141
|
-
* so we have to raise the limit (the default is 10)
|
142
|
-
*/
|
143
|
-
if (typeof websocket.setMaxListeners === 'function') {
|
144
|
-
websocket.setMaxListeners(Infinity)
|
145
|
-
}
|
146
|
-
return websocket
|
77
|
+
const websocketOptions = { ...options }
|
78
|
+
return new WebSocket(url, websocketOptions)
|
147
79
|
}
|
148
80
|
|
149
81
|
/**
|
@@ -177,7 +109,7 @@ export class Connection extends EventEmitter {
|
|
177
109
|
private ws: WebSocket | null = null
|
178
110
|
// Typing necessary for Jest tests running in browser
|
179
111
|
private reconnectTimeoutID: null | ReturnType<typeof setTimeout> = null
|
180
|
-
// Typing necessary for Jest
|
112
|
+
// Typing necessary for Jest tests running in browser
|
181
113
|
private heartbeatIntervalID: null | ReturnType<typeof setTimeout> = null
|
182
114
|
private readonly retryConnectionBackoff = new ExponentialBackoff({
|
183
115
|
min: 100,
|
@@ -196,7 +128,6 @@ export class Connection extends EventEmitter {
|
|
196
128
|
*/
|
197
129
|
public constructor(url?: string, options: ConnectionUserOptions = {}) {
|
198
130
|
super()
|
199
|
-
this.setMaxListeners(Infinity)
|
200
131
|
this.url = url
|
201
132
|
this.config = {
|
202
133
|
timeout: TIMEOUT * 1000,
|
@@ -356,17 +287,17 @@ export class Connection extends EventEmitter {
|
|
356
287
|
* @returns The response from the rippled server.
|
357
288
|
* @throws NotConnectedError if the Connection isn't connected to a server.
|
358
289
|
*/
|
359
|
-
public async request<
|
360
|
-
request:
|
290
|
+
public async request<R extends BaseRequest, T = RequestResponseMap<R>>(
|
291
|
+
request: R,
|
361
292
|
timeout?: number,
|
362
|
-
): Promise<
|
293
|
+
): Promise<T> {
|
363
294
|
if (!this.shouldBeConnected || this.ws == null) {
|
364
295
|
throw new NotConnectedError(JSON.stringify(request), request)
|
365
296
|
}
|
366
|
-
const [id, message, responsePromise] = this.requestManager.createRequest
|
367
|
-
|
368
|
-
|
369
|
-
)
|
297
|
+
const [id, message, responsePromise] = this.requestManager.createRequest<
|
298
|
+
R,
|
299
|
+
T
|
300
|
+
>(request, timeout ?? this.config.timeout)
|
370
301
|
this.trace('send', message)
|
371
302
|
websocketSendAsync(this.ws, message).catch((error) => {
|
372
303
|
this.requestManager.reject(id, error)
|
@@ -451,7 +382,7 @@ export class Connection extends EventEmitter {
|
|
451
382
|
this.emit('error', 'websocket', error.message, error),
|
452
383
|
)
|
453
384
|
// Handle a closed connection: reconnect if it was unexpected
|
454
|
-
this.ws.once('close', (code?: number, reason?:
|
385
|
+
this.ws.once('close', (code?: number, reason?: Uint8Array) => {
|
455
386
|
if (this.ws == null) {
|
456
387
|
throw new XrplError('onceClose: ws is null')
|
457
388
|
}
|
@@ -459,7 +390,9 @@ export class Connection extends EventEmitter {
|
|
459
390
|
this.clearHeartbeatInterval()
|
460
391
|
this.requestManager.rejectAll(
|
461
392
|
new DisconnectedError(
|
462
|
-
`websocket was closed, ${
|
393
|
+
`websocket was closed, ${
|
394
|
+
reason ? hexToString(bytesToHex(reason)) : ''
|
395
|
+
}`,
|
463
396
|
),
|
464
397
|
)
|
465
398
|
this.ws.removeAllListeners()
|