validator0x 0.3.0 → 0.4.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.
Files changed (45) hide show
  1. package/AGENTS.md +71 -65
  2. package/CHANGELOG.md +10 -2
  3. package/README.md +13 -5
  4. package/dist/bitcoin.cjs +1 -1
  5. package/dist/bitcoin.mjs +1 -1
  6. package/dist/cardano.cjs +1 -1
  7. package/dist/cardano.mjs +1 -1
  8. package/dist/cosmos.cjs +1 -1
  9. package/dist/cosmos.mjs +1 -1
  10. package/dist/dogecoin.cjs +1 -1
  11. package/dist/dogecoin.mjs +1 -1
  12. package/dist/ethereum.cjs +1 -1
  13. package/dist/ethereum.mjs +1 -1
  14. package/dist/evm.cjs +1 -1
  15. package/dist/evm.mjs +1 -1
  16. package/dist/formatters.cjs +1 -1
  17. package/dist/formatters.mjs +1 -1
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.mjs +1 -1
  20. package/dist/index.umd.js +1 -1
  21. package/dist/litecoin.cjs +1 -1
  22. package/dist/litecoin.mjs +1 -1
  23. package/dist/move.cjs +1 -1
  24. package/dist/move.mjs +1 -1
  25. package/dist/near.cjs +1 -1
  26. package/dist/near.mjs +1 -1
  27. package/dist/ripple.cjs +1 -1
  28. package/dist/ripple.mjs +1 -1
  29. package/dist/shared/base-BtbJMDNm.cjs +1 -0
  30. package/dist/shared/base-D2s8b6tx.mjs +1 -0
  31. package/dist/shared/base58-CjvbdRzA.mjs +1 -0
  32. package/dist/shared/base58-DaLDoaS-.cjs +1 -0
  33. package/dist/shared/base58check-BBzwHAsr.mjs +1 -0
  34. package/dist/shared/base58check-CE9wLmUB.cjs +1 -0
  35. package/dist/shared/bech32-ClvuyXIQ.cjs +1 -0
  36. package/dist/shared/bech32-DsNhxmrB.mjs +1 -0
  37. package/dist/shared/sha256-BbwKo1_x.mjs +1 -0
  38. package/dist/shared/sha256-CRbh7pIK.cjs +1 -0
  39. package/dist/shared/utxo-CRr3-5en.mjs +1 -0
  40. package/dist/shared/utxo-DhlBlYDy.cjs +1 -0
  41. package/dist/solana.cjs +1 -1
  42. package/dist/solana.mjs +1 -1
  43. package/dist/tron.cjs +1 -1
  44. package/dist/tron.mjs +1 -1
  45. package/package.json +9 -8
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;exports.ValidationError=void 0,(r=exports.ValidationError||(exports.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH";class n{static sanitize(t){if(null==t)throw new Error(exports.ValidationError.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(t.length>256)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(exports.ValidationError.UNSAFE_INPUT);return t.trim()}}class o{validate(t,e){try{const r=n.sanitize(t),o=this.validateImplementation(r,e),i=o.details?.network;return o.valid&&i&&(e?.network&&"auto"!==e.network&&e.network!==i||!1===e?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:exports.ValidationError.NETWORK_MISMATCH}}:o}catch(t){const e=t instanceof Error?t.message:String(t);return e===exports.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:exports.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}format(t,e){return i(t,e)}}function i(t,e,r=4){const o=n.sanitize(t);if(!e?.shorten)return o;const i=e.shortenLength??r;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const a=o.startsWith("0x")?2:0;return o.length<=2*i+a+3?o:`${o.slice(0,i+a)}...${o.slice(-i)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const l=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],d=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function h(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&l}function u(t){const e=new Array(5),r=new Array(25);for(const n of d){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^h(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=h(t[e+5*n],c[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class f extends o{validateImplementation(t,e){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:exports.ValidationError.INVALID_CHARACTERS}};if(!e?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:exports.ValidationError.BURN_ADDRESS}};const n=this.isChecksummed(r);return(e?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!n?{valid:!1,error:"Invalid checksum",details:{errorCode:exports.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:n}}}format(t,e){let r=s(n.sanitize(t));return e?.checksum&&(r=this.toChecksumAddress(r)),i(r,e)}isChecksummed(t){const e=a(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));u(n)}let o="";for(let t=0;t<32;t++)o+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}const p="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",m=p.charAt(0),v={};for(let t=0;t<58;t++)v[p.charAt(t)]=t;function x(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===m;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=v[r];if(void 0===o)throw new Error(`Invalid Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let i=0;for(let t=0;t<n.length;++t)n[t]+=i,i=n[t]>>8,n[t]&=255;for(;i;)n.push(255&i),i>>=8}const o=t.length===r?[]:n.reverse();return Uint8Array.from([...new Array(r).fill(0),...o])}class I extends o{validateImplementation(t){if(t.length<32||t.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};try{if(32!==x(t).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===t?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function g(t){const e=[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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*t.length,o=t.length,i=new Uint8Array(64-(o+8)%64+8);i[0]=128;const a=n,s=Math.floor(a/4294967296),l=a%4294967296,c=i.length;i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=255&l,i[c-8]=s>>>24&255,i[c-7]=s>>>16&255,i[c-6]=s>>>8&255,i[c-5]=255&s;const d=new Uint8Array(o+i.length);d.set(t),d.set(i,o);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=A(h[t-2],17)^A(h[t-2],19)^h[t-2]>>>10,r=A(h[t-15],7)^A(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+r+h[t-16]|0}let n=r[0],o=r[1],i=r[2],a=r[3],s=r[4],l=r[5],c=r[6],u=r[7];for(let t=0;t<64;t++){const r=u+(A(s,6)^A(s,11)^A(s,25))+(s&l^~s&c)+e[t]+h[t]|0,d=n&o^n&i^o&i;u=c,c=l,l=s,s=a+r|0,a=i,i=o,o=n,n=r+((A(n,2)^A(n,13)^A(n,22))+d|0)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+i|0,r[3]=r[3]+a|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+c|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u}function A(t,e){return t>>>e|t<<32-e}function E(t){try{const e=x(t);if(e.length<5)return null;const r=e.slice(0,-4),n=g(g(r));return e.slice(-4).every((t,e)=>t===n[e])?r:null}catch{return null}}var w;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(w||(w={}));const C=[996825010,642813549,513874426,1027748829,705979059];function V(t,e,r){const n=r===w.BECH32M?734539939:1;return function(t){let e=1;for(const r of t){const t=e>>25;e=(33554431&e)<<5^r;for(let r=0;r<5;r++)t>>r&1&&(e^=C[r])}return e}(function(t){const e=[];for(let r=0;r<t.length;r++)e.push(t.charCodeAt(r)>>5);e.push(0);for(let r=0;r<t.length;r++)e.push(31&t.charCodeAt(r));return e}(t).concat(e))===n}function N(t,e=90){if(t.length<8||t.length>e)return null;const r=t.toLowerCase();if(t!==r&&t!==t.toUpperCase())return null;const n=r.lastIndexOf("1");if(n<1||n+7>r.length)return null;const o=r.substring(0,n);if(/[^\x21-\x7E]/.test(o))return null;const i=[];for(let t=n+1;t<r.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(r[t]);if(-1===e)return null;i.push(e)}return V(o,i,w.BECH32)?{hrp:o,data:i.slice(0,i.length-6),encoding:w.BECH32}:V(o,i,w.BECH32M)?{hrp:o,data:i.slice(0,i.length-6),encoding:w.BECH32M}:null}function k(t){let e=0,r=0;const n=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),r+=5,r>=8&&(r-=8,n.push(e>>>r&255))}return r>=5||e<<8-r&255?null:Uint8Array.from(n)}class b extends o{constructor(t){super(),this.config=t}validateImplementation(t){const e=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(t,this.config.hrps[e]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",exports.ValidationError.INVALID_LENGTH);const r=E(t);if(!r)return this.invalid("Invalid Base58Check address",exports.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",exports.ValidationError.INVALID_LENGTH);const n=this.config.versions[r[0]];return n?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:n,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(t,e){const r=N(t);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const n=r.data[0],o=k(r.data.slice(1));if(n>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===n&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",exports.ValidationError.INVALID_LENGTH);const i=0===n?w.BECH32:w.BECH32M;if(r.encoding!==i)return this.invalid("Wrong checksum encoding for witness version",exports.ValidationError.INVALID_CHECKSUM);const a=0===n?"segwit":1===n&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:a,network:e,checksum:!0}}}invalid(t,e=exports.ValidationError.INVALID_FORMAT){return{valid:!1,error:t,details:{errorCode:e}}}}class L extends b{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class T extends b{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class _ extends b{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class y{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const r=31&e;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const n=1<<r-24;if(this.offset+n>this.data.length)throw new Error("Truncated CBOR");let o=0;for(let t=0;t<n;t++)o=256*o+this.data[this.offset++];return o}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class S extends o{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new y(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const n=new y(r);if(3!==n.head(4)||28!==n.bytes().length)return null;const o=n.head(5);if(o>r.length)return null;const i=new Set;let a="mainnet";for(let t=0;t<o;t++){const t=n.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=n.bytes();if(1===t){const t=new y(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new y(e);t.head(0),t.end(),a="testnet"}}const s=n.head(0);return 0!==s&&2!==s?null:(n.end(),a)}catch{return null}}(x(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=N(t,256),r=e&&k(e.data);if(!e||e.encoding!==w.BECH32||!r?.length)return this.invalid();const n=r[0]>>>4,o=15&r[0];if(0!==o&&1!==o)return this.invalid();const i=14===n||15===n,a=(i?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==a)return this.invalid();let s=!1;return n<=3?s=57===r.length:6===n||7===n||i?s=29===r.length:4!==n&&5!==n||(s=this.validPointer(r)),s?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let r=0;r<3;r++){let r=0n;const n=e;do{if(e>=t.length||e-n>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-n>1&&128===t[n]||r>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}format(t,e){return i(t,e,8)}}const U="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",D=U.charAt(0),R={};for(let t=0;t<58;t++)R[U.charAt(t)]=t;class H extends o{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:exports.ValidationError.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===D;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=R[r];if(void 0===o)throw new Error(`Invalid Ripple Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let i=0;for(let t=0;t<n.length;++t)n[t]+=i,i=n[t]>>8,n[t]&=255;for(;i;)n.push(255&i),i>>=8}let o=[];t.length!==r&&(o=n.reverse());for(let t=0;t<r;t++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};const r=e.slice(0,21),n=e.slice(21),o=g(r),i=g(o);return i[0]!==n[0]||i[1]!==n[1]||i[2]!==n[2]||i[3]!==n[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:exports.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:exports.ValidationError.INVALID_CHARACTERS}}}}}class B extends f{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain=this.chain),r}}class M extends o{validateImplementation(t){if(/^41[0-9a-fA-F]{40}$/.test(t))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const e=34===t.length&&t.startsWith("T")?E(t):null;return e&&21===e.length&&65===e[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}const O={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class F extends o{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(t){const e=N(t),r=e&&k(e.data),n="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===O[this.chain]&&e.encoding===w.BECH32&&r&&n.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}class $ extends o{validateImplementation(t){return/^0x[0-9a-fA-F]{64}$/.test(t)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}class P extends o{validateImplementation(t,e){const r=/^0x[0-9a-fA-F]{64}$/.test(t),n=/^0x[0-9a-f]$/.test(t),o=n||/^0x[0-9a-f]{64}$/.test(t)&&!/^0x0{63}[0-9a-f]$/.test(t);return(e?.strict?o:r||n)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let r=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),i(r,e)}}class z extends o{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:exports.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}const j=new Map;for(const e of t)j.set(e,"ethereum"===e?new f:new B(e));for(const t of e)j.set(t,new F(t));j.set("bitcoin",new L),j.set("litecoin",new T),j.set("dogecoin",new _),j.set("solana",new I),j.set("ripple",new H),j.set("cardano",new S),j.set("tron",new M),j.set("sui",new $),j.set("aptos",new P),j.set("near",new z);const W=Object.freeze([...j.keys()]);function G(t){const e=j.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}exports.AddressValidator=o,exports.AptosValidator=P,exports.ArbitrumValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}},exports.AvalancheValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}},exports.BaseValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}},exports.BitcoinValidator=L,exports.BscValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}},exports.COSMOS_CHAINS=e,exports.CardanoValidator=S,exports.CosmosValidator=F,exports.DogecoinValidator=_,exports.EVM_CHAINS=t,exports.EthereumValidator=f,exports.EvmValidator=B,exports.LitecoinValidator=T,exports.NearValidator=z,exports.OptimismValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}},exports.PolygonValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}},exports.RippleValidator=H,exports.SUPPORTED_CHAINS=W,exports.SolanaValidator=I,exports.SuiValidator=$,exports.TronValidator=M,exports.addChecksum=function(e,r){return t.includes(r)?(new f).format(e,{checksum:!0}):n.sanitize(e)},exports.detectBlockchain=function(e,r){let o;try{o=n.sanitize(e)}catch{return null}if(!o)return null;const i=[];G("ethereum").validate(o,r).valid&&i.push(...t);for(const e of W)t.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(o)||/^[0-9a-f]{64}$/.test(o)||/^0[xs][0-9a-f]{40}$/.test(o)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(o))&&G(e).validate(o,r).valid&&i.push(e);return 0===i.length?null:1===i.length?i[0]:i},exports.formatAddress=function(t,e,r){return G(e).format(t,r)},exports.isSupportedChain=function(t){return"string"==typeof t&&j.has(t)},exports.normalizeAddress=function(e,r){const o=n.sanitize(e);return t.includes(r)||"sui"===r||"aptos"===r?o.toLowerCase():o},exports.shortenAddress=function(t,e=4){return i(t,{shorten:!0,shortenLength:e})},exports.validateAddress=function(t,e,r){return G(e).validate(t,r)},exports.validateBatch=function(t,e,r){const n=G(e);return t.map(t=>n.validate(t,r))};
1
+ "use strict";var e=require("./ethereum.cjs"),r=require("./solana.cjs"),t=require("./bitcoin.cjs"),a=require("./litecoin.cjs"),o=require("./dogecoin.cjs"),i=require("./cardano.cjs"),s=require("./ripple.cjs"),n=require("./evm.cjs"),d=require("./shared/base-BtbJMDNm.cjs"),l=require("./tron.cjs"),c=require("./cosmos.cjs"),u=require("./move.cjs"),p=require("./near.cjs"),V=require("./formatters.cjs");require("./shared/base58-DaLDoaS-.cjs"),require("./shared/utxo-DhlBlYDy.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class m extends e.EthereumValidator{validateImplementation(e,r){const t=super.validateImplementation(e,r);return t.valid&&(t.blockchain="polygon"),t}}const h=new Map;for(const r of d.EVM_CHAINS)h.set(r,"ethereum"===r?new e.EthereumValidator:new n.EvmValidator(r));for(const e of d.COSMOS_CHAINS)h.set(e,new c.CosmosValidator(e));h.set("bitcoin",new t.BitcoinValidator),h.set("litecoin",new a.LitecoinValidator),h.set("dogecoin",new o.DogecoinValidator),h.set("solana",new r.SolanaValidator),h.set("ripple",new s.RippleValidator),h.set("cardano",new i.CardanoValidator),h.set("tron",new l.TronValidator),h.set("sui",new u.SuiValidator),h.set("aptos",new u.AptosValidator),h.set("near",new p.NearValidator);const x=Object.freeze([...h.keys()]);function A(e){const r=h.get(e);if(!r)throw new Error(`Unsupported blockchain: ${String(e)}`);return r}exports.EthereumValidator=e.EthereumValidator,exports.SolanaValidator=r.SolanaValidator,exports.BitcoinValidator=t.BitcoinValidator,exports.LitecoinValidator=a.LitecoinValidator,exports.DogecoinValidator=o.DogecoinValidator,exports.CardanoValidator=i.CardanoValidator,exports.RippleValidator=s.RippleValidator,exports.ArbitrumValidator=n.ArbitrumValidator,exports.AvalancheValidator=n.AvalancheValidator,exports.BaseValidator=n.BaseValidator,exports.BscValidator=n.BscValidator,exports.EvmValidator=n.EvmValidator,exports.OptimismValidator=n.OptimismValidator,exports.AddressValidator=d.AddressValidator,exports.COSMOS_CHAINS=d.COSMOS_CHAINS,exports.EVM_CHAINS=d.EVM_CHAINS,Object.defineProperty(exports,"ValidationError",{enumerable:!0,get:function(){return d.ValidationError}}),exports.TronValidator=l.TronValidator,exports.CosmosValidator=c.CosmosValidator,exports.AptosValidator=u.AptosValidator,exports.SuiValidator=u.SuiValidator,exports.NearValidator=p.NearValidator,exports.addChecksum=V.addChecksum,exports.normalizeAddress=V.normalizeAddress,exports.shortenAddress=V.shortenAddress,exports.PolygonValidator=m,exports.SUPPORTED_CHAINS=x,exports.detectBlockchain=function(e,r){let t;try{t=d.InputSanitizer.sanitize(e)}catch{return null}if(!t)return null;const a=[];A("ethereum").validate(t,r).valid&&a.push(...d.EVM_CHAINS);for(const e of x)d.EVM_CHAINS.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(t)||/^[0-9a-f]{64}$/.test(t)||/^0[xs][0-9a-f]{40}$/.test(t)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t))&&A(e).validate(t,r).valid&&a.push(e);return 0===a.length?null:1===a.length?a[0]:a},exports.formatAddress=function(e,r,t){return A(r).format(e,t)},exports.isSupportedChain=function(e){return"string"==typeof e&&h.has(e)},exports.validateAddress=function(e,r,t){return A(r).validate(e,t)},exports.validateBatch=function(e,r,t){const a=A(r);return Array.from(e,e=>a.validate(e,t))};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const t=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var n;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(n||(n={}));class r{static sanitize(t){if(null==t)throw new Error(n.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(n.UNSAFE_INPUT);if(t.length>256)throw new Error(n.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(n.UNSAFE_INPUT);return t.trim()}}class s{validate(t,e){try{const s=r.sanitize(t),i=this.validateImplementation(s,e),a=i.details?.network;return i.valid&&a&&(e?.network&&"auto"!==e.network&&e.network!==a||!1===e?.allowTestnet&&"testnet"===a)?{valid:!1,error:"Address network does not match the requested network",details:{...i.details,errorCode:n.NETWORK_MISMATCH}}:i}catch(t){const e=t instanceof Error?t.message:String(t);return e===n.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:n.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:n.INVALID_FORMAT}}}}format(t,e){return i(t,e)}}function i(t,e,n=4){const s=r.sanitize(t);if(!e?.shorten)return s;const i=e.shortenLength??n;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const a=s.startsWith("0x")?2:0;return s.length<=2*i+a+3?s:`${s.slice(0,i+a)}...${s.slice(-i)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function o(t){return t.startsWith("0x")?t:`0x${t}`}const l=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],d=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function h(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&l}function u(t){const e=new Array(5),n=new Array(25);for(const r of d){for(let n=0;n<5;n++)e[n]=t[n]^t[n+5]^t[n+10]^t[n+15]^t[n+20];for(let n=0;n<5;n++){const r=e[(n+4)%5]^h(e[(n+1)%5],1);for(let e=0;e<5;e++)t[n+5*e]^=r}for(let e=0;e<5;e++)for(let r=0;r<5;r++)n[r+(2*e+3*r)%5*5]=h(t[e+5*r],c[e+5*r]);for(let e=0;e<5;e++)for(let r=0;r<5;r++)t[e+5*r]=n[e+5*r]^~n[(e+1)%5+5*r]&n[(e+2)%5+5*r];t[0]^=r}}class f extends s{validateImplementation(t,e){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:n.INVALID_CHARACTERS}};if(!e?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:n.BURN_ADDRESS}};const s=this.isChecksummed(r);return(e?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:n.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,e){let n=o(r.sanitize(t));return e?.checksum&&(n=this.toChecksumAddress(n)),i(n,e)}isChecksummed(t){const e=a(t);return o(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(136*(Math.floor(e.length/136)+1));n.set(e),n[e.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let t=0;t<n.length;t+=136){for(let e=0;e<136;e++)r[e>>3]^=BigInt(n[t+e])<<BigInt(8*(7&e));u(r)}let s="";for(let t=0;t<32;t++)s+=Number(r[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return s}(e);return"0x"+[...e].map((t,e)=>parseInt(n[e],16)>=8?t.toUpperCase():t).join("")}}const v="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",m=v.charAt(0),I={};for(let t=0;t<58;t++)I[v.charAt(t)]=t;function g(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===m;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],s=I[n];if(void 0===s)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=s;let i=0;for(let t=0;t<r.length;++t)r[t]+=i,i=r[t]>>8,r[t]&=255;for(;i;)r.push(255&i),i>>=8}const s=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...s])}class p extends s{validateImplementation(t){if(t.length<32||t.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};try{if(32!==g(t).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:n.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:n.INVALID_FORMAT}}}return"11111111111111111111111111111111"===t?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function A(t){const e=[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],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,s=t.length,i=new Uint8Array(64-(s+8)%64+8);i[0]=128;const a=r,o=Math.floor(a/4294967296),l=a%4294967296,c=i.length;i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=255&l,i[c-8]=o>>>24&255,i[c-7]=o>>>16&255,i[c-6]=o>>>8&255,i[c-5]=255&o;const d=new Uint8Array(s+i.length);d.set(t),d.set(i,s);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=w(h[t-2],17)^w(h[t-2],19)^h[t-2]>>>10,n=w(h[t-15],7)^w(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+n+h[t-16]|0}let r=n[0],s=n[1],i=n[2],a=n[3],o=n[4],l=n[5],c=n[6],u=n[7];for(let t=0;t<64;t++){const n=u+(w(o,6)^w(o,11)^w(o,25))+(o&l^~o&c)+e[t]+h[t]|0,d=r&s^r&i^s&i;u=c,c=l,l=o,o=a+n|0,a=i,i=s,s=r,r=n+((w(r,2)^w(r,13)^w(r,22))+d|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+s|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+o|0,n[5]=n[5]+l|0,n[6]=n[6]+c|0,n[7]=n[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=n[t]>>>24&255,u[4*t+1]=n[t]>>>16&255,u[4*t+2]=n[t]>>>8&255,u[4*t+3]=255&n[t];return u}function w(t,e){return t>>>e|t<<32-e}function C(t){try{const e=g(t);if(e.length<5)return null;const n=e.slice(0,-4),r=A(A(n));return e.slice(-4).every((t,e)=>t===r[e])?n:null}catch{return null}}var x;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(x||(x={}));const N=[996825010,642813549,513874426,1027748829,705979059];function E(t,e,n){const r=n===x.BECH32M?734539939:1;return function(t){let e=1;for(const n of t){const t=e>>25;e=(33554431&e)<<5^n;for(let n=0;n<5;n++)t>>n&1&&(e^=N[n])}return e}(function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n)>>5);e.push(0);for(let n=0;n<t.length;n++)e.push(31&t.charCodeAt(n));return e}(t).concat(e))===r}function k(t,e=90){if(t.length<8||t.length>e)return null;const n=t.toLowerCase();if(t!==n&&t!==t.toUpperCase())return null;const r=n.lastIndexOf("1");if(r<1||r+7>n.length)return null;const s=n.substring(0,r);if(/[^\x21-\x7E]/.test(s))return null;const i=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;i.push(e)}return E(s,i,x.BECH32)?{hrp:s,data:i.slice(0,i.length-6),encoding:x.BECH32}:E(s,i,x.BECH32M)?{hrp:s,data:i.slice(0,i.length-6),encoding:x.BECH32M}:null}function b(t){let e=0,n=0;const r=[];for(const s of t){if(!Number.isInteger(s)||s<0||s>31)return null;e=65535&(e<<5|s),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}class L extends s{constructor(t){super(),this.config=t}validateImplementation(t){const e=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(t,this.config.hrps[e]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",n.INVALID_LENGTH);const r=C(t);if(!r)return this.invalid("Invalid Base58Check address",n.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",n.INVALID_LENGTH);const s=this.config.versions[r[0]];return s?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:s,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(t,e){const r=k(t);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const s=r.data[0],i=b(r.data.slice(1));if(s>16)return this.invalid("Invalid witness version");if(!i||i.length<2||i.length>40||0===s&&20!==i.length&&32!==i.length)return this.invalid("Invalid witness program or padding",n.INVALID_LENGTH);const a=0===s?x.BECH32:x.BECH32M;if(r.encoding!==a)return this.invalid("Wrong checksum encoding for witness version",n.INVALID_CHECKSUM);const o=0===s?"segwit":1===s&&32===i.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:o,network:e,checksum:!0}}}invalid(t,e=n.INVALID_FORMAT){return{valid:!1,error:t,details:{errorCode:e}}}}class T extends L{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class y extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="polygon"),n}}class _ extends L{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class U extends L{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class D{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<r;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class R extends s{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new D(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new D(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const i=new Set;let a="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=r.bytes();if(1===t){const t=new D(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new D(e);t.head(0),t.end(),a="testnet"}}const o=r.head(0);return 0!==o&&2!==o?null:(r.end(),a)}catch{return null}}(g(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=k(t,256),n=e&&b(e.data);if(!e||e.encoding!==x.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,s=15&n[0];if(0!==s&&1!==s)return this.invalid();const i=14===r||15===r,a=(i?"stake":"addr")+(0===s?"_test":"");if(e.hrp!==a)return this.invalid();let o=!1;return r<=3?o=57===n.length:6===r||7===r||i?o=29===n.length:4!==r&&5!==r||(o=this.validPointer(n)),o?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===s?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let n=0n;const r=e;do{if(e>=t.length||e-r>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-r>1&&128===t[r]||n>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:n.INVALID_FORMAT}}}format(t,e){return i(t,e,8)}}const S="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",H=S.charAt(0),M={};for(let t=0;t<58;t++)M[S.charAt(t)]=t;class B extends s{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:n.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===H;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],s=M[n];if(void 0===s)throw new Error(`Invalid Ripple Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=s;let i=0;for(let t=0;t<r.length;++t)r[t]+=i,i=r[t]>>8,r[t]&=255;for(;i;)r.push(255&i),i>>=8}let s=[];t.length!==n&&(s=r.reverse());for(let t=0;t<n;t++)s.unshift(0);return new Uint8Array(s)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:n.INVALID_LENGTH}};const r=e.slice(0,21),s=e.slice(21),i=A(r),a=A(i);return a[0]!==s[0]||a[1]!==s[1]||a[2]!==s[2]||a[3]!==s[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:n.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:n.INVALID_CHARACTERS}}}}}class V extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="bsc"),n}}class O extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="avalanche"),n}}class F extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="arbitrum"),n}}class $ extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="optimism"),n}}class z extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="base"),n}}class P extends f{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain=this.chain),n}}class j extends s{validateImplementation(t){if(/^41[0-9a-fA-F]{40}$/.test(t))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const e=34===t.length&&t.startsWith("T")?C(t):null;return e&&21===e.length&&65===e[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:n.INVALID_FORMAT}}}}const W={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class G extends s{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(t){const e=k(t),r=e&&b(e.data),s="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===W[this.chain]&&e.encoding===x.BECH32&&r&&s.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:n.INVALID_FORMAT}}}}class K extends s{validateImplementation(t){return/^0x[0-9a-fA-F]{64}$/.test(t)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:n.INVALID_FORMAT}}}}class q extends s{validateImplementation(t,e){const r=/^0x[0-9a-fA-F]{64}$/.test(t),s=/^0x[0-9a-f]$/.test(t),i=s||/^0x[0-9a-f]{64}$/.test(t)&&!/^0x0{63}[0-9a-f]$/.test(t);return(e?.strict?i:r||s)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:n.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let n=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(n)&&(n="0x"+n.slice(-1)),i(n,e)}}class J extends s{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:n.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}const Q=new Map;for(const e of t)Q.set(e,"ethereum"===e?new f:new P(e));for(const t of e)Q.set(t,new G(t));Q.set("bitcoin",new T),Q.set("litecoin",new _),Q.set("dogecoin",new U),Q.set("solana",new p),Q.set("ripple",new B),Q.set("cardano",new R),Q.set("tron",new j),Q.set("sui",new K),Q.set("aptos",new q),Q.set("near",new J);const X=Object.freeze([...Q.keys()]);function Y(t){return"string"==typeof t&&Q.has(t)}function Z(t){const e=Q.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}function tt(e,n){let s;try{s=r.sanitize(e)}catch{return null}if(!s)return null;const i=[];Z("ethereum").validate(s,n).valid&&i.push(...t);for(const e of X)t.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(s)||/^[0-9a-f]{64}$/.test(s)||/^0[xs][0-9a-f]{40}$/.test(s)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(s))&&Z(e).validate(s,n).valid&&i.push(e);return 0===i.length?null:1===i.length?i[0]:i}function et(t,e=4){return i(t,{shorten:!0,shortenLength:e})}function nt(e,n){const s=r.sanitize(e);return t.includes(n)||"sui"===n||"aptos"===n?s.toLowerCase():s}function rt(e,n){return t.includes(n)?(new f).format(e,{checksum:!0}):r.sanitize(e)}function st(t,e,n){return Z(e).validate(t,n)}function it(t,e,n){const r=Z(e);return t.map(t=>r.validate(t,n))}function at(t,e,n){return Z(e).format(t,n)}export{s as AddressValidator,q as AptosValidator,F as ArbitrumValidator,O as AvalancheValidator,z as BaseValidator,T as BitcoinValidator,V as BscValidator,e as COSMOS_CHAINS,R as CardanoValidator,G as CosmosValidator,U as DogecoinValidator,t as EVM_CHAINS,f as EthereumValidator,P as EvmValidator,_ as LitecoinValidator,J as NearValidator,$ as OptimismValidator,y as PolygonValidator,B as RippleValidator,X as SUPPORTED_CHAINS,p as SolanaValidator,K as SuiValidator,j as TronValidator,n as ValidationError,rt as addChecksum,tt as detectBlockchain,at as formatAddress,Y as isSupportedChain,nt as normalizeAddress,et as shortenAddress,st as validateAddress,it as validateBatch};
1
+ import{EthereumValidator as t}from"./ethereum.mjs";import{SolanaValidator as e}from"./solana.mjs";import{BitcoinValidator as r}from"./bitcoin.mjs";import{LitecoinValidator as o}from"./litecoin.mjs";import{DogecoinValidator as s}from"./dogecoin.mjs";import{CardanoValidator as n}from"./cardano.mjs";import{RippleValidator as a}from"./ripple.mjs";import{EvmValidator as m}from"./evm.mjs";export{ArbitrumValidator,AvalancheValidator,BaseValidator,BscValidator,OptimismValidator}from"./evm.mjs";import{E as i,C as l,I as c}from"./shared/base-D2s8b6tx.mjs";export{A as AddressValidator,V as ValidationError}from"./shared/base-D2s8b6tx.mjs";import{TronValidator as p}from"./tron.mjs";import{CosmosValidator as d}from"./cosmos.mjs";import{SuiValidator as f,AptosValidator as u}from"./move.mjs";import{NearValidator as h}from"./near.mjs";export{addChecksum,normalizeAddress,shortenAddress}from"./formatters.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/utxo-CRr3-5en.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class j extends t{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}}const w=new Map;for(const e of i)w.set(e,"ethereum"===e?new t:new m(e));for(const t of l)w.set(t,new d(t));w.set("bitcoin",new r),w.set("litecoin",new o),w.set("dogecoin",new s),w.set("solana",new e),w.set("ripple",new a),w.set("cardano",new n),w.set("tron",new p),w.set("sui",new f),w.set("aptos",new u),w.set("near",new h);const v=Object.freeze([...w.keys()]);function b(t){return"string"==typeof t&&w.has(t)}function g(t){const e=w.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}function x(t,e){let r;try{r=c.sanitize(t)}catch{return null}if(!r)return null;const o=[];g("ethereum").validate(r,e).valid&&o.push(...i);for(const t of v)i.includes(t)||("near"!==t||/(\.near|\.testnet)$/.test(r)||/^[0-9a-f]{64}$/.test(r)||/^0[xs][0-9a-f]{40}$/.test(r)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(r))&&g(t).validate(r,e).valid&&o.push(t);return 0===o.length?null:1===o.length?o[0]:o}function k(t,e,r){return g(e).validate(t,r)}function y(t,e,r){const o=g(e);return Array.from(t,t=>o.validate(t,r))}function $(t,e,r){return g(e).format(t,r)}export{u as AptosValidator,r as BitcoinValidator,l as COSMOS_CHAINS,n as CardanoValidator,d as CosmosValidator,s as DogecoinValidator,i as EVM_CHAINS,t as EthereumValidator,m as EvmValidator,o as LitecoinValidator,h as NearValidator,j as PolygonValidator,a as RippleValidator,v as SUPPORTED_CHAINS,e as SolanaValidator,f as SuiValidator,p as TronValidator,x as detectBlockchain,$ as formatAddress,b as isSupportedChain,k as validateAddress,y as validateBatch};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).validator0x={})}(this,function(t){"use strict";const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),n=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;t.ValidationError=void 0,(r=t.ValidationError||(t.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH";class i{static sanitize(e){if(null==e)throw new Error(t.ValidationError.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.ValidationError.UNSAFE_INPUT);if(e.length>256)throw new Error(t.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.ValidationError.UNSAFE_INPUT);return e.trim()}}class a{validate(e,n){try{const r=i.sanitize(e),a=this.validateImplementation(r,n),o=a.details?.network;return a.valid&&o&&(n?.network&&"auto"!==n.network&&n.network!==o||!1===n?.allowTestnet&&"testnet"===o)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:t.ValidationError.NETWORK_MISMATCH}}:a}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}format(t,e){return o(t,e)}}function o(t,e,n=4){const r=i.sanitize(t);if(!e?.shorten)return r;const a=e.shortenLength??n;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const o=r.startsWith("0x")?2:0;return r.length<=2*a+o+3?r:`${r.slice(0,a+o)}...${r.slice(-a)}`}function s(t){return t.startsWith("0x")?t.slice(2):t}function l(t){return t.startsWith("0x")?t:`0x${t}`}const c=(1n<<64n)-1n,d=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],h=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function u(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&c}function f(t){const e=new Array(5),n=new Array(25);for(const r of h){for(let n=0;n<5;n++)e[n]=t[n]^t[n+5]^t[n+10]^t[n+15]^t[n+20];for(let n=0;n<5;n++){const r=e[(n+4)%5]^u(e[(n+1)%5],1);for(let e=0;e<5;e++)t[n+5*e]^=r}for(let e=0;e<5;e++)for(let r=0;r<5;r++)n[r+(2*e+3*r)%5*5]=u(t[e+5*r],d[e+5*r]);for(let e=0;e<5;e++)for(let r=0;r<5;r++)t[e+5*r]=n[e+5*r]^~n[(e+1)%5+5*r]&n[(e+2)%5+5*r];t[0]^=r}}class m extends a{validateImplementation(e,n){const r=s(e);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:t.ValidationError.BURN_ADDRESS}};const i=this.isChecksummed(r);return(n?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!i?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:i}}}format(t,e){let n=l(i.sanitize(t));return e?.checksum&&(n=this.toChecksumAddress(n)),o(n,e)}isChecksummed(t){const e=s(t);return l(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=s(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(136*(Math.floor(e.length/136)+1));n.set(e),n[e.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let t=0;t<n.length;t+=136){for(let e=0;e<136;e++)r[e>>3]^=BigInt(n[t+e])<<BigInt(8*(7&e));f(r)}let i="";for(let t=0;t<32;t++)i+=Number(r[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return i}(e);return"0x"+[...e].map((t,e)=>parseInt(n[e],16)>=8?t.toUpperCase():t).join("")}}const v="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",I=v.charAt(0),g={};for(let t=0;t<58;t++)g[v.charAt(t)]=t;function p(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===I;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=g[n];if(void 0===i)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}const i=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...i])}class A extends a{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{if(32!==p(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:t.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function E(t){const e=[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],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,a=new Uint8Array(64-(i+8)%64+8);a[0]=128;const o=r,s=Math.floor(o/4294967296),l=o%4294967296,c=a.length;a[c-4]=l>>>24&255,a[c-3]=l>>>16&255,a[c-2]=l>>>8&255,a[c-1]=255&l,a[c-8]=s>>>24&255,a[c-7]=s>>>16&255,a[c-6]=s>>>8&255,a[c-5]=255&s;const d=new Uint8Array(i+a.length);d.set(t),d.set(a,i);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=w(h[t-2],17)^w(h[t-2],19)^h[t-2]>>>10,n=w(h[t-15],7)^w(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+n+h[t-16]|0}let r=n[0],i=n[1],a=n[2],o=n[3],s=n[4],l=n[5],c=n[6],u=n[7];for(let t=0;t<64;t++){const n=u+(w(s,6)^w(s,11)^w(s,25))+(s&l^~s&c)+e[t]+h[t]|0,d=r&i^r&a^i&a;u=c,c=l,l=s,s=o+n|0,o=a,a=i,i=r,r=n+((w(r,2)^w(r,13)^w(r,22))+d|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+a|0,n[3]=n[3]+o|0,n[4]=n[4]+s|0,n[5]=n[5]+l|0,n[6]=n[6]+c|0,n[7]=n[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=n[t]>>>24&255,u[4*t+1]=n[t]>>>16&255,u[4*t+2]=n[t]>>>8&255,u[4*t+3]=255&n[t];return u}function w(t,e){return t>>>e|t<<32-e}function C(t){try{const e=p(t);if(e.length<5)return null;const n=e.slice(0,-4),r=E(E(n));return e.slice(-4).every((t,e)=>t===r[e])?n:null}catch{return null}}var V;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(V||(V={}));const x=[996825010,642813549,513874426,1027748829,705979059];function N(t,e,n){const r=n===V.BECH32M?734539939:1;return function(t){let e=1;for(const n of t){const t=e>>25;e=(33554431&e)<<5^n;for(let n=0;n<5;n++)t>>n&1&&(e^=x[n])}return e}(function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n)>>5);e.push(0);for(let n=0;n<t.length;n++)e.push(31&t.charCodeAt(n));return e}(t).concat(e))===r}function k(t,e=90){if(t.length<8||t.length>e)return null;const n=t.toLowerCase();if(t!==n&&t!==t.toUpperCase())return null;const r=n.lastIndexOf("1");if(r<1||r+7>n.length)return null;const i=n.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const a=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;a.push(e)}return N(i,a,V.BECH32)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32}:N(i,a,V.BECH32M)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32M}:null}function b(t){let e=0,n=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;e=65535&(e<<5|i),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}class y extends a{constructor(t){super(),this.config=t}validateImplementation(e){const n=e.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,n))return this.validateWitness(e,this.config.hrps[n]);if(e.length<26||e.length>35)return this.invalid("Invalid address length",t.ValidationError.INVALID_LENGTH);const r=C(e);if(!r)return this.invalid("Invalid Base58Check address",t.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.ValidationError.INVALID_LENGTH);const i=this.config.versions[r[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,n){const r=k(e);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],a=b(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===i&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",t.ValidationError.INVALID_LENGTH);const o=0===i?V.BECH32:V.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",t.ValidationError.INVALID_CHECKSUM);const s=0===i?"segwit":1===i&&32===a.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:s,network:n,checksum:!0}}}invalid(e,n=t.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:n}}}}class T extends y{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class L extends y{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class _ extends y{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class S{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let i=0;for(let t=0;t<r;t++)i=256*i+this.data[this.offset++];return i}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class U extends a{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new S(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new S(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const i=r.head(5);if(i>n.length)return null;const a=new Set;let o="mainnet";for(let t=0;t<i;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new S(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new S(e);t.head(0),t.end(),o="testnet"}}const s=r.head(0);return 0!==s&&2!==s?null:(r.end(),o)}catch{return null}}(p(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=k(t,256),n=e&&b(e.data);if(!e||e.encoding!==V.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,i=15&n[0];if(0!==i&&1!==i)return this.invalid();const a=14===r||15===r,o=(a?"stake":"addr")+(0===i?"_test":"");if(e.hrp!==o)return this.invalid();let s=!1;return r<=3?s=57===n.length:6===r||7===r||a?s=29===n.length:4!==r&&5!==r||(s=this.validPointer(n)),s?{valid:!0,blockchain:"cardano",details:{format:a?"stake":"shelley",network:1===i?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let n=0n;const r=e;do{if(e>=t.length||e-r>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-r>1&&128===t[r]||n>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){return o(t,e,8)}}const D="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",R=D.charAt(0),H={};for(let t=0;t<58;t++)H[D.charAt(t)]=t;class B extends a{validateImplementation(e){if(!e.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:t.ValidationError.INVALID_FORMAT}};if(e.length<25||e.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{const n=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===R;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=H[n];if(void 0===i)throw new Error(`Invalid Ripple Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}let i=[];t.length!==n&&(i=r.reverse());for(let t=0;t<n;t++)i.unshift(0);return new Uint8Array(i)}(e);if(25!==n.length||0!==n[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};const r=n.slice(0,21),i=n.slice(21),a=E(r),o=E(a);return o[0]!==i[0]||o[1]!==i[1]||o[2]!==i[2]||o[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}}}}}class M extends m{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain=this.chain),n}}class O extends a{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const n=34===e.length&&e.startsWith("T")?C(e):null;return n&&21===n.length&&65===n[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}const F={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class $ extends a{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(e){const n=k(e),r=n&&b(n.data),i="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return n&&n.hrp===F[this.chain]&&n.encoding===V.BECH32&&r&&i.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class P extends a{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class z extends a{validateImplementation(e,n){const r=/^0x[0-9a-fA-F]{64}$/.test(e),i=/^0x[0-9a-f]$/.test(e),a=i||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(n?.strict?a:r||i)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let n=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(n)&&(n="0x"+n.slice(-1)),o(n,e)}}class j extends a{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}const W=new Map;for(const t of e)W.set(t,"ethereum"===t?new m:new M(t));for(const t of n)W.set(t,new $(t));W.set("bitcoin",new T),W.set("litecoin",new L),W.set("dogecoin",new _),W.set("solana",new A),W.set("ripple",new B),W.set("cardano",new U),W.set("tron",new O),W.set("sui",new P),W.set("aptos",new z),W.set("near",new j);const G=Object.freeze([...W.keys()]);function K(t){const e=W.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}t.AddressValidator=a,t.AptosValidator=z,t.ArbitrumValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="arbitrum"),n}},t.AvalancheValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="avalanche"),n}},t.BaseValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="base"),n}},t.BitcoinValidator=T,t.BscValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="bsc"),n}},t.COSMOS_CHAINS=n,t.CardanoValidator=U,t.CosmosValidator=$,t.DogecoinValidator=_,t.EVM_CHAINS=e,t.EthereumValidator=m,t.EvmValidator=M,t.LitecoinValidator=L,t.NearValidator=j,t.OptimismValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="optimism"),n}},t.PolygonValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="polygon"),n}},t.RippleValidator=B,t.SUPPORTED_CHAINS=G,t.SolanaValidator=A,t.SuiValidator=P,t.TronValidator=O,t.addChecksum=function(t,n){return e.includes(n)?(new m).format(t,{checksum:!0}):i.sanitize(t)},t.detectBlockchain=function(t,n){let r;try{r=i.sanitize(t)}catch{return null}if(!r)return null;const a=[];K("ethereum").validate(r,n).valid&&a.push(...e);for(const t of G)e.includes(t)||("near"!==t||/(\.near|\.testnet)$/.test(r)||/^[0-9a-f]{64}$/.test(r)||/^0[xs][0-9a-f]{40}$/.test(r)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(r))&&K(t).validate(r,n).valid&&a.push(t);return 0===a.length?null:1===a.length?a[0]:a},t.formatAddress=function(t,e,n){return K(e).format(t,n)},t.isSupportedChain=function(t){return"string"==typeof t&&W.has(t)},t.normalizeAddress=function(t,n){const r=i.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?r.toLowerCase():r},t.shortenAddress=function(t,e=4){return o(t,{shorten:!0,shortenLength:e})},t.validateAddress=function(t,e,n){return K(e).validate(t,n)},t.validateBatch=function(t,e,n){const r=K(e);return t.map(t=>r.validate(t,n))}});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).validator0x={})}(this,function(t){"use strict";const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),n=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;t.ValidationError=void 0,(r=t.ValidationError||(t.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH";class i{static sanitize(e){if(null==e)throw new Error(t.ValidationError.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.ValidationError.UNSAFE_INPUT);if(e.length>256)throw new Error(t.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.ValidationError.UNSAFE_INPUT);return e.trim()}}class a{validate(e,n){try{const r=i.sanitize(e),a=this.validateImplementation(r,n),o=a.details?.network;return a.valid&&o&&(n?.network&&"auto"!==n.network&&n.network!==o||!1===n?.allowTestnet&&"testnet"===o)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:t.ValidationError.NETWORK_MISMATCH}}:a}catch(e){const n=e instanceof Error?e.message:String(e);return n===t.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}format(t,e){return o(t,e)}}function o(t,e,n=4){const r=i.sanitize(t);if(!e?.shorten)return r;const a=e.shortenLength??n;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const o=r.startsWith("0x")?2:0;return r.length<=2*a+o+3?r:`${r.slice(0,a+o)}...${r.slice(-a)}`}function s(t){return t.startsWith("0x")?t.slice(2):t}function l(t){return t.startsWith("0x")?t:`0x${t}`}const c=(1n<<64n)-1n,d=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],h=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function u(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&c}function f(t){const e=new Array(5),n=new Array(25);for(const r of h){for(let n=0;n<5;n++)e[n]=t[n]^t[n+5]^t[n+10]^t[n+15]^t[n+20];for(let n=0;n<5;n++){const r=e[(n+4)%5]^u(e[(n+1)%5],1);for(let e=0;e<5;e++)t[n+5*e]^=r}for(let e=0;e<5;e++)for(let r=0;r<5;r++)n[r+(2*e+3*r)%5*5]=u(t[e+5*r],d[e+5*r]);for(let e=0;e<5;e++)for(let r=0;r<5;r++)t[e+5*r]=n[e+5*r]^~n[(e+1)%5+5*r]&n[(e+2)%5+5*r];t[0]^=r}}class m extends a{validateImplementation(e,n){const r=s(e);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:t.ValidationError.BURN_ADDRESS}};const i=this.isChecksummed(r);return(n?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!i?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:i}}}format(t,e){let n=l(i.sanitize(t));return e?.checksum&&(n=this.toChecksumAddress(n)),o(n,e)}isChecksummed(t){const e=s(t);return l(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=s(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(136*(Math.floor(e.length/136)+1));n.set(e),n[e.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let t=0;t<n.length;t+=136){for(let e=0;e<136;e++)r[e>>3]^=BigInt(n[t+e])<<BigInt(8*(7&e));f(r)}let i="";for(let t=0;t<32;t++)i+=Number(r[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return i}(e);return"0x"+[...e].map((t,e)=>parseInt(n[e],16)>=8?t.toUpperCase():t).join("")}}const v="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",I=v.charAt(0),g={};for(let t=0;t<58;t++)g[v.charAt(t)]=t;function p(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===I;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=g[n];if(void 0===i)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}const i=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...i])}class A extends a{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{if(32!==p(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:t.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function E(t){const e=[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],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,a=new Uint8Array(64-(i+8)%64+8);a[0]=128;const o=r,s=Math.floor(o/4294967296),l=o%4294967296,c=a.length;a[c-4]=l>>>24&255,a[c-3]=l>>>16&255,a[c-2]=l>>>8&255,a[c-1]=255&l,a[c-8]=s>>>24&255,a[c-7]=s>>>16&255,a[c-6]=s>>>8&255,a[c-5]=255&s;const d=new Uint8Array(i+a.length);d.set(t),d.set(a,i);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=w(h[t-2],17)^w(h[t-2],19)^h[t-2]>>>10,n=w(h[t-15],7)^w(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+n+h[t-16]|0}let r=n[0],i=n[1],a=n[2],o=n[3],s=n[4],l=n[5],c=n[6],u=n[7];for(let t=0;t<64;t++){const n=u+(w(s,6)^w(s,11)^w(s,25))+(s&l^~s&c)+e[t]+h[t]|0,d=r&i^r&a^i&a;u=c,c=l,l=s,s=o+n|0,o=a,a=i,i=r,r=n+((w(r,2)^w(r,13)^w(r,22))+d|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+a|0,n[3]=n[3]+o|0,n[4]=n[4]+s|0,n[5]=n[5]+l|0,n[6]=n[6]+c|0,n[7]=n[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=n[t]>>>24&255,u[4*t+1]=n[t]>>>16&255,u[4*t+2]=n[t]>>>8&255,u[4*t+3]=255&n[t];return u}function w(t,e){return t>>>e|t<<32-e}function C(t){try{const e=p(t);if(e.length<5)return null;const n=e.slice(0,-4),r=E(E(n));return e.slice(-4).every((t,e)=>t===r[e])?n:null}catch{return null}}var V;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(V||(V={}));const x=[996825010,642813549,513874426,1027748829,705979059];function N(t,e,n){const r=n===V.BECH32M?734539939:1;return function(t){let e=1;for(const n of t){const t=e>>25;e=(33554431&e)<<5^n;for(let n=0;n<5;n++)t>>n&1&&(e^=x[n])}return e}(function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n)>>5);e.push(0);for(let n=0;n<t.length;n++)e.push(31&t.charCodeAt(n));return e}(t).concat(e))===r}function k(t,e=90){if(t.length<8||t.length>e)return null;const n=t.toLowerCase();if(t!==n&&t!==t.toUpperCase())return null;const r=n.lastIndexOf("1");if(r<1||r+7>n.length)return null;const i=n.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const a=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;a.push(e)}return N(i,a,V.BECH32)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32}:N(i,a,V.BECH32M)?{hrp:i,data:a.slice(0,a.length-6),encoding:V.BECH32M}:null}function b(t){let e=0,n=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;e=65535&(e<<5|i),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}class y extends a{constructor(t){super(),this.config=t}validateImplementation(e){const n=e.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,n))return this.validateWitness(e,this.config.hrps[n]);if(e.length<26||e.length>35)return this.invalid("Invalid address length",t.ValidationError.INVALID_LENGTH);const r=C(e);if(!r)return this.invalid("Invalid Base58Check address",t.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.ValidationError.INVALID_LENGTH);const i=this.config.versions[r[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,n){const r=k(e);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],a=b(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===i&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",t.ValidationError.INVALID_LENGTH);const o=0===i?V.BECH32:V.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",t.ValidationError.INVALID_CHECKSUM);const s=0===i?"segwit":1===i&&32===a.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:s,network:n,checksum:!0}}}invalid(e,n=t.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:n}}}}class T extends y{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class L extends y{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class _ extends y{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class S{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let i=0;for(let t=0;t<r;t++)i=256*i+this.data[this.offset++];return i}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class U extends a{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new S(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new S(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const i=r.head(5);if(i>n.length)return null;const a=new Set;let o="mainnet";for(let t=0;t<i;t++){const t=r.head(0);if(a.has(t)||t>255)return null;a.add(t);const e=r.bytes();if(1===t){const t=new S(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new S(e);t.head(0),t.end(),o="testnet"}}const s=r.head(0);return 0!==s&&2!==s?null:(r.end(),o)}catch{return null}}(p(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=k(t,256),n=e&&b(e.data);if(!e||e.encoding!==V.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,i=15&n[0];if(0!==i&&1!==i)return this.invalid();const a=14===r||15===r,o=(a?"stake":"addr")+(0===i?"_test":"");if(e.hrp!==o)return this.invalid();let s=!1;return r<=3?s=57===n.length:6===r||7===r||a?s=29===n.length:4!==r&&5!==r||(s=this.validPointer(n)),s?{valid:!0,blockchain:"cardano",details:{format:a?"stake":"shelley",network:1===i?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let r=0n;const i=e;do{if(e>=t.length||e-i>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-i>1&&128===t[i]||r>(0===n?0xffffffffn:0xffffn))return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){return o(t,e,8)}}const R="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",D=R.charAt(0),H={};for(let t=0;t<58;t++)H[R.charAt(t)]=t;class B extends a{validateImplementation(e){if(!e.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:t.ValidationError.INVALID_FORMAT}};if(e.length<25||e.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};try{const n=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===D;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],i=H[n];if(void 0===i)throw new Error(`Invalid Ripple Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let a=0;for(let t=0;t<r.length;++t)r[t]+=a,a=r[t]>>8,r[t]&=255;for(;a;)r.push(255&a),a>>=8}let i=[];t.length!==n&&(i=r.reverse());for(let t=0;t<n;t++)i.unshift(0);return new Uint8Array(i)}(e);if(25!==n.length||0!==n[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:t.ValidationError.INVALID_LENGTH}};const r=n.slice(0,21),i=n.slice(21),a=E(r),o=E(a);return o[0]!==i[0]||o[1]!==i[1]||o[2]!==i[2]||o[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:t.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:t.ValidationError.INVALID_CHARACTERS}}}}}class M extends m{constructor(t="evm"){if(super(),this.chain=t,!e.includes(t))throw new RangeError(`Unsupported EVM chain: ${String(t)}`)}validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain=this.chain),n}}class O extends a{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const n=34===e.length&&e.startsWith("T")?C(e):null;return n&&21===n.length&&65===n[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}const $={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class F extends a{constructor(t="cosmos"){if(super(),this.chain=t,!n.includes(t))throw new RangeError(`Unsupported Cosmos chain: ${String(t)}`)}validateImplementation(e){const n=k(e),r=n&&b(n.data),i="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return n&&n.hrp===$[this.chain]&&n.encoding===V.BECH32&&r&&i.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class P extends a{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class z extends a{validateImplementation(e,n){const r=/^0x[0-9a-fA-F]{64}$/.test(e),i=/^0x[0-9a-f]$/.test(e),a=i||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(n?.strict?a:r||i)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let n=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(n)&&(n="0x"+n.slice(-1)),o(n,e)}}class j extends a{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}const W=new Map;for(const t of e)W.set(t,"ethereum"===t?new m:new M(t));for(const t of n)W.set(t,new F(t));W.set("bitcoin",new T),W.set("litecoin",new L),W.set("dogecoin",new _),W.set("solana",new A),W.set("ripple",new B),W.set("cardano",new U),W.set("tron",new O),W.set("sui",new P),W.set("aptos",new z),W.set("near",new j);const G=Object.freeze([...W.keys()]);function K(t){const e=W.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}t.AddressValidator=a,t.AptosValidator=z,t.ArbitrumValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="arbitrum"),n}},t.AvalancheValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="avalanche"),n}},t.BaseValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="base"),n}},t.BitcoinValidator=T,t.BscValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="bsc"),n}},t.COSMOS_CHAINS=n,t.CardanoValidator=U,t.CosmosValidator=F,t.DogecoinValidator=_,t.EVM_CHAINS=e,t.EthereumValidator=m,t.EvmValidator=M,t.LitecoinValidator=L,t.NearValidator=j,t.OptimismValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="optimism"),n}},t.PolygonValidator=class extends m{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="polygon"),n}},t.RippleValidator=B,t.SUPPORTED_CHAINS=G,t.SolanaValidator=A,t.SuiValidator=P,t.TronValidator=O,t.addChecksum=function(t,n){return e.includes(n)?(new m).format(t,{checksum:!0}):i.sanitize(t)},t.detectBlockchain=function(t,n){let r;try{r=i.sanitize(t)}catch{return null}if(!r)return null;const a=[];K("ethereum").validate(r,n).valid&&a.push(...e);for(const t of G)e.includes(t)||("near"!==t||/(\.near|\.testnet)$/.test(r)||/^[0-9a-f]{64}$/.test(r)||/^0[xs][0-9a-f]{40}$/.test(r)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(r))&&K(t).validate(r,n).valid&&a.push(t);return 0===a.length?null:1===a.length?a[0]:a},t.formatAddress=function(t,e,n){return K(e).format(t,n)},t.isSupportedChain=function(t){return"string"==typeof t&&W.has(t)},t.normalizeAddress=function(t,n){const r=i.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?r.toLowerCase():r},t.shortenAddress=function(t,e=4){return o(t,{shorten:!0,shortenLength:e})},t.validateAddress=function(t,e,n){return K(e).validate(t,n)},t.validateBatch=function(t,e,n){const r=K(e);return Array.from(t,t=>r.validate(t,n))}});
package/dist/litecoin.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),s=this.validateImplementation(i,r),o=s.details?.network;return s.valid&&o&&(r?.network&&"auto"!==r.network&&r.network!==o||!1===r?.allowTestnet&&"testnet"===o)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const s=e.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const o=i.startsWith("0x")?2:0;return i.length<=2*s+o+3?i:`${i.slice(0,s+o)}...${i.slice(-s)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),s={};for(let t=0;t<58;t++)s[r.charAt(t)]=t;function o(t){const n=[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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,s=new Uint8Array(64-(i+8)%64+8);s[0]=128;const o=r,a=Math.floor(o/4294967296),c=o%4294967296,h=s.length;s[h-4]=c>>>24&255,s[h-3]=c>>>16&255,s[h-2]=c>>>8&255,s[h-1]=255&c,s[h-8]=a>>>24&255,s[h-7]=a>>>16&255,s[h-6]=a>>>8&255,s[h-5]=255&a;const u=new Uint8Array(i+s.length);u.set(t),u.set(s,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],s=e[2],o=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&s^i&s;d=h,h=c,c=a,a=o+e|0,o=s,s=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|0)|0}e[0]=e[0]+r|0,e[1]=e[1]+i|0,e[2]=e[2]+s|0,e[3]=e[3]+o|0,e[4]=e[4]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=s[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let o=0;for(let t=0;t<r.length;++t)r[t]+=o,o=r[t]>>8,r[t]&=255;for(;o;)r.push(255&o),o>>=8}const o=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...o])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=o(o(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.INVALID_LENGTH);const i=this.config.versions[r[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const s=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;s.push(n)}return u(i,s,c.BECH32)?{hrp:i,data:s.slice(0,s.length-6),encoding:c.BECH32}:u(i,s,c.BECH32M)?{hrp:i,data:s.slice(0,s.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],s=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!s||s.length<2||s.length>40||0===i&&20!==s.length&&32!==s.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const o=0===i?c.BECH32:c.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===s.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}exports.LitecoinValidator=class extends f{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}};
1
+ "use strict";var e=require("./shared/utxo-DhlBlYDy.cjs");require("./shared/base-BtbJMDNm.cjs"),require("./shared/base58check-CE9wLmUB.cjs"),require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs"),require("./shared/bech32-ClvuyXIQ.cjs");class s extends e.UtxoValidator{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}exports.LitecoinValidator=s;
package/dist/litecoin.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class n{static sanitize(n){if(null==n)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof n)throw new Error(t.UNSAFE_INPUT);if(n.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(n))throw new Error(t.UNSAFE_INPUT);return n.trim()}}class e{validate(e,r){try{const i=n.sanitize(e),o=this.validateImplementation(i,r),s=o.details?.network;return o.valid&&s&&(r?.network&&"auto"!==r.network&&r.network!==s||!1===r?.allowTestnet&&"testnet"===s)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:t.NETWORK_MISMATCH}}:o}catch(n){const e=n instanceof Error?n.message:String(n);return e===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return function(t,e,r=4){const i=n.sanitize(t);if(!e?.shorten)return i;const o=e.shortenLength??r;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const s=i.startsWith("0x")?2:0;return i.length<=2*o+s+3?i:`${i.slice(0,o+s)}...${i.slice(-o)}`}(t,e)}}const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",i=r.charAt(0),o={};for(let t=0;t<58;t++)o[r.charAt(t)]=t;function s(t){const n=[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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,i=t.length,o=new Uint8Array(64-(i+8)%64+8);o[0]=128;const s=r,a=Math.floor(s/4294967296),c=s%4294967296,h=o.length;o[h-4]=c>>>24&255,o[h-3]=c>>>16&255,o[h-2]=c>>>8&255,o[h-1]=255&c,o[h-8]=a>>>24&255,o[h-7]=a>>>16&255,o[h-6]=a>>>8&255,o[h-5]=255&a;const u=new Uint8Array(i+o.length);u.set(t),u.set(o,i);const f=new Uint32Array(64);for(let t=0;t<u.length;t+=64){for(let n=0;n<16;n++)f[n]=u[t+4*n]<<24|u[t+4*n+1]<<16|u[t+4*n+2]<<8|u[t+4*n+3];for(let t=16;t<64;t++){const n=l(f[t-2],17)^l(f[t-2],19)^f[t-2]>>>10,e=l(f[t-15],7)^l(f[t-15],18)^f[t-15]>>>3;f[t]=n+f[t-7]+e+f[t-16]|0}let r=e[0],i=e[1],o=e[2],s=e[3],a=e[4],c=e[5],h=e[6],d=e[7];for(let t=0;t<64;t++){const e=d+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+n[t]+f[t]|0,u=r&i^r&o^i&o;d=h,h=c,c=a,a=s+e|0,s=o,o=i,i=r,r=e+((l(r,2)^l(r,13)^l(r,22))+u|0)|0}e[0]=e[0]+r|0,e[1]=e[1]+i|0,e[2]=e[2]+o|0,e[3]=e[3]+s|0,e[4]=e[4]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+h|0,e[7]=e[7]+d|0}const d=new Uint8Array(32);for(let t=0;t<8;t++)d[4*t]=e[t]>>>24&255,d[4*t+1]=e[t]>>>16&255,d[4*t+2]=e[t]>>>8&255,d[4*t+3]=255&e[t];return d}function l(t,n){return t>>>n|t<<32-n}function a(t){try{const n=function(t){if(0===t.length)return new Uint8Array(0);let n=0;for(;n<t.length&&t[n]===i;)n++;const e=n,r=[0];for(;n<t.length;n++){const e=t[n],i=o[e];if(void 0===i)throw new Error(`Invalid Base58 character: ${e}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=i;let s=0;for(let t=0;t<r.length;++t)r[t]+=s,s=r[t]>>8,r[t]&=255;for(;s;)r.push(255&s),s>>=8}const s=t.length===e?[]:r.reverse();return Uint8Array.from([...new Array(e).fill(0),...s])}(t);if(n.length<5)return null;const e=n.slice(0,-4),r=s(s(e));return n.slice(-4).every((t,n)=>t===r[n])?e:null}catch{return null}}var c;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(c||(c={}));const h=[996825010,642813549,513874426,1027748829,705979059];function u(t,n,e){const r=e===c.BECH32M?734539939:1;return function(t){let n=1;for(const e of t){const t=n>>25;n=(33554431&n)<<5^e;for(let e=0;e<5;e++)t>>e&1&&(n^=h[e])}return n}(function(t){const n=[];for(let e=0;e<t.length;e++)n.push(t.charCodeAt(e)>>5);n.push(0);for(let e=0;e<t.length;e++)n.push(31&t.charCodeAt(e));return n}(t).concat(n))===r}class f extends e{constructor(t){super(),this.config=t}validateImplementation(n){const e=n.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(n,this.config.hrps[e]);if(n.length<26||n.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const r=a(n);if(!r)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",t.INVALID_LENGTH);const i=this.config.versions[r[0]];return i?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:i,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(n,e){const r=function(t,n=90){if(t.length<8||t.length>n)return null;const e=t.toLowerCase();if(t!==e&&t!==t.toUpperCase())return null;const r=e.lastIndexOf("1");if(r<1||r+7>e.length)return null;const i=e.substring(0,r);if(/[^\x21-\x7E]/.test(i))return null;const o=[];for(let t=r+1;t<e.length;t++){const n="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===n)return null;o.push(n)}return u(i,o,c.BECH32)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32}:u(i,o,c.BECH32M)?{hrp:i,data:o.slice(0,o.length-6),encoding:c.BECH32M}:null}(n);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const i=r.data[0],o=function(t){let n=0,e=0;const r=[];for(const i of t){if(!Number.isInteger(i)||i<0||i>31)return null;n=65535&(n<<5|i),e+=5,e>=8&&(e-=8,r.push(n>>>e&255))}return e>=5||n<<8-e&255?null:Uint8Array.from(r)}(r.data.slice(1));if(i>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===i&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const s=0===i?c.BECH32:c.BECH32M;if(r.encoding!==s)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const l=0===i?"segwit":1===i&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:l,network:e,checksum:!0}}}invalid(n,e=t.INVALID_FORMAT){return{valid:!1,error:n,details:{errorCode:e}}}}class d extends f{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}export{d as LitecoinValidator};
1
+ import{U as t}from"./shared/utxo-CRr3-5en.mjs";import"./shared/base-D2s8b6tx.mjs";import"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";import"./shared/bech32-DsNhxmrB.mjs";class e extends t{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}export{e as LitecoinValidator};
package/dist/move.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,s){try{const a=e.sanitize(r),o=this.validateImplementation(a,s),i=o.details?.network;return o.valid&&i&&(s?.network&&"auto"!==s.network&&s.network!==i||!1===s?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:t.NETWORK_MISMATCH}}:o}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,e){return s(t,e)}}function s(t,r,s=4){const a=e.sanitize(t);if(!r?.shorten)return a;const o=r.shortenLength??s;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const i=a.startsWith("0x")?2:0;return a.length<=2*o+i+3?a:`${a.slice(0,o+i)}...${a.slice(-o)}`}exports.AptosValidator=class extends r{validateImplementation(e,r){const s=/^0x[0-9a-fA-F]{64}$/.test(e),a=/^0x[0-9a-f]$/.test(e),o=a||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(r?.strict?o:s||a)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let r=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),s(r,e)}},exports.SuiValidator=class extends r{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.INVALID_FORMAT}}}};
1
+ "use strict";var t=require("./shared/base-BtbJMDNm.cjs");class e extends t.AddressValidator{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}}class a extends t.AddressValidator{validateImplementation(e,a){const r=/^0x[0-9a-fA-F]{64}$/.test(e),s=/^0x[0-9a-f]$/.test(e),d=s||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(a?.strict?d:r||s)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.ValidationError.INVALID_FORMAT}}}format(e,a){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let r=e.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),t.formatPlainAddress(r,a)}}exports.AptosValidator=a,exports.SuiValidator=e;
package/dist/move.mjs CHANGED
@@ -1 +1 @@
1
- var e;!function(e){e.INVALID_FORMAT="INVALID_FORMAT",e.INVALID_CHECKSUM="INVALID_CHECKSUM",e.INVALID_LENGTH="INVALID_LENGTH",e.INVALID_CHARACTERS="INVALID_CHARACTERS",e.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",e.BURN_ADDRESS="BURN_ADDRESS",e.UNSAFE_INPUT="UNSAFE_INPUT",e.NETWORK_MISMATCH="NETWORK_MISMATCH"}(e||(e={}));class t{static sanitize(t){if(null==t)throw new Error(e.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(e.UNSAFE_INPUT);if(t.length>256)throw new Error(e.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(e.UNSAFE_INPUT);return t.trim()}}class r{validate(r,s){try{const a=t.sanitize(r),o=this.validateImplementation(a,s),i=o.details?.network;return o.valid&&i&&(s?.network&&"auto"!==s.network&&s.network!==i||!1===s?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:e.NETWORK_MISMATCH}}:o}catch(t){const r=t instanceof Error?t.message:String(t);return r===e.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:e.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:e.INVALID_FORMAT}}}}format(e,t){return s(e,t)}}function s(e,r,s=4){const a=t.sanitize(e);if(!r?.shorten)return a;const o=r.shortenLength??s;if(!Number.isSafeInteger(o)||o<1)throw new RangeError("shortenLength must be a positive integer");const i=a.startsWith("0x")?2:0;return a.length<=2*o+i+3?a:`${a.slice(0,o+i)}...${a.slice(-o)}`}class a extends r{validateImplementation(t){return/^0x[0-9a-fA-F]{64}$/.test(t)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:e.INVALID_FORMAT}}}}class o extends r{validateImplementation(t,r){const s=/^0x[0-9a-fA-F]{64}$/.test(t),a=/^0x[0-9a-f]$/.test(t),o=a||/^0x[0-9a-f]{64}$/.test(t)&&!/^0x0{63}[0-9a-f]$/.test(t);return(r?.strict?o:s||a)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:e.INVALID_FORMAT}}}format(e,t){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let r=e.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),s(r,t)}}export{o as AptosValidator,a as SuiValidator};
1
+ import{A as e,V as t,f as a}from"./shared/base-D2s8b6tx.mjs";class s extends e{validateImplementation(e){return/^0x[0-9a-fA-F]{64}$/.test(e)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:t.INVALID_FORMAT}}}}class r extends e{validateImplementation(e,a){const s=/^0x[0-9a-fA-F]{64}$/.test(e),r=/^0x[0-9a-f]$/.test(e),i=r||/^0x[0-9a-f]{64}$/.test(e)&&!/^0x0{63}[0-9a-f]$/.test(e);return(a?.strict?i:s||r)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:t.INVALID_FORMAT}}}format(e,t){if(!this.validate(e).valid)throw new Error("Invalid Aptos address");let s=e.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(s)&&(s="0x"+s.slice(-1)),a(s,t)}}export{r as AptosValidator,s as SuiValidator};
package/dist/near.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const i=e.sanitize(r),s=this.validateImplementation(i,n),a=s.details?.network;return s.valid&&a&&(n?.network&&"auto"!==n.network&&n.network!==a||!1===n?.allowTestnet&&"testnet"===a)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,r){return function(t,r,n=4){const i=e.sanitize(t);if(!r?.shorten)return i;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const a=i.startsWith("0x")?2:0;return i.length<=2*s+a+3?i:`${i.slice(0,s+a)}...${i.slice(-s)}`}(t,r)}}exports.NearValidator=class extends r{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}};
1
+ "use strict";var e=require("./shared/base-BtbJMDNm.cjs");class t extends e.AddressValidator{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:e.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}exports.NearValidator=t;
package/dist/near.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const i=e.sanitize(r),s=this.validateImplementation(i,n),a=s.details?.network;return s.valid&&a&&(n?.network&&"auto"!==n.network&&n.network!==a||!1===n?.allowTestnet&&"testnet"===a)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,r){return function(t,r,n=4){const i=e.sanitize(t);if(!r?.shorten)return i;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const a=i.startsWith("0x")?2:0;return i.length<=2*s+a+3?i:`${i.slice(0,s+a)}...${i.slice(-s)}`}(t,r)}}class n extends r{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}export{n as NearValidator};
1
+ import{A as e,V as t}from"./shared/base-D2s8b6tx.mjs";class a extends e{validateImplementation(e){if(e.length<2||e.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(e))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:t.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(e)||/^0x[0-9a-f]{40}$/.test(e)?"implicit":/^0s[0-9a-f]{40}$/.test(e)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(e)?"universal":"named",checksum:!1}}}}export{a as NearValidator};
package/dist/ripple.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var r;!function(r){r.INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class t{static sanitize(t){if(null==t)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(r.UNSAFE_INPUT);if(t.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(r.UNSAFE_INPUT);return t.trim()}}class e{validate(e,n){try{const o=t.sanitize(e),i=this.validateImplementation(o,n),s=i.details?.network;return i.valid&&s&&(n?.network&&"auto"!==n.network&&n.network!==s||!1===n?.allowTestnet&&"testnet"===s)?{valid:!1,error:"Address network does not match the requested network",details:{...i.details,errorCode:r.NETWORK_MISMATCH}}:i}catch(t){const e=t instanceof Error?t.message:String(t);return e===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:r.INVALID_FORMAT}}}}format(r,e){return function(r,e,n=4){const o=t.sanitize(r);if(!e?.shorten)return o;const i=e.shortenLength??n;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const s=o.startsWith("0x")?2:0;return o.length<=2*i+s+3?o:`${o.slice(0,i+s)}...${o.slice(-i)}`}(r,e)}}function n(r){const t=[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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*r.length,i=r.length,s=new Uint8Array(64-(i+8)%64+8);s[0]=128;const l=n,a=Math.floor(l/4294967296),c=l%4294967296,d=s.length;s[d-4]=c>>>24&255,s[d-3]=c>>>16&255,s[d-2]=c>>>8&255,s[d-1]=255&c,s[d-8]=a>>>24&255,s[d-7]=a>>>16&255,s[d-6]=a>>>8&255,s[d-5]=255&a;const A=new Uint8Array(i+s.length);A.set(r),A.set(s,i);const I=new Uint32Array(64);for(let r=0;r<A.length;r+=64){for(let t=0;t<16;t++)I[t]=A[r+4*t]<<24|A[r+4*t+1]<<16|A[r+4*t+2]<<8|A[r+4*t+3];for(let r=16;r<64;r++){const t=o(I[r-2],17)^o(I[r-2],19)^I[r-2]>>>10,e=o(I[r-15],7)^o(I[r-15],18)^I[r-15]>>>3;I[r]=t+I[r-7]+e+I[r-16]|0}let n=e[0],i=e[1],s=e[2],l=e[3],a=e[4],c=e[5],d=e[6],h=e[7];for(let r=0;r<64;r++){const e=h+(o(a,6)^o(a,11)^o(a,25))+(a&c^~a&d)+t[r]+I[r]|0,A=n&i^n&s^i&s;h=d,d=c,c=a,a=l+e|0,l=s,s=i,i=n,n=e+((o(n,2)^o(n,13)^o(n,22))+A|0)|0}e[0]=e[0]+n|0,e[1]=e[1]+i|0,e[2]=e[2]+s|0,e[3]=e[3]+l|0,e[4]=e[4]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+d|0,e[7]=e[7]+h|0}const h=new Uint8Array(32);for(let r=0;r<8;r++)h[4*r]=e[r]>>>24&255,h[4*r+1]=e[r]>>>16&255,h[4*r+2]=e[r]>>>8&255,h[4*r+3]=255&e[r];return h}function o(r,t){return r>>>t|r<<32-t}const i="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",s=i.charAt(0),l={};for(let r=0;r<58;r++)l[i.charAt(r)]=r;exports.RippleValidator=class extends e{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:r.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:r.INVALID_LENGTH}};try{const e=function(r){if(0===r.length)return new Uint8Array(0);let t=0;for(;t<r.length&&r[t]===s;)t++;const e=t,n=[0];for(;t<r.length;t++){const e=r[t],o=l[e];if(void 0===o)throw new Error(`Invalid Ripple Base58 character: ${e}`);for(let r=0;r<n.length;r++)n[r]*=58;n[0]+=o;let i=0;for(let r=0;r<n.length;++r)n[r]+=i,i=n[r]>>8,n[r]&=255;for(;i;)n.push(255&i),i>>=8}let o=[];r.length!==e&&(o=n.reverse());for(let r=0;r<e;r++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:r.INVALID_LENGTH}};const o=e.slice(0,21),i=e.slice(21),a=n(o),c=n(a);return c[0]!==i[0]||c[1]!==i[1]||c[2]!==i[2]||c[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:r.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:r.INVALID_CHARACTERS}}}}};
1
+ "use strict";var r=require("./shared/base-BtbJMDNm.cjs"),e=require("./shared/sha256-CRbh7pIK.cjs");const t="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",a=t.charAt(0),i={};for(let r=0;r<58;r++)i[t.charAt(r)]=r;class l extends r.AddressValidator{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:r.ValidationError.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{const l=function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===a;)e++;const t=e,l=[0];for(;e<r.length;e++){const t=r[e],a=i[t];if(void 0===a)throw new Error(`Invalid Ripple Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=a;let o=0;for(let r=0;r<l.length;++r)l[r]+=o,o=l[r]>>8,l[r]&=255;for(;o;)l.push(255&o),o>>=8}let o=[];r.length!==t&&(o=l.reverse());for(let r=0;r<t;r++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==l.length||0!==l[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};const o=l.slice(0,21),n=l.slice(21),d=e.sha256(o),s=e.sha256(d);return s[0]!==n[0]||s[1]!==n[1]||s[2]!==n[2]||s[3]!==n[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:r.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:r.ValidationError.INVALID_CHARACTERS}}}}}exports.RippleValidator=l;
package/dist/ripple.mjs CHANGED
@@ -1 +1 @@
1
- var r;!function(r){r.INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class t{static sanitize(t){if(null==t)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(r.UNSAFE_INPUT);if(t.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(r.UNSAFE_INPUT);return t.trim()}}class e{validate(e,n){try{const o=t.sanitize(e),i=this.validateImplementation(o,n),l=i.details?.network;return i.valid&&l&&(n?.network&&"auto"!==n.network&&n.network!==l||!1===n?.allowTestnet&&"testnet"===l)?{valid:!1,error:"Address network does not match the requested network",details:{...i.details,errorCode:r.NETWORK_MISMATCH}}:i}catch(t){const e=t instanceof Error?t.message:String(t);return e===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:r.INVALID_FORMAT}}}}format(r,e){return function(r,e,n=4){const o=t.sanitize(r);if(!e?.shorten)return o;const i=e.shortenLength??n;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const l=o.startsWith("0x")?2:0;return o.length<=2*i+l+3?o:`${o.slice(0,i+l)}...${o.slice(-i)}`}(r,e)}}function n(r){const t=[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],e=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*r.length,i=r.length,l=new Uint8Array(64-(i+8)%64+8);l[0]=128;const s=n,a=Math.floor(s/4294967296),c=s%4294967296,A=l.length;l[A-4]=c>>>24&255,l[A-3]=c>>>16&255,l[A-2]=c>>>8&255,l[A-1]=255&c,l[A-8]=a>>>24&255,l[A-7]=a>>>16&255,l[A-6]=a>>>8&255,l[A-5]=255&a;const I=new Uint8Array(i+l.length);I.set(r),I.set(l,i);const d=new Uint32Array(64);for(let r=0;r<I.length;r+=64){for(let t=0;t<16;t++)d[t]=I[r+4*t]<<24|I[r+4*t+1]<<16|I[r+4*t+2]<<8|I[r+4*t+3];for(let r=16;r<64;r++){const t=o(d[r-2],17)^o(d[r-2],19)^d[r-2]>>>10,e=o(d[r-15],7)^o(d[r-15],18)^d[r-15]>>>3;d[r]=t+d[r-7]+e+d[r-16]|0}let n=e[0],i=e[1],l=e[2],s=e[3],a=e[4],c=e[5],A=e[6],h=e[7];for(let r=0;r<64;r++){const e=h+(o(a,6)^o(a,11)^o(a,25))+(a&c^~a&A)+t[r]+d[r]|0,I=n&i^n&l^i&l;h=A,A=c,c=a,a=s+e|0,s=l,l=i,i=n,n=e+((o(n,2)^o(n,13)^o(n,22))+I|0)|0}e[0]=e[0]+n|0,e[1]=e[1]+i|0,e[2]=e[2]+l|0,e[3]=e[3]+s|0,e[4]=e[4]+a|0,e[5]=e[5]+c|0,e[6]=e[6]+A|0,e[7]=e[7]+h|0}const h=new Uint8Array(32);for(let r=0;r<8;r++)h[4*r]=e[r]>>>24&255,h[4*r+1]=e[r]>>>16&255,h[4*r+2]=e[r]>>>8&255,h[4*r+3]=255&e[r];return h}function o(r,t){return r>>>t|r<<32-t}const i="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",l=i.charAt(0),s={};for(let r=0;r<58;r++)s[i.charAt(r)]=r;class a extends e{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:r.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:r.INVALID_LENGTH}};try{const e=function(r){if(0===r.length)return new Uint8Array(0);let t=0;for(;t<r.length&&r[t]===l;)t++;const e=t,n=[0];for(;t<r.length;t++){const e=r[t],o=s[e];if(void 0===o)throw new Error(`Invalid Ripple Base58 character: ${e}`);for(let r=0;r<n.length;r++)n[r]*=58;n[0]+=o;let i=0;for(let r=0;r<n.length;++r)n[r]+=i,i=n[r]>>8,n[r]&=255;for(;i;)n.push(255&i),i>>=8}let o=[];r.length!==e&&(o=n.reverse());for(let r=0;r<e;r++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:r.INVALID_LENGTH}};const o=e.slice(0,21),i=e.slice(21),a=n(o),c=n(a);return c[0]!==i[0]||c[1]!==i[1]||c[2]!==i[2]||c[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:r.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:r.INVALID_CHARACTERS}}}}}export{a as RippleValidator};
1
+ import{A as r,V as e}from"./shared/base-D2s8b6tx.mjs";import{s as t}from"./shared/sha256-BbwKo1_x.mjs";const l="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",a=l.charAt(0),n={};for(let r=0;r<58;r++)n[l.charAt(r)]=r;class o extends r{validateImplementation(r){if(!r.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:e.INVALID_FORMAT}};if(r.length<25||r.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const l=function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===a;)e++;const t=e,l=[0];for(;e<r.length;e++){const t=r[e],a=n[t];if(void 0===a)throw new Error(`Invalid Ripple Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=a;let o=0;for(let r=0;r<l.length;++r)l[r]+=o,o=l[r]>>8,l[r]&=255;for(;o;)l.push(255&o),o>>=8}let o=[];r.length!==t&&(o=l.reverse());for(let r=0;r<t;r++)o.unshift(0);return new Uint8Array(o)}(r);if(25!==l.length||0!==l[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const o=l.slice(0,21),i=l.slice(21),s=t(o),d=t(s);return d[0]!==i[0]||d[1]!==i[1]||d[2]!==i[2]||d[3]!==i[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:e.INVALID_CHARACTERS}}}}}export{o as RippleValidator};
@@ -0,0 +1 @@
1
+ "use strict";const r=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var t;exports.ValidationError=void 0,(t=exports.ValidationError||(exports.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH";class o{static sanitize(r){if(null==r)throw new Error(exports.ValidationError.UNSAFE_INPUT);if("string"!=typeof r)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(r.length>256)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(r))throw new Error(exports.ValidationError.UNSAFE_INPUT);return r.trim()}}function s(r,e,t=4){const s=o.sanitize(r);if(!e?.shorten)return s;const i=e.shortenLength??t;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const n=s.startsWith("0x")?2:0;return s.length<=2*i+n+3?s:`${s.slice(0,i+n)}...${s.slice(-i)}`}exports.AddressValidator=class{validate(r,e){try{const t=o.sanitize(r),s=this.validateImplementation(t,e),i=s.details?.network;return s.valid&&i&&(e?.network&&"auto"!==e.network&&e.network!==i||!1===e?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:exports.ValidationError.NETWORK_MISMATCH}}:s}catch(r){const e=r instanceof Error?r.message:String(r);return e===exports.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:exports.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}format(r,e){return s(r,e)}},exports.COSMOS_CHAINS=e,exports.EVM_CHAINS=r,exports.InputSanitizer=o,exports.formatPlainAddress=s;
@@ -0,0 +1 @@
1
+ const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),t=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;!function(e){e.INVALID_FORMAT="INVALID_FORMAT",e.INVALID_CHECKSUM="INVALID_CHECKSUM",e.INVALID_LENGTH="INVALID_LENGTH",e.INVALID_CHARACTERS="INVALID_CHARACTERS",e.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",e.BURN_ADDRESS="BURN_ADDRESS",e.UNSAFE_INPUT="UNSAFE_INPUT",e.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class o{static sanitize(e){if(null==e)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(r.UNSAFE_INPUT);if(e.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(r.UNSAFE_INPUT);return e.trim()}}class n{validate(e,t){try{const n=o.sanitize(e),s=this.validateImplementation(n,t),i=s.details?.network;return s.valid&&i&&(t?.network&&"auto"!==t.network&&t.network!==i||!1===t?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:r.NETWORK_MISMATCH}}:s}catch(e){const t=e instanceof Error?e.message:String(e);return t===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:t,details:{errorCode:r.INVALID_FORMAT}}}}format(e,t){return s(e,t)}}function s(e,t,r=4){const n=o.sanitize(e);if(!t?.shorten)return n;const s=t.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=n.startsWith("0x")?2:0;return n.length<=2*s+i+3?n:`${n.slice(0,s+i)}...${n.slice(-s)}`}export{n as A,t as C,e as E,o as I,r as V,s as f};
@@ -0,0 +1 @@
1
+ const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t=r.charAt(0),e={};for(let t=0;t<58;t++)e[r.charAt(t)]=t;function n(r){if(0===r.length)return new Uint8Array(0);let n=0;for(;n<r.length&&r[n]===t;)n++;const o=n,l=[0];for(;n<r.length;n++){const t=r[n],o=e[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=o;let f=0;for(let r=0;r<l.length;++r)l[r]+=f,f=l[r]>>8,l[r]&=255;for(;f;)l.push(255&f),f>>=8}const f=r.length===o?[]:l.reverse();return Uint8Array.from([...new Array(o).fill(0),...f])}export{n as d};
@@ -0,0 +1 @@
1
+ "use strict";const r="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",t=r.charAt(0),e={};for(let t=0;t<58;t++)e[r.charAt(t)]=t;exports.decodeBase58=function(r){if(0===r.length)return new Uint8Array(0);let n=0;for(;n<r.length&&r[n]===t;)n++;const o=n,l=[0];for(;n<r.length;n++){const t=r[n],o=e[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<l.length;r++)l[r]*=58;l[0]+=o;let c=0;for(let r=0;r<l.length;++r)l[r]+=c,c=l[r]>>8,l[r]&=255;for(;c;)l.push(255&c),c>>=8}const c=r.length===o?[]:l.reverse();return Uint8Array.from([...new Array(o).fill(0),...c])};
@@ -0,0 +1 @@
1
+ import{d as r}from"./base58-CjvbdRzA.mjs";import{s}from"./sha256-BbwKo1_x.mjs";function t(t){try{const n=r(t);if(n.length<5)return null;const e=n.slice(0,-4),l=s(s(e));return n.slice(-4).every((r,s)=>r===l[s])?e:null}catch{return null}}export{t as d};
@@ -0,0 +1 @@
1
+ "use strict";var e=require("./base58-DaLDoaS-.cjs"),r=require("./sha256-CRbh7pIK.cjs");exports.decodeBase58Check=function(s){try{const c=e.decodeBase58(s);if(c.length<5)return null;const t=c.slice(0,-4),n=r.sha256(r.sha256(t));return c.slice(-4).every((e,r)=>e===n[r])?t:null}catch{return null}};
@@ -0,0 +1 @@
1
+ "use strict";var n;exports.Bech32Encoding=void 0,(n=exports.Bech32Encoding||(exports.Bech32Encoding={})).BECH32="bech32",n.BECH32M="bech32m";const t=[996825010,642813549,513874426,1027748829,705979059];function e(n,e,o){const r=o===exports.Bech32Encoding.BECH32M?734539939:1;return function(n){let e=1;for(const o of n){const n=e>>25;e=(33554431&e)<<5^o;for(let o=0;o<5;o++)n>>o&1&&(e^=t[o])}return e}(function(n){const t=[];for(let e=0;e<n.length;e++)t.push(n.charCodeAt(e)>>5);t.push(0);for(let e=0;e<n.length;e++)t.push(31&n.charCodeAt(e));return t}(n).concat(e))===r}exports.decodeBech32=function(n,t=90){if(n.length<8||n.length>t)return null;const o=n.toLowerCase();if(n!==o&&n!==n.toUpperCase())return null;const r=o.lastIndexOf("1");if(r<1||r+7>o.length)return null;const c=o.substring(0,r);if(/[^\x21-\x7E]/.test(c))return null;const s=[];for(let n=r+1;n<o.length;n++){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(o[n]);if(-1===t)return null;s.push(t)}return e(c,s,exports.Bech32Encoding.BECH32)?{hrp:c,data:s.slice(0,s.length-6),encoding:exports.Bech32Encoding.BECH32}:e(c,s,exports.Bech32Encoding.BECH32M)?{hrp:c,data:s.slice(0,s.length-6),encoding:exports.Bech32Encoding.BECH32M}:null},exports.wordsToBytes=function(n){let t=0,e=0;const o=[];for(const r of n){if(!Number.isInteger(r)||r<0||r>31)return null;t=65535&(t<<5|r),e+=5,e>=8&&(e-=8,o.push(t>>>e&255))}return e>=5||t<<8-e&255?null:Uint8Array.from(o)};
@@ -0,0 +1 @@
1
+ var n;!function(n){n.BECH32="bech32",n.BECH32M="bech32m"}(n||(n={}));const t=[996825010,642813549,513874426,1027748829,705979059];function e(e,r,o){const l=o===n.BECH32M?734539939:1;return function(n){let e=1;for(const r of n){const n=e>>25;e=(33554431&e)<<5^r;for(let r=0;r<5;r++)n>>r&1&&(e^=t[r])}return e}(function(n){const t=[];for(let e=0;e<n.length;e++)t.push(n.charCodeAt(e)>>5);t.push(0);for(let e=0;e<n.length;e++)t.push(31&n.charCodeAt(e));return t}(e).concat(r))===l}function r(t,r=90){if(t.length<8||t.length>r)return null;const o=t.toLowerCase();if(t!==o&&t!==t.toUpperCase())return null;const l=o.lastIndexOf("1");if(l<1||l+7>o.length)return null;const u=o.substring(0,l);if(/[^\x21-\x7E]/.test(u))return null;const s=[];for(let n=l+1;n<o.length;n++){const t="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(o[n]);if(-1===t)return null;s.push(t)}return e(u,s,n.BECH32)?{hrp:u,data:s.slice(0,s.length-6),encoding:n.BECH32}:e(u,s,n.BECH32M)?{hrp:u,data:s.slice(0,s.length-6),encoding:n.BECH32M}:null}function o(n){let t=0,e=0;const r=[];for(const o of n){if(!Number.isInteger(o)||o<0||o>31)return null;t=65535&(t<<5|o),e+=5,e>=8&&(e-=8,r.push(t>>>e&255))}return e>=5||t<<8-e&255?null:Uint8Array.from(r)}export{n as B,r as d,o as w};
@@ -0,0 +1 @@
1
+ function t(t){const e=[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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],o=8*t.length,l=t.length,s=new Uint8Array(64-(l+8)%64+8);s[0]=128;const c=o,f=Math.floor(c/4294967296),a=c%4294967296,h=s.length;s[h-4]=a>>>24&255,s[h-3]=a>>>16&255,s[h-2]=a>>>8&255,s[h-1]=255&a,s[h-8]=f>>>24&255,s[h-7]=f>>>16&255,s[h-6]=f>>>8&255,s[h-5]=255&f;const i=new Uint8Array(l+s.length);i.set(t),i.set(s,l);const g=new Uint32Array(64);for(let t=0;t<i.length;t+=64){for(let n=0;n<16;n++)g[n]=i[t+4*n]<<24|i[t+4*n+1]<<16|i[t+4*n+2]<<8|i[t+4*n+3];for(let t=16;t<64;t++){const e=n(g[t-2],17)^n(g[t-2],19)^g[t-2]>>>10,r=n(g[t-15],7)^n(g[t-15],18)^g[t-15]>>>3;g[t]=e+g[t-7]+r+g[t-16]|0}let o=r[0],l=r[1],s=r[2],c=r[3],f=r[4],a=r[5],h=r[6],u=r[7];for(let t=0;t<64;t++){const r=u+(n(f,6)^n(f,11)^n(f,25))+(f&a^~f&h)+e[t]+g[t]|0,i=o&l^o&s^l&s;u=h,h=a,a=f,f=c+r|0,c=s,s=l,l=o,o=r+((n(o,2)^n(o,13)^n(o,22))+i|0)|0}r[0]=r[0]+o|0,r[1]=r[1]+l|0,r[2]=r[2]+s|0,r[3]=r[3]+c|0,r[4]=r[4]+f|0,r[5]=r[5]+a|0,r[6]=r[6]+h|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u}function n(t,n){return t>>>n|t<<32-n}export{t as s};
@@ -0,0 +1 @@
1
+ "use strict";function t(t,n){return t>>>n|t<<32-n}exports.sha256=function(n){const e=[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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],o=8*n.length,s=n.length,l=new Uint8Array(64-(s+8)%64+8);l[0]=128;const c=o,f=Math.floor(c/4294967296),h=c%4294967296,i=l.length;l[i-4]=h>>>24&255,l[i-3]=h>>>16&255,l[i-2]=h>>>8&255,l[i-1]=255&h,l[i-8]=f>>>24&255,l[i-7]=f>>>16&255,l[i-6]=f>>>8&255,l[i-5]=255&f;const a=new Uint8Array(s+l.length);a.set(n),a.set(l,s);const g=new Uint32Array(64);for(let n=0;n<a.length;n+=64){for(let t=0;t<16;t++)g[t]=a[n+4*t]<<24|a[n+4*t+1]<<16|a[n+4*t+2]<<8|a[n+4*t+3];for(let n=16;n<64;n++){const e=t(g[n-2],17)^t(g[n-2],19)^g[n-2]>>>10,r=t(g[n-15],7)^t(g[n-15],18)^g[n-15]>>>3;g[n]=e+g[n-7]+r+g[n-16]|0}let o=r[0],s=r[1],l=r[2],c=r[3],f=r[4],h=r[5],i=r[6],u=r[7];for(let n=0;n<64;n++){const r=u+(t(f,6)^t(f,11)^t(f,25))+(f&h^~f&i)+e[n]+g[n]|0,a=o&s^o&l^s&l;u=i,i=h,h=f,f=c+r|0,c=l,l=s,s=o,o=r+((t(o,2)^t(o,13)^t(o,22))+a|0)|0}r[0]=r[0]+o|0,r[1]=r[1]+s|0,r[2]=r[2]+l|0,r[3]=r[3]+c|0,r[4]=r[4]+f|0,r[5]=r[5]+h|0,r[6]=r[6]+i|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u};
@@ -0,0 +1 @@
1
+ import{A as i,V as t}from"./base-D2s8b6tx.mjs";import{d as n}from"./base58check-BBzwHAsr.mjs";import{d as s,w as e,B as a}from"./bech32-DsNhxmrB.mjs";class r extends i{constructor(i){super(),this.config=i}validateImplementation(i){const s=i.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,s))return this.validateWitness(i,this.config.hrps[s]);if(i.length<26||i.length>35)return this.invalid("Invalid address length",t.INVALID_LENGTH);const e=n(i);if(!e)return this.invalid("Invalid Base58Check address",t.INVALID_CHECKSUM);if(21!==e.length)return this.invalid("Invalid payload length",t.INVALID_LENGTH);const a=this.config.versions[e[0]];return a?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:a,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(i,n){const r=s(i);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const o=r.data[0],l=e(r.data.slice(1));if(o>16)return this.invalid("Invalid witness version");if(!l||l.length<2||l.length>40||0===o&&20!==l.length&&32!==l.length)return this.invalid("Invalid witness program or padding",t.INVALID_LENGTH);const d=0===o?a.BECH32:a.BECH32M;if(r.encoding!==d)return this.invalid("Wrong checksum encoding for witness version",t.INVALID_CHECKSUM);const h=0===o?"segwit":1===o&&32===l.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:h,network:n,checksum:!0}}}invalid(i,n=t.INVALID_FORMAT){return{valid:!1,error:i,details:{errorCode:n}}}}export{r as U};
@@ -0,0 +1 @@
1
+ "use strict";var i=require("./base-BtbJMDNm.cjs"),e=require("./base58check-CE9wLmUB.cjs"),t=require("./bech32-ClvuyXIQ.cjs");class n extends i.AddressValidator{constructor(i){super(),this.config=i}validateImplementation(t){const n=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,n))return this.validateWitness(t,this.config.hrps[n]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",i.ValidationError.INVALID_LENGTH);const r=e.decodeBase58Check(t);if(!r)return this.invalid("Invalid Base58Check address",i.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",i.ValidationError.INVALID_LENGTH);const s=this.config.versions[r[0]];return s?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:s,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(e,n){const r=t.decodeBech32(e);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const s=r.data[0],a=t.wordsToBytes(r.data.slice(1));if(s>16)return this.invalid("Invalid witness version");if(!a||a.length<2||a.length>40||0===s&&20!==a.length&&32!==a.length)return this.invalid("Invalid witness program or padding",i.ValidationError.INVALID_LENGTH);const o=0===s?t.Bech32Encoding.BECH32:t.Bech32Encoding.BECH32M;if(r.encoding!==o)return this.invalid("Wrong checksum encoding for witness version",i.ValidationError.INVALID_CHECKSUM);const d=0===s?"segwit":1===s&&32===a.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:d,network:n,checksum:!0}}}invalid(e,t=i.ValidationError.INVALID_FORMAT){return{valid:!1,error:e,details:{errorCode:t}}}}exports.UtxoValidator=n;
package/dist/solana.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var r;!function(r){r.INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class e{static sanitize(e){if(null==e)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(r.UNSAFE_INPUT);if(e.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(r.UNSAFE_INPUT);return e.trim()}}class t{validate(t,n){try{const o=e.sanitize(t),a=this.validateImplementation(o,n),i=a.details?.network;return a.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:r.NETWORK_MISMATCH}}:a}catch(e){const t=e instanceof Error?e.message:String(e);return t===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:t,details:{errorCode:r.INVALID_FORMAT}}}}format(r,t){return function(r,t,n=4){const o=e.sanitize(r);if(!t?.shorten)return o;const a=t.shortenLength??n;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*a+i+3?o:`${o.slice(0,a+i)}...${o.slice(-a)}`}(r,t)}}const n="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=n.charAt(0),a={};for(let r=0;r<58;r++)a[n.charAt(r)]=r;exports.SolanaValidator=class extends t{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:r.INVALID_LENGTH}};try{if(32!==function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===o;)e++;const t=e,n=[0];for(;e<r.length;e++){const t=r[e],o=a[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<n.length;r++)n[r]*=58;n[0]+=o;let i=0;for(let r=0;r<n.length;++r)n[r]+=i,i=n[r]>>8,n[r]&=255;for(;i;)n.push(255&i),i>>=8}const i=r.length===t?[]:n.reverse();return Uint8Array.from([...new Array(t).fill(0),...i])}(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:r.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:r.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}};
1
+ "use strict";var r=require("./shared/base-BtbJMDNm.cjs"),a=require("./shared/base58-DaLDoaS-.cjs");class e extends r.AddressValidator{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:r.ValidationError.INVALID_LENGTH}};try{if(32!==a.decodeBase58(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:r.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:r.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}exports.SolanaValidator=e;
package/dist/solana.mjs CHANGED
@@ -1 +1 @@
1
- var r;!function(r){r.INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH"}(r||(r={}));class e{static sanitize(e){if(null==e)throw new Error(r.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(r.UNSAFE_INPUT);if(e.length>256)throw new Error(r.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(r.UNSAFE_INPUT);return e.trim()}}class t{validate(t,n){try{const o=e.sanitize(t),a=this.validateImplementation(o,n),i=a.details?.network;return a.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...a.details,errorCode:r.NETWORK_MISMATCH}}:a}catch(e){const t=e instanceof Error?e.message:String(e);return t===r.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:r.UNSAFE_INPUT}}:{valid:!1,error:t,details:{errorCode:r.INVALID_FORMAT}}}}format(r,t){return function(r,t,n=4){const o=e.sanitize(r);if(!t?.shorten)return o;const a=t.shortenLength??n;if(!Number.isSafeInteger(a)||a<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*a+i+3?o:`${o.slice(0,a+i)}...${o.slice(-a)}`}(r,t)}}const n="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=n.charAt(0),a={};for(let r=0;r<58;r++)a[n.charAt(r)]=r;class i extends t{validateImplementation(e){if(e.length<32||e.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:r.INVALID_LENGTH}};try{if(32!==function(r){if(0===r.length)return new Uint8Array(0);let e=0;for(;e<r.length&&r[e]===o;)e++;const t=e,n=[0];for(;e<r.length;e++){const t=r[e],o=a[t];if(void 0===o)throw new Error(`Invalid Base58 character: ${t}`);for(let r=0;r<n.length;r++)n[r]*=58;n[0]+=o;let i=0;for(let r=0;r<n.length;++r)n[r]+=i,i=n[r]>>8,n[r]&=255;for(;i;)n.push(255&i),i>>=8}const i=r.length===t?[]:n.reverse();return Uint8Array.from([...new Array(t).fill(0),...i])}(e).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:r.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:r.INVALID_FORMAT}}}return"11111111111111111111111111111111"===e?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}export{i as SolanaValidator};
1
+ import{A as r,V as e}from"./shared/base-D2s8b6tx.mjs";import{d as a}from"./shared/base58-CjvbdRzA.mjs";class l extends r{validateImplementation(r){if(r.length<32||r.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{if(32!==a(r).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:e.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:e.INVALID_FORMAT}}}return"11111111111111111111111111111111"===r?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}export{l as SolanaValidator};
package/dist/tron.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const o=e.sanitize(r),s=this.validateImplementation(o,n),i=s.details?.network;return s.valid&&i&&(n?.network&&"auto"!==n.network&&n.network!==i||!1===n?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,r){return function(t,r,n=4){const o=e.sanitize(t);if(!r?.shorten)return o;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const i=o.startsWith("0x")?2:0;return o.length<=2*s+i+3?o:`${o.slice(0,s+i)}...${o.slice(-s)}`}(t,r)}}const n="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=n.charAt(0),s={};for(let t=0;t<58;t++)s[n.charAt(t)]=t;function i(t){const e=[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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*t.length,o=t.length,s=new Uint8Array(64-(o+8)%64+8);s[0]=128;const i=n,a=Math.floor(i/4294967296),c=i%4294967296,h=s.length;s[h-4]=c>>>24&255,s[h-3]=c>>>16&255,s[h-2]=c>>>8&255,s[h-1]=255&c,s[h-8]=a>>>24&255,s[h-7]=a>>>16&255,s[h-6]=a>>>8&255,s[h-5]=255&a;const A=new Uint8Array(o+s.length);A.set(t),A.set(s,o);const N=new Uint32Array(64);for(let t=0;t<A.length;t+=64){for(let e=0;e<16;e++)N[e]=A[t+4*e]<<24|A[t+4*e+1]<<16|A[t+4*e+2]<<8|A[t+4*e+3];for(let t=16;t<64;t++){const e=l(N[t-2],17)^l(N[t-2],19)^N[t-2]>>>10,r=l(N[t-15],7)^l(N[t-15],18)^N[t-15]>>>3;N[t]=e+N[t-7]+r+N[t-16]|0}let n=r[0],o=r[1],s=r[2],i=r[3],a=r[4],c=r[5],h=r[6],f=r[7];for(let t=0;t<64;t++){const r=f+(l(a,6)^l(a,11)^l(a,25))+(a&c^~a&h)+e[t]+N[t]|0,A=n&o^n&s^o&s;f=h,h=c,c=a,a=i+r|0,i=s,s=o,o=n,n=r+((l(n,2)^l(n,13)^l(n,22))+A|0)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+s|0,r[3]=r[3]+i|0,r[4]=r[4]+a|0,r[5]=r[5]+c|0,r[6]=r[6]+h|0,r[7]=r[7]+f|0}const f=new Uint8Array(32);for(let t=0;t<8;t++)f[4*t]=r[t]>>>24&255,f[4*t+1]=r[t]>>>16&255,f[4*t+2]=r[t]>>>8&255,f[4*t+3]=255&r[t];return f}function l(t,e){return t>>>e|t<<32-e}function a(t){try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===o;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=s[r];if(void 0===o)throw new Error(`Invalid Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let i=0;for(let t=0;t<n.length;++t)n[t]+=i,i=n[t]>>8,n[t]&=255;for(;i;)n.push(255&i),i>>=8}const i=t.length===r?[]:n.reverse();return Uint8Array.from([...new Array(r).fill(0),...i])}(t);if(e.length<5)return null;const r=e.slice(0,-4),n=i(i(r));return e.slice(-4).every((t,e)=>t===n[e])?r:null}catch{return null}}exports.TronValidator=class extends r{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?a(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.INVALID_FORMAT}}}};
1
+ "use strict";var e=require("./shared/base-BtbJMDNm.cjs"),r=require("./shared/base58check-CE9wLmUB.cjs");require("./shared/base58-DaLDoaS-.cjs"),require("./shared/sha256-CRbh7pIK.cjs");class a extends e.AddressValidator{validateImplementation(a){if(/^41[0-9a-fA-F]{40}$/.test(a))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const s=34===a.length&&a.startsWith("T")?r.decodeBase58Check(a):null;return s&&21===s.length&&65===s[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:e.ValidationError.INVALID_FORMAT}}}}exports.TronValidator=a;
package/dist/tron.mjs CHANGED
@@ -1 +1 @@
1
- var t;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(t||(t={}));class e{static sanitize(e){if(null==e)throw new Error(t.UNSAFE_INPUT);if("string"!=typeof e)throw new Error(t.UNSAFE_INPUT);if(e.length>256)throw new Error(t.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(e))throw new Error(t.UNSAFE_INPUT);return e.trim()}}class r{validate(r,n){try{const o=e.sanitize(r),s=this.validateImplementation(o,n),l=s.details?.network;return s.valid&&l&&(n?.network&&"auto"!==n.network&&n.network!==l||!1===n?.allowTestnet&&"testnet"===l)?{valid:!1,error:"Address network does not match the requested network",details:{...s.details,errorCode:t.NETWORK_MISMATCH}}:s}catch(e){const r=e instanceof Error?e.message:String(e);return r===t.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:t.UNSAFE_INPUT}}:{valid:!1,error:r,details:{errorCode:t.INVALID_FORMAT}}}}format(t,r){return function(t,r,n=4){const o=e.sanitize(t);if(!r?.shorten)return o;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const l=o.startsWith("0x")?2:0;return o.length<=2*s+l+3?o:`${o.slice(0,s+l)}...${o.slice(-s)}`}(t,r)}}const n="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",o=n.charAt(0),s={};for(let t=0;t<58;t++)s[n.charAt(t)]=t;function l(t){const e=[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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*t.length,o=t.length,s=new Uint8Array(64-(o+8)%64+8);s[0]=128;const l=n,a=Math.floor(l/4294967296),c=l%4294967296,h=s.length;s[h-4]=c>>>24&255,s[h-3]=c>>>16&255,s[h-2]=c>>>8&255,s[h-1]=255&c,s[h-8]=a>>>24&255,s[h-7]=a>>>16&255,s[h-6]=a>>>8&255,s[h-5]=255&a;const A=new Uint8Array(o+s.length);A.set(t),A.set(s,o);const N=new Uint32Array(64);for(let t=0;t<A.length;t+=64){for(let e=0;e<16;e++)N[e]=A[t+4*e]<<24|A[t+4*e+1]<<16|A[t+4*e+2]<<8|A[t+4*e+3];for(let t=16;t<64;t++){const e=i(N[t-2],17)^i(N[t-2],19)^N[t-2]>>>10,r=i(N[t-15],7)^i(N[t-15],18)^N[t-15]>>>3;N[t]=e+N[t-7]+r+N[t-16]|0}let n=r[0],o=r[1],s=r[2],l=r[3],a=r[4],c=r[5],h=r[6],f=r[7];for(let t=0;t<64;t++){const r=f+(i(a,6)^i(a,11)^i(a,25))+(a&c^~a&h)+e[t]+N[t]|0,A=n&o^n&s^o&s;f=h,h=c,c=a,a=l+r|0,l=s,s=o,o=n,n=r+((i(n,2)^i(n,13)^i(n,22))+A|0)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+s|0,r[3]=r[3]+l|0,r[4]=r[4]+a|0,r[5]=r[5]+c|0,r[6]=r[6]+h|0,r[7]=r[7]+f|0}const f=new Uint8Array(32);for(let t=0;t<8;t++)f[4*t]=r[t]>>>24&255,f[4*t+1]=r[t]>>>16&255,f[4*t+2]=r[t]>>>8&255,f[4*t+3]=255&r[t];return f}function i(t,e){return t>>>e|t<<32-e}function a(t){try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===o;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=s[r];if(void 0===o)throw new Error(`Invalid Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let l=0;for(let t=0;t<n.length;++t)n[t]+=l,l=n[t]>>8,n[t]&=255;for(;l;)n.push(255&l),l>>=8}const l=t.length===r?[]:n.reverse();return Uint8Array.from([...new Array(r).fill(0),...l])}(t);if(e.length<5)return null;const r=e.slice(0,-4),n=l(l(r));return e.slice(-4).every((t,e)=>t===n[e])?r:null}catch{return null}}class c extends r{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?a(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:t.INVALID_FORMAT}}}}export{c as TronValidator};
1
+ import{A as e,V as a}from"./shared/base-D2s8b6tx.mjs";import{d as s}from"./shared/base58check-BBzwHAsr.mjs";import"./shared/base58-CjvbdRzA.mjs";import"./shared/sha256-BbwKo1_x.mjs";class r extends e{validateImplementation(e){if(/^41[0-9a-fA-F]{40}$/.test(e))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const r=34===e.length&&e.startsWith("T")?s(e):null;return r&&21===r.length&&65===r[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:a.INVALID_FORMAT}}}}export{r as TronValidator};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validator0x",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Lightweight, zero-dependency wallet address validation for EVM, Bitcoin, Solana, TRON, Cosmos, Cardano, Sui, Aptos, NEAR and more.",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -61,21 +61,22 @@
61
61
  "author": "Samarth Patel",
62
62
  "license": "MIT",
63
63
  "devDependencies": {
64
+ "@eslint/js": "^10.0.1",
65
+ "@noble/hashes": "^2.4.0",
66
+ "@rollup/plugin-terser": "^1.0.2",
64
67
  "@rollup/plugin-typescript": "^12.3.1",
68
+ "@scure/base": "^2.4.0",
65
69
  "@types/node": "^22.0.0",
70
+ "@vitest/coverage-v8": "^5.1.0",
66
71
  "eslint": "^10.14.0",
72
+ "playwright-core": "^1.65.1",
67
73
  "prettier": "^3.10.1",
68
74
  "rollup": "^4.68.3",
75
+ "rollup-plugin-dts": "^6.5.1",
69
76
  "tslib": "^2.8.1",
70
77
  "typescript": "5.9.3",
71
- "@rollup/plugin-terser": "^1.0.2",
72
- "rollup-plugin-dts": "^6.5.1",
73
78
  "typescript-eslint": "^8.72.2",
74
- "@eslint/js": "^10.0.1",
75
- "@noble/hashes": "^2.4.0",
76
- "@scure/base": "^2.4.0",
77
- "vitest": "^5.1.0",
78
- "@vitest/coverage-v8": "^5.1.0"
79
+ "vitest": "^5.1.0"
79
80
  },
80
81
  "unpkg": "./dist/index.umd.js",
81
82
  "jsdelivr": "./dist/index.umd.js",