@metamask-previews/user-operation-controller 41.2.9-preview-3e34650c2 → 41.2.9-preview-4f4c98e
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 +4 -0
- package/dist/{BlockTrackerPollingController.d.mts → BlockTrackerPollingController.d.ts} +11 -11
- package/dist/BlockTrackerPollingController.d.ts.map +1 -0
- package/dist/{BlockTrackerPollingController.mjs → BlockTrackerPollingController.js} +17 -16
- package/dist/BlockTrackerPollingController.js.map +1 -0
- package/dist/{UserOperationController-method-action-types.d.cts → UserOperationController-method-action-types.d.ts} +2 -2
- package/dist/UserOperationController-method-action-types.d.ts.map +1 -0
- package/dist/{UserOperationController-method-action-types.mjs → UserOperationController-method-action-types.js} +1 -1
- package/dist/UserOperationController-method-action-types.js.map +1 -0
- package/dist/{UserOperationController.d.cts → UserOperationController.d.ts} +13 -15
- package/dist/UserOperationController.d.ts.map +1 -0
- package/dist/{UserOperationController.mjs → UserOperationController.js} +19 -20
- package/dist/UserOperationController.js.map +1 -0
- package/dist/{constants.d.cts → constants.d.ts} +1 -1
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/helpers/{Bundler.d.cts → Bundler.d.ts} +2 -2
- package/dist/helpers/Bundler.d.ts.map +1 -0
- package/dist/helpers/{Bundler.mjs → Bundler.js} +2 -2
- package/dist/helpers/Bundler.js.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.d.cts → PendingUserOperationTracker.d.ts} +10 -12
- package/dist/helpers/PendingUserOperationTracker.d.ts.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.mjs → PendingUserOperationTracker.js} +9 -16
- package/dist/helpers/PendingUserOperationTracker.js.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.d.cts → SnapSmartContractAccount.d.ts} +3 -3
- package/dist/helpers/SnapSmartContractAccount.d.ts.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.mjs → SnapSmartContractAccount.js} +3 -3
- package/dist/helpers/SnapSmartContractAccount.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/{logger.mjs → logger.js} +2 -2
- package/dist/logger.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +3 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/utils/{chain-id.d.cts → chain-id.d.ts} +1 -1
- package/dist/utils/chain-id.d.ts.map +1 -0
- package/dist/utils/{chain-id.mjs → chain-id.js} +1 -1
- package/dist/utils/chain-id.js.map +1 -0
- package/dist/utils/{gas-fees.d.cts → gas-fees.d.ts} +6 -6
- package/dist/utils/gas-fees.d.ts.map +1 -0
- package/dist/utils/{gas-fees.mjs → gas-fees.js} +8 -15
- package/dist/utils/gas-fees.js.map +1 -0
- package/dist/utils/{gas.d.mts → gas.d.ts} +2 -2
- package/dist/utils/gas.d.ts.map +1 -0
- package/dist/utils/{gas.mjs → gas.js} +7 -14
- package/dist/utils/gas.js.map +1 -0
- package/dist/utils/{transaction.d.cts → transaction.d.ts} +3 -3
- package/dist/utils/transaction.d.ts.map +1 -0
- package/dist/utils/{transaction.mjs → transaction.js} +6 -13
- package/dist/utils/transaction.js.map +1 -0
- package/dist/utils/{validation.d.cts → validation.d.ts} +3 -3
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/{validation.mjs → validation.js} +5 -5
- package/dist/utils/validation.js.map +1 -0
- package/package.json +13 -17
- package/dist/BlockTrackerPollingController.cjs +0 -68
- package/dist/BlockTrackerPollingController.cjs.map +0 -1
- package/dist/BlockTrackerPollingController.d.cts +0 -41
- package/dist/BlockTrackerPollingController.d.cts.map +0 -1
- package/dist/BlockTrackerPollingController.d.mts.map +0 -1
- package/dist/BlockTrackerPollingController.mjs.map +0 -1
- package/dist/UserOperationController-method-action-types.cjs +0 -7
- package/dist/UserOperationController-method-action-types.cjs.map +0 -1
- package/dist/UserOperationController-method-action-types.d.cts.map +0 -1
- package/dist/UserOperationController-method-action-types.d.mts +0 -57
- package/dist/UserOperationController-method-action-types.d.mts.map +0 -1
- package/dist/UserOperationController-method-action-types.mjs.map +0 -1
- package/dist/UserOperationController.cjs +0 -495
- package/dist/UserOperationController.cjs.map +0 -1
- package/dist/UserOperationController.d.cts.map +0 -1
- package/dist/UserOperationController.d.mts +0 -136
- package/dist/UserOperationController.d.mts.map +0 -1
- package/dist/UserOperationController.mjs.map +0 -1
- package/dist/constants.cjs +0 -7
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -4
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/helpers/Bundler.cjs +0 -91
- package/dist/helpers/Bundler.cjs.map +0 -1
- package/dist/helpers/Bundler.d.cts.map +0 -1
- package/dist/helpers/Bundler.d.mts +0 -46
- package/dist/helpers/Bundler.d.mts.map +0 -1
- package/dist/helpers/Bundler.mjs.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.cjs +0 -127
- package/dist/helpers/PendingUserOperationTracker.cjs.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.cts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.mts +0 -51
- package/dist/helpers/PendingUserOperationTracker.d.mts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.mjs.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.cjs +0 -64
- package/dist/helpers/SnapSmartContractAccount.cjs.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.cts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.mts +0 -10
- package/dist/helpers/SnapSmartContractAccount.d.mts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.mjs.map +0 -1
- package/dist/index.cjs +0 -19
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -4
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -8
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs.map +0 -1
- package/dist/types.cjs +0 -16
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -294
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils/chain-id.cjs +0 -17
- package/dist/utils/chain-id.cjs.map +0 -1
- package/dist/utils/chain-id.d.cts.map +0 -1
- package/dist/utils/chain-id.d.mts +0 -8
- package/dist/utils/chain-id.d.mts.map +0 -1
- package/dist/utils/chain-id.mjs.map +0 -1
- package/dist/utils/gas-fees.cjs +0 -194
- package/dist/utils/gas-fees.cjs.map +0 -1
- package/dist/utils/gas-fees.d.cts.map +0 -1
- package/dist/utils/gas-fees.d.mts +0 -24
- package/dist/utils/gas-fees.d.mts.map +0 -1
- package/dist/utils/gas-fees.mjs.map +0 -1
- package/dist/utils/gas.cjs +0 -72
- package/dist/utils/gas.cjs.map +0 -1
- package/dist/utils/gas.d.cts +0 -10
- package/dist/utils/gas.d.cts.map +0 -1
- package/dist/utils/gas.d.mts.map +0 -1
- package/dist/utils/gas.mjs.map +0 -1
- package/dist/utils/transaction.cjs +0 -117
- package/dist/utils/transaction.cjs.map +0 -1
- package/dist/utils/transaction.d.cts.map +0 -1
- package/dist/utils/transaction.d.mts +0 -10
- package/dist/utils/transaction.d.mts.map +0 -1
- package/dist/utils/transaction.mjs.map +0 -1
- package/dist/utils/validation.cjs +0 -162
- package/dist/utils/validation.cjs.map +0 -1
- package/dist/utils/validation.d.cts.map +0 -1
- package/dist/utils/validation.d.mts +0 -33
- package/dist/utils/validation.d.mts.map +0 -1
- package/dist/utils/validation.mjs.map +0 -1
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getTransactionMetadata = void 0;
|
|
7
|
-
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
8
|
-
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
-
const constants_js_1 = require("../constants.cjs");
|
|
11
|
-
const types_js_1 = require("../types.cjs");
|
|
12
|
-
/**
|
|
13
|
-
* Converts a user operation metadata object into a transaction metadata object.
|
|
14
|
-
*
|
|
15
|
-
* @param metadata - The user operation metadata object to convert.
|
|
16
|
-
* @returns The equivalent transaction metadata object.
|
|
17
|
-
*/
|
|
18
|
-
function getTransactionMetadata(metadata) {
|
|
19
|
-
const { actualGasCost, actualGasUsed, baseFeePerGas, chainId, error: rawError, origin, transactionHash, id, swapsMetadata, time, transactionParams, transactionType, userFeeLevel: rawUserFeeLevel, userOperation, } = metadata;
|
|
20
|
-
if (!transactionParams) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
// effectiveGasPrice = actualGasCost / actualGasUsed
|
|
24
|
-
const effectiveGasPrice = actualGasCost && actualGasUsed
|
|
25
|
-
? (0, utils_1.add0x)(new bn_js_1.default((0, utils_1.remove0x)(actualGasCost), 16)
|
|
26
|
-
.div(new bn_js_1.default((0, utils_1.remove0x)(actualGasUsed), 16))
|
|
27
|
-
.toString(16))
|
|
28
|
-
: undefined;
|
|
29
|
-
const error = (rawError
|
|
30
|
-
? {
|
|
31
|
-
name: rawError.name,
|
|
32
|
-
message: rawError.message,
|
|
33
|
-
stack: rawError.stack,
|
|
34
|
-
code: rawError.code,
|
|
35
|
-
rpc: rawError.rpc,
|
|
36
|
-
}
|
|
37
|
-
: undefined);
|
|
38
|
-
const status = {
|
|
39
|
-
[types_js_1.UserOperationStatus.Unapproved]: transaction_controller_1.TransactionStatus.unapproved,
|
|
40
|
-
[types_js_1.UserOperationStatus.Approved]: transaction_controller_1.TransactionStatus.approved,
|
|
41
|
-
[types_js_1.UserOperationStatus.Signed]: transaction_controller_1.TransactionStatus.signed,
|
|
42
|
-
[types_js_1.UserOperationStatus.Submitted]: transaction_controller_1.TransactionStatus.submitted,
|
|
43
|
-
[types_js_1.UserOperationStatus.Confirmed]: transaction_controller_1.TransactionStatus.confirmed,
|
|
44
|
-
[types_js_1.UserOperationStatus.Failed]: transaction_controller_1.TransactionStatus.failed,
|
|
45
|
-
}[metadata.status];
|
|
46
|
-
const gas = addHex(userOperation.preVerificationGas, userOperation.verificationGasLimit, userOperation.callGasLimit);
|
|
47
|
-
const hasPaymaster = userOperation.paymasterAndData !== constants_js_1.EMPTY_BYTES;
|
|
48
|
-
const maxFeePerGas = hasPaymaster ? constants_js_1.VALUE_ZERO : userOperation.maxFeePerGas;
|
|
49
|
-
const maxPriorityFeePerGas = hasPaymaster
|
|
50
|
-
? constants_js_1.VALUE_ZERO
|
|
51
|
-
: userOperation.maxPriorityFeePerGas;
|
|
52
|
-
const nonce = userOperation.nonce === constants_js_1.EMPTY_BYTES ? undefined : userOperation.nonce;
|
|
53
|
-
const txParams = {
|
|
54
|
-
...transactionParams,
|
|
55
|
-
from: userOperation.sender,
|
|
56
|
-
gas,
|
|
57
|
-
nonce,
|
|
58
|
-
maxFeePerGas,
|
|
59
|
-
maxPriorityFeePerGas,
|
|
60
|
-
};
|
|
61
|
-
// User operations only support EIP-1559 gas fee properties.
|
|
62
|
-
delete txParams.gasPrice;
|
|
63
|
-
const swaps = {
|
|
64
|
-
approvalTxId: swapsMetadata?.approvalTxId ?? undefined,
|
|
65
|
-
destinationTokenAddress: swapsMetadata?.destinationTokenAddress ?? undefined,
|
|
66
|
-
destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,
|
|
67
|
-
destinationTokenDecimals: swapsMetadata?.destinationTokenDecimals ?? undefined,
|
|
68
|
-
destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,
|
|
69
|
-
estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,
|
|
70
|
-
sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,
|
|
71
|
-
sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,
|
|
72
|
-
sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,
|
|
73
|
-
sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,
|
|
74
|
-
swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,
|
|
75
|
-
swapMetaData: swapsMetadata?.swapMetaData ?? undefined,
|
|
76
|
-
swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,
|
|
77
|
-
};
|
|
78
|
-
const userFeeLevel = hasPaymaster ? transaction_controller_1.UserFeeLevel.CUSTOM : rawUserFeeLevel;
|
|
79
|
-
return {
|
|
80
|
-
baseFeePerGas: baseFeePerGas ?? undefined,
|
|
81
|
-
chainId: chainId,
|
|
82
|
-
error,
|
|
83
|
-
hash: transactionHash ?? undefined,
|
|
84
|
-
id,
|
|
85
|
-
isUserOperation: true,
|
|
86
|
-
networkClientId: 'user-operation',
|
|
87
|
-
origin,
|
|
88
|
-
status,
|
|
89
|
-
time,
|
|
90
|
-
txParams,
|
|
91
|
-
txReceipt: {
|
|
92
|
-
effectiveGasPrice: effectiveGasPrice ?? undefined,
|
|
93
|
-
gasUsed: actualGasUsed ?? undefined,
|
|
94
|
-
},
|
|
95
|
-
type: transactionType ?? undefined,
|
|
96
|
-
userFeeLevel: userFeeLevel,
|
|
97
|
-
...swaps,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
exports.getTransactionMetadata = getTransactionMetadata;
|
|
101
|
-
/**
|
|
102
|
-
* Adds the given hexadecimal values together.
|
|
103
|
-
*
|
|
104
|
-
* @param values - The hexadecimal values to add together.
|
|
105
|
-
* @returns The sum of the given hexadecimal values.
|
|
106
|
-
*/
|
|
107
|
-
function addHex(...values) {
|
|
108
|
-
const total = new bn_js_1.default(0);
|
|
109
|
-
for (const value of values) {
|
|
110
|
-
if (!value) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
total.iadd(new bn_js_1.default((0, utils_1.remove0x)(value), 16));
|
|
114
|
-
}
|
|
115
|
-
return (0, utils_1.add0x)(total.toString(16));
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=transaction.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,mDAA0D;AAC1D,2CAAkD;AAGlD;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,eAAe,EACf,EAAE,EACF,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,GAAG,QAAQ,CAAC;IAEb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oDAAoD;IACpD,MAAM,iBAAiB,GACrB,aAAa,IAAI,aAAa;QAC5B,CAAC,CAAC,IAAA,aAAK,EACH,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,EAAE,EAAE,CAAC;aAChC,GAAG,CAAC,IAAI,eAAE,CAAC,IAAA,gBAAQ,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IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,EAAE;QACF,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,gBAAgB;QACjC,MAAM;QACN,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS,EAAE;YACT,iBAAiB,EAAE,iBAAiB,IAAI,SAAS;YACjD,OAAO,EAAE,aAAa,IAAI,SAAS;SACpC;QACD,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,YAAY,EAAE,YAAsB;QACpC,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AA5HD,wDA4HC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAG,MAA8B;IAC/C,MAAM,KAAK,GAAG,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC;IAExB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAA,aAAK,EAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
|
-
import type { UserOperationMetadata } from "../types.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* Converts a user operation metadata object into a transaction metadata object.
|
|
5
|
-
*
|
|
6
|
-
* @param metadata - The user operation metadata object to convert.
|
|
7
|
-
* @returns The equivalent transaction metadata object.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getTransactionMetadata(metadata: UserOperationMetadata): TransactionMeta | undefined;
|
|
10
|
-
//# sourceMappingURL=transaction.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,yCAAyC;AAE1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,wBAAwB;AAClD,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAwB;AAC1D,OAAO,EAAE,mBAAmB,EAAE,qBAAoB;AAGlD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,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} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateSignUserOperationResponse = exports.validateUpdateUserOperationResponse = exports.validatePrepareUserOperationResponse = exports.validateAddUserOperationOptions = exports.validateAddUserOperationRequest = void 0;
|
|
4
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
-
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
6
|
-
const utils_1 = require("@metamask/utils");
|
|
7
|
-
const constants_js_1 = require("../constants.cjs");
|
|
8
|
-
/**
|
|
9
|
-
* Validate a request to add a user operation.
|
|
10
|
-
*
|
|
11
|
-
* @param request - The request to validate.
|
|
12
|
-
*/
|
|
13
|
-
function validateAddUserOperationRequest(request) {
|
|
14
|
-
const Hex = defineHex();
|
|
15
|
-
const HexOrEmptyBytes = defineHexOrEmptyBytes();
|
|
16
|
-
const ValidRequest = (0, superstruct_1.object)({
|
|
17
|
-
data: (0, superstruct_1.optional)(HexOrEmptyBytes),
|
|
18
|
-
from: Hex,
|
|
19
|
-
maxFeePerGas: (0, superstruct_1.optional)(Hex),
|
|
20
|
-
maxPriorityFeePerGas: (0, superstruct_1.optional)(Hex),
|
|
21
|
-
to: (0, superstruct_1.optional)(Hex),
|
|
22
|
-
value: (0, superstruct_1.optional)(Hex),
|
|
23
|
-
});
|
|
24
|
-
validate(request, ValidRequest, 'Invalid request to add user operation');
|
|
25
|
-
}
|
|
26
|
-
exports.validateAddUserOperationRequest = validateAddUserOperationRequest;
|
|
27
|
-
/**
|
|
28
|
-
* Validate the options when adding a user operation.
|
|
29
|
-
*
|
|
30
|
-
* @param options - The options to validate.
|
|
31
|
-
*/
|
|
32
|
-
function validateAddUserOperationOptions(options) {
|
|
33
|
-
const ValidOptions = (0, superstruct_1.object)({
|
|
34
|
-
networkClientId: (0, superstruct_1.string)(),
|
|
35
|
-
origin: (0, superstruct_1.string)(),
|
|
36
|
-
requireApproval: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
37
|
-
smartContractAccount: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
38
|
-
prepareUserOperation: (0, superstruct_1.func)(),
|
|
39
|
-
updateUserOperation: (0, superstruct_1.func)(),
|
|
40
|
-
signUserOperation: (0, superstruct_1.func)(),
|
|
41
|
-
})),
|
|
42
|
-
swaps: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
43
|
-
approvalTxId: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
44
|
-
destinationTokenAddress: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
45
|
-
destinationTokenDecimals: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
46
|
-
destinationTokenSymbol: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
47
|
-
estimatedBaseFee: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
48
|
-
sourceTokenSymbol: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
49
|
-
swapMetaData: (0, superstruct_1.optional)((0, superstruct_1.object)()),
|
|
50
|
-
swapTokenValue: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
51
|
-
destinationTokenAmount: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
52
|
-
sourceTokenAddress: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
53
|
-
sourceTokenAmount: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
54
|
-
sourceTokenDecimals: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
55
|
-
swapAndSendRecipient: (0, superstruct_1.optional)((0, superstruct_1.string)()),
|
|
56
|
-
})),
|
|
57
|
-
type: (0, superstruct_1.optional)((0, superstruct_1.enums)(Object.values(transaction_controller_1.TransactionType))),
|
|
58
|
-
});
|
|
59
|
-
validate(options, ValidOptions, 'Invalid options to add user operation');
|
|
60
|
-
}
|
|
61
|
-
exports.validateAddUserOperationOptions = validateAddUserOperationOptions;
|
|
62
|
-
/**
|
|
63
|
-
* Validate the response from a smart contract account when preparing the user operation.
|
|
64
|
-
*
|
|
65
|
-
* @param response - The response to validate.
|
|
66
|
-
*/
|
|
67
|
-
function validatePrepareUserOperationResponse(response) {
|
|
68
|
-
const Hex = defineHex();
|
|
69
|
-
const HexOrEmptyBytes = defineHexOrEmptyBytes();
|
|
70
|
-
const ValidResponse = (0, superstruct_1.refine)((0, superstruct_1.object)({
|
|
71
|
-
bundler: (0, superstruct_1.string)(),
|
|
72
|
-
callData: Hex,
|
|
73
|
-
dummyPaymasterAndData: (0, superstruct_1.optional)(HexOrEmptyBytes),
|
|
74
|
-
dummySignature: (0, superstruct_1.optional)(HexOrEmptyBytes),
|
|
75
|
-
gas: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
76
|
-
callGasLimit: Hex,
|
|
77
|
-
preVerificationGas: Hex,
|
|
78
|
-
verificationGasLimit: Hex,
|
|
79
|
-
})),
|
|
80
|
-
initCode: (0, superstruct_1.optional)(HexOrEmptyBytes),
|
|
81
|
-
nonce: Hex,
|
|
82
|
-
sender: Hex,
|
|
83
|
-
}), 'ValidPrepareUserOperationResponse', ({ gas, dummySignature }) => {
|
|
84
|
-
if (!gas && (!dummySignature || dummySignature === constants_js_1.EMPTY_BYTES)) {
|
|
85
|
-
return 'Must specify dummySignature if not specifying gas';
|
|
86
|
-
}
|
|
87
|
-
/* istanbul ignore next */
|
|
88
|
-
return true;
|
|
89
|
-
});
|
|
90
|
-
validate(response, ValidResponse, 'Invalid response when preparing user operation');
|
|
91
|
-
}
|
|
92
|
-
exports.validatePrepareUserOperationResponse = validatePrepareUserOperationResponse;
|
|
93
|
-
/**
|
|
94
|
-
* Validate the response from a smart contract account when updating the user operation.
|
|
95
|
-
*
|
|
96
|
-
* @param response - The response to validate.
|
|
97
|
-
*/
|
|
98
|
-
function validateUpdateUserOperationResponse(response) {
|
|
99
|
-
const ValidResponse = (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
100
|
-
paymasterAndData: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
|
|
101
|
-
callGasLimit: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
|
|
102
|
-
preVerificationGas: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
|
|
103
|
-
verificationGasLimit: (0, superstruct_1.optional)(defineHexOrEmptyBytes()),
|
|
104
|
-
}));
|
|
105
|
-
validate(response, ValidResponse, 'Invalid response when updating user operation');
|
|
106
|
-
}
|
|
107
|
-
exports.validateUpdateUserOperationResponse = validateUpdateUserOperationResponse;
|
|
108
|
-
/**
|
|
109
|
-
* Validate the response from a smart contract account when signing the user operation.
|
|
110
|
-
*
|
|
111
|
-
* @param response - The response to validate.
|
|
112
|
-
*/
|
|
113
|
-
function validateSignUserOperationResponse(response) {
|
|
114
|
-
const Hex = defineHex();
|
|
115
|
-
const ValidResponse = (0, superstruct_1.object)({
|
|
116
|
-
signature: Hex,
|
|
117
|
-
});
|
|
118
|
-
validate(response, ValidResponse, 'Invalid response when signing user operation');
|
|
119
|
-
}
|
|
120
|
-
exports.validateSignUserOperationResponse = validateSignUserOperationResponse;
|
|
121
|
-
/**
|
|
122
|
-
* Validate data against a struct.
|
|
123
|
-
*
|
|
124
|
-
* @param data - The data to validate.
|
|
125
|
-
* @param struct - The struct to validate against.
|
|
126
|
-
* @param message - The message to throw if validation fails.
|
|
127
|
-
*/
|
|
128
|
-
function validate(data, struct, message) {
|
|
129
|
-
try {
|
|
130
|
-
(0, superstruct_1.assert)(data, struct, message);
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
const causes = error
|
|
134
|
-
.failures()
|
|
135
|
-
.map((failure) => {
|
|
136
|
-
if (!failure.path.length) {
|
|
137
|
-
return failure.message;
|
|
138
|
-
}
|
|
139
|
-
return `${failure.path.join('.')} - ${failure.message}`;
|
|
140
|
-
})
|
|
141
|
-
.join('\n');
|
|
142
|
-
const finalMessage = `${message}\n${causes}`;
|
|
143
|
-
throw new Error(finalMessage);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Define the Hex type used by superstruct.
|
|
148
|
-
*
|
|
149
|
-
* @returns The Hex superstruct type.
|
|
150
|
-
*/
|
|
151
|
-
function defineHex() {
|
|
152
|
-
return (0, superstruct_1.define)('Hexadecimal String', (value) => (0, utils_1.isStrictHexString)(value));
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Define the HexOrEmptyBytes type used by superstruct.
|
|
156
|
-
*
|
|
157
|
-
* @returns The HexOrEmptyBytes superstruct type.
|
|
158
|
-
*/
|
|
159
|
-
function defineHexOrEmptyBytes() {
|
|
160
|
-
return (0, superstruct_1.define)('Hexadecimal String or 0x', (value) => (0, utils_1.isStrictHexString)(value) || value === constants_js_1.EMPTY_BYTES);
|
|
161
|
-
}
|
|
162
|
-
//# sourceMappingURL=validation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AACA,uDAW+B;AAC/B,6EAAmE;AACnE,2CAAoD;AAEpD,mDAA8C;AAW9C;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,MAAM,YAAY,GAAG,IAAA,oBAAM,EAAC;QAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,eAAe,CAAC;QAC/B,IAAI,EAAE,GAAG;QACT,YAAY,EAAE,IAAA,sBAAQ,EAAC,GAAG,CAAC;QA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AC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAI,KAAqB;aAClC,QAAQ,EAAE;aACV,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC;YACzB,CAAC;YAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS;IAChB,OAAO,IAAA,oBAAM,EAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,IAAA,yBAAiB,EAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB;IAC5B,OAAO,IAAA,oBAAM,EACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,IAAI,KAAK,KAAK,0BAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController.js';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAoB;AACrB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAsC;AAEvC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUserOperationResponse } from "../types.mjs";
|
|
2
|
-
import type { AddUserOperationOptions, AddUserOperationRequest } from "../UserOperationController.mjs";
|
|
3
|
-
/**
|
|
4
|
-
* Validate a request to add a user operation.
|
|
5
|
-
*
|
|
6
|
-
* @param request - The request to validate.
|
|
7
|
-
*/
|
|
8
|
-
export declare function validateAddUserOperationRequest(request: AddUserOperationRequest): void;
|
|
9
|
-
/**
|
|
10
|
-
* Validate the options when adding a user operation.
|
|
11
|
-
*
|
|
12
|
-
* @param options - The options to validate.
|
|
13
|
-
*/
|
|
14
|
-
export declare function validateAddUserOperationOptions(options: AddUserOperationOptions): void;
|
|
15
|
-
/**
|
|
16
|
-
* Validate the response from a smart contract account when preparing the user operation.
|
|
17
|
-
*
|
|
18
|
-
* @param response - The response to validate.
|
|
19
|
-
*/
|
|
20
|
-
export declare function validatePrepareUserOperationResponse(response: PrepareUserOperationResponse): void;
|
|
21
|
-
/**
|
|
22
|
-
* Validate the response from a smart contract account when updating the user operation.
|
|
23
|
-
*
|
|
24
|
-
* @param response - The response to validate.
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateUpdateUserOperationResponse(response: UpdateUserOperationResponse): void;
|
|
27
|
-
/**
|
|
28
|
-
* Validate the response from a smart contract account when signing the user operation.
|
|
29
|
-
*
|
|
30
|
-
* @param response - The response to validate.
|
|
31
|
-
*/
|
|
32
|
-
export declare function validateSignUserOperationResponse(response: SignUserOperationResponse): void;
|
|
33
|
-
//# sourceMappingURL=validation.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,qBAAoB;AACrB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,uCAAsC;AAEvC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"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AAE,OAAe;IACpE,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAI,KAAqB;aAClC,QAAQ,EAAE;aACV,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC;YACzB,CAAC;YAED,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,MAAM,YAAY,GAAG,GAAG,OAAO,KAAK,MAAM,EAAE,CAAC;QAE7C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS;IAChB,OAAO,MAAM,CAAS,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE,CACpD,iBAAiB,CAAC,KAAK,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB;IAC5B,OAAO,MAAM,CACX,0BAA0B,EAC1B,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,WAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController.js';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
|