xrpl 4.3.0-smartescrow.2 → 4.3.0-smartescrow.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/xrpl-latest.js +100 -6
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/models/ledger/Delegate.d.ts +11 -0
- package/dist/npm/models/ledger/Delegate.d.ts.map +1 -0
- package/dist/npm/models/ledger/Delegate.js +3 -0
- package/dist/npm/models/ledger/Delegate.js.map +1 -0
- 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/index.d.ts +2 -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/ledgerEntry.d.ts +4 -0
- package/dist/npm/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.d.ts +1 -0
- package/dist/npm/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/models/transactions/common.js +5 -0
- package/dist/npm/models/transactions/common.js.map +1 -1
- package/dist/npm/models/transactions/delegateSet.d.ts +13 -0
- package/dist/npm/models/transactions/delegateSet.d.ts.map +1 -0
- package/dist/npm/models/transactions/delegateSet.js +53 -0
- package/dist/npm/models/transactions/delegateSet.js.map +1 -0
- package/dist/npm/models/transactions/index.d.ts +1 -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/transaction.d.ts +2 -1
- package/dist/npm/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/models/transactions/transaction.js +4 -0
- package/dist/npm/models/transactions/transaction.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/models/ledger/Delegate.d.ts +11 -0
- package/dist/npm/src/models/ledger/Delegate.d.ts.map +1 -0
- package/dist/npm/src/models/ledger/Delegate.js +3 -0
- package/dist/npm/src/models/ledger/Delegate.js.map +1 -0
- 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/index.d.ts +2 -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/ledgerEntry.d.ts +4 -0
- package/dist/npm/src/models/methods/ledgerEntry.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.d.ts +1 -0
- package/dist/npm/src/models/transactions/common.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/common.js +5 -0
- package/dist/npm/src/models/transactions/common.js.map +1 -1
- package/dist/npm/src/models/transactions/delegateSet.d.ts +13 -0
- package/dist/npm/src/models/transactions/delegateSet.d.ts.map +1 -0
- package/dist/npm/src/models/transactions/delegateSet.js +53 -0
- package/dist/npm/src/models/transactions/delegateSet.js.map +1 -0
- package/dist/npm/src/models/transactions/index.d.ts +1 -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/transaction.d.ts +2 -1
- package/dist/npm/src/models/transactions/transaction.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/transaction.js +4 -0
- package/dist/npm/src/models/transactions/transaction.js.map +1 -1
- package/package.json +3 -3
- package/src/models/ledger/Delegate.ts +39 -0
- package/src/models/ledger/LedgerEntry.ts +3 -0
- package/src/models/ledger/index.ts +2 -0
- package/src/models/methods/ledgerEntry.ts +5 -0
- package/src/models/transactions/common.ts +14 -0
- package/src/models/transactions/delegateSet.ts +111 -0
- package/src/models/transactions/index.ts +1 -0
- package/src/models/transactions/transaction.ts +6 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
import { ValidationError } from '../../errors'
|
2
|
+
|
3
|
+
import {
|
4
|
+
BaseTransaction,
|
5
|
+
validateBaseTransaction,
|
6
|
+
validateRequiredField,
|
7
|
+
isAccount,
|
8
|
+
Account,
|
9
|
+
} from './common'
|
10
|
+
|
11
|
+
const PERMISSIONS_MAX_LENGTH = 10
|
12
|
+
const NON_DELEGATABLE_TRANSACTIONS = new Set([
|
13
|
+
'AccountSet',
|
14
|
+
'SetRegularKey',
|
15
|
+
'SignerListSet',
|
16
|
+
'DelegateSet',
|
17
|
+
'AccountDelete',
|
18
|
+
// Pseudo transactions below:
|
19
|
+
'EnableAmendment',
|
20
|
+
'SetFee',
|
21
|
+
'UNLModify',
|
22
|
+
])
|
23
|
+
|
24
|
+
export interface Permission {
|
25
|
+
Permission: {
|
26
|
+
PermissionValue: string
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
/**
|
31
|
+
* DelegateSet allows an account to delegate a set of permissions to another account.
|
32
|
+
*
|
33
|
+
* @category Transaction Models
|
34
|
+
*/
|
35
|
+
export interface DelegateSet extends BaseTransaction {
|
36
|
+
TransactionType: 'DelegateSet'
|
37
|
+
|
38
|
+
/**
|
39
|
+
* The authorized account.
|
40
|
+
*/
|
41
|
+
Authorize: Account
|
42
|
+
|
43
|
+
/**
|
44
|
+
* The transaction permissions (represented by integers) that the account has been granted.
|
45
|
+
*/
|
46
|
+
Permissions: Permission[]
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Verify the form and type of an DelegateSet at runtime.
|
51
|
+
*
|
52
|
+
* @param tx - An DelegateSet Transaction.
|
53
|
+
* @throws When the DelegateSet is malformed.
|
54
|
+
*/
|
55
|
+
// eslint-disable-next-line max-lines-per-function -- necessary for validation
|
56
|
+
export function validateDelegateSet(tx: Record<string, unknown>): void {
|
57
|
+
validateBaseTransaction(tx)
|
58
|
+
|
59
|
+
validateRequiredField(tx, 'Authorize', isAccount)
|
60
|
+
|
61
|
+
if (tx.Authorize === tx.Account) {
|
62
|
+
throw new ValidationError(
|
63
|
+
'DelegateSet: Authorize and Account must be different.',
|
64
|
+
)
|
65
|
+
}
|
66
|
+
|
67
|
+
validateRequiredField(tx, 'Permissions', Array.isArray)
|
68
|
+
|
69
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- required for validation
|
70
|
+
const permissions = tx.Permissions as DelegateSet['Permissions']
|
71
|
+
if (permissions.length > PERMISSIONS_MAX_LENGTH) {
|
72
|
+
throw new ValidationError(
|
73
|
+
`DelegateSet: Permissions array length cannot be greater than ${PERMISSIONS_MAX_LENGTH}.`,
|
74
|
+
)
|
75
|
+
}
|
76
|
+
|
77
|
+
const permissionValueSet = new Set()
|
78
|
+
permissions.forEach((permission: Permission) => {
|
79
|
+
if (
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- required for validation
|
81
|
+
permission == null ||
|
82
|
+
Object.keys(permission).length !== 1 ||
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- required for validation
|
84
|
+
permission.Permission == null ||
|
85
|
+
Object.keys(permission.Permission).length !== 1
|
86
|
+
) {
|
87
|
+
throw new ValidationError(
|
88
|
+
'DelegateSet: Permissions array element is malformed',
|
89
|
+
)
|
90
|
+
}
|
91
|
+
const permissionValue = permission.Permission.PermissionValue
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- required for validation
|
93
|
+
if (permissionValue == null) {
|
94
|
+
throw new ValidationError('DelegateSet: PermissionValue must be defined')
|
95
|
+
}
|
96
|
+
if (typeof permissionValue !== 'string') {
|
97
|
+
throw new ValidationError('DelegateSet: PermissionValue must be a string')
|
98
|
+
}
|
99
|
+
if (NON_DELEGATABLE_TRANSACTIONS.has(permissionValue)) {
|
100
|
+
throw new ValidationError(
|
101
|
+
`DelegateSet: PermissionValue contains a non-delegatable transaction ${permissionValue}`,
|
102
|
+
)
|
103
|
+
}
|
104
|
+
permissionValueSet.add(permissionValue)
|
105
|
+
})
|
106
|
+
if (permissions.length !== permissionValueSet.size) {
|
107
|
+
throw new ValidationError(
|
108
|
+
'DelegateSet: Permissions array cannot contain duplicate values',
|
109
|
+
)
|
110
|
+
}
|
111
|
+
}
|
@@ -42,6 +42,7 @@ export { CredentialCreate } from './CredentialCreate'
|
|
42
42
|
export { CredentialDelete } from './CredentialDelete'
|
43
43
|
export { DIDDelete } from './DIDDelete'
|
44
44
|
export { DIDSet } from './DIDSet'
|
45
|
+
export { DelegateSet, Permission } from './delegateSet'
|
45
46
|
export { DepositPreauth } from './depositPreauth'
|
46
47
|
export { EscrowCancel } from './escrowCancel'
|
47
48
|
export { EscrowCreate } from './escrowCreate'
|
@@ -23,6 +23,7 @@ import { BaseTransaction, isIssuedCurrency } from './common'
|
|
23
23
|
import { CredentialAccept, validateCredentialAccept } from './CredentialAccept'
|
24
24
|
import { CredentialCreate, validateCredentialCreate } from './CredentialCreate'
|
25
25
|
import { CredentialDelete, validateCredentialDelete } from './CredentialDelete'
|
26
|
+
import { DelegateSet, validateDelegateSet } from './delegateSet'
|
26
27
|
import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
|
27
28
|
import { DIDDelete, validateDIDDelete } from './DIDDelete'
|
28
29
|
import { DIDSet, validateDIDSet } from './DIDSet'
|
@@ -141,6 +142,7 @@ export type SubmittableTransaction =
|
|
141
142
|
| CredentialDelete
|
142
143
|
| DIDDelete
|
143
144
|
| DIDSet
|
145
|
+
| DelegateSet
|
144
146
|
| DepositPreauth
|
145
147
|
| EscrowCancel
|
146
148
|
| EscrowCreate
|
@@ -343,6 +345,10 @@ export function validate(transaction: Record<string, unknown>): void {
|
|
343
345
|
validateDIDSet(tx)
|
344
346
|
break
|
345
347
|
|
348
|
+
case 'DelegateSet':
|
349
|
+
validateDelegateSet(tx)
|
350
|
+
break
|
351
|
+
|
346
352
|
case 'DepositPreauth':
|
347
353
|
validateDepositPreauth(tx)
|
348
354
|
break
|