@rhinestone/sdk 1.0.0-alpha.8 → 1.0.0-beta.38
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/dist/src/accounts/error.d.ts +38 -3
- package/dist/src/accounts/error.d.ts.map +1 -1
- package/dist/src/accounts/error.js +57 -7
- package/dist/src/accounts/index.d.ts +30 -15
- package/dist/src/accounts/index.d.ts.map +1 -1
- package/dist/src/accounts/index.js +304 -138
- package/dist/src/accounts/index.test.js +3 -5
- package/dist/src/accounts/json-rpc/index.d.ts +5 -0
- package/dist/src/accounts/json-rpc/index.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/index.js +16 -0
- package/dist/src/accounts/json-rpc/index.test.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/index.test.js +16 -0
- package/dist/src/accounts/json-rpc/providers.d.ts +4 -0
- package/dist/src/accounts/json-rpc/providers.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/providers.js +14 -0
- package/dist/src/accounts/json-rpc/providers.test.d.ts +2 -0
- package/dist/src/accounts/json-rpc/providers.test.d.ts.map +1 -0
- package/dist/src/accounts/json-rpc/providers.test.js +15 -0
- package/dist/src/accounts/kernel.d.ts +4 -3
- package/dist/src/accounts/kernel.d.ts.map +1 -1
- package/dist/src/accounts/kernel.js +32 -6
- package/dist/src/accounts/kernel.test.js +41 -19
- package/dist/src/accounts/nexus.d.ts +14 -7
- package/dist/src/accounts/nexus.d.ts.map +1 -1
- package/dist/src/accounts/nexus.js +191 -34
- package/dist/src/accounts/nexus.test.js +44 -18
- package/dist/src/accounts/safe.d.ts +2 -2
- package/dist/src/accounts/safe.d.ts.map +1 -1
- package/dist/src/accounts/safe.js +88 -58
- package/dist/src/accounts/safe.test.js +40 -14
- package/dist/src/accounts/signing/common.d.ts +27 -0
- package/dist/src/accounts/signing/common.d.ts.map +1 -0
- package/dist/src/accounts/signing/common.js +145 -0
- package/dist/src/accounts/signing/message.d.ts +5 -0
- package/dist/src/accounts/signing/message.d.ts.map +1 -0
- package/dist/src/accounts/signing/message.js +47 -0
- package/dist/src/accounts/signing/passkeys.d.ts +36 -0
- package/dist/src/accounts/signing/passkeys.d.ts.map +1 -0
- package/dist/src/accounts/signing/passkeys.js +125 -0
- package/dist/src/accounts/signing/passkeys.test.d.ts +2 -0
- package/dist/src/accounts/signing/passkeys.test.d.ts.map +1 -0
- package/dist/src/accounts/signing/passkeys.test.js +88 -0
- package/dist/src/accounts/signing/typedData.d.ts +5 -0
- package/dist/src/accounts/signing/typedData.d.ts.map +1 -0
- package/dist/src/accounts/signing/typedData.js +35 -0
- package/dist/src/accounts/startale.d.ts +20 -0
- package/dist/src/accounts/startale.d.ts.map +1 -0
- package/dist/src/accounts/startale.js +100 -0
- package/dist/src/accounts/startale.test.d.ts +2 -0
- package/dist/src/accounts/startale.test.d.ts.map +1 -0
- package/dist/src/accounts/startale.test.js +92 -0
- package/dist/src/accounts/utils.d.ts +4 -4
- package/dist/src/accounts/utils.d.ts.map +1 -1
- package/dist/src/accounts/utils.js +3 -40
- package/dist/src/accounts/walletClient.d.ts +7 -0
- package/dist/src/accounts/walletClient.d.ts.map +1 -0
- package/dist/src/accounts/walletClient.js +38 -0
- package/dist/src/actions/compact.d.ts +13 -0
- package/dist/src/actions/compact.d.ts.map +1 -0
- package/dist/src/actions/compact.js +210 -0
- package/dist/src/actions/ecdsa.d.ts +35 -0
- package/dist/src/actions/ecdsa.d.ts.map +1 -0
- package/dist/src/actions/ecdsa.js +114 -0
- package/dist/src/actions/ecdsa.test.d.ts +2 -0
- package/dist/src/actions/ecdsa.test.d.ts.map +1 -0
- package/dist/src/actions/ecdsa.test.js +99 -0
- package/dist/src/actions/index.d.ts +23 -38
- package/dist/src/actions/index.d.ts.map +1 -1
- package/dist/src/actions/index.js +29 -294
- package/dist/src/actions/mfa.d.ts +37 -0
- package/dist/src/actions/mfa.d.ts.map +1 -0
- package/dist/src/actions/mfa.js +133 -0
- package/dist/src/actions/passkeys.d.ts +37 -0
- package/dist/src/actions/passkeys.d.ts.map +1 -0
- package/dist/src/actions/passkeys.js +129 -0
- package/dist/src/actions/passkeys.test.d.ts +2 -0
- package/dist/src/actions/passkeys.test.d.ts.map +1 -0
- package/dist/src/actions/passkeys.test.js +54 -0
- package/dist/src/actions/recovery.d.ts +33 -0
- package/dist/src/actions/recovery.d.ts.map +1 -0
- package/dist/src/actions/recovery.js +193 -0
- package/dist/src/actions/recovery.test.d.ts +2 -0
- package/dist/src/actions/recovery.test.d.ts.map +1 -0
- package/dist/src/actions/recovery.test.js +168 -0
- package/dist/src/actions/smart-session.d.ts +6 -0
- package/dist/src/actions/smart-session.d.ts.map +1 -1
- package/dist/src/actions/smart-session.js +6 -0
- package/dist/src/errors/index.d.ts +5 -0
- package/dist/src/errors/index.d.ts.map +1 -0
- package/dist/src/errors/index.js +35 -0
- package/dist/src/execution/compact.d.ts +150 -7
- package/dist/src/execution/compact.d.ts.map +1 -1
- package/dist/src/execution/compact.js +112 -95
- package/dist/src/execution/error.d.ts +2 -9
- package/dist/src/execution/error.d.ts.map +1 -1
- package/dist/src/execution/error.js +4 -13
- package/dist/src/execution/index.d.ts +34 -22
- package/dist/src/execution/index.d.ts.map +1 -1
- package/dist/src/execution/index.js +62 -43
- package/dist/src/execution/permit2.d.ts +148 -0
- package/dist/src/execution/permit2.d.ts.map +1 -0
- package/dist/src/execution/permit2.js +282 -0
- package/dist/src/execution/smart-session.d.ts +3 -3
- package/dist/src/execution/smart-session.d.ts.map +1 -1
- package/dist/src/execution/types.d.ts +35 -0
- package/dist/src/execution/types.d.ts.map +1 -0
- package/dist/src/execution/types.js +2 -0
- package/dist/src/execution/utils.d.ts +36 -27
- package/dist/src/execution/utils.d.ts.map +1 -1
- package/dist/src/execution/utils.js +357 -103
- package/dist/src/index.d.ts +41 -22
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +199 -65
- package/dist/src/modules/common.d.ts +10 -4
- package/dist/src/modules/common.d.ts.map +1 -1
- package/dist/src/modules/common.js +22 -1
- package/dist/src/modules/index.d.ts +4 -18
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js +15 -63
- package/dist/src/modules/index.test.js +9 -26
- package/dist/src/modules/omni-account.d.ts +2 -1
- package/dist/src/modules/omni-account.d.ts.map +1 -1
- package/dist/src/modules/omni-account.js +3 -1
- package/dist/src/modules/read.d.ts.map +1 -1
- package/dist/src/modules/read.js +5 -0
- package/dist/src/modules/validators/core.d.ts +5 -3
- package/dist/src/modules/validators/core.d.ts.map +1 -1
- package/dist/src/modules/validators/core.js +64 -41
- package/dist/src/modules/validators/core.test.js +7 -7
- package/dist/src/modules/validators/smart-sessions.js +3 -3
- package/dist/src/modules/validators/smart-sessions.test.js +4 -7
- package/dist/src/orchestrator/client.d.ts +4 -4
- package/dist/src/orchestrator/client.d.ts.map +1 -1
- package/dist/src/orchestrator/client.js +30 -15
- package/dist/src/orchestrator/index.d.ts +2 -3
- package/dist/src/orchestrator/index.d.ts.map +1 -1
- package/dist/src/orchestrator/index.js +1 -3
- package/dist/src/orchestrator/registry.d.ts +1 -23
- package/dist/src/orchestrator/registry.d.ts.map +1 -1
- package/dist/src/orchestrator/registry.js +37 -33
- package/dist/src/orchestrator/registry.test.js +7 -7
- package/dist/src/orchestrator/types.d.ts +97 -29
- package/dist/src/orchestrator/types.d.ts.map +1 -1
- package/dist/src/orchestrator/utils.d.ts +1 -3
- package/dist/src/orchestrator/utils.d.ts.map +1 -1
- package/dist/src/orchestrator/utils.js +0 -102
- package/dist/src/types.d.ts +74 -10
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +72 -1
- package/dist/src/actions/index.test.d.ts.map +0 -1
- package/dist/src/actions/index.test.js +0 -302
- package/dist/src/orchestrator/registry.json +0 -365
- /package/dist/src/{actions → accounts/json-rpc}/index.test.d.ts +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInstallData = getInstallData;
|
|
4
4
|
exports.getAddress = getAddress;
|
|
5
|
-
exports.
|
|
5
|
+
exports.packSignature = packSignature;
|
|
6
6
|
exports.getDeployArgs = getDeployArgs;
|
|
7
7
|
exports.getSmartAccount = getSmartAccount;
|
|
8
8
|
exports.getSessionSmartAccount = getSessionSmartAccount;
|
|
@@ -11,78 +11,104 @@ const viem_1 = require("viem");
|
|
|
11
11
|
const account_abstraction_1 = require("viem/account-abstraction");
|
|
12
12
|
const modules_1 = require("../modules");
|
|
13
13
|
const validators_1 = require("../modules/validators");
|
|
14
|
+
const error_1 = require("./error");
|
|
14
15
|
const utils_1 = require("./utils");
|
|
15
16
|
const SAFE_7579_LAUNCHPAD_ADDRESS = '0x75798463024Bda64D83c94A64Bc7D7eaB41300eF';
|
|
16
17
|
const SAFE_7579_ADAPTER_ADDRESS = '0x7579f2AD53b01c3D8779Fe17928e0D48885B0003';
|
|
17
18
|
const SAFE_SINGLETON_ADDRESS = '0x29fcb43b46531bca003ddc8fcb67ffe91900c762';
|
|
18
19
|
const SAFE_PROXY_FACTORY_ADDRESS = '0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67';
|
|
19
20
|
const NO_SAFE_OWNER_ADDRESS = '0xbabe99e62d8bcbd3acf5ccbcfcd4f64fe75e5e72';
|
|
21
|
+
const SAFE_PROXY_INIT_CODE = '0x608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea264697066735822122003d1488ee65e08fa41e58e888a9865554c535f2c77126a82cb4c0f917f31441364736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564';
|
|
20
22
|
function getDeployArgs(config) {
|
|
21
|
-
{
|
|
22
|
-
const
|
|
23
|
-
const threshold = getThreshold(config);
|
|
24
|
-
const moduleSetup = (0, modules_1.getSetup)(config);
|
|
25
|
-
const modules = [
|
|
26
|
-
...moduleSetup.validators,
|
|
27
|
-
...moduleSetup.executors,
|
|
28
|
-
...moduleSetup.fallbacks,
|
|
29
|
-
...moduleSetup.hooks,
|
|
30
|
-
];
|
|
31
|
-
const initData = (0, viem_1.encodeFunctionData)({
|
|
32
|
-
abi: (0, viem_1.parseAbi)([
|
|
33
|
-
'function setup(address[] calldata _owners,uint256 _threshold,address to,bytes calldata data,address fallbackHandler,address paymentToken,uint256 payment, address paymentReceiver) external',
|
|
34
|
-
]),
|
|
35
|
-
functionName: 'setup',
|
|
36
|
-
args: [
|
|
37
|
-
owners,
|
|
38
|
-
threshold,
|
|
39
|
-
SAFE_7579_LAUNCHPAD_ADDRESS,
|
|
40
|
-
(0, viem_1.encodeFunctionData)({
|
|
41
|
-
abi: (0, viem_1.parseAbi)([
|
|
42
|
-
'struct ModuleInit {address module;bytes initData;uint256 moduleType}',
|
|
43
|
-
'function addSafe7579(address safe7579,ModuleInit[] calldata modules,address[] calldata attesters,uint8 threshold) external',
|
|
44
|
-
]),
|
|
45
|
-
functionName: 'addSafe7579',
|
|
46
|
-
args: [
|
|
47
|
-
SAFE_7579_ADAPTER_ADDRESS,
|
|
48
|
-
modules.map((m) => ({
|
|
49
|
-
module: m.address,
|
|
50
|
-
initData: m.initData,
|
|
51
|
-
moduleType: m.type,
|
|
52
|
-
})),
|
|
53
|
-
[],
|
|
54
|
-
0,
|
|
55
|
-
],
|
|
56
|
-
}),
|
|
57
|
-
SAFE_7579_ADAPTER_ADDRESS,
|
|
58
|
-
viem_1.zeroAddress,
|
|
59
|
-
BigInt(0),
|
|
60
|
-
viem_1.zeroAddress,
|
|
61
|
-
],
|
|
62
|
-
});
|
|
63
|
-
const saltNonce = 0n;
|
|
64
|
-
const factoryData = (0, viem_1.encodeFunctionData)({
|
|
23
|
+
if (config.initData) {
|
|
24
|
+
const factoryData = (0, viem_1.decodeFunctionData)({
|
|
65
25
|
abi: (0, viem_1.parseAbi)([
|
|
66
26
|
'function createProxyWithNonce(address singleton,bytes calldata initializer,uint256 saltNonce) external payable returns (address)',
|
|
67
27
|
]),
|
|
68
|
-
|
|
69
|
-
args: [SAFE_SINGLETON_ADDRESS, initData, saltNonce],
|
|
28
|
+
data: config.initData.factoryData,
|
|
70
29
|
});
|
|
30
|
+
if (factoryData.functionName !== 'createProxyWithNonce') {
|
|
31
|
+
throw new error_1.AccountConfigurationNotSupportedError('Invalid factory data', 'safe');
|
|
32
|
+
}
|
|
33
|
+
const implementation = factoryData.args[0];
|
|
34
|
+
const initData = factoryData.args[1];
|
|
35
|
+
const saltNonce = factoryData.args[2];
|
|
71
36
|
const salt = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes32', 'uint256'], [(0, viem_1.keccak256)(initData), saltNonce]));
|
|
72
37
|
return {
|
|
73
|
-
factory:
|
|
74
|
-
factoryData,
|
|
38
|
+
factory: config.initData.factory,
|
|
39
|
+
factoryData: config.initData.factoryData,
|
|
75
40
|
salt,
|
|
76
|
-
implementation
|
|
41
|
+
implementation,
|
|
77
42
|
initializationCallData: null,
|
|
78
43
|
};
|
|
79
44
|
}
|
|
45
|
+
const owners = getOwners(config);
|
|
46
|
+
const threshold = getThreshold(config);
|
|
47
|
+
const moduleSetup = (0, modules_1.getSetup)(config);
|
|
48
|
+
const modules = [
|
|
49
|
+
...moduleSetup.validators,
|
|
50
|
+
...moduleSetup.executors,
|
|
51
|
+
...moduleSetup.fallbacks,
|
|
52
|
+
...moduleSetup.hooks,
|
|
53
|
+
];
|
|
54
|
+
const initData = (0, viem_1.encodeFunctionData)({
|
|
55
|
+
abi: (0, viem_1.parseAbi)([
|
|
56
|
+
'function setup(address[] calldata _owners,uint256 _threshold,address to,bytes calldata data,address fallbackHandler,address paymentToken,uint256 payment, address paymentReceiver) external',
|
|
57
|
+
]),
|
|
58
|
+
functionName: 'setup',
|
|
59
|
+
args: [
|
|
60
|
+
owners,
|
|
61
|
+
threshold,
|
|
62
|
+
SAFE_7579_LAUNCHPAD_ADDRESS,
|
|
63
|
+
(0, viem_1.encodeFunctionData)({
|
|
64
|
+
abi: (0, viem_1.parseAbi)([
|
|
65
|
+
'struct ModuleInit {address module;bytes initData;uint256 moduleType}',
|
|
66
|
+
'function addSafe7579(address safe7579,ModuleInit[] calldata modules,address[] calldata attesters,uint8 threshold) external',
|
|
67
|
+
]),
|
|
68
|
+
functionName: 'addSafe7579',
|
|
69
|
+
args: [
|
|
70
|
+
SAFE_7579_ADAPTER_ADDRESS,
|
|
71
|
+
modules.map((m) => ({
|
|
72
|
+
module: m.address,
|
|
73
|
+
initData: m.initData,
|
|
74
|
+
moduleType: m.type,
|
|
75
|
+
})),
|
|
76
|
+
[],
|
|
77
|
+
0,
|
|
78
|
+
],
|
|
79
|
+
}),
|
|
80
|
+
SAFE_7579_ADAPTER_ADDRESS,
|
|
81
|
+
viem_1.zeroAddress,
|
|
82
|
+
BigInt(0),
|
|
83
|
+
viem_1.zeroAddress,
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
const saltNonce = 0n;
|
|
87
|
+
const factoryData = (0, viem_1.encodeFunctionData)({
|
|
88
|
+
abi: (0, viem_1.parseAbi)([
|
|
89
|
+
'function createProxyWithNonce(address singleton,bytes calldata initializer,uint256 saltNonce) external payable returns (address)',
|
|
90
|
+
]),
|
|
91
|
+
functionName: 'createProxyWithNonce',
|
|
92
|
+
args: [SAFE_SINGLETON_ADDRESS, initData, saltNonce],
|
|
93
|
+
});
|
|
94
|
+
const salt = (0, viem_1.keccak256)((0, viem_1.encodePacked)(['bytes32', 'uint256'], [(0, viem_1.keccak256)(initData), saltNonce]));
|
|
95
|
+
return {
|
|
96
|
+
factory: SAFE_PROXY_FACTORY_ADDRESS,
|
|
97
|
+
factoryData,
|
|
98
|
+
salt,
|
|
99
|
+
implementation: SAFE_SINGLETON_ADDRESS,
|
|
100
|
+
initializationCallData: null,
|
|
101
|
+
};
|
|
80
102
|
}
|
|
81
103
|
function getAddress(config) {
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
104
|
+
const { factory, implementation, salt } = getDeployArgs(config);
|
|
105
|
+
const constructorArgs = (0, viem_1.encodeAbiParameters)((0, viem_1.parseAbiParameters)('address singleton'), [implementation]);
|
|
106
|
+
const address = (0, viem_1.getContractAddress)({
|
|
107
|
+
opcode: 'CREATE2',
|
|
108
|
+
from: factory,
|
|
109
|
+
salt,
|
|
110
|
+
bytecode: (0, viem_1.concat)([SAFE_PROXY_INIT_CODE, constructorArgs]),
|
|
111
|
+
});
|
|
86
112
|
return address;
|
|
87
113
|
}
|
|
88
114
|
function getInstallData(module) {
|
|
@@ -113,10 +139,8 @@ function getInstallData(module) {
|
|
|
113
139
|
args: [module.type, module.address, module.initData],
|
|
114
140
|
});
|
|
115
141
|
}
|
|
116
|
-
async function
|
|
117
|
-
|
|
118
|
-
const packedSig = (0, viem_1.encodePacked)(['address', 'bytes'], [validator.address, transformSignature(signature)]);
|
|
119
|
-
return packedSig;
|
|
142
|
+
async function packSignature(signature, validator, transformSignature = (signature) => signature) {
|
|
143
|
+
return (0, viem_1.encodePacked)(['address', 'bytes'], [validator.address, transformSignature(signature)]);
|
|
120
144
|
}
|
|
121
145
|
async function getSmartAccount(client, address, owners, validatorAddress, sign) {
|
|
122
146
|
return getBaseSmartAccount(address, client, validatorAddress, async () => {
|
|
@@ -210,6 +234,9 @@ async function getBaseSmartAccount(address, client, validatorAddress, getStubSig
|
|
|
210
234
|
});
|
|
211
235
|
}
|
|
212
236
|
function getOwners(config) {
|
|
237
|
+
if (!config.owners) {
|
|
238
|
+
throw new error_1.OwnersFieldRequiredError();
|
|
239
|
+
}
|
|
213
240
|
const ownerSet = config.owners;
|
|
214
241
|
switch (ownerSet.type) {
|
|
215
242
|
case 'ecdsa':
|
|
@@ -221,6 +248,9 @@ function getOwners(config) {
|
|
|
221
248
|
}
|
|
222
249
|
}
|
|
223
250
|
function getThreshold(config) {
|
|
251
|
+
if (!config.owners) {
|
|
252
|
+
throw new error_1.OwnersFieldRequiredError();
|
|
253
|
+
}
|
|
224
254
|
const ownerSet = config.owners;
|
|
225
255
|
switch (ownerSet.type) {
|
|
226
256
|
case 'ecdsa':
|
|
@@ -13,11 +13,10 @@ const MOCK_MODULE_ADDRESS = '0x28de6501fa86f2e6cd0b33c3aabdaeb4a1b93f3f';
|
|
|
13
13
|
type: 'ecdsa',
|
|
14
14
|
accounts: [consts_1.accountA, consts_1.accountB],
|
|
15
15
|
},
|
|
16
|
-
rhinestoneApiKey: consts_1.MOCK_API_KEY,
|
|
17
16
|
});
|
|
18
17
|
(0, vitest_1.expect)(factory).toEqual('0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67');
|
|
19
|
-
(0, vitest_1.expect)(factoryData).toEqual('
|
|
20
|
-
(0, vitest_1.expect)(salt).toEqual('
|
|
18
|
+
(0, vitest_1.expect)(factoryData).toEqual('0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000444b63e800d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000075798463024bda64d83c94a64bc7d7eab41300ef00000000000000000000000000000000000000000000000000000000000001600000000000000000000000007579f2ad53b01c3d8779fe17928e0d48885b00030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000f6c02c78ded62973b43bfa523b247da0994869360000000000000000000000006092086a3dc0020cd604a68fcf5d430007d51bb700000000000000000000000000000000000000000000000000000000000002a447cbbdca0000000000000000000000007579f2ad53b01c3d8779fe17928e0d48885b0003000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000013fdb5234e4e3162a810f54d9f7e980000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000020000000000000000000000006092086a3dc0020cd604a68fcf5d430007d51bb7000000000000000000000000f6c02c78ded62973b43bfa523b247da09948693600000000000000000000000000000000005ad9ce1f5035fd62ca96cef16adaaf00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
|
|
19
|
+
(0, vitest_1.expect)(salt).toEqual('0xf31933c8d3ab801f5d7dbfd374464b228d509d625a72334e218cbe08be7716e6');
|
|
21
20
|
(0, vitest_1.expect)(implementation).toEqual('0x29fcb43b46531bca003ddc8fcb67ffe91900c762');
|
|
22
21
|
(0, vitest_1.expect)(initializationCallData).toEqual(null);
|
|
23
22
|
});
|
|
@@ -25,16 +24,31 @@ const MOCK_MODULE_ADDRESS = '0x28de6501fa86f2e6cd0b33c3aabdaeb4a1b93f3f';
|
|
|
25
24
|
const { factory, factoryData, salt, implementation, initializationCallData, } = (0, safe_1.getDeployArgs)({
|
|
26
25
|
owners: {
|
|
27
26
|
type: 'passkey',
|
|
28
|
-
|
|
27
|
+
accounts: [consts_1.passkeyAccount],
|
|
29
28
|
},
|
|
30
|
-
rhinestoneApiKey: consts_1.MOCK_API_KEY,
|
|
31
29
|
});
|
|
32
30
|
(0, vitest_1.expect)(factory).toEqual('0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67');
|
|
33
|
-
(0, vitest_1.expect)(factoryData).toEqual('
|
|
34
|
-
(0, vitest_1.expect)(salt).toEqual('
|
|
31
|
+
(0, vitest_1.expect)(factoryData).toEqual('0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000444b63e800d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000075798463024bda64d83c94a64bc7d7eab41300ef00000000000000000000000000000000000000000000000000000000000001400000000000000000000000007579f2ad53b01c3d8779fe17928e0d48885b00030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000babe99e62d8bcbd3acf5ccbcfcd4f64fe75e5e7200000000000000000000000000000000000000000000000000000000000002c447cbbdca0000000000000000000000007579f2ad53b01c3d8779fe17928e0d48885b0003000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000578c4cb0e472a5462da43c495c3f330000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001580a9af0569ad3905b26a703201b358aa0904236642ebe79b22a19d00d3737637d46f725a5427ae45a9569259bf67e1e16b187d7b3ad1ed70138c4f0409677d1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005ad9ce1f5035fd62ca96cef16adaaf00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
|
|
32
|
+
(0, vitest_1.expect)(salt).toEqual('0xdc83fad4a7d91e2ee81a5adc74eb2bca07d012c5259cb8ea10e89cf05de74c8d');
|
|
35
33
|
(0, vitest_1.expect)(implementation).toEqual('0x29fcb43b46531bca003ddc8fcb67ffe91900c762');
|
|
36
34
|
(0, vitest_1.expect)(initializationCallData).toEqual(null);
|
|
37
35
|
});
|
|
36
|
+
(0, vitest_1.test)('Existing account', () => {
|
|
37
|
+
const { factory, factoryData } = (0, safe_1.getDeployArgs)({
|
|
38
|
+
owners: {
|
|
39
|
+
type: 'ecdsa',
|
|
40
|
+
accounts: [consts_1.accountA, consts_1.accountB],
|
|
41
|
+
},
|
|
42
|
+
initData: {
|
|
43
|
+
factory: '0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67',
|
|
44
|
+
factoryData: '0x1688f0b90000000000000000000000007579011ab74c46090561ea277ba79d510c6c00ff0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000844fff40e1ec88f0966a6bc17a138345cdf7519caf9a1e0bb840330108a6a4315f1028c39000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
45
|
+
address: '0xc41bb9cfB2658dD3D74Ada0862044f5f30304b38',
|
|
46
|
+
intentExecutorInstalled: true,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.expect)(factory).toEqual('0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67');
|
|
50
|
+
(0, vitest_1.expect)(factoryData).toEqual('0x1688f0b90000000000000000000000007579011ab74c46090561ea277ba79d510c6c00ff0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000844fff40e1ec88f0966a6bc17a138345cdf7519caf9a1e0bb840330108a6a4315f1028c39000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000');
|
|
51
|
+
});
|
|
38
52
|
});
|
|
39
53
|
(0, vitest_1.describe)('Get Address', () => {
|
|
40
54
|
(0, vitest_1.test)('ECDSA owners', () => {
|
|
@@ -43,19 +57,32 @@ const MOCK_MODULE_ADDRESS = '0x28de6501fa86f2e6cd0b33c3aabdaeb4a1b93f3f';
|
|
|
43
57
|
type: 'ecdsa',
|
|
44
58
|
accounts: [consts_1.accountA, consts_1.accountB],
|
|
45
59
|
},
|
|
46
|
-
rhinestoneApiKey: consts_1.MOCK_API_KEY,
|
|
47
60
|
});
|
|
48
|
-
(0, vitest_1.expect)(address).toEqual('
|
|
61
|
+
(0, vitest_1.expect)(address).toEqual('0x3a249204D37245504d4aB37FF88f574B222a6349');
|
|
49
62
|
});
|
|
50
63
|
(0, vitest_1.test)('Passkey owner', () => {
|
|
51
64
|
const address = (0, safe_1.getAddress)({
|
|
52
65
|
owners: {
|
|
53
66
|
type: 'passkey',
|
|
54
|
-
|
|
67
|
+
accounts: [consts_1.passkeyAccount],
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.expect)(address).toEqual('0xE86e416045645E1Ca4360D5DC396E4c513277C31');
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.test)('Existing account', () => {
|
|
73
|
+
const address = (0, safe_1.getAddress)({
|
|
74
|
+
owners: {
|
|
75
|
+
type: 'ecdsa',
|
|
76
|
+
accounts: [consts_1.accountA, consts_1.accountB],
|
|
77
|
+
},
|
|
78
|
+
initData: {
|
|
79
|
+
factory: '0x4e1dcf7ad4e460cfd30791ccc4f9c8a4f820ec67',
|
|
80
|
+
factoryData: '0x1688f0b90000000000000000000000007579011ab74c46090561ea277ba79d510c6c00ff0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000844fff40e1ec88f0966a6bc17a138345cdf7519caf9a1e0bb840330108a6a4315f1028c39000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
81
|
+
address: '0xc41bb9cfB2658dD3D74Ada0862044f5f30304b38',
|
|
82
|
+
intentExecutorInstalled: true,
|
|
55
83
|
},
|
|
56
|
-
rhinestoneApiKey: consts_1.MOCK_API_KEY,
|
|
57
84
|
});
|
|
58
|
-
(0, vitest_1.expect)(address).toEqual('
|
|
85
|
+
(0, vitest_1.expect)(address).toEqual('0xc41bb9cfB2658dD3D74Ada0862044f5f30304b38');
|
|
59
86
|
});
|
|
60
87
|
});
|
|
61
88
|
(0, vitest_1.describe)('Get Install Data', () => {
|
|
@@ -72,13 +99,12 @@ const MOCK_MODULE_ADDRESS = '0x28de6501fa86f2e6cd0b33c3aabdaeb4a1b93f3f';
|
|
|
72
99
|
});
|
|
73
100
|
(0, vitest_1.describe)('Get Packed Signature', () => {
|
|
74
101
|
(0, vitest_1.test)('Mock signature', async () => {
|
|
75
|
-
const hash = '0xabcd';
|
|
76
102
|
const mockSignature = '0x1234';
|
|
77
103
|
const validator = {
|
|
78
104
|
address: '0xe35b75e5ec3c04e9cefa8e581fbee859f56edeb4',
|
|
79
105
|
isRoot: true,
|
|
80
106
|
};
|
|
81
|
-
const signature = await (0, safe_1.
|
|
107
|
+
const signature = await (0, safe_1.packSignature)(mockSignature, validator);
|
|
82
108
|
(0, vitest_1.expect)(signature).toEqual('0xe35b75e5ec3c04e9cefa8e581fbee859f56edeb41234');
|
|
83
109
|
});
|
|
84
110
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WebAuthnP256 } from 'ox';
|
|
2
|
+
import { type Account, type Address, type Chain, type Hex } from 'viem';
|
|
3
|
+
import type { WebAuthnAccount } from 'viem/account-abstraction';
|
|
4
|
+
import type { OwnerSet, SignerSet } from '../../types';
|
|
5
|
+
declare function convertOwnerSetToSignerSet(owners: OwnerSet): SignerSet;
|
|
6
|
+
type SigningFunctions<T> = {
|
|
7
|
+
signEcdsa: (account: Account, params: T, updateV: boolean) => Promise<Hex>;
|
|
8
|
+
signPasskey: (account: WebAuthnAccount, params: T) => Promise<{
|
|
9
|
+
webauthn: WebAuthnP256.SignMetadata;
|
|
10
|
+
signature: Hex;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
declare function signWithMultiFactorAuth<T>(signers: SignerSet & {
|
|
14
|
+
type: 'owner';
|
|
15
|
+
kind: 'multi-factor';
|
|
16
|
+
}, chain: Chain, address: Address, params: T, isUserOpHash: boolean, signMain: (signers: SignerSet, chain: Chain, address: Address, params: T, isUserOpHash: boolean) => Promise<Hex>): Promise<Hex>;
|
|
17
|
+
declare function signWithSession<T>(signers: SignerSet & {
|
|
18
|
+
type: 'session';
|
|
19
|
+
}, chain: Chain, address: Address, params: T, isUserOpHash: boolean, signMain: (signers: SignerSet, chain: Chain, address: Address, params: T, isUserOpHash: boolean) => Promise<Hex>): Promise<Hex>;
|
|
20
|
+
declare function signWithGuardians<T>(signers: SignerSet & {
|
|
21
|
+
type: 'guardians';
|
|
22
|
+
}, params: T, signingFunctions: SigningFunctions<T>): Promise<Hex>;
|
|
23
|
+
declare function signWithOwners<T>(signers: SignerSet & {
|
|
24
|
+
type: 'owner';
|
|
25
|
+
}, chain: Chain, address: Address, params: T, signingFunctions: SigningFunctions<T>, isUserOpHash: boolean, signMain: (signers: SignerSet, chain: Chain, address: Address, params: T, isUserOpHash: boolean) => Promise<Hex>): Promise<Hex>;
|
|
26
|
+
export { convertOwnerSetToSignerSet, signWithMultiFactorAuth, signWithSession, signWithGuardians, signWithOwners, type SigningFunctions, };
|
|
27
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../accounts/signing/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AACtC,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EAGV,KAAK,GAAG,EAGT,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAO/D,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAStD,iBAAS,0BAA0B,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CA6C/D;AAED,KAAK,gBAAgB,CAAC,CAAC,IAAI;IACzB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1E,WAAW,EAAE,CACX,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,CAAC,KACN,OAAO,CAAC;QACX,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAA;QACnC,SAAS,EAAE,GAAG,CAAA;KACf,CAAC,CAAA;CACH,CAAA;AAED,iBAAe,uBAAuB,CAAC,CAAC,EACtC,OAAO,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,EAC5D,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,CACR,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,GAAG,CAAC,GAChB,OAAO,CAAC,GAAG,CAAC,CA0Cd;AAED,iBAAe,eAAe,CAAC,CAAC,EAC9B,OAAO,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,EACxC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,CACR,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,GAAG,CAAC,GAChB,OAAO,CAAC,GAAG,CAAC,CAKd;AAED,iBAAe,iBAAiB,CAAC,CAAC,EAChC,OAAO,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,EAC1C,MAAM,EAAE,CAAC,EACT,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,GAAG,CAAC,CAOd;AAED,iBAAe,cAAc,CAAC,CAAC,EAC7B,OAAO,EAAE,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,EACtC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACrC,YAAY,EAAE,OAAO,EACrB,QAAQ,EAAE,CACR,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,CAAC,EACT,YAAY,EAAE,OAAO,KAClB,OAAO,CAAC,GAAG,CAAC,GAChB,OAAO,CAAC,GAAG,CAAC,CA0Dd;AAED,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,KAAK,gBAAgB,GACtB,CAAA"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertOwnerSetToSignerSet = convertOwnerSetToSignerSet;
|
|
4
|
+
exports.signWithMultiFactorAuth = signWithMultiFactorAuth;
|
|
5
|
+
exports.signWithSession = signWithSession;
|
|
6
|
+
exports.signWithGuardians = signWithGuardians;
|
|
7
|
+
exports.signWithOwners = signWithOwners;
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
const modules_1 = require("../../modules");
|
|
10
|
+
const core_1 = require("../../modules/validators/core");
|
|
11
|
+
const passkeys_1 = require("./passkeys");
|
|
12
|
+
function convertOwnerSetToSignerSet(owners) {
|
|
13
|
+
switch (owners.type) {
|
|
14
|
+
case 'ecdsa': {
|
|
15
|
+
return {
|
|
16
|
+
type: 'owner',
|
|
17
|
+
kind: 'ecdsa',
|
|
18
|
+
accounts: owners.accounts,
|
|
19
|
+
module: owners.module,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
case 'passkey': {
|
|
23
|
+
return {
|
|
24
|
+
type: 'owner',
|
|
25
|
+
kind: 'passkey',
|
|
26
|
+
accounts: owners.accounts,
|
|
27
|
+
module: owners.module,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'multi-factor': {
|
|
31
|
+
return {
|
|
32
|
+
type: 'owner',
|
|
33
|
+
kind: 'multi-factor',
|
|
34
|
+
validators: owners.validators.map((validator, index) => {
|
|
35
|
+
switch (validator.type) {
|
|
36
|
+
case 'ecdsa': {
|
|
37
|
+
return {
|
|
38
|
+
type: validator.type,
|
|
39
|
+
id: index,
|
|
40
|
+
accounts: validator.accounts,
|
|
41
|
+
module: validator.module,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
case 'passkey': {
|
|
45
|
+
return {
|
|
46
|
+
type: 'passkey',
|
|
47
|
+
id: index,
|
|
48
|
+
accounts: validator.accounts,
|
|
49
|
+
module: validator.module,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function signWithMultiFactorAuth(signers, chain, address, params, isUserOpHash, signMain) {
|
|
59
|
+
const signatures = await Promise.all(signers.validators.map(async (validator) => {
|
|
60
|
+
if (validator === null) {
|
|
61
|
+
return '0x';
|
|
62
|
+
}
|
|
63
|
+
const validatorSigners = convertOwnerSetToSignerSet(validator);
|
|
64
|
+
return signMain(validatorSigners, chain, address, params, isUserOpHash);
|
|
65
|
+
}));
|
|
66
|
+
const data = (0, viem_1.encodeAbiParameters)([
|
|
67
|
+
{
|
|
68
|
+
components: [
|
|
69
|
+
{
|
|
70
|
+
internalType: 'bytes32',
|
|
71
|
+
name: 'packedValidatorAndId',
|
|
72
|
+
type: 'bytes32',
|
|
73
|
+
},
|
|
74
|
+
{ internalType: 'bytes', name: 'data', type: 'bytes' },
|
|
75
|
+
],
|
|
76
|
+
name: 'validators',
|
|
77
|
+
type: 'tuple[]',
|
|
78
|
+
},
|
|
79
|
+
], [
|
|
80
|
+
signers.validators.map((validator, index) => {
|
|
81
|
+
const validatorModule = (0, core_1.getValidator)(validator);
|
|
82
|
+
return {
|
|
83
|
+
packedValidatorAndId: (0, viem_1.concat)([
|
|
84
|
+
(0, viem_1.pad)((0, viem_1.toHex)(validator.id), {
|
|
85
|
+
size: 12,
|
|
86
|
+
}),
|
|
87
|
+
validatorModule.address,
|
|
88
|
+
]),
|
|
89
|
+
data: signatures[index],
|
|
90
|
+
};
|
|
91
|
+
}),
|
|
92
|
+
]);
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
async function signWithSession(signers, chain, address, params, isUserOpHash, signMain) {
|
|
96
|
+
const sessionSigners = convertOwnerSetToSignerSet(signers.session.owners);
|
|
97
|
+
return signMain(sessionSigners, chain, address, params, isUserOpHash);
|
|
98
|
+
}
|
|
99
|
+
async function signWithGuardians(signers, params, signingFunctions) {
|
|
100
|
+
const signatures = await Promise.all(signers.guardians.map((account) => signingFunctions.signEcdsa(account, params, false)));
|
|
101
|
+
return (0, viem_1.concat)(signatures);
|
|
102
|
+
}
|
|
103
|
+
async function signWithOwners(signers, chain, address, params, signingFunctions, isUserOpHash, signMain) {
|
|
104
|
+
switch (signers.kind) {
|
|
105
|
+
case 'ecdsa': {
|
|
106
|
+
// Ownable validator uses `v` value to determine which validation mode to use
|
|
107
|
+
// This is not needed for UserOps
|
|
108
|
+
const updateV = (!signers.module ||
|
|
109
|
+
signers.module?.toLowerCase() === core_1.OWNABLE_VALIDATOR_ADDRESS) &&
|
|
110
|
+
!isUserOpHash;
|
|
111
|
+
const signatures = await Promise.all(signers.accounts.map((account) => signingFunctions.signEcdsa(account, params, updateV)));
|
|
112
|
+
return (0, viem_1.concat)(signatures);
|
|
113
|
+
}
|
|
114
|
+
case 'passkey': {
|
|
115
|
+
const signatures = await Promise.all(signers.accounts.map((account) => signingFunctions.signPasskey(account, params)));
|
|
116
|
+
const usePrecompile = (0, modules_1.isRip7212SupportedNetwork)(chain);
|
|
117
|
+
const credIds = signers.accounts.map((account) => {
|
|
118
|
+
const publicKey = account.publicKey;
|
|
119
|
+
const { x, y } = (0, passkeys_1.parsePublicKey)(publicKey);
|
|
120
|
+
return (0, passkeys_1.generateCredentialId)(x, y, address);
|
|
121
|
+
});
|
|
122
|
+
const webAuthns = signatures.map((signature) => {
|
|
123
|
+
const { r, s } = (0, passkeys_1.parseSignature)(signature.signature);
|
|
124
|
+
return {
|
|
125
|
+
authenticatorData: signature.webauthn.authenticatorData,
|
|
126
|
+
clientDataJSON: signature.webauthn.clientDataJSON,
|
|
127
|
+
challengeIndex: BigInt(signature.webauthn.challengeIndex),
|
|
128
|
+
typeIndex: BigInt(signature.webauthn.typeIndex),
|
|
129
|
+
r,
|
|
130
|
+
s,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
if (signers.module?.toLowerCase() === core_1.WEBAUTHN_V0_VALIDATOR_ADDRESS) {
|
|
134
|
+
return (0, passkeys_1.packSignatureV0)(webAuthns[0], usePrecompile);
|
|
135
|
+
}
|
|
136
|
+
return (0, passkeys_1.packSignature)(credIds, usePrecompile, webAuthns);
|
|
137
|
+
}
|
|
138
|
+
case 'multi-factor': {
|
|
139
|
+
return signWithMultiFactorAuth(signers, chain, address, params, isUserOpHash, signMain);
|
|
140
|
+
}
|
|
141
|
+
default: {
|
|
142
|
+
throw new Error('Unsupported owner kind');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Address, type Chain, type Hex } from 'viem';
|
|
2
|
+
import type { SignerSet } from '../../types';
|
|
3
|
+
declare function sign(signers: SignerSet, chain: Chain, address: Address, hash: Hex, isUserOpHash: boolean): Promise<Hex>;
|
|
4
|
+
export { sign };
|
|
5
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../../accounts/signing/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,GAAG,EAGT,MAAM,MAAM,CAAA;AAEb,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAS5C,iBAAe,IAAI,CACjB,OAAO,EAAE,SAAS,EAClB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,GAAG,EACT,YAAY,EAAE,OAAO,GACpB,OAAO,CAAC,GAAG,CAAC,CAyBd;AA4BD,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sign = sign;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
async function sign(signers, chain, address, hash, isUserOpHash) {
|
|
8
|
+
const signingFunctions = {
|
|
9
|
+
signEcdsa: (account, hash, updateV) => signEcdsa(account, hash, updateV),
|
|
10
|
+
signPasskey: (account, hash) => signPasskey(account, hash),
|
|
11
|
+
};
|
|
12
|
+
switch (signers.type) {
|
|
13
|
+
case 'owner': {
|
|
14
|
+
return (0, common_1.signWithOwners)(signers, chain, address, hash, signingFunctions, isUserOpHash, sign);
|
|
15
|
+
}
|
|
16
|
+
case 'session': {
|
|
17
|
+
return (0, common_1.signWithSession)(signers, chain, address, hash, isUserOpHash, sign);
|
|
18
|
+
}
|
|
19
|
+
case 'guardians': {
|
|
20
|
+
return (0, common_1.signWithGuardians)(signers, hash, signingFunctions);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function signEcdsa(account, hash, updateV) {
|
|
25
|
+
if (!account.signMessage) {
|
|
26
|
+
throw new error_1.SigningNotSupportedForAccountError();
|
|
27
|
+
}
|
|
28
|
+
const originalSignature = await account.signMessage({
|
|
29
|
+
message: { raw: hash },
|
|
30
|
+
});
|
|
31
|
+
// Manually tweak the `v` value to trigger the message prefixing onchain
|
|
32
|
+
// https://github.com/rhinestonewtf/checknsignatures/blob/main/src/CheckNSignatures.sol#L53-L61
|
|
33
|
+
const { r, s, v } = (0, viem_1.parseSignature)(originalSignature);
|
|
34
|
+
if (!v) {
|
|
35
|
+
throw new Error('Invalid signature');
|
|
36
|
+
}
|
|
37
|
+
const newV = updateV ? v + 4n : v;
|
|
38
|
+
const newSignature = (0, viem_1.concat)([r, s, (0, viem_1.toHex)(newV)]);
|
|
39
|
+
return newSignature;
|
|
40
|
+
}
|
|
41
|
+
async function signPasskey(account, hash) {
|
|
42
|
+
const { webauthn, signature } = await account.sign({ hash });
|
|
43
|
+
return {
|
|
44
|
+
webauthn,
|
|
45
|
+
signature,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Address, type Hex } from 'viem';
|
|
2
|
+
interface WebAuthnSignature {
|
|
3
|
+
authenticatorData: Hex;
|
|
4
|
+
clientDataJSON: string;
|
|
5
|
+
challengeIndex: bigint;
|
|
6
|
+
typeIndex: bigint;
|
|
7
|
+
r: bigint;
|
|
8
|
+
s: bigint;
|
|
9
|
+
}
|
|
10
|
+
declare function parsePublicKey(publicKey: Hex | Uint8Array): {
|
|
11
|
+
x: bigint;
|
|
12
|
+
y: bigint;
|
|
13
|
+
};
|
|
14
|
+
declare function parseSignature(signature: Hex | Uint8Array): {
|
|
15
|
+
r: bigint;
|
|
16
|
+
s: bigint;
|
|
17
|
+
};
|
|
18
|
+
declare function generateCredentialId(pubKeyX: bigint, pubKeyY: bigint, account: Address): `0x${string}`;
|
|
19
|
+
declare function packSignature(credIds: Hex[], usePrecompile: boolean, webAuthns: {
|
|
20
|
+
authenticatorData: Hex;
|
|
21
|
+
clientDataJSON: string;
|
|
22
|
+
challengeIndex: bigint;
|
|
23
|
+
typeIndex: bigint;
|
|
24
|
+
r: bigint;
|
|
25
|
+
s: bigint;
|
|
26
|
+
}[]): Hex;
|
|
27
|
+
declare function packSignatureV0(webauthn: {
|
|
28
|
+
authenticatorData: Hex;
|
|
29
|
+
clientDataJSON: string;
|
|
30
|
+
typeIndex: number | bigint;
|
|
31
|
+
r: bigint;
|
|
32
|
+
s: bigint;
|
|
33
|
+
}, usePrecompiled: boolean): `0x${string}`;
|
|
34
|
+
export { parsePublicKey, parseSignature, generateCredentialId, packSignature, packSignatureV0, };
|
|
35
|
+
export type { WebAuthnSignature };
|
|
36
|
+
//# sourceMappingURL=passkeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"passkeys.d.ts","sourceRoot":"","sources":["../../../../accounts/signing/passkeys.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,GAAG,EAGT,MAAM,MAAM,CAAA;AAEb,UAAU,iBAAiB;IACzB,iBAAiB,EAAE,GAAG,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,iBAAS,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,UAAU,GAAG;IACpD,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,CAUA;AAED,iBAAS,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,UAAU,GAAG;IACpD,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,CASA;AAED,iBAAS,oBAAoB,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,iBAkBjB;AAED,iBAAS,aAAa,CACpB,OAAO,EAAE,GAAG,EAAE,EACd,aAAa,EAAE,OAAO,EACtB,SAAS,EAAE;IACT,iBAAiB,EAAE,GAAG,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,EAAE,GACF,GAAG,CAqDL;AAED,iBAAS,eAAe,CACtB,QAAQ,EAAE;IACR,iBAAiB,EAAE,GAAG,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,EACD,cAAc,EAAE,OAAO,iBAqCxB;AAED,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,eAAe,GAChB,CAAA;AACD,YAAY,EAAE,iBAAiB,EAAE,CAAA"}
|