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
@@ -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),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,e){return n(t,e)}}function n(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)}`}function o(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const i=(1n<<64n)-1n,a=[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],l=[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 d(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&i}function c(t){const e=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^d(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=d(t[e+5*n],a[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class I extends r{validateImplementation(e,r){const n=o(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.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)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const s=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,r){let o=s(e.sanitize(t));return r?.checksum&&(o=this.toChecksumAddress(o)),n(o,r)}isChecksummed(t){const e=o(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=o(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));c(n)}let o="";for(let t=0;t<32;t++)o+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}export{I as EthereumValidator};
package/dist/evm.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 a=e.sanitize(r),s=this.validateImplementation(a,n),o=s.details?.network;return s.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:{...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,e){return n(t,e)}}function n(t,r,n=4){const a=e.sanitize(t);if(!r?.shorten)return a;const s=r.shortenLength??n;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const o=a.startsWith("0x")?2:0;return a.length<=2*s+o+3?a:`${a.slice(0,s+o)}...${a.slice(-s)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const o=(1n<<64n)-1n,i=[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],l=[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 c(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&o}function d(t){const e=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^c(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=c(t[e+5*n],i[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class u extends r{validateImplementation(e,r){const n=a(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.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)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const s=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,r){let a=s(e.sanitize(t));return r?.checksum&&(a=this.toChecksumAddress(a)),n(a,r)}isChecksummed(t){const e=a(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));d(n)}let a="";for(let t=0;t<32;t++)a+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return a}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}exports.ArbitrumValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}},exports.AvalancheValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}},exports.BaseValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}},exports.BscValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}},exports.EvmValidator=class extends u{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain=this.chain),r}},exports.OptimismValidator=class extends u{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}};
package/dist/evm.d.cts ADDED
@@ -0,0 +1 @@
1
+ export { EvmValidator, BscValidator, AvalancheValidator, ArbitrumValidator, OptimismValidator, BaseValidator } from './index.cjs';
package/dist/evm.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { EvmValidator, BscValidator, AvalancheValidator, ArbitrumValidator, OptimismValidator, BaseValidator } from './index.mjs';
package/dist/evm.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 n{validate(n,r){try{const a=t.sanitize(n),s=this.validateImplementation(a,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:e.NETWORK_MISMATCH}}:s}catch(t){const n=t instanceof Error?t.message:String(t);return n===e.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:e.UNSAFE_INPUT}}:{valid:!1,error:n,details:{errorCode:e.INVALID_FORMAT}}}}format(e,t){return r(e,t)}}function r(e,n,r=4){const a=t.sanitize(e);if(!n?.shorten)return a;const s=n.shortenLength??r;if(!Number.isSafeInteger(s)||s<1)throw new RangeError("shortenLength must be a positive integer");const o=a.startsWith("0x")?2:0;return a.length<=2*s+o+3?a:`${a.slice(0,s+o)}...${a.slice(-s)}`}function a(e){return e.startsWith("0x")?e.slice(2):e}function s(e){return e.startsWith("0x")?e:`0x${e}`}const o=(1n<<64n)-1n,i=[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],l=[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 c(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&o}function d(e){const t=new Array(5),n=new Array(25);for(const r of l){for(let n=0;n<5;n++)t[n]=e[n]^e[n+5]^e[n+10]^e[n+15]^e[n+20];for(let n=0;n<5;n++){const r=t[(n+4)%5]^c(t[(n+1)%5],1);for(let t=0;t<5;t++)e[n+5*t]^=r}for(let t=0;t<5;t++)for(let r=0;r<5;r++)n[r+(2*t+3*r)%5*5]=c(e[t+5*r],i[t+5*r]);for(let t=0;t<5;t++)for(let r=0;r<5;r++)e[t+5*r]=n[t+5*r]^~n[(t+1)%5+5*r]&n[(t+2)%5+5*r];e[0]^=r}}class I extends n{validateImplementation(t,n){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:e.INVALID_LENGTH}};if(!function(e){if("string"!=typeof e)return!1;const t=e.startsWith("0x")?e.slice(2):e;return/^[0-9a-fA-F]*$/.test(t)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:e.INVALID_CHARACTERS}};if(!n?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:e.BURN_ADDRESS}};const s=this.isChecksummed(r);return(n?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:e.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(e,n){let a=s(t.sanitize(e));return n?.checksum&&(a=this.toChecksumAddress(a)),r(a,n)}isChecksummed(e){const t=a(e);return s(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=a(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const n=function(e){const t=(new TextEncoder).encode(e),n=new Uint8Array(136*(Math.floor(t.length/136)+1));n.set(t),n[t.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let e=0;e<n.length;e+=136){for(let t=0;t<136;t++)r[t>>3]^=BigInt(n[e+t])<<BigInt(8*(7&t));d(r)}let a="";for(let e=0;e<32;e++)a+=Number(r[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return a}(t);return"0x"+[...t].map((e,t)=>parseInt(n[t],16)>=8?e.toUpperCase():e).join("")}}class u extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="bsc"),n}}class h extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="avalanche"),n}}class m extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="arbitrum"),n}}class A extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="optimism"),n}}class x extends I{validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain="base"),n}}class N extends I{constructor(e="evm"){super(),this.chain=e}validateImplementation(e,t){const n=super.validateImplementation(e,t);return n.valid&&(n.blockchain=this.chain),n}}export{m as ArbitrumValidator,h as AvalancheValidator,x as BaseValidator,u as BscValidator,N as EvmValidator,A as OptimismValidator};
@@ -0,0 +1 @@
1
+ "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"]);var t;!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"}(t||(t={}));class r{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 n{validate(e,n){try{const o=r.sanitize(e),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(e,t){return o(e,t)}}function o(e,t,n=4){const o=r.sanitize(e);if(!t?.shorten)return o;const s=t.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)}`}function s(e){return e.startsWith("0x")?e.slice(2):e}function i(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=[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 d(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function u(e){const t=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)t[r]=e[r]^e[r+5]^e[r+10]^e[r+15]^e[r+20];for(let r=0;r<5;r++){const n=t[(r+4)%5]^d(t[(r+1)%5],1);for(let t=0;t<5;t++)e[r+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[n+(2*t+3*n)%5*5]=d(e[t+5*n],c[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[t+5*n]=r[t+5*n]^~r[(t+1)%5+5*n]&r[(t+2)%5+5*n];e[0]^=n}}class h extends n{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!function(e){if("string"!=typeof e)return!1;const t=e.startsWith("0x")?e.slice(2):e;return/^[0-9a-fA-F]*$/.test(t)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const o=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!o?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:o}}}format(e,t){let n=i(r.sanitize(e));return t?.checksum&&(n=this.toChecksumAddress(n)),o(n,t)}isChecksummed(e){const t=s(e);return i(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=s(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const r=function(e){const t=(new TextEncoder).encode(e),r=new Uint8Array(136*(Math.floor(t.length/136)+1));r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let e=0;e<r.length;e+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(r[e+t])<<BigInt(8*(7&t));u(n)}let o="";for(let e=0;e<32;e++)o+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return o}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}exports.addChecksum=function(t,n){return e.includes(n)?(new h).format(t,{checksum:!0}):r.sanitize(t)},exports.normalizeAddress=function(t,n){const o=r.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?o.toLowerCase():o},exports.shortenAddress=function(e,t=4){return o(e,{shorten:!0,shortenLength:t})};
@@ -0,0 +1 @@
1
+ export { shortenAddress, normalizeAddress, addChecksum } from './index.cjs';
@@ -0,0 +1 @@
1
+ export { shortenAddress, normalizeAddress, addChecksum } from './index.mjs';
@@ -0,0 +1 @@
1
+ const e=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]);var t;!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"}(t||(t={}));class r{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 n{validate(e,n){try{const o=r.sanitize(e),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(e,t){return o(e,t)}}function o(e,t,n=4){const o=r.sanitize(e);if(!t?.shorten)return o;const s=t.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)}`}function s(e){return e.startsWith("0x")?e.slice(2):e}function i(e){return e.startsWith("0x")?e:`0x${e}`}const a=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],l=[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 d(e,t){return(e<<BigInt(t)|e>>BigInt(64-t))&a}function u(e){const t=new Array(5),r=new Array(25);for(const n of l){for(let r=0;r<5;r++)t[r]=e[r]^e[r+5]^e[r+10]^e[r+15]^e[r+20];for(let r=0;r<5;r++){const n=t[(r+4)%5]^d(t[(r+1)%5],1);for(let t=0;t<5;t++)e[r+5*t]^=n}for(let t=0;t<5;t++)for(let n=0;n<5;n++)r[n+(2*t+3*n)%5*5]=d(e[t+5*n],c[t+5*n]);for(let t=0;t<5;t++)for(let n=0;n<5;n++)e[t+5*n]=r[t+5*n]^~r[(t+1)%5+5*n]&r[(t+2)%5+5*n];e[0]^=n}}class h extends n{validateImplementation(e,r){const n=s(e);if(40!==n.length)return{valid:!1,error:"Invalid length",details:{errorCode:t.INVALID_LENGTH}};if(!function(e){if("string"!=typeof e)return!1;const t=e.startsWith("0x")?e.slice(2):e;return/^[0-9a-fA-F]*$/.test(t)}(n))return{valid:!1,error:"Invalid hex characters",details:{errorCode:t.INVALID_CHARACTERS}};if(!r?.allowBurnAddress&&/^0+$/.test(n))return{valid:!1,error:"Burn address detected",details:{errorCode:t.BURN_ADDRESS}};const o=this.isChecksummed(n);return(r?.strict||n!==n.toLowerCase()&&n!==n.toUpperCase())&&!o?{valid:!1,error:"Invalid checksum",details:{errorCode:t.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:o}}}format(e,t){let n=i(r.sanitize(e));return t?.checksum&&(n=this.toChecksumAddress(n)),o(n,t)}isChecksummed(e){const t=s(e);return i(t)===this.toChecksumAddress(t)}toChecksumAddress(e){const t=s(e).toLowerCase();if(!/^[0-9a-f]{40}$/.test(t))throw new Error("Expected a 20-byte hexadecimal address");const r=function(e){const t=(new TextEncoder).encode(e),r=new Uint8Array(136*(Math.floor(t.length/136)+1));r.set(t),r[t.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let e=0;e<r.length;e+=136){for(let t=0;t<136;t++)n[t>>3]^=BigInt(r[e+t])<<BigInt(8*(7&t));u(n)}let o="";for(let e=0;e<32;e++)o+=Number(n[e>>3]>>BigInt(8*(7&e))&255n).toString(16).padStart(2,"0");return o}(t);return"0x"+[...t].map((e,t)=>parseInt(r[t],16)>=8?e.toUpperCase():e).join("")}}function I(e,t=4){return o(e,{shorten:!0,shortenLength:t})}function f(t,n){const o=r.sanitize(t);return e.includes(n)||"sui"===n||"aptos"===n?o.toLowerCase():o}function A(t,n){return e.includes(n)?(new h).format(t,{checksum:!0}):r.sanitize(t)}export{A as addChecksum,f as normalizeAddress,I as shortenAddress};
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const t=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var r;exports.ValidationError=void 0,(r=exports.ValidationError||(exports.ValidationError={})).INVALID_FORMAT="INVALID_FORMAT",r.INVALID_CHECKSUM="INVALID_CHECKSUM",r.INVALID_LENGTH="INVALID_LENGTH",r.INVALID_CHARACTERS="INVALID_CHARACTERS",r.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",r.BURN_ADDRESS="BURN_ADDRESS",r.UNSAFE_INPUT="UNSAFE_INPUT",r.NETWORK_MISMATCH="NETWORK_MISMATCH";class n{static sanitize(t){if(null==t)throw new Error(exports.ValidationError.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(t.length>256)throw new Error(exports.ValidationError.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(exports.ValidationError.UNSAFE_INPUT);return t.trim()}}class o{validate(t,e){try{const r=n.sanitize(t),o=this.validateImplementation(r,e),i=o.details?.network;return o.valid&&i&&(e?.network&&"auto"!==e.network&&e.network!==i||!1===e?.allowTestnet&&"testnet"===i)?{valid:!1,error:"Address network does not match the requested network",details:{...o.details,errorCode:exports.ValidationError.NETWORK_MISMATCH}}:o}catch(t){const e=t instanceof Error?t.message:String(t);return e===exports.ValidationError.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:exports.ValidationError.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}format(t,e){return i(t,e)}}function i(t,e,r=4){const o=n.sanitize(t);if(!e?.shorten)return o;const i=e.shortenLength??r;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const a=o.startsWith("0x")?2:0;return o.length<=2*i+a+3?o:`${o.slice(0,i+a)}...${o.slice(-i)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function s(t){return t.startsWith("0x")?t:`0x${t}`}const l=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],d=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function h(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&l}function u(t){const e=new Array(5),r=new Array(25);for(const n of d){for(let r=0;r<5;r++)e[r]=t[r]^t[r+5]^t[r+10]^t[r+15]^t[r+20];for(let r=0;r<5;r++){const n=e[(r+4)%5]^h(e[(r+1)%5],1);for(let e=0;e<5;e++)t[r+5*e]^=n}for(let e=0;e<5;e++)for(let n=0;n<5;n++)r[n+(2*e+3*n)%5*5]=h(t[e+5*n],c[e+5*n]);for(let e=0;e<5;e++)for(let n=0;n<5;n++)t[e+5*n]=r[e+5*n]^~r[(e+1)%5+5*n]&r[(e+2)%5+5*n];t[0]^=n}}class f extends o{validateImplementation(t,e){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:exports.ValidationError.INVALID_CHARACTERS}};if(!e?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:exports.ValidationError.BURN_ADDRESS}};const n=this.isChecksummed(r);return(e?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!n?{valid:!1,error:"Invalid checksum",details:{errorCode:exports.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:n}}}format(t,e){let r=s(n.sanitize(t));return e?.checksum&&(r=this.toChecksumAddress(r)),i(r,e)}isChecksummed(t){const e=a(t);return s(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const r=function(t){const e=(new TextEncoder).encode(t),r=new Uint8Array(136*(Math.floor(e.length/136)+1));r.set(e),r[e.length]=1,r[r.length-1]|=128;const n=new Array(25).fill(0n);for(let t=0;t<r.length;t+=136){for(let e=0;e<136;e++)n[e>>3]^=BigInt(r[t+e])<<BigInt(8*(7&e));u(n)}let o="";for(let t=0;t<32;t++)o+=Number(n[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return o}(e);return"0x"+[...e].map((t,e)=>parseInt(r[e],16)>=8?t.toUpperCase():t).join("")}}const p="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",m=p.charAt(0),v={};for(let t=0;t<58;t++)v[p.charAt(t)]=t;function x(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===m;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=v[r];if(void 0===o)throw new Error(`Invalid Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let i=0;for(let t=0;t<n.length;++t)n[t]+=i,i=n[t]>>8,n[t]&=255;for(;i;)n.push(255&i),i>>=8}const o=t.length===r?[]:n.reverse();return Uint8Array.from([...new Array(r).fill(0),...o])}class I extends o{validateImplementation(t){if(t.length<32||t.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};try{if(32!==x(t).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}return"11111111111111111111111111111111"===t?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function g(t){const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],r=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],n=8*t.length,o=t.length,i=new Uint8Array(64-(o+8)%64+8);i[0]=128;const a=n,s=Math.floor(a/4294967296),l=a%4294967296,c=i.length;i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=255&l,i[c-8]=s>>>24&255,i[c-7]=s>>>16&255,i[c-6]=s>>>8&255,i[c-5]=255&s;const d=new Uint8Array(o+i.length);d.set(t),d.set(i,o);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=A(h[t-2],17)^A(h[t-2],19)^h[t-2]>>>10,r=A(h[t-15],7)^A(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+r+h[t-16]|0}let n=r[0],o=r[1],i=r[2],a=r[3],s=r[4],l=r[5],c=r[6],u=r[7];for(let t=0;t<64;t++){const r=u+(A(s,6)^A(s,11)^A(s,25))+(s&l^~s&c)+e[t]+h[t]|0,d=n&o^n&i^o&i;u=c,c=l,l=s,s=a+r|0,a=i,i=o,o=n,n=r+((A(n,2)^A(n,13)^A(n,22))+d|0)|0}r[0]=r[0]+n|0,r[1]=r[1]+o|0,r[2]=r[2]+i|0,r[3]=r[3]+a|0,r[4]=r[4]+s|0,r[5]=r[5]+l|0,r[6]=r[6]+c|0,r[7]=r[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=r[t]>>>24&255,u[4*t+1]=r[t]>>>16&255,u[4*t+2]=r[t]>>>8&255,u[4*t+3]=255&r[t];return u}function A(t,e){return t>>>e|t<<32-e}function E(t){try{const e=x(t);if(e.length<5)return null;const r=e.slice(0,-4),n=g(g(r));return e.slice(-4).every((t,e)=>t===n[e])?r:null}catch{return null}}var w;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(w||(w={}));const C=[996825010,642813549,513874426,1027748829,705979059];function V(t,e,r){const n=r===w.BECH32M?734539939:1;return function(t){let e=1;for(const r of t){const t=e>>25;e=(33554431&e)<<5^r;for(let r=0;r<5;r++)t>>r&1&&(e^=C[r])}return e}(function(t){const e=[];for(let r=0;r<t.length;r++)e.push(t.charCodeAt(r)>>5);e.push(0);for(let r=0;r<t.length;r++)e.push(31&t.charCodeAt(r));return e}(t).concat(e))===n}function N(t,e=90){if(t.length<8||t.length>e)return null;const r=t.toLowerCase();if(t!==r&&t!==t.toUpperCase())return null;const n=r.lastIndexOf("1");if(n<1||n+7>r.length)return null;const o=r.substring(0,n);if(/[^\x21-\x7E]/.test(o))return null;const i=[];for(let t=n+1;t<r.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(r[t]);if(-1===e)return null;i.push(e)}return V(o,i,w.BECH32)?{hrp:o,data:i.slice(0,i.length-6),encoding:w.BECH32}:V(o,i,w.BECH32M)?{hrp:o,data:i.slice(0,i.length-6),encoding:w.BECH32M}:null}function k(t){let e=0,r=0;const n=[];for(const o of t){if(!Number.isInteger(o)||o<0||o>31)return null;e=65535&(e<<5|o),r+=5,r>=8&&(r-=8,n.push(e>>>r&255))}return r>=5||e<<8-r&255?null:Uint8Array.from(n)}class b extends o{constructor(t){super(),this.config=t}validateImplementation(t){const e=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(t,this.config.hrps[e]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",exports.ValidationError.INVALID_LENGTH);const r=E(t);if(!r)return this.invalid("Invalid Base58Check address",exports.ValidationError.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",exports.ValidationError.INVALID_LENGTH);const n=this.config.versions[r[0]];return n?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:n,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(t,e){const r=N(t);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const n=r.data[0],o=k(r.data.slice(1));if(n>16)return this.invalid("Invalid witness version");if(!o||o.length<2||o.length>40||0===n&&20!==o.length&&32!==o.length)return this.invalid("Invalid witness program or padding",exports.ValidationError.INVALID_LENGTH);const i=0===n?w.BECH32:w.BECH32M;if(r.encoding!==i)return this.invalid("Wrong checksum encoding for witness version",exports.ValidationError.INVALID_CHECKSUM);const a=0===n?"segwit":1===n&&32===o.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:a,network:e,checksum:!0}}}invalid(t,e=exports.ValidationError.INVALID_FORMAT){return{valid:!1,error:t,details:{errorCode:e}}}}class L extends b{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class T extends b{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class _ extends b{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class y{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const r=31&e;if(r<24)return r;if(r>26)throw new Error("Unsupported CBOR length");const n=1<<r-24;if(this.offset+n>this.data.length)throw new Error("Truncated CBOR");let o=0;for(let t=0;t<n;t++)o=256*o+this.data[this.offset++];return o}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class S extends o{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new y(t);if(2!==e.head(4)||24!==e.head(6))return null;const r=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const r of t){e^=r;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(r))return null;e.end();const n=new y(r);if(3!==n.head(4)||28!==n.bytes().length)return null;const o=n.head(5);if(o>r.length)return null;const i=new Set;let a="mainnet";for(let t=0;t<o;t++){const t=n.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=n.bytes();if(1===t){const t=new y(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new y(e);t.head(0),t.end(),a="testnet"}}const s=n.head(0);return 0!==s&&2!==s?null:(n.end(),a)}catch{return null}}(x(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=N(t,256),r=e&&k(e.data);if(!e||e.encoding!==w.BECH32||!r?.length)return this.invalid();const n=r[0]>>>4,o=15&r[0];if(0!==o&&1!==o)return this.invalid();const i=14===n||15===n,a=(i?"stake":"addr")+(0===o?"_test":"");if(e.hrp!==a)return this.invalid();let s=!1;return n<=3?s=57===r.length:6===n||7===n||i?s=29===r.length:4!==n&&5!==n||(s=this.validPointer(r)),s?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===o?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let r=0;r<3;r++){let r=0n;const n=e;do{if(e>=t.length||e-n>=10)return!1;r=r<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-n>1&&128===t[n]||r>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}format(t,e){return i(t,e,8)}}const U="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",D=U.charAt(0),R={};for(let t=0;t<58;t++)R[U.charAt(t)]=t;class H extends o{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:exports.ValidationError.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===D;)e++;const r=e,n=[0];for(;e<t.length;e++){const r=t[e],o=R[r];if(void 0===o)throw new Error(`Invalid Ripple Base58 character: ${r}`);for(let t=0;t<n.length;t++)n[t]*=58;n[0]+=o;let i=0;for(let t=0;t<n.length;++t)n[t]+=i,i=n[t]>>8,n[t]&=255;for(;i;)n.push(255&i),i>>=8}let o=[];t.length!==r&&(o=n.reverse());for(let t=0;t<r;t++)o.unshift(0);return new Uint8Array(o)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:exports.ValidationError.INVALID_LENGTH}};const r=e.slice(0,21),n=e.slice(21),o=g(r),i=g(o);return i[0]!==n[0]||i[1]!==n[1]||i[2]!==n[2]||i[3]!==n[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:exports.ValidationError.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:exports.ValidationError.INVALID_CHARACTERS}}}}}class B extends f{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain=this.chain),r}}class M extends o{validateImplementation(t){if(/^41[0-9a-fA-F]{40}$/.test(t))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const e=34===t.length&&t.startsWith("T")?E(t):null;return e&&21===e.length&&65===e[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}const O={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class F extends o{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(t){const e=N(t),r=e&&k(e.data),n="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===O[this.chain]&&e.encoding===w.BECH32&&r&&n.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}class $ extends o{validateImplementation(t){return/^0x[0-9a-fA-F]{64}$/.test(t)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}}class P extends o{validateImplementation(t,e){const r=/^0x[0-9a-fA-F]{64}$/.test(t),n=/^0x[0-9a-f]$/.test(t),o=n||/^0x[0-9a-f]{64}$/.test(t)&&!/^0x0{63}[0-9a-f]$/.test(t);return(e?.strict?o:r||n)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:exports.ValidationError.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let r=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(r)&&(r="0x"+r.slice(-1)),i(r,e)}}class z extends o{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:exports.ValidationError.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}const j=new Map;for(const e of t)j.set(e,"ethereum"===e?new f:new B(e));for(const t of e)j.set(t,new F(t));j.set("bitcoin",new L),j.set("litecoin",new T),j.set("dogecoin",new _),j.set("solana",new I),j.set("ripple",new H),j.set("cardano",new S),j.set("tron",new M),j.set("sui",new $),j.set("aptos",new P),j.set("near",new z);const W=Object.freeze([...j.keys()]);function G(t){const e=j.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}exports.AddressValidator=o,exports.AptosValidator=P,exports.ArbitrumValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="arbitrum"),r}},exports.AvalancheValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="avalanche"),r}},exports.BaseValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="base"),r}},exports.BitcoinValidator=L,exports.BscValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="bsc"),r}},exports.COSMOS_CHAINS=e,exports.CardanoValidator=S,exports.CosmosValidator=F,exports.DogecoinValidator=_,exports.EVM_CHAINS=t,exports.EthereumValidator=f,exports.EvmValidator=B,exports.LitecoinValidator=T,exports.NearValidator=z,exports.OptimismValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="optimism"),r}},exports.PolygonValidator=class extends f{validateImplementation(t,e){const r=super.validateImplementation(t,e);return r.valid&&(r.blockchain="polygon"),r}},exports.RippleValidator=H,exports.SUPPORTED_CHAINS=W,exports.SolanaValidator=I,exports.SuiValidator=$,exports.TronValidator=M,exports.addChecksum=function(e,r){return t.includes(r)?(new f).format(e,{checksum:!0}):n.sanitize(e)},exports.detectBlockchain=function(e,r){let o;try{o=n.sanitize(e)}catch{return null}if(!o)return null;const i=[];G("ethereum").validate(o,r).valid&&i.push(...t);for(const e of W)t.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(o)||/^[0-9a-f]{64}$/.test(o)||/^0[xs][0-9a-f]{40}$/.test(o)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(o))&&G(e).validate(o,r).valid&&i.push(e);return 0===i.length?null:1===i.length?i[0]:i},exports.formatAddress=function(t,e,r){return G(e).format(t,r)},exports.isSupportedChain=function(t){return"string"==typeof t&&j.has(t)},exports.normalizeAddress=function(e,r){const o=n.sanitize(e);return t.includes(r)||"sui"===r||"aptos"===r?o.toLowerCase():o},exports.shortenAddress=function(t,e=4){return i(t,{shorten:!0,shortenLength:e})},exports.validateAddress=function(t,e,r){return G(e).validate(t,r)},exports.validateBatch=function(t,e,r){const n=G(e);return t.map(t=>n.validate(t,r))};
@@ -0,0 +1,164 @@
1
+ declare const EVM_CHAINS: readonly ["ethereum", "polygon", "bsc", "avalanche", "arbitrum", "optimism", "base", "evm", "fantom", "sonic", "gnosis", "celo", "cronos", "moonbeam", "moonriver", "zksync", "linea", "scroll", "mantle", "blast", "opbnb", "zora", "worldchain"];
2
+ type EvmChain = typeof EVM_CHAINS[number];
3
+ declare const COSMOS_CHAINS: readonly ["cosmos", "osmosis", "celestia", "injective", "sei"];
4
+ type CosmosChain = typeof COSMOS_CHAINS[number];
5
+ type BlockchainType = EvmChain | CosmosChain | 'solana' | 'bitcoin' | 'litecoin' | 'dogecoin' | 'cardano' | 'ripple' | 'tron' | 'sui' | 'aptos' | 'near';
6
+ interface ValidationResult {
7
+ valid: boolean;
8
+ blockchain?: BlockchainType;
9
+ error?: string;
10
+ details?: {
11
+ format?: string;
12
+ network?: 'mainnet' | 'testnet';
13
+ checksum?: boolean;
14
+ errorCode?: ValidationError;
15
+ };
16
+ }
17
+ interface ValidationOptions {
18
+ strict?: boolean;
19
+ network?: 'mainnet' | 'testnet' | 'auto';
20
+ allowTestnet?: boolean;
21
+ allowBurnAddress?: boolean;
22
+ }
23
+ interface FormatOptions {
24
+ checksum?: boolean;
25
+ shorten?: boolean;
26
+ shortenLength?: number;
27
+ }
28
+ declare enum ValidationError {
29
+ INVALID_FORMAT = "INVALID_FORMAT",
30
+ INVALID_CHECKSUM = "INVALID_CHECKSUM",
31
+ INVALID_LENGTH = "INVALID_LENGTH",
32
+ INVALID_CHARACTERS = "INVALID_CHARACTERS",
33
+ UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
34
+ BURN_ADDRESS = "BURN_ADDRESS",
35
+ UNSAFE_INPUT = "UNSAFE_INPUT",
36
+ NETWORK_MISMATCH = "NETWORK_MISMATCH"
37
+ }
38
+
39
+ declare abstract class AddressValidator {
40
+ /**
41
+ * Validates an address.
42
+ * @param address - The address string to validate
43
+ * @param options - Validation options
44
+ */
45
+ validate(address: unknown, options?: ValidationOptions): ValidationResult;
46
+ protected abstract validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
47
+ format(address: string, options?: FormatOptions): string;
48
+ }
49
+
50
+ declare class EthereumValidator extends AddressValidator {
51
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
52
+ format(address: string, options?: FormatOptions): string;
53
+ private isChecksummed;
54
+ private toChecksumAddress;
55
+ }
56
+
57
+ declare class SolanaValidator extends AddressValidator {
58
+ protected validateImplementation(address: string): ValidationResult;
59
+ }
60
+
61
+ type Network = 'mainnet' | 'testnet';
62
+ interface UtxoConfig {
63
+ chain: BlockchainType;
64
+ versions: Readonly<Record<number, Network>>;
65
+ hrps?: Readonly<Record<string, Network>>;
66
+ }
67
+ /** Shared Base58Check and BIP-173/350 validation; versions are checked after decoding. */
68
+ declare class UtxoValidator extends AddressValidator {
69
+ private readonly config;
70
+ constructor(config: UtxoConfig);
71
+ protected validateImplementation(address: string): ValidationResult;
72
+ private validateWitness;
73
+ private invalid;
74
+ }
75
+
76
+ declare class BitcoinValidator extends UtxoValidator {
77
+ constructor();
78
+ }
79
+
80
+ declare class PolygonValidator extends EthereumValidator {
81
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
82
+ }
83
+
84
+ declare class LitecoinValidator extends UtxoValidator {
85
+ constructor();
86
+ }
87
+
88
+ declare class DogecoinValidator extends UtxoValidator {
89
+ constructor();
90
+ }
91
+
92
+ declare class CardanoValidator extends AddressValidator {
93
+ protected validateImplementation(address: string): ValidationResult;
94
+ private validateShelley;
95
+ private validPointer;
96
+ private invalid;
97
+ format(address: string, options?: FormatOptions): string;
98
+ }
99
+
100
+ declare class RippleValidator extends AddressValidator {
101
+ protected validateImplementation(address: string): ValidationResult;
102
+ }
103
+
104
+ declare class BscValidator extends EthereumValidator {
105
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
106
+ }
107
+ declare class AvalancheValidator extends EthereumValidator {
108
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
109
+ }
110
+ declare class ArbitrumValidator extends EthereumValidator {
111
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
112
+ }
113
+ declare class OptimismValidator extends EthereumValidator {
114
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
115
+ }
116
+ declare class BaseValidator extends EthereumValidator {
117
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
118
+ }
119
+ /** Use `evm` for any chain that uses standard Ethereum/EIP-55 account addresses. */
120
+ declare class EvmValidator extends EthereumValidator {
121
+ private readonly chain;
122
+ constructor(chain?: EvmChain);
123
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
124
+ }
125
+
126
+ /** Format candidates only: never use detection as proof of a destination's chain. */
127
+ declare function detectBlockchain(address: unknown, options?: ValidationOptions): BlockchainType | BlockchainType[] | null;
128
+
129
+ declare function shortenAddress(address: string, chars?: number): string;
130
+ declare function normalizeAddress(address: string, blockchain: BlockchainType): string;
131
+ declare function addChecksum(address: string, blockchain: BlockchainType): string;
132
+
133
+ declare const SUPPORTED_CHAINS: readonly BlockchainType[];
134
+ declare function isSupportedChain(chain: unknown): chain is BlockchainType;
135
+
136
+ declare class TronValidator extends AddressValidator {
137
+ protected validateImplementation(address: string): ValidationResult;
138
+ }
139
+
140
+ /** Account addresses only; validator/operator/consensus prefixes are deliberately excluded. */
141
+ declare class CosmosValidator extends AddressValidator {
142
+ private readonly chain;
143
+ constructor(chain?: CosmosChain);
144
+ protected validateImplementation(address: string): ValidationResult;
145
+ }
146
+
147
+ declare class SuiValidator extends AddressValidator {
148
+ protected validateImplementation(address: string): ValidationResult;
149
+ }
150
+ declare class AptosValidator extends AddressValidator {
151
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
152
+ format(address: string, options?: FormatOptions): string;
153
+ }
154
+
155
+ declare class NearValidator extends AddressValidator {
156
+ protected validateImplementation(address: string): ValidationResult;
157
+ }
158
+
159
+ declare function validateAddress(address: unknown, blockchain: BlockchainType, options?: ValidationOptions): ValidationResult;
160
+ declare function validateBatch(addresses: readonly unknown[], blockchain: BlockchainType, options?: ValidationOptions): ValidationResult[];
161
+ declare function formatAddress(address: string, blockchain: BlockchainType, options?: FormatOptions): string;
162
+
163
+ export { AddressValidator, AptosValidator, ArbitrumValidator, AvalancheValidator, BaseValidator, BitcoinValidator, BscValidator, COSMOS_CHAINS, CardanoValidator, CosmosValidator, DogecoinValidator, EVM_CHAINS, EthereumValidator, EvmValidator, LitecoinValidator, NearValidator, OptimismValidator, PolygonValidator, RippleValidator, SUPPORTED_CHAINS, SolanaValidator, SuiValidator, TronValidator, ValidationError, addChecksum, detectBlockchain, formatAddress, isSupportedChain, normalizeAddress, shortenAddress, validateAddress, validateBatch };
164
+ export type { BlockchainType, CosmosChain, EvmChain, FormatOptions, ValidationOptions, ValidationResult };
@@ -0,0 +1,164 @@
1
+ declare const EVM_CHAINS: readonly ["ethereum", "polygon", "bsc", "avalanche", "arbitrum", "optimism", "base", "evm", "fantom", "sonic", "gnosis", "celo", "cronos", "moonbeam", "moonriver", "zksync", "linea", "scroll", "mantle", "blast", "opbnb", "zora", "worldchain"];
2
+ type EvmChain = typeof EVM_CHAINS[number];
3
+ declare const COSMOS_CHAINS: readonly ["cosmos", "osmosis", "celestia", "injective", "sei"];
4
+ type CosmosChain = typeof COSMOS_CHAINS[number];
5
+ type BlockchainType = EvmChain | CosmosChain | 'solana' | 'bitcoin' | 'litecoin' | 'dogecoin' | 'cardano' | 'ripple' | 'tron' | 'sui' | 'aptos' | 'near';
6
+ interface ValidationResult {
7
+ valid: boolean;
8
+ blockchain?: BlockchainType;
9
+ error?: string;
10
+ details?: {
11
+ format?: string;
12
+ network?: 'mainnet' | 'testnet';
13
+ checksum?: boolean;
14
+ errorCode?: ValidationError;
15
+ };
16
+ }
17
+ interface ValidationOptions {
18
+ strict?: boolean;
19
+ network?: 'mainnet' | 'testnet' | 'auto';
20
+ allowTestnet?: boolean;
21
+ allowBurnAddress?: boolean;
22
+ }
23
+ interface FormatOptions {
24
+ checksum?: boolean;
25
+ shorten?: boolean;
26
+ shortenLength?: number;
27
+ }
28
+ declare enum ValidationError {
29
+ INVALID_FORMAT = "INVALID_FORMAT",
30
+ INVALID_CHECKSUM = "INVALID_CHECKSUM",
31
+ INVALID_LENGTH = "INVALID_LENGTH",
32
+ INVALID_CHARACTERS = "INVALID_CHARACTERS",
33
+ UNSUPPORTED_CHAIN = "UNSUPPORTED_CHAIN",
34
+ BURN_ADDRESS = "BURN_ADDRESS",
35
+ UNSAFE_INPUT = "UNSAFE_INPUT",
36
+ NETWORK_MISMATCH = "NETWORK_MISMATCH"
37
+ }
38
+
39
+ declare abstract class AddressValidator {
40
+ /**
41
+ * Validates an address.
42
+ * @param address - The address string to validate
43
+ * @param options - Validation options
44
+ */
45
+ validate(address: unknown, options?: ValidationOptions): ValidationResult;
46
+ protected abstract validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
47
+ format(address: string, options?: FormatOptions): string;
48
+ }
49
+
50
+ declare class EthereumValidator extends AddressValidator {
51
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
52
+ format(address: string, options?: FormatOptions): string;
53
+ private isChecksummed;
54
+ private toChecksumAddress;
55
+ }
56
+
57
+ declare class SolanaValidator extends AddressValidator {
58
+ protected validateImplementation(address: string): ValidationResult;
59
+ }
60
+
61
+ type Network = 'mainnet' | 'testnet';
62
+ interface UtxoConfig {
63
+ chain: BlockchainType;
64
+ versions: Readonly<Record<number, Network>>;
65
+ hrps?: Readonly<Record<string, Network>>;
66
+ }
67
+ /** Shared Base58Check and BIP-173/350 validation; versions are checked after decoding. */
68
+ declare class UtxoValidator extends AddressValidator {
69
+ private readonly config;
70
+ constructor(config: UtxoConfig);
71
+ protected validateImplementation(address: string): ValidationResult;
72
+ private validateWitness;
73
+ private invalid;
74
+ }
75
+
76
+ declare class BitcoinValidator extends UtxoValidator {
77
+ constructor();
78
+ }
79
+
80
+ declare class PolygonValidator extends EthereumValidator {
81
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
82
+ }
83
+
84
+ declare class LitecoinValidator extends UtxoValidator {
85
+ constructor();
86
+ }
87
+
88
+ declare class DogecoinValidator extends UtxoValidator {
89
+ constructor();
90
+ }
91
+
92
+ declare class CardanoValidator extends AddressValidator {
93
+ protected validateImplementation(address: string): ValidationResult;
94
+ private validateShelley;
95
+ private validPointer;
96
+ private invalid;
97
+ format(address: string, options?: FormatOptions): string;
98
+ }
99
+
100
+ declare class RippleValidator extends AddressValidator {
101
+ protected validateImplementation(address: string): ValidationResult;
102
+ }
103
+
104
+ declare class BscValidator extends EthereumValidator {
105
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
106
+ }
107
+ declare class AvalancheValidator extends EthereumValidator {
108
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
109
+ }
110
+ declare class ArbitrumValidator extends EthereumValidator {
111
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
112
+ }
113
+ declare class OptimismValidator extends EthereumValidator {
114
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
115
+ }
116
+ declare class BaseValidator extends EthereumValidator {
117
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
118
+ }
119
+ /** Use `evm` for any chain that uses standard Ethereum/EIP-55 account addresses. */
120
+ declare class EvmValidator extends EthereumValidator {
121
+ private readonly chain;
122
+ constructor(chain?: EvmChain);
123
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
124
+ }
125
+
126
+ /** Format candidates only: never use detection as proof of a destination's chain. */
127
+ declare function detectBlockchain(address: unknown, options?: ValidationOptions): BlockchainType | BlockchainType[] | null;
128
+
129
+ declare function shortenAddress(address: string, chars?: number): string;
130
+ declare function normalizeAddress(address: string, blockchain: BlockchainType): string;
131
+ declare function addChecksum(address: string, blockchain: BlockchainType): string;
132
+
133
+ declare const SUPPORTED_CHAINS: readonly BlockchainType[];
134
+ declare function isSupportedChain(chain: unknown): chain is BlockchainType;
135
+
136
+ declare class TronValidator extends AddressValidator {
137
+ protected validateImplementation(address: string): ValidationResult;
138
+ }
139
+
140
+ /** Account addresses only; validator/operator/consensus prefixes are deliberately excluded. */
141
+ declare class CosmosValidator extends AddressValidator {
142
+ private readonly chain;
143
+ constructor(chain?: CosmosChain);
144
+ protected validateImplementation(address: string): ValidationResult;
145
+ }
146
+
147
+ declare class SuiValidator extends AddressValidator {
148
+ protected validateImplementation(address: string): ValidationResult;
149
+ }
150
+ declare class AptosValidator extends AddressValidator {
151
+ protected validateImplementation(address: string, options?: ValidationOptions): ValidationResult;
152
+ format(address: string, options?: FormatOptions): string;
153
+ }
154
+
155
+ declare class NearValidator extends AddressValidator {
156
+ protected validateImplementation(address: string): ValidationResult;
157
+ }
158
+
159
+ declare function validateAddress(address: unknown, blockchain: BlockchainType, options?: ValidationOptions): ValidationResult;
160
+ declare function validateBatch(addresses: readonly unknown[], blockchain: BlockchainType, options?: ValidationOptions): ValidationResult[];
161
+ declare function formatAddress(address: string, blockchain: BlockchainType, options?: FormatOptions): string;
162
+
163
+ export { AddressValidator, AptosValidator, ArbitrumValidator, AvalancheValidator, BaseValidator, BitcoinValidator, BscValidator, COSMOS_CHAINS, CardanoValidator, CosmosValidator, DogecoinValidator, EVM_CHAINS, EthereumValidator, EvmValidator, LitecoinValidator, NearValidator, OptimismValidator, PolygonValidator, RippleValidator, SUPPORTED_CHAINS, SolanaValidator, SuiValidator, TronValidator, ValidationError, addChecksum, detectBlockchain, formatAddress, isSupportedChain, normalizeAddress, shortenAddress, validateAddress, validateBatch };
164
+ export type { BlockchainType, CosmosChain, EvmChain, FormatOptions, ValidationOptions, ValidationResult };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ const t=Object.freeze(["ethereum","polygon","bsc","avalanche","arbitrum","optimism","base","evm","fantom","sonic","gnosis","celo","cronos","moonbeam","moonriver","zksync","linea","scroll","mantle","blast","opbnb","zora","worldchain"]),e=Object.freeze(["cosmos","osmosis","celestia","injective","sei"]);var n;!function(t){t.INVALID_FORMAT="INVALID_FORMAT",t.INVALID_CHECKSUM="INVALID_CHECKSUM",t.INVALID_LENGTH="INVALID_LENGTH",t.INVALID_CHARACTERS="INVALID_CHARACTERS",t.UNSUPPORTED_CHAIN="UNSUPPORTED_CHAIN",t.BURN_ADDRESS="BURN_ADDRESS",t.UNSAFE_INPUT="UNSAFE_INPUT",t.NETWORK_MISMATCH="NETWORK_MISMATCH"}(n||(n={}));class r{static sanitize(t){if(null==t)throw new Error(n.UNSAFE_INPUT);if("string"!=typeof t)throw new Error(n.UNSAFE_INPUT);if(t.length>256)throw new Error(n.UNSAFE_INPUT);if(/[^\x20-\x7E]/.test(t))throw new Error(n.UNSAFE_INPUT);return t.trim()}}class s{validate(t,e){try{const s=r.sanitize(t),i=this.validateImplementation(s,e),a=i.details?.network;return i.valid&&a&&(e?.network&&"auto"!==e.network&&e.network!==a||!1===e?.allowTestnet&&"testnet"===a)?{valid:!1,error:"Address network does not match the requested network",details:{...i.details,errorCode:n.NETWORK_MISMATCH}}:i}catch(t){const e=t instanceof Error?t.message:String(t);return e===n.UNSAFE_INPUT?{valid:!1,error:"Unsafe input detected",details:{errorCode:n.UNSAFE_INPUT}}:{valid:!1,error:e,details:{errorCode:n.INVALID_FORMAT}}}}format(t,e){return i(t,e)}}function i(t,e,n=4){const s=r.sanitize(t);if(!e?.shorten)return s;const i=e.shortenLength??n;if(!Number.isSafeInteger(i)||i<1)throw new RangeError("shortenLength must be a positive integer");const a=s.startsWith("0x")?2:0;return s.length<=2*i+a+3?s:`${s.slice(0,i+a)}...${s.slice(-i)}`}function a(t){return t.startsWith("0x")?t.slice(2):t}function o(t){return t.startsWith("0x")?t:`0x${t}`}const l=(1n<<64n)-1n,c=[0,1,62,28,27,36,44,6,55,20,3,10,43,25,39,41,45,15,21,8,18,2,61,56,14],d=[0x0000000000000001n,0x0000000000008082n,0x800000000000808an,0x8000000080008000n,0x000000000000808bn,0x0000000080000001n,0x8000000080008081n,0x8000000000008009n,0x000000000000008an,0x0000000000000088n,0x0000000080008009n,0x000000008000000an,0x000000008000808bn,0x800000000000008bn,0x8000000000008089n,0x8000000000008003n,0x8000000000008002n,0x8000000000000080n,0x000000000000800an,0x800000008000000an,0x8000000080008081n,0x8000000000008080n,0x0000000080000001n,0x8000000080008008n];function h(t,e){return(t<<BigInt(e)|t>>BigInt(64-e))&l}function u(t){const e=new Array(5),n=new Array(25);for(const r of d){for(let n=0;n<5;n++)e[n]=t[n]^t[n+5]^t[n+10]^t[n+15]^t[n+20];for(let n=0;n<5;n++){const r=e[(n+4)%5]^h(e[(n+1)%5],1);for(let e=0;e<5;e++)t[n+5*e]^=r}for(let e=0;e<5;e++)for(let r=0;r<5;r++)n[r+(2*e+3*r)%5*5]=h(t[e+5*r],c[e+5*r]);for(let e=0;e<5;e++)for(let r=0;r<5;r++)t[e+5*r]=n[e+5*r]^~n[(e+1)%5+5*r]&n[(e+2)%5+5*r];t[0]^=r}}class f extends s{validateImplementation(t,e){const r=a(t);if(40!==r.length)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};if(!function(t){if("string"!=typeof t)return!1;const e=t.startsWith("0x")?t.slice(2):t;return/^[0-9a-fA-F]*$/.test(e)}(r))return{valid:!1,error:"Invalid hex characters",details:{errorCode:n.INVALID_CHARACTERS}};if(!e?.allowBurnAddress&&/^0+$/.test(r))return{valid:!1,error:"Burn address detected",details:{errorCode:n.BURN_ADDRESS}};const s=this.isChecksummed(r);return(e?.strict||r!==r.toLowerCase()&&r!==r.toUpperCase())&&!s?{valid:!1,error:"Invalid checksum",details:{errorCode:n.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ethereum",details:{checksum:s}}}format(t,e){let n=o(r.sanitize(t));return e?.checksum&&(n=this.toChecksumAddress(n)),i(n,e)}isChecksummed(t){const e=a(t);return o(e)===this.toChecksumAddress(e)}toChecksumAddress(t){const e=a(t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(e))throw new Error("Expected a 20-byte hexadecimal address");const n=function(t){const e=(new TextEncoder).encode(t),n=new Uint8Array(136*(Math.floor(e.length/136)+1));n.set(e),n[e.length]=1,n[n.length-1]|=128;const r=new Array(25).fill(0n);for(let t=0;t<n.length;t+=136){for(let e=0;e<136;e++)r[e>>3]^=BigInt(n[t+e])<<BigInt(8*(7&e));u(r)}let s="";for(let t=0;t<32;t++)s+=Number(r[t>>3]>>BigInt(8*(7&t))&255n).toString(16).padStart(2,"0");return s}(e);return"0x"+[...e].map((t,e)=>parseInt(n[e],16)>=8?t.toUpperCase():t).join("")}}const v="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",m=v.charAt(0),I={};for(let t=0;t<58;t++)I[v.charAt(t)]=t;function g(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===m;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],s=I[n];if(void 0===s)throw new Error(`Invalid Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=s;let i=0;for(let t=0;t<r.length;++t)r[t]+=i,i=r[t]>>8,r[t]&=255;for(;i;)r.push(255&i),i>>=8}const s=t.length===n?[]:r.reverse();return Uint8Array.from([...new Array(n).fill(0),...s])}class p extends s{validateImplementation(t){if(t.length<32||t.length>44)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};try{if(32!==g(t).length)return{valid:!1,error:"Invalid public key length",details:{errorCode:n.INVALID_LENGTH}}}catch{return{valid:!1,error:"Invalid Base58 characters",details:{errorCode:n.INVALID_FORMAT}}}return"11111111111111111111111111111111"===t?{valid:!0,blockchain:"solana",details:{format:"System Program"}}:{valid:!0,blockchain:"solana"}}}function A(t){const e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],r=8*t.length,s=t.length,i=new Uint8Array(64-(s+8)%64+8);i[0]=128;const a=r,o=Math.floor(a/4294967296),l=a%4294967296,c=i.length;i[c-4]=l>>>24&255,i[c-3]=l>>>16&255,i[c-2]=l>>>8&255,i[c-1]=255&l,i[c-8]=o>>>24&255,i[c-7]=o>>>16&255,i[c-6]=o>>>8&255,i[c-5]=255&o;const d=new Uint8Array(s+i.length);d.set(t),d.set(i,s);const h=new Uint32Array(64);for(let t=0;t<d.length;t+=64){for(let e=0;e<16;e++)h[e]=d[t+4*e]<<24|d[t+4*e+1]<<16|d[t+4*e+2]<<8|d[t+4*e+3];for(let t=16;t<64;t++){const e=w(h[t-2],17)^w(h[t-2],19)^h[t-2]>>>10,n=w(h[t-15],7)^w(h[t-15],18)^h[t-15]>>>3;h[t]=e+h[t-7]+n+h[t-16]|0}let r=n[0],s=n[1],i=n[2],a=n[3],o=n[4],l=n[5],c=n[6],u=n[7];for(let t=0;t<64;t++){const n=u+(w(o,6)^w(o,11)^w(o,25))+(o&l^~o&c)+e[t]+h[t]|0,d=r&s^r&i^s&i;u=c,c=l,l=o,o=a+n|0,a=i,i=s,s=r,r=n+((w(r,2)^w(r,13)^w(r,22))+d|0)|0}n[0]=n[0]+r|0,n[1]=n[1]+s|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+o|0,n[5]=n[5]+l|0,n[6]=n[6]+c|0,n[7]=n[7]+u|0}const u=new Uint8Array(32);for(let t=0;t<8;t++)u[4*t]=n[t]>>>24&255,u[4*t+1]=n[t]>>>16&255,u[4*t+2]=n[t]>>>8&255,u[4*t+3]=255&n[t];return u}function w(t,e){return t>>>e|t<<32-e}function C(t){try{const e=g(t);if(e.length<5)return null;const n=e.slice(0,-4),r=A(A(n));return e.slice(-4).every((t,e)=>t===r[e])?n:null}catch{return null}}var x;!function(t){t.BECH32="bech32",t.BECH32M="bech32m"}(x||(x={}));const N=[996825010,642813549,513874426,1027748829,705979059];function E(t,e,n){const r=n===x.BECH32M?734539939:1;return function(t){let e=1;for(const n of t){const t=e>>25;e=(33554431&e)<<5^n;for(let n=0;n<5;n++)t>>n&1&&(e^=N[n])}return e}(function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n)>>5);e.push(0);for(let n=0;n<t.length;n++)e.push(31&t.charCodeAt(n));return e}(t).concat(e))===r}function k(t,e=90){if(t.length<8||t.length>e)return null;const n=t.toLowerCase();if(t!==n&&t!==t.toUpperCase())return null;const r=n.lastIndexOf("1");if(r<1||r+7>n.length)return null;const s=n.substring(0,r);if(/[^\x21-\x7E]/.test(s))return null;const i=[];for(let t=r+1;t<n.length;t++){const e="qpzry9x8gf2tvdw0s3jn54khce6mua7l".indexOf(n[t]);if(-1===e)return null;i.push(e)}return E(s,i,x.BECH32)?{hrp:s,data:i.slice(0,i.length-6),encoding:x.BECH32}:E(s,i,x.BECH32M)?{hrp:s,data:i.slice(0,i.length-6),encoding:x.BECH32M}:null}function b(t){let e=0,n=0;const r=[];for(const s of t){if(!Number.isInteger(s)||s<0||s>31)return null;e=65535&(e<<5|s),n+=5,n>=8&&(n-=8,r.push(e>>>n&255))}return n>=5||e<<8-n&255?null:Uint8Array.from(r)}class L extends s{constructor(t){super(),this.config=t}validateImplementation(t){const e=t.toLowerCase().split("1")[0];if(this.config.hrps&&Object.prototype.hasOwnProperty.call(this.config.hrps,e))return this.validateWitness(t,this.config.hrps[e]);if(t.length<26||t.length>35)return this.invalid("Invalid address length",n.INVALID_LENGTH);const r=C(t);if(!r)return this.invalid("Invalid Base58Check address",n.INVALID_CHECKSUM);if(21!==r.length)return this.invalid("Invalid payload length",n.INVALID_LENGTH);const s=this.config.versions[r[0]];return s?{valid:!0,blockchain:this.config.chain,details:{format:"legacy",network:s,checksum:!0}}:this.invalid("Invalid address version")}validateWitness(t,e){const r=k(t);if(!r||0===r.data.length)return this.invalid("Invalid Bech32 encoding");const s=r.data[0],i=b(r.data.slice(1));if(s>16)return this.invalid("Invalid witness version");if(!i||i.length<2||i.length>40||0===s&&20!==i.length&&32!==i.length)return this.invalid("Invalid witness program or padding",n.INVALID_LENGTH);const a=0===s?x.BECH32:x.BECH32M;if(r.encoding!==a)return this.invalid("Wrong checksum encoding for witness version",n.INVALID_CHECKSUM);const o=0===s?"segwit":1===s&&32===i.length?"taproot":"future";return{valid:!0,blockchain:this.config.chain,details:{format:o,network:e,checksum:!0}}}invalid(t,e=n.INVALID_FORMAT){return{valid:!1,error:t,details:{errorCode:e}}}}class T extends L{constructor(){super({chain:"bitcoin",versions:{0:"mainnet",5:"mainnet",111:"testnet",196:"testnet"},hrps:{bc:"mainnet",tb:"testnet"}})}}class y extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="polygon"),n}}class _ extends L{constructor(){super({chain:"litecoin",versions:{48:"mainnet",50:"mainnet",5:"mainnet",111:"testnet",58:"testnet",196:"testnet"},hrps:{ltc:"mainnet",tltc:"testnet"}})}}class U extends L{constructor(){super({chain:"dogecoin",versions:{30:"mainnet",22:"mainnet",113:"testnet",196:"testnet"}})}}class D{constructor(t){this.data=t,this.offset=0}head(t){if(this.offset>=this.data.length)throw new Error("Truncated CBOR");const e=this.data[this.offset++];if(e>>>5!==t)throw new Error("Invalid CBOR type");const n=31&e;if(n<24)return n;if(n>26)throw new Error("Unsupported CBOR length");const r=1<<n-24;if(this.offset+r>this.data.length)throw new Error("Truncated CBOR");let s=0;for(let t=0;t<r;t++)s=256*s+this.data[this.offset++];return s}bytes(){const t=this.head(2);if(this.offset+t>this.data.length)throw new Error("Truncated bytes");const e=this.data.slice(this.offset,this.offset+t);return this.offset+=t,e}end(){if(this.offset!==this.data.length)throw new Error("Trailing CBOR data")}}class R extends s{validateImplementation(t){if(/^(addr|stake)(_test)?1/i.test(t))return this.validateShelley(t);try{const e=function(t){try{const e=new D(t);if(2!==e.head(4)||24!==e.head(6))return null;const n=e.bytes();if(e.head(0)!==function(t){let e=4294967295;for(const n of t){e^=n;for(let t=0;t<8;t++)e=e>>>1^(1&e?3988292384:0)}return(4294967295^e)>>>0}(n))return null;e.end();const r=new D(n);if(3!==r.head(4)||28!==r.bytes().length)return null;const s=r.head(5);if(s>n.length)return null;const i=new Set;let a="mainnet";for(let t=0;t<s;t++){const t=r.head(0);if(i.has(t)||t>255)return null;i.add(t);const e=r.bytes();if(1===t){const t=new D(e);if(28!==t.bytes().length)return null;t.end()}if(2===t){const t=new D(e);t.head(0),t.end(),a="testnet"}}const o=r.head(0);return 0!==o&&2!==o?null:(r.end(),a)}catch{return null}}(g(t));if(e)return{valid:!0,blockchain:"cardano",details:{format:"byron",network:e,checksum:!0}}}catch{}return this.invalid()}validateShelley(t){const e=k(t,256),n=e&&b(e.data);if(!e||e.encoding!==x.BECH32||!n?.length)return this.invalid();const r=n[0]>>>4,s=15&n[0];if(0!==s&&1!==s)return this.invalid();const i=14===r||15===r,a=(i?"stake":"addr")+(0===s?"_test":"");if(e.hrp!==a)return this.invalid();let o=!1;return r<=3?o=57===n.length:6===r||7===r||i?o=29===n.length:4!==r&&5!==r||(o=this.validPointer(n)),o?{valid:!0,blockchain:"cardano",details:{format:i?"stake":"shelley",network:1===s?"mainnet":"testnet",checksum:!0}}:this.invalid()}validPointer(t){let e=29;for(let n=0;n<3;n++){let n=0n;const r=e;do{if(e>=t.length||e-r>=10)return!1;n=n<<7n|BigInt(127&t[e])}while(128&t[e++]);if(e-r>1&&128===t[r]||n>0xffffffffffffffffn)return!1}return e===t.length}invalid(){return{valid:!1,error:"Invalid Cardano address structure, network, or checksum",details:{errorCode:n.INVALID_FORMAT}}}format(t,e){return i(t,e,8)}}const S="rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",H=S.charAt(0),M={};for(let t=0;t<58;t++)M[S.charAt(t)]=t;class B extends s{validateImplementation(t){if(!t.startsWith("r"))return{valid:!1,error:"Must start with r",details:{errorCode:n.INVALID_FORMAT}};if(t.length<25||t.length>35)return{valid:!1,error:"Invalid length",details:{errorCode:n.INVALID_LENGTH}};try{const e=function(t){if(0===t.length)return new Uint8Array(0);let e=0;for(;e<t.length&&t[e]===H;)e++;const n=e,r=[0];for(;e<t.length;e++){const n=t[e],s=M[n];if(void 0===s)throw new Error(`Invalid Ripple Base58 character: ${n}`);for(let t=0;t<r.length;t++)r[t]*=58;r[0]+=s;let i=0;for(let t=0;t<r.length;++t)r[t]+=i,i=r[t]>>8,r[t]&=255;for(;i;)r.push(255&i),i>>=8}let s=[];t.length!==n&&(s=r.reverse());for(let t=0;t<n;t++)s.unshift(0);return new Uint8Array(s)}(t);if(25!==e.length||0!==e[0])return{valid:!1,error:"Invalid decoded length",details:{errorCode:n.INVALID_LENGTH}};const r=e.slice(0,21),s=e.slice(21),i=A(r),a=A(i);return a[0]!==s[0]||a[1]!==s[1]||a[2]!==s[2]||a[3]!==s[3]?{valid:!1,error:"Invalid checksum",details:{errorCode:n.INVALID_CHECKSUM}}:{valid:!0,blockchain:"ripple"}}catch{return{valid:!1,error:"Invalid characters",details:{errorCode:n.INVALID_CHARACTERS}}}}}class V extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="bsc"),n}}class O extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="avalanche"),n}}class F extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="arbitrum"),n}}class $ extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="optimism"),n}}class z extends f{validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain="base"),n}}class P extends f{constructor(t="evm"){super(),this.chain=t}validateImplementation(t,e){const n=super.validateImplementation(t,e);return n.valid&&(n.blockchain=this.chain),n}}class j extends s{validateImplementation(t){if(/^41[0-9a-fA-F]{40}$/.test(t))return{valid:!0,blockchain:"tron",details:{format:"hex",checksum:!1}};const e=34===t.length&&t.startsWith("T")?C(t):null;return e&&21===e.length&&65===e[0]?{valid:!0,blockchain:"tron",details:{format:"base58check",checksum:!0}}:{valid:!1,error:"Invalid TRON address",details:{errorCode:n.INVALID_FORMAT}}}}const W={cosmos:"cosmos",osmosis:"osmo",celestia:"celestia",injective:"inj",sei:"sei"};class G extends s{constructor(t="cosmos"){super(),this.chain=t}validateImplementation(t){const e=k(t),r=e&&b(e.data),s="injective"===this.chain||"celestia"===this.chain?[20]:[20,32];return e&&e.hrp===W[this.chain]&&e.encoding===x.BECH32&&r&&s.includes(r.length)?{valid:!0,blockchain:this.chain,details:{format:"bech32",checksum:!0}}:{valid:!1,error:"Invalid account prefix, checksum, length, or padding",details:{errorCode:n.INVALID_FORMAT}}}}class K extends s{validateImplementation(t){return/^0x[0-9a-fA-F]{64}$/.test(t)?{valid:!0,blockchain:"sui",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Expected 0x followed by 64 hex digits",details:{errorCode:n.INVALID_FORMAT}}}}class q extends s{validateImplementation(t,e){const r=/^0x[0-9a-fA-F]{64}$/.test(t),s=/^0x[0-9a-f]$/.test(t),i=s||/^0x[0-9a-f]{64}$/.test(t)&&!/^0x0{63}[0-9a-f]$/.test(t);return(e?.strict?i:r||s)?{valid:!0,blockchain:"aptos",details:{format:"hex",checksum:!1}}:{valid:!1,error:"Invalid Aptos address (AIP-40)",details:{errorCode:n.INVALID_FORMAT}}}format(t,e){if(!this.validate(t).valid)throw new Error("Invalid Aptos address");let n=t.trim().toLowerCase();return/^0x0{63}[0-9a-f]$/.test(n)&&(n="0x"+n.slice(-1)),i(n,e)}}class J extends s{validateImplementation(t){if(t.length<2||t.length>64||!/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(t))return{valid:!1,error:"Invalid NEAR account ID",details:{errorCode:n.INVALID_FORMAT}};return{valid:!0,blockchain:"near",details:{format:/^[0-9a-f]{64}$/.test(t)||/^0x[0-9a-f]{40}$/.test(t)?"implicit":/^0s[0-9a-f]{40}$/.test(t)?"deterministic":/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(t)?"universal":"named",checksum:!1}}}}const Q=new Map;for(const e of t)Q.set(e,"ethereum"===e?new f:new P(e));for(const t of e)Q.set(t,new G(t));Q.set("bitcoin",new T),Q.set("litecoin",new _),Q.set("dogecoin",new U),Q.set("solana",new p),Q.set("ripple",new B),Q.set("cardano",new R),Q.set("tron",new j),Q.set("sui",new K),Q.set("aptos",new q),Q.set("near",new J);const X=Object.freeze([...Q.keys()]);function Y(t){return"string"==typeof t&&Q.has(t)}function Z(t){const e=Q.get(t);if(!e)throw new Error(`Unsupported blockchain: ${String(t)}`);return e}function tt(e,n){let s;try{s=r.sanitize(e)}catch{return null}if(!s)return null;const i=[];Z("ethereum").validate(s,n).valid&&i.push(...t);for(const e of X)t.includes(e)||("near"!==e||/(\.near|\.testnet)$/.test(s)||/^[0-9a-f]{64}$/.test(s)||/^0[xs][0-9a-f]{40}$/.test(s)||/^0u[0-9a-hjkmnp-tv-z]{51}[0g]$/.test(s))&&Z(e).validate(s,n).valid&&i.push(e);return 0===i.length?null:1===i.length?i[0]:i}function et(t,e=4){return i(t,{shorten:!0,shortenLength:e})}function nt(e,n){const s=r.sanitize(e);return t.includes(n)||"sui"===n||"aptos"===n?s.toLowerCase():s}function rt(e,n){return t.includes(n)?(new f).format(e,{checksum:!0}):r.sanitize(e)}function st(t,e,n){return Z(e).validate(t,n)}function it(t,e,n){const r=Z(e);return t.map(t=>r.validate(t,n))}function at(t,e,n){return Z(e).format(t,n)}export{s as AddressValidator,q as AptosValidator,F as ArbitrumValidator,O as AvalancheValidator,z as BaseValidator,T as BitcoinValidator,V as BscValidator,e as COSMOS_CHAINS,R as CardanoValidator,G as CosmosValidator,U as DogecoinValidator,t as EVM_CHAINS,f as EthereumValidator,P as EvmValidator,_ as LitecoinValidator,J as NearValidator,$ as OptimismValidator,y as PolygonValidator,B as RippleValidator,X as SUPPORTED_CHAINS,p as SolanaValidator,K as SuiValidator,j as TronValidator,n as ValidationError,rt as addChecksum,tt as detectBlockchain,at as formatAddress,Y as isSupportedChain,nt as normalizeAddress,et as shortenAddress,st as validateAddress,it as validateBatch};