kokio-sdk 0.0.1 → 0.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/package.json +5 -1
- package/src/abis/index.ts +9 -9
- package/src/config.ts +22 -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 +1 -1
- package/src/logic/P256Verifier.ts +3 -1
- package/src/logic/account-kit/createSmartAccount.ts +19 -14
- package/src/logic/constants.ts +15 -29
- 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.2",
|
|
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,13 +14,15 @@ export class Kokio {
|
|
|
14
14
|
viemWalletClient: WalletClient;
|
|
15
15
|
turnkeyClient: TurnkeyClient;
|
|
16
16
|
organizationId: string;
|
|
17
|
+
|
|
17
18
|
constants: ConstantsSubPackage;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
|
|
20
|
+
smartAccount: SmartAccountSubPackage;
|
|
21
|
+
deviceWalletFactory?: DeviceWalletFactorySubPackage;
|
|
22
|
+
eSIMWalletFactory?: ESIMWalletFactorySubPackage;
|
|
23
|
+
lazyWalletRegistry?: LazyWalletRegistrySubPackage;
|
|
24
|
+
deviceWallet?: DeviceWalletSubPackage;
|
|
25
|
+
eSIMWallet?: ESIMWalletSubPackage;
|
|
24
26
|
P256Verifier?: P256VerifierSubPackage;
|
|
25
27
|
|
|
26
28
|
constructor(
|
|
@@ -34,13 +36,15 @@ export class Kokio {
|
|
|
34
36
|
this.viemWalletClient = viemWalletClient;
|
|
35
37
|
this.turnkeyClient = turnkeyClient;
|
|
36
38
|
this.organizationId = organizationId;
|
|
39
|
+
|
|
37
40
|
this.constants = new ConstantsSubPackage(this.viemWalletClient);
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
41
|
+
|
|
42
|
+
this.smartAccount = new SmartAccountSubPackage(this.viemWalletClient, this.turnkeyClient, this.organizationId);
|
|
43
|
+
this.deviceWalletFactory = smartAccountClient? new DeviceWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
|
|
44
|
+
this.eSIMWalletFactory = smartAccountClient? new ESIMWalletFactorySubPackage(viemWalletClient, smartAccountClient): undefined;
|
|
45
|
+
this.lazyWalletRegistry = smartAccountClient? new LazyWalletRegistrySubPackage(smartAccountClient): undefined;
|
|
42
46
|
this.P256Verifier = smartAccountClient? new P256VerifierSubPackage(smartAccountClient): undefined;
|
|
43
|
-
this.deviceWallet = deviceWalletAddress && smartAccountClient? new
|
|
44
|
-
this.eSIMWallet = eSIMWalletAddress && smartAccountClient? new
|
|
47
|
+
this.deviceWallet = deviceWalletAddress && smartAccountClient? new DeviceWalletSubPackage(viemWalletClient, smartAccountClient, deviceWalletAddress): undefined;
|
|
48
|
+
this.eSIMWallet = eSIMWalletAddress && smartAccountClient? new ESIMWalletSubPackage(smartAccountClient, eSIMWalletAddress): undefined;
|
|
45
49
|
}
|
|
46
50
|
}
|
|
@@ -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,7 +4,7 @@ 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;
|
|
@@ -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
|
|
@@ -61,25 +61,27 @@ const _encodeBatchExecute = async (txs: AccountOp[]) => {
|
|
|
61
61
|
|
|
62
62
|
const _getAccountInitCode = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint): Promise<Hex> => {
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
// To send with user operations
|
|
65
|
+
const chainID = await client.getChainId();
|
|
66
|
+
const rpcURL = client.transport.url;
|
|
67
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
const callData = encodeFunctionData({
|
|
70
|
+
abi: DeviceWalletFactory,
|
|
71
|
+
functionName: "createAccount",
|
|
72
|
+
args: [deviceUniqueIdentifier, deviceWalletOwnerKey, salt, ZERO],
|
|
73
|
+
})
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
return values.factoryAddresses.DEVICE_WALLET_FACTORY.concat(_remove0x(callData)) as Hex;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const getInitCodeHash = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key): Promise<BytesLike> => {
|
|
78
79
|
|
|
79
80
|
const chainID = await client.getChainId();
|
|
80
|
-
const
|
|
81
|
+
const rpcURL = client.transport.url;
|
|
82
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
// off-chain computation of the DeviceWallet address
|
|
83
85
|
const registry = values.factoryAddresses.REGISTRY;
|
|
84
86
|
const deviceWalletFactoryAddress = values.factoryAddresses.DEVICE_WALLET_FACTORY;
|
|
85
87
|
|
|
@@ -133,7 +135,8 @@ const prepareSaltForCreate2 = (sender: Address, salt: BigInt): BytesLike => {
|
|
|
133
135
|
const getCounterFactualAddress = async (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: BigInt, sender?: Address):Promise<Hex> => {
|
|
134
136
|
|
|
135
137
|
const chainID = await client.getChainId();
|
|
136
|
-
const
|
|
138
|
+
const rpcURL = client.transport.url;
|
|
139
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
137
140
|
const deviceWalletFactoryAddress = values.factoryAddresses.DEVICE_WALLET_FACTORY;
|
|
138
141
|
|
|
139
142
|
sender = sender? sender : values.factoryAddresses.SENDER_CREATOR;
|
|
@@ -227,7 +230,8 @@ const _signUserOperationHash = async (hash: Hex, turnkeyClient: TurnkeyClient, o
|
|
|
227
230
|
export const _getSmartWallet = async (client: WalletClient, turnkeyClient: TurnkeyClient, organiationId: string, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint, sender?: Address): Promise<SmartContractAccount> => {
|
|
228
231
|
|
|
229
232
|
const chainID = await client.getChainId();
|
|
230
|
-
const
|
|
233
|
+
const rpcURL = client.transport.url;
|
|
234
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
231
235
|
|
|
232
236
|
if (!client.account) throw new Error ('Error: No signer account found with WalletClient')
|
|
233
237
|
const signWith = client.account.address;
|
|
@@ -271,7 +275,8 @@ export const _getSmartWallet = async (client: WalletClient, turnkeyClient: Turnk
|
|
|
271
275
|
export const _getSmartWalletClient = async (client: WalletClient, account: SmartContractAccount) => {
|
|
272
276
|
|
|
273
277
|
const chainID = await client.getChainId();
|
|
274
|
-
const
|
|
278
|
+
const rpcURL = client.transport.url;
|
|
279
|
+
const values = _getChainSpecificConstants(chainID, rpcURL);
|
|
275
280
|
|
|
276
281
|
return createSmartAccountClient({
|
|
277
282
|
// created above
|
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,7 +38,7 @@ 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',
|
|
@@ -63,7 +48,7 @@ export const sepoliaFactoryAddresses: Record<string, `0x${string}`> = {
|
|
|
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,7 +68,7 @@ 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',
|
|
@@ -93,7 +78,7 @@ export const optimismSepoliaFactoryAddresses: Record<string, `0x${string}`> = {
|
|
|
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>
|