@zkpassport/sdk 0.16.2 → 0.17.0-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.
- package/README.md +96 -107
- package/dist/cjs/index-PPMt5JWF.d.cts +444 -0
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -399
- package/dist/cjs/popup.cjs +3 -0
- package/dist/cjs/popup.cjs.map +1 -0
- package/dist/cjs/popup.d.cts +91 -0
- package/dist/cjs/query.cjs +2 -0
- package/dist/cjs/query.cjs.map +1 -0
- package/dist/cjs/query.d.cts +3 -0
- package/dist/esm/index-PPMt5JWF.d.ts +444 -0
- package/dist/esm/index.d.ts +2 -399
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/popup.d.ts +91 -0
- package/dist/esm/popup.js +3 -0
- package/dist/esm/popup.js.map +1 -0
- package/dist/esm/query.d.ts +3 -0
- package/dist/esm/query.js +2 -0
- package/dist/esm/query.js.map +1 -0
- package/package.json +31 -7
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ProofMode, NullifierType, ProofResult, QueryResult, Query } from '@zkpassport/utils';
|
|
2
|
+
import { O as OnSuccessVerdict, Q as QueryBuilder, a as QueryBuilderResult } from './index-PPMt5JWF.js';
|
|
3
|
+
import 'i18n-iso-countries';
|
|
4
|
+
|
|
5
|
+
declare const DEFAULT_POPUP_URL = "https://verify.zkpassport.id";
|
|
6
|
+
type PopupRequestConfig = {
|
|
7
|
+
name?: string;
|
|
8
|
+
logo?: string;
|
|
9
|
+
purpose?: string;
|
|
10
|
+
scope?: string;
|
|
11
|
+
mode?: ProofMode;
|
|
12
|
+
devMode?: boolean;
|
|
13
|
+
validity?: number;
|
|
14
|
+
uniqueIdentifierType?: NullifierType.NON_SALTED | NullifierType.SALTED;
|
|
15
|
+
oprfKeyId?: string;
|
|
16
|
+
};
|
|
17
|
+
type PopupConfigureMessage = {
|
|
18
|
+
zkpassport: true;
|
|
19
|
+
type: "configure";
|
|
20
|
+
request: PopupRequestConfig;
|
|
21
|
+
query: Query;
|
|
22
|
+
};
|
|
23
|
+
type PopupReadyMessage = {
|
|
24
|
+
zkpassport: true;
|
|
25
|
+
type: "ready";
|
|
26
|
+
};
|
|
27
|
+
type PopupEventMessage = {
|
|
28
|
+
zkpassport: true;
|
|
29
|
+
type: "request-received";
|
|
30
|
+
} | {
|
|
31
|
+
zkpassport: true;
|
|
32
|
+
type: "generating";
|
|
33
|
+
} | {
|
|
34
|
+
zkpassport: true;
|
|
35
|
+
type: "proof-generated";
|
|
36
|
+
index?: number;
|
|
37
|
+
total?: number;
|
|
38
|
+
name?: string;
|
|
39
|
+
} | {
|
|
40
|
+
zkpassport: true;
|
|
41
|
+
type: "success";
|
|
42
|
+
proofs: ProofResult[];
|
|
43
|
+
result: QueryResult;
|
|
44
|
+
} | {
|
|
45
|
+
zkpassport: true;
|
|
46
|
+
type: "rejected";
|
|
47
|
+
} | {
|
|
48
|
+
zkpassport: true;
|
|
49
|
+
type: "error";
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
type PopupMessage = PopupConfigureMessage | PopupReadyMessage | PopupEventMessage;
|
|
53
|
+
declare function isPopupMessage(data: any): data is PopupMessage;
|
|
54
|
+
|
|
55
|
+
type PopupSuccess = Extract<PopupEventMessage, {
|
|
56
|
+
type: "success";
|
|
57
|
+
}>;
|
|
58
|
+
type PopupCallbacks = {
|
|
59
|
+
onRequestReceived?: () => void;
|
|
60
|
+
onGeneratingProof?: () => void;
|
|
61
|
+
onProofGenerated?: (progress: {
|
|
62
|
+
index?: number;
|
|
63
|
+
total?: number;
|
|
64
|
+
name?: string;
|
|
65
|
+
}) => void;
|
|
66
|
+
onSuccess?: (response: Omit<PopupSuccess, "zkpassport" | "type">) => OnSuccessVerdict;
|
|
67
|
+
onReject?: () => void;
|
|
68
|
+
onError?: (message: string) => void;
|
|
69
|
+
onClose?: () => void;
|
|
70
|
+
};
|
|
71
|
+
type OpenVerificationPopupOptions = {
|
|
72
|
+
popupUrl?: string;
|
|
73
|
+
request: PopupRequestConfig;
|
|
74
|
+
query: Query;
|
|
75
|
+
callbacks?: PopupCallbacks;
|
|
76
|
+
};
|
|
77
|
+
type VerificationPopupHandle = {
|
|
78
|
+
close: () => void;
|
|
79
|
+
popup: Window;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Open the hosted verification popup. MUST be called from a user gesture
|
|
83
|
+
* (e.g. a click handler) or the browser will block the popup.
|
|
84
|
+
*
|
|
85
|
+
* If popup is blocked, will attempt to open in a new window.
|
|
86
|
+
*/
|
|
87
|
+
declare function openVerificationPopup(options: OpenVerificationPopupOptions): VerificationPopupHandle | null;
|
|
88
|
+
|
|
89
|
+
declare function hydrateQueryBuilder(builder: QueryBuilder, query: Query): QueryBuilderResult;
|
|
90
|
+
|
|
91
|
+
export { DEFAULT_POPUP_URL, type OpenVerificationPopupOptions, type PopupCallbacks, type PopupConfigureMessage, type PopupEventMessage, type PopupMessage, type PopupReadyMessage, type PopupRequestConfig, type PopupSuccess, type VerificationPopupHandle, hydrateQueryBuilder, isPopupMessage, openVerificationPopup };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var y="https://verify.zkpassport.id";function d(e){return !!e&&e.zkpassport===true&&typeof e.type=="string"}var f=460,g=780,v=500;function h(e){if(typeof window>"u")return null;let p=e.popupUrl??y,i=new URL(p).origin,P=Math.max(0,(window.screenX??0)+(window.outerWidth-f)/2),m=Math.max(0,(window.screenY??0)+(window.outerHeight-g)/2),t=window.open(p,"zkpassport-verify",`popup,width=${f},height=${g},left=${Math.round(P)},top=${Math.round(m)}`)??window.open(p,"zkpassport-verify");if(!t)return null;let r=e.callbacks??{},n=false,s=null,a=()=>{window.removeEventListener("message",c),s&&(clearInterval(s),s=null);},c=u=>{if(u.origin!==i||u.source!==t)return;let o=u.data;if(d(o))switch(o.type){case "ready":try{t.postMessage({zkpassport:!0,type:"configure",request:e.request,query:e.query},i);}catch(l){console.error("[zkpassport] failed to send the request to the popup:",l),r.onError?.("Failed to send the request to the verification popup");try{t.close();}catch{}}break;case "request-received":r.onRequestReceived?.();break;case "generating":r.onGeneratingProof?.();break;case "proof-generated":r.onProofGenerated?.({index:o.index,total:o.total,name:o.name});break;case "success":{n=true;let{zkpassport:l,type:x,...k}=o;r.onSuccess?.(k);break}case "rejected":n=true,r.onReject?.();break;case "error":r.onError?.(o.message);break}};return window.addEventListener("message",c),s=setInterval(()=>{t.closed&&(a(),n||r.onClose?.());},v),{popup:t,close:()=>{a();try{t.close();}catch{}}}}function w(e,p){return e.raw(p).done()}
|
|
2
|
+
export{y as DEFAULT_POPUP_URL,w as hydrateQueryBuilder,d as isPopupMessage,h as openVerificationPopup};//# sourceMappingURL=popup.js.map
|
|
3
|
+
//# sourceMappingURL=popup.js.map
|
|
@@ -0,0 +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","openVerificationPopup","options","popupUrl","popupOrigin","left","top","popup","callbacks","finished","closePoll","cleanup","onMessage","event","error","_z","_t","response","hydrateQueryBuilder","builder","query"],"mappings":"AAEO,IAAMA,CAAAA,CAAoB,+BA6C1B,SAASC,CAAAA,CAAeC,EAAiC,CAC9D,OAAO,CAAC,CAACA,GAAQA,CAAAA,CAAK,UAAA,GAAe,IAAA,EAAQ,OAAOA,EAAK,IAAA,EAAS,QACpE,CCfA,IAAMC,EAAc,GAAA,CACdC,CAAAA,CAAe,GAAA,CACfC,CAAAA,CAAsB,IAQrB,SAASC,CAAAA,CACdC,CAAAA,CACgC,CAChC,GAAI,OAAO,MAAA,CAAW,GAAA,CAAa,OAAO,KAC1C,IAAMC,CAAAA,CAAWD,CAAAA,CAAQ,QAAA,EAAYP,CA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AA,CAAO,IAAM,CACXI,CAAAA,EAAQ,CACR,GAAI,CACFJ,CAAAA,CAAM,KAAA,GACR,CAAA,KAAQ,CAER,CACF,CACF,CACF,CChJO,SAASW,CAAAA,CAAoBC,CAAAA,CAAuBC,CAAAA,CAAkC,CAC3F,OAAOD,CAAAA,CAAQ,GAAA,CAAIC,CAAK,CAAA,CAAE,MAC5B","file":"popup.js","sourcesContent":["import type { NullifierType, ProofMode, ProofResult, Query, QueryResult } from \"@zkpassport/utils\"\n\nexport const DEFAULT_POPUP_URL = \"https://verify.zkpassport.id\"\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\nexport type PopupConfigureMessage = {\n zkpassport: true\n type: \"configure\"\n request: PopupRequestConfig\n query: Query\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 }\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 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 request: PopupRequestConfig\n query: Query\n callbacks?: PopupCallbacks\n}\n\nexport type VerificationPopupHandle = {\n close: () => void\n popup: Window\n}\n\nconst POPUP_WIDTH = 460\nconst POPUP_HEIGHT = 780\nconst CLOSE_POLL_INTERVAL = 500\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 // 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 const popup =\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 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 },\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 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"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {registerLocale,getAlpha3Code}from'i18n-iso-countries';import C from'i18n-iso-countries/langs/en.json';registerLocale(C);function s(n){if(n==="Zero Knowledge Republic")return "ZKR";let r;return r=getAlpha3Code(n,"en")||n||"ZKR",r}function l(n,r,o,a,i){i[a][r]={...i[a][r],[n]:o};}function m(n,r,o,a){a[o][n]={...a[o][n],range:r};}function d(n,r,o,a,i){i[a][r]={...i[a][r],[n]:o};}function D(){let n={query:{}},r="query",o=false,a=e=>{if(n[r].policy)throw new Error(`Cannot call .${e}() on a policy-driven query. The query for policy '${n[r].policy}' is immutable.`);o=true;},i={eq:(e,t)=>(a("eq"),(e==="issuing_country"||e==="nationality")&&(t=s(t)),d("eq",e,t,r,n),i),gte:(e,t)=>{if(a("gte"),l("gte",e,t,r,n),e==="age"&&(t<1||t>=100))throw new Error("Age must be between 1 and 99 (inclusive)");return i},gt:(e,t)=>(a("gt"),l("gt",e,t,r,n),i),lte:(e,t)=>(a("lte"),l("lte",e,t,r,n),i),lt:(e,t)=>(a("lt"),l("lt",e,t,r,n),i),range:(e,t,u)=>(a("range"),m(e,[t,u],r,n),i),in:(e,t)=>(a("in"),t=t.map(u=>s(u)),d("in",e,t,r,n),i),out:(e,t)=>(a("out"),t=t.map(u=>s(u)),d("out",e,t,r,n),i),disclose:e=>(a("disclose"),n[r][e]={...n[r][e],disclose:true},i),bind:(e,t)=>(n[r].bind={...n[r].bind,[e]:t},i),sanctions:(e="all",t="all",u={strict:false})=>(a("sanctions"),n[r].sanctions={...n[r].sanctions,countries:e,lists:t,strict:u.strict??false},i),facematch:(e="strict")=>(a("facematch"),n[r].facematch={mode:e},i),raw:e=>(a("raw"),n[r]=e,i),policy:e=>{if(typeof e!="string"||e.length===0)throw new Error(".policy() requires a non-empty string id.");if(n[r].policy)throw new Error(`Cannot call .policy() more than once on a request (already set to '${n[r].policy}').`);if(o)throw new Error("Cannot combine .policy() with builder methods like .gte()/.disclose()/etc.");return n[r].policy=e,i},done:(()=>({query:n[r]}))};return i}export{D as createOfflineQuery,d as generalCompare,s as normalizeCountry,l as numericalCompare,m as rangeCompare};//# sourceMappingURL=query.js.map
|
|
2
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/offline-query.ts"],"names":["registerLocale","i18en","normalizeCountry","country","normalizedCountry","getAlpha3Code","numericalCompare","fnName","key","value","requestId","requestIdToConfig","rangeCompare","generalCompare","createOfflineQuery","config","topic","hasConditions","assertNotPolicyLocked","method","builder","start","end","v","countries","lists","options","mode","query","id"],"mappings":"8GAkBAA,cAAAA,CAAeC,CAAK,CAAA,CAEb,SAASC,EAAiBC,CAAAA,CAAmC,CAClE,GAAIA,CAAAA,GAAY,yBAAA,CACd,OAAO,KAAA,CAET,IAAIC,CAAAA,CAEJ,OAAAA,CAAAA,CADeC,aAAAA,CAAcF,CAAAA,CAAwB,IAAI,GAC1BA,CAAAA,EAA0B,KAAA,CAClDC,CACT,CAEO,SAASE,CAAAA,CACdC,EACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACA,CACAA,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,CAAA,CAAI,CAClC,GAAGG,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,CAAA,CACnC,CAACD,CAAM,EAAGE,CACZ,EACF,CAEO,SAASG,CAAAA,CACdJ,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,EACA,CACAA,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,CAAA,CAAI,CAClC,GAAGG,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,CAAA,CACnC,KAAA,CAAOC,CACT,EACF,CAEO,SAASI,CAAAA,CACdN,CAAAA,CACAC,CAAAA,CACAC,EACAC,CAAAA,CACAC,CAAAA,CACA,CACAA,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,CAAA,CAAI,CAClC,GAAGG,CAAAA,CAAkBD,CAAS,CAAA,CAAEF,CAAG,EACnC,CAACD,CAAM,EAAGE,CACZ,EACF,CAGO,SAASK,CAAAA,EAA8C,CAC5D,IAAMC,CAAAA,CAAgC,CAAE,KAAA,CAAO,EAAG,CAAA,CAC5CC,CAAAA,CAAQ,OAAA,CACVC,CAAAA,CAAgB,KAAA,CAEdC,CAAAA,CAAyBC,GAAmB,CAChD,GAAIJ,CAAAA,CAAOC,CAAK,CAAA,CAAE,MAAA,CAChB,MAAM,IAAI,KAAA,CACR,C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AA,CAAOL,CAAAA,CAAOC,CAAK,CAAE,CAAA,CAAA,CAElC,CAAA,CACA,OAAOI,CACT","file":"query.js","sourcesContent":["import { Alpha3Code, getAlpha3Code, registerLocale } from \"i18n-iso-countries\"\nimport i18en from \"i18n-iso-countries/langs/en.json\"\nimport type {\n BoundData,\n CountryName,\n DisclosableIDCredential,\n FacematchMode,\n IDCredential,\n IDCredentialValue,\n NumericalIDCredential,\n Query,\n SanctionsCountries,\n SanctionsLists,\n SupportedChain,\n} from \"@zkpassport/utils\"\nimport type { OfflineQueryBuilderResult, QueryBuilder } from \"./types\"\n\n// Country-name normalization needs the English locale registered (idempotent)\nregisterLocale(i18en)\n\nexport function normalizeCountry(country: CountryName | Alpha3Code) {\n if (country === \"Zero Knowledge Republic\") {\n return \"ZKR\"\n }\n let normalizedCountry: Alpha3Code | \"ZKR\" | undefined = undefined\n const alpha3 = getAlpha3Code(country as CountryName, \"en\") as Alpha3Code | \"ZKR\" | undefined\n normalizedCountry = alpha3 || (country as Alpha3Code) || \"ZKR\"\n return normalizedCountry as Alpha3Code | \"ZKR\"\n}\n\nexport function numericalCompare(\n fnName: \"gte\" | \"gt\" | \"lte\" | \"lt\",\n key: NumericalIDCredential,\n value: number | Date,\n requestId: string,\n requestIdToConfig: Record<string, Query>,\n) {\n requestIdToConfig[requestId][key] = {\n ...requestIdToConfig[requestId][key],\n [fnName]: value,\n }\n}\n\nexport function rangeCompare(\n key: NumericalIDCredential,\n value: [number | Date, number | Date],\n requestId: string,\n requestIdToConfig: Record<string, Query>,\n) {\n requestIdToConfig[requestId][key] = {\n ...requestIdToConfig[requestId][key],\n range: value,\n }\n}\n\nexport function generalCompare(\n fnName: \"in\" | \"out\" | \"eq\",\n key: IDCredential,\n value: any, // eslint-disable-line\n requestId: string,\n requestIdToConfig: Record<string, Query>,\n) {\n requestIdToConfig[requestId][key] = {\n ...requestIdToConfig[requestId][key],\n [fnName]: value,\n }\n}\n\n// Same Query output as request()'s builder, with no bridge/network/class deps\nexport function createOfflineQuery(): QueryBuilder<\"offline\"> {\n const config: Record<string, Query> = { query: {} }\n const topic = \"query\"\n let hasConditions = false\n\n const assertNotPolicyLocked = (method: string) => {\n if (config[topic].policy) {\n throw new Error(\n `Cannot call .${method}() on a policy-driven query. The query for policy '${config[topic].policy}' is immutable.`,\n )\n }\n hasConditions = true\n }\n\n const builder: QueryBuilder<\"offline\"> = {\n eq: <T extends IDCredential>(key: T, value: IDCredentialValue<T>) => {\n assertNotPolicyLocked(\"eq\")\n if (key === \"issuing_country\" || key === \"nationality\") {\n value = normalizeCountry(value as CountryName) as IDCredentialValue<T>\n }\n generalCompare(\"eq\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n gte: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => {\n assertNotPolicyLocked(\"gte\")\n numericalCompare(\"gte\", key, value, topic, config)\n if (key === \"age\" && ((value as number) < 1 || (value as number) >= 100)) {\n throw new Error(\"Age must be between 1 and 99 (inclusive)\")\n }\n return builder as unknown as QueryBuilder\n },\n gt: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => {\n assertNotPolicyLocked(\"gt\")\n numericalCompare(\"gt\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n lte: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => {\n assertNotPolicyLocked(\"lte\")\n numericalCompare(\"lte\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n lt: <T extends NumericalIDCredential>(key: T, value: IDCredentialValue<T>) => {\n assertNotPolicyLocked(\"lt\")\n numericalCompare(\"lt\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n range: <T extends NumericalIDCredential>(\n key: T,\n start: IDCredentialValue<T>,\n end: IDCredentialValue<T>,\n ) => {\n assertNotPolicyLocked(\"range\")\n rangeCompare(key, [start, end], topic, config)\n return builder as unknown as QueryBuilder\n },\n in: <T extends \"nationality\" | \"issuing_country\">(key: T, value: IDCredentialValue<T>[]) => {\n assertNotPolicyLocked(\"in\")\n value = value.map((v) => normalizeCountry(v as CountryName)) as IDCredentialValue<T>[]\n generalCompare(\"in\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n out: <T extends \"nationality\" | \"issuing_country\">(key: T, value: IDCredentialValue<T>[]) => {\n assertNotPolicyLocked(\"out\")\n value = value.map((v) => normalizeCountry(v as CountryName)) as IDCredentialValue<T>[]\n generalCompare(\"out\", key, value, topic, config)\n return builder as unknown as QueryBuilder\n },\n disclose: (key: DisclosableIDCredential) => {\n assertNotPolicyLocked(\"disclose\")\n config[topic][key] = {\n ...config[topic][key],\n disclose: true,\n }\n return builder as unknown as QueryBuilder\n },\n bind: <T extends keyof BoundData>(\n key: T,\n value: T extends \"chain\"\n ? SupportedChain\n : T extends \"user_address\"\n ? `0x${string}`\n : string | undefined,\n ) => {\n // Runtime payload: composes with policies (it only adds committed data)\n config[topic].bind = {\n ...config[topic].bind,\n [key]: value,\n }\n return builder as unknown as QueryBuilder\n },\n sanctions: (\n countries: SanctionsCountries = \"all\",\n lists: SanctionsLists = \"all\",\n options: { strict?: boolean } = { strict: false },\n ) => {\n assertNotPolicyLocked(\"sanctions\")\n config[topic].sanctions = {\n ...config[topic].sanctions,\n countries,\n lists,\n strict: options.strict ?? false,\n }\n return builder as unknown as QueryBuilder\n },\n facematch: (mode: FacematchMode = \"strict\") => {\n assertNotPolicyLocked(\"facematch\")\n config[topic].facematch = { mode }\n return builder as unknown as QueryBuilder\n },\n raw: (query: Query) => {\n assertNotPolicyLocked(\"raw\")\n config[topic] = query\n return builder\n },\n policy: (id: string) => {\n if (typeof id !== \"string\" || id.length === 0) {\n throw new Error(\".policy() requires a non-empty string id.\")\n }\n if (config[topic].policy) {\n throw new Error(\n `Cannot call .policy() more than once on a request (already set to '${config[topic].policy}').`,\n )\n }\n if (hasConditions) {\n throw new Error(\n \"Cannot combine .policy() with builder methods like .gte()/.disclose()/etc.\",\n )\n }\n config[topic].policy = id\n return builder\n },\n done: (() => {\n return { query: config[topic] } satisfies OfflineQueryBuilderResult\n }) as QueryBuilder<\"offline\">[\"done\"],\n }\n return builder\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zkpassport/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0-beta.2",
|
|
4
4
|
"description": "Privacy-preserving identity verification using passports and ID cards",
|
|
5
5
|
"author": "ZKPassport",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,8 +14,34 @@
|
|
|
14
14
|
"types": "./dist/esm/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"import":
|
|
18
|
-
|
|
17
|
+
"import": {
|
|
18
|
+
"types": "./dist/esm/index.d.ts",
|
|
19
|
+
"default": "./dist/esm/index.js"
|
|
20
|
+
},
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/cjs/index.d.cts",
|
|
23
|
+
"default": "./dist/cjs/index.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./popup": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/esm/popup.d.ts",
|
|
29
|
+
"default": "./dist/esm/popup.js"
|
|
30
|
+
},
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/cjs/popup.d.cts",
|
|
33
|
+
"default": "./dist/cjs/popup.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./query": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/query.d.ts",
|
|
39
|
+
"default": "./dist/esm/query.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/cjs/query.d.cts",
|
|
43
|
+
"default": "./dist/cjs/query.cjs"
|
|
44
|
+
}
|
|
19
45
|
}
|
|
20
46
|
},
|
|
21
47
|
"scripts": {
|
|
@@ -45,9 +71,10 @@
|
|
|
45
71
|
"@noble/ciphers": "^1.2.1",
|
|
46
72
|
"@noble/hashes": "^2.0.1",
|
|
47
73
|
"@noble/secp256k1": "^2.2.3",
|
|
74
|
+
"@noir-lang/noir_js": "1.0.0-beta.22",
|
|
48
75
|
"@obsidion/bridge": "^0.11.2",
|
|
49
76
|
"@zkpassport/registry": "0.14.0",
|
|
50
|
-
"@zkpassport/utils": "0.
|
|
77
|
+
"@zkpassport/utils": "0.38.0-beta.2",
|
|
51
78
|
"buffer": "^6.0.3",
|
|
52
79
|
"i18n-iso-countries": "^7.12.0",
|
|
53
80
|
"pako": "^2.1.0",
|
|
@@ -59,8 +86,5 @@
|
|
|
59
86
|
"@types/pako": "^2.0.3",
|
|
60
87
|
"@types/ws": "^8.5.12"
|
|
61
88
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"typescript": "^5.0.0"
|
|
64
|
-
},
|
|
65
89
|
"packageManager": "bun@1.3.1"
|
|
66
90
|
}
|