xrpl 4.2.0-batch.0 → 4.3.0-smartescrow.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.js +525 -1525
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.d.ts +1 -2
- package/dist/npm/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.js +0 -5
- package/dist/npm/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/Wallet/index.d.ts.map +1 -1
- package/dist/npm/Wallet/index.js +2 -8
- package/dist/npm/Wallet/index.js.map +1 -1
- package/dist/npm/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/client/RequestManager.js +3 -3
- package/dist/npm/client/RequestManager.js.map +1 -1
- package/dist/npm/client/connection.d.ts.map +1 -1
- package/dist/npm/client/connection.js.map +1 -1
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js +8 -5
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/models/ledger/Credential.d.ts +2 -2
- package/dist/npm/models/ledger/Credential.d.ts.map +1 -1
- package/dist/npm/models/ledger/Escrow.d.ts +2 -0
- package/dist/npm/models/ledger/Escrow.d.ts.map +1 -1
- package/dist/npm/models/ledger/FeeSettings.d.ts +2 -0
- package/dist/npm/models/ledger/FeeSettings.d.ts.map +1 -1
- package/dist/npm/models/methods/baseMethod.d.ts +0 -1
- package/dist/npm/models/methods/baseMethod.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMClawback.d.ts +2 -2
- package/dist/npm/models/transactions/AMMClawback.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMDeposit.d.ts +2 -2
- package/dist/npm/models/transactions/AMMDeposit.d.ts.map +1 -1
- package/dist/npm/models/transactions/AMMWithdraw.d.ts +2 -2
- package/dist/npm/models/transactions/AMMWithdraw.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenAuthorize.d.ts +2 -2
- package/dist/npm/models/transactions/MPTokenAuthorize.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.d.ts +2 -2
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.js.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts +2 -2
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts +2 -2
- package/dist/npm/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.d.ts +2 -2
- package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts +2 -2
- package/dist/npm/models/transactions/XChainModifyBridge.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountSet.d.ts +2 -2
- package/dist/npm/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +4 -16
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +10 -28
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/escrowCreate.d.ts +2 -0
- package/dist/npm/models/transactions/escrowCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowCreate.js +4 -2
- package/dist/npm/models/transactions/escrowCreate.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +2 -3
- 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 +0 -1
- package/dist/npm/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/models/transactions/offerCreate.d.ts +2 -2
- package/dist/npm/models/transactions/offerCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/oracleSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/oracleSet.js +17 -3
- package/dist/npm/models/transactions/oracleSet.js.map +1 -1
- package/dist/npm/models/transactions/payment.d.ts +2 -2
- package/dist/npm/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.d.ts +2 -2
- package/dist/npm/models/transactions/paymentChannelClaim.d.ts.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +1 -2
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +0 -7
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/transactions/trustSet.d.ts +2 -2
- package/dist/npm/models/transactions/trustSet.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.d.ts +0 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +2 -22
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.d.ts +1 -2
- package/dist/npm/src/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.js +0 -5
- package/dist/npm/src/Wallet/defaultFaucets.js.map +1 -1
- package/dist/npm/src/Wallet/index.d.ts.map +1 -1
- package/dist/npm/src/Wallet/index.js +2 -8
- package/dist/npm/src/Wallet/index.js.map +1 -1
- package/dist/npm/src/client/RequestManager.d.ts.map +1 -1
- package/dist/npm/src/client/RequestManager.js +3 -3
- package/dist/npm/src/client/RequestManager.js.map +1 -1
- package/dist/npm/src/client/connection.d.ts.map +1 -1
- package/dist/npm/src/client/connection.js.map +1 -1
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js +8 -5
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/models/ledger/Credential.d.ts +2 -2
- package/dist/npm/src/models/ledger/Credential.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Escrow.d.ts +2 -0
- package/dist/npm/src/models/ledger/Escrow.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/FeeSettings.d.ts +2 -0
- package/dist/npm/src/models/ledger/FeeSettings.d.ts.map +1 -1
- package/dist/npm/src/models/methods/baseMethod.d.ts +0 -1
- package/dist/npm/src/models/methods/baseMethod.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMClawback.d.ts +2 -2
- package/dist/npm/src/models/transactions/AMMClawback.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts +2 -2
- package/dist/npm/src/models/transactions/AMMDeposit.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts +2 -2
- package/dist/npm/src/models/transactions/AMMWithdraw.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenAuthorize.d.ts +2 -2
- package/dist/npm/src/models/transactions/MPTokenAuthorize.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.d.ts +2 -2
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts +2 -2
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts +2 -2
- package/dist/npm/src/models/transactions/NFTokenCreateOffer.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts +2 -2
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts +2 -2
- package/dist/npm/src/models/transactions/XChainModifyBridge.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.d.ts +2 -2
- package/dist/npm/src/models/transactions/accountSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountSet.js.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +4 -16
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +10 -28
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowCreate.d.ts +2 -0
- package/dist/npm/src/models/transactions/escrowCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowCreate.js +4 -2
- package/dist/npm/src/models/transactions/escrowCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +2 -3
- 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 +0 -1
- package/dist/npm/src/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/offerCreate.d.ts +2 -2
- package/dist/npm/src/models/transactions/offerCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/oracleSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/oracleSet.js +17 -3
- package/dist/npm/src/models/transactions/oracleSet.js.map +1 -1
- package/dist/npm/src/models/transactions/payment.d.ts +2 -2
- package/dist/npm/src/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.d.ts +2 -2
- package/dist/npm/src/models/transactions/paymentChannelClaim.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +1 -2
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +0 -7
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/transactions/trustSet.d.ts +2 -2
- package/dist/npm/src/models/transactions/trustSet.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts +0 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +2 -22
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts +1 -3
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +8 -100
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/src/sugar/submit.d.ts.map +1 -1
- package/dist/npm/src/sugar/submit.js.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/src/utils/hashes/hashLedger.js +1 -4
- package/dist/npm/src/utils/hashes/hashLedger.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts +1 -3
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +8 -100
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/submit.d.ts.map +1 -1
- package/dist/npm/sugar/submit.js.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.d.ts.map +1 -1
- package/dist/npm/utils/hashes/hashLedger.js +1 -4
- package/dist/npm/utils/hashes/hashLedger.js.map +1 -1
- package/package.json +5 -8
- package/src/Wallet/defaultFaucets.ts +0 -6
- package/src/Wallet/index.ts +3 -9
- package/src/client/RequestManager.ts +1 -4
- package/src/client/connection.ts +1 -0
- package/src/client/index.ts +28 -7
- package/src/models/ledger/Credential.ts +2 -2
- package/src/models/ledger/Escrow.ts +4 -0
- package/src/models/ledger/FeeSettings.ts +4 -0
- package/src/models/methods/baseMethod.ts +0 -1
- package/src/models/transactions/AMMClawback.ts +2 -2
- package/src/models/transactions/AMMDeposit.ts +2 -2
- package/src/models/transactions/AMMWithdraw.ts +2 -2
- package/src/models/transactions/MPTokenAuthorize.ts +2 -2
- package/src/models/transactions/MPTokenIssuanceCreate.ts +2 -3
- package/src/models/transactions/MPTokenIssuanceSet.ts +2 -2
- package/src/models/transactions/NFTokenCreateOffer.ts +2 -2
- package/src/models/transactions/NFTokenMint.ts +2 -2
- package/src/models/transactions/XChainModifyBridge.ts +2 -2
- package/src/models/transactions/accountSet.ts +1 -2
- package/src/models/transactions/common.ts +22 -62
- package/src/models/transactions/escrowCreate.ts +10 -2
- package/src/models/transactions/index.ts +3 -3
- package/src/models/transactions/metadata.ts +0 -2
- package/src/models/transactions/offerCreate.ts +2 -2
- package/src/models/transactions/oracleSet.ts +30 -8
- package/src/models/transactions/payment.ts +2 -2
- package/src/models/transactions/paymentChannelClaim.ts +2 -3
- package/src/models/transactions/transaction.ts +0 -15
- package/src/models/transactions/trustSet.ts +2 -2
- package/src/models/utils/flags.ts +1 -30
- package/src/sugar/autofill.ts +15 -140
- package/src/sugar/submit.ts +2 -1
- package/src/utils/hashes/hashLedger.ts +2 -5
- package/build/xrpl-latest-min.js +0 -3
- package/build/xrpl-latest-min.js.map +0 -1
- package/dist/npm/Wallet/batchSigner.d.ts +0 -8
- package/dist/npm/Wallet/batchSigner.d.ts.map +0 -1
- package/dist/npm/Wallet/batchSigner.js +0 -124
- package/dist/npm/Wallet/batchSigner.js.map +0 -1
- package/dist/npm/models/transactions/batch.d.ts +0 -39
- package/dist/npm/models/transactions/batch.d.ts.map +0 -1
- package/dist/npm/models/transactions/batch.js +0 -62
- package/dist/npm/models/transactions/batch.js.map +0 -1
- package/dist/npm/src/Wallet/batchSigner.d.ts +0 -8
- package/dist/npm/src/Wallet/batchSigner.d.ts.map +0 -1
- package/dist/npm/src/Wallet/batchSigner.js +0 -124
- package/dist/npm/src/Wallet/batchSigner.js.map +0 -1
- package/dist/npm/src/models/transactions/batch.d.ts +0 -39
- package/dist/npm/src/models/transactions/batch.d.ts.map +0 -1
- package/dist/npm/src/models/transactions/batch.js +0 -62
- package/dist/npm/src/models/transactions/batch.js.map +0 -1
- package/src/Wallet/batchSigner.ts +0 -222
- package/src/models/transactions/batch.ts +0 -147
@@ -1,222 +0,0 @@
|
|
1
|
-
import { bytesToHex } from '@xrplf/isomorphic/utils'
|
2
|
-
import BigNumber from 'bignumber.js'
|
3
|
-
import { decodeAccountID } from 'ripple-address-codec'
|
4
|
-
import { decode, encode, encodeForSigningBatch } from 'ripple-binary-codec'
|
5
|
-
import { sign } from 'ripple-keypairs'
|
6
|
-
|
7
|
-
import { ValidationError } from '../errors'
|
8
|
-
import { Batch, Transaction, validate } from '../models'
|
9
|
-
import { BatchSigner, validateBatch } from '../models/transactions/batch'
|
10
|
-
import { hashSignedTx } from '../utils/hashes'
|
11
|
-
|
12
|
-
import { Wallet } from '.'
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Sign a multi-account Batch transaction.
|
16
|
-
*
|
17
|
-
* @param wallet - Wallet instance.
|
18
|
-
* @param transaction - The Batch transaction to sign.
|
19
|
-
* @param opts - Additional options for regular key and multi-signing complexity.
|
20
|
-
* @param opts.batchAccount - The account submitting the inner Batch transaction, on behalf of which is this signature.
|
21
|
-
* @param opts.multisign - Specify true/false to use multisign or actual address (classic/x-address) to make multisign tx request.
|
22
|
-
* The actual address is only needed in the case of regular key usage.
|
23
|
-
* @throws ValidationError if the transaction is malformed.
|
24
|
-
*/
|
25
|
-
// eslint-disable-next-line max-lines-per-function -- TODO: refactor
|
26
|
-
export function signMultiBatch(
|
27
|
-
wallet: Wallet,
|
28
|
-
transaction: Batch,
|
29
|
-
opts: { batchAccount?: string; multisign?: boolean | string } = {},
|
30
|
-
): void {
|
31
|
-
const batchAccount = opts.batchAccount ?? wallet.classicAddress
|
32
|
-
let multisignAddress: boolean | string = false
|
33
|
-
if (typeof opts.multisign === 'string') {
|
34
|
-
multisignAddress = opts.multisign
|
35
|
-
} else if (opts.multisign) {
|
36
|
-
multisignAddress = wallet.classicAddress
|
37
|
-
}
|
38
|
-
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- needed for JS
|
40
|
-
if (transaction.TransactionType !== 'Batch') {
|
41
|
-
throw new ValidationError('Must be a Batch transaction.')
|
42
|
-
}
|
43
|
-
|
44
|
-
const involvedAccounts = transaction.RawTransactions.map(
|
45
|
-
(raw) => raw.RawTransaction.Account,
|
46
|
-
)
|
47
|
-
if (!involvedAccounts.includes(batchAccount)) {
|
48
|
-
throw new ValidationError(
|
49
|
-
'Must be signing for an address included in the Batch.',
|
50
|
-
)
|
51
|
-
}
|
52
|
-
/*
|
53
|
-
* This will throw a more clear error for JS users if the supplied transaction has incorrect formatting
|
54
|
-
*/
|
55
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- validate does not accept Transaction type
|
56
|
-
validate(transaction as unknown as Record<string, unknown>)
|
57
|
-
const fieldsToSign = {
|
58
|
-
flags: transaction.Flags,
|
59
|
-
txIDs: transaction.RawTransactions.map((rawTx) =>
|
60
|
-
hashSignedTx(rawTx.RawTransaction),
|
61
|
-
),
|
62
|
-
}
|
63
|
-
let batchSigner: BatchSigner
|
64
|
-
if (multisignAddress) {
|
65
|
-
batchSigner = {
|
66
|
-
BatchSigner: {
|
67
|
-
Account: batchAccount,
|
68
|
-
Signers: [
|
69
|
-
{
|
70
|
-
Signer: {
|
71
|
-
Account: multisignAddress,
|
72
|
-
SigningPubKey: wallet.publicKey,
|
73
|
-
TxnSignature: sign(
|
74
|
-
encodeForSigningBatch(fieldsToSign),
|
75
|
-
wallet.privateKey,
|
76
|
-
),
|
77
|
-
},
|
78
|
-
},
|
79
|
-
],
|
80
|
-
},
|
81
|
-
}
|
82
|
-
} else {
|
83
|
-
batchSigner = {
|
84
|
-
BatchSigner: {
|
85
|
-
Account: batchAccount,
|
86
|
-
SigningPubKey: wallet.publicKey,
|
87
|
-
TxnSignature: sign(
|
88
|
-
encodeForSigningBatch(fieldsToSign),
|
89
|
-
wallet.privateKey,
|
90
|
-
),
|
91
|
-
},
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
// eslint-disable-next-line no-param-reassign -- okay for signing
|
96
|
-
transaction.BatchSigners = [batchSigner]
|
97
|
-
}
|
98
|
-
|
99
|
-
/**
|
100
|
-
* Takes several transactions with BatchSigners fields (in object or blob form) and creates a
|
101
|
-
* single transaction with all BatchSigners that then gets signed and returned.
|
102
|
-
*
|
103
|
-
* @param transactions The transactions to combine `BatchSigners` values on.
|
104
|
-
* @returns A single signed Transaction which has all BatchSigners from transactions within it.
|
105
|
-
* @throws ValidationError if:
|
106
|
-
* - There were no transactions given to sign
|
107
|
-
* @category Signing
|
108
|
-
*/
|
109
|
-
export function combineBatchSigners(
|
110
|
-
transactions: Array<Batch | string>,
|
111
|
-
): string {
|
112
|
-
if (transactions.length === 0) {
|
113
|
-
throw new ValidationError('There are 0 transactions to combine.')
|
114
|
-
}
|
115
|
-
|
116
|
-
const decodedTransactions: Transaction[] = transactions.map((txOrBlob) => {
|
117
|
-
return getDecodedTransaction(txOrBlob)
|
118
|
-
})
|
119
|
-
|
120
|
-
decodedTransactions.forEach((tx) => {
|
121
|
-
if (tx.TransactionType !== 'Batch') {
|
122
|
-
throw new ValidationError('TransactionType must be `Batch`.')
|
123
|
-
}
|
124
|
-
/*
|
125
|
-
* This will throw a more clear error for JS users if any of the supplied transactions has incorrect formatting
|
126
|
-
*/
|
127
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- validate does not accept Transaction type
|
128
|
-
validateBatch(tx as unknown as Record<string, unknown>)
|
129
|
-
if (tx.BatchSigners == null || tx.BatchSigners.length === 0) {
|
130
|
-
throw new ValidationError(
|
131
|
-
'For combining Batch transaction signatures, all transactions must include a BatchSigners field containing an array of signatures.',
|
132
|
-
)
|
133
|
-
}
|
134
|
-
|
135
|
-
if (tx.TxnSignature != null || tx.Signers != null) {
|
136
|
-
throw new ValidationError('Batch transaction must be unsigned.')
|
137
|
-
}
|
138
|
-
})
|
139
|
-
|
140
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
141
|
-
const batchTransactions = decodedTransactions as Batch[]
|
142
|
-
|
143
|
-
validateBatchTransactionEquivalence(batchTransactions)
|
144
|
-
|
145
|
-
return encode(getTransactionWithAllBatchSigners(batchTransactions))
|
146
|
-
}
|
147
|
-
|
148
|
-
/**
|
149
|
-
* The transactions should all be equal except for the 'Signers' field.
|
150
|
-
*
|
151
|
-
* @param transactions - An array of Transactions which are expected to be equal other than 'Signers'.
|
152
|
-
* @throws ValidationError if the transactions are not equal in any field other than 'Signers'.
|
153
|
-
*/
|
154
|
-
function validateBatchTransactionEquivalence(transactions: Batch[]): void {
|
155
|
-
const exampleTransaction = JSON.stringify({
|
156
|
-
flags: transactions[0].Flags,
|
157
|
-
transactionIDs: transactions[0].RawTransactions.map((rawTx) =>
|
158
|
-
hashSignedTx(rawTx.RawTransaction),
|
159
|
-
),
|
160
|
-
})
|
161
|
-
if (
|
162
|
-
transactions.slice(1).some(
|
163
|
-
(tx) =>
|
164
|
-
JSON.stringify({
|
165
|
-
flags: tx.Flags,
|
166
|
-
transactionIDs: tx.RawTransactions.map((rawTx) =>
|
167
|
-
hashSignedTx(rawTx.RawTransaction),
|
168
|
-
),
|
169
|
-
}) !== exampleTransaction,
|
170
|
-
)
|
171
|
-
) {
|
172
|
-
throw new ValidationError(
|
173
|
-
'Flags and transaction hashes are not the same for all provided transactions.',
|
174
|
-
)
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
function getTransactionWithAllBatchSigners(transactions: Batch[]): Batch {
|
179
|
-
// Signers must be sorted in the combined transaction - See compareSigners' documentation for more details
|
180
|
-
const sortedSigners: BatchSigner[] = transactions
|
181
|
-
.flatMap((tx) => tx.BatchSigners ?? [])
|
182
|
-
.filter((signer) => signer.BatchSigner.Account !== transactions[0].Account)
|
183
|
-
.sort(compareBatchSigners)
|
184
|
-
|
185
|
-
return { ...transactions[0], BatchSigners: sortedSigners }
|
186
|
-
}
|
187
|
-
|
188
|
-
/**
|
189
|
-
* If presented in binary form, the BatchSigners array must be sorted based on
|
190
|
-
* the numeric value of the signer addresses, with the lowest value first.
|
191
|
-
* (If submitted as JSON, the submit_multisigned method handles this automatically.)
|
192
|
-
* https://xrpl.org/multi-signing.html.
|
193
|
-
*
|
194
|
-
* @param left - A BatchSigner to compare with.
|
195
|
-
* @param right - A second BatchSigner to compare with.
|
196
|
-
* @returns 1 if left \> right, 0 if left = right, -1 if left \< right, and null if left or right are NaN.
|
197
|
-
*/
|
198
|
-
function compareBatchSigners(left: BatchSigner, right: BatchSigner): number {
|
199
|
-
return addressToBigNumber(left.BatchSigner.Account).comparedTo(
|
200
|
-
addressToBigNumber(right.BatchSigner.Account),
|
201
|
-
)
|
202
|
-
}
|
203
|
-
|
204
|
-
// copied from signer.ts
|
205
|
-
// TODO: refactor
|
206
|
-
const NUM_BITS_IN_HEX = 16
|
207
|
-
|
208
|
-
function addressToBigNumber(address: string): BigNumber {
|
209
|
-
const hex = bytesToHex(decodeAccountID(address))
|
210
|
-
return new BigNumber(hex, NUM_BITS_IN_HEX)
|
211
|
-
}
|
212
|
-
|
213
|
-
function getDecodedTransaction(txOrBlob: Transaction | string): Transaction {
|
214
|
-
if (typeof txOrBlob === 'object') {
|
215
|
-
// We need this to handle X-addresses in multisigning
|
216
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We are casting here to get strong typing
|
217
|
-
return decode(encode(txOrBlob)) as unknown as Transaction
|
218
|
-
}
|
219
|
-
|
220
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We are casting here to get strong typing
|
221
|
-
return decode(txOrBlob) as unknown as Transaction
|
222
|
-
}
|
@@ -1,147 +0,0 @@
|
|
1
|
-
import { ValidationError } from '../../errors'
|
2
|
-
import { Signer } from '../common'
|
3
|
-
|
4
|
-
import {
|
5
|
-
BaseTransaction,
|
6
|
-
GlobalFlagsInterface,
|
7
|
-
isArray,
|
8
|
-
isObject,
|
9
|
-
isString,
|
10
|
-
validateBaseTransaction,
|
11
|
-
validateOptionalField,
|
12
|
-
validateRequiredField,
|
13
|
-
} from './common'
|
14
|
-
import type { SubmittableTransaction } from './transaction'
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Enum representing values of {@link Batch} transaction flags.
|
18
|
-
*
|
19
|
-
* @category Transaction Flags
|
20
|
-
*/
|
21
|
-
export enum BatchFlags {
|
22
|
-
tfAllOrNothing = 0x00010000,
|
23
|
-
tfOnlyOne = 0x00020000,
|
24
|
-
tfUntilFailure = 0x00040000,
|
25
|
-
tfIndependent = 0x00080000,
|
26
|
-
}
|
27
|
-
|
28
|
-
/**
|
29
|
-
* Map of flags to boolean values representing {@link Batch} transaction
|
30
|
-
* flags.
|
31
|
-
*
|
32
|
-
* @category Transaction Flags
|
33
|
-
*/
|
34
|
-
export interface BatchFlagsInterface extends GlobalFlagsInterface {
|
35
|
-
tfAllOrNothing?: boolean
|
36
|
-
tfOnlyOne?: boolean
|
37
|
-
tfUntilFailure?: boolean
|
38
|
-
tfIndependent?: boolean
|
39
|
-
}
|
40
|
-
|
41
|
-
export type BatchInnerTransaction = SubmittableTransaction & {
|
42
|
-
Fee?: '0'
|
43
|
-
|
44
|
-
SigningPubKey?: ''
|
45
|
-
|
46
|
-
TxnSignature?: never
|
47
|
-
|
48
|
-
Signers?: never
|
49
|
-
|
50
|
-
LastLedgerSequence?: never
|
51
|
-
}
|
52
|
-
|
53
|
-
export interface BatchSigner {
|
54
|
-
BatchSigner: {
|
55
|
-
Account: string
|
56
|
-
|
57
|
-
SigningPubKey?: string
|
58
|
-
|
59
|
-
TxnSignature?: string
|
60
|
-
|
61
|
-
Signers?: Signer[]
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
/**
|
66
|
-
* @category Transaction Models
|
67
|
-
*/
|
68
|
-
export interface Batch extends BaseTransaction {
|
69
|
-
TransactionType: 'Batch'
|
70
|
-
|
71
|
-
BatchSigners?: BatchSigner[]
|
72
|
-
|
73
|
-
RawTransactions: Array<{
|
74
|
-
RawTransaction: BatchInnerTransaction
|
75
|
-
}>
|
76
|
-
}
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Verify the form and type of a Batch at runtime.
|
80
|
-
*
|
81
|
-
* @param tx - A Batch Transaction.
|
82
|
-
* @throws When the Batch is malformed.
|
83
|
-
*/
|
84
|
-
// eslint-disable-next-line max-lines-per-function -- needed here due to the complexity
|
85
|
-
export function validateBatch(tx: Record<string, unknown>): void {
|
86
|
-
validateBaseTransaction(tx)
|
87
|
-
|
88
|
-
validateRequiredField(tx, 'RawTransactions', isArray)
|
89
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
90
|
-
const rawTransactions = tx.RawTransactions as unknown[]
|
91
|
-
rawTransactions.forEach((rawTxObj, index) => {
|
92
|
-
if (!isObject(rawTxObj)) {
|
93
|
-
throw new ValidationError(
|
94
|
-
`Batch: RawTransactions[${index}] is not object.`,
|
95
|
-
)
|
96
|
-
}
|
97
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
98
|
-
const rawTxRecord = rawTxObj as Record<string, unknown>
|
99
|
-
validateRequiredField(rawTxRecord, 'RawTransaction', isObject, {
|
100
|
-
paramName: `RawTransactions[${index}].RawTransaction`,
|
101
|
-
txType: 'Batch',
|
102
|
-
})
|
103
|
-
|
104
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
105
|
-
const rawTx = rawTxRecord.RawTransaction as Record<string, unknown>
|
106
|
-
if (rawTx.TransactionType === 'Batch') {
|
107
|
-
throw new ValidationError(
|
108
|
-
`Batch: RawTransactions[${index}] is a Batch transaction. Cannot nest Batch transactions.`,
|
109
|
-
)
|
110
|
-
}
|
111
|
-
})
|
112
|
-
// Full validation of each `RawTransaction` object is done in `validate` to avoid dependency cycles
|
113
|
-
|
114
|
-
validateOptionalField(tx, 'BatchSigners', isArray)
|
115
|
-
|
116
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
117
|
-
const batchSigners = tx.BatchSigners as unknown[] | undefined
|
118
|
-
batchSigners?.forEach((signerObj, index) => {
|
119
|
-
if (!isObject(signerObj)) {
|
120
|
-
throw new ValidationError(`Batch: BatchSigners[${index}] is not object.`)
|
121
|
-
}
|
122
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
123
|
-
const signerRecord = signerObj as Record<string, unknown>
|
124
|
-
validateRequiredField(signerRecord, 'BatchSigner', isObject, {
|
125
|
-
paramName: `BatchSigners[${index}].BatchSigner`,
|
126
|
-
txType: 'Batch',
|
127
|
-
})
|
128
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- checked above
|
129
|
-
const signer = signerRecord.BatchSigner as Record<string, unknown>
|
130
|
-
validateRequiredField(signer, 'Account', isString, {
|
131
|
-
paramName: `BatchSigners[${index}].Account`,
|
132
|
-
txType: 'Batch',
|
133
|
-
})
|
134
|
-
validateOptionalField(signer, 'SigningPubKey', isString, {
|
135
|
-
paramName: `BatchSigners[${index}].SigningPubKey`,
|
136
|
-
txType: 'Batch',
|
137
|
-
})
|
138
|
-
validateOptionalField(signer, 'TxnSignature', isString, {
|
139
|
-
paramName: `BatchSigners[${index}].TxnSignature`,
|
140
|
-
txType: 'Batch',
|
141
|
-
})
|
142
|
-
validateOptionalField(signer, 'Signers', isArray, {
|
143
|
-
paramName: `BatchSigners[${index}].Signers`,
|
144
|
-
txType: 'Batch',
|
145
|
-
})
|
146
|
-
})
|
147
|
-
}
|