@zkpassport/sdk 0.18.3-beta.1 → 0.18.3-beta.2

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.
@@ -1,5 +1,6 @@
1
1
  import { ProofMode, SupportedChain, ProofResult, QueryResult, Query } from '@zkpassport/utils';
2
- import { R as RequestedNullifierType, O as OnSuccessVerdict, Q as QueryBuilder, a as QueryBuilderResult } from './index-CAudQvTm.js';
2
+ import { R as RequestedNullifierType, O as OnSuccessVerdict, Q as QueryBuilder, a as QueryBuilderResult } from './index-D9GMXc4k.js';
3
+ import '@obsidion/bridge';
3
4
  import 'i18n-iso-countries';
4
5
 
5
6
  declare const DEFAULT_POPUP_URL = "https://verify.zkpassport.id";
@@ -32,6 +33,7 @@ type PopupRequestConfig = {
32
33
  domain?: string;
33
34
  bridgeUrl?: string;
34
35
  cloudProverUrl?: string;
36
+ appClip?: boolean;
35
37
  };
36
38
  type PopupCredentialOutcome = {
37
39
  policyId: `0x${string}`;
@@ -40,44 +42,44 @@ type PopupCredentialOutcome = {
40
42
  contract: `0x${string}`;
41
43
  txHash?: `0x${string}`;
42
44
  };
43
- type PopupConfigureMessage = {
45
+ /**
46
+ * Every message names its verification, because a browser that discards the popup's tab rebuilds it
47
+ * as a different window and the handle no longer recognises it.
48
+ */
49
+ type Addressed<T> = T & {
44
50
  zkpassport: true;
51
+ session?: string;
52
+ };
53
+ type PopupConfigureMessage = Addressed<{
45
54
  type: "configure";
46
55
  request: PopupRequestConfig;
47
56
  query: Query;
48
57
  /** Mint mode; a sibling of `query` because each defines what to prove for its mode. */
49
58
  credential?: PopupCredentialConfig;
50
- };
51
- type PopupReadyMessage = {
52
- zkpassport: true;
59
+ }>;
60
+ type PopupReadyMessage = Addressed<{
53
61
  type: "ready";
54
- };
55
- type PopupEventMessage = {
56
- zkpassport: true;
62
+ }>;
63
+ type PopupEventMessage = Addressed<{
57
64
  type: "request-received";
58
- } | {
59
- zkpassport: true;
65
+ }> | Addressed<{
60
66
  type: "generating";
61
- } | {
62
- zkpassport: true;
67
+ }> | Addressed<{
63
68
  type: "proof-generated";
64
69
  index?: number;
65
70
  total?: number;
66
71
  name?: string;
67
- } | {
68
- zkpassport: true;
72
+ }> | Addressed<{
69
73
  type: "success";
70
74
  proofs: ProofResult[];
71
75
  result: QueryResult;
72
76
  credential?: PopupCredentialOutcome;
73
- } | {
74
- zkpassport: true;
77
+ }> | Addressed<{
75
78
  type: "rejected";
76
- } | {
77
- zkpassport: true;
79
+ }> | Addressed<{
78
80
  type: "error";
79
81
  message: string;
80
- };
82
+ }>;
81
83
  type PopupMessage = PopupConfigureMessage | PopupReadyMessage | PopupEventMessage;
82
84
  declare function isPopupMessage(data: any): data is PopupMessage;
83
85
 
@@ -92,7 +94,7 @@ type PopupCallbacks = {
92
94
  total?: number;
93
95
  name?: string;
94
96
  }) => void;
95
- onSuccess?: (response: Omit<PopupSuccess, "zkpassport" | "type">) => OnSuccessVerdict;
97
+ onSuccess?: (response: Omit<PopupSuccess, "zkpassport" | "type" | "session">) => OnSuccessVerdict;
96
98
  onReject?: () => void;
97
99
  onError?: (message: string) => void;
98
100
  onClose?: () => void;
@@ -100,6 +102,8 @@ type PopupCallbacks = {
100
102
  type OpenVerificationPopupOptions = {
101
103
  popupUrl?: string;
102
104
  windowMode?: "popup" | "tab";
105
+ /** Reopens the verification of this `session`, from an earlier handle, instead of starting one. */
106
+ session?: string;
103
107
  request: PopupRequestConfig;
104
108
  query: Query;
105
109
  credential?: PopupCredentialConfig;
@@ -111,6 +115,8 @@ type VerificationPopupHandle = {
111
115
  /** Stop listening to the popup but leave the window open for the user. */
112
116
  release: () => void;
113
117
  popup: Window;
118
+ /** Names this verification to the popup. Persist it to reopen the same one later. */
119
+ session: string;
114
120
  };
115
121
  /**
116
122
  * Open the hosted verification popup. MUST be called from a user gesture
package/dist/esm/popup.js CHANGED
@@ -1,3 +1,3 @@
1
- var l="https://verify.zkpassport.id";function y(e){return !!e&&e.zkpassport===true&&typeof e.type=="string"}var g=460,f=780,m=500;function w(e){let r=Math.max(0,(window.screenX??0)+(window.outerWidth-g)/2),s=Math.max(0,(window.screenY??0)+(window.outerHeight-f)/2);return window.open(e,"zkpassport-verify",`popup,width=${g},height=${f},left=${Math.round(r)},top=${Math.round(s)}`)??window.open(e,"zkpassport-verify")}function R(e){if(typeof window>"u")return null;let r=e.popupUrl??l,s=new URL(r).origin,o=(e.credential?"tab":e.windowMode)==="tab"?window.open(r,"zkpassport-verify"):w(r);if(!o)return null;let t=e.callbacks??{},i=false,n=null,u=()=>{window.removeEventListener("message",c),n&&(clearInterval(n),n=null);},c=a=>{if(a.origin!==s||a.source!==o)return;let p=a.data;if(y(p))switch(p.type){case "ready":try{o.postMessage({zkpassport:!0,type:"configure",request:e.request,query:e.query,...e.credential?{credential:e.credential}:{}},s);}catch(d){console.error("[zkpassport] failed to send the request to the popup:",d),t.onError?.("Failed to send the request to the verification popup");try{o.close();}catch{}}break;case "request-received":t.onRequestReceived?.();break;case "generating":t.onGeneratingProof?.();break;case "proof-generated":t.onProofGenerated?.({index:p.index,total:p.total,name:p.name});break;case "success":{i=true;let{zkpassport:d,type:v,...P}=p;t.onSuccess?.(P);break}case "rejected":i=true,t.onReject?.();break;case "error":t.onError?.(p.message);break}};return window.addEventListener("message",c),n=setInterval(()=>{o.closed&&(u(),i||t.onClose?.());},m),{popup:o,release:u,close:()=>{u();try{o.close();}catch{}}}}function k(e,r){return e.raw(r).done()}
2
- export{l as DEFAULT_POPUP_URL,k as hydrateQueryBuilder,y as isPopupMessage,R as openVerificationPopup};//# sourceMappingURL=popup.js.map
1
+ var m="https://verify.zkpassport.id";function w(e){return !!e&&e.zkpassport===true&&typeof e.type=="string"}var R=460,v=780,C=500,b=300,M=20;function k(){let e=crypto.getRandomValues(new Uint8Array(16));return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")}function q(e,t){let s=new URL(e);return s.searchParams.set("s",t),s.toString()}function E(e){let t=Math.max(0,(window.screenX??0)+(window.outerWidth-R)/2),s=Math.max(0,(window.screenY??0)+(window.outerHeight-v)/2);return window.open(e,"zkpassport-verify",`popup,width=${R},height=${v},left=${Math.round(t)},top=${Math.round(s)}`)??window.open(e,"zkpassport-verify")}function _(e){if(typeof window>"u")return null;let t=e.session??k(),s=e.popupUrl??m,c=q(s,t),l=new URL(s).origin,n=(e.credential?"tab":e.windowMode)==="tab"?window.open(c,"zkpassport-verify"):E(c);if(!n)return null;let o=e.callbacks??{},i=false,u=null,a=null,x=0,d=()=>{a&&(clearInterval(a),a=null);},y=()=>{u&&(clearInterval(u),u=null);},g=()=>{window.removeEventListener("message",P),d(),y();},f=()=>{try{n.postMessage({zkpassport:!0,type:"configure",session:t,request:e.request,query:e.query,...e.credential?{credential:e.credential}:{}},l);}catch(p){console.error("[zkpassport] failed to send the request to the popup:",p),d(),o.onError?.("Failed to send the request to the verification popup");try{n.close();}catch{}}},P=p=>{if(p.origin!==l)return;let r=p.data;if(!(!w(r)||!(r.session?r.session===t:p.source===n)))switch(d(),r.type){case "ready":f();break;case "request-received":o.onRequestReceived?.();break;case "generating":o.onGeneratingProof?.();break;case "proof-generated":o.onProofGenerated?.({index:r.index,total:r.total,name:r.name});break;case "success":{if(i)break;i=true;let{zkpassport:A,type:T,session:S,...h}=r;o.onSuccess?.(h);break}case "rejected":i=true,o.onReject?.();break;case "error":o.onError?.(r.message);break}};return window.addEventListener("message",P),a=setInterval(()=>{++x>M?d():f();},b),u=setInterval(()=>{n.closed&&(y(),i||o.onClose?.());},C),{popup:n,session:t,release:g,close:()=>{g();try{n.close();}catch{}}}}function O(e,t){return e.raw(t).done()}
2
+ export{m as DEFAULT_POPUP_URL,O as hydrateQueryBuilder,w as isPopupMessage,_ as openVerificationPopup};//# sourceMappingURL=popup.js.map
3
3
  //# sourceMappingURL=popup.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/popup/protocol.ts","../../src/popup/client.ts","../../src/popup/hydrate.ts"],"names":["DEFAULT_POPUP_URL","isPopupMessage","data","POPUP_WIDTH","POPUP_HEIGHT","CLOSE_POLL_INTERVAL","openPopupWindow","popupUrl","left","top","openVerificationPopup","options","popupOrigin","popup","callbacks","finished","closePoll","cleanup","onMessage","event","error","_z","_t","response","hydrateQueryBuilder","builder","query"],"mappings":"AAGO,IAAMA,EAAoB,+BA4E1B,SAASC,CAAAA,CAAeC,CAAAA,CAAiC,CAC9D,OAAO,CAAC,CAACA,CAAAA,EAAQA,EAAK,UAAA,GAAe,IAAA,EAAQ,OAAOA,CAAAA,CAAK,IAAA,EAAS,QACpE,CCxCA,IAAMC,CAAAA,CAAc,GAAA,CACdC,EAAe,GAAA,CACfC,CAAAA,CAAsB,IAE5B,SAASC,CAAAA,CAAgBC,EAAiC,CAExD,IAAMC,CAAAA,CAAO,IAAA,CAAK,IAAI,CAAA,CAAA,CAAI,MAAA,CAAO,SAAW,CAAA,EAAA,CAAM,MAAA,CAAO,WAAaL,CAAAA,EAAe,CAAC,CAAA,CAChFM,CAAAA,CAAM,KAAK,GAAA,CAAI,CAAA,CAAA,CAAI,MAAA,CAAO,OAAA,EAAW,IAAM,MAAA,CAAO,WAAA,CAAcL,CAAAA,EAAgB,CAAC,EACvF,OACE,MAAA,CAAO,KACLG,CAAAA,CACA,mBAAA,CACA,eAAeJ,CAAW,CAAA,QAAA,EAAWC,CAAY,CAAA,MAAA,EAAS,KAAK,KAAA,CAAMI,CAAI,CAAC,CAAA,KAAA,EAAQ,IAAA,CAAK,MAAMC,CAAG,CAAC,CAAA,CACnG,CAAA,EAEA,OAAO,IAAA,CAAKF,CAAAA,CAAU,mBAAmB,CAE7C,CAQO,SAASG,CAAAA,CACdC,CAAAA,CACgC,CAChC,GAAI,OAAO,MAAA,CAAW,GAAA,CAAa,OAAO,IAAA,CAC1C,IAAMJ,CAAAA,CAAWI,CAAAA,CAAQ,QAAA,EAAYX,CAAAA,CAC/BY,EAAc,IAAI,GAAA,CAAIL,CAAQ,CAAA,CAAE,MAAA,CAGhCM,GADaF,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mB,CAAE,KAAA,CAAOZ,EAAK,KAAA,CAAO,KAAA,CAAOA,EAAK,KAAA,CAAO,IAAA,CAAMA,CAAAA,CAAK,IAAK,CAAC,CAAA,CACtF,MACF,KAAK,SAAA,CAAW,CACda,EAAW,IAAA,CACX,GAAM,CAAE,UAAA,CAAYM,EAAI,IAAA,CAAMC,CAAAA,CAAI,GAAGC,CAAS,EAAIrB,CAAAA,CAClDY,CAAAA,CAAU,SAAA,GAAYS,CAAQ,EAC9B,KACF,CACA,KAAK,UAAA,CACHR,CAAAA,CAAW,KACXD,CAAAA,CAAU,QAAA,IAAW,CACrB,MACF,KAAK,OAAA,CACHA,CAAAA,CAAU,UAAUZ,CAAAA,CAAK,OAAO,EAChC,KACJ,CACF,CAAA,CAEA,OAAA,MAAA,CAAO,iBAAiB,SAAA,CAAWgB,CAAS,EAC5CF,CAAAA,CAAY,WAAA,CAAY,IAAM,CACxBH,CAAAA,CAAM,MAAA,GACRI,CAAAA,GACKF,CAAAA,EAAUD,CAAAA,CAAU,WAAU,EAEvC,CAAA,CAAGT,CAAmB,CAAA,CAEf,CACL,KAAA,CAAAQ,CAAAA,CACA,QAASI,CAAAA,CACT,KAAA,CAAO,IAAM,CACXA,CAAAA,GACA,GAAI,CACFJ,CAAAA,CAAM,KAAA,GACR,CAAA,KAAQ,CAER,CACF,CACF,CACF,CChKO,SAASW,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,IAAIC,CAAK,CAAA,CAAE,MAC5B","file":"popup.js","sourcesContent":["import type { ProofMode, ProofResult, Query, QueryResult, SupportedChain } from \"@zkpassport/utils\"\nimport type { RequestedNullifierType } from \"../types\"\n\nexport const DEFAULT_POPUP_URL = \"https://verify.zkpassport.id\"\n\n/**\n * Credential minting request. When present, the popup ignores the free-form\n * query and instead resolves the on-chain policy from the registry, binds the\n * recipient and the chain into the proof, and once the proof is verified has\n * the user connect a wallet to submit ZKPassportCredentials.issue(). Any\n * account may pay for the mint; the credential always lands on `recipient`.\n */\nexport type PopupCredentialConfig = {\n /** Chain the registry lives on; also bound into the proof. */\n chain: SupportedChain\n /** On-chain policy id, as a 0x-prefixed 32-byte hex string. */\n policyId: `0x${string}`\n /** Wallet the credential is issued to, chosen by the relying party and bound into the proof. */\n recipient: `0x${string}`\n}\n\nexport type PopupRequestConfig = {\n name?: string\n logo?: string\n purpose?: string\n scope?: string\n mode?: ProofMode\n devMode?: boolean\n validity?: number\n uniqueIdentifierType?: RequestedNullifierType\n oprfKeyId?: string\n policyId?: string\n domain?: string\n bridgeUrl?: string\n cloudProverUrl?: string\n}\n\nexport type PopupCredentialOutcome = {\n policyId: `0x${string}`\n account: `0x${string}`\n chainId: number\n contract: `0x${string}`\n txHash?: `0x${string}`\n}\n\nexport type PopupConfigureMessage = {\n zkpassport: true\n type: \"configure\"\n request: PopupRequestConfig\n query: Query\n /** Mint mode; a sibling of `query` because each defines what to prove for its mode. */\n credential?: PopupCredentialConfig\n}\n\nexport type PopupReadyMessage = { zkpassport: true; type: \"ready\" }\n\nexport type PopupEventMessage =\n | { zkpassport: true; type: \"request-received\" }\n | { zkpassport: true; type: \"generating\" }\n | {\n zkpassport: true\n type: \"proof-generated\"\n index?: number\n total?: number\n name?: string\n }\n | {\n zkpassport: true\n type: \"success\"\n proofs: ProofResult[]\n result: QueryResult\n credential?: PopupCredentialOutcome\n }\n | { zkpassport: true; type: \"rejected\" }\n | { zkpassport: true; type: \"error\"; message: string }\n\nexport type PopupMessage = PopupConfigureMessage | PopupReadyMessage | PopupEventMessage\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isPopupMessage(data: any): data is PopupMessage {\n return !!data && data.zkpassport === true && typeof data.type === \"string\"\n}\n","import type { Query } from \"@zkpassport/utils\"\nimport type { OnSuccessVerdict } from \"../types\"\nimport {\n DEFAULT_POPUP_URL,\n isPopupMessage,\n type PopupCredentialConfig,\n type PopupEventMessage,\n type PopupRequestConfig,\n} from \"./protocol\"\n\nexport type PopupSuccess = Extract<PopupEventMessage, { type: \"success\" }>\n\nexport type PopupCallbacks = {\n onRequestReceived?: () => void\n onGeneratingProof?: () => void\n onProofGenerated?: (progress: { index?: number; total?: number; name?: string }) => void\n onSuccess?: (response: Omit<PopupSuccess, \"zkpassport\" | \"type\">) => OnSuccessVerdict\n onReject?: () => void\n onError?: (message: string) => void\n // Fired when the user closes the popup before a result was produced\n onClose?: () => void\n}\n\nexport type OpenVerificationPopupOptions = {\n popupUrl?: string\n // Ignored when `credential` is set: a mint always opens a tab.\n windowMode?: \"popup\" | \"tab\"\n request: PopupRequestConfig\n query: Query\n credential?: PopupCredentialConfig\n callbacks?: PopupCallbacks\n}\n\nexport type VerificationPopupHandle = {\n /** Close the popup window and stop listening to it. */\n close: () => void\n /** Stop listening to the popup but leave the window open for the user. */\n release: () => void\n popup: Window\n}\n\nconst POPUP_WIDTH = 460\nconst POPUP_HEIGHT = 780\nconst CLOSE_POLL_INTERVAL = 500\n\nfunction openPopupWindow(popupUrl: string): Window | null {\n // Centered on the current window\n const left = Math.max(0, (window.screenX ?? 0) + (window.outerWidth - POPUP_WIDTH) / 2)\n const top = Math.max(0, (window.screenY ?? 0) + (window.outerHeight - POPUP_HEIGHT) / 2)\n return (\n window.open(\n popupUrl,\n \"zkpassport-verify\",\n `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${Math.round(left)},top=${Math.round(top)}`,\n ) ??\n // Popup blocked: retry as a regular new tab\n window.open(popupUrl, \"zkpassport-verify\")\n )\n}\n\n/**\n * Open the hosted verification popup. MUST be called from a user gesture\n * (e.g. a click handler) or the browser will block the popup.\n *\n * If popup is blocked, will attempt to open in a new window.\n */\nexport function openVerificationPopup(\n options: OpenVerificationPopupOptions,\n): VerificationPopupHandle | null {\n if (typeof window === \"undefined\") return null\n const popupUrl = options.popupUrl ?? DEFAULT_POPUP_URL\n const popupOrigin = new URL(popupUrl).origin\n\n const windowMode = options.credential ? \"tab\" : options.windowMode\n const popup =\n windowMode === \"tab\" ? window.open(popupUrl, \"zkpassport-verify\") : openPopupWindow(popupUrl)\n if (!popup) return null\n\n const callbacks = options.callbacks ?? {}\n let finished = false\n let closePoll: ReturnType<typeof setInterval> | null = null\n\n const cleanup = () => {\n window.removeEventListener(\"message\", onMessage)\n if (closePoll) {\n clearInterval(closePoll)\n closePoll = null\n }\n }\n\n const onMessage = (event: MessageEvent) => {\n if (event.origin !== popupOrigin) return\n if (event.source !== popup) return\n const data = event.data\n if (!isPopupMessage(data)) return\n switch (data.type) {\n case \"ready\":\n try {\n popup.postMessage(\n {\n zkpassport: true,\n type: \"configure\",\n request: options.request,\n query: options.query,\n ...(options.credential ? { credential: options.credential } : {}),\n },\n popupOrigin,\n )\n } catch (error) {\n // Most likely DataCloneError: a non-serializable value in the request options\n console.error(\"[zkpassport] failed to send the request to the popup:\", error)\n callbacks.onError?.(\"Failed to send the request to the verification popup\")\n try {\n popup.close()\n } catch {\n // Already closed\n }\n }\n break\n case \"request-received\":\n callbacks.onRequestReceived?.()\n break\n case \"generating\":\n callbacks.onGeneratingProof?.()\n break\n case \"proof-generated\":\n callbacks.onProofGenerated?.({ index: data.index, total: data.total, name: data.name })\n break\n case \"success\": {\n finished = true\n const { zkpassport: _z, type: _t, ...response } = data\n callbacks.onSuccess?.(response)\n break\n }\n case \"rejected\":\n finished = true\n callbacks.onReject?.()\n break\n case \"error\":\n callbacks.onError?.(data.message)\n break\n }\n }\n\n window.addEventListener(\"message\", onMessage)\n closePoll = setInterval(() => {\n if (popup.closed) {\n cleanup()\n if (!finished) callbacks.onClose?.()\n }\n }, CLOSE_POLL_INTERVAL)\n\n return {\n popup,\n release: cleanup,\n close: () => {\n cleanup()\n try {\n popup.close()\n } catch {\n // Already closed\n }\n },\n }\n}\n","import type { Query } from \"@zkpassport/utils\"\nimport type { QueryBuilder, QueryBuilderResult } from \"../types\"\n\n// Seed a fresh builder from the serialized Query the RP page sent over postMessage.\nexport function hydrateQueryBuilder(builder: QueryBuilder, query: Query): QueryBuilderResult {\n return builder.raw(query).done()\n}\n"]}
1
+ {"version":3,"sources":["../../src/popup/protocol.ts","../../src/popup/client.ts","../../src/popup/hydrate.ts"],"names":["DEFAULT_POPUP_URL","isPopupMessage","data","POPUP_WIDTH","POPUP_HEIGHT","CLOSE_POLL_INTERVAL","CONFIGURE_RETRY_INTERVAL","CONFIGURE_ATTEMPTS","newSessionId","bytes","byte","withSession","popupUrl","session","url","openPopupWindow","left","top","openVerificationPopup","options","baseUrl","popupOrigin","popup","callbacks","finished","closePoll","configurePoll","configureAttempts","stopConfiguring","stopWatchingForClose","cleanup","onMessage","configure","error","event","_z","_t","_s","response","hydrateQueryBuilder","builder","query"],"mappings":"AAGO,IAAMA,CAAAA,CAAoB,+BA2E1B,SAASC,CAAAA,CAAeC,CAAAA,CAAiC,CAC9D,OAAO,CAAC,CAACA,CAAAA,EAAQA,CAAAA,CAAK,UAAA,GAAe,MAAQ,OAAOA,CAAAA,CAAK,IAAA,EAAS,QACpE,CCnCA,IAAMC,CAAAA,CAAc,GAAA,CACdC,CAAAA,CAAe,GAAA,CAEfC,CAAAA,CAAsB,GAAA,CAGtBC,CAAAA,CAA2B,GAAA,CAC3BC,EAAqB,EAAA,CAG3B,SAASC,CAAAA,EAAuB,CAC9B,IAAMC,CAAAA,CAAQ,MAAA,CAAO,eAAA,CAAgB,IAAI,UAAA,CAAW,EAAE,CAAC,CAAA,CACvD,OAAO,MAAM,IAAA,CAAKA,CAAAA,CAAQC,CAAAA,EAASA,CAAAA,CAAK,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,CAAA,CAAG,GAAG,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAChF,CAGA,SAASC,CAAAA,CAAYC,CAAAA,CAAkBC,CAAAA,CAAyB,CAC9D,IAAMC,CAAAA,CAAM,IAAI,GAAA,CAAIF,CAAQ,CAAA,CAC5B,OAAAE,EAAI,YAAA,CAAa,GAAA,CAAI,GAAA,CAAKD,CAAO,CA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Y,IAAM,CACvBH,CAAAA,CAAM,MAAA,GAGXO,GAAqB,CAChBL,CAAAA,EAAUD,CAAAA,CAAU,OAAA,IAAU,EACrC,CAAA,CAAGlB,CAAmB,CAAA,CAEf,CACL,KAAA,CAAAiB,CAAAA,CACA,OAAA,CAAAT,CAAAA,CACA,OAAA,CAASiB,EACT,KAAA,CAAO,IAAM,CACXA,CAAAA,EAAQ,CACR,GAAI,CACFR,CAAAA,CAAM,KAAA,GACR,CAAA,KAAQ,CAER,CACF,CACF,CACF,CCrNO,SAASiB,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,GAAA,CAAIC,CAAK,CAAA,CAAE,IAAA,EAC5B","file":"popup.js","sourcesContent":["import type { ProofMode, ProofResult, Query, QueryResult, SupportedChain } from \"@zkpassport/utils\"\nimport type { RequestedNullifierType } from \"../types\"\n\nexport const DEFAULT_POPUP_URL = \"https://verify.zkpassport.id\"\n\n/**\n * Credential minting request. When present, the popup ignores the free-form\n * query and instead resolves the on-chain policy from the registry, binds the\n * recipient and the chain into the proof, and once the proof is verified has\n * the user connect a wallet to submit ZKPassportCredentials.issue(). Any\n * account may pay for the mint; the credential always lands on `recipient`.\n */\nexport type PopupCredentialConfig = {\n /** Chain the registry lives on; also bound into the proof. */\n chain: SupportedChain\n /** On-chain policy id, as a 0x-prefixed 32-byte hex string. */\n policyId: `0x${string}`\n /** Wallet the credential is issued to, chosen by the relying party and bound into the proof. */\n recipient: `0x${string}`\n}\n\nexport type PopupRequestConfig = {\n name?: string\n logo?: string\n purpose?: string\n scope?: string\n mode?: ProofMode\n devMode?: boolean\n validity?: number\n uniqueIdentifierType?: RequestedNullifierType\n oprfKeyId?: string\n policyId?: string\n domain?: string\n bridgeUrl?: string\n cloudProverUrl?: string\n appClip?: boolean\n}\n\nexport type PopupCredentialOutcome = {\n policyId: `0x${string}`\n account: `0x${string}`\n chainId: number\n contract: `0x${string}`\n txHash?: `0x${string}`\n}\n\n/**\n * Every message names its verification, because a browser that discards the popup's tab rebuilds it\n * as a different window and the handle no longer recognises it.\n */\ntype Addressed<T> = T & { zkpassport: true; session?: string }\n\nexport type PopupConfigureMessage = Addressed<{\n type: \"configure\"\n request: PopupRequestConfig\n query: Query\n /** Mint mode; a sibling of `query` because each defines what to prove for its mode. */\n credential?: PopupCredentialConfig\n}>\n\nexport type PopupReadyMessage = Addressed<{ type: \"ready\" }>\n\nexport type PopupEventMessage =\n | Addressed<{ type: \"request-received\" }>\n | Addressed<{ type: \"generating\" }>\n | Addressed<{ type: \"proof-generated\"; index?: number; total?: number; name?: string }>\n | Addressed<{\n type: \"success\"\n proofs: ProofResult[]\n result: QueryResult\n credential?: PopupCredentialOutcome\n }>\n | Addressed<{ type: \"rejected\" }>\n | Addressed<{ type: \"error\"; message: string }>\n\nexport type PopupMessage = PopupConfigureMessage | PopupReadyMessage | PopupEventMessage\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isPopupMessage(data: any): data is PopupMessage {\n return !!data && data.zkpassport === true && typeof data.type === \"string\"\n}\n","import type { Query } from \"@zkpassport/utils\"\nimport type { OnSuccessVerdict } from \"../types\"\nimport {\n DEFAULT_POPUP_URL,\n isPopupMessage,\n type PopupCredentialConfig,\n type PopupEventMessage,\n type PopupRequestConfig,\n} from \"./protocol\"\n\nexport type PopupSuccess = Extract<PopupEventMessage, { type: \"success\" }>\n\nexport type PopupCallbacks = {\n onRequestReceived?: () => void\n onGeneratingProof?: () => void\n onProofGenerated?: (progress: { index?: number; total?: number; name?: string }) => void\n onSuccess?: (response: Omit<PopupSuccess, \"zkpassport\" | \"type\" | \"session\">) => OnSuccessVerdict\n onReject?: () => void\n onError?: (message: string) => void\n // Fired when the user closes the popup before a result was produced\n onClose?: () => void\n}\n\nexport type OpenVerificationPopupOptions = {\n popupUrl?: string\n // Ignored when `credential` is set: a mint always opens a tab.\n windowMode?: \"popup\" | \"tab\"\n /** Reopens the verification of this `session`, from an earlier handle, instead of starting one. */\n session?: string\n request: PopupRequestConfig\n query: Query\n credential?: PopupCredentialConfig\n callbacks?: PopupCallbacks\n}\n\nexport type VerificationPopupHandle = {\n /** Close the popup window and stop listening to it. */\n close: () => void\n /** Stop listening to the popup but leave the window open for the user. */\n release: () => void\n popup: Window\n /** Names this verification to the popup. Persist it to reopen the same one later. */\n session: string\n}\n\nconst POPUP_WIDTH = 460\nconst POPUP_HEIGHT = 780\n// Browsers throttle timers in a background tab, so noticing a closed window can take seconds\nconst CLOSE_POLL_INTERVAL = 500\n// A popup the browser restored can have lost `window.opener`, so it cannot announce itself. These\n// blind retries reach it anyway.\nconst CONFIGURE_RETRY_INTERVAL = 300\nconst CONFIGURE_ATTEMPTS = 20\n\n// Not randomUUID, which a plain-http dev site does not get\nfunction newSessionId(): string {\n const bytes = crypto.getRandomValues(new Uint8Array(16))\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, \"0\")).join(\"\")\n}\n\n/** The popup reads the session from its own URL, so it survives a reload that drops every handle. */\nfunction withSession(popupUrl: string, session: string): string {\n const url = new URL(popupUrl)\n url.searchParams.set(\"s\", session)\n return url.toString()\n}\n\nfunction openPopupWindow(popupUrl: string): Window | null {\n // Centered on the current window\n const left = Math.max(0, (window.screenX ?? 0) + (window.outerWidth - POPUP_WIDTH) / 2)\n const top = Math.max(0, (window.screenY ?? 0) + (window.outerHeight - POPUP_HEIGHT) / 2)\n return (\n window.open(\n popupUrl,\n \"zkpassport-verify\",\n `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${Math.round(left)},top=${Math.round(top)}`,\n ) ??\n // Popup blocked: retry as a regular new tab\n window.open(popupUrl, \"zkpassport-verify\")\n )\n}\n\n/**\n * Open the hosted verification popup. MUST be called from a user gesture\n * (e.g. a click handler) or the browser will block the popup.\n *\n * If popup is blocked, will attempt to open in a new window.\n */\nexport function openVerificationPopup(\n options: OpenVerificationPopupOptions,\n): VerificationPopupHandle | null {\n if (typeof window === \"undefined\") return null\n const session = options.session ?? newSessionId()\n const baseUrl = options.popupUrl ?? DEFAULT_POPUP_URL\n const popupUrl = withSession(baseUrl, session)\n const popupOrigin = new URL(baseUrl).origin\n\n const windowMode = options.credential ? \"tab\" : options.windowMode\n const popup =\n windowMode === \"tab\" ? window.open(popupUrl, \"zkpassport-verify\") : openPopupWindow(popupUrl)\n if (!popup) return null\n\n const callbacks = options.callbacks ?? {}\n let finished = false\n let closePoll: ReturnType<typeof setInterval> | null = null\n let configurePoll: ReturnType<typeof setInterval> | null = null\n let configureAttempts = 0\n\n const stopConfiguring = () => {\n if (!configurePoll) return\n clearInterval(configurePoll)\n configurePoll = null\n }\n\n const stopWatchingForClose = () => {\n if (!closePoll) return\n clearInterval(closePoll)\n closePoll = null\n }\n\n const cleanup = () => {\n window.removeEventListener(\"message\", onMessage)\n stopConfiguring()\n stopWatchingForClose()\n }\n\n const configure = () => {\n try {\n popup.postMessage(\n {\n zkpassport: true,\n type: \"configure\",\n session,\n request: options.request,\n query: options.query,\n ...(options.credential ? { credential: options.credential } : {}),\n },\n popupOrigin,\n )\n } catch (error) {\n // Most likely DataCloneError: a non-serializable value in the request options\n console.error(\"[zkpassport] failed to send the request to the popup:\", error)\n stopConfiguring()\n callbacks.onError?.(\"Failed to send the request to the verification popup\")\n try {\n popup.close()\n } catch {\n // Already closed\n }\n }\n }\n\n const onMessage = (event: MessageEvent) => {\n if (event.origin !== popupOrigin) return\n const data = event.data\n if (!isPopupMessage(data)) return\n // Older popups send no session and still have to prove themselves by their window\n const isOurs = data.session ? data.session === session : event.source === popup\n if (!isOurs) return\n // Anything at all means the popup is listening, so stop configuring it blindly\n stopConfiguring()\n switch (data.type) {\n case \"ready\":\n configure()\n break\n case \"request-received\":\n callbacks.onRequestReceived?.()\n break\n case \"generating\":\n callbacks.onGeneratingProof?.()\n break\n case \"proof-generated\":\n callbacks.onProofGenerated?.({ index: data.index, total: data.total, name: data.name })\n break\n case \"success\": {\n if (finished) break\n finished = true\n const { zkpassport: _z, type: _t, session: _s, ...response } = data\n callbacks.onSuccess?.(response)\n break\n }\n case \"rejected\":\n finished = true\n callbacks.onReject?.()\n break\n case \"error\":\n callbacks.onError?.(data.message)\n break\n }\n }\n\n window.addEventListener(\"message\", onMessage)\n configurePoll = setInterval(() => {\n if (++configureAttempts > CONFIGURE_ATTEMPTS) stopConfiguring()\n else configure()\n }, CONFIGURE_RETRY_INTERVAL)\n closePoll = setInterval(() => {\n if (!popup.closed) return\n // A discarded tab also reports as closed and may come back, so only the watch stops here: the\n // listener stays on for a result that arrives after the window is gone\n stopWatchingForClose()\n if (!finished) callbacks.onClose?.()\n }, CLOSE_POLL_INTERVAL)\n\n return {\n popup,\n session,\n release: cleanup,\n close: () => {\n cleanup()\n try {\n popup.close()\n } catch {\n // Already closed\n }\n },\n }\n}\n","import type { Query } from \"@zkpassport/utils\"\nimport type { QueryBuilder, QueryBuilderResult } from \"../types\"\n\n// Seed a fresh builder from the serialized Query the RP page sent over postMessage.\nexport function hydrateQueryBuilder(builder: QueryBuilder, query: Query): QueryBuilderResult {\n return builder.raw(query).done()\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  import 'i18n-iso-countries';
2
2
  import '@zkpassport/utils';
3
- export { c as createOfflineQuery, g as generalCompare, n as normalizeCountry, b as numericalCompare, r as rangeCompare } from './index-CAudQvTm.js';
3
+ export { c as createOfflineQuery, g as generalCompare, n as normalizeCountry, b as numericalCompare, r as rangeCompare } from './index-D9GMXc4k.js';
4
+ import '@obsidion/bridge';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zkpassport/sdk",
3
- "version": "0.18.3-beta.1",
3
+ "version": "0.18.3-beta.2",
4
4
  "description": "Privacy-preserving identity verification using passports and ID cards",
5
5
  "author": "ZKPassport",
6
6
  "license": "Apache-2.0",
@@ -74,7 +74,7 @@
74
74
  "@noir-lang/noir_js": "1.0.0-beta.22",
75
75
  "@obsidion/bridge": "^0.12.2",
76
76
  "@zkpassport/registry": "0.15.3",
77
- "@zkpassport/utils": "0.40.0-beta.0",
77
+ "@zkpassport/utils": "0.40.0-beta.2",
78
78
  "buffer": "^6.0.3",
79
79
  "i18n-iso-countries": "^7.12.0",
80
80
  "pako": "^2.1.0",