x402check 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -555,7 +555,7 @@ declare function extractConfig(response: ResponseLike): ExtractionResult;
555
555
  declare function check(response: ResponseLike, options?: ValidationOptions): CheckResult;
556
556
  //#endregion
557
557
  //#region src/index.d.ts
558
- declare const VERSION: "0.2.0";
558
+ declare const VERSION: "0.3.1";
559
559
  //#endregion
560
560
  export { AcceptSummary, AcceptsEntry, AssetInfo, CAIP2_REGEX, CheckResult, ConfigFormat, ErrorCode, ErrorMessages, type ExtractionResult, type ExtractionSource, KNOWN_ASSETS, KNOWN_NETWORKS, NetworkInfo, NetworkType, NormalizedConfig, ParsedInput, Resource, type ResponseLike, SIMPLE_NAME_TO_CAIP2, Severity, V1AcceptsEntry, V1Config, V2Config, VERSION, ValidationIssue, type ValidationOptions, ValidationResult, check, decodeBase58, detect, extractConfig, getAssetInfo, getCanonicalNetwork, getNetworkInfo, getNetworkNamespace, isKnownAsset, isKnownNetwork, isValidCaip2, isValidChecksum, keccak256, normalize, parseInput, toChecksumAddress, validate, validateAddress, validateEvmAddress, validateSolanaAddress };
561
561
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -555,7 +555,7 @@ declare function extractConfig(response: ResponseLike): ExtractionResult;
555
555
  declare function check(response: ResponseLike, options?: ValidationOptions): CheckResult;
556
556
  //#endregion
557
557
  //#region src/index.d.ts
558
- declare const VERSION: "0.2.0";
558
+ declare const VERSION: "0.3.1";
559
559
  //#endregion
560
560
  export { AcceptSummary, AcceptsEntry, AssetInfo, CAIP2_REGEX, CheckResult, ConfigFormat, ErrorCode, ErrorMessages, type ExtractionResult, type ExtractionSource, KNOWN_ASSETS, KNOWN_NETWORKS, NetworkInfo, NetworkType, NormalizedConfig, ParsedInput, Resource, type ResponseLike, SIMPLE_NAME_TO_CAIP2, Severity, V1AcceptsEntry, V1Config, V2Config, VERSION, ValidationIssue, type ValidationOptions, ValidationResult, check, decodeBase58, detect, extractConfig, getAssetInfo, getCanonicalNetwork, getNetworkInfo, getNetworkNamespace, isKnownAsset, isKnownNetwork, isValidCaip2, isValidChecksum, keccak256, normalize, parseInput, toChecksumAddress, validate, validateAddress, validateEvmAddress, validateSolanaAddress };
561
561
  //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ var x402Validate=(function(e){let t={INVALID_JSON:`INVALID_JSON`,NOT_OBJECT:`NOT
2
2
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
3
  function de(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function fe(e,t=``){if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw Error(`${n}expected integer >= 0, got ${e}`)}}function b(e,t,n=``){let r=de(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 pe(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 me(e,t){b(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw Error(`"digestInto() output" expected to be of length >=`+n)}function he(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ge(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}let _e=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ve(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ye(e){for(let t=0;t<e.length;t++)e[t]=ve(e[t]);return e}let x=_e?e=>e:ye;typeof Uint8Array.from([]).toHex==`function`&&Uint8Array.fromHex;function be(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function xe(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Se(e){var t=xe(e,`string`);return S(t)==`symbol`?t:t+``}function C(e,t,n){return(t=Se(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Ce=BigInt(0),w=BigInt(1),we=BigInt(2),Te=BigInt(7),Ee=BigInt(256),De=BigInt(113),T=[],E=[],D=[];for(let e=0,t=w,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],T.push(2*(5*r+n)),E.push((e+1)*(e+2)/2%64);let i=Ce;for(let e=0;e<7;e++)t=(t<<w^(t>>Te)*De)%Ee,t&we&&(i^=w<<(w<<BigInt(e))-w);D.push(i)}let O=oe(D,!0),Oe=O[0],ke=O[1],k=(e,t,n)=>n>32?le(e,t,n):se(e,t,n),A=(e,t,n)=>n>32?ue(e,t,n):ce(e,t,n);function Ae(e,t=24){let n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){let r=(t+8)%10,i=(t+2)%10,a=n[i],o=n[i+1],s=k(a,o,1)^n[r],c=A(a,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){let r=E[n],a=k(t,i,r),o=A(t,i,r),s=T[n];t=e[s],i=e[s+1],e[s]=a,e[s+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=Oe[r],e[1]^=ke[r]}ge(n)}var je=class e{constructor(e,t,n,r=!1,i=24){if(C(this,`state`,void 0),C(this,`pos`,0),C(this,`posOut`,0),C(this,`finished`,!1),C(this,`state32`,void 0),C(this,`destroyed`,!1),C(this,`blockLen`,void 0),C(this,`suffix`,void 0),C(this,`outputLen`,void 0),C(this,`enableXOF`,!1),C(this,`rounds`,void 0),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=i,fe(n,`outputLen`),!(0<e&&e<200))throw Error(`only keccak-f1600 function is supported`);this.state=new Uint8Array(200),this.state32=he(this.state)}clone(){return this._cloneInto()}keccak(){x(this.state32),Ae(this.state32,this.rounds),x(this.state32),this.posOut=0,this.pos=0}update(e){pe(this),b(e);let{blockLen:t,state:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(t-this.pos,r-i);for(let t=0;t<a;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;let{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,t&128&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){pe(this,!1),b(e),this.finish();let t=this.state,{blockLen:n}=this;for(let r=0,i=e.length;r<i;){this.posOut>=n&&this.keccak();let a=Math.min(n-this.posOut,i-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw Error(`XOF is not possible for this instance`);return this.writeInto(e)}xof(e){return fe(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(me(e,this),this.finished)throw Error(`digest() was already called`);return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,ge(this.state)}_cloneInto(t){let{blockLen:n,suffix:r,outputLen:i,rounds:a,enableXOF:o}=this;return t||(t=new e(n,r,i,o,a)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=a,t.suffix=r,t.outputLen=i,t.enableXOF=o,t.destroyed=this.destroyed,t}};let Me=((e,t,n,r={})=>be(()=>new je(t,e,n),r))(1,136,32);function j(e){let t=Me(typeof e==`string`?new TextEncoder().encode(e):e);return Array.from(t).map(e=>e.toString(16).padStart(2,`0`)).join(``)}
4
4
  /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
5
- function M(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function N(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(e=>typeof e==`string`):t.every(e=>Number.isSafeInteger(e)):!1}function P(e){if(typeof e!=`function`)throw Error(`function expected`);return!0}function F(e,t){if(typeof t!=`string`)throw Error(`${e}: string expected`);return!0}function I(e){if(!Number.isSafeInteger(e))throw Error(`invalid integer: ${e}`)}function L(e){if(!Array.isArray(e))throw Error(`array expected`)}function R(e,t){if(!N(!0,t))throw Error(`${e}: array of strings expected`)}function z(e,t){if(!N(!1,t))throw Error(`${e}: array of numbers expected`)}function B(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function V(e){let t=typeof e==`string`?e.split(``):e,n=t.length;R(`alphabet`,t);let r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(L(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(L(t),t.map(t=>{F(`alphabet.decode`,t);let n=r.get(t);if(n===void 0)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function H(e=``){return F(`join`,e),{encode:t=>(R(`join.decode`,t),t.join(e)),decode:t=>(F(`join.decode`,t),t.split(e))}}function U(e,t=`=`){return I(e),F(`padding`,t),{encode(n){for(R(`padding.encode`,n);n.length*e%8;)n.push(t);return n},decode(n){R(`padding.decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid, string should have whole number of bytes`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: invalid, string has too much padding`);return n.slice(0,r)}}}function W(e){return P(e),{encode:e=>e,decode:t=>e(t)}}function Ne(e,t,n){if(t<2)throw Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(L(e),!e.length)return[];let r=0,i=[],a=Array.from(e,e=>{if(I(e),e<0||e>=t)throw Error(`invalid integer: ${e}`);return e}),o=a.length;for(;;){let e=0,s=!0;for(let i=r;i<o;i++){let o=a[i],c=t*e,l=c+o;if(!Number.isSafeInteger(l)||c/t!==e||l-o!==c)throw Error(`convertRadix: carry overflow`);let u=l/n;e=l%n;let d=Math.floor(u);if(a[i]=d,!Number.isSafeInteger(d)||d*n+e!==l)throw Error(`convertRadix: carry overflow`);if(s)d?s=!1:r=i;else continue}if(i.push(e),s)break}for(let t=0;t<e.length-1&&e[t]===0;t++)i.push(0);return i.reverse()}let Pe=(e,t)=>t===0?e:Pe(t,e%t),G=(e,t)=>e+(t-Pe(e,t)),K=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function q(e,t,n,r){if(L(e),t<=0||t>32)throw Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw Error(`convertRadix2: wrong to=${n}`);if(G(t,n)>32)throw Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${G(t,n)}`);let i=0,a=0,o=K[t],s=K[n]-1,c=[];for(let r of e){if(I(r),r>=o)throw Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,a+t>32)throw Error(`convertRadix2: carry overflow pos=${a} from=${t}`);for(a+=t;a>=n;a-=n)c.push((i>>a-n&s)>>>0);let e=K[a];if(e===void 0)throw Error(`invalid carry`);i&=e-1}if(i=i<<n-a&s,!r&&a>=t)throw Error(`Excess padding`);if(!r&&i>0)throw Error(`Non-zero padding: ${i}`);return r&&a>0&&c.push(i>>>0),c}function Fe(e){return I(e),{encode:t=>{if(!M(t))throw Error(`radix.encode input should be Uint8Array`);return Ne(Array.from(t),256,e)},decode:t=>(z(`radix.decode`,t),Uint8Array.from(Ne(t,e,256)))}}function J(e,t=!1){if(I(e),e<=0||e>32)throw Error(`radix2: bits should be in (0..32]`);if(G(8,e)>32||G(e,8)>32)throw Error(`radix2: carry overflow`);return{encode:n=>{if(!M(n))throw Error(`radix2.encode input should be Uint8Array`);return q(Array.from(n),8,e,!t)},decode:n=>(z(`radix2.decode`,n),Uint8Array.from(q(n,e,8,t)))}}function Ie(e){return P(e),function(...t){try{return e.apply(null,t)}catch{}}}B(J(4),V(`0123456789ABCDEF`),H(``)),B(J(5),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),U(5),H(``)),B(J(5),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),H(``)),B(J(5),V(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),U(5),H(``)),B(J(5),V(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),H(``)),B(J(5),V(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),H(``),W(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`)));let Le=typeof Uint8Array.from([]).toBase64==`function`&&typeof Uint8Array.fromBase64==`function`;Le||B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),U(6),H(``)),B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),H(``)),Le||B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),U(6),H(``)),B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),H(``));let Re=(e=>B(Fe(58),V(e),H(``)))(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`),Y=B(V(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),H(``)),ze=[996825010,642813549,513874426,1027748829,705979059];function X(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<ze.length;e++)(t>>e&1)==1&&(n^=ze[e]);return n}function Be(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=X(i)^n>>5}i=X(i);for(let t=0;t<r;t++)i=X(i)^e.charCodeAt(t)&31;for(let e of t)i=X(i)^e;for(let e=0;e<6;e++)i=X(i);return i^=n,Y.encode(q([i%K[30]],30,5,!1))}function Ve(e){let t=e===`bech32`?1:734539939,n=J(5),r=n.decode,i=n.encode,a=Ie(r);function o(e,n,r=90){F(`bech32.encode prefix`,e),M(n)&&(n=Array.from(n)),z(`bech32.encode`,n);let i=e.length;if(i===0)throw TypeError(`Invalid prefix length ${i}`);let a=i+7+n.length;if(r!==!1&&a>r)throw TypeError(`Length ${a} exceeds limit ${r}`);let o=e.toLowerCase(),s=Be(o,n,t);return`${o}1${Y.encode(n)}${s}`}function s(e,n=90){F(`bech32.decode input`,e);let r=e.length;if(r<8||n!==!1&&r>n)throw TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);let i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);let a=i.lastIndexOf(`1`);if(a===0||a===-1)throw Error(`Letter "1" must be present between prefix and data only`);let o=i.slice(0,a),s=i.slice(a+1);if(s.length<6)throw Error(`Data must be at least 6 characters long`);let c=Y.decode(s).slice(0,-6),l=Be(o,c,t);if(!s.endsWith(l))throw Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:c}}let c=Ie(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}function u(e,t){return o(e,i(t))}return{encode:o,decode:s,encodeFromBytes:u,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}Ve(`bech32`),Ve(`bech32m`),typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`||B(J(4),V(`0123456789abcdef`),H(``),W(e=>{if(typeof e!=`string`||e.length%2!=0)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));function He(e){try{return Re.decode(e)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Invalid Base58: ${t}`)}}function Z(e){let t=e.slice(2).toLowerCase(),n=j(t),r=`0x`;for(let e=0;e<t.length;e++){let i=t[e],a=n[e];!i||!a||(i>=`a`&&i<=`f`?r+=parseInt(a,16)>=8?i.toUpperCase():i:r+=i)}return r}function Ue(e){return e===Z(e)}let We=/^0x[0-9a-fA-F]{40}$/;function Ge(e,n){if(!We.test(e))return[{code:t.INVALID_EVM_ADDRESS,field:n,message:`EVM address must be 42 hex characters with 0x prefix`,severity:`error`,fix:`Format: 0x followed by 40 hex digits (0-9, a-f, A-F)`}];let r=e.slice(2);return e===e.toLowerCase()&&/[a-f]/.test(r)?[{code:t.NO_EVM_CHECKSUM,field:n,message:`EVM address is all-lowercase with no checksum protection`,severity:`warning`,fix:`Use checksummed address to detect typos: ${Z(e)}`}]:/^[0-9A-F]{40}$/.test(r)&&/[A-F]/.test(r)||/^[0-9]{40}$/.test(r)||Ue(e)?[]:[{code:t.BAD_EVM_CHECKSUM,field:n,message:`EVM address has invalid checksum (EIP-55)`,severity:`warning`,fix:`Expected: ${Z(e)}`}]}let Ke=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function qe(e,n){if(!Ke.test(e))return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Solana address must be 32-44 Base58 characters`,severity:`error`,fix:`Valid characters: 1-9, A-H, J-N, P-Z, a-k, m-z (no 0, O, I, l)`}];try{let r=He(e);if(r.length!==32)return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Solana address must decode to 32 bytes, got ${r.length}`,severity:`error`,fix:`Verify address is a valid Solana public key`}]}catch(e){return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Invalid Base58 encoding`,severity:`error`,fix:e instanceof Error?e.message:`Check Base58 encoding`}]}return[]}function Je(e,t,n){let r=l(t);if(r===void 0)return[];switch(r){case`eip155`:return Ge(e,n);case`solana`:return qe(e,n);case`stellar`:case`aptos`:return[];default:return[]}}function Ye(e){let i=[],{parsed:a,error:o}=r(e);if(o)return{parsed:null,format:`unknown`,issues:[o]};if(!m(a))return i.push({code:t.NOT_OBJECT,field:`$`,message:n.NOT_OBJECT,severity:`error`}),{parsed:null,format:`unknown`,issues:i};let s=g(a);return s===`unknown`&&i.push({code:t.UNKNOWN_FORMAT,field:`$`,message:n.UNKNOWN_FORMAT,severity:`error`}),{parsed:a,format:s,issues:i}}function Xe(e,r){let i=[],a=e.x402Version;return a!==1&&a!==2&&i.push({code:t.INVALID_VERSION,field:`x402Version`,message:n.INVALID_VERSION,severity:`error`}),i}function Ze(e,r){let i=[];return e.scheme||i.push({code:t.MISSING_SCHEME,field:`${r}.scheme`,message:n.MISSING_SCHEME,severity:`error`}),e.network||i.push({code:t.MISSING_NETWORK,field:`${r}.network`,message:n.MISSING_NETWORK,severity:`error`}),e.amount||i.push({code:t.MISSING_AMOUNT,field:`${r}.amount`,message:n.MISSING_AMOUNT,severity:`error`}),e.asset||i.push({code:t.MISSING_ASSET,field:`${r}.asset`,message:n.MISSING_ASSET,severity:`error`}),e.payTo||i.push({code:t.MISSING_PAY_TO,field:`${r}.payTo`,message:n.MISSING_PAY_TO,severity:`error`}),i}function Qe(e){let r=[];return Array.isArray(e.accepts)?(e.accepts.length===0&&r.push({code:t.EMPTY_ACCEPTS,field:`accepts`,message:n.EMPTY_ACCEPTS,severity:`error`}),r):(r.push({code:t.INVALID_ACCEPTS,field:`accepts`,message:n.INVALID_ACCEPTS,severity:`error`}),r)}function $e(e,r){let i=[];if(!e.resource)return r===`v2`&&i.push({code:t.MISSING_RESOURCE,field:`resource`,message:n.MISSING_RESOURCE,severity:`warning`}),i;if(!e.resource.url)return i.push({code:t.MISSING_RESOURCE,field:`resource.url`,message:n.MISSING_RESOURCE,severity:`warning`}),i;try{new URL(e.resource.url)}catch{i.push({code:t.INVALID_URL,field:`resource.url`,message:`resource.url is not a valid URL format`,severity:`warning`})}return i}function et(e,r){let i=[];if(!e.network)return i;if(!o(e.network)){let a=p(e.network);return a?i.push({code:t.INVALID_NETWORK_FORMAT,field:`${r}.network`,message:n.INVALID_NETWORK_FORMAT,severity:`error`,fix:`Use '${a}' instead of '${e.network}'`}):i.push({code:t.INVALID_NETWORK_FORMAT,field:`${r}.network`,message:n.INVALID_NETWORK_FORMAT,severity:`error`}),i}return s(e.network)||i.push({code:t.UNKNOWN_NETWORK,field:`${r}.network`,message:n.UNKNOWN_NETWORK,severity:`warning`}),i}function tt(e,r){let i=[];return e.asset&&e.network&&o(e.network)&&!d(e.network,e.asset)&&i.push({code:t.UNKNOWN_ASSET,field:`${r}.asset`,message:n.UNKNOWN_ASSET,severity:`warning`}),i}function nt(e,r){let i=[];return e.amount?/^\d+$/.test(e.amount)?(e.amount===`0`&&i.push({code:t.ZERO_AMOUNT,field:`${r}.amount`,message:n.ZERO_AMOUNT,severity:`error`}),i):(i.push({code:t.INVALID_AMOUNT,field:`${r}.amount`,message:n.INVALID_AMOUNT,severity:`error`}),i):i}function rt(e,r,i){let a=[];return e.maxTimeoutSeconds===void 0?(i===`v2`&&a.push({code:t.MISSING_MAX_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.MISSING_MAX_TIMEOUT,severity:`warning`}),a):typeof e.maxTimeoutSeconds!=`number`||!Number.isInteger(e.maxTimeoutSeconds)?(a.push({code:t.INVALID_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.INVALID_TIMEOUT,severity:`error`}),a):(e.maxTimeoutSeconds<=0&&a.push({code:t.INVALID_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.INVALID_TIMEOUT,severity:`error`}),a)}function it(e,r,i){let a=[];return r===`v1`&&a.push({code:t.LEGACY_FORMAT,field:`$`,message:n.LEGACY_FORMAT,severity:`warning`,fix:`Upgrade to x402 v2 -- use amount instead of maxAmountRequired, add resource object`}),a}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function at(e){let r=[];if(!e.extensions)return r;let i=e.extensions.bazaar;if(i===void 0)return r;if(!Q(i))return r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar`,message:`extensions.bazaar must be an object`,severity:`warning`,fix:`Set extensions.bazaar to an object with info and schema properties`}),r;let a=i.info;if(!Q(a))r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar.info`,message:n.INVALID_BAZAAR_INFO,severity:`warning`,fix:`Add an info object with input and output properties describing your API`});else{let e=a.input;(!Q(e)||!e.type||!e.method)&&r.push({code:t.INVALID_BAZAAR_INFO_INPUT,field:`extensions.bazaar.info.input`,message:n.INVALID_BAZAAR_INFO_INPUT,severity:`warning`,fix:`Add input.type (e.g. "application/json") and input.method (e.g. "POST")`});let i=a.output;Q(i)||r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar.info.output`,message:`extensions.bazaar.info.output must be an object`,severity:`warning`,fix:`Add an output object describing the API response format`})}let o=i.schema;return(!Q(o)||!o.type&&!o.$schema&&!o.properties)&&r.push({code:t.INVALID_BAZAAR_SCHEMA,field:`extensions.bazaar.schema`,message:n.INVALID_BAZAAR_SCHEMA,severity:`warning`,fix:`Add a JSON Schema object with type, $schema, or properties`}),r}function ot(e){let r=[],i=e.accepts;if(!Array.isArray(i))return r;for(let e=0;e<i.length;e++){let a=i[e];if(!Q(a))continue;let o=a.outputSchema;if(o===void 0)continue;let s=`accepts[${e}].outputSchema`;if(!Q(o)){r.push({code:t.INVALID_OUTPUT_SCHEMA,field:s,message:n.INVALID_OUTPUT_SCHEMA,severity:`warning`,fix:`Set outputSchema to an object with input and output properties`});continue}let c=o.input;(!Q(c)||!c.type||!c.method)&&r.push({code:t.INVALID_OUTPUT_SCHEMA_INPUT,field:`${s}.input`,message:n.INVALID_OUTPUT_SCHEMA_INPUT,severity:`warning`,fix:`Add input.type (e.g. "application/json") and input.method (e.g. "POST")`});let l=o.output;Q(l)||r.push({code:t.INVALID_OUTPUT_SCHEMA,field:`${s}.output`,message:`accepts[i].outputSchema.output must be an object`,severity:`warning`,fix:`Add an output object describing the API response format`})}return r}function st(e,r){if(e.extensions&&e.extensions.bazaar!==void 0)return[];let i=r.accepts;if(Array.isArray(i)){for(let e of i)if(Q(e)&&e.outputSchema!==void 0)return[]}return[{code:t.MISSING_INPUT_SCHEMA,field:`extensions`,message:n.MISSING_INPUT_SCHEMA,severity:`warning`,fix:`Add extensions.bazaar with info and schema to help agents discover your API -- see https://bazaar.x402.org`}]}function ct(e,n){try{return lt(e,n)}catch{return{valid:!1,version:`unknown`,errors:[{code:t.UNKNOWN_FORMAT,field:`$`,message:`Unexpected validation error`,severity:`error`}],warnings:[],normalized:null}}}function lt(e,r){let i=Ye(e);if(i.issues.length>0)return{valid:!1,version:i.format||`unknown`,errors:i.issues,warnings:[],normalized:null};let a=i.parsed,o=i.format,s=_(a);if(s===null)return{valid:!1,version:o,errors:[{code:t.UNKNOWN_FORMAT,field:`$`,message:n.UNKNOWN_FORMAT,severity:`error`}],warnings:[],normalized:null};let c=[],l=[];if(c.push(...Xe(s,o)),c.push(...Qe(s)),l.push(...$e(s,o)),Array.isArray(s.accepts)&&s.accepts.length>0)for(let e=0;e<s.accepts.length;e++){let t=s.accepts[e],n=`accepts[${e}]`;c.push(...Ze(t,n));for(let e of et(t,n))e.severity===`error`?c.push(e):l.push(e);l.push(...tt(t,n)),c.push(...nt(t,n));for(let e of rt(t,n,o))e.severity===`error`?c.push(e):l.push(e);if(t.payTo&&t.network)for(let e of Je(t.payTo,t.network,`${n}.payTo`))e.severity===`error`?c.push(e):l.push(e)}if(l.push(...it(s,o,a)),l.push(...at(s)),l.push(...ot(a)),l.push(...st(s,a)),r?.strict===!0){for(let e of l)c.push({...e,severity:`error`});l.length=0}return{valid:c.length===0,version:o,errors:c,warnings:l,normalized:s}}function ut(e,t){if(!e)return null;if(typeof e.get==`function`)return e.get(t);let n=t.toLowerCase();for(let t of Object.keys(e))if(t.toLowerCase()===n)return e[t];return null}function dt(e){return typeof atob==`function`?atob(e):Buffer.from(e,`base64`).toString(`utf-8`)}function ft(e){if(!e||typeof e!=`object`)return!1;let t=e;return!!(t.accepts||t.payTo||t.x402Version)}function pt(e){let t=ut(e,`payment-required`);if(!t)return null;try{let e=dt(t),n=JSON.parse(e);if(n&&typeof n==`object`&&!Array.isArray(n))return{config:n,source:`header`}}catch{}try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return{config:e,source:`header`}}catch{}return null}function $(e){let t=e.body;if(t&&typeof t==`object`&&!Array.isArray(t)&&ft(t))return{config:t,source:`body`,error:null};if(typeof t==`string`&&t.trim())try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e)&&ft(e))return{config:e,source:`body`,error:null}}catch{}let n=pt(e.headers);return n?{config:n.config,source:n.source,error:null}:{config:null,source:null,error:`No x402 config found in response body or PAYMENT-REQUIRED header`}}function mt(e,t){let n=$(e);if(!n.config)return{extracted:!1,source:null,extractionError:n.error,valid:!1,version:`unknown`,errors:[],warnings:[],normalized:null,summary:[],raw:null};let r=ct(n.config,t),i=[],a=r.normalized?.accepts??[];for(let e=0;e<a.length;e++){let t=a[e],n=c(t.network),r=ee(t.network,t.asset);i.push({index:e,network:t.network,networkName:n?.name??t.network,networkType:n?.type??null,payTo:t.payTo,amount:t.amount,asset:t.asset,assetSymbol:r?.symbol??null,assetDecimals:r?.decimals??null,scheme:t.scheme})}return{extracted:!0,source:n.source,extractionError:null,valid:r.valid,version:r.version,errors:r.errors,warnings:r.warnings,normalized:r.normalized,summary:i,raw:n.config}}return e.CAIP2_REGEX=i,e.ErrorCode=t,e.ErrorMessages=n,e.KNOWN_ASSETS=u,e.KNOWN_NETWORKS=a,e.SIMPLE_NAME_TO_CAIP2=f,e.VERSION=`0.2.0`,e.check=mt,e.decodeBase58=He,e.detect=g,e.extractConfig=$,e.getAssetInfo=ee,e.getCanonicalNetwork=p,e.getNetworkInfo=c,e.getNetworkNamespace=l,e.isKnownAsset=d,e.isKnownNetwork=s,e.isValidCaip2=o,e.isValidChecksum=Ue,e.keccak256=j,e.normalize=_,e.parseInput=r,e.toChecksumAddress=Z,e.validate=ct,e.validateAddress=Je,e.validateEvmAddress=Ge,e.validateSolanaAddress=qe,e})({});
5
+ function M(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function N(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(e=>typeof e==`string`):t.every(e=>Number.isSafeInteger(e)):!1}function P(e){if(typeof e!=`function`)throw Error(`function expected`);return!0}function F(e,t){if(typeof t!=`string`)throw Error(`${e}: string expected`);return!0}function I(e){if(!Number.isSafeInteger(e))throw Error(`invalid integer: ${e}`)}function L(e){if(!Array.isArray(e))throw Error(`array expected`)}function R(e,t){if(!N(!0,t))throw Error(`${e}: array of strings expected`)}function z(e,t){if(!N(!1,t))throw Error(`${e}: array of numbers expected`)}function B(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}function V(e){let t=typeof e==`string`?e.split(``):e,n=t.length;R(`alphabet`,t);let r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(L(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(L(t),t.map(t=>{F(`alphabet.decode`,t);let n=r.get(t);if(n===void 0)throw Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}function H(e=``){return F(`join`,e),{encode:t=>(R(`join.decode`,t),t.join(e)),decode:t=>(F(`join.decode`,t),t.split(e))}}function U(e,t=`=`){return I(e),F(`padding`,t),{encode(n){for(R(`padding.encode`,n);n.length*e%8;)n.push(t);return n},decode(n){R(`padding.decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid, string should have whole number of bytes`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: invalid, string has too much padding`);return n.slice(0,r)}}}function W(e){return P(e),{encode:e=>e,decode:t=>e(t)}}function Ne(e,t,n){if(t<2)throw Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(L(e),!e.length)return[];let r=0,i=[],a=Array.from(e,e=>{if(I(e),e<0||e>=t)throw Error(`invalid integer: ${e}`);return e}),o=a.length;for(;;){let e=0,s=!0;for(let i=r;i<o;i++){let o=a[i],c=t*e,l=c+o;if(!Number.isSafeInteger(l)||c/t!==e||l-o!==c)throw Error(`convertRadix: carry overflow`);let u=l/n;e=l%n;let d=Math.floor(u);if(a[i]=d,!Number.isSafeInteger(d)||d*n+e!==l)throw Error(`convertRadix: carry overflow`);if(s)d?s=!1:r=i;else continue}if(i.push(e),s)break}for(let t=0;t<e.length-1&&e[t]===0;t++)i.push(0);return i.reverse()}let Pe=(e,t)=>t===0?e:Pe(t,e%t),G=(e,t)=>e+(t-Pe(e,t)),K=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function q(e,t,n,r){if(L(e),t<=0||t>32)throw Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw Error(`convertRadix2: wrong to=${n}`);if(G(t,n)>32)throw Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${G(t,n)}`);let i=0,a=0,o=K[t],s=K[n]-1,c=[];for(let r of e){if(I(r),r>=o)throw Error(`convertRadix2: invalid data word=${r} from=${t}`);if(i=i<<t|r,a+t>32)throw Error(`convertRadix2: carry overflow pos=${a} from=${t}`);for(a+=t;a>=n;a-=n)c.push((i>>a-n&s)>>>0);let e=K[a];if(e===void 0)throw Error(`invalid carry`);i&=e-1}if(i=i<<n-a&s,!r&&a>=t)throw Error(`Excess padding`);if(!r&&i>0)throw Error(`Non-zero padding: ${i}`);return r&&a>0&&c.push(i>>>0),c}function Fe(e){return I(e),{encode:t=>{if(!M(t))throw Error(`radix.encode input should be Uint8Array`);return Ne(Array.from(t),256,e)},decode:t=>(z(`radix.decode`,t),Uint8Array.from(Ne(t,e,256)))}}function J(e,t=!1){if(I(e),e<=0||e>32)throw Error(`radix2: bits should be in (0..32]`);if(G(8,e)>32||G(e,8)>32)throw Error(`radix2: carry overflow`);return{encode:n=>{if(!M(n))throw Error(`radix2.encode input should be Uint8Array`);return q(Array.from(n),8,e,!t)},decode:n=>(z(`radix2.decode`,n),Uint8Array.from(q(n,e,8,t)))}}function Ie(e){return P(e),function(...t){try{return e.apply(null,t)}catch{}}}B(J(4),V(`0123456789ABCDEF`),H(``)),B(J(5),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),U(5),H(``)),B(J(5),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),H(``)),B(J(5),V(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),U(5),H(``)),B(J(5),V(`0123456789ABCDEFGHIJKLMNOPQRSTUV`),H(``)),B(J(5),V(`0123456789ABCDEFGHJKMNPQRSTVWXYZ`),H(``),W(e=>e.toUpperCase().replace(/O/g,`0`).replace(/[IL]/g,`1`)));let Le=typeof Uint8Array.from([]).toBase64==`function`&&typeof Uint8Array.fromBase64==`function`;Le||B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),U(6),H(``)),B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`),H(``)),Le||B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),U(6),H(``)),B(J(6),V(`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`),H(``));let Re=(e=>B(Fe(58),V(e),H(``)))(`123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz`),Y=B(V(`qpzry9x8gf2tvdw0s3jn54khce6mua7l`),H(``)),ze=[996825010,642813549,513874426,1027748829,705979059];function X(e){let t=e>>25,n=(e&33554431)<<5;for(let e=0;e<ze.length;e++)(t>>e&1)==1&&(n^=ze[e]);return n}function Be(e,t,n=1){let r=e.length,i=1;for(let t=0;t<r;t++){let n=e.charCodeAt(t);if(n<33||n>126)throw Error(`Invalid prefix (${e})`);i=X(i)^n>>5}i=X(i);for(let t=0;t<r;t++)i=X(i)^e.charCodeAt(t)&31;for(let e of t)i=X(i)^e;for(let e=0;e<6;e++)i=X(i);return i^=n,Y.encode(q([i%K[30]],30,5,!1))}function Ve(e){let t=e===`bech32`?1:734539939,n=J(5),r=n.decode,i=n.encode,a=Ie(r);function o(e,n,r=90){F(`bech32.encode prefix`,e),M(n)&&(n=Array.from(n)),z(`bech32.encode`,n);let i=e.length;if(i===0)throw TypeError(`Invalid prefix length ${i}`);let a=i+7+n.length;if(r!==!1&&a>r)throw TypeError(`Length ${a} exceeds limit ${r}`);let o=e.toLowerCase(),s=Be(o,n,t);return`${o}1${Y.encode(n)}${s}`}function s(e,n=90){F(`bech32.decode input`,e);let r=e.length;if(r<8||n!==!1&&r>n)throw TypeError(`invalid string length: ${r} (${e}). Expected (8..${n})`);let i=e.toLowerCase();if(e!==i&&e!==e.toUpperCase())throw Error(`String must be lowercase or uppercase`);let a=i.lastIndexOf(`1`);if(a===0||a===-1)throw Error(`Letter "1" must be present between prefix and data only`);let o=i.slice(0,a),s=i.slice(a+1);if(s.length<6)throw Error(`Data must be at least 6 characters long`);let c=Y.decode(s).slice(0,-6),l=Be(o,c,t);if(!s.endsWith(l))throw Error(`Invalid checksum in ${e}: expected "${l}"`);return{prefix:o,words:c}}let c=Ie(s);function l(e){let{prefix:t,words:n}=s(e,!1);return{prefix:t,words:n,bytes:r(n)}}function u(e,t){return o(e,i(t))}return{encode:o,decode:s,encodeFromBytes:u,decodeToBytes:l,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:a,toWords:i}}Ve(`bech32`),Ve(`bech32m`),typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`||B(J(4),V(`0123456789abcdef`),H(``),W(e=>{if(typeof e!=`string`||e.length%2!=0)throw TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));function He(e){try{return Re.decode(e)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`Invalid Base58: ${t}`)}}function Z(e){let t=e.slice(2).toLowerCase(),n=j(t),r=`0x`;for(let e=0;e<t.length;e++){let i=t[e],a=n[e];!i||!a||(i>=`a`&&i<=`f`?r+=parseInt(a,16)>=8?i.toUpperCase():i:r+=i)}return r}function Ue(e){return e===Z(e)}let We=/^0x[0-9a-fA-F]{40}$/;function Ge(e,n){if(!We.test(e))return[{code:t.INVALID_EVM_ADDRESS,field:n,message:`EVM address must be 42 hex characters with 0x prefix`,severity:`error`,fix:`Format: 0x followed by 40 hex digits (0-9, a-f, A-F)`}];let r=e.slice(2);return e===e.toLowerCase()&&/[a-f]/.test(r)?[{code:t.NO_EVM_CHECKSUM,field:n,message:`EVM address is all-lowercase with no checksum protection`,severity:`warning`,fix:`Use checksummed address to detect typos: ${Z(e)}`}]:/^[0-9A-F]{40}$/.test(r)&&/[A-F]/.test(r)||/^[0-9]{40}$/.test(r)||Ue(e)?[]:[{code:t.BAD_EVM_CHECKSUM,field:n,message:`EVM address has invalid checksum (EIP-55)`,severity:`warning`,fix:`Expected: ${Z(e)}`}]}let Ke=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function qe(e,n){if(!Ke.test(e))return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Solana address must be 32-44 Base58 characters`,severity:`error`,fix:`Valid characters: 1-9, A-H, J-N, P-Z, a-k, m-z (no 0, O, I, l)`}];try{let r=He(e);if(r.length!==32)return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Solana address must decode to 32 bytes, got ${r.length}`,severity:`error`,fix:`Verify address is a valid Solana public key`}]}catch(e){return[{code:t.INVALID_SOLANA_ADDRESS,field:n,message:`Invalid Base58 encoding`,severity:`error`,fix:e instanceof Error?e.message:`Check Base58 encoding`}]}return[]}function Je(e,t,n){let r=l(t);if(r===void 0)return[];switch(r){case`eip155`:return Ge(e,n);case`solana`:return qe(e,n);case`stellar`:case`aptos`:return[];default:return[]}}function Ye(e){let i=[],{parsed:a,error:o}=r(e);if(o)return{parsed:null,format:`unknown`,issues:[o]};if(!m(a))return i.push({code:t.NOT_OBJECT,field:`$`,message:n.NOT_OBJECT,severity:`error`}),{parsed:null,format:`unknown`,issues:i};let s=g(a);return s===`unknown`&&i.push({code:t.UNKNOWN_FORMAT,field:`$`,message:n.UNKNOWN_FORMAT,severity:`error`}),{parsed:a,format:s,issues:i}}function Xe(e,r){let i=[],a=e.x402Version;return a!==1&&a!==2&&i.push({code:t.INVALID_VERSION,field:`x402Version`,message:n.INVALID_VERSION,severity:`error`}),i}function Ze(e,r){let i=[];return e.scheme||i.push({code:t.MISSING_SCHEME,field:`${r}.scheme`,message:n.MISSING_SCHEME,severity:`error`}),e.network||i.push({code:t.MISSING_NETWORK,field:`${r}.network`,message:n.MISSING_NETWORK,severity:`error`}),e.amount||i.push({code:t.MISSING_AMOUNT,field:`${r}.amount`,message:n.MISSING_AMOUNT,severity:`error`}),e.asset||i.push({code:t.MISSING_ASSET,field:`${r}.asset`,message:n.MISSING_ASSET,severity:`error`}),e.payTo||i.push({code:t.MISSING_PAY_TO,field:`${r}.payTo`,message:n.MISSING_PAY_TO,severity:`error`}),i}function Qe(e){let r=[];return Array.isArray(e.accepts)?(e.accepts.length===0&&r.push({code:t.EMPTY_ACCEPTS,field:`accepts`,message:n.EMPTY_ACCEPTS,severity:`error`}),r):(r.push({code:t.INVALID_ACCEPTS,field:`accepts`,message:n.INVALID_ACCEPTS,severity:`error`}),r)}function $e(e,r){let i=[];if(!e.resource)return r===`v2`&&i.push({code:t.MISSING_RESOURCE,field:`resource`,message:n.MISSING_RESOURCE,severity:`warning`}),i;if(!e.resource.url)return i.push({code:t.MISSING_RESOURCE,field:`resource.url`,message:n.MISSING_RESOURCE,severity:`warning`}),i;try{new URL(e.resource.url)}catch{i.push({code:t.INVALID_URL,field:`resource.url`,message:`resource.url is not a valid URL format`,severity:`warning`})}return i}function et(e,r){let i=[];if(!e.network)return i;if(!o(e.network)){let a=p(e.network);return a?i.push({code:t.INVALID_NETWORK_FORMAT,field:`${r}.network`,message:n.INVALID_NETWORK_FORMAT,severity:`error`,fix:`Use '${a}' instead of '${e.network}'`}):i.push({code:t.INVALID_NETWORK_FORMAT,field:`${r}.network`,message:n.INVALID_NETWORK_FORMAT,severity:`error`}),i}return s(e.network)||i.push({code:t.UNKNOWN_NETWORK,field:`${r}.network`,message:n.UNKNOWN_NETWORK,severity:`warning`}),i}function tt(e,r){let i=[];return e.asset&&e.network&&o(e.network)&&!d(e.network,e.asset)&&i.push({code:t.UNKNOWN_ASSET,field:`${r}.asset`,message:n.UNKNOWN_ASSET,severity:`warning`}),i}function nt(e,r){let i=[];return e.amount?/^\d+$/.test(e.amount)?(e.amount===`0`&&i.push({code:t.ZERO_AMOUNT,field:`${r}.amount`,message:n.ZERO_AMOUNT,severity:`error`}),i):(i.push({code:t.INVALID_AMOUNT,field:`${r}.amount`,message:n.INVALID_AMOUNT,severity:`error`}),i):i}function rt(e,r,i){let a=[];return e.maxTimeoutSeconds===void 0?(i===`v2`&&a.push({code:t.MISSING_MAX_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.MISSING_MAX_TIMEOUT,severity:`warning`}),a):typeof e.maxTimeoutSeconds!=`number`||!Number.isInteger(e.maxTimeoutSeconds)?(a.push({code:t.INVALID_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.INVALID_TIMEOUT,severity:`error`}),a):(e.maxTimeoutSeconds<=0&&a.push({code:t.INVALID_TIMEOUT,field:`${r}.maxTimeoutSeconds`,message:n.INVALID_TIMEOUT,severity:`error`}),a)}function it(e,r,i){let a=[];return r===`v1`&&a.push({code:t.LEGACY_FORMAT,field:`$`,message:n.LEGACY_FORMAT,severity:`warning`,fix:`Upgrade to x402 v2 -- use amount instead of maxAmountRequired, add resource object`}),a}function Q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function at(e){let r=[];if(!e.extensions)return r;let i=e.extensions.bazaar;if(i===void 0)return r;if(!Q(i))return r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar`,message:`extensions.bazaar must be an object`,severity:`warning`,fix:`Set extensions.bazaar to an object with info and schema properties`}),r;let a=i.info;if(!Q(a))r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar.info`,message:n.INVALID_BAZAAR_INFO,severity:`warning`,fix:`Add an info object with input and output properties describing your API`});else{let e=a.input;(!Q(e)||!e.type||!e.method)&&r.push({code:t.INVALID_BAZAAR_INFO_INPUT,field:`extensions.bazaar.info.input`,message:n.INVALID_BAZAAR_INFO_INPUT,severity:`warning`,fix:`Add input.type (e.g. "application/json") and input.method (e.g. "POST")`});let i=a.output;Q(i)||r.push({code:t.INVALID_BAZAAR_INFO,field:`extensions.bazaar.info.output`,message:`extensions.bazaar.info.output must be an object`,severity:`warning`,fix:`Add an output object describing the API response format`})}let o=i.schema;return(!Q(o)||!o.type&&!o.$schema&&!o.properties)&&r.push({code:t.INVALID_BAZAAR_SCHEMA,field:`extensions.bazaar.schema`,message:n.INVALID_BAZAAR_SCHEMA,severity:`warning`,fix:`Add a JSON Schema object with type, $schema, or properties`}),r}function ot(e){let r=[],i=e.accepts;if(!Array.isArray(i))return r;for(let e=0;e<i.length;e++){let a=i[e];if(!Q(a))continue;let o=a.outputSchema;if(o===void 0)continue;let s=`accepts[${e}].outputSchema`;if(!Q(o)){r.push({code:t.INVALID_OUTPUT_SCHEMA,field:s,message:n.INVALID_OUTPUT_SCHEMA,severity:`warning`,fix:`Set outputSchema to an object with input and output properties`});continue}let c=o.input;(!Q(c)||!c.type||!c.method)&&r.push({code:t.INVALID_OUTPUT_SCHEMA_INPUT,field:`${s}.input`,message:n.INVALID_OUTPUT_SCHEMA_INPUT,severity:`warning`,fix:`Add input.type (e.g. "application/json") and input.method (e.g. "POST")`});let l=o.output;Q(l)||r.push({code:t.INVALID_OUTPUT_SCHEMA,field:`${s}.output`,message:`accepts[i].outputSchema.output must be an object`,severity:`warning`,fix:`Add an output object describing the API response format`})}return r}function st(e,r){if(e.extensions&&e.extensions.bazaar!==void 0)return[];let i=r.accepts;if(Array.isArray(i)){for(let e of i)if(Q(e)&&e.outputSchema!==void 0)return[]}return[{code:t.MISSING_INPUT_SCHEMA,field:`extensions`,message:n.MISSING_INPUT_SCHEMA,severity:`warning`,fix:`Add extensions.bazaar with info and schema to help agents discover your API -- see https://bazaar.x402.org`}]}function ct(e,n){try{return lt(e,n)}catch{return{valid:!1,version:`unknown`,errors:[{code:t.UNKNOWN_FORMAT,field:`$`,message:`Unexpected validation error`,severity:`error`}],warnings:[],normalized:null}}}function lt(e,r){let i=Ye(e);if(i.issues.length>0)return{valid:!1,version:i.format||`unknown`,errors:i.issues,warnings:[],normalized:null};let a=i.parsed,o=i.format,s=_(a);if(s===null)return{valid:!1,version:o,errors:[{code:t.UNKNOWN_FORMAT,field:`$`,message:n.UNKNOWN_FORMAT,severity:`error`}],warnings:[],normalized:null};let c=[],l=[];if(c.push(...Xe(s,o)),c.push(...Qe(s)),l.push(...$e(s,o)),Array.isArray(s.accepts)&&s.accepts.length>0)for(let e=0;e<s.accepts.length;e++){let t=s.accepts[e],n=`accepts[${e}]`;c.push(...Ze(t,n));for(let e of et(t,n))e.severity===`error`?c.push(e):l.push(e);l.push(...tt(t,n)),c.push(...nt(t,n));for(let e of rt(t,n,o))e.severity===`error`?c.push(e):l.push(e);if(t.payTo&&t.network)for(let e of Je(t.payTo,t.network,`${n}.payTo`))e.severity===`error`?c.push(e):l.push(e)}if(l.push(...it(s,o,a)),l.push(...at(s)),l.push(...ot(a)),l.push(...st(s,a)),r?.strict===!0){for(let e of l)c.push({...e,severity:`error`});l.length=0}return{valid:c.length===0,version:o,errors:c,warnings:l,normalized:s}}function ut(e,t){if(!e)return null;if(typeof e.get==`function`)return e.get(t);let n=t.toLowerCase();for(let t of Object.keys(e))if(t.toLowerCase()===n)return e[t];return null}function dt(e){return typeof atob==`function`?atob(e):Buffer.from(e,`base64`).toString(`utf-8`)}function ft(e){if(!e||typeof e!=`object`)return!1;let t=e;return!!(t.accepts||t.payTo||t.x402Version)}function pt(e){let t=ut(e,`payment-required`);if(!t)return null;try{let e=dt(t),n=JSON.parse(e);if(n&&typeof n==`object`&&!Array.isArray(n))return{config:n,source:`header`}}catch{}try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return{config:e,source:`header`}}catch{}return null}function $(e){let t=e.body;if(t&&typeof t==`object`&&!Array.isArray(t)&&ft(t))return{config:t,source:`body`,error:null};if(typeof t==`string`&&t.trim())try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e)&&ft(e))return{config:e,source:`body`,error:null}}catch{}let n=pt(e.headers);return n?{config:n.config,source:n.source,error:null}:{config:null,source:null,error:`No x402 config found in response body or PAYMENT-REQUIRED header`}}function mt(e,t){let n=$(e);if(!n.config)return{extracted:!1,source:null,extractionError:n.error,valid:!1,version:`unknown`,errors:[],warnings:[],normalized:null,summary:[],raw:null};let r=ct(n.config,t),i=[],a=r.normalized?.accepts??[];for(let e=0;e<a.length;e++){let t=a[e],n=c(t.network),r=ee(t.network,t.asset);i.push({index:e,network:t.network,networkName:n?.name??t.network,networkType:n?.type??null,payTo:t.payTo,amount:t.amount,asset:t.asset,assetSymbol:r?.symbol??null,assetDecimals:r?.decimals??null,scheme:t.scheme})}return{extracted:!0,source:n.source,extractionError:null,valid:r.valid,version:r.version,errors:r.errors,warnings:r.warnings,normalized:r.normalized,summary:i,raw:n.config}}return e.CAIP2_REGEX=i,e.ErrorCode=t,e.ErrorMessages=n,e.KNOWN_ASSETS=u,e.KNOWN_NETWORKS=a,e.SIMPLE_NAME_TO_CAIP2=f,e.VERSION=`0.3.1`,e.check=mt,e.decodeBase58=He,e.detect=g,e.extractConfig=$,e.getAssetInfo=ee,e.getCanonicalNetwork=p,e.getNetworkInfo=c,e.getNetworkNamespace=l,e.isKnownAsset=d,e.isKnownNetwork=s,e.isValidCaip2=o,e.isValidChecksum=Ue,e.keccak256=j,e.normalize=_,e.parseInput=r,e.toChecksumAddress=Z,e.validate=ct,e.validateAddress=Je,e.validateEvmAddress=Ge,e.validateSolanaAddress=qe,e})({});
package/dist/index.js CHANGED
@@ -2130,7 +2130,7 @@ function check(response, options) {
2130
2130
 
2131
2131
  //#endregion
2132
2132
  //#region src/index.ts
2133
- const VERSION = "0.2.0";
2133
+ const VERSION = "0.3.1";
2134
2134
 
2135
2135
  //#endregion
2136
2136
  export { CAIP2_REGEX, ErrorCode, ErrorMessages, KNOWN_ASSETS, KNOWN_NETWORKS, SIMPLE_NAME_TO_CAIP2, VERSION, check, decodeBase58, detect, extractConfig, getAssetInfo, getCanonicalNetwork, getNetworkInfo, getNetworkNamespace, isKnownAsset, isKnownNetwork, isValidCaip2, isValidChecksum, keccak256, normalize, parseInput, toChecksumAddress, validate, validateAddress, validateEvmAddress, validateSolanaAddress };