xrpl 2.13.0 → 3.0.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/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 +18279 -74867
- 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/signer.d.ts +2 -4
- package/dist/npm/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/Wallet/signer.js +17 -13
- 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 +8 -54
- package/dist/npm/client/connection.js.map +1 -1
- package/dist/npm/client/index.d.ts +56 -78
- 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/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/subscribe.d.ts +3 -0
- package/dist/npm/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/models/methods/tx.d.ts +1 -1
- 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/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 +4 -3
- 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/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/signer.d.ts +2 -4
- package/dist/npm/src/Wallet/signer.d.ts.map +1 -1
- package/dist/npm/src/Wallet/signer.js +17 -13
- 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 +8 -54
- package/dist/npm/src/client/connection.js.map +1 -1
- package/dist/npm/src/client/index.d.ts +56 -78
- 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/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/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 +1 -1
- 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/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 +4 -3
- 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 +6 -9
- 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 +7 -0
- package/dist/npm/src/utils/collections.d.ts.map +1 -0
- package/dist/npm/src/utils/collections.js +22 -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/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/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 +6 -9
- 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 +7 -0
- package/dist/npm/utils/collections.d.ts.map +1 -0
- package/dist/npm/utils/collections.js +22 -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/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/package.json +23 -25
- package/src/Wallet/authorizeChannel.ts +26 -0
- package/src/Wallet/fundWallet.ts +151 -212
- package/src/Wallet/index.ts +28 -25
- package/src/Wallet/signer.ts +32 -43
- package/src/Wallet/walletFromSecretNumbers.ts +1 -1
- package/src/client/RequestManager.ts +40 -14
- package/src/client/connection.ts +20 -89
- package/src/client/index.ts +704 -269
- package/src/client/partialPayment.ts +14 -8
- package/src/errors.ts +1 -3
- package/src/index.ts +1 -3
- package/src/models/ledger/Ledger.ts +1 -1
- package/src/models/methods/index.ts +175 -0
- package/src/models/methods/ledger.ts +149 -20
- package/src/models/methods/subscribe.ts +36 -0
- package/src/models/methods/tx.ts +2 -1
- 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/metadata.ts +31 -1
- package/src/models/transactions/payment.ts +6 -0
- package/src/models/transactions/transaction.ts +6 -4
- 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 +114 -132
- package/src/utils/collections.ts +53 -0
- package/src/utils/getBalanceChanges.ts +2 -3
- package/src/utils/getNFTokenID.ts +18 -16
- package/src/utils/hashes/sha512Half.ts +4 -7
- 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/fundWallet.ts
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
import
|
2
|
-
import { request as httpsRequest, RequestOptions } from 'https'
|
3
|
-
|
1
|
+
import fetch from 'cross-fetch'
|
4
2
|
import { isValidClassicAddress } from 'ripple-address-codec'
|
5
3
|
|
6
4
|
import type { Client } from '../client'
|
7
|
-
import {
|
5
|
+
import { XRPLFaucetError } from '../errors'
|
8
6
|
|
9
7
|
import {
|
10
8
|
FaucetWallet,
|
@@ -19,53 +17,103 @@ const INTERVAL_SECONDS = 1
|
|
19
17
|
// Maximum attempts to retrieve a balance
|
20
18
|
const MAX_ATTEMPTS = 20
|
21
19
|
|
20
|
+
export interface FundingOptions {
|
21
|
+
/**
|
22
|
+
* A custom amount to fund, if undefined or null, the default amount will be 1000.
|
23
|
+
*/
|
24
|
+
amount?: string
|
25
|
+
/**
|
26
|
+
* A custom host for a faucet server. On devnet, testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
|
27
|
+
* attempt to determine the correct server automatically. In other environments, or if you would like to customize
|
28
|
+
* the faucet host in devnet or testnet, you should provide the host using this option.
|
29
|
+
*/
|
30
|
+
faucetHost?: string
|
31
|
+
/**
|
32
|
+
* A custom path for a faucet server. On devnet,
|
33
|
+
* testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
|
34
|
+
* attempt to determine the correct path automatically. In other environments,
|
35
|
+
* or if you would like to customize the faucet path in devnet or testnet,
|
36
|
+
* you should provide the path using this option.
|
37
|
+
* Ex: client.fundWallet(null,{'faucet.altnet.rippletest.net', '/accounts'})
|
38
|
+
* specifies a request to 'faucet.altnet.rippletest.net/accounts' to fund a new wallet.
|
39
|
+
*/
|
40
|
+
faucetPath?: string
|
41
|
+
/**
|
42
|
+
* An optional field to indicate the use case context of the faucet transaction
|
43
|
+
* Ex: integration test, code snippets.
|
44
|
+
*/
|
45
|
+
usageContext?: string
|
46
|
+
}
|
47
|
+
|
22
48
|
/**
|
23
|
-
*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
* Parameters to pass into a faucet request to fund an XRP account.
|
50
|
+
*/
|
51
|
+
export interface FaucetRequestBody {
|
52
|
+
/**
|
53
|
+
* The address to fund. If no address is provided the faucet will fund a random account.
|
54
|
+
*/
|
55
|
+
destination?: string
|
56
|
+
/**
|
57
|
+
* The total amount of XRP to fund the account with.
|
58
|
+
*/
|
59
|
+
xrpAmount?: string
|
60
|
+
/**
|
61
|
+
* An optional field to indicate the use case context of the faucet transaction
|
62
|
+
* Ex: integration test, code snippets.
|
63
|
+
*/
|
64
|
+
usageContext?: string
|
65
|
+
/**
|
66
|
+
* Information about the context of where the faucet is being called from.
|
67
|
+
* Ex: xrpl.js or xrpl-py
|
68
|
+
*/
|
69
|
+
userAgent: string
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Generate a new wallet to fund if no existing wallet is provided or its address is invalid.
|
44
74
|
*
|
45
|
-
*
|
75
|
+
* @param wallet - Optional existing wallet.
|
76
|
+
* @returns The wallet to fund.
|
77
|
+
*/
|
78
|
+
export function generateWalletToFund(wallet?: Wallet | null): Wallet {
|
79
|
+
if (wallet && isValidClassicAddress(wallet.classicAddress)) {
|
80
|
+
return wallet
|
81
|
+
}
|
82
|
+
return Wallet.generate()
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Get the starting balance of the wallet.
|
46
87
|
*
|
47
|
-
*
|
48
|
-
*
|
49
|
-
*
|
50
|
-
|
88
|
+
* @param client - The client object.
|
89
|
+
* @param classicAddress - The classic address of the wallet.
|
90
|
+
* @returns The starting balance.
|
91
|
+
*/
|
92
|
+
export async function getStartingBalance(
|
93
|
+
client: Client,
|
94
|
+
classicAddress: string,
|
95
|
+
): Promise<number> {
|
96
|
+
let startingBalance = 0
|
97
|
+
try {
|
98
|
+
startingBalance = Number(await client.getXrpBalance(classicAddress))
|
99
|
+
} catch {
|
100
|
+
// startingBalance remains '0'
|
101
|
+
}
|
102
|
+
return startingBalance
|
103
|
+
}
|
104
|
+
|
105
|
+
export interface FundWalletOptions {
|
106
|
+
faucetHost?: string
|
107
|
+
faucetPath?: string
|
108
|
+
amount?: string
|
109
|
+
usageContext?: string
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
51
113
|
*
|
52
|
-
*
|
53
|
-
* const newWallet = Wallet.generate()
|
54
|
-
* const { balance, wallet } = await client.fundWallet(newWallet, {
|
55
|
-
* amount: '10',
|
56
|
-
* faucetHost: 'https://custom-faucet.example.com',
|
57
|
-
* faucetPath: '/accounts'
|
58
|
-
* })
|
59
|
-
* console.log(`Sent 10 XRP to wallet: ${address} from the given faucet. Resulting balance: ${balance} XRP`)
|
60
|
-
* } catch (error) {
|
61
|
-
* console.error(`Failed to fund wallet: ${error}`)
|
62
|
-
* }
|
63
|
-
* }
|
64
|
-
* ```
|
114
|
+
* Helper function to request funding from a faucet. Should not be called directly from outside the xrpl.js library.
|
65
115
|
*
|
66
|
-
* @param
|
67
|
-
* @param wallet - An existing XRPL Wallet to fund. If undefined or null, a new Wallet will be created.
|
68
|
-
* @param options - See below.
|
116
|
+
* @param options - See below
|
69
117
|
* @param options.faucetHost - A custom host for a faucet server. On devnet,
|
70
118
|
* testnet, AMM devnet, and HooksV3 testnet, `fundWallet` will
|
71
119
|
* attempt to determine the correct server automatically. In other environments,
|
@@ -79,182 +127,69 @@ const MAX_ATTEMPTS = 20
|
|
79
127
|
* Ex: client.fundWallet(null,{'faucet.altnet.rippletest.net', '/accounts'})
|
80
128
|
* specifies a request to 'faucet.altnet.rippletest.net/accounts' to fund a new wallet.
|
81
129
|
* @param options.amount - A custom amount to fund, if undefined or null, the default amount will be 1000.
|
82
|
-
* @param
|
83
|
-
*
|
84
|
-
* @
|
85
|
-
*
|
86
|
-
*
|
130
|
+
* @param client - A connection to the XRPL to send requests and transactions.
|
131
|
+
* @param startingBalance - The amount of XRP in the given walletToFund on ledger already.
|
132
|
+
* @param walletToFund - An existing XRPL Wallet to fund.
|
133
|
+
* @param postBody - The content to send the faucet to indicate which address to fund, how much to fund it, and
|
134
|
+
* where the request is coming from.
|
135
|
+
* @returns A promise that resolves to a funded wallet and the balance within it.
|
87
136
|
*/
|
88
|
-
// eslint-disable-next-line max-lines-per-function -- All lines necessary
|
89
|
-
async function fundWallet(
|
90
|
-
this: Client,
|
91
|
-
wallet?: Wallet | null,
|
92
|
-
options?: {
|
93
|
-
faucetHost?: string
|
94
|
-
faucetPath?: string
|
95
|
-
amount?: string
|
96
|
-
usageContext?: string
|
97
|
-
},
|
98
|
-
): Promise<{
|
99
|
-
wallet: Wallet
|
100
|
-
balance: number
|
101
|
-
}> {
|
102
|
-
if (!this.isConnected()) {
|
103
|
-
throw new RippledError('Client not connected, cannot call faucet')
|
104
|
-
}
|
105
|
-
|
106
|
-
// Generate a new Wallet if no existing Wallet is provided or its address is invalid to fund
|
107
|
-
const walletToFund =
|
108
|
-
wallet && isValidClassicAddress(wallet.classicAddress)
|
109
|
-
? wallet
|
110
|
-
: Wallet.generate()
|
111
|
-
|
112
|
-
// Create the POST request body
|
113
|
-
const postBody = Buffer.from(
|
114
|
-
new TextEncoder().encode(
|
115
|
-
JSON.stringify({
|
116
|
-
destination: walletToFund.classicAddress,
|
117
|
-
xrpAmount: options?.amount,
|
118
|
-
userAgent: 'xrpl.js',
|
119
|
-
usageContext: options?.usageContext,
|
120
|
-
}),
|
121
|
-
),
|
122
|
-
)
|
123
|
-
|
124
|
-
let startingBalance = 0
|
125
|
-
try {
|
126
|
-
startingBalance = Number(
|
127
|
-
await this.getXrpBalance(walletToFund.classicAddress),
|
128
|
-
)
|
129
|
-
} catch {
|
130
|
-
/* startingBalance remains '0' */
|
131
|
-
}
|
132
|
-
// Options to pass to https.request
|
133
|
-
const httpOptions = getHTTPOptions(this, postBody, {
|
134
|
-
hostname: options?.faucetHost,
|
135
|
-
pathname: options?.faucetPath,
|
136
|
-
})
|
137
|
-
|
138
|
-
return returnPromise(
|
139
|
-
httpOptions,
|
140
|
-
this,
|
141
|
-
startingBalance,
|
142
|
-
walletToFund,
|
143
|
-
postBody,
|
144
|
-
)
|
145
|
-
}
|
146
|
-
|
147
137
|
// eslint-disable-next-line max-params -- Helper function created for organizational purposes
|
148
|
-
async function
|
149
|
-
options:
|
138
|
+
export async function requestFunding(
|
139
|
+
options: FundingOptions,
|
150
140
|
client: Client,
|
151
141
|
startingBalance: number,
|
152
142
|
walletToFund: Wallet,
|
153
|
-
postBody:
|
143
|
+
postBody: FaucetRequestBody,
|
154
144
|
): Promise<{
|
155
145
|
wallet: Wallet
|
156
146
|
balance: number
|
157
147
|
}> {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
onEnd(
|
165
|
-
response,
|
166
|
-
chunks,
|
167
|
-
client,
|
168
|
-
startingBalance,
|
169
|
-
walletToFund,
|
170
|
-
resolve,
|
171
|
-
reject,
|
172
|
-
),
|
173
|
-
)
|
174
|
-
})
|
175
|
-
// POST the body
|
176
|
-
request.write(postBody)
|
177
|
-
|
178
|
-
request.on('error', (error) => {
|
179
|
-
reject(error)
|
180
|
-
})
|
181
|
-
|
182
|
-
request.end()
|
183
|
-
})
|
184
|
-
}
|
185
|
-
|
186
|
-
function getHTTPOptions(
|
187
|
-
client: Client,
|
188
|
-
postBody: Uint8Array,
|
189
|
-
options?: {
|
190
|
-
hostname?: string
|
191
|
-
pathname?: string
|
192
|
-
},
|
193
|
-
): RequestOptions {
|
194
|
-
const finalHostname = options?.hostname ?? getFaucetHost(client)
|
195
|
-
const finalPathname = options?.pathname ?? getDefaultFaucetPath(finalHostname)
|
196
|
-
return {
|
197
|
-
hostname: finalHostname,
|
198
|
-
port: 443,
|
199
|
-
path: finalPathname,
|
148
|
+
const hostname = options.faucetHost ?? getFaucetHost(client)
|
149
|
+
if (!hostname) {
|
150
|
+
throw new XRPLFaucetError('No faucet hostname could be derived')
|
151
|
+
}
|
152
|
+
const pathname = options.faucetPath ?? getDefaultFaucetPath(hostname)
|
153
|
+
const response = await fetch(`https://${hostname}${pathname}`, {
|
200
154
|
method: 'POST',
|
201
155
|
headers: {
|
202
156
|
'Content-Type': 'application/json',
|
203
|
-
'Content-Length': postBody.length,
|
204
157
|
},
|
205
|
-
|
206
|
-
}
|
207
|
-
|
208
|
-
// eslint-disable-next-line max-params -- Helper function created for organizational purposes
|
209
|
-
async function onEnd(
|
210
|
-
response: IncomingMessage,
|
211
|
-
chunks: Uint8Array[],
|
212
|
-
client: Client,
|
213
|
-
startingBalance: number,
|
214
|
-
walletToFund: Wallet,
|
215
|
-
resolve: (response: { wallet: Wallet; balance: number }) => void,
|
216
|
-
reject: (err: ErrorConstructor | Error | unknown) => void,
|
217
|
-
): Promise<void> {
|
218
|
-
const body = Buffer.concat(chunks).toString()
|
158
|
+
body: JSON.stringify(postBody),
|
159
|
+
})
|
219
160
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- It's a FaucetWallet
|
162
|
+
const body = (await response.json()) as FaucetWallet
|
220
163
|
// "application/json; charset=utf-8"
|
221
|
-
if (
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
164
|
+
if (
|
165
|
+
response.ok &&
|
166
|
+
response.headers.get('Content-Type')?.startsWith('application/json')
|
167
|
+
) {
|
168
|
+
const classicAddress = body.account.classicAddress
|
169
|
+
return processSuccessfulResponse(
|
226
170
|
client,
|
227
171
|
classicAddress,
|
228
172
|
walletToFund,
|
229
173
|
startingBalance,
|
230
|
-
resolve,
|
231
|
-
reject,
|
232
|
-
)
|
233
|
-
} else {
|
234
|
-
reject(
|
235
|
-
new XRPLFaucetError(
|
236
|
-
`Content type is not \`application/json\`: ${JSON.stringify({
|
237
|
-
statusCode: response.statusCode,
|
238
|
-
contentType: response.headers['content-type'],
|
239
|
-
body,
|
240
|
-
})}`,
|
241
|
-
),
|
242
174
|
)
|
243
175
|
}
|
176
|
+
return processError(response)
|
244
177
|
}
|
245
178
|
|
246
|
-
// eslint-disable-next-line max-params
|
179
|
+
// eslint-disable-next-line max-params -- Only used as a helper function, lines inc due to added balance.
|
247
180
|
async function processSuccessfulResponse(
|
248
181
|
client: Client,
|
249
182
|
classicAddress: string | undefined,
|
250
183
|
walletToFund: Wallet,
|
251
184
|
startingBalance: number,
|
252
|
-
|
253
|
-
|
254
|
-
|
185
|
+
): Promise<{
|
186
|
+
wallet: Wallet
|
187
|
+
balance: number
|
188
|
+
}> {
|
255
189
|
if (!classicAddress) {
|
256
|
-
reject(
|
257
|
-
|
190
|
+
return Promise.reject(
|
191
|
+
new XRPLFaucetError(`The faucet account is undefined`),
|
192
|
+
)
|
258
193
|
}
|
259
194
|
try {
|
260
195
|
// Check at regular interval if the address is enabled on the XRPL and funded
|
@@ -265,31 +200,37 @@ async function processSuccessfulResponse(
|
|
265
200
|
)
|
266
201
|
|
267
202
|
if (updatedBalance > startingBalance) {
|
268
|
-
|
203
|
+
return {
|
269
204
|
wallet: walletToFund,
|
270
|
-
balance:
|
271
|
-
|
272
|
-
walletToFund.classicAddress,
|
273
|
-
startingBalance,
|
274
|
-
),
|
275
|
-
})
|
276
|
-
} else {
|
277
|
-
reject(
|
278
|
-
new XRPLFaucetError(
|
279
|
-
`Unable to fund address with faucet after waiting ${
|
280
|
-
INTERVAL_SECONDS * MAX_ATTEMPTS
|
281
|
-
} seconds`,
|
282
|
-
),
|
283
|
-
)
|
205
|
+
balance: updatedBalance,
|
206
|
+
}
|
284
207
|
}
|
208
|
+
throw new XRPLFaucetError(
|
209
|
+
`Unable to fund address with faucet after waiting ${
|
210
|
+
INTERVAL_SECONDS * MAX_ATTEMPTS
|
211
|
+
} seconds`,
|
212
|
+
)
|
285
213
|
} catch (err) {
|
286
214
|
if (err instanceof Error) {
|
287
|
-
|
215
|
+
throw new XRPLFaucetError(err.message)
|
288
216
|
}
|
289
|
-
|
217
|
+
throw err
|
290
218
|
}
|
291
219
|
}
|
292
220
|
|
221
|
+
async function processError(response: Response): Promise<never> {
|
222
|
+
return Promise.reject(
|
223
|
+
new XRPLFaucetError(
|
224
|
+
`Request failed: ${JSON.stringify({
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- json response could be anything
|
226
|
+
body: (await response.json()) || {},
|
227
|
+
contentType: response.headers.get('Content-Type'),
|
228
|
+
statusCode: response.status,
|
229
|
+
})}`,
|
230
|
+
),
|
231
|
+
)
|
232
|
+
}
|
233
|
+
|
293
234
|
/**
|
294
235
|
* Check at regular interval if the address is enabled on the XRPL and funded.
|
295
236
|
*
|
@@ -340,5 +281,3 @@ async function getUpdatedBalance(
|
|
340
281
|
}, INTERVAL_SECONDS * 1000)
|
341
282
|
})
|
342
283
|
}
|
343
|
-
|
344
|
-
export default fundWallet
|
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/signer.ts
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
import { BigNumber } from 'bignumber.js'
|
2
|
-
import { flatMap } from 'lodash'
|
3
2
|
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'
|
3
|
+
import { decode, encode, encodeForSigning } from 'ripple-binary-codec'
|
4
|
+
import { verify } from 'ripple-keypairs'
|
11
5
|
|
12
6
|
import { ValidationError } from '../errors'
|
13
7
|
import { Signer } from '../models/common'
|
14
8
|
import { Transaction, validate } from '../models/transactions'
|
15
9
|
|
16
|
-
import { Wallet } from '.'
|
17
|
-
|
18
10
|
/**
|
19
11
|
* Takes several transactions with Signer fields (in object or blob form) and creates a
|
20
12
|
* single transaction with all Signers that then gets signed and returned.
|
@@ -62,42 +54,40 @@ function multisign(transactions: Array<Transaction | string>): string {
|
|
62
54
|
return encode(getTransactionWithAllSigners(decodedTransactions))
|
63
55
|
}
|
64
56
|
|
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
57
|
/**
|
88
58
|
* Verifies that the given transaction has a valid signature based on public-key encryption.
|
89
59
|
*
|
90
60
|
* @param tx - A transaction to verify the signature of. (Can be in object or encoded string format).
|
61
|
+
* @param [publicKey] Specific public key to use to verify. If not specified the `SigningPublicKey` of tx will be used.
|
91
62
|
* @returns Returns true if tx has a valid signature, and returns false otherwise.
|
63
|
+
* @throws Error when transaction is missing TxnSignature
|
64
|
+
* @throws Error when publicKey is not provided and transaction is missing SigningPubKey
|
92
65
|
* @category Utilities
|
93
66
|
*/
|
94
|
-
function verifySignature(
|
67
|
+
function verifySignature(
|
68
|
+
tx: Transaction | string,
|
69
|
+
publicKey?: string,
|
70
|
+
): boolean {
|
95
71
|
const decodedTx: Transaction = getDecodedTransaction(tx)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
72
|
+
let key = publicKey
|
73
|
+
|
74
|
+
// Need a SignedTransaction class where TxnSignature is not optional.
|
75
|
+
if (typeof decodedTx.TxnSignature !== 'string' || !decodedTx.TxnSignature) {
|
76
|
+
throw new Error('Transaction is missing a signature, TxnSignature')
|
77
|
+
}
|
78
|
+
|
79
|
+
if (!key) {
|
80
|
+
// Need a SignedTransaction class where TxnSignature is not optional.
|
81
|
+
if (
|
82
|
+
typeof decodedTx.SigningPubKey !== 'string' ||
|
83
|
+
!decodedTx.SigningPubKey
|
84
|
+
) {
|
85
|
+
throw new Error('Transaction is missing a public key, SigningPubKey')
|
86
|
+
}
|
87
|
+
key = decodedTx.SigningPubKey
|
88
|
+
}
|
89
|
+
|
90
|
+
return verify(encodeForSigning(decodedTx), decodedTx.TxnSignature, key)
|
101
91
|
}
|
102
92
|
|
103
93
|
/**
|
@@ -128,10 +118,9 @@ function getTransactionWithAllSigners(
|
|
128
118
|
transactions: Transaction[],
|
129
119
|
): Transaction {
|
130
120
|
// Signers must be sorted in the combined transaction - See compareSigners' documentation for more details
|
131
|
-
const sortedSigners: Signer[] =
|
132
|
-
|
133
|
-
(
|
134
|
-
).sort(compareSigners)
|
121
|
+
const sortedSigners: Signer[] = transactions
|
122
|
+
.flatMap((tx) => tx.Signers ?? [])
|
123
|
+
.sort(compareSigners)
|
135
124
|
|
136
125
|
return { ...transactions[0], Signers: sortedSigners }
|
137
126
|
}
|
@@ -170,4 +159,4 @@ function getDecodedTransaction(txOrBlob: Transaction | string): Transaction {
|
|
170
159
|
return decode(txOrBlob) as unknown as Transaction
|
171
160
|
}
|
172
161
|
|
173
|
-
export {
|
162
|
+
export { verifySignature, multisign }
|