@catena/cli 0.10.0 → 0.12.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 +42 -6
- package/dist/dist-C970_f6m.mjs +1 -0
- package/dist/getAddress-BlHiG3c6.mjs +2 -0
- package/dist/hmac-DW0MnYTR.mjs +1 -0
- package/dist/index.mjs +135 -28
- package/dist/movements-BPWh6hg3.mjs +9 -0
- package/dist/mpp-DDG3E9du.mjs +13 -0
- package/dist/{nodecrypto-86590WN-.mjs → nodecrypto-GFkDS5iF.mjs} +1 -1
- package/dist/{purejs-xzcexc4T.mjs → purejs-CRJs90lt.mjs} +1 -1
- package/dist/sha256-CJuuQjmL.mjs +3 -0
- package/dist/{utils-CnOz_tNs.mjs → utils-q3q3KGtm.mjs} +1 -1
- package/dist/{webcrypto-CejAJWkk.mjs → webcrypto-DIO-H-XA.mjs} +1 -1
- package/package.json +2 -2
- package/dist/dist-w03V0QPF.mjs +0 -3
- package/dist/hmac-CXnNqvhW.mjs +0 -1
- package/dist/mpp-C1N0QzFM.mjs +0 -14
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{t as e}from"./sha256-CJuuQjmL.mjs";import{_ as t,a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,n as d,o as f,p,r as m,s as h,t as ee,u as g,v as _}from"./getAddress-BlHiG3c6.mjs";import*as v from"valibot";var y=class extends _{constructor({chainId:e}){super(typeof e==`number`?`Chain ID "${e}" is invalid.`:`Chain ID is invalid.`,{name:`InvalidChainIdError`})}},te=class extends _{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join(`
|
|
2
|
+
`),{name:`AbiEncodingArrayLengthMismatchError`})}},ne=class extends _{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${o(t)}) does not match expected size (bytes${e}).`,{name:`AbiEncodingBytesSizeMismatchError`})}},re=class extends _{constructor({expectedLength:e,givenLength:t}){super([`ABI encoding params/values length mismatch.`,`Expected length (params): ${e}`,`Given length (values): ${t}`].join(`
|
|
3
|
+
`),{name:`AbiEncodingLengthMismatchError`})}},ie=class extends _{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:`BytesSizeMismatchError`})}},ae=class extends _{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,`Please provide a valid ABI type.`].join(`
|
|
4
|
+
`),{docsPath:t,name:`InvalidAbiEncodingType`})}},oe=class extends _{constructor(e){super([`Value "${e}" is not a valid array.`].join(`
|
|
5
|
+
`),{name:`InvalidArrayError`})}};function b(e,n,r,{strict:i}={}){return t(e,{strict:!1})?ce(e,n,r,{strict:i}):se(e,n,r,{strict:i})}function x(e,t){if(typeof t==`number`&&t>0&&t>o(e)-1)throw new s({offset:t,position:`start`,size:o(e)})}function S(e,t,n){if(typeof t==`number`&&typeof n==`number`&&o(e)!==n-t)throw new s({offset:n,position:`end`,size:o(e)})}function se(e,t,n,{strict:r}={}){x(e,t);let i=e.slice(t,n);return r&&S(i,t,n),i}function ce(e,t,n,{strict:r}={}){x(e,t);let i=`0x${e.replace(`0x`,``).slice((t??0)*2,(n??e.length)*2)}`;return r&&S(i,t,n),i}function C(e,{dir:t=`left`}={}){let n=typeof e==`string`?e.replace(`0x`,``):e,r=0;for(let e=0;e<n.length-1&&n[t===`left`?e:n.length-e-1].toString()===`0`;e++)r++;return n=t===`left`?n.slice(r):n.slice(0,n.length-r),typeof e==`string`?(n.length===1&&t===`right`&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}var le=class extends _{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:`NegativeOffsetError`})}},ue=class extends _{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:`PositionOutOfBoundsError`})}},de=class extends _{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:`RecursiveReadLimitExceededError`})}};const fe={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:1/0,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new de({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new ue({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new le({offset:e});let t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new le({offset:e});let t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){let t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){let n=t??this.position;return this.assertPosition(n+e-1),this.bytes.subarray(n,n+e)},inspectUint8(e){let t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){let t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){let t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){let t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,e&255),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();let e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();let n=this.inspectBytes(e);return this.position+=t??e,n},readUint8(){this.assertReadLimit(),this._touch();let e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();let e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();let e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();let e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){let t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===1/0)return;let e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function w(e,{recursiveReadLimit:t=8192}={}){let n=Object.create(fe);return n.bytes=e,n.dataView=new DataView(e.buffer??e,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function pe(e){return typeof e[0]==`string`?T(e):me(e)}function me(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function T(e){return`0x${e.reduce((e,t)=>e+t.replace(`0x`,``),``)}`}const he=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,E=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function D(e,t){if(e.length!==t.length)throw new re({expectedLength:e.length,givenLength:t.length});return k(ge({params:e,values:t}))}function ge({params:e,values:t}){let n=[];for(let r=0;r<e.length;r++)n.push(O({param:e[r],value:t[r]}));return n}function O({param:e,value:t}){let n=A(e.type);if(n){let[r,i]=n;return ve(t,{length:r,param:{...e,type:i}})}if(e.type===`tuple`)return Ce(t,{param:e});if(e.type===`address`)return _e(t);if(e.type===`bool`)return be(t);if(e.type.startsWith(`uint`)||e.type.startsWith(`int`)){let n=e.type.startsWith(`int`),[,,r=`256`]=E.exec(e.type)??[];return xe(t,{signed:n,size:Number(r)})}if(e.type.startsWith(`bytes`))return ye(t,{param:e});if(e.type===`string`)return Se(t);throw new ae(e.type,{docsPath:`/docs/contract/encodeAbiParameters`})}function k(e){let t=0;for(let n=0;n<e.length;n++){let{dynamic:r,encoded:i}=e[n];t+=r?32:o(i)}let n=[],r=[],i=0;for(let a=0;a<e.length;a++){let{dynamic:s,encoded:c}=e[a];s?(n.push(l(t+i,{size:32})),r.push(c),i+=o(c)):n.push(c)}return T([...n,...r])}function _e(e){if(!d(e))throw new m({address:e});return{dynamic:!1,encoded:u(e.toLowerCase())}}function ve(e,{length:t,param:n}){let r=t===null;if(!Array.isArray(e))throw new oe(e);if(!r&&e.length!==t)throw new te({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let i=e.length===0&&j(n),a=[];for(let t=0;t<e.length;t++){let r=O({param:n,value:e[t]});r.dynamic&&(i=!0),a.push(r)}if(r||i){let e=k(a);if(r)return{dynamic:!0,encoded:T([l(a.length,{size:32}),e])};if(i)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:T(a.map(({encoded:e})=>e))}}function ye(e,{param:t}){let[,n]=t.type.split(`bytes`),r=o(e);if(!n){let t=e;return r%32!=0&&(t=u(t,{dir:`right`,size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:T([u(l(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new ne({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:u(e,{dir:`right`})}}function be(e){if(typeof e!=`boolean`)throw new _(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:u(h(e))}}function xe(e,{signed:t,size:n=256}){if(typeof n==`number`){let r=2n**(BigInt(n)-(t?1n:0n))-1n,i=t?-r-1n:0n;if(e>r||e<i)throw new p({max:r.toString(),min:i.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:l(e,{size:32,signed:t})}}function Se(e){let t=g(e),n=Math.ceil(o(t)/32),r=[];for(let e=0;e<n;e++)r.push(u(b(t,e*32,(e+1)*32),{dir:`right`}));return{dynamic:!0,encoded:T([u(l(o(t),{size:32})),...r])}}function Ce(e,{param:t}){let n=!1,r=[];for(let i=0;i<t.components.length;i++){let a=t.components[i],o=O({param:a,value:e[Array.isArray(e)?i:a.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?k(r):T(r.map(({encoded:e})=>e))}}function A(e){let t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function j(e){let{type:t}=e;if(t===`string`||t===`bytes`||t.endsWith(`[]`))return!0;if(t===`tuple`)return e.components.some(j);let n=A(t);return n?j({...e,type:n[1]}):!1}const we=(e,t,n)=>JSON.stringify(e,(e,n)=>{let r=typeof n==`bigint`?n.toString():n;return typeof t==`function`?t(e,r):r},n),M={wei:0,gwei:9,szabo:12,finney:15,ether:18};function Te(e,t=0){if(!Number.isInteger(t)||t<0)throw new De({decimals:t});let n=e.toString(),r=n.startsWith(`-`);r&&(n=n.slice(1)),n=n.padStart(t,`0`);let[i,a]=[n.slice(0,n.length-t),n.slice(n.length-t)];return a=a.replace(/(0+)$/,``),`${r?`-`:``}${i||`0`}${a?`.${a}`:``}`}function Ee(e,t=`wei`){return Te(e,M.gwei-M[t])}var De=class extends Error{constructor({decimals:e}){super(`\`decimals\` must be a non-negative integer. Got \`${e}\`.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:`Value.InvalidDecimalsError`})}};function N(e,t=`wei`){return Ee(e,t)}function Oe(e){let t=Object.entries(e).map(([e,t])=>t===void 0||t===!1?null:[e,t]).filter(Boolean),n=t.reduce((e,[t])=>Math.max(e,t.length),0);return t.map(([e,t])=>` ${`${e}:`.padEnd(n+1)} ${t}`).join(`
|
|
6
|
+
`)}var ke=class extends _{constructor({v:e}){super(`Invalid \`v\` value "${e}". Expected 27 or 28.`,{name:`InvalidLegacyVError`})}},Ae=class extends _{constructor({transaction:e}){super(`Cannot infer a transaction type from provided transaction.`,{metaMessages:[`Provided Transaction:`,`{`,Oe(e),`}`,``,`To infer the type, either provide:`,"- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:`InvalidSerializableTransactionError`})}},je=class extends _{constructor({storageKey:e}){super(`Size for storage key "${e}" is invalid. Expected 32 bytes. Got ${Math.floor((e.length-2)/2)} bytes.`,{name:`InvalidStorageKeySizeError`})}},P=class extends _{constructor({cause:e,message:t}={}){let n=t?.replace(`execution reverted: `,``)?.replace(`execution reverted`,``);super(`Execution reverted ${n?`with reason: ${n}`:`for an unknown reason`}.`,{cause:e,name:`ExecutionRevertedError`})}};Object.defineProperty(P,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(P,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted|gas required exceeds allowance/});var F=class extends _{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${N(t)} gwei`:``}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:e,name:`FeeCapTooHighError`})}};Object.defineProperty(F,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/}),Object.defineProperty(class extends _{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${N(t)}`:``} gwei) cannot be lower than the block base fee.`,{cause:e,name:`FeeCapTooLowError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/}),Object.defineProperty(class extends _{constructor({cause:e,nonce:t}={}){super(`Nonce provided for the transaction ${t?`(${t}) `:``}is higher than the next one expected.`,{cause:e,name:`NonceTooHighError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/}),Object.defineProperty(class extends _{constructor({cause:e,nonce:t}={}){super([`Nonce provided for the transaction ${t?`(${t}) `:``}is lower than the current nonce of the account.`,"Try increasing the nonce or find the latest nonce with `getTransactionCount`."].join(`
|
|
7
|
+
`),{cause:e,name:`NonceTooLowError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/}),Object.defineProperty(class extends _{constructor({cause:e,nonce:t}={}){super(`Nonce provided for the transaction ${t?`(${t}) `:``}exceeds the maximum allowed nonce.`,{cause:e,name:`NonceMaxValueError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/}),Object.defineProperty(class extends _{constructor({cause:e}={}){super([`The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.`].join(`
|
|
8
|
+
`),{cause:e,metaMessages:[`This error could arise when the account does not have enough funds to:`,` - pay for the total gas fee,`,` - pay for the value to send.`,` `,"The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."],name:`InsufficientFundsError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/}),Object.defineProperty(class extends _{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:``}provided for the transaction exceeds the limit allowed for the block.`,{cause:e,name:`IntrinsicGasTooHighError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/}),Object.defineProperty(class extends _{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:``}provided for the transaction is too low.`,{cause:e,name:`IntrinsicGasTooLowError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/}),Object.defineProperty(class extends _{constructor({cause:e}){super(`The transaction type is not supported for this chain.`,{cause:e,name:`TransactionTypeNotSupportedError`})}},"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});var I=class extends _{constructor({cause:e,maxPriorityFeePerGas:t,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${t?` = ${N(t)} gwei`:``}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${N(n)} gwei`:``}).`].join(`
|
|
9
|
+
`),{cause:e,name:`TipAboveFeeCapError`})}};Object.defineProperty(I,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/}),2n**(8n-1n)-1n,2n**(16n-1n)-1n,2n**(24n-1n)-1n,2n**(32n-1n)-1n,2n**(40n-1n)-1n,2n**(48n-1n)-1n,2n**(56n-1n)-1n,2n**(64n-1n)-1n,2n**(72n-1n)-1n,2n**(80n-1n)-1n,2n**(88n-1n)-1n,2n**(96n-1n)-1n,2n**(104n-1n)-1n,2n**(112n-1n)-1n,2n**(120n-1n)-1n,2n**(128n-1n)-1n,2n**(136n-1n)-1n,2n**(144n-1n)-1n,2n**(152n-1n)-1n,2n**(160n-1n)-1n,2n**(168n-1n)-1n,2n**(176n-1n)-1n,2n**(184n-1n)-1n,2n**(192n-1n)-1n,2n**(200n-1n)-1n,2n**(208n-1n)-1n,2n**(216n-1n)-1n,2n**(224n-1n)-1n,2n**(232n-1n)-1n,2n**(240n-1n)-1n,2n**(248n-1n)-1n,2n**(256n-1n)-1n,-(2n**(8n-1n)),-(2n**(16n-1n)),-(2n**(24n-1n)),-(2n**(32n-1n)),-(2n**(40n-1n)),-(2n**(48n-1n)),-(2n**(56n-1n)),-(2n**(64n-1n)),-(2n**(72n-1n)),-(2n**(80n-1n)),-(2n**(88n-1n)),-(2n**(96n-1n)),-(2n**(104n-1n)),-(2n**(112n-1n)),-(2n**(120n-1n)),-(2n**(128n-1n)),-(2n**(136n-1n)),-(2n**(144n-1n)),-(2n**(152n-1n)),-(2n**(160n-1n)),-(2n**(168n-1n)),-(2n**(176n-1n)),-(2n**(184n-1n)),-(2n**(192n-1n)),-(2n**(200n-1n)),-(2n**(208n-1n)),-(2n**(216n-1n)),-(2n**(224n-1n)),-(2n**(232n-1n)),-(2n**(240n-1n)),-(2n**(248n-1n)),-(2n**(256n-1n));const L=2n**256n-1n;function R(e,t=`hex`){let n=z(e),i=w(new Uint8Array(n.length));return n.encode(i),t===`hex`?r(i.bytes):i.bytes}function z(e){return Array.isArray(e)?Me(e.map(e=>z(e))):Ne(e)}function Me(e){let t=e.reduce((e,t)=>e+t.length,0),n=B(t);return{length:t<=55?1+t:1+n+t,encode(r){t<=55?r.pushByte(192+t):(r.pushByte(247+n),n===1?r.pushUint8(t):n===2?r.pushUint16(t):n===3?r.pushUint24(t):r.pushUint32(t));for(let{encode:t}of e)t(r)}}}function Ne(e){let t=typeof e==`string`?n(e):e,r=B(t.length);return{length:t.length===1&&t[0]<128?1:t.length<=55?1+t.length:1+r+t.length,encode(e){t.length===1&&t[0]<128?e.pushBytes(t):t.length<=55?(e.pushByte(128+t.length),e.pushBytes(t)):(e.pushByte(183+r),r===1?e.pushUint8(t.length):r===2?e.pushUint16(t.length):r===3?e.pushUint24(t.length):e.pushUint32(t.length),e.pushBytes(t))}}}function B(e){if(e<256)return 1;if(e<2**16)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new _(`Length is too large.`)}function Pe(e){let{chainId:t,nonce:r,to:i}=e,a=e.contractAddress??e.address,o=c(T([`0x05`,R([t?l(t):`0x`,a,r?l(r):`0x`])]));return i===`bytes`?n(o):o}function V(e){let{kzg:t}=e,i=e.to??(typeof e.blobs[0]==`string`?`hex`:`bytes`),a=typeof e.blobs[0]==`string`?e.blobs.map(e=>n(e)):e.blobs,o=[];for(let e of a)o.push(Uint8Array.from(t.blobToKzgCommitment(e)));return i===`bytes`?o:o.map(e=>r(e))}function H(e){let{kzg:t}=e,i=e.to??(typeof e.blobs[0]==`string`?`hex`:`bytes`),a=typeof e.blobs[0]==`string`?e.blobs.map(e=>n(e)):e.blobs,o=typeof e.commitments[0]==`string`?e.commitments.map(e=>n(e)):e.commitments,s=[];for(let e=0;e<a.length;e++){let n=a[e],r=o[e];s.push(Uint8Array.from(t.computeBlobKzgProof(n,r)))}return i===`bytes`?s:s.map(e=>r(e))}function Fe(n,r){let a=r||`hex`,o=e(t(n,{strict:!1})?f(n):n);return a===`bytes`?o:i(o)}function Ie(e){let{commitment:t,version:n=1}=e,i=e.to??(typeof t==`string`?`hex`:`bytes`),a=Fe(t,`bytes`);return a.set([n],0),i===`bytes`?a:r(a)}function Le(e){let{commitments:t,version:n}=e,r=e.to??(typeof t[0]==`string`?`hex`:`bytes`),i=[];for(let e of t)i.push(Ie({commitment:e,to:r,version:n}));return i}var Re=class extends _{constructor({maxSize:e,size:t}){super(`Blob size is too large.`,{metaMessages:[`Max: ${e} bytes`,`Given: ${t} bytes`],name:`BlobSizeTooLargeError`})}},U=class extends _{constructor(){super(`Blob data must not be empty.`,{name:`EmptyBlobError`})}},ze=class extends _{constructor({hash:e,size:t}){super(`Versioned hash "${e}" size is invalid.`,{metaMessages:[`Expected: 32`,`Received: ${t}`],name:`InvalidVersionedHashSizeError`})}},Be=class extends _{constructor({hash:e,version:t}){super(`Versioned hash "${e}" version is invalid.`,{metaMessages:[`Expected: 1`,`Received: ${t}`],name:`InvalidVersionedHashVersionError`})}};function Ve(e){let t=e.to??(typeof e.data==`string`?`hex`:`bytes`),i=typeof e.data==`string`?n(e.data):e.data,a=o(i);if(!a)throw new U;if(a>761855)throw new Re({maxSize:761855,size:a});let s=[],c=!0,l=0;for(;c;){let e=w(new Uint8Array(131072)),t=0;for(;t<4096;){let n=i.slice(l,l+31);if(e.pushByte(0),e.pushBytes(n),n.length<31){e.pushByte(128),c=!1;break}t++,l+=31}s.push(e)}return t===`bytes`?s.map(e=>e.bytes):s.map(e=>r(e.bytes))}function He(e){let{data:t,kzg:n,to:r}=e,i=e.blobs??Ve({data:t,to:r}),a=e.commitments??V({blobs:i,kzg:n,to:r}),o=e.proofs??H({blobs:i,commitments:a,kzg:n,to:r}),s=[];for(let e=0;e<i.length;e++)s.push({blob:i[e],commitment:a[e],proof:o[e]});return s}function Ue(e){let{authorizationList:t}=e;if(t)for(let e of t){let{chainId:t}=e,n=e.address;if(!d(n))throw new m({address:n});if(t<0)throw new y({chainId:t})}W(e)}function We(e){let{blobVersionedHashes:t}=e;if(t){if(t.length===0)throw new U;for(let e of t){let t=o(e),n=a(b(e,0,1));if(t!==32)throw new ze({hash:e,size:t});if(n!==1)throw new Be({hash:e,version:n})}}W(e)}function W(e){let{chainId:t,maxPriorityFeePerGas:n,maxFeePerGas:r,to:i}=e;if(t<=0)throw new y({chainId:t});if(i&&!d(i))throw new m({address:i});if(r&&r>L)throw new F({maxFeePerGas:r});if(n&&r&&n>r)throw new I({maxFeePerGas:r,maxPriorityFeePerGas:n})}function Ge(e){let{chainId:t,maxPriorityFeePerGas:n,gasPrice:r,maxFeePerGas:i,to:a}=e;if(t<=0)throw new y({chainId:t});if(a&&!d(a))throw new m({address:a});if(n||i)throw new _("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid EIP-2930 Transaction attribute.");if(r&&r>L)throw new F({maxFeePerGas:r})}function Ke(e){let{chainId:t,maxPriorityFeePerGas:n,gasPrice:r,maxFeePerGas:i,to:a}=e;if(a&&!d(a))throw new m({address:a});if(t!==void 0&&t<=0)throw new y({chainId:t});if(n||i)throw new _("`maxFeePerGas`/`maxPriorityFeePerGas` is not a valid Legacy Transaction attribute.");if(r&&r>L)throw new F({maxFeePerGas:r})}function qe(e){if(e.type)return e.type;if(e.authorizationList!==void 0)return`eip7702`;if(e.blobs!==void 0||e.blobVersionedHashes!==void 0||e.maxFeePerBlobGas!==void 0||e.sidecars!==void 0)return`eip4844`;if(e.maxFeePerGas!==void 0||e.maxPriorityFeePerGas!==void 0)return`eip1559`;if(e.gasPrice!==void 0)return e.accessList===void 0?`legacy`:`eip2930`;throw new Ae({transaction:e})}function G(e){if(!e||e.length===0)return[];let t=[];for(let n=0;n<e.length;n++){let{address:r,storageKeys:i}=e[n];for(let e=0;e<i.length;e++)if(i[e].length-2!=64)throw new je({storageKey:i[e]});if(!d(r,{strict:!1}))throw new m({address:r});t.push([r,i])}return t}function Je(e,t){let n=qe(e);return n===`eip1559`?Ze(e,t):n===`eip2930`?Qe(e,t):n===`eip4844`?Xe(e,t):n===`eip7702`?Ye(e,t):$e(e,t)}function Ye(e,t){let{authorizationList:n,chainId:r,gas:i,nonce:a,to:o,value:s,maxFeePerGas:c,maxPriorityFeePerGas:u,accessList:d,data:f}=e;Ue(e);let p=G(d),m=et(n);return T([`0x04`,R([l(r),a?l(a):`0x`,u?l(u):`0x`,c?l(c):`0x`,i?l(i):`0x`,o??`0x`,s?l(s):`0x`,f??`0x`,p,m,...K(e,t)])])}function Xe(e,t){let{chainId:n,gas:i,nonce:a,to:o,value:s,maxFeePerBlobGas:c,maxFeePerGas:u,maxPriorityFeePerGas:d,accessList:f,data:p}=e;We(e);let m=e.blobVersionedHashes,h=e.sidecars;if(e.blobs&&(m===void 0||h===void 0)){let t=typeof e.blobs[0]==`string`?e.blobs:e.blobs.map(e=>r(e)),n=e.kzg,i=V({blobs:t,kzg:n});m===void 0&&(m=Le({commitments:i})),h===void 0&&(h=He({blobs:t,commitments:i,proofs:H({blobs:t,commitments:i,kzg:n})}))}let ee=G(f),g=[l(n),a?l(a):`0x`,d?l(d):`0x`,u?l(u):`0x`,i?l(i):`0x`,o??`0x`,s?l(s):`0x`,p??`0x`,ee,c?l(c):`0x`,m??[],...K(e,t)],_=[],v=[],y=[];if(h)for(let e=0;e<h.length;e++){let{blob:t,commitment:n,proof:r}=h[e];_.push(t),v.push(n),y.push(r)}return T([`0x03`,R(h?[g,_,v,y]:g)])}function Ze(e,t){let{chainId:n,gas:r,nonce:i,to:a,value:o,maxFeePerGas:s,maxPriorityFeePerGas:c,accessList:u,data:d}=e;W(e);let f=G(u);return T([`0x02`,R([l(n),i?l(i):`0x`,c?l(c):`0x`,s?l(s):`0x`,r?l(r):`0x`,a??`0x`,o?l(o):`0x`,d??`0x`,f,...K(e,t)])])}function Qe(e,t){let{chainId:n,gas:r,data:i,nonce:a,to:o,value:s,accessList:c,gasPrice:u}=e;Ge(e);let d=G(c);return T([`0x01`,R([l(n),a?l(a):`0x`,u?l(u):`0x`,r?l(r):`0x`,o??`0x`,s?l(s):`0x`,i??`0x`,d,...K(e,t)])])}function $e(e,t){let{chainId:n=0,gas:r,data:i,nonce:a,to:o,value:s,gasPrice:c}=e;Ke(e);let u=[a?l(a):`0x`,c?l(c):`0x`,r?l(r):`0x`,o??`0x`,s?l(s):`0x`,i??`0x`];if(t){let e=(()=>{if(t.v>=35n)return(t.v-35n)/2n>0?t.v:27n+(t.v===35n?0n:1n);if(n>0)return BigInt(n*2)+BigInt(35n+t.v-27n);let e=27n+(t.v===27n?0n:1n);if(t.v!==e)throw new ke({v:t.v});return e})(),r=C(t.r),i=C(t.s);u=[...u,l(e),r===`0x00`?`0x`:r,i===`0x00`?`0x`:i]}else n>0&&(u=[...u,l(n),`0x`,`0x`]);return R(u)}function K(e,t){let n=t??e,{v:r,yParity:i}=n;if(n.r===void 0||n.s===void 0||r===void 0&&i===void 0)return[];let a=C(n.r),o=C(n.s);return[typeof i==`number`?i?l(1):`0x`:r===0n?`0x`:r===1n?l(1):r===27n?`0x`:l(1),a===`0x00`?`0x`:a,o===`0x00`?`0x`:o]}function et(e){if(!e||e.length===0)return[];let t=[];for(let n of e){let{chainId:e,nonce:r,...a}=n,o=n.address;t.push([e?i(e):`0x`,o,r?i(r):`0x`,...K({},a)])}return t}var tt=class extends _{constructor({domain:e}){super(`Invalid domain "${we(e)}".`,{metaMessages:[`Must be a valid EIP-712 domain.`]})}},nt=class extends _{constructor({primaryType:e,types:t}){super(`Invalid primary type \`${e}\` must be one of \`${JSON.stringify(Object.keys(t))}\`.`,{docsPath:`/api/glossary/Errors#typeddatainvalidprimarytypeerror`,metaMessages:["Check that the primary type is a key in `types`."]})}},rt=class extends _{constructor({type:e}){super(`Struct type "${e}" is invalid.`,{metaMessages:[`Struct type must not be a Solidity type.`],name:`InvalidStructTypeError`})}},it=class extends _{constructor({type:e}){let t=e.replace(/^(u?int)/,`$&256`);super(`Type "${e}" is not a valid EIP-712 type.`,{metaMessages:[`Use "${t}" instead.`],name:`InvalidTypedDataTypeError`})}};function at(e){let{domain:t,message:n,primaryType:r,types:i}=e,a=(e,t)=>{for(let n of e){let{name:e,type:r}=n,s=t[e],c=r.replace(/(\[[0-9]*\])+$/,``);if(c===`int`||c===`uint`)throw new it({type:r});let u=r.match(E);if(u&&(typeof s==`number`||typeof s==`bigint`)){let[e,t,n]=u;l(s,{signed:t===`int`,size:Number.parseInt(n,10)/8})}if(r===`address`&&typeof s==`string`&&!d(s))throw new m({address:s});let f=r.match(he);if(f){let[e,t]=f;if(t&&o(s)!==Number.parseInt(t,10))throw new ie({expectedSize:Number.parseInt(t,10),givenSize:o(s)})}let p=i[r];p&&(st(r),a(p,s))}};if(i.EIP712Domain&&t){if(typeof t!=`object`)throw new tt({domain:t});a(i.EIP712Domain,t)}if(r!==`EIP712Domain`){if(i[r])a(i[r],n);else throw new nt({primaryType:r,types:i})}}function ot({domain:e}){return[typeof e?.name==`string`&&{name:`name`,type:`string`},e?.version&&{name:`version`,type:`string`},(typeof e?.chainId==`number`||typeof e?.chainId==`bigint`)&&{name:`chainId`,type:`uint256`},e?.verifyingContract&&{name:`verifyingContract`,type:`address`},e?.salt&&{name:`salt`,type:`bytes32`}].filter(Boolean)}function st(e){if(e===`address`||e===`bool`||e===`string`||e.startsWith(`bytes`)||e.startsWith(`uint`)||e.startsWith(`int`))throw new rt({type:e})}function q(e){let{domain:t={},message:n,primaryType:r}=e,i={EIP712Domain:ot({domain:t}),...e.types};at({domain:t,message:n,primaryType:r,types:i});let a=[`0x1901`];return t&&a.push(ct({domain:t,types:i})),r!==`EIP712Domain`&&a.push(lt({data:n,primaryType:r,types:i})),c(pe(a))}function ct({domain:e,types:t}){return lt({data:e,primaryType:`EIP712Domain`,types:t})}function lt({data:e,primaryType:t,types:n}){let r=ut({data:e,primaryType:t,types:n});return c(r)}function ut({data:e,primaryType:t,types:n}){let r=[{type:`bytes32`}],i=[dt({primaryType:t,types:n})];for(let a of n[t]){let[t,o]=mt({types:n,name:a.name,type:a.type,value:e[a.name]});r.push(t),i.push(o)}return D(r,i)}function dt({primaryType:e,types:t}){let n=i(ft({primaryType:e,types:t}));return c(n)}function ft({primaryType:e,types:t}){let n=``,r=pt({primaryType:e,types:t});r.delete(e);let i=[e,...Array.from(r).sort()];for(let e of i)n+=`${e}(${t[e].map(({name:e,type:t})=>`${t} ${e}`).join(`,`)})`;return n}function pt({primaryType:e,types:t},n=new Set){let r=e.match(/^\w*/u)?.[0];if(n.has(r)||t[r]===void 0)return n;n.add(r);for(let e of t[r])pt({primaryType:e.type,types:t},n);return n}function mt({types:e,name:t,type:n,value:r}){if(e[n]!==void 0)return[{type:`bytes32`},c(ut({data:r,primaryType:n,types:e}))];if(n===`bytes`)return[{type:`bytes32`},c(r)];if(n===`string`)return[{type:`bytes32`},c(i(r))];if(n.lastIndexOf(`]`)===n.length-1){let i=n.slice(0,n.lastIndexOf(`[`)),a=r.map(n=>mt({name:t,type:i,types:e,value:n}));return[{type:`bytes32`},c(D(a.map(([e])=>e),a.map(([,e])=>e)))]}return[{type:n},r]}const J=v.pipe(v.string(),v.transform(ee)),Y=v.pipe(v.string(),v.regex(/^\d+$/)),X=v.custom(e=>typeof e==`string`&&/^0x([0-9a-fA-F]{2})*$/.test(e),`expected hex bytes`),ht=v.custom(e=>typeof e==`string`&&/^0x[0-9a-fA-F]{64}$/.test(e),`expected a 32-byte value`),gt=[`base`,`base-sepolia`],Z={base:{name:`USD Coin`,version:`2`,chainId:8453,verifyingContract:`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`},"base-sepolia":{name:`USDC`,version:`2`,chainId:84532,verifyingContract:`0x036CbD53842c5426634e7929541eC2318f3dCF7e`}},_t={name:`TKGasDelegate`,version:`1.1`},vt={...Object.fromEntries(Object.entries(Z).map(([e,t])=>[e,t.chainId])),arc:5042},yt=v.looseObject({transaction:v.object({chainId:v.pipe(v.number(),v.integer(),v.minValue(1)),nonce:v.pipe(v.number(),v.integer(),v.minValue(0)),to:J,value:Y,data:X,gas:Y,maxFeePerGasWei:Y,maxPriorityFeePerGasWei:Y})}),Q=v.looseObject({network:v.picklist(gt),authorization:v.object({from:J,to:J,value:Y,validAfter:v.union([v.number(),Y]),validBefore:v.union([v.number(),Y]),nonce:ht})}),bt=v.looseObject({authorization:v.object({address:J,chainId:v.pipe(v.number(),v.integer(),v.minValue(1)),nonce:v.pipe(v.number(),v.integer(),v.minValue(0))})}),xt=v.looseObject({batch:v.object({from:J,chainId:v.pipe(v.number(),v.integer(),v.minValue(1)),nonce:Y,deadline:v.pipe(v.number(),v.integer(),v.minValue(1)),calls:v.pipe(v.array(v.object({to:J,value:Y,data:X})),v.minLength(1))})}),St=v.looseObject({type:v.literal(`ACTIVITY_TYPE_SIGN_RAW_PAYLOADS`),parameters:v.looseObject({signWith:J,payloads:v.pipe(v.array(ht),v.minLength(1)),encoding:v.literal(`PAYLOAD_ENCODING_HEXADECIMAL`),hashFunction:v.literal(`HASH_FUNCTION_NO_OP`)})});function Ct(e){let t=/^(\d+)(?:\.(\d{1,6}))?$/.exec(e.trim());if(t===null)return null;let[,n=`0`,r=``]=t;return BigInt(n)*1000000n+BigInt(r.padEnd(6,`0`))}function wt(e){try{switch(e.kind){case`evm_raw_transaction`:{let{transaction:t}=v.parse(yt,e.payload);return{digest:c(Je({type:`eip1559`,chainId:t.chainId,nonce:t.nonce,to:t.to,value:BigInt(t.value),data:t.data,gas:BigInt(t.gas),maxFeePerGas:BigInt(t.maxFeePerGasWei),maxPriorityFeePerGas:BigInt(t.maxPriorityFeePerGasWei),accessList:[]})),chainId:t.chainId,movesNative:BigInt(t.value)!==0n}}case`eip3009_transfer_authorization`:{let{network:t,authorization:n}=v.parse(Q,e.payload);return{digest:q({domain:Z[t],types:{TransferWithAuthorization:[{name:`from`,type:`address`},{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`validAfter`,type:`uint256`},{name:`validBefore`,type:`uint256`},{name:`nonce`,type:`bytes32`}]},primaryType:`TransferWithAuthorization`,message:{from:n.from,to:n.to,value:BigInt(n.value),validAfter:BigInt(n.validAfter),validBefore:BigInt(n.validBefore),nonce:n.nonce}}),chainId:Z[t].chainId,from:n.from}}case`eip7702_delegation`:{let{authorization:t}=v.parse(bt,e.payload);return{digest:Pe({address:t.address,chainId:t.chainId,nonce:t.nonce}),chainId:t.chainId,delegate:t.address}}case`eip712_execution`:{let{batch:t}=v.parse(xt,e.payload);return{digest:q({domain:{..._t,chainId:t.chainId,verifyingContract:t.from},types:{BatchExecution:[{name:`nonce`,type:`uint128`},{name:`deadline`,type:`uint32`},{name:`calls`,type:`Call[]`}],Call:[{name:`to`,type:`address`},{name:`value`,type:`uint256`},{name:`data`,type:`bytes`}]},primaryType:`BatchExecution`,message:{nonce:BigInt(t.nonce),deadline:t.deadline,calls:t.calls.map(e=>({to:e.to,value:BigInt(e.value),data:e.data}))}}),from:t.from,chainId:t.chainId,movesNative:t.calls.some(e=>BigInt(e.value)!==0n)}}}}catch{return null}return null}function Tt(e){return wt(e)?.digest??null}function $(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Et(e,t){if(e.instructions.length===0)return{ok:!1,reason:`The approval carries nothing to sign.`};let n=e.signerAddress.toLowerCase();for(let t of e.instructions){let e=wt(t);if(e===null||e.digest.toLowerCase()!==t.digest.toLowerCase())return{ok:!1,reason:`An instruction does not match what it says it signs.`};if(t.signerAddress.toLowerCase()!==n)return{ok:!1,reason:`An instruction names a different wallet than the approval.`};let r=vt[t.network];if(r===void 0)return{ok:!1,reason:`An instruction names a network this client cannot place: ${t.network}. If the payment looks right, this client may be out of date.`};if(e.chainId!==r)return{ok:!1,reason:`An instruction names a different network than it signs on.`};if(e.delegate!==void 0&&e.delegate.toLowerCase()!==`0x955d84139e7621bc571b117d8eb5d28a4a222c6f`)return{ok:!1,reason:`An instruction would hand the wallet over to an unrecognised contract.`};if(e.from!==void 0&&e.from.toLowerCase()!==n)return{ok:!1,reason:`An instruction would spend from a different wallet.`};if(e.movesNative===!0)return{ok:!1,reason:`An instruction would move the network's own token.`}}let r=e.instructions.map(e=>e.digest.toLowerCase());if(new Set(r).size!==r.length)return{ok:!1,reason:`The approval lists the same digest more than once.`};let i=new Set;for(let t of e.instructions){if(t.kind!==`eip3009_transfer_authorization`)continue;let e=v.safeParse(Q,t.payload);if(!e.success)continue;let{network:n,authorization:r}=e.output,a=`${n}:${r.from.toLowerCase()}:${r.nonce.toLowerCase()}`;if(i.has(a))return{ok:!1,reason:`The approval spends one authorization nonce twice.`};i.add(a)}if(!$(e.digests.map(e=>e.toLowerCase()),r))return{ok:!1,reason:`The approval lists different digests than its instructions.`};let a;try{a=v.parse(St,JSON.parse(e.body))}catch{return{ok:!1,reason:`The prepared request is not in the shape expected.`}}return $(a.parameters.payloads.map(e=>e.toLowerCase()),r)?a.parameters.signWith.toLowerCase()===n?Dt(e,n,t):{ok:!1,reason:`The prepared request names a different wallet than the approval.`}:{ok:!1,reason:`The prepared request would sign different digests.`}}function Dt(e,t,n){if(n===void 0)return{ok:!0};let r=Ct(n.amount);if(r===null)return{ok:!1,reason:`The requested amount is not an amount this client can check.`};let i=0n;for(let n of e.instructions){if(n.kind===`evm_raw_transaction`||n.kind===`eip712_execution`)return{ok:!0};if(n.kind!==`eip3009_transfer_authorization`)continue;let e=v.safeParse(Q,n.payload);if(!e.success)return{ok:!1,reason:`An instruction does not match what it says it signs.`};e.output.authorization.to.toLowerCase()!==t&&(i+=BigInt(e.output.authorization.value))}return i===r?{ok:!0}:{ok:!1,reason:`This approval does not pay the amount that was requested.`}}export{Tt as rebuildInstructionDigest,Et as verifyPreparedMovement};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{t as e}from"./sha256-CJuuQjmL.mjs";import{t}from"./hmac-DW0MnYTR.mjs";import{A as n,C as r,D as i,E as a,M as o,O as s,S as c,T as l,_ as u,a as d,b as f,c as p,d as m,f as h,g,h as _,i as v,j as y,k as ee,l as te,m as ne,n as re,o as b,p as x,r as ie,s as S,t as ae,u as oe,v as C,w,x as se,y as ce}from"./index.mjs";import{n as le}from"./getAddress-BlHiG3c6.mjs";import{defineCommand as ue}from"citty";import*as T from"valibot";function de(){return`0.1.1`}var E=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(`
|
|
2
|
+
`);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 fe(this,e)}};Object.defineProperty(E,"defaultStaticOptions",{enumerable:!0,configurable:!0,writable:!0,value:{docsOrigin:`https://oxlib.sh`,showVersion:!1,version:`ox@${de()}`}}),E.setStaticOptions(E.defaultStaticOptions);function fe(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause?fe(e.cause,t):t?null:e}function pe(e,t){if(Ne(e)>t)throw new Ie({givenSize:Ne(e),maxSize:t})}const D={zero:48,nine:57,A:65,F:70,a:97,f:102};function me(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 he(e,t={}){let{dir:n,size:r=32}=t;if(r===0)return e;if(e.length>r)throw new Le({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 ge(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 _e(e,t){if(Ce(e)>t)throw new we({givenSize:Ce(e),maxSize:t})}function ve(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 Te({size:Math.ceil(i.length/2),targetSize:r,type:`Hex`});return`0x${i[n===`right`?`padEnd`:`padStart`](r*2,`0`)}`}function ye(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=>ye(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)}:${ye(r)}`),t},[]).join(`,`)}}`}const be=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function xe(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=be[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(_e(r,t.size),Se(r,t.size)):r}function Se(e,t){return ve(e,{dir:`right`,size:t})}function Ce(e){return Math.ceil((e.length-2)/2)}var we=class extends E{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`})}},Te=class extends E{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 Ee=new TextDecoder,De=new TextEncoder;function Oe(e){return e instanceof Uint8Array?e:typeof e==`string`?Ae(e):ke(e)}function ke(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Ae(e,t={}){let{size:n}=t,r=e;n&&(_e(e,n),r=Se(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=me(i.charCodeAt(t++)),r=me(i.charCodeAt(t++));if(n===void 0||r===void 0)throw new E(`Invalid byte sequence ("${i[t-2]}${i[t-1]}" in "${i}").`);o[e]=n<<4|r}return o}function je(e,t={}){let{size:n}=t,r=De.encode(e);return typeof n==`number`?(pe(r,n),Me(r,n)):r}function Me(e,t){return he(e,{dir:`right`,size:t})}function Ne(e){return e.length}function Pe(e,t={}){let{size:n}=t,r=e;return n!==void 0&&(pe(r,n),r=Fe(r)),Ee.decode(r)}function Fe(e){return ge(e,{dir:`right`})}var Ie=class extends E{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`})}},Le=class extends E{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 Re(n,r,i={}){let{as:a=typeof r==`string`?`Hex`:`Bytes`}=i,o=t(e,Oe(n),Oe(r));return a===`Bytes`?o:xe(o)}const ze=new TextEncoder,Be=new TextDecoder,Ve=Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[t,e.charCodeAt(0)])),He={...Object.fromEntries(Array.from(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`).map((e,t)=>[e.charCodeAt(0),t])),61:0,45:62,95:63};function Ue(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]=Ve[r>>18],i[t+1]=Ve[r>>12&63],i[t+2]=Ve[r>>6&63],i[t+3]=Ve[r&63]}let a=e.length%3,o=Math.floor(e.length/3)*4+(a&&a+1),s=Be.decode(new Uint8Array(i.buffer,0,o));return n&&a===1&&(s+=`==`),n&&a===2&&(s+=`=`),r&&(s=s.replaceAll(`+`,`-`).replaceAll(`/`,`_`)),s}function We(e,t={}){return Ue(je(e),t)}function Ge(e){let t=e.replace(/=+$/,``),n=t.length,r=new Uint8Array(n+3);ze.encodeInto(t+`===`,r);for(let e=0,n=0;e<t.length;e+=4,n+=3){let t=(He[r[e]]<<18)+(He[r[e+1]]<<12)+(He[r[e+2]]<<6)+He[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 Ke(e){return Pe(Ge(e))}const O={acceptPayment:`Accept-Payment`,authorization:`Authorization`,paymentAuthorization:`Payment-Authorization`,paymentReceipt:`Payment-Receipt`,paymentSession:`Payment-Session`,paymentSessionSnapshot:`Payment-Session-Snapshot`,wwwAuthenticate:`WWW-Authenticate`},qe={payment:`Payment`};function Je(e){let t=Ke(e);return JSON.parse(t)}function k(e){return We(ye(e),{pad:!1,url:!0})}function Ye(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 Xe(e,t){return typeof t==`bigint`?t.toString():t}function Ze(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Qe(e){return e==null}function $e(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function et(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}const tt=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function nt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rt(e){if(nt(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return nt(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}const it=new Set([`string`,`number`,`symbol`]);function at(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function ot(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function A(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 st(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}function ct(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 lt(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 j(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function ut(e){return typeof e==`string`?e:e?.message}function dt(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function M(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:ut(e.inst?._zod.def?.error?.(e))??ut(a?.(e))??ut(t?.error?.(e))??ut(n.customError?.(e))??ut(n.localeError?.(e))??`Invalid input`,{inst:s,schema:c,continue:l,input:u,...d}=e;return d.path??=[],d.message=o,t?.reportInput&&(d.input=u),d}const ft=/[\uD800-\uDBFF]/;function pt(e){let t=e.length;if(!ft.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function mt(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function ht(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function gt(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):yt(e,n,r.value)}}function _t(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function vt(e,t,n){return _t(e,t,n,!1)}function yt(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:_t(this,t,n.bind(this))},set(e){_t(this,t,e)}})}function bt(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}let xt,N=!1;const St={configurable:!0,get(){N=!0}};function P(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&xt!==e._zod){xt=void 0;return}xt=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,St);let e=N;N=!1;try{let r=n(this);return N?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),N||=e,r}catch(n){throw delete this[t],N||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function Ct(e,t,n,r){let i=bt(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var wt;const Tt={value:void 0,enumerable:!1};let Et=`captureStackTrace`in Error?Error:null;function Dt(e){let t=Et;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return Et=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function F(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){Tt.value=new a(r);try{Object.defineProperty(n,"_zod",Tt)}finally{Tt.value=void 0}}if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),gt(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?Dt(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var Ot=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}};(wt=globalThis).__zod_globalConfig??(wt.__zod_globalConfig={});const kt=globalThis.__zod_globalConfig;function I(e){return e&&Object.assign(kt,e),kt}function At(){let e=this._zod;return e.message??=JSON.stringify(e.def,Xe,2),e.message}function jt(e){this._zod.message=e}const Mt={get:At,set:jt,enumerable:!0,configurable:!0},Nt={value:void 0,enumerable:!1},Pt={value:void 0,enumerable:!1},Ft=new WeakSet([Object.prototype,Error.prototype]),It=(e,t)=>{e.name=`$ZodError`,Nt.value=e._zod,Object.defineProperty(e,"_zod",Nt),Pt.value=t,Object.defineProperty(e,"issues",Pt),Nt.value=void 0,Pt.value=void 0,Object.defineProperty(e,"message",Mt);let n=Object.getPrototypeOf(e);Ft.has(n)||(Ft.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},Lt=F(`$ZodError`,It),Rt=F(`$ZodError`,It,void 0,{Parent:Error}),zt=(e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Ot;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>M(e,o,I())));throw tt(n,a?.callee??t),n}return s.value};return t})(Rt),Bt=(e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>M(e,o,I())));throw tt(n,a?.callee??t),n}return s.value};return t})(Rt),Vt=(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 Ot;return a.issues.length?{success:!1,error:new(e??Lt)(a.issues.map(e=>M(e,i,I())))}:{success:!0,data:a.value}})(Rt),Ht=(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=>M(e,i,I())))}:{success:!0,data:a.value}})(Rt),Ut=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Wt=/^-?\d+(?:\.\d+)?$/,Gt=/^(?:true|false)$/i,Kt=F(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),qt=e=>{let t=e.value;return!Qe(t)&&t.length!==void 0},Jt=F(`$ZodCheckMinLength`,(e,t)=>{var n;Kt.init(e,t),(n=e._zod.def).when??(n.when=qt),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,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?pt(r):i)>=t.minimum)return;let a=mt(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Yt=F(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Kt.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=()=>{})}),Xt=F(`$ZodCheckRegex`,(e,t)=>{Yt.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})}}),Zt={major:4,minor:5,patch:4},L=F(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Zt;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=ct(t),a;for(let o of n){if(o._zod.def.when){if(lt(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new Ot;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(dt(t.issues,n,e),i||=ct(t,n))});else{if(t.issues.length===n)continue;dt(t.issues,n,e),i||=ct(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(ct(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new Ot;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new Ot;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return vt(this,`~standard`,$t(this))},set"~standard"(e){_t(this,`~standard`,e)}}),Qt=e=>e.success?{value:e.data}:{issues:e.error?.issues};function $t(e){return{validate:t=>{try{return Qt(Vt(e,t))}catch{return Ht(e,t).then(Qt)}},vendor:`zod`,version:1}}const en=F(`$ZodString`,(e,t)=>{L.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Ut(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}}),tn=F(`$ZodNumber`,(e,t)=>{L.init(e,t),e._zod.pattern=e._zod.bag.pattern??Wt,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:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),nn=F(`$ZodBoolean`,(e,t)=>{L.init(e,t),e._zod.pattern=Gt,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}}),rn=F(`$ZodUnknown`,(e,t)=>{L.init(e,t),e._zod.parse=e=>e}),an=F(`$ZodNever`,(e,t)=>{L.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function on(e,t,n){e.issues.length&&t.issues.push(...j(n,e.issues)),t.value[n]=e.value}const sn=F(`$ZodArray`,(e,t)=>{L.init(e,t);let n=kt.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[];for(let e=0;e<a.length;e++){let n=a[e],s=t.element._zod.run({value:n,issues:[]},i);s instanceof Promise?o.push(s.then(t=>on(t,r,e))):on(s,r,e)}return o.length?Promise.all(o).then(()=>r):r}});function cn(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...j(n,e.issues))}if(!o&&i===void 0){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}}const ln=[];function un(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:ln,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=st(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function dn(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin,d=c.optout;for(let i in t){if(s.has(i))continue;if(i===`__proto__`){l===`never`&&o.push(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=>cn(e,n,i,t,u,d))):cn(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}const fn=new WeakMap,pn=F(`$ZodObject`,(e,t)=>{if(L.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;fn.set(t,e),Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),fn.set(t,n),n}})}let n=Ze(()=>un(t));P(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||et(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let r=nt,i=t.catchall,a,o=kt.memoizer;o?.attach(e),e._zod.parse=(t,s)=>{a??=n.value;let c=t.value;if(!r(c))return t.issues.push({expected:`object`,code:`invalid_type`,input:c,inst:e}),t;t.value=o?o.alloc(e,t,{},s):{};let l=[],u=a.shape;for(let e of a.allKeys){if(e===`__proto__`)continue;let n=u[e],r=n._zod.optin,i=n._zod.optout,a=n._zod.run({value:c[e],issues:[]},s);a instanceof Promise?l.push(a.then(n=>cn(n,t,e,c,r,i))):cn(a,t,e,c,r,i)}return i?dn(l,c,t,s,n.value,e):l.length?Promise.all(l).then(()=>t):t}});function mn(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=>!ct(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=>M(e,r,I())))}),t)}const hn=F(`$ZodUnion`,(e,t)=>{L.init(e,t),P(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),P(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),P(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),P(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>$e(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=>mn(t,r,e,i)):mn(o,r,e,i)}}),gn=F(`$ZodRecord`,(e,t)=>{L.init(e,t);let n=kt.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!rt(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>M(e,i,I())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...j(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...j(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Wt.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>M(e,i,I())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...j(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...j(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),_n=F(`$ZodEnum`,(e,t)=>{L.init(e,t);let n=Ye(t.entries),r=new Set(n);e._zod.values=r;let i=n.filter(e=>it.has(typeof e));e._zod.pattern=RegExp(i.length?`^(${i.map(e=>at(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`),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}}),vn=F(`$ZodLiteral`,(e,t)=>{L.init(e,t);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(t.values.length?`^(${t.values.map(e=>typeof e==`string`?at(e):e?at(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`),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 yn(e,t){return e.value=t.issues.length?void 0:t.value,e}const bn=F(`$ZodOptional`,(e,t)=>{L.init(e,t),P(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,P(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),P(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${$e(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>yn(e,t)):yn(e,r)}return t.innerType._zod.run(e,n)}}),xn=F(`$ZodCustom`,(e,t)=>{Kt.init(e,t),L.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=>Sn(t,n,r,e));Sn(i,n,r,e)}});function Sn(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(ht(e))}}function Cn(e,t){return new e({type:`string`,...A(t)})}function wn(e,t){return new e({type:`number`,checks:[],...A(t)})}function Tn(e,t){return new e({type:`boolean`,...A(t)})}function En(e){return new e({type:`unknown`})}function Dn(e,t){return new e({type:`never`,...A(t)})}function On(e,t){return new Jt({check:`min_length`,...A(t),minimum:e})}function R(e,t){return new Xt({check:`string_format`,format:`regex`,...A(t),pattern:e})}function kn(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...A(n)})}const z=F(`ZodMiniType`,(e,t)=>{if(!e._zod)throw Error(`Uninitialized schema in ZodMiniType.`);L.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){_t(this,`with`,e)},parse(e,t){return zt(this,e,t,{callee:this.parse})},parseAsync(e,t){return Bt(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return Vt(this,e,t)},safeParseAsync(e,t){return Ht(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]},{parent:!0})},clone(e,t){return ot(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),An=F(`ZodMiniString`,(e,t)=>{en.init(e,t),z.init(e,t)});function B(e){return Cn(An,e)}const jn=F(`ZodMiniNumber`,(e,t)=>{tn.init(e,t),z.init(e,t)});function Mn(e){return wn(jn,e)}const Nn=F(`ZodMiniBoolean`,(e,t)=>{nn.init(e,t),z.init(e,t)});function Pn(e){return Tn(Nn,e)}const Fn=F(`ZodMiniUnknown`,(e,t)=>{rn.init(e,t),z.init(e,t)});function V(){return En(Fn)}const In=F(`ZodMiniNever`,(e,t)=>{an.init(e,t),z.init(e,t)});function Ln(e){return Dn(In,e)}const Rn=F(`ZodMiniArray`,(e,t)=>{sn.init(e,t),z.init(e,t)});function zn(e,t){return new Rn({type:`array`,element:e,...A(t)})}const Bn=F(`ZodMiniObject`,(e,t)=>{pn.init(e,t),z.init(e,t),Ct(e,`shape`,e=>e._zod.def.shape,!1)});function H(e,t){let n={type:`object`,shape:e??{},...A(t)};return new Bn(n)}function Vn(e,t){return new Bn({type:`object`,shape:e,catchall:V(),...A(t)})}const Hn=F(`ZodMiniUnion`,(e,t)=>{hn.init(e,t),z.init(e,t)});function Un(e,t){return new Hn({type:`union`,options:e,...A(t)})}const Wn=F(`ZodMiniRecord`,(e,t)=>{gn.init(e,t),z.init(e,t)});function U(e,t,n){return!t||!t._zod?new Wn({type:`record`,keyType:B(),valueType:e,...A(t)}):new Wn({type:`record`,keyType:e,valueType:t,...A(n)})}const Gn=F(`ZodMiniEnum`,(e,t)=>{_n.init(e,t),z.init(e,t),e.options=Object.values(t.entries)});function Kn(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Gn({type:`enum`,entries:n,...A(t)})}const qn=F(`ZodMiniLiteral`,(e,t)=>{vn.init(e,t),z.init(e,t)});function W(e,t){return new qn({type:`literal`,values:Array.isArray(e)?e:[e],...A(t)})}const Jn=F(`ZodMiniOptional`,(e,t)=>{bn.init(e,t),z.init(e,t)});function G(e){return new Jn({type:`optional`,innerType:e})}const Yn=F(`ZodMiniCustom`,(e,t)=>{xn.init(e,t),z.init(e,t)});function Xn(e,t={}){return kn(Yn,e,t)}function Zn(){return B().check(R(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,`Invalid ISO 8601 datetime`))}function Qn(e){return e instanceof Date?Number.isFinite(e.getTime())?e.toISOString():`Invalid Date`:e}function $n(){return B().check(R(/^0x[0-9a-fA-F]{40}$/,`Invalid address`))}function er(){return B().check(R(/^0x[0-9a-fA-F]{64}$/,`Invalid hash`))}function tr(){return B().check(R(/^0x[0-9a-fA-F]+$/,`Invalid signature`))}const nr=H({description:G(B()),digest:G(B().check(R(/^sha-256=/,`Invalid digest format`))),expires:G(Zn()),header:G(B().check(R(/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/,`Invalid HTTP header name`))),id:B().check(On(1)),intent:B(),method:B(),meta:G(U(B(),B())),opaque:G(B()),realm:B(),request:U(B(),V())});function rr(e,t){let{description:n,digest:r,meta:i,method:a,header:o,intent:s,realm:c,request:l,secretKey:u}=e,d=_r(o)?void 0:o,f=e.expires?Qn(e.expires):void 0,p=e.opaque??(i===void 0?void 0:k(i)),m=u?vr({...e,expires:f,...i!==void 0&&{meta:i},opaque:p},{secretKey:u}):e.id;return nr.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 ir(e){let t=[K(`id`,e.id),K(`realm`,e.realm),K(`method`,e.method),K(`intent`,e.intent),K(`request`,k(e.request))];e.description!==void 0&&t.push(K(`description`,e.description)),e.digest!==void 0&&t.push(K(`digest`,e.digest)),e.expires!==void 0&&t.push(K(`expires`,e.expires));let n=e.header;return n!==void 0&&!_r(n)&&t.push(K(`header`,n)),e.opaque===void 0?e.meta!==void 0&&t.push(K(`opaque`,k(e.meta))):t.push(K(`opaque`,e.opaque)),`${qe.payment} ${t.join(`, `)}`}function K(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 ar(e,t){let n=or(e);if(!n)throw Error(`Missing Payment scheme.`);let{request:r,opaque:i,...a}=sr(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 rr({...a,request:Je(r),...i&&{opaque:i}},t)}function or(e){let t=qe.payment,[n]=dr(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 sr(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]=cr(e,n);if(n=o,i in t)throw Error(`Duplicate parameter: ${i}`);t[i]=a}return t}function cr(e,t){if(e[t]===`"`)return lr(e,t+1);let n=t;for(;n<e.length&&e[n]!==`,`;)n++;return[e.slice(t,n).trim(),n]}function lr(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 ur(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 dr(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(!ur(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 fr(e,t){if(e.status!==402)throw Error(`Response status is not 402.`);return pr(e.headers,t)}function pr(e,t){let n=e.get(O.wwwAuthenticate);if(!n)throw Error(`Missing ${O.wwwAuthenticate} header.`);return mr(n,t)}function mr(e,t){let n=dr(e,qe.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 ar(e.slice(r,a).replace(/,\s*$/,``),t)})}function hr(e){let t=[e.realm,e.method,e.intent,k(e.request),e.expires??``,e.digest??``],n=e.header;return n!==void 0&&!_r(n)&&t.push(n),t.push(e.opaque??(e.meta?k(e.meta):``)),t.join(`|`)}function gr(e){return e.header??O.authorization}function _r(e){return e?.toLowerCase()===O.authorization.toLowerCase()}function vr(e,t){let n=hr(e);return Ue(Re(je(t.secretKey),je(n),{as:`Bytes`}),{url:!0,pad:!1})}var yr=class extends Error{name=`MissingPaymentSchemeError`;constructor(){super(`Missing Payment scheme.`)}},br=class extends Error{name=`InvalidCredentialEncodingError`;constructor(){super(`Invalid base64url or JSON.`)}};function xr(e){let t=e.match(RegExp(`^${qe.payment}\\s+(.+)$`,`i`));if(!t?.[1])throw new yr;try{let e=Ke(t[1]),n=JSON.parse(e),{opaque:r,request:i,meta:a,...o}=n.challenge,{meta:s,opaque:c}=Sr(r);return{challenge:nr.parse({...o,...s!==void 0&&{meta:s},...c!==void 0&&{opaque:c},request:Je(i)}),payload:n.payload,...n.source&&{source:n.source}}}catch{throw new br}}function Sr(e){if(e===void 0)return{};if(typeof e==`string`)return{opaque:e};if(!Cr(e))throw Error(`Invalid opaque.`);return{meta:e,opaque:k(e)}}function Cr(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:Object.values(e).every(e=>typeof e==`string`)}var wr=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}}}},Tr=class extends wr{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}.`)}},Er=class extends wr{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 Dr(e,t){if(!e)throw new Tr({...t&&{id:t},reason:`missing required expires field`});if(Number.isNaN(new Date(e).getTime()))throw new Tr({...t&&{id:t},reason:`malformed expires timestamp`});if(new Date(e)<new Date)throw new Er({expires:e})}function Or(e){return e}function kr(e,t){let{canHandleChallenge:n,context:r,createCredential:i}=t;return{...e,canHandleChallenge:n,context:r,createCredential:i}}const Ar=Vn({method:B(),reference:B(),externalId:G(B()),subscriptionId:G(B()),status:W(`success`),timestamp:Zn()});function jr(e){let t=Ke(e);return Mr(JSON.parse(t))}function Mr(e){return Ar.parse(e)}function Nr(e){let t=e.headers.get(O.paymentReceipt);if(!t)throw Error(`Missing ${O.paymentReceipt} header.`);return jr(t)}function Pr(e){return{encode(t){return We(JSON.stringify(e.parse(t)))},decode(t){try{return e.parse(JSON.parse(Ke(t)))}catch{throw new Fr}}}}var Fr=class extends Error{name=`InvalidJsonHeaderError`;constructor(){super(`Invalid base64 JSON header.`)}};const Ir=[`exact`],Lr=`PAYMENT-REQUIRED`,Rr=`PAYMENT-SIGNATURE`,zr=B().check(On(1)),Br=Mn().check(Xn(e=>e>0,`Must be positive`)),q=B().check(R(/^\d+$/,`Invalid atomic amount`)),J=$n(),Vr=B().check(R(RegExp(`^eip155:\\d+$`),`Invalid EVM CAIP-2 network`)),Hr=H({description:G(B()),iconUrl:G(B()),mimeType:G(B()),serviceName:G(B()),tags:G(zn(B())),url:zr}),Ur=H({amount:q,asset:zr,extra:G(U(B(),V())),maxTimeoutSeconds:Br,network:Vr,payTo:zr,scheme:Kn(Ir)}),Wr=U(B(),H({info:U(B(),V()),schema:U(B(),V())})),Gr=H({accepts:zn(Ur).check(On(1)),error:G(B()),extensions:G(Wr),resource:Hr,x402Version:W(2)}),Kr=Un([H({authorization:H({from:J,nonce:er(),to:J,validAfter:q,validBefore:q,value:q}),signature:tr()}),H({permit2Authorization:H({deadline:q,from:J,nonce:q,permitted:H({amount:q,token:J}),spender:J,witness:H({to:J,validAfter:q})}),signature:tr()})]),qr=H({accepted:Ur,extensions:G(Wr),payload:Kr,resource:G(Hr),x402Version:W(2)}),Jr=H({amount:G(q),errorMessage:G(B()),errorReason:G(B()),extensions:G(Wr),extra:G(U(B(),V())),network:zr,payer:G(B()),success:Pn(),transaction:B()}),Yr=Pr(Gr),Xr=Pr(qr),Zr=Pr(Jr);Yr.encode,Yr.decode;function Qr(e){try{let t=JSON.parse(Ke(e));return $r(t)}catch{throw new Fr}}Xr.encode,Xr.decode,Zr.encode,Zr.decode;const $r=e=>{if(!e||typeof e!=`object`||Array.isArray(e))throw new Fr;let t=e;if(t.x402Version!==2||!Array.isArray(t.accepts))throw new Fr;let n=Hr.parse(t.resource),r=t.extensions===void 0?void 0:Wr.safeParse(t.extensions).data;return{accepts:t.accepts,...r?{extensions:r}:{},resource:n,x402Version:2}},ei=Symbol.for(`mppx.x402.challenge`);function ti(e){return Object.defineProperty(e,ei,{value:!0}),e}function ni(e){return!!e?.[ei]}function ri(e){let t={};for(let n of e){let e=t[n.name]??={};e[n.intent]=ci(n)}return t}function ii(e,t){let n=ri(e),r=hi(e,n,t),i=e.map((e,t)=>({intent:e.intent,method:e.name,q:r[ci(e)]??1,index:t}));return{definition:r,entries:i,header:oi(i),keys:n}}function ai(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)=>pi(e,t))}function oi(e){return e.map(({method:e,intent:t,q:n})=>{let r=`${e}/${t}`;return n===1?r:`${r};q=${yi(n)}`}).join(`, `)}function si(e,t,n){let r=new Map;for(let e of t){let t=ci(e),n=r.get(t);n?n.push(e):r.set(t,[e])}return e.flatMap((e,t)=>{let i=r.get(ci(e));if(!i)return[];let a=li(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)=>fi(e.challenge)-fi(t.challenge)||t.match.q-e.match.q||e.index-t.index).map(e=>{let{match:t,...n}=e;return n})}function ci(e){let t=e.method??e.name;if(!t)throw Error(`Missing payment method name.`);return`${t}/${e.intent}`}function li(e,t){let n;for(let r of t){if(!ui(e,r))continue;let t={...r,specificity:di(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 ui(e,t){return(t.method===`*`||t.method===e.method)&&(t.intent===`*`||t.intent===e.intent)}function di(e){return Number(e.method!==`*`)+Number(e.intent!==`*`)}function fi(e){return+!!ni(e)}function pi(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}`);bi(r,`method`),bi(i,`intent`);let a=1;for(let t of mi(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=_i(i,`Accept-Payment entry "${e}"`))}return{intent:i,method:r,q:a,index:t}}function mi(e){return e?e.split(/\s*;\s*/).filter(Boolean):[]}function hi(e,t,n){if(!n)return{};let r=typeof n==`function`?n(t):n,i=new Set(e.map(e=>ci(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]=gi(t,`payment preference "${e}"`)}return a}function gi(e,t){if(typeof e!=`number`||Number.isNaN(e)||!Number.isFinite(e))throw Error(`Invalid q-value for ${t}. Expected a finite number.`);return vi(e,t)}function _i(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 vi(Number(e),t)}function vi(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 yi(e){return e.toFixed(3).replace(/\.0+$/,``).replace(/(\.\d*?)0+$/,`$1`)}function bi(e,t){if(e!==`*`&&!/^[a-z0-9-]+$/.test(e))throw Error(`Invalid Accept-Payment ${t}: ${e}`)}var xi=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 Si(e){}function Ci(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=Si,onError:n=Si,onRetry:r=Si,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(`
|
|
3
|
+
`)===-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 xi(`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(`
|
|
4
|
+
`,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(`
|
|
5
|
+
`,n);continue}let i=e.charCodeAt(n);if(wi(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(`
|
|
6
|
+
`,n);continue}u=d===0?a:`${u}
|
|
7
|
+
${a}`,d++}else Ti(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(`
|
|
8
|
+
`,n)}return e.slice(n)}for(;n<e.length;){let t=e.indexOf(`\r`,n),r=e.indexOf(`
|
|
9
|
+
`,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(wi(e,t,r)){let r=e.charCodeAt(t+5)===32?t+6:t+5,i=e.slice(r,n);u=d===0?i:`${u}
|
|
10
|
+
${i}`,d++;return}if(Ti(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}
|
|
11
|
+
${t}`,d++;break;case`id`:t.includes(`\0`)||(l=t);break;case`retry`:/^\d+$/.test(t)?r(parseInt(t,10)):n(new xi(`Invalid \`retry\` value: "${t}"`,{type:`invalid-retry`,value:t,line:i}));break;default:n(new xi(`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 ee(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:ee}}function wi(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 Ti(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 Ei=[O.authorization,Lr,`PAYMENT-RESPONSE`,Rr];function Di(e,t,n){let r=new Headers(e.headers);for(let e of Ei)(e!==O.authorization||r.get(e)?.startsWith(`Payment `))&&r.delete(e);return r.set(t,n),{...e,headers:r}}function Oi(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 ki=new WeakMap;function Ai(e){let t=Oi(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 ji(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 Mi(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=nr.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 Ni(e){if(e)return`error`in e?e.error?.code!==-32042&&e.error?.code!==-32043?void 0:Mi(e.error.data):Mi(e.result?._meta?.[`org.paymentauth/payment-required`])}function Pi(e,t){return!e||e.id!==t?[]:Ni(e)?.challenges??[]}async function Fi(e){let t=e.clone().body?.getReader();if(!t)return;let n=new TextDecoder,r=!1,i,a=Ci({onEvent(e){if(!r&&e.data&&(r=!0,!(e.event&&e.event!==`message`)))try{i=ji(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 Ii(e){let t=ki.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(ji).catch(()=>void 0);if(t.includes(`text/event-stream`))return Fi(e)})();return ki.set(e,n),n}function Li(){return{getChallenges(e,t){let n=Ai(t);return e.status===402||n===void 0?[]:Ii(e).then(e=>Pi(e,n))},setCredential(e,t){let n=JSON.parse(e.body),r=xr(t);return{...e,body:JSON.stringify({...n,params:{...n.params,_meta:{...n.params?._meta,"org.paymentauth/credential":r}}})}}}}function Ri(){return{getChallenges(e){return e.status!==402||!e.headers.has(O.wwwAuthenticate)?[]:fr(e)},setCredential(e,t,n){return Di(e,n?.challenge?gr(n.challenge):O.authorization,t)}}}function zi(){return{getChallenges(e){if(e.status!==402)return[];let t=e.headers.get(Lr);if(!t)return[];let n=Qr(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=Ur.safeParse(e);if(!r.success)return[];let i=r.data;return ti(rr({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 Di(e,Rr,t)}}}function Bi(e){return e}function Vi(){let e=[Ri(),zi(),Li()],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 Bi({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 Hi=new WeakMap;function Ui(e){return Hi.has(e)}function Wi(e,t){return Promise.resolve(Hi.get(e)?.(t))}const Gi=new WeakMap,Ki=new WeakMap;function qi(e,t,n){Gi.has(e)&&Ki.set(t,n)}function Ji(e,t){return Promise.resolve(Gi.get(e)?.(t)??t.response)}const Yi=Symbol.for(`mppx.fetch.wrapper`);let Xi;const Zi=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 Qi(e){let{acceptPayment:t,acceptPaymentPolicy:n=`always`,fetch:r=globalThis.fetch,maxPaymentRetries:i=3,methods:a,onChallenge:o,orderChallenges:s,transport:c=Vi()}=e,l=e.eventDispatcher??ea(),u=t??ii(a),d=ba(r),f=async(e,t,r)=>{let p=ya(e,t?.headers),m=p.has(O.acceptPayment),h=Ta(p,u),g=_a(e,t,p),_=ga(e,t,p,h.header,m,n),v=await d(xa(_.input),_.init),y=va(_.init,await g);if(!await c.isPaymentRequired(v,y))return v;let ee=t?.context,{context:te,orderChallenges:ne,...re}=y??{},b,x,ie,S;try{for(let n=0;n<i;n++){x=await c.getChallenges(v,y);let i=(await Ea(si(x,a,h.entries),ne??s))[0];if(!i){if(await Y(S,{challenges:x,response:v,status:`rejected`}),n>0)return v;throw Error(`No method found for challenges: ${x.map(e=>`${e.method}.${e.intent}`).join(`, `)}. Available: ${a.map(e=>`${e.name}.${e.intent}`).join(`, `)}`)}let u=i.challenge;b=u,ie=i.method,b.expires&&Dr(b.expires,b.id);let p=ja(v,_.input,_.input),m=S,g=ir(u),te=m?.method===i.method&&m?.key===g,ae=!1;if(m){let e=await Y(m,{challenges:x,response:v,status:te?`pending`:`rejected`});ae=te&&!e}S=ae?m:void 0;let oe=aa(async e=>{if(e===void 0&&ae&&m)return m.promise;ae&&m&&(await Y(m,{status:`rejected`}),S=void 0);let t=e??ee;if(!Ui(i.method))return wa(u,i.method,t);let n={prepare:()=>Wi(i.method,{challenge:u,context:t,fetch:d,input:p})},r=n.prepare().then(()=>wa(u,i.method,t,n));return S={attempt:n,key:e===void 0?g:void 0,method:i.method,promise:r},r}),C=await l.emit(`challenge.received`,oa({challenge:u,challenges:x,createCredential:oe,init:t,input:e,method:i.method,response:v}))??(o?await o(b,{createCredential:oe}):void 0)??await oe(),w=S;w&&await w.promise.catch(()=>void 0)!==C&&(await Y(w,{status:`rejected`}),S=void 0),Ca(C),await l.emit(`credential.created`,sa({challenge:u,credential:C,init:t,input:e,method:i.method,response:v})),v=await d(p,c.setCredential({...re,headers:_.headers},C,{challenge:u}));let se=await c.isPaymentRequired(v,y);if(se||(await Y(w,{response:v,status:v.ok?`accepted`:`rejected`}),S=void 0),v.ok&&ta(l,`payment.response`)&&await l.emit(`payment.response`,ca({challenge:u,credential:C,init:t,input:e,method:i.method,response:v})),!se)return v.ok?Ji(i.method,{challenge:u,credential:C,fetch:d,headers:_.headers,input:p,...r?{refetch:()=>f(xa(_.input),t,!1)}:{},response:v,signal:Sa(e,t)}):v}x=void 0;try{x=await c.getChallenges(v,y)}catch{}return await Y(S,{challenges:x,response:v,status:`rejected`}),v}catch(n){throw await Y(S,{challenges:x,response:v,status:`rejected`}),await l.emit(`payment.failed`,la({challenge:b,challenges:x,error:n,init:t,input:e,method:ie,response:v})),n}},p=(e,t)=>f(e,t,!0);return p[Yi]=d,p}function $i(e){let t=Object.getOwnPropertyDescriptor(globalThis,`fetch`);if(!t||!t.writable&&!t.set)throw Error(`globalThis.fetch is not writable`);Xi||=globalThis.fetch,globalThis.fetch=Qi({...e,acceptPaymentPolicy:e.acceptPaymentPolicy??(ka()?`same-origin`:`always`),fetch:globalThis.fetch})}function ea(){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 na(t,n);if(typeof e==`string`&&e.length>0){r=e;break}}return await ia(e[`*`],t,n),r}case`credential.created`:await ra(e[`credential.created`],n),await ia(e[`*`],t,n);return;case`payment.failed`:await ra(e[`payment.failed`],n),await ia(e[`*`],t,n);return;case`payment.response`:await ra(e[`payment.response`],n),await ia(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 Zi.set(t,t=>e[t].size>0||e[`*`].size>0),t}function ta(e,t){return Zi.get(e)?.(t)??!0}async function na(e,t){try{return await e(t)}catch{return}}async function ra(e,t){for(let n of e)try{await n(t)}catch{}}async function ia(e,t,n){await ra(e,Object.freeze({name:t,payload:n}))}function aa(e){let t;return n=>(t??=e(n),t)}function oa(e){return Object.freeze({challenge:X(e.challenge),challenges:e.challenges.map(e=>X(e)),createCredential:e.createCredential,init:ua(e.init),input:da(e.input),method:fa(e.method),response:pa(e.response)})}function sa(e){return Object.freeze({challenge:X(e.challenge),credential:e.credential,init:ua(e.init),input:da(e.input),method:fa(e.method),...e.response===void 0?{}:{response:pa(e.response)}})}function ca(e){return Object.freeze({challenge:X(e.challenge),credential:e.credential,init:ua(e.init),input:da(e.input),method:fa(e.method),response:pa(e.response)})}function la(e){return Object.freeze({...e.challenge?{challenge:X(e.challenge)}:{},...e.challenges?{challenges:e.challenges.map(e=>X(e))}:{},error:e.error,init:ua(e.init),input:da(e.input),...e.method?{method:fa(e.method)}:{},...e.response===void 0?{}:{response:pa(e.response)}})}function ua(e){if(e)return ha({...e,...e.headers?{headers:new Headers(e.headers)}:{}})}function da(e){if(e instanceof Request)try{return e.clone()}catch{return e}return e instanceof URL?new URL(e):e}function fa(e){return ha(Object.assign({},e))}function pa(e){return e instanceof Response?e.clone():X(e)}function X(e){try{return ma(structuredClone(e))}catch{return ha(e)}}function ma(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))ma(t);return e}function ha(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function ga(e,t,n,r,i,a){let o=!!r&&!i&&Da(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(O.acceptPayment,r),t?(t.headers=s,{headers:s,init:t,input:e}):{headers:s,init:o?{headers:s}:void 0,input:e}}function _a(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 va(e,t){return t===void 0?e:{...e,body:t}}function ya(e,t){return t?new Headers(t):new Headers(e instanceof Request?e.headers:void 0)}function ba(e){let t=e;for(;t[Yi];)t=t[Yi];return t}function xa(e){if(!(e instanceof Request)||!e.body||e.bodyUsed)return e;try{return e.clone()}catch{return e}}function Sa(e,t){return t?.signal??(e instanceof Request?e.signal:void 0)}function Ca(e){if(!e.trim())throw Error(`Credential header value must be non-empty`);if(e.includes(`\r`)||e.includes(`
|
|
12
|
+
`))throw Error(`Credential header value contains illegal newline characters`)}async function wa(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&&qi(t,a,r),t.createCredential(a)}function Ta(e,t){let n=e.get(O.acceptPayment);if(!n)return t;try{return{...t,entries:ai(n),header:n}}catch{return t}}async function Ea(e,t){return t?t(e):e}function Da(e,t){if(t===`always`)return!0;if(t===`never`)return!1;let n=Aa(e);return t===`same-origin`?!ka()||n.origin===globalThis.location.origin:t.origins.some(e=>Oa(n,e))}function Oa(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 ka(){return globalThis.location!==void 0}function Aa(e){return e instanceof URL?e:e instanceof Request?new URL(e.url):new URL(e,ka()?globalThis.location.href:void 0)}function ja(e,t,n){if(!e.url)return t;let r=new URL(e.url),i=Aa(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 Ma(){let e=new Uint8Array(64);return crypto.getRandomValues(e),Object.freeze({created:Math.floor(Date.now()/1e3),nonce:Ue(e,{pad:!1,url:!0})})}function Na(...e){return{protocol:`composed`,async sign(t,n=Ma()){for(let r of e)t=await r.sign(t,n);return t}}}function Pa(e,t){return async(n,r)=>e(await t.sign(new Request(n,r)))}function Fa(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=Vi()}=e,c=e.fetch??globalThis.fetch,l=t?Ia(c,t):c,u=e.methods.flat(),d=ii(u,e.paymentPreferences),f=ea(),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=Qi(m);a&&$i(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 ee(e,t){let n=Ha(e),r=await s.getChallenges(e,t?.request),a=Object.freeze(r.map(e=>Z(e))),o=Ga(d.entries,t?.acceptPayment),c,l;try{let e=(await Ka(si(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&&Dr(c.expires,c.id);let p=c,m=l,h=La(async e=>{try{p.expires&&Dr(p.expires,p.id);let t=La(t=>qa(p,m,t??e)),i=await f.emit(`challenge.received`,Ra({challenge:p,challenges:r,createCredential:t,method:m,response:n}))??await t();return Ca(i),await f.emit(`credential.created`,za({challenge:p,credential:i,method:m,response:n})),i}catch(e){throw await f.emit(`payment.failed`,Ba({challenge:p,challenges:r,error:e,method:m,response:n})),e}});return Object.freeze({challenge:p,challenges:a,createCredential:h,method:Va(m),setCredential(e,t){return Ca(t),s.setCredential(e,t,{challenge:d})}})}catch(e){throw await f.emit(`payment.failed`,Ba({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:ee,async createCredential(e,t,n){return(await ee(e,n)).createCredential(t)}}}function Ia(e,t){let n=Object.values(t);if(n.length===0)throw TypeError(`Mppx client attestation must configure at least one signer.`);return Pa(e,Na(...n))}function La(e){let t;return n=>(t??=e(n),t)}function Ra(e){return Object.freeze({challenge:Z(e.challenge),challenges:e.challenges.map(e=>Z(e)),createCredential:e.createCredential,method:Va(e.method),response:Ha(e.response)})}function za(e){return Object.freeze({challenge:Z(e.challenge),credential:e.credential,method:Va(e.method),response:Ha(e.response)})}function Ba(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:Va(e.method)}:{},response:Ha(e.response)})}function Va(e){return Wa(Object.assign({},e))}function Ha(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 Ua(t)}catch{return Wa(e)}}function Ua(e){if(!e||typeof e!=`object`||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))Ua(t);return e}function Wa(e){return!e||typeof e!=`object`||Object.isFrozen(e)||Object.freeze(e),e}function Ga(e,t){return t?typeof t==`string`?ai(t):t:e}async function Ka(e,t){return t?t(e):e}async function qa(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 Ja=2048;var Q=class extends Error{name=`MppResourceUrlError`};function Ya(e){if(e.length>Ja)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:`&&Xa(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>Ja)throw new Q(`MPP resource URL is too long`);return o}function Xa(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 Za=/^[A-Za-z0-9_-]+$/,Qa=/^0x[0-9a-fA-F]{40}$/,$a=/^(?:0|[1-9]\d*)$/,eo=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/,to=/^sha-256=:([A-Za-z0-9+/]{43}=):$/,no=/^sha-256=([A-Za-z0-9+/]{43}=)$/,ro=new Set([`mpp_challenge_not_payable`,`mpp_network_mismatch`,`mpp_counterparty_rail_not_found`]),io=`mpp_counterparty_rail_not_found`,ao=`mpp_network_mismatch`,oo=H({type:W(`authorization`),from:B(),to:B(),value:B(),validAfter:B(),validBefore:B(),nonce:B(),signature:B()}),so={amount:B(),currency:B(),description:G(B()),externalId:G(B()),recipient:B()},co=H({...so,methodDetails:H({chainId:Mn(),credentialTypes:zn(W(`authorization`)),decimals:W(6),permit2Address:G(B()),splits:G(Ln())})}),lo=H({...so,methodDetails:H({type:W(`evm`),evm:H({chainId:Mn(),credentialTypes:G(zn(W(`authorization`))),decimals:W(6),permit2Address:G(B()),splits:G(Ln())})})}),uo=Or({name:`evm`,intent:`charge`,schema:{credential:{payload:oo},request:co}}),fo=Or({name:`usdc`,intent:`charge`,schema:{credential:{payload:oo},request:lo}});var po=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??[]}},mo=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.map(_).join(`, `)}`,{reasons:n}),this.name=`MppNetworkMismatchError`,this.accountId=e,this.requiredNetworks=t}},ho=class extends ${recipient;network;requiredRail;constructor(e,t,n,r){super(`No saved Catena counterparty rail can pay ${e} on ${t}`,{reasons:n}),this.name=`MppCounterpartyNotFoundError`,this.recipient=e,this.network=t,this.requiredRail=r}},go=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}},_o=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}},vo=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}},yo=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 bo(e){let t=async({challenge:t})=>(await jo(e,Ao(t,e.maxAtomicAmount))).credential;return[kr(uo,{canHandleChallenge:({challenge:t})=>Mo(`evm`,t,e.maxAtomicAmount)!==void 0,createCredential:t}),kr(fo,{canHandleChallenge:({challenge:t})=>Mo(`usdc`,t,e.maxAtomicAmount)!==void 0,createCredential:t})]}const xo=Object.assign(e=>bo(e),{charge:bo});function So(e,t){let n=(t.baseFetch??globalThis.fetch).bind(globalThis),r={client:e,accountId:t.accountId,...t.maxAtomicAmount!==void 0&&{maxAtomicAmount:t.maxAtomicAmount}},i=Fa({methods:xo(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(!u(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=Eo(a,s),{payment:d,prepared:f}=await Co(i,s,c,o,r,l),p={intentId:d.intentId,...d.terms,resourceUrl:l};await Oo(p,async()=>{await t.onPayment?.(p)});let m=g(a,o),h=f.setCredential({...o,headers:m},d.credential),_=await Oo(p,()=>n(a,h));if(_.status===402)throw new yo(p,Error(`The paid MPP retry still requires payment`));return ko(e,p.intentId,_),_}}async function Co(e,t,r,i,a,o){let s,c=[];for(let l=0;l<5;l+=1){let u={missing:!1},d;try{d=await e.preparePayment(t,{request:i,orderChallenges:e=>{s??=e.slice(0,5).map(e=>e.index);let t=s[l],n=e.find(e=>e.index===t);return u.missing=n===void 0,n===void 0?[]:[n]}})}catch(e){let t=s??[];if(t.length===0)throw r.some(e=>No(e,a.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(u.missing&&c.length>0){if(l+1<t.length)continue;break}throw new $(`The selected MPP challenge could not be prepared`,{cause:e})}let f=Ao(d.challenge,a.maxAtomicAmount);try{return{payment:await jo(a,f,o),prepared:d}}catch(e){if(e instanceof n&&e.code!==void 0&&ro.has(e.code))c.push({error:e,terms:f.terms});else throw wo(e,f.terms,o)}if(l+1>=(s?.length??0))break}throw To(a.accountId,c)}function wo(e,t,n){if(e instanceof y&&e.outcome===`unknown`)return new vo(e.intentId,t,n,e);if(!(e instanceof po))return e;switch(e.status){case`pending`:return new go(e.intentId,e.reasons,e.expiresAt);case`blocked`:case`failed`:return new _o(e.intentId,e.status,e.reasons);case`processing`:case`completed`:return new $(e.message,{intentId:e.intentId,reasons:e.reasons,cause:e})}return ce(e.status)}function To(e,t){let n=t.filter(e=>e.error.code===io),r=t.filter(e=>e.error.code===ao),i=t.filter(e=>e.error.code!==io&&e.error.code!==ao),a=[...new Set([...n,...r,...i].map(e=>e.error.message))],o=n.find(e=>e.error.status===404);return o?new ho(o.terms.recipient,o.terms.network,a,C(o.error.details,o.terms.recipient)):r.length>0&&n.length===0?new mo(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 Eo(e,t){let n;try{n=typeof e==`string`?Do(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 Ya(t.url||n.href)}catch(e){throw new $(`The final MPP resource URL cannot be bound to a payment intent`,{cause:e})}}function Do(e){try{return new URL(e)}catch{return new URL(e,globalThis.location.href)}}async function Oo(e,t){try{return await t()}catch(t){throw new yo(e,t)}}function ko(e,t,n){try{let r=Nr(n);if(!x.test(r.reference))return;ne(e,t,r.reference)}catch{return}}function Ao(e,t){let n=e.method;if(n!==`evm`&&n!==`usdc`)throw Error(`Unsupported Catena MPP challenge ${e.method}/${e.intent}`);let r=Mo(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 jo(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:Go(r,t.challenge),intentId:r.id}}function Mo(e,t,n){if(t.method!==e||t.intent!==`charge`)return;let r=Bo(t);if(r===void 0)return;let i=e===`evm`?Io(t.request,n):Lo(t.request,n);return i===void 0?void 0:{...r,terms:i}}function No(e,t){if(t===void 0||e.method!==`evm`&&e.method!==`usdc`)return!1;let n=Mo(e.method,e,void 0);return n!==void 0&&BigInt(n.terms.atomicAmount)>t}function Po(e,t){return Uo(e.amount)&&(t===void 0||BigInt(e.amount)<=t)&&Wo(e.currency)&&Wo(e.recipient)&&(e.description===void 0||Fo(e.description,1024))&&(e.externalId===void 0||Fo(e.externalId,256))}function Fo(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 Io(e,t){let n=co.safeParse(e);if(!n.success||!Po(n.data,t))return;let{amount:r,methodDetails:i,recipient:a}=n.data,o=zo(i.chainId);return Ro(i)&&i.credentialTypes.length===1&&o!==void 0?{method:`evm`,atomicAmount:r,network:o,recipient:a}:void 0}function Lo(e,t){let n=lo.safeParse(e);if(!n.success||!Po(n.data,t))return;let{amount:r,methodDetails:i,recipient:a}=n.data,o=i.evm,s=zo(o.chainId);return Ro(o)&&(o.credentialTypes===void 0||o.credentialTypes.length===1)&&s!==void 0?{method:`usdc`,atomicAmount:r,network:s,recipient:a}:void 0}function Ro(e){return Number.isSafeInteger(e.chainId)&&e.chainId>=1&&(e.permit2Address===void 0||Wo(e.permit2Address))}function zo(e){return Number.isSafeInteger(e)&&e>=1?`eip155:${e}`:void 0}function Bo(e){if(!Vo(e))return;let t=Date.parse(e.expires),n=t-Date.now();if(!Number.isFinite(t)||n<5e3||n>36e5)return;let r=k(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 Vo(e){return!(e.id.length<1||e.id.length>256||e.realm.length<1||e.realm.length>256||e.expires===void 0||!eo.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||!Za.test(e.opaque))||e.digest!==void 0&&!Ho(e.digest))}function Ho(e){if(e.length>128)return!1;let t=to.exec(e)??no.exec(e);if(!t)return!1;try{let e=atob(t[1]);return e.length===32&&btoa(e)===t[1]}catch{return!1}}function Uo(e){return e.length<=78&&$a.test(e)&&BigInt(e)>0n}function Wo(e){return Qa.test(e)&&le(e)}function Go(e,t){switch(e.status){case`completed`:{let n=o(e.data,`mpp`);if(n===void 0)throw Jo(`Catena MPP payment ${e.id} completed without an MPP credential`,e);if(!Ko(n,t))throw Jo(`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 Jo(`Catena MPP payment ${e.id} is pending${Yo(e.reasons)}`,e);case`processing`:throw Jo(`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 Jo(`Catena MPP payment ${e.id} was blocked${Yo(e.reasons)}`,e);case`failed`:throw Jo(`Catena MPP payment ${e.id} failed${Yo(e.reasons)}`,e)}return ce(e.status)}function Ko(e,t){if(e.trim().length===0||e.includes(`\r`)||e.includes(`
|
|
13
|
+
`))return!1;let n;try{n=xr(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||k(r.request)!==t.request)return!1;let i=oo.safeParse(n.payload),a=t.method===`evm`?co.safeParse(r.request):lo.safeParse(r.request);if(!i.success||!a.success)return!1;let o=a.data.recipient;return Wo(i.data.from)&&Wo(i.data.to)&&i.data.to.toLowerCase()===o.toLowerCase()&&i.data.value===a.data.amount&&qo(i.data.validAfter)&&qo(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 qo(e){return e.length<=78&&$a.test(e)}function Jo(e,t){return new po(e,{intentId:t.id,status:t.status,reasons:t.reasons,expiresAt:t.expiresAt})}function Yo(e){return e.length>0?`: ${e.join(`; `)}`:``}function Xo(e){return{intentId:e.intentId,method:e.method,amountAtomicUsdc:e.atomicAmount,recipient:e.recipient,network:e.network}}const Zo=/(?:^|,)\s*Payment(?![!#$%&'*+\-.^_`|~0-9A-Za-z])/i;function Qo(e,t){b(e,`payment-authorization`)&&s(`--header cannot set Payment-Authorization; the payment loop attaches it after paying`),e.some(e=>e.name.toLowerCase()===`authorization`&&Zo.test(e.value))&&s(`--header cannot provide the Payment authentication scheme in Authorization; the payment loop attaches it after paying`),ie(e,t)}const $o=l({url:w({description:`The paywalled URL to fetch (an MPP endpoint)`,required:!0,schema:T.pipe(T.string(),T.url())}),account:w({description:`Source wallet account id the payment draws from`,required:!0,schema:se}),maxAmount:w({description:`Refuse challenges above this USD amount (decimal string, e.g. 0.25). Policy limits still apply server-side.`,schema:T.pipe(T.string(),T.regex(/^\d+(\.\d{1,6})?$/))}),method:c({description:`HTTP method for the request`,choices:[`GET`,`POST`]}),data:w({description:`Request body. Use @path to read a file or @- for stdin. Implies POST and a JSON content type unless overridden.`}),contentType:w({description:`Content-Type header for the request body (default application/json when --data is set)`}),output:w({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:r({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:p}),profile:i,json:a}),es=ue({meta:{name:`mpp`,description:`Fetch a URL, paying its MPP challenge via USDC`},args:$o.args,async run({args:e,rawArgs:t}){let n=$o.parse(e,t),r=n.method??(n.data===void 0?`GET`:`POST`);n.data!==void 0&&r!==`POST`&&s(`--data cannot be sent with --method ${r}; a body requires POST`),n.contentType!==void 0&&n.data===void 0&&s(`--content-type has no effect without --data`),Qo(n.header,n.contentType);let i=n.output===void 0?void 0:re(n.output),a=n.data===void 0?void 0:m(n.data),o=v(n.header,n.contentType,a);await f(n)(async e=>{let t,s=So(e,{accountId:n.account,...n.maxAmount!==void 0&&{maxAtomicAmount:h(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 vo&&e.intentId!==void 0)throw Error(oe(e.intentId,n.profile),{cause:e});if(e instanceof yo)return{status:null,paid:!0,retryFailed:!0,payment:Xo(e.receipt),error:e.message};if(e instanceof mo){let t=e.requiredNetworks.map(e=>S(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${te(n.profile)}\`).`}}if(e instanceof ho){let t=e.requiredRail?.network??S(e.network)??e.network,r=d(e.recipient,t,void 0,n.profile);return{status:null,paid:!1,retryFailed:!1,counterpartyNotFound:{recipient:e.recipient,network:t,networkId:e.network,...e.requiredRail!==void 0&&{requiredRail:e.requiredRail},createCommand:r,nameIsPlaceholder:!0},error:`${e.message}. Add it, then re-run:\n ${r}\n(counterparty creation may require approval per your policy)`}}if(e instanceof go)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:Xo(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}${te(n.profile)}\` before any manual retry`;return{...l,error:`failed to read the response body: ${ee(e)}${r}`}}return{...l,...ae(u,t?.intentId,i)}},{exitCode:e=>+(`error`in e)})}});export{es as mppCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./utils-
|
|
1
|
+
import{t as e}from"./utils-q3q3KGtm.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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as e}from"./dist-C970_f6m.mjs";import{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"./sha256-CJuuQjmL.mjs";import{t as f}from"./hmac-DW0MnYTR.mjs";
|
|
2
2
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
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
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import*as e from"node:crypto";const t=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 n(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function r(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function i(e,...t){if(!n(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 a(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);r(e.outputLen),r(e.blockLen)}function o(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 s(e,t){i(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function c(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function l(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function u(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function d(e,t){return e<<32-t|e>>>t}const f=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function p(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function m(e){for(let t=0;t<e.length;t++)e[t]=p(e[t]);return e}const h=f?e=>e:m,g=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,_=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function v(e){if(i(e),g)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=_[e[n]];return t}const y={_0:48,_9:57,A:65,F:70,a:97,f:102};function b(e){if(e>=y._0&&e<=y._9)return e-y._0;if(e>=y.A&&e<=y.F)return e-(y.A-10);if(e>=y.a&&e<=y.f)return e-(y.a-10)}function x(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(g)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=b(e.charCodeAt(i)),a=b(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 S(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function C(e){return typeof e==`string`&&(e=S(e)),i(e),e}function w(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];i(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 T=class{};function E(e){let t=t=>e().update(C(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function D(e=32){if(t&&typeof t.getRandomValues==`function`)return t.getRandomValues(new Uint8Array(e));if(t&&typeof t.randomBytes==`function`)return Uint8Array.from(t.randomBytes(e));throw Error(`crypto.getRandomValues must be defined`)}function O(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 ee(e,t,n){return e&t^~e&n}function k(e,t,n){return e&t^e&n^t&n}var A=class extends T{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=u(this.buffer)}update(e){o(this),e=C(e),i(e);let{view:t,buffer:n,blockLen:r}=this,a=e.length;for(let i=0;i<a;){let o=Math.min(r-this.pos,a-i);if(o===r){let t=u(e);for(;r<=a-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){o(this),s(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,l(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;O(n,r-8,BigInt(this.length*8),i),this.process(n,0);let c=u(e),d=this.outputLen;if(d%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let f=d/4,p=this.get();if(f>p.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<f;e++)c.setUint32(4*e,p[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 j=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),M=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),N=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),P=BigInt(2**32-1),F=BigInt(32);function te(e,t=!1){return t?{h:Number(e&P),l:Number(e>>F&P)}:{h:Number(e>>F&P)|0,l:Number(e&P)|0}}function I(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}=te(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}const L=(e,t,n)=>e>>>n,R=(e,t,n)=>e<<32-n|t>>>n,z=(e,t,n)=>e>>>n|t<<32-n,B=(e,t,n)=>e<<32-n|t>>>n,V=(e,t,n)=>e<<64-n|t>>>n-32,H=(e,t,n)=>e>>>n-32|t<<64-n,U=(e,t,n)=>e<<n|t>>>32-n,W=(e,t,n)=>t<<n|e>>>32-n,G=(e,t,n)=>t<<n-32|e>>>64-n,K=(e,t,n)=>e<<n-32|t>>>64-n;function q(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}const ne=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),re=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,ie=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),ae=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,oe=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),se=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0,ce=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]),J=new Uint32Array(64);var le=class extends A{constructor(e=32){super(64,e,8,!1),this.A=j[0]|0,this.B=j[1]|0,this.C=j[2]|0,this.D=j[3]|0,this.E=j[4]|0,this.F=j[5]|0,this.G=j[6]|0,this.H=j[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)J[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=J[e-15],n=J[e-2],r=d(t,7)^d(t,18)^t>>>3,i=d(n,17)^d(n,19)^n>>>10;J[e]=i+J[e-7]+r+J[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=d(o,6)^d(o,11)^d(o,25),u=l+t+ee(o,s,c)+ce[e]+J[e]|0,f=(d(n,2)^d(n,13)^d(n,22))+k(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+f|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(){l(J)}destroy(){this.set(0,0,0,0,0,0,0,0),l(this.buffer)}};const Y=I(`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))),ue=Y[0],de=Y[1],X=new Uint32Array(80),Z=new Uint32Array(80);var Q=class extends A{constructor(e=64){super(128,e,16,!1),this.Ah=N[0]|0,this.Al=N[1]|0,this.Bh=N[2]|0,this.Bl=N[3]|0,this.Ch=N[4]|0,this.Cl=N[5]|0,this.Dh=N[6]|0,this.Dl=N[7]|0,this.Eh=N[8]|0,this.El=N[9]|0,this.Fh=N[10]|0,this.Fl=N[11]|0,this.Gh=N[12]|0,this.Gl=N[13]|0,this.Hh=N[14]|0,this.Hl=N[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)X[n]=e.getUint32(t),Z[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=X[e-15]|0,n=Z[e-15]|0,r=z(t,n,1)^z(t,n,8)^L(t,n,7),i=B(t,n,1)^B(t,n,8)^R(t,n,7),a=X[e-2]|0,o=Z[e-2]|0,s=z(a,o,19)^V(a,o,61)^L(a,o,6),c=B(a,o,19)^H(a,o,61)^R(a,o,6),l=ie(i,c,Z[e-7],Z[e-16]),u=ae(l,r,s,X[e-7],X[e-16]);X[e]=u|0,Z[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=z(u,d,14)^z(u,d,18)^V(u,d,41),v=B(u,d,14)^B(u,d,18)^H(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=oe(_,v,b,de[e],Z[e]),S=se(x,g,t,y,ue[e],X[e]),C=x|0,w=z(n,r,28)^V(n,r,34)^V(n,r,39),T=B(n,r,28)^H(n,r,34)^H(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}=q(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=ne(C,T,D);n=re(O,S,w,E),r=O|0}({h:n,l:r}=q(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=q(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=q(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=q(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=q(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=q(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=q(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=q(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(){l(X,Z)}destroy(){l(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},fe=class extends Q{constructor(){super(48),this.Ah=M[0]|0,this.Al=M[1]|0,this.Bh=M[2]|0,this.Bl=M[3]|0,this.Ch=M[4]|0,this.Cl=M[5]|0,this.Dh=M[6]|0,this.Dl=M[7]|0,this.Eh=M[8]|0,this.El=M[9]|0,this.Fh=M[10]|0,this.Fl=M[11]|0,this.Gh=M[12]|0,this.Gl=M[13]|0,this.Hh=M[14]|0,this.Hl=M[15]|0}};const $=E(()=>new le),pe=E(()=>new Q),me=E(()=>new fe),he=$;export{h as C,D as S,c as T,l as _,G as a,x as b,W as c,i as d,o as f,v as g,s as h,pe as i,I as l,r as m,$ as n,K as o,a as p,me as r,U as s,he as t,T as u,w as v,C as w,n as x,E as y};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e}from"./dist-C970_f6m.mjs";import{N 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{r as e}from"./dist-C970_f6m.mjs";import{t}from"./utils-q3q3KGtm.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.12.0",
|
|
4
4
|
"description": "Catena CLI for agent runtimes",
|
|
5
5
|
"homepage": "https://catena.com/",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@bank/money": "0.1.0",
|
|
27
27
|
"@bank/shared": "0.1.0",
|
|
28
|
-
"@catena/sdk": "0.
|
|
28
|
+
"@catena/sdk": "0.4.0",
|
|
29
29
|
"@types/semver": "7.8.0",
|
|
30
30
|
"mppx": "0.9.2",
|
|
31
31
|
"publint": "0.3.24",
|
package/dist/dist-w03V0QPF.mjs
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-B0Z9INg1.mjs";import*as t from"node:crypto";function n(e){return e.reduce((e,t)=>e+t.toString(16).padStart(2,`0`),``)}const r=(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},i=(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 a(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 o=e({default:()=>s}),s=a(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`);function c(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}c(o);const l=t&&typeof t==`object`&&`webcrypto`in t?t.webcrypto:t&&typeof t==`object`&&`randomBytes`in t?t:void 0;
|
|
2
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
-
function u(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function d(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got `+e)}function f(e,...t){if(!u(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 p(e){if(typeof e!=`function`||typeof e.create!=`function`)throw Error(`Hash should be wrapped by utils.createHasher`);d(e.outputLen),d(e.blockLen)}function m(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 h(e,t){f(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function g(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function _(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function v(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function y(e,t){return e<<32-t|e>>>t}const b=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function x(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function S(e){for(let t=0;t<e.length;t++)e[t]=x(e[t]);return e}const C=b?e=>e:S,w=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,T=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function E(e){if(f(e),w)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=T[e[n]];return t}const D={_0:48,_9:57,A:65,F:70,a:97,f:102};function O(e){if(e>=D._0&&e<=D._9)return e-D._0;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 ee(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);if(w)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=O(e.charCodeAt(i)),a=O(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 te(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function k(e){return typeof e==`string`&&(e=te(e)),f(e),e}function ne(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];f(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 A=class{};function j(e){let t=t=>e().update(k(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function re(e=32){if(l&&typeof l.getRandomValues==`function`)return l.getRandomValues(new Uint8Array(e));if(l&&typeof l.randomBytes==`function`)return Uint8Array.from(l.randomBytes(e));throw Error(`crypto.getRandomValues must be defined`)}function ie(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 ae(e,t,n){return e&t^~e&n}function oe(e,t,n){return e&t^e&n^t&n}var M=class extends A{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=v(this.buffer)}update(e){m(this),e=k(e),f(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=v(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){m(this),h(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,_(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;ie(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=v(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 N=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),P=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),F=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),I=BigInt(2**32-1),L=BigInt(32);function se(e,t=!1){return t?{h:Number(e&I),l:Number(e>>L&I)}:{h:Number(e>>L&I)|0,l:Number(e&I)|0}}function R(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}=se(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}const z=(e,t,n)=>e>>>n,B=(e,t,n)=>e<<32-n|t>>>n,V=(e,t,n)=>e>>>n|t<<32-n,H=(e,t,n)=>e<<32-n|t>>>n,U=(e,t,n)=>e<<64-n|t>>>n-32,W=(e,t,n)=>e>>>n-32|t<<64-n,ce=(e,t,n)=>e<<n|t>>>32-n,le=(e,t,n)=>t<<n|e>>>32-n,ue=(e,t,n)=>t<<n-32|e>>>64-n,G=(e,t,n)=>e<<n-32|t>>>64-n;function K(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]),q=new Uint32Array(64);var ve=class extends M{constructor(e=32){super(64,e,8,!1),this.A=N[0]|0,this.B=N[1]|0,this.C=N[2]|0,this.D=N[3]|0,this.E=N[4]|0,this.F=N[5]|0,this.G=N[6]|0,this.H=N[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)q[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=q[e-15],n=q[e-2],r=y(t,7)^y(t,18)^t>>>3,i=y(n,17)^y(n,19)^n>>>10;q[e]=i+q[e-7]+r+q[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=y(o,6)^y(o,11)^y(o,25),u=l+t+ae(o,s,c)+_e[e]+q[e]|0,d=(y(n,2)^y(n,13)^y(n,22))+oe(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(){_(q)}destroy(){this.set(0,0,0,0,0,0,0,0),_(this.buffer)}};const J=R(`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=J[0],be=J[1],Y=new Uint32Array(80),X=new Uint32Array(80);var Z=class extends M{constructor(e=64){super(128,e,16,!1),this.Ah=F[0]|0,this.Al=F[1]|0,this.Bh=F[2]|0,this.Bl=F[3]|0,this.Ch=F[4]|0,this.Cl=F[5]|0,this.Dh=F[6]|0,this.Dl=F[7]|0,this.Eh=F[8]|0,this.El=F[9]|0,this.Fh=F[10]|0,this.Fl=F[11]|0,this.Gh=F[12]|0,this.Gl=F[13]|0,this.Hh=F[14]|0,this.Hl=F[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)Y[n]=e.getUint32(t),X[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Y[e-15]|0,n=X[e-15]|0,r=V(t,n,1)^V(t,n,8)^z(t,n,7),i=H(t,n,1)^H(t,n,8)^B(t,n,7),a=Y[e-2]|0,o=X[e-2]|0,s=V(a,o,19)^U(a,o,61)^z(a,o,6),c=H(a,o,19)^W(a,o,61)^B(a,o,6),l=pe(i,c,X[e-7],X[e-16]),u=me(l,r,s,Y[e-7],Y[e-16]);Y[e]=u|0,X[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=V(u,d,14)^V(u,d,18)^U(u,d,41),v=H(u,d,14)^H(u,d,18)^W(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=he(_,v,b,be[e],X[e]),S=ge(x,g,t,y,ye[e],Y[e]),C=x|0,w=V(n,r,28)^U(n,r,34)^U(n,r,39),T=H(n,r,28)^W(n,r,34)^W(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}=K(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}=K(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=K(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=K(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=K(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=K(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=K(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=K(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=K(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(){_(Y,X)}destroy(){_(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},xe=class extends Z{constructor(){super(48),this.Ah=P[0]|0,this.Al=P[1]|0,this.Bh=P[2]|0,this.Bl=P[3]|0,this.Ch=P[4]|0,this.Cl=P[5]|0,this.Dh=P[6]|0,this.Dl=P[7]|0,this.Eh=P[8]|0,this.El=P[9]|0,this.Fh=P[10]|0,this.Fl=P[11]|0,this.Gh=P[12]|0,this.Gl=P[13]|0,this.Hh=P[14]|0,this.Hl=P[15]|0}};const Q=j(()=>new ve),Se=j(()=>new Z),Ce=j(()=>new xe),$=Q;function we(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),s.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=s.decodeUnsafe(e);if(t!=null)return n(t)}function i(e){var t=n(s.decode(e));if(t==null)throw Error(`Invalid checksum`);return t}return{encode:t,decode:i,decodeUnsafe:r}}var Te=e({default:()=>De});function Ee(e){return $($(e))}var De=we(Ee);function Oe(e){let t=e;for(;t&&!(t.encode&&t.decode&&t.decodeUnsafe)&&t.default;)t=t.default;return t}Oe(Te);export{C,r as D,i as E,n as O,re as S,g as T,_,ue as a,ee as b,le as c,f as d,m as f,E as g,h,Se as i,R as l,d as m,Q as n,G as o,p,Ce as r,ce as s,$ as t,A as u,ne as v,k as w,u as x,j as y};
|
package/dist/hmac-CXnNqvhW.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e,d as t,f as n,p as r,u as i,w as a}from"./dist-w03V0QPF.mjs";var o=class extends i{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,r(t);let i=a(n);if(this.iHash=t.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 o=this.blockLen,s=new Uint8Array(o);s.set(i.length>o?t.create().update(i).digest():i);for(let e=0;e<s.length;e++)s[e]^=54;this.iHash.update(s),this.oHash=t.create();for(let e=0;e<s.length;e++)s[e]^=106;this.oHash.update(s),e(s)}update(e){return n(this),this.iHash.update(e),this}digestInto(e){n(this),t(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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 s=(e,t,n)=>new o(e,t).update(n).digest();s.create=(e,t)=>new o(e,t);export{s as t};
|