@lit-protocol/vincent-ability-sdk 2.3.4 → 2.4.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 +26 -0
- package/README.md +49 -1
- package/dist/CHANGELOG.md +6 -0
- package/dist/README.md +49 -1
- package/dist/package.json +7 -1
- package/dist/src/gatedSigner.d.ts +2 -0
- package/dist/src/gatedSigner.d.ts.map +1 -0
- package/dist/src/gatedSigner.js +5 -0
- package/dist/src/gatedSigner.js.map +1 -0
- package/dist/src/lib/abilityHelpers/gasSponsorship/get-alchemy-chain-config.js +1 -1
- package/dist/src/lib/abilityHelpers/gasSponsorship/get-alchemy-chain-config.js.map +1 -1
- package/dist/src/lib/gatedSigner/helpers/eip712.d.ts +34 -0
- package/dist/src/lib/gatedSigner/helpers/eip712.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/eip712.js +30 -0
- package/dist/src/lib/gatedSigner/helpers/eip712.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/hex.d.ts +5 -0
- package/dist/src/lib/gatedSigner/helpers/hex.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/hex.js +16 -0
- package/dist/src/lib/gatedSigner/helpers/hex.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/lifecycleFunctions.d.ts +56 -0
- package/dist/src/lib/gatedSigner/helpers/lifecycleFunctions.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/lifecycleFunctions.js +91 -0
- package/dist/src/lib/gatedSigner/helpers/lifecycleFunctions.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/lowLevelCall.d.ts +13 -0
- package/dist/src/lib/gatedSigner/helpers/lowLevelCall.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/lowLevelCall.js +21 -0
- package/dist/src/lib/gatedSigner/helpers/lowLevelCall.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/schemas.d.ts +925 -0
- package/dist/src/lib/gatedSigner/helpers/schemas.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/schemas.js +64 -0
- package/dist/src/lib/gatedSigner/helpers/schemas.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/signTransaction.d.ts +9 -0
- package/dist/src/lib/gatedSigner/helpers/signTransaction.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/signTransaction.js +30 -0
- package/dist/src/lib/gatedSigner/helpers/signTransaction.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/signUserOperation.d.ts +15 -0
- package/dist/src/lib/gatedSigner/helpers/signUserOperation.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/signUserOperation.js +115 -0
- package/dist/src/lib/gatedSigner/helpers/signUserOperation.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/simulation.d.ts +204 -0
- package/dist/src/lib/gatedSigner/helpers/simulation.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/simulation.js +93 -0
- package/dist/src/lib/gatedSigner/helpers/simulation.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/kernel.d.ts +8 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/kernel.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/kernel.js +177 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/kernel.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/safe.d.ts +26 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/safe.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/safe.js +195 -0
- package/dist/src/lib/gatedSigner/helpers/smartAccounts/safe.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/toLitActionAccount.d.ts +20 -0
- package/dist/src/lib/gatedSigner/helpers/toLitActionAccount.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/toLitActionAccount.js +69 -0
- package/dist/src/lib/gatedSigner/helpers/toLitActionAccount.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/transaction.d.ts +148 -0
- package/dist/src/lib/gatedSigner/helpers/transaction.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/transaction.js +87 -0
- package/dist/src/lib/gatedSigner/helpers/transaction.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/userOperation.d.ts +200 -0
- package/dist/src/lib/gatedSigner/helpers/userOperation.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/userOperation.js +106 -0
- package/dist/src/lib/gatedSigner/helpers/userOperation.js.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/validation.d.ts +43 -0
- package/dist/src/lib/gatedSigner/helpers/validation.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/helpers/validation.js +81 -0
- package/dist/src/lib/gatedSigner/helpers/validation.js.map +1 -0
- package/dist/src/lib/gatedSigner/index.d.ts +12 -0
- package/dist/src/lib/gatedSigner/index.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/index.js +19 -0
- package/dist/src/lib/gatedSigner/index.js.map +1 -0
- package/dist/src/lib/gatedSigner/vincentGatedSignerAbility.d.ts +566 -0
- package/dist/src/lib/gatedSigner/vincentGatedSignerAbility.d.ts.map +1 -0
- package/dist/src/lib/gatedSigner/vincentGatedSignerAbility.js +48 -0
- package/dist/src/lib/gatedSigner/vincentGatedSignerAbility.js.map +1 -0
- package/dist/src/type-inference-verification/ability-definition-tests.d.ts +6 -6
- package/dist/src/type-inference-verification/allow-deny-test-cases-ability.d.ts +90 -90
- package/dist/src/type-inference-verification/allow-deny-test-cases.d.ts +8 -8
- package/dist/src/type-inference-verification/context-switching-tests.d.ts +3 -3
- package/dist/src/type-inference-verification/create-vincent-gated-signer-ability.d.ts +533 -0
- package/dist/src/type-inference-verification/create-vincent-gated-signer-ability.d.ts.map +1 -0
- package/dist/src/type-inference-verification/create-vincent-gated-signer-ability.js +19 -0
- package/dist/src/type-inference-verification/create-vincent-gated-signer-ability.js.map +1 -0
- package/dist/src/type-inference-verification/parameter-inference-tests-tool.d.ts +58 -58
- package/dist/src/type-inference-verification/parameter-inference-tests.d.ts +5 -5
- package/dist/src/type-inference-verification/playground.d.ts +8 -8
- package/dist/src/type-inference-verification/schema-test.d.ts +5 -5
- package/package.json +8 -2
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryDecodeKernelCalldataToLowLevelCalls = tryDecodeKernelCalldataToLowLevelCalls;
|
|
4
|
+
exports.formatSecondaryValidatorKernelSignature = formatSecondaryValidatorKernelSignature;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const kernelAccountsAbi = [
|
|
7
|
+
// Kernel v3.3/v3.1/v3.0
|
|
8
|
+
{
|
|
9
|
+
type: 'function',
|
|
10
|
+
name: 'execute',
|
|
11
|
+
inputs: [
|
|
12
|
+
{ name: 'execMode', type: 'bytes32', internalType: 'ExecMode' },
|
|
13
|
+
{ name: 'executionCalldata', type: 'bytes', internalType: 'bytes' },
|
|
14
|
+
],
|
|
15
|
+
outputs: [],
|
|
16
|
+
stateMutability: 'payable',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
type: 'function',
|
|
20
|
+
name: 'executeFromExecutor',
|
|
21
|
+
inputs: [
|
|
22
|
+
{ name: 'execMode', type: 'bytes32', internalType: 'ExecMode' },
|
|
23
|
+
{ name: 'executionCalldata', type: 'bytes', internalType: 'bytes' },
|
|
24
|
+
],
|
|
25
|
+
outputs: [{ name: 'returnData', type: 'bytes[]', internalType: 'bytes[]' }],
|
|
26
|
+
stateMutability: 'payable',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'function',
|
|
30
|
+
name: 'executeUserOp',
|
|
31
|
+
inputs: [
|
|
32
|
+
{
|
|
33
|
+
name: 'userOp',
|
|
34
|
+
type: 'tuple',
|
|
35
|
+
internalType: 'struct PackedUserOperation',
|
|
36
|
+
components: [
|
|
37
|
+
{
|
|
38
|
+
name: 'sender',
|
|
39
|
+
type: 'address',
|
|
40
|
+
internalType: 'address',
|
|
41
|
+
},
|
|
42
|
+
{ name: 'nonce', type: 'uint256', internalType: 'uint256' },
|
|
43
|
+
{ name: 'initCode', type: 'bytes', internalType: 'bytes' },
|
|
44
|
+
{ name: 'callData', type: 'bytes', internalType: 'bytes' },
|
|
45
|
+
{
|
|
46
|
+
name: 'accountGasLimits',
|
|
47
|
+
type: 'bytes32',
|
|
48
|
+
internalType: 'bytes32',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'preVerificationGas',
|
|
52
|
+
type: 'uint256',
|
|
53
|
+
internalType: 'uint256',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'gasFees',
|
|
57
|
+
type: 'bytes32',
|
|
58
|
+
internalType: 'bytes32',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'paymasterAndData',
|
|
62
|
+
type: 'bytes',
|
|
63
|
+
internalType: 'bytes',
|
|
64
|
+
},
|
|
65
|
+
{ name: 'signature', type: 'bytes', internalType: 'bytes' },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{ name: 'userOpHash', type: 'bytes32', internalType: 'bytes32' },
|
|
69
|
+
],
|
|
70
|
+
outputs: [],
|
|
71
|
+
stateMutability: 'payable',
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
function tryDecodeKernelExecuteBatchCall(df) {
|
|
75
|
+
try {
|
|
76
|
+
// https://github.com/zerodevapp/sdk/blob/main/packages/core/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.ts
|
|
77
|
+
const [tuples] = (0, viem_1.decodeAbiParameters)([
|
|
78
|
+
{
|
|
79
|
+
name: 'executionBatch',
|
|
80
|
+
type: 'tuple[]',
|
|
81
|
+
components: [
|
|
82
|
+
{
|
|
83
|
+
name: 'target',
|
|
84
|
+
type: 'address',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'value',
|
|
88
|
+
type: 'uint256',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'callData',
|
|
92
|
+
type: 'bytes',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
], df.args[1]);
|
|
97
|
+
if (!tuples.length)
|
|
98
|
+
return null;
|
|
99
|
+
return tuples.map((t) => ({
|
|
100
|
+
to: (0, viem_1.getAddress)(t.target),
|
|
101
|
+
value: t.value,
|
|
102
|
+
data: t.callData,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error('tryDecodeKernelExecuteBatchCall', e);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function tryDecodeKernelExecuteCall(df) {
|
|
111
|
+
// https://github.com/zerodevapp/sdk/blob/main/packages/core/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.ts
|
|
112
|
+
// Because Execute with a single call is just a hex concatenation of the calldata,
|
|
113
|
+
// this function might produce invalid decoding. It MUST be called last, only if
|
|
114
|
+
// all other, stricter, decodings failed or if we know the calldata is a single call.
|
|
115
|
+
// Also, the current implementation does not support delegate calls. It will produce
|
|
116
|
+
// an invalid decoding for them.
|
|
117
|
+
try {
|
|
118
|
+
const data = df.args[1];
|
|
119
|
+
const hex = data.slice(2);
|
|
120
|
+
const MIN = 20 * 2 + 32 * 2; // address + value
|
|
121
|
+
if (hex.length < MIN)
|
|
122
|
+
return null;
|
|
123
|
+
const to = (0, viem_1.getAddress)((0, viem_1.sliceHex)(data, 0, 20));
|
|
124
|
+
const value = (0, viem_1.hexToBigInt)((0, viem_1.sliceHex)(data, 20, 52));
|
|
125
|
+
const calldata = (0, viem_1.sliceHex)(data, 52);
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
data: calldata,
|
|
129
|
+
to,
|
|
130
|
+
value,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
console.error('tryDecodeKernelExecuteCall', e);
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function isDelegatecallOrUnknown(execMode) {
|
|
140
|
+
const lastByte = BigInt(execMode) & 0xffn;
|
|
141
|
+
return lastByte !== 0n; // 0x00 == CALL; others => block
|
|
142
|
+
}
|
|
143
|
+
function tryDecodeKernelCalldataToLowLevelCalls(callData) {
|
|
144
|
+
let df;
|
|
145
|
+
try {
|
|
146
|
+
df = (0, viem_1.decodeFunctionData)({ abi: kernelAccountsAbi, data: callData });
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
console.log('Calldata is not a known Kernel calldata. Continuing...');
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
console.log('Decoded calldata for Kernel smart account.');
|
|
153
|
+
if (!['execute', 'executeFromExecutor'].includes(df.functionName)) {
|
|
154
|
+
console.log('Not a known Kernel execute/executor call');
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const [execMode] = df.args;
|
|
158
|
+
// BLOCK delegatecall/unknown modes up-front
|
|
159
|
+
if (isDelegatecallOrUnknown(execMode)) {
|
|
160
|
+
throw new Error(`Blocked by execMode (non-CALL): ${execMode}`);
|
|
161
|
+
}
|
|
162
|
+
// Try common inner shapes
|
|
163
|
+
const shapes = [
|
|
164
|
+
tryDecodeKernelExecuteBatchCall,
|
|
165
|
+
tryDecodeKernelExecuteCall,
|
|
166
|
+
];
|
|
167
|
+
for (const dec of shapes) {
|
|
168
|
+
const res = dec(df);
|
|
169
|
+
if (res)
|
|
170
|
+
return res;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
function formatSecondaryValidatorKernelSignature(params) {
|
|
175
|
+
return (0, viem_1.concat)([params.secondValidatorId, params.signature]);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=kernel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernel.js","sourceRoot":"","sources":["../../../../../../src/lib/gatedSigner/helpers/smartAccounts/kernel.ts"],"names":[],"mappings":";;AA8JA,wFAkCC;AAED,0FAKC;AArMD,+BAOc;AAOd,MAAM,iBAAiB,GAAQ;IAC7B,wBAAwB;IACxB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,SAAS;QACf,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE;YAC/D,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE;SACpE;QACD,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,SAAS;KAC3B;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE;YAC/D,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE;SACpE;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC;QAC3E,eAAe,EAAE,SAAS;KAC3B;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,OAAO;gBACb,YAAY,EAAE,4BAA4B;gBAC1C,UAAU,EAAE;oBACV;wBACE,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,SAAS;wBACf,YAAY,EAAE,SAAS;qBACxB;oBACD,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE;oBAC3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,EAAE,CAAC,CAAC;QACpB,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC;IACtB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,uCAAuC,CAAC,MAGvD;IACC,OAAO,IAAA,aAAM,EAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
import type { Eip712Params } from '../eip712';
|
|
3
|
+
import type { LowLevelCall } from '../lowLevelCall';
|
|
4
|
+
interface InternalTransaction {
|
|
5
|
+
operation: number;
|
|
6
|
+
to: Address;
|
|
7
|
+
value: bigint;
|
|
8
|
+
data: Hex;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Decodes a stream of packed internal transactions.
|
|
12
|
+
* Opposite of encodeInternalTransaction.
|
|
13
|
+
* https://github.com/pimlicolabs/permissionless.js/blob/main/packages/permissionless/accounts/safe/toSafeSmartAccount.ts#L566
|
|
14
|
+
* * Format:
|
|
15
|
+
* [operation (1b)][to (20b)][value (32b)][dataLength (32b)][data (variable)]
|
|
16
|
+
*/
|
|
17
|
+
export declare function decodeInternalTransactions(data: Hex | string): InternalTransaction[];
|
|
18
|
+
export declare function tryDecodeSafeCalldataToLowLevelCalls(callData: Hex): LowLevelCall[] | null;
|
|
19
|
+
export declare const safeEip712Params: Eip712Params;
|
|
20
|
+
export declare function formatSafeSignature(params: {
|
|
21
|
+
validAfter: number;
|
|
22
|
+
validUntil: number;
|
|
23
|
+
signature: Hex;
|
|
24
|
+
}): Hex;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=safe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/gatedSigner/helpers/smartAccounts/safe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAY9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzE,UAAU,mBAAmB;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;CACX;AAgDD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,mBAAmB,EAAE,CA8CpF;AAkCD,wBAAgB,oCAAoC,CAAC,QAAQ,EAAE,GAAG,GAAG,YAAY,EAAE,GAAG,IAAI,CAyBzF;AAED,eAAO,MAAM,gBAAgB,EAAE,YAsC9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,GAAG,CAAC;CAChB,GAAG,GAAG,CAMN"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeEip712Params = void 0;
|
|
4
|
+
exports.decodeInternalTransactions = decodeInternalTransactions;
|
|
5
|
+
exports.tryDecodeSafeCalldataToLowLevelCalls = tryDecodeSafeCalldataToLowLevelCalls;
|
|
6
|
+
exports.formatSafeSignature = formatSafeSignature;
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const safeAccountsAbi = [
|
|
9
|
+
{
|
|
10
|
+
inputs: [
|
|
11
|
+
{ name: 'to', internalType: 'address', type: 'address' },
|
|
12
|
+
{ name: 'value', internalType: 'uint256', type: 'uint256' },
|
|
13
|
+
{ name: 'data', internalType: 'bytes', type: 'bytes' },
|
|
14
|
+
{ name: 'operation', internalType: 'uint8', type: 'uint8' },
|
|
15
|
+
],
|
|
16
|
+
name: 'executeUserOp',
|
|
17
|
+
outputs: [],
|
|
18
|
+
stateMutability: 'nonpayable',
|
|
19
|
+
type: 'function',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: 'function',
|
|
23
|
+
name: 'executeUserOpWithErrorString',
|
|
24
|
+
inputs: [
|
|
25
|
+
{ name: 'to', internalType: 'address', type: 'address' },
|
|
26
|
+
{ name: 'value', internalType: 'uint256', type: 'uint256' },
|
|
27
|
+
{ name: 'data', internalType: 'bytes', type: 'bytes' },
|
|
28
|
+
{ name: 'operation', internalType: 'uint8', type: 'uint8' },
|
|
29
|
+
],
|
|
30
|
+
outputs: [],
|
|
31
|
+
stateMutability: 'nonpayable',
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
const multiSendAbi = [
|
|
35
|
+
{
|
|
36
|
+
inputs: [
|
|
37
|
+
{
|
|
38
|
+
internalType: 'bytes',
|
|
39
|
+
name: 'transactions',
|
|
40
|
+
type: 'bytes',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
name: 'multiSend',
|
|
44
|
+
outputs: [],
|
|
45
|
+
stateMutability: 'payable',
|
|
46
|
+
type: 'function',
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Decodes a stream of packed internal transactions.
|
|
51
|
+
* Opposite of encodeInternalTransaction.
|
|
52
|
+
* https://github.com/pimlicolabs/permissionless.js/blob/main/packages/permissionless/accounts/safe/toSafeSmartAccount.ts#L566
|
|
53
|
+
* * Format:
|
|
54
|
+
* [operation (1b)][to (20b)][value (32b)][dataLength (32b)][data (variable)]
|
|
55
|
+
*/
|
|
56
|
+
function decodeInternalTransactions(data) {
|
|
57
|
+
// Ensure data is a valid Hex string with 0x prefix for viem utils
|
|
58
|
+
const hex = data.startsWith('0x') ? data : `0x${data}`;
|
|
59
|
+
// If empty, return empty array
|
|
60
|
+
if (hex === '0x' || hex.length === 0)
|
|
61
|
+
return [];
|
|
62
|
+
const txs = [];
|
|
63
|
+
let cursor = 0;
|
|
64
|
+
const totalBytes = (hex.length - 2) / 2; // Calculate byte length from hex string
|
|
65
|
+
while (cursor < totalBytes) {
|
|
66
|
+
// 1. Decode Operation (uint8 = 1 byte)
|
|
67
|
+
const opBytes = (0, viem_1.slice)(hex, cursor, cursor + 1);
|
|
68
|
+
const operation = (0, viem_1.hexToNumber)(opBytes);
|
|
69
|
+
cursor += 1;
|
|
70
|
+
// 2. Decode To Address (address = 20 bytes)
|
|
71
|
+
const toBytes = (0, viem_1.slice)(hex, cursor, cursor + 20);
|
|
72
|
+
const to = (0, viem_1.getAddress)(toBytes); // Checksums the address
|
|
73
|
+
cursor += 20;
|
|
74
|
+
// 3. Decode Value (uint256 = 32 bytes)
|
|
75
|
+
const valueBytes = (0, viem_1.slice)(hex, cursor, cursor + 32);
|
|
76
|
+
const value = (0, viem_1.hexToBigInt)(valueBytes);
|
|
77
|
+
cursor += 32;
|
|
78
|
+
// 4. Decode Data Length (uint256 = 32 bytes)
|
|
79
|
+
const lengthBytes = (0, viem_1.slice)(hex, cursor, cursor + 32);
|
|
80
|
+
const dataLength = (0, viem_1.hexToNumber)(lengthBytes);
|
|
81
|
+
cursor += 32;
|
|
82
|
+
// 5. Decode Data (bytes = dynamic length)
|
|
83
|
+
// Note: encodePacked simply appends the bytes, no padding
|
|
84
|
+
const dataBytes = (0, viem_1.slice)(hex, cursor, cursor + dataLength);
|
|
85
|
+
cursor += dataLength;
|
|
86
|
+
txs.push({
|
|
87
|
+
operation,
|
|
88
|
+
to,
|
|
89
|
+
value,
|
|
90
|
+
data: dataBytes,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return txs;
|
|
94
|
+
}
|
|
95
|
+
function tryDecodeSafeMultiSendCalldata(df) {
|
|
96
|
+
try {
|
|
97
|
+
const { args } = (0, viem_1.decodeFunctionData)({
|
|
98
|
+
data: df.args[2],
|
|
99
|
+
abi: multiSendAbi,
|
|
100
|
+
});
|
|
101
|
+
const [internalTxs] = (args || ['0x']);
|
|
102
|
+
const decodedInternalTxs = decodeInternalTransactions(internalTxs);
|
|
103
|
+
return decodedInternalTxs.map((t) => ({ data: t.data, to: t.to, value: t.value }));
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error('tryDecodeSafeMultiSendCalldata', e);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function tryDecodeSafeSendCalldata(df) {
|
|
111
|
+
try {
|
|
112
|
+
const lowLevelCall = {
|
|
113
|
+
data: df.args[2],
|
|
114
|
+
to: df.args[0],
|
|
115
|
+
value: df.args[1],
|
|
116
|
+
};
|
|
117
|
+
return [lowLevelCall];
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
console.error('tryDecodeSafeSendCalldata', e);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function tryDecodeSafeCalldataToLowLevelCalls(callData) {
|
|
125
|
+
let df;
|
|
126
|
+
try {
|
|
127
|
+
df = (0, viem_1.decodeFunctionData)({ abi: safeAccountsAbi, data: callData });
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
console.log('Calldata is not a known Safe calldata. Continuing...');
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
console.log('Decoded calldata for Safe smart account.');
|
|
134
|
+
if (!['executeUserOp', 'executeUserOpWithErrorString'].includes(df.functionName)) {
|
|
135
|
+
console.log('Not a known Safe execute/executor call');
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const safeShapes = [
|
|
139
|
+
tryDecodeSafeMultiSendCalldata,
|
|
140
|
+
tryDecodeSafeSendCalldata,
|
|
141
|
+
];
|
|
142
|
+
for (const dec of safeShapes) {
|
|
143
|
+
const res = dec(df);
|
|
144
|
+
if (res)
|
|
145
|
+
return res;
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
exports.safeEip712Params = {
|
|
150
|
+
domain: {
|
|
151
|
+
chainId: '$chainId',
|
|
152
|
+
verifyingContract: '$safe4337ModuleAddress',
|
|
153
|
+
},
|
|
154
|
+
types: {
|
|
155
|
+
SafeOp: [
|
|
156
|
+
{ type: 'address', name: 'safe' },
|
|
157
|
+
{ type: 'uint256', name: 'nonce' },
|
|
158
|
+
{ type: 'bytes', name: 'initCode' },
|
|
159
|
+
{ type: 'bytes', name: 'callData' },
|
|
160
|
+
{ type: 'uint128', name: 'verificationGasLimit' },
|
|
161
|
+
{ type: 'uint128', name: 'callGasLimit' },
|
|
162
|
+
{ type: 'uint256', name: 'preVerificationGas' },
|
|
163
|
+
{ type: 'uint128', name: 'maxPriorityFeePerGas' },
|
|
164
|
+
{ type: 'uint128', name: 'maxFeePerGas' },
|
|
165
|
+
{ type: 'bytes', name: 'paymasterAndData' },
|
|
166
|
+
{ type: 'uint48', name: 'validAfter' },
|
|
167
|
+
{ type: 'uint48', name: 'validUntil' },
|
|
168
|
+
{ type: 'address', name: 'entryPoint' },
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
primaryType: 'SafeOp',
|
|
172
|
+
message: {
|
|
173
|
+
safe: '$userOp.sender',
|
|
174
|
+
nonce: '$userOp.nonce',
|
|
175
|
+
initCode: '$userOp.initCode',
|
|
176
|
+
callData: '$userOp.callData',
|
|
177
|
+
callGasLimit: '$userOp.callGasLimit',
|
|
178
|
+
verificationGasLimit: '$userOp.verificationGasLimit',
|
|
179
|
+
preVerificationGas: '$userOp.preVerificationGas',
|
|
180
|
+
maxFeePerGas: '$userOp.maxFeePerGas',
|
|
181
|
+
maxPriorityFeePerGas: '$userOp.maxPriorityFeePerGas',
|
|
182
|
+
paymasterAndData: '$userOp.paymasterAndData',
|
|
183
|
+
validAfter: '$validAfter',
|
|
184
|
+
validUntil: '$validUntil',
|
|
185
|
+
entryPoint: '$entryPointAddress',
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
function formatSafeSignature(params) {
|
|
189
|
+
return (0, viem_1.concat)([
|
|
190
|
+
(0, viem_1.toHex)(params.validAfter, { size: 6 }),
|
|
191
|
+
(0, viem_1.toHex)(params.validUntil, { size: 6 }),
|
|
192
|
+
params.signature,
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=safe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe.js","sourceRoot":"","sources":["../../../../../../src/lib/gatedSigner/helpers/smartAccounts/safe.ts"],"names":[],"mappings":";;;AA2EA,gEA8CC;AAkCD,oFAyBC;AA0CD,kDAUC;AAtOD,+BAQc;AAed,MAAM,eAAe,GAAQ;IAC3B;QACE,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACxD,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;YACtD,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;SAC5D;QACD,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,EAAE;QACX,eAAe,EAAE,YAAY;QAC7B,IAAI,EAAE,UAAU;KACjB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,8BAA8B;QACpC,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACxD,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE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YAAY,EAAE;SACxC;KACF;IACD,WAAW,EAAE,QAAQ;IACrB,OAAO,EAAE;QACP,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,eAAe;QACtB,QAAQ,EAAE,kBAAkB;QAC5B,QAAQ,EAAE,kBAAkB;QAC5B,YAAY,EAAE,sBAAsB;QACpC,oBAAoB,EAAE,8BAA8B;QACpD,kBAAkB,EAAE,4BAA4B;QAChD,YAAY,EAAE,sBAAsB;QACpC,oBAAoB,EAAE,8BAA8B;QACpD,gBAAgB,EAAE,0BAA0B;QAC5C,UAAU,EAAE,aAAa;QACzB,UAAU,EAAE,aAAa;QACzB,UAAU,EAAE,oBAAoB;KACjC;CACF,CAAC;AAEF,SAAgB,mBAAmB,CAAC,MAInC;IACC,OAAO,IAAA,aAAM,EAAC;QACZ,IAAA,YAAK,EAAC,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACrC,IAAA,YAAK,EAAC,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACrC,MAAM,CAAC,SAAS;KACjB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Hex, SignableMessage, TransactionSerializable } from 'viem';
|
|
2
|
+
export declare function toLitActionAccount(pkpPublicKey: Hex): {
|
|
3
|
+
address: import("viem").Address;
|
|
4
|
+
nonceManager?: import("viem").NonceManager | undefined;
|
|
5
|
+
sign?: ((parameters: {
|
|
6
|
+
hash: import("viem").Hash;
|
|
7
|
+
}) => Promise<Hex>) | undefined | undefined;
|
|
8
|
+
signAuthorization?: ((parameters: import("viem").AuthorizationRequest) => Promise<import("viem/accounts").SignAuthorizationReturnType>) | undefined | undefined;
|
|
9
|
+
signMessage: ({ message }: {
|
|
10
|
+
message: SignableMessage;
|
|
11
|
+
}) => Promise<Hex>;
|
|
12
|
+
signTransaction: <serializer extends import("viem").SerializeTransactionFn<TransactionSerializable> = import("viem").SerializeTransactionFn<TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
|
|
13
|
+
serializer?: serializer | undefined;
|
|
14
|
+
} | undefined) => Promise<Hex>;
|
|
15
|
+
signTypedData: <const typedData extends import("viem").TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: import("viem").TypedDataDefinition<typedData, primaryType>) => Promise<Hex>;
|
|
16
|
+
publicKey: Hex;
|
|
17
|
+
source: string;
|
|
18
|
+
type: "local";
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=toLitActionAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toLitActionAccount.d.ts","sourceRoot":"","sources":["../../../../../src/lib/gatedSigner/helpers/toLitActionAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,MAAM,CAAC;AA6B1E,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,GAAG;;;;;;;;;;sRAwB9C,CAAF;kBAAsB,CAAC;;;;;;EA+C1B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toLitActionAccount = toLitActionAccount;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const accounts_1 = require("viem/accounts");
|
|
6
|
+
const utils_1 = require("viem/utils");
|
|
7
|
+
function toLitActionAccount(pkpPublicKey) {
|
|
8
|
+
const pkpEthAddress = (0, utils_1.publicKeyToAddress)(pkpPublicKey);
|
|
9
|
+
const pkpPublicKeyForLit = pkpPublicKey.replace('0x', '');
|
|
10
|
+
return (0, accounts_1.toAccount)({
|
|
11
|
+
address: pkpEthAddress,
|
|
12
|
+
async signMessage({ message }) {
|
|
13
|
+
const hashedMessage = (0, viem_1.hashMessage)(message);
|
|
14
|
+
const signature = await Lit.Actions.signAndCombineEcdsa({
|
|
15
|
+
toSign: (0, viem_1.hexToBytes)(hashedMessage),
|
|
16
|
+
publicKey: pkpPublicKeyForLit,
|
|
17
|
+
sigName: 'signMessage',
|
|
18
|
+
});
|
|
19
|
+
const structuredSignature = JSON.parse(signature);
|
|
20
|
+
return (0, viem_1.serializeSignature)({
|
|
21
|
+
r: `0x${structuredSignature.r.substring(2)}`,
|
|
22
|
+
s: `0x${structuredSignature.s}`,
|
|
23
|
+
yParity: structuredSignature.v,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async signTransaction(transaction, { serializer } = {}) {
|
|
27
|
+
const signableTransaction = {
|
|
28
|
+
...transaction,
|
|
29
|
+
chainId: transaction.chainId ? Number(transaction.chainId) : undefined,
|
|
30
|
+
};
|
|
31
|
+
const serializerToUse = serializer || viem_1.serializeTransaction;
|
|
32
|
+
const serializedTx = (await serializerToUse(signableTransaction));
|
|
33
|
+
const txHash = (0, viem_1.keccak256)(serializedTx);
|
|
34
|
+
const toSign = (0, viem_1.hexToBytes)(txHash);
|
|
35
|
+
const signature = await Lit.Actions.signAndCombineEcdsa({
|
|
36
|
+
toSign,
|
|
37
|
+
publicKey: pkpPublicKeyForLit,
|
|
38
|
+
sigName: 'signTransaction',
|
|
39
|
+
});
|
|
40
|
+
const structuredSignature = JSON.parse(signature);
|
|
41
|
+
return serializerToUse(signableTransaction, {
|
|
42
|
+
r: `0x${structuredSignature.r.substring(2)}`,
|
|
43
|
+
s: `0x${structuredSignature.s}`,
|
|
44
|
+
yParity: structuredSignature.v,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async signTypedData(typedData) {
|
|
48
|
+
const { domain, types, primaryType, message } = typedData;
|
|
49
|
+
const hashedTypedData = (0, viem_1.hashTypedData)({
|
|
50
|
+
domain,
|
|
51
|
+
types,
|
|
52
|
+
primaryType,
|
|
53
|
+
message,
|
|
54
|
+
});
|
|
55
|
+
const signature = await Lit.Actions.signAndCombineEcdsa({
|
|
56
|
+
toSign: (0, viem_1.hexToBytes)(hashedTypedData),
|
|
57
|
+
publicKey: pkpPublicKeyForLit,
|
|
58
|
+
sigName: 'signTypedData',
|
|
59
|
+
});
|
|
60
|
+
const structuredSignature = JSON.parse(signature);
|
|
61
|
+
return (0, viem_1.serializeSignature)({
|
|
62
|
+
r: `0x${structuredSignature.r.substring(2)}`,
|
|
63
|
+
s: `0x${structuredSignature.s}`,
|
|
64
|
+
yParity: structuredSignature.v,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=toLitActionAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toLitActionAccount.js","sourceRoot":"","sources":["../../../../../src/lib/gatedSigner/helpers/toLitActionAccount.ts"],"names":[],"mappings":";;AA6BA,gDAuEC;AAlGD,+BAOc;AACd,4CAA0C;AAC1C,sCAAgD;AAkBhD,SAAgB,kBAAkB,CAAC,YAAiB;IAClD,MAAM,aAAa,GAAG,IAAA,0BAAkB,EAAC,YAAY,CAAC,CAAC;IACvD,MAAM,kBAAkB,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAE1D,OAAO,IAAA,oBAAS,EAAC;QACf,OAAO,EAAE,aAAa;QAEtB,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAgC;YACzD,MAAM,aAAa,GAAG,IAAA,kBAAW,EAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC;gBACtD,MAAM,EAAE,IAAA,iBAAU,EAAC,aAAa,CAAC;gBACjC,SAAS,EAAE,kBAAkB;gBAC7B,OAAO,EAAE,aAAa;aACvB,CAAC,CAAC;YACH,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAuB,CAAC;YAExE,OAAO,IAAA,yBAAkB,EAAC;gB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