@waaskey/sdk 0.2.0 → 0.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.
package/dist/index.d.cts CHANGED
@@ -658,11 +658,21 @@ interface PrimePoolOptions {
658
658
  targetSize?: number;
659
659
  /** Persistence for the pool. Defaults to an in-memory store. */
660
660
  store?: PrimePoolStore;
661
+ /**
662
+ * Kick off a refill automatically after every {@link PrimePool.take}. Default `false`:
663
+ * unless the core generates primes in a Web Worker, wasm prime generation is a
664
+ * synchronous CPU burn on the calling thread — a "background" refill starves the event
665
+ * loop and stalls the very keygen ceremony the take() was for (it also freezes a
666
+ * browser UI). Refill explicitly via {@link PrimePool.ensure} (`wallets.prewarm`) at
667
+ * boot/idle, or set `true` only when the core is worker-backed.
668
+ */
669
+ autoRefill?: boolean;
661
670
  }
662
671
  declare class PrimePool {
663
672
  private readonly core;
664
673
  private readonly store;
665
674
  private readonly targetSize;
675
+ private readonly autoRefill;
666
676
  /** Per-curve in-flight refill, so concurrent calls don't over-generate. */
667
677
  private readonly refilling;
668
678
  constructor(core: PrimeGenerator, options?: PrimePoolOptions);
@@ -674,8 +684,9 @@ declare class PrimePool {
674
684
  private refill;
675
685
  /**
676
686
  * Claim a prime for a keygen. Returns a cached one instantly when the pool is warm; otherwise
677
- * generates one inline (the slow fallback) so keygen never fails on an empty pool. Either way it
678
- * kicks off a background refill so the next wallet is instant.
687
+ * generates one inline (the slow fallback) so keygen never fails on an empty pool. Refill the
688
+ * pool for the next wallet via {@link ensure} at idle (or opt into `autoRefill` when the core
689
+ * is worker-backed).
679
690
  */
680
691
  take(curve: MpcCurve): Promise<string>;
681
692
  }
package/dist/index.d.ts CHANGED
@@ -658,11 +658,21 @@ interface PrimePoolOptions {
658
658
  targetSize?: number;
659
659
  /** Persistence for the pool. Defaults to an in-memory store. */
660
660
  store?: PrimePoolStore;
661
+ /**
662
+ * Kick off a refill automatically after every {@link PrimePool.take}. Default `false`:
663
+ * unless the core generates primes in a Web Worker, wasm prime generation is a
664
+ * synchronous CPU burn on the calling thread — a "background" refill starves the event
665
+ * loop and stalls the very keygen ceremony the take() was for (it also freezes a
666
+ * browser UI). Refill explicitly via {@link PrimePool.ensure} (`wallets.prewarm`) at
667
+ * boot/idle, or set `true` only when the core is worker-backed.
668
+ */
669
+ autoRefill?: boolean;
661
670
  }
662
671
  declare class PrimePool {
663
672
  private readonly core;
664
673
  private readonly store;
665
674
  private readonly targetSize;
675
+ private readonly autoRefill;
666
676
  /** Per-curve in-flight refill, so concurrent calls don't over-generate. */
667
677
  private readonly refilling;
668
678
  constructor(core: PrimeGenerator, options?: PrimePoolOptions);
@@ -674,8 +684,9 @@ declare class PrimePool {
674
684
  private refill;
675
685
  /**
676
686
  * Claim a prime for a keygen. Returns a cached one instantly when the pool is warm; otherwise
677
- * generates one inline (the slow fallback) so keygen never fails on an empty pool. Either way it
678
- * kicks off a background refill so the next wallet is instant.
687
+ * generates one inline (the slow fallback) so keygen never fails on an empty pool. Refill the
688
+ * pool for the next wallet via {@link ensure} at idle (or opt into `autoRefill` when the core
689
+ * is worker-backed).
679
690
  */
680
691
  take(curve: MpcCurve): Promise<string>;
681
692
  }
package/dist/index.js CHANGED
@@ -2298,10 +2298,12 @@ var PrimePool = class {
2298
2298
  this.core = core;
2299
2299
  this.store = options.store ?? new MemoryPrimeStore();
2300
2300
  this.targetSize = Math.max(1, options.targetSize ?? 2);
2301
+ this.autoRefill = options.autoRefill ?? false;
2301
2302
  }
2302
2303
  core;
2303
2304
  store;
2304
2305
  targetSize;
2306
+ autoRefill;
2305
2307
  /** Per-curve in-flight refill, so concurrent calls don't over-generate. */
2306
2308
  refilling = /* @__PURE__ */ new Map();
2307
2309
  /**
@@ -2322,13 +2324,14 @@ var PrimePool = class {
2322
2324
  }
2323
2325
  /**
2324
2326
  * Claim a prime for a keygen. Returns a cached one instantly when the pool is warm; otherwise
2325
- * generates one inline (the slow fallback) so keygen never fails on an empty pool. Either way it
2326
- * kicks off a background refill so the next wallet is instant.
2327
+ * generates one inline (the slow fallback) so keygen never fails on an empty pool. Refill the
2328
+ * pool for the next wallet via {@link ensure} at idle (or opt into `autoRefill` when the core
2329
+ * is worker-backed).
2327
2330
  */
2328
2331
  async take(curve) {
2329
2332
  const cached = await this.store.take(curve);
2330
2333
  const primes = cached ?? await this.core.pregeneratePrimes(curve);
2331
- void this.ensure(curve).catch(() => void 0);
2334
+ if (this.autoRefill) void this.ensure(curve).catch(() => void 0);
2332
2335
  return primes;
2333
2336
  }
2334
2337
  };