@zkproofport-app/sdk 0.2.14 → 0.2.16

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.mjs CHANGED
@@ -4342,26 +4342,33 @@ const CIRCUIT_SUPPORT_STATUS = Object.freeze({
4342
4342
  mdl_kr_region: 'planned',
4343
4343
  });
4344
4344
  /**
4345
- * Where each circuit's verification key lives inside the `zkproofport/circuits`
4346
- * repository, relative to its root.
4345
+ * Where each circuit's verification key FILE lives inside the
4346
+ * `zkproofport/circuits` repository, relative to its root.
4347
4347
  *
4348
4348
  * Off-chain verification needs the verification key and nothing else — no
4349
4349
  * circuit bytecode, no witness. The key is public by nature: it is what anyone
4350
4350
  * checking a proof must already have, and the Solidity verifiers deployed
4351
4351
  * on-chain embed the same key.
4352
4352
  *
4353
+ * NOTE THE TRAILING `/vk` TWICE. In that repository `target/vk` is a DIRECTORY
4354
+ * holding `vk`, `vk_hash` and `SHA256SUMS`; the key itself is `target/vk/vk`.
4355
+ * These paths were first copied here from the mobile app, which keeps the
4356
+ * directory and the filename as two fields and joins them — so taking only the
4357
+ * directory produced a URL that answers 404, and the first browser to try
4358
+ * off-chain verification said "Could not fetch the verification key (HTTP 404)".
4359
+ *
4353
4360
  * Exhaustive over {@link CircuitId} on purpose. A new circuit whose key path is
4354
4361
  * not listed here fails to compile rather than failing at verification time,
4355
4362
  * where the only symptom would be a proof that cannot be checked.
4356
4363
  */
4357
4364
  const CIRCUIT_VK_PATHS = Object.freeze({
4358
- coinbase_attestation: 'coinbase-attestation/target/vk',
4359
- coinbase_country_attestation: 'coinbase-country-attestation/target/vk',
4360
- oidc_domain_attestation: 'oidc-domain-attestation/target/vk',
4361
- giwa_attestation: 'giwa-attestation/target/vk',
4362
- mdl_kr_ownership: 'mdl/kr-ownership/target/vk',
4363
- mdl_kr_age: 'mdl/kr-age/target/vk',
4364
- mdl_kr_region: 'mdl/kr-region/target/vk',
4365
+ coinbase_attestation: 'coinbase-attestation/target/vk/vk',
4366
+ coinbase_country_attestation: 'coinbase-country-attestation/target/vk/vk',
4367
+ oidc_domain_attestation: 'oidc-domain-attestation/target/vk/vk',
4368
+ giwa_attestation: 'giwa-attestation/target/vk/vk',
4369
+ mdl_kr_ownership: 'mdl/kr-ownership/target/vk/vk',
4370
+ mdl_kr_age: 'mdl/kr-age/target/vk/vk',
4371
+ mdl_kr_region: 'mdl/kr-region/target/vk/vk',
4365
4372
  });
4366
4373
  /**
4367
4374
  * Every canonical circuit identifier, in declaration order.
@@ -4477,6 +4484,38 @@ const CIRCUITS_VK_BASE = 'https://raw.githubusercontent.com/zkproofport/circuits
4477
4484
  /** How long a fetched verification key is reused. Keys change only on a recompile. */
4478
4485
  const VK_CACHE_TTL_MS = 60 * 60 * 1000;
4479
4486
  const vkCache = new Map();
4487
+ /**
4488
+ * Make sure a Node-shaped `Buffer` exists before Barretenberg is loaded.
4489
+ *
4490
+ * WHY THE SDK DOES THIS RATHER THAN THE CALLER. bb.js's own BROWSER build —
4491
+ * not just its node build — converts field elements through `Buffer.alloc` and
4492
+ * `buf.writeBigUInt64BE`. Browsers have no Buffer, and bundlers stopped
4493
+ * polyfilling Node globals years ago, so in a browser the first verification
4494
+ * dies with "r.writeBigUInt64BE is not a function" — a message that names
4495
+ * nothing a caller could act on. Measured on the demo page, 2026-09-04, against
4496
+ * a real GIWA proof.
4497
+ *
4498
+ * Leaving it to callers would mean every browser customer editing their
4499
+ * bundler config to make an SDK method work, which is the configuration this
4500
+ * SDK promises not to require.
4501
+ *
4502
+ * Deliberately narrow:
4503
+ * - It only fills a GAP. A real Buffer (Node, or a page that already has one)
4504
+ * is left alone, so nothing is shadowed by a lesser implementation.
4505
+ * - It checks for the METHOD, not just the global. A partial Buffer — which is
4506
+ * what several bundlers leave behind, and what the demo page actually had —
4507
+ * passes a `typeof Buffer` test and then fails inside Barretenberg.
4508
+ */
4509
+ async function ensureBufferForBarretenberg() {
4510
+ const existing = globalThis.Buffer;
4511
+ if (existing?.alloc) {
4512
+ const probe = existing.alloc(8);
4513
+ if (typeof probe.writeBigUInt64BE === 'function')
4514
+ return;
4515
+ }
4516
+ const { Buffer } = await import('buffer/');
4517
+ globalThis.Buffer = Buffer;
4518
+ }
4480
4519
  /** @internal Hex string (with or without 0x) to bytes. */
4481
4520
  function hexToBytes(hex) {
4482
4521
  const clean = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
@@ -4586,6 +4625,8 @@ async function verifyProofOffChain(circuit, proof, publicInputs, options = {}) {
4586
4625
  //
4587
4626
  // The dynamic import is what keeps the cost off everyone else — a bundler
4588
4627
  // splits it out, and a caller who never verifies off-chain never loads it.
4628
+ // Before bb.js, not after: its module-level code already reaches for Buffer.
4629
+ await ensureBufferForBarretenberg();
4589
4630
  let bb;
4590
4631
  try {
4591
4632
  bb = await import('@aztec/bb.js');