UNPKG

@hanchon/ethermint-address-converter

Version:

Converter between ETH and Ethermint addresses

3 lines (2 loc) 1.33 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("crypto-addr-codec"),require("bech32")):"function"==typeof define&&define.amd?define(["exports","crypto-addr-codec","bech32"],r):r((e||self).ethermintAddressConverter={},e.cryptoAddrCodec,e.bech32)}(this,function(e,r,o){const d={decoder:e=>{const o=r.stripHexPrefix(e);if(!r.isValidChecksumAddress(e,null)&&o!==o.toLowerCase()&&o!==o.toUpperCase())throw Error("Invalid address checksum");return Buffer.from(r.stripHexPrefix(e),"hex")},encoder:e=>r.toChecksumAddress(e.toString("hex"),null),name:"ETH"};function t(e){return r=>o.encode(e,o.toWords(r))}const n=(e,r)=>{return{decoder:(d=r,e=>{const{prefix:r,words:t}=o.decode(e);if(r!==d)throw Error("Unrecognised address format");return Buffer.from(o.fromWords(t))}),encoder:t(r),name:e};var d},c=n("ETHERMINT","ethm"),s=n("EVMOS","evmos"),i=n("REBUS","rebus");e.ETH=d,e.ETHERMINT=c,e.EVMOS=s,e.REBUS=i,e.ethToEthermint=e=>{let r=d.decoder(e);return c.encoder(r)},e.ethToEvmos=e=>{let r=d.decoder(e);return s.encoder(r)},e.ethToRebus=e=>{let r=d.decoder(e);return i.encoder(r)},e.ethermintToEth=e=>{let r=c.decoder(e);return d.encoder(r)},e.evmosToEth=e=>{let r=s.decoder(e);return d.encoder(r)},e.rebusToEth=e=>{let r=i.decoder(e);return d.encoder(r)}}); //# sourceMappingURL=converter.umd.js.map