kokio-sdk 3.2.0 → 3.2.1

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.
@@ -2,7 +2,7 @@ import { BaseError, ContractFunctionRevertedError, isAddressEqual, parseEventLog
2
2
  import { _chainId, _getChainSpecificConstants } from "../constants.js";
3
3
  import { BatchSizeOutOfRangeError, DepositOnResumeError, ESIMWalletNotLazyDeployedError, MissingBatchEventError, MissingEOAWalletError, StalledBatchError, writeContractOrThrow, } from "../errors.js";
4
4
  import { LazyWalletRegistry, Registry } from "../../abis/index.js";
5
- import { _eSIMWalletsDeployed, _lazyDeployedESIMWallet } from "./reads/lazyWalletRegistry.reads.js";
5
+ import { _eSIMIdentifiersAssociatedWithDeviceIdentifier, _eSIMWalletsDeployed, _lazyDeployedESIMWallet, } from "./reads/lazyWalletRegistry.reads.js";
6
6
  // Admin-EOA logic for `LazyWalletRegistry`. Every function here is
7
7
  // `onlyESIMWalletAdmin` on chain, so they can only succeed from the admin EOA -
8
8
  // a device-wallet userOp (whose sender is the smart account) always reverts.
@@ -199,6 +199,7 @@ export const _deployLazyWalletAllBatches = async (client, deviceOwnerPublicKey,
199
199
  }
200
200
  const alreadyDeployed = await _eSIMWalletsDeployed(client, deviceUniqueIdentifier);
201
201
  const batches = [];
202
+ let earlier = { eSIMWallets: [], eSIMIdentifiers: [] };
202
203
  let deviceWallet;
203
204
  let outstanding;
204
205
  if (alreadyDeployed === 0n) {
@@ -216,6 +217,9 @@ export const _deployLazyWalletAllBatches = async (client, deviceOwnerPublicKey,
216
217
  else {
217
218
  if (depositAmount !== 0n)
218
219
  throw new DepositOnResumeError(deviceUniqueIdentifier, depositAmount);
220
+ // Wallets an earlier call deployed. Without them a resume would report only its
221
+ // own batches, and a caller walking the result would skip the rest of the device.
222
+ earlier = await _readDeployedESIMWallets(client, deviceUniqueIdentifier, alreadyDeployed);
219
223
  deviceWallet = await publicClient.readContract({
220
224
  address: values.factoryAddresses.REGISTRY,
221
225
  abi: Registry,
@@ -230,7 +234,7 @@ export const _deployLazyWalletAllBatches = async (client, deviceOwnerPublicKey,
230
234
  account: client.account,
231
235
  }, "AllESIMWalletsDeployed");
232
236
  if (finished) {
233
- return { deviceWallet, eSIMWallets: [], eSIMIdentifiers: [], batches: [], alreadyComplete: true };
237
+ return { deviceWallet, ...earlier, batches: [], alreadyComplete: true };
234
238
  }
235
239
  outstanding = true;
236
240
  }
@@ -249,12 +253,22 @@ export const _deployLazyWalletAllBatches = async (client, deviceOwnerPublicKey,
249
253
  }
250
254
  return {
251
255
  deviceWallet,
252
- eSIMWallets: batches.flatMap((batch) => [...batch.eSIMWallets]),
253
- eSIMIdentifiers: batches.flatMap((batch) => [...batch.eSIMIdentifiers]),
256
+ eSIMWallets: [...earlier.eSIMWallets, ...batches.flatMap((batch) => [...batch.eSIMWallets])],
257
+ eSIMIdentifiers: [...earlier.eSIMIdentifiers, ...batches.flatMap((batch) => [...batch.eSIMIdentifiers])],
254
258
  batches,
255
259
  alreadyComplete: false,
256
260
  };
257
261
  };
262
+ /**
263
+ * The first `count` eSIM wallets deployed for a device, in deploy order. The
264
+ * deploy walks the device's identifier list from the start, so the first
265
+ * `count` identifiers are exactly the ones with wallets.
266
+ */
267
+ const _readDeployedESIMWallets = async (client, deviceUniqueIdentifier, count) => {
268
+ const eSIMIdentifiers = await Promise.all(Array.from({ length: Number(count) }, (_, i) => _eSIMIdentifiersAssociatedWithDeviceIdentifier(client, deviceUniqueIdentifier, BigInt(i))));
269
+ const eSIMWallets = await Promise.all(eSIMIdentifiers.map((id) => _lazyDeployedESIMWallet(client, id)));
270
+ return { eSIMWallets, eSIMIdentifiers };
271
+ };
258
272
  /**
259
273
  * Copy an eSIM's whole stored purchase history onto its wallet, over as many
260
274
  * transactions as that takes. `onlyESIMWalletAdmin`.
@@ -127,8 +127,8 @@ export type LazyDeploymentBatch = {
127
127
  };
128
128
  /**
129
129
  * What a fully paginated lazy deployment did. `eSIMWallets` and `eSIMIdentifiers`
130
- * cover only the batches this call ran, so a resume reports what it finished
131
- * rather than the device's whole set.
130
+ * cover the device's whole set, including wallets an earlier call deployed, so a
131
+ * resume can be walked like a fresh deploy. `batches` holds only what this call sent.
132
132
  */
133
133
  export type LazyDeployment = {
134
134
  deviceWallet: Address;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kokio-sdk",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/config.js",