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.
Files changed (107) hide show
  1. package/README.md +68 -19
  2. package/dist/esm/abis/BeaconProxy.js +30 -46
  3. package/dist/esm/abis/DeviceWallet.js +546 -535
  4. package/dist/esm/abis/DeviceWalletFactory.js +537 -544
  5. package/dist/esm/abis/ESIMWallet.js +440 -299
  6. package/dist/esm/abis/ESIMWalletFactory.js +372 -289
  7. package/dist/esm/abis/LazyWalletRegistry.js +941 -421
  8. package/dist/esm/abis/P256Verifier.js +29 -29
  9. package/dist/esm/abis/ProtocolAdmin.js +1228 -0
  10. package/dist/esm/abis/Registry.js +1207 -466
  11. package/dist/esm/abis/RegistryHelper.js +414 -20
  12. package/dist/esm/abis/index.js +2 -1
  13. package/dist/esm/admin/config-admin.js +24 -0
  14. package/dist/esm/admin/interface/deviceWalletClass.js +27 -6
  15. package/dist/esm/admin/interface/deviceWalletFactoryClass.js +41 -19
  16. package/dist/esm/admin/interface/eSIMWalletClass.js +10 -1
  17. package/dist/esm/admin/interface/eSIMWalletFactoryClass.js +24 -2
  18. package/dist/esm/admin/interface/lazyWalletRegistryClass.js +83 -4
  19. package/dist/esm/admin/interface/protocolAdminClass.js +195 -0
  20. package/dist/esm/admin/interface/registryClass.js +93 -2
  21. package/dist/esm/config.js +42 -7
  22. package/dist/esm/interface/deviceWalletClass.js +45 -5
  23. package/dist/esm/interface/deviceWalletFactoryClass.js +20 -1
  24. package/dist/esm/interface/eSIMWalletClass.js +12 -3
  25. package/dist/esm/interface/registryClass.js +47 -0
  26. package/dist/esm/interface/smartAccountClass.js +2 -4
  27. package/dist/esm/logic/account-kit/createSmartAccount.js +156 -102
  28. package/dist/esm/logic/admin/deviceWallet.eoa.js +23 -12
  29. package/dist/esm/logic/admin/deviceWalletFactory.eoa.js +63 -42
  30. package/dist/esm/logic/admin/eSIMWallet.eoa.js +3 -5
  31. package/dist/esm/logic/admin/eSIMWalletFactory.eoa.js +76 -8
  32. package/dist/esm/logic/admin/lazyWalletRegistry.eoa.js +330 -19
  33. package/dist/esm/logic/admin/protocolAdmin.eoa.js +524 -0
  34. package/dist/esm/logic/admin/reads/deviceWallet.reads.js +82 -7
  35. package/dist/esm/logic/admin/reads/deviceWalletFactory.reads.js +82 -23
  36. package/dist/esm/logic/admin/reads/eSIMWallet.reads.js +50 -6
  37. package/dist/esm/logic/admin/reads/eSIMWalletFactory.reads.js +63 -5
  38. package/dist/esm/logic/admin/reads/lazyWalletRegistry.reads.js +171 -10
  39. package/dist/esm/logic/admin/reads/protocolAdmin.reads.js +154 -0
  40. package/dist/esm/logic/admin/reads/registry.reads.js +289 -9
  41. package/dist/esm/logic/admin/registry.eoa.js +274 -4
  42. package/dist/esm/logic/constants.js +53 -26
  43. package/dist/esm/logic/deviceWallet.js +224 -31
  44. package/dist/esm/logic/deviceWalletFactory.js +89 -0
  45. package/dist/esm/logic/eSIMWallet.js +113 -43
  46. package/dist/esm/logic/eSIMWalletFactory.js +8 -8
  47. package/dist/esm/logic/errors.js +64 -0
  48. package/dist/esm/logic/registry.js +236 -0
  49. package/dist/esm/logic/utils.js +2 -1
  50. package/dist/types/abis/BeaconProxy.d.ts +21 -33
  51. package/dist/types/abis/DeviceWallet.d.ts +372 -365
  52. package/dist/types/abis/DeviceWalletFactory.d.ts +438 -448
  53. package/dist/types/abis/ESIMWallet.d.ts +352 -245
  54. package/dist/types/abis/ESIMWalletFactory.d.ts +278 -216
  55. package/dist/types/abis/LazyWalletRegistry.d.ts +710 -317
  56. package/dist/types/abis/P256Verifier.d.ts +16 -16
  57. package/dist/types/abis/ProtocolAdmin.d.ts +947 -0
  58. package/dist/types/abis/Registry.d.ts +960 -393
  59. package/dist/types/abis/RegistryHelper.d.ts +317 -16
  60. package/dist/types/abis/index.d.ts +2 -1
  61. package/dist/types/admin/config-admin.d.ts +16 -0
  62. package/dist/types/admin/interface/deviceWalletClass.d.ts +10 -3
  63. package/dist/types/admin/interface/deviceWalletFactoryClass.d.ts +14 -7
  64. package/dist/types/admin/interface/eSIMWalletClass.d.ts +3 -0
  65. package/dist/types/admin/interface/eSIMWalletFactoryClass.d.ts +8 -1
  66. package/dist/types/admin/interface/lazyWalletRegistryClass.d.ts +38 -2
  67. package/dist/types/admin/interface/protocolAdminClass.d.ts +95 -0
  68. package/dist/types/admin/interface/registryClass.d.ts +30 -0
  69. package/dist/types/config.d.ts +26 -5
  70. package/dist/types/interface/P256VerifierClass.d.ts +3 -4
  71. package/dist/types/interface/constantsClass.d.ts +2 -2
  72. package/dist/types/interface/deviceWalletClass.d.ts +22 -2569
  73. package/dist/types/interface/deviceWalletFactoryClass.d.ts +10 -2564
  74. package/dist/types/interface/eSIMWalletClass.d.ts +11 -8
  75. package/dist/types/interface/eSIMWalletFactoryClass.d.ts +5 -2565
  76. package/dist/types/interface/registryClass.d.ts +19 -0
  77. package/dist/types/interface/smartAccountClass.d.ts +6 -2568
  78. package/dist/types/logic/P256Verifier.d.ts +2 -2
  79. package/dist/types/logic/account-kit/createSmartAccount.d.ts +43 -19
  80. package/dist/types/logic/admin/deviceWallet.eoa.d.ts +15 -9
  81. package/dist/types/logic/admin/deviceWalletFactory.eoa.d.ts +34 -23
  82. package/dist/types/logic/admin/eSIMWallet.eoa.d.ts +0 -5
  83. package/dist/types/logic/admin/eSIMWalletFactory.eoa.d.ts +27 -9
  84. package/dist/types/logic/admin/lazyWalletRegistry.eoa.d.ts +102 -10
  85. package/dist/types/logic/admin/protocolAdmin.eoa.d.ts +163 -0
  86. package/dist/types/logic/admin/reads/deviceWallet.reads.d.ts +28 -8
  87. package/dist/types/logic/admin/reads/deviceWalletFactory.reads.d.ts +45 -14
  88. package/dist/types/logic/admin/reads/eSIMWallet.reads.d.ts +25 -6
  89. package/dist/types/logic/admin/reads/eSIMWalletFactory.reads.d.ts +21 -6
  90. package/dist/types/logic/admin/reads/lazyWalletRegistry.reads.d.ts +44 -11
  91. package/dist/types/logic/admin/reads/protocolAdmin.reads.d.ts +53 -0
  92. package/dist/types/logic/admin/reads/registry.reads.d.ts +105 -9
  93. package/dist/types/logic/admin/registry.eoa.d.ts +102 -5
  94. package/dist/types/logic/constants.d.ts +2 -0
  95. package/dist/types/logic/deviceWallet.d.ts +78 -6
  96. package/dist/types/logic/deviceWalletFactory.d.ts +32 -3
  97. package/dist/types/logic/eSIMWallet.d.ts +48 -7
  98. package/dist/types/logic/eSIMWalletFactory.d.ts +3 -3
  99. package/dist/types/logic/errors.d.ts +45 -0
  100. package/dist/types/logic/registry.d.ts +78 -0
  101. package/dist/types/types-export.d.ts +1 -1
  102. package/dist/types/types.d.ts +111 -1
  103. package/package.json +11 -13
  104. package/dist/esm/interface/lazyWalletRegistryClass.js +0 -10
  105. package/dist/esm/logic/lazyWalletRegistry.js +0 -19
  106. package/dist/types/interface/lazyWalletRegistryClass.d.ts +0 -6
  107. package/dist/types/logic/lazyWalletRegistry.d.ts +0 -2
@@ -1,4 +1,4 @@
1
1
  import { Hex } from "viem";
2
2
  import { WebAuthnSignature } from "../types.js";
3
- import { SmartAccountClient } from "@aa-sdk/core";
4
- export declare const _verifySignature: (client: SmartAccountClient, message: Hex, requireMessageVerification: boolean, webAuthnSignature: WebAuthnSignature, x: bigint, y: bigint) => Promise<boolean>;
3
+ import { KokioSmartAccountClient } from "../types.js";
4
+ export declare const _verifySignature: (client: KokioSmartAccountClient, message: Hex, requireMessageVerification: boolean, webAuthnSignature: WebAuthnSignature, x: bigint, y: bigint) => Promise<boolean>;
@@ -1,6 +1,5 @@
1
- import { SmartContractAccount, SmartAccountClient } from "@aa-sdk/core";
2
- import { type SignableMessage, WalletClient, Hex, TypedDataDefinition, TypedData } from "viem";
3
- import { P256Key, WebAuthnSignature } from "../../types.js";
1
+ import { type SignableMessage, WalletClient, Hex, Address, TypedDataDefinition, TypedData } from "viem";
2
+ import { P256Key, WebAuthnSignature, KokioSmartAccount, KokioSmartAccountClient } from "../../types.js";
4
3
  /**
5
4
  * BeaconProxy creation bytecode, used to compute the CREATE2 counterfactual
6
5
  * DeviceWallet address off-chain (initCode = creationCode ++ abi.encode(beacon, initData)).
@@ -9,35 +8,60 @@ import { P256Key, WebAuthnSignature } from "../../types.js";
9
8
  * DeviceWalletFactory deploys, or the computed address will diverge from the
10
9
  * deployed one. Source of truth:
11
10
  * OpenZeppelin Contracts v5.0.0 - proxy/beacon/BeaconProxy.sol
12
- * compiled by Hardhat (smart-contract-suite `artifacts/@openzeppelin/contracts/
13
- * proxy/beacon/BeaconProxy.sol/BeaconProxy.json`), solc 0.8.25+commit.b61c2a91,
14
- * optimizer { enabled: true, runs: 200 }, viaIR: true.
15
- * NOTE: the Foundry `out/` artifact (different optimizer settings) produces a
16
- * DIFFERENT bytecode - do not swap it in without re-verifying the counterfactual.
17
- * `_assertCounterfactualMatchesOnChain` guards against drift at runtime.
11
+ * smart-contract-suite `deployments/base-sepolia-84532-entrypoint-v8.json`,
12
+ * section `create2`, solc 0.8.36, optimizer runs 10000000, viaIR: true,
13
+ * evm target osaka. Hash: 0xc571dd76379a732e12f1973fa9f4cbbaeb1702bb0ace06e5beb7e2b56cd03c6b.
14
+ * NOTE: a different optimizer/compiler setting produces a DIFFERENT bytecode -
15
+ * do not swap it in without re-verifying the counterfactual.
16
+ * `_assertCounterfactualMatchesOnChain` guards against drift; `_getSmartWallet`
17
+ * runs it once per chain per process.
18
18
  */
19
19
  export declare const BEACON_PROXY_CREATION_CODE: Hex;
20
+ /**
21
+ * Stamp is client-side authentication. Since the passkeys are on the user's mobile device
22
+ * react-native-passkey helps fetch passkey for the user (provided credentialId, rpId).
23
+ * This is exactly how the WebAuthn.sol contract needs it to be.
24
+ */
20
25
  export declare const _stamp: (credentialId: string, rpId: string, payload: Hex) => Promise<WebAuthnSignature>;
21
- export declare const _getAccountInitCode: (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<Hex>;
26
+ type Call = {
27
+ to: Hex;
28
+ data?: Hex | undefined;
29
+ value?: bigint | undefined;
30
+ };
31
+ export declare const _encodeCalls: (calls: readonly Call[]) => Promise<Hex>;
32
+ export declare const _getFactoryArgs: (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<{
33
+ factory: Address;
34
+ factoryData: Hex;
35
+ }>;
22
36
  export declare const getInitCodeHash: (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key) => Promise<Hex>;
23
37
  export declare const getCounterFactualAddress: (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<Hex>;
24
38
  /**
25
- * Optional drift guard. Recomputes the counterfactual address off-chain (using
26
- * the pinned {@link BEACON_PROXY_CREATION_CODE}) and compares it against the
39
+ * Drift guard. Recomputes the counterfactual address off-chain (using the
40
+ * pinned {@link BEACON_PROXY_CREATION_CODE}) and compares it against the
27
41
  * on-chain `DeviceWalletFactory.getCounterFactualAddress` view - which derives
28
42
  * the address from the BeaconProxy the factory ACTUALLY deploys. A mismatch
29
43
  * means the pinned proxy bytecode (or init encoding) has drifted from the
30
44
  * deployed contract, so this throws early instead of letting a UserOp deploy to,
31
45
  * or fund, the wrong address.
32
46
  *
33
- * Not wired into the default account-creation path (it costs one extra RPC);
34
- * call it explicitly in environments where you want the extra safety, e.g.
35
- * after a contract redeploy or on first use against a new chain.
47
+ * `_getSmartWallet` runs this once per chain per process; call it directly for
48
+ * an unconditional check, e.g. right after a contract redeploy.
36
49
  */
37
50
  export declare const _assertCounterfactualMatchesOnChain: (client: WalletClient, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<Hex>;
38
51
  export declare const _encodeSignature: (webAuthnSignature: WebAuthnSignature, validUntil: number) => Promise<Hex>;
39
- export declare const _signMessage: (message: SignableMessage, credentialId: string, rpId: string) => Promise<Hex>;
40
- export declare const _signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(typedData: TypedDataDefinition<typedData, primaryType>, credentialId: string, rpId: string) => Promise<Hex>;
52
+ export declare const _signMessage: (message: SignableMessage, credentialId: string, rpId: string, chainId: number, accountAddress: Address) => Promise<Hex>;
53
+ export declare const _signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(typedData: TypedDataDefinition<typedData, primaryType>, credentialId: string, rpId: string, chainId: number, accountAddress: Address) => Promise<Hex>;
41
54
  export declare const _signUserOperationHash: (credentialId: string, rpId: string, userOpHash: Hex) => Promise<Hex>;
42
- export declare const _getSmartWallet: (client: WalletClient, credentialId: string, rpId: string, organiationId: string, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<SmartContractAccount>;
43
- export declare const _getSmartWalletClient: (client: WalletClient, pimlicoAPIKey: string, gasPolicyId: string, account: SmartContractAccount) => Promise<SmartAccountClient>;
55
+ export declare const _getSmartWallet: (client: WalletClient, credentialId: string, rpId: string, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<KokioSmartAccount>;
56
+ type RawGasEstimate = Record<string, Hex>;
57
+ /**
58
+ * Raise the bundler's verification estimates to what a real signature costs.
59
+ * See `STUB_VERIFICATION_GAS_PAD` for the measurements behind the numbers.
60
+ *
61
+ * This sits in the transport because viem binds `prepareUserOperation` to the
62
+ * client as it was before `.extend` ran, so an `estimateUserOperationGas`
63
+ * override placed on the client is never the one it calls.
64
+ */
65
+ export declare const _padGasEstimate: (estimate: RawGasEstimate) => RawGasEstimate;
66
+ export declare const _getSmartWalletClient: (client: WalletClient, pimlicoAPIKey: string, gasPolicyId: string, account: KokioSmartAccount) => Promise<KokioSmartAccountClient>;
67
+ export {};
@@ -1,12 +1,18 @@
1
1
  import { Address, WalletClient } from "viem";
2
2
  /**
3
- * Admin-EOA logic targeting a specific `DeviceWallet` instance (its address is
4
- * passed in - there is no single factory address). Both functions are admin
5
- * gated on chain (`deployESIMWallet` is `onlyESIMWalletAdmin`,
6
- * `setESIMUniqueIdentifierForAnESIMWallet` is `onlyESIMWalletAdminOrRegistry`),
7
- * so they cannot be driven from a device-wallet userOp and live on the EOA surface.
3
+ * Deploy a new eSIM wallet under a device wallet. `onlyESIMWalletAdmin`.
4
+ *
5
+ * The bind that follows never carries ETH access: the contract reverts on a
6
+ * `true` rather than downgrading it quietly, so the SDK passes `false` and there
7
+ * is nothing to choose. The owner grants access afterwards with
8
+ * `toggleAccessToETH`, which the admin EOA cannot reach.
8
9
  */
9
- /** Deploy a new eSIM wallet under a device wallet. `onlyESIMWalletAdmin`. */
10
- export declare const _deployESIMWallet: (client: WalletClient, deviceWalletAddress: Address, hasAccessToETH: boolean, salt: bigint) => Promise<`0x${string}`>;
11
- /** Bind an eSIM's unique identifier to its wallet. `onlyESIMWalletAdminOrRegistry`. */
12
- export declare const _setESIMUniqueIdentifierForAnESIMWallet: (client: WalletClient, deviceWalletAddress: Address, eSIMWalletAddress: Address, eSIMUniqueIdentifier: string) => Promise<`0x${string}`>;
10
+ export declare const _deployESIMWallet: (client: WalletClient, deviceWalletAddress: Address, salt: bigint) => Promise<`0x${string}`>;
11
+ /**
12
+ * Top up a device wallet's gas deposit at the EntryPoint, paid by the admin EOA.
13
+ *
14
+ * Open to anyone: paying another account's gas costs the payer and nobody else.
15
+ * `withdrawDepositTo` is `onlySelf`, so only the wallet's owner can take it back
16
+ * out, and topping one up is not a way to reach its funds.
17
+ */
18
+ export declare const _addDeposit: (client: WalletClient, deviceWalletAddress: Address, amount: bigint) => Promise<`0x${string}`>;
@@ -1,33 +1,44 @@
1
- import { Address, WalletClient } from "viem";
2
- import { P256Key } from "../../types.js";
3
- /**
4
- * Admin-EOA logic for `DeviceWalletFactory`.
5
- *
6
- * Every function here is `onlyAdmin` / `onlyAdminOrRegistry` / `onlyOwner` on
7
- * chain, i.e. the caller must be the `eSIMWalletAdmin` (or `upgradeManager`)
8
- * EOA - never a device-wallet userOp. They therefore live on the EOA surface
9
- * (`KokioAdmin`) and use `writeContract`, mirroring `_createAccountWithEOA`
10
- * (which is reused as-is from `../deviceWalletFactory.js`).
11
- */
1
+ import { Address, Hex, WalletClient } from "viem";
2
+ import { OwnerCall, P256Key } from "../../types.js";
12
3
  /**
13
4
  * Batch-deploy device wallets for lazy/fiat users. `onlyAdminOrRegistry`,
14
5
  * `payable`: `value` is the total ETH pot from which each `depositAmounts[i]`
15
6
  * is drawn; any surplus is refunded to the caller on chain.
16
7
  */
17
8
  export declare const _deployDeviceWalletForUsers: (client: WalletClient, deviceUniqueIdentifiers: Array<string>, deviceWalletOwnersKey: Array<P256Key>, salts: Array<bigint>, depositAmounts: Array<bigint>, value: bigint) => Promise<`0x${string}`>;
18
- /** Register a freshly created device wallet with the factory. `onlyAdminOrRegistry`. */
19
- export declare const _postCreateAccount: (client: WalletClient, deviceWallet: Address, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key) => Promise<`0x${string}`>;
20
- /** One-time wiring of the registry into the factory. `onlyAdmin`. */
21
- export declare const _addRegistryAddress: (client: WalletClient, registryContractAddress: Address) => Promise<`0x${string}`>;
22
- /** Update the vault that receives eSIM payments. `onlyAdmin`. */
23
- export declare const _updateVaultAddress: (client: WalletClient, newVaultAddress: Address) => Promise<`0x${string}`>;
24
- /** Step 1 of the 2-step admin handover: propose a new admin. `onlyAdmin`. */
25
- export declare const _requestAdminUpdate: (client: WalletClient, newAdmin: Address) => Promise<`0x${string}`>;
26
9
  /**
27
- * Step 2 of the 2-step admin handover: the proposed admin accepts. The chain
28
- * requires `msg.sender` to equal the pending admin, so the `client` here must
29
- * be the newly proposed admin EOA.
10
+ * Register a freshly created device wallet with the factory. `onlyAdminOrRegistry`.
11
+ * The salt has to be the one the deploying `createAccount` used, since the
12
+ * factory rederives the counterfactual address from it to check the wallet.
30
13
  */
31
- export declare const _acceptAdminUpdate: (client: WalletClient) => Promise<`0x${string}`>;
14
+ export declare const _postCreateAccount: (client: WalletClient, deviceWallet: Address, deviceUniqueIdentifier: string, deviceWalletOwnerKey: P256Key, salt: bigint) => Promise<`0x${string}`>;
15
+ /** One-time wiring of the registry into the factory. `onlyAdmin`. */
16
+ export declare const _addRegistryAddress: (client: WalletClient, registryContractAddress: Address) => Promise<`0x${string}`>;
32
17
  /** Point the device-wallet beacon at a new implementation. `onlyOwner` (upgradeManager). */
33
18
  export declare const _updateDeviceWalletImplementation: (client: WalletClient, newDeviceImpl: Address) => Promise<`0x${string}`>;
19
+ /**
20
+ * Offer ownership to a new address. Pass the result to `schedule`.
21
+ *
22
+ * Ownable2Step, so the offer changes nothing until the named address calls
23
+ * `acceptOwnership`. Note this hands over the beacon too, since the factory owns
24
+ * it, so the new owner can move every deployed device wallet at once.
25
+ */
26
+ export declare const _transferOwnershipCall: (client: WalletClient, newOwner: Address) => Promise<OwnerCall>;
27
+ /**
28
+ * Point the factory's own proxy at a new implementation. Builds
29
+ * `upgradeToAndCall`. Pass the result to `schedule`.
30
+ *
31
+ * This does not touch deployed device wallets. They read their implementation
32
+ * from the beacon, which moves through `updateDeviceWalletImplementation`
33
+ * instead. Changing what the factory deploys next is a beacon update, not this.
34
+ */
35
+ export declare const _upgradeCall: (client: WalletClient, newImplementation: Address, data?: Hex) => Promise<OwnerCall>;
36
+ /**
37
+ * Take ownership after a `transferOwnership` named this client. `msg.sender`
38
+ * must equal `pendingOwner`, so the `client` is the incoming owner.
39
+ *
40
+ * Where the incoming owner is the timelock, use
41
+ * `protocolAdmin.acceptOwnershipBatch` instead, which accepts for every contract
42
+ * at once.
43
+ */
44
+ export declare const _acceptOwnership: (client: WalletClient) => Promise<`0x${string}`>;
@@ -1,10 +1,5 @@
1
1
  import { Address, WalletClient } from "viem";
2
2
  import { DataBundleDetails } from "../../types.js";
3
- /**
4
- * Admin-EOA logic targeting a specific `ESIMWallet` instance (address passed in).
5
- * `buyDataBundle` is `onlyDeviceWalletOrESIMWalletAdmin`, so the admin EOA can
6
- * call it directly.
7
- */
8
3
  /**
9
4
  * Buy a data bundle for an eSIM wallet. `onlyDeviceWalletOrESIMWalletAdmin`,
10
5
  * `payable`. `value` is optional: the contract pulls any shortfall from the
@@ -1,13 +1,31 @@
1
- import { Address, WalletClient } from "viem";
2
- /**
3
- * Admin-EOA logic for `ESIMWalletFactory`. Both functions are owner-gated
4
- * (`addRegistryAddress` requires `msg.sender == owner()`, `updateESIMWalletImplementation`
5
- * is `onlyOwner`), so the `client` must carry the `upgradeManager` EOA.
6
- *
7
- * Note: `ESIMWalletFactory.deployESIMWallet` is intentionally NOT exposed - it is
8
- * `onlyRegistryOrDeviceWalletFactoryOrDeviceWallet`, so a bare EOA always reverts.
9
- */
1
+ import { Address, Hex, WalletClient } from "viem";
2
+ import type { OwnerCall } from "../../types.js";
10
3
  /** One-time wiring of the registry into the eSIM factory. Owner only. */
11
4
  export declare const _addRegistryAddress: (client: WalletClient, registryContractAddress: Address) => Promise<`0x${string}`>;
12
5
  /** Point the eSIM-wallet beacon at a new implementation. `onlyOwner`. */
13
6
  export declare const _updateESIMWalletImplementation: (client: WalletClient, eSIMWalletImpl: Address) => Promise<`0x${string}`>;
7
+ /**
8
+ * Offer ownership to a new address. Pass the result to `schedule`.
9
+ *
10
+ * Ownable2Step, so the offer changes nothing until the named address calls
11
+ * `acceptOwnership`. Note this hands over the beacon too, since the factory owns
12
+ * it, so the new owner can move every deployed eSIM wallet at once.
13
+ */
14
+ export declare const _transferOwnershipCall: (client: WalletClient, newOwner: Address) => Promise<OwnerCall>;
15
+ /**
16
+ * Point the factory's own proxy at a new implementation. Builds
17
+ * `upgradeToAndCall`. Pass the result to `schedule`.
18
+ *
19
+ * This does not touch deployed eSIM wallets. They read their implementation from
20
+ * the beacon, which moves through `updateESIMWalletImplementation` instead.
21
+ */
22
+ export declare const _upgradeCall: (client: WalletClient, newImplementation: Address, data?: Hex) => Promise<OwnerCall>;
23
+ /**
24
+ * Take ownership after a `transferOwnership` named this client. `msg.sender`
25
+ * must equal `pendingOwner`, so the `client` is the incoming owner.
26
+ *
27
+ * Where the incoming owner is the timelock, use
28
+ * `protocolAdmin.acceptOwnershipBatch` instead, which accepts for every contract
29
+ * at once.
30
+ */
31
+ export declare const _acceptOwnership: (client: WalletClient) => Promise<`0x${string}`>;
@@ -1,18 +1,110 @@
1
- import { WalletClient } from "viem";
2
- import { DataBundleDetails, P256Key } from "../../types.js";
1
+ import { Address, Hex, WalletClient } from "viem";
2
+ import type { DataBundleDetails, LazyDeployment, LazyHistoryCopy, OwnerCall, P256Key } from "../../types.js";
3
3
  /**
4
- * Admin-EOA logic for `LazyWalletRegistry`. All three functions are
5
- * `onlyESIMWalletAdmin` on chain, so they can only succeed from the admin EOA -
6
- * a device-wallet userOp (whose sender is the smart account) always reverts.
7
- * This is why they belong on the EOA surface rather than the mobile userOp one.
4
+ * The contract's own caps, mirrored here because they are `constant` on chain and
5
+ * reading them would cost a round trip on every call. The fork tier checks these
6
+ * against the live deployment, so an upgrade that moved one would fail there
7
+ * rather than turning every call into a reverted transaction.
8
8
  */
9
+ export declare const MAX_ESIM_WALLETS_PER_CALL = 20n;
10
+ export declare const MAX_HISTORY_ENTRIES_PER_CALL = 50n;
11
+ /**
12
+ * Default batch sizes, both below the caps above.
13
+ *
14
+ * A continuation call costs about 28,000 gas before it deploys anything, against
15
+ * roughly 556,000 per eSIM wallet, so a smaller batch buys headroom for almost
16
+ * nothing: running a 45 eSIM device at 10 rather than 20 costs about 0.4% more
17
+ * gas in total. That headroom matters because a full batch of 20 measures between
18
+ * 9.3M and 11.8M gas depending on identifier length and storage warmth, which is
19
+ * uncomfortably close to a per-transaction gas ceiling.
20
+ */
21
+ export declare const DEFAULT_ESIM_WALLETS_PER_CALL = 10n;
22
+ export declare const DEFAULT_HISTORY_ENTRIES_PER_CALL = 25n;
9
23
  /** Record fiat/lazy purchase history for a batch of devices. `onlyESIMWalletAdmin`. */
10
24
  export declare const _batchPopulateHistory: (client: WalletClient, deviceUniqueIdentifiers: Array<string>, eSIMUniqueIdentifiers: Array<Array<string>>, dataBundleDetails: Array<Array<DataBundleDetails>>) => Promise<`0x${string}`>;
11
25
  /**
12
- * Materialise a lazily-provisioned device wallet and its eSIMs on chain.
13
- * `onlyESIMWalletAdmin`, `payable`: the contract requires `depositAmount == msg.value`,
14
- * so `value` is set to `depositAmount` here.
26
+ * Materialise a lazily-provisioned device wallet and the first batch of its eSIMs
27
+ * on chain. `onlyESIMWalletAdmin`, `payable`: the contract requires
28
+ * `depositAmount == msg.value`, so `value` is set to `depositAmount` here.
29
+ *
30
+ * One transaction. `maxWallets` caps how many eSIM wallets it deploys, and the
31
+ * contract refuses anything above `MAX_ESIM_WALLETS_PER_CALL` rather than
32
+ * clamping it. Prefer `_deployLazyWalletAllBatches`, which finishes the device.
33
+ */
34
+ export declare const _deployLazyWalletAndSetESIMIdentifier: (client: WalletClient, deviceOwnerPublicKey: P256Key, deviceUniqueIdentifier: string, salt: bigint, depositAmount: bigint, maxWallets: bigint) => Promise<`0x${string}`>;
35
+ /**
36
+ * Deploy the next batch of eSIM wallets for a device the lazy route already
37
+ * started. `onlyESIMWalletAdmin`.
38
+ *
39
+ * One transaction. The contract reads its position from a cursor, so a dropped
40
+ * transaction is retried by repeating the identical call. It reverts
41
+ * `AllESIMWalletsDeployed` once nothing is left, which is the terminal condition
42
+ * rather than a failure.
15
43
  */
16
- export declare const _deployLazyWalletAndSetESIMIdentifier: (client: WalletClient, deviceOwnerPublicKey: P256Key, deviceUniqueIdentifier: string, salt: bigint, depositAmount: bigint) => Promise<`0x${string}`>;
44
+ export declare const _deployMoreESIMWalletsForLazyDevice: (client: WalletClient, deviceUniqueIdentifier: string, maxWallets: bigint) => Promise<`0x${string}`>;
45
+ /**
46
+ * Copy the next batch of an eSIM's stored purchase history onto its deployed
47
+ * wallet. `onlyESIMWalletAdmin`.
48
+ *
49
+ * One transaction, with its own cursor per eSIM. Reverts `HistoryAlreadyCopied`
50
+ * once nothing is left. Prefer `_setHistoryForLazyWalletAllBatches`.
51
+ */
52
+ export declare const _setHistoryForLazyWallet: (client: WalletClient, eSIMIdentifier: string, maxEntries: bigint) => Promise<`0x${string}`>;
17
53
  /** Re-point an eSIM identifier from an old device to a new one. `onlyESIMWalletAdmin`. */
18
54
  export declare const _switchESIMIdentifierToNewDeviceIdentifier: (client: WalletClient, eSIMIdentifier: string, oldDeviceIdentifier: string, newDeviceIdentifier: string) => Promise<`0x${string}`>;
55
+ /**
56
+ * Deploy a lazy device and every one of its eSIM wallets, over as many
57
+ * transactions as that takes. `onlyESIMWalletAdmin`.
58
+ *
59
+ * Resumable. A device that is part-deployed, because a batch was dropped or an
60
+ * earlier call threw, is continued from its cursor instead of being restarted,
61
+ * so retrying is just calling this again with the same arguments. Pass a deposit
62
+ * of 0 on a retry: only the first batch is payable and it already took one.
63
+ *
64
+ * All of a device's purchase history has to be recorded before this runs. The
65
+ * first batch creates the device wallet, and `batchPopulateHistory` refuses any
66
+ * device that has one.
67
+ *
68
+ * @param maxWallets eSIM wallets per transaction, 1 to `MAX_ESIM_WALLETS_PER_CALL`.
69
+ */
70
+ export declare const _deployLazyWalletAllBatches: (client: WalletClient, deviceOwnerPublicKey: P256Key, deviceUniqueIdentifier: string, salt: bigint, depositAmount: bigint, maxWallets?: bigint) => Promise<LazyDeployment>;
71
+ /**
72
+ * Copy an eSIM's whole stored purchase history onto its wallet, over as many
73
+ * transactions as that takes. `onlyESIMWalletAdmin`.
74
+ *
75
+ * Resumable for the same reason as the deployment: the cursor lives on chain, so
76
+ * a partly copied eSIM is continued rather than restarted.
77
+ *
78
+ * The history cursor is per eSIM and the deploy cursor is per device, so this can
79
+ * run against an eSIM whose wallet has landed while its siblings are still
80
+ * undeployed.
81
+ *
82
+ * @param maxEntries entries per transaction, 1 to `MAX_HISTORY_ENTRIES_PER_CALL`.
83
+ */
84
+ export declare const _setHistoryForLazyWalletAllBatches: (client: WalletClient, eSIMIdentifier: string, maxEntries?: bigint) => Promise<LazyHistoryCopy>;
85
+ /**
86
+ * Offer ownership to a new address. Pass the result to `schedule`.
87
+ *
88
+ * Ownable2Step, so the offer changes nothing until the named address calls
89
+ * `acceptOwnership`. Until then the current owner keeps every power.
90
+ */
91
+ export declare const _transferOwnershipCall: (client: WalletClient, newOwner: Address) => Promise<OwnerCall>;
92
+ /**
93
+ * Point the proxy at a new implementation. Builds `upgradeToAndCall`. Pass the
94
+ * result to `schedule`.
95
+ *
96
+ * This contract holds every fiat user's unclaimed purchase history, so a layout
97
+ * change here strands data that has no other copy. Diff the storage layout
98
+ * before scheduling. `data` runs on the proxy straight after the swap and is
99
+ * where a `reinitializer` goes.
100
+ */
101
+ export declare const _upgradeCall: (client: WalletClient, newImplementation: Address, data?: Hex) => Promise<OwnerCall>;
102
+ /**
103
+ * Take ownership after a `transferOwnership` named this client. `msg.sender`
104
+ * must equal `pendingOwner`, so the `client` is the incoming owner.
105
+ *
106
+ * Where the incoming owner is the timelock, use
107
+ * `protocolAdmin.acceptOwnershipBatch` instead, which accepts for every contract
108
+ * at once.
109
+ */
110
+ export declare const _acceptOwnership: (client: WalletClient) => Promise<`0x${string}`>;
@@ -0,0 +1,163 @@
1
+ import { Address, Hex, WalletClient } from "viem";
2
+ import type { OperationOptions, OwnerCall, ScheduledBatchOperation, ScheduledOperation } from "../../types.js";
3
+ /**
4
+ * The id the timelock will file this call under. Computed on chain so the SDK
5
+ * and the contract cannot disagree about it.
6
+ */
7
+ export declare const _operationId: (client: WalletClient, call: OwnerCall, opts?: OperationOptions) => Promise<Hex>;
8
+ /** The id for a batch. Hashes differently from the same calls scheduled one by one. */
9
+ export declare const _operationIdBatch: (client: WalletClient, calls: readonly OwnerCall[], opts?: OperationOptions) => Promise<Hex>;
10
+ /**
11
+ * The id for a payload built outside this SDK. `_scheduleRaw` hands back only a
12
+ * transaction hash, so this is the only way to get the id that `cancel`,
13
+ * `getTimestamp` and the `isOperation*` reads need.
14
+ */
15
+ export declare const _operationIdRaw: (client: WalletClient, target: Address, value: bigint, payload: Hex, predecessor: Hex, salt: Hex) => Promise<Hex>;
16
+ /** The id for a raw batch. Same reason as `_operationIdRaw`. */
17
+ export declare const _operationIdBatchRaw: (client: WalletClient, targets: readonly Address[], callValues: readonly bigint[], payloads: readonly Hex[], predecessor: Hex, salt: Hex) => Promise<Hex>;
18
+ /**
19
+ * Announce an owner call. `PROPOSER_ROLE`.
20
+ *
21
+ * `delay` defaults to `getMinDelay()`. Keep the returned object: `execute` rebuilds
22
+ * the id from it, and without it the arguments have to be recovered from the
23
+ * `CallScheduled` event.
24
+ */
25
+ export declare const _schedule: (client: WalletClient, call: OwnerCall, opts?: OperationOptions, delay?: bigint) => Promise<ScheduledOperation>;
26
+ /**
27
+ * Announce several owner calls as one operation. `PROPOSER_ROLE`.
28
+ *
29
+ * Use this where the calls only make sense together, such as evicting a guardian,
30
+ * which needs both its guardian and its executor role revoked before it can act
31
+ * again.
32
+ */
33
+ export declare const _scheduleBatch: (client: WalletClient, calls: readonly OwnerCall[], opts?: OperationOptions, delay?: bigint) => Promise<ScheduledBatchOperation>;
34
+ /**
35
+ * Schedule a payload built elsewhere. `PROPOSER_ROLE`. For calldata that did not
36
+ * come from an ABI in this SDK.
37
+ *
38
+ * Returns what `_schedule` returns, so the id needed to cancel or inspect the
39
+ * operation comes back with it.
40
+ */
41
+ export declare const _scheduleRaw: (client: WalletClient, target: Address, value: bigint, payload: Hex, predecessor: Hex, salt: Hex, delay: bigint) => Promise<ScheduledOperation>;
42
+ /**
43
+ * Run a scheduled operation once its delay has elapsed. Permissionless, so any
44
+ * funded EOA works.
45
+ *
46
+ * Pass back the object `schedule` returned. The timelock recomputes the id from
47
+ * these fields, so an altered value looks up an operation that was never
48
+ * scheduled and reverts.
49
+ */
50
+ export declare const _execute: (client: WalletClient, operation: ScheduledOperation) => Promise<`0x${string}`>;
51
+ /** Run a scheduled batch. Permissionless, same rules as `_execute`. */
52
+ export declare const _executeBatch: (client: WalletClient, operation: ScheduledBatchOperation) => Promise<`0x${string}`>;
53
+ /** Execute a payload scheduled through `_scheduleRaw`. Permissionless. */
54
+ export declare const _executeRaw: (client: WalletClient, target: Address, value: bigint, payload: Hex, predecessor: Hex, salt: Hex) => Promise<`0x${string}`>;
55
+ /**
56
+ * Drop a scheduled operation before it runs. `CANCELLER_ROLE`, which every
57
+ * proposer also holds.
58
+ */
59
+ export declare const _cancel: (client: WalletClient, id: Hex) => Promise<`0x${string}`>;
60
+ /**
61
+ * Release a pause on a protocol contract straight away. `GUARDIAN_ROLE`.
62
+ *
63
+ * The selector is fixed in the contract, so this cannot be pointed at anything
64
+ * else on the target.
65
+ */
66
+ export declare const _unpauseInstantly: (client: WalletClient, target: Address) => Promise<`0x${string}`>;
67
+ /**
68
+ * Strip the cancel power from accounts straight away. `GUARDIAN_ROLE`.
69
+ *
70
+ * All or nothing: an account that does not hold the role reverts the whole batch
71
+ * rather than being skipped, so a guardian acting on a list is never left
72
+ * believing a veto is gone while it is still there.
73
+ */
74
+ export declare const _revokeCancellersInstantly: (client: WalletClient, accounts: readonly Address[]) => Promise<`0x${string}`>;
75
+ /**
76
+ * Suspend a protocol contract's admin key straight away. `GUARDIAN_ROLE`.
77
+ *
78
+ * Takes the power away and hands none out. Reinstating the key or naming a
79
+ * replacement is an owner action and waits out the delay.
80
+ *
81
+ * `target` defaults to the registry, the one contract that keeps the admin
82
+ * address. Everything else reads it from there, so suspending it there closes
83
+ * every gate in the protocol.
84
+ */
85
+ export declare const _disableAdminInstantly: (client: WalletClient, target?: Address) => Promise<`0x${string}`>;
86
+ /**
87
+ * Finish taking ownership of contracts that have already offered it.
88
+ * Permissionless, and reverts `OwnershipNotOffered` for any target whose
89
+ * `pendingOwner` is not the timelock.
90
+ */
91
+ export declare const _acceptOwnershipBatch: (client: WalletClient, targets: readonly Address[]) => Promise<`0x${string}`>;
92
+ /**
93
+ * Give up one of your own roles. The chain requires `account` to be the caller,
94
+ * so this is the one role change that does not wait.
95
+ */
96
+ export declare const _renounceRole: (client: WalletClient, role: Hex, account: Address) => Promise<`0x${string}`>;
97
+ /** Grant a role. Pass the result to `schedule`. */
98
+ export declare const _grantRoleCall: (client: WalletClient, role: Hex, account: Address) => Promise<OwnerCall>;
99
+ /**
100
+ * Revoke a role. Pass the result to `schedule`.
101
+ *
102
+ * Evicting a guardian takes two of these in one `scheduleBatch`, its guardian
103
+ * role and its executor role, because the grant paired them but the revoke
104
+ * cannot tell that pairing from an independent grant.
105
+ */
106
+ export declare const _revokeRoleCall: (client: WalletClient, role: Hex, account: Address) => Promise<OwnerCall>;
107
+ /**
108
+ * Change the delay. Pass the result to `schedule`. `minDelayFloor` still clamps
109
+ * whatever this writes, so it cannot take the timelock below the floor.
110
+ */
111
+ export declare const _updateDelayCall: (client: WalletClient, newDelay: bigint) => Promise<OwnerCall>;
112
+ /**
113
+ * Suspend a protocol contract's admin and nominate its replacement in one step.
114
+ * Pass the result to `schedule`.
115
+ *
116
+ * The nominee still has to accept, and the role stays dormant until it does.
117
+ */
118
+ export declare const _disableAndNominateCall: (client: WalletClient, target: Address, newAdmin: Address) => Promise<OwnerCall>;
119
+ /**
120
+ * Release the protocol pause on the owner's route. Pass the result to `schedule`.
121
+ *
122
+ * There is no matching `pauseCall`. Tripping the pause is `onlyESIMWalletAdmin`,
123
+ * so the timelock cannot do it at all; the admin key calls `registry.pause`
124
+ * directly.
125
+ *
126
+ * A guardian can skip the delay with `_unpauseInstantly`. Use this form when no
127
+ * guardian key is to hand, or when the release is planned rather than urgent.
128
+ *
129
+ * `target` defaults to the registry.
130
+ */
131
+ export declare const _unpauseCall: (client: WalletClient, target?: Address) => Promise<OwnerCall>;
132
+ /**
133
+ * Set the fallback data bundle price ceiling. Pass the result to `schedule`.
134
+ *
135
+ * Zero reverts on execution, not on scheduling, so a zero here costs the whole
136
+ * delay before it fails.
137
+ *
138
+ * `target` defaults to the registry.
139
+ */
140
+ export declare const _setDefaultDataBundlePriceCapCall: (client: WalletClient, cap: bigint, target?: Address) => Promise<OwnerCall>;
141
+ /**
142
+ * Suspend a contract's admin key on the owner's route. Pass the result to
143
+ * `schedule`.
144
+ *
145
+ * Prefer `_disableAdminInstantly` during an incident: it does the same thing
146
+ * with no wait. This form is for a planned suspension, and for an owner holding
147
+ * no guardian key.
148
+ *
149
+ * `target` defaults to the registry, the one contract that keeps the admin
150
+ * address.
151
+ */
152
+ export declare const _disableAdminCall: (client: WalletClient, target?: Address) => Promise<OwnerCall>;
153
+ /**
154
+ * Give a suspended admin its powers back. Pass the result to `schedule`.
155
+ *
156
+ * The only route there is, and it waits out the delay however the key is held.
157
+ * Leaves an outstanding nomination alone, so an incumbent stripped by one is
158
+ * still powerless afterwards; withdraw that by naming the incumbent in
159
+ * `requestAdminUpdate`.
160
+ *
161
+ * `target` defaults to the registry.
162
+ */
163
+ export declare const _enableAdminCall: (client: WalletClient, target?: Address) => Promise<OwnerCall>;
@@ -1,11 +1,5 @@
1
- import { Address, WalletClient } from "viem";
2
- /**
3
- * Read-only admin logic targeting a specific `DeviceWallet` instance (its address
4
- * is passed in). Surfaces the instance's public storage getters + `getVaultAddress`
5
- * view for the backend. Each read extends the `WalletClient` with `publicActions`;
6
- * no EOA account is required, and the target is the instance address (not a
7
- * factory address, so no chain-constants lookup is needed).
8
- */
1
+ import { Address, Hex, WalletClient } from "viem";
2
+ import { P256Key } from "../../../types.js";
9
3
  /** The device's unique identifier string. */
10
4
  export declare const _deviceUniqueIdentifier: (client: WalletClient, deviceWalletAddress: Address) => Promise<string>;
11
5
  /** Whether an eSIM wallet is a valid child of this device wallet. */
@@ -14,3 +8,29 @@ export declare const _isValidESIMWallet: (client: WalletClient, deviceWalletAddr
14
8
  export declare const _canPullETH: (client: WalletClient, deviceWalletAddress: Address, eSIMWallet: Address) => Promise<boolean>;
15
9
  /** The vault address this device wallet pays eSIM purchases to. */
16
10
  export declare const _getVaultAddress: (client: WalletClient, deviceWalletAddress: Address) => Promise<Address>;
11
+ /**
12
+ * The P256 key that owns this wallet, as its X and Y co-ordinates. Two reads,
13
+ * because the contract stores the pair as an array and Solidity gives an indexed
14
+ * getter rather than one returning both.
15
+ */
16
+ export declare const _getOwner: (client: WalletClient, deviceWalletAddress: Address) => Promise<P256Key>;
17
+ /** Gas this wallet has on deposit at the EntryPoint. */
18
+ export declare const _getDeposit: (client: WalletClient, deviceWalletAddress: Address) => Promise<bigint>;
19
+ /**
20
+ * Check a signature over an arbitrary message, per ERC-1271. Returns `0x1626ba7e`
21
+ * when the signature is valid and unexpired, `0xffffffff` otherwise.
22
+ *
23
+ * The signature is a version byte, then six bytes of `validUntil`, then the
24
+ * ABI-encoded WebAuthn assertion. What was signed is an EIP-191 digest over
25
+ * version, validUntil, chain id, the wallet address and `messageHash`, not
26
+ * `messageHash` on its own.
27
+ */
28
+ export declare const _isValidSignature: (client: WalletClient, deviceWalletAddress: Address, messageHash: Hex, signature: Hex) => Promise<Hex>;
29
+ /** The registry this wallet reports its ownership changes to. */
30
+ export declare const _registry: (client: WalletClient, deviceWalletAddress: Address) => Promise<Address>;
31
+ /** The factory that deploys this wallet's eSIM wallets. */
32
+ export declare const _eSIMWalletFactory: (client: WalletClient, deviceWalletAddress: Address) => Promise<Address>;
33
+ /** The ERC-4337 EntryPoint this wallet answers to. Immutable. */
34
+ export declare const _entryPoint: (client: WalletClient, deviceWalletAddress: Address) => Promise<Address>;
35
+ /** The P256 verifier used when the RIP-7212 precompile is unavailable. */
36
+ export declare const _verifier: (client: WalletClient, deviceWalletAddress: Address) => Promise<Address>;