kokio-sdk 0.1.4 → 1.1.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.
Files changed (85) hide show
  1. package/README.md +185 -1
  2. package/dist/esm/admin/config-admin.js +102 -0
  3. package/dist/esm/admin/interface/deviceWalletClass.js +34 -0
  4. package/dist/esm/admin/interface/deviceWalletFactoryClass.js +57 -0
  5. package/dist/esm/admin/interface/eSIMWalletClass.js +31 -0
  6. package/dist/esm/admin/interface/eSIMWalletFactoryClass.js +22 -0
  7. package/dist/esm/admin/interface/lazyWalletRegistryClass.js +33 -0
  8. package/dist/esm/admin/interface/registryClass.js +43 -0
  9. package/dist/esm/config.js +4 -0
  10. package/dist/esm/interface/deviceWalletClass.js +1 -13
  11. package/dist/esm/interface/eSIMWalletClass.js +2 -8
  12. package/dist/esm/interface/eSIMWalletFactoryClass.js +2 -8
  13. package/dist/esm/interface/lazyWalletRegistryClass.js +2 -11
  14. package/dist/esm/logic/P256Verifier.js +8 -15
  15. package/dist/esm/logic/account-kit/createSmartAccount.js +76 -24
  16. package/dist/esm/logic/admin/deviceWallet.eoa.js +42 -0
  17. package/dist/esm/logic/admin/deviceWalletFactory.eoa.js +133 -0
  18. package/dist/esm/logic/admin/eSIMWallet.eoa.js +30 -0
  19. package/dist/esm/logic/admin/eSIMWalletFactory.eoa.js +43 -0
  20. package/dist/esm/logic/admin/lazyWalletRegistry.eoa.js +62 -0
  21. package/dist/esm/logic/admin/reads/deviceWallet.reads.js +45 -0
  22. package/dist/esm/logic/admin/reads/deviceWalletFactory.reads.js +87 -0
  23. package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +44 -0
  24. package/dist/esm/logic/admin/reads/eSIMWalletFactory.reads.js +32 -0
  25. package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +62 -0
  26. package/dist/esm/logic/admin/reads/registry.reads.js +136 -0
  27. package/dist/esm/logic/admin/registry.eoa.js +23 -0
  28. package/dist/esm/logic/constants.js +31 -71
  29. package/dist/esm/logic/deviceWallet.js +28 -91
  30. package/dist/esm/logic/deviceWalletFactory.js +21 -30
  31. package/dist/esm/logic/eSIMWallet.js +25 -57
  32. package/dist/esm/logic/eSIMWalletFactory.js +17 -50
  33. package/dist/esm/logic/errors.js +118 -0
  34. package/dist/esm/logic/lazyWalletRegistry.js +12 -72
  35. package/dist/esm/logic/utils.js +3 -3
  36. package/dist/types/abis/BeaconProxy.d.ts +58 -2
  37. package/dist/types/abis/DeviceWallet.d.ts +702 -2
  38. package/dist/types/abis/DeviceWalletFactory.d.ts +634 -2
  39. package/dist/types/abis/ESIMWallet.d.ts +375 -2
  40. package/dist/types/abis/ESIMWalletFactory.d.ts +355 -2
  41. package/dist/types/abis/LazyWalletRegistry.d.ts +565 -2
  42. package/dist/types/abis/P256Verifier.d.ts +56 -2
  43. package/dist/types/abis/Registry.d.ts +623 -2
  44. package/dist/types/abis/RegistryHelper.d.ts +295 -2
  45. package/dist/types/admin/config-admin.d.ts +68 -0
  46. package/dist/types/admin/interface/deviceWalletClass.d.ts +17 -0
  47. package/dist/types/admin/interface/deviceWalletFactoryClass.d.ts +25 -0
  48. package/dist/types/admin/interface/eSIMWalletClass.d.ts +17 -0
  49. package/dist/types/admin/interface/eSIMWalletFactoryClass.d.ts +10 -0
  50. package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +14 -0
  51. package/dist/types/admin/interface/registryClass.d.ts +17 -0
  52. package/dist/types/config.d.ts +2 -0
  53. package/dist/types/interface/P256VerifierClass.d.ts +2 -1
  54. package/dist/types/interface/constantsClass.d.ts +2 -2
  55. package/dist/types/interface/deviceWalletClass.d.ts +24 -28
  56. package/dist/types/interface/deviceWalletFactoryClass.d.ts +27 -26
  57. package/dist/types/interface/eSIMWalletClass.d.ts +2 -4
  58. package/dist/types/interface/eSIMWalletFactoryClass.d.ts +24 -26
  59. package/dist/types/interface/lazyWalletRegistryClass.d.ts +1 -6
  60. package/dist/types/interface/smartAccountClass.d.ts +23 -23
  61. package/dist/types/logic/P256Verifier.d.ts +2 -1
  62. package/dist/types/logic/account-kit/createSmartAccount.d.ts +38 -1
  63. package/dist/types/logic/admin/deviceWallet.eoa.d.ts +12 -0
  64. package/dist/types/logic/admin/deviceWalletFactory.eoa.d.ts +33 -0
  65. package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +14 -0
  66. package/dist/types/logic/admin/eSIMWalletFactory.eoa.d.ts +13 -0
  67. package/dist/types/logic/admin/lazyWalletRegistry.eoa.d.ts +18 -0
  68. package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +16 -0
  69. package/dist/types/logic/admin/reads/deviceWalletFactory.reads.d.ts +26 -0
  70. package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +15 -0
  71. package/dist/types/logic/admin/reads/eSIMWalletFactory.reads.d.ts +10 -0
  72. package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +20 -0
  73. package/dist/types/logic/admin/reads/registry.reads.d.ts +34 -0
  74. package/dist/types/logic/admin/registry.eoa.d.ts +7 -0
  75. package/dist/types/logic/deviceWallet.d.ts +1 -5
  76. package/dist/types/logic/deviceWalletFactory.d.ts +5 -4
  77. package/dist/types/logic/eSIMWallet.d.ts +1 -3
  78. package/dist/types/logic/eSIMWalletFactory.d.ts +2 -4
  79. package/dist/types/logic/errors.d.ts +63 -0
  80. package/dist/types/logic/lazyWalletRegistry.d.ts +1 -6
  81. package/dist/types/logic/utils.d.ts +8 -1
  82. package/dist/types/types.d.ts +1 -1
  83. package/package.json +12 -3
  84. package/dist/esm/interface/utilsClass.js +0 -13
  85. package/dist/types/interface/utilsClass.d.ts +0 -2567
package/README.md CHANGED
@@ -1,3 +1,187 @@
1
1
  # Kokio SDK
2
2
 
3
- This is an internal SDK that allows Koki'o mobile app to interact with the Smart contracts.
3
+ A TypeScript SDK for interacting with the Koki'o eSIM smart contracts. It wraps
4
+ [viem](https://viem.sh) and [`@aa-sdk/core`](https://www.npmjs.com/package/@aa-sdk/core)
5
+ so that two very different callers can use the same contracts:
6
+
7
+ - the **mobile app** (Expo / React Native), which acts on behalf of a user through
8
+ an ERC-4337 device-wallet smart account signed by an on-device passkey, and
9
+ - the **backend server**, which acts as the platform admin through a plain EOA.
10
+
11
+ Each caller has its own entry point so it only deals with the parameters it
12
+ actually needs.
13
+
14
+ | Entry point | Import | Signer | For |
15
+ | --- | --- | --- | --- |
16
+ | `Kokio` | `kokio-sdk` | Passkey (WebAuthn P-256) via user operations | Mobile app |
17
+ | `KokioAdmin` | `kokio-sdk/admin` | Admin / owner EOA via direct transactions | Backend server |
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ npm install kokio-sdk
23
+ ```
24
+
25
+ The package ships as ES modules and requires Node 18 or newer (or a React Native
26
+ runtime). `viem` and `@aa-sdk/core` are bundled as dependencies, so you do not
27
+ need to install them separately.
28
+
29
+ ## Mobile client (Expo / React Native)
30
+
31
+ The mobile surface represents a user's **device wallet**, an ERC-4337 smart
32
+ account whose owner is a P-256 passkey stored on the device. Actions are sent as
33
+ user operations through a bundler and signed with the passkey, so no private key
34
+ is ever held in the app.
35
+
36
+ You will need:
37
+
38
+ - a viem `WalletClient` connected to the target chain,
39
+ - the passkey `credentialId` and `rpId` registered for the device,
40
+ - your `organizationId`, a Pimlico API key, and a gas policy id (used by the
41
+ bundler and paymaster).
42
+
43
+ ```ts
44
+ import { Kokio } from "kokio-sdk";
45
+ import { createWalletClient, http } from "viem";
46
+ import { baseSepolia } from "viem/chains";
47
+
48
+ const walletClient = createWalletClient({ chain: baseSepolia, transport: http() });
49
+
50
+ const kokio = new Kokio(
51
+ walletClient,
52
+ credentialId, // passkey credential id on the device
53
+ rpId, // relying party id (your app domain)
54
+ organizationId,
55
+ pimlicoAPIKey,
56
+ gasPolicyId,
57
+ );
58
+
59
+ // 1. Resolve the smart account for this device passkey. `ownerKey` is the
60
+ // passkey's P-256 public key as [x, y] hex coordinates; `salt` makes the
61
+ // counterfactual address unique per user.
62
+ const account = await kokio.smartAccount.getSmartWallet(deviceUniqueIdentifier, ownerKey, salt);
63
+
64
+ // 2. Build a bundler-backed client for that account.
65
+ const smartAccountClient = await kokio.smartAccount.getSmartWalletClient(account);
66
+
67
+ // 3. Re-create Kokio with the smart account client (and any known instance
68
+ // addresses) so the contract surfaces become available.
69
+ const session = new Kokio(
70
+ walletClient,
71
+ credentialId,
72
+ rpId,
73
+ organizationId,
74
+ pimlicoAPIKey,
75
+ gasPolicyId,
76
+ smartAccountClient,
77
+ deviceWalletAddress,
78
+ eSIMWalletAddress,
79
+ );
80
+
81
+ // 4. Send a user operation. The passkey signs it on the device.
82
+ const { hash } = await session.deviceWallet!.toggleAccessToETH(eSIMWalletAddress, true);
83
+ await smartAccountClient.waitForUserOperationTransaction({ hash });
84
+ ```
85
+
86
+ The contract surfaces (`deviceWallet`, `eSIMWallet`, `deviceWalletFactory`,
87
+ `eSIMWalletFactory`, `lazyWalletRegistry`, `P256Verifier`) are only present once a
88
+ `smartAccountClient` is supplied, which is why the example constructs `Kokio`
89
+ twice. Instance surfaces (`deviceWallet`, `eSIMWallet`) also need their contract
90
+ address. They stay `undefined` until you pass it.
91
+
92
+ The passkey signing path depends on
93
+ [`react-native-passkey`](https://github.com/f-23/react-native-passkey) and runs
94
+ only on a device or simulator that supports WebAuthn. It is not available in a
95
+ plain Node process.
96
+
97
+ ## Backend server (admin)
98
+
99
+ The backend surface, `KokioAdmin`, exposes exactly the contract functions that are
100
+ restricted on chain to the admin or owner EOA (`onlyAdmin`, `onlyOwner`,
101
+ `onlyESIMWalletAdmin`). These can never be called through a device-wallet user
102
+ operation, so they live here instead. No bundler, paymaster, or passkey is
103
+ involved. A viem `WalletClient` carrying the admin account is all that is needed.
104
+
105
+ ```ts
106
+ import { KokioAdmin } from "kokio-sdk/admin";
107
+ import { createWalletClient, http } from "viem";
108
+ import { privateKeyToAccount } from "viem/accounts";
109
+ import { baseSepolia } from "viem/chains";
110
+
111
+ const account = privateKeyToAccount(process.env.ADMIN_PRIVATE_KEY as `0x${string}`);
112
+ const walletClient = createWalletClient({
113
+ account,
114
+ chain: baseSepolia,
115
+ transport: http(process.env.RPC_URL),
116
+ });
117
+
118
+ const admin = new KokioAdmin(walletClient);
119
+
120
+ // Deploy a device wallet for a user.
121
+ const deployHash = await admin.deviceWalletFactory.createAccount(
122
+ deviceUniqueIdentifier,
123
+ ownerKey,
124
+ salt,
125
+ depositAmount,
126
+ );
127
+ ```
128
+
129
+ The backend often does not know a contract instance address at construction time.
130
+ It deploys a device wallet, then needs to act on it. Bind the address afterwards
131
+ with a setter and keep using the same `KokioAdmin` reference:
132
+
133
+ ```ts
134
+ admin.setDeviceWalletAddress(deviceWalletAddress);
135
+ await admin.deviceWallet!.deployESIMWallet(true, salt);
136
+
137
+ admin.setESIMWalletAddress(eSIMWalletAddress);
138
+ await admin.eSIMWallet!.buyDataBundle({ dataBundleID, dataBundlePrice });
139
+ ```
140
+
141
+ `setDeviceWalletAddress`, `setESIMWalletAddress`, and `setWalletClient` each mutate
142
+ the instance and return `this`, so they can be chained. Admin methods send ordinary
143
+ transactions and resolve to a transaction hash.
144
+
145
+ The chain-wide surfaces (`deviceWalletFactory`, `eSIMWalletFactory`, `registry`,
146
+ `lazyWalletRegistry`) are available as soon as the instance exists. The
147
+ instance-scoped surfaces (`deviceWallet`, `eSIMWallet`) become available once their
148
+ address is set.
149
+
150
+ ## Errors
151
+
152
+ Both entry points re-export a typed error surface, so you can catch and decode
153
+ on-chain reverts without reaching into internal module paths:
154
+
155
+ ```ts
156
+ import { KokioError, ContractRevertError } from "kokio-sdk"; // or "kokio-sdk/admin"
157
+
158
+ try {
159
+ await admin.deviceWalletFactory.requestAdminUpdate(newAdmin);
160
+ } catch (err) {
161
+ if (err instanceof ContractRevertError) {
162
+ console.error("reverted:", err.message);
163
+ }
164
+ }
165
+ ```
166
+
167
+ `KokioError` is the base class. Subclasses include `MissingSmartWalletError`,
168
+ `MissingEOAWalletError`, `InvalidClientError`, `UnsupportedChainError`,
169
+ `CounterfactualMismatchError`, and `ContractRevertError`. `decodeContractRevert`
170
+ turns raw revert data into a readable reason.
171
+
172
+ ## Supported chains
173
+
174
+ The SDK resolves the contract addresses from the wallet client's connected chain
175
+ id, so you do not pass them yourself. Base Sepolia (chain id `84532`) is the
176
+ deployment used in development. Sepolia and other testnets are also configured.
177
+
178
+ ## Testing
179
+
180
+ `npm test` runs the offline unit suite with no network access. Two opt-in
181
+ integration tiers (a read-only parity check against a live RPC, and a local
182
+ `anvil` fork that exercises real write and user-operation flows) are documented in
183
+ [tests/README.md](tests/README.md).
184
+
185
+ ## License
186
+
187
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,102 @@
1
+ import { ConstantsSubPackage } from "../interface/constantsClass.js";
2
+ import { AdminDeviceWalletFactorySubPackage } from "./interface/deviceWalletFactoryClass.js";
3
+ import { AdminESIMWalletFactorySubPackage } from "./interface/eSIMWalletFactoryClass.js";
4
+ import { AdminRegistrySubPackage } from "./interface/registryClass.js";
5
+ import { AdminLazyWalletRegistrySubPackage } from "./interface/lazyWalletRegistryClass.js";
6
+ import { AdminDeviceWalletSubPackage } from "./interface/deviceWalletClass.js";
7
+ import { AdminESIMWalletSubPackage } from "./interface/eSIMWalletClass.js";
8
+ // Re-export the typed error surface so backend consumers can `instanceof
9
+ // KokioError` (or a subclass) and decode reverts without reaching into internal
10
+ // module paths - mirroring `config.ts`.
11
+ export { KokioError, NullOrUndefinedValueError, MissingSmartWalletError, MissingEOAWalletError, InvalidClientError, UnsupportedChainError, UnconfiguredChainError, CounterfactualMismatchError, ContractRevertError, decodeContractRevert, } from "../logic/errors.js";
12
+ /**
13
+ * EOA-only entry point for the NodeJS backend.
14
+ *
15
+ * Unlike {@link Kokio} (the mobile/passkey surface), `KokioAdmin` needs no
16
+ * bundler, paymaster, or WebAuthn params - only a viem `WalletClient` carrying
17
+ * the admin/owner EOA. It exposes exactly the contract functions that are
18
+ * `onlyAdmin`/`onlyOwner`/`onlyESIMWalletAdmin(OrRegistry)` on chain and thus
19
+ * callable directly by an EOA (never via a device-wallet userOp).
20
+ *
21
+ * Contract-instance surfaces (`deviceWallet`, `eSIMWallet`) target a specific
22
+ * deployed address. The backend often does not know that address at construction
23
+ * time - e.g. it deploys a device wallet, then acts on it - so those addresses
24
+ * can be supplied later via {@link setDeviceWalletAddress}/{@link setESIMWalletAddress}
25
+ * on the *same* instance, without re-constructing. The accessors stay `undefined`
26
+ * until their address is set.
27
+ */
28
+ export class KokioAdmin {
29
+ walletClient;
30
+ deviceWalletAddress;
31
+ eSIMWalletAddress;
32
+ _constants;
33
+ // Chain-wide surfaces - available as soon as a wallet client exists.
34
+ deviceWalletFactory;
35
+ eSIMWalletFactory;
36
+ registry;
37
+ lazyWalletRegistry;
38
+ // Instance-scoped surfaces - undefined until their address is known.
39
+ deviceWallet;
40
+ eSIMWallet;
41
+ constructor(walletClient, deviceWalletAddress, eSIMWalletAddress) {
42
+ this.walletClient = walletClient;
43
+ this.deviceWalletAddress = deviceWalletAddress;
44
+ this.eSIMWalletAddress = eSIMWalletAddress;
45
+ this._constants = new ConstantsSubPackage(walletClient);
46
+ this.deviceWalletFactory = new AdminDeviceWalletFactorySubPackage(walletClient);
47
+ this.eSIMWalletFactory = new AdminESIMWalletFactorySubPackage(walletClient);
48
+ this.registry = new AdminRegistrySubPackage(walletClient);
49
+ this.lazyWalletRegistry = new AdminLazyWalletRegistrySubPackage(walletClient);
50
+ this.deviceWallet = deviceWalletAddress ? new AdminDeviceWalletSubPackage(walletClient, deviceWalletAddress) : undefined;
51
+ this.eSIMWallet = eSIMWalletAddress ? new AdminESIMWalletSubPackage(walletClient, eSIMWalletAddress) : undefined;
52
+ }
53
+ /**
54
+ * Chain-specific constants (factory addresses, chain, RPC URLs, custom errors)
55
+ * for the wallet client's connected chain. Resolution is asynchronous because
56
+ * the chain id is read from the client, so this getter returns a promise:
57
+ *
58
+ * const { factoryAddresses } = await admin.constants;
59
+ *
60
+ * The underlying value is memoized, so repeated awaits do not re-fetch.
61
+ * There is no Pimlico key on this surface, so `pimlicoRpcURL` is always `""`.
62
+ */
63
+ get constants() {
64
+ return this._constants.load();
65
+ }
66
+ /**
67
+ * Bind a `DeviceWallet` instance address after construction and (re)wire the
68
+ * `deviceWallet` surface to it. Returns `this` for chaining. This is the
69
+ * backend's primary flow: deploy a wallet, resolve its address, then keep
70
+ * using the same `KokioAdmin` reference.
71
+ */
72
+ setDeviceWalletAddress(deviceWalletAddress) {
73
+ this.deviceWalletAddress = deviceWalletAddress;
74
+ this.deviceWallet = new AdminDeviceWalletSubPackage(this.walletClient, deviceWalletAddress);
75
+ return this;
76
+ }
77
+ /**
78
+ * Bind an `ESIMWallet` instance address after construction and (re)wire the
79
+ * `eSIMWallet` surface to it. Returns `this` for chaining.
80
+ */
81
+ setESIMWalletAddress(eSIMWalletAddress) {
82
+ this.eSIMWalletAddress = eSIMWalletAddress;
83
+ this.eSIMWallet = new AdminESIMWalletSubPackage(this.walletClient, eSIMWalletAddress);
84
+ return this;
85
+ }
86
+ /**
87
+ * Swap the underlying wallet client (e.g. to change the acting EOA) and
88
+ * re-instantiate every surface against it, preserving any bound instance
89
+ * addresses. Returns `this` for chaining.
90
+ */
91
+ setWalletClient(walletClient) {
92
+ this.walletClient = walletClient;
93
+ this._constants = new ConstantsSubPackage(walletClient);
94
+ this.deviceWalletFactory = new AdminDeviceWalletFactorySubPackage(walletClient);
95
+ this.eSIMWalletFactory = new AdminESIMWalletFactorySubPackage(walletClient);
96
+ this.registry = new AdminRegistrySubPackage(walletClient);
97
+ this.lazyWalletRegistry = new AdminLazyWalletRegistrySubPackage(walletClient);
98
+ this.deviceWallet = this.deviceWalletAddress ? new AdminDeviceWalletSubPackage(walletClient, this.deviceWalletAddress) : undefined;
99
+ this.eSIMWallet = this.eSIMWalletAddress ? new AdminESIMWalletSubPackage(walletClient, this.eSIMWalletAddress) : undefined;
100
+ return this;
101
+ }
102
+ }
@@ -0,0 +1,34 @@
1
+ import { _deployESIMWallet, _setESIMUniqueIdentifierForAnESIMWallet, } from "../../logic/admin/deviceWallet.eoa.js";
2
+ import { _deviceUniqueIdentifier, _isValidESIMWallet, _canPullETH, _getVaultAddress, } from "../../logic/admin/reads/deviceWallet.reads.js";
3
+ /**
4
+ * Thin EOA wrapper around a specific `DeviceWallet` instance. The instance
5
+ * address is bound at construction; `KokioAdmin.setDeviceWalletAddress` swaps it
6
+ * by re-instantiating this SubPackage.
7
+ */
8
+ export class AdminDeviceWalletSubPackage {
9
+ walletClient;
10
+ deviceWalletAddress;
11
+ constructor(walletClient, deviceWalletAddress) {
12
+ this.walletClient = walletClient;
13
+ this.deviceWalletAddress = deviceWalletAddress;
14
+ }
15
+ deployESIMWallet(hasAccessToETH, salt) {
16
+ return _deployESIMWallet(this.walletClient, this.deviceWalletAddress, hasAccessToETH, salt);
17
+ }
18
+ setESIMUniqueIdentifierForAnESIMWallet(eSIMWalletAddress, eSIMUniqueIdentifier) {
19
+ return _setESIMUniqueIdentifierForAnESIMWallet(this.walletClient, this.deviceWalletAddress, eSIMWalletAddress, eSIMUniqueIdentifier);
20
+ }
21
+ // Reads: public storage getters and views
22
+ deviceUniqueIdentifier() {
23
+ return _deviceUniqueIdentifier(this.walletClient, this.deviceWalletAddress);
24
+ }
25
+ isValidESIMWallet(eSIMWallet) {
26
+ return _isValidESIMWallet(this.walletClient, this.deviceWalletAddress, eSIMWallet);
27
+ }
28
+ canPullETH(eSIMWallet) {
29
+ return _canPullETH(this.walletClient, this.deviceWalletAddress, eSIMWallet);
30
+ }
31
+ getVaultAddress() {
32
+ return _getVaultAddress(this.walletClient, this.deviceWalletAddress);
33
+ }
34
+ }
@@ -0,0 +1,57 @@
1
+ import { _createAccountWithEOA } from "../../logic/deviceWalletFactory.js";
2
+ import { _deployDeviceWalletForUsers, _postCreateAccount, _addRegistryAddress, _updateVaultAddress, _requestAdminUpdate, _acceptAdminUpdate, _updateDeviceWalletImplementation, } from "../../logic/admin/deviceWalletFactory.eoa.js";
3
+ import { _eSIMWalletAdmin, _vault, _newRequestedAdmin, _deviceWalletInfoAdded, _getCurrentDeviceWalletImplementation, _getCounterFactualAddress, } from "../../logic/admin/reads/deviceWalletFactory.reads.js";
4
+ /**
5
+ * Thin EOA wrapper around `DeviceWalletFactory`. Holds only the wallet client;
6
+ * every method forwards to a logic function. `createAccountWithEOA` reuses the
7
+ * existing shared logic (the same call the mobile surface exposes).
8
+ */
9
+ export class AdminDeviceWalletFactorySubPackage {
10
+ walletClient;
11
+ constructor(walletClient) {
12
+ this.walletClient = walletClient;
13
+ }
14
+ createAccount(deviceUniqueIdentifier, deviceWalletOwnerKey, salt, depositAmount) {
15
+ return _createAccountWithEOA(this.walletClient, deviceUniqueIdentifier, deviceWalletOwnerKey, salt, depositAmount);
16
+ }
17
+ deployDeviceWalletForUsers(deviceUniqueIdentifiers, deviceWalletOwnersKey, salts, depositAmounts, value) {
18
+ return _deployDeviceWalletForUsers(this.walletClient, deviceUniqueIdentifiers, deviceWalletOwnersKey, salts, depositAmounts, value);
19
+ }
20
+ postCreateAccount(deviceWallet, deviceUniqueIdentifier, deviceWalletOwnerKey) {
21
+ return _postCreateAccount(this.walletClient, deviceWallet, deviceUniqueIdentifier, deviceWalletOwnerKey);
22
+ }
23
+ addRegistryAddress(registryContractAddress) {
24
+ return _addRegistryAddress(this.walletClient, registryContractAddress);
25
+ }
26
+ updateVaultAddress(newVaultAddress) {
27
+ return _updateVaultAddress(this.walletClient, newVaultAddress);
28
+ }
29
+ requestAdminUpdate(newAdmin) {
30
+ return _requestAdminUpdate(this.walletClient, newAdmin);
31
+ }
32
+ acceptAdminUpdate() {
33
+ return _acceptAdminUpdate(this.walletClient);
34
+ }
35
+ updateDeviceWalletImplementation(newDeviceImpl) {
36
+ return _updateDeviceWalletImplementation(this.walletClient, newDeviceImpl);
37
+ }
38
+ // Reads: public storage getters and views
39
+ eSIMWalletAdmin() {
40
+ return _eSIMWalletAdmin(this.walletClient);
41
+ }
42
+ vault() {
43
+ return _vault(this.walletClient);
44
+ }
45
+ newRequestedAdmin() {
46
+ return _newRequestedAdmin(this.walletClient);
47
+ }
48
+ deviceWalletInfoAdded(deviceWallet) {
49
+ return _deviceWalletInfoAdded(this.walletClient, deviceWallet);
50
+ }
51
+ getCurrentDeviceWalletImplementation() {
52
+ return _getCurrentDeviceWalletImplementation(this.walletClient);
53
+ }
54
+ getCounterFactualAddress(deviceWalletOwnerKey, deviceUniqueIdentifier, salt) {
55
+ return _getCounterFactualAddress(this.walletClient, deviceWalletOwnerKey, deviceUniqueIdentifier, salt);
56
+ }
57
+ }
@@ -0,0 +1,31 @@
1
+ import { _buyDataBundle } from "../../logic/admin/eSIMWallet.eoa.js";
2
+ import { _eSIMWalletFactory, _eSIMUniqueIdentifier, _newRequestedOwner, _owner, } from "../../logic/admin/reads/eSIMWallet.reads.js";
3
+ /**
4
+ * Thin EOA wrapper around a specific `ESIMWallet` instance. The instance address
5
+ * is bound at construction; `KokioAdmin.setESIMWalletAddress` swaps it by
6
+ * re-instantiating this SubPackage.
7
+ */
8
+ export class AdminESIMWalletSubPackage {
9
+ walletClient;
10
+ eSIMWalletAddress;
11
+ constructor(walletClient, eSIMWalletAddress) {
12
+ this.walletClient = walletClient;
13
+ this.eSIMWalletAddress = eSIMWalletAddress;
14
+ }
15
+ buyDataBundle(dataBundleDetails, value = 0n) {
16
+ return _buyDataBundle(this.walletClient, this.eSIMWalletAddress, dataBundleDetails, value);
17
+ }
18
+ // Reads: public storage getters and views
19
+ eSIMWalletFactory() {
20
+ return _eSIMWalletFactory(this.walletClient, this.eSIMWalletAddress);
21
+ }
22
+ eSIMUniqueIdentifier() {
23
+ return _eSIMUniqueIdentifier(this.walletClient, this.eSIMWalletAddress);
24
+ }
25
+ newRequestedOwner() {
26
+ return _newRequestedOwner(this.walletClient, this.eSIMWalletAddress);
27
+ }
28
+ owner() {
29
+ return _owner(this.walletClient, this.eSIMWalletAddress);
30
+ }
31
+ }
@@ -0,0 +1,22 @@
1
+ import { _addRegistryAddress, _updateESIMWalletImplementation, } from "../../logic/admin/eSIMWalletFactory.eoa.js";
2
+ import { _isESIMWalletDeployed, _getCurrentESIMWalletImplementation, } from "../../logic/admin/reads/eSIMWalletFactory.reads.js";
3
+ /** Thin EOA (owner) wrapper around `ESIMWalletFactory`. */
4
+ export class AdminESIMWalletFactorySubPackage {
5
+ walletClient;
6
+ constructor(walletClient) {
7
+ this.walletClient = walletClient;
8
+ }
9
+ addRegistryAddress(registryContractAddress) {
10
+ return _addRegistryAddress(this.walletClient, registryContractAddress);
11
+ }
12
+ updateESIMWalletImplementation(eSIMWalletImpl) {
13
+ return _updateESIMWalletImplementation(this.walletClient, eSIMWalletImpl);
14
+ }
15
+ // Reads: public storage getters and views
16
+ isESIMWalletDeployed(eSIMWallet) {
17
+ return _isESIMWalletDeployed(this.walletClient, eSIMWallet);
18
+ }
19
+ getCurrentESIMWalletImplementation() {
20
+ return _getCurrentESIMWalletImplementation(this.walletClient);
21
+ }
22
+ }
@@ -0,0 +1,33 @@
1
+ import { _batchPopulateHistory, _deployLazyWalletAndSetESIMIdentifier, _switchESIMIdentifierToNewDeviceIdentifier, } from "../../logic/admin/lazyWalletRegistry.eoa.js";
2
+ import { _upgradeManager, _eSIMIdentifierToDeviceIdentifier, _deviceIdentifierToESIMDetails, _eSIMIdentifiersAssociatedWithDeviceIdentifier, } from "../../logic/admin/reads/lazyWalletRegistry.reads.js";
3
+ /** Thin EOA (eSIMWalletAdmin) wrapper around `LazyWalletRegistry`. */
4
+ export class AdminLazyWalletRegistrySubPackage {
5
+ walletClient;
6
+ constructor(walletClient) {
7
+ this.walletClient = walletClient;
8
+ }
9
+ batchPopulateHistory(deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails) {
10
+ return _batchPopulateHistory(this.walletClient, deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails);
11
+ }
12
+ deployLazyWalletAndSetESIMIdentifier(deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount) {
13
+ return _deployLazyWalletAndSetESIMIdentifier(this.walletClient, deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount);
14
+ }
15
+ switchESIMIdentifierToNewDeviceIdentifier(eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier) {
16
+ return _switchESIMIdentifierToNewDeviceIdentifier(this.walletClient, eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier);
17
+ }
18
+ // Reads: public storage getters
19
+ upgradeManager() {
20
+ return _upgradeManager(this.walletClient);
21
+ }
22
+ eSIMIdentifierToDeviceIdentifier(eSIMIdentifier) {
23
+ return _eSIMIdentifierToDeviceIdentifier(this.walletClient, eSIMIdentifier);
24
+ }
25
+ // Array-backed getters take an element index and return one entry - iterate
26
+ // indices to read the full list (there is no on-chain full-array getter).
27
+ deviceIdentifierToESIMDetails(deviceIdentifier, eSIMIdentifier, index) {
28
+ return _deviceIdentifierToESIMDetails(this.walletClient, deviceIdentifier, eSIMIdentifier, index);
29
+ }
30
+ eSIMIdentifiersAssociatedWithDeviceIdentifier(deviceIdentifier, index) {
31
+ return _eSIMIdentifiersAssociatedWithDeviceIdentifier(this.walletClient, deviceIdentifier, index);
32
+ }
33
+ }
@@ -0,0 +1,43 @@
1
+ import { _addOrUpdateLazyWalletRegistryAddress } from "../../logic/admin/registry.eoa.js";
2
+ import { _eSIMWalletAdmin, _vault, _upgradeManager, _lazyWalletRegistry, _uniqueIdentifierToDeviceWallet, _deviceWalletToOwner, _registeredP256Keys, _isDeviceWalletValid, _isESIMWalletValid, _isESIMWalletOnStandby, } from "../../logic/admin/reads/registry.reads.js";
3
+ /** Thin EOA (owner) wrapper around `Registry`. */
4
+ export class AdminRegistrySubPackage {
5
+ walletClient;
6
+ constructor(walletClient) {
7
+ this.walletClient = walletClient;
8
+ }
9
+ addOrUpdateLazyWalletRegistryAddress(lazyWalletRegistry) {
10
+ return _addOrUpdateLazyWalletRegistryAddress(this.walletClient, lazyWalletRegistry);
11
+ }
12
+ // Reads: public storage getters, including the inherited RegistryHelper mappings
13
+ eSIMWalletAdmin() {
14
+ return _eSIMWalletAdmin(this.walletClient);
15
+ }
16
+ vault() {
17
+ return _vault(this.walletClient);
18
+ }
19
+ upgradeManager() {
20
+ return _upgradeManager(this.walletClient);
21
+ }
22
+ lazyWalletRegistry() {
23
+ return _lazyWalletRegistry(this.walletClient);
24
+ }
25
+ uniqueIdentifierToDeviceWallet(deviceIdentifier) {
26
+ return _uniqueIdentifierToDeviceWallet(this.walletClient, deviceIdentifier);
27
+ }
28
+ deviceWalletToOwner(deviceWallet, index) {
29
+ return _deviceWalletToOwner(this.walletClient, deviceWallet, index);
30
+ }
31
+ registeredP256Keys(hashOfOwnerP256Keys) {
32
+ return _registeredP256Keys(this.walletClient, hashOfOwnerP256Keys);
33
+ }
34
+ isDeviceWalletValid(deviceWallet) {
35
+ return _isDeviceWalletValid(this.walletClient, deviceWallet);
36
+ }
37
+ isESIMWalletValid(eSIMWallet) {
38
+ return _isESIMWalletValid(this.walletClient, eSIMWallet);
39
+ }
40
+ isESIMWalletOnStandby(eSIMWallet) {
41
+ return _isESIMWalletOnStandby(this.walletClient, eSIMWallet);
42
+ }
43
+ }
@@ -6,6 +6,10 @@ import { LazyWalletRegistrySubPackage } from "./interface/lazyWalletRegistryClas
6
6
  import { DeviceWalletSubPackage } from "./interface/deviceWalletClass.js";
7
7
  import { ESIMWalletSubPackage } from "./interface/eSIMWalletClass.js";
8
8
  import { ESIMWalletFactorySubPackage } from "./interface/eSIMWalletFactoryClass.js";
9
+ // Re-export the typed error surface so consumers can `instanceof KokioError`
10
+ // (or a specific subclass) and decode on-chain reverts without reaching into
11
+ // internal module paths.
12
+ export { KokioError, NullOrUndefinedValueError, MissingSmartWalletError, MissingEOAWalletError, InvalidClientError, UnsupportedChainError, UnconfiguredChainError, CounterfactualMismatchError, ContractRevertError, decodeContractRevert, } from "./logic/errors.js";
9
13
  export class Kokio {
10
14
  viemWalletClient;
11
15
  credentialId;
@@ -1,4 +1,4 @@
1
- import { _addESIMWallet, _deployESIMWallet, _getOwner, _getVaultAddress, _payETHForDataBundles, _pullETH, _removeESIMWallet, _setESIMUniqueIdentifierForAnESIMWallet, _toggleAccessToETH } from "../logic/deviceWallet.js";
1
+ import { _addESIMWallet, _getOwner, _getVaultAddress, _removeESIMWallet, _toggleAccessToETH } from "../logic/deviceWallet.js";
2
2
  export class DeviceWalletSubPackage {
3
3
  smartAccountClient;
4
4
  walletClient;
@@ -11,24 +11,12 @@ export class DeviceWalletSubPackage {
11
11
  addESIMWallet(eSIMWalletAddress, hasAccessToETH) {
12
12
  return _addESIMWallet(this.smartAccountClient, this.address, eSIMWalletAddress, hasAccessToETH);
13
13
  }
14
- deployESIMWallet(hasAccessToETH, salt) {
15
- return _deployESIMWallet(this.smartAccountClient, this.address, hasAccessToETH, salt);
16
- }
17
14
  getVaultAddress() {
18
15
  return _getVaultAddress(this.smartAccountClient, this.address);
19
16
  }
20
- payETHForDataBundles(amount) {
21
- return _payETHForDataBundles(this.smartAccountClient, this.address, amount);
22
- }
23
- pullETH(amount) {
24
- return _pullETH(this.smartAccountClient, this.address, amount);
25
- }
26
17
  removeESIMWallet(eSIMWalletAddress, hasAccessToETH) {
27
18
  return _removeESIMWallet(this.smartAccountClient, this.address, eSIMWalletAddress, hasAccessToETH);
28
19
  }
29
- setESIMUniqueIdentifierForAnESIMWallet(eSIMWalletAddress, eSIMUniqueIdentifier) {
30
- return _setESIMUniqueIdentifierForAnESIMWallet(this.smartAccountClient, this.address, eSIMWalletAddress, eSIMUniqueIdentifier);
31
- }
32
20
  toggleAccessToETH(eSIMWalletAddress, hasAccessToETH) {
33
21
  return _toggleAccessToETH(this.smartAccountClient, this.address, eSIMWalletAddress, hasAccessToETH);
34
22
  }
@@ -1,4 +1,4 @@
1
- import { _acceptOwnershipTransfer, _buyDataBundle, _owner, _populateHistory, _requestTransferOwnership, _sendETHToDeviceWallet, _setESIMUniqueIdentifier, _transferOwnership } from "../logic/eSIMWallet.js";
1
+ import { _acceptOwnershipTransfer, _buyDataBundle, _owner, _requestTransferOwnership, _sendETHToDeviceWallet, _setESIMUniqueIdentifier } from "../logic/eSIMWallet.js";
2
2
  export class ESIMWalletSubPackage {
3
3
  client;
4
4
  address;
@@ -15,19 +15,13 @@ export class ESIMWalletSubPackage {
15
15
  owner() {
16
16
  return _owner(this.client, this.address);
17
17
  }
18
- populateHistory(dataBundleDetails) {
19
- return _populateHistory(this.client, this.address, dataBundleDetails);
20
- }
21
18
  requestTransferOwnership(newOwner) {
22
19
  return _requestTransferOwnership(this.client, this.address, newOwner);
23
20
  }
24
21
  sendETHToDeviceWallet(amount) {
25
22
  return _sendETHToDeviceWallet(this.client, this.address, amount);
26
23
  }
27
- _setESIMUniqueIdentifier(eSIMUniqueIdentifier) {
24
+ setESIMUniqueIdentifier(eSIMUniqueIdentifier) {
28
25
  return _setESIMUniqueIdentifier(this.client, this.address, eSIMUniqueIdentifier);
29
26
  }
30
- _transferOwnership(amount) {
31
- return _transferOwnership(this.client, this.address, amount);
32
- }
33
27
  }
@@ -1,4 +1,4 @@
1
- import { _addRegistryAddress, _deployESIMWalletWithEOA, _deployESIMWalletWithUserOp, _getCurrentESIMWalletImplementation } from "../logic/eSIMWalletFactory.js";
1
+ import { _deployESIMWalletWithUserOp, _getCurrentESIMWalletImplementation } from "../logic/eSIMWalletFactory.js";
2
2
  export class ESIMWalletFactorySubPackage {
3
3
  smartAccountClient;
4
4
  walletClient;
@@ -6,16 +6,10 @@ export class ESIMWalletFactorySubPackage {
6
6
  this.smartAccountClient = smartAccountClient;
7
7
  this.walletClient = walletClient;
8
8
  }
9
- deployESIMWalletWithEOA(deviceWalletAddress, salt) {
10
- return _deployESIMWalletWithEOA(this.walletClient, deviceWalletAddress, salt);
11
- }
12
9
  deployESIMWalletWithUserOp(deviceWalletAddress, salt) {
13
10
  return _deployESIMWalletWithUserOp(this.smartAccountClient, deviceWalletAddress, salt);
14
11
  }
15
- addRegistryAddress(registryContractAddress) {
16
- return _addRegistryAddress(this.smartAccountClient, registryContractAddress);
17
- }
18
- _getCurrentESIMWalletImplementation() {
12
+ getCurrentESIMWalletImplementation() {
19
13
  return _getCurrentESIMWalletImplementation(this.smartAccountClient);
20
14
  }
21
15
  }
@@ -1,19 +1,10 @@
1
- import { _batchPopulateHistory, _deployLazyWalletAndSetESIMIdentifier, _isLazyWalletDeployed, _switchESIMIdentifierToNewDeviceIdentifier } from "../logic/lazyWalletRegistry.js";
1
+ import { _isLazyWalletDeployed } from "../logic/lazyWalletRegistry.js";
2
2
  export class LazyWalletRegistrySubPackage {
3
3
  client;
4
4
  constructor(client) {
5
5
  this.client = client;
6
6
  }
7
- _batchPopulateHistory(deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails) {
8
- return _batchPopulateHistory(this.client, deviceUniqueIdentifiers, eSIMUniqueIdentifiers, dataBundleDetails);
9
- }
10
- _deployLazyWalletAndSetESIMIdentifier(deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount) {
11
- return _deployLazyWalletAndSetESIMIdentifier(this.client, deviceOwnerPublicKey, deviceUniqueIdentifier, salt, depositAmount);
12
- }
13
- _isLazyWalletDeployed(deviceUniqueIdentifier) {
7
+ isLazyWalletDeployed(deviceUniqueIdentifier) {
14
8
  return _isLazyWalletDeployed(this.client, deviceUniqueIdentifier);
15
9
  }
16
- _switchESIMIdentifierToNewDeviceIdentifier(eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier) {
17
- return _switchESIMIdentifierToNewDeviceIdentifier(this.client, eSIMIdentifier, oldDeviceIdentifier, newDeviceIdentifier);
18
- }
19
10
  }