@zkpassport/sdk 0.17.1 → 0.18.0
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/cjs/{index-BBgXLFAR.d.cts → index-J_WoAigp.d.cts} +1 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/popup.cjs +2 -2
- package/dist/cjs/popup.cjs.map +1 -1
- package/dist/cjs/popup.d.cts +13 -39
- package/dist/cjs/query.d.cts +1 -1
- package/dist/esm/{index-BBgXLFAR.d.ts → index-J_WoAigp.d.ts} +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/popup.d.ts +13 -39
- package/dist/esm/popup.js +2 -2
- package/dist/esm/popup.js.map +1 -1
- package/dist/esm/query.d.ts +1 -1
- package/package.json +3 -3
package/dist/esm/popup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProofMode,
|
|
2
|
-
import { O as OnSuccessVerdict, Q as QueryBuilder, a as QueryBuilderResult } from './index-
|
|
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-J_WoAigp.js';
|
|
3
3
|
import 'i18n-iso-countries';
|
|
4
4
|
|
|
5
5
|
declare const DEFAULT_POPUP_URL = "https://verify.zkpassport.id";
|
|
@@ -26,41 +26,19 @@ type PopupRequestConfig = {
|
|
|
26
26
|
mode?: ProofMode;
|
|
27
27
|
devMode?: boolean;
|
|
28
28
|
validity?: number;
|
|
29
|
-
uniqueIdentifierType?:
|
|
29
|
+
uniqueIdentifierType?: RequestedNullifierType;
|
|
30
30
|
oprfKeyId?: string;
|
|
31
|
+
policyId?: string;
|
|
32
|
+
domain?: string;
|
|
33
|
+
bridgeUrl?: string;
|
|
34
|
+
cloudProverUrl?: string;
|
|
31
35
|
};
|
|
32
|
-
/**
|
|
33
|
-
* Ready-to-send ZKPassportCredentials.issue() call, minus the ABI: pair it with
|
|
34
|
-
* `ZKPassportCredentialsAbi` from `@zkpassport/onchain-credentials`.
|
|
35
|
-
* The first argument is the `policyId`.
|
|
36
|
-
* The second argument is the proof data.
|
|
37
|
-
*/
|
|
38
|
-
type PopupCredentialIssueCall = {
|
|
39
|
-
address: `0x${string}`;
|
|
40
|
-
functionName: "issue";
|
|
41
|
-
args: readonly [bigint, `0x${string}`];
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* issue() checks the wallet bound into the proof, not the transaction sender,
|
|
45
|
-
* so an "unminted" issueCall may be submitted by any account the relying party
|
|
46
|
-
* controls. The hosted popup emits "minted" or "already-verified" only;
|
|
47
|
-
* "unminted" is reserved for a flow that hands the issue() call over instead
|
|
48
|
-
* of submitting it.
|
|
49
|
-
* `recipient` is the one the relying party passed in.
|
|
50
|
-
*/
|
|
51
36
|
type PopupCredentialOutcome = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
status: "unminted";
|
|
58
|
-
recipient: `0x${string}`;
|
|
59
|
-
reason?: string;
|
|
60
|
-
issueCall: PopupCredentialIssueCall;
|
|
61
|
-
} | {
|
|
62
|
-
status: "already-verified";
|
|
63
|
-
recipient: `0x${string}`;
|
|
37
|
+
policyId: `0x${string}`;
|
|
38
|
+
account: `0x${string}`;
|
|
39
|
+
chainId: number;
|
|
40
|
+
contract: `0x${string}`;
|
|
41
|
+
txHash?: `0x${string}`;
|
|
64
42
|
};
|
|
65
43
|
type PopupConfigureMessage = {
|
|
66
44
|
zkpassport: true;
|
|
@@ -121,10 +99,6 @@ type PopupCallbacks = {
|
|
|
121
99
|
};
|
|
122
100
|
type OpenVerificationPopupOptions = {
|
|
123
101
|
popupUrl?: string;
|
|
124
|
-
/**
|
|
125
|
-
* "popup" (default) opens a small chromeless window; "tab" opens a regular
|
|
126
|
-
* browser tab (or window, per the user's browser settings) with full chrome.
|
|
127
|
-
*/
|
|
128
102
|
windowMode?: "popup" | "tab";
|
|
129
103
|
request: PopupRequestConfig;
|
|
130
104
|
query: Query;
|
|
@@ -148,4 +122,4 @@ declare function openVerificationPopup(options: OpenVerificationPopupOptions): V
|
|
|
148
122
|
|
|
149
123
|
declare function hydrateQueryBuilder(builder: QueryBuilder, query: Query): QueryBuilderResult;
|
|
150
124
|
|
|
151
|
-
export { DEFAULT_POPUP_URL, type OpenVerificationPopupOptions, type PopupCallbacks, type PopupConfigureMessage, type PopupCredentialConfig, type
|
|
125
|
+
export { DEFAULT_POPUP_URL, type OpenVerificationPopupOptions, type PopupCallbacks, type PopupConfigureMessage, type PopupCredentialConfig, type PopupCredentialOutcome, type PopupEventMessage, type PopupMessage, type PopupReadyMessage, type PopupRequestConfig, type PopupSuccess, type VerificationPopupHandle, hydrateQueryBuilder, isPopupMessage, openVerificationPopup };
|
package/dist/esm/popup.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
export{
|
|
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
|
|
3
3
|
//# sourceMappingURL=popup.js.map
|
package/dist/esm/popup.js.map
CHANGED
|
@@ -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":"AASO,IAAMA,EAAoB,+BAmG1B,SAASC,CAAAA,CAAeC,CAAAA,CAAiC,CAC9D,OAAO,CAAC,CAACA,CAAAA,EAAQA,EAAK,UAAA,GAAe,IAAA,EAAQ,OAAOA,CAAAA,CAAK,IAAA,EAAS,QACpE,CClEA,IAAMC,CAAAA,CAAc,GAAA,CACdC,EAAe,GAAA,CACfC,CAAAA,CAAsB,GAAA,CAE5B,SAASC,EAAgBC,CAAAA,CAAiC,CAExD,IAAMC,CAAAA,CAAO,KAA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A,CAEA,OAAA,MAAA,CAAO,gBAAA,CAAiB,UAAWgB,CAAS,CAAA,CAC5CF,EAAY,WAAA,CAAY,IAAM,CACxBH,CAAAA,CAAM,MAAA,GACRI,CAAAA,EAAQ,CACHF,GAAUD,CAAAA,CAAU,OAAA,IAAU,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,CCpKO,SAASW,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,IAAIC,CAAK,CAAA,CAAE,MAC5B","file":"popup.js","sourcesContent":["import type {\n NullifierType,\n ProofMode,\n ProofResult,\n Query,\n QueryResult,\n SupportedChain,\n} from \"@zkpassport/utils\"\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?: NullifierType.NON_SALTED | NullifierType.SALTED\n oprfKeyId?: string\n}\n\n/**\n * Ready-to-send ZKPassportCredentials.issue() call, minus the ABI: pair it with\n * `ZKPassportCredentialsAbi` from `@zkpassport/onchain-credentials`.\n * The first argument is the `policyId`.\n * The second argument is the proof data.\n */\nexport type PopupCredentialIssueCall = {\n address: `0x${string}`\n functionName: \"issue\"\n args: readonly [bigint, `0x${string}`]\n}\n\n/**\n * issue() checks the wallet bound into the proof, not the transaction sender,\n * so an \"unminted\" issueCall may be submitted by any account the relying party\n * controls. The hosted popup emits \"minted\" or \"already-verified\" only;\n * \"unminted\" is reserved for a flow that hands the issue() call over instead\n * of submitting it.\n * `recipient` is the one the relying party passed in.\n */\nexport type PopupCredentialOutcome =\n | {\n status: \"minted\"\n recipient: `0x${string}`\n txHash: `0x${string}`\n issueCall: PopupCredentialIssueCall\n }\n | {\n status: \"unminted\"\n recipient: `0x${string}`\n reason?: string\n issueCall: PopupCredentialIssueCall\n }\n | { status: \"already-verified\"; recipient: `0x${string}` }\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 /**\n * \"popup\" (default) opens a small chromeless window; \"tab\" opens a regular\n * browser tab (or window, per the user's browser settings) with full chrome.\n */\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 popup =\n options.windowMode === \"tab\"\n ? window.open(popupUrl, \"zkpassport-verify\")\n : 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","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,MAA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AAA,GACR,CAAA,KAAQ,CAER,CACF,CACA,MACF,KAAK,kBAAA,CACHC,CAAAA,CAAU,iBAAA,KACV,MACF,KAAK,aACHA,CAAAA,CAAU,iBAAA,KACV,MACF,KAAK,iBAAA,CACHA,CAAAA,CAAU,mBAAmB,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"]}
|
package/dist/esm/query.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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-
|
|
3
|
+
export { c as createOfflineQuery, g as generalCompare, n as normalizeCountry, b as numericalCompare, r as rangeCompare } from './index-J_WoAigp.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkpassport/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Privacy-preserving identity verification using passports and ID cards",
|
|
5
5
|
"author": "ZKPassport",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@noble/secp256k1": "^2.2.3",
|
|
74
74
|
"@noir-lang/noir_js": "1.0.0-beta.22",
|
|
75
75
|
"@obsidion/bridge": "^0.12.2",
|
|
76
|
-
"@zkpassport/registry": "0.
|
|
77
|
-
"@zkpassport/utils": "0.
|
|
76
|
+
"@zkpassport/registry": "0.15.0",
|
|
77
|
+
"@zkpassport/utils": "0.39.0-beta.2",
|
|
78
78
|
"buffer": "^6.0.3",
|
|
79
79
|
"i18n-iso-countries": "^7.12.0",
|
|
80
80
|
"pako": "^2.1.0",
|