@zkpassport/sdk 0.20.0 → 0.21.0-beta.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/cjs/{index-D9GMXc4k.d.cts → index-CnSQu9Cx.d.cts} +38 -5
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -2
- package/dist/cjs/popup.cjs +2 -2
- package/dist/cjs/popup.cjs.map +1 -1
- package/dist/cjs/popup.d.cts +8 -4
- package/dist/cjs/query.d.cts +2 -1
- package/dist/esm/{index-D9GMXc4k.d.ts → index-CnSQu9Cx.d.ts} +38 -5
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/popup.d.ts +8 -4
- package/dist/esm/popup.js +2 -2
- package/dist/esm/popup.js.map +1 -1
- package/dist/esm/query.d.ts +2 -1
- package/package.json +3 -3
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { D as DashboardConfig, d as OfflineQueryBuilderResult, O as OnSuccessVerdict, P as Policy, Q as QueryBuilder, a as QueryBuilderResult, e as QueryResultError, f as QueryResultErrors, h as RequestSuccess, R as RequestedNullifierType, S as SolidityProofVerificationData, i as SolidityServiceConfig, j as SolidityVerifierParameters, V as VERSION, k as VerificationConfig, l as VerificationResult, m as VerifierMode, Z as ZKPassport, c as createOfflineQuery, n as normalizeCountry } from './index-
|
|
2
|
-
export { ASEAN_COUNTRIES, BoundData, CountryName, DisclosableIDCredential, EEA_COUNTRIES, EU_COUNTRIES, FacematchMode, IDCredential, IDCredentialValue, JsonRpcRequest, MERCOSUR_COUNTRIES, NullifierType, NumericalIDCredential, ProofMode, ProofResult, ProofType, ProofTypeLength, Query, QueryResult, SANCTIONED_COUNTRIES, SCHENGEN_COUNTRIES, SanctionsCountries, SanctionsLists, Service, SupportedChain, getChainFromId, getIdFromChain } from '@zkpassport/utils';
|
|
1
|
+
export { D as DashboardConfig, d as OfflineQueryBuilderResult, O as OnSuccessVerdict, P as Policy, Q as QueryBuilder, a as QueryBuilderResult, e as QueryResultError, f as QueryResultErrors, h as RequestSuccess, R as RequestedNullifierType, S as SolidityProofVerificationData, i as SolidityServiceConfig, j as SolidityVerifierParameters, V as VERSION, k as VerificationConfig, l as VerificationResult, m as VerifierMode, Z as ZKPassport, c as createOfflineQuery, o as getRegistryClientOptions, n as normalizeCountry } from './index-CnSQu9Cx.cjs';
|
|
2
|
+
export { ASEAN_COUNTRIES, AllowedVerificationMethod, BoundData, CountryName, DEFAULT_ALLOWED_VERIFICATION_METHODS, DisclosableIDCredential, EEA_COUNTRIES, EU_COUNTRIES, FacematchMode, IDCredential, IDCredentialValue, JsonRpcRequest, MERCOSUR_COUNTRIES, NullifierType, NumericalIDCredential, ProofMode, ProofResult, ProofType, ProofTypeLength, Query, QueryResult, SANCTIONED_COUNTRIES, SCHENGEN_COUNTRIES, SanctionsCountries, SanctionsLists, Service, SupportedChain, VerificationMethod, VerificationTier, expandAllowedVerificationMethods, getChainFromId, getIdFromChain, getTierForVerificationMethod, isVerificationMethodAllowed } from '@zkpassport/utils';
|
|
3
|
+
import '@zkpassport/registry';
|
|
3
4
|
export { KeyPair } from '@obsidion/bridge';
|
|
4
5
|
import 'i18n-iso-countries';
|
package/dist/cjs/popup.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var w="https://verify.zkpassport.id";function
|
|
2
|
-
exports.DEFAULT_POPUP_URL=w;exports.hydrateQueryBuilder=
|
|
1
|
+
'use strict';var w="https://verify.zkpassport.id";function x(e){return !!e&&e.zkpassport===true&&typeof e.type=="string"}var R=460,h=780,b=500,E=300,k=20;function q(){let e=crypto.getRandomValues(new Uint8Array(16));return Array.from(e,r=>r.toString(16).padStart(2,"0")).join("")}function O(e,r){let n=new URL(e);return n.searchParams.set("s",r),n.toString()}function A(e){return `zkpassport-verify-${e}`}function I(e,r){let n=Math.max(0,(window.screenX??0)+(window.outerWidth-R)/2),i=Math.max(0,(window.screenY??0)+(window.outerHeight-h)/2);return window.open(e,r,`popup,width=${R},height=${h},left=${Math.round(n)},top=${Math.round(i)}`)??window.open(e,r)}function z(e){if(typeof window>"u")return null;let r=e.session??q(),n=e.popupUrl??w,i=O(n,r),l=new URL(n).origin,C=e.credential?"tab":e.windowMode,g=A(r),o=C==="tab"?window.open(i,g):I(i,g);if(!o)return null;o.focus();let s=e.callbacks??{},u=false,a=null,d=null,v=0,c=()=>{d&&(clearInterval(d),d=null);},y=()=>{a&&(clearInterval(a),a=null);},f=()=>{window.removeEventListener("message",m),c(),y();},P=()=>{try{o.postMessage({zkpassport:!0,type:"configure",session:r,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),c(),s.onError?.("Failed to send the request to the verification popup");try{o.close();}catch{}}},m=p=>{if(p.origin!==l)return;let t=p.data;if(!(!x(t)||!(t.session?t.session===r:p.source===o)))switch(c(),t.type){case "ready":P();break;case "request-received":s.onRequestReceived?.();break;case "generating":s.onGeneratingProof?.();break;case "proof-generated":s.onProofGenerated?.({index:t.index,total:t.total,name:t.name});break;case "success":{if(u)break;u=true;let{zkpassport:S,type:Q,session:_,...M}=t;s.onSuccess?.(M);break}case "rejected":u=true,s.onReject?.();break;case "error":s.onError?.(t.message,t.code);break}};return window.addEventListener("message",m),d=setInterval(()=>{++v>k?c():P();},E),a=setInterval(()=>{o.closed&&(y(),u||s.onClose?.());},b),{popup:o,session:r,release:f,close:()=>{f();try{o.close();}catch{}}}}function U(e,r){return e.raw(r).done()}
|
|
2
|
+
exports.DEFAULT_POPUP_URL=w;exports.hydrateQueryBuilder=U;exports.isPopupMessage=x;exports.openVerificationPopup=z;//# sourceMappingURL=popup.cjs.map
|
|
3
3
|
//# sourceMappingURL=popup.cjs.map
|
package/dist/cjs/popup.cjs.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","CONFIGURE_RETRY_INTERVAL","CONFIGURE_ATTEMPTS","newSessionId","bytes","byte","withSession","popupUrl","session","url","windowName","openPopupWindow","name","left","top","openVerificationPopup","options","baseUrl","popupOrigin","windowMode","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,IAAA,EAAQ,OAAOA,CAAAA,CAAK,IAAA,EAAS,QACpE,CCnCA,IAAMC,CAAAA,CAAc,GAAA,CACdC,CAAAA,CAAe,GAAA,CAEfC,CAAAA,CAAsB,GAAA,CAGtBC,CAAAA,CAA2B,GAAA,CAC3BC,CAAAA,CAAqB,GAG3B,SAASC,CAAAA,EAAuB,CAC9B,IAAMC,CAAAA,CAAQ,MAAA,CAAO,eAAA,CAAgB,IAAI,UAAA,CAAW,EAAE,CAAC,CAAA,CACvD,OAAO,KAAA,CAAM,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,CAAAA,CAAI,YAAA,CAAa,GAAA,CAAI,GAAA,CAAKD,CAAO,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A,CAChC,KACJ,CACF,CAAA,CAEA,OAAA,MAAA,CAAO,gBAAA,CAAiB,SAAA,CAAWgC,CAAS,CAAA,CAC5CL,CAAAA,CAAgB,WAAA,CAAY,IAAM,CAC5B,EAAEC,CAAAA,CAAoBvB,CAAAA,CAAoBwB,CAAAA,EAAgB,CACzDI,CAAAA,GACP,CAAA,CAAG7B,CAAwB,CAAA,CAC3BsB,CAAAA,CAAY,WAAA,CAAY,IAAM,CACvBH,CAAAA,CAAM,MAAA,GAGXO,CAAAA,EAAqB,CAChBL,CAAAA,EAAUD,CAAAA,CAAU,OAAA,IAAU,EACrC,CAAA,CAAGrB,CAAmB,CAAA,CAEf,CACL,KAAA,CAAAoB,CAAAA,CACA,OAAA,CAAAZ,CAAAA,CACA,QAASoB,CAAAA,CACT,KAAA,CAAO,IAAM,CACXA,CAAAA,EAAQ,CACR,GAAI,CACFR,CAAAA,CAAM,KAAA,GACR,CAAA,KAAQ,CAER,CACF,CACF,CACF,CC1NO,SAASiB,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,GAAA,CAAIC,CAAK,CAAA,CAAE,IAAA,EAC5B","file":"popup.cjs","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 windowName(session: string): string {\n return `zkpassport-verify-${session}`\n}\n\nfunction openPopupWindow(popupUrl: string, name: 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 name,\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, name)\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 name = windowName(session)\n const popup = windowMode === \"tab\" ? window.open(popupUrl, name) : openPopupWindow(popupUrl, name)\n if (!popup) return null\n popup.focus()\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
|
+
{"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","windowName","openPopupWindow","name","left","top","openVerificationPopup","options","baseUrl","popupOrigin","windowMode","popup","callbacks","finished","closePoll","configurePoll","configureAttempts","stopConfiguring","stopWatchingForClose","cleanup","onMessage","configure","error","event","_z","_t","_s","response","hydrateQueryBuilder","builder","query"],"mappings":"aAUO,IAAMA,CAAAA,CAAoB,+BA+E1B,SAASC,CAAAA,CAAeC,CAAAA,CAAiC,CAC9D,OAAO,CAAC,CAACA,CAAAA,EAAQA,CAAAA,CAAK,UAAA,GAAe,IAAA,EAAQ,OAAOA,CAAAA,CAAK,IAAA,EAAS,QACpE,CC7CA,IAAMC,CAAAA,CAAc,GAAA,CACdC,CAAAA,CAAe,GAAA,CAEfC,CAAAA,CAAsB,GAAA,CAGtBC,CAAAA,CAA2B,GAAA,CAC3BC,CAAAA,CAAqB,EAAA,CAG3B,SAASC,CAAAA,EAAuB,CAC9B,IAAMC,CAAAA,CAAQ,MAAA,CAAO,eAAA,CAAgB,IAAI,UAAA,CAAW,EAAE,CAAC,CAAA,CACvD,OAAO,KAAA,CAAM,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,EAAYC,CAAAA,CAAkBC,CAAAA,CAAyB,CAC9D,IAAMC,CAAAA,CAAM,IAAI,GAAA,CAAIF,CAAQ,CAAA,CAC5B,OAAAE,CAAAA,CAAI,YAAA,CAAa,GAAA,CAAI,GAAA,CAAKD,CAAO,CAAA,CAC1BC,CAAAA,CAAI,QAAA,EACb,CAEA,SAASC,CAAAA,CAAWF,CAAAA,CAAyB,CAC3C,OAAO,CAAA,kBAAA,EAAqBA,CAAO,CAAA,CACrC,CAEA,SAASG,EAAgBJ,CAAAA,CAAkBK,CAAAA,CAA6B,CAEtE,IAAMC,CAAAA,CAAO,IAAA,CAAK,GAAA,CAAI,CAAA,CAAA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CAAG7B,CAAwB,CAAA,CAC3BsB,CAAAA,CAAY,WAAA,CAAY,IAAM,CACvBH,CAAAA,CAAM,MAAA,GAGXO,CAAAA,EAAqB,CAChBL,CAAAA,EAAUD,CAAAA,CAAU,OAAA,IAAU,EACrC,CAAA,CAAGrB,CAAmB,CAAA,CAEf,CACL,KAAA,CAAAoB,CAAAA,CACA,OAAA,CAAAZ,CAAAA,CACA,QAASoB,CAAAA,CACT,KAAA,CAAO,IAAM,CACXA,CAAAA,EAAQ,CACR,GAAI,CACFR,CAAAA,CAAM,KAAA,GACR,CAAA,KAAQ,CAER,CACF,CACF,CACF,CC3NO,SAASiB,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,GAAA,CAAIC,CAAK,CAAA,CAAE,IAAA,EAC5B","file":"popup.cjs","sourcesContent":["import type {\n AllowedVerificationMethod,\n ProofMode,\n ProofResult,\n Query,\n QueryResult,\n SupportedChain,\n} 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 allowedVerificationMethods?: AllowedVerificationMethod[]\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 PopupErrorCode =\n \"unsupported-id\" | \"id-not-accepted\" | \"device-unsupported\" | \"requirements-not-met\"\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; code?: PopupErrorCode }>\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 PopupErrorCode,\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, code?: PopupErrorCode) => 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 windowName(session: string): string {\n return `zkpassport-verify-${session}`\n}\n\nfunction openPopupWindow(popupUrl: string, name: 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 name,\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, name)\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 name = windowName(session)\n const popup = windowMode === \"tab\" ? window.open(popupUrl, name) : openPopupWindow(popupUrl, name)\n if (!popup) return null\n popup.focus()\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, data.code)\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"]}
|
package/dist/cjs/popup.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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-
|
|
1
|
+
import { ProofMode, AllowedVerificationMethod, SupportedChain, ProofResult, QueryResult, Query } from '@zkpassport/utils';
|
|
2
|
+
import { R as RequestedNullifierType, O as OnSuccessVerdict, Q as QueryBuilder, a as QueryBuilderResult } from './index-CnSQu9Cx.cjs';
|
|
3
|
+
import '@zkpassport/registry';
|
|
3
4
|
import '@obsidion/bridge';
|
|
4
5
|
import 'i18n-iso-countries';
|
|
5
6
|
|
|
@@ -34,6 +35,7 @@ type PopupRequestConfig = {
|
|
|
34
35
|
bridgeUrl?: string;
|
|
35
36
|
cloudProverUrl?: string;
|
|
36
37
|
appClip?: boolean;
|
|
38
|
+
allowedVerificationMethods?: AllowedVerificationMethod[];
|
|
37
39
|
};
|
|
38
40
|
type PopupCredentialOutcome = {
|
|
39
41
|
policyId: `0x${string}`;
|
|
@@ -42,6 +44,7 @@ type PopupCredentialOutcome = {
|
|
|
42
44
|
contract: `0x${string}`;
|
|
43
45
|
txHash?: `0x${string}`;
|
|
44
46
|
};
|
|
47
|
+
type PopupErrorCode = "unsupported-id" | "id-not-accepted" | "device-unsupported" | "requirements-not-met";
|
|
45
48
|
/**
|
|
46
49
|
* Every message names its verification, because a browser that discards the popup's tab rebuilds it
|
|
47
50
|
* as a different window and the handle no longer recognises it.
|
|
@@ -79,6 +82,7 @@ type PopupEventMessage = Addressed<{
|
|
|
79
82
|
}> | Addressed<{
|
|
80
83
|
type: "error";
|
|
81
84
|
message: string;
|
|
85
|
+
code?: PopupErrorCode;
|
|
82
86
|
}>;
|
|
83
87
|
type PopupMessage = PopupConfigureMessage | PopupReadyMessage | PopupEventMessage;
|
|
84
88
|
declare function isPopupMessage(data: any): data is PopupMessage;
|
|
@@ -96,7 +100,7 @@ type PopupCallbacks = {
|
|
|
96
100
|
}) => void;
|
|
97
101
|
onSuccess?: (response: Omit<PopupSuccess, "zkpassport" | "type" | "session">) => OnSuccessVerdict;
|
|
98
102
|
onReject?: () => void;
|
|
99
|
-
onError?: (message: string) => void;
|
|
103
|
+
onError?: (message: string, code?: PopupErrorCode) => void;
|
|
100
104
|
onClose?: () => void;
|
|
101
105
|
};
|
|
102
106
|
type OpenVerificationPopupOptions = {
|
|
@@ -128,4 +132,4 @@ declare function openVerificationPopup(options: OpenVerificationPopupOptions): V
|
|
|
128
132
|
|
|
129
133
|
declare function hydrateQueryBuilder(builder: QueryBuilder, query: Query): QueryBuilderResult;
|
|
130
134
|
|
|
131
|
-
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 };
|
|
135
|
+
export { DEFAULT_POPUP_URL, type OpenVerificationPopupOptions, type PopupCallbacks, type PopupConfigureMessage, type PopupCredentialConfig, type PopupCredentialOutcome, type PopupErrorCode, type PopupEventMessage, type PopupMessage, type PopupReadyMessage, type PopupRequestConfig, type PopupSuccess, type VerificationPopupHandle, hydrateQueryBuilder, isPopupMessage, openVerificationPopup };
|
package/dist/cjs/query.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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-CnSQu9Cx.cjs';
|
|
4
|
+
import '@zkpassport/registry';
|
|
4
5
|
import '@obsidion/bridge';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Query, IDCredential, IDCredentialValue, NumericalIDCredential, DisclosableIDCredential, BoundData, SupportedChain, SanctionsCountries, SanctionsLists, FacematchMode, ProofResult, QueryResult, NullifierType, CountryName, ProofMode, Service } from '@zkpassport/utils';
|
|
1
|
+
import { Query, IDCredential, IDCredentialValue, NumericalIDCredential, DisclosableIDCredential, BoundData, SupportedChain, SanctionsCountries, SanctionsLists, FacematchMode, ProofResult, QueryResult, NullifierType, VerificationMethod, AllowedVerificationMethod, CountryName, ProofMode, Service } from '@zkpassport/utils';
|
|
2
|
+
import { createRegistryClient } from '@zkpassport/registry';
|
|
2
3
|
import { KeyPair } from '@obsidion/bridge';
|
|
3
4
|
import { Alpha3Code } from 'i18n-iso-countries';
|
|
4
5
|
|
|
@@ -8,7 +9,7 @@ type QueryResultError<T> = {
|
|
|
8
9
|
message: string;
|
|
9
10
|
};
|
|
10
11
|
type QueryResultErrors = {
|
|
11
|
-
[key in IDCredential | "sig_check_dsc" | "sig_check_id_data" | "data_check_integrity" | "outer" | "disclose" | "bind" | "facematch" | "sanctions"]: {
|
|
12
|
+
[key in IDCredential | "sig_check_dsc" | "sig_check_id_data" | "data_check_integrity" | "attested_id" | "verification_method" | "outer" | "disclose" | "bind" | "facematch" | "sanctions"]: {
|
|
12
13
|
disclose?: QueryResultError<string | number | Date>;
|
|
13
14
|
gte?: QueryResultError<number | Date>;
|
|
14
15
|
gt?: QueryResultError<number | Date>;
|
|
@@ -21,6 +22,7 @@ type QueryResultErrors = {
|
|
|
21
22
|
commitment?: QueryResultError<string>;
|
|
22
23
|
date?: QueryResultError<string>;
|
|
23
24
|
certificate?: QueryResultError<string>;
|
|
25
|
+
revocation?: QueryResultError<string>;
|
|
24
26
|
scope?: QueryResultError<string>;
|
|
25
27
|
};
|
|
26
28
|
};
|
|
@@ -32,12 +34,28 @@ type VerificationConfig = {
|
|
|
32
34
|
* and Ethereum otherwise. Defaults to the built-in endpoint for that chain.
|
|
33
35
|
*/
|
|
34
36
|
rpcUrl?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Where to fetch the circuit manifest and the packaged circuits (the verification keys) from,
|
|
39
|
+
* instead of ZKPassport's CDN. For verifying proofs made with locally packaged circuits, served
|
|
40
|
+
* with the circuits repo's `serve-circuits` script: it must be the same server the app proved
|
|
41
|
+
* with. Expects `<url>/by-version/<version>/manifest.json`, `<url>/by-root/<root>/manifest.json`
|
|
42
|
+
* and `<url>/by-hash/<vkey hash>.json`.
|
|
43
|
+
*/
|
|
44
|
+
circuitsUrl?: string;
|
|
35
45
|
};
|
|
36
46
|
type RequestedNullifierType = NullifierType.NON_SALTED | NullifierType.SALTED | NullifierType.NONE;
|
|
37
47
|
type VerificationResult = {
|
|
38
48
|
uniqueIdentifier: string | undefined;
|
|
39
49
|
uniqueIdentifierType: NullifierType | undefined;
|
|
40
50
|
verified: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The scheme the proofs were made under. Its tier (`getTierForVerificationMethod`) says what
|
|
53
|
+
* they rest on. Tier 1: the ID's chip, signed by its issuing country. Tier 2: the printed data
|
|
54
|
+
* page read by camera and attested by the device (App Attest or Play Integrity) together with
|
|
55
|
+
* a strict face match. A Tier 2 unique identifier is derived from the printed MRZ, not from a
|
|
56
|
+
* signature, so it is not proof against fabricated documents.
|
|
57
|
+
*/
|
|
58
|
+
verificationMethod?: VerificationMethod;
|
|
41
59
|
queryResultErrors?: Partial<QueryResultErrors>;
|
|
42
60
|
};
|
|
43
61
|
type SolidityProofVerificationData = {
|
|
@@ -50,6 +68,8 @@ type SolidityServiceConfig = {
|
|
|
50
68
|
domain: string;
|
|
51
69
|
scope: string;
|
|
52
70
|
devMode: boolean;
|
|
71
|
+
/** The credentials the service accepts; empty means signed credentials only */
|
|
72
|
+
allowedVerificationMethods?: AllowedVerificationMethod[];
|
|
53
73
|
};
|
|
54
74
|
type SolidityVerifierParameters = {
|
|
55
75
|
version: string;
|
|
@@ -150,6 +170,7 @@ type QueryBuilderResult = {
|
|
|
150
170
|
uniqueIdentifier: string | undefined;
|
|
151
171
|
uniqueIdentifierType: NullifierType | undefined;
|
|
152
172
|
verified: boolean;
|
|
173
|
+
verificationMethod?: VerificationMethod;
|
|
153
174
|
result: QueryResult;
|
|
154
175
|
queryResultErrors?: Partial<QueryResultErrors>;
|
|
155
176
|
proofs: ProofResult[];
|
|
@@ -291,6 +312,10 @@ declare function createOfflineQuery(): QueryBuilder<"offline">;
|
|
|
291
312
|
|
|
292
313
|
declare const VERSION: string;
|
|
293
314
|
|
|
315
|
+
type RegistryClientOptions = NonNullable<Parameters<typeof createRegistryClient>[1]>;
|
|
316
|
+
/** The registry client overrides a {@link VerificationConfig} asks for */
|
|
317
|
+
declare function getRegistryClientOptions(config: VerificationConfig | undefined): RegistryClientOptions;
|
|
318
|
+
|
|
294
319
|
declare class ZKPassport {
|
|
295
320
|
private domain;
|
|
296
321
|
private domainProvided;
|
|
@@ -348,9 +373,12 @@ declare class ZKPassport {
|
|
|
348
373
|
* @param keyPairOverride A keypair from {@link getRequestKeyPair}, which keeps the request ID and bridge topic.
|
|
349
374
|
* @param replayMissedMessages Redelivers what was already sent on this topic, for a request resumed on a new page.
|
|
350
375
|
* @param config Settings for verifying the received proofs, see {@link VerificationConfig}.
|
|
376
|
+
* @param allowedVerificationMethods The credentials your service accepts: tiers and/or exact schemes,
|
|
377
|
+
* see {@link AllowedVerificationMethod}. Defaults to signed credentials only (tier 1); an ID verified
|
|
378
|
+
* another way is refused by the app before proving and by `verify()` after.
|
|
351
379
|
* @returns The query builder object.
|
|
352
380
|
*/
|
|
353
|
-
request({ name, logo, purpose, scope, projectID, mode, validity, devMode, uniqueIdentifierType, oprfKeyId, topicOverride, keyPairOverride, replayMissedMessages, cloudProverUrl, bridgeUrl, returnDeepLink, verifierMode, config, overrides, }: {
|
|
381
|
+
request({ name, logo, purpose, scope, projectID, mode, validity, devMode, uniqueIdentifierType, oprfKeyId, topicOverride, keyPairOverride, replayMissedMessages, cloudProverUrl, bridgeUrl, returnDeepLink, verifierMode, config, overrides, allowedVerificationMethods, }: {
|
|
354
382
|
name?: string;
|
|
355
383
|
logo?: string;
|
|
356
384
|
purpose?: string;
|
|
@@ -369,9 +397,11 @@ declare class ZKPassport {
|
|
|
369
397
|
returnDeepLink?: string;
|
|
370
398
|
verifierMode?: VerifierMode;
|
|
371
399
|
config?: VerificationConfig;
|
|
400
|
+
/** `appClip` allows the popup to send a chip-only request to the no-install App Clip lane */
|
|
372
401
|
overrides?: {
|
|
373
402
|
appClip?: boolean;
|
|
374
403
|
};
|
|
404
|
+
allowedVerificationMethods?: AllowedVerificationMethod[];
|
|
375
405
|
}): Promise<QueryBuilder>;
|
|
376
406
|
/**
|
|
377
407
|
* @notice Create a new offline query
|
|
@@ -399,10 +429,12 @@ declare class ZKPassport {
|
|
|
399
429
|
* ZKPassport verifier API, and "auto" (default) verifies locally but defers to the API when
|
|
400
430
|
* the local result is not verified — e.g. proofs from a newer bb version than this SDK supports.
|
|
401
431
|
* @param config Verification settings such as the RPC URL, see {@link VerificationConfig}.
|
|
432
|
+
* @param allowedVerificationMethods The credentials your service accepts, see {@link AllowedVerificationMethod}.
|
|
433
|
+
* Defaults to signed credentials only (tier 1).
|
|
402
434
|
* @returns An object containing the unique identifier associated to the user
|
|
403
435
|
* and a boolean indicating whether the proofs were successfully verified.
|
|
404
436
|
*/
|
|
405
|
-
verify({ proofs, originalQuery, queryResult, validity, scope, devMode, writingDirectory, oprfKeyId, uniqueIdentifierType, verifierMode, config, }: {
|
|
437
|
+
verify({ proofs, originalQuery, queryResult, validity, scope, devMode, writingDirectory, oprfKeyId, uniqueIdentifierType, verifierMode, config, allowedVerificationMethods, }: {
|
|
406
438
|
proofs: Array<ProofResult>;
|
|
407
439
|
originalQuery: Query;
|
|
408
440
|
queryResult: QueryResult;
|
|
@@ -414,6 +446,7 @@ declare class ZKPassport {
|
|
|
414
446
|
uniqueIdentifierType?: RequestedNullifierType;
|
|
415
447
|
verifierMode?: VerifierMode;
|
|
416
448
|
config?: VerificationConfig;
|
|
449
|
+
allowedVerificationMethods?: AllowedVerificationMethod[];
|
|
417
450
|
}): Promise<VerificationResult>;
|
|
418
451
|
private verifyLocally;
|
|
419
452
|
getSolidityVerifierDetails(): {
|
|
@@ -472,4 +505,4 @@ declare class ZKPassport {
|
|
|
472
505
|
clearAllRequests(): void;
|
|
473
506
|
}
|
|
474
507
|
|
|
475
|
-
export { type DashboardConfig as D, type OnSuccessVerdict as O, type Policy as P, type QueryBuilder as Q, type RequestedNullifierType as R, type SolidityProofVerificationData as S, VERSION as V, ZKPassport as Z, type QueryBuilderResult as a, numericalCompare as b, createOfflineQuery as c, type OfflineQueryBuilderResult as d, type QueryResultError as e, type QueryResultErrors as f, generalCompare as g, type RequestSuccess as h, type SolidityServiceConfig as i, type SolidityVerifierParameters as j, type VerificationConfig as k, type VerificationResult as l, type VerifierMode as m, normalizeCountry as n, rangeCompare as r };
|
|
508
|
+
export { type DashboardConfig as D, type OnSuccessVerdict as O, type Policy as P, type QueryBuilder as Q, type RequestedNullifierType as R, type SolidityProofVerificationData as S, VERSION as V, ZKPassport as Z, type QueryBuilderResult as a, numericalCompare as b, createOfflineQuery as c, type OfflineQueryBuilderResult as d, type QueryResultError as e, type QueryResultErrors as f, generalCompare as g, type RequestSuccess as h, type SolidityServiceConfig as i, type SolidityVerifierParameters as j, type VerificationConfig as k, type VerificationResult as l, type VerifierMode as m, normalizeCountry as n, getRegistryClientOptions as o, rangeCompare as r };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { D as DashboardConfig, d as OfflineQueryBuilderResult, O as OnSuccessVerdict, P as Policy, Q as QueryBuilder, a as QueryBuilderResult, e as QueryResultError, f as QueryResultErrors, h as RequestSuccess, R as RequestedNullifierType, S as SolidityProofVerificationData, i as SolidityServiceConfig, j as SolidityVerifierParameters, V as VERSION, k as VerificationConfig, l as VerificationResult, m as VerifierMode, Z as ZKPassport, c as createOfflineQuery, n as normalizeCountry } from './index-
|
|
2
|
-
export { ASEAN_COUNTRIES, BoundData, CountryName, DisclosableIDCredential, EEA_COUNTRIES, EU_COUNTRIES, FacematchMode, IDCredential, IDCredentialValue, JsonRpcRequest, MERCOSUR_COUNTRIES, NullifierType, NumericalIDCredential, ProofMode, ProofResult, ProofType, ProofTypeLength, Query, QueryResult, SANCTIONED_COUNTRIES, SCHENGEN_COUNTRIES, SanctionsCountries, SanctionsLists, Service, SupportedChain, getChainFromId, getIdFromChain } from '@zkpassport/utils';
|
|
1
|
+
export { D as DashboardConfig, d as OfflineQueryBuilderResult, O as OnSuccessVerdict, P as Policy, Q as QueryBuilder, a as QueryBuilderResult, e as QueryResultError, f as QueryResultErrors, h as RequestSuccess, R as RequestedNullifierType, S as SolidityProofVerificationData, i as SolidityServiceConfig, j as SolidityVerifierParameters, V as VERSION, k as VerificationConfig, l as VerificationResult, m as VerifierMode, Z as ZKPassport, c as createOfflineQuery, o as getRegistryClientOptions, n as normalizeCountry } from './index-CnSQu9Cx.js';
|
|
2
|
+
export { ASEAN_COUNTRIES, AllowedVerificationMethod, BoundData, CountryName, DEFAULT_ALLOWED_VERIFICATION_METHODS, DisclosableIDCredential, EEA_COUNTRIES, EU_COUNTRIES, FacematchMode, IDCredential, IDCredentialValue, JsonRpcRequest, MERCOSUR_COUNTRIES, NullifierType, NumericalIDCredential, ProofMode, ProofResult, ProofType, ProofTypeLength, Query, QueryResult, SANCTIONED_COUNTRIES, SCHENGEN_COUNTRIES, SanctionsCountries, SanctionsLists, Service, SupportedChain, VerificationMethod, VerificationTier, expandAllowedVerificationMethods, getChainFromId, getIdFromChain, getTierForVerificationMethod, isVerificationMethodAllowed } from '@zkpassport/utils';
|
|
3
|
+
import '@zkpassport/registry';
|
|
3
4
|
export { KeyPair } from '@obsidion/bridge';
|
|
4
5
|
import 'i18n-iso-countries';
|