xrpl 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/xrpl-latest-min.js +3 -0
- package/build/xrpl-latest-min.js.map +1 -0
- package/build/xrpl-latest.js +240 -54
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/client/index.d.ts +4 -0
- package/dist/npm/client/index.d.ts.map +1 -1
- package/dist/npm/client/index.js +11 -1
- package/dist/npm/client/index.js.map +1 -1
- package/dist/npm/models/index.d.ts +1 -1
- package/dist/npm/models/index.d.ts.map +1 -1
- package/dist/npm/models/index.js +3 -2
- package/dist/npm/models/index.js.map +1 -1
- package/dist/npm/models/ledger/LedgerEntry.d.ts +3 -2
- package/dist/npm/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/models/ledger/PermissionedDomain.d.ts +11 -0
- package/dist/npm/models/ledger/PermissionedDomain.d.ts.map +1 -0
- package/dist/npm/models/ledger/PermissionedDomain.js +3 -0
- package/dist/npm/models/ledger/PermissionedDomain.js.map +1 -0
- package/dist/npm/models/ledger/RippleState.d.ts +3 -1
- package/dist/npm/models/ledger/RippleState.d.ts.map +1 -1
- package/dist/npm/models/ledger/RippleState.js +2 -0
- package/dist/npm/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/models/methods/index.d.ts +5 -4
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledger.d.ts +2 -2
- package/dist/npm/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/models/methods/serverState.d.ts +1 -0
- package/dist/npm/models/methods/serverState.d.ts.map +1 -1
- package/dist/npm/models/methods/simulate.d.ts +42 -0
- package/dist/npm/models/methods/simulate.d.ts.map +1 -0
- package/dist/npm/models/methods/simulate.js +3 -0
- package/dist/npm/models/methods/simulate.js.map +1 -0
- package/dist/npm/models/transactions/AMMClawback.d.ts +17 -0
- package/dist/npm/models/transactions/AMMClawback.d.ts.map +1 -0
- package/dist/npm/models/transactions/AMMClawback.js +34 -0
- package/dist/npm/models/transactions/AMMClawback.js.map +1 -0
- package/dist/npm/models/transactions/NFTokenMint.d.ts +3 -1
- package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.js +1 -0
- package/dist/npm/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/models/transactions/NFTokenModify.d.ts +9 -0
- package/dist/npm/models/transactions/NFTokenModify.d.ts.map +1 -0
- package/dist/npm/models/transactions/NFTokenModify.js +22 -0
- package/dist/npm/models/transactions/NFTokenModify.js.map +1 -0
- package/dist/npm/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountDelete.js +1 -1
- package/dist/npm/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +5 -2
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +25 -7
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/depositPreauth.d.ts.map +1 -1
- package/dist/npm/models/transactions/depositPreauth.js +2 -2
- package/dist/npm/models/transactions/depositPreauth.js.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.js +1 -1
- package/dist/npm/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +5 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +5 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- 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.d.ts.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/permissionedDomainDelete.d.ts +7 -0
- package/dist/npm/models/transactions/permissionedDomainDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/permissionedDomainDelete.js +10 -0
- package/dist/npm/models/transactions/permissionedDomainDelete.js.map +1 -0
- package/dist/npm/models/transactions/permissionedDomainSet.d.ts +9 -0
- package/dist/npm/models/transactions/permissionedDomainSet.d.ts.map +1 -0
- package/dist/npm/models/transactions/permissionedDomainSet.js +13 -0
- package/dist/npm/models/transactions/permissionedDomainSet.js.map +1 -0
- package/dist/npm/models/transactions/transaction.d.ts +5 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +17 -1
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/transactions/trustSet.d.ts +5 -1
- package/dist/npm/models/transactions/trustSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/trustSet.js +2 -0
- package/dist/npm/models/transactions/trustSet.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts +1 -0
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +41 -28
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/client/index.d.ts +4 -0
- package/dist/npm/src/client/index.d.ts.map +1 -1
- package/dist/npm/src/client/index.js +11 -1
- package/dist/npm/src/client/index.js.map +1 -1
- package/dist/npm/src/models/index.d.ts +1 -1
- package/dist/npm/src/models/index.d.ts.map +1 -1
- package/dist/npm/src/models/index.js +3 -2
- package/dist/npm/src/models/index.js.map +1 -1
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts +3 -2
- package/dist/npm/src/models/ledger/LedgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/PermissionedDomain.d.ts +11 -0
- package/dist/npm/src/models/ledger/PermissionedDomain.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/PermissionedDomain.js +3 -0
- package/dist/npm/src/models/ledger/PermissionedDomain.js.map +1 -0
- package/dist/npm/src/models/ledger/RippleState.d.ts +3 -1
- package/dist/npm/src/models/ledger/RippleState.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/RippleState.js +2 -0
- package/dist/npm/src/models/ledger/RippleState.js.map +1 -1
- package/dist/npm/src/models/methods/index.d.ts +5 -4
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledger.d.ts +2 -2
- package/dist/npm/src/models/methods/ledger.d.ts.map +1 -1
- package/dist/npm/src/models/methods/serverState.d.ts +1 -0
- package/dist/npm/src/models/methods/serverState.d.ts.map +1 -1
- package/dist/npm/src/models/methods/simulate.d.ts +42 -0
- package/dist/npm/src/models/methods/simulate.d.ts.map +1 -0
- package/dist/npm/src/models/methods/simulate.js +3 -0
- package/dist/npm/src/models/methods/simulate.js.map +1 -0
- package/dist/npm/src/models/transactions/AMMClawback.d.ts +17 -0
- package/dist/npm/src/models/transactions/AMMClawback.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/AMMClawback.js +34 -0
- package/dist/npm/src/models/transactions/AMMClawback.js.map +1 -0
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts +3 -1
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js +1 -0
- package/dist/npm/src/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenModify.d.ts +9 -0
- package/dist/npm/src/models/transactions/NFTokenModify.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/NFTokenModify.js +22 -0
- package/dist/npm/src/models/transactions/NFTokenModify.js.map +1 -0
- package/dist/npm/src/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountDelete.js +1 -1
- package/dist/npm/src/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +5 -2
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +25 -7
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/depositPreauth.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/depositPreauth.js +2 -2
- package/dist/npm/src/models/transactions/depositPreauth.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.js +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +5 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +5 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- 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.d.ts.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/permissionedDomainDelete.d.ts +7 -0
- package/dist/npm/src/models/transactions/permissionedDomainDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/permissionedDomainDelete.js +10 -0
- package/dist/npm/src/models/transactions/permissionedDomainDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/permissionedDomainSet.d.ts +9 -0
- package/dist/npm/src/models/transactions/permissionedDomainSet.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/permissionedDomainSet.js +13 -0
- package/dist/npm/src/models/transactions/permissionedDomainSet.js.map +1 -0
- package/dist/npm/src/models/transactions/transaction.d.ts +5 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +17 -1
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/transactions/trustSet.d.ts +5 -1
- package/dist/npm/src/models/transactions/trustSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/trustSet.js +2 -0
- package/dist/npm/src/models/transactions/trustSet.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts +1 -0
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +41 -28
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/sugar/submit.d.ts.map +1 -1
- package/dist/npm/src/sugar/submit.js +7 -7
- package/dist/npm/src/sugar/submit.js.map +1 -1
- package/dist/npm/sugar/submit.d.ts.map +1 -1
- package/dist/npm/sugar/submit.js +7 -7
- package/dist/npm/sugar/submit.js.map +1 -1
- package/package.json +4 -4
- package/src/client/index.ts +42 -2
- package/src/models/index.ts +2 -1
- package/src/models/ledger/LedgerEntry.ts +3 -0
- package/src/models/ledger/PermissionedDomain.ts +29 -0
- package/src/models/ledger/RippleState.ts +4 -0
- package/src/models/methods/index.ts +18 -0
- package/src/models/methods/ledger.ts +2 -2
- package/src/models/methods/serverState.ts +1 -0
- package/src/models/methods/simulate.ts +88 -0
- package/src/models/transactions/AMMClawback.ts +120 -0
- package/src/models/transactions/NFTokenMint.ts +5 -0
- package/src/models/transactions/NFTokenModify.ts +67 -0
- package/src/models/transactions/accountDelete.ts +2 -0
- package/src/models/transactions/common.ts +49 -9
- package/src/models/transactions/depositPreauth.ts +3 -0
- package/src/models/transactions/escrowFinish.ts +2 -0
- package/src/models/transactions/index.ts +10 -1
- package/src/models/transactions/payment.ts +2 -0
- package/src/models/transactions/paymentChannelClaim.ts +2 -0
- package/src/models/transactions/permissionedDomainDelete.ts +28 -0
- package/src/models/transactions/permissionedDomainSet.ts +54 -0
- package/src/models/transactions/transaction.ts +32 -2
- package/src/models/transactions/trustSet.ts +10 -0
- package/src/models/utils/flags.ts +61 -35
- package/src/sugar/submit.ts +2 -3
@@ -0,0 +1,88 @@
|
|
1
|
+
import {
|
2
|
+
BaseTransaction,
|
3
|
+
Transaction,
|
4
|
+
TransactionMetadata,
|
5
|
+
} from '../transactions'
|
6
|
+
|
7
|
+
import { BaseRequest, BaseResponse } from './baseMethod'
|
8
|
+
|
9
|
+
/**
|
10
|
+
* The `simulate` method simulates a transaction without submitting it to the network.
|
11
|
+
* Returns a {@link SimulateResponse}.
|
12
|
+
*
|
13
|
+
* @category Requests
|
14
|
+
*/
|
15
|
+
export type SimulateRequest = BaseRequest & {
|
16
|
+
command: 'simulate'
|
17
|
+
|
18
|
+
binary?: boolean
|
19
|
+
} & (
|
20
|
+
| {
|
21
|
+
tx_blob: string
|
22
|
+
tx_json?: never
|
23
|
+
}
|
24
|
+
| {
|
25
|
+
tx_json: Transaction
|
26
|
+
tx_blob?: never
|
27
|
+
}
|
28
|
+
)
|
29
|
+
|
30
|
+
export type SimulateBinaryRequest = SimulateRequest & {
|
31
|
+
binary: true
|
32
|
+
}
|
33
|
+
|
34
|
+
export type SimulateJsonRequest = SimulateRequest & {
|
35
|
+
binary?: false
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Response expected from an {@link SimulateRequest}.
|
40
|
+
*
|
41
|
+
* @category Responses
|
42
|
+
*/
|
43
|
+
export type SimulateResponse = SimulateJsonResponse | SimulateBinaryResponse
|
44
|
+
|
45
|
+
export interface SimulateBinaryResponse extends BaseResponse {
|
46
|
+
result: {
|
47
|
+
applied: false
|
48
|
+
|
49
|
+
engine_result: string
|
50
|
+
|
51
|
+
engine_result_code: number
|
52
|
+
|
53
|
+
engine_result_message: string
|
54
|
+
|
55
|
+
tx_blob: string
|
56
|
+
|
57
|
+
meta_blob: string
|
58
|
+
|
59
|
+
/**
|
60
|
+
* The ledger index of the ledger version that was used to generate this
|
61
|
+
* response.
|
62
|
+
*/
|
63
|
+
ledger_index: number
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
export interface SimulateJsonResponse<T extends BaseTransaction = Transaction>
|
68
|
+
extends BaseResponse {
|
69
|
+
result: {
|
70
|
+
applied: false
|
71
|
+
|
72
|
+
engine_result: string
|
73
|
+
|
74
|
+
engine_result_code: number
|
75
|
+
|
76
|
+
engine_result_message: string
|
77
|
+
|
78
|
+
/**
|
79
|
+
* The ledger index of the ledger version that was used to generate this
|
80
|
+
* response.
|
81
|
+
*/
|
82
|
+
ledger_index: number
|
83
|
+
|
84
|
+
tx_json: T
|
85
|
+
|
86
|
+
meta?: TransactionMetadata<T>
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { ValidationError } from '../../errors'
|
2
|
+
import { Currency, IssuedCurrency, IssuedCurrencyAmount } from '../common'
|
3
|
+
|
4
|
+
import {
|
5
|
+
Account,
|
6
|
+
BaseTransaction,
|
7
|
+
GlobalFlags,
|
8
|
+
isAccount,
|
9
|
+
isAmount,
|
10
|
+
isCurrency,
|
11
|
+
validateBaseTransaction,
|
12
|
+
validateOptionalField,
|
13
|
+
validateRequiredField,
|
14
|
+
} from './common'
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Enum representing values for AMMClawback Transaction Flags.
|
18
|
+
*
|
19
|
+
* @category Transaction Flags
|
20
|
+
*/
|
21
|
+
export enum AMMClawbackFlags {
|
22
|
+
tfClawTwoAssets = 0x00000001,
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Map of flags to boolean values representing {@link AMMClawback} transaction
|
27
|
+
* flags.
|
28
|
+
*
|
29
|
+
* @category Transaction Flags
|
30
|
+
*/
|
31
|
+
export interface AMMClawbackFlagsInterface extends GlobalFlags {
|
32
|
+
tfClawTwoAssets?: boolean
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Claw back tokens from a holder that has deposited your issued tokens into an AMM pool.
|
37
|
+
*
|
38
|
+
* Clawback is disabled by default. To use clawback, you must send an AccountSet transaction to enable the
|
39
|
+
* Allow Trust Line Clawback setting. An issuer with any existing tokens cannot enable clawback. You can
|
40
|
+
* only enable Allow Trust Line Clawback if you have a completely empty owner directory, meaning you must
|
41
|
+
* do so before you set up any trust lines, offers, escrows, payment channels, checks, or signer lists.
|
42
|
+
* After you enable clawback, it cannot reverted: the account permanently gains the ability to claw back
|
43
|
+
* issued assets on trust lines.
|
44
|
+
*/
|
45
|
+
export interface AMMClawback extends BaseTransaction {
|
46
|
+
TransactionType: 'AMMClawback'
|
47
|
+
|
48
|
+
/**
|
49
|
+
* The account holding the asset to be clawed back.
|
50
|
+
*/
|
51
|
+
Holder: Account
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Specifies the asset that the issuer wants to claw back from the AMM pool.
|
55
|
+
* In JSON, this is an object with currency and issuer fields. The issuer field must match with Account.
|
56
|
+
*/
|
57
|
+
Asset: IssuedCurrency
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Specifies the other asset in the AMM's pool. In JSON, this is an object with currency and
|
61
|
+
* issuer fields (omit issuer for XRP).
|
62
|
+
*/
|
63
|
+
Asset2: Currency
|
64
|
+
|
65
|
+
/**
|
66
|
+
* The maximum amount to claw back from the AMM account. The currency and issuer subfields should match
|
67
|
+
* the Asset subfields. If this field isn't specified, or the value subfield exceeds the holder's available
|
68
|
+
* tokens in the AMM, all of the holder's tokens will be clawed back.
|
69
|
+
*/
|
70
|
+
Amount?: IssuedCurrencyAmount
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Verify the form and type of an AMMClawback at runtime.
|
75
|
+
*
|
76
|
+
* @param tx - An AMMClawback Transaction.
|
77
|
+
* @throws {ValidationError} When the transaction is malformed.
|
78
|
+
*/
|
79
|
+
export function validateAMMClawback(tx: Record<string, unknown>): void {
|
80
|
+
validateBaseTransaction(tx)
|
81
|
+
|
82
|
+
validateRequiredField(tx, 'Holder', isAccount)
|
83
|
+
|
84
|
+
validateRequiredField(tx, 'Asset', isCurrency)
|
85
|
+
|
86
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- required
|
87
|
+
const asset = tx.Asset as IssuedCurrency
|
88
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- required
|
89
|
+
const amount = tx.Amount as IssuedCurrencyAmount
|
90
|
+
|
91
|
+
if (tx.Holder === asset.issuer) {
|
92
|
+
throw new ValidationError(
|
93
|
+
'AMMClawback: Holder and Asset.issuer must be distinct',
|
94
|
+
)
|
95
|
+
}
|
96
|
+
|
97
|
+
if (tx.Account !== asset.issuer) {
|
98
|
+
throw new ValidationError(
|
99
|
+
'AMMClawback: Account must be the same as Asset.issuer',
|
100
|
+
)
|
101
|
+
}
|
102
|
+
|
103
|
+
validateRequiredField(tx, 'Asset2', isCurrency)
|
104
|
+
|
105
|
+
validateOptionalField(tx, 'Amount', isAmount)
|
106
|
+
|
107
|
+
if (tx.Amount != null) {
|
108
|
+
if (amount.currency !== asset.currency) {
|
109
|
+
throw new ValidationError(
|
110
|
+
'AMMClawback: Amount.currency must match Asset.currency',
|
111
|
+
)
|
112
|
+
}
|
113
|
+
|
114
|
+
if (amount.issuer !== asset.issuer) {
|
115
|
+
throw new ValidationError(
|
116
|
+
'AMMClawback: Amount.issuer must match Amount.issuer',
|
117
|
+
)
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
@@ -38,6 +38,10 @@ export enum NFTokenMintFlags {
|
|
38
38
|
* issuer.
|
39
39
|
*/
|
40
40
|
tfTransferable = 0x00000008,
|
41
|
+
/**
|
42
|
+
* If set, indicates that this NFT's URI can be modified.
|
43
|
+
*/
|
44
|
+
tfMutable = 0x00000010,
|
41
45
|
}
|
42
46
|
|
43
47
|
/**
|
@@ -51,6 +55,7 @@ export interface NFTokenMintFlagsInterface extends GlobalFlags {
|
|
51
55
|
tfOnlyXRP?: boolean
|
52
56
|
tfTrustLine?: boolean
|
53
57
|
tfTransferable?: boolean
|
58
|
+
tfMutable?: boolean
|
54
59
|
}
|
55
60
|
|
56
61
|
/**
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { ValidationError } from '../../errors'
|
2
|
+
import { isHex } from '../utils'
|
3
|
+
|
4
|
+
import {
|
5
|
+
BaseTransaction,
|
6
|
+
validateBaseTransaction,
|
7
|
+
isAccount,
|
8
|
+
isString,
|
9
|
+
validateOptionalField,
|
10
|
+
Account,
|
11
|
+
validateRequiredField,
|
12
|
+
} from './common'
|
13
|
+
|
14
|
+
/**
|
15
|
+
* The NFTokenModify transaction modifies an NFToken's URI
|
16
|
+
* if its tfMutable is set to true.
|
17
|
+
*/
|
18
|
+
export interface NFTokenModify extends BaseTransaction {
|
19
|
+
TransactionType: 'NFTokenModify'
|
20
|
+
/**
|
21
|
+
* Identifies the NFTokenID of the NFToken object that the
|
22
|
+
* offer references.
|
23
|
+
*/
|
24
|
+
NFTokenID: string
|
25
|
+
/**
|
26
|
+
* Indicates the AccountID of the account that owns the corresponding NFToken.
|
27
|
+
* Can be omitted if the owner is the account submitting this transaction
|
28
|
+
*/
|
29
|
+
Owner?: Account
|
30
|
+
/**
|
31
|
+
* URI that points to the data and/or metadata associated with the NFT.
|
32
|
+
* This field need not be an HTTP or HTTPS URL; it could be an IPFS URI, a
|
33
|
+
* magnet link, immediate data encoded as an RFC2379 "data" URL, or even an
|
34
|
+
* opaque issuer-specific encoding. The URI is NOT checked for validity, but
|
35
|
+
* the field is limited to a maximum length of 256 bytes.
|
36
|
+
*
|
37
|
+
* This field must be hex-encoded. You can use `convertStringToHex` to
|
38
|
+
* convert this field to the proper encoding.
|
39
|
+
*
|
40
|
+
* This field must not be an empty string. Omit it from the transaction or
|
41
|
+
* set to `null` if you do not use it.
|
42
|
+
*/
|
43
|
+
URI?: string | null
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Verify the form and type of an NFTokenModify at runtime.
|
48
|
+
*
|
49
|
+
* @param tx - An NFTokenModify Transaction.
|
50
|
+
* @throws When the NFTokenModify is Malformed.
|
51
|
+
*/
|
52
|
+
export function validateNFTokenModify(tx: Record<string, unknown>): void {
|
53
|
+
validateBaseTransaction(tx)
|
54
|
+
|
55
|
+
validateRequiredField(tx, 'NFTokenID', isString)
|
56
|
+
validateOptionalField(tx, 'Owner', isAccount)
|
57
|
+
validateOptionalField(tx, 'URI', isString)
|
58
|
+
|
59
|
+
if (tx.URI !== undefined && typeof tx.URI === 'string') {
|
60
|
+
if (tx.URI === '') {
|
61
|
+
throw new ValidationError('NFTokenModify: URI must not be empty string')
|
62
|
+
}
|
63
|
+
if (!isHex(tx.URI)) {
|
64
|
+
throw new ValidationError('NFTokenModify: URI must be in hex format')
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
validateCredentialsList,
|
8
8
|
validateOptionalField,
|
9
9
|
validateRequiredField,
|
10
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
10
11
|
} from './common'
|
11
12
|
|
12
13
|
/**
|
@@ -54,5 +55,6 @@ export function validateAccountDelete(tx: Record<string, unknown>): void {
|
|
54
55
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
55
56
|
tx.TransactionType as string,
|
56
57
|
true,
|
58
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
57
59
|
)
|
58
60
|
}
|
@@ -9,15 +9,15 @@ import {
|
|
9
9
|
AuthorizeCredential,
|
10
10
|
Currency,
|
11
11
|
IssuedCurrencyAmount,
|
12
|
+
MPTAmount,
|
12
13
|
Memo,
|
13
14
|
Signer,
|
14
15
|
XChainBridge,
|
15
|
-
MPTAmount,
|
16
16
|
} from '../common'
|
17
17
|
import { onlyHasFields } from '../utils'
|
18
18
|
|
19
19
|
const MEMO_SIZE = 3
|
20
|
-
const
|
20
|
+
export const MAX_AUTHORIZED_CREDENTIALS = 8
|
21
21
|
const MAX_CREDENTIAL_BYTE_LENGTH = 64
|
22
22
|
const MAX_CREDENTIAL_TYPE_LENGTH = MAX_CREDENTIAL_BYTE_LENGTH * 2
|
23
23
|
|
@@ -134,7 +134,9 @@ export function isIssuedCurrency(
|
|
134
134
|
* @param input - The input to check the form and type of
|
135
135
|
* @returns Whether the AuthorizeCredential is properly formed
|
136
136
|
*/
|
137
|
-
function isAuthorizeCredential(
|
137
|
+
export function isAuthorizeCredential(
|
138
|
+
input: unknown,
|
139
|
+
): input is AuthorizeCredential {
|
138
140
|
return (
|
139
141
|
isRecord(input) &&
|
140
142
|
isRecord(input.Credential) &&
|
@@ -455,13 +457,16 @@ export function validateCredentialType(tx: Record<string, unknown>): void {
|
|
455
457
|
* @param credentials An array of credential IDs to check for errors
|
456
458
|
* @param transactionType The transaction type to include in error messages
|
457
459
|
* @param isStringID Toggle for if array contains IDs instead of AuthorizeCredential objects
|
460
|
+
* @param maxCredentials The maximum length of the credentials array.
|
461
|
+
* PermissionedDomainSet transaction uses 10, other transactions use 8.
|
458
462
|
* @throws Validation Error if the formatting is incorrect
|
459
463
|
*/
|
460
|
-
// eslint-disable-next-line max-lines-per-function -- separating logic further will add unnecessary complexity
|
464
|
+
// eslint-disable-next-line max-lines-per-function, max-params -- separating logic further will add unnecessary complexity
|
461
465
|
export function validateCredentialsList(
|
462
466
|
credentials: unknown,
|
463
467
|
transactionType: string,
|
464
468
|
isStringID: boolean,
|
469
|
+
maxCredentials: number,
|
465
470
|
): void {
|
466
471
|
if (credentials == null) {
|
467
472
|
return
|
@@ -471,9 +476,9 @@ export function validateCredentialsList(
|
|
471
476
|
`${transactionType}: Credentials must be an array`,
|
472
477
|
)
|
473
478
|
}
|
474
|
-
if (credentials.length >
|
479
|
+
if (credentials.length > maxCredentials) {
|
475
480
|
throw new ValidationError(
|
476
|
-
`${transactionType}: Credentials length cannot exceed ${
|
481
|
+
`${transactionType}: Credentials length cannot exceed ${maxCredentials} elements`,
|
477
482
|
)
|
478
483
|
} else if (credentials.length === 0) {
|
479
484
|
throw new ValidationError(
|
@@ -500,7 +505,42 @@ export function validateCredentialsList(
|
|
500
505
|
}
|
501
506
|
}
|
502
507
|
|
503
|
-
|
504
|
-
|
505
|
-
|
508
|
+
// Type guard to ensure we're working with AuthorizeCredential[]
|
509
|
+
// Note: This is not a rigorous type-guard. A more thorough solution would be to iterate over the array and check each item.
|
510
|
+
function isAuthorizeCredentialArray(
|
511
|
+
list: AuthorizeCredential[] | string[],
|
512
|
+
): list is AuthorizeCredential[] {
|
513
|
+
return typeof list[0] !== 'string'
|
514
|
+
}
|
515
|
+
|
516
|
+
/**
|
517
|
+
* Check if an array of objects contains any duplicates.
|
518
|
+
*
|
519
|
+
* @param objectList - Array of objects to check for duplicates
|
520
|
+
* @returns True if duplicates exist, false otherwise
|
521
|
+
*/
|
522
|
+
export function containsDuplicates(
|
523
|
+
objectList: AuthorizeCredential[] | string[],
|
524
|
+
): boolean {
|
525
|
+
// Case-1: Process a list of string-IDs
|
526
|
+
if (typeof objectList[0] === 'string') {
|
527
|
+
const objSet = new Set(objectList.map((obj) => JSON.stringify(obj)))
|
528
|
+
return objSet.size !== objectList.length
|
529
|
+
}
|
530
|
+
|
531
|
+
// Case-2: Process a list of nested objects
|
532
|
+
const seen = new Set<string>()
|
533
|
+
|
534
|
+
if (isAuthorizeCredentialArray(objectList)) {
|
535
|
+
for (const item of objectList) {
|
536
|
+
const key = `${item.Credential.Issuer}-${item.Credential.CredentialType}`
|
537
|
+
// eslint-disable-next-line max-depth -- necessary to check for type-guards
|
538
|
+
if (seen.has(key)) {
|
539
|
+
return true
|
540
|
+
}
|
541
|
+
seen.add(key)
|
542
|
+
}
|
543
|
+
}
|
544
|
+
|
545
|
+
return false
|
506
546
|
}
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
BaseTransaction,
|
6
6
|
validateBaseTransaction,
|
7
7
|
validateCredentialsList,
|
8
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
8
9
|
} from './common'
|
9
10
|
|
10
11
|
/**
|
@@ -72,6 +73,7 @@ export function validateDepositPreauth(tx: Record<string, unknown>): void {
|
|
72
73
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- confirmed in base transaction check
|
73
74
|
tx.TransactionType as string,
|
74
75
|
false,
|
76
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
75
77
|
)
|
76
78
|
} else if (tx.UnauthorizeCredentials !== undefined) {
|
77
79
|
validateCredentialsList(
|
@@ -79,6 +81,7 @@ export function validateDepositPreauth(tx: Record<string, unknown>): void {
|
|
79
81
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- confirmed in base transaction check
|
80
82
|
tx.TransactionType as string,
|
81
83
|
false,
|
84
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
82
85
|
)
|
83
86
|
}
|
84
87
|
}
|
@@ -7,6 +7,7 @@ import {
|
|
7
7
|
validateBaseTransaction,
|
8
8
|
validateCredentialsList,
|
9
9
|
validateRequiredField,
|
10
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
10
11
|
} from './common'
|
11
12
|
|
12
13
|
/**
|
@@ -55,6 +56,7 @@ export function validateEscrowFinish(tx: Record<string, unknown>): void {
|
|
55
56
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
56
57
|
tx.TransactionType as string,
|
57
58
|
true,
|
59
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
58
60
|
)
|
59
61
|
|
60
62
|
if (tx.OfferSequence == null) {
|
@@ -15,13 +15,18 @@ export {
|
|
15
15
|
} from './accountSet'
|
16
16
|
export { AccountDelete } from './accountDelete'
|
17
17
|
export { AMMBid } from './AMMBid'
|
18
|
+
export {
|
19
|
+
AMMClawbackFlags,
|
20
|
+
AMMClawbackFlagsInterface,
|
21
|
+
AMMClawback,
|
22
|
+
} from './AMMClawback'
|
23
|
+
export { AMMCreate } from './AMMCreate'
|
18
24
|
export { AMMDelete } from './AMMDelete'
|
19
25
|
export {
|
20
26
|
AMMDepositFlags,
|
21
27
|
AMMDepositFlagsInterface,
|
22
28
|
AMMDeposit,
|
23
29
|
} from './AMMDeposit'
|
24
|
-
export { AMMCreate } from './AMMCreate'
|
25
30
|
export { AMMVote } from './AMMVote'
|
26
31
|
export {
|
27
32
|
AMMWithdrawFlags,
|
@@ -71,6 +76,7 @@ export {
|
|
71
76
|
NFTokenMintFlags,
|
72
77
|
NFTokenMintFlagsInterface,
|
73
78
|
} from './NFTokenMint'
|
79
|
+
export { NFTokenModify, validateNFTokenModify } from './NFTokenModify'
|
74
80
|
export { OfferCancel } from './offerCancel'
|
75
81
|
export {
|
76
82
|
OfferCreateFlags,
|
@@ -105,3 +111,6 @@ export {
|
|
105
111
|
XChainModifyBridgeFlags,
|
106
112
|
XChainModifyBridgeFlagsInterface,
|
107
113
|
} from './XChainModifyBridge'
|
114
|
+
|
115
|
+
export { PermissionedDomainSet } from './permissionedDomainSet'
|
116
|
+
export { PermissionedDomainDelete } from './permissionedDomainDelete'
|
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
isNumber,
|
14
14
|
Account,
|
15
15
|
validateCredentialsList,
|
16
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
16
17
|
} from './common'
|
17
18
|
import type { TransactionMetadataBase } from './metadata'
|
18
19
|
|
@@ -188,6 +189,7 @@ export function validatePayment(tx: Record<string, unknown>): void {
|
|
188
189
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
189
190
|
tx.TransactionType as string,
|
190
191
|
true,
|
192
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
191
193
|
)
|
192
194
|
|
193
195
|
if (tx.InvoiceID !== undefined && typeof tx.InvoiceID !== 'string') {
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
GlobalFlags,
|
6
6
|
validateBaseTransaction,
|
7
7
|
validateCredentialsList,
|
8
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
8
9
|
} from './common'
|
9
10
|
|
10
11
|
/**
|
@@ -153,6 +154,7 @@ export function validatePaymentChannelClaim(tx: Record<string, unknown>): void {
|
|
153
154
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
154
155
|
tx.TransactionType as string,
|
155
156
|
true,
|
157
|
+
MAX_AUTHORIZED_CREDENTIALS,
|
156
158
|
)
|
157
159
|
|
158
160
|
if (tx.Channel === undefined) {
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import {
|
2
|
+
BaseTransaction,
|
3
|
+
isString,
|
4
|
+
validateBaseTransaction,
|
5
|
+
validateRequiredField,
|
6
|
+
} from './common'
|
7
|
+
|
8
|
+
export interface PermissionedDomainDelete extends BaseTransaction {
|
9
|
+
/* The transaction type (PermissionedDomainDelete). */
|
10
|
+
TransactionType: 'PermissionedDomainDelete'
|
11
|
+
|
12
|
+
/* The domain to delete. */
|
13
|
+
DomainID: string
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Verify the form and type of a PermissionedDomainDelete transaction.
|
18
|
+
*
|
19
|
+
* @param tx - The transaction to verify.
|
20
|
+
* @throws When the transaction is malformed.
|
21
|
+
*/
|
22
|
+
export function validatePermissionedDomainDelete(
|
23
|
+
tx: Record<string, unknown>,
|
24
|
+
): void {
|
25
|
+
validateBaseTransaction(tx)
|
26
|
+
|
27
|
+
validateRequiredField(tx, 'DomainID', isString)
|
28
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { AuthorizeCredential } from '../common'
|
2
|
+
|
3
|
+
import {
|
4
|
+
BaseTransaction,
|
5
|
+
isString,
|
6
|
+
validateBaseTransaction,
|
7
|
+
validateOptionalField,
|
8
|
+
validateRequiredField,
|
9
|
+
validateCredentialsList,
|
10
|
+
} from './common'
|
11
|
+
|
12
|
+
const MAX_ACCEPTED_CREDENTIALS = 10
|
13
|
+
|
14
|
+
export interface PermissionedDomainSet extends BaseTransaction {
|
15
|
+
/* The transaction type (PermissionedDomainSet). */
|
16
|
+
TransactionType: 'PermissionedDomainSet'
|
17
|
+
|
18
|
+
/* The domain to modify. Must be included if modifying an existing domain. */
|
19
|
+
DomainID?: string
|
20
|
+
|
21
|
+
/* The credentials that are accepted by the domain. Ownership of one
|
22
|
+
of these credentials automatically makes you a member of the domain.
|
23
|
+
An empty array means deleting the field. */
|
24
|
+
AcceptedCredentials: AuthorizeCredential[]
|
25
|
+
}
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Validate a PermissionedDomainSet transaction.
|
29
|
+
*
|
30
|
+
* @param tx - The transaction to validate.
|
31
|
+
* @throws {ValidationError} When the transaction is invalid.
|
32
|
+
*/
|
33
|
+
export function validatePermissionedDomainSet(
|
34
|
+
tx: Record<string, unknown>,
|
35
|
+
): void {
|
36
|
+
validateBaseTransaction(tx)
|
37
|
+
|
38
|
+
validateOptionalField(tx, 'DomainID', isString)
|
39
|
+
validateRequiredField(
|
40
|
+
tx,
|
41
|
+
'AcceptedCredentials',
|
42
|
+
() => tx.AcceptedCredentials instanceof Array,
|
43
|
+
)
|
44
|
+
|
45
|
+
validateCredentialsList(
|
46
|
+
tx.AcceptedCredentials,
|
47
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
48
|
+
tx.TransactionType as string,
|
49
|
+
// PermissionedDomainSet uses AuthorizeCredential nested objects only, strings are not allowed
|
50
|
+
false,
|
51
|
+
// PermissionedDomainSet uses at most 10 accepted credentials. This is different from Credential-feature transactions.
|
52
|
+
MAX_ACCEPTED_CREDENTIALS,
|
53
|
+
)
|
54
|
+
}
|