@reclaimprotocol/attestor-core 5.0.1-beta.23 → 5.0.1-beta.24

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.
@@ -4510,3 +4510,4 @@ zP3pGJ9FCbMHmMLLyuBd+uCWvVcF2ogYAawufChS/PT61D9rqzPRS5I2uqa3tmIT
4510
4510
  \r
4511
4511
  `,f6.length)+4,B<4)throw new Error("Response body start not found")}else B=f6.length;let L=Tf(mV).exec(S);if(L&&L.length>1){let $=new Date(L[1]);Date.now()-$.getTime()>gV&&r.info({dateHeader:L[0],current:Date.now()},"date header is off")}let j=a.body instanceof Uint8Array?a.body:or(a.body||"");if(j.length>0&&!l6(j,u.body))throw new Error("request body mismatch");i||(S=S.slice(B).replace(/(\*){3,}/g,""));for(let{type:$,value:G,invert:fe}of a.responseMatches||[]){let de=!!fe;switch($){case"regex":let Ae=Tf(G).exec(S),Y=Ae!==null;if(Y===de)throw new Error(`Invalid receipt. Regex "${G}" ${fe?"matched":"didn't match"}`);if(!Y)continue;let te=Ae?.groups;for(let Ee in te||[]){if(Ee in s)throw new Error(`Duplicate parameter ${Ee}`);let re=te?.[Ee];typeof re=="string"&&(s[Ee]=re)}break;case"contains":if(S.includes(G)===de)throw new Error(`Invalid receipt. Response ${fe?"contains":"does not contain"} "${G}"`);break;default:throw new Error(`Invalid response match type ${$}`)}}function V(...$){let G=$.reduce((Ae,Y)=>Ae+Y.length,0),fe=new Uint8Array(G),de=0;for(let Ae of $)fe.set(Ae,de),de+=Ae.length;return fe}return{extractedParameters:s};function Z(){let $=t.filter(Ae=>Ae.sender==="client").map(Ae=>Ae.message),G=t.filter(Ae=>Ae.sender==="server").map(Ae=>Ae.message),fe=kr(we($)),de=kr(we(G));r.debug({request:fe,response:de,params:e})}}};function IS({version:t}){return t>=Mr.ATTESTOR_VERSION_2_0_1}function xV(t,e){let{host:r}=new URL(TV(t,e));if(!r)throw new Error("url is incorrect");return r}function h6(t){let e=t.hostname,r=t.port;return r&&+r!==uf?`${e}:${r}`:e}var $g=/{{([^{}]+)}}/sgi;function*yV(t,e,r,n){let s=t,i=0,o=-1;if(e.xPath){let d=s6(t,e.xPath,!!e.jsonPath);for(let{start:p,end:m}of d)s=t.slice(p,m),i=p,o=m-p,e.jsonPath?yield*a():e.regex?yield*u():yield*l()}else if(e.jsonPath)yield*a();else if(e.regex)yield*u();else throw new Error("Expected either xPath, jsonPath or regex for redaction");function*a(){let d=i6(s,e.jsonPath),p=i;for(let m of d){let y=m.start,x=m.end;s=t.slice(p+y,p+x),i=p+y,o=x-y,e.regex?yield*u():yield*l()}}function*u(){Vt.debug({element:kr(or(s)),body:kr(or(t))});let d=Tf(e.regex),p=s||t,m=d.exec(p);if(!m?.[0])throw new Error(`regexp ${e.regex} does not match found element '${kr(or(p))}'`);if(i+=m.index,o=d.lastIndex-m.index,s=m[0],e.hash&&(!m.groups||Object.keys(m.groups).length>1))throw new Error("Exactly one named capture group is needed per hashed redaction");if(!e.hash||!m.groups){yield*l();return}let y=m[0],x=Object.values(m.groups)[0],b=y.indexOf(x);o=b,s=y.slice(0,b),yield*l(null),i+=b,s=x,o=x.length;let w=f(i,o,e.hash),S=c6(w.fromIndex,w.toIndex,n);if(S.length)throw new Error("Hash redactions cannot be performed if the redacted string is split between 2 or more HTTP chunks");yield{reveal:w,redactions:S},i+=x.length,s=y.slice(b+x.length),o=s.length,yield*l(null)}function*l(d=e.hash,p=n){if(i<0||!o)return;let m=f(i,o,d||void 0);yield{reveal:m,redactions:c6(m.fromIndex,m.toIndex,p)}}function f(d,p,m){let y=a6(d,r,n),x=a6(d+p,r,n);return{fromIndex:y,toIndex:x,hash:m}}}function d6(t,e,r){let n=JSON.parse(JSON.stringify(t)),s={},i=[],o=d(n.url,r);if(o&&(n.url=o.newParam,s={...o.extractedValues},o.hiddenParts.length)){let m=`https://${h6(new URL(n.url))}`.length-t.method.length-1;for(let y of o.hiddenParts)i.push({index:y.index-m,length:y.length})}let a,u=[];if(n.body){let p=typeof n.body=="string"?n.body:ks(n.body);a=d(p,r),a&&(n.body=a.newParam,s={...s,...a.extractedValues},u=a.hiddenParts)}let l=d(n.geoLocation);l&&(n.geoLocation=l.newParam,s={...s,...l.extractedValues});let f=d(n.proxySessionId);if(f&&(n.proxySessionId=f.newParam,s={...s,...f.extractedValues}),n.responseRedactions)for(let p of n.responseRedactions){if(p.regex){let m=d(p.regex);p.regex=m?.newParam}if(p.xPath){let m=d(p.xPath);p.xPath=m?.newParam}if(p.jsonPath){let m=d(p.jsonPath);p.jsonPath=m?.newParam}}if(n.responseMatches){for(let p of n.responseMatches)if(p.value!==""){let m=d(p.value);p.value=m?.newParam,s={...s,...m?.extractedValues}}}return{newParams:n,extractedValues:s,hiddenBodyParts:u,hiddenURLParts:i};function d(p,m){if(!p)return null;let y={},x=[],b=0;return p=p.replace($g,(w,S,O)=>{if(n.paramValues&&S in n.paramValues)return y[S]=n.paramValues[S],b+=n.paramValues[S].length-w.length,n.paramValues[S];if(e){if(e?.paramValues&&S in e?.paramValues)return x.push({index:O+b,length:e.paramValues[S].length}),b+=e.paramValues[S].length-w.length,e.paramValues[S];throw new Error(`parameter's "${S}" value not found in paramValues and secret parameter's paramValues`)}else{if(m)return w;throw new Error(`parameter's "${S}" value not found in paramValues`)}}),{newParam:p,extractedValues:y,hiddenParts:x}}}function bV(t,e){if(t?.geoLocation){let r=new Set,n=t.geoLocation,s=null;for(;s=$g.exec(n);)r.add(s[1]);for(let o of r)if(t.paramValues&&o in t.paramValues)n=n?.replaceAll(`{{${o}}}`,t.paramValues[o].toString());else if(e?.paramValues&&o in e.paramValues)n=n?.replaceAll(`{{${o}}}`,e.paramValues[o].toString());else throw new Error(`parameter "${o}" value not found in templateParams`);if(!/^[A-Za-z]{2}$/sgiu.test(n))throw new Error(`Geolocation ${n} is invalid`);return n}}function wV(t,e){if(t?.proxySessionId){let r=new Set,n=t.proxySessionId,s=null;for(;s=$g.exec(n);)r.add(s[1]);for(let i of r)if(t.paramValues&&i in t.paramValues)n=n?.replaceAll(`{{${i}}}`,t.paramValues[i].toString());else if(e?.paramValues&&i in e.paramValues)n=n?.replaceAll(`{{${i}}}`,e.paramValues[i].toString());else throw new Error(`parameter "${i}" value not found in templateParams`);if(!BS(n))throw new Error(`proxySessionId ${n} is invalid`);return n}}function TV(t,e){let r=t?.url,n=new Set,s=null;for(;s=$g.exec(r);)n.add(s[1]);for(let i of n)if(t.paramValues&&i in t.paramValues)r=r?.replaceAll(`{{${i}}}`,t.paramValues[i].toString());else if(e?.paramValues&&i in e.paramValues)r=r?.replaceAll(`{{${i}}}`,e.paramValues[i].toString());else throw new Error(`parameter "${i}" value not found in templateParams`);return r}var DS=EV;var NS={http:DS};async function RS(t,{maxRetries:e=3,shouldRetry:r,logger:n}){let s=0;for(;s<e;)try{return await t(s)}catch(i){if(s+=1,s>=e||!r(i))throw i;n.info({err:i,retries:s},"retrying failed operation")}throw new Error("retries exhausted")}function Cf({logger:t,maxRetries:e=3,...r}){let n=t||("logger"in r.client?r.client.logger:Vt);return RS(s=>BV({...r,logger:s?n.child({attempt:s}):n}),{maxRetries:e,logger:n,shouldRetry:CV})}function CV(t){return t instanceof TypeError?!1:t?.message?.includes("stream ended before")?!0:t instanceof dt&&t.code!=="ERROR_INVALID_CLAIM"&&t.code!=="ERROR_BAD_REQUEST"&&t.code!=="ERROR_AUTHENTICATION_FAILED"&&t.code!=="ERROR_TOPRF_OUT_OF_BOUNDS"}async function BV({name:t,params:e,secretParams:r,context:n,onStep:s,ownerPrivateKey:i,client:o,logger:a=Vt,timestampS:u,updateProviderParams:l,updateParametersFromOprfData:f=!0,...d}){let p=NS[t],m=tf(e,p.hostPort,r),y=tf(e,p.geoLocation,r),x=tf(e,p.proxySessionId,r),b=tf(e,p.additionalClientOptions),w={...AM(),fetchCertificateBytes:tr,...b},{zkEngine:S="snarkjs"}=d,O=tf(e,p.writeRedactionMode),[P,B]=m.split(":"),L=sg(),j,V=!1,Z=new Map;s?.({name:"connecting"});let $,G={host:P,port:B?+B:uf,geoLocation:y,proxySessionId:x,id:$m()};a=a.child({tunnelId:G.id});let fe="authRequest"in o?typeof o.authRequest=="function"?await o.authRequest():o.authRequest:void 0,de=await gM({tlsOpts:w,connect:De=>{let Ve=!1;return"metadata"in o?j=o:j=A0(o.url,()=>(Ve=!0,{authRequest:fe,initMessages:De,logger:a})),Ve||j.waitForInit().then(()=>j.sendMessage(...De)).catch(he=>{a.error({err:he},"error in sending init msgs")}),j},logger:a,request:G,onMessage(De){a.debug({bytes:De.length},"recv data from server"),L.onChunk(De),L.res.complete&&(a?.debug("got complete HTTP response from server"),setTimeout(()=>{$?.()},100))},onClose(De){a?.[De?"error":"debug"]({err:De},"tls session ended"),$?.(De);try{L.streamEnded()}catch{}}}),{version:Ae,cipherSuite:Y}=de.tls.getMetadata();Ae==="TLS1_2"&&O!=="zk"&&(O="zk",a.info("TLS1.2 detected, defaulting to zk redaction mode"));let{redactions:te,data:ae}=p.createRequest(r,e,a),Ee=typeof ae=="string"?Ir(ae):ae;a.debug({redactions:te.length},"generated request");let re=new Promise((De,Ve)=>{$=he=>he?Ve(he):De()});s?.({name:"sending-request-data"});try{O==="zk"?await It():await Os(),a.info("wrote request to server")}catch(De){a.error({err:De},"session errored during write, waiting for stream end")}if(s?.({name:"waiting-for-response"}),await re,await de.close(),a.info("session closed, processing response"),l){let{params:De,secretParams:Ve}=await l(de.transcript,Ae??"TLS1_2");e={...e,...De},r={...r,...Ve}}let Ne=p0[j.metadata.signatureType],Se,ce,[$e]=be("server",1);$e?.message.type==="ciphertext"&&(Se=$e.message.fixedIv);let[ht]=be("client",1);ht?.message.type==="ciphertext"&&(ce=ht.message.fixedIv);let qe=await dr(),We=In.create({request:G,data:{provider:t,parameters:Uo(e),context:Uo(n),timestampS:u??u0(),owner:ue()},transcript:qe,zkEngine:yw(S),fixedServerIV:Se,fixedClientIV:ce});s?.({name:"waiting-for-verification"});let Kt=In.encode(We).finish(),fr=await Ne.sign(Kt,i);We.signatures={requestSignature:fr};let er=await j.rpc("claimTunnel",We);return a.info({success:!!er.claim},"recv claim response"),er;async function tr(De){if(!j)throw new Error("attestor client not initialized");return(await j.rpc("fetchCertificateBytes",{url:De})).bytes}async function Os(){let De=0;for(let Ze of te){let pt=Ee.slice(De,Ze.fromIndex);pt.length&&await pe(pt,!0);let ne=Ee.slice(Ze.fromIndex,Ze.toIndex);await pe(ne,!1),De=Ze.toIndex}let Ve=te?.[te.length-1]?.toIndex||0,he=Ee.slice(Ve);he.length&&await pe(he,!0)}async function It(){let De=de.transcript.length;await de.tls.write(Ee),De=de.transcript.length-De,Wn({type:"zk",redactedPlaintext:yR(Ee,te)},De)}async function pe(De,Ve){Ve!==V&&await de.tls.updateTrafficKeys();let he=de.transcript.length;await de.write(De),he=de.transcript.length-he,Wn(Ve?{type:"complete"}:void 0,he),V=Ve}function Wn(De,Ve=1){let he=be("client",Ve);if(he.length)for(let Ze of he)J(Ze.message,De)}function be(De,Ve){let he=[];for(let Ze=de.transcript.length-1;Ze>=0;Ze--){let pt=de.transcript[Ze];if(pt.sender===De&&(he.push(pt),he.length===Ve))break}return he}async function dr(){await Br();let De=Date.now();return await lM(de.transcript,Z,{logger:a,cipherSuite:Y,onZkProgress(he,Ze){let qt=(Date.now()-De)/he*(Ze-he);s?.({name:"generating-zk-proofs",proofsDone:he,proofsTotal:Ze,approxTimeLeftS:Math.round(qt/1e3)})},...d})}async function Br(){let De=de.transcript,Ve="all",he=[],Ze=[];for(let ne of De){if(ne.message.type!=="ciphertext"||!Zh(ne.message,Ae))continue;let qt=Ae==="TLS1_3"?ne.message.plaintext.slice(0,-1):ne.message.plaintext;he.push({message:qt,sender:ne.sender}),ne.sender==="server"&&Ze.push({plaintext:qt,message:ne.message})}p.getResponseRedactions&&(Ve=await xR(Ze,ne=>p.getResponseRedactions({response:ne,params:e,logger:a,ctx:mw}),Mt));let pt=he.filter(ne=>ne.sender==="client");if(Ve==="all"){for(let{message:ne,sender:qt}of De)qt==="server"&&J(ne,{type:"complete"});pt.push(...he.filter(ne=>ne.sender==="server"))}else for(let{block:ne,redactedPlaintext:qt,overshotToprfFromPrevBlock:Qr,toprfs:pn,oprfRawMarkers:hr}of Ve)if(J(ne.message,{type:"zk",redactedPlaintext:qt,toprfs:pn,oprfRawMarkers:hr,overshotToprfFromPrevBlock:Qr}),pt.push({sender:"server",message:qt}),f&&pn){let Q=Uo(e);for(let k of pn){let U=ks(k.plaintext),me=rp(k.nullifier,k.dataLocation.length);Q=Q.replaceAll(U,me)}e=JSON.parse(Q)}await p.assertValidProviderReceipt({receipt:pt,params:{...e,secretParams:r},logger:a,ctx:mw});for(let ne of De)if(ne.message.type==="ciphertext"){if(Zh(ne.message,Ae))break;J(ne.message,{type:"complete"})}}async function Mt(De){a.info({length:De.length},"generating OPRF...");let Ve=d.oprfOperators?.chacha20||hg("chacha20",S,a),he=await Ve.generateOPRFRequestData(De,lp,a),Ze=await j.rpc("toprf",{maskedData:he.maskedData,engine:yw(S)});return{nullifier:await Ve.finaliseOPRF(j.initResponse.toprfPublicKey,he,[Ze]),responses:[Ze],mask:he.mask,dataLocation:void 0,plaintext:De}}function J(De,Ve){if(Ve){Z.set(De,Ve);return}Z.delete(De)}function ue(){let{getAddress:De,getPublicKey:Ve}=Ne,he=Ve(i);return De(he)}}var IV=z(new Uint8Array(32));async function MS({onStep:t,createClaimOnAttestor:e=Cf,chainId:r=zm,payer:n,...s}){let{logger:i=Vt,ownerPrivateKey:o,name:a,params:u,context:l}=s,{contract:f,wallet:d,provider:p}=I2(Wm[r],o);i.info({owner:d.address,contract:await f.getAddress()},"creating claim");let m=await w();i.info({index:m.taskIndex,operators:m.task.operators.length},"task created, collecting claim signatures..."),t?.({type:"taskCreated",data:m});let y=[],x=+m.task.createdAt.toString();for(let O of m.task.operators){let P=await e({...s,client:{url:O.url},timestampS:x,onStep:j=>t?.({type:"attestorStep",data:{operatorAddress:O.addr,step:j}}),logger:i.child({operator:O.addr})});if(!P.signatures?.claimSignature)throw new Error("INTERNAL: Claim signature not generated");let L=DV(P.request?.data,P.claim);if(L)throw new dt("ERROR_INVALID_CLAIM",`Claim request does not match the claim res data: ${L}`,{diff:L,request:P.request?.data?.[L],claim:P.claim?.[L]});y.push(P),i.info({operator:O.addr},"signature generated"),t?.({type:"attestorDone",data:{task:m,responsesDone:y}})}let b=await S();return i.info({tx:b.txHash,task:m.taskIndex},"claim submitted & validated"),{...b,claimData:y[0].claim};async function w(){let O={provider:a,claimUserId:IV,claimHash:dp({provider:a,parameters:Uo(u),context:l?Uo(l):""}),owner:d.address,requestedAt:u0()};if(!n){let j=new Pi(o,p),{task:V}=await UN({request:O,payer:j,owner:j,chainId:r});return V}let P=await D2(O,d,r),B=A0(n.attestor);await B.waitForInit();let L=await B.rpc("createClaimOnChain",{chainId:+r,jsonCreateClaimRequest:JSON.stringify(O),requestSignature:P});return JSON.parse(L.jsonTask)}async function S(){let O={task:m.task,signatures:y.map(j=>z(j.signatures?.claimSignature))};if(!n){let V=await(await f.taskCompleted(O,m.taskIndex)).wait();return{object:(V?.logs??[]).filter(fe=>fe instanceof Es)[0]?.args,txHash:V.hash}}let P=A0(n.attestor);await P.waitForInit();let B=await P.rpc("completeClaimOnChain",{chainId:+r,taskIndex:Number(m.taskIndex),completedTaskJson:JSON.stringify(O)});return{object:JSON.parse(B.taskCompletedObjectJson),txHash:B.txHash}}}function DV(t,e){if(t.provider!==e.provider)return"provider";if(t.context!==e.context)return"context";if(t.parameters!==e.parameters)return"parameters";if(t.timestampS!==e.timestampS)return"timestampS"}var NV=["TLS_CHACHA20_POLY1305_SHA256","TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384","TLS_AES_128_GCM_SHA256"];async function SS(){let t="";for(let e of NV){let r=Date.now(),n=e.includes("CHACHA20")?"CHACHA20-POLY1305":e.includes("AES_256_GCM")?"AES-256-GCM":"AES-128-GCM",s=n==="AES-128-GCM"?16:32,i=Buffer.alloc(s,0),{ivLength:o}=yt[e],a=Buffer.alloc(o,0),u=await Re.importKey(n,i),l=[{plaintext:`My cool API secret is "my name jeff". Please don't reveal it`}],f=await dg({logger:Vt,cipherSuite:e});for(let{plaintext:d}of l){let p=or(d),{ciphertext:m,iv:y}=await uh(p,{key:u,iv:a,recordNumber:0,recordHeaderOpts:{type:"WRAPPED_RECORD"},cipherSuite:e,version:e.includes("ECDHE_")?"TLS1_2":"TLS1_3"}),x={type:"ciphertext",encKey:u,iv:y,recordNumber:0,plaintext:p,ciphertext:m,fixedIv:new Uint8Array(0),data:m};await f.addPacketToProve(x,{type:"zk",redactedPlaintext:p},()=>{},()=>{throw new Error("should not be called in benchmark")}),await f.generateProofs()}t=t+`Benchmark ${n} ok. Took ${Date.now()-r} ms
4512
4512
  `}return Vt.info(t),t}var eE=class{#e=[];addListener(e){return this.#e.push(e),()=>{this.#e=this.#e.filter(r=>r!==e)}}dispatch(e){for(let r of this.#e)r(e)}};var p6=new eE;async function vS(){if(window.crossOriginIsolated)if(performance.measureUserAgentSpecificMemory)try{let t=performance.measureUserAgentSpecificMemory();return{available:!0,content:`${Math.round(t.bytes/1024/1024)}mb`}}catch(t){if(t instanceof DOMException&&t.name==="SecurityError")return{available:!1,content:`N/A (${t.message})`};throw t}else return{available:!1,content:"N/A (performance.measureUserAgentSpecificMemory() is not available)"};else return{available:!1,content:"N/A (page not cross-origin-isolated)"}}function A6(){return Math.random().toString(36).slice(2)}function b0(){if(typeof ATTESTOR_BASE_URL!="string")throw new Error("ATTESTOR_BASE_URL is not set");let t=new URL(ATTESTOR_BASE_URL),{host:e,protocol:r}=t;return`${r==="https:"?"wss:":"ws:"}//${e}${tM}`}function m6(t){let e=A6(),r=g6(t.type,e);return oc({id:e,type:t.type,request:t.request}),r}function g6(t,e,r=6e4){let n=`${t}Done`;return new Promise((s,i)=>{let o=setTimeout(()=>{i(new dt("ERROR_INTERNAL",`Timeout waiting for response: ${t}`,{requestId:e})),a()},r),a=p6.addListener(u=>{if(u.id===e){if(u.type==="error")i(new Error(u.data.message));else if(u.type===n)s(u.response);else return;clearTimeout(o),a()}})})}function oc(t){let e=JSON.stringify(t,hM);if(!RPC_CHANNEL_NAME)throw new Error("global RPC_CHANNEL_NAME is not set");let r=globalThis[RPC_CHANNEL_NAME];if(!r)throw new Error(`RPC channel ${RPC_CHANNEL_NAME} not set on globalThis`);r.postMessage(e)}var E6=["aes-256-ctr","aes-128-ctr","chacha20"];function OS(t,e="snarkjs"){return{async generateWitness(r){return(await fp(t,e,Vt)).generateWitness(r)},groth16Prove(r){return kS({fn:"groth16Prove",args:[r]})},groth16Verify(r,n){return kS({fn:"groth16Verify",args:[r,n]})}}}function kS(t){return m6({type:"executeZkFunctionV3",request:t})}function PS(t,e="snarkjs"){return{async generateWitness(r){return(await fp(t,e,Vt)).generateWitness(r)},groth16Prove(r){return Bf({fn:"groth16Prove",args:[r]})},groth16Verify(r,n){return Bf({fn:"groth16Verify",args:[r,n]})},generateThresholdKeys(r,n){return Bf({fn:"generateThresholdKeys",args:[r,n]})},generateOPRFRequestData(r,n){return Bf({fn:"generateOPRFRequestData",args:[r,n]})},finaliseOPRF(r,n,s){return Bf({fn:"finaliseOPRF",args:[r,n,s]})},evaluateOPRF(r,n){return Bf({fn:"evaluateOPRF",args:[r,n]})}}}function Bf(t){return m6({type:"executeOprfFunctionV3",request:t})}async function US({createClaimOnAttestor:t=Cf,onStep:e,client:r,...n}){let s=A0(r.url),i=Math.floor(Date.now()/1e3);await s.waitForInit(),e?.({type:"taskRequested",timestamp:i});let{taskId:o,requiredAttestors:a,hosts:u}=await s.rpc("createTaskOnMechain",{timestamp:i});e?.({type:"taskCreated",taskId:o});let l=[];for(let f=0;f<a;f++){e?.({type:"attestorRequested",host:u[f]});let d=new lf({url:u[f]}),p=await t({...n,client:d});l.push(p)}return{taskId:o,responses:l}}async function QS(t){let e="";try{let n=typeof t=="string"?JSON.parse(t,pM):t;e=n.id||"";let s=await RV(n);if(!s)return;r(s)}catch(n){console.error("Error in RPC",{id:e,error:n}),r({type:"error",data:{message:n.message,stack:n.stack}})}function r(n){let s={...n,id:e,isResponse:!0};return oc(s)}}async function RV(t){let{id:e,type:r}=t;if(!(!e||!r)&&(p6.dispatch(t),!("isResponse"in t&&t.isResponse))){if(!e){Vt.warn({req:t},"Window RPC request missing ID");return}switch(Vt.info({req:t},"processing RPC request"),t.type){case"createClaim":let n=await Cf({...t.request,context:t.request.context?JSON.parse(t.request.context):void 0,zkOperators:x6(t.request.zkOperatorMode,t.request.zkEngine),oprfOperators:y6(t.request.zkOperatorMode,t.request.zkEngine),client:{url:b0(),authRequest:t.request.authRequest},logger:Vt,onStep(u){oc({type:"createClaimStep",step:{name:"attestor-progress",step:u},id:t.id})},updateProviderParams:t.request.updateProviderParams?MV:void 0});return{type:"createClaimDone",response:FS(n)};case"createClaimOnAvs":return{type:"createClaimOnAvsDone",response:await MS({...t.request,payer:t.request.payer==="attestor"?{attestor:b0()}:void 0,context:t.request.context?JSON.parse(t.request.context):void 0,zkOperators:x6(t.request.zkOperatorMode,t.request.zkEngine),oprfOperators:y6(t.request.zkOperatorMode,t.request.zkEngine),logger:Vt,onStep(u){oc({type:"createClaimOnAvsStep",step:u,id:t.id})}})};case"createClaimOnMechain":let o=await US({...t.request,context:t.request.context?JSON.parse(t.request.context):void 0,zkOperators:x6(t.request.zkOperatorMode,t.request.zkEngine),oprfOperators:y6(t.request.zkOperatorMode,t.request.zkEngine),client:{url:b0()},logger:Vt,onStep(u){oc({type:"createClaimOnMechainStep",step:u,id:t.id})}}),a=[];for(let u=0;u<o.responses.length;u++)a[u]=FS(o.responses[u]);return{type:"createClaimOnMechainDone",response:{taskId:o.taskId,data:a}};case"extractHtmlElement":return{type:"extractHtmlElementDone",response:wS(t.request.html,t.request.xpathExpression,t.request.contentsOnly)};case"extractJSONValueIndex":return{type:"extractJSONValueIndexDone",response:TS(t.request.json,t.request.jsonPath)};case"getCurrentMemoryUsage":return{type:"getCurrentMemoryUsageDone",response:await vS()};case"setLogLevel":return tp(!0,t.request.logLevel,t.request.sendLogsToApp?(u,l)=>oc({type:"log",level:u,message:l,id:t.id}):void 0),{type:"setLogLevelDone",response:void 0};case"benchmarkZK":return{type:"benchmarkZKDone",response:await SS()};case"ping":return{type:"pingDone",response:{pong:new Date().toJSON()}};default:break}}}function x6(t="default",e="snarkjs"){if(t==="default")return;let r={};for(let n of E6)r[n]=OS(n,e);return r}function y6(t="default",e="snarkjs"){if(t==="default")return;let r={};for(let n of E6)r[n]=PS(n,e);return r}async function MV(t,e){let{req:r,res:n}=CS(t,e),s=A6(),i=g6("updateProviderParams",s);return oc({type:"updateProviderParams",id:s,request:{request:{...r,body:r.body?ks(r.body):void 0},response:{...n,body:ks(n.body)}}}),i}function FS(t){if(!t.claim)throw dt.fromProto(t.error);return{identifier:dp(t.claim),claimData:t.claim,witnesses:[{id:t.signatures.attestorAddress,url:b0()}],signatures:[z(t.signatures.claimSignature).toLowerCase()]}}tp(!0);rE(iI);function a2e(t,e="attestor-core"){if(t)globalThis.ATTESTOR_BASE_URL=t;else if(typeof window<"u"&&window.location)globalThis.ATTESTOR_BASE_URL=window.location.toString();else throw new Error("No base URL provided and window.location unavailable");if(e)globalThis.RPC_CHANNEL_NAME=e;else if(!globalThis.RPC_CHANNEL_NAME)throw new Error("No channel name provided and globalThis.RPC_CHANNEL_NAME unavailable");typeof window<"u"&&window.addEventListener("message",r=>QS(r.data),!1),Vt.info({defaultUrl:b0()},"window RPC setup")}export{Kme as API_SERVER_PORT,Jme as ATTESTOR_ADDRESS_PATHNAME,lf as AttestorClient,dt as AttestorError,hM as B64_JSON_REPLACER,pM as B64_JSON_REVIVER,sM as BGP_WS_URL,yQ as BROWSER_RPC_PATHNAME,nge as CERT_ALLOWED_MIMETYPES,qme as CONNECTION_TIMEOUT_MS,rM as CURRENT_ATTESTOR_VERSION,nM as DEFAULT_AUTH_EXPIRY_S,uf as DEFAULT_HTTPS_PORT,up as DEFAULT_METADATA,Aw as DEFAULT_REMOTE_FILE_FETCH_BASE_URL,fg as DEFAULT_RPC_TIMEOUT_MS,$R as DEFAULT_ZK_CONCURRENCY,Zme as DNS_SERVERS,rge as MAX_CERT_SIZE_BYTES,Xme as MAX_CLAIM_TIMESTAMP_DIFF_S,ege as MAX_NO_DATA_INTERVAL_MS,tge as MAX_PAYLOAD_SIZE,$me as PING_INTERVAL_MS,mw as PROVIDER_CTX,eM as RECLAIM_USER_AGENT,$2 as REDACTION_CHAR,Cr as REDACTION_CHAR_CODE,p0 as SIGNATURES,dM as SelectedServiceSignature,SQ as SelectedServiceSignatureType,lp as TOPRF_DOMAIN_SEPARATOR,tM as WS_PATHNAME,zge as assertValidAuthRequest,Nge as assertValidClaimSignatures,rp as binaryHashToStr,Uo as canonicalStringify,Jge as createAuthRequest,rEe as createBgpListener,Cf as createClaimOnAttestor,US as createClaimOnMechain,RQ as createSignDataForClaim,sme as decryptDirect,sR as ethersStructToPlainObject,vF as extractApplicationDataFromTranscript,aR as extractArrayBufferFromWsData,nme as extractHandshakeFromTranscript,qh as findIndexInUint8Array,l0 as generateRpcMessageId,rme as generateSessionId,$m as generateTunnelId,A0 as getAttestorClientFromPool,xR as getBlocksToReveal,AM as getDefaultTlsOptions,yw as getEngineProto,bge as getEngineString,ig as getHttpRequestDataFromTranscript,dp as getIdentifierFromClaimInfo,tf as getProviderValue,j2 as getPureCiphertext,W2 as getRecordIV,cR as getRpcRequest,eg as getRpcRequestType,oR as getRpcResponseType,SF as getRpcTypeFromKey,tme as getTranscriptString,ef as getZkAlgorithmForCipherSuite,Rge as hashProviderParams,Zh as isApplicationData,ew as isFullyRedacted,ER as isRedactionCongruent,z2 as isTls13Suite,Vt as logger,hg as makeDefaultOPRFOperator,fp as makeDefaultZkOperator,sg as makeHttpResponseParser,tp as makeLogger,iR as makeRpcEvent,dg as makeZkProofGenerator,tg as packRpcMessages,lM as preparePacketsForReveal,nR as proto,NS as providers,$h as redact,yR as redactSlices,a2e as setupWindowRpc,or as strToUint8Array,N5 as tls,fc as uint8ArrayToBinaryStr,ks as uint8ArrayToStr,u0 as unixTimestampSeconds,yge as verifyZkPacket};
4513
+ //# sourceMappingURL=attestor-browser.min.mjs.map