@metamask/delegation-core 1.0.0 → 2.0.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/CHANGELOG.md +19 -1
- package/README.md +8 -8
- package/dist/index.cjs +621 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +143 -66
- package/dist/index.d.ts +143 -66
- package/dist/index.mjs +626 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/caveats/types.ts
|
|
2
|
+
var BalanceChangeType = /* @__PURE__ */ ((BalanceChangeType2) => {
|
|
3
|
+
BalanceChangeType2[BalanceChangeType2["Increase"] = 0] = "Increase";
|
|
4
|
+
BalanceChangeType2[BalanceChangeType2["Decrease"] = 1] = "Decrease";
|
|
5
|
+
return BalanceChangeType2;
|
|
6
|
+
})(BalanceChangeType || {});
|
|
7
|
+
|
|
8
|
+
// src/internalUtils.ts
|
|
2
9
|
|
|
3
10
|
|
|
4
11
|
|
|
@@ -47,6 +54,52 @@ var normalizeAddressLowercase = (value, errorMessage) => {
|
|
|
47
54
|
var concatHex = (parts) => {
|
|
48
55
|
return `0x${parts.map(_utils.remove0x).join("")}`;
|
|
49
56
|
};
|
|
57
|
+
var extractBigInt = (value, offset, size) => {
|
|
58
|
+
const start = 2 + offset * 2;
|
|
59
|
+
const end = start + size * 2;
|
|
60
|
+
const slice = value.slice(start, end);
|
|
61
|
+
return BigInt(`0x${slice}`);
|
|
62
|
+
};
|
|
63
|
+
var extractNumber = (value, offset, size) => {
|
|
64
|
+
const bigIntValue = extractBigInt(value, offset, size);
|
|
65
|
+
if (bigIntValue > Number.MAX_SAFE_INTEGER) {
|
|
66
|
+
throw new Error("Number is too large");
|
|
67
|
+
}
|
|
68
|
+
return Number(bigIntValue);
|
|
69
|
+
};
|
|
70
|
+
var extractAddress = (value, offset) => {
|
|
71
|
+
const start = 2 + offset * 2;
|
|
72
|
+
const end = start + 40;
|
|
73
|
+
return `0x${value.slice(start, end)}`;
|
|
74
|
+
};
|
|
75
|
+
var extractHex = (value, offset, size) => {
|
|
76
|
+
const start = 2 + offset * 2;
|
|
77
|
+
const end = start + size * 2;
|
|
78
|
+
return `0x${value.slice(start, end)}`;
|
|
79
|
+
};
|
|
80
|
+
var extractRemainingHex = (value, offset) => {
|
|
81
|
+
const start = 2 + offset * 2;
|
|
82
|
+
return `0x${value.slice(start)}`;
|
|
83
|
+
};
|
|
84
|
+
function getByteLength(value) {
|
|
85
|
+
return (value.length - 2) / 2;
|
|
86
|
+
}
|
|
87
|
+
function assertHexByteExactLength(hexTerms, expectedBytes, errorMessage) {
|
|
88
|
+
if (getByteLength(hexTerms) !== expectedBytes) {
|
|
89
|
+
throw new Error(errorMessage);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function assertHexByteLengthAtLeastOneMultipleOf(hexTerms, unitBytes, errorMessage) {
|
|
93
|
+
const byteLength = getByteLength(hexTerms);
|
|
94
|
+
if (byteLength === 0 || byteLength % unitBytes !== 0) {
|
|
95
|
+
throw new Error(errorMessage);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function assertHexBytesMinLength(hexTerms, minBytes, errorMessage) {
|
|
99
|
+
if (getByteLength(hexTerms) < minBytes) {
|
|
100
|
+
throw new Error(errorMessage);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
50
103
|
|
|
51
104
|
// src/returns.ts
|
|
52
105
|
|
|
@@ -81,47 +134,64 @@ function createValueLteTerms(terms, options = defaultOptions) {
|
|
|
81
134
|
const hexValue = toHexString({ value: maxValue, size: 32 });
|
|
82
135
|
return prepareResult(hexValue, options);
|
|
83
136
|
}
|
|
137
|
+
function decodeValueLteTerms(terms) {
|
|
138
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
139
|
+
assertHexByteExactLength(
|
|
140
|
+
hexTerms,
|
|
141
|
+
32,
|
|
142
|
+
"Invalid ValueLte terms: must be exactly 32 bytes"
|
|
143
|
+
);
|
|
144
|
+
const maxValue = extractBigInt(hexTerms, 0, 32);
|
|
145
|
+
return { maxValue };
|
|
146
|
+
}
|
|
84
147
|
|
|
85
148
|
// src/caveats/timestamp.ts
|
|
86
149
|
var TIMESTAMP_UPPER_BOUND_SECONDS = 253402300799;
|
|
87
150
|
function createTimestampTerms(terms, encodingOptions = defaultOptions) {
|
|
88
|
-
const {
|
|
89
|
-
if (
|
|
90
|
-
throw new Error(
|
|
91
|
-
"Invalid timestampAfterThreshold: must be zero or positive"
|
|
92
|
-
);
|
|
151
|
+
const { afterThreshold, beforeThreshold } = terms;
|
|
152
|
+
if (afterThreshold < 0) {
|
|
153
|
+
throw new Error("Invalid afterThreshold: must be zero or positive");
|
|
93
154
|
}
|
|
94
|
-
if (
|
|
95
|
-
throw new Error(
|
|
96
|
-
"Invalid timestampBeforeThreshold: must be zero or positive"
|
|
97
|
-
);
|
|
155
|
+
if (beforeThreshold < 0) {
|
|
156
|
+
throw new Error("Invalid beforeThreshold: must be zero or positive");
|
|
98
157
|
}
|
|
99
|
-
if (
|
|
158
|
+
if (beforeThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {
|
|
100
159
|
throw new Error(
|
|
101
|
-
`Invalid
|
|
160
|
+
`Invalid beforeThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`
|
|
102
161
|
);
|
|
103
162
|
}
|
|
104
|
-
if (
|
|
163
|
+
if (afterThreshold > TIMESTAMP_UPPER_BOUND_SECONDS) {
|
|
105
164
|
throw new Error(
|
|
106
|
-
`Invalid
|
|
165
|
+
`Invalid afterThreshold: must be less than or equal to ${TIMESTAMP_UPPER_BOUND_SECONDS}`
|
|
107
166
|
);
|
|
108
167
|
}
|
|
109
|
-
if (
|
|
168
|
+
if (beforeThreshold !== 0 && afterThreshold >= beforeThreshold) {
|
|
110
169
|
throw new Error(
|
|
111
|
-
"Invalid thresholds:
|
|
170
|
+
"Invalid thresholds: beforeThreshold must be greater than afterThreshold when both are specified"
|
|
112
171
|
);
|
|
113
172
|
}
|
|
114
173
|
const afterThresholdHex = toHexString({
|
|
115
|
-
value:
|
|
174
|
+
value: afterThreshold,
|
|
116
175
|
size: 16
|
|
117
176
|
});
|
|
118
177
|
const beforeThresholdHex = toHexString({
|
|
119
|
-
value:
|
|
178
|
+
value: beforeThreshold,
|
|
120
179
|
size: 16
|
|
121
180
|
});
|
|
122
181
|
const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;
|
|
123
182
|
return prepareResult(hexValue, encodingOptions);
|
|
124
183
|
}
|
|
184
|
+
function decodeTimestampTerms(terms) {
|
|
185
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
186
|
+
assertHexByteExactLength(
|
|
187
|
+
hexTerms,
|
|
188
|
+
32,
|
|
189
|
+
"Invalid Timestamp terms: must be exactly 32 bytes"
|
|
190
|
+
);
|
|
191
|
+
const afterThreshold = extractNumber(hexTerms, 0, 16);
|
|
192
|
+
const beforeThreshold = extractNumber(hexTerms, 16, 16);
|
|
193
|
+
return { afterThreshold, beforeThreshold };
|
|
194
|
+
}
|
|
125
195
|
|
|
126
196
|
// src/caveats/nativeTokenPeriodTransfer.ts
|
|
127
197
|
function createNativeTokenPeriodTransferTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -141,6 +211,18 @@ function createNativeTokenPeriodTransferTerms(terms, encodingOptions = defaultOp
|
|
|
141
211
|
const hexValue = `0x${periodAmountHex}${periodDurationHex}${startDateHex}`;
|
|
142
212
|
return prepareResult(hexValue, encodingOptions);
|
|
143
213
|
}
|
|
214
|
+
function decodeNativeTokenPeriodTransferTerms(terms) {
|
|
215
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
216
|
+
assertHexByteExactLength(
|
|
217
|
+
hexTerms,
|
|
218
|
+
96,
|
|
219
|
+
"Invalid NativeTokenPeriodTransfer terms: must be exactly 96 bytes"
|
|
220
|
+
);
|
|
221
|
+
const periodAmount = extractBigInt(hexTerms, 0, 32);
|
|
222
|
+
const periodDuration = extractNumber(hexTerms, 32, 32);
|
|
223
|
+
const startDate = extractNumber(hexTerms, 64, 32);
|
|
224
|
+
return { periodAmount, periodDuration, startDate };
|
|
225
|
+
}
|
|
144
226
|
|
|
145
227
|
// src/caveats/exactCalldata.ts
|
|
146
228
|
function createExactCalldataTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -153,6 +235,11 @@ function createExactCalldataTerms(terms, encodingOptions = defaultOptions) {
|
|
|
153
235
|
}
|
|
154
236
|
return prepareResult(calldata, encodingOptions);
|
|
155
237
|
}
|
|
238
|
+
function decodeExactCalldataTerms(terms, encodingOptions = defaultOptions) {
|
|
239
|
+
const calldataHex = bytesLikeToHex(terms);
|
|
240
|
+
const calldata = prepareResult(calldataHex, encodingOptions);
|
|
241
|
+
return { calldata };
|
|
242
|
+
}
|
|
156
243
|
|
|
157
244
|
// src/caveats/exactCalldataBatch.ts
|
|
158
245
|
var _abiutils = require('@metamask/abi-utils');
|
|
@@ -187,6 +274,18 @@ function createExactCalldataBatchTerms(terms, encodingOptions = defaultOptions)
|
|
|
187
274
|
const hexValue = _abiutils.encodeSingle.call(void 0, EXECUTION_ARRAY_ABI, encodableExecutions);
|
|
188
275
|
return prepareResult(hexValue, encodingOptions);
|
|
189
276
|
}
|
|
277
|
+
function decodeExactCalldataBatchTerms(terms, encodingOptions = defaultOptions) {
|
|
278
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
279
|
+
const decoded = _abiutils.decodeSingle.call(void 0, EXECUTION_ARRAY_ABI, hexTerms);
|
|
280
|
+
const executions = decoded.map(
|
|
281
|
+
([target, value, callData]) => ({
|
|
282
|
+
target: prepareResult(target, encodingOptions),
|
|
283
|
+
value,
|
|
284
|
+
callData: prepareResult(_utils.bytesToHex.call(void 0, callData), encodingOptions)
|
|
285
|
+
})
|
|
286
|
+
);
|
|
287
|
+
return { executions };
|
|
288
|
+
}
|
|
190
289
|
|
|
191
290
|
// src/caveats/exactExecution.ts
|
|
192
291
|
|
|
@@ -214,6 +313,24 @@ function createExactExecutionTerms(terms, encodingOptions = defaultOptions) {
|
|
|
214
313
|
const hexValue = concatHex([targetHex, valueHex, callDataHex]);
|
|
215
314
|
return prepareResult(hexValue, encodingOptions);
|
|
216
315
|
}
|
|
316
|
+
function decodeExactExecutionTerms(terms, encodingOptions = defaultOptions) {
|
|
317
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
318
|
+
assertHexBytesMinLength(
|
|
319
|
+
hexTerms,
|
|
320
|
+
52,
|
|
321
|
+
"Invalid ExactExecution terms: must be at least 52 bytes"
|
|
322
|
+
);
|
|
323
|
+
const targetHex = extractAddress(hexTerms, 0);
|
|
324
|
+
const value = extractBigInt(hexTerms, 20, 32);
|
|
325
|
+
const callDataHex = extractRemainingHex(hexTerms, 52);
|
|
326
|
+
return {
|
|
327
|
+
execution: {
|
|
328
|
+
target: prepareResult(targetHex, encodingOptions),
|
|
329
|
+
value,
|
|
330
|
+
callData: prepareResult(callDataHex, encodingOptions)
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
217
334
|
|
|
218
335
|
// src/caveats/exactExecutionBatch.ts
|
|
219
336
|
|
|
@@ -248,6 +365,18 @@ function createExactExecutionBatchTerms(terms, encodingOptions = defaultOptions)
|
|
|
248
365
|
const hexValue = _abiutils.encodeSingle.call(void 0, EXECUTION_ARRAY_ABI2, encodableExecutions);
|
|
249
366
|
return prepareResult(hexValue, encodingOptions);
|
|
250
367
|
}
|
|
368
|
+
function decodeExactExecutionBatchTerms(terms, encodingOptions = defaultOptions) {
|
|
369
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
370
|
+
const decoded = _abiutils.decodeSingle.call(void 0, EXECUTION_ARRAY_ABI2, hexTerms);
|
|
371
|
+
const executions = decoded.map(
|
|
372
|
+
([target, value, callData]) => ({
|
|
373
|
+
target: prepareResult(target, encodingOptions),
|
|
374
|
+
value,
|
|
375
|
+
callData: prepareResult(_utils.bytesToHex.call(void 0, callData), encodingOptions)
|
|
376
|
+
})
|
|
377
|
+
);
|
|
378
|
+
return { executions };
|
|
379
|
+
}
|
|
251
380
|
|
|
252
381
|
// src/caveats/nativeTokenStreaming.ts
|
|
253
382
|
var TIMESTAMP_UPPER_BOUND_SECONDS2 = 253402300799;
|
|
@@ -280,6 +409,19 @@ function createNativeTokenStreamingTerms(terms, encodingOptions = defaultOptions
|
|
|
280
409
|
const hexValue = `0x${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;
|
|
281
410
|
return prepareResult(hexValue, encodingOptions);
|
|
282
411
|
}
|
|
412
|
+
function decodeNativeTokenStreamingTerms(terms) {
|
|
413
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
414
|
+
assertHexByteExactLength(
|
|
415
|
+
hexTerms,
|
|
416
|
+
128,
|
|
417
|
+
"Invalid NativeTokenStreaming terms: must be exactly 128 bytes"
|
|
418
|
+
);
|
|
419
|
+
const initialAmount = extractBigInt(hexTerms, 0, 32);
|
|
420
|
+
const maxAmount = extractBigInt(hexTerms, 32, 32);
|
|
421
|
+
const amountPerSecond = extractBigInt(hexTerms, 64, 32);
|
|
422
|
+
const startTime = extractNumber(hexTerms, 96, 32);
|
|
423
|
+
return { initialAmount, maxAmount, amountPerSecond, startTime };
|
|
424
|
+
}
|
|
283
425
|
|
|
284
426
|
// src/caveats/nativeTokenTransferAmount.ts
|
|
285
427
|
function createNativeTokenTransferAmountTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -290,6 +432,16 @@ function createNativeTokenTransferAmountTerms(terms, encodingOptions = defaultOp
|
|
|
290
432
|
const hexValue = `0x${toHexString({ value: maxAmount, size: 32 })}`;
|
|
291
433
|
return prepareResult(hexValue, encodingOptions);
|
|
292
434
|
}
|
|
435
|
+
function decodeNativeTokenTransferAmountTerms(terms) {
|
|
436
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
437
|
+
assertHexByteExactLength(
|
|
438
|
+
hexTerms,
|
|
439
|
+
32,
|
|
440
|
+
"Invalid NativeTokenTransferAmount terms: must be exactly 32 bytes"
|
|
441
|
+
);
|
|
442
|
+
const maxAmount = extractBigInt(hexTerms, 0, 32);
|
|
443
|
+
return { maxAmount };
|
|
444
|
+
}
|
|
293
445
|
|
|
294
446
|
// src/caveats/nativeTokenPayment.ts
|
|
295
447
|
function createNativeTokenPaymentTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -305,10 +457,24 @@ function createNativeTokenPaymentTerms(terms, encodingOptions = defaultOptions)
|
|
|
305
457
|
const hexValue = concatHex([recipientHex, amountHex]);
|
|
306
458
|
return prepareResult(hexValue, encodingOptions);
|
|
307
459
|
}
|
|
460
|
+
function decodeNativeTokenPaymentTerms(terms, encodingOptions = defaultOptions) {
|
|
461
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
462
|
+
assertHexByteExactLength(
|
|
463
|
+
hexTerms,
|
|
464
|
+
52,
|
|
465
|
+
"Invalid NativeTokenPayment terms: must be exactly 52 bytes"
|
|
466
|
+
);
|
|
467
|
+
const recipientHex = extractAddress(hexTerms, 0);
|
|
468
|
+
const amount = extractBigInt(hexTerms, 20, 32);
|
|
469
|
+
return {
|
|
470
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
471
|
+
amount
|
|
472
|
+
};
|
|
473
|
+
}
|
|
308
474
|
|
|
309
475
|
// src/caveats/nativeBalanceChange.ts
|
|
310
476
|
function createNativeBalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
311
|
-
const { recipient, balance, changeType
|
|
477
|
+
const { recipient, balance, changeType } = terms;
|
|
312
478
|
const recipientHex = normalizeAddressLowercase(
|
|
313
479
|
recipient,
|
|
314
480
|
"Invalid recipient: must be a valid Address"
|
|
@@ -316,7 +482,6 @@ function createNativeBalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
316
482
|
if (balance <= 0n) {
|
|
317
483
|
throw new Error("Invalid balance: must be a positive number");
|
|
318
484
|
}
|
|
319
|
-
const changeType = changeTypeNumber;
|
|
320
485
|
if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
|
|
321
486
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
322
487
|
}
|
|
@@ -325,6 +490,22 @@ function createNativeBalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
325
490
|
const hexValue = concatHex([changeTypeHex, recipientHex, balanceHex]);
|
|
326
491
|
return prepareResult(hexValue, encodingOptions);
|
|
327
492
|
}
|
|
493
|
+
function decodeNativeBalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
494
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
495
|
+
assertHexByteExactLength(
|
|
496
|
+
hexTerms,
|
|
497
|
+
53,
|
|
498
|
+
"Invalid NativeBalanceChange terms: must be exactly 53 bytes"
|
|
499
|
+
);
|
|
500
|
+
const changeType = extractNumber(hexTerms, 0, 1);
|
|
501
|
+
const recipientHex = extractAddress(hexTerms, 1);
|
|
502
|
+
const balance = extractBigInt(hexTerms, 21, 32);
|
|
503
|
+
return {
|
|
504
|
+
changeType,
|
|
505
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
506
|
+
balance
|
|
507
|
+
};
|
|
508
|
+
}
|
|
328
509
|
|
|
329
510
|
// src/caveats/erc20Streaming.ts
|
|
330
511
|
|
|
@@ -373,6 +554,26 @@ function createERC20StreamingTerms(terms, encodingOptions = defaultOptions) {
|
|
|
373
554
|
const hexValue = `${prefixedTokenAddressHex}${initialAmountHex}${maxAmountHex}${amountPerSecondHex}${startTimeHex}`;
|
|
374
555
|
return prepareResult(hexValue, encodingOptions);
|
|
375
556
|
}
|
|
557
|
+
function decodeERC20StreamingTerms(terms, encodingOptions = defaultOptions) {
|
|
558
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
559
|
+
assertHexByteExactLength(
|
|
560
|
+
hexTerms,
|
|
561
|
+
148,
|
|
562
|
+
"Invalid ERC20Streaming terms: must be exactly 148 bytes"
|
|
563
|
+
);
|
|
564
|
+
const tokenAddressHex = extractAddress(hexTerms, 0);
|
|
565
|
+
const initialAmount = extractBigInt(hexTerms, 20, 32);
|
|
566
|
+
const maxAmount = extractBigInt(hexTerms, 52, 32);
|
|
567
|
+
const amountPerSecond = extractBigInt(hexTerms, 84, 32);
|
|
568
|
+
const startTime = extractNumber(hexTerms, 116, 32);
|
|
569
|
+
return {
|
|
570
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
571
|
+
initialAmount,
|
|
572
|
+
maxAmount,
|
|
573
|
+
amountPerSecond,
|
|
574
|
+
startTime
|
|
575
|
+
};
|
|
576
|
+
}
|
|
376
577
|
|
|
377
578
|
// src/caveats/erc20TokenPeriodTransfer.ts
|
|
378
579
|
|
|
@@ -408,6 +609,24 @@ function createERC20TokenPeriodTransferTerms(terms, encodingOptions = defaultOpt
|
|
|
408
609
|
const hexValue = `${prefixedTokenAddressHex}${periodAmountHex}${periodDurationHex}${startDateHex}`;
|
|
409
610
|
return prepareResult(hexValue, encodingOptions);
|
|
410
611
|
}
|
|
612
|
+
function decodeERC20TokenPeriodTransferTerms(terms, encodingOptions = defaultOptions) {
|
|
613
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
614
|
+
assertHexByteExactLength(
|
|
615
|
+
hexTerms,
|
|
616
|
+
116,
|
|
617
|
+
"Invalid ERC20TokenPeriodTransfer terms: must be exactly 116 bytes"
|
|
618
|
+
);
|
|
619
|
+
const tokenAddressHex = extractAddress(hexTerms, 0);
|
|
620
|
+
const periodAmount = extractBigInt(hexTerms, 20, 32);
|
|
621
|
+
const periodDuration = extractNumber(hexTerms, 52, 32);
|
|
622
|
+
const startDate = extractNumber(hexTerms, 84, 32);
|
|
623
|
+
return {
|
|
624
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
625
|
+
periodAmount,
|
|
626
|
+
periodDuration,
|
|
627
|
+
startDate
|
|
628
|
+
};
|
|
629
|
+
}
|
|
411
630
|
|
|
412
631
|
// src/caveats/erc20TransferAmount.ts
|
|
413
632
|
function createERC20TransferAmountTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -423,15 +642,24 @@ function createERC20TransferAmountTerms(terms, encodingOptions = defaultOptions)
|
|
|
423
642
|
const hexValue = concatHex([tokenAddressHex, maxAmountHex]);
|
|
424
643
|
return prepareResult(hexValue, encodingOptions);
|
|
425
644
|
}
|
|
645
|
+
function decodeERC20TransferAmountTerms(terms, encodingOptions = defaultOptions) {
|
|
646
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
647
|
+
assertHexByteExactLength(
|
|
648
|
+
hexTerms,
|
|
649
|
+
52,
|
|
650
|
+
"Invalid ERC20TransferAmount terms: must be exactly 52 bytes"
|
|
651
|
+
);
|
|
652
|
+
const tokenAddressHex = extractAddress(hexTerms, 0);
|
|
653
|
+
const maxAmount = extractBigInt(hexTerms, 20, 32);
|
|
654
|
+
return {
|
|
655
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
656
|
+
maxAmount
|
|
657
|
+
};
|
|
658
|
+
}
|
|
426
659
|
|
|
427
660
|
// src/caveats/erc20BalanceChange.ts
|
|
428
661
|
function createERC20BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
429
|
-
const {
|
|
430
|
-
tokenAddress,
|
|
431
|
-
recipient,
|
|
432
|
-
balance,
|
|
433
|
-
changeType: changeTypeNumber
|
|
434
|
-
} = terms;
|
|
662
|
+
const { tokenAddress, recipient, balance, changeType } = terms;
|
|
435
663
|
const tokenAddressHex = normalizeAddressLowercase(
|
|
436
664
|
tokenAddress,
|
|
437
665
|
"Invalid tokenAddress: must be a valid address"
|
|
@@ -443,7 +671,6 @@ function createERC20BalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
443
671
|
if (balance <= 0n) {
|
|
444
672
|
throw new Error("Invalid balance: must be a positive number");
|
|
445
673
|
}
|
|
446
|
-
const changeType = changeTypeNumber;
|
|
447
674
|
if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
|
|
448
675
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
449
676
|
}
|
|
@@ -457,15 +684,28 @@ function createERC20BalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
457
684
|
]);
|
|
458
685
|
return prepareResult(hexValue, encodingOptions);
|
|
459
686
|
}
|
|
687
|
+
function decodeERC20BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
688
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
689
|
+
assertHexByteExactLength(
|
|
690
|
+
hexTerms,
|
|
691
|
+
73,
|
|
692
|
+
"Invalid ERC20BalanceChange terms: must be exactly 73 bytes"
|
|
693
|
+
);
|
|
694
|
+
const changeType = extractNumber(hexTerms, 0, 1);
|
|
695
|
+
const tokenAddressHex = extractAddress(hexTerms, 1);
|
|
696
|
+
const recipientHex = extractAddress(hexTerms, 21);
|
|
697
|
+
const balance = extractBigInt(hexTerms, 41, 32);
|
|
698
|
+
return {
|
|
699
|
+
changeType,
|
|
700
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
701
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
702
|
+
balance
|
|
703
|
+
};
|
|
704
|
+
}
|
|
460
705
|
|
|
461
706
|
// src/caveats/erc721BalanceChange.ts
|
|
462
707
|
function createERC721BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
463
|
-
const {
|
|
464
|
-
tokenAddress,
|
|
465
|
-
recipient,
|
|
466
|
-
amount,
|
|
467
|
-
changeType: changeTypeNumber
|
|
468
|
-
} = terms;
|
|
708
|
+
const { tokenAddress, recipient, amount, changeType } = terms;
|
|
469
709
|
const tokenAddressHex = normalizeAddressLowercase(
|
|
470
710
|
tokenAddress,
|
|
471
711
|
"Invalid tokenAddress: must be a valid address"
|
|
@@ -477,7 +717,6 @@ function createERC721BalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
477
717
|
if (amount <= 0n) {
|
|
478
718
|
throw new Error("Invalid balance: must be a positive number");
|
|
479
719
|
}
|
|
480
|
-
const changeType = changeTypeNumber;
|
|
481
720
|
if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
|
|
482
721
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
483
722
|
}
|
|
@@ -491,6 +730,24 @@ function createERC721BalanceChangeTerms(terms, encodingOptions = defaultOptions)
|
|
|
491
730
|
]);
|
|
492
731
|
return prepareResult(hexValue, encodingOptions);
|
|
493
732
|
}
|
|
733
|
+
function decodeERC721BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
734
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
735
|
+
assertHexByteExactLength(
|
|
736
|
+
hexTerms,
|
|
737
|
+
73,
|
|
738
|
+
"Invalid ERC721BalanceChange terms: must be exactly 73 bytes"
|
|
739
|
+
);
|
|
740
|
+
const changeType = extractNumber(hexTerms, 0, 1);
|
|
741
|
+
const tokenAddressHex = extractAddress(hexTerms, 1);
|
|
742
|
+
const recipientHex = extractAddress(hexTerms, 21);
|
|
743
|
+
const amount = extractBigInt(hexTerms, 41, 32);
|
|
744
|
+
return {
|
|
745
|
+
changeType,
|
|
746
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
747
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
748
|
+
amount
|
|
749
|
+
};
|
|
750
|
+
}
|
|
494
751
|
|
|
495
752
|
// src/caveats/erc721Transfer.ts
|
|
496
753
|
function createERC721TransferTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -506,16 +763,24 @@ function createERC721TransferTerms(terms, encodingOptions = defaultOptions) {
|
|
|
506
763
|
const hexValue = concatHex([tokenAddressHex, tokenIdHex]);
|
|
507
764
|
return prepareResult(hexValue, encodingOptions);
|
|
508
765
|
}
|
|
766
|
+
function decodeERC721TransferTerms(terms, encodingOptions = defaultOptions) {
|
|
767
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
768
|
+
assertHexByteExactLength(
|
|
769
|
+
hexTerms,
|
|
770
|
+
52,
|
|
771
|
+
"Invalid ERC721Transfer terms: must be exactly 52 bytes"
|
|
772
|
+
);
|
|
773
|
+
const tokenAddressHex = extractAddress(hexTerms, 0);
|
|
774
|
+
const tokenId = extractBigInt(hexTerms, 20, 32);
|
|
775
|
+
return {
|
|
776
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
777
|
+
tokenId
|
|
778
|
+
};
|
|
779
|
+
}
|
|
509
780
|
|
|
510
781
|
// src/caveats/erc1155BalanceChange.ts
|
|
511
782
|
function createERC1155BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
512
|
-
const {
|
|
513
|
-
tokenAddress,
|
|
514
|
-
recipient,
|
|
515
|
-
tokenId,
|
|
516
|
-
balance,
|
|
517
|
-
changeType: changeTypeNumber
|
|
518
|
-
} = terms;
|
|
783
|
+
const { tokenAddress, recipient, tokenId, balance, changeType } = terms;
|
|
519
784
|
const tokenAddressHex = normalizeAddressLowercase(
|
|
520
785
|
tokenAddress,
|
|
521
786
|
"Invalid tokenAddress: must be a valid address"
|
|
@@ -530,7 +795,6 @@ function createERC1155BalanceChangeTerms(terms, encodingOptions = defaultOptions
|
|
|
530
795
|
if (tokenId < 0n) {
|
|
531
796
|
throw new Error("Invalid tokenId: must be a non-negative number");
|
|
532
797
|
}
|
|
533
|
-
const changeType = changeTypeNumber;
|
|
534
798
|
if (changeType !== 0 /* Increase */ && changeType !== 1 /* Decrease */) {
|
|
535
799
|
throw new Error("Invalid changeType: must be either Increase or Decrease");
|
|
536
800
|
}
|
|
@@ -546,6 +810,26 @@ function createERC1155BalanceChangeTerms(terms, encodingOptions = defaultOptions
|
|
|
546
810
|
]);
|
|
547
811
|
return prepareResult(hexValue, encodingOptions);
|
|
548
812
|
}
|
|
813
|
+
function decodeERC1155BalanceChangeTerms(terms, encodingOptions = defaultOptions) {
|
|
814
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
815
|
+
assertHexByteExactLength(
|
|
816
|
+
hexTerms,
|
|
817
|
+
105,
|
|
818
|
+
"Invalid ERC1155BalanceChange terms: must be exactly 105 bytes"
|
|
819
|
+
);
|
|
820
|
+
const changeType = extractNumber(hexTerms, 0, 1);
|
|
821
|
+
const tokenAddressHex = extractAddress(hexTerms, 1);
|
|
822
|
+
const recipientHex = extractAddress(hexTerms, 21);
|
|
823
|
+
const tokenId = extractBigInt(hexTerms, 41, 32);
|
|
824
|
+
const balance = extractBigInt(hexTerms, 73, 32);
|
|
825
|
+
return {
|
|
826
|
+
changeType,
|
|
827
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
828
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
829
|
+
tokenId,
|
|
830
|
+
balance
|
|
831
|
+
};
|
|
832
|
+
}
|
|
549
833
|
|
|
550
834
|
// src/caveats/nonce.ts
|
|
551
835
|
|
|
@@ -573,6 +857,16 @@ function createNonceTerms(terms, encodingOptions = defaultOptions) {
|
|
|
573
857
|
const hexValue = `0x${paddedNonce}`;
|
|
574
858
|
return prepareResult(hexValue, encodingOptions);
|
|
575
859
|
}
|
|
860
|
+
function decodeNonceTerms(terms, encodingOptions = defaultOptions) {
|
|
861
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
862
|
+
assertHexByteExactLength(
|
|
863
|
+
hexTerms,
|
|
864
|
+
32,
|
|
865
|
+
"Invalid Nonce terms: must be exactly 32 bytes"
|
|
866
|
+
);
|
|
867
|
+
const nonce = prepareResult(hexTerms, encodingOptions);
|
|
868
|
+
return { nonce };
|
|
869
|
+
}
|
|
576
870
|
|
|
577
871
|
// src/caveats/allowedCalldata.ts
|
|
578
872
|
|
|
@@ -596,6 +890,18 @@ function createAllowedCalldataTerms(terms, encodingOptions = defaultOptions) {
|
|
|
596
890
|
const indexHex = toHexString({ value: startIndex, size: 32 });
|
|
597
891
|
return prepareResult(`0x${indexHex}${unprefixedValue}`, encodingOptions);
|
|
598
892
|
}
|
|
893
|
+
function decodeAllowedCalldataTerms(terms, encodingOptions = defaultOptions) {
|
|
894
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
895
|
+
assertHexBytesMinLength(
|
|
896
|
+
hexTerms,
|
|
897
|
+
32,
|
|
898
|
+
"Invalid AllowedCalldata terms: must be at least 32 bytes"
|
|
899
|
+
);
|
|
900
|
+
const startIndex = extractNumber(hexTerms, 0, 32);
|
|
901
|
+
const valueHex = extractRemainingHex(hexTerms, 32);
|
|
902
|
+
const value = prepareResult(valueHex, encodingOptions);
|
|
903
|
+
return { startIndex, value };
|
|
904
|
+
}
|
|
599
905
|
|
|
600
906
|
// src/caveats/allowedMethods.ts
|
|
601
907
|
|
|
@@ -621,6 +927,22 @@ function createAllowedMethodsTerms(terms, encodingOptions = defaultOptions) {
|
|
|
621
927
|
const hexValue = concatHex(normalizedSelectors);
|
|
622
928
|
return prepareResult(hexValue, encodingOptions);
|
|
623
929
|
}
|
|
930
|
+
function decodeAllowedMethodsTerms(terms, encodingOptions = defaultOptions) {
|
|
931
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
932
|
+
const selectorSize = 4;
|
|
933
|
+
assertHexByteLengthAtLeastOneMultipleOf(
|
|
934
|
+
hexTerms,
|
|
935
|
+
selectorSize,
|
|
936
|
+
"Invalid selectors: must be a multiple of 4"
|
|
937
|
+
);
|
|
938
|
+
const selectorCount = getByteLength(hexTerms) / selectorSize;
|
|
939
|
+
const selectors = [];
|
|
940
|
+
for (let i = 0; i < selectorCount; i++) {
|
|
941
|
+
const selector = extractHex(hexTerms, i * selectorSize, selectorSize);
|
|
942
|
+
selectors.push(prepareResult(selector, encodingOptions));
|
|
943
|
+
}
|
|
944
|
+
return { selectors };
|
|
945
|
+
}
|
|
624
946
|
|
|
625
947
|
// src/caveats/allowedTargets.ts
|
|
626
948
|
function createAllowedTargetsTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -636,6 +958,22 @@ function createAllowedTargetsTerms(terms, encodingOptions = defaultOptions) {
|
|
|
636
958
|
const hexValue = concatHex(normalizedTargets);
|
|
637
959
|
return prepareResult(hexValue, encodingOptions);
|
|
638
960
|
}
|
|
961
|
+
function decodeAllowedTargetsTerms(terms, encodingOptions = defaultOptions) {
|
|
962
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
963
|
+
const addressSize = 20;
|
|
964
|
+
assertHexByteLengthAtLeastOneMultipleOf(
|
|
965
|
+
hexTerms,
|
|
966
|
+
addressSize,
|
|
967
|
+
"Invalid targets: must be a multiple of 20"
|
|
968
|
+
);
|
|
969
|
+
const addressCount = getByteLength(hexTerms) / addressSize;
|
|
970
|
+
const targets = [];
|
|
971
|
+
for (let i = 0; i < addressCount; i++) {
|
|
972
|
+
const target = extractAddress(hexTerms, i * addressSize);
|
|
973
|
+
targets.push(prepareResult(target, encodingOptions));
|
|
974
|
+
}
|
|
975
|
+
return { targets };
|
|
976
|
+
}
|
|
639
977
|
|
|
640
978
|
// src/caveats/argsEqualityCheck.ts
|
|
641
979
|
function createArgsEqualityCheckTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -649,6 +987,11 @@ function createArgsEqualityCheckTerms(terms, encodingOptions = defaultOptions) {
|
|
|
649
987
|
);
|
|
650
988
|
return prepareResult(hexValue, encodingOptions);
|
|
651
989
|
}
|
|
990
|
+
function decodeArgsEqualityCheckTerms(terms, encodingOptions = defaultOptions) {
|
|
991
|
+
const argsHex = bytesLikeToHex(terms);
|
|
992
|
+
const args = prepareResult(argsHex, encodingOptions);
|
|
993
|
+
return { args };
|
|
994
|
+
}
|
|
652
995
|
|
|
653
996
|
// src/caveats/blockNumber.ts
|
|
654
997
|
function createBlockNumberTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -671,6 +1014,17 @@ function createBlockNumberTerms(terms, encodingOptions = defaultOptions) {
|
|
|
671
1014
|
const hexValue = `0x${afterThresholdHex}${beforeThresholdHex}`;
|
|
672
1015
|
return prepareResult(hexValue, encodingOptions);
|
|
673
1016
|
}
|
|
1017
|
+
function decodeBlockNumberTerms(terms) {
|
|
1018
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1019
|
+
assertHexByteExactLength(
|
|
1020
|
+
hexTerms,
|
|
1021
|
+
32,
|
|
1022
|
+
"Invalid BlockNumber terms: must be exactly 32 bytes"
|
|
1023
|
+
);
|
|
1024
|
+
const afterThreshold = extractBigInt(hexTerms, 0, 16);
|
|
1025
|
+
const beforeThreshold = extractBigInt(hexTerms, 16, 16);
|
|
1026
|
+
return { afterThreshold, beforeThreshold };
|
|
1027
|
+
}
|
|
674
1028
|
|
|
675
1029
|
// src/caveats/deployed.ts
|
|
676
1030
|
|
|
@@ -696,6 +1050,22 @@ function createDeployedTerms(terms, encodingOptions = defaultOptions) {
|
|
|
696
1050
|
const hexValue = concatHex([contractAddressHex, paddedSalt, bytecodeHex]);
|
|
697
1051
|
return prepareResult(hexValue, encodingOptions);
|
|
698
1052
|
}
|
|
1053
|
+
function decodeDeployedTerms(terms, encodingOptions = defaultOptions) {
|
|
1054
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1055
|
+
assertHexBytesMinLength(
|
|
1056
|
+
hexTerms,
|
|
1057
|
+
52,
|
|
1058
|
+
"Invalid Deployed terms: must be at least 52 bytes"
|
|
1059
|
+
);
|
|
1060
|
+
const contractAddressHex = extractAddress(hexTerms, 0);
|
|
1061
|
+
const saltHex = extractHex(hexTerms, 20, 32);
|
|
1062
|
+
const bytecodeHex = extractRemainingHex(hexTerms, 52);
|
|
1063
|
+
return {
|
|
1064
|
+
contractAddress: prepareResult(contractAddressHex, encodingOptions),
|
|
1065
|
+
salt: prepareResult(saltHex, encodingOptions),
|
|
1066
|
+
bytecode: prepareResult(bytecodeHex, encodingOptions)
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
699
1069
|
|
|
700
1070
|
// src/caveats/id.ts
|
|
701
1071
|
var MAX_UINT256 = BigInt(`0x${"f".repeat(64)}`);
|
|
@@ -721,6 +1091,16 @@ function createIdTerms(terms, encodingOptions = defaultOptions) {
|
|
|
721
1091
|
const hexValue = `0x${toHexString({ value: idBigInt, size: 32 })}`;
|
|
722
1092
|
return prepareResult(hexValue, encodingOptions);
|
|
723
1093
|
}
|
|
1094
|
+
function decodeIdTerms(terms) {
|
|
1095
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1096
|
+
assertHexByteExactLength(
|
|
1097
|
+
hexTerms,
|
|
1098
|
+
32,
|
|
1099
|
+
"Invalid Id terms: must be exactly 32 bytes"
|
|
1100
|
+
);
|
|
1101
|
+
const id = extractBigInt(hexTerms, 0, 32);
|
|
1102
|
+
return { id };
|
|
1103
|
+
}
|
|
724
1104
|
|
|
725
1105
|
// src/caveats/limitedCalls.ts
|
|
726
1106
|
function createLimitedCallsTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -734,6 +1114,16 @@ function createLimitedCallsTerms(terms, encodingOptions = defaultOptions) {
|
|
|
734
1114
|
const hexValue = `0x${toHexString({ value: limit, size: 32 })}`;
|
|
735
1115
|
return prepareResult(hexValue, encodingOptions);
|
|
736
1116
|
}
|
|
1117
|
+
function decodeLimitedCallsTerms(terms) {
|
|
1118
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1119
|
+
assertHexByteExactLength(
|
|
1120
|
+
hexTerms,
|
|
1121
|
+
32,
|
|
1122
|
+
"Invalid LimitedCalls terms: must be exactly 32 bytes"
|
|
1123
|
+
);
|
|
1124
|
+
const limit = extractNumber(hexTerms, 0, 32);
|
|
1125
|
+
return { limit };
|
|
1126
|
+
}
|
|
737
1127
|
|
|
738
1128
|
// src/caveats/multiTokenPeriod.ts
|
|
739
1129
|
function createMultiTokenPeriodTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -768,6 +1158,31 @@ function createMultiTokenPeriodTerms(terms, encodingOptions = defaultOptions) {
|
|
|
768
1158
|
const hexValue = concatHex(hexParts);
|
|
769
1159
|
return prepareResult(hexValue, encodingOptions);
|
|
770
1160
|
}
|
|
1161
|
+
function decodeMultiTokenPeriodTerms(terms, encodingOptions = defaultOptions) {
|
|
1162
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1163
|
+
const configSize = 116;
|
|
1164
|
+
assertHexByteLengthAtLeastOneMultipleOf(
|
|
1165
|
+
hexTerms,
|
|
1166
|
+
configSize,
|
|
1167
|
+
"Invalid MultiTokenPeriod terms: must be a multiple of 116 bytes"
|
|
1168
|
+
);
|
|
1169
|
+
const configCount = getByteLength(hexTerms) / configSize;
|
|
1170
|
+
const tokenConfigs = [];
|
|
1171
|
+
for (let i = 0; i < configCount; i++) {
|
|
1172
|
+
const offset = i * configSize;
|
|
1173
|
+
const tokenHex = extractAddress(hexTerms, offset);
|
|
1174
|
+
const periodAmount = extractBigInt(hexTerms, offset + 20, 32);
|
|
1175
|
+
const periodDuration = extractNumber(hexTerms, offset + 52, 32);
|
|
1176
|
+
const startDate = extractNumber(hexTerms, offset + 84, 32);
|
|
1177
|
+
tokenConfigs.push({
|
|
1178
|
+
token: prepareResult(tokenHex, encodingOptions),
|
|
1179
|
+
periodAmount,
|
|
1180
|
+
periodDuration,
|
|
1181
|
+
startDate
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
return { tokenConfigs };
|
|
1185
|
+
}
|
|
771
1186
|
|
|
772
1187
|
// src/caveats/ownershipTransfer.ts
|
|
773
1188
|
function createOwnershipTransferTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -778,6 +1193,18 @@ function createOwnershipTransferTerms(terms, encodingOptions = defaultOptions) {
|
|
|
778
1193
|
);
|
|
779
1194
|
return prepareResult(contractAddressHex, encodingOptions);
|
|
780
1195
|
}
|
|
1196
|
+
function decodeOwnershipTransferTerms(terms, encodingOptions = defaultOptions) {
|
|
1197
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1198
|
+
assertHexByteExactLength(
|
|
1199
|
+
hexTerms,
|
|
1200
|
+
20,
|
|
1201
|
+
"Invalid OwnershipTransfer terms: must be exactly 20 bytes"
|
|
1202
|
+
);
|
|
1203
|
+
const contractAddressHex = extractAddress(hexTerms, 0);
|
|
1204
|
+
return {
|
|
1205
|
+
contractAddress: prepareResult(contractAddressHex, encodingOptions)
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
781
1208
|
|
|
782
1209
|
// src/caveats/redeemer.ts
|
|
783
1210
|
function createRedeemerTerms(terms, encodingOptions = defaultOptions) {
|
|
@@ -793,6 +1220,22 @@ function createRedeemerTerms(terms, encodingOptions = defaultOptions) {
|
|
|
793
1220
|
const hexValue = concatHex(normalizedRedeemers);
|
|
794
1221
|
return prepareResult(hexValue, encodingOptions);
|
|
795
1222
|
}
|
|
1223
|
+
function decodeRedeemerTerms(terms, encodingOptions = defaultOptions) {
|
|
1224
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1225
|
+
const addressSize = 20;
|
|
1226
|
+
assertHexByteLengthAtLeastOneMultipleOf(
|
|
1227
|
+
hexTerms,
|
|
1228
|
+
addressSize,
|
|
1229
|
+
"Invalid redeemers: must be a multiple of 20"
|
|
1230
|
+
);
|
|
1231
|
+
const addressCount = getByteLength(hexTerms) / addressSize;
|
|
1232
|
+
const redeemers = [];
|
|
1233
|
+
for (let i = 0; i < addressCount; i++) {
|
|
1234
|
+
const redeemer = extractAddress(hexTerms, i * addressSize);
|
|
1235
|
+
redeemers.push(prepareResult(redeemer, encodingOptions));
|
|
1236
|
+
}
|
|
1237
|
+
return { redeemers };
|
|
1238
|
+
}
|
|
796
1239
|
|
|
797
1240
|
// src/caveats/specificActionERC20TransferBatch.ts
|
|
798
1241
|
|
|
@@ -834,6 +1277,105 @@ function createSpecificActionERC20TransferBatchTerms(terms, encodingOptions = de
|
|
|
834
1277
|
]);
|
|
835
1278
|
return prepareResult(hexValue, encodingOptions);
|
|
836
1279
|
}
|
|
1280
|
+
function decodeSpecificActionERC20TransferBatchTerms(terms, encodingOptions = defaultOptions) {
|
|
1281
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1282
|
+
assertHexBytesMinLength(
|
|
1283
|
+
hexTerms,
|
|
1284
|
+
92,
|
|
1285
|
+
"Invalid SpecificActionERC20TransferBatch terms: must be at least 92 bytes"
|
|
1286
|
+
);
|
|
1287
|
+
const tokenAddressHex = extractAddress(hexTerms, 0);
|
|
1288
|
+
const recipientHex = extractAddress(hexTerms, 20);
|
|
1289
|
+
const amount = extractBigInt(hexTerms, 40, 32);
|
|
1290
|
+
const targetHex = extractAddress(hexTerms, 72);
|
|
1291
|
+
const calldataHex = extractRemainingHex(hexTerms, 92);
|
|
1292
|
+
return {
|
|
1293
|
+
tokenAddress: prepareResult(tokenAddressHex, encodingOptions),
|
|
1294
|
+
recipient: prepareResult(recipientHex, encodingOptions),
|
|
1295
|
+
amount,
|
|
1296
|
+
target: prepareResult(targetHex, encodingOptions),
|
|
1297
|
+
calldata: prepareResult(calldataHex, encodingOptions)
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// src/caveats/logicalOrWrapper.ts
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
var CAVEAT_GROUPS_ABI = "((address,bytes,bytes)[])[]";
|
|
1305
|
+
var SELECTED_GROUP_ABI = "(uint256,bytes[])";
|
|
1306
|
+
function assertValidCaveatGroups(groups) {
|
|
1307
|
+
if (!_optionalChain([groups, 'optionalAccess', _ => _.length])) {
|
|
1308
|
+
throw new Error(
|
|
1309
|
+
"Invalid caveatGroups: must provide at least one caveat group"
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
for (let i = 0; i < groups.length; i++) {
|
|
1313
|
+
const group = groups[i];
|
|
1314
|
+
if (!_optionalChain([group, 'optionalAccess', _2 => _2.length])) {
|
|
1315
|
+
throw new Error(
|
|
1316
|
+
`Invalid caveatGroups: group at index ${i} must contain at least one caveat`
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
function normalizeCaveatTuple(caveat) {
|
|
1322
|
+
return [
|
|
1323
|
+
normalizeAddress(
|
|
1324
|
+
caveat.enforcer,
|
|
1325
|
+
"Invalid enforcer: must be a valid address"
|
|
1326
|
+
),
|
|
1327
|
+
normalizeHex(caveat.terms, "Invalid terms: must be a valid hex string"),
|
|
1328
|
+
normalizeHex(caveat.args, "Invalid args: must be a valid hex string")
|
|
1329
|
+
];
|
|
1330
|
+
}
|
|
1331
|
+
function encodeCaveatGroupTuple(group) {
|
|
1332
|
+
return [group.map(normalizeCaveatTuple)];
|
|
1333
|
+
}
|
|
1334
|
+
function createLogicalOrWrapperTerms(terms, encodingOptions = defaultOptions) {
|
|
1335
|
+
assertValidCaveatGroups(terms.caveatGroups);
|
|
1336
|
+
const encodableGroups = terms.caveatGroups.map(encodeCaveatGroupTuple);
|
|
1337
|
+
const hexValue = _abiutils.encodeSingle.call(void 0, CAVEAT_GROUPS_ABI, encodableGroups);
|
|
1338
|
+
return prepareResult(hexValue, encodingOptions);
|
|
1339
|
+
}
|
|
1340
|
+
function decodeLogicalOrWrapperTerms(terms, encodingOptions = defaultOptions) {
|
|
1341
|
+
const hexTerms = bytesLikeToHex(terms);
|
|
1342
|
+
const decoded = _abiutils.decodeSingle.call(void 0,
|
|
1343
|
+
CAVEAT_GROUPS_ABI,
|
|
1344
|
+
hexTerms
|
|
1345
|
+
);
|
|
1346
|
+
const caveatGroups = decoded.map(
|
|
1347
|
+
([caveats]) => caveats.map(([enforcer, caveatTerms, args]) => ({
|
|
1348
|
+
enforcer: prepareResult(enforcer, encodingOptions),
|
|
1349
|
+
terms: prepareResult(_utils.bytesToHex.call(void 0, caveatTerms), encodingOptions),
|
|
1350
|
+
args: prepareResult(_utils.bytesToHex.call(void 0, args), encodingOptions)
|
|
1351
|
+
}))
|
|
1352
|
+
);
|
|
1353
|
+
return { caveatGroups };
|
|
1354
|
+
}
|
|
1355
|
+
function createLogicalOrWrapperArgs(args, encodingOptions = defaultOptions) {
|
|
1356
|
+
if (args.groupIndex < 0n) {
|
|
1357
|
+
throw new Error("Invalid groupIndex: must be a non-negative number");
|
|
1358
|
+
}
|
|
1359
|
+
const caveatArgsHex = args.caveatArgs.map(
|
|
1360
|
+
(arg) => normalizeHex(arg, "Invalid caveatArgs: must be valid hex strings")
|
|
1361
|
+
);
|
|
1362
|
+
const hexValue = _abiutils.encodeSingle.call(void 0, SELECTED_GROUP_ABI, [
|
|
1363
|
+
args.groupIndex,
|
|
1364
|
+
caveatArgsHex
|
|
1365
|
+
]);
|
|
1366
|
+
return prepareResult(hexValue, encodingOptions);
|
|
1367
|
+
}
|
|
1368
|
+
function decodeLogicalOrWrapperArgs(args, encodingOptions = defaultOptions) {
|
|
1369
|
+
const hexArgs = bytesLikeToHex(args);
|
|
1370
|
+
const [groupIndex, caveatArgsRaw] = _abiutils.decodeSingle.call(void 0,
|
|
1371
|
+
SELECTED_GROUP_ABI,
|
|
1372
|
+
hexArgs
|
|
1373
|
+
);
|
|
1374
|
+
const caveatArgs = caveatArgsRaw.map(
|
|
1375
|
+
(arg) => prepareResult(_utils.bytesToHex.call(void 0, arg), encodingOptions)
|
|
1376
|
+
);
|
|
1377
|
+
return { groupIndex, caveatArgs };
|
|
1378
|
+
}
|
|
837
1379
|
|
|
838
1380
|
// src/delegation.ts
|
|
839
1381
|
|
|
@@ -1003,5 +1545,41 @@ function getCaveatHash(caveat) {
|
|
|
1003
1545
|
|
|
1004
1546
|
|
|
1005
1547
|
|
|
1006
|
-
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
|
|
1568
|
+
|
|
1569
|
+
|
|
1570
|
+
|
|
1571
|
+
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
|
|
1575
|
+
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
exports.ANY_BENEFICIARY = ANY_BENEFICIARY; exports.BalanceChangeType = BalanceChangeType; exports.CAVEAT_TYPEHASH = CAVEAT_TYPEHASH; exports.DELEGATION_TYPEHASH = DELEGATION_TYPEHASH; exports.ROOT_AUTHORITY = ROOT_AUTHORITY; exports.createAllowedCalldataTerms = createAllowedCalldataTerms; exports.createAllowedMethodsTerms = createAllowedMethodsTerms; exports.createAllowedTargetsTerms = createAllowedTargetsTerms; exports.createArgsEqualityCheckTerms = createArgsEqualityCheckTerms; exports.createBlockNumberTerms = createBlockNumberTerms; exports.createDeployedTerms = createDeployedTerms; exports.createERC1155BalanceChangeTerms = createERC1155BalanceChangeTerms; exports.createERC20BalanceChangeTerms = createERC20BalanceChangeTerms; exports.createERC20StreamingTerms = createERC20StreamingTerms; exports.createERC20TokenPeriodTransferTerms = createERC20TokenPeriodTransferTerms; exports.createERC20TransferAmountTerms = createERC20TransferAmountTerms; exports.createERC721BalanceChangeTerms = createERC721BalanceChangeTerms; exports.createERC721TransferTerms = createERC721TransferTerms; exports.createExactCalldataBatchTerms = createExactCalldataBatchTerms; exports.createExactCalldataTerms = createExactCalldataTerms; exports.createExactExecutionBatchTerms = createExactExecutionBatchTerms; exports.createExactExecutionTerms = createExactExecutionTerms; exports.createIdTerms = createIdTerms; exports.createLimitedCallsTerms = createLimitedCallsTerms; exports.createLogicalOrWrapperArgs = createLogicalOrWrapperArgs; exports.createLogicalOrWrapperTerms = createLogicalOrWrapperTerms; exports.createMultiTokenPeriodTerms = createMultiTokenPeriodTerms; exports.createNativeBalanceChangeTerms = createNativeBalanceChangeTerms; exports.createNativeTokenPaymentTerms = createNativeTokenPaymentTerms; exports.createNativeTokenPeriodTransferTerms = createNativeTokenPeriodTransferTerms; exports.createNativeTokenStreamingTerms = createNativeTokenStreamingTerms; exports.createNativeTokenTransferAmountTerms = createNativeTokenTransferAmountTerms; exports.createNonceTerms = createNonceTerms; exports.createOwnershipTransferTerms = createOwnershipTransferTerms; exports.createRedeemerTerms = createRedeemerTerms; exports.createSpecificActionERC20TransferBatchTerms = createSpecificActionERC20TransferBatchTerms; exports.createTimestampTerms = createTimestampTerms; exports.createValueLteTerms = createValueLteTerms; exports.decodeAllowedCalldataTerms = decodeAllowedCalldataTerms; exports.decodeAllowedMethodsTerms = decodeAllowedMethodsTerms; exports.decodeAllowedTargetsTerms = decodeAllowedTargetsTerms; exports.decodeArgsEqualityCheckTerms = decodeArgsEqualityCheckTerms; exports.decodeBlockNumberTerms = decodeBlockNumberTerms; exports.decodeDelegation = decodeDelegation; exports.decodeDelegations = decodeDelegations; exports.decodeDeployedTerms = decodeDeployedTerms; exports.decodeERC1155BalanceChangeTerms = decodeERC1155BalanceChangeTerms; exports.decodeERC20BalanceChangeTerms = decodeERC20BalanceChangeTerms; exports.decodeERC20StreamingTerms = decodeERC20StreamingTerms; exports.decodeERC20TokenPeriodTransferTerms = decodeERC20TokenPeriodTransferTerms; exports.decodeERC20TransferAmountTerms = decodeERC20TransferAmountTerms; exports.decodeERC721BalanceChangeTerms = decodeERC721BalanceChangeTerms; exports.decodeERC721TransferTerms = decodeERC721TransferTerms; exports.decodeExactCalldataBatchTerms = decodeExactCalldataBatchTerms; exports.decodeExactCalldataTerms = decodeExactCalldataTerms; exports.decodeExactExecutionBatchTerms = decodeExactExecutionBatchTerms; exports.decodeExactExecutionTerms = decodeExactExecutionTerms; exports.decodeIdTerms = decodeIdTerms; exports.decodeLimitedCallsTerms = decodeLimitedCallsTerms; exports.decodeLogicalOrWrapperArgs = decodeLogicalOrWrapperArgs; exports.decodeLogicalOrWrapperTerms = decodeLogicalOrWrapperTerms; exports.decodeMultiTokenPeriodTerms = decodeMultiTokenPeriodTerms; exports.decodeNativeBalanceChangeTerms = decodeNativeBalanceChangeTerms; exports.decodeNativeTokenPaymentTerms = decodeNativeTokenPaymentTerms; exports.decodeNativeTokenPeriodTransferTerms = decodeNativeTokenPeriodTransferTerms; exports.decodeNativeTokenStreamingTerms = decodeNativeTokenStreamingTerms; exports.decodeNativeTokenTransferAmountTerms = decodeNativeTokenTransferAmountTerms; exports.decodeNonceTerms = decodeNonceTerms; exports.decodeOwnershipTransferTerms = decodeOwnershipTransferTerms; exports.decodeRedeemerTerms = decodeRedeemerTerms; exports.decodeSpecificActionERC20TransferBatchTerms = decodeSpecificActionERC20TransferBatchTerms; exports.decodeTimestampTerms = decodeTimestampTerms; exports.decodeValueLteTerms = decodeValueLteTerms; exports.encodeDelegation = encodeDelegation; exports.encodeDelegations = encodeDelegations; exports.hashDelegation = hashDelegation;
|
|
1007
1585
|
//# sourceMappingURL=index.cjs.map
|