@turnkey/gas-station 2.0.0 → 3.0.1
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 +23 -25
- package/dist/abi/gas-station.d.ts +10 -56
- package/dist/abi/gas-station.d.ts.map +1 -1
- package/dist/abi/gas-station.js +7 -30
- package/dist/abi/gas-station.js.map +1 -1
- package/dist/abi/gas-station.mjs +7 -30
- package/dist/abi/gas-station.mjs.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.mjs +2 -2
- package/dist/intentBuilder.js +14 -14
- package/dist/intentBuilder.js.map +1 -1
- package/dist/intentBuilder.mjs +14 -14
- package/dist/intentBuilder.mjs.map +1 -1
- package/dist/policyUtils.d.ts +46 -47
- package/dist/policyUtils.d.ts.map +1 -1
- package/dist/policyUtils.js +49 -50
- package/dist/policyUtils.js.map +1 -1
- package/dist/policyUtils.mjs +49 -50
- package/dist/policyUtils.mjs.map +1 -1
- package/package.json +3 -3
package/dist/intentBuilder.mjs
CHANGED
|
@@ -107,22 +107,22 @@ class IntentBuilder {
|
|
|
107
107
|
chainId: this.config.chainId,
|
|
108
108
|
verifyingContract: this.config.eoaAddress,
|
|
109
109
|
};
|
|
110
|
-
//
|
|
110
|
+
// keccak256("Execution(uint128 nonce,uint32 deadline,address to,uint256 value,bytes data)")
|
|
111
111
|
const types = {
|
|
112
112
|
Execution: [
|
|
113
113
|
{ name: "nonce", type: "uint128" },
|
|
114
114
|
{ name: "deadline", type: "uint32" },
|
|
115
|
-
{ name: "
|
|
116
|
-
{ name: "
|
|
117
|
-
{ name: "
|
|
115
|
+
{ name: "to", type: "address" },
|
|
116
|
+
{ name: "value", type: "uint256" },
|
|
117
|
+
{ name: "data", type: "bytes" },
|
|
118
118
|
],
|
|
119
119
|
};
|
|
120
120
|
const message = {
|
|
121
121
|
nonce,
|
|
122
122
|
deadline,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
to: this.outputContract,
|
|
124
|
+
value: this.ethAmount,
|
|
125
|
+
data: this.callData,
|
|
126
126
|
};
|
|
127
127
|
const signature = await this.config.eoaWalletClient.signTypedData({
|
|
128
128
|
account: this.config.eoaWalletClient.account,
|
|
@@ -161,7 +161,7 @@ class IntentBuilder {
|
|
|
161
161
|
verifyingContract: this.config.eoaAddress,
|
|
162
162
|
};
|
|
163
163
|
// Based on hashApproveThenExecute from the contract
|
|
164
|
-
// keccak256("ApproveThenExecute(uint128 nonce,uint32 deadline,address erc20Contract,address spender,uint256 approveAmount,address
|
|
164
|
+
// keccak256("ApproveThenExecute(uint128 nonce,uint32 deadline,address erc20Contract,address spender,uint256 approveAmount,address to,uint256 value,bytes data)")
|
|
165
165
|
const types = {
|
|
166
166
|
ApproveThenExecute: [
|
|
167
167
|
{ name: "nonce", type: "uint128" },
|
|
@@ -169,9 +169,9 @@ class IntentBuilder {
|
|
|
169
169
|
{ name: "erc20Contract", type: "address" },
|
|
170
170
|
{ name: "spender", type: "address" },
|
|
171
171
|
{ name: "approveAmount", type: "uint256" },
|
|
172
|
-
{ name: "
|
|
173
|
-
{ name: "
|
|
174
|
-
{ name: "
|
|
172
|
+
{ name: "to", type: "address" },
|
|
173
|
+
{ name: "value", type: "uint256" },
|
|
174
|
+
{ name: "data", type: "bytes" },
|
|
175
175
|
],
|
|
176
176
|
};
|
|
177
177
|
const message = {
|
|
@@ -180,9 +180,9 @@ class IntentBuilder {
|
|
|
180
180
|
erc20Contract: erc20Address,
|
|
181
181
|
spender,
|
|
182
182
|
approveAmount,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
to: this.outputContract,
|
|
184
|
+
value: this.ethAmount,
|
|
185
|
+
data: this.callData,
|
|
186
186
|
};
|
|
187
187
|
const signature = await this.config.eoaWalletClient.signTypedData({
|
|
188
188
|
account: this.config.eoaWalletClient.account,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intentBuilder.mjs","sources":["../src/intentBuilder.ts"],"sourc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e,EAAE,IAAI,EAAE,SAAS,EAAE;AAC1C,gBAAA,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;AAC/B,gBAAA,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;AAClC,gBAAA,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;AAChC,aAAA;SACF;AAED,QAAA,MAAM,OAAO,GAAG;YACd,KAAK;YACL,QAAQ;AACR,YAAA,aAAa,EAAE,YAAY;YAC3B,OAAO;YACP,aAAa;YACb,EAAE,EAAE,IAAI,CAAC,cAAc;YACvB,KAAK,EAAE,IAAI,CAAC,SAAS;YACrB,IAAI,EAAE,IAAI,CAAC,QAAQ;SACpB;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,aAAa,CAAC;AAChE,YAAA,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO;YAC5C,MAAM;YACN,KAAK;AACL,YAAA,WAAW,EAAE,oBAAoB;YACjC,OAAO;AACR,SAAA,CAAC;QAEF,OAAO;YACL,KAAK;YACL,QAAQ;YACR,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS;AACT,YAAA,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,YAAY;YACZ,OAAO;YACP,aAAa;SACd;IACH;;IAGA,OAAO,MAAM,CAAC,MAA2B,EAAA;AACvC,QAAA,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC;IAClC;AACD;;;;"}
|
package/dist/policyUtils.d.ts
CHANGED
|
@@ -11,15 +11,15 @@ import type { Hex } from "viem";
|
|
|
11
11
|
* @param config.customConsensus - Optional custom consensus expression (overrides eoaUserId and additionalApprovers)
|
|
12
12
|
* @param config.restrictions - Signing restrictions
|
|
13
13
|
* @param config.restrictions.allowedContracts - Whitelist of contract addresses EOA can sign intents for
|
|
14
|
-
* @param config.restrictions.disallowEthTransfer - Whether to disallow ETH transfers (if true,
|
|
14
|
+
* @param config.restrictions.disallowEthTransfer - Whether to disallow ETH transfers (if true, value must be 0)
|
|
15
15
|
* @param config.policyName - Optional policy name
|
|
16
16
|
* @returns Policy object ready to submit to Turnkey createPolicy API
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* // Simple: single user approval, token-only transfers
|
|
20
20
|
* const policy = buildIntentSigningPolicy({
|
|
21
|
-
* organizationId: "
|
|
22
|
-
* eoaUserId: "
|
|
21
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
22
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
23
23
|
* restrictions: {
|
|
24
24
|
* allowedContracts: ["0x833...USDC", "0x6B1...DAI"],
|
|
25
25
|
* disallowEthTransfer: true,
|
|
@@ -29,24 +29,24 @@ import type { Hex } from "viem";
|
|
|
29
29
|
*
|
|
30
30
|
* // Resulting policy:
|
|
31
31
|
* {
|
|
32
|
-
* organizationId: "
|
|
32
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
33
33
|
* policyName: "Stablecoin Only",
|
|
34
34
|
* effect: "EFFECT_ALLOW",
|
|
35
|
-
* consensus: "approvers.any(user, user.id == '
|
|
35
|
+
* consensus: "approvers.any(user, user.id == '3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a')",
|
|
36
36
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
37
37
|
* "eth.eip_712.primary_type == 'Execution' && " +
|
|
38
|
-
* "(eth.eip_712.message['
|
|
39
|
-
* "eth.eip_712.message['
|
|
40
|
-
* "eth.eip_712.message['
|
|
38
|
+
* "(eth.eip_712.message['to'] == '0x833...usdc' || " +
|
|
39
|
+
* "eth.eip_712.message['to'] == '0x6b1...dai') && " +
|
|
40
|
+
* "eth.eip_712.message['value'] == '0'",
|
|
41
41
|
* notes: "Restricts which EIP-712 intents the EOA can sign for gas station execution"
|
|
42
42
|
* }
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* // Multi-approval: EOA AND backup user must both approve
|
|
46
46
|
* const policy = buildIntentSigningPolicy({
|
|
47
|
-
* organizationId: "
|
|
48
|
-
* eoaUserId: "
|
|
49
|
-
* additionalApprovers: ["
|
|
47
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
48
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
49
|
+
* additionalApprovers: ["9d4e2f5b-6c7d-8e9f-0a1b-2c3d4e5f6a7b"],
|
|
50
50
|
* restrictions: {
|
|
51
51
|
* allowedContracts: ["0x833...USDC"],
|
|
52
52
|
* disallowEthTransfer: true,
|
|
@@ -55,23 +55,23 @@ import type { Hex } from "viem";
|
|
|
55
55
|
*
|
|
56
56
|
* // Resulting policy:
|
|
57
57
|
* {
|
|
58
|
-
* organizationId: "
|
|
58
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
59
59
|
* policyName: "Gas Station Intent Signing Policy",
|
|
60
60
|
* effect: "EFFECT_ALLOW",
|
|
61
|
-
* consensus: "approvers.any(user, user.id == '
|
|
62
|
-
* "approvers.any(user, user.id == '
|
|
61
|
+
* consensus: "approvers.any(user, user.id == '3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a') && " +
|
|
62
|
+
* "approvers.any(user, user.id == '9d4e2f5b-6c7d-8e9f-0a1b-2c3d4e5f6a7b')",
|
|
63
63
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
64
64
|
* "eth.eip_712.primary_type == 'Execution' && " +
|
|
65
|
-
* "(eth.eip_712.message['
|
|
66
|
-
* "eth.eip_712.message['
|
|
65
|
+
* "(eth.eip_712.message['to'] == '0x833...usdc') && " +
|
|
66
|
+
* "eth.eip_712.message['value'] == '0'",
|
|
67
67
|
* notes: "Restricts which EIP-712 intents the EOA can sign for gas station execution"
|
|
68
68
|
* }
|
|
69
69
|
*
|
|
70
70
|
* @example
|
|
71
71
|
* // Advanced: custom consensus expression
|
|
72
72
|
* const policy = buildIntentSigningPolicy({
|
|
73
|
-
* organizationId: "
|
|
74
|
-
* eoaUserId: "
|
|
73
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
74
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
75
75
|
* customConsensus: "approvers.count() >= 2",
|
|
76
76
|
* restrictions: {
|
|
77
77
|
* disallowEthTransfer: false,
|
|
@@ -125,9 +125,9 @@ export declare function buildIntentSigningPolicy(config: {
|
|
|
125
125
|
* @example
|
|
126
126
|
* // Simple: single paymaster approval with ETH amount limit
|
|
127
127
|
* const policy = buildPaymasterExecutionPolicy({
|
|
128
|
-
* organizationId: "
|
|
129
|
-
* paymasterUserId: "
|
|
130
|
-
* executionContractAddress: "
|
|
128
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
129
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
130
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
131
131
|
* restrictions: {
|
|
132
132
|
* allowedEOAs: ["0xAli...ce", "0xBob...by"],
|
|
133
133
|
* allowedContracts: ["0x833...USDC", "0x6B1...DAI"],
|
|
@@ -140,17 +140,17 @@ export declare function buildIntentSigningPolicy(config: {
|
|
|
140
140
|
*
|
|
141
141
|
* // Resulting policy (uses ABI parsing):
|
|
142
142
|
* {
|
|
143
|
-
* organizationId: "
|
|
143
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
144
144
|
* policyName: "Paymaster Protection",
|
|
145
145
|
* effect: "EFFECT_ALLOW",
|
|
146
|
-
* consensus: "approvers.any(user, user.id == '
|
|
146
|
+
* consensus: "approvers.any(user, user.id == '8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c')",
|
|
147
147
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
148
|
-
* "eth.tx.to == '
|
|
148
|
+
* "eth.tx.to == '0x00000000008c57a1ce37836a5e9d36759d070d8c' && " +
|
|
149
149
|
* "(eth.tx.contract_call_args['_to'] == '0x833...usdc' || " +
|
|
150
150
|
* "eth.tx.contract_call_args['_to'] == '0x6b1...dai') && " +
|
|
151
|
-
* "(eth.tx.contract_call_args['
|
|
152
|
-
* "eth.tx.contract_call_args['
|
|
153
|
-
* "eth.tx.contract_call_args['
|
|
151
|
+
* "(eth.tx.contract_call_args['_target'] == '0xali...ce' || " +
|
|
152
|
+
* "eth.tx.contract_call_args['_target'] == '0xbob...by') && " +
|
|
153
|
+
* "eth.tx.contract_call_args['_ethAmount'] <= 100000000000000000 && " +
|
|
154
154
|
* "eth.tx.gasPrice <= 50000000000 && eth.tx.gas <= 500000",
|
|
155
155
|
* notes: "Restricts which execute() transactions the paymaster can submit on-chain"
|
|
156
156
|
* }
|
|
@@ -158,10 +158,10 @@ export declare function buildIntentSigningPolicy(config: {
|
|
|
158
158
|
* @example
|
|
159
159
|
* // Multi-user: primary paymaster OR backup can approve
|
|
160
160
|
* const policy = buildPaymasterExecutionPolicy({
|
|
161
|
-
* organizationId: "
|
|
162
|
-
* paymasterUserId: "
|
|
163
|
-
* additionalApprovers: ["
|
|
164
|
-
* executionContractAddress: "
|
|
161
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
162
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
163
|
+
* additionalApprovers: ["2e4f6a8b-9c0d-1e2f-3a4b-5c6d7e8f9a0b"],
|
|
164
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
165
165
|
* restrictions: {
|
|
166
166
|
* allowedEOAs: ["0xAli...ce"],
|
|
167
167
|
* maxEthAmount: parseEther("1"), // Max 1 ETH
|
|
@@ -171,15 +171,15 @@ export declare function buildIntentSigningPolicy(config: {
|
|
|
171
171
|
*
|
|
172
172
|
* // Resulting policy (uses ABI parsing):
|
|
173
173
|
* {
|
|
174
|
-
* organizationId: "
|
|
174
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
175
175
|
* policyName: "Gas Station Paymaster Execution Policy",
|
|
176
176
|
* effect: "EFFECT_ALLOW",
|
|
177
|
-
* consensus: "approvers.any(user, user.id == '
|
|
178
|
-
* "user.id == '
|
|
177
|
+
* consensus: "approvers.any(user, user.id == '8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c' || " +
|
|
178
|
+
* "user.id == '2e4f6a8b-9c0d-1e2f-3a4b-5c6d7e8f9a0b')",
|
|
179
179
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
180
|
-
* "eth.tx.to == '
|
|
181
|
-
* "(eth.tx.contract_call_args['
|
|
182
|
-
* "eth.tx.contract_call_args['
|
|
180
|
+
* "eth.tx.to == '0x00000000008c57a1ce37836a5e9d36759d070d8c' && " +
|
|
181
|
+
* "(eth.tx.contract_call_args['_target'] == '0xali...ce') && " +
|
|
182
|
+
* "eth.tx.contract_call_args['_ethAmount'] <= 1000000000000000000 && " +
|
|
183
183
|
* "eth.tx.gasPrice <= 100000000000",
|
|
184
184
|
* notes: "Restricts which execute() transactions the paymaster can submit on-chain"
|
|
185
185
|
* }
|
|
@@ -187,10 +187,10 @@ export declare function buildIntentSigningPolicy(config: {
|
|
|
187
187
|
* @example
|
|
188
188
|
* // Advanced: require multiple approvals
|
|
189
189
|
* const policy = buildPaymasterExecutionPolicy({
|
|
190
|
-
* organizationId: "
|
|
191
|
-
* paymasterUserId: "
|
|
190
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
191
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
192
192
|
* customConsensus: "approvers.count() >= 2",
|
|
193
|
-
* executionContractAddress: "
|
|
193
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
194
194
|
* restrictions: { ... },
|
|
195
195
|
* });
|
|
196
196
|
*
|
|
@@ -254,13 +254,12 @@ export declare function uploadGasStationInterface({ client, organizationId, cont
|
|
|
254
254
|
* @returns The smart contract interface ID
|
|
255
255
|
*
|
|
256
256
|
* @example
|
|
257
|
-
* const interfaceId = await ensureGasStationInterface(
|
|
258
|
-
* turnkeyClient.apiClient(),
|
|
259
|
-
* "
|
|
260
|
-
* "
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* );
|
|
257
|
+
* const interfaceId = await ensureGasStationInterface({
|
|
258
|
+
* client: turnkeyClient.apiClient(),
|
|
259
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
260
|
+
* contractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
261
|
+
* chainName: "Base Sepolia"
|
|
262
|
+
* });
|
|
264
263
|
*/
|
|
265
264
|
export declare function ensureGasStationInterface({ client, organizationId, contractAddress, label, chainName, }: {
|
|
266
265
|
client: TurnkeyApiClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policyUtils.d.ts","sourceRoot":"","sources":["../src/policyUtils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C,cAAc,EAAE,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CAoBlB"}
|
package/dist/policyUtils.js
CHANGED
|
@@ -14,15 +14,15 @@ var gasStation = require('./abi/gas-station.js');
|
|
|
14
14
|
* @param config.customConsensus - Optional custom consensus expression (overrides eoaUserId and additionalApprovers)
|
|
15
15
|
* @param config.restrictions - Signing restrictions
|
|
16
16
|
* @param config.restrictions.allowedContracts - Whitelist of contract addresses EOA can sign intents for
|
|
17
|
-
* @param config.restrictions.disallowEthTransfer - Whether to disallow ETH transfers (if true,
|
|
17
|
+
* @param config.restrictions.disallowEthTransfer - Whether to disallow ETH transfers (if true, value must be 0)
|
|
18
18
|
* @param config.policyName - Optional policy name
|
|
19
19
|
* @returns Policy object ready to submit to Turnkey createPolicy API
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* // Simple: single user approval, token-only transfers
|
|
23
23
|
* const policy = buildIntentSigningPolicy({
|
|
24
|
-
* organizationId: "
|
|
25
|
-
* eoaUserId: "
|
|
24
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
25
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
26
26
|
* restrictions: {
|
|
27
27
|
* allowedContracts: ["0x833...USDC", "0x6B1...DAI"],
|
|
28
28
|
* disallowEthTransfer: true,
|
|
@@ -32,24 +32,24 @@ var gasStation = require('./abi/gas-station.js');
|
|
|
32
32
|
*
|
|
33
33
|
* // Resulting policy:
|
|
34
34
|
* {
|
|
35
|
-
* organizationId: "
|
|
35
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
36
36
|
* policyName: "Stablecoin Only",
|
|
37
37
|
* effect: "EFFECT_ALLOW",
|
|
38
|
-
* consensus: "approvers.any(user, user.id == '
|
|
38
|
+
* consensus: "approvers.any(user, user.id == '3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a')",
|
|
39
39
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
40
40
|
* "eth.eip_712.primary_type == 'Execution' && " +
|
|
41
|
-
* "(eth.eip_712.message['
|
|
42
|
-
* "eth.eip_712.message['
|
|
43
|
-
* "eth.eip_712.message['
|
|
41
|
+
* "(eth.eip_712.message['to'] == '0x833...usdc' || " +
|
|
42
|
+
* "eth.eip_712.message['to'] == '0x6b1...dai') && " +
|
|
43
|
+
* "eth.eip_712.message['value'] == '0'",
|
|
44
44
|
* notes: "Restricts which EIP-712 intents the EOA can sign for gas station execution"
|
|
45
45
|
* }
|
|
46
46
|
*
|
|
47
47
|
* @example
|
|
48
48
|
* // Multi-approval: EOA AND backup user must both approve
|
|
49
49
|
* const policy = buildIntentSigningPolicy({
|
|
50
|
-
* organizationId: "
|
|
51
|
-
* eoaUserId: "
|
|
52
|
-
* additionalApprovers: ["
|
|
50
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
51
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
52
|
+
* additionalApprovers: ["9d4e2f5b-6c7d-8e9f-0a1b-2c3d4e5f6a7b"],
|
|
53
53
|
* restrictions: {
|
|
54
54
|
* allowedContracts: ["0x833...USDC"],
|
|
55
55
|
* disallowEthTransfer: true,
|
|
@@ -58,23 +58,23 @@ var gasStation = require('./abi/gas-station.js');
|
|
|
58
58
|
*
|
|
59
59
|
* // Resulting policy:
|
|
60
60
|
* {
|
|
61
|
-
* organizationId: "
|
|
61
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
62
62
|
* policyName: "Gas Station Intent Signing Policy",
|
|
63
63
|
* effect: "EFFECT_ALLOW",
|
|
64
|
-
* consensus: "approvers.any(user, user.id == '
|
|
65
|
-
* "approvers.any(user, user.id == '
|
|
64
|
+
* consensus: "approvers.any(user, user.id == '3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a') && " +
|
|
65
|
+
* "approvers.any(user, user.id == '9d4e2f5b-6c7d-8e9f-0a1b-2c3d4e5f6a7b')",
|
|
66
66
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
67
67
|
* "eth.eip_712.primary_type == 'Execution' && " +
|
|
68
|
-
* "(eth.eip_712.message['
|
|
69
|
-
* "eth.eip_712.message['
|
|
68
|
+
* "(eth.eip_712.message['to'] == '0x833...usdc') && " +
|
|
69
|
+
* "eth.eip_712.message['value'] == '0'",
|
|
70
70
|
* notes: "Restricts which EIP-712 intents the EOA can sign for gas station execution"
|
|
71
71
|
* }
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* // Advanced: custom consensus expression
|
|
75
75
|
* const policy = buildIntentSigningPolicy({
|
|
76
|
-
* organizationId: "
|
|
77
|
-
* eoaUserId: "
|
|
76
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
77
|
+
* eoaUserId: "3c7d6e8a-4b5c-6d7e-8f9a-0b1c2d3e4f5a",
|
|
78
78
|
* customConsensus: "approvers.count() >= 2",
|
|
79
79
|
* restrictions: {
|
|
80
80
|
* disallowEthTransfer: false,
|
|
@@ -94,12 +94,12 @@ function buildIntentSigningPolicy(config) {
|
|
|
94
94
|
// Build OR conditions for each allowed contract
|
|
95
95
|
// Convert to lowercase for case-insensitive comparison
|
|
96
96
|
const contractConditions = config.restrictions.allowedContracts
|
|
97
|
-
.map((c) => `eth.eip_712.message['
|
|
97
|
+
.map((c) => `eth.eip_712.message['to'] == '${c.toLowerCase()}'`)
|
|
98
98
|
.join(" || ");
|
|
99
99
|
conditions.push(`(${contractConditions})`);
|
|
100
100
|
}
|
|
101
101
|
if (!!config.restrictions?.disallowEthTransfer) {
|
|
102
|
-
conditions.push(`eth.eip_712.message['
|
|
102
|
+
conditions.push(`eth.eip_712.message['value'] == '0'`);
|
|
103
103
|
}
|
|
104
104
|
// Build consensus expression
|
|
105
105
|
let consensus;
|
|
@@ -156,9 +156,9 @@ function buildIntentSigningPolicy(config) {
|
|
|
156
156
|
* @example
|
|
157
157
|
* // Simple: single paymaster approval with ETH amount limit
|
|
158
158
|
* const policy = buildPaymasterExecutionPolicy({
|
|
159
|
-
* organizationId: "
|
|
160
|
-
* paymasterUserId: "
|
|
161
|
-
* executionContractAddress: "
|
|
159
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
160
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
161
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
162
162
|
* restrictions: {
|
|
163
163
|
* allowedEOAs: ["0xAli...ce", "0xBob...by"],
|
|
164
164
|
* allowedContracts: ["0x833...USDC", "0x6B1...DAI"],
|
|
@@ -171,17 +171,17 @@ function buildIntentSigningPolicy(config) {
|
|
|
171
171
|
*
|
|
172
172
|
* // Resulting policy (uses ABI parsing):
|
|
173
173
|
* {
|
|
174
|
-
* organizationId: "
|
|
174
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
175
175
|
* policyName: "Paymaster Protection",
|
|
176
176
|
* effect: "EFFECT_ALLOW",
|
|
177
|
-
* consensus: "approvers.any(user, user.id == '
|
|
177
|
+
* consensus: "approvers.any(user, user.id == '8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c')",
|
|
178
178
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
179
|
-
* "eth.tx.to == '
|
|
179
|
+
* "eth.tx.to == '0x00000000008c57a1ce37836a5e9d36759d070d8c' && " +
|
|
180
180
|
* "(eth.tx.contract_call_args['_to'] == '0x833...usdc' || " +
|
|
181
181
|
* "eth.tx.contract_call_args['_to'] == '0x6b1...dai') && " +
|
|
182
|
-
* "(eth.tx.contract_call_args['
|
|
183
|
-
* "eth.tx.contract_call_args['
|
|
184
|
-
* "eth.tx.contract_call_args['
|
|
182
|
+
* "(eth.tx.contract_call_args['_target'] == '0xali...ce' || " +
|
|
183
|
+
* "eth.tx.contract_call_args['_target'] == '0xbob...by') && " +
|
|
184
|
+
* "eth.tx.contract_call_args['_ethAmount'] <= 100000000000000000 && " +
|
|
185
185
|
* "eth.tx.gasPrice <= 50000000000 && eth.tx.gas <= 500000",
|
|
186
186
|
* notes: "Restricts which execute() transactions the paymaster can submit on-chain"
|
|
187
187
|
* }
|
|
@@ -189,10 +189,10 @@ function buildIntentSigningPolicy(config) {
|
|
|
189
189
|
* @example
|
|
190
190
|
* // Multi-user: primary paymaster OR backup can approve
|
|
191
191
|
* const policy = buildPaymasterExecutionPolicy({
|
|
192
|
-
* organizationId: "
|
|
193
|
-
* paymasterUserId: "
|
|
194
|
-
* additionalApprovers: ["
|
|
195
|
-
* executionContractAddress: "
|
|
192
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
193
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
194
|
+
* additionalApprovers: ["2e4f6a8b-9c0d-1e2f-3a4b-5c6d7e8f9a0b"],
|
|
195
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
196
196
|
* restrictions: {
|
|
197
197
|
* allowedEOAs: ["0xAli...ce"],
|
|
198
198
|
* maxEthAmount: parseEther("1"), // Max 1 ETH
|
|
@@ -202,15 +202,15 @@ function buildIntentSigningPolicy(config) {
|
|
|
202
202
|
*
|
|
203
203
|
* // Resulting policy (uses ABI parsing):
|
|
204
204
|
* {
|
|
205
|
-
* organizationId: "
|
|
205
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
206
206
|
* policyName: "Gas Station Paymaster Execution Policy",
|
|
207
207
|
* effect: "EFFECT_ALLOW",
|
|
208
|
-
* consensus: "approvers.any(user, user.id == '
|
|
209
|
-
* "user.id == '
|
|
208
|
+
* consensus: "approvers.any(user, user.id == '8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c' || " +
|
|
209
|
+
* "user.id == '2e4f6a8b-9c0d-1e2f-3a4b-5c6d7e8f9a0b')",
|
|
210
210
|
* condition: "activity.resource == 'PRIVATE_KEY' && activity.action == 'SIGN' && " +
|
|
211
|
-
* "eth.tx.to == '
|
|
212
|
-
* "(eth.tx.contract_call_args['
|
|
213
|
-
* "eth.tx.contract_call_args['
|
|
211
|
+
* "eth.tx.to == '0x00000000008c57a1ce37836a5e9d36759d070d8c' && " +
|
|
212
|
+
* "(eth.tx.contract_call_args['_target'] == '0xali...ce') && " +
|
|
213
|
+
* "eth.tx.contract_call_args['_ethAmount'] <= 1000000000000000000 && " +
|
|
214
214
|
* "eth.tx.gasPrice <= 100000000000",
|
|
215
215
|
* notes: "Restricts which execute() transactions the paymaster can submit on-chain"
|
|
216
216
|
* }
|
|
@@ -218,10 +218,10 @@ function buildIntentSigningPolicy(config) {
|
|
|
218
218
|
* @example
|
|
219
219
|
* // Advanced: require multiple approvals
|
|
220
220
|
* const policy = buildPaymasterExecutionPolicy({
|
|
221
|
-
* organizationId: "
|
|
222
|
-
* paymasterUserId: "
|
|
221
|
+
* organizationId: "f8c3a5e7-9876-5432-1abc-def098765432",
|
|
222
|
+
* paymasterUserId: "8f2a1b4c-5d6e-7f8a-9b0c-1d2e3f4a5b6c",
|
|
223
223
|
* customConsensus: "approvers.count() >= 2",
|
|
224
|
-
* executionContractAddress: "
|
|
224
|
+
* executionContractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
225
225
|
* restrictions: { ... },
|
|
226
226
|
* });
|
|
227
227
|
*
|
|
@@ -234,7 +234,7 @@ function buildPaymasterExecutionPolicy(config) {
|
|
|
234
234
|
`eth.tx.to == '${config.executionContractAddress.toLowerCase()}'`,
|
|
235
235
|
];
|
|
236
236
|
// Check output contract address using ABI parsing
|
|
237
|
-
// Turnkey parses execute(address
|
|
237
|
+
// Turnkey parses execute(address _target, address _to, uint256 _ethAmount, bytes _data)
|
|
238
238
|
// and exposes arguments via eth.tx.contract_call_args
|
|
239
239
|
if (config.restrictions?.allowedContracts &&
|
|
240
240
|
config.restrictions.allowedContracts.length > 0) {
|
|
@@ -351,13 +351,12 @@ async function uploadGasStationInterface({ client, organizationId, contractAddre
|
|
|
351
351
|
* @returns The smart contract interface ID
|
|
352
352
|
*
|
|
353
353
|
* @example
|
|
354
|
-
* const interfaceId = await ensureGasStationInterface(
|
|
355
|
-
* turnkeyClient.apiClient(),
|
|
356
|
-
* "
|
|
357
|
-
* "
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* );
|
|
354
|
+
* const interfaceId = await ensureGasStationInterface({
|
|
355
|
+
* client: turnkeyClient.apiClient(),
|
|
356
|
+
* organizationId: "a5b89e4f-1234-5678-9abc-def012345678",
|
|
357
|
+
* contractAddress: "0x00000000008c57a1CE37836a5e9d36759D070d8c",
|
|
358
|
+
* chainName: "Base Sepolia"
|
|
359
|
+
* });
|
|
361
360
|
*/
|
|
362
361
|
async function ensureGasStationInterface({ client, organizationId, contractAddress, label, chainName, }) {
|
|
363
362
|
// Check if interface already exists
|
package/dist/policyUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policyUtils.js","sources":["../src/policyUtils.ts"],"sourcesContent":[null],"names":["gasStationAbi"],"mappings":";;;;AAAA;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EG;AACG,SAAU,wBAAwB,CAAC,MAUxC,EAAA;AACC,IAAA,MAAM,UAAU,GAAa;QAC3B,oCAAoC;QACpC,2BAA2B;QAC3B,yCAAyC;KAC1C;AAED,IAAA,IACE,MAAM,CAAC,YAAY,EAAE,gBAAgB;QACrC,MAAM,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAC/C;;;AAGA,QAAA,MAAM,kBAAkB,GAAG,MAAM,CAAC,YAAY,CAAC;AAC5C,aAAA,GAAG,
|
|
1
|
+
{"version":3,"file":"policyUtils.js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