@safe-global/relay-kit 3.0.0 → 3.0.2
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/README.md +2 -2
- package/dist/src/packs/safe-4337/Safe4337Pack.d.ts +11 -5
- package/dist/src/packs/safe-4337/Safe4337Pack.js +104 -85
- package/dist/src/packs/safe-4337/Safe4337Pack.js.map +1 -1
- package/dist/src/packs/safe-4337/Safe4337Pack.test.js +83 -25
- package/dist/src/packs/safe-4337/Safe4337Pack.test.js.map +1 -1
- package/dist/src/packs/safe-4337/SafeOperation.d.ts +3 -1
- package/dist/src/packs/safe-4337/SafeOperation.js +2 -1
- package/dist/src/packs/safe-4337/SafeOperation.js.map +1 -1
- package/dist/src/packs/safe-4337/SafeOperation.test.js +5 -0
- package/dist/src/packs/safe-4337/SafeOperation.test.js.map +1 -1
- package/dist/src/packs/safe-4337/constants.d.ts +2 -0
- package/dist/src/packs/safe-4337/constants.js +3 -1
- package/dist/src/packs/safe-4337/constants.js.map +1 -1
- package/dist/src/packs/safe-4337/testing-utils/fixtures.d.ts +36 -0
- package/dist/src/packs/safe-4337/testing-utils/fixtures.js +41 -5
- package/dist/src/packs/safe-4337/testing-utils/fixtures.js.map +1 -1
- package/dist/src/packs/safe-4337/testing-utils/helpers.js +6 -1
- package/dist/src/packs/safe-4337/testing-utils/helpers.js.map +1 -1
- package/dist/src/packs/safe-4337/types.d.ts +2 -4
- package/dist/src/packs/safe-4337/utils/entrypoint.d.ts +4 -0
- package/dist/src/packs/safe-4337/utils/entrypoint.js +23 -0
- package/dist/src/packs/safe-4337/utils/entrypoint.js.map +1 -0
- package/dist/src/packs/safe-4337/utils.d.ts +32 -5
- package/dist/src/packs/safe-4337/utils.js +71 -9
- package/dist/src/packs/safe-4337/utils.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntryPointV6 = exports.entryPointToSafeModules = exports.sameString = exports.EQ_OR_GT_0_3_0 = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const EQ_0_2_0 = '0.2.0';
|
|
6
|
+
exports.EQ_OR_GT_0_3_0 = '>=0.3.0';
|
|
7
|
+
function sameString(str1, str2) {
|
|
8
|
+
return str1.toLowerCase() === str2.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
exports.sameString = sameString;
|
|
11
|
+
function entryPointToSafeModules(entryPoint) {
|
|
12
|
+
const moduleVersionToEntryPoint = {
|
|
13
|
+
[constants_1.ENTRYPOINT_ADDRESS_V06]: EQ_0_2_0,
|
|
14
|
+
[constants_1.ENTRYPOINT_ADDRESS_V07]: exports.EQ_OR_GT_0_3_0
|
|
15
|
+
};
|
|
16
|
+
return moduleVersionToEntryPoint[entryPoint];
|
|
17
|
+
}
|
|
18
|
+
exports.entryPointToSafeModules = entryPointToSafeModules;
|
|
19
|
+
function isEntryPointV6(address) {
|
|
20
|
+
return sameString(address, constants_1.ENTRYPOINT_ADDRESS_V06);
|
|
21
|
+
}
|
|
22
|
+
exports.isEntryPointV6 = isEntryPointV6;
|
|
23
|
+
//# sourceMappingURL=entrypoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entrypoint.js","sourceRoot":"","sources":["../../../../../src/packs/safe-4337/utils/entrypoint.ts"],"names":[],"mappings":";;;AAAA,4CAA6E;AAE7E,MAAM,QAAQ,GAAG,OAAO,CAAA;AAEX,QAAA,cAAc,GAAG,SAAS,CAAA;AAEvC,SAAgB,UAAU,CAAC,IAAY,EAAE,IAAY;IACnD,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,CAAA;AAClD,CAAC;AAFD,gCAEC;AAED,SAAgB,uBAAuB,CAAC,UAAkB;IACxD,MAAM,yBAAyB,GAA2B;QACxD,CAAC,kCAAsB,CAAC,EAAE,QAAQ;QAClC,CAAC,kCAAsB,CAAC,EAAE,sBAAc;KACzC,CAAA;IAED,OAAO,yBAAyB,CAAC,UAAU,CAAC,CAAA;AAC9C,CAAC;AAPD,0DAOC;AAED,SAAgB,cAAc,CAAC,OAAe;IAC5C,OAAO,UAAU,CAAC,OAAO,EAAE,kCAAsB,CAAC,CAAA;AACpD,CAAC;AAFD,wCAEC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { SafeUserOperation, MetaTransactionData, SafeSignature, UserOperation } from '@safe-global/safe-core-sdk-types';
|
|
2
|
+
import { SafeProvider } from '@safe-global/protocol-kit';
|
|
1
3
|
import { ethers } from 'ethers';
|
|
2
|
-
import { UserOperation } from '@safe-global/safe-core-sdk-types';
|
|
3
4
|
/**
|
|
4
5
|
* Gets the EIP-4337 bundler provider.
|
|
5
6
|
*
|
|
@@ -8,12 +9,30 @@ import { UserOperation } from '@safe-global/safe-core-sdk-types';
|
|
|
8
9
|
*/
|
|
9
10
|
export declare function getEip4337BundlerProvider(bundlerUrl: string): ethers.JsonRpcProvider;
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Signs typed data.
|
|
12
13
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @
|
|
14
|
+
* @param {SafeUserOperation} safeUserOperation - Safe user operation to sign.
|
|
15
|
+
* @param {SafeProvider} safeProvider - Safe provider.
|
|
16
|
+
* @param {string} safe4337ModuleAddress - Safe 4337 module address.
|
|
17
|
+
* @return {Promise<SafeSignature>} The SafeSignature object containing the data and the signatures.
|
|
15
18
|
*/
|
|
16
|
-
export declare function
|
|
19
|
+
export declare function signSafeOp(safeUserOperation: SafeUserOperation, safeProvider: SafeProvider, safe4337ModuleAddress: string): Promise<SafeSignature>;
|
|
20
|
+
/**
|
|
21
|
+
* Encodes multi-send data from transactions batch.
|
|
22
|
+
*
|
|
23
|
+
* @param {MetaTransactionData[]} transactions - an array of transaction to to be encoded.
|
|
24
|
+
* @return {string} The encoded data string.
|
|
25
|
+
*/
|
|
26
|
+
export declare function encodeMultiSendCallData(transactions: MetaTransactionData[]): string;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the safe user operation hash.
|
|
29
|
+
*
|
|
30
|
+
* @param {SafeUserOperation} safeUserOperation - The SafeUserOperation.
|
|
31
|
+
* @param {bigint} chainId - The chain id.
|
|
32
|
+
* @param {string} safe4337ModuleAddress - The Safe 4337 module address.
|
|
33
|
+
* @return {string} The hash of the safe operation.
|
|
34
|
+
*/
|
|
35
|
+
export declare function calculateSafeUserOperationHash(safeUserOperation: SafeUserOperation, chainId: bigint, safe4337ModuleAddress: string): string;
|
|
17
36
|
/**
|
|
18
37
|
* Converts various bigint values from a UserOperation to their hexadecimal representation.
|
|
19
38
|
*
|
|
@@ -33,3 +52,11 @@ export declare function userOperationToHexValues(userOperation: UserOperation):
|
|
|
33
52
|
paymasterAndData: string;
|
|
34
53
|
signature: string;
|
|
35
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* This method creates a dummy signature for the SafeOperation based the owners.
|
|
57
|
+
* This is useful for gas estimations
|
|
58
|
+
* @param userOperation - The user operation
|
|
59
|
+
* @param safeOwners - The safe owner addresses
|
|
60
|
+
* @returns The user operation with the dummy signature
|
|
61
|
+
*/
|
|
62
|
+
export declare function addDummySignature(userOperation: UserOperation, safeOwners: string[]): UserOperation;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userOperationToHexValues = exports.
|
|
3
|
+
exports.addDummySignature = exports.userOperationToHexValues = exports.calculateSafeUserOperationHash = exports.encodeMultiSendCallData = exports.signSafeOp = exports.getEip4337BundlerProvider = void 0;
|
|
4
|
+
const safe_core_sdk_types_1 = require("@safe-global/safe-core-sdk-types");
|
|
5
|
+
const protocol_kit_1 = require("@safe-global/protocol-kit");
|
|
4
6
|
const ethers_1 = require("ethers");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
5
8
|
/**
|
|
6
9
|
* Gets the EIP-4337 bundler provider.
|
|
7
10
|
*
|
|
@@ -16,18 +19,58 @@ function getEip4337BundlerProvider(bundlerUrl) {
|
|
|
16
19
|
}
|
|
17
20
|
exports.getEip4337BundlerProvider = getEip4337BundlerProvider;
|
|
18
21
|
/**
|
|
19
|
-
*
|
|
22
|
+
* Signs typed data.
|
|
20
23
|
*
|
|
21
|
-
* @param {
|
|
22
|
-
* @
|
|
24
|
+
* @param {SafeUserOperation} safeUserOperation - Safe user operation to sign.
|
|
25
|
+
* @param {SafeProvider} safeProvider - Safe provider.
|
|
26
|
+
* @param {string} safe4337ModuleAddress - Safe 4337 module address.
|
|
27
|
+
* @return {Promise<SafeSignature>} The SafeSignature object containing the data and the signatures.
|
|
23
28
|
*/
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
|
|
29
|
+
async function signSafeOp(safeUserOperation, safeProvider, safe4337ModuleAddress) {
|
|
30
|
+
const signer = (await safeProvider.getExternalSigner());
|
|
31
|
+
const chainId = await safeProvider.getChainId();
|
|
32
|
+
const signerAddress = await signer.getAddress();
|
|
33
|
+
const signature = await signer.signTypedData({
|
|
34
|
+
chainId,
|
|
35
|
+
verifyingContract: safe4337ModuleAddress
|
|
36
|
+
}, constants_1.EIP712_SAFE_OPERATION_TYPE, {
|
|
37
|
+
...safeUserOperation,
|
|
38
|
+
nonce: ethers_1.ethers.toBeHex(safeUserOperation.nonce),
|
|
39
|
+
validAfter: ethers_1.ethers.toBeHex(safeUserOperation.validAfter),
|
|
40
|
+
validUntil: ethers_1.ethers.toBeHex(safeUserOperation.validUntil),
|
|
41
|
+
maxFeePerGas: ethers_1.ethers.toBeHex(safeUserOperation.maxFeePerGas),
|
|
42
|
+
maxPriorityFeePerGas: ethers_1.ethers.toBeHex(safeUserOperation.maxPriorityFeePerGas)
|
|
27
43
|
});
|
|
28
|
-
return
|
|
44
|
+
return new protocol_kit_1.EthSafeSignature(signerAddress, signature);
|
|
45
|
+
}
|
|
46
|
+
exports.signSafeOp = signSafeOp;
|
|
47
|
+
/**
|
|
48
|
+
* Encodes multi-send data from transactions batch.
|
|
49
|
+
*
|
|
50
|
+
* @param {MetaTransactionData[]} transactions - an array of transaction to to be encoded.
|
|
51
|
+
* @return {string} The encoded data string.
|
|
52
|
+
*/
|
|
53
|
+
function encodeMultiSendCallData(transactions) {
|
|
54
|
+
return constants_1.INTERFACES.encodeFunctionData('multiSend', [
|
|
55
|
+
(0, protocol_kit_1.encodeMultiSendData)(transactions.map((tx) => ({ ...tx, operation: tx.operation ?? safe_core_sdk_types_1.OperationType.Call })))
|
|
56
|
+
]);
|
|
29
57
|
}
|
|
30
|
-
exports.
|
|
58
|
+
exports.encodeMultiSendCallData = encodeMultiSendCallData;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the safe user operation hash.
|
|
61
|
+
*
|
|
62
|
+
* @param {SafeUserOperation} safeUserOperation - The SafeUserOperation.
|
|
63
|
+
* @param {bigint} chainId - The chain id.
|
|
64
|
+
* @param {string} safe4337ModuleAddress - The Safe 4337 module address.
|
|
65
|
+
* @return {string} The hash of the safe operation.
|
|
66
|
+
*/
|
|
67
|
+
function calculateSafeUserOperationHash(safeUserOperation, chainId, safe4337ModuleAddress) {
|
|
68
|
+
return ethers_1.ethers.TypedDataEncoder.hash({
|
|
69
|
+
chainId,
|
|
70
|
+
verifyingContract: safe4337ModuleAddress
|
|
71
|
+
}, constants_1.EIP712_SAFE_OPERATION_TYPE, safeUserOperation);
|
|
72
|
+
}
|
|
73
|
+
exports.calculateSafeUserOperationHash = calculateSafeUserOperationHash;
|
|
31
74
|
/**
|
|
32
75
|
* Converts various bigint values from a UserOperation to their hexadecimal representation.
|
|
33
76
|
*
|
|
@@ -47,4 +90,23 @@ function userOperationToHexValues(userOperation) {
|
|
|
47
90
|
return userOperationWithHexValues;
|
|
48
91
|
}
|
|
49
92
|
exports.userOperationToHexValues = userOperationToHexValues;
|
|
93
|
+
/**
|
|
94
|
+
* This method creates a dummy signature for the SafeOperation based the owners.
|
|
95
|
+
* This is useful for gas estimations
|
|
96
|
+
* @param userOperation - The user operation
|
|
97
|
+
* @param safeOwners - The safe owner addresses
|
|
98
|
+
* @returns The user operation with the dummy signature
|
|
99
|
+
*/
|
|
100
|
+
function addDummySignature(userOperation, safeOwners) {
|
|
101
|
+
const signatures = [];
|
|
102
|
+
for (const owner of safeOwners) {
|
|
103
|
+
const dummySignature = `0x000000000000000000000000${owner.slice(2)}000000000000000000000000000000000000000000000000000000000000000001`;
|
|
104
|
+
signatures.push(new protocol_kit_1.EthSafeSignature(owner, dummySignature));
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
...userOperation,
|
|
108
|
+
signature: ethers_1.ethers.solidityPacked(['uint48', 'uint48', 'bytes'], [0, 0, (0, protocol_kit_1.buildSignatureBytes)(signatures)])
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
exports.addDummySignature = addDummySignature;
|
|
50
112
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/packs/safe-4337/utils.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/packs/safe-4337/utils.ts"],"names":[],"mappings":";;;AAAA,0EAMyC;AACzC,4DAKkC;AAClC,mCAA+B;AAC/B,2CAAoE;AAEpE;;;;;GAKG;AACH,SAAgB,yBAAyB,CAAC,UAAkB;IAC1D,MAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,UAAU,EAAE,SAAS,EAAE;QACjE,aAAa,EAAE,CAAC;KACjB,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAA;AACjB,CAAC;AAND,8DAMC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAC9B,iBAAoC,EACpC,YAA0B,EAC1B,qBAA6B;IAE7B,M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