@celo/buy-identity 0.4.0 → 0.4.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.ts CHANGED
@@ -3,4 +3,4 @@ export * from './config.js';
3
3
  export * from './verify.js';
4
4
  export * from './receiver.js';
5
5
  export * from './hosted.js';
6
- export { renderQrToTerminal } from './qr.js';
6
+ export { qrFitWarning, renderQrToTerminal } from './qr.js';
package/dist/index.js CHANGED
@@ -48659,6 +48659,17 @@ function decodeUserDefinedData(hex2) {
48659
48659
  }
48660
48660
  }
48661
48661
  async function verifyProof(request, payload) {
48662
+ if (request.mockPassport !== "either") {
48663
+ return verifyAgainstHub(request, payload, request.mockPassport);
48664
+ }
48665
+ const first = request.endpointType?.startsWith("staging_") === true;
48666
+ const primary = await verifyAgainstHub(request, payload, first);
48667
+ if (primary.ok) return primary;
48668
+ const secondary = await verifyAgainstHub(request, payload, !first);
48669
+ if (secondary.ok) return secondary;
48670
+ return primary;
48671
+ }
48672
+ async function verifyAgainstHub(request, payload, mockPassport) {
48662
48673
  const configStore = new DefaultConfigStore({
48663
48674
  minimumAge: request.requirements.minimumAge,
48664
48675
  excludedCountries: request.requirements.excludedCountries,
@@ -48667,7 +48678,7 @@ async function verifyProof(request, payload) {
48667
48678
  const verifier = new SelfBackendVerifier(
48668
48679
  request.scope,
48669
48680
  request.endpoint,
48670
- request.mockPassport,
48681
+ mockPassport,
48671
48682
  AllIds,
48672
48683
  configStore,
48673
48684
  "hex"
@@ -48708,7 +48719,10 @@ async function verifyProof(request, payload) {
48708
48719
  // Both forms are exposed: the hex is what an identity comparison should
48709
48720
  // use, and the decoded string is what everything else wants.
48710
48721
  userDefinedDataHex: result.userData?.userDefinedData,
48711
- userDefinedData: decodeUserDefinedData(result.userData?.userDefinedData)
48722
+ userDefinedData: decodeUserDefinedData(result.userData?.userDefinedData),
48723
+ // Which hub actually held this identity's root. The attestation records
48724
+ // the matching endpointType so re-verification looks in the same place.
48725
+ usedMockPassport: mockPassport
48712
48726
  };
48713
48727
  } catch (err) {
48714
48728
  return { ok: false, reason: err instanceof Error ? err.message : String(err) };
@@ -48773,6 +48787,11 @@ function json(res, statusCode, body) {
48773
48787
  res.writeHead(statusCode, { "Content-Type": "application/json" });
48774
48788
  res.end(JSON.stringify(body));
48775
48789
  }
48790
+ function endpointTypeForHub(requested, usedMockPassport) {
48791
+ const onChain = requested === "celo" || requested === "staging_celo";
48792
+ if (onChain) return usedMockPassport ? "staging_celo" : "celo";
48793
+ return usedMockPassport ? "staging_https" : "https";
48794
+ }
48776
48795
  function createProofReceiver(options) {
48777
48796
  const path = options.path ?? DEFAULT_VERIFY_PATH;
48778
48797
  const healthPath = options.healthPath === void 0 ? "/healthz" : options.healthPath;
@@ -48812,7 +48831,12 @@ function createProofReceiver(options) {
48812
48831
  proofHash: result.proofHash,
48813
48832
  verifiedAt: (/* @__PURE__ */ new Date()).toISOString(),
48814
48833
  endpoint: request.endpoint,
48815
- endpointType: request.endpointType,
48834
+ // The endpointType of the hub that ACTUALLY validated, not the one
48835
+ // the request asked for. With `mockPassport: 'either'` those differ
48836
+ // whenever the fallback hub won, and re-verification picks its hub
48837
+ // from this field — recording the requested one would send it to the
48838
+ // wrong hub and fail a proof that is perfectly valid.
48839
+ endpointType: result.usedMockPassport === void 0 ? request.endpointType : endpointTypeForHub(request.endpointType, result.usedMockPassport),
48816
48840
  proofPayload: payload,
48817
48841
  ...result.userIdentifier ? { userIdentifier: result.userIdentifier } : {},
48818
48842
  ...result.nullifier ? { nullifier: result.nullifier } : {}
@@ -49014,6 +49038,12 @@ function renderQrToTerminal(link, opts = {}) {
49014
49038
  qrcode.generate(link, { small: opts.small ?? true }, (out) => resolve(out));
49015
49039
  });
49016
49040
  }
49041
+ function qrFitWarning(qr, rows = process.stdout.rows) {
49042
+ if (!rows) return void 0;
49043
+ const needed = qr.split("\n").length;
49044
+ if (needed + 2 <= rows) return void 0;
49045
+ return `This QR needs about ${needed} rows and your terminal has ${rows}. Enlarge the window and run the command again, or open the link below on the phone directly.`;
49046
+ }
49017
49047
  export {
49018
49048
  DEFAULT_VERIFY_PATH,
49019
49049
  MAX_VERIFY_BODY_BYTES,
@@ -49028,6 +49058,7 @@ export {
49028
49058
  createProofReceiver,
49029
49059
  decodeUserDefinedData,
49030
49060
  gatewayOriginFor,
49061
+ qrFitWarning,
49031
49062
  readVerifyBody,
49032
49063
  renderQrToTerminal,
49033
49064
  runHostedVerification,