validator0x 0.2.0 → 0.3.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 (106) hide show
  1. package/AGENTS.md +65 -0
  2. package/CHANGELOG.md +34 -0
  3. package/README.md +193 -101
  4. package/dist/bitcoin.cjs +1 -0
  5. package/dist/bitcoin.d.cts +1 -0
  6. package/dist/bitcoin.d.mts +1 -0
  7. package/dist/bitcoin.mjs +1 -0
  8. package/dist/cardano.cjs +1 -0
  9. package/dist/cardano.d.cts +1 -0
  10. package/dist/cardano.d.mts +1 -0
  11. package/dist/cardano.mjs +1 -0
  12. package/dist/cosmos.cjs +1 -0
  13. package/dist/cosmos.d.cts +1 -0
  14. package/dist/cosmos.d.mts +1 -0
  15. package/dist/cosmos.mjs +1 -0
  16. package/dist/dogecoin.cjs +1 -0
  17. package/dist/dogecoin.d.cts +1 -0
  18. package/dist/dogecoin.d.mts +1 -0
  19. package/dist/dogecoin.mjs +1 -0
  20. package/dist/ethereum.cjs +1 -0
  21. package/dist/ethereum.d.cts +1 -0
  22. package/dist/ethereum.d.mts +1 -0
  23. package/dist/ethereum.mjs +1 -0
  24. package/dist/evm.cjs +1 -0
  25. package/dist/evm.d.cts +1 -0
  26. package/dist/evm.d.mts +1 -0
  27. package/dist/evm.mjs +1 -0
  28. package/dist/formatters.cjs +1 -0
  29. package/dist/formatters.d.cts +1 -0
  30. package/dist/formatters.d.mts +1 -0
  31. package/dist/formatters.mjs +1 -0
  32. package/dist/index.cjs +1 -0
  33. package/dist/index.d.cts +164 -0
  34. package/dist/index.d.mts +164 -0
  35. package/dist/index.mjs +1 -0
  36. package/dist/index.umd.js +1 -2
  37. package/dist/litecoin.cjs +1 -0
  38. package/dist/litecoin.d.cts +1 -0
  39. package/dist/litecoin.d.mts +1 -0
  40. package/dist/litecoin.mjs +1 -0
  41. package/dist/move.cjs +1 -0
  42. package/dist/move.d.cts +1 -0
  43. package/dist/move.d.mts +1 -0
  44. package/dist/move.mjs +1 -0
  45. package/dist/near.cjs +1 -0
  46. package/dist/near.d.cts +1 -0
  47. package/dist/near.d.mts +1 -0
  48. package/dist/near.mjs +1 -0
  49. package/dist/ripple.cjs +1 -0
  50. package/dist/ripple.d.cts +1 -0
  51. package/dist/ripple.d.mts +1 -0
  52. package/dist/ripple.mjs +1 -0
  53. package/dist/solana.cjs +1 -0
  54. package/dist/solana.d.cts +1 -0
  55. package/dist/solana.d.mts +1 -0
  56. package/dist/solana.mjs +1 -0
  57. package/dist/tron.cjs +1 -0
  58. package/dist/tron.d.cts +1 -0
  59. package/dist/tron.d.mts +1 -0
  60. package/dist/tron.mjs +1 -0
  61. package/package.json +244 -29
  62. package/dist/detectors/chain-detector.d.ts +0 -8
  63. package/dist/detectors/chain-detector.d.ts.map +0 -1
  64. package/dist/formatters/index.d.ts +0 -5
  65. package/dist/formatters/index.d.ts.map +0 -1
  66. package/dist/index.cjs.js +0 -2
  67. package/dist/index.cjs.js.map +0 -1
  68. package/dist/index.d.ts +0 -20
  69. package/dist/index.d.ts.map +0 -1
  70. package/dist/index.esm.js +0 -2
  71. package/dist/index.esm.js.map +0 -1
  72. package/dist/index.umd.js.map +0 -1
  73. package/dist/security/sanitizer.d.ts +0 -4
  74. package/dist/security/sanitizer.d.ts.map +0 -1
  75. package/dist/types.d.ts +0 -36
  76. package/dist/types.d.ts.map +0 -1
  77. package/dist/utils/base58.d.ts +0 -3
  78. package/dist/utils/base58.d.ts.map +0 -1
  79. package/dist/utils/bech32.d.ts +0 -12
  80. package/dist/utils/bech32.d.ts.map +0 -1
  81. package/dist/utils/hex.d.ts +0 -4
  82. package/dist/utils/hex.d.ts.map +0 -1
  83. package/dist/utils/keccak256.d.ts +0 -2
  84. package/dist/utils/keccak256.d.ts.map +0 -1
  85. package/dist/utils/sha256.d.ts +0 -2
  86. package/dist/utils/sha256.d.ts.map +0 -1
  87. package/dist/validators/base.d.ts +0 -12
  88. package/dist/validators/base.d.ts.map +0 -1
  89. package/dist/validators/bitcoin.d.ts +0 -9
  90. package/dist/validators/bitcoin.d.ts.map +0 -1
  91. package/dist/validators/cardano.d.ts +0 -9
  92. package/dist/validators/cardano.d.ts.map +0 -1
  93. package/dist/validators/dogecoin.d.ts +0 -7
  94. package/dist/validators/dogecoin.d.ts.map +0 -1
  95. package/dist/validators/ethereum.d.ts +0 -10
  96. package/dist/validators/ethereum.d.ts.map +0 -1
  97. package/dist/validators/evm.d.ts +0 -18
  98. package/dist/validators/evm.d.ts.map +0 -1
  99. package/dist/validators/litecoin.d.ts +0 -9
  100. package/dist/validators/litecoin.d.ts.map +0 -1
  101. package/dist/validators/polygon.d.ts +0 -6
  102. package/dist/validators/polygon.d.ts.map +0 -1
  103. package/dist/validators/ripple.d.ts +0 -7
  104. package/dist/validators/ripple.d.ts.map +0 -1
  105. package/dist/validators/solana.d.ts +0 -7
  106. package/dist/validators/solana.d.ts.map +0 -1
package/dist/index.umd.js CHANGED
@@ -1,2 +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";var e;!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"}(e||(e={}));class r{static sanitize(t){if(null==t)throw new Error(e.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(e.UNSAFE_INPUT);const r=t.trim();if(r.length>256)throw new Error(e.UNSAFE_INPUT);if(/[\x00-\x1F\x7F]/.test(r))throw new Error(e.UNSAFE_INPUT);return r}}class n{validate(t,n){try{const e=r.sanitize(t);return this.validateImplementation(e)}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}}}}function a(t){return t.startsWith("0x")?t.slice(2):t}function i(t){return t.startsWith("0x")?t:`0x${t}`}const o=function(){var t="input is invalid type",e="object"==typeof window,r=e?window:{};r.JS_SHA3_NO_WINDOW&&(e=!1);var n=!e&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=global:n&&(r=self),!r.JS_SHA3_NO_COMMON_JS&&"object"==typeof module&&module.exports,"function"==typeof define&&define.amd;for(var a=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,i="0123456789abcdef".split(""),o=[4,1024,262144,67108864],s=[0,8,16,24],l=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],d=[224,256,384,512],c=[128,256],h=["hex","buffer","arrayBuffer","array","digest"],u={128:168,256:136},f=r.JS_SHA3_NO_NODE_JS||!Array.isArray?function(t){return"[object Array]"===Object.prototype.toString.call(t)}:Array.isArray,v=!a||!r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView?ArrayBuffer.isView:function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer},p=function(e){var r=typeof e;if("string"===r)return[e,!0];if("object"!==r||null===e)throw new Error(t);if(a&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!f(e)&&!v(e))throw new Error(t);return[e,!1]},I=function(t){return 0===p(t)[0].length},A=function(t){for(var e=[],r=0;r<t.length;++r)e[r]=t[r];return e},g=function(t,e,r){return function(n){return new S(t,e,t).update(n)[r]()}},m=function(t,e,r){return function(n,a){return new S(t,e,a).update(n)[r]()}},C=function(t,e,r){return function(e,n,a,i){return b["cshake"+t].update(e,n,a,i)[r]()}},y=function(t,e,r){return function(e,n,a,i){return b["kmac"+t].update(e,n,a,i)[r]()}},N=function(t,e,r,n){for(var a=0;a<h.length;++a){var i=h[a];t[i]=e(r,n,i)}return t},w=function(t,e){var r=g(t,e,"hex");return r.create=function(){return new S(t,e,t)},r.update=function(t){return r.create().update(t)},N(r,g,t,e)},_=[{name:"keccak",padding:[1,256,65536,16777216],bits:d,createMethod:w},{name:"sha3",padding:[6,1536,393216,100663296],bits:d,createMethod:w},{name:"shake",padding:[31,7936,2031616,520093696],bits:c,createMethod:function(t,e){var r=m(t,e,"hex");return r.create=function(r){return new S(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},N(r,m,t,e)}},{name:"cshake",padding:o,bits:c,createMethod:function(t,e){var r=u[t],n=C(t,0,"hex");return n.create=function(n,a,i){return I(a)&&I(i)?b["shake"+t].create(n):new S(t,e,n).bytepad([a,i],r)},n.update=function(t,e,r,a){return n.create(e,r,a).update(t)},N(n,C,t,e)}},{name:"kmac",padding:o,bits:c,createMethod:function(t,e){var r=u[t],n=y(t,0,"hex");return n.create=function(n,a,i){return new U(t,e,a).bytepad(["KMAC",i],r).bytepad([n],r)},n.update=function(t,e,r,a){return n.create(t,r,a).update(e)},N(n,y,t,e)}}],b={},k=0;k<_.length;++k)for(var L=_[k],E=L.bits,B=0;B<E.length;++B){var V=L.name+"_"+E[B];if(b[V]=L.createMethod(E[B],L.padding),"sha3"!==L.name){var D=L.name+E[B];b[D]=b[V]}}function S(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function U(t,e,r){S.call(this,t,e,r)}S.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var e=p(t);t=e[0];for(var r,n,a=e[1],i=this.blocks,o=this.byteCount,l=t.length,d=this.blockCount,c=0,h=this.s;c<l;){if(this.reset)for(this.reset=!1,i[0]=this.block,r=1;r<d+1;++r)i[r]=0;if(a)for(r=this.start;c<l&&r<o;++c)(n=t.charCodeAt(c))<128?i[r>>2]|=n<<s[3&r++]:n<2048?(i[r>>2]|=(192|n>>6)<<s[3&r++],i[r>>2]|=(128|63&n)<<s[3&r++]):n<55296||n>=57344?(i[r>>2]|=(224|n>>12)<<s[3&r++],i[r>>2]|=(128|n>>6&63)<<s[3&r++],i[r>>2]|=(128|63&n)<<s[3&r++]):(n=65536+((1023&n)<<10|1023&t.charCodeAt(++c)),i[r>>2]|=(240|n>>18)<<s[3&r++],i[r>>2]|=(128|n>>12&63)<<s[3&r++],i[r>>2]|=(128|n>>6&63)<<s[3&r++],i[r>>2]|=(128|63&n)<<s[3&r++]);else for(r=this.start;c<l&&r<o;++c)i[r>>2]|=t[c]<<s[3&r++];if(this.lastByteIndex=r,r>=o){for(this.start=r-o,this.block=i[d],r=0;r<d;++r)h[r]^=i[r];H(h),this.reset=!0}else this.start=r}return this},S.prototype.encode=function(t,e){var r=255&t,n=1,a=[r];for(r=255&(t>>=8);r>0;)a.unshift(r),r=255&(t>>=8),++n;return e?a.push(n):a.unshift(n),this.update(a),a.length},S.prototype.encodeString=function(t){var e=p(t);t=e[0];var r=e[1],n=0,a=t.length;if(r)for(var i=0;i<t.length;++i){var o=t.charCodeAt(i);o<128?n+=1:o<2048?n+=2:o<55296||o>=57344?n+=3:(o=65536+((1023&o)<<10|1023&t.charCodeAt(++i)),n+=4)}else n=a;return n+=this.encode(8*n),this.update(t),n},S.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var a=(e-r%e)%e,i=[];return i.length=a,this.update(i),this},S.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];H(n)}},S.prototype.toString=S.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,a=this.extraBytes,o=0,s=0,l="";s<n;){for(o=0;o<e&&s<n;++o,++s)t=r[o],l+=i[t>>4&15]+i[15&t]+i[t>>12&15]+i[t>>8&15]+i[t>>20&15]+i[t>>16&15]+i[t>>28&15]+i[t>>24&15];s%e===0&&(r=A(r),H(r),o=0)}return a&&(t=r[o],l+=i[t>>4&15]+i[15&t],a>1&&(l+=i[t>>12&15]+i[t>>8&15]),a>2&&(l+=i[t>>20&15]+i[t>>16&15])),l},S.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,a=this.extraBytes,i=0,o=0,s=this.outputBits>>3;t=a?new ArrayBuffer(n+1<<2):new ArrayBuffer(s);for(var l=new Uint32Array(t);o<n;){for(i=0;i<e&&o<n;++i,++o)l[o]=r[i];o%e===0&&(r=A(r),H(r))}return a&&(l[o]=r[i],t=t.slice(0,s)),t},S.prototype.buffer=S.prototype.arrayBuffer,S.prototype.digest=S.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,a=this.outputBlocks,i=this.extraBytes,o=0,s=0,l=[];s<a;){for(o=0;o<r&&s<a;++o,++s)t=s<<2,e=n[o],l[t]=255&e,l[t+1]=e>>8&255,l[t+2]=e>>16&255,l[t+3]=e>>24&255;s%r===0&&(n=A(n),H(n))}return i&&(t=s<<2,e=n[o],l[t]=255&e,i>1&&(l[t+1]=e>>8&255),i>2&&(l[t+2]=e>>16&255)),l},U.prototype=new S,U.prototype.finalize=function(){return this.encode(this.outputBits,!0),S.prototype.finalize.call(this)};var H=function(t){var e,r,n,a,i,o,s,d,c,h,u,f,v,p,I,A,g,m,C,y,N,w,_,b,k,L,E,B,V,D,S,U,H,T,R,x,M,W,O,F,P,$,G,z,j,J,K,Y,q,Q,X,Z,tt,et,rt,nt,at,it,ot,st,lt,dt,ct;for(n=0;n<48;n+=2)a=t[0]^t[10]^t[20]^t[30]^t[40],i=t[1]^t[11]^t[21]^t[31]^t[41],o=t[2]^t[12]^t[22]^t[32]^t[42],s=t[3]^t[13]^t[23]^t[33]^t[43],d=t[4]^t[14]^t[24]^t[34]^t[44],c=t[5]^t[15]^t[25]^t[35]^t[45],h=t[6]^t[16]^t[26]^t[36]^t[46],u=t[7]^t[17]^t[27]^t[37]^t[47],e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|s>>>31),r=(v=t[9]^t[19]^t[29]^t[39]^t[49])^(s<<1|o>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=a^(d<<1|c>>>31),r=i^(c<<1|d>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=o^(h<<1|u>>>31),r=s^(u<<1|h>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=d^(f<<1|v>>>31),r=c^(v<<1|f>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=h^(a<<1|i>>>31),r=u^(i<<1|a>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,p=t[0],I=t[1],J=t[11]<<4|t[10]>>>28,K=t[10]<<4|t[11]>>>28,B=t[20]<<3|t[21]>>>29,V=t[21]<<3|t[20]>>>29,st=t[31]<<9|t[30]>>>23,lt=t[30]<<9|t[31]>>>23,$=t[40]<<18|t[41]>>>14,G=t[41]<<18|t[40]>>>14,T=t[2]<<1|t[3]>>>31,R=t[3]<<1|t[2]>>>31,A=t[13]<<12|t[12]>>>20,g=t[12]<<12|t[13]>>>20,Y=t[22]<<10|t[23]>>>22,q=t[23]<<10|t[22]>>>22,D=t[33]<<13|t[32]>>>19,S=t[32]<<13|t[33]>>>19,dt=t[42]<<2|t[43]>>>30,ct=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,x=t[14]<<6|t[15]>>>26,M=t[15]<<6|t[14]>>>26,m=t[25]<<11|t[24]>>>21,C=t[24]<<11|t[25]>>>21,Q=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,U=t[45]<<29|t[44]>>>3,H=t[44]<<29|t[45]>>>3,b=t[6]<<28|t[7]>>>4,k=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,at=t[16]<<23|t[17]>>>9,W=t[26]<<25|t[27]>>>7,O=t[27]<<25|t[26]>>>7,y=t[36]<<21|t[37]>>>11,N=t[37]<<21|t[36]>>>11,Z=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,z=t[8]<<27|t[9]>>>5,j=t[9]<<27|t[8]>>>5,L=t[18]<<20|t[19]>>>12,E=t[19]<<20|t[18]>>>12,it=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,F=t[38]<<8|t[39]>>>24,P=t[39]<<8|t[38]>>>24,w=t[48]<<14|t[49]>>>18,_=t[49]<<14|t[48]>>>18,t[0]=p^~A&m,t[1]=I^~g&C,t[10]=b^~L&B,t[11]=k^~E&V,t[20]=T^~x&W,t[21]=R^~M&O,t[30]=z^~J&Y,t[31]=j^~K&q,t[40]=et^~nt&it,t[41]=rt^~at&ot,t[2]=A^~m&y,t[3]=g^~C&N,t[12]=L^~B&D,t[13]=E^~V&S,t[22]=x^~W&F,t[23]=M^~O&P,t[32]=J^~Y&Q,t[33]=K^~q&X,t[42]=nt^~it&st,t[43]=at^~ot&lt,t[4]=m^~y&w,t[5]=C^~N&_,t[14]=B^~D&U,t[15]=V^~S&H,t[24]=W^~F&$,t[25]=O^~P&G,t[34]=Y^~Q&Z,t[35]=q^~X&tt,t[44]=it^~st&dt,t[45]=ot^~lt&ct,t[6]=y^~w&p,t[7]=N^~_&I,t[16]=D^~U&b,t[17]=S^~H&k,t[26]=F^~$&T,t[27]=P^~G&R,t[36]=Q^~Z&z,t[37]=X^~tt&j,t[46]=st^~dt&et,t[47]=lt^~ct&rt,t[8]=w^~p&A,t[9]=_^~I&g,t[18]=U^~b&L,t[19]=H^~k&E,t[28]=$^~T&x,t[29]=G^~R&M,t[38]=Z^~z&J,t[39]=tt^~j&K,t[48]=dt^~et&nt,t[49]=ct^~rt&at,t[0]^=l[n],t[1]^=l[n+1]};return b}().keccak_256;class s extends n{validateImplementation(t,r){const n=a(t);return 40!==n.length?{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}}:function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(n)?/^0+$/.test(n)?{valid:!1,error:"Burn address detected",details:{errorCode:e.BURN_ADDRESS}}:(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!this.checkChecksum(n)?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:this.isChecksummed(t),network:"mainnet"}}:{valid:!1,error:"Invalid hex characters",details:{errorCode:e.INVALID_CHARACTERS}}}format(t,e){let r=t.startsWith("0x")?t:i(t);if(e?.checksum&&(r=this.toChecksumAddress(r)),e?.shorten){const t=e.shortenLength||4;return`${r.slice(0,2+t)}...${r.slice(-t)}`}return r}isChecksummed(t){const e=a(t);return i(e)===this.toChecksumAddress(e)}checkChecksum(t){const e=a(t);if(e===e.toLowerCase()||e===e.toUpperCase())return!0;return e===a(this.toChecksumAddress(e))}toChecksumAddress(t){try{if(!t)return"";const e=a(t).toLowerCase(),r=o(e);let n="0x";for(let t=0;t<e.length;t++)parseInt(r[t],16)>=8?n+=e[t].toUpperCase():n+=e[t];return n}catch(e){return console.error("Checksum error:",e),t}}}const l="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",d=l.charAt(0),c={};for(let t=0;t<58;t++)c[l.charAt(t)]=t;function h(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],a=c[r];if(void 0===a)throw new Error(`Invalid Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=a;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 a;a=t.length===r?[]:n.reverse();for(let t=0;t<r;t++)a.unshift(0);return new Uint8Array(a)}class u extends n{validateImplementation(t){if(t.length<32||t.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{if(32!==h(t).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/^1+$/.test(t)&&"11111111111111111111111111111111"===t?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}format(t,e){if(e?.shorten){const r=e.shortenLength||4;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}var f;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(f||(f={}));const v=[996825010,642813549,513874426,1027748829,705979059];function p(t,e,r){const n=r===f.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^=v[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 I(t){if(t.length<8||t.length>1024)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 n=e.substring(0,r),a=[];for(let t=r+1;t<e.length;t++){const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(e[t]);if(-1===r)return null;a.push(r)}return p(n,a,f.BECH32)?{hrp:n,data:a.slice(0,a.length-6),encoding:f.BECH32}:p(n,a,f.BECH32M)?{hrp:n,data:a.slice(0,a.length-6),encoding:f.BECH32M}:null}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],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*t.length,a=t.length,i=new Uint8Array((((n+1+64)%512<=448?448-(n+1)%512:960-(n+1)%512)+1+64)/8);i[0]=128;const o=n,s=Math.floor(o/4294967296),l=o%4294967296,d=i.length;i[d-4]=l>>>24&255,i[d-3]=l>>>16&255,i[d-2]=l>>>8&255,i[d-1]=255&l,i[d-8]=s>>>24&255,i[d-7]=s>>>16&255,i[d-6]=s>>>8&255,i[d-5]=255&s;const c=new Uint8Array(a+i.length);c.set(t),c.set(i,a);const h=new Uint32Array(64);for(let t=0;t<c.length;t+=64){for(let e=0;e<16;e++)h[e]=c[t+4*e]<<24|c[t+4*e+1]<<16|c[t+4*e+2]<<8|c[t+4*e+3];for(let t=16;t<64;t++){const e=g(h[t-2],17)^g(h[t-2],19)^h[t-2]>>>10,r=g(h[t-15],7)^g(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+r+h[t-16]|0}let n=r[0],a=r[1],i=r[2],o=r[3],s=r[4],l=r[5],d=r[6],u=r[7];for(let t=0;t<64;t++){const r=u+(g(s,6)^g(s,11)^g(s,25))+(s&l^~s&d)+e[t]+h[t]|0,c=n&a^n&i^a&i;u=d,d=l,l=s,s=o+r|0,o=i,i=a,a=n,n=r+((g(n,2)^g(n,13)^g(n,22))+c|0)|0}r[0]=r[0]+n|0,r[1]=r[1]+a|0,r[2]=r[2]+i|0,r[3]=r[3]+o|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+d|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 g(t,e){return t>>>e|t<<32-e}class m extends n{validateImplementation(t){return t.startsWith("1")||t.startsWith("3")?this.validateLegacy(t):t.toLowerCase().startsWith("bc1")?this.validateBech32(t):{valid:!1,error:"Unknown format",details:{errorCode:e.INVALID_FORMAT}}}validateLegacy(t){if(t.length<26||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const r=h(t);if(25!==r.length)return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const n=r.slice(0,21),a=r.slice(21),i=A(n),o=A(i);return o[0]!==a[0]||o[1]!==a[1]||o[2]!==a[2]||o[3]!==a[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"bitcoin",details:{format:"legacy"}}}catch{return{valid:!1,error:"Invalid Base58",details:{errorCode:e.INVALID_CHARACTERS}}}}validateBech32(t){const r=I(t);if(!r)return{valid:!1,error:"Invalid Bech32 encoding",details:{errorCode:e.INVALID_FORMAT}};if("bc"!==r.hrp)return{valid:!1,error:"Invalid HRP",details:{errorCode:e.UNSUPPORTED_CHAIN}};const n=r.data[0];return 0===n?21!==r.data.length&&33!==r.data.length?{valid:!1,error:"Invalid SegWit program length",details:{errorCode:e.INVALID_LENGTH}}:r.encoding!==f.BECH32?{valid:!1,error:"V0 uses Bech32",details:{errorCode:e.INVALID_FORMAT}}:{valid:!0,blockchain:"bitcoin",details:{format:"segwit",network:"mainnet"}}:1===n?53!==r.data.length?{valid:!1,error:"Invalid Taproot program length",details:{errorCode:e.INVALID_LENGTH}}:r.encoding!==f.BECH32M?{valid:!1,error:"V1 uses Bech32m",details:{errorCode:e.INVALID_FORMAT}}:{valid:!0,blockchain:"bitcoin",details:{format:"taproot",network:"mainnet"}}:n>=2&&n<=16?r.encoding!==f.BECH32M?{valid:!1,error:"Version 2+ uses Bech32m",details:{errorCode:e.INVALID_FORMAT}}:{valid:!0,blockchain:"bitcoin",details:{format:"future",network:"mainnet"}}:{valid:!1,error:"Invalid witness version"}}format(t,e){if(e?.shorten){const r=e.shortenLength||4;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}class C extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}}class y extends n{validateImplementation(t){return t.startsWith("L")||t.startsWith("M")?this.validateLegacy(t):t.toLowerCase().startsWith("ltc1")?this.validateBech32(t):{valid:!1,error:"Unknown format",details:{errorCode:e.INVALID_FORMAT}}}validateLegacy(t){if(t.length<26||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const r=h(t);if(25!==r.length)return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const n=r.slice(0,21),a=r.slice(21),i=A(n),o=A(i);return o[0]!==a[0]||o[1]!==a[1]||o[2]!==a[2]||o[3]!==a[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"litecoin",details:{format:"legacy"}}}catch{return{valid:!1,error:"Invalid Base58",details:{errorCode:e.INVALID_CHARACTERS}}}}validateBech32(t){const r=I(t);if(!r)return{valid:!1,error:"Invalid Bech32 encoding",details:{errorCode:e.INVALID_FORMAT}};if("ltc"!==r.hrp)return{valid:!1,error:"Invalid HRP",details:{errorCode:e.UNSUPPORTED_CHAIN}};const n=r.data[0];return 0===n?21!==r.data.length&&33!==r.data.length?{valid:!1,error:"Invalid SegWit program length",details:{errorCode:e.INVALID_LENGTH}}:r.encoding!==f.BECH32?{valid:!1,error:"V0 uses Bech32",details:{errorCode:e.INVALID_FORMAT}}:{valid:!0,blockchain:"litecoin",details:{format:"segwit",network:"mainnet"}}:n>=1&&n<=16?r.encoding!==f.BECH32M?{valid:!1,error:"Version 1+ uses Bech32m",details:{errorCode:e.INVALID_FORMAT}}:{valid:!0,blockchain:"litecoin",details:{format:"future",network:"mainnet"}}:{valid:!1,error:"Invalid witness version"}}format(t,e){if(e?.shorten){const r=e.shortenLength||4;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}class N extends n{validateImplementation(t){if(!t.startsWith("D")&&!t.startsWith("9")&&!t.startsWith("A"))return{valid:!1,error:"Unknown format",details:{errorCode:e.INVALID_FORMAT}};if(t.length<26||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const r=h(t);if(25!==r.length)return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const n=r.slice(0,21),a=r.slice(21),i=A(n),o=A(i);return o[0]!==a[0]||o[1]!==a[1]||o[2]!==a[2]||o[3]!==a[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"dogecoin",details:{format:"legacy"}}}catch{return{valid:!1,error:"Invalid Base58",details:{errorCode:e.INVALID_CHARACTERS}}}}format(t,e){if(e?.shorten){const r=e.shortenLength||4;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}class w extends n{validateImplementation(t){return t.startsWith("addr1")||t.startsWith("addr_test1")||t.startsWith("stake1")||t.startsWith("stake_test1")?this.validateShelley(t):t.startsWith("A")||t.startsWith("D")||t.startsWith("Ae2")?this.validateByron(t):{valid:!1,error:"Unknown Cardano format",details:{errorCode:e.INVALID_FORMAT}}}validateShelley(t){const r=I(t);if(!r)return{valid:!1,error:"Invalid Bech32 encoding",details:{errorCode:e.INVALID_FORMAT}};if(!["addr","addr_test","stake","stake_test"].includes(r.hrp))return{valid:!1,error:"Invalid HRP for Cardano",details:{errorCode:e.UNSUPPORTED_CHAIN}};return{valid:!0,blockchain:"cardano",details:{format:"shelley",network:r.hrp.includes("test")?"testnet":"mainnet"}}}validateByron(t){try{const r=h(t);return r.length<32||r.length>128?{valid:!1,error:"Invalid Byron address length",details:{errorCode:e.INVALID_LENGTH}}:{valid:!0,blockchain:"cardano",details:{format:"byron"}}}catch{return{valid:!1,error:"Invalid Base58",details:{errorCode:e.INVALID_CHARACTERS}}}}format(t,e){if(e?.shorten){const r=e.shortenLength||8;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}const _="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",b=_.charAt(0),k={};for(let t=0;t<58;t++)k[_.charAt(t)]=t;class L extends n{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:e.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};try{const r=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===b;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],a=k[r];if(void 0===a)throw new Error(`Invalid Ripple Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=a;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 a=[];t.length!==r&&(a=n.reverse());for(let t=0;t<r;t++)a.unshift(0);return new Uint8Array(a)}(t);if(25!==r.length)return{valid:!1,error:"Invalid decoded length",details:{errorCode:e.INVALID_LENGTH}};const n=r.slice(0,21),a=r.slice(21),i=A(n),o=A(i);return o[0]!==a[0]||o[1]!==a[1]||o[2]!==a[2]||o[3]!==a[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}}}}format(t,e){if(e?.shorten){const r=e.shortenLength||4;return`${t.slice(0,r)}...${t.slice(-r)}`}return t}}class E extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}}class B extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}}class V extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}}class D extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}}class S extends s{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}}const U={ethereum:new s,solana:new u,bitcoin:new m,litecoin:new y,dogecoin:new N,cardano:new w,ripple:new L};const H={ethereum:new s,solana:new u,bitcoin:new m,polygon:new C,litecoin:new y,dogecoin:new N,cardano:new w,ripple:new L,bsc:new E,avalanche:new B,arbitrum:new V,optimism:new D,base:new S};t.ArbitrumValidator=V,t.AvalancheValidator=B,t.BaseValidator=S,t.BitcoinValidator=m,t.BscValidator=E,t.CardanoValidator=w,t.DogecoinValidator=N,t.EthereumValidator=s,t.LitecoinValidator=y,t.OptimismValidator=D,t.PolygonValidator=C,t.RippleValidator=L,t.SolanaValidator=u,t.addChecksum=function(t,e){if("ethereum"===e||"polygon"===e){return(new s).format(t,{checksum:!0})}return t},t.detectBlockchain=function(t){return t.startsWith("0x")&&42===t.length&&U.ethereum.validate(t).valid?["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base"]:t.startsWith("r")&&t.length>=25&&U.ripple.validate(t).valid?"ripple":(t.startsWith("addr")||t.startsWith("stake")||t.startsWith("A")||t.startsWith("D"))&&U.cardano.validate(t).valid?"cardano":(t.startsWith("1")||t.startsWith("3")||t.toLowerCase().startsWith("bc1"))&&U.bitcoin.validate(t).valid?"bitcoin":(t.startsWith("L")||t.startsWith("M")||t.toLowerCase().startsWith("ltc1"))&&U.litecoin.validate(t).valid?"litecoin":(t.startsWith("D")||t.startsWith("9")||t.startsWith("A"))&&U.dogecoin.validate(t).valid?"dogecoin":U.solana.validate(t).valid?"solana":null},t.formatAddress=function(t,e,r){const n=H[e];if(!n)throw new Error(`Unsupported blockchain: ${e}`);return n.format(t,r)},t.normalizeAddress=function(t,e){return"ethereum"===e||"polygon"===e?t.toLowerCase():t},t.shortenAddress=function(t,e=4){return!t||t.length<2*e+2?t:`${t.slice(0,e+2)}...${t.slice(-e)}`},t.validateAddress=function(t,e,r){const n=H[e];if(!n)throw new Error(`Unsupported blockchain: ${e}`);return n.validate(t,r)},t.validateBatch=function(t,e,r){const n=H[e];if(!n)throw new Error(`Unsupported blockchain: ${e}`);return t.map(t=>n.validate(t,r))}});
2
- //# sourceMappingURL=index.umd.js.map
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))}});
@@ -0,0 +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"}})}};
@@ -0,0 +1 @@
1
+ export { LitecoinValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { LitecoinValidator } from './index.mjs';
@@ -0,0 +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};
package/dist/move.cjs ADDED
@@ -0,0 +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}}}};
@@ -0,0 +1 @@
1
+ export { SuiValidator, AptosValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { SuiValidator, AptosValidator } from './index.mjs';
package/dist/move.mjs ADDED
@@ -0,0 +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};
package/dist/near.cjs ADDED
@@ -0,0 +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}}}};
@@ -0,0 +1 @@
1
+ export { NearValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { NearValidator } from './index.mjs';
package/dist/near.mjs ADDED
@@ -0,0 +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};
@@ -0,0 +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}}}}};
@@ -0,0 +1 @@
1
+ export { RippleValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { RippleValidator } from './index.mjs';
@@ -0,0 +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};
@@ -0,0 +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"}}};
@@ -0,0 +1 @@
1
+ export { SolanaValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { SolanaValidator } from './index.mjs';
@@ -0,0 +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};
package/dist/tron.cjs ADDED
@@ -0,0 +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}}}};
@@ -0,0 +1 @@
1
+ export { TronValidator } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { TronValidator } from './index.mjs';
package/dist/tron.mjs ADDED
@@ -0,0 +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};
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "validator0x",
3
- "version": "0.2.0",
4
- "description": "Multi-chain wallet address validator and formatter for Ethereum, Solana, Bitcoin, Polygon, Litecoin, Dogecoin, Cardano, Ripple, and more. Supports batch validation and zero dependencies.",
5
- "main": "dist/index.cjs.js",
6
- "module": "dist/index.esm.js",
7
- "browser": "dist/index.umd.js",
8
- "types": "dist/index.d.ts",
3
+ "version": "0.3.0",
4
+ "description": "Lightweight, zero-dependency wallet address validation for EVM, Bitcoin, Solana, TRON, Cosmos, Cardano, Sui, Aptos, NEAR and more.",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.cts",
9
8
  "files": [
10
9
  "dist",
11
10
  "README.md",
11
+ "AGENTS.md",
12
+ "CHANGELOG.md",
12
13
  "LICENSE"
13
14
  ],
14
15
  "repository": {
@@ -16,13 +17,19 @@
16
17
  "url": "git+https://github.com/Samarth208P/validator0x.git"
17
18
  },
18
19
  "scripts": {
19
- "build": "rimraf dist && rollup -c rollup.config.mjs && tsc --emitDeclarationOnly",
20
- "test": "jest",
21
- "test:coverage": "jest --coverage",
22
- "lint": "eslint src tests --ext .ts",
23
- "format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts'",
24
- "benchmark": "ts-node --project tsconfig.benchmark.json tests/benchmark.ts",
25
- "prepublishOnly": "npm run lint && npm test && npm run build"
20
+ "build": "node scripts/clean.mjs && rollup -c && node scripts/declarations.mjs",
21
+ "test": "vitest run",
22
+ "test:coverage": "vitest run --coverage",
23
+ "test:package": "node scripts/test-package.mjs",
24
+ "test:differential": "node scripts/test-differential.mjs",
25
+ "lint": "eslint src tests --max-warnings 0",
26
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.test.json",
27
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
28
+ "benchmark": "node scripts/benchmark.mjs",
29
+ "check": "npm run lint && npm run typecheck && npm test && npm run build && npm run test:differential && npm run test:package",
30
+ "prepack": "npm run build",
31
+ "prepublishOnly": "npm run check",
32
+ "prepare:release": "npm run check && npm run test:coverage && npm audit && npm pack --ignore-scripts"
26
33
  },
27
34
  "keywords": [
28
35
  "blockchain",
@@ -42,25 +49,233 @@
42
49
  "crypto",
43
50
  "batch-validation",
44
51
  "checksum",
45
- "validator0x"
52
+ "validator0x",
53
+ "tron",
54
+ "cosmos",
55
+ "sui",
56
+ "aptos",
57
+ "near",
58
+ "osmosis",
59
+ "celestia"
46
60
  ],
47
61
  "author": "Samarth Patel",
48
62
  "license": "MIT",
49
63
  "devDependencies": {
50
- "@rollup/plugin-typescript": "^11.0.0",
51
- "@types/jest": "^29.0.0",
52
- "@types/node": "^20.0.0",
53
- "@typescript-eslint/eslint-plugin": "^6.0.0",
54
- "@typescript-eslint/parser": "^6.0.0",
55
- "eslint": "^8.0.0",
56
- "jest": "^29.0.0",
57
- "prettier": "^3.0.0",
58
- "rimraf": "^5.0.0",
59
- "rollup": "^4.0.0",
60
- "rollup-plugin-terser": "^7.0.0",
61
- "ts-jest": "^29.0.0",
62
- "ts-node": "^10.0.0",
64
+ "@rollup/plugin-typescript": "^12.3.1",
65
+ "@types/node": "^22.0.0",
66
+ "eslint": "^10.14.0",
67
+ "prettier": "^3.10.1",
68
+ "rollup": "^4.68.3",
63
69
  "tslib": "^2.8.1",
64
- "typescript": "5.3.3"
70
+ "typescript": "5.9.3",
71
+ "@rollup/plugin-terser": "^1.0.2",
72
+ "rollup-plugin-dts": "^6.5.1",
73
+ "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
+ },
80
+ "unpkg": "./dist/index.umd.js",
81
+ "jsdelivr": "./dist/index.umd.js",
82
+ "sideEffects": false,
83
+ "engines": {
84
+ "node": ">=22"
85
+ },
86
+ "exports": {
87
+ ".": {
88
+ "import": {
89
+ "types": "./dist/index.d.mts",
90
+ "default": "./dist/index.mjs"
91
+ },
92
+ "require": {
93
+ "types": "./dist/index.d.cts",
94
+ "default": "./dist/index.cjs"
95
+ }
96
+ },
97
+ "./ethereum": {
98
+ "import": {
99
+ "types": "./dist/ethereum.d.mts",
100
+ "default": "./dist/ethereum.mjs"
101
+ },
102
+ "require": {
103
+ "types": "./dist/ethereum.d.cts",
104
+ "default": "./dist/ethereum.cjs"
105
+ }
106
+ },
107
+ "./evm": {
108
+ "import": {
109
+ "types": "./dist/evm.d.mts",
110
+ "default": "./dist/evm.mjs"
111
+ },
112
+ "require": {
113
+ "types": "./dist/evm.d.cts",
114
+ "default": "./dist/evm.cjs"
115
+ }
116
+ },
117
+ "./bitcoin": {
118
+ "import": {
119
+ "types": "./dist/bitcoin.d.mts",
120
+ "default": "./dist/bitcoin.mjs"
121
+ },
122
+ "require": {
123
+ "types": "./dist/bitcoin.d.cts",
124
+ "default": "./dist/bitcoin.cjs"
125
+ }
126
+ },
127
+ "./litecoin": {
128
+ "import": {
129
+ "types": "./dist/litecoin.d.mts",
130
+ "default": "./dist/litecoin.mjs"
131
+ },
132
+ "require": {
133
+ "types": "./dist/litecoin.d.cts",
134
+ "default": "./dist/litecoin.cjs"
135
+ }
136
+ },
137
+ "./dogecoin": {
138
+ "import": {
139
+ "types": "./dist/dogecoin.d.mts",
140
+ "default": "./dist/dogecoin.mjs"
141
+ },
142
+ "require": {
143
+ "types": "./dist/dogecoin.d.cts",
144
+ "default": "./dist/dogecoin.cjs"
145
+ }
146
+ },
147
+ "./solana": {
148
+ "import": {
149
+ "types": "./dist/solana.d.mts",
150
+ "default": "./dist/solana.mjs"
151
+ },
152
+ "require": {
153
+ "types": "./dist/solana.d.cts",
154
+ "default": "./dist/solana.cjs"
155
+ }
156
+ },
157
+ "./ripple": {
158
+ "import": {
159
+ "types": "./dist/ripple.d.mts",
160
+ "default": "./dist/ripple.mjs"
161
+ },
162
+ "require": {
163
+ "types": "./dist/ripple.d.cts",
164
+ "default": "./dist/ripple.cjs"
165
+ }
166
+ },
167
+ "./cardano": {
168
+ "import": {
169
+ "types": "./dist/cardano.d.mts",
170
+ "default": "./dist/cardano.mjs"
171
+ },
172
+ "require": {
173
+ "types": "./dist/cardano.d.cts",
174
+ "default": "./dist/cardano.cjs"
175
+ }
176
+ },
177
+ "./tron": {
178
+ "import": {
179
+ "types": "./dist/tron.d.mts",
180
+ "default": "./dist/tron.mjs"
181
+ },
182
+ "require": {
183
+ "types": "./dist/tron.d.cts",
184
+ "default": "./dist/tron.cjs"
185
+ }
186
+ },
187
+ "./cosmos": {
188
+ "import": {
189
+ "types": "./dist/cosmos.d.mts",
190
+ "default": "./dist/cosmos.mjs"
191
+ },
192
+ "require": {
193
+ "types": "./dist/cosmos.d.cts",
194
+ "default": "./dist/cosmos.cjs"
195
+ }
196
+ },
197
+ "./move": {
198
+ "import": {
199
+ "types": "./dist/move.d.mts",
200
+ "default": "./dist/move.mjs"
201
+ },
202
+ "require": {
203
+ "types": "./dist/move.d.cts",
204
+ "default": "./dist/move.cjs"
205
+ }
206
+ },
207
+ "./near": {
208
+ "import": {
209
+ "types": "./dist/near.d.mts",
210
+ "default": "./dist/near.mjs"
211
+ },
212
+ "require": {
213
+ "types": "./dist/near.d.cts",
214
+ "default": "./dist/near.cjs"
215
+ }
216
+ },
217
+ "./formatters": {
218
+ "import": {
219
+ "types": "./dist/formatters.d.mts",
220
+ "default": "./dist/formatters.mjs"
221
+ },
222
+ "require": {
223
+ "types": "./dist/formatters.d.cts",
224
+ "default": "./dist/formatters.cjs"
225
+ }
226
+ },
227
+ "./package.json": "./package.json",
228
+ "./AGENTS.md": "./AGENTS.md"
229
+ },
230
+ "typesVersions": {
231
+ "*": {
232
+ "ethereum": [
233
+ "./dist/ethereum.d.cts"
234
+ ],
235
+ "evm": [
236
+ "./dist/evm.d.cts"
237
+ ],
238
+ "bitcoin": [
239
+ "./dist/bitcoin.d.cts"
240
+ ],
241
+ "litecoin": [
242
+ "./dist/litecoin.d.cts"
243
+ ],
244
+ "dogecoin": [
245
+ "./dist/dogecoin.d.cts"
246
+ ],
247
+ "solana": [
248
+ "./dist/solana.d.cts"
249
+ ],
250
+ "ripple": [
251
+ "./dist/ripple.d.cts"
252
+ ],
253
+ "cardano": [
254
+ "./dist/cardano.d.cts"
255
+ ],
256
+ "tron": [
257
+ "./dist/tron.d.cts"
258
+ ],
259
+ "cosmos": [
260
+ "./dist/cosmos.d.cts"
261
+ ],
262
+ "move": [
263
+ "./dist/move.d.cts"
264
+ ],
265
+ "near": [
266
+ "./dist/near.d.cts"
267
+ ],
268
+ "formatters": [
269
+ "./dist/formatters.d.cts"
270
+ ]
271
+ }
272
+ },
273
+ "overrides": {
274
+ "minimatch": "^11.0.1"
275
+ },
276
+ "publishConfig": {
277
+ "registry": "https://registry.npmjs.org/",
278
+ "access": "public",
279
+ "tag": "latest"
65
280
  }
66
- }
281
+ }
@@ -1,8 +0,0 @@
1
- import { BlockchainType } from '../types';
2
- /**
3
- * Auto-detects the blockchain for an address.
4
- * Because EVM chains share identical formats, if it matches Ethereum,
5
- * it returns an array of possible matching chains.
6
- */
7
- export declare function detectBlockchain(address: string): BlockchainType | BlockchainType[] | null;
8
- //# sourceMappingURL=chain-detector.d.ts.map