@gol/sdk 0.1.0-next.0 → 0.3.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/README.md CHANGED
@@ -1,18 +1,88 @@
1
1
  # GOL SDK
2
2
 
3
- Public TypeScript interfaces for GOL Network.
3
+ TypeScript SDK for GOL Network bounded mandates with hosted, owner-reimbursed gas on Base Sepolia testnet (chain `84532`).
4
4
 
5
- This first package covers developer onboarding and API credential verification through the public GOL Platform API. Mandates, payment actions, receipts, and webhooks are intentionally not exposed until their contract and platform interfaces exist.
5
+ A developer's agent sends bounded USDC transfers from an end user's existing smart account. GOL's relayer pays the network gas first. After the action reaches the hosted profile's selected Base head, GOL claims the actual gas back in native ETH from the same account, within caps the owner signed. The owner signs every authority in their own wallet and can pause, resume, or revoke without GOL.
6
6
 
7
- ## Install
7
+ Supported accounts are four exact configurations: Safe 1.4.1, Biconomy Nexus 1.0.0, ZeroDev Kernel v0.3.1, and Alchemy Modular Account v2. The transfer asset is Circle USDC on Base Sepolia. Read deployed addresses and limits from `getGasConfiguration`; do not hard-code them.
8
8
 
9
- The package is not published yet. After a release is available:
9
+ ## Install
10
10
 
11
11
  ```sh
12
- pnpm add @gol/sdk
12
+ pnpm add @gol/sdk@next
13
13
  ```
14
14
 
15
- Use Node.js 22 or later. The root entry point exports browser-safe types and errors. API clients that accept session tokens or API keys are available only from `@gol/sdk/server`.
15
+ Use Node.js 22 or later. The root entry point (`@gol/sdk`) is browser-safe: policy encoding, owner wallet payloads, owner operations, and verification. API clients and webhook verification are in `@gol/sdk/server` and must run on your server, because they hold your API key.
16
+
17
+ ## Integration flow
18
+
19
+ Create a test project and an API key with `project:read`, `accounts:read`, `mandates:read`, `mandates:write`, `actions:submit`, and `webhooks:manage` at [console.gol.network](https://console.gol.network).
20
+
21
+ 1. **Install the core on the owner's account.** `getAccountStatus` reports the detected family and whether the core is installed. If not, build the owner operation in the browser with `prepareOwnerInstallation` and `prepareOwnerOperation`, have the owner sign it with `signOwnerOperation`, and submit the returned transaction (a Safe transaction, or an EntryPoint v0.7 user operation for Nexus, Kernel, and Alchemy).
22
+ 2. **Prepare the approval on your server.** `prepareGasPolicy` compiles the exact mandate policy (allowed recipients, per-action and total USDC caps) and gas policy (per-action and total ETH reimbursement caps, expiry, chargeable outcomes).
23
+ 3. **Have the owner sign in the browser.** `signPreparedGasPolicy(ownerWallet, prepared, expectations)` independently recomputes every ID, digest, and wallet payload, asks the wallet for one `eth_signTypedData_v4` signature, and returns a `createMandateWithGas` call. Any address may send it; authority comes only from the owner's signature.
24
+ 4. **Confirm.** `confirmGasPolicy` (or `waitForGasPolicyConfirmation`) returns the policy once both receipt providers observe the approval at the hosted profile's selected Base head. Profile 3 uses the lower `safe` head, usually tens of seconds behind the latest head on Base Sepolia. This is earlier than Ethereum finality, and timing varies with network conditions.
25
+ 5. **Submit actions from your agent.** `prepareGasExecution` returns EIP-712 typed data; your agent signs it and you call `submitGasExecution` with the same 32-byte action ID as the idempotency key. A retry with the same ID and signature returns the original execution and moves no additional value.
26
+ 6. **Observe.** Poll `getGasExecution` or `waitForGasExecution`, or receive signed webhooks. Network cost, owner reimbursement, and GOL cost are reported separately.
27
+ 7. **Pause or resume.** On your server, call `prepareGasPolicySafetyAction(projectId, gasPolicyId, { action: "pause" })` or use `"resume"`. In the owner's browser, `signPreparedSafetyAction(walletClient, prepared)` verifies the digest and wallet payload before signing and returns a core call that any address may relay. Alternatively, submit `prepared.directOwnerCall` through the owner's account. Confirm the transaction with `waitForGasPolicySafetyAction`. A paused policy refuses new submissions. An accepted action waiting to be sent remains held while paused, proceeds if the owner resumes before its quote expires, or closes without owner liability at quote expiry.
28
+ 8. **Revoke.** `prepareGasPolicyRevocation` returns both owner paths: a relayed owner signature (`signPreparedRevocation`) and a direct account call. Either works without GOL or the agent.
29
+
30
+ ```ts
31
+ // Server
32
+ import { GolApiClient } from "@gol/sdk/server";
33
+ const gol = new GolApiClient({
34
+ baseUrl: "https://api.gol.network",
35
+ apiKey: process.env.GOL_API_KEY!,
36
+ });
37
+ const prepared = await gol.prepareGasPolicy(projectId, {
38
+ account,
39
+ family: "safe",
40
+ agent,
41
+ transfer: {
42
+ recipients: [merchant],
43
+ maxPerActionBaseUnits: "1000000",
44
+ maxTotalBaseUnits: "10000000",
45
+ },
46
+ mandate: {
47
+ validFrom: now - 60,
48
+ expiresAt: now + 30 * 86400,
49
+ approvalExpiresAt: now + 3600,
50
+ },
51
+ gas: {
52
+ maxPerActionWei: "20000000000000",
53
+ maxTotalWei: "200000000000000",
54
+ expiresAt: now + 30 * 86400,
55
+ chargeableOutcomesMask: 1,
56
+ },
57
+ });
58
+
59
+ // Browser
60
+ import { signPreparedGasPolicy } from "@gol/sdk";
61
+ const call = await signPreparedGasPolicy(walletClient, prepared, {
62
+ agent,
63
+ recipients: [merchant],
64
+ });
65
+ const hash = await walletClient.sendTransaction(call);
66
+ ```
67
+
68
+ ## Webhooks
69
+
70
+ Create an endpoint with `createWebhookEndpoint` (or in the console) and store the returned `whsec_` secret. Deliveries are signed, at least once, and may arrive out of order; deduplicate by event ID and treat polling as authoritative.
71
+
72
+ ```ts
73
+ import { verifyWebhook } from "@gol/sdk/server";
74
+ const event = verifyWebhook(
75
+ rawBody,
76
+ request.headers,
77
+ process.env.GOL_WEBHOOK_SECRET!,
78
+ );
79
+ ```
80
+
81
+ ## Owner signing details
82
+
83
+ Each family's owner path is fixed: Safe `SafeMessage` under the account's domain, Nexus ERC-7739 `PersonalSign` with the K1 validator prefix, Kernel `Kernel(bytes32 hash)` with the root locator, and Alchemy `ReplaySafeHash` with the entity-zero prefix. `buildWalletSigningPayload` and `verifyWalletSigningPayload` expose them. The SDK never signs a raw hash with `personal_sign` for an approval, and never receives an owner key. Owner user operations for Nexus, Kernel, and Alchemy are signed with `personal_sign` over the EntryPoint v0.7 user operation hash. An Alchemy account can hold one GOL validation at entity 1; remove an earlier GOL core with `preparePermanentRemoval` before installing this one.
84
+
85
+ The encoders are checked against the independent Python reference vectors in `contracts/tools/encoding/gol_encoding.py`, and `pnpm verify:owner-fork` drives installation, approval, relayed and direct pause and resume, and both revocation paths for the four families on an anvil fork of Base Sepolia.
16
86
 
17
87
  ## API key authentication
18
88
 
@@ -55,6 +125,7 @@ const projects = await gol.listProjects();
55
125
  ```sh
56
126
  pnpm install --frozen-lockfile
57
127
  pnpm sync:openapi
128
+ pnpm verify:gas-encoding
58
129
  pnpm generate:check
59
130
  pnpm upstream:check
60
131
  pnpm typecheck
@@ -62,9 +133,12 @@ pnpm lint
62
133
  pnpm test
63
134
  pnpm build
64
135
  pnpm verify:pack
136
+ pnpm verify:account-dialects
65
137
  pnpm format:check
66
138
  ```
67
139
 
140
+ `pnpm upstream:check` and `pnpm verify:gas-encoding` need sibling `platform` and `contracts` checkouts. `pnpm verify:account-dialects` reads Base Sepolia over RPC, using `BASE_SEPOLIA_RPC_URL`, else an Alchemy endpoint built from `ALCHEMY_API_KEY`, else the public endpoint. CI runs `generate:check`, `typecheck`, `lint`, `test`, `format:check`, and `verify:pack` on Node.js 22; it does not run the sibling or RPC checks.
141
+
68
142
  `openapi/platform.json` is a versioned snapshot of the platform contract. `pnpm sync:openapi` refreshes the snapshot from `../platform/openapi/openapi.json` by default and regenerates TypeScript declarations. Set `GOL_PLATFORM_OPENAPI_PATH` when the platform repository is elsewhere.
69
143
 
70
144
  `pnpm verify:pack` builds and packs the SDK, installs the archive into a temporary clean consumer, checks both package entry points, runs the compiled consumer, and deletes the temporary files. It does not publish the package.
@@ -0,0 +1,33 @@
1
+ import { type Address, type Hex, type PublicClient } from "viem";
2
+ /** Candidate Base Sepolia dialects. An Active compatibility profile is still required. */
3
+ export type AccountFamily = "safe" | "nexus" | "kernel" | "alchemy";
4
+ export declare const BASE_SEPOLIA_CHAIN_ID = 84532;
5
+ export declare const ERC1967_IMPLEMENTATION_SLOT: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
6
+ type AccountReader = Pick<PublicClient, "getChainId" | "getBytecode" | "getStorageAt" | "readContract">;
7
+ /** Read a fixed block for a consistent preflight. Call before each owner approval and agent submission. */
8
+ export declare function assertAccountImplementation(client: AccountReader, family: AccountFamily, account: Address, blockNumber?: bigint): Promise<void>;
9
+ /** The owner signs this hash with its wallet. The SDK never accepts an owner key. */
10
+ export declare function ownerSigningHash(client: AccountReader, family: AccountFamily, account: Address, digest: Hex): Promise<Hex>;
11
+ /** Safety digests remain preparable after implementation drift. This does not grant authority. */
12
+ export declare function ownerSafetySigningHash(client: AccountReader, family: AccountFamily, account: Address, digest: Hex): Promise<Hex>;
13
+ /** Preserve a Safe threshold payload or pack the reviewed single-owner dialect. */
14
+ export declare function packOwnerSignature(family: AccountFamily, signature: Hex): Hex;
15
+ /** EntryPoint v0.7 nonce key for owner UserOperations. Safe has no selected UserOperation path. */
16
+ export declare function ownerUserOpNonceKey(family: Exclude<AccountFamily, "safe">): bigint;
17
+ export declare function ownerUserOpSigningHash(family: Exclude<AccountFamily, "safe">, userOpHash: Hex): Hex;
18
+ export declare function packOwnerUserOpSignature(family: Exclude<AccountFamily, "safe">, signature: Hex): Hex;
19
+ export type OwnerAccountCall = {
20
+ to: Address;
21
+ data: Hex;
22
+ /** Safe must delegatecall MultiSendCallOnly. Other calls target the account itself. */
23
+ operation: 0 | 1;
24
+ };
25
+ /** Prepare account self-call calldata after a fresh implementation preflight. */
26
+ export declare function prepareOwnerInstallation(client: AccountReader, family: AccountFamily, account: Address, core: Address, entityId?: number): Promise<OwnerAccountCall>;
27
+ /** Prepare tested invalidate-then-remove calldata, including after slot drift. The owner must authorize it. */
28
+ export declare function preparePermanentRemoval(client: AccountReader, family: AccountFamily, account: Address, core: Address, options?: {
29
+ safePreviousModule?: Address;
30
+ alchemyEntityId?: number;
31
+ }): Promise<OwnerAccountCall>;
32
+ export {};
33
+ //# sourceMappingURL=account-dialects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-dialects.d.ts","sourceRoot":"","sources":["../src/account-dialects.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AG,CAUL;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,EACtC,SAAS,EAAE,GAAG,GACb,GAAG,CAGL;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,uFAAuF;IACvF,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;CAClB,CAAC;AAqCF,iFAAiF;AACjF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,OAAO,EACb,QAAQ,SAAI,GACX,OAAO,CAAC,gBAAgB,CAAC,CAuD3B;AAYD,+GAA+G;AAC/G,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,OAAO,EACb,OAAO,GAAE;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAO,GACvE,OAAO,CAAC,gBAAgB,CAAC,CA8G3B"}
@@ -0,0 +1,386 @@
1
+ import { concatHex, encodeAbiParameters, encodeFunctionData, keccak256, padHex, size, stringToHex, } from "viem";
2
+ export const BASE_SEPOLIA_CHAIN_ID = 84532;
3
+ export const ERC1967_IMPLEMENTATION_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
4
+ const SAFE_PROXY_HASH = "0xd7d408ebcd99b2b70be43e20253d6d92a8ea8fab29bd3be7f55b10032331fb4c";
5
+ const ERC1967_PROXY_HASH = "0xaaa52c8cc8a0e3fd27ce756cc6b4e70c51423e9b597b11f32d3e49f8b1fc890d";
6
+ const IMPLEMENTATION = {
7
+ safe: "0x29fcB43b46531BcA003ddC8FCB67FFE91900C762",
8
+ nexus: "0x000000039dfcAd030719B07296710F045F0558f7",
9
+ kernel: "0xBAC849bB641841b44E965fB01A4Bf5F074f84b4D",
10
+ alchemy: "0x00000000000002377B26b1EdA7b0BC371C60DD4f",
11
+ };
12
+ const OWNER_PREFIX = {
13
+ safe: "0x",
14
+ nexus: "0x00000004171351c442b202678c48d8ab5b321e8f",
15
+ kernel: "0x00",
16
+ alchemy: "0x0100000000ff00",
17
+ };
18
+ const EIP712_DOMAIN_TYPEHASH = keccak256(stringToHex("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"));
19
+ const SAFE_MESSAGE_TYPEHASH = keccak256(stringToHex("SafeMessage(bytes message)"));
20
+ const NEXUS_PERSONAL_SIGN_TYPEHASH = keccak256(stringToHex("PersonalSign(bytes prefixed)"));
21
+ const KERNEL_WRAPPER_TYPEHASH = "0x1547321c374afde8a591d972a084b071c594c275e36724931ff96c25f2999c83";
22
+ const ALCHEMY_OWNER_MODULE = "0x00000000000099DE0BF6fA90dEB851E2A2df7d83";
23
+ const domainAbi = [
24
+ {
25
+ type: "function",
26
+ name: "eip712Domain",
27
+ stateMutability: "view",
28
+ inputs: [],
29
+ outputs: [
30
+ { type: "bytes1" },
31
+ { type: "string" },
32
+ { type: "string" },
33
+ { type: "uint256" },
34
+ { type: "address" },
35
+ { type: "bytes32" },
36
+ { type: "uint256[]" },
37
+ ],
38
+ },
39
+ ];
40
+ /** Read a fixed block for a consistent preflight. Call before each owner approval and agent submission. */
41
+ export async function assertAccountImplementation(client, family, account, blockNumber) {
42
+ const chainId = await client.getChainId();
43
+ if (chainId !== BASE_SEPOLIA_CHAIN_ID)
44
+ throw new Error("wrong_chain");
45
+ const code = await client.getBytecode({ address: account, blockNumber });
46
+ if (!code ||
47
+ keccak256(code) !==
48
+ (family === "safe" ? SAFE_PROXY_HASH : ERC1967_PROXY_HASH)) {
49
+ throw new Error("account_proxy_mismatch");
50
+ }
51
+ const slot = await client.getStorageAt({
52
+ address: account,
53
+ slot: family === "safe" ? `0x${"00".repeat(32)}` : ERC1967_IMPLEMENTATION_SLOT,
54
+ blockNumber,
55
+ });
56
+ if (!slot || slot.length !== 66)
57
+ throw new Error("account_implementation_unavailable");
58
+ const actual = `0x${slot.slice(-40)}`.toLowerCase();
59
+ if (actual !== IMPLEMENTATION[family].toLowerCase()) {
60
+ throw new Error("account_implementation_mismatch");
61
+ }
62
+ }
63
+ /** The owner signs this hash with its wallet. The SDK never accepts an owner key. */
64
+ export async function ownerSigningHash(client, family, account, digest) {
65
+ if (digest.length !== 66)
66
+ throw new Error("invalid_digest");
67
+ await assertAccountImplementation(client, family, account);
68
+ return accountSigningHash(client, family, account, digest);
69
+ }
70
+ /** Safety digests remain preparable after implementation drift. This does not grant authority. */
71
+ export async function ownerSafetySigningHash(client, family, account, digest) {
72
+ if ((await client.getChainId()) !== BASE_SEPOLIA_CHAIN_ID)
73
+ throw new Error("wrong_chain");
74
+ if (digest.length !== 66)
75
+ throw new Error("invalid_digest");
76
+ return accountSigningHash(client, family, account, digest);
77
+ }
78
+ async function accountSigningHash(client, family, account, digest) {
79
+ if (family === "alchemy") {
80
+ return client.readContract({
81
+ address: ALCHEMY_OWNER_MODULE,
82
+ abi: [
83
+ {
84
+ type: "function",
85
+ name: "replaySafeHash",
86
+ stateMutability: "view",
87
+ inputs: [{ type: "address" }, { type: "bytes32" }],
88
+ outputs: [{ type: "bytes32" }],
89
+ },
90
+ ],
91
+ functionName: "replaySafeHash",
92
+ args: [account, digest],
93
+ });
94
+ }
95
+ let domain;
96
+ if (family === "safe") {
97
+ domain = await client.readContract({
98
+ address: account,
99
+ abi: [
100
+ {
101
+ type: "function",
102
+ name: "domainSeparator",
103
+ stateMutability: "view",
104
+ inputs: [],
105
+ outputs: [{ type: "bytes32" }],
106
+ },
107
+ ],
108
+ functionName: "domainSeparator",
109
+ });
110
+ const message = keccak256(encodeAbiParameters([{ type: "bytes32" }], [digest]));
111
+ const structHash = keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "bytes32" }], [SAFE_MESSAGE_TYPEHASH, message]));
112
+ return keccak256(concatHex(["0x1901", domain, structHash]));
113
+ }
114
+ const [, name, version] = await client.readContract({
115
+ address: account,
116
+ abi: domainAbi,
117
+ functionName: "eip712Domain",
118
+ });
119
+ domain = keccak256(encodeAbiParameters([
120
+ { type: "bytes32" },
121
+ { type: "bytes32" },
122
+ { type: "bytes32" },
123
+ { type: "uint256" },
124
+ { type: "address" },
125
+ ], [
126
+ EIP712_DOMAIN_TYPEHASH,
127
+ keccak256(stringToHex(name)),
128
+ keccak256(stringToHex(version)),
129
+ 84532n,
130
+ account,
131
+ ]));
132
+ const structHash = keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "bytes32" }], [
133
+ family === "nexus"
134
+ ? NEXUS_PERSONAL_SIGN_TYPEHASH
135
+ : KERNEL_WRAPPER_TYPEHASH,
136
+ digest,
137
+ ]));
138
+ return keccak256(concatHex(["0x1901", domain, structHash]));
139
+ }
140
+ /** Preserve a Safe threshold payload or pack the reviewed single-owner dialect. */
141
+ export function packOwnerSignature(family, signature) {
142
+ if (family === "safe") {
143
+ // Safe checkSignatures enforces its own threshold and accepts assembled
144
+ // multisignature payloads, including contract-signature offsets. Preserve
145
+ // the wallet's exact bytes instead of imposing a one-owner ECDSA shape.
146
+ if (!/^0x(?:[0-9a-fA-F]{2})+$/.test(signature) || size(signature) > 4096)
147
+ throw new Error("invalid_safe_owner_signatures");
148
+ return signature;
149
+ }
150
+ return concatHex([OWNER_PREFIX[family], plainOwnerEcdsa(signature)]);
151
+ }
152
+ function plainOwnerEcdsa(signature) {
153
+ if (!/^0x[0-9a-fA-F]{130}$/.test(signature))
154
+ throw new Error("invalid_owner_signature");
155
+ const v = Number.parseInt(signature.slice(-2), 16);
156
+ if (v !== 27 && v !== 28)
157
+ throw new Error("invalid_owner_signature_v");
158
+ return signature;
159
+ }
160
+ /** EntryPoint v0.7 nonce key for owner UserOperations. Safe has no selected UserOperation path. */
161
+ export function ownerUserOpNonceKey(family) {
162
+ return family === "nexus"
163
+ ? BigInt(OWNER_PREFIX.nexus)
164
+ : family === "alchemy"
165
+ ? 1n
166
+ : 0n;
167
+ }
168
+ export function ownerUserOpSigningHash(family, userOpHash) {
169
+ if (userOpHash.length !== 66)
170
+ throw new Error("invalid_user_op_hash");
171
+ return family === "alchemy"
172
+ ? keccak256(concatHex([
173
+ stringToHex("\x19Ethereum Signed Message:\n32"),
174
+ userOpHash,
175
+ ]))
176
+ : userOpHash;
177
+ }
178
+ export function packOwnerUserOpSignature(family, signature) {
179
+ const plain = plainOwnerEcdsa(signature);
180
+ return family === "alchemy" ? concatHex(["0xff00", plain]) : plain;
181
+ }
182
+ const SAFE_MULTISEND_CALL_ONLY = "0x9641d764fc13c8B624c04430C7356C1C7C8102e2";
183
+ const moduleAbi = [
184
+ {
185
+ type: "function",
186
+ name: "installModule",
187
+ stateMutability: "nonpayable",
188
+ inputs: [{ type: "uint256" }, { type: "address" }, { type: "bytes" }],
189
+ outputs: [],
190
+ },
191
+ {
192
+ type: "function",
193
+ name: "uninstallModule",
194
+ stateMutability: "nonpayable",
195
+ inputs: [{ type: "uint256" }, { type: "address" }, { type: "bytes" }],
196
+ outputs: [],
197
+ },
198
+ ];
199
+ const invalidateAbi = [
200
+ {
201
+ type: "function",
202
+ name: "invalidateAccountMandates",
203
+ stateMutability: "nonpayable",
204
+ inputs: [{ type: "address" }, { type: "uint48" }, { type: "bytes" }],
205
+ outputs: [],
206
+ },
207
+ ];
208
+ function alchemyEntityId(entityId) {
209
+ if (!Number.isInteger(entityId) || entityId < 0 || entityId > 0xffffffff) {
210
+ throw new Error("invalid_alchemy_entity_id");
211
+ }
212
+ return `0x${entityId.toString(16).padStart(8, "0")}`;
213
+ }
214
+ /** Prepare account self-call calldata after a fresh implementation preflight. */
215
+ export async function prepareOwnerInstallation(client, family, account, core, entityId = 1) {
216
+ await assertAccountImplementation(client, family, account);
217
+ let data;
218
+ if (family === "safe") {
219
+ data = encodeFunctionData({
220
+ abi: [
221
+ {
222
+ type: "function",
223
+ name: "enableModule",
224
+ stateMutability: "nonpayable",
225
+ inputs: [{ type: "address" }],
226
+ outputs: [],
227
+ },
228
+ ],
229
+ functionName: "enableModule",
230
+ args: [core],
231
+ });
232
+ }
233
+ else if (family === "nexus" || family === "kernel") {
234
+ const init = family === "nexus"
235
+ ? "0x"
236
+ : concatHex([
237
+ padHex("0x", { size: 20 }),
238
+ encodeAbiParameters([{ type: "bytes" }, { type: "bytes" }], ["0x", "0x"]),
239
+ ]);
240
+ data = encodeFunctionData({
241
+ abi: moduleAbi,
242
+ functionName: "installModule",
243
+ args: [2n, core, init],
244
+ });
245
+ }
246
+ else {
247
+ const config = concatHex([core, alchemyEntityId(entityId), "0x04"]);
248
+ data = encodeFunctionData({
249
+ abi: [
250
+ {
251
+ type: "function",
252
+ name: "installValidation",
253
+ stateMutability: "nonpayable",
254
+ inputs: [
255
+ { type: "bytes25" },
256
+ { type: "bytes4[]" },
257
+ { type: "bytes" },
258
+ { type: "bytes[]" },
259
+ ],
260
+ outputs: [],
261
+ },
262
+ ],
263
+ functionName: "installValidation",
264
+ args: [config, [], "0x01", []],
265
+ });
266
+ }
267
+ return { to: account, data: data.toLowerCase(), operation: 0 };
268
+ }
269
+ function multiSendTransaction(to, data) {
270
+ return concatHex([
271
+ "0x00",
272
+ to,
273
+ padHex("0x", { size: 32 }),
274
+ padHex(`0x${size(data).toString(16)}`, { size: 32 }),
275
+ data,
276
+ ]);
277
+ }
278
+ /** Prepare tested invalidate-then-remove calldata, including after slot drift. The owner must authorize it. */
279
+ export async function preparePermanentRemoval(client, family, account, core, options = {}) {
280
+ if ((await client.getChainId()) !== BASE_SEPOLIA_CHAIN_ID)
281
+ throw new Error("wrong_chain");
282
+ const invalidate = encodeFunctionData({
283
+ abi: invalidateAbi,
284
+ functionName: "invalidateAccountMandates",
285
+ args: [account, 0, "0x"],
286
+ });
287
+ if (family === "safe") {
288
+ if (!options.safePreviousModule)
289
+ throw new Error("safe_previous_module_required");
290
+ const disable = encodeFunctionData({
291
+ abi: [
292
+ {
293
+ type: "function",
294
+ name: "disableModule",
295
+ stateMutability: "nonpayable",
296
+ inputs: [{ type: "address" }, { type: "address" }],
297
+ outputs: [],
298
+ },
299
+ ],
300
+ functionName: "disableModule",
301
+ args: [options.safePreviousModule, core],
302
+ });
303
+ const payload = concatHex([
304
+ multiSendTransaction(core, invalidate),
305
+ multiSendTransaction(account, disable),
306
+ ]);
307
+ const data = encodeFunctionData({
308
+ abi: [
309
+ {
310
+ type: "function",
311
+ name: "multiSend",
312
+ stateMutability: "payable",
313
+ inputs: [{ type: "bytes" }],
314
+ outputs: [],
315
+ },
316
+ ],
317
+ functionName: "multiSend",
318
+ args: [payload],
319
+ });
320
+ return {
321
+ to: SAFE_MULTISEND_CALL_ONLY,
322
+ data: data.toLowerCase(),
323
+ operation: 1,
324
+ };
325
+ }
326
+ if (family === "alchemy") {
327
+ const config = concatHex([
328
+ core,
329
+ alchemyEntityId(options.alchemyEntityId ?? 1),
330
+ ]);
331
+ const uninstall = encodeFunctionData({
332
+ abi: [
333
+ {
334
+ type: "function",
335
+ name: "uninstallValidation",
336
+ stateMutability: "nonpayable",
337
+ inputs: [{ type: "bytes24" }, { type: "bytes" }, { type: "bytes[]" }],
338
+ outputs: [],
339
+ },
340
+ ],
341
+ functionName: "uninstallValidation",
342
+ args: [config, "0x", []],
343
+ });
344
+ const data = encodeFunctionData({
345
+ abi: [
346
+ {
347
+ type: "function",
348
+ name: "executeBatch",
349
+ stateMutability: "nonpayable",
350
+ inputs: [
351
+ {
352
+ type: "tuple[]",
353
+ components: [
354
+ { type: "address" },
355
+ { type: "uint256" },
356
+ { type: "bytes" },
357
+ ],
358
+ },
359
+ ],
360
+ outputs: [],
361
+ },
362
+ ],
363
+ functionName: "executeBatch",
364
+ args: [
365
+ [
366
+ [core, 0n, invalidate],
367
+ [account, 0n, uninstall],
368
+ ],
369
+ ],
370
+ });
371
+ return { to: account, data: data.toLowerCase(), operation: 0 };
372
+ }
373
+ const deinit = family === "nexus"
374
+ ? encodeAbiParameters([{ type: "address" }, { type: "bytes" }], ["0x0000000000000000000000000000000000000001", "0x"])
375
+ : "0x";
376
+ return {
377
+ to: account,
378
+ data: encodeFunctionData({
379
+ abi: moduleAbi,
380
+ functionName: "uninstallModule",
381
+ args: [2n, core, deinit],
382
+ }).toLowerCase(),
383
+ operation: 0,
384
+ };
385
+ }
386
+ //# sourceMappingURL=account-dialects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-dialects.js","sourceRoot":"","sources":["../src/account-dialects.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,MAAM,EACN,IAAI,EACJ,WAAW,GAIZ,MAAM,MAAM,CAAC;AAKd,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,2BAA2B,GACtC,oEAA6E,CAAC;AAEhF,MAAM,eAAe,GACnB,oEAAoE,CAAC;AACvE,MAAM,kBAAkB,GACtB,oEAAoE,CAAC;AACvE,MAAM,cAAc,GAAmC;IACrD,IAAI,EAAE,4CAA4C;IAClD,KAAK,EAAE,4CAA4C;IACnD,MAAM,EAAE,4CAA4C;IACpD,OAAO,EAAE,4CAA4C;CACtD,CAAC;AACF,MAAM,YAAY,GAA+B;IAC/C,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,4CAA4C;IACnD,MAAM,EAAE,MAAM;IACd,OAAO,EAAE,kBAAkB;CAC5B,CAAC;AACF,MAAM,sBAAsB,GAAG,SAAS,CACtC,WAAW,CACT,oFAAoF,CACrF,CACF,CAAC;AACF,MAAM,qBAAqB,GAAG,SAAS,CACrC,WAAW,CAAC,4BAA4B,CAAC,CAC1C,CAAC;AACF,MAAM,4BAA4B,GAAG,SAAS,CAC5C,WAAW,CAAC,8BAA8B,CAAC,CAC5C,CAAC;AACF,MAAM,uBAAuB,GAC3B,oEAA6E,CAAC;AAChF,MAAM,oBAAoB,GACxB,4CAA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,IAAI,EAAE,IAAI,CAAC,WAAW,EAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACxE,CAAC;IACD,MAAM,MAAM,GACV,MAAM,KAAK,OAAO;QAChB,CAAC,CAAC,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACxC,CAAC,4CAA4C,EAAE,IAAI,CAAC,CACrD;QACH,CAAC,CAAC,IAAI,CAAC;IACX,OAAO;QACL,EAAE,EAAE,OAAO;QACX,IAAI,EAAE,kBAAkB,CAAC;YACvB,GAAG,EAAE,SAAS;YACd,YAAY,EAAE,iBAAiB;YAC/B,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC;SACzB,CAAC,CAAC,WAAW,EAAS;QACvB,SAAS,EAAE,CAAC;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { type Address, type Hex, type PublicClient } from "viem";
2
+ import { type AccountFamily } from "./account-dialects.js";
3
+ export interface GasMandateTerms {
4
+ parentId: Hex;
5
+ account: Address;
6
+ agent: Address;
7
+ accountProfileId: Hex;
8
+ installEpoch: bigint;
9
+ projectId: Hex;
10
+ mode: number;
11
+ policyVersion: number;
12
+ policyHash: Hex;
13
+ validFrom: number;
14
+ expiresAt: number;
15
+ maxDepth: number;
16
+ maxActiveDescendants: number;
17
+ approvalExpiresAt: number;
18
+ salt: Hex;
19
+ }
20
+ export interface OwnerGasPolicy {
21
+ mandateId: Hex;
22
+ account: Address;
23
+ projectId: Hex;
24
+ accountProfileId: Hex;
25
+ installEpoch: bigint;
26
+ /** Version 1 supports native ETH only. */
27
+ feeAsset: Address;
28
+ recipient: Address;
29
+ attester: Address;
30
+ maxPerAction: bigint;
31
+ maxTotal: bigint;
32
+ expiresAt: number;
33
+ /** 1 = success, 2 = refusal, 4 = revert. */
34
+ chargeableOutcomes: number;
35
+ formulaVersion: number;
36
+ nonce: bigint;
37
+ }
38
+ export interface CombinedGasApproval {
39
+ mandateId: Hex;
40
+ gasPolicyId: Hex;
41
+ digest: Hex;
42
+ ownerSigningHash: Hex;
43
+ summary: {
44
+ chainId: number;
45
+ account: Address;
46
+ core: Address;
47
+ projectId: Hex;
48
+ agent: Address;
49
+ recipient: Address;
50
+ attester: Address;
51
+ feeAsset: Address;
52
+ maxPerActionWei: bigint;
53
+ maxTotalWei: bigint;
54
+ chargeableOutcomes: number;
55
+ expiresAt: number;
56
+ };
57
+ encodeSubmission(ownerWalletSignature: Hex): Hex;
58
+ }
59
+ export interface PreparedGasRevocation {
60
+ account: Address;
61
+ policyId: Hex;
62
+ nonce: bigint;
63
+ deadline: number;
64
+ digest: Hex;
65
+ ownerSigningHash: Hex;
66
+ encodeSubmission(ownerWalletSignature: Hex): Hex;
67
+ }
68
+ export declare function hashGasMandate(terms: GasMandateTerms, chainId: number, core: Address): Hex;
69
+ export declare function hashOwnerGasPolicy(policy: OwnerGasPolicy, chainId: number, core: Address): Hex;
70
+ /** Internal parity point for the existing v2 combined owner commitment. */
71
+ export declare function hashCombinedGasApproval(mandateId: Hex, gasPolicyId: Hex, chainId: number, core: Address): Hex;
72
+ /** Internal parity point for the existing v2 owner safety commitment. */
73
+ export declare function hashGasRevocation(gasPolicyId: Hex, nonce: bigint, deadline: number, chainId: number, core: Address): Hex;
74
+ /** Prepare one owner signature after the account installation has been verified. */
75
+ export declare function prepareCombinedGasApproval(client: Pick<PublicClient, "getChainId" | "getBytecode" | "getStorageAt" | "readContract">, family: AccountFamily, chainId: number, core: Address, terms: GasMandateTerms, mandatePolicy: Hex, gasPolicy: OwnerGasPolicy): Promise<CombinedGasApproval>;
76
+ /** Bind a platform project UUID before any owner signing request is prepared. */
77
+ export declare function prepareProjectBoundGasApproval(client: Parameters<typeof prepareCombinedGasApproval>[0], family: AccountFamily, chainId: number, core: Address, projectUuid: string, terms: GasMandateTerms, mandatePolicy: Hex, gasPolicy: OwnerGasPolicy): Promise<CombinedGasApproval>;
78
+ /** Owner safety action. It remains preparable after an account implementation drift. */
79
+ export declare function prepareGasRevocation(client: Pick<PublicClient, "getChainId" | "getBytecode" | "getStorageAt" | "readContract">, family: AccountFamily, chainId: number, core: Address, account: Address, policyId: Hex, deadline: number): Promise<PreparedGasRevocation>;
80
+ //# sourceMappingURL=gas-approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-approval.d.ts","sourceRoot":"","sources":["../src/gas-approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAEd,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AA2B/B,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,gBAAgB,EAAE,GAAG,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,GAAG,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,GAAG,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,GAAG,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,GAAG,CAAC;IACf,gBAAgB,EAAE,GAAG,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,Y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