@catena/cli 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -16
- package/THIRD-PARTY-NOTICES +156 -0
- package/dist/dist-w03V0QPF.mjs +3 -0
- package/dist/hmac-CXnNqvhW.mjs +1 -0
- package/dist/index.mjs +136 -75
- package/dist/mpp-Dr8gzsL-.mjs +14 -0
- package/dist/{nodecrypto-CIGSbdQh.mjs → nodecrypto-BSdTIm8T.mjs} +1 -1
- package/dist/purejs-xzcexc4T.mjs +15 -0
- package/dist/rolldown-runtime-B0Z9INg1.mjs +1 -0
- package/dist/{utils-DZmc0RJW.mjs → utils-CrMT-n--.mjs} +1 -1
- package/dist/{webcrypto-CRLL4ptE.mjs → webcrypto-BeKbrVgs.mjs} +1 -1
- package/package.json +8 -5
- package/dist/base64-WTSXTrii.mjs +0 -1
- package/dist/dist-B0qgGwAq.mjs +0 -3
- package/dist/purejs-CZxWHjtN.mjs +0 -15
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{C as e,T as t,_ as n,a as r,c as i,d as a,f as o,h as s,l as c,m as l,o as u,s as d,t as f,u as p,w as m,y as h}from"./dist-w03V0QPF.mjs";import{t as g}from"./hmac-CXnNqvhW.mjs";import{A as _,C as v,D as y,E as b,O as ee,S as x,T as te,_ as S,a as C,b as ne,c as w,d as re,f as ie,g as T,h as ae,i as oe,k as se,l as ce,m as le,n as ue,o as de,p as fe,r as pe,s as me,t as he,u as ge,v as _e,w as ve,x as ye,y as be}from"./index.mjs";import{defineCommand as xe}from"citty";import*as E from"valibot";const Se=`2.56.3`;let Ce={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${Se}`};var we=class e extends Error{constructor(t,n={}){let r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=Ce.getDocsUrl?.({...n,docsPath:i}),o=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...Ce.version?[`Version: ${Ce.version}`]:[]].join(`
|
|
2
|
+
`);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=Se}walk(e){return Te(this,e)}};function Te(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?Te(e.cause,t):t?null:e}function Ee(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}function De(e){return Ee(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var Oe=class extends we{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}};function ke(e,{dir:t,size:n=32}={}){return typeof e==`string`?Ae(e,{dir:t,size:n}):je(e,{dir:t,size:n})}function Ae(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new Oe({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function je(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new Oe({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var Me=class extends we{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},Ne=class extends we{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}};function Pe(e,{size:t}){if(De(e)>t)throw new Ne({givenSize:De(e),maxSize:t})}const Fe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Ie(e,t={}){return typeof e==`number`||typeof e==`bigint`?ze(e,t):typeof e==`string`?Ve(e,t):typeof e==`boolean`?Le(e,t):Re(e,t)}function Le(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(Pe(n,{size:t.size}),ke(n,{size:t.size})):n}function Re(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=Fe[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(Pe(r,{size:t.size}),ke(r,{dir:`right`,size:t.size})):r}function ze(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new Me({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?ke(s,{size:r}):s}const Be=new TextEncoder;function Ve(e,t={}){return Re(Be.encode(e),t)}const He=new TextEncoder;function Ue(e,t={}){return typeof e==`number`||typeof e==`bigint`?qe(e,t):typeof e==`boolean`?We(e,t):Ee(e)?Ke(e,t):Je(e,t)}function We(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(Pe(n,{size:t.size}),ke(n,{size:t.size})):n}const D={zero:48,nine:57,A:65,F:70,a:97,f:102};function Ge(e){if(e>=D.zero&&e<=D.nine)return e-D.zero;if(e>=D.A&&e<=D.F)return e-(D.A-10);if(e>=D.a&&e<=D.f)return e-(D.a-10)}function Ke(e,t={}){let n=e;t.size&&(Pe(n,{size:t.size}),n=ke(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=Ge(r.charCodeAt(t++)),i=Ge(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new we(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function qe(e,t){return Ke(ze(e,t))}function Je(e,t={}){let n=He.encode(e);return typeof t.size==`number`?(Pe(n,{size:t.size}),ke(n,{dir:`right`,size:t.size})):n}const Ye=BigInt(0),Xe=BigInt(1),Ze=BigInt(2),Qe=BigInt(7),$e=BigInt(256),et=BigInt(113),tt=[],nt=[],rt=[];for(let e=0,t=Xe,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],tt.push(2*(5*r+n)),nt.push((e+1)*(e+2)/2%64);let i=Ye;for(let e=0;e<7;e++)t=(t<<Xe^(t>>Qe)*et)%$e,t&Ze&&(i^=Xe<<(Xe<<BigInt(e))-Xe);rt.push(i)}const it=c(rt,!0),at=it[0],ot=it[1],st=(e,t,n)=>n>32?r(e,t,n):d(e,t,n),ct=(e,t,n)=>n>32?u(e,t,n):i(e,t,n);function lt(e,t=24){let r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let n=(t+8)%10,i=(t+2)%10,a=r[i],o=r[i+1],s=st(a,o,1)^r[n],c=ct(a,o,1)^r[n+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){let r=nt[n],a=st(t,i,r),o=ct(t,i,r),s=tt[n];t=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=at[n],e[1]^=ot[n]}n(r)}var ut=class r extends p{constructor(e,n,r,i=!1,a=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=a,l(r),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=t(this.state)}clone(){return this._cloneInto()}keccak(){e(this.state32),lt(this.state32,this.rounds),e(this.state32),this.posOut=0,this.pos=0}update(e){o(this),e=m(e),a(e);let{blockLen:t,state:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){o(this,!1),a(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return l(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(s(e,this),this.finished)throw Error(`digest() was already called`);return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,n(this.state)}_cloneInto(e){let{blockLen:t,suffix:n,outputLen:i,rounds:a,enableXOF:o}=this;return e||=new r(t,n,i,o,a),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=a,e.suffix=n,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}};const dt=((e,t,n)=>h(()=>new ut(t,e,n)))(1,136,32);function ft(e,t){let n=t||`hex`,r=dt(Ee(e,{strict:!1})?Ue(e):e);return n===`bytes`?r:Ie(r)}var pt=class extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};const mt=/^0x[a-fA-F0-9]{40}$/,ht=new pt(8192);function gt(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(ht.has(r))return ht.get(r);let i=mt.test(e)?e.toLowerCase()===e||!n||vt(e)===e:!1;return ht.set(r,i),i}const _t=new pt(8192);function vt(e,t){if(_t.has(`${e}.${t}`))return _t.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=ft(Je(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return _t.set(`${e}.${t}`,a),a}function yt(){return`0.1.1`}var O=class e extends Error{static setStaticOptions(t){e.prototype.docsOrigin=t.docsOrigin,e.prototype.showVersion=t.showVersion,e.prototype.version=t.version}constructor(t,n={}){let r=(()=>{if(n.cause instanceof e){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&`details`in n.cause&&typeof n.cause.details==`string`?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=n.docsOrigin??e.prototype.docsOrigin,o=`${a}${i??``}`,s=!!(n.version??e.prototype.showVersion),c=n.version??e.prototype.version,l=[t||`An error occurred.`,...n.metaMessages?[``,...n.metaMessages]:[],...r||i||s?[``,r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0,s?`Version: ${c}`:void 0]:[]].filter(e=>typeof e==`string`).join(`
|
|
3
|
+
`);super(l,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsOrigin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"showVersion",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsOrigin=a,this.docsPath=i,this.shortMessage=t,this.showVersion=s,this.version=c}walk(e){return bt(this,e)}};Object.defineProperty(O,"defaultStaticOptions",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${yt()}`}}),O.setStaticOptions(O.defaultStaticOptions);function bt(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?bt(e.cause,t):t?null:e}function xt(e,t){if(Vt(e)>t)throw new Wt({givenSize:Vt(e),maxSize:t})}const k={zero:48,nine:57,A:65,F:70,a:97,f:102};function St(e){if(e>=k.zero&&e<=k.nine)return e-k.zero;if(e>=k.A&&e<=k.F)return e-(k.A-10);if(e>=k.a&&e<=k.f)return e-(k.a-10)}function Ct(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new Gt({size:e.length,targetSize:r,type:`Bytes`});let i=new Uint8Array(r);for(let t=0;t<r;t++){let a=n===`right`;i[a?t:r-t-1]=e[a?t:e.length-t-1]}return i}function wt(e,t={}){let{dir:n=`left`}=t,r=e,i=0;for(let e=0;e<r.length-1&&r[n===`left`?e:r.length-e-1].toString()===`0`;e++)i++;return r=n===`left`?r.slice(i):r.slice(0,r.length-i),r}function Tt(e,t){if(jt(e)>t)throw new Mt({givenSize:jt(e),maxSize:t})}function Et(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;let i=e.replace(`0x`,``);if(i.length>r*2)throw new Nt({size:Math.ceil(i.length/2),targetSize:r,type:`Hex`});return`0x${i[n===`right`?`padEnd`:`padStart`](r*2,`0`)}`}function Dt(e){if(e===null||typeof e==`boolean`||typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`){if(!Number.isFinite(e))throw TypeError(`Cannot canonicalize non-finite number`);return Object.is(e,-0)?`0`:JSON.stringify(e)}if(typeof e==`bigint`)throw TypeError(`Cannot canonicalize bigint`);if(Array.isArray(e))return`[${e.map(e=>Dt(e)).join(`,`)}]`;if(typeof e==`object`)return`{${Object.keys(e).sort().reduce((t,n)=>{let r=e[n];return r!==void 0&&t.push(`${JSON.stringify(n)}:${Dt(r)}`),t},[]).join(`,`)}}`}const Ot=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function kt(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=Ot[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(Tt(r,t.size),At(r,t.size)):r}function At(e,t){return Et(e,{dir:`right`,size:t})}function jt(e){return Math.ceil((e.length-2)/2)}var Mt=class extends O{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Hex.SizeOverflowError`})}},Nt=class extends O{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Hex.SizeExceedsPaddingSizeError`})}};const Pt=new TextDecoder,Ft=new TextEncoder;function It(e){return e instanceof Uint8Array?e:typeof e==`string`?Rt(e):Lt(e)}function Lt(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Rt(e,t={}){let{size:n}=t,r=e;n&&(Tt(e,n),r=At(e,n));let i=r.slice(2);i.length%2&&(i=`0${i}`);let a=i.length/2,o=new Uint8Array(a);for(let e=0,t=0;e<a;e++){let n=St(i.charCodeAt(t++)),r=St(i.charCodeAt(t++));if(n===void 0||r===void 0)throw new O(`Invalid byte sequence ("${i[t-2]}${i[t-1]}" in "${i}").`);o[e]=n<<4|r}return o}function zt(e,t={}){let{size:n}=t,r=Ft.encode(e);return typeof n==`number`?(xt(r,n),Bt(r,n)):r}function Bt(e,t){return Ct(e,{dir:`right`,size:t})}function Vt(e){return e.length}function Ht(e,t={}){let{size:n}=t,r=e;return n!==void 0&&(xt(r,n),r=Ut(r)),Pt.decode(r)}function Ut(e){return wt(e,{dir:`right`})}var Wt=class extends O{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed \`${t}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeOverflowError`})}},Gt=class extends O{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${t}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Bytes.SizeExceedsPaddingSizeError`})}};function Kt(e,t,n={}){let{as:r=typeof t==`string`?`Hex`:`Bytes`}=n,i=g(f,It(e),It(t));return r===`Bytes`?i:kt(i)}const qt=new TextEncoder,Jt=new TextDecoder,Yt=Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[t,e.charCodeAt(0)])),Xt={...Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[e.charCodeAt(0),t])),61:0,45:62,95:63};function Zt(e,t={}){let{pad:n=!0,url:r=!1}=t,i=new Uint8Array(Math.ceil(e.length/3)*4);for(let t=0,n=0;n<e.length;t+=4,n+=3){let r=(e[n]<<16)+(e[n+1]<<8)+(e[n+2]|0);i[t]=Yt[r>>18],i[t+1]=Yt[r>>12&63],i[t+2]=Yt[r>>6&63],i[t+3]=Yt[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=Jt.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function Qt(e,t={}){return Zt(zt(e),t)}function $t(e){let t=e.replace(/=+$/,``),n=t.length,r=new Uint8Array(n+3);qt.encodeInto(t+`===`,r);for(let e=0,n=0;e<t.length;e+=4,n+=3){let t=(Xt[r[e]]<<18)+(Xt[r[e+1]]<<12)+(Xt[r[e+2]]<<6)+Xt[r[e+3]];r[n]=t>>16,r[n+1]=t>>8&255,r[n+2]=t&255}let i=(n>>2)*3+(n%4&&n%4-1);return new Uint8Array(r.buffer,0,i)}function en(e){return Ht($t(e))}const A={acceptPayment:`Accept-Payment`,authorization:`Authorization`,paymentAuthorization:`Payment-Authorization`,paymentReceipt:`Payment-Receipt`,paymentSession:`Payment-Session`,paymentSessionSnapshot:`Payment-Session-Snapshot`,wwwAuthenticate:`WWW-Authenticate`},tn={payment:`Payment`};function nn(e){let t=en(e);return JSON.parse(t)}function j(e){return Qt(Dt(e),{pad:!1,url:!0})}var rn;function M(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var an=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};(rn=globalThis).__zod_globalConfig??(rn.__zod_globalConfig={});const on=globalThis.__zod_globalConfig;function N(e){return e&&Object.assign(on,e),on}function sn(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function cn(e,t){return typeof t==`bigint`?t.toString():t}function ln(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function un(e){return e==null}function dn(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}const fn=Symbol(`evaluating`);function P(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==fn)return r===void 0&&(r=fn,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}const pn=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function mn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hn(e){if(mn(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return mn(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}const gn=new Set([`string`,`number`,`symbol`]);function _n(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function vn(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function F(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function yn(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}-Number.MAX_VALUE,Number.MAX_VALUE;function bn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function xn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function I(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Sn(e){return typeof e==`string`?e:e?.message}function L(e,t,n){let r=e.message?e.message:Sn(e.inst?._zod.def?.error?.(e))??Sn(t?.error?.(e))??Sn(n.customError?.(e))??Sn(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function Cn(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function wn(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}const Tn=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,cn,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},En=M(`$ZodError`,Tn),Dn=M(`$ZodError`,Tn,{Parent:Error}),On=(e=>(t,n,r,i)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new an;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>L(e,a,N())));throw pn(t,i?.callee),t}return o.value})(Dn),kn=(e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>L(e,a,N())));throw pn(t,i?.callee),t}return o.value})(Dn),An=(e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new an;return a.issues.length?{success:!1,error:new(e??En)(a.issues.map(e=>L(e,i,N())))}:{success:!0,data:a.value}})(Dn),jn=(e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>L(e,i,N())))}:{success:!0,data:a.value}})(Dn),Mn=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Nn=/^-?\d+(?:\.\d+)?$/,Pn=/^(?:true|false)$/i,Fn=M(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),In=M(`$ZodCheckMinLength`,(e,t)=>{var n;Fn.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!un(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=Cn(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Ln=M(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Fn.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Rn=M(`$ZodCheckRegex`,(e,t)=>{Ln.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),zn={major:4,minor:4,patch:3},R=M(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=zn;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=bn(e),i;for(let a of t){if(a._zod.def.when){if(xn(e)||!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new an;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=bn(e,t))});else{if(e.issues.length===t)continue;r||=bn(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(bn(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new an;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new an;return o.then(e=>t(e,r,a))}return t(o,r,a)}}P(e,`~standard`,()=>({validate:t=>{try{let n=An(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return jn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),Bn=M(`$ZodString`,(e,t)=>{R.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Mn(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),Vn=M(`$ZodNumber`,(e,t)=>{R.init(e,t),e._zod.pattern=e._zod.bag.pattern??Nn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Hn=M(`$ZodBoolean`,(e,t)=>{R.init(e,t),e._zod.pattern=Pn,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Un=M(`$ZodUnknown`,(e,t)=>{R.init(e,t),e._zod.parse=e=>e}),Wn=M(`$ZodNever`,(e,t)=>{R.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Gn(e,t,n){e.issues.length&&t.issues.push(...I(n,e.issues)),t.value[n]=e.value}const Kn=M(`$ZodArray`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>Gn(t,n,e))):Gn(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function qn(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(...I(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function Jn(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=yn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Yn(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>qn(e,n,i,t,u,d))):qn(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}const Xn=M(`$ZodObject`,(e,t)=>{if(R.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=ln(()=>Jn(t));P(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=mn,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>qn(n,t,e,s,r,i))):qn(a,t,e,s,r,i)}return i?Yn(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}});function Zn(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!bn(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>L(e,r,N())))}),t)}const Qn=M(`$ZodUnion`,(e,t)=>{R.init(e,t),P(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),P(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),P(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),P(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>dn(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>Zn(t,r,e,i)):Zn(o,r,e,i)}}),$n=M(`$ZodRecord`,(e,t)=>{R.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!hn(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let c of o)if(typeof c==`string`||typeof c==`number`||typeof c==`symbol`){s.add(typeof c==`number`?c.toString():c);let o=t.keyType._zod.run({value:c,issues:[]},r);if(o instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(o.issues.length){n.issues.push({code:`invalid_key`,origin:`record`,issues:o.issues.map(e=>L(e,r,N())),input:c,path:[c],inst:e});continue}let l=o.value,u=t.valueType._zod.run({value:i[c],issues:[]},r);u instanceof Promise?a.push(u.then(e=>{e.issues.length&&n.issues.push(...I(c,e.issues)),n.value[l]=e.value})):(u.issues.length&&n.issues.push(...I(c,u.issues)),n.value[l]=u.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`||!Object.prototype.propertyIsEnumerable.call(i,o))continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Nn.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>L(e,r,N())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...I(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...I(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),er=M(`$ZodEnum`,(e,t)=>{R.init(e,t);let n=sn(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>gn.has(typeof e)).map(e=>typeof e==`string`?_n(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),tr=M(`$ZodLiteral`,(e,t)=>{if(R.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?_n(e):e?_n(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}});function nr(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}const rr=M(`$ZodOptional`,(e,t)=>{R.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,P(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),P(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${dn(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>nr(e,r)):nr(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),ir=M(`$ZodCustom`,(e,t)=>{Fn.init(e,t),R.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>ar(t,n,r,e));ar(i,n,r,e)}});function ar(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(wn(e))}}function or(e,t){return new e({type:`string`,...F(t)})}function sr(e,t){return new e({type:`number`,checks:[],...F(t)})}function cr(e,t){return new e({type:`boolean`,...F(t)})}function lr(e){return new e({type:`unknown`})}function ur(e,t){return new e({type:`never`,...F(t)})}function dr(e,t){return new In({check:`min_length`,...F(t),minimum:e})}function z(e,t){return new Rn({check:`string_format`,format:`regex`,...F(t),pattern:e})}function fr(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...F(n)})}const B=M(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);R.init(e,t),e.def=t,e.type=t.type,e.parse=(t,n)=>On(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>An(e,t,n),e.parseAsync=async(t,n)=>kn(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>jn(e,t,n),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0}),e.with=e.check,e.clone=(t,n)=>vn(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.apply=t=>t(e)}),pr=M(`ZodMiniString`,(e,t)=>{Bn.init(e,t),B.init(e,t)});function V(e){return or(pr,e)}const mr=M(`ZodMiniNumber`,(e,t)=>{Vn.init(e,t),B.init(e,t)});function hr(e){return sr(mr,e)}const gr=M(`ZodMiniBoolean`,(e,t)=>{Hn.init(e,t),B.init(e,t)});function _r(e){return cr(gr,e)}const vr=M(`ZodMiniUnknown`,(e,t)=>{Un.init(e,t),B.init(e,t)});function H(){return lr(vr)}const yr=M(`ZodMiniNever`,(e,t)=>{Wn.init(e,t),B.init(e,t)});function br(e){return ur(yr,e)}const xr=M(`ZodMiniArray`,(e,t)=>{Kn.init(e,t),B.init(e,t)});function Sr(e,t){return new xr({type:`array`,element:e,...F(t)})}const Cr=M(`ZodMiniObject`,(e,t)=>{Xn.init(e,t),B.init(e,t),P(e,`shape`,()=>t.shape)});function U(e,t){let n={type:`object`,shape:e??{},...F(t)};return new Cr(n)}function wr(e,t){return new Cr({type:`object`,shape:e,catchall:H(),...F(t)})}const Tr=M(`ZodMiniUnion`,(e,t)=>{Qn.init(e,t),B.init(e,t)});function Er(e,t){return new Tr({type:`union`,options:e,...F(t)})}const Dr=M(`ZodMiniRecord`,(e,t)=>{$n.init(e,t),B.init(e,t)});function W(e,t,n){return!t||!t._zod?new Dr({type:`record`,keyType:V(),valueType:e,...F(t)}):new Dr({type:`record`,keyType:e,valueType:t,...F(n)})}const Or=M(`ZodMiniEnum`,(e,t)=>{er.init(e,t),B.init(e,t),e.options=Object.values(t.entries)});function kr(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Or({type:`enum`,entries:n,...F(t)})}const Ar=M(`ZodMiniLiteral`,(e,t)=>{tr.init(e,t),B.init(e,t)});function G(e,t){return new Ar({type:`literal`,values:Array.isArray(e)?e:[e],...F(t)})}const jr=M(`ZodMiniOptional`,(e,t)=>{rr.init(e,t),B.init(e,t)});function K(e){return new jr({type:`optional`,innerType:e})}const Mr=M(`ZodMiniCustom`,(e,t)=>{ir.init(e,t),B.init(e,t)});function Nr(e,t={}){return fr(Mr,e,t)}function Pr(){return V().check(z(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,`Invalid ISO 8601 datetime`))}function Fr(e){return e instanceof Date?Number.isFinite(e.getTime())?e.toISOString():`Invalid Date`:e}function Ir(){return V().check(z(/^0x[0-9a-fA-F]{40}$/,`Invalid address`))}function Lr(){return V().check(z(/^0x[0-9a-fA-F]{64}$/,`Invalid hash`))}function Rr(){return V().check(z(/^0x[0-9a-fA-F]+$/,`Invalid signature`))}const zr=U({description:K(V()),digest:K(V().check(z(/^sha-256=/,`Invalid digest format`))),expires:K(Pr()),header:K(V().check(z(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,`Invalid HTTP header name`))),id:V().check(dr(1)),intent:V(),method:V(),meta:K(W(V(),V())),opaque:K(V()),realm:V(),request:W(V(),H())});function Br(e,t){let{description:n,digest:r,meta:i,method:a,header:o,intent:s,realm:c,request:l,secretKey:u}=e,d=ei(o)?void 0:o,f=e.expires?Fr(e.expires):void 0,p=e.opaque??(i===void 0?void 0:j(i)),m=u?ti({...e,expires:f,...i!==void 0&&{meta:i},opaque:p},{secretKey:u}):e.id;return zr.parse({id:m,realm:c,method:a,intent:s,request:l,...n&&{description:n},...r&&{digest:r},...f&&{expires:f},...d!==void 0&&{header:d},...i!==void 0&&{meta:i},...p!==void 0&&{opaque:p}})}function Vr(e){let t=[q(`id`,e.id),q(`realm`,e.realm),q(`method`,e.method),q(`intent`,e.intent),q(`request`,j(e.request))];e.description!==void 0&&t.push(q(`description`,e.description)),e.digest!==void 0&&t.push(q(`digest`,e.digest)),e.expires!==void 0&&t.push(q(`expires`,e.expires));let n=e.header;return n!==void 0&&!ei(n)&&t.push(q(`header`,n)),e.opaque===void 0?e.meta!==void 0&&t.push(q(`opaque`,j(e.meta))):t.push(q(`opaque`,e.opaque)),`${tn.payment} ${t.join(`, `)}`}function q(e,t){if(/[\r\n]/.test(t))throw Error(`Invalid quoted-string value.`);return`${e}="${t.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/[\u0100-\uffff]/g,e=>`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)}"`}function Hr(e,t){let n=Ur(e);if(!n)throw Error(`Missing Payment scheme.`);let{request:r,opaque:i,...a}=Wr(n);if(!r)throw Error(`Missing request parameter.`);if(r.length>16384)throw Error(`Request parameter too large.`);if(a.method&&!/^[a-z][a-z0-9:_-]*$/.test(a.method))throw Error(`Invalid method: "${a.method}". Must be lowercase per spec.`);return Br({...a,request:nn(r),...i&&{opaque:i}},t)}function Ur(e){let t=tn.payment,[n]=Jr(e,t);if(n===void 0)return null;let r=n+t.length;for(;r<e.length&&/\s/.test(e[r]??``);)r++;return e.slice(r)}function Wr(e){let t=Object.create(null),n=0;for(;n<e.length;){for(;n<e.length&&/[\s,]/.test(e[n]??``);)n++;if(n>=e.length)break;let r=n;for(;n<e.length&&/[A-Za-z0-9_-]/.test(e[n]??``);)n++;let i=e.slice(r,n).toLowerCase();if(!i)throw Error(`Malformed auth-param.`);for(;n<e.length&&/\s/.test(e[n]??``);)n++;if(e[n]!==`=`)break;for(n++;n<e.length&&/\s/.test(e[n]??``);)n++;let[a,o]=Gr(e,n);if(n=o,i in t)throw Error(`Duplicate parameter: ${i}`);t[i]=a}return t}function Gr(e,t){if(e[t]===`"`)return Kr(e,t+1);let n=t;for(;n<e.length&&e[n]!==`,`;)n++;return[e.slice(t,n).trim(),n]}function Kr(e,t){let n=t,r=!1,i=t,a;for(;n<e.length;){let o=e[n];if(n++,r){a??=[];let t=o===`u`?e.slice(n,n+4):void 0;t&&/^[0-9A-Fa-f]{4}$/.test(t)?(a.push(String.fromCharCode(Number.parseInt(t,16))),n+=4):a.push(o),i=n,r=!1;continue}if(o===`\\`){a??=[],a.push(e.slice(i,n-1)),i=n,r=!0;continue}if(o===`"`)return[a?[...a,e.slice(i,n-1)].join(``):e.slice(t,n-1),n]}throw Error(`Unterminated quoted-string.`)}function qr(e,t,n){if(e.slice(t,t+n.length).toLowerCase()!==n.toLowerCase())return!1;let r=e[t+n.length];return!!(r&&/\s/.test(r))}function Jr(e,t){let n=[],r=!1,i=!1;for(let a=0;a<e.length;a++){let o=e[a];if(r){i?i=!1:o===`\\`?i=!0:o===`"`&&(r=!1);continue}if(o===`"`){r=!0;continue}if(!qr(e,a,t))continue;let s=a-1;for(;s>=0&&/\s/.test(e[s]??``);)s--;s>=0&&e[s]!==`,`||n.push(a)}return n}function Yr(e,t){if(e.status!==402)throw Error(`Response status is not 402.`);return Xr(e.headers,t)}function Xr(e,t){let n=e.get(A.wwwAuthenticate);if(!n)throw Error(`Missing ${A.wwwAuthenticate} header.`);return Zr(n,t)}function Zr(e,t){let n=Jr(e,tn.payment);if(n.length===0)throw Error(`No Payment schemes found.`);return n.map((r,i)=>{let a=i+1<n.length?n[i+1]:e.length;return Hr(e.slice(r,a).replace(/,\s*$/,``),t)})}function Qr(e){let t=[e.realm,e.method,e.intent,j(e.request),e.expires??``,e.digest??``],n=e.header;return n!==void 0&&!ei(n)&&t.push(n),t.push(e.opaque??(e.meta?j(e.meta):``)),t.join(`|`)}function $r(e){return e.header??A.authorization}function ei(e){return e?.toLowerCase()===A.authorization.toLowerCase()}function ti(e,t){let n=Qr(e);return Zt(Kt(zt(t.secretKey),zt(n),{as:`Bytes`}),{url:!0,pad:!1})}var ni=class extends Error{name=`MissingPaymentSchemeError`;constructor(){super(`Missing Payment scheme.`)}},ri=class extends Error{name=`InvalidCredentialEncodingError`;constructor(){super(`Invalid base64url or JSON.`)}};function ii(e){let t=e.match(RegExp(`^${tn.payment}\\s+(.+)$`,`i`));if(!t?.[1])throw new ni;try{let e=en(t[1]),n=JSON.parse(e),{opaque:r,request:i,meta:a,...o}=n.challenge,{meta:s,opaque:c}=ai(r);return{challenge:zr.parse({...o,...s!==void 0&&{meta:s},...c!==void 0&&{opaque:c},request:nn(i)}),payload:n.payload,...n.source&&{source:n.source}}}catch{throw new ri}}function ai(e){if(e===void 0)return{};if(typeof e==`string`)return{opaque:e};if(!oi(e))throw Error(`Invalid opaque.`);return{meta:e,opaque:j(e)}}function oi(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.values(e).every(e=>typeof e==`string`)}var si=class extends Error{details;status=402;hint;constructor(e,t={}){super(e),this.details=t.details}toProblemDetails(e){return{type:this.type,title:this.title,status:this.status,detail:this.message,...this.details&&Object.keys(this.details).length>0&&{details:this.details},...this.hint&&{hint:this.hint},...e&&{challengeId:e}}}},ci=class extends si{name=`InvalidChallengeError`;title=`Invalid Challenge`;status=402;type=`https://paymentauth.org/problems/invalid-challenge`;constructor(e={}){let{id:t,reason:n}=e,r=t?` "${t}"`:``,i=n?`: ${n}`:``;super(`Challenge${r} is invalid${i}.`)}},li=class extends si{name=`PaymentExpiredError`;title=`Payment Expired`;type=`https://paymentauth.org/problems/payment-expired`;constructor(e={}){let{expires:t}=e;super(t?`Payment expired at ${t}.`:`Payment has expired.`)}};function ui(e,t){if(!e)throw new ci({...t&&{id:t},reason:`missing required expires field`});if(Number.isNaN(new Date(e).getTime()))throw new ci({...t&&{id:t},reason:`malformed expires timestamp`});if(new Date(e)<new Date)throw new li({expires:e})}function di(e){return e}function fi(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}const pi=wr({method:V(),reference:V(),externalId:K(V()),subscriptionId:K(V()),status:G(`success`),timestamp:Pr()});function mi(e){let t=en(e);return hi(JSON.parse(t))}function hi(e){return pi.parse(e)}function gi(e){let t=e.headers.get(A.paymentReceipt);if(!t)throw Error(`Missing ${A.paymentReceipt} header.`);return mi(t)}function _i(e){return{encode(t){return Qt(JSON.stringify(e.parse(t)))},decode(t){try{return e.parse(JSON.parse(en(t)))}catch{throw new vi}}}}var vi=class extends Error{name=`InvalidJsonHeaderError`;constructor(){super(`Invalid base64 JSON header.`)}};const yi=[`exact`],bi=`PAYMENT-REQUIRED`,xi=`PAYMENT-SIGNATURE`,Si=V().check(dr(1)),Ci=hr().check(Nr(e=>e>0,`Must be positive`)),J=V().check(z(/^\d+$/,`Invalid atomic amount`)),wi=Ir(),Ti=V().check(z(RegExp(`^eip155:\\d+$`),`Invalid EVM CAIP-2 network`)),Ei=U({description:K(V()),iconUrl:K(V()),mimeType:K(V()),serviceName:K(V()),tags:K(Sr(V())),url:Si}),Di=U({amount:J,asset:Si,extra:K(W(V(),H())),maxTimeoutSeconds:Ci,network:Ti,payTo:Si,scheme:kr(yi)}),Oi=W(V(),U({info:W(V(),H()),schema:W(V(),H())})),ki=U({accepts:Sr(Di).check(dr(1)),error:K(V()),extensions:K(Oi),resource:Ei,x402Version:G(2)}),Ai=Er([U({authorization:U({from:wi,nonce:Lr(),to:wi,validAfter:J,validBefore:J,value:J}),signature:Rr()}),U({permit2Authorization:U({deadline:J,from:wi,nonce:J,permitted:U({amount:J,token:wi}),spender:wi,witness:U({to:wi,validAfter:J})}),signature:Rr()})]),ji=U({accepted:Di,extensions:K(Oi),payload:Ai,resource:K(Ei),x402Version:G(2)}),Mi=U({amount:K(J),errorMessage:K(V()),errorReason:K(V()),extensions:K(Oi),extra:K(W(V(),H())),network:Si,payer:K(V()),success:_r(),transaction:V()}),Ni=_i(ki),Pi=_i(ji),Fi=_i(Mi);Ni.encode,Ni.decode;function Ii(e){try{let t=JSON.parse(en(e));return Li(t)}catch{throw new vi}}Pi.encode,Pi.decode,Fi.encode,Fi.decode;const Li=e=>{if(!e||typeof e!=`object`||Array.isArray(e))throw new vi;let t=e;if(t.x402Version!==2||!Array.isArray(t.accepts))throw new vi;let n=Ei.parse(t.resource),r=t.extensions===void 0?void 0:Oi.safeParse(t.extensions).data;return{accepts:t.accepts,...r?{extensions:r}:{},resource:n,x402Version:2}},Ri=Symbol.for(`mppx.x402.challenge`);function zi(e){return Object.defineProperty(e,Ri,{value:!0}),e}function Bi(e){return!!e?.[Ri]}function Vi(e){let t={};for(let n of e){let e=t[n.name]??={};e[n.intent]=Ki(n)}return t}function Hi(e,t){let n=Vi(e),r=$i(e,n,t),i=e.map((e,t)=>({intent:e.intent,method:e.name,q:r[Ki(e)]??1,index:t}));return{definition:r,entries:i,header:Wi(i),keys:n}}function Ui(e){let t=e.split(/\s*,\s*/).map(e=>e.trim()).filter(Boolean);if(t.length===0)throw Error(`Accept-Payment header is empty.`);return t.map((e,t)=>Zi(e,t))}function Wi(e){return e.map(({method:e,intent:t,q:n})=>{let r=`${e}/${t}`;return n===1?r:`${r};q=${ra(n)}`}).join(`, `)}function Gi(e,t,n){let r=new Map;for(let e of t){let t=Ki(e),n=r.get(t);n?n.push(e):r.set(t,[e])}return e.flatMap((e,t)=>{let i=r.get(Ki(e));if(!i)return[];let a=qi(e,n);return!a||a.q<=0?[]:i.filter(t=>t.canHandleChallenge?.({challenge:e})??!0).map(n=>({challenge:e,index:t,match:a,method:n}))}).sort((e,t)=>Xi(e.challenge)-Xi(t.challenge)||t.match.q-e.match.q||e.index-t.index).map(e=>{let{match:t,...n}=e;return n})}function Ki(e){let t=e.method??e.name;if(!t)throw Error(`Missing payment method name.`);return`${t}/${e.intent}`}function qi(e,t){let n;for(let r of t){if(!Ji(e,r))continue;let t={...r,specificity:Yi(r)};(!n||t.specificity>n.specificity||t.specificity===n.specificity&&t.q>n.q||t.specificity===n.specificity&&t.q===n.q&&t.index<n.index)&&(n=t)}return n}function Ji(e,t){return(t.method===`*`||t.method===e.method)&&(t.intent===`*`||t.intent===e.intent)}function Yi(e){return Number(e.method!==`*`)+Number(e.intent!==`*`)}function Xi(e){return+!!Bi(e)}function Zi(e,t){let n=/^(?<method>[^/;\s]+|\*)\s*\/\s*(?<intent>[^/;\s]+|\*)(?<params>(?:\s*;\s*.+)?)$/u.exec(e),r=n?.groups?.method,i=n?.groups?.intent;if(!r||!i)throw Error(`Invalid Accept-Payment entry: ${e}`);ia(r,`method`),ia(i,`intent`);let a=1;for(let t of Qi(n.groups?.params)){if(!t)continue;let n=/^(?<name>[A-Za-z0-9_-]+)\s*=\s*(?<value>\S+)$/u.exec(t),r=n?.groups?.name,i=n?.groups?.value;if(!r||!i)throw Error(`Invalid Accept-Payment parameter: ${t}`);r===`q`&&(a=ta(i,`Accept-Payment entry "${e}"`))}return{intent:i,method:r,q:a,index:t}}function Qi(e){return e?e.split(/\s*;\s*/).filter(Boolean):[]}function $i(e,t,n){if(!n)return{};let r=typeof n==`function`?n(t):n,i=new Set(e.map(e=>Ki(e))),a={};for(let[e,t]of Object.entries(r??{})){if(!i.has(e))throw Error(`Unknown payment preference "${e}". Available: ${[...i].join(`, `)}`);a[e]=ea(t,`payment preference "${e}"`)}return a}function ea(e,t){if(typeof e!=`number`||Number.isNaN(e)||!Number.isFinite(e))throw Error(`Invalid q-value for ${t}. Expected a finite number.`);return na(e,t)}function ta(e,t){if(!/^0(?:\.\d{0,3})?$|^1(?:\.0{0,3})?$/.test(e))throw Error(`Invalid q-value for ${t}. Expected an HTTP qvalue.`);return na(Number(e),t)}function na(e,t){if(e<0||e>1)throw Error(`Invalid q-value for ${t}. Expected a value between 0 and 1.`);let n=Math.round(e*1e3);if(Math.abs(e*1e3-n)>1e-9)throw Error(`Invalid q-value for ${t}. Expected at most 3 decimal places.`);return n/1e3}function ra(e){return e.toFixed(3).replace(/\.0+$/,``).replace(/(\.\d*?)0+$/,`$1`)}function ia(e,t){if(e!==`*`&&!/^[a-z0-9-]+$/.test(e))throw Error(`Invalid Accept-Payment ${t}: ${e}`)}var aa=class extends Error{constructor(e,t){super(e),this.name=`ParseError`,this.type=t.type,this.field=t.field,this.value=t.value,this.line=t.line}};function oa(e){}function sa(e){if(typeof e==`function`)throw TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");let{onEvent:t=oa,onError:n=oa,onRetry:r=oa,onComment:i,maxBufferSize:a}=e,o=[],s=0,c=!0,l,u=``,d=0,f,p=!1;function m(e){if(p)throw Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");if(c&&(c=!1,e.charCodeAt(0)===239&&e.charCodeAt(1)===187&&e.charCodeAt(2)===191&&(e=e.slice(3))),o.length===0){let t=g(e);t!==``&&(o.push(t),s=t.length),h();return}if(e.indexOf(`
|
|
4
|
+
`)===-1&&e.indexOf(`\r`)===-1){o.push(e),s+=e.length,h();return}o.push(e);let t=o.join(``);o.length=0,s=0;let n=g(t);n!==``&&(o.push(n),s=n.length),h()}function h(){a!==void 0&&(s+u.length<=a||(p=!0,o.length=0,s=0,l=void 0,u=``,d=0,f=void 0,n(new aa(`Buffered data exceeded max buffer size of ${a} characters`,{type:`max-buffer-size-exceeded`}))))}function g(e){let n=0;if(e.indexOf(`\r`)===-1){let r=e.indexOf(`
|
|
5
|
+
`,n);for(;r!==-1;){if(n===r){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0,n=r+1,r=e.indexOf(`
|
|
6
|
+
`,n);continue}let i=e.charCodeAt(n);if(ca(e,n,i)){let i=e.charCodeAt(n+5)===32?n+6:n+5,a=e.slice(i,r);if(d===0&&e.charCodeAt(r+1)===10){t({id:l,event:f,data:a}),l=void 0,u=``,f=void 0,n=r+2,r=e.indexOf(`
|
|
7
|
+
`,n);continue}u=d===0?a:`${u}
|
|
8
|
+
${a}`,d++}else la(e,n,i)?f=e.slice(e.charCodeAt(n+6)===32?n+7:n+6,r)||void 0:_(e,n,r);n=r+1,r=e.indexOf(`
|
|
9
|
+
`,n)}return e.slice(n)}for(;n<e.length;){let t=e.indexOf(`\r`,n),r=e.indexOf(`
|
|
10
|
+
`,n),i=-1;if(t!==-1&&r!==-1?i=t<r?t:r:t===-1?r!==-1&&(i=r):i=t===e.length-1?-1:t,i===-1)break;_(e,n,i),n=i+1,e.charCodeAt(n-1)===13&&e.charCodeAt(n)===10&&n++}return e.slice(n)}function _(e,t,n){if(t===n){y();return}let r=e.charCodeAt(t);if(ca(e,t,r)){let r=e.charCodeAt(t+5)===32?t+6:t+5,i=e.slice(r,n);u=d===0?i:`${u}
|
|
11
|
+
${i}`,d++;return}if(la(e,t,r)){f=e.slice(e.charCodeAt(t+6)===32?t+7:t+6,n)||void 0;return}if(r===105&&e.charCodeAt(t+1)===100&&e.charCodeAt(t+2)===58){let r=e.slice(e.charCodeAt(t+3)===32?t+4:t+3,n);r.includes(`\0`)||(l=r);return}if(r===58){if(i){let r=e.slice(t,n);i(r.slice(e.charCodeAt(t+1)===32?2:1))}return}let a=e.slice(t,n),o=a.indexOf(`:`);if(o===-1){v(a,``,a);return}let s=a.slice(0,o),c=a.charCodeAt(o+1)===32?2:1;v(s,a.slice(o+c),a)}function v(e,t,i){switch(e){case`event`:f=t||void 0;break;case`data`:u=d===0?t:`${u}
|
|
12
|
+
${t}`,d++;break;case`id`:t.includes(`\0`)||(l=t);break;case`retry`:/^\d+$/.test(t)?r(parseInt(t,10)):n(new aa(`Invalid \`retry\` value: "${t}"`,{type:`invalid-retry`,value:t,line:i}));break;default:n(new aa(`Unknown field "${e.length>20?`${e.slice(0,20)}\u2026`:e}"`,{type:`unknown-field`,field:e,value:t,line:i}))}}function y(){d>0&&t({id:l,event:f,data:u}),l=void 0,u=``,d=0,f=void 0}function b(e={}){if(e.consume&&o.length>0){let e=o.join(``);_(e,0,e.length)}c=!0,l=void 0,u=``,d=0,f=void 0,o.length=0,s=0,p=!1}return{feed:m,reset:b}}function ca(e,t,n){return n===100&&e.charCodeAt(t+1)===97&&e.charCodeAt(t+2)===116&&e.charCodeAt(t+3)===97&&e.charCodeAt(t+4)===58}function la(e,t,n){return n===101&&e.charCodeAt(t+1)===118&&e.charCodeAt(t+2)===101&&e.charCodeAt(t+3)===110&&e.charCodeAt(t+4)===116&&e.charCodeAt(t+5)===58}const ua=[A.authorization,bi,`PAYMENT-RESPONSE`,xi];function da(e,t,n){let r=new Headers(e.headers);for(let e of ua)(e!==A.authorization||r.get(e)?.startsWith(`Payment `))&&r.delete(e);return r.set(t,n),{...e,headers:r}}function fa(e){if(typeof e==`string`)try{let t=JSON.parse(e),n=t?.id;return t?.jsonrpc!==`2.0`||typeof t?.method!=`string`?void 0:typeof n==`string`||typeof n==`number`?n:void 0}catch{return}}const pa=new WeakMap;function ma(e){let t=fa(e?.body);if(t===void 0)return;let n=new Headers(e?.headers);if(n.has(`mcp-method`))return t;let r=n.get(`accept`)?.toLowerCase()??``;return r.includes(`application/json`)&&r.includes(`text/event-stream`)?t:void 0}function ha(e){if(!e||typeof e!=`object`)return;let t=e,n=t.id;if(t.jsonrpc!==`2.0`||n!==void 0&&typeof n!=`string`&&typeof n!=`number`)return;let r=`error`in t;if(r!==`result`in t)return r?Number.isInteger(t.error?.code)&&typeof t.error?.message==`string`?e:void 0:n!==void 0&&typeof t.result==`object`?e:void 0}function ga(e){if(!e||typeof e!=`object`)return;let t=e?.challenges;if(!Array.isArray(t)||t.length===0)return;let n=[];for(let e of t){let t=zr.safeParse(e);if(!t.success)return;n.push(t.data)}let{httpStatus:r,problem:i}=e;return{challenges:n,...typeof r==`number`?{httpStatus:r}:{},...i===void 0?{}:{problem:i}}}function _a(e){if(e)return`error`in e?e.error?.code===-32042?ga(e.error.data):void 0:ga(e.result?._meta?.[`org.paymentauth/payment-required`])}function va(e,t){return!e||e.id!==t?[]:_a(e)?.challenges??[]}async function ya(e){let t=e.clone().body?.getReader();if(!t)return;let n=new TextDecoder,r=!1,i,a=sa({onEvent(e){if(!r&&e.data&&(r=!0,!(e.event&&e.event!==`message`)))try{i=ha(JSON.parse(e.data))}catch{}}});try{for(;;){if(r)return i;let{done:e,value:o}=await t.read();if(e)return a.feed(n.decode()),a.reset({consume:!0}),i;a.feed(n.decode(o,{stream:!0}))}}finally{t.cancel().catch(()=>{})}}function ba(e){let t=pa.get(e);if(t)return t;let n=(async()=>{let t=e.headers.get(`content-type`)?.toLowerCase()??``;if(t.includes(`application/json`))return e.clone().json().then(ha).catch(()=>void 0);if(t.includes(`text/event-stream`))return ya(e)})();return pa.set(e,n),n}function xa(){return{getChallenges(e,t){let n=ma(t);return e.status===402||n===void 0?[]:ba(e).then(e=>va(e,n))},setCredential(e,t){let n=JSON.parse(e.body),r=ii(t);return{...e,body:JSON.stringify({...n,params:{...n.params,_meta:{...n.params?._meta,"org.paymentauth/credential":r}}})}}}}function Sa(){return{getChallenges(e){return e.status!==402||!e.headers.has(A.wwwAuthenticate)?[]:Yr(e)},setCredential(e,t,n){return da(e,n?.challenge?$r(n.challenge):A.authorization,t)}}}function Ca(){return{getChallenges(e){if(e.status!==402)return[];let t=e.headers.get(bi);if(!t)return[];let n=Ii(t);if(e.url&&n.resource.url!==e.url)throw Error(`x402 payment-required resource does not match response URL.`);return n.accepts.flatMap((e,t)=>{let r=Di.safeParse(e);if(!r.success)return[];let i=r.data;return zi(Br({id:`x402:${t}`,intent:`charge`,method:`evm`,realm:new URL(n.resource.url).host,request:{...i,...n.extensions?{extensions:n.extensions}:{},resource:n.resource}}))})},setCredential(e,t){return da(e,xi,t)}}}function wa(e){return e}function Ta(){let e=[Sa(),Ca(),xa()],t=new WeakMap,n=(e,n)=>{for(let r of n)t.set(r,e);return n},r=(t,r)=>{let i=(a,o)=>{for(let s=a;s<e.length;s++){let a=e[s],c=a.getChallenges(t,r);if(c instanceof Promise)return c.then(e=>i(s+1,[...o,...n(a,e)]));o.push(...n(a,c))}return o};return i(0,[])};return wa({name:`http`,isPaymentRequired(e,t){if(e.status===402)return!0;let n=r(e,t);return n instanceof Promise?n.then(e=>e.length>0):n.length>0},getChallenges(e,t){return r(e,t)},setCredential(n,r,i){let a=i?.challenge?t.get(i.challenge):void 0,o=e[0];if(!a&&!o)throw Error(`No protocol to attach the credential.`);return(a??o).setCredential(n,r,i)}})}const Ea=new WeakMap;function Da(e){return Ea.has(e)}function Oa(e,t){return Promise.resolve(Ea.get(e)?.(t))}const ka=new WeakMap,Aa=new WeakMap;function ja(e,t,n){ka.has(e)&&Aa.set(t,n)}function Ma(e,t){return Promise.resolve(ka.get(e)?.(t)??t.response)}const Na=Symbol.for(`mppx.fetch.wrapper`);let Pa;const Fa=new WeakMap;async function Y(e,t){let n=e?.attempt.settle;if(!n)return t.status!==`pending`;e.attempt.settle=void 0;let r=await n(t);return r||(e.attempt.settle=n),r}function Ia(e){let{acceptPayment:t,acceptPaymentPolicy:n=`always`,fetch:r=globalThis.fetch,maxPaymentRetries:i=3,methods:a,onChallenge:o,orderChallenges:s,transport:c=Ta()}=e,l=e.eventDispatcher??Ra(),u=t??Hi(a),d=io(r),f=async(e,t,r)=>{let p=ro(e,t?.headers),m=p.has(A.acceptPayment),h=lo(p,u),g=to(e,t,p),_=eo(e,t,p,h.header,m,n),v=await d(ao(_.input),_.init),y=no(_.init,await g);if(!await c.isPaymentRequired(v,y))return v;let b=t?.context,{context:ee,orderChallenges:x,...te}=y??{},S,C,ne,w;try{for(let n=0;n<i;n++){C=await c.getChallenges(v,y);let i=(await uo(Gi(C,a,h.entries),x??s))[0];if(!i){if(await Y(w,{challenges:C,response:v,status:`rejected`}),n>0)return v;throw Error(`No method found for challenges: ${C.map(e=>`${e.method}.${e.intent}`).join(`, `)}. Available: ${a.map(e=>`${e.name}.${e.intent}`).join(`, `)}`)}let u=i.challenge;S=u,ne=i.method,S.expires&&ui(S.expires,S.id);let p=go(v,_.input,_.input),m=w,g=Vr(u),ee=m?.method===i.method&&m?.key===g,re=!1;if(m){let e=await Y(m,{challenges:C,response:v,status:ee?`pending`:`rejected`});re=ee&&!e}w=re?m:void 0;let ie=Ua(async e=>{if(e===void 0&&re&&m)return m.promise;re&&m&&(await Y(m,{status:`rejected`}),w=void 0);let t=e??b;if(!Da(i.method))return co(u,i.method,t);let n={prepare:()=>Oa(i.method,{challenge:u,context:t,fetch:d,input:p})},r=n.prepare().then(()=>co(u,i.method,t,n));return w={attempt:n,key:e===void 0?g:void 0,method:i.method,promise:r},r}),T=await l.emit(`challenge.received`,Wa({challenge:u,challenges:C,createCredential:ie,init:t,input:e,method:i.method,response:v}))??(o?await o(S,{createCredential:ie}):void 0)??await ie(),ae=w;ae&&await ae.promise.catch(()=>void 0)!==T&&(await Y(ae,{status:`rejected`}),w=void 0),so(T),await l.emit(`credential.created`,Ga({challenge:u,credential:T,init:t,input:e,method:i.method,response:v})),v=await d(p,c.setCredential({...te,headers:_.headers},T,{challenge:u}));let oe=await c.isPaymentRequired(v,y);if(oe||(await Y(ae,{response:v,status:v.ok?`accepted`:`rejected`}),w=void 0),v.ok&&za(l,`payment.response`)&&await l.emit(`payment.response`,Ka({challenge:u,credential:T,init:t,input:e,method:i.method,response:v})),!oe)return v.ok?Ma(i.method,{challenge:u,credential:T,fetch:d,headers:_.headers,input:p,...r?{refetch:()=>f(ao(_.input),t,!1)}:{},response:v,signal:oo(e,t)}):v}C=void 0;try{C=await c.getChallenges(v,y)}catch{}return await Y(w,{challenges:C,response:v,status:`rejected`}),v}catch(n){throw await Y(w,{challenges:C,response:v,status:`rejected`}),await l.emit(`payment.failed`,qa({challenge:S,challenges:C,error:n,init:t,input:e,method:ne,response:v})),n}},p=(e,t)=>f(e,t,!0);return p[Na]=d,p}function La(e){let t=Object.getOwnPropertyDescriptor(globalThis,`fetch`);if(!t||!t.writable&&!t.set)throw Error(`globalThis.fetch is not writable`);Pa||=globalThis.fetch,globalThis.fetch=Ia({...e,acceptPaymentPolicy:e.acceptPaymentPolicy??(mo()?`same-origin`:`always`),fetch:globalThis.fetch})}function Ra(){let e={"*":new Set,"challenge.received":new Set,"credential.created":new Set,"payment.failed":new Set,"payment.response":new Set},t={async emit(t,n){switch(t){case`challenge.received`:{let r;for(let t of e[`challenge.received`]){let e=await Ba(t,n);if(typeof e==`string`&&e.length>0){r=e;break}}return await Ha(e[`*`],t,n),r}case`credential.created`:await Va(e[`credential.created`],n),await Ha(e[`*`],t,n);return;case`payment.failed`:await Va(e[`payment.failed`],n),await Ha(e[`*`],t,n);return;case`payment.response`:await Va(e[`payment.response`],n),await Ha(e[`*`],t,n);return}},on:(t,n)=>{switch(t){case`*`:case`challenge.received`:case`credential.created`:case`payment.failed`:case`payment.response`:return e[t].add(n),()=>e[t].delete(n);default:throw Error(`Unknown client event "${String(t)}".`)}}};return Fa.set(t,t=>e[t].size>0||e[`*`].size>0),t}function za(e,t){return Fa.get(e)?.(t)??!0}async function Ba(e,t){try{return await e(t)}catch{return}}async function Va(e,t){for(let n of e)try{await n(t)}catch{}}async function Ha(e,t,n){await Va(e,Object.freeze({name:t,payload:n}))}function Ua(e){let t;return n=>(t??=e(n),t)}function Wa(e){return Object.freeze({challenge:X(e.challenge),challenges:e.challenges.map(e=>X(e)),createCredential:e.createCredential,init:Ja(e.init),input:Ya(e.input),method:Xa(e.method),response:Za(e.response)})}function Ga(e){return Object.freeze({challenge:X(e.challenge),credential:e.credential,init:Ja(e.init),input:Ya(e.input),method:Xa(e.method),...e.response===void 0?{}:{response:Za(e.response)}})}function Ka(e){return Object.freeze({challenge:X(e.challenge),credential:e.credential,init:Ja(e.init),input:Ya(e.input),method:Xa(e.method),response:Za(e.response)})}function qa(e){return Object.freeze({...e.challenge?{challenge:X(e.challenge)}:{},...e.challenges?{challenges:e.challenges.map(e=>X(e))}:{},error:e.error,init:Ja(e.init),input:Ya(e.input),...e.method?{method:Xa(e.method)}:{},...e.response===void 0?{}:{response:Za(e.response)}})}function Ja(e){if(e)return $a({...e,...e.headers?{headers:new Headers(e.headers)}:{}})}function Ya(e){if(e instanceof Request)try{return e.clone()}catch{return e}return e instanceof URL?new URL(e):e}function Xa(e){return $a(Object.assign({},e))}function Za(e){return e instanceof Response?e.clone():X(e)}function X(e){try{return Qa(structuredClone(e))}catch{return $a(e)}}function Qa(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))Qa(t);return e}function $a(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function eo(e,t,n,r,i,a){let o=!!r&&!i&&fo(e,a);if(!o)return{headers:n,init:t,input:e};let s=new Headers(e instanceof Request?e.headers:void 0);return n.forEach((e,t)=>{s.set(t,e)}),s.set(A.acceptPayment,r),t?(t.headers=s,{headers:s,init:t,input:e}):{headers:s,init:o?{headers:s}:void 0,input:e}}function to(e,t,n){if(e instanceof Request&&t?.body===void 0&&e.body&&!e.bodyUsed){if(!n.has(`mcp-method`)){let e=n.get(`accept`)?.toLowerCase()??``;if(!e.includes(`application/json`)||!e.includes(`text/event-stream`))return}try{return e.clone().text().catch(()=>void 0)}catch{return}}}function no(e,t){return t===void 0?e:{...e,body:t}}function ro(e,t){return t?new Headers(t):new Headers(e instanceof Request?e.headers:void 0)}function io(e){let t=e;for(;t[Na];)t=t[Na];return t}function ao(e){if(!(e instanceof Request)||!e.body||e.bodyUsed)return e;try{return e.clone()}catch{return e}}function oo(e,t){return t?.signal??(e instanceof Request?e.signal:void 0)}function so(e){if(!e.trim())throw Error(`Credential header value must be non-empty`);if(e.includes(`\r`)||e.includes(`
|
|
13
|
+
`))throw Error(`Credential header value contains illegal newline characters`)}async function co(e,t,n,r){let i=t.context&&n!==void 0?t.context.parse(n):void 0,a=i===void 0?{challenge:e}:{challenge:e,context:i};return r&&ja(t,a,r),t.createCredential(a)}function lo(e,t){let n=e.get(A.acceptPayment);if(!n)return t;try{return{...t,entries:Ui(n),header:n}}catch{return t}}async function uo(e,t){return t?t(e):e}function fo(e,t){if(t===`always`)return!0;if(t===`never`)return!1;let n=ho(e);return t===`same-origin`?!mo()||n.origin===globalThis.location.origin:t.origins.some(e=>po(n,e))}function po(e,t){if(t.startsWith(`*.`)){let n=t.slice(1);return e.hostname.endsWith(n)||e.hostname===t.slice(2)}return e.origin===new URL(t).origin}function mo(){return globalThis.location!==void 0}function ho(e){return e instanceof URL?e:e instanceof Request?new URL(e.url):new URL(e,mo()?globalThis.location.href:void 0)}function go(e,t,n){if(!e.url)return t;let r=new URL(e.url),i=ho(n);if(r.origin!==i.origin)throw Error(`Refusing to send payment credential across redirect from ${i.origin} to ${r.origin}`);return e.url}function _o(){let e=new Uint8Array(64);return crypto.getRandomValues(e),Object.freeze({created:Math.floor(Date.now()/1e3),nonce:Zt(e,{pad:!1,url:!0})})}function vo(...e){return{protocol:`composed`,async sign(t,n=_o()){for(let r of e)t=await r.sign(t,n);return t}}}function yo(e,t){return async(n,r)=>e(await t.sign(new Request(n,r)))}function bo(e){let{attestation:t,maxPaymentRetries:n,onChallenge:r,orderChallenges:i,polyfill:a=!0,acceptPaymentPolicy:o=a&&globalThis.location!==void 0?`same-origin`:`always`,transport:s=Ta()}=e,c=e.fetch??globalThis.fetch,l=t?xo(c,t):c,u=e.methods.flat(),d=Hi(u,e.paymentPreferences),f=Ra(),p=r,m={acceptPayment:d,acceptPaymentPolicy:o,...(e.fetch||t)&&{fetch:l},eventDispatcher:f,...n!==void 0&&{maxPaymentRetries:n},...p&&{onChallenge:p},...i&&{orderChallenges:i},methods:u,transport:s},h=Ia(m);a&&La(m);function g(e){return f.on(`challenge.received`,e)}function _(e){return f.on(`credential.created`,e)}function v(e){return f.on(`payment.failed`,e)}function y(e){return f.on(`payment.response`,e)}async function b(e,t){let n=Do(e),r=await s.getChallenges(e,t?.request),a=Object.freeze(r.map(e=>Z(e))),o=Ao(d.entries,t?.acceptPayment),c,l;try{let e=(await jo(Gi(r,u,o),t?.orderChallenges??i))[0];if(!e)throw Error(`No method found for challenges: ${r.map(e=>`${e.method}.${e.intent}`).join(`, `)}. Available: ${u.map(e=>`${e.name}.${e.intent}`).join(`, `)}`);let d=e.challenge;c=a[e.index],l=e.method,c.expires&&ui(c.expires,c.id);let p=c,m=l,h=So(async e=>{try{p.expires&&ui(p.expires,p.id);let t=So(t=>Mo(p,m,t??e)),i=await f.emit(`challenge.received`,Co({challenge:p,challenges:r,createCredential:t,method:m,response:n}))??await t();return so(i),await f.emit(`credential.created`,wo({challenge:p,credential:i,method:m,response:n})),i}catch(e){throw await f.emit(`payment.failed`,To({challenge:p,challenges:r,error:e,method:m,response:n})),e}});return Object.freeze({challenge:p,challenges:a,createCredential:h,method:Eo(m),setCredential(e,t){return so(t),s.setCredential(e,t,{challenge:d})}})}catch(e){throw await f.emit(`payment.failed`,To({challenge:c,challenges:r,error:e,method:l,response:n})),e}}return{fetch:h,rawFetch:c,methods:u,transport:s,on:f.on,onChallengeReceived:g,onCredentialCreated:_,onPaymentFailed:v,onPaymentResponse:y,preparePayment:b,async createCredential(e,t,n){return(await b(e,n)).createCredential(t)}}}function xo(e,t){let n=Object.values(t);if(n.length===0)throw TypeError(`Mppx client attestation must configure at least one signer.`);return yo(e,vo(...n))}function So(e){let t;return n=>(t??=e(n),t)}function Co(e){return Object.freeze({challenge:Z(e.challenge),challenges:e.challenges.map(e=>Z(e)),createCredential:e.createCredential,method:Eo(e.method),response:Do(e.response)})}function wo(e){return Object.freeze({challenge:Z(e.challenge),credential:e.credential,method:Eo(e.method),response:Do(e.response)})}function To(e){return Object.freeze({...e.challenge?{challenge:Z(e.challenge)}:{},...e.challenges?{challenges:e.challenges.map(e=>Z(e))}:{},error:e.error,...e.method?{method:Eo(e.method)}:{},response:Do(e.response)})}function Eo(e){return ko(Object.assign({},e))}function Do(e){if(e instanceof Response)try{return e.clone()}catch{return new Response(null,{headers:e.headers,status:e.status,statusText:e.statusText})}return Z(e)}function Z(e){try{let t=structuredClone(e);if(e&&t&&typeof e==`object`&&typeof t==`object`)for(let n of Object.getOwnPropertySymbols(e)){let r=Object.getOwnPropertyDescriptor(e,n);r&&Object.defineProperty(t,n,r)}return Oo(t)}catch{return ko(e)}}function Oo(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))Oo(t);return e}function ko(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function Ao(e,t){return t?typeof t==`string`?Ui(t):t:e}async function jo(e,t){return t?t(e):e}async function Mo(e,t,n){let r=t.context&&n!==void 0?t.context.parse(n):void 0;return t.createCredential(r===void 0?{challenge:e}:{challenge:e,context:r})}const No=2048;var Q=class extends Error{name=`MppResourceUrlError`};function Po(e){if(e.length>No)throw new Q(`MPP resource URL is too long`);if(Array.from(e).some(e=>{let t=e.charCodeAt(0);return e===`\\`||t<=32||t===127}))throw new Q(`MPP resource URL is invalid`);let t=e.match(/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(?:#.*)?$/);if(!t)throw new Q(`MPP resource URL must be absolute`);let n;try{n=new URL(e)}catch{throw new Q(`MPP resource URL is invalid`)}if(n.username||n.password)throw new Q(`MPP resource URL must not contain credentials`);let r=n.protocol.toLowerCase();if(r!==`https:`&&!(r===`http:`&&Fo(n.hostname)))throw new Q(`MPP resource URL must use HTTPS or loopback HTTP`);let i=t[3]||`/`,a=t[4]||``,o=`${r}//${n.hostname.toLowerCase()}${n.port?`:${n.port}`:``}${i}${a}`;if(o.length>No)throw new Q(`MPP resource URL is too long`);return o}function Fo(e){let t=e.toLowerCase();if(t===`localhost`||t===`[::1]`)return!0;let n=t.split(`.`);return n.length===4&&n[0]===`127`&&n.every(e=>/^\d{1,3}$/.test(e)&&Number(e)<=255)}const Io=/^[A-Za-z0-9_-]+$/,Lo=/^0x[0-9a-fA-F]{40}$/,Ro=/^(?:0|[1-9]\d*)$/,zo=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/,Bo=/^sha-256=:([A-Za-z0-9+/]{43}=):$/,Vo=/^sha-256=([A-Za-z0-9+/]{43}=)$/,Ho=new Set([`mpp_challenge_not_payable`,`mpp_network_mismatch`,`mpp_counterparty_rail_not_found`]),Uo=`mpp_counterparty_rail_not_found`,Wo=`mpp_network_mismatch`,Go=U({type:G(`authorization`),from:V(),to:V(),value:V(),validAfter:V(),validBefore:V(),nonce:V(),signature:V()}),Ko={amount:V(),currency:V(),description:K(V()),externalId:K(V()),recipient:V()},qo=U({...Ko,methodDetails:U({chainId:hr(),credentialTypes:Sr(G(`authorization`)),decimals:G(6),permit2Address:K(V()),splits:K(br())})}),Jo=U({...Ko,methodDetails:U({type:G(`evm`),evm:U({chainId:hr(),credentialTypes:K(Sr(G(`authorization`))),decimals:G(6),permit2Address:K(V()),splits:K(br())})})}),Yo=di({name:`evm`,intent:`charge`,schema:{credential:{payload:Go},request:qo}}),Xo=di({name:`usdc`,intent:`charge`,schema:{credential:{payload:Go},request:Jo}});var Zo=class extends Error{intentId;status;reasons;expiresAt;constructor(e,t){super(e),this.name=`MppPaymentError`,this.intentId=t.intentId,this.status=t.status,this.reasons=t.reasons,this.expiresAt=t.expiresAt}},$=class extends Error{intentId;reasons;constructor(e,t={}){super(e,t.cause===void 0?void 0:{cause:t.cause}),this.name=`MppFetchPaymentError`,this.intentId=t.intentId,this.reasons=t.reasons??[]}},Qo=class extends ${accountId;requiredNetworks;constructor(e,t,n){super(`Account ${e} cannot pay on the MPP challenge's required network${t.length===1?``:`s`}: ${t.join(`, `)}`,{reasons:n}),this.name=`MppNetworkMismatchError`,this.accountId=e,this.requiredNetworks=t}},$o=class extends ${recipient;network;constructor(e,t,n){super(`No saved Catena counterparty rail can pay ${e} on ${t}`,{reasons:n}),this.name=`MppCounterpartyNotFoundError`,this.recipient=e,this.network=t}},es=class extends ${expiresAt;constructor(e,t,n){super(`The MPP payment is awaiting human approval (intent ${e}); retry the request after approval`,{intentId:e,reasons:t}),this.name=`MppApprovalPendingError`,this.expiresAt=n}},ts=class extends ${status;constructor(e,t,n){super(`Catena ${t} the MPP payment (intent ${e})`,{intentId:e,reasons:n}),this.name=`MppPaymentDeclinedError`,this.status=t}},ns=class extends ${method;atomicAmount;network;recipient;resourceUrl;constructor(e,t,n,r){super(`The MPP payment could not be confirmed (intent ${e}); reconcile it with getIntent("${e}") before paying again`,{intentId:e,cause:r}),this.name=`MppSubmitInterruptedError`,this.method=t.method,this.atomicAmount=t.atomicAmount,this.network=t.network,this.recipient=t.recipient,this.resourceUrl=n}},rs=class extends ${receipt;constructor(e,t){super(`The MPP payment completed (intent ${e.intentId}) but the post-payment continuation failed; inspect getIntent("${e.intentId}") before retrying manually`,{intentId:e.intentId,cause:t}),this.name=`MppRetryFailedError`,this.receipt=e}};function is(e){let t=async({challenge:t})=>(await hs(e,ms(t,e.maxAtomicAmount))).credential;return[fi(Yo,{canHandleChallenge:({challenge:t})=>gs(`evm`,t,e.maxAtomicAmount)!==void 0,createCredential:t}),fi(Xo,{canHandleChallenge:({challenge:t})=>gs(`usdc`,t,e.maxAtomicAmount)!==void 0,createCredential:t})]}const as=Object.assign(e=>is(e),{charge:is});function os(e,t){let n=(t.baseFetch??globalThis.fetch).bind(globalThis),r={client:e,accountId:t.accountId,...t.maxAtomicAmount!==void 0&&{maxAtomicAmount:t.maxAtomicAmount}},i=bo({methods:as(r),fetch:n,polyfill:!1});return async(a,o)=>{let s=await n(a,o);if(s.status!==402||!s.headers.has(`WWW-Authenticate`))return s;let c;try{c=await i.transport.getChallenges(s,o)}catch{return s}if(c.length===0)return s;if(!T(a,o))throw new $(`The request body cannot be replayed after MPP payment; buffer it as a string, URLSearchParams, Blob, ArrayBuffer, or typed array`);let l=us(a,s),{payment:u,prepared:d}=await ss(i,s,c,o,r,l),f={intentId:u.intentId,...u.terms,resourceUrl:l};await fs(f,async()=>{await t.onPayment?.(f)});let p=ae(a,o),m=d.setCredential({...o,headers:p},u.credential),h=await fs(f,()=>n(a,m));if(h.status===402)throw new rs(f,Error(`The paid MPP retry still requires payment`));return ps(e,f.intentId,h),h}}async function ss(e,t,n,r,i,a){let o,s=[];for(let c=0;c<5;c+=1){let l={missing:!1},u;try{u=await e.preparePayment(t,{request:r,orderChallenges:e=>{o??=e.slice(0,5).map(e=>e.index);let t=o[c],n=e.find(e=>e.index===t);return l.missing=n===void 0,n===void 0?[]:[n]}})}catch(e){let t=o??[];if(t.length===0)throw n.some(e=>_s(e,i.maxAtomicAmount))?new $(`Every supported charge in the MPP challenge costs more than the caller's maximum amount`,{cause:e}):new $(`The MPP challenge offers no Catena-supported native USDC charge`,{cause:e});if(l.missing&&s.length>0){if(c+1<t.length)continue;break}throw new $(`The selected MPP challenge could not be prepared`,{cause:e})}let d=ms(u.challenge,i.maxAtomicAmount);try{return{payment:await hs(i,d,a),prepared:u}}catch(e){if(e instanceof ee&&e.code!==void 0&&Ho.has(e.code))s.push({error:e,terms:d.terms});else throw cs(e,d.terms,a)}if(c+1>=(o?.length??0))break}throw ls(i.accountId,s)}function cs(e,t,n){if(e instanceof se&&e.outcome===`unknown`)return new ns(e.intentId,t,n,e);if(!(e instanceof Zo))return e;switch(e.status){case`pending`:return new es(e.intentId,e.reasons,e.expiresAt);case`blocked`:case`failed`:return new ts(e.intentId,e.status,e.reasons);case`processing`:case`completed`:return new $(e.message,{intentId:e.intentId,reasons:e.reasons,cause:e})}return S(e.status)}function ls(e,t){let n=t.filter(e=>e.error.code===Uo),r=t.filter(e=>e.error.code===Wo),i=t.filter(e=>e.error.code!==Uo&&e.error.code!==Wo),a=[...new Set([...n,...r,...i].map(e=>e.error.message))],o=n.find(e=>e.error.status===404);return o?new $o(o.terms.recipient,o.terms.network,a):r.length>0&&n.length===0?new Qo(e,[...new Set(r.map(e=>e.terms.network))],a):new $(`No supported candidate in the MPP challenge is payable from this account`,{reasons:a})}function us(e,t){let n;try{n=typeof e==`string`?ds(e):e instanceof URL?e:new URL(e.url)}catch(e){throw new $(`The MPP resource request URL must be absolute`,{cause:e})}let r;try{r=new URL(t.url||n.href)}catch(e){throw new $(`The final MPP resource URL is invalid`,{cause:e})}if(r.origin!==n.origin)throw new $(`Refusing to pay after a cross-origin redirect from ${n.origin} to ${r.origin}`);try{return Po(t.url||n.href)}catch(e){throw new $(`The final MPP resource URL cannot be bound to a payment intent`,{cause:e})}}function ds(e){try{return new URL(e)}catch{return new URL(e,globalThis.location.href)}}async function fs(e,t){try{return await t()}catch(t){throw new rs(e,t)}}function ps(e,t,n){try{let r=gi(n);if(!fe.test(r.reference))return;le(e,t,r.reference)}catch{return}}function ms(e,t){let n=e.method;if(n!==`evm`&&n!==`usdc`)throw Error(`Unsupported Catena MPP challenge ${e.method}/${e.intent}`);let r=gs(n,e,t);if(r===void 0)throw Error(`Catena MPP charge challenge failed validation`);return{challenge:{id:e.id,realm:e.realm,method:n,intent:`charge`,request:r.request,...e.description!==void 0&&{description:e.description},...e.digest!==void 0&&{digest:e.digest},expires:r.expires,...r.header!==void 0&&{header:r.header},...e.opaque!==void 0&&{opaque:e.opaque}},terms:r.terms}}async function hs(e,t,n){let r=await e.client.submitIntent({action:{type:`mpp`,accountId:e.accountId,challenge:t.challenge,...n!==void 0&&{resource:{url:n}}}});return{...t,credential:ks(r,t.challenge),intentId:r.id}}function gs(e,t,n){if(t.method!==e||t.intent!==`charge`)return;let r=ws(t);if(r===void 0)return;let i=e===`evm`?bs(t.request,n):xs(t.request,n);return i===void 0?void 0:{...r,terms:i}}function _s(e,t){if(t===void 0||e.method!==`evm`&&e.method!==`usdc`)return!1;let n=gs(e.method,e,void 0);return n!==void 0&&BigInt(n.terms.atomicAmount)>t}function vs(e,t){return Ds(e.amount)&&(t===void 0||BigInt(e.amount)<=t)&&Os(e.currency)&&Os(e.recipient)&&(e.description===void 0||ys(e.description,1024))&&(e.externalId===void 0||ys(e.externalId,256))}function ys(e,t){if(e.length>t)return!1;for(let t of e){let e=t.codePointAt(0);if(e!==void 0&&e>=55296&&e<=57343)return!1}return!0}function bs(e,t){let n=qo.safeParse(e);if(!n.success||!vs(n.data,t))return;let{amount:r,currency:i,methodDetails:a,recipient:o}=n.data,s=Cs(a.chainId,i);return Ss(a)&&a.credentialTypes.length===1&&s!==void 0?{method:`evm`,atomicAmount:r,network:s,recipient:o}:void 0}function xs(e,t){let n=Jo.safeParse(e);if(!n.success||!vs(n.data,t))return;let{amount:r,currency:i,methodDetails:a,recipient:o}=n.data,s=a.evm,c=Cs(s.chainId,i);return Ss(s)&&(s.credentialTypes===void 0||s.credentialTypes.length===1)&&c!==void 0?{method:`usdc`,atomicAmount:r,network:c,recipient:o}:void 0}function Ss(e){return Number.isSafeInteger(e.chainId)&&e.chainId>=1&&(e.permit2Address===void 0||Os(e.permit2Address))}function Cs(e,t){if(e===8453)return t.toLowerCase()===`0x833589fcd6edb6e08f4c7c32d4f71b54bda02913`?`eip155:8453`:void 0;if(e===84532)return t.toLowerCase()===`0x036cbd53842c5426634e7929541ec2318f3dcf7e`?`eip155:84532`:void 0}function ws(e){if(!Ts(e))return;let t=Date.parse(e.expires),n=t-Date.now();if(!Number.isFinite(t)||n<5e3||n>36e5)return;let r=j(e.request),i=new TextEncoder().encode(JSON.stringify({...e,request:r})).byteLength;return r.length>0&&r.length<=16384&&i<=32768?{request:r,expires:e.expires,header:e.header}:void 0}function Ts(e){return!(e.id.length<1||e.id.length>256||e.realm.length<1||e.realm.length>256||e.expires===void 0||!zo.test(e.expires)||e.description!==void 0&&e.description.length>1024||e.header!==void 0&&e.header!==`Payment-Authorization`||e.opaque!==void 0&&(e.opaque.length>8192||!Io.test(e.opaque))||e.digest!==void 0&&!Es(e.digest))}function Es(e){if(e.length>128)return!1;let t=Bo.exec(e)??Vo.exec(e);if(!t)return!1;try{let e=atob(t[1]);return e.length===32&&btoa(e)===t[1]}catch{return!1}}function Ds(e){return e.length<=78&&Ro.test(e)&&BigInt(e)>0n}function Os(e){return Lo.test(e)&>(e)}function ks(e,t){switch(e.status){case`completed`:{let n=_(e.data,`mpp`);if(n===void 0)throw Ms(`Catena MPP payment ${e.id} completed without an MPP credential`,e);if(!As(n,t))throw Ms(`Catena MPP payment ${e.id} completed with a credential that does not match the selected challenge; reconcile with client.getIntent("${e.id}") before another payment attempt`,e);return n}case`pending`:throw Ms(`Catena MPP payment ${e.id} is pending${Ns(e.reasons)}`,e);case`processing`:throw Ms(`Catena MPP payment ${e.id} is processing; if it was approved, re-run the paid request so a fresh challenge can consume the grant (polling never advances an approved payment); otherwise poll client.getIntent("${e.id}"), because an executing payment completes on its own`,e);case`blocked`:throw Ms(`Catena MPP payment ${e.id} was blocked${Ns(e.reasons)}`,e);case`failed`:throw Ms(`Catena MPP payment ${e.id} failed${Ns(e.reasons)}`,e)}return S(e.status)}function As(e,t){if(e.trim().length===0||e.includes(`\r`)||e.includes(`
|
|
14
|
+
`))return!1;let n;try{n=ii(e)}catch{return!1}let r=n.challenge;if(r.id!==t.id||r.realm!==t.realm||r.method!==t.method||r.intent!==t.intent||r.description!==t.description||r.digest!==t.digest||r.expires!==t.expires||r.header!==t.header||r.opaque!==t.opaque||j(r.request)!==t.request)return!1;let i=Go.safeParse(n.payload),a=t.method===`evm`?qo.safeParse(r.request):Jo.safeParse(r.request);if(!i.success||!a.success)return!1;let o=a.data.recipient;return Os(i.data.from)&&Os(i.data.to)&&i.data.to.toLowerCase()===o.toLowerCase()&&i.data.value===a.data.amount&&js(i.data.validAfter)&&js(i.data.validBefore)&&BigInt(i.data.validBefore)>BigInt(i.data.validAfter)&&/^0x[0-9a-fA-F]{64}$/.test(i.data.nonce)&&/^0x[0-9a-fA-F]{130}$/.test(i.data.signature)}function js(e){return e.length<=78&&Ro.test(e)}function Ms(e,t){return new Zo(e,{intentId:t.id,status:t.status,reasons:t.reasons,expiresAt:t.expiresAt})}function Ns(e){return e.length>0?`: ${e.join(`; `)}`:``}function Ps(e){return{intentId:e.intentId,method:e.method,amountAtomicUsdc:e.atomicAmount,recipient:e.recipient,network:e.network}}const Fs=/(?:^|,)\s*Payment(?![!#$%&'*+\-.^_`|~0-9A-Za-z])/i;function Is(e,t){de(e,`payment-authorization`)&&b(`--header cannot set Payment-Authorization; the payment loop attaches it after paying`),e.some(e=>e.name.toLowerCase()===`authorization`&&Fs.test(e.value))&&b(`--header cannot provide the Payment authentication scheme in Authorization; the payment loop attaches it after paying`),pe(e,t)}const Ls=v({url:x({description:`The paywalled URL to fetch (an MPP endpoint)`,required:!0,schema:E.pipe(E.string(),E.url())}),account:x({description:`Source wallet account id the payment draws from`,required:!0,schema:be}),maxAmount:x({description:`Refuse challenges above this USD amount (decimal string, e.g. 0.25). Policy limits still apply server-side.`,schema:E.pipe(E.string(),E.regex(/^\d+(\.\d{1,6})?$/))}),method:ne({description:`HTTP method for the request`,choices:[`GET`,`POST`]}),data:x({description:`Request body. Use @path to read a file or @- for stdin. Implies POST and a JSON content type unless overridden.`}),contentType:x({description:`Content-Type header for the request body (default application/json when --data is set)`}),output:x({description:`Write the full response body to this file (must be a regular file; written for any HTTP status — check .status). Without it .body is capped at 4000 characters; longer or non-UTF-8 bodies are saved to a file (path reported in .bodyPath)`}),header:ye({description:`Request header as "Name: Value" (repeatable, like curl -H); sent on both requests, except caller Authorization is replaced on the paid retry when MPP uses that field for its credential`,schema:w}),profile:te,json:ve}),Rs=xe({meta:{name:`mpp`,description:`Fetch a URL, paying its MPP challenge via USDC`},args:Ls.args,async run({args:e,rawArgs:t}){let n=Ls.parse(e,t),r=n.method??(n.data===void 0?`GET`:`POST`);n.data!==void 0&&r!==`POST`&&b(`--data cannot be sent with --method ${r}; a body requires POST`),n.contentType!==void 0&&n.data===void 0&&b(`--content-type has no effect without --data`),Is(n.header,n.contentType);let i=n.output===void 0?void 0:ue(n.output),a=n.data===void 0?void 0:re(n.data),o=oe(n.header,n.contentType,a);await _e(n)(async e=>{let t,s=os(e,{accountId:n.account,...n.maxAmount!==void 0&&{maxAtomicAmount:ie(n.maxAmount)},onPayment:e=>{t=e}}),c;try{c=await s(n.url,{method:r,...a!==void 0&&{body:a},...o!==void 0&&{headers:o}})}catch(e){if(e instanceof ns&&e.intentId!==void 0)throw Error(ge(e.intentId,n.profile),{cause:e});if(e instanceof rs)return{status:null,paid:!0,retryFailed:!0,payment:Ps(e.receipt),error:e.message};if(e instanceof Qo){let t=e.requiredNetworks.map(e=>me(e)??e);return{status:null,paid:!1,retryFailed:!1,networkMismatch:{account:e.accountId,requiredNetworks:t,requiredNetworkIds:[...e.requiredNetworks]},error:`${e.message}. Re-run with --account set to a wallet account on ${t.join(` or `)} (your account ids are in \`catena accounts list${ce(n.profile)}\`).`}}if(e instanceof $o){let t=C(e.recipient,e.network,void 0,n.profile);return{status:null,paid:!1,retryFailed:!1,counterpartyNotFound:{recipient:e.recipient,network:me(e.network)??e.network,networkId:e.network,createCommand:t,nameIsPlaceholder:!0},error:`${e.message}. Add it, then re-run:\n ${t}\n(counterparty creation may require approval per your policy)`}}if(e instanceof es)return{status:null,paid:!1,retryFailed:!1,approvalPending:{intentId:e.intentId,expiresAt:e.expiresAt,reasons:[...e.reasons]},error:e.message};throw e}let l={status:c.status,paid:t!==void 0,retryFailed:!1,...t!==void 0&&{payment:Ps(t)}},u;try{u=Buffer.from(await c.arrayBuffer())}catch(e){let r=t===void 0?``:`; the payment completed — inspect it with \`catena intents get ${t.intentId}${ce(n.profile)}\` before any manual retry`;return{...l,error:`failed to read the response body: ${y(e)}${r}`}}return{...l,...he(u,t?.intentId,i)}},{exitCode:e=>+(`error`in e)})}});export{Rs as mppCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./utils-
|
|
1
|
+
import{t as e}from"./utils-CrMT-n--.mjs";import*as t from"crypto";const n=async n=>{let{content:r,publicKey:i,privateKey:a}=n,o=t.createPrivateKey({key:e({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:i}),format:`jwk`}),s=t.createSign(`SHA256`);return s.write(Buffer.from(r)),s.end(),s.sign(o,`hex`)};export{n as signWithApiKey};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{O as e,S as t,b as n,d as r,g as i,i as a,m as o,n as s,p as c,r as l,v as u,x as d}from"./dist-w03V0QPF.mjs";import{t as f}from"./hmac-CXnNqvhW.mjs";
|
|
2
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
const p=BigInt(0),m=BigInt(1);function h(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function g(e,t,n=``){let r=d(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function _(e){let t=e.toString(16);return t.length&1?`0`+t:t}function v(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?p:BigInt(`0x`+e)}function y(e){return v(i(e))}function b(e){return r(e),v(i(Uint8Array.from(e).reverse()))}function x(e,t){return n(e.toString(16).padStart(t*2,`0`))}function S(e,t){return x(e,t).reverse()}function C(e,t,r){let i;if(typeof t==`string`)try{i=n(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(d(t))i=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let a=i.length;if(typeof r==`number`&&a!==r)throw Error(e+` of length `+r+` expected, got `+a);return i}const w=e=>typeof e==`bigint`&&p<=e;function T(e,t,n){return w(e)&&w(t)&&w(n)&&t<=e&&e<n}function ee(e,t,n,r){if(!T(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function E(e){let t=0;for(;e>p;e>>=m,t+=1);return t}const D=e=>(m<<BigInt(e))-m;function te(e,t,n){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof n!=`function`)throw Error(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=e=>Uint8Array.of(e),a=r(e),o=r(e),s=0,c=()=>{a.fill(1),o.fill(0),s=0},l=(...e)=>n(o,a,...e),d=(e=r(0))=>{o=l(i(0),e),a=l(),e.length!==0&&(o=l(i(1),e),a=l())},f=()=>{if(s++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,n=[];for(;e<t;){a=l();let t=a.slice();n.push(t),e+=a.length}return u(...n)};return(e,t)=>{c(),d(e);let n;for(;!(n=t(f()));)d();return c(),n}}function ne(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function O(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const k=BigInt(0),A=BigInt(1),j=BigInt(2),M=BigInt(3),re=BigInt(4),N=BigInt(5),P=BigInt(7),ie=BigInt(8),ae=BigInt(9),oe=BigInt(16);function F(e,t){let n=e%t;return n>=k?n:t+n}function se(e,t){if(e===k)throw Error(`invert: expected non-zero number`);if(t<=k)throw Error(`invert: expected positive modulus, got `+t);let n=F(e,t),r=t,i=k,a=A,o=A,s=k;for(;n!==k;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==A)throw Error(`invert: does not exist`);return F(i,t)}function ce(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function le(e,t){let n=(e.ORDER+A)/re,r=e.pow(t,n);return ce(e,r,t),r}function ue(e,t){let n=(e.ORDER-N)/ie,r=e.mul(t,j),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,j),i),s=e.mul(a,e.sub(o,e.ONE));return ce(e,s,t),s}function de(e){let t=I(e),n=fe(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+P)/oe;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return ce(e,p,t),p}}function fe(e){if(e<M)throw Error(`sqrt is not defined for small field`);let t=e-A,n=0;for(;t%j===k;)t/=j,n++;let r=j,i=I(e);for(;ve(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return le;let a=i.pow(r,t),o=(t+A)/j;return function(e,r){if(e.is0(r))return r;if(ve(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=A<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function pe(e){return e%re===M?le:e%ie===N?ue:e%oe===ae?de(e):fe(e)}const me=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function he(e){return ne(e,me.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function ge(e,t,n){if(n<k)throw Error(`invalid exponent, negatives unsupported`);if(n===k)return e.ONE;if(n===A)return t;let r=e.ONE,i=t;for(;n>k;)n&A&&(r=e.mul(r,i)),i=e.sqr(i),n>>=A;return r}function _e(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function ve(e,t){let n=(e.ORDER-A)/j,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function ye(e,t){t!==void 0&&o(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function I(e,t,n=!1,r={}){if(e<=k)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=ye(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:D(c),ZERO:k,ONE:A,allowedLengths:s,create:t=>F(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return k<=t&&t<e},is0:e=>e===k,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&A)===A,neg:t=>F(-t,e),eql:(e,t)=>e===t,sqr:t=>F(t*t,e),add:(t,n)=>F(t+n,e),sub:(t,n)=>F(t-n,e),mul:(t,n)=>F(t*n,e),pow:(e,t)=>ge(d,e,t),div:(t,n)=>F(t*se(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>se(t,e),sqrt:a||(t=>(u||=pe(e),u(d,t))),toBytes:e=>n?S(e,l):x(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?b(t):y(t);if(o&&(i=F(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>_e(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function be(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function xe(e){let t=be(e);return t+Math.ceil(t/2)}function Se(e,t,n=!1){let r=e.length,i=be(t),a=xe(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=F(n?b(e):y(e),t-A)+A;return n?S(o,i):x(o,i)}
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
+
const L=BigInt(0),R=BigInt(1);function z(e,t){let n=t.negate();return e?n:t}function Ce(e,t){let n=_e(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function we(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Te(e,t){we(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:D(e),maxNumber:i,shiftBy:BigInt(e)}}function Ee(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=R);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function De(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function Oe(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const ke=new WeakMap,Ae=new WeakMap;function B(e){return Ae.get(e)||1}function je(e){if(e!==L)throw Error(`invalid wNAF`)}var Me=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>L;)t&R&&(n=n.add(r)),r=r.double(),t>>=R;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Te(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Te(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=Ee(n,e,a);n=o,c?i=i.add(z(u,t[d])):r=r.add(z(l,t[s]))}return je(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Te(e,this.bits);for(let e=0;e<i.windows&&n!==L;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=Ee(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return je(n),r}getPrecomputes(e,t,n){let r=ke.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),ke.set(t,r))),r}cached(e,t,n){let r=B(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=B(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){we(t,this.bits),Ae.set(e,t),ke.delete(e)}hasCache(e){return B(e)!==1}};function Ne(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>L||r>L;)n&R&&(a=a.add(i)),r&R&&(o=o.add(i)),i=i.double(),n>>=R,r>>=R;return{p1:a,p2:o}}function Pe(e,t,n,r){De(n,e),Oe(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=E(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=D(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Fe(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return he(t),t}return I(e,{isLE:n})}function Ie(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>L))throw Error(`CURVE.${e} must be positive bigint`)}let i=Fe(t.p,n.Fp,r),a=Fe(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
+
const Le=(e,t)=>(e+(e>=0?t:-t)/ze)/t;function Re(e,t,n){let[[r,i],[a,o]]=t,s=Le(o*e,n),c=Le(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<W,f=u<W;d&&(l=-l),f&&(u=-u);let p=D(Math.ceil(E(n)/2))+G;if(l<W||l>=p||u<W||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function V(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function H(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return h(n.lowS,`lowS`),h(n.prehash,`prehash`),n.format!==void 0&&V(n.format),n}const U={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=U;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=_(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?_(i.length/2|128):``;return _(e)+a+i+t},decode(e,t){let{Err:n}=U,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=U;if(e<W)throw new t(`integer: negative integers are not allowed`);let n=_(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=U;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return y(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=U,i=C(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=U,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},W=BigInt(0),G=BigInt(1),ze=BigInt(2),K=BigInt(3),Be=BigInt(4);function q(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=C(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function Ve(e,t={}){let n=Ie(`weierstrass`,e,t),{Fp:r,Fn:a}=n,o=n.CURVE,{h:s,n:c}=o;ne(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:l}=t;if(l&&(!r.is0(o.a)||typeof l.beta!=`bigint`||!Array.isArray(l.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=Ue(r,a);function f(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,n){let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);if(h(n,`isCompressed`),n){f();let e=!r.isOdd(a);return u(He(e),o)}return u(Uint8Array.of(4),o,r.toBytes(a))}function m(e){g(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,i=e.length,a=e[0],o=e.subarray(1);if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=y(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!b(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let _=t.toBytes||p,v=t.fromBytes||m;function y(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,o.a)),o.b)}function b(e,t){let n=r.sqr(t),i=y(e);return r.eql(n,i)}if(!b(o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let x=r.mul(r.pow(o.a,K),Be),S=r.mul(r.sqr(o.b),BigInt(27));if(r.is0(r.add(x,S)))throw Error(`bad curve params: a or b`);function w(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function T(e){if(!(e instanceof k))throw Error(`ProjectivePoint expected`)}function ee(e){if(!l||!l.basises)throw Error(`no endo`);return Re(e,l.basises,a.ORDER)}let E=O((e,t)=>{let{X:n,Y:i,Z:a}=e;if(r.eql(a,r.ONE))return{x:n,y:i};let o=e.is0();t??=o?r.ONE:r.inv(a);let s=r.mul(n,t),c=r.mul(i,t),l=r.mul(a,t);if(o)return{x:r.ZERO,y:r.ZERO};if(!r.eql(l,r.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),D=O(e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!b(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function te(e,t,n,i,a){return n=new k(r.mul(n.X,e),n.Y,n.Z),t=z(i,t),n=z(a,n),t.add(n)}class k{constructor(e,t,n){this.X=w(`x`,e),this.Y=w(`y`,t,!0),this.Z=w(`z`,n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof k)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?k.ZERO:new k(t,n,r.ONE)}static fromBytes(e){let t=k.fromAffine(v(g(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return k.fromBytes(C(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return j.createCache(this,e),t||this.multiply(K),this}assertValidity(){D(this)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){T(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new k(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=o,n=r.mul(t,K),{X:i,Y:a,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(a,a),p=r.mul(s,s),m=r.mul(i,a);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(a,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new k(c,l,u)}add(e){T(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=o.a,p=r.mul(o.b,K),m=r.mul(t,a),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(a,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(a,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new k(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(k.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,i,o=e=>j.cached(this,e,e=>Ce(k,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=ee(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=te(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return Ce(k,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!a.isValid(e))throw Error(`invalid scalar: out of range`);if(e===W||r.is0())return k.ZERO;if(e===G)return r;if(j.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=ee(e),{p1:s,p2:c}=Ne(k,r,i,o);return te(n.beta,s,c,t,a)}return j.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return E(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return s===G?!0:e?e(k,this):j.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:e}=t;return s===G?this:e?e(k,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return h(e,`isCompressed`),this.assertValidity(),_(k,this,e)}toHex(e=!0){return i(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return Ce(k,e)}static msm(e,t){return Pe(k,a,e,t)}static fromPrivateKey(e){return k.BASE.multiply(q(a,e))}}k.BASE=new k(o.Gx,o.Gy,r.ONE),k.ZERO=new k(r.ZERO,r.ONE,r.ZERO),k.Fp=r,k.Fn=a;let A=a.BITS,j=new Me(k,t.endo?Math.ceil(A/2):A);return k.BASE.precompute(8),k}function He(e){return Uint8Array.of(e?2:3)}function Ue(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function We(e,n={}){let{Fn:r}=e,i=n.randomBytes||t,a=Object.assign(Ue(e.Fp,r),{seed:xe(r.ORDER)});function o(e){try{return!!q(r,e)}catch{return!1}}function s(t,n){let{publicKey:r,publicKeyUncompressed:i}=a;try{let a=t.length;return n===!0&&a!==r||n===!1&&a!==i?!1:!!e.fromBytes(t)}catch{return!1}}function c(e=i(a.seed)){return Se(g(e,a.seed,`seed`),r.ORDER)}function l(t,n=!0){return e.BASE.multiply(q(r,t)).toBytes(n)}function u(e){let t=c(e);return{secretKey:t,publicKey:l(t)}}function d(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:n,publicKey:i,publicKeyUncompressed:o}=a;if(r.allowedLengths||n===i)return;let s=C(`key`,t).length;return s===i||s===o}function f(t,n,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(n)===!1)throw Error(`second arg must be public key`);let a=q(r,t);return e.fromHex(n).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:l,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:o,randomPrivateKey:c,normPrivateKeyToScalar:e=>q(r,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:a})}function Ge(e,r,a={}){c(r),ne(a,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let o=a.randomBytes||t,s=a.hmac||((e,...t)=>f(r,e,u(...t))),{Fp:l,Fn:p}=e,{ORDER:m,BITS:h}=p,{keygen:_,getPublicKey:v,getSharedSecret:b,utils:x,lengths:S}=We(e,a),w={prehash:!1,lowS:typeof a.lowS==`boolean`&&a.lowS,format:void 0,extraEntropy:!1},T=`compact`;function E(e){return e>m>>G}function O(e,t){if(!p.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function k(e,t){V(t);let n=S.signature;return g(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class A{constructor(e,t,n){this.r=O(`r`,e),this.s=O(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=T){k(e,t);let n;if(t===`der`){let{r:t,s:n}=U.toSig(g(e));return new A(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=p.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new A(p.fromBytes(i),p.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(n(e),t)}addRecoveryBit(e){return new A(this.r,this.s,e)}recoverPublicKey(t){let n=l.ORDER,{r,s:i,recovery:a}=this;if(a==null||![0,1,2,3].includes(a))throw Error(`recovery id invalid`);if(m*ze<n&&a>1)throw Error(`recovery id is ambiguous for h>1 curve`);let o=a===2||a===3?r+m:r;if(!l.isValid(o))throw Error(`recovery id 2 or 3 invalid`);let s=l.toBytes(o),c=e.fromBytes(u(He(!(a&1)),s)),d=p.inv(o),f=M(C(`msgHash`,t)),h=p.create(-f*d),g=p.create(i*d),_=e.BASE.multiplyUnsafe(h).add(c.multiplyUnsafe(g));if(_.is0())throw Error(`point at infinify`);return _.assertValidity(),_}hasHighS(){return E(this.s)}toBytes(e=T){if(V(e),e===`der`)return n(U.hexFromSig(this));let t=p.toBytes(this.r),r=p.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return u(Uint8Array.of(this.recovery),t,r)}return u(t,r)}toHex(e){return i(this.toBytes(e))}assertValidity(){}static fromCompact(e){return A.fromBytes(C(`sig`,e),`compact`)}static fromDER(e){return A.fromBytes(C(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new A(this.r,p.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return i(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return i(this.toBytes(`compact`))}}let j=a.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=y(e),n=e.length*8-h;return n>0?t>>BigInt(n):t},M=a.bits2int_modN||function(e){return p.create(j(e))},re=D(h);function N(e){return ee(`num < 2^`+h,e,W,re),p.toBytes(e)}function P(e,t){return g(e,void 0,`message`),t?g(r(e),void 0,`prehashed message`):e}function ie(t,n,r){if([`recovered`,`canonical`].some(e=>e in r))throw Error(`sign() legacy options not supported`);let{lowS:i,prehash:a,extraEntropy:s}=H(r,w);t=P(t,a);let c=M(t),l=q(p,n),d=[N(l),N(c)];if(s!=null&&s!==!1){let e=s===!0?o(S.secretKey):s;d.push(C(`extraEntropy`,e))}let f=u(...d),m=c;function h(t){let n=j(t);if(!p.isValidNot0(n))return;let r=p.inv(n),a=e.BASE.multiply(n).toAffine(),o=p.create(a.x);if(o===W)return;let s=p.create(r*p.create(m+o*l));if(s===W)return;let c=(a.x===o?0:2)|Number(a.y&G),u=s;return i&&E(s)&&(u=p.neg(s),c^=1),new A(o,u,c)}return{seed:f,k2sig:h}}function ae(e,t,n={}){e=C(`message`,e);let{seed:i,k2sig:a}=ie(e,t,n);return te(r.outputLen,p.BYTES,s)(i,a)}function oe(e){let t,n=typeof e==`string`||d(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new A(e.r,e.s);else if(n){try{t=A.fromBytes(C(`sig`,e),`der`)}catch(e){if(!(e instanceof U.Err))throw e}if(!t)try{t=A.fromBytes(C(`sig`,e),`compact`)}catch{return!1}}return t||!1}function F(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=H(i,w);if(r=C(`publicKey`,r),n=P(C(`message`,n),o),`strict`in i)throw Error(`options.strict was renamed to lowS`);let c=s===void 0?oe(t):A.fromBytes(C(`sig`,t),s);if(c===!1)return!1;try{let t=e.fromBytes(r);if(a&&c.hasHighS())return!1;let{r:i,s:o}=c,s=M(n),l=p.inv(o),u=p.create(s*l),d=p.create(i*l),f=e.BASE.multiplyUnsafe(u).add(t.multiplyUnsafe(d));return!f.is0()&&p.create(f.x)===i}catch{return!1}}function se(e,t,n={}){let{prehash:r}=H(n,w);return t=P(t,r),A.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:_,getPublicKey:v,getSharedSecret:b,utils:x,lengths:S,Point:e,sign:ae,verify:F,recoverPublicKey:se,Signature:A,hash:r})}function Ke(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:I(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function qe(e){let{CURVE:t,curveOpts:n}=Ke(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Je(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,ye(n.Fn.ORDER,n.Fn.BITS))})}function Ye(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=qe(e);return Je(e,Ge(Ve(t,n),r,i))}
|
|
10
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
+
function J(e,t){let n=t=>Ye({...e,hash:t});return{...n(t),create:n}}
|
|
12
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
+
const Xe={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},Ze={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},Qe={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},$e=I(Xe.p),et=I(Ze.p),tt=I(Qe.p),nt=J({...Xe,Fp:$e,lowS:!1},s);J({...Ze,Fp:et,lowS:!1},l),J({...Qe,Fp:tt,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},a);
|
|
14
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15
|
+
const rt=nt,it=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],at={sha256:1};function ot(e){if(e&&!at[e]&&!at[e.toLowerCase()])throw Error(`Digest method not supported`);return new st}var st=class{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!X||Z>=8e3)&&(X=new ArrayBuffer(8e3),Z=0),this._byte=new Uint8Array(X,Z,80),this._word=new Int32Array(X,Z,20),Z+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this,u=0;for(t|=0;u<16;)Y[u++]=$(e[t++]);for(u=16;u<64;u++)Y[u]=pt(Y[u-2])+Y[u-7]+ft(Y[u-15])+Y[u-16]|0;for(u=0;u<64;u++){let e=l+dt(o)+ct(o,s,c)+it[u]+Y[u]|0,t=ut(n)+lt(n,r,i)|0;l=c,c=s,s=o,o=a+e|0,a=i,i=r,r=n,n=e+t|0}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0,this.F=s+this.F|0,this.G=c+this.G|0,this.H=l+this.H|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=$(o)),a&&(n[15]=$(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return Q(e)+Q(t)+Q(n)+Q(r)+Q(i)+Q(a)+Q(o)+Q(s)}_bin(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s,_byte:c,_word:l}=this;return l[0]=$(e),l[1]=$(t),l[2]=$(n),l[3]=$(r),l[4]=$(i),l[5]=$(a),l[6]=$(o),l[7]=$(s),c.slice(0,32)}};const Y=new Int32Array(64);let X,Z=0;const Q=e=>(e+4294967296).toString(16).substr(-8),$=mt()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),ct=(e,t,n)=>n^e&(t^n),lt=(e,t,n)=>e&t|n&(e|t),ut=e=>(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),dt=e=>(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),ft=e=>(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,pt=e=>(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10;function mt(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const ht=async t=>{let n=rt.getPublicKey(t.privateKey,!0),r=e(n);if(r!=t.publicKey)throw Error(`Bad API key. Expected to get public key ${t.publicKey}, got ${r}`);let i=ot().update(t.content).digest();return rt.sign(i,t.privateKey).toDERHex()};export{ht as signWithApiKey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,o)=>(o=n==null?{}:e(i(n)),l(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e);export{u as a,d as i,o as n,c as r,s as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{D as e}from"./dist-w03V0QPF.mjs";import{j as t}from"./index.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Code modified from https://github.com/google/tink/blob/6f74b99a2bfe6677e3670799116a57268fd067fa/javascript/subtle/bytes.ts
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{O as e}from"./dist-w03V0QPF.mjs";import{t}from"./utils-CrMT-n--.mjs";const n=async e=>{let{content:t,publicKey:n,privateKey:a}=e;return await i({key:await r({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:n}),content:t})};async function r(e){let{uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r}=e,i=t({uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r});return await crypto.subtle.importKey(`jwk`,i,{name:`ECDSA`,namedCurve:`P-256`},!1,[`sign`])}async function i(t){let{key:n,content:r}=t,i=await crypto.subtle.sign({name:`ECDSA`,hash:`SHA-256`},n,new TextEncoder().encode(r)),o=a(new Uint8Array(i));return e(o)}function a(e){if(e.length%2!=0||e.length==0||e.length>132)throw Error(`Invalid IEEE P1363 signature encoding. Length: `+e.length);let t=o(e.subarray(0,e.length/2)),n=o(e.subarray(e.length/2,e.length)),r=0,i=2+t.length+1+1+n.length,a;return i>=128?(a=new Uint8Array(i+3),a[r++]=48,a[r++]=129,a[r++]=i):(a=new Uint8Array(i+2),a[r++]=48,a[r++]=i),a[r++]=2,a[r++]=t.length,a.set(t,r),r+=t.length,a[r++]=2,a[r++]=n.length,a.set(n,r),a}function o(e){let t=0;for(;t<e.length&&e[t]==0;)t++;t==e.length&&(t=e.length-1);let n=0;(e[t]&128)==128&&(n=1);let r=new Uint8Array(e.length-t+n);return r.set(e.subarray(t),n),r}export{n as signWithApiKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catena/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Catena CLI for agent runtimes",
|
|
5
5
|
"homepage": "https://catena.com/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"LICENSE",
|
|
13
|
-
"README.md"
|
|
13
|
+
"README.md",
|
|
14
|
+
"THIRD-PARTY-NOTICES"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
16
17
|
"publishConfig": {
|
|
@@ -23,9 +24,11 @@
|
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/semver": "7.8.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"mppx": "0.9.0",
|
|
28
|
+
"publint": "0.3.24",
|
|
29
|
+
"tsdown": "0.23.0",
|
|
30
|
+
"tsx": "4.23.13",
|
|
31
|
+
"viem": "2.56.3",
|
|
29
32
|
"@bank/money": "0.1.0",
|
|
30
33
|
"@bank/shared": "0.1.0",
|
|
31
34
|
"@catena/sdk": "0.1.0"
|
package/dist/base64-WTSXTrii.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e}from"./dist-B0qgGwAq.mjs";function t(e){return r(i(e))}function n(n,r){let i=n.padStart(Math.ceil(n.length/2)*2,`0`);return t(e(i,r).reduce((e,t)=>e+String.fromCharCode(t),``))}function r(e){return e.replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function i(e){if(arguments.length===0)throw TypeError(`1 argument required, but only 0 present.`);let t;for(e=`${e}`,t=0;t<e.length;t++)if(e.charCodeAt(t)>255)throw Error(`InvalidCharacterError: found code point greater than 255:${e.charCodeAt(t)} at position ${t}`);let n=``;for(t=0;t<e.length;t+=3){let r=[void 0,void 0,void 0,void 0];r[0]=e.charCodeAt(t)>>2,r[1]=(e.charCodeAt(t)&3)<<4,e.length>t+1&&(r[1]|=e.charCodeAt(t+1)>>4,r[2]=(e.charCodeAt(t+1)&15)<<2),e.length>t+2&&(r[2]|=e.charCodeAt(t+2)>>6,r[3]=e.charCodeAt(t+2)&63);for(let e=0;e<r.length;e++)r[e]===void 0?n+=`=`:n+=a(r[e])}return n}function a(e){if(e>=0&&e<64)return`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`[e]}export{t as n,n as t};
|
package/dist/dist-B0qgGwAq.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import*as e from"node:crypto";var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},u=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},d=(e,r,i)=>(i=e==null?{}:t(a(e)),u(r||!e||!e.__esModule||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e)),f=e=>o.call(e,`module.exports`)?e[`module.exports`]:u(n({},`__esModule`,{value:!0}),e);function p(e){return e.reduce((e,t)=>e+t.toString(16).padStart(2,`0`),``)}const m=(e,t)=>{if(!e||e.length%2!=0||!/^[0-9A-Fa-f]+$/.test(e))throw Error(`cannot create uint8array from invalid hex string: "${e}"`);let n=new Uint8Array(e.match(/../g).map(e=>parseInt(e,16)));if(!t)return n;if(e.length/2>t)throw Error(`hex value cannot fit in a buffer of `+t+` byte(s)`);let r=new Uint8Array(t);return r.set(n,t-n.length),r},h=(e,t)=>{let n=t-e.length;if(n>0){let t=new Uint8Array(n).fill(0);return new Uint8Array([...t,...e])}if(n<0){let r=n*-1,i=0;for(let t=0;t<r&&t<e.length;t++)e[t]===0&&i++;if(i!==r)throw Error(`invalid number of starting zeroes. Expected number of zeroes: ${r}. Found: ${i}.`);return e.slice(r,r+t)}return e};function g(e){if(e.length>=255)throw TypeError(`Alphabet too long`);let t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let n=0;n<e.length;n++){let r=e.charAt(n),i=r.charCodeAt(0);if(t[i]!==255)throw TypeError(r+` is ambiguous`);t[i]=n}let n=e.length,r=e.charAt(0),i=Math.log(n)/Math.log(256),a=Math.log(256)/Math.log(n);function o(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw TypeError(`Expected Uint8Array`);if(t.length===0)return``;let i=0,o=0,s=0,c=t.length;for(;s!==c&&t[s]===0;)s++,i++;let l=(c-s)*a+1>>>0,u=new Uint8Array(l);for(;s!==c;){let e=t[s],r=0;for(let t=l-1;(e!==0||r<o)&&t!==-1;t--,r++)e+=256*u[t]>>>0,u[t]=e%n>>>0,e=e/n>>>0;if(e!==0)throw Error(`Non-zero carry`);o=r,s++}let d=l-o;for(;d!==l&&u[d]===0;)d++;let f=r.repeat(i);for(;d<l;++d)f+=e.charAt(u[d]);return f}function s(e){if(typeof e!=`string`)throw TypeError(`Expected String`);if(e.length===0)return new Uint8Array;let a=0,o=0,s=0;for(;e[a]===r;)o++,a++;let c=(e.length-a)*i+1>>>0,l=new Uint8Array(c);for(;a<e.length;){let r=e.charCodeAt(a);if(r>255)return;let i=t[r];if(i===255)return;let o=0;for(let e=c-1;(i!==0||o<s)&&e!==-1;e--,o++)i+=n*l[e]>>>0,l[e]=i%256>>>0,i=i/256>>>0;if(i!==0)throw Error(`Non-zero carry`);s=o,a++}let u=c-s;for(;u!==c&&l[u]===0;)u++;let d=new Uint8Array(o+(c-u)),f=o;for(;u!==c;)d[f++]=l[u++];return d}function c(e){let t=s(e);if(t)return t;throw Error(`Non-base`+n+` character`)}return{encode:o,decodeUnsafe:s,decode:c}}var _=l({default:()=>v}),v=g(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function y(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}y(_);const b=e&&typeof e==`object`&&`webcrypto`in e?e.webcrypto:e&&typeof e==`object`&&`randomBytes`in e?e:void 0;
|
|
2
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
function x(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function S(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function C(e,...t){if(!x(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function w(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);S(e.outputLen),S(e.blockLen)}function T(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function E(e,t){C(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function D(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function O(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function k(e,t){return e<<32-t|e>>>t}const A=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ee=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function te(e){if(C(e),A)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ee[e[n]];return t}const j={_0:48,_9:57,A:65,F:70,a:97,f:102};function M(e){if(e>=j._0&&e<=j._9)return e-j._0;if(e>=j.A&&e<=j.F)return e-(j.A-10);if(e>=j.a&&e<=j.f)return e-(j.a-10)}function ne(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(A)return Uint8Array.fromHex(e);let t=e.length,n=t/2;if(t%2)throw Error(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=M(e.charCodeAt(i)),a=M(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw Error(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function re(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function N(e){return typeof e==`string`&&(e=re(e)),C(e),e}function ie(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];C(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}var P=class{};function F(e){let t=t=>e().update(N(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ae(e=32){if(b&&typeof b.getRandomValues==`function`)return b.getRandomValues(new Uint8Array(e));if(b&&typeof b.randomBytes==`function`)return Uint8Array.from(b.randomBytes(e));throw Error(`crypto.getRandomValues must be defined`)}function oe(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function se(e,t,n){return e&t^~e&n}function ce(e,t,n){return e&t^e&n^t&n}var I=class extends P{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=O(this.buffer)}update(e){T(this),e=N(e),C(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=O(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){T(this),E(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,D(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;oe(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=O(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}};const L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),R=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),z=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),B=BigInt(2**32-1),V=BigInt(32);function le(e,t=!1){return t?{h:Number(e&B),l:Number(e>>V&B)}:{h:Number(e>>V&B)|0,l:Number(e&B)|0}}function ue(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=le(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}const H=(e,t,n)=>e>>>n,U=(e,t,n)=>e<<32-n|t>>>n,W=(e,t,n)=>e>>>n|t<<32-n,G=(e,t,n)=>e<<32-n|t>>>n,K=(e,t,n)=>e<<64-n|t>>>n-32,q=(e,t,n)=>e>>>n-32|t<<64-n;function J(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const de=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),fe=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,pe=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),me=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,he=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),ge=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0,_e=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Y=new Uint32Array(64);var ve=class extends I{constructor(e=32){super(64,e,8,!1),this.A=L[0]|0,this.B=L[1]|0,this.C=L[2]|0,this.D=L[3]|0,this.E=L[4]|0,this.F=L[5]|0,this.G=L[6]|0,this.H=L[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)Y[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Y[e-15],n=Y[e-2],r=k(t,7)^k(t,18)^t>>>3,i=k(n,17)^k(n,19)^n>>>10;Y[e]=i+Y[e-7]+r+Y[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=k(o,6)^k(o,11)^k(o,25),u=l+t+se(o,s,c)+_e[e]+Y[e]|0,d=(k(n,2)^k(n,13)^k(n,22))+ce(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){D(Y)}destroy(){this.set(0,0,0,0,0,0,0,0),D(this.buffer)}};const X=ue(`0x428a2f98d728ae22.0x7137449123ef65cd.0xb5c0fbcfec4d3b2f.0xe9b5dba58189dbbc.0x3956c25bf348b538.0x59f111f1b605d019.0x923f82a4af194f9b.0xab1c5ed5da6d8118.0xd807aa98a3030242.0x12835b0145706fbe.0x243185be4ee4b28c.0x550c7dc3d5ffb4e2.0x72be5d74f27b896f.0x80deb1fe3b1696b1.0x9bdc06a725c71235.0xc19bf174cf692694.0xe49b69c19ef14ad2.0xefbe4786384f25e3.0x0fc19dc68b8cd5b5.0x240ca1cc77ac9c65.0x2de92c6f592b0275.0x4a7484aa6ea6e483.0x5cb0a9dcbd41fbd4.0x76f988da831153b5.0x983e5152ee66dfab.0xa831c66d2db43210.0xb00327c898fb213f.0xbf597fc7beef0ee4.0xc6e00bf33da88fc2.0xd5a79147930aa725.0x06ca6351e003826f.0x142929670a0e6e70.0x27b70a8546d22ffc.0x2e1b21385c26c926.0x4d2c6dfc5ac42aed.0x53380d139d95b3df.0x650a73548baf63de.0x766a0abb3c77b2a8.0x81c2c92e47edaee6.0x92722c851482353b.0xa2bfe8a14cf10364.0xa81a664bbc423001.0xc24b8b70d0f89791.0xc76c51a30654be30.0xd192e819d6ef5218.0xd69906245565a910.0xf40e35855771202a.0x106aa07032bbd1b8.0x19a4c116b8d2d0c8.0x1e376c085141ab53.0x2748774cdf8eeb99.0x34b0bcb5e19b48a8.0x391c0cb3c5c95a63.0x4ed8aa4ae3418acb.0x5b9cca4f7763e373.0x682e6ff3d6b2b8a3.0x748f82ee5defb2fc.0x78a5636f43172f60.0x84c87814a1f0ab72.0x8cc702081a6439ec.0x90befffa23631e28.0xa4506cebde82bde9.0xbef9a3f7b2c67915.0xc67178f2e372532b.0xca273eceea26619c.0xd186b8c721c0c207.0xeada7dd6cde0eb1e.0xf57d4f7fee6ed178.0x06f067aa72176fba.0x0a637dc5a2c898a6.0x113f9804bef90dae.0x1b710b35131c471b.0x28db77f523047d84.0x32caab7b40c72493.0x3c9ebe0a15c9bebc.0x431d67c49c100d4c.0x4cc5d4becb3e42b6.0x597f299cfc657e2a.0x5fcb6fab3ad6faec.0x6c44198c4a475817`.split(`.`).map(e=>BigInt(e))),ye=X[0],be=X[1],Z=new Uint32Array(80),Q=new Uint32Array(80);var xe=class extends I{constructor(e=64){super(128,e,16,!1),this.Ah=z[0]|0,this.Al=z[1]|0,this.Bh=z[2]|0,this.Bl=z[3]|0,this.Ch=z[4]|0,this.Cl=z[5]|0,this.Dh=z[6]|0,this.Dl=z[7]|0,this.Eh=z[8]|0,this.El=z[9]|0,this.Fh=z[10]|0,this.Fl=z[11]|0,this.Gh=z[12]|0,this.Gl=z[13]|0,this.Hh=z[14]|0,this.Hl=z[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:f,Gl:p,Hh:m,Hl:h}=this;return[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=r|0,this.Ch=i|0,this.Cl=a|0,this.Dh=o|0,this.Dl=s|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=f|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}process(e,t){for(let n=0;n<16;n++,t+=4)Z[n]=e.getUint32(t),Q[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Z[e-15]|0,n=Q[e-15]|0,r=W(t,n,1)^W(t,n,8)^H(t,n,7),i=G(t,n,1)^G(t,n,8)^U(t,n,7),a=Z[e-2]|0,o=Q[e-2]|0,s=W(a,o,19)^K(a,o,61)^H(a,o,6),c=G(a,o,19)^q(a,o,61)^U(a,o,6),l=pe(i,c,Q[e-7],Q[e-16]),u=me(l,r,s,Z[e-7],Z[e-16]);Z[e]=u|0,Q[e]=l|0}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:f,Fl:p,Gh:m,Gl:h,Hh:g,Hl:_}=this;for(let e=0;e<80;e++){let t=W(u,d,14)^W(u,d,18)^K(u,d,41),v=G(u,d,14)^G(u,d,18)^q(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=he(_,v,b,be[e],Q[e]),S=ge(x,g,t,y,ye[e],Z[e]),C=x|0,w=W(n,r,28)^K(n,r,34)^K(n,r,39),T=G(n,r,28)^q(n,r,34)^q(n,r,39),E=n&i^n&o^i&o,D=r&a^r&s^a&s;g=m|0,_=h|0,m=f|0,h=p|0,f=u|0,p=d|0,{h:u,l:d}=J(c|0,l|0,S|0,C|0),c=o|0,l=s|0,o=i|0,s=a|0,i=n|0,a=r|0;let O=de(C,T,D);n=fe(O,S,w,E),r=O|0}({h:n,l:r}=J(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=J(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=J(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=J(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=J(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=J(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=J(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=J(this.Hh|0,this.Hl|0,g|0,_|0),this.set(n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)}roundClean(){D(Z,Q)}destroy(){D(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Se=class extends xe{constructor(){super(48),this.Ah=R[0]|0,this.Al=R[1]|0,this.Bh=R[2]|0,this.Bl=R[3]|0,this.Ch=R[4]|0,this.Cl=R[5]|0,this.Dh=R[6]|0,this.Dl=R[7]|0,this.Eh=R[8]|0,this.El=R[9]|0,this.Fh=R[10]|0,this.Fl=R[11]|0,this.Gh=R[12]|0,this.Gl=R[13]|0,this.Hh=R[14]|0,this.Hl=R[15]|0}};const Ce=F(()=>new ve),we=F(()=>new xe),Te=F(()=>new Se),$=Ce;function Ee(e){function t(t){var n=Uint8Array.from(t),r=e(n),i=n.length+4,a=new Uint8Array(i);return a.set(n,0),a.set(r.subarray(0,4),n.length),v.encode(a)}function n(t){var n=t.slice(0,-4),r=t.slice(-4),i=e(n);if(!(r[0]^i[0]|r[1]^i[1]|r[2]^i[2]|r[3]^i[3]))return n}function r(e){var t=v.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(v.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}var De=l({default:()=>ke});function Oe(e){return $($(e))}var ke=Ee(Oe);function Ae(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}Ae(De);export{d as C,f as S,m as _,C as a,s as b,S as c,ie as d,ne as f,h as g,N as h,P as i,te as l,ae as m,Te as n,T as o,x as p,we as r,w as s,Ce as t,D as u,p as v,l as x,c as y};
|
package/dist/purejs-CZxWHjtN.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m,v as h}from"./dist-B0qgGwAq.mjs";var g=class extends a{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,f(e);let n=i(t);if(this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let r=this.blockLen,a=new Uint8Array(r);a.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<a.length;e++)a[e]^=54;this.iHash.update(a),this.oHash=e.create();for(let e=0;e<a.length;e++)a[e]^=106;this.oHash.update(a),m(a)}update(e){return l(this),this.iHash.update(e),this}digestInto(t){l(this),e(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const _=(e,t,n)=>new g(e,t).update(n).digest();_.create=(e,t)=>new g(e,t);
|
|
2
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
const v=BigInt(0),y=BigInt(1);function b(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function x(e,t,n=``){let r=u(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function S(e){let t=e.toString(16);return t.length&1?`0`+t:t}function C(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?v:BigInt(`0x`+e)}function w(e){return C(o(e))}function T(t){return e(t),C(o(Uint8Array.from(t).reverse()))}function E(e,t){return r(e.toString(16).padStart(t*2,`0`))}function D(e,t){return E(e,t).reverse()}function O(e,t,n){let i;if(typeof t==`string`)try{i=r(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(u(t))i=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let a=i.length;if(typeof n==`number`&&a!==n)throw Error(e+` of length `+n+` expected, got `+a);return i}const k=e=>typeof e==`bigint`&&v<=e;function A(e,t,n){return k(e)&&k(t)&&k(n)&&t<=e&&e<n}function j(e,t,n,r){if(!A(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function M(e){let t;for(t=0;e>v;e>>=y,t+=1);return t}const N=e=>(y<<BigInt(e))-y;function ee(e,t,r){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof r!=`function`)throw Error(`hmacFn must be a function`);let i=e=>new Uint8Array(e),a=e=>Uint8Array.of(e),o=i(e),s=i(e),c=0,l=()=>{o.fill(1),s.fill(0),c=0},u=(...e)=>r(s,o,...e),d=(e=i(0))=>{s=u(a(0),e),o=u(),e.length!==0&&(s=u(a(1),e),o=u())},f=()=>{if(c++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,r=[];for(;e<t;){o=u();let t=o.slice();r.push(t),e+=o.length}return n(...r)};return(e,t)=>{l(),d(e);let n;for(;!(n=t(f()));)d();return l(),n}}function te(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ne(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
|
|
4
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
-
const P=BigInt(0),F=BigInt(1),I=BigInt(2),re=BigInt(3),ie=BigInt(4),ae=BigInt(5),oe=BigInt(7),se=BigInt(8),ce=BigInt(9),le=BigInt(16);function L(e,t){let n=e%t;return n>=P?n:t+n}function ue(e,t){if(e===P)throw Error(`invert: expected non-zero number`);if(t<=P)throw Error(`invert: expected positive modulus, got `+t);let n=L(e,t),r=t,i=P,a=F,o=F,s=P;for(;n!==P;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==F)throw Error(`invert: does not exist`);return L(i,t)}function R(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function de(e,t){let n=(e.ORDER+F)/ie,r=e.pow(t,n);return R(e,r,t),r}function fe(e,t){let n=(e.ORDER-ae)/se,r=e.mul(t,I),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,I),i),s=e.mul(a,e.sub(o,e.ONE));return R(e,s,t),s}function pe(e){let t=z(e),n=me(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+oe)/le;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return R(e,p,t),p}}function me(e){if(e<re)throw Error(`sqrt is not defined for small field`);let t=e-F,n=0;for(;t%I===P;)t/=I,n++;let r=I,i=z(e);for(;be(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return de;let a=i.pow(r,t),o=(t+F)/I;return function(e,r){if(e.is0(r))return r;if(be(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=F<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function he(e){return e%ie===re?de:e%se===ae?fe:e%le===ce?pe(e):me(e)}const ge=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function _e(e){return te(e,ge.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function ve(e,t,n){if(n<P)throw Error(`invalid exponent, negatives unsupported`);if(n===P)return e.ONE;if(n===F)return t;let r=e.ONE,i=t;for(;n>P;)n&F&&(r=e.mul(r,i)),i=e.sqr(i),n>>=F;return r}function ye(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function be(e,t){let n=(e.ORDER-F)/I,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function xe(e,n){n!==void 0&&t(n);let r=n===void 0?e.toString(2).length:n;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function z(e,t,n=!1,r={}){if(e<=P)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=xe(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:N(c),ZERO:P,ONE:F,allowedLengths:s,create:t=>L(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return P<=t&&t<e},is0:e=>e===P,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&F)===F,neg:t=>L(-t,e),eql:(e,t)=>e===t,sqr:t=>L(t*t,e),add:(t,n)=>L(t+n,e),sub:(t,n)=>L(t-n,e),mul:(t,n)=>L(t*n,e),pow:(e,t)=>ve(d,e,t),div:(t,n)=>L(t*ue(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>ue(t,e),sqrt:a||(t=>(u||=he(e),u(d,t))),toBytes:e=>n?D(e,l):E(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?T(t):w(t);if(o&&(i=L(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>ye(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function Se(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function Ce(e){let t=Se(e);return t+Math.ceil(t/2)}function we(e,t,n=!1){let r=e.length,i=Se(t),a=Ce(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=L(n?T(e):w(e),t-F)+F;return n?D(o,i):E(o,i)}
|
|
6
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
const B=BigInt(0),V=BigInt(1);function H(e,t){let n=t.negate();return e?n:t}function U(e,t){let n=ye(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Te(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Ee(e,t){Te(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:N(e),maxNumber:i,shiftBy:BigInt(e)}}function De(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=V);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function Oe(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function ke(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const Ae=new WeakMap,je=new WeakMap;function Me(e){return je.get(e)||1}function Ne(e){if(e!==B)throw Error(`invalid wNAF`)}var Pe=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>B;)t&V&&(n=n.add(r)),r=r.double(),t>>=V;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Ee(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Ee(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=De(n,e,a);n=o,c?i=i.add(H(u,t[d])):r=r.add(H(l,t[s]))}return Ne(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Ee(e,this.bits);for(let e=0;e<i.windows&&n!==B;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=De(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return Ne(n),r}getPrecomputes(e,t,n){let r=Ae.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),Ae.set(t,r))),r}cached(e,t,n){let r=Me(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=Me(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Te(t,this.bits),je.set(e,t),Ae.delete(e)}hasCache(e){return Me(e)!==1}};function Fe(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>B||r>B;)n&V&&(a=a.add(i)),r&V&&(o=o.add(i)),i=i.double(),n>>=V,r>>=V;return{p1:a,p2:o}}function Ie(e,t,n,r){Oe(n,e),ke(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=M(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=N(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Le(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return _e(t),t}return z(e,{isLE:n})}function Re(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>B))throw Error(`CURVE.${e} must be positive bigint`)}let i=Le(t.p,n.Fp,r),a=Le(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
|
|
8
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
-
const ze=(e,t)=>(e+(e>=0?t:-t)/Ue)/t;function Be(e,t,n){let[[r,i],[a,o]]=t,s=ze(o*e,n),c=ze(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<G,f=u<G;d&&(l=-l),f&&(u=-u);let p=N(Math.ceil(M(n)/2))+K;if(l<G||l>=p||u<G||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Ve(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function He(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return b(n.lowS,`lowS`),b(n.prehash,`prehash`),n.format!==void 0&&Ve(n.format),n}const W={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=W;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=S(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?S(i.length/2|128):``;return S(e)+a+i+t},decode(e,t){let{Err:n}=W,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=W;if(e<G)throw new t(`integer: negative integers are not allowed`);let n=S(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=W;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return w(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=W,i=O(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=W,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},G=BigInt(0),K=BigInt(1),Ue=BigInt(2),q=BigInt(3),We=BigInt(4);function J(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=O(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function Ge(e,t={}){let r=Re(`weierstrass`,e,t),{Fp:i,Fn:a}=r,s=r.CURVE,{h:c,n:l}=s;te(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:u}=t;if(u&&(!i.is0(s.a)||typeof u.beta!=`bigint`||!Array.isArray(u.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=qe(i,a);function f(){if(!i.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,r){let{x:a,y:o}=t.toAffine(),s=i.toBytes(a);if(b(r,`isCompressed`),r){f();let e=!i.isOdd(o);return n(Ke(e),s)}return n(Uint8Array.of(4),s,i.toBytes(o))}function m(e){x(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,r=e.length,a=e[0],o=e.subarray(1);if(r===t&&(a===2||a===3)){let e=i.fromBytes(o);if(!i.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=_(e),n;try{n=i.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let r=i.isOdd(n);return(a&1)==1!==r&&(n=i.neg(n)),{x:e,y:n}}if(r===n&&a===4){let e=i.BYTES,t=i.fromBytes(o.subarray(0,e)),n=i.fromBytes(o.subarray(e,e*2));if(!v(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${r}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes||p,g=t.fromBytes||m;function _(e){let t=i.sqr(e),n=i.mul(t,e);return i.add(i.add(n,i.mul(e,s.a)),s.b)}function v(e,t){let n=i.sqr(t),r=_(e);return i.eql(n,r)}if(!v(s.Gx,s.Gy))throw Error(`bad curve params: generator point`);let y=i.mul(i.pow(s.a,q),We),S=i.mul(i.sqr(s.b),BigInt(27));if(i.is0(i.add(y,S)))throw Error(`bad curve params: a or b`);function C(e,t,n=!1){if(!i.isValid(t)||n&&i.is0(t))throw Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof A))throw Error(`ProjectivePoint expected`)}function T(e){if(!u||!u.basises)throw Error(`no endo`);return Be(e,u.basises,a.ORDER)}let E=ne((e,t)=>{let{X:n,Y:r,Z:a}=e;if(i.eql(a,i.ONE))return{x:n,y:r};let o=e.is0();t??=o?i.ONE:i.inv(a);let s=i.mul(n,t),c=i.mul(r,t),l=i.mul(a,t);if(o)return{x:i.ZERO,y:i.ZERO};if(!i.eql(l,i.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),D=ne(e=>{if(e.is0()){if(t.allowInfinityPoint&&!i.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:r}=e.toAffine();if(!i.isValid(n)||!i.isValid(r))throw Error(`bad point: x or y not field elements`);if(!v(n,r))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function k(e,t,n,r,a){return n=new A(i.mul(n.X,e),n.Y,n.Z),t=H(r,t),n=H(a,n),t.add(n)}class A{constructor(e,t,n){this.X=C(`x`,e),this.Y=C(`y`,t,!0),this.Z=C(`z`,n),Object.freeze(this)}static CURVE(){return s}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!i.isValid(t)||!i.isValid(n))throw Error(`invalid affine point`);if(e instanceof A)throw Error(`projective point not allowed`);return i.is0(t)&&i.is0(n)?A.ZERO:new A(t,n,i.ONE)}static fromBytes(e){let t=A.fromAffine(g(x(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return A.fromBytes(O(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return M.createCache(this,e),t||this.multiply(q),this}assertValidity(){D(this)}hasEvenY(){let{y:e}=this.toAffine();if(!i.isOdd)throw Error(`Field doesn't support isOdd`);return!i.isOdd(e)}equals(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:s}=e,c=i.eql(i.mul(t,s),i.mul(a,r)),l=i.eql(i.mul(n,s),i.mul(o,r));return c&&l}negate(){return new A(this.X,i.neg(this.Y),this.Z)}double(){let{a:e,b:t}=s,n=i.mul(t,q),{X:r,Y:a,Z:o}=this,c=i.ZERO,l=i.ZERO,u=i.ZERO,d=i.mul(r,r),f=i.mul(a,a),p=i.mul(o,o),m=i.mul(r,a);return m=i.add(m,m),u=i.mul(r,o),u=i.add(u,u),c=i.mul(e,u),l=i.mul(n,p),l=i.add(c,l),c=i.sub(f,l),l=i.add(f,l),l=i.mul(c,l),c=i.mul(m,c),u=i.mul(n,u),p=i.mul(e,p),m=i.sub(d,p),m=i.mul(e,m),m=i.add(m,u),u=i.add(d,d),d=i.add(u,d),d=i.add(d,p),d=i.mul(d,m),l=i.add(l,d),p=i.mul(a,o),p=i.add(p,p),d=i.mul(p,m),c=i.sub(c,d),u=i.mul(p,f),u=i.add(u,u),u=i.add(u,u),new A(c,l,u)}add(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:c}=e,l=i.ZERO,u=i.ZERO,d=i.ZERO,f=s.a,p=i.mul(s.b,q),m=i.mul(t,a),h=i.mul(n,o),g=i.mul(r,c),_=i.add(t,n),v=i.add(a,o);_=i.mul(_,v),v=i.add(m,h),_=i.sub(_,v),v=i.add(t,r);let y=i.add(a,c);return v=i.mul(v,y),y=i.add(m,g),v=i.sub(v,y),y=i.add(n,r),l=i.add(o,c),y=i.mul(y,l),l=i.add(h,g),y=i.sub(y,l),d=i.mul(f,v),l=i.mul(p,g),d=i.add(l,d),l=i.sub(h,d),d=i.add(h,d),u=i.mul(l,d),h=i.add(m,m),h=i.add(h,m),g=i.mul(f,g),v=i.mul(p,v),h=i.add(h,g),g=i.sub(m,g),g=i.mul(f,g),v=i.add(v,g),m=i.mul(h,v),u=i.add(u,m),m=i.mul(y,v),l=i.mul(_,l),l=i.sub(l,m),m=i.mul(_,h),d=i.mul(y,d),d=i.add(d,m),new A(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(A.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,i,o=e=>M.cached(this,e,e=>U(A,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=T(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=k(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return U(A,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!a.isValid(e))throw Error(`invalid scalar: out of range`);if(e===G||r.is0())return A.ZERO;if(e===K)return r;if(M.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=T(e),{p1:s,p2:c}=Fe(A,r,i,o);return k(n.beta,s,c,t,a)}return M.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return E(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return c===K?!0:e?e(A,this):M.unsafe(this,l).is0()}clearCofactor(){let{clearCofactor:e}=t;return c===K?this:e?e(A,this):this.multiplyUnsafe(c)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}toBytes(e=!0){return b(e,`isCompressed`),this.assertValidity(),h(A,this,e)}toHex(e=!0){return o(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return U(A,e)}static msm(e,t){return Ie(A,a,e,t)}static fromPrivateKey(e){return A.BASE.multiply(J(a,e))}}A.BASE=new A(s.Gx,s.Gy,i.ONE),A.ZERO=new A(i.ZERO,i.ONE,i.ZERO),A.Fp=i,A.Fn=a;let j=a.BITS,M=new Pe(A,t.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function Ke(e){return Uint8Array.of(e?2:3)}function qe(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Je(e,t={}){let{Fn:n}=e,r=t.randomBytes||s,i=Object.assign(qe(e.Fp,n),{seed:Ce(n.ORDER)});function a(e){try{return!!J(n,e)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function c(e=r(i.seed)){return we(x(e,i.seed,`seed`),n.ORDER)}function l(t,r=!0){return e.BASE.multiply(J(n,t)).toBytes(r)}function u(e){let t=c(e);return{secretKey:t,publicKey:l(t)}}function d(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:r,publicKey:a,publicKeyUncompressed:o}=i;if(n.allowedLengths||r===a)return;let s=O(`key`,t).length;return s===a||s===o}function f(t,r,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(r)===!1)throw Error(`second arg must be public key`);let a=J(n,t);return e.fromHex(r).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:l,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:c,isValidPrivateKey:a,randomPrivateKey:c,normPrivateKeyToScalar:e=>J(n,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:i})}function Ye(e,t,i={}){f(t),te(i,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let a=i.randomBytes||s,c=i.hmac||((e,...r)=>_(t,e,n(...r))),{Fp:l,Fn:d}=e,{ORDER:p,BITS:m}=d,{keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b}=Je(e,i),S={prehash:!1,lowS:typeof i.lowS==`boolean`&&i.lowS,format:void 0,extraEntropy:!1},C=`compact`;function T(e){return e>p>>K}function E(e,t){if(!d.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function D(e,t){Ve(t);let n=b.signature;return x(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class k{constructor(e,t,n){this.r=E(`r`,e),this.s=E(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=C){D(e,t);let n;if(t===`der`){let{r:t,s:n}=W.toSig(x(e));return new k(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=d.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new k(d.fromBytes(i),d.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(r(e),t)}addRecoveryBit(e){return new k(this.r,this.s,e)}recoverPublicKey(t){let r=l.ORDER,{r:i,s:a,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error(`recovery id invalid`);if(p*Ue<r&&o>1)throw Error(`recovery id is ambiguous for h>1 curve`);let s=o===2||o===3?i+p:i;if(!l.isValid(s))throw Error(`recovery id 2 or 3 invalid`);let c=l.toBytes(s),u=e.fromBytes(n(Ke(!(o&1)),c)),f=d.inv(s),m=M(O(`msgHash`,t)),h=d.create(-m*f),g=d.create(a*f),_=e.BASE.multiplyUnsafe(h).add(u.multiplyUnsafe(g));if(_.is0())throw Error(`point at infinify`);return _.assertValidity(),_}hasHighS(){return T(this.s)}toBytes(e=C){if(Ve(e),e===`der`)return r(W.hexFromSig(this));let t=d.toBytes(this.r),i=d.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return n(Uint8Array.of(this.recovery),t,i)}return n(t,i)}toHex(e){return o(this.toBytes(e))}assertValidity(){}static fromCompact(e){return k.fromBytes(O(`sig`,e),`compact`)}static fromDER(e){return k.fromBytes(O(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new k(this.r,d.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return o(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return o(this.toBytes(`compact`))}}let A=i.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=w(e),n=e.length*8-m;return n>0?t>>BigInt(n):t},M=i.bits2int_modN||function(e){return d.create(A(e))},ne=N(m);function P(e){return j(`num < 2^`+m,e,G,ne),d.toBytes(e)}function F(e,n){return x(e,void 0,`message`),n?x(t(e),void 0,`prehashed message`):e}function I(t,r,i){if([`recovered`,`canonical`].some(e=>e in i))throw Error(`sign() legacy options not supported`);let{lowS:o,prehash:s,extraEntropy:c}=He(i,S);t=F(t,s);let l=M(t),u=J(d,r),f=[P(u),P(l)];if(c!=null&&c!==!1){let e=c===!0?a(b.secretKey):c;f.push(O(`extraEntropy`,e))}let p=n(...f),m=l;function h(t){let n=A(t);if(!d.isValidNot0(n))return;let r=d.inv(n),i=e.BASE.multiply(n).toAffine(),a=d.create(i.x);if(a===G)return;let s=d.create(r*d.create(m+a*u));if(s===G)return;let c=(i.x===a?0:2)|Number(i.y&K),l=s;return o&&T(s)&&(l=d.neg(s),c^=1),new k(a,l,c)}return{seed:p,k2sig:h}}function re(e,n,r={}){e=O(`message`,e);let{seed:i,k2sig:a}=I(e,n,r);return ee(t.outputLen,d.BYTES,c)(i,a)}function ie(e){let t,n=typeof e==`string`||u(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new k(e.r,e.s);else if(n){try{t=k.fromBytes(O(`sig`,e),`der`)}catch(e){if(!(e instanceof W.Err))throw e}if(!t)try{t=k.fromBytes(O(`sig`,e),`compact`)}catch{return!1}}return t||!1}function ae(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=He(i,S);if(r=O(`publicKey`,r),n=F(O(`message`,n),o),`strict`in i)throw Error(`options.strict was renamed to lowS`);let c=s===void 0?ie(t):k.fromBytes(O(`sig`,t),s);if(c===!1)return!1;try{let t=e.fromBytes(r);if(a&&c.hasHighS())return!1;let{r:i,s:o}=c,s=M(n),l=d.inv(o),u=d.create(s*l),f=d.create(i*l),p=e.BASE.multiplyUnsafe(u).add(t.multiplyUnsafe(f));return!p.is0()&&d.create(p.x)===i}catch{return!1}}function oe(e,t,n={}){let{prehash:r}=He(n,S);return t=F(t,r),k.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b,Point:e,sign:re,verify:ae,recoverPublicKey:oe,Signature:k,hash:t})}function Xe(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:z(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function Ze(e){let{CURVE:t,curveOpts:n}=Xe(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Qe(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,xe(n.Fn.ORDER,n.Fn.BITS))})}function $e(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=Ze(e);return Qe(e,Ye(Ge(t,n),r,i))}
|
|
10
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
-
function et(e,t){let n=t=>$e({...e,hash:t});return{...n(t),create:n}}
|
|
12
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
13
|
-
const tt={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},nt={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},rt={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},it=z(tt.p),at=z(nt.p),ot=z(rt.p),st=et({...tt,Fp:it,lowS:!1},p);et({...nt,Fp:at,lowS:!1},c),et({...rt,Fp:ot,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},d);
|
|
14
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15
|
-
const ct=st,lt=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],ut={sha256:1};function dt(e){if(e&&!ut[e]&&!ut[e.toLowerCase()])throw Error(`Digest method not supported`);return new ft}var ft=class{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!X||Z>=8e3)&&(X=new ArrayBuffer(8e3),Z=0),this._byte=new Uint8Array(X,Z,80),this._word=new Int32Array(X,Z,20),Z+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this,u=0;for(t|=0;u<16;)Y[u++]=$(e[t++]);for(u=16;u<64;u++)Y[u]=vt(Y[u-2])+Y[u-7]+_t(Y[u-15])+Y[u-16]|0;for(u=0;u<64;u++){let e=l+gt(o)+pt(o,s,c)+lt[u]+Y[u]|0,t=ht(n)+mt(n,r,i)|0;l=c,c=s,s=o,o=a+e|0,a=i,i=r,r=n,n=e+t|0}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0,this.F=s+this.F|0,this.G=c+this.G|0,this.H=l+this.H|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=$(o)),a&&(n[15]=$(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return Q(e)+Q(t)+Q(n)+Q(r)+Q(i)+Q(a)+Q(o)+Q(s)}_bin(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s,_byte:c,_word:l}=this;return l[0]=$(e),l[1]=$(t),l[2]=$(n),l[3]=$(r),l[4]=$(i),l[5]=$(a),l[6]=$(o),l[7]=$(s),c.slice(0,32)}};const Y=new Int32Array(64);let X,Z=0;const Q=e=>(e+4294967296).toString(16).substr(-8),$=yt()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),pt=(e,t,n)=>n^e&(t^n),mt=(e,t,n)=>e&t|n&(e|t),ht=e=>(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),gt=e=>(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),_t=e=>(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,vt=e=>(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10;function yt(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const bt=async e=>{let t=ct.getPublicKey(e.privateKey,!0),n=h(t);if(n!=e.publicKey)throw Error(`Bad API key. Expected to get public key ${e.publicKey}, got ${n}`);let r=dt().update(e.content).digest();return ct.sign(r,e.privateKey).toDERHex()};export{bt as signWithApiKey};
|