kokio-sdk 1.0.0 → 2.0.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 +68 -19
- package/dist/esm/abis/BeaconProxy.js +30 -46
- package/dist/esm/abis/DeviceWallet.js +546 -535
- package/dist/esm/abis/DeviceWalletFactory.js +537 -544
- package/dist/esm/abis/ESIMWallet.js +440 -299
- package/dist/esm/abis/ESIMWalletFactory.js +372 -289
- package/dist/esm/abis/LazyWalletRegistry.js +941 -421
- package/dist/esm/abis/P256Verifier.js +29 -29
- package/dist/esm/abis/ProtocolAdmin.js +1228 -0
- package/dist/esm/abis/Registry.js +1207 -466
- package/dist/esm/abis/RegistryHelper.js +414 -20
- package/dist/esm/abis/index.js +2 -1
- package/dist/esm/admin/config-admin.js +24 -0
- package/dist/esm/admin/interface/deviceWalletClass.js +27 -6
- package/dist/esm/admin/interface/deviceWalletFactoryClass.js +41 -19
- package/dist/esm/admin/interface/eSIMWalletClass.js +10 -1
- package/dist/esm/admin/interface/eSIMWalletFactoryClass.js +24 -2
- package/dist/esm/admin/interface/lazyWalletRegistryClass.js +83 -4
- package/dist/esm/admin/interface/protocolAdminClass.js +195 -0
- package/dist/esm/admin/interface/registryClass.js +93 -2
- package/dist/esm/config.js +42 -7
- package/dist/esm/interface/deviceWalletClass.js +45 -5
- package/dist/esm/interface/deviceWalletFactoryClass.js +20 -1
- package/dist/esm/interface/eSIMWalletClass.js +12 -3
- package/dist/esm/interface/registryClass.js +47 -0
- package/dist/esm/interface/smartAccountClass.js +2 -4
- package/dist/esm/logic/account-kit/createSmartAccount.js +156 -102
- package/dist/esm/logic/admin/deviceWallet.eoa.js +23 -12
- package/dist/esm/logic/admin/deviceWalletFactory.eoa.js +63 -42
- package/dist/esm/logic/admin/eSIMWallet.eoa.js +3 -5
- package/dist/esm/logic/admin/eSIMWalletFactory.eoa.js +76 -8
- package/dist/esm/logic/admin/lazyWalletRegistry.eoa.js +330 -19
- package/dist/esm/logic/admin/protocolAdmin.eoa.js +524 -0
- package/dist/esm/logic/admin/reads/deviceWallet.reads.js +82 -7
- package/dist/esm/logic/admin/reads/deviceWalletFactory.reads.js +82 -23
- package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +50 -6
- package/dist/esm/logic/admin/reads/eSIMWalletFactory.reads.js +63 -5
- package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +171 -10
- package/dist/esm/logic/admin/reads/protocolAdmin.reads.js +154 -0
- package/dist/esm/logic/admin/reads/registry.reads.js +289 -9
- package/dist/esm/logic/admin/registry.eoa.js +274 -4
- package/dist/esm/logic/constants.js +53 -26
- package/dist/esm/logic/deviceWallet.js +224 -31
- package/dist/esm/logic/deviceWalletFactory.js +89 -0
- package/dist/esm/logic/eSIMWallet.js +113 -43
- package/dist/esm/logic/eSIMWalletFactory.js +8 -8
- package/dist/esm/logic/errors.js +64 -0
- package/dist/esm/logic/registry.js +236 -0
- package/dist/esm/logic/utils.js +2 -1
- package/dist/types/abis/BeaconProxy.d.ts +21 -33
- package/dist/types/abis/DeviceWallet.d.ts +372 -365
- package/dist/types/abis/DeviceWalletFactory.d.ts +438 -448
- package/dist/types/abis/ESIMWallet.d.ts +352 -245
- package/dist/types/abis/ESIMWalletFactory.d.ts +278 -216
- package/dist/types/abis/LazyWalletRegistry.d.ts +710 -317
- package/dist/types/abis/P256Verifier.d.ts +16 -16
- package/dist/types/abis/ProtocolAdmin.d.ts +947 -0
- package/dist/types/abis/Registry.d.ts +960 -393
- package/dist/types/abis/RegistryHelper.d.ts +317 -16
- package/dist/types/abis/index.d.ts +2 -1
- package/dist/types/admin/config-admin.d.ts +16 -0
- package/dist/types/admin/interface/deviceWalletClass.d.ts +10 -3
- package/dist/types/admin/interface/deviceWalletFactoryClass.d.ts +14 -7
- package/dist/types/admin/interface/eSIMWalletClass.d.ts +3 -0
- package/dist/types/admin/interface/eSIMWalletFactoryClass.d.ts +8 -1
- package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +38 -2
- package/dist/types/admin/interface/protocolAdminClass.d.ts +95 -0
- package/dist/types/admin/interface/registryClass.d.ts +30 -0
- package/dist/types/config.d.ts +26 -5
- package/dist/types/interface/P256VerifierClass.d.ts +3 -4
- package/dist/types/interface/constantsClass.d.ts +2 -2
- package/dist/types/interface/deviceWalletClass.d.ts +22 -2569
- package/dist/types/interface/deviceWalletFactoryClass.d.ts +10 -2564
- package/dist/types/interface/eSIMWalletClass.d.ts +11 -8
- package/dist/types/interface/eSIMWalletFactoryClass.d.ts +5 -2565
- package/dist/types/interface/registryClass.d.ts +19 -0
- package/dist/types/interface/smartAccountClass.d.ts +6 -2568
- package/dist/types/logic/P256Verifier.d.ts +2 -2
- package/dist/types/logic/account-kit/createSmartAccount.d.ts +43 -19
- package/dist/types/logic/admin/deviceWallet.eoa.d.ts +15 -9
- package/dist/types/logic/admin/deviceWalletFactory.eoa.d.ts +34 -23
- package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +0 -5
- package/dist/types/logic/admin/eSIMWalletFactory.eoa.d.ts +27 -9
- package/dist/types/logic/admin/lazyWalletRegistry.eoa.d.ts +102 -10
- package/dist/types/logic/admin/protocolAdmin.eoa.d.ts +163 -0
- package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +28 -8
- package/dist/types/logic/admin/reads/deviceWalletFactory.reads.d.ts +45 -14
- package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +25 -6
- package/dist/types/logic/admin/reads/eSIMWalletFactory.reads.d.ts +21 -6
- package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +44 -11
- package/dist/types/logic/admin/reads/protocolAdmin.reads.d.ts +53 -0
- package/dist/types/logic/admin/reads/registry.reads.d.ts +105 -9
- package/dist/types/logic/admin/registry.eoa.d.ts +102 -5
- package/dist/types/logic/constants.d.ts +2 -0
- package/dist/types/logic/deviceWallet.d.ts +78 -6
- package/dist/types/logic/deviceWalletFactory.d.ts +32 -3
- package/dist/types/logic/eSIMWallet.d.ts +48 -7
- package/dist/types/logic/eSIMWalletFactory.d.ts +3 -3
- package/dist/types/logic/errors.d.ts +45 -0
- package/dist/types/logic/registry.d.ts +78 -0
- package/dist/types/types-export.d.ts +1 -1
- package/dist/types/types.d.ts +111 -1
- package/package.json +11 -13
- package/dist/esm/interface/lazyWalletRegistryClass.js +0 -10
- package/dist/esm/logic/lazyWalletRegistry.js +0 -19
- package/dist/types/interface/lazyWalletRegistryClass.d.ts +0 -6
- package/dist/types/logic/lazyWalletRegistry.d.ts +0 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Kokio SDK
|
|
2
2
|
|
|
3
3
|
A TypeScript SDK for interacting with the Koki'o eSIM smart contracts. It wraps
|
|
4
|
-
[viem](https://viem.sh)
|
|
5
|
-
|
|
4
|
+
[viem](https://viem.sh), including its account abstraction module, so that two
|
|
5
|
+
very different callers can use the same contracts:
|
|
6
6
|
|
|
7
7
|
- the **mobile app** (Expo / React Native), which acts on behalf of a user through
|
|
8
8
|
an ERC-4337 device-wallet smart account signed by an on-device passkey, and
|
|
@@ -16,6 +16,10 @@ actually needs.
|
|
|
16
16
|
| `Kokio` | `kokio-sdk` | Passkey (WebAuthn P-256) via user operations | Mobile app |
|
|
17
17
|
| `KokioAdmin` | `kokio-sdk/admin` | Admin / owner EOA via direct transactions | Backend server |
|
|
18
18
|
|
|
19
|
+
This README covers setup and the common flows. For every method on every
|
|
20
|
+
surface, with a code example and return type, see the
|
|
21
|
+
[full SDK reference](docs/README.md).
|
|
22
|
+
|
|
19
23
|
## Installation
|
|
20
24
|
|
|
21
25
|
```sh
|
|
@@ -23,8 +27,8 @@ npm install kokio-sdk
|
|
|
23
27
|
```
|
|
24
28
|
|
|
25
29
|
The package ships as ES modules and requires Node 18 or newer (or a React Native
|
|
26
|
-
runtime). `viem`
|
|
27
|
-
|
|
30
|
+
runtime). `viem` is bundled as a dependency, so you do not need to install it
|
|
31
|
+
separately.
|
|
28
32
|
|
|
29
33
|
## Mobile client (Expo / React Native)
|
|
30
34
|
|
|
@@ -37,8 +41,7 @@ You will need:
|
|
|
37
41
|
|
|
38
42
|
- a viem `WalletClient` connected to the target chain,
|
|
39
43
|
- the passkey `credentialId` and `rpId` registered for the device,
|
|
40
|
-
-
|
|
41
|
-
bundler and paymaster).
|
|
44
|
+
- a Pimlico API key and a gas policy id (used by the bundler and paymaster).
|
|
42
45
|
|
|
43
46
|
```ts
|
|
44
47
|
import { Kokio } from "kokio-sdk";
|
|
@@ -51,7 +54,6 @@ const kokio = new Kokio(
|
|
|
51
54
|
walletClient,
|
|
52
55
|
credentialId, // passkey credential id on the device
|
|
53
56
|
rpId, // relying party id (your app domain)
|
|
54
|
-
organizationId,
|
|
55
57
|
pimlicoAPIKey,
|
|
56
58
|
gasPolicyId,
|
|
57
59
|
);
|
|
@@ -70,7 +72,6 @@ const session = new Kokio(
|
|
|
70
72
|
walletClient,
|
|
71
73
|
credentialId,
|
|
72
74
|
rpId,
|
|
73
|
-
organizationId,
|
|
74
75
|
pimlicoAPIKey,
|
|
75
76
|
gasPolicyId,
|
|
76
77
|
smartAccountClient,
|
|
@@ -79,16 +80,31 @@ const session = new Kokio(
|
|
|
79
80
|
);
|
|
80
81
|
|
|
81
82
|
// 4. Send a user operation. The passkey signs it on the device.
|
|
82
|
-
const
|
|
83
|
+
const hash = await session.deviceWallet!.toggleAccessToETH(eSIMWalletAddress, true);
|
|
83
84
|
await smartAccountClient.waitForUserOperationTransaction({ hash });
|
|
84
85
|
```
|
|
85
86
|
|
|
86
87
|
The contract surfaces (`deviceWallet`, `eSIMWallet`, `deviceWalletFactory`,
|
|
87
|
-
`eSIMWalletFactory`, `
|
|
88
|
+
`eSIMWalletFactory`, `registry`, `P256Verifier`) are only present once a
|
|
88
89
|
`smartAccountClient` is supplied, which is why the example constructs `Kokio`
|
|
89
90
|
twice. Instance surfaces (`deviceWallet`, `eSIMWallet`) also need their contract
|
|
90
91
|
address. They stay `undefined` until you pass it.
|
|
91
92
|
|
|
93
|
+
A device wallet often holds more than one eSIM wallet, and the app needs to
|
|
94
|
+
switch which one it is acting on without resolving the smart account again.
|
|
95
|
+
Bind a new instance address with a setter and keep using the same `Kokio`
|
|
96
|
+
reference:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
session.setESIMWalletAddress(anotherESIMWalletAddress);
|
|
100
|
+
const hash = await session.eSIMWallet!.buyDataBundle({ dataBundleID, dataBundlePrice });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`setDeviceWalletAddress` and `setESIMWalletAddress` each mutate the instance
|
|
104
|
+
and return `this`, so they can be chained. Both need a `smartAccountClient`
|
|
105
|
+
already on the instance; without one the corresponding surface stays
|
|
106
|
+
`undefined`, same as when no address is passed to the constructor.
|
|
107
|
+
|
|
92
108
|
The passkey signing path depends on
|
|
93
109
|
[`react-native-passkey`](https://github.com/f-23/react-native-passkey) and runs
|
|
94
110
|
only on a device or simulator that supports WebAuthn. It is not available in a
|
|
@@ -132,7 +148,7 @@ with a setter and keep using the same `KokioAdmin` reference:
|
|
|
132
148
|
|
|
133
149
|
```ts
|
|
134
150
|
admin.setDeviceWalletAddress(deviceWalletAddress);
|
|
135
|
-
await admin.deviceWallet!.deployESIMWallet(
|
|
151
|
+
await admin.deviceWallet!.deployESIMWallet(salt);
|
|
136
152
|
|
|
137
153
|
admin.setESIMWalletAddress(eSIMWalletAddress);
|
|
138
154
|
await admin.eSIMWallet!.buyDataBundle({ dataBundleID, dataBundlePrice });
|
|
@@ -143,9 +159,27 @@ the instance and return `this`, so they can be chained. Admin methods send ordin
|
|
|
143
159
|
transactions and resolve to a transaction hash.
|
|
144
160
|
|
|
145
161
|
The chain-wide surfaces (`deviceWalletFactory`, `eSIMWalletFactory`, `registry`,
|
|
146
|
-
`lazyWalletRegistry`) are available as soon as the instance
|
|
147
|
-
instance-scoped surfaces (`deviceWallet`, `eSIMWallet`) become
|
|
148
|
-
address is set.
|
|
162
|
+
`lazyWalletRegistry`, `protocolAdmin`) are available as soon as the instance
|
|
163
|
+
exists. The instance-scoped surfaces (`deviceWallet`, `eSIMWallet`) become
|
|
164
|
+
available once their address is set.
|
|
165
|
+
|
|
166
|
+
`protocolAdmin` wraps the timelock that owns `registry`, `lazyWalletRegistry`,
|
|
167
|
+
`deviceWalletFactory`, and `eSIMWalletFactory` on chain. It schedules, executes,
|
|
168
|
+
and cancels privileged calls behind a delay, split across four role-scoped
|
|
169
|
+
surfaces: `proposer` schedules a call, `executor` runs one once its delay has
|
|
170
|
+
passed, `canceller` cancels a pending one, and `guardian` bypasses the delay for
|
|
171
|
+
emergency actions such as unpausing or disabling a compromised admin.
|
|
172
|
+
|
|
173
|
+
## Types and ABIs
|
|
174
|
+
|
|
175
|
+
Two more subpaths support the entry points above:
|
|
176
|
+
|
|
177
|
+
- `kokio-sdk/types` re-exports the shared types (`P256Key`, `WebAuthnSignature`,
|
|
178
|
+
`DataBundleDetails`, `KokioSmartAccountClient`, `OwnerCall`, and others) so you
|
|
179
|
+
can type your own code without reaching into internal paths.
|
|
180
|
+
- `kokio-sdk/abis` re-exports the typed contract ABIs (`DeviceWallet`,
|
|
181
|
+
`ESIMWallet`, `Registry`, `ProtocolAdmin`, and others), useful if you need to
|
|
182
|
+
decode logs or call a contract directly with viem.
|
|
149
183
|
|
|
150
184
|
## Errors
|
|
151
185
|
|
|
@@ -156,7 +190,7 @@ on-chain reverts without reaching into internal module paths:
|
|
|
156
190
|
import { KokioError, ContractRevertError } from "kokio-sdk"; // or "kokio-sdk/admin"
|
|
157
191
|
|
|
158
192
|
try {
|
|
159
|
-
await admin.
|
|
193
|
+
await admin.registry.requestAdminUpdate(newAdmin);
|
|
160
194
|
} catch (err) {
|
|
161
195
|
if (err instanceof ContractRevertError) {
|
|
162
196
|
console.error("reverted:", err.message);
|
|
@@ -169,11 +203,26 @@ try {
|
|
|
169
203
|
`CounterfactualMismatchError`, and `ContractRevertError`. `decodeContractRevert`
|
|
170
204
|
turns raw revert data into a readable reason.
|
|
171
205
|
|
|
172
|
-
|
|
206
|
+
The paginated `lazyWalletRegistry` calls on `KokioAdmin` can also throw a few
|
|
207
|
+
narrower `KokioError` subclasses that are not exported by name (for example
|
|
208
|
+
`BatchSizeOutOfRangeError`). Catch them with `instanceof KokioError` and read
|
|
209
|
+
`.code` instead of importing the specific class.
|
|
210
|
+
|
|
211
|
+
## Constants and supported chains
|
|
212
|
+
|
|
213
|
+
Both entry points expose an async `constants` getter with the resolved factory
|
|
214
|
+
addresses, chain, RPC URL, and custom-error selectors for the wallet client's
|
|
215
|
+
connected chain:
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
const { factoryAddresses, chain, rpcURL } = await kokio.constants;
|
|
219
|
+
```
|
|
173
220
|
|
|
174
|
-
The SDK resolves
|
|
175
|
-
|
|
176
|
-
deployment
|
|
221
|
+
The SDK resolves these from the wallet client's connected chain id, so you do not
|
|
222
|
+
pass addresses yourself. Base Sepolia (chain id `84532`) is the only chain with a
|
|
223
|
+
live deployment today. Ethereum, Optimism, and Arbitrum (mainnet and their
|
|
224
|
+
testnets) are wired into the chain-resolution logic but not yet deployed;
|
|
225
|
+
connecting to one of them throws `UnconfiguredChainError` until it is.
|
|
177
226
|
|
|
178
227
|
## Testing
|
|
179
228
|
|
|
@@ -1,79 +1,63 @@
|
|
|
1
1
|
const BeaconProxy = [
|
|
2
2
|
{
|
|
3
|
+
"type": "fallback",
|
|
4
|
+
"stateMutability": "payable"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"type": "event",
|
|
8
|
+
"name": "BeaconUpgraded",
|
|
3
9
|
"inputs": [
|
|
4
10
|
{
|
|
5
|
-
"internalType": "address",
|
|
6
11
|
"name": "beacon",
|
|
7
|
-
"type": "address"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"internalType": "bytes",
|
|
11
|
-
"name": "data",
|
|
12
|
-
"type": "bytes"
|
|
12
|
+
"type": "address",
|
|
13
|
+
"indexed": true,
|
|
14
|
+
"internalType": "address"
|
|
13
15
|
}
|
|
14
16
|
],
|
|
15
|
-
"
|
|
16
|
-
"type": "constructor"
|
|
17
|
+
"anonymous": false
|
|
17
18
|
},
|
|
18
19
|
{
|
|
20
|
+
"type": "error",
|
|
21
|
+
"name": "AddressEmptyCode",
|
|
19
22
|
"inputs": [
|
|
20
23
|
{
|
|
21
|
-
"internalType": "address",
|
|
22
24
|
"name": "target",
|
|
23
|
-
"type": "address"
|
|
25
|
+
"type": "address",
|
|
26
|
+
"internalType": "address"
|
|
24
27
|
}
|
|
25
|
-
]
|
|
26
|
-
"name": "AddressEmptyCode",
|
|
27
|
-
"type": "error"
|
|
28
|
+
]
|
|
28
29
|
},
|
|
29
30
|
{
|
|
31
|
+
"type": "error",
|
|
32
|
+
"name": "ERC1967InvalidBeacon",
|
|
30
33
|
"inputs": [
|
|
31
34
|
{
|
|
32
|
-
"internalType": "address",
|
|
33
35
|
"name": "beacon",
|
|
34
|
-
"type": "address"
|
|
36
|
+
"type": "address",
|
|
37
|
+
"internalType": "address"
|
|
35
38
|
}
|
|
36
|
-
]
|
|
37
|
-
"name": "ERC1967InvalidBeacon",
|
|
38
|
-
"type": "error"
|
|
39
|
+
]
|
|
39
40
|
},
|
|
40
41
|
{
|
|
42
|
+
"type": "error",
|
|
43
|
+
"name": "ERC1967InvalidImplementation",
|
|
41
44
|
"inputs": [
|
|
42
45
|
{
|
|
43
|
-
"internalType": "address",
|
|
44
46
|
"name": "implementation",
|
|
45
|
-
"type": "address"
|
|
47
|
+
"type": "address",
|
|
48
|
+
"internalType": "address"
|
|
46
49
|
}
|
|
47
|
-
]
|
|
48
|
-
"name": "ERC1967InvalidImplementation",
|
|
49
|
-
"type": "error"
|
|
50
|
+
]
|
|
50
51
|
},
|
|
51
52
|
{
|
|
52
|
-
"
|
|
53
|
+
"type": "error",
|
|
53
54
|
"name": "ERC1967NonPayable",
|
|
54
|
-
"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"inputs": [],
|
|
58
|
-
"name": "FailedInnerCall",
|
|
59
|
-
"type": "error"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"anonymous": false,
|
|
63
|
-
"inputs": [
|
|
64
|
-
{
|
|
65
|
-
"indexed": true,
|
|
66
|
-
"internalType": "address",
|
|
67
|
-
"name": "beacon",
|
|
68
|
-
"type": "address"
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
|
-
"name": "BeaconUpgraded",
|
|
72
|
-
"type": "event"
|
|
55
|
+
"inputs": []
|
|
73
56
|
},
|
|
74
57
|
{
|
|
75
|
-
"
|
|
76
|
-
"
|
|
58
|
+
"type": "error",
|
|
59
|
+
"name": "FailedCall",
|
|
60
|
+
"inputs": []
|
|
77
61
|
}
|
|
78
62
|
];
|
|
79
63
|
export default BeaconProxy;
|