xrpl 4.0.1-mpt-beta → 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 +2510 -793
- 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 +4 -5
- package/dist/npm/client/partialPayment.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +6 -0
- package/dist/npm/models/common/index.d.ts.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 +1 -2
- package/dist/npm/models/ledger/MPToken.d.ts.map +1 -1
- package/dist/npm/models/ledger/MPTokenIssuance.d.ts +0 -1
- package/dist/npm/models/ledger/MPTokenIssuance.d.ts.map +1 -1
- package/dist/npm/models/ledger/index.d.ts +4 -3
- 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 +7 -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 +1 -1
- package/dist/npm/models/transactions/MPTokenAuthorize.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenAuthorize.js +1 -1
- package/dist/npm/models/transactions/MPTokenAuthorize.js.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.js +28 -0
- package/dist/npm/models/transactions/MPTokenIssuanceCreate.js.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -1
- package/dist/npm/models/transactions/MPTokenIssuanceSet.js +11 -4
- package/dist/npm/models/transactions/MPTokenIssuanceSet.js.map +1 -1
- 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 +1 -1
- package/dist/npm/models/transactions/clawback.d.ts.map +1 -1
- package/dist/npm/models/transactions/clawback.js +6 -6
- package/dist/npm/models/transactions/clawback.js.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +2 -0
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +68 -3
- 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 +3 -0
- 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 +1 -1
- package/dist/npm/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/models/transactions/payment.d.ts +3 -2
- 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 -5
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +16 -4
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/models/utils/flags.js +3 -3
- 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 +4 -5
- package/dist/npm/src/client/partialPayment.js.map +1 -1
- package/dist/npm/src/models/common/index.d.ts +6 -0
- package/dist/npm/src/models/common/index.d.ts.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 +1 -2
- package/dist/npm/src/models/ledger/MPToken.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/MPTokenIssuance.d.ts +0 -1
- package/dist/npm/src/models/ledger/MPTokenIssuance.d.ts.map +1 -1
- package/dist/npm/src/models/ledger/index.d.ts +4 -3
- 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 +7 -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 +1 -1
- package/dist/npm/src/models/transactions/MPTokenAuthorize.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenAuthorize.js +1 -1
- package/dist/npm/src/models/transactions/MPTokenAuthorize.js.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.js +28 -0
- package/dist/npm/src/models/transactions/MPTokenIssuanceCreate.js.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.js +11 -4
- package/dist/npm/src/models/transactions/MPTokenIssuanceSet.js.map +1 -1
- 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 +1 -1
- package/dist/npm/src/models/transactions/clawback.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/clawback.js +6 -6
- package/dist/npm/src/models/transactions/clawback.js.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +2 -0
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +68 -3
- 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 +3 -0
- 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 +1 -1
- package/dist/npm/src/models/transactions/metadata.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/payment.d.ts +3 -2
- 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 -5
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +16 -4
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/dist/npm/src/models/utils/flags.d.ts.map +1 -1
- package/dist/npm/src/models/utils/flags.js +3 -3
- 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/dist/npm/src/utils/index.d.ts +1 -2
- package/dist/npm/src/utils/index.d.ts.map +1 -1
- package/dist/npm/src/utils/index.js +1 -3
- package/dist/npm/src/utils/index.js.map +1 -1
- package/dist/npm/utils/index.d.ts +1 -2
- package/dist/npm/utils/index.d.ts.map +1 -1
- package/dist/npm/utils/index.js +1 -3
- package/dist/npm/utils/index.js.map +1 -1
- package/package.json +5 -5
- package/src/client/partialPayment.ts +18 -5
- package/src/models/common/index.ts +10 -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 +3 -0
- package/src/models/ledger/MPToken.ts +1 -2
- package/src/models/ledger/MPTokenIssuance.ts +0 -1
- package/src/models/ledger/index.ts +4 -2
- package/src/models/methods/depositAuthorized.ts +10 -0
- package/src/models/methods/index.ts +2 -0
- package/src/models/methods/ledgerEntry.ts +29 -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 +2 -2
- package/src/models/transactions/MPTokenIssuanceCreate.ts +58 -11
- package/src/models/transactions/MPTokenIssuanceSet.ts +18 -8
- package/src/models/transactions/accountDelete.ts +14 -0
- package/src/models/transactions/clawback.ts +7 -9
- package/src/models/transactions/common.ts +117 -0
- package/src/models/transactions/depositPreauth.ts +51 -15
- package/src/models/transactions/escrowFinish.ts +12 -0
- package/src/models/transactions/index.ts +3 -0
- package/src/models/transactions/metadata.ts +4 -4
- package/src/models/transactions/payment.ts +15 -2
- package/src/models/transactions/paymentChannelClaim.ts +18 -1
- package/src/models/transactions/transaction.ts +31 -13
- package/src/models/utils/flags.ts +3 -3
- package/src/models/utils/index.ts +1 -0
- package/src/utils/index.ts +0 -2
- 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
- package/dist/npm/src/utils/mptConversion.d.ts +0 -2
- package/dist/npm/src/utils/mptConversion.d.ts.map +0 -1
- package/dist/npm/src/utils/mptConversion.js +0 -31
- package/dist/npm/src/utils/mptConversion.js.map +0 -1
- package/dist/npm/utils/mptConversion.d.ts +0 -2
- package/dist/npm/utils/mptConversion.d.ts.map +0 -1
- package/dist/npm/utils/mptConversion.js +0 -31
- package/dist/npm/utils/mptConversion.js.map +0 -1
- package/src/utils/mptConversion.ts +0 -61
@@ -1,9 +1,12 @@
|
|
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,
|
@@ -14,6 +17,9 @@ import {
|
|
14
17
|
import { onlyHasFields } from '../utils'
|
15
18
|
|
16
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
|
17
23
|
|
18
24
|
function isMemo(obj: { Memo?: unknown }): boolean {
|
19
25
|
if (obj.Memo == null) {
|
@@ -61,6 +67,7 @@ const ISSUE_SIZE = 2
|
|
61
67
|
const ISSUED_CURRENCY_SIZE = 3
|
62
68
|
const XCHAIN_BRIDGE_SIZE = 4
|
63
69
|
const MPTOKEN_SIZE = 2
|
70
|
+
const AUTHORIZE_CREDENTIAL_SIZE = 1
|
64
71
|
|
65
72
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
66
73
|
return value !== null && typeof value === 'object'
|
@@ -121,6 +128,22 @@ export function isIssuedCurrency(
|
|
121
128
|
)
|
122
129
|
}
|
123
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
|
+
|
124
147
|
/**
|
125
148
|
* Verify the form and type of an MPT at runtime.
|
126
149
|
*
|
@@ -387,3 +410,97 @@ export function parseAmountValue(amount: unknown): number {
|
|
387
410
|
}
|
388
411
|
return parseFloat(amount.value)
|
389
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
|
+
}
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { ValidationError } from '../../errors'
|
2
|
+
import { AuthorizeCredential } from '../common'
|
2
3
|
|
3
|
-
import {
|
4
|
+
import {
|
5
|
+
BaseTransaction,
|
6
|
+
validateBaseTransaction,
|
7
|
+
validateCredentialsList,
|
8
|
+
} from './common'
|
4
9
|
|
5
10
|
/**
|
6
11
|
* A DepositPreauth transaction gives another account pre-approval to deliver
|
@@ -18,6 +23,16 @@ export interface DepositPreauth extends BaseTransaction {
|
|
18
23
|
* revoked.
|
19
24
|
*/
|
20
25
|
Unauthorize?: string
|
26
|
+
|
27
|
+
/**
|
28
|
+
* The credential(s) to preauthorize.
|
29
|
+
*/
|
30
|
+
AuthorizeCredentials?: AuthorizeCredential[]
|
31
|
+
|
32
|
+
/**
|
33
|
+
* The credential(s) whose preauthorization should be revoked.
|
34
|
+
*/
|
35
|
+
UnauthorizeCredentials?: AuthorizeCredential[]
|
21
36
|
}
|
22
37
|
|
23
38
|
/**
|
@@ -29,17 +44,7 @@ export interface DepositPreauth extends BaseTransaction {
|
|
29
44
|
export function validateDepositPreauth(tx: Record<string, unknown>): void {
|
30
45
|
validateBaseTransaction(tx)
|
31
46
|
|
32
|
-
|
33
|
-
throw new ValidationError(
|
34
|
-
"DepositPreauth: can't provide both Authorize and Unauthorize fields",
|
35
|
-
)
|
36
|
-
}
|
37
|
-
|
38
|
-
if (tx.Authorize === undefined && tx.Unauthorize === undefined) {
|
39
|
-
throw new ValidationError(
|
40
|
-
'DepositPreauth: must provide either Authorize or Unauthorize field',
|
41
|
-
)
|
42
|
-
}
|
47
|
+
validateSingleAuthorizationFieldProvided(tx)
|
43
48
|
|
44
49
|
if (tx.Authorize !== undefined) {
|
45
50
|
if (typeof tx.Authorize !== 'string') {
|
@@ -51,9 +56,7 @@ export function validateDepositPreauth(tx: Record<string, unknown>): void {
|
|
51
56
|
"DepositPreauth: Account can't preauthorize its own address",
|
52
57
|
)
|
53
58
|
}
|
54
|
-
}
|
55
|
-
|
56
|
-
if (tx.Unauthorize !== undefined) {
|
59
|
+
} else if (tx.Unauthorize !== undefined) {
|
57
60
|
if (typeof tx.Unauthorize !== 'string') {
|
58
61
|
throw new ValidationError('DepositPreauth: Unauthorize must be a string')
|
59
62
|
}
|
@@ -63,5 +66,38 @@ export function validateDepositPreauth(tx: Record<string, unknown>): void {
|
|
63
66
|
"DepositPreauth: Account can't unauthorize its own address",
|
64
67
|
)
|
65
68
|
}
|
69
|
+
} else if (tx.AuthorizeCredentials !== undefined) {
|
70
|
+
validateCredentialsList(
|
71
|
+
tx.AuthorizeCredentials,
|
72
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- confirmed in base transaction check
|
73
|
+
tx.TransactionType as string,
|
74
|
+
false,
|
75
|
+
)
|
76
|
+
} else if (tx.UnauthorizeCredentials !== undefined) {
|
77
|
+
validateCredentialsList(
|
78
|
+
tx.UnauthorizeCredentials,
|
79
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- confirmed in base transaction check
|
80
|
+
tx.TransactionType as string,
|
81
|
+
false,
|
82
|
+
)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
// Boolean logic to ensure exactly one of 4 inputs was provided
|
87
|
+
function validateSingleAuthorizationFieldProvided(
|
88
|
+
tx: Record<string, unknown>,
|
89
|
+
): void {
|
90
|
+
const fields = [
|
91
|
+
'Authorize',
|
92
|
+
'Unauthorize',
|
93
|
+
'AuthorizeCredentials',
|
94
|
+
'UnauthorizeCredentials',
|
95
|
+
]
|
96
|
+
const countProvided = fields.filter((key) => tx[key] !== undefined).length
|
97
|
+
|
98
|
+
if (countProvided !== 1) {
|
99
|
+
throw new ValidationError(
|
100
|
+
'DepositPreauth: Requires exactly one field of the following: Authorize, Unauthorize, AuthorizeCredentials, UnauthorizeCredentials.',
|
101
|
+
)
|
66
102
|
}
|
67
103
|
}
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
BaseTransaction,
|
6
6
|
isAccount,
|
7
7
|
validateBaseTransaction,
|
8
|
+
validateCredentialsList,
|
8
9
|
validateRequiredField,
|
9
10
|
} from './common'
|
10
11
|
|
@@ -32,6 +33,10 @@ export interface EscrowFinish extends BaseTransaction {
|
|
32
33
|
* the held payment's Condition.
|
33
34
|
*/
|
34
35
|
Fulfillment?: string
|
36
|
+
/** Credentials associated with the sender of this transaction.
|
37
|
+
* The credentials included must not be expired.
|
38
|
+
*/
|
39
|
+
CredentialIDs?: string[]
|
35
40
|
}
|
36
41
|
|
37
42
|
/**
|
@@ -45,6 +50,13 @@ export function validateEscrowFinish(tx: Record<string, unknown>): void {
|
|
45
50
|
|
46
51
|
validateRequiredField(tx, 'Owner', isAccount)
|
47
52
|
|
53
|
+
validateCredentialsList(
|
54
|
+
tx.CredentialIDs,
|
55
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
56
|
+
tx.TransactionType as string,
|
57
|
+
true,
|
58
|
+
)
|
59
|
+
|
48
60
|
if (tx.OfferSequence == null) {
|
49
61
|
throw new ValidationError('EscrowFinish: missing field OfferSequence')
|
50
62
|
}
|
@@ -32,6 +32,9 @@ export { CheckCancel } from './checkCancel'
|
|
32
32
|
export { CheckCash } from './checkCash'
|
33
33
|
export { CheckCreate } from './checkCreate'
|
34
34
|
export { Clawback } from './clawback'
|
35
|
+
export { CredentialAccept } from './CredentialAccept'
|
36
|
+
export { CredentialCreate } from './CredentialCreate'
|
37
|
+
export { CredentialDelete } from './CredentialDelete'
|
35
38
|
export { DIDDelete } from './DIDDelete'
|
36
39
|
export { DIDSet } from './DIDSet'
|
37
40
|
export { DepositPreauth } from './depositPreauth'
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import { Amount, MPTAmount } from '../common'
|
2
2
|
|
3
3
|
import { BaseTransaction } from './common'
|
4
|
+
import {
|
5
|
+
MPTokenIssuanceCreate,
|
6
|
+
MPTokenIssuanceCreateMetadata,
|
7
|
+
} from './MPTokenIssuanceCreate'
|
4
8
|
import {
|
5
9
|
NFTokenAcceptOffer,
|
6
10
|
NFTokenAcceptOfferMetadata,
|
@@ -14,10 +18,6 @@ import {
|
|
14
18
|
NFTokenCreateOfferMetadata,
|
15
19
|
} from './NFTokenCreateOffer'
|
16
20
|
import { NFTokenMint, NFTokenMintMetadata } from './NFTokenMint'
|
17
|
-
import {
|
18
|
-
MPTokenIssuanceCreate,
|
19
|
-
MPTokenIssuanceCreateMetadata,
|
20
|
-
} from './MPTokenIssuanceCreate'
|
21
21
|
import { Payment, PaymentMetadata } from './payment'
|
22
22
|
import type { Transaction } from './transaction'
|
23
23
|
|
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
validateOptionalField,
|
13
13
|
isNumber,
|
14
14
|
Account,
|
15
|
+
validateCredentialsList,
|
15
16
|
} from './common'
|
16
17
|
import type { TransactionMetadataBase } from './metadata'
|
17
18
|
|
@@ -142,13 +143,18 @@ export interface Payment extends BaseTransaction {
|
|
142
143
|
* cross-currency/cross-issue payments. Must be omitted for XRP-to-XRP
|
143
144
|
* Payments.
|
144
145
|
*/
|
145
|
-
SendMax?: Amount
|
146
|
+
SendMax?: Amount | MPTAmount
|
146
147
|
/**
|
147
148
|
* Minimum amount of destination currency this transaction should deliver.
|
148
149
|
* Only valid if this is a partial payment. For non-XRP amounts, the nested
|
149
150
|
* field names are lower-case.
|
150
151
|
*/
|
151
|
-
DeliverMin?: Amount
|
152
|
+
DeliverMin?: Amount | MPTAmount
|
153
|
+
/**
|
154
|
+
* Credentials associated with the sender of this transaction.
|
155
|
+
* The credentials included must not be expired.
|
156
|
+
*/
|
157
|
+
CredentialIDs?: string[]
|
152
158
|
Flags?: number | PaymentFlagsInterface
|
153
159
|
}
|
154
160
|
|
@@ -177,6 +183,13 @@ export function validatePayment(tx: Record<string, unknown>): void {
|
|
177
183
|
validateRequiredField(tx, 'Destination', isAccount)
|
178
184
|
validateOptionalField(tx, 'DestinationTag', isNumber)
|
179
185
|
|
186
|
+
validateCredentialsList(
|
187
|
+
tx.CredentialIDs,
|
188
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
189
|
+
tx.TransactionType as string,
|
190
|
+
true,
|
191
|
+
)
|
192
|
+
|
180
193
|
if (tx.InvoiceID !== undefined && typeof tx.InvoiceID !== 'string') {
|
181
194
|
throw new ValidationError('PaymentTransaction: InvoiceID must be a string')
|
182
195
|
}
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { ValidationError } from '../../errors'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
BaseTransaction,
|
5
|
+
GlobalFlags,
|
6
|
+
validateBaseTransaction,
|
7
|
+
validateCredentialsList,
|
8
|
+
} from './common'
|
4
9
|
|
5
10
|
/**
|
6
11
|
* Enum representing values for PaymentChannelClaim transaction flags.
|
@@ -127,6 +132,11 @@ export interface PaymentChannelClaim extends BaseTransaction {
|
|
127
132
|
* field is omitted.
|
128
133
|
*/
|
129
134
|
PublicKey?: string
|
135
|
+
/**
|
136
|
+
* Credentials associated with the sender of this transaction.
|
137
|
+
* The credentials included must not be expired.
|
138
|
+
*/
|
139
|
+
CredentialIDs?: string[]
|
130
140
|
}
|
131
141
|
|
132
142
|
/**
|
@@ -138,6 +148,13 @@ export interface PaymentChannelClaim extends BaseTransaction {
|
|
138
148
|
export function validatePaymentChannelClaim(tx: Record<string, unknown>): void {
|
139
149
|
validateBaseTransaction(tx)
|
140
150
|
|
151
|
+
validateCredentialsList(
|
152
|
+
tx.CredentialIDs,
|
153
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- known from base check
|
154
|
+
tx.TransactionType as string,
|
155
|
+
true,
|
156
|
+
)
|
157
|
+
|
141
158
|
if (tx.Channel === undefined) {
|
142
159
|
throw new ValidationError('PaymentChannelClaim: missing Channel')
|
143
160
|
}
|
@@ -19,6 +19,9 @@ import { CheckCash, validateCheckCash } from './checkCash'
|
|
19
19
|
import { CheckCreate, validateCheckCreate } from './checkCreate'
|
20
20
|
import { Clawback, validateClawback } from './clawback'
|
21
21
|
import { BaseTransaction, isIssuedCurrency } from './common'
|
22
|
+
import { CredentialAccept, validateCredentialAccept } from './CredentialAccept'
|
23
|
+
import { CredentialCreate, validateCredentialCreate } from './CredentialCreate'
|
24
|
+
import { CredentialDelete, validateCredentialDelete } from './CredentialDelete'
|
22
25
|
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
|
23
26
|
import { DIDDelete, validateDIDDelete } from './DIDDelete'
|
24
27
|
import { DIDSet, validateDIDSet } from './DIDSet'
|
@@ -27,6 +30,19 @@ import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
|
|
27
30
|
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
|
28
31
|
import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
|
29
32
|
import { TransactionMetadata } from './metadata'
|
33
|
+
import { MPTokenAuthorize, validateMPTokenAuthorize } from './MPTokenAuthorize'
|
34
|
+
import {
|
35
|
+
MPTokenIssuanceCreate,
|
36
|
+
validateMPTokenIssuanceCreate,
|
37
|
+
} from './MPTokenIssuanceCreate'
|
38
|
+
import {
|
39
|
+
MPTokenIssuanceDestroy,
|
40
|
+
validateMPTokenIssuanceDestroy,
|
41
|
+
} from './MPTokenIssuanceDestroy'
|
42
|
+
import {
|
43
|
+
MPTokenIssuanceSet,
|
44
|
+
validateMPTokenIssuanceSet,
|
45
|
+
} from './MPTokenIssuanceSet'
|
30
46
|
import {
|
31
47
|
NFTokenAcceptOffer,
|
32
48
|
validateNFTokenAcceptOffer,
|
@@ -90,19 +106,6 @@ import {
|
|
90
106
|
XChainModifyBridge,
|
91
107
|
validateXChainModifyBridge,
|
92
108
|
} from './XChainModifyBridge'
|
93
|
-
import { MPTokenAuthorize, validateMPTokenAuthorize } from './MPTokenAuthorize'
|
94
|
-
import {
|
95
|
-
MPTokenIssuanceCreate,
|
96
|
-
validateMPTokenIssuanceCreate,
|
97
|
-
} from './MPTokenIssuanceCreate'
|
98
|
-
import {
|
99
|
-
MPTokenIssuanceDestroy,
|
100
|
-
validateMPTokenIssuanceDestroy,
|
101
|
-
} from './MPTokenIssuanceDestroy'
|
102
|
-
import {
|
103
|
-
MPTokenIssuanceSet,
|
104
|
-
validateMPTokenIssuanceSet,
|
105
|
-
} from './MPTokenIssuanceSet'
|
106
109
|
|
107
110
|
/**
|
108
111
|
* Transactions that can be submitted by clients
|
@@ -122,6 +125,9 @@ export type SubmittableTransaction =
|
|
122
125
|
| CheckCash
|
123
126
|
| CheckCreate
|
124
127
|
| Clawback
|
128
|
+
| CredentialAccept
|
129
|
+
| CredentialCreate
|
130
|
+
| CredentialDelete
|
125
131
|
| DIDDelete
|
126
132
|
| DIDSet
|
127
133
|
| DepositPreauth
|
@@ -299,6 +305,18 @@ export function validate(transaction: Record<string, unknown>): void {
|
|
299
305
|
validateClawback(tx)
|
300
306
|
break
|
301
307
|
|
308
|
+
case 'CredentialAccept':
|
309
|
+
validateCredentialAccept(tx)
|
310
|
+
break
|
311
|
+
|
312
|
+
case 'CredentialCreate':
|
313
|
+
validateCredentialCreate(tx)
|
314
|
+
break
|
315
|
+
|
316
|
+
case 'CredentialDelete':
|
317
|
+
validateCredentialDelete(tx)
|
318
|
+
break
|
319
|
+
|
302
320
|
case 'DIDDelete':
|
303
321
|
validateDIDDelete(tx)
|
304
322
|
break
|
@@ -9,6 +9,9 @@ import { AccountSetTfFlags } from '../transactions/accountSet'
|
|
9
9
|
import { AMMDepositFlags } from '../transactions/AMMDeposit'
|
10
10
|
import { AMMWithdrawFlags } from '../transactions/AMMWithdraw'
|
11
11
|
import { GlobalFlags } from '../transactions/common'
|
12
|
+
import { MPTokenAuthorizeFlags } from '../transactions/MPTokenAuthorize'
|
13
|
+
import { MPTokenIssuanceCreateFlags } from '../transactions/MPTokenIssuanceCreate'
|
14
|
+
import { MPTokenIssuanceSetFlags } from '../transactions/MPTokenIssuanceSet'
|
12
15
|
import { NFTokenCreateOfferFlags } from '../transactions/NFTokenCreateOffer'
|
13
16
|
import { NFTokenMintFlags } from '../transactions/NFTokenMint'
|
14
17
|
import { OfferCreateFlags } from '../transactions/offerCreate'
|
@@ -17,9 +20,6 @@ import { PaymentChannelClaimFlags } from '../transactions/paymentChannelClaim'
|
|
17
20
|
import type { Transaction } from '../transactions/transaction'
|
18
21
|
import { TrustSetFlags } from '../transactions/trustSet'
|
19
22
|
import { XChainModifyBridgeFlags } from '../transactions/XChainModifyBridge'
|
20
|
-
import { MPTokenAuthorizeFlags } from '../transactions/MPTokenAuthorize'
|
21
|
-
import { MPTokenIssuanceCreateFlags } from '../transactions/MPTokenIssuanceCreate'
|
22
|
-
import { MPTokenIssuanceSetFlags } from '../transactions/MPTokenIssuanceSet'
|
23
23
|
|
24
24
|
import { isFlagEnabled } from '.'
|
25
25
|
|
package/src/utils/index.ts
CHANGED
@@ -66,7 +66,6 @@ import {
|
|
66
66
|
} from './timeConversion'
|
67
67
|
import verifyPaymentChannelClaim from './verifyPaymentChannelClaim'
|
68
68
|
import { xrpToDrops, dropsToXrp } from './xrpConversion'
|
69
|
-
import { mptUint64ToHex } from './mptConversion'
|
70
69
|
|
71
70
|
/**
|
72
71
|
* Check if a secret is valid.
|
@@ -230,5 +229,4 @@ export {
|
|
230
229
|
getNFTokenID,
|
231
230
|
parseNFTokenID,
|
232
231
|
getXChainClaimID,
|
233
|
-
mptUint64ToHex,
|
234
232
|
}
|