kokio-sdk 0.0.1 → 0.0.3
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/package.json +5 -1
- package/src/abis/index.ts +9 -9
- package/src/config.ts +25 -18
- package/src/interface/constantsClass.ts +2 -1
- package/src/interface/deviceWalletClass.ts +1 -1
- package/src/interface/deviceWalletFactoryClass.ts +1 -1
- package/src/interface/eSIMWalletClass.ts +1 -1
- package/src/interface/eSIMWalletFactoryClass.ts +1 -1
- package/src/interface/lazyWalletRegistryClass.ts +1 -1
- package/src/interface/smartAccountClass.ts +5 -3
- package/src/logic/P256Verifier.ts +3 -1
- package/src/logic/account-kit/createSmartAccount.ts +33 -18
- package/src/logic/constants.ts +18 -32
- package/src/logic/deviceWallet.ts +1 -4
- package/src/logic/deviceWalletFactory.ts +10 -3
- package/src/logic/eSIMWalletFactory.ts +14 -4
- package/src/logic/lazyWalletRegistry.ts +16 -4
- package/src/logic/utils.ts +1 -1
- package/src/types-export.ts +7 -0
- package/.env.example +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kokio-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/config.js",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
"import": "./dist/esm/config.js",
|
|
11
11
|
"default": "./dist/esm/config.js"
|
|
12
12
|
},
|
|
13
|
+
"./types": {
|
|
14
|
+
"types": "./dist/types/types-export.d.ts",
|
|
15
|
+
"import": "./dist/esm/types.js"
|
|
16
|
+
},
|
|
13
17
|
"./package.json": "./package.json"
|
|
14
18
|
},
|
|
15
19
|
"scripts": {
|
package/src/abis/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import DeviceWallet from './DeviceWallet.json'
|
|
2
|
-
import DeviceWalletFactory from './DeviceWalletFactory.json'
|
|
3
|
-
import ESIMWallet from './ESIMWallet.json'
|
|
4
|
-
import ESIMWalletFactory from './ESIMWalletFactory.json'
|
|
5
|
-
import LazyWalletRegistry from './LazyWalletRegistry.json'
|
|
6
|
-
import P256Verifier from './P256Verifier.json'
|
|
7
|
-
import Registry from './Registry.json'
|
|
8
|
-
import RegistryHelper from './RegistryHelper.json'
|
|
9
|
-
import BeaconProxy from './BeaconProxy.json'
|
|
1
|
+
import DeviceWallet from './DeviceWallet.json' with { type: 'json' };
|
|
2
|
+
import DeviceWalletFactory from './DeviceWalletFactory.json' with { type: 'json' };
|
|
3
|
+
import ESIMWallet from './ESIMWallet.json' with { type: 'json' };
|
|
4
|
+
import ESIMWalletFactory from './ESIMWalletFactory.json' with { type: 'json' };
|
|
5
|
+
import LazyWalletRegistry from './LazyWalletRegistry.json' with { type: 'json' };
|
|
6
|
+
import P256Verifier from './P256Verifier.json' with { type: 'json' };
|
|
7
|
+
import Registry from './Registry.json' with { type: 'json' };
|
|
8
|
+
import RegistryHelper from './RegistryHelper.json' with { type: 'json' };
|
|
9
|
+
import BeaconProxy from './BeaconProxy.json' with { type: 'json' }
|
|
10
10
|
|
|
11
11
|
export {
|
|
12
12
|
DeviceWallet,
|
package/src/config.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Address, WalletClient } from "viem";
|
|
2
2
|
import { ConstantsSubPackage } from "./interface/constantsClass.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { SmartAccountSubPackage } from "./interface/smartAccountClass.js";
|
|
4
|
+
import { DeviceWalletFactorySubPackage } from "./interface/deviceWalletFactoryClass.js";
|
|
5
5
|
import { P256VerifierSubPackage } from "./interface/P256VerifierClass.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { LazyWalletRegistrySubPackage } from "./interface/lazyWalletRegistryClass.js";
|
|
7
|
+
import { DeviceWalletSubPackage } from "./interface/deviceWalletClass.js";
|
|
8
|
+
import { ESIMWalletSubPackage } from "./interface/eSIMWalletClass.js";
|
|
9
|
+
import { ESIMWalletFactorySubPackage } from "./interface/eSIMWalletFactoryClass.js";
|
|
10
10
|
import { SmartAccountClient } from "@aa-sdk/core";
|
|
11
11
|
import { TurnkeyClient } from "@turnkey/http";
|
|
12
12
|
|
|
@@ -14,19 +14,23 @@ export class Kokio {
|
|
|
14
14
|
viemWalletClient: WalletClient;
|
|
15
15
|
turnkeyClient: TurnkeyClient;
|
|
16
16
|
organizationId: string;
|
|
17
|
+
gasPolicyId: string;
|
|
18
|
+
|
|
17
19
|
constants: ConstantsSubPackage;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
|
|
21
|
+
smartAccount: SmartAccountSubPackage;
|
|
22
|
+
deviceWalletFactory?: DeviceWalletFactorySubPackage;
|
|
23
|
+
eSIMWalletFactory?: ESIMWalletFactorySubPackage;
|
|
24
|
+
lazyWalletRegistry?: LazyWalletRegistrySubPackage;
|
|
25
|
+
deviceWallet?: DeviceWalletSubPackage;
|
|
26
|
+
eSIMWallet?: ESIMWalletSubPackage;
|
|
24
27
|
P256Verifier?: P256VerifierSubPackage;
|
|
25
28
|
|
|
26
29
|
constructor(
|
|
27
30
|
viemWalletClient: WalletClient,
|
|
28
31
|
turnkeyClient: TurnkeyClient,
|
|
29
32
|
organizationId: string,
|
|
33
|
+
gasPolicyId: string,
|
|
30
34
|
smartAccountClient?: SmartAccountClient,
|
|
31
35
|
deviceWalletAddress?: Address,
|
|
32
36
|
eSIMWalletAddress?: Address
|
|
@@ -34,13 +38,16 @@ export class Kokio {
|
|
|
34
38
|
this.viemWalletClient = viemWalletClient;
|
|
35
39
|
this.turnkeyClient = turnkeyClient;
|
|
36
40
|
this.organizationId = organizationId;
|
|
41
|
+
this.gasPolicyId = gasPolicyId;
|
|
42
|
+
|
|
37
43
|
this.constants = new ConstantsSubPackage(this.viemWalletClient);
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
44
|
+
|
|
45
|
+
this.smartAccount = new SmartAccountSubPackage(this.viemWalletClient, this.turnkeyClient, this.organizationId, this.gasPolicyId);
|
|
46
|
+
this.deviceWalletFactory = smartAccountClient? new DeviceWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
|
|
47
|
+
this.eSIMWalletFactory = smartAccountClient? new ESIMWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
|
|
48
|
+
this.lazyWalletRegistry = smartAccountClient? new LazyWalletRegistrySubPackage(smartAccountClient): undefined;
|
|
42
49
|
this.P256Verifier = smartAccountClient? new P256VerifierSubPackage(smartAccountClient): undefined;
|
|
43
|
-
this.deviceWallet = deviceWalletAddress && smartAccountClient? new
|
|
44
|
-
this.eSIMWallet = eSIMWalletAddress && smartAccountClient? new
|
|
50
|
+
this.deviceWallet = deviceWalletAddress && smartAccountClient? new DeviceWalletSubPackage(viemWalletClient, smartAccountClient, deviceWalletAddress): undefined;
|
|
51
|
+
this.eSIMWallet = eSIMWalletAddress && smartAccountClient? new ESIMWalletSubPackage(smartAccountClient, eSIMWalletAddress): undefined;
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -24,7 +24,8 @@ export class ConstantsSubPackage {
|
|
|
24
24
|
constructor(client: WalletClient) {
|
|
25
25
|
(async () => {
|
|
26
26
|
const chainID = await _extractChainID(client);
|
|
27
|
-
const
|
|
27
|
+
const rpcURL = client.transport.url;
|
|
28
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
28
29
|
|
|
29
30
|
this.factoryAddresses = values?.factoryAddresses;
|
|
30
31
|
this.customErrors = values?.customErrors;
|
|
@@ -4,16 +4,18 @@ import { P256Key, SignedRequest } from "../types";
|
|
|
4
4
|
import { SmartAccountClient, SmartContractAccount } from "@aa-sdk/core";
|
|
5
5
|
import { TurnkeyClient } from "@turnkey/http";
|
|
6
6
|
|
|
7
|
-
export class
|
|
7
|
+
export class SmartAccountSubPackage {
|
|
8
8
|
|
|
9
9
|
client;
|
|
10
10
|
turnkeyClient;
|
|
11
11
|
organizationId;
|
|
12
|
+
gasPolicyId;
|
|
12
13
|
|
|
13
|
-
constructor(client: WalletClient, turnkeyClient: TurnkeyClient, organiationId: string) {
|
|
14
|
+
constructor(client: WalletClient, turnkeyClient: TurnkeyClient, organiationId: string, gasPolicyId: string) {
|
|
14
15
|
this.client = client;
|
|
15
16
|
this.turnkeyClient = turnkeyClient;
|
|
16
17
|
this.organizationId = organiationId;
|
|
18
|
+
this.gasPolicyId = gasPolicyId;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
getSmartWallet (deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint, sender?: Address) {
|
|
@@ -21,6 +23,6 @@ export class smartAccountSubPackage {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
getSmartWalletClient (account: SmartContractAccount) {
|
|
24
|
-
return _getSmartWalletClient(this.client, account)
|
|
26
|
+
return _getSmartWalletClient(this.client, this.gasPolicyId, account)
|
|
25
27
|
}
|
|
26
28
|
}
|
|
@@ -13,7 +13,9 @@ export const _verifySignature = async (
|
|
|
13
13
|
y: bigint
|
|
14
14
|
) => {
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const chainID = await client.getChainId();
|
|
17
|
+
const rpcURL = client.transport.url;
|
|
18
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
17
19
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
18
20
|
|
|
19
21
|
// UserOp
|
|
@@ -26,6 +26,7 @@ import { _add0x, _concatUint8Arrays, _remove0x, _shouldRemoveLeadingZero } from
|
|
|
26
26
|
import { P256Key, WebAuthnSignature } from "../../types.js";
|
|
27
27
|
import { DeviceWallet, DeviceWalletFactory } from "../../abis/index.js";
|
|
28
28
|
import { _signMessageWithTurnkey, _signTypedDataWithTurnkey } from "../services/turnkeyClient.js";
|
|
29
|
+
import { alchemyGasManagerMiddleware } from "@account-kit/infra";
|
|
29
30
|
|
|
30
31
|
const _encodeExecute = async (tx: AccountOp) => {
|
|
31
32
|
|
|
@@ -61,25 +62,27 @@ const _encodeBatchExecute = async (txs: AccountOp[]) => {
|
|
|
61
62
|
|
|
62
63
|
const _getAccountInitCode = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint): Promise<Hex> => {
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
// To send with user operations
|
|
66
|
+
const chainID = await client.getChainId();
|
|
67
|
+
const rpcURL = client.transport.url;
|
|
68
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const callData = encodeFunctionData({
|
|
71
|
+
abi: DeviceWalletFactory,
|
|
72
|
+
functionName: "createAccount",
|
|
73
|
+
args: [deviceUniqueIdentifier, deviceWalletOwnerKey, salt, ZERO],
|
|
74
|
+
})
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
return values.factoryAddresses.DEVICE_WALLET_FACTORY.concat(_remove0x(callData)) as Hex;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
const getInitCodeHash = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key): Promise<BytesLike> => {
|
|
78
80
|
|
|
79
81
|
const chainID = await client.getChainId();
|
|
80
|
-
const
|
|
82
|
+
const rpcURL = client.transport.url;
|
|
83
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
// off-chain computation of the DeviceWallet address
|
|
83
86
|
const registry = values.factoryAddresses.REGISTRY;
|
|
84
87
|
const deviceWalletFactoryAddress = values.factoryAddresses.DEVICE_WALLET_FACTORY;
|
|
85
88
|
|
|
@@ -133,7 +136,8 @@ const prepareSaltForCreate2 = (sender: Address, salt: BigInt): BytesLike => {
|
|
|
133
136
|
const getCounterFactualAddress = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: BigInt, sender?: Address):Promise<Hex> => {
|
|
134
137
|
|
|
135
138
|
const chainID = await client.getChainId();
|
|
136
|
-
const
|
|
139
|
+
const rpcURL = client.transport.url;
|
|
140
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
137
141
|
const deviceWalletFactoryAddress = values.factoryAddresses.DEVICE_WALLET_FACTORY;
|
|
138
142
|
|
|
139
143
|
sender = sender? sender : values.factoryAddresses.SENDER_CREATOR;
|
|
@@ -224,10 +228,19 @@ const _signUserOperationHash = async (hash: Hex, turnkeyClient: TurnkeyClient, o
|
|
|
224
228
|
return _signMessage(message, turnkeyClient, organiationId, signWith);
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
export const _getSmartWallet = async (
|
|
231
|
+
export const _getSmartWallet = async (
|
|
232
|
+
client: WalletClient,
|
|
233
|
+
turnkeyClient: TurnkeyClient,
|
|
234
|
+
organiationId: string,
|
|
235
|
+
deviceUniqueIdentifier: string,
|
|
236
|
+
deviceWalletOwnerKey: P256Key,
|
|
237
|
+
salt: bigint,
|
|
238
|
+
sender?: Address
|
|
239
|
+
): Promise<SmartContractAccount> => {
|
|
228
240
|
|
|
229
241
|
const chainID = await client.getChainId();
|
|
230
|
-
const
|
|
242
|
+
const rpcURL = client.transport.url;
|
|
243
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
231
244
|
|
|
232
245
|
if (!client.account) throw new Error ('Error: No signer account found with WalletClient')
|
|
233
246
|
const signWith = client.account.address;
|
|
@@ -240,14 +253,14 @@ export const _getSmartWallet = async (client: WalletClient, turnkeyClient: Turnk
|
|
|
240
253
|
chain: values.chain,
|
|
241
254
|
|
|
242
255
|
// The EntryPointDef that your account is compatible with
|
|
243
|
-
|
|
256
|
+
entryPoint: getEntryPoint(values.chain, {version: "0.7.0"}),
|
|
244
257
|
|
|
245
258
|
getAccountInitCode: async (): Promise<Hex> => await _getAccountInitCode(client, deviceUniqueIdentifier, deviceWalletOwnerKey, salt),
|
|
246
259
|
|
|
247
260
|
// getAccountInitCodeHash: async (): Promise<BytesLike> => await getInitCodeHash(client, deviceUniqueIdentifier, deviceWalletOwnerKey),
|
|
248
261
|
|
|
249
262
|
// an invalid signature that doesn't cause your account to revert during validation
|
|
250
|
-
getDummySignature: async (): Promise<Hash> => "
|
|
263
|
+
getDummySignature: async (): Promise<Hash> => "0x",
|
|
251
264
|
|
|
252
265
|
// given a UO in the form of {target, data, value} should output the calldata for calling your contract's execution method
|
|
253
266
|
encodeExecute: async (uo): Promise<Hash> => _encodeExecute(uo),
|
|
@@ -268,15 +281,17 @@ export const _getSmartWallet = async (client: WalletClient, turnkeyClient: Turnk
|
|
|
268
281
|
});
|
|
269
282
|
}
|
|
270
283
|
|
|
271
|
-
export const _getSmartWalletClient = async (client: WalletClient, account: SmartContractAccount) => {
|
|
284
|
+
export const _getSmartWalletClient = async (client: WalletClient, gasPolicyId: string, account: SmartContractAccount) => {
|
|
272
285
|
|
|
273
286
|
const chainID = await client.getChainId();
|
|
274
|
-
const
|
|
287
|
+
const rpcURL = client.transport.url;
|
|
288
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
275
289
|
|
|
276
290
|
return createSmartAccountClient({
|
|
277
291
|
// created above
|
|
278
292
|
account: account,
|
|
279
293
|
chain: values.chain,
|
|
280
294
|
transport: http(values.rpcURL),
|
|
295
|
+
...alchemyGasManagerMiddleware(gasPolicyId)
|
|
281
296
|
});
|
|
282
297
|
}
|
package/src/logic/constants.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
import { WalletClient } from "viem";
|
|
5
|
-
|
|
1
|
+
import { WalletClient, Address } from 'viem';
|
|
6
2
|
import {
|
|
7
3
|
mainnet,
|
|
8
4
|
sepolia,
|
|
@@ -14,8 +10,6 @@ import {
|
|
|
14
10
|
|
|
15
11
|
export const ZERO = BigInt('0');
|
|
16
12
|
|
|
17
|
-
export const API_KEY = process.env.API_KEY;
|
|
18
|
-
|
|
19
13
|
export enum CHAIN_ID {
|
|
20
14
|
MAINNET = 1,
|
|
21
15
|
SEPOLIA = 11155111,
|
|
@@ -25,15 +19,6 @@ export enum CHAIN_ID {
|
|
|
25
19
|
ARBITRUM_SEPOLIA = 421614,
|
|
26
20
|
}
|
|
27
21
|
|
|
28
|
-
export const rpcURLs: Record<string, string> = {
|
|
29
|
-
mainnet: `https://eth-mainnet.g.alchemy.com/v2/${API_KEY}`,
|
|
30
|
-
sepolia: `https://eth-sepolia.g.alchemy.com/v2/${API_KEY}`,
|
|
31
|
-
optimismMainnet : `https://opt-mainnet.g.alchemy.com/v2/${API_KEY}`,
|
|
32
|
-
optimismSepolia: `https://opt-sepolia.g.alchemy.com/v2/${API_KEY}`,
|
|
33
|
-
arbitrum: `https://arb-mainnet.g.alchemy.com/v2/${API_KEY}`,
|
|
34
|
-
arbitrumSepolia: `https://arb-sepolia.g.alchemy.com/v2/${API_KEY}`,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
22
|
export interface chainSpecifcConstants {
|
|
38
23
|
factoryAddresses:
|
|
39
24
|
typeof sepoliaFactoryAddresses |
|
|
@@ -53,17 +38,17 @@ export interface chainSpecifcConstants {
|
|
|
53
38
|
customErrors: typeof customErrors;
|
|
54
39
|
}
|
|
55
40
|
|
|
56
|
-
export const sepoliaFactoryAddresses: Record<string,
|
|
41
|
+
export const sepoliaFactoryAddresses: Record<string, Address> = {
|
|
57
42
|
DEVICE_WALLET_FACTORY: '0x63005d8214533fC7209678Aa39F7b9b0b51a7bcB',
|
|
58
43
|
ESIM_WALLET_FACTORY: '0xB4473979ff8cE4e09161B08f74EEb66BD7718076',
|
|
59
44
|
LAZY_WALLET_REGISTRY: '0x8a1E53b903efcc6b252CE4bD3b255202318505Ef',
|
|
60
45
|
REGISTRY: '0xCa447f5C75C57f6C59027304A5Fb5A09F0E005c9',
|
|
61
46
|
ENTRY_POINT: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
62
|
-
SENDER_CREATOR: '
|
|
47
|
+
SENDER_CREATOR: '0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c',
|
|
63
48
|
P256VERIFIER: '0xF04f3b3935aD461D17d4a8a78E7ea21d4a61AEb1'
|
|
64
49
|
}
|
|
65
50
|
|
|
66
|
-
export const mainnetFactoryAddresses: Record<string,
|
|
51
|
+
export const mainnetFactoryAddresses: Record<string, Address> = {
|
|
67
52
|
DEVICE_WALLET_FACTORY: '0x',
|
|
68
53
|
ESIM_WALLET_FACTORY: '0x',
|
|
69
54
|
LAZY_WALLET_REGISTRY: '0x',
|
|
@@ -73,7 +58,7 @@ export const mainnetFactoryAddresses: Record<string, `0x${string}`> = {
|
|
|
73
58
|
P256VERIFIER: '0x'
|
|
74
59
|
}
|
|
75
60
|
|
|
76
|
-
export const optimismMainnetFactoryAddresses: Record<string,
|
|
61
|
+
export const optimismMainnetFactoryAddresses: Record<string, Address> = {
|
|
77
62
|
DEVICE_WALLET_FACTORY: '0x',
|
|
78
63
|
ESIM_WALLET_FACTORY: '0x',
|
|
79
64
|
LAZY_WALLET_REGISTRY: '0x',
|
|
@@ -83,17 +68,17 @@ export const optimismMainnetFactoryAddresses: Record<string, `0x${string}`> = {
|
|
|
83
68
|
P256VERIFIER: '0x'
|
|
84
69
|
}
|
|
85
70
|
|
|
86
|
-
export const optimismSepoliaFactoryAddresses: Record<string,
|
|
71
|
+
export const optimismSepoliaFactoryAddresses: Record<string, Address> = {
|
|
87
72
|
DEVICE_WALLET_FACTORY: '0x3feA4dB0C0bBB73142d5bB6b776EE238884a3705',
|
|
88
73
|
ESIM_WALLET_FACTORY: '0xaD2Ba6248D0e6990a844C94ACE78F8775A68b631',
|
|
89
74
|
LAZY_WALLET_REGISTRY: '0x29b98C32D83604664fd0742b9112b0825a74849F',
|
|
90
75
|
REGISTRY: '0xaeB98F0f092fCb4a476ea3a5EB6A4B9E3D63A686',
|
|
91
|
-
ENTRY_POINT: '
|
|
92
|
-
SENDER_CREATOR: '
|
|
76
|
+
ENTRY_POINT: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
77
|
+
SENDER_CREATOR: '0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c',
|
|
93
78
|
P256VERIFIER: '0x5349aEA97Faa6D5d6D78A8847068300a4eC9D39E'
|
|
94
79
|
}
|
|
95
80
|
|
|
96
|
-
export const arbitrumOneFactoryAddresses: Record<string,
|
|
81
|
+
export const arbitrumOneFactoryAddresses: Record<string, Address> = {
|
|
97
82
|
DEVICE_WALLET_FACTORY: '0x',
|
|
98
83
|
ESIM_WALLET_FACTORY: '0x',
|
|
99
84
|
LAZY_WALLET_REGISTRY: '0x',
|
|
@@ -103,7 +88,7 @@ export const arbitrumOneFactoryAddresses: Record<string, `0x${string}`> = {
|
|
|
103
88
|
P256VERIFIER: '0x'
|
|
104
89
|
}
|
|
105
90
|
|
|
106
|
-
export const arbitrumSepoliaFactoryAddresses: Record<string,
|
|
91
|
+
export const arbitrumSepoliaFactoryAddresses: Record<string, Address> = {
|
|
107
92
|
DEVICE_WALLET_FACTORY: '0x',
|
|
108
93
|
ESIM_WALLET_FACTORY: '0x',
|
|
109
94
|
LAZY_WALLET_REGISTRY: '0x',
|
|
@@ -134,14 +119,15 @@ export const _getChainSpecificConstants = (
|
|
|
134
119
|
CHAIN_ID.OPTIMISM_MAINNET |
|
|
135
120
|
CHAIN_ID.OPTIMISM_SEPOLIA |
|
|
136
121
|
CHAIN_ID.ARBITRUM_ONE |
|
|
137
|
-
CHAIN_ID.ARBITRUM_SEPOLIA
|
|
122
|
+
CHAIN_ID.ARBITRUM_SEPOLIA,
|
|
123
|
+
rpcURL: string
|
|
138
124
|
): chainSpecifcConstants => {
|
|
139
125
|
|
|
140
126
|
if (chainID == CHAIN_ID.SEPOLIA) {
|
|
141
127
|
return {
|
|
142
128
|
factoryAddresses: sepoliaFactoryAddresses,
|
|
143
129
|
chain: sepolia,
|
|
144
|
-
rpcURL:
|
|
130
|
+
rpcURL: rpcURL,
|
|
145
131
|
customErrors: customErrors
|
|
146
132
|
}
|
|
147
133
|
}
|
|
@@ -149,7 +135,7 @@ export const _getChainSpecificConstants = (
|
|
|
149
135
|
return {
|
|
150
136
|
factoryAddresses: mainnetFactoryAddresses,
|
|
151
137
|
chain: mainnet,
|
|
152
|
-
rpcURL:
|
|
138
|
+
rpcURL: rpcURL,
|
|
153
139
|
customErrors: customErrors
|
|
154
140
|
}
|
|
155
141
|
}
|
|
@@ -157,7 +143,7 @@ export const _getChainSpecificConstants = (
|
|
|
157
143
|
return {
|
|
158
144
|
factoryAddresses: optimismMainnetFactoryAddresses,
|
|
159
145
|
chain: optimism,
|
|
160
|
-
rpcURL:
|
|
146
|
+
rpcURL: rpcURL,
|
|
161
147
|
customErrors: customErrors
|
|
162
148
|
}
|
|
163
149
|
}
|
|
@@ -165,7 +151,7 @@ export const _getChainSpecificConstants = (
|
|
|
165
151
|
return {
|
|
166
152
|
factoryAddresses: optimismSepoliaFactoryAddresses,
|
|
167
153
|
chain: optimismSepolia,
|
|
168
|
-
rpcURL:
|
|
154
|
+
rpcURL: rpcURL,
|
|
169
155
|
customErrors: customErrors
|
|
170
156
|
}
|
|
171
157
|
}
|
|
@@ -173,7 +159,7 @@ export const _getChainSpecificConstants = (
|
|
|
173
159
|
return {
|
|
174
160
|
factoryAddresses: arbitrumOneFactoryAddresses,
|
|
175
161
|
chain: arbitrum,
|
|
176
|
-
rpcURL:
|
|
162
|
+
rpcURL: rpcURL,
|
|
177
163
|
customErrors: customErrors
|
|
178
164
|
}
|
|
179
165
|
}
|
|
@@ -181,7 +167,7 @@ export const _getChainSpecificConstants = (
|
|
|
181
167
|
return {
|
|
182
168
|
factoryAddresses: arbitrumSepoliaFactoryAddresses,
|
|
183
169
|
chain: arbitrumSepolia,
|
|
184
|
-
rpcURL:
|
|
170
|
+
rpcURL: rpcURL,
|
|
185
171
|
customErrors: customErrors
|
|
186
172
|
}
|
|
187
173
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address, createPublicClient, encodeFunctionData, getContract, PublicClient, WalletClient } from "viem";
|
|
2
2
|
import { SmartAccountClient } from "@aa-sdk/core";
|
|
3
3
|
import { DeviceWallet } from "../abis/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { customErrors } from "./constants.js";
|
|
5
5
|
import { P256Key } from "../types.js";
|
|
6
6
|
|
|
7
7
|
export const _deployESIMWallet = async (client: SmartAccountClient, address: Address, hasAccessToETH: boolean, salt: bigint) => {
|
|
@@ -158,9 +158,6 @@ export const _removeESIMWallet = async (client: SmartAccountClient, address: Add
|
|
|
158
158
|
|
|
159
159
|
export const _getOwner = async (client: WalletClient, address: Address) => {
|
|
160
160
|
|
|
161
|
-
const chainID = await client.getChainId();
|
|
162
|
-
const values = _getChainSpecificConstants(chainID);
|
|
163
|
-
|
|
164
161
|
const contract = getContract({
|
|
165
162
|
abi: DeviceWallet,
|
|
166
163
|
address: address,
|
|
@@ -12,7 +12,8 @@ export const _createAccountWithEOA = async (
|
|
|
12
12
|
) => {
|
|
13
13
|
|
|
14
14
|
const chainID = await client.getChainId();
|
|
15
|
-
|
|
15
|
+
const rpcURL = client.transport.url;
|
|
16
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
16
17
|
|
|
17
18
|
if (!client.account) throw new Error(customErrors.MISSING_EOA_WALLET);
|
|
18
19
|
|
|
@@ -33,7 +34,10 @@ export const _getAddress = async (
|
|
|
33
34
|
salt: bigint,
|
|
34
35
|
) => {
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
+
const chainID = await client.getChainId();
|
|
38
|
+
const rpcURL = client.transport.url;
|
|
39
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
40
|
+
|
|
37
41
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
38
42
|
|
|
39
43
|
// UserOp
|
|
@@ -52,7 +56,10 @@ export const _getAddress = async (
|
|
|
52
56
|
|
|
53
57
|
export const _getCurrentDeviceWalletImplementation = async (client: SmartAccountClient) => {
|
|
54
58
|
|
|
55
|
-
const
|
|
59
|
+
const chainID = await client.getChainId();
|
|
60
|
+
const rpcURL = client.transport.url;
|
|
61
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
62
|
+
|
|
56
63
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
57
64
|
|
|
58
65
|
// UserOp
|
|
@@ -5,7 +5,10 @@ import { ESIMWalletFactory } from "../abis/index.js";
|
|
|
5
5
|
|
|
6
6
|
export const _addRegistryAddress = async (client: SmartAccountClient, registryContractAddress: Address) => {
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const chainID = await client.getChainId();
|
|
9
|
+
const rpcURL = client.transport.url;
|
|
10
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
11
|
+
|
|
9
12
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
10
13
|
|
|
11
14
|
// UserOp
|
|
@@ -25,7 +28,8 @@ export const _addRegistryAddress = async (client: SmartAccountClient, registryCo
|
|
|
25
28
|
export const _deployESIMWalletWithEOA = async (client: WalletClient, deviceWalletAddress: Address, salt: bigint) => {
|
|
26
29
|
|
|
27
30
|
const chainID = await client.getChainId();
|
|
28
|
-
|
|
31
|
+
const rpcURL = client.transport.url;
|
|
32
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
29
33
|
|
|
30
34
|
if (!client.account) throw new Error(customErrors.MISSING_EOA_WALLET);
|
|
31
35
|
|
|
@@ -41,7 +45,10 @@ export const _deployESIMWalletWithEOA = async (client: WalletClient, deviceWalle
|
|
|
41
45
|
|
|
42
46
|
export const _deployESIMWalletWithUserOp = async (client: SmartAccountClient, deviceWalletAddress: Address, salt: bigint) => {
|
|
43
47
|
|
|
44
|
-
const
|
|
48
|
+
const chainID = await client.getChainId();
|
|
49
|
+
const rpcURL = client.transport.url;
|
|
50
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
51
|
+
|
|
45
52
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
46
53
|
|
|
47
54
|
// UserOp
|
|
@@ -60,7 +67,10 @@ export const _deployESIMWalletWithUserOp = async (client: SmartAccountClient, de
|
|
|
60
67
|
|
|
61
68
|
export const _getCurrentESIMWalletImplementation = async (client: SmartAccountClient) => {
|
|
62
69
|
|
|
63
|
-
const
|
|
70
|
+
const chainID = await client.getChainId();
|
|
71
|
+
const rpcURL = client.transport.url;
|
|
72
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
73
|
+
|
|
64
74
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
65
75
|
|
|
66
76
|
// UserOp
|
|
@@ -7,7 +7,10 @@ import { LazyWalletRegistry } from "../abis/index.js";
|
|
|
7
7
|
|
|
8
8
|
export const _isLazyWalletDeployed = async (client: SmartAccountClient, deviceUniqueIdentifier: string) => {
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const chainID = await client.getChainId();
|
|
11
|
+
const rpcURL = client.transport.url;
|
|
12
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
13
|
+
|
|
11
14
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
12
15
|
|
|
13
16
|
// UserOp
|
|
@@ -31,7 +34,10 @@ export const _batchPopulateHistory = async (
|
|
|
31
34
|
dataBundleDetails: Array<Array<DataBundleDetails>>
|
|
32
35
|
) => {
|
|
33
36
|
|
|
34
|
-
const
|
|
37
|
+
const chainID = await client.getChainId();
|
|
38
|
+
const rpcURL = client.transport.url;
|
|
39
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
40
|
+
|
|
35
41
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
36
42
|
|
|
37
43
|
// UserOp
|
|
@@ -56,7 +62,10 @@ export const _deployLazyWalletAndSetESIMIdentifier = async (
|
|
|
56
62
|
depositAmount: bigint
|
|
57
63
|
) => {
|
|
58
64
|
|
|
59
|
-
const
|
|
65
|
+
const chainID = await client.getChainId();
|
|
66
|
+
const rpcURL = client.transport.url;
|
|
67
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
68
|
+
|
|
60
69
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
61
70
|
|
|
62
71
|
// UserOp
|
|
@@ -80,7 +89,10 @@ export const _switchESIMIdentifierToNewDeviceIdentifier = async (
|
|
|
80
89
|
newDeviceIdentifier: string
|
|
81
90
|
) => {
|
|
82
91
|
|
|
83
|
-
const
|
|
92
|
+
const chainID = await client.getChainId();
|
|
93
|
+
const rpcURL = client.transport.url;
|
|
94
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
95
|
+
|
|
84
96
|
if(!client.account) throw new Error(customErrors.MISSING_SMART_WALLET)
|
|
85
97
|
|
|
86
98
|
// UserOp
|
package/src/logic/utils.ts
CHANGED
package/.env.example
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
API_KEY=<YOUR_ALCHEMY_API_KEY>
|