xrpl 4.0.0 → 4.1.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 +1 -1
- package/build/xrpl-latest.js +2789 -731
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/client/partialPayment.d.ts +2 -2
- package/dist/npm/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/client/partialPayment.js +11 -3
- package/dist/npm/client/partialPayment.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +10 -0
- package/dist/npm/models/common/index.d.ts.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 +2 -1
- package/dist/npm/models/index.js.map +1 -1
- package/dist/npm/models/ledger/Credential.d.ts +17 -0
- package/dist/npm/models/ledger/Credential.d.ts.map +1 -0
- package/dist/npm/models/ledger/Credential.js +3 -0
- package/dist/npm/models/ledger/Credential.js.map +1 -0
- package/dist/npm/models/ledger/DepositPreauth.d.ts +3 -1
- package/dist/npm/models/ledger/DepositPreauth.d.ts.map +1 -1
- package/dist/npm/models/ledger/Ledger.d.ts +1 -0
- package/dist/npm/models/ledger/Ledger.d.ts.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/MPToken.d.ts +10 -0
- package/dist/npm/models/ledger/MPToken.d.ts.map +1 -0
- package/dist/npm/models/ledger/MPToken.js +3 -0
- package/dist/npm/models/ledger/MPToken.js.map +1 -0
- package/dist/npm/models/ledger/MPTokenIssuance.d.ts +13 -0
- package/dist/npm/models/ledger/MPTokenIssuance.d.ts.map +1 -0
- package/dist/npm/models/ledger/MPTokenIssuance.js +3 -0
- package/dist/npm/models/ledger/MPTokenIssuance.js.map +1 -0
- package/dist/npm/models/ledger/index.d.ts +4 -1
- package/dist/npm/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.js.map +1 -1
- package/dist/npm/models/methods/depositAuthorized.d.ts +2 -0
- package/dist/npm/models/methods/depositAuthorized.d.ts.map +1 -1
- package/dist/npm/models/methods/index.d.ts +2 -2
- package/dist/npm/models/methods/index.d.ts.map +1 -1
- package/dist/npm/models/methods/ledgerEntry.d.ts +12 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/methods/subscribe.d.ts +7 -3
- package/dist/npm/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/models/transactions/CredentialAccept.d.ts +9 -0
- package/dist/npm/models/transactions/CredentialAccept.d.ts.map +1 -0
- package/dist/npm/models/transactions/CredentialAccept.js +12 -0
- package/dist/npm/models/transactions/CredentialAccept.js.map +1 -0
- package/dist/npm/models/transactions/CredentialCreate.d.ts +11 -0
- package/dist/npm/models/transactions/CredentialCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/CredentialCreate.js +34 -0
- package/dist/npm/models/transactions/CredentialCreate.js.map +1 -0
- package/dist/npm/models/transactions/CredentialDelete.d.ts +10 -0
- package/dist/npm/models/transactions/CredentialDelete.d.ts.map +1 -0
- package/dist/npm/models/transactions/CredentialDelete.js +17 -0
- package/dist/npm/models/transactions/CredentialDelete.js.map +1 -0
- package/dist/npm/models/transactions/MPTokenAuthorize.d.ts +15 -0
- package/dist/npm/models/transactions/MPTokenAuthorize.d.ts.map +1 -0
- package/dist/npm/models/transactions/MPTokenAuthorize.js +15 -0
- package/dist/npm/models/transactions/MPTokenAuthorize.js.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.d.ts +31 -0
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.js +54 -0
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.js.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceDestroy.d.ts +7 -0
- package/dist/npm/models/transactions/MPTokenIssuanceDestroy.d.ts.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceDestroy.js +10 -0
- package/dist/npm/models/transactions/MPTokenIssuanceDestroy.js.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts +17 -0
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -0
- package/dist/npm/models/transactions/MPTokenIssuanceSet.js +29 -0
- package/dist/npm/models/transactions/MPTokenIssuanceSet.js.map +1 -0
- package/dist/npm/models/transactions/accountDelete.d.ts +1 -0
- package/dist/npm/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/models/transactions/accountDelete.js +1 -0
- package/dist/npm/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/models/transactions/clawback.d.ts +3 -2
- package/dist/npm/models/transactions/clawback.d.ts.map +1 -1
- package/dist/npm/models/transactions/clawback.js +11 -1
- package/dist/npm/models/transactions/clawback.js.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +4 -1
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +79 -4
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/depositPreauth.d.ts +3 -0
- package/dist/npm/models/transactions/depositPreauth.d.ts.map +1 -1
- package/dist/npm/models/transactions/depositPreauth.js +20 -7
- package/dist/npm/models/transactions/depositPreauth.js.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.d.ts +1 -0
- package/dist/npm/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.js +1 -0
- package/dist/npm/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/models/transactions/index.d.ts +8 -1
- package/dist/npm/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/models/transactions/index.js +9 -1
- package/dist/npm/models/transactions/index.js.map +1 -1
- package/dist/npm/models/transactions/metadata.d.ts +5 -4
- 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/payment.d.ts +7 -6
- package/dist/npm/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/models/transactions/payment.js +1 -0
- package/dist/npm/models/transactions/payment.js.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.d.ts +1 -0
- package/dist/npm/models/transactions/paymentChannelClaim.d.ts.map +1 -1
- package/dist/npm/models/transactions/paymentChannelClaim.js +1 -0
- package/dist/npm/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +28 -0
- package/dist/npm/models/transactions/transaction.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 +23 -1
- package/dist/npm/models/utils/flags.js.map +1 -1
- package/dist/npm/models/utils/index.d.ts +1 -0
- package/dist/npm/models/utils/index.d.ts.map +1 -1
- package/dist/npm/models/utils/index.js +2 -1
- package/dist/npm/models/utils/index.js.map +1 -1
- package/dist/npm/snippets/src/paths.js +5 -9
- package/dist/npm/snippets/src/paths.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/client/partialPayment.d.ts +2 -2
- package/dist/npm/src/client/partialPayment.d.ts.map +1 -1
- package/dist/npm/src/client/partialPayment.js +11 -3
- package/dist/npm/src/client/partialPayment.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +10 -0
- package/dist/npm/src/models/common/index.d.ts.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 +2 -1
- package/dist/npm/src/models/index.js.map +1 -1
- package/dist/npm/src/models/ledger/Credential.d.ts +17 -0
- package/dist/npm/src/models/ledger/Credential.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/Credential.js +3 -0
- package/dist/npm/src/models/ledger/Credential.js.map +1 -0
- package/dist/npm/src/models/ledger/DepositPreauth.d.ts +3 -1
- package/dist/npm/src/models/ledger/DepositPreauth.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/Ledger.d.ts +1 -0
- package/dist/npm/src/models/ledger/Ledger.d.ts.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/MPToken.d.ts +10 -0
- package/dist/npm/src/models/ledger/MPToken.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/MPToken.js +3 -0
- package/dist/npm/src/models/ledger/MPToken.js.map +1 -0
- package/dist/npm/src/models/ledger/MPTokenIssuance.d.ts +13 -0
- package/dist/npm/src/models/ledger/MPTokenIssuance.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/MPTokenIssuance.js +3 -0
- package/dist/npm/src/models/ledger/MPTokenIssuance.js.map +1 -0
- package/dist/npm/src/models/ledger/index.d.ts +4 -1
- package/dist/npm/src/models/ledger/index.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.js.map +1 -1
- package/dist/npm/src/models/methods/depositAuthorized.d.ts +2 -0
- package/dist/npm/src/models/methods/depositAuthorized.d.ts.map +1 -1
- package/dist/npm/src/models/methods/index.d.ts +2 -2
- package/dist/npm/src/models/methods/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/ledgerEntry.d.ts +12 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/methods/subscribe.d.ts +7 -3
- package/dist/npm/src/models/methods/subscribe.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/CredentialAccept.d.ts +9 -0
- package/dist/npm/src/models/transactions/CredentialAccept.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/CredentialAccept.js +12 -0
- package/dist/npm/src/models/transactions/CredentialAccept.js.map +1 -0
- package/dist/npm/src/models/transactions/CredentialCreate.d.ts +11 -0
- package/dist/npm/src/models/transactions/CredentialCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/CredentialCreate.js +34 -0
- package/dist/npm/src/models/transactions/CredentialCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/CredentialDelete.d.ts +10 -0
- package/dist/npm/src/models/transactions/CredentialDelete.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/CredentialDelete.js +17 -0
- package/dist/npm/src/models/transactions/CredentialDelete.js.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenAuthorize.d.ts +15 -0
- package/dist/npm/src/models/transactions/MPTokenAuthorize.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenAuthorize.js +15 -0
- package/dist/npm/src/models/transactions/MPTokenAuthorize.js.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.d.ts +31 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.js +54 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.js.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceDestroy.d.ts +7 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceDestroy.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceDestroy.js +10 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceDestroy.js.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts +17 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.js +29 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.js.map +1 -0
- package/dist/npm/src/models/transactions/accountDelete.d.ts +1 -0
- package/dist/npm/src/models/transactions/accountDelete.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/accountDelete.js +1 -0
- package/dist/npm/src/models/transactions/accountDelete.js.map +1 -1
- package/dist/npm/src/models/transactions/clawback.d.ts +3 -2
- package/dist/npm/src/models/transactions/clawback.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/clawback.js +11 -1
- package/dist/npm/src/models/transactions/clawback.js.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +4 -1
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +79 -4
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/depositPreauth.d.ts +3 -0
- package/dist/npm/src/models/transactions/depositPreauth.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/depositPreauth.js +20 -7
- package/dist/npm/src/models/transactions/depositPreauth.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.d.ts +1 -0
- package/dist/npm/src/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.js +1 -0
- package/dist/npm/src/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/src/models/transactions/index.d.ts +8 -1
- package/dist/npm/src/models/transactions/index.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/index.js +9 -1
- package/dist/npm/src/models/transactions/index.js.map +1 -1
- package/dist/npm/src/models/transactions/metadata.d.ts +5 -4
- 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/payment.d.ts +7 -6
- package/dist/npm/src/models/transactions/payment.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/payment.js +1 -0
- package/dist/npm/src/models/transactions/payment.js.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.d.ts +1 -0
- package/dist/npm/src/models/transactions/paymentChannelClaim.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/paymentChannelClaim.js +1 -0
- package/dist/npm/src/models/transactions/paymentChannelClaim.js.map +1 -1
- package/dist/npm/src/models/transactions/transaction.d.ts +8 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +28 -0
- package/dist/npm/src/models/transactions/transaction.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 +23 -1
- package/dist/npm/src/models/utils/flags.js.map +1 -1
- package/dist/npm/src/models/utils/index.d.ts +1 -0
- package/dist/npm/src/models/utils/index.d.ts.map +1 -1
- package/dist/npm/src/models/utils/index.js +2 -1
- package/dist/npm/src/models/utils/index.js.map +1 -1
- package/package.json +5 -5
- package/src/client/partialPayment.ts +37 -7
- package/src/models/common/index.ts +15 -0
- package/src/models/index.ts +1 -0
- package/src/models/ledger/Credential.ts +47 -0
- package/src/models/ledger/DepositPreauth.ts +6 -2
- package/src/models/ledger/Ledger.ts +5 -0
- package/src/models/ledger/LedgerEntry.ts +5 -0
- package/src/models/ledger/MPToken.ts +11 -0
- package/src/models/ledger/MPTokenIssuance.ts +13 -0
- package/src/models/ledger/index.ts +6 -0
- package/src/models/methods/depositAuthorized.ts +10 -0
- package/src/models/methods/index.ts +2 -0
- package/src/models/methods/ledgerEntry.ts +45 -1
- package/src/models/methods/subscribe.ts +34 -3
- package/src/models/transactions/CredentialAccept.ts +44 -0
- package/src/models/transactions/CredentialCreate.ts +81 -0
- package/src/models/transactions/CredentialDelete.ts +55 -0
- package/src/models/transactions/MPTokenAuthorize.ts +67 -0
- package/src/models/transactions/MPTokenIssuanceCreate.ts +179 -0
- package/src/models/transactions/MPTokenIssuanceDestroy.ts +34 -0
- package/src/models/transactions/MPTokenIssuanceSet.ts +86 -0
- package/src/models/transactions/accountDelete.ts +14 -0
- package/src/models/transactions/clawback.ts +27 -6
- package/src/models/transactions/common.ts +139 -1
- package/src/models/transactions/depositPreauth.ts +51 -15
- package/src/models/transactions/escrowFinish.ts +12 -0
- package/src/models/transactions/index.ts +20 -1
- package/src/models/transactions/metadata.ts +9 -3
- package/src/models/transactions/payment.ts +19 -6
- package/src/models/transactions/paymentChannelClaim.ts +18 -1
- package/src/models/transactions/transaction.ts +51 -0
- package/src/models/utils/flags.ts +33 -1
- package/src/models/utils/index.ts +1 -0
- package/build/xrpl-latest-min.js +0 -3
- package/build/xrpl-latest-min.js.map +0 -1
- package/dist/npm/snippets/src/bridgeTransfer.d.ts +0 -2
- package/dist/npm/snippets/src/bridgeTransfer.d.ts.map +0 -1
- package/dist/npm/snippets/src/bridgeTransfer.js +0 -126
- package/dist/npm/snippets/src/bridgeTransfer.js.map +0 -1
@@ -0,0 +1,67 @@
|
|
1
|
+
import {
|
2
|
+
BaseTransaction,
|
3
|
+
isString,
|
4
|
+
validateBaseTransaction,
|
5
|
+
validateRequiredField,
|
6
|
+
Account,
|
7
|
+
validateOptionalField,
|
8
|
+
isAccount,
|
9
|
+
GlobalFlags,
|
10
|
+
} from './common'
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Transaction Flags for an MPTokenAuthorize Transaction.
|
14
|
+
*
|
15
|
+
* @category Transaction Flags
|
16
|
+
*/
|
17
|
+
export enum MPTokenAuthorizeFlags {
|
18
|
+
/**
|
19
|
+
* If set and transaction is submitted by a holder, it indicates that the holder no
|
20
|
+
* longer wants to hold the MPToken, which will be deleted as a result. If the the holder's
|
21
|
+
* MPToken has non-zero balance while trying to set this flag, the transaction will fail. On
|
22
|
+
* the other hand, if set and transaction is submitted by an issuer, it would mean that the
|
23
|
+
* issuer wants to unauthorize the holder (only applicable for allow-listing),
|
24
|
+
* which would unset the lsfMPTAuthorized flag on the MPToken.
|
25
|
+
*/
|
26
|
+
tfMPTUnauthorize = 0x00000001,
|
27
|
+
}
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Map of flags to boolean values representing {@link MPTokenAuthorize} transaction
|
31
|
+
* flags.
|
32
|
+
*
|
33
|
+
* @category Transaction Flags
|
34
|
+
*/
|
35
|
+
export interface MPTokenAuthorizeFlagsInterface extends GlobalFlags {
|
36
|
+
tfMPTUnauthorize?: boolean
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* The MPTokenAuthorize transaction is used to globally lock/unlock a MPTokenIssuance,
|
41
|
+
* or lock/unlock an individual's MPToken.
|
42
|
+
*/
|
43
|
+
export interface MPTokenAuthorize extends BaseTransaction {
|
44
|
+
TransactionType: 'MPTokenAuthorize'
|
45
|
+
/**
|
46
|
+
* Identifies the MPTokenIssuance
|
47
|
+
*/
|
48
|
+
MPTokenIssuanceID: string
|
49
|
+
/**
|
50
|
+
* An optional XRPL Address of an individual token holder balance to lock/unlock.
|
51
|
+
* If omitted, this transaction will apply to all any accounts holding MPTs.
|
52
|
+
*/
|
53
|
+
Holder?: Account
|
54
|
+
Flags?: number | MPTokenAuthorizeFlagsInterface
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Verify the form and type of an MPTokenAuthorize at runtime.
|
59
|
+
*
|
60
|
+
* @param tx - An MPTokenAuthorize Transaction.
|
61
|
+
* @throws When the MPTokenAuthorize is Malformed.
|
62
|
+
*/
|
63
|
+
export function validateMPTokenAuthorize(tx: Record<string, unknown>): void {
|
64
|
+
validateBaseTransaction(tx)
|
65
|
+
validateRequiredField(tx, 'MPTokenIssuanceID', isString)
|
66
|
+
validateOptionalField(tx, 'Holder', isAccount)
|
67
|
+
}
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import { ValidationError } from '../../errors'
|
2
|
+
import { isHex, INTEGER_SANITY_CHECK, isFlagEnabled } from '../utils'
|
3
|
+
|
4
|
+
import {
|
5
|
+
BaseTransaction,
|
6
|
+
GlobalFlags,
|
7
|
+
validateBaseTransaction,
|
8
|
+
validateOptionalField,
|
9
|
+
isString,
|
10
|
+
isNumber,
|
11
|
+
} from './common'
|
12
|
+
import type { TransactionMetadataBase } from './metadata'
|
13
|
+
|
14
|
+
// 2^63 - 1
|
15
|
+
const MAX_AMT = '9223372036854775807'
|
16
|
+
const MAX_TRANSFER_FEE = 50000
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Transaction Flags for an MPTokenIssuanceCreate Transaction.
|
20
|
+
*
|
21
|
+
* @category Transaction Flags
|
22
|
+
*/
|
23
|
+
export enum MPTokenIssuanceCreateFlags {
|
24
|
+
/**
|
25
|
+
* If set, indicates that the MPT can be locked both individually and globally.
|
26
|
+
* If not set, the MPT cannot be locked in any way.
|
27
|
+
*/
|
28
|
+
tfMPTCanLock = 0x00000002,
|
29
|
+
/**
|
30
|
+
* If set, indicates that individual holders must be authorized.
|
31
|
+
* This enables issuers to limit who can hold their assets.
|
32
|
+
*/
|
33
|
+
tfMPTRequireAuth = 0x00000004,
|
34
|
+
/**
|
35
|
+
* If set, indicates that individual holders can place their balances into an escrow.
|
36
|
+
*/
|
37
|
+
tfMPTCanEscrow = 0x00000008,
|
38
|
+
/**
|
39
|
+
* If set, indicates that individual holders can trade their balances
|
40
|
+
* using the XRP Ledger DEX or AMM.
|
41
|
+
*/
|
42
|
+
tfMPTCanTrade = 0x00000010,
|
43
|
+
/**
|
44
|
+
* If set, indicates that tokens may be transferred to other accounts
|
45
|
+
* that are not the issuer.
|
46
|
+
*/
|
47
|
+
tfMPTCanTransfer = 0x00000020,
|
48
|
+
/**
|
49
|
+
* If set, indicates that the issuer may use the Clawback transaction
|
50
|
+
* to clawback value from individual holders.
|
51
|
+
*/
|
52
|
+
tfMPTCanClawback = 0x00000040,
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Map of flags to boolean values representing {@link MPTokenIssuanceCreate} transaction
|
57
|
+
* flags.
|
58
|
+
*
|
59
|
+
* @category Transaction Flags
|
60
|
+
*/
|
61
|
+
export interface MPTokenIssuanceCreateFlagsInterface extends GlobalFlags {
|
62
|
+
tfMPTCanLock?: boolean
|
63
|
+
tfMPTRequireAuth?: boolean
|
64
|
+
tfMPTCanEscrow?: boolean
|
65
|
+
tfMPTCanTrade?: boolean
|
66
|
+
tfMPTCanTransfer?: boolean
|
67
|
+
tfMPTCanClawback?: boolean
|
68
|
+
}
|
69
|
+
|
70
|
+
/**
|
71
|
+
* The MPTokenIssuanceCreate transaction creates a MPTokenIssuance object
|
72
|
+
* and adds it to the relevant directory node of the creator account.
|
73
|
+
* This transaction is the only opportunity an issuer has to specify any token fields
|
74
|
+
* that are defined as immutable (e.g., MPT Flags). If the transaction is successful,
|
75
|
+
* the newly created token will be owned by the account (the creator account) which
|
76
|
+
* executed the transaction.
|
77
|
+
*/
|
78
|
+
export interface MPTokenIssuanceCreate extends BaseTransaction {
|
79
|
+
TransactionType: 'MPTokenIssuanceCreate'
|
80
|
+
/**
|
81
|
+
* An asset scale is the difference, in orders of magnitude, between a standard unit and
|
82
|
+
* a corresponding fractional unit. More formally, the asset scale is a non-negative integer
|
83
|
+
* (0, 1, 2, …) such that one standard unit equals 10^(-scale) of a corresponding
|
84
|
+
* fractional unit. If the fractional unit equals the standard unit, then the asset scale is 0.
|
85
|
+
* Note that this value is optional, and will default to 0 if not supplied.
|
86
|
+
*/
|
87
|
+
AssetScale?: number
|
88
|
+
/**
|
89
|
+
* Specifies the maximum asset amount of this token that should ever be issued.
|
90
|
+
* It is a non-negative integer string that can store a range of up to 63 bits. If not set, the max
|
91
|
+
* amount will default to the largest unsigned 63-bit integer (0x7FFFFFFFFFFFFFFF or 9223372036854775807)
|
92
|
+
*
|
93
|
+
* Example:
|
94
|
+
* ```
|
95
|
+
* MaximumAmount: '9223372036854775807'
|
96
|
+
* ```
|
97
|
+
*/
|
98
|
+
MaximumAmount?: string
|
99
|
+
/**
|
100
|
+
* Specifies the fee to charged by the issuer for secondary sales of the Token,
|
101
|
+
* if such sales are allowed. Valid values for this field are between 0 and 50,000 inclusive,
|
102
|
+
* allowing transfer rates of between 0.000% and 50.000% in increments of 0.001.
|
103
|
+
* The field must NOT be present if the `tfMPTCanTransfer` flag is not set.
|
104
|
+
*/
|
105
|
+
TransferFee?: number
|
106
|
+
/**
|
107
|
+
* Arbitrary metadata about this issuance, in hex format.
|
108
|
+
*/
|
109
|
+
MPTokenMetadata?: string | null
|
110
|
+
Flags?: number | MPTokenIssuanceCreateFlagsInterface
|
111
|
+
}
|
112
|
+
|
113
|
+
export interface MPTokenIssuanceCreateMetadata extends TransactionMetadataBase {
|
114
|
+
mpt_issuance_id?: string
|
115
|
+
}
|
116
|
+
|
117
|
+
/* eslint-disable max-lines-per-function -- Not needed to reduce function */
|
118
|
+
/**
|
119
|
+
* Verify the form and type of an MPTokenIssuanceCreate at runtime.
|
120
|
+
*
|
121
|
+
* @param tx - An MPTokenIssuanceCreate Transaction.
|
122
|
+
* @throws When the MPTokenIssuanceCreate is Malformed.
|
123
|
+
*/
|
124
|
+
export function validateMPTokenIssuanceCreate(
|
125
|
+
tx: Record<string, unknown>,
|
126
|
+
): void {
|
127
|
+
validateBaseTransaction(tx)
|
128
|
+
validateOptionalField(tx, 'MaximumAmount', isString)
|
129
|
+
validateOptionalField(tx, 'MPTokenMetadata', isString)
|
130
|
+
validateOptionalField(tx, 'TransferFee', isNumber)
|
131
|
+
validateOptionalField(tx, 'AssetScale', isNumber)
|
132
|
+
|
133
|
+
if (typeof tx.MPTokenMetadata === 'string' && tx.MPTokenMetadata === '') {
|
134
|
+
throw new ValidationError(
|
135
|
+
'MPTokenIssuanceCreate: MPTokenMetadata must not be empty string',
|
136
|
+
)
|
137
|
+
}
|
138
|
+
|
139
|
+
if (typeof tx.MPTokenMetadata === 'string' && !isHex(tx.MPTokenMetadata)) {
|
140
|
+
throw new ValidationError(
|
141
|
+
'MPTokenIssuanceCreate: MPTokenMetadata must be in hex format',
|
142
|
+
)
|
143
|
+
}
|
144
|
+
|
145
|
+
if (typeof tx.MaximumAmount === 'string') {
|
146
|
+
if (!INTEGER_SANITY_CHECK.exec(tx.MaximumAmount)) {
|
147
|
+
throw new ValidationError('MPTokenIssuanceCreate: Invalid MaximumAmount')
|
148
|
+
} else if (
|
149
|
+
BigInt(tx.MaximumAmount) > BigInt(MAX_AMT) ||
|
150
|
+
BigInt(tx.MaximumAmount) < BigInt(`0`)
|
151
|
+
) {
|
152
|
+
throw new ValidationError(
|
153
|
+
'MPTokenIssuanceCreate: MaximumAmount out of range',
|
154
|
+
)
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
if (typeof tx.TransferFee === 'number') {
|
159
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary
|
160
|
+
const flags = tx.Flags as number | MPTokenIssuanceCreateFlagsInterface
|
161
|
+
const isTfMPTCanTransfer =
|
162
|
+
typeof flags === 'number'
|
163
|
+
? isFlagEnabled(flags, MPTokenIssuanceCreateFlags.tfMPTCanTransfer)
|
164
|
+
: flags.tfMPTCanTransfer ?? false
|
165
|
+
|
166
|
+
if (tx.TransferFee < 0 || tx.TransferFee > MAX_TRANSFER_FEE) {
|
167
|
+
throw new ValidationError(
|
168
|
+
`MPTokenIssuanceCreate: TransferFee must be between 0 and ${MAX_TRANSFER_FEE}`,
|
169
|
+
)
|
170
|
+
}
|
171
|
+
|
172
|
+
if (tx.TransferFee && !isTfMPTCanTransfer) {
|
173
|
+
throw new ValidationError(
|
174
|
+
'MPTokenIssuanceCreate: TransferFee cannot be provided without enabling tfMPTCanTransfer flag',
|
175
|
+
)
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
/* eslint-enable max-lines-per-function */
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import {
|
2
|
+
BaseTransaction,
|
3
|
+
isString,
|
4
|
+
validateBaseTransaction,
|
5
|
+
validateRequiredField,
|
6
|
+
} from './common'
|
7
|
+
|
8
|
+
/**
|
9
|
+
* The MPTokenIssuanceDestroy transaction is used to remove an MPTokenIssuance object
|
10
|
+
* from the directory node in which it is being held, effectively removing the token
|
11
|
+
* from the ledger. If this operation succeeds, the corresponding
|
12
|
+
* MPTokenIssuance is removed and the owner’s reserve requirement is reduced by one.
|
13
|
+
* This operation must fail if there are any holders who have non-zero balances.
|
14
|
+
*/
|
15
|
+
export interface MPTokenIssuanceDestroy extends BaseTransaction {
|
16
|
+
TransactionType: 'MPTokenIssuanceDestroy'
|
17
|
+
/**
|
18
|
+
* Identifies the MPTokenIssuance object to be removed by the transaction.
|
19
|
+
*/
|
20
|
+
MPTokenIssuanceID: string
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Verify the form and type of an MPTokenIssuanceDestroy at runtime.
|
25
|
+
*
|
26
|
+
* @param tx - An MPTokenIssuanceDestroy Transaction.
|
27
|
+
* @throws When the MPTokenIssuanceDestroy is Malformed.
|
28
|
+
*/
|
29
|
+
export function validateMPTokenIssuanceDestroy(
|
30
|
+
tx: Record<string, unknown>,
|
31
|
+
): void {
|
32
|
+
validateBaseTransaction(tx)
|
33
|
+
validateRequiredField(tx, 'MPTokenIssuanceID', isString)
|
34
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { ValidationError } from '../../errors'
|
2
|
+
import { isFlagEnabled } from '../utils'
|
3
|
+
|
4
|
+
import {
|
5
|
+
BaseTransaction,
|
6
|
+
isString,
|
7
|
+
validateBaseTransaction,
|
8
|
+
validateRequiredField,
|
9
|
+
Account,
|
10
|
+
validateOptionalField,
|
11
|
+
isAccount,
|
12
|
+
GlobalFlags,
|
13
|
+
} from './common'
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Transaction Flags for an MPTokenIssuanceSet Transaction.
|
17
|
+
*
|
18
|
+
* @category Transaction Flags
|
19
|
+
*/
|
20
|
+
export enum MPTokenIssuanceSetFlags {
|
21
|
+
/**
|
22
|
+
* If set, indicates that issuer locks the MPT
|
23
|
+
*/
|
24
|
+
tfMPTLock = 0x00000001,
|
25
|
+
/**
|
26
|
+
* If set, indicates that issuer unlocks the MPT
|
27
|
+
*/
|
28
|
+
tfMPTUnlock = 0x00000002,
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Map of flags to boolean values representing {@link MPTokenIssuanceSet} transaction
|
33
|
+
* flags.
|
34
|
+
*
|
35
|
+
* @category Transaction Flags
|
36
|
+
*/
|
37
|
+
export interface MPTokenIssuanceSetFlagsInterface extends GlobalFlags {
|
38
|
+
tfMPTLock?: boolean
|
39
|
+
tfMPTUnlock?: boolean
|
40
|
+
}
|
41
|
+
|
42
|
+
/**
|
43
|
+
* The MPTokenIssuanceSet transaction is used to globally lock/unlock a MPTokenIssuance,
|
44
|
+
* or lock/unlock an individual's MPToken.
|
45
|
+
*/
|
46
|
+
export interface MPTokenIssuanceSet extends BaseTransaction {
|
47
|
+
TransactionType: 'MPTokenIssuanceSet'
|
48
|
+
/**
|
49
|
+
* Identifies the MPTokenIssuance
|
50
|
+
*/
|
51
|
+
MPTokenIssuanceID: string
|
52
|
+
/**
|
53
|
+
* An optional XRPL Address of an individual token holder balance to lock/unlock.
|
54
|
+
* If omitted, this transaction will apply to all any accounts holding MPTs.
|
55
|
+
*/
|
56
|
+
Holder?: Account
|
57
|
+
Flags?: number | MPTokenIssuanceSetFlagsInterface
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Verify the form and type of an MPTokenIssuanceSet at runtime.
|
62
|
+
*
|
63
|
+
* @param tx - An MPTokenIssuanceSet Transaction.
|
64
|
+
* @throws When the MPTokenIssuanceSet is Malformed.
|
65
|
+
*/
|
66
|
+
export function validateMPTokenIssuanceSet(tx: Record<string, unknown>): void {
|
67
|
+
validateBaseTransaction(tx)
|
68
|
+
validateRequiredField(tx, 'MPTokenIssuanceID', isString)
|
69
|
+
validateOptionalField(tx, 'Holder', isAccount)
|
70
|
+
|
71
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Not necessary
|
72
|
+
const flags = tx.Flags as number | MPTokenIssuanceSetFlagsInterface
|
73
|
+
const isTfMPTLock =
|
74
|
+
typeof flags === 'number'
|
75
|
+
? isFlagEnabled(flags, MPTokenIssuanceSetFlags.tfMPTLock)
|
76
|
+
: flags.tfMPTLock ?? false
|
77
|
+
|
78
|
+
const isTfMPTUnlock =
|
79
|
+
typeof flags === 'number'
|
80
|
+
? isFlagEnabled(flags, MPTokenIssuanceSetFlags.tfMPTUnlock)
|
81
|
+
: flags.tfMPTUnlock ?? false
|
82
|
+
|
83
|
+
if (isTfMPTLock && isTfMPTUnlock) {
|
84
|
+
throw new ValidationError('MPTokenIssuanceSet: flag conflict')
|
85
|
+
}
|
86
|
+
}
|
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
isAccount,
|
5
5
|
isNumber,
|
6
6
|
validateBaseTransaction,
|
7
|
+
validateCredentialsList,
|
7
8
|
validateOptionalField,
|
8
9
|
validateRequiredField,
|
9
10
|
} from './common'
|
@@ -28,6 +29,12 @@ export interface AccountDelete extends BaseTransaction {
|
|
28
29
|
* information for the recipient of the deleted account's leftover XRP.
|
29
30
|
*/
|
30
31
|
DestinationTag?: number
|
32
|
+
/**
|
33
|
+
* Credentials associated with sender of this transaction. The credentials included
|
34
|
+
* must not be expired. The list must not be empty when specified and cannot contain
|
35
|
+
* more than 8 credentials.
|
36
|
+
*/
|
37
|
+
CredentialIDs?: string[]
|
31
38
|
}
|
32
39
|
|
33
40
|
/**
|
@@ -41,4 +48,11 @@ export function validateAccountDelete(tx: Record<string, unknown>): void {
|
|
41
48
|
|
42
49
|
validateRequiredField(tx, 'Destination', isAccount)
|
43
50
|
validateOptionalField(tx, 'DestinationTag', isNumber)
|
51
|
+
|
52
|
+
validateCredentialsList(
|
53
|
+
tx.CredentialIDs,
|
54
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
55
|
+
tx.TransactionType as string,
|
56
|
+
true,
|
57
|
+
)
|
44
58
|
}
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import { ValidationError } from '../../errors'
|
2
|
-
import { IssuedCurrencyAmount } from '../common'
|
2
|
+
import { IssuedCurrencyAmount, MPTAmount } from '../common'
|
3
3
|
|
4
4
|
import {
|
5
5
|
BaseTransaction,
|
6
6
|
validateBaseTransaction,
|
7
7
|
isIssuedCurrency,
|
8
|
+
isMPTAmount,
|
9
|
+
isAccount,
|
10
|
+
validateOptionalField,
|
8
11
|
} from './common'
|
9
12
|
|
10
13
|
/**
|
@@ -15,15 +18,20 @@ export interface Clawback extends BaseTransaction {
|
|
15
18
|
TransactionType: 'Clawback'
|
16
19
|
/**
|
17
20
|
* Indicates the AccountID that submitted this transaction. The account MUST
|
18
|
-
* be the issuer of the currency.
|
21
|
+
* be the issuer of the currency or MPT.
|
19
22
|
*/
|
20
23
|
Account: string
|
21
24
|
/**
|
22
|
-
* The amount of currency to
|
23
|
-
* names MUST be lower-case.
|
25
|
+
* The amount of currency or MPT to clawback, and it must be non-XRP. The nested field
|
26
|
+
* names MUST be lower-case. If the amount is IOU, the `issuer` field MUST be the holder's address,
|
24
27
|
* whom to be clawed back.
|
25
28
|
*/
|
26
|
-
Amount: IssuedCurrencyAmount
|
29
|
+
Amount: IssuedCurrencyAmount | MPTAmount
|
30
|
+
/**
|
31
|
+
* Indicates the AccountID that the issuer wants to clawback. This field is only valid for clawing back
|
32
|
+
* MPTs.
|
33
|
+
*/
|
34
|
+
Holder?: string
|
27
35
|
}
|
28
36
|
|
29
37
|
/**
|
@@ -34,16 +42,29 @@ export interface Clawback extends BaseTransaction {
|
|
34
42
|
*/
|
35
43
|
export function validateClawback(tx: Record<string, unknown>): void {
|
36
44
|
validateBaseTransaction(tx)
|
45
|
+
validateOptionalField(tx, 'Holder', isAccount)
|
37
46
|
|
38
47
|
if (tx.Amount == null) {
|
39
48
|
throw new ValidationError('Clawback: missing field Amount')
|
40
49
|
}
|
41
50
|
|
42
|
-
if (!isIssuedCurrency(tx.Amount)) {
|
51
|
+
if (!isIssuedCurrency(tx.Amount) && !isMPTAmount(tx.Amount)) {
|
43
52
|
throw new ValidationError('Clawback: invalid Amount')
|
44
53
|
}
|
45
54
|
|
46
55
|
if (isIssuedCurrency(tx.Amount) && tx.Account === tx.Amount.issuer) {
|
47
56
|
throw new ValidationError('Clawback: invalid holder Account')
|
48
57
|
}
|
58
|
+
|
59
|
+
if (isMPTAmount(tx.Amount) && tx.Account === tx.Holder) {
|
60
|
+
throw new ValidationError('Clawback: invalid holder Account')
|
61
|
+
}
|
62
|
+
|
63
|
+
if (isIssuedCurrency(tx.Amount) && tx.Holder) {
|
64
|
+
throw new ValidationError('Clawback: cannot have Holder for currency')
|
65
|
+
}
|
66
|
+
|
67
|
+
if (isMPTAmount(tx.Amount) && !tx.Holder) {
|
68
|
+
throw new ValidationError('Clawback: missing Holder')
|
69
|
+
}
|
49
70
|
}
|
@@ -1,18 +1,25 @@
|
|
1
|
+
/* eslint-disable max-lines -- common utility file */
|
2
|
+
import { HEX_REGEX } from '@xrplf/isomorphic/utils'
|
1
3
|
import { isValidClassicAddress, isValidXAddress } from 'ripple-address-codec'
|
2
4
|
import { TRANSACTION_TYPES } from 'ripple-binary-codec'
|
3
5
|
|
4
6
|
import { ValidationError } from '../../errors'
|
5
7
|
import {
|
6
8
|
Amount,
|
9
|
+
AuthorizeCredential,
|
7
10
|
Currency,
|
8
11
|
IssuedCurrencyAmount,
|
9
12
|
Memo,
|
10
13
|
Signer,
|
11
14
|
XChainBridge,
|
15
|
+
MPTAmount,
|
12
16
|
} from '../common'
|
13
17
|
import { onlyHasFields } from '../utils'
|
14
18
|
|
15
19
|
const MEMO_SIZE = 3
|
20
|
+
const MAX_CREDENTIALS_LIST_LENGTH = 8
|
21
|
+
const MAX_CREDENTIAL_BYTE_LENGTH = 64
|
22
|
+
const MAX_CREDENTIAL_TYPE_LENGTH = MAX_CREDENTIAL_BYTE_LENGTH * 2
|
16
23
|
|
17
24
|
function isMemo(obj: { Memo?: unknown }): boolean {
|
18
25
|
if (obj.Memo == null) {
|
@@ -59,6 +66,8 @@ const XRP_CURRENCY_SIZE = 1
|
|
59
66
|
const ISSUE_SIZE = 2
|
60
67
|
const ISSUED_CURRENCY_SIZE = 3
|
61
68
|
const XCHAIN_BRIDGE_SIZE = 4
|
69
|
+
const MPTOKEN_SIZE = 2
|
70
|
+
const AUTHORIZE_CREDENTIAL_SIZE = 1
|
62
71
|
|
63
72
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
64
73
|
return value !== null && typeof value === 'object'
|
@@ -119,6 +128,37 @@ export function isIssuedCurrency(
|
|
119
128
|
)
|
120
129
|
}
|
121
130
|
|
131
|
+
/**
|
132
|
+
* Verify the form and type of an AuthorizeCredential at runtime
|
133
|
+
*
|
134
|
+
* @param input - The input to check the form and type of
|
135
|
+
* @returns Whether the AuthorizeCredential is properly formed
|
136
|
+
*/
|
137
|
+
function isAuthorizeCredential(input: unknown): input is AuthorizeCredential {
|
138
|
+
return (
|
139
|
+
isRecord(input) &&
|
140
|
+
isRecord(input.Credential) &&
|
141
|
+
Object.keys(input).length === AUTHORIZE_CREDENTIAL_SIZE &&
|
142
|
+
typeof input.Credential.CredentialType === 'string' &&
|
143
|
+
typeof input.Credential.Issuer === 'string'
|
144
|
+
)
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Verify the form and type of an MPT at runtime.
|
149
|
+
*
|
150
|
+
* @param input - The input to check the form and type of.
|
151
|
+
* @returns Whether the MPTAmount is properly formed.
|
152
|
+
*/
|
153
|
+
export function isMPTAmount(input: unknown): input is MPTAmount {
|
154
|
+
return (
|
155
|
+
isRecord(input) &&
|
156
|
+
Object.keys(input).length === MPTOKEN_SIZE &&
|
157
|
+
typeof input.value === 'string' &&
|
158
|
+
typeof input.mpt_issuance_id === 'string'
|
159
|
+
)
|
160
|
+
}
|
161
|
+
|
122
162
|
/**
|
123
163
|
* Must be a valid account address
|
124
164
|
*/
|
@@ -144,7 +184,11 @@ export function isAccount(account: unknown): account is Account {
|
|
144
184
|
* @returns Whether the Amount is properly formed.
|
145
185
|
*/
|
146
186
|
export function isAmount(amount: unknown): amount is Amount {
|
147
|
-
return
|
187
|
+
return (
|
188
|
+
typeof amount === 'string' ||
|
189
|
+
isIssuedCurrency(amount) ||
|
190
|
+
isMPTAmount(amount)
|
191
|
+
)
|
148
192
|
}
|
149
193
|
|
150
194
|
/**
|
@@ -366,3 +410,97 @@ export function parseAmountValue(amount: unknown): number {
|
|
366
410
|
}
|
367
411
|
return parseFloat(amount.value)
|
368
412
|
}
|
413
|
+
|
414
|
+
/**
|
415
|
+
* Verify the form and type of a CredentialType at runtime.
|
416
|
+
*
|
417
|
+
* @param tx A CredentialType Transaction.
|
418
|
+
* @throws when the CredentialType is malformed.
|
419
|
+
*/
|
420
|
+
export function validateCredentialType(tx: Record<string, unknown>): void {
|
421
|
+
if (typeof tx.TransactionType !== 'string') {
|
422
|
+
throw new ValidationError('Invalid TransactionType')
|
423
|
+
}
|
424
|
+
if (tx.CredentialType === undefined) {
|
425
|
+
throw new ValidationError(
|
426
|
+
`${tx.TransactionType}: missing field CredentialType`,
|
427
|
+
)
|
428
|
+
}
|
429
|
+
|
430
|
+
if (!isString(tx.CredentialType)) {
|
431
|
+
throw new ValidationError(
|
432
|
+
`${tx.TransactionType}: CredentialType must be a string`,
|
433
|
+
)
|
434
|
+
}
|
435
|
+
if (tx.CredentialType.length === 0) {
|
436
|
+
throw new ValidationError(
|
437
|
+
`${tx.TransactionType}: CredentialType cannot be an empty string`,
|
438
|
+
)
|
439
|
+
} else if (tx.CredentialType.length > MAX_CREDENTIAL_TYPE_LENGTH) {
|
440
|
+
throw new ValidationError(
|
441
|
+
`${tx.TransactionType}: CredentialType length cannot be > ${MAX_CREDENTIAL_TYPE_LENGTH}`,
|
442
|
+
)
|
443
|
+
}
|
444
|
+
|
445
|
+
if (!HEX_REGEX.test(tx.CredentialType)) {
|
446
|
+
throw new ValidationError(
|
447
|
+
`${tx.TransactionType}: CredentialType must be encoded in hex`,
|
448
|
+
)
|
449
|
+
}
|
450
|
+
}
|
451
|
+
|
452
|
+
/**
|
453
|
+
* Check a CredentialAuthorize array for parameter errors
|
454
|
+
*
|
455
|
+
* @param credentials An array of credential IDs to check for errors
|
456
|
+
* @param transactionType The transaction type to include in error messages
|
457
|
+
* @param isStringID Toggle for if array contains IDs instead of AuthorizeCredential objects
|
458
|
+
* @throws Validation Error if the formatting is incorrect
|
459
|
+
*/
|
460
|
+
// eslint-disable-next-line max-lines-per-function -- separating logic further will add unnecessary complexity
|
461
|
+
export function validateCredentialsList(
|
462
|
+
credentials: unknown,
|
463
|
+
transactionType: string,
|
464
|
+
isStringID: boolean,
|
465
|
+
): void {
|
466
|
+
if (credentials == null) {
|
467
|
+
return
|
468
|
+
}
|
469
|
+
if (!Array.isArray(credentials)) {
|
470
|
+
throw new ValidationError(
|
471
|
+
`${transactionType}: Credentials must be an array`,
|
472
|
+
)
|
473
|
+
}
|
474
|
+
if (credentials.length > MAX_CREDENTIALS_LIST_LENGTH) {
|
475
|
+
throw new ValidationError(
|
476
|
+
`${transactionType}: Credentials length cannot exceed ${MAX_CREDENTIALS_LIST_LENGTH} elements`,
|
477
|
+
)
|
478
|
+
} else if (credentials.length === 0) {
|
479
|
+
throw new ValidationError(
|
480
|
+
`${transactionType}: Credentials cannot be an empty array`,
|
481
|
+
)
|
482
|
+
}
|
483
|
+
credentials.forEach((credential) => {
|
484
|
+
if (isStringID) {
|
485
|
+
if (!isString(credential)) {
|
486
|
+
throw new ValidationError(
|
487
|
+
`${transactionType}: Invalid Credentials ID list format`,
|
488
|
+
)
|
489
|
+
}
|
490
|
+
} else if (!isAuthorizeCredential(credential)) {
|
491
|
+
throw new ValidationError(
|
492
|
+
`${transactionType}: Invalid Credentials format`,
|
493
|
+
)
|
494
|
+
}
|
495
|
+
})
|
496
|
+
if (containsDuplicates(credentials)) {
|
497
|
+
throw new ValidationError(
|
498
|
+
`${transactionType}: Credentials cannot contain duplicate elements`,
|
499
|
+
)
|
500
|
+
}
|
501
|
+
}
|
502
|
+
|
503
|
+
function containsDuplicates(objectList: object[]): boolean {
|
504
|
+
const objSet = new Set(objectList.map((obj) => JSON.stringify(obj)))
|
505
|
+
return objSet.size !== objectList.length
|
506
|
+
}
|