diff --git a/README.md b/README.md index 0b20f6b1..a6621d59 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,27 @@ const encodedAddress = btcCoder.encode(decodedAddress); // 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa ``` +### Hex String Encoding + +If the data you are encoding is a hex string rather than `Uint8Array`, you can use the included `hexToBytes()` to convert it to the correct type. + +```ts +import { getCoderByCoinName } from "@ensdomains/address-encoder"; +import { hexToBytes } from "@ensdomains/address-encoder/utils"; + +const btcCoder = getCoderByCoinName("btc"); + +// Convert hex encoded data to bytes +const dataAsBytes = hexToBytes( + "0x76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac" +); +// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ] + +// Pass bytes to encoder +const encodedAddress = btcCoder.encode(decodedAddress); +// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa +``` + ## Supported Cryptocurrencies To view all the supported cryptocurrencies of this library, see [here](https://github.com/ensdomains/address-encoder/blob/master/docs/supported-cryptocurrencies.md). @@ -45,7 +66,7 @@ To view all the supported cryptocurrencies of this library, see [here](https://g ```ts import { getCoderByCoinNameAsync } from "@ensdomains/address-encoder/async"; -const btcCoder = await getCoderByCoinName("btc"); +const btcCoder = await getCoderByCoinNameAsync("btc"); ``` ### Individual Coin Imports diff --git a/bun.lockb b/bun.lockb index fa0c4683..d3a18ba5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 547a10f4..5dd03270 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,7 @@ "bun-types": "1.0.22", "fs-extra": "^11.1.1", "mitata": "^0.1.6", + "ts-arithmetic": "^0.1.1", "typescript": "^5.1.6" }, "dependencies": { diff --git a/scripts/addEvmCoin.ts b/scripts/addEvmCoin.ts new file mode 100644 index 00000000..01dd94a9 --- /dev/null +++ b/scripts/addEvmCoin.ts @@ -0,0 +1,92 @@ +import * as readline from "readline"; +import { coinTypeToEvmChainId } from "../src/utils/evm.js"; + +const SLIP44_MSB = 0x80000000; +const evmChainIdToCoinType = (chainId: number) => { + if (chainId >= SLIP44_MSB) throw new Error("Invalid chainId"); + return (SLIP44_MSB | chainId) >>> 0; +}; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); +const questionAsync = (question: string) => + new Promise((resolve) => { + rl.question(question, (answer) => { + resolve(answer); + }); + }); + +let newCoins: [string, [string, string]][] = []; + +async function addEvmCoin() { + const coinSymbol_ = await questionAsync("Coin Symbol: "); + const coinName_ = await questionAsync("Coin Name: "); + const chainId = await questionAsync("Chain ID: ").then((ans) => + parseInt(ans) + ); + + const coinName = coinName_.trim(); + const coinSymbol = coinSymbol_.toLowerCase().trim(); + + newCoins.push([`${evmChainIdToCoinType(chainId)}`, [coinSymbol, coinName]]); + + const runAgain = await questionAsync("Add another coin? (y/n): ").then( + (ans) => ans.toLowerCase() === "y" + ); + + if (runAgain) return addEvmCoin(); +} + +await addEvmCoin(); + +console.log("Adding new coins:", newCoins.map(([, [c]]) => c).join(", ")); + +const { evmCoinTypeToNameMap, nonEvmCoinTypeToNameMap } = await import( + "../src/consts/coinTypeToNameMap.js" +); + +const evmCoinsWithNew = [ + ...Object.entries(evmCoinTypeToNameMap), + ...newCoins, +].sort(([a], [b]) => parseInt(a) - parseInt(b)); + +const evmCoinTypeToNameMapString = `export const evmCoinTypeToNameMap = Object.freeze({ +${evmCoinsWithNew + .map( + ([ + coinType, + [coinSymbol, coinName], + ]) => ` /* Chain ID: ${coinTypeToEvmChainId(parseInt(coinType))} */ + "${coinType}": ["${coinSymbol}", "${coinName}"],` + ) + .join("\n")} +} as const);`; + +const nonEvmCoinTypeToNameMapString = `export const nonEvmCoinTypeToNameMap = Object.freeze({ +${Object.entries(nonEvmCoinTypeToNameMap) + .map( + ([coinType, [coinSymbol, coinName]]) => + ` "${coinType}": ["${coinSymbol}", "${coinName}"],` + ) + .join("\n")} +} as const);`; + +const coinTypeToNameMapString = `export const coinTypeToNameMap = Object.freeze({ + ...nonEvmCoinTypeToNameMap, + ...evmCoinTypeToNameMap, +} as const);`; + +const toWrite = `${evmCoinTypeToNameMapString} + +${nonEvmCoinTypeToNameMapString} + +${coinTypeToNameMapString} +`; + +await Bun.write("./src/consts/coinTypeToNameMap.ts", toWrite); + +console.log("Done!"); + +rl.close(); diff --git a/src/async.test.ts b/src/async.test.ts index acaab687..395a054e 100644 --- a/src/async.test.ts +++ b/src/async.test.ts @@ -1,5 +1,14 @@ import { expect, test } from "bun:test"; import { getCoderByCoinNameAsync, getCoderByCoinTypeAsync } from "./async.js"; +import { + evmCoinNameToTypeMap, + nonEvmCoinNameToTypeMap, +} from "./consts/coinNameToTypeMap.js"; +import { + evmCoinTypeToNameMap, + nonEvmCoinTypeToNameMap, +} from "./consts/coinTypeToNameMap.js"; +import { coinTypeToEvmChainId } from "./utils/evm.js"; test("coin name", async () => { const coder = await getCoderByCoinNameAsync("btc"); @@ -12,3 +21,60 @@ test("coin type", async () => { expect(coder.coinType).toBe(0); expect(coder.name).toBe("btc"); }); + +test("evm coin name", async () => { + const coder = await getCoderByCoinNameAsync("op"); + expect(coder.coinType).toBe(2147483658); + expect(coder.name).toBe("op"); + expect(coder.evmChainId).toBe(10); +}); + +test("evm coin type", async () => { + const coder = await getCoderByCoinTypeAsync(2147483658); + expect(coder.coinType).toBe(2147483658); + expect(coder.name).toBe("op"); + expect(coder.evmChainId).toBe(10); +}); + +const nonEvmCoinNames = Object.keys(nonEvmCoinNameToTypeMap); +const evmCoinNames = Object.keys(evmCoinNameToTypeMap); + +test.each(nonEvmCoinNames)( + 'getCoderByCoinNameAsync("%s")', + async (coinName) => { + const coder = await getCoderByCoinNameAsync(coinName); + expect(coder.name).toBe(coinName); + expect(coder.coinType).toBe(nonEvmCoinNameToTypeMap[coinName]); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); + } +); + +test.each(evmCoinNames)('getCoderByCoinNameAsync("%s")', async (coinName) => { + const coder = await getCoderByCoinNameAsync(coinName); + expect(coder.name).toBe(coinName); + expect(coder.coinType).toBe(evmCoinNameToTypeMap[coinName]); + expect(coder.evmChainId).toBe(coinTypeToEvmChainId(coder.coinType)); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +const nonEvmCoinTypes = Object.values(nonEvmCoinNameToTypeMap); +const evmCoinTypes = Object.values(evmCoinNameToTypeMap); + +test.each(nonEvmCoinTypes)("getCoderByCoinTypeAsync(%d)", async (coinType) => { + const coder = await getCoderByCoinTypeAsync(coinType); + expect(coder.name).toBe(nonEvmCoinTypeToNameMap[coinType][0]); + expect(coder.coinType).toBe(coinType); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +test.each(evmCoinTypes)("getCoderByCoinTypeAsync(%d)", async (coinType) => { + const coder = await getCoderByCoinTypeAsync(coinType); + expect(coder.name).toBe(evmCoinTypeToNameMap[coinType][0]); + expect(coder.coinType).toBe(coinType); + expect(coder.evmChainId).toBe(coinTypeToEvmChainId(coinType)); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); diff --git a/src/async.ts b/src/async.ts index 346f287b..36825468 100644 --- a/src/async.ts +++ b/src/async.ts @@ -1,38 +1,69 @@ -import { coinTypeMap } from "./consts/coinTypeMap.js"; +import { eth } from "./coins.js"; +import { coinNameToTypeMap } from "./consts/coinNameToTypeMap.js"; +import { coinTypeToNameMap } from "./consts/coinTypeToNameMap.js"; import type { - Coin, CoinName, CoinType, - CoinTypeInvertedReference, - Formats, + EvmCoinName, + EvmCoinType, + GetCoderByCoinName, + GetCoderByCoinType, } from "./types.js"; +import { SLIP44_MSB, coinTypeToEvmChainId } from "./utils/evm.js"; export const getCoderByCoinNameAsync = async < - TCoinName extends CoinName | string = string + TCoinName extends CoinName | string = CoinName | string >( name: TCoinName -): Promise => { - const mod = await import(`./coin/${name}`); - if (!mod) { - throw new Error(`Unsupported coin: ${name}`); +): Promise> => { + const coinType = coinNameToTypeMap[name as CoinName]; + + if (coinType === undefined) throw new Error(`Unsupported coin: ${name}`); + + if (coinType >= SLIP44_MSB) { + // EVM coin + const evmChainId = coinTypeToEvmChainId(coinType); + return { + name: name as EvmCoinName, + coinType, + evmChainId, + encode: eth.encode, + decode: eth.decode, + } as GetCoderByCoinName; } + const mod = await import(`./coin/${name}`); + + if (!mod) throw new Error(`Failed to load coin: ${name}`); + return mod[name]; }; export const getCoderByCoinTypeAsync = async < - TCoinType extends CoinType | number = number + TCoinType extends CoinType | number = CoinType | number >( coinType: TCoinType -): Promise< - TCoinType extends CoinType ? CoinTypeInvertedReference[TCoinType] : Coin -> => { - const name = coinTypeMap[String(coinType) as keyof typeof coinTypeMap]; - if (!name) { - throw new Error(`Unsupported coin type: ${coinType}`); +): Promise> => { + const names = + coinTypeToNameMap[String(coinType) as keyof typeof coinTypeToNameMap]; + + if (!names) throw new Error(`Unsupported coin type: ${coinType}`); + + const [name] = names; + + if (coinType >= SLIP44_MSB) { + // EVM coin + const evmChainId = coinTypeToEvmChainId(coinType); + return { + name, + coinType: coinType as EvmCoinType, + evmChainId, + encode: eth.encode, + decode: eth.decode, + } as GetCoderByCoinType; } const mod = await import(`./coin/${name}`); - if (!mod) { - throw new Error(`Unsupported coin: ${name}`); - } + + if (!mod) throw new Error(`Failed to load coin: ${name}`); + return mod[name]; }; diff --git a/src/coders.test.ts b/src/coders.test.ts new file mode 100644 index 00000000..0c74f476 --- /dev/null +++ b/src/coders.test.ts @@ -0,0 +1,15 @@ +import { expect, test } from "bun:test"; +import * as coders from "./coders.js"; +import { nonEvmCoinNameToTypeMap } from "./consts/coinNameToTypeMap.js"; + +const coinNames = Object.keys(nonEvmCoinNameToTypeMap); + +const capitalise = (s: string) => s[0].toUpperCase() + s.slice(1); + +test.each(coinNames)("coders.ts exports - %s", (coinName) => { + const coderSuffix = `${capitalise(coinName)}Address`; + const encoder = coders[`encode${coderSuffix}`]; + const decoder = coders[`decode${coderSuffix}`]; + expect(encoder).toBeFunction(); + expect(decoder).toBeFunction(); +}); diff --git a/src/coders.ts b/src/coders.ts index cc5dcfb4..7de36ffe 100644 --- a/src/coders.ts +++ b/src/coders.ts @@ -5,19 +5,16 @@ export { decodeAibAddress, encodeAibAddress } from "./coin/aib.js"; export { decodeAionAddress, encodeAionAddress } from "./coin/aion.js"; export { decodeAlgoAddress, encodeAlgoAddress } from "./coin/algo.js"; export { decodeArAddress, encodeArAddress } from "./coin/ar.js"; -export { decodeArb1Address, encodeArb1Address } from "./coin/arb1.js"; export { decodeArdrAddress, encodeArdrAddress } from "./coin/ardr.js"; export { decodeArkAddress, encodeArkAddress } from "./coin/ark.js"; export { decodeAtomAddress, encodeAtomAddress } from "./coin/atom.js"; export { decodeAvaxAddress, encodeAvaxAddress } from "./coin/avax.js"; -export { decodeAvaxcAddress, encodeAvaxcAddress } from "./coin/avaxc.js"; export { decodeBcdAddress, encodeBcdAddress } from "./coin/bcd.js"; export { decodeBchAddress, encodeBchAddress } from "./coin/bch.js"; export { decodeBcnAddress, encodeBcnAddress } from "./coin/bcn.js"; export { decodeBdxAddress, encodeBdxAddress } from "./coin/bdx.js"; export { decodeBnbAddress, encodeBnbAddress } from "./coin/bnb.js"; export { decodeBpsAddress, encodeBpsAddress } from "./coin/bps.js"; -export { decodeBscAddress, encodeBscAddress } from "./coin/bsc.js"; export { decodeBsvAddress, encodeBsvAddress } from "./coin/bsv.js"; export { decodeBtcAddress, encodeBtcAddress } from "./coin/btc.js"; export { decodeBtgAddress, encodeBtgAddress } from "./coin/btg.js"; @@ -25,18 +22,15 @@ export { decodeBtmAddress, encodeBtmAddress } from "./coin/btm.js"; export { decodeBtsAddress, encodeBtsAddress } from "./coin/bts.js"; export { decodeCcaAddress, encodeCcaAddress } from "./coin/cca.js"; export { decodeCcxxAddress, encodeCcxxAddress } from "./coin/ccxx.js"; -export { decodeCeloAddress, encodeCeloAddress } from "./coin/celo.js"; export { decodeCeloLegacyAddress, encodeCeloLegacyAddress, } from "./coin/celoLegacy.js"; export { decodeCkbAddress, encodeCkbAddress } from "./coin/ckb.js"; -export { decodeCloAddress, encodeCloAddress } from "./coin/clo.js"; export { decodeCloLegacyAddress, encodeCloLegacyAddress, } from "./coin/cloLegacy.js"; -export { decodeCroAddress, encodeCroAddress } from "./coin/cro.js"; export { decodeDashAddress, encodeDashAddress } from "./coin/dash.js"; export { decodeDcrAddress, encodeDcrAddress } from "./coin/dcr.js"; export { decodeDgbAddress, encodeDgbAddress } from "./coin/dgb.js"; @@ -46,14 +40,12 @@ export { decodeDotAddress, encodeDotAddress } from "./coin/dot.js"; export { decodeEgldAddress, encodeEgldAddress } from "./coin/egld.js"; export { decodeElaAddress, encodeElaAddress } from "./coin/ela.js"; export { decodeEosAddress, encodeEosAddress } from "./coin/eos.js"; -export { decodeEtcAddress, encodeEtcAddress } from "./coin/etc.js"; export { decodeEtcLegacyAddress, encodeEtcLegacyAddress, } from "./coin/etcLegacy.js"; export { decodeEthAddress, encodeEthAddress } from "./coin/eth.js"; export { decodeEtnAddress, encodeEtnAddress } from "./coin/etn.js"; -export { decodeEwtAddress, encodeEwtAddress } from "./coin/ewt.js"; export { decodeEwtLegacyAddress, encodeEwtLegacyAddress, @@ -62,17 +54,15 @@ export { decodeFilAddress, encodeFilAddress } from "./coin/fil.js"; export { decodeFioAddress, encodeFioAddress } from "./coin/fio.js"; export { decodeFiroAddress, encodeFiroAddress } from "./coin/firo.js"; export { decodeFlowAddress, encodeFlowAddress } from "./coin/flow.js"; -export { decodeFtmAddress, encodeFtmAddress } from "./coin/ftm.js"; +export { decodeFluxAddress, encodeFluxAddress } from "./coin/flux.js"; export { decodeFtmLegacyAddress, encodeFtmLegacyAddress, } from "./coin/ftmLegacy.js"; -export { decodeGnoAddress, encodeGnoAddress } from "./coin/gno.js"; export { decodeGnoLegacyAddress, encodeGnoLegacyAddress, } from "./coin/gnoLegacy.js"; -export { decodeGoAddress, encodeGoAddress } from "./coin/go.js"; export { decodeGoLegacyAddress, encodeGoLegacyAddress, @@ -96,7 +86,6 @@ export { decodeLrgAddress, encodeLrgAddress } from "./coin/lrg.js"; export { decodeLskAddress, encodeLskAddress } from "./coin/lsk.js"; export { decodeLtcAddress, encodeLtcAddress } from "./coin/ltc.js"; export { decodeLunaAddress, encodeLunaAddress } from "./coin/luna.js"; -export { decodeMaticAddress, encodeMaticAddress } from "./coin/matic.js"; export { decodeMonaAddress, encodeMonaAddress } from "./coin/mona.js"; export { decodeMrxAddress, encodeMrxAddress } from "./coin/mrx.js"; export { decodeNanoAddress, encodeNanoAddress } from "./coin/nano.js"; @@ -106,7 +95,6 @@ export { decodeNeoAddress, encodeNeoAddress } from "./coin/neo.js"; export { decodeNimAddress, encodeNimAddress } from "./coin/nim.js"; export { decodeNmcAddress, encodeNmcAddress } from "./coin/nmc.js"; export { decodeNostrAddress, encodeNostrAddress } from "./coin/nostr.js"; -export { decodeNrgAddress, encodeNrgAddress } from "./coin/nrg.js"; export { decodeNrgLegacyAddress, encodeNrgLegacyAddress, @@ -114,16 +102,14 @@ export { export { decodeNulsAddress, encodeNulsAddress } from "./coin/nuls.js"; export { decodeOneAddress, encodeOneAddress } from "./coin/one.js"; export { decodeOntAddress, encodeOntAddress } from "./coin/ont.js"; -export { decodeOpAddress, encodeOpAddress } from "./coin/op.js"; -export { decodePoaAddress, encodePoaAddress } from "./coin/poa.js"; export { decodePoaLegacyAddress, encodePoaLegacyAddress, } from "./coin/poaLegacy.js"; export { decodePpcAddress, encodePpcAddress } from "./coin/ppc.js"; export { decodeQtumAddress, encodeQtumAddress } from "./coin/qtum.js"; +export { decodeRbtcAddress, encodeRbtcAddress } from "./coin/rbtc.js"; export { decodeRddAddress, encodeRddAddress } from "./coin/rdd.js"; -export { decodeRskAddress, encodeRskAddress } from "./coin/rsk.js"; export { decodeRuneAddress, encodeRuneAddress } from "./coin/rune.js"; export { decodeRvnAddress, encodeRvnAddress } from "./coin/rvn.js"; export { decodeScAddress, encodeScAddress } from "./coin/sc.js"; @@ -136,18 +122,15 @@ export { decodeStrkAddress, encodeStrkAddress } from "./coin/strk.js"; export { decodeStxAddress, encodeStxAddress } from "./coin/stx.js"; export { decodeSysAddress, encodeSysAddress } from "./coin/sys.js"; export { decodeTfuelAddress, encodeTfuelAddress } from "./coin/tfuel.js"; -export { decodeThetaAddress, encodeThetaAddress } from "./coin/theta.js"; export { decodeThetaLegacyAddress, encodeThetaLegacyAddress, } from "./coin/thetaLegacy.js"; -export { decodeTomoAddress, encodeTomoAddress } from "./coin/tomo.js"; export { decodeTomoLegacyAddress, encodeTomoLegacyAddress, } from "./coin/tomoLegacy.js"; export { decodeTrxAddress, encodeTrxAddress } from "./coin/trx.js"; -export { decodeTtAddress, encodeTtAddress } from "./coin/tt.js"; export { decodeTtLegacyAddress, encodeTtLegacyAddress, @@ -155,6 +138,10 @@ export { export { decodeVetAddress, encodeVetAddress } from "./coin/vet.js"; export { decodeViaAddress, encodeViaAddress } from "./coin/via.js"; export { decodeVlxAddress, encodeVlxAddress } from "./coin/vlx.js"; +export { + decodeVlxLegacyAddress, + encodeVlxLegacyAddress, +} from "./coin/vlxLegacy.js"; export { decodeVsysAddress, encodeVsysAddress } from "./coin/vsys.js"; export { decodeWanAddress, encodeWanAddress } from "./coin/wan.js"; export { decodeWavesAddress, encodeWavesAddress } from "./coin/waves.js"; @@ -168,6 +155,5 @@ export { decodeXrpAddress, encodeXrpAddress } from "./coin/xrp.js"; export { decodeXtzAddress, encodeXtzAddress } from "./coin/xtz.js"; export { decodeXvgAddress, encodeXvgAddress } from "./coin/xvg.js"; export { decodeZecAddress, encodeZecAddress } from "./coin/zec.js"; -export { decodeZelAddress, encodeZelAddress } from "./coin/zel.js"; export { decodeZenAddress, encodeZenAddress } from "./coin/zen.js"; export { decodeZilAddress, encodeZilAddress } from "./coin/zil.js"; diff --git a/src/coin/abbc.ts b/src/coin/abbc.ts index 340faa10..d5cf1f99 100644 --- a/src/coin/abbc.ts +++ b/src/coin/abbc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "abbc"; @@ -14,4 +14,4 @@ export const abbc = { coinType, encode: encodeAbbcAddress, decode: decodeAbbcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ada.ts b/src/coin/ada.ts index a88c1e17..1bbb5ca5 100644 --- a/src/coin/ada.ts +++ b/src/coin/ada.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; import { byronDecode, byronEncode } from "../utils/byron.js"; @@ -30,4 +30,4 @@ export const ada = { coinType, encode: encodeAdaAddress, decode: decodeAdaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ae.ts b/src/coin/ae.ts index b0343c25..e1a2d871 100644 --- a/src/coin/ae.ts +++ b/src/coin/ae.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "ae"; @@ -20,4 +20,4 @@ export const ae = { coinType, encode: encodeAeAddress, decode: decodeAeAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/aib.ts b/src/coin/aib.ts index 7152e123..b58ef940 100644 --- a/src/coin/aib.ts +++ b/src/coin/aib.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const aib = { coinType, encode: encodeAibAddress, decode: decodeAibAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/aion.ts b/src/coin/aion.ts index 54281d83..fbdd3da4 100644 --- a/src/coin/aion.ts +++ b/src/coin/aion.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHex, hexWithoutPrefixToBytes } from "../utils/bytes.js"; const name = "aion"; @@ -22,4 +22,4 @@ export const aion = { coinType, encode: encodeAionAddress, decode: decodeAionAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/algo.ts b/src/coin/algo.ts index 60affdba..f13627b1 100644 --- a/src/coin/algo.ts +++ b/src/coin/algo.ts @@ -1,6 +1,6 @@ import { sha512_256 } from "@noble/hashes/sha512"; import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base32UnpaddedDecode, base32UnpaddedEncode } from "../utils/base32.js"; const name = "algo"; @@ -25,4 +25,4 @@ export const algo = { coinType, encode: encodeAlgoAddress, decode: decodeAlgoAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ar.ts b/src/coin/ar.ts index 510e7c24..6342c6db 100644 --- a/src/coin/ar.ts +++ b/src/coin/ar.ts @@ -1,5 +1,5 @@ import { base64urlnopad } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "ar"; const coinType = 472; @@ -12,4 +12,4 @@ export const ar = { coinType, encode: encodeArAddress, decode: decodeArAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/arb1.test.ts b/src/coin/arb1.test.ts deleted file mode 100644 index 19ac3e96..00000000 --- a/src/coin/arb1.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeArb1Address, encodeArb1Address } from "./arb1.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("arb1 address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeArb1Address(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeArb1Address(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/arb1.ts b/src/coin/arb1.ts deleted file mode 100644 index 60229209..00000000 --- a/src/coin/arb1.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "arb1"; -const evmChainId = 42161; -const coinType = 2147525809; - -export const encodeArb1Address = createHexChecksummedEncoder(); -export const decodeArb1Address = createHexChecksummedDecoder(); - -export const arb1 = { - name, - coinType, - evmChainId, - encode: encodeArb1Address, - decode: decodeArb1Address, -} as const satisfies Coin; diff --git a/src/coin/ardr.ts b/src/coin/ardr.ts index fbdc491a..d299fcc1 100644 --- a/src/coin/ardr.ts +++ b/src/coin/ardr.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "ardr"; const coinType = 16754; @@ -87,4 +87,4 @@ export const ardr = { coinType, encode: encodeArdrAddress, decode: decodeArdrAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ark.ts b/src/coin/ark.ts index b0bb6aec..ab158d06 100644 --- a/src/coin/ark.ts +++ b/src/coin/ark.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "ark"; @@ -16,4 +16,4 @@ export const ark = { coinType, encode: encodeArkAddress, decode: decodeArkAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/atom.ts b/src/coin/atom.ts index 17602956..f738a332 100644 --- a/src/coin/atom.ts +++ b/src/coin/atom.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "atom"; @@ -12,4 +12,4 @@ export const atom = { coinType, encode: encodeAtomAddress, decode: decodeAtomAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/avax.ts b/src/coin/avax.ts index 230eaff1..cad170a3 100644 --- a/src/coin/avax.ts +++ b/src/coin/avax.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "avax"; @@ -26,4 +26,4 @@ export const avax = { coinType, encode: encodeAvaxAddress, decode: decodeAvaxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/avaxc.test.ts b/src/coin/avaxc.test.ts deleted file mode 100644 index b731b2c7..00000000 --- a/src/coin/avaxc.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeAvaxcAddress, encodeAvaxcAddress } from "./avaxc.js"; - -describe.each([ - { - text: "0x67316300f17f063085Ca8bCa4bd3f7a5a3C66275", - hex: "67316300f17f063085ca8bca4bd3f7a5a3c66275", - }, -])("avaxc address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeAvaxcAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeAvaxcAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/avaxc.ts b/src/coin/avaxc.ts deleted file mode 100644 index 6bbbb656..00000000 --- a/src/coin/avaxc.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "avaxc"; -const evmChainId = 43114; -const coinType = 2147526762; - -export const encodeAvaxcAddress = createHexChecksummedEncoder(); -export const decodeAvaxcAddress = createHexChecksummedDecoder(); - -export const avaxc = { - name, - coinType, - evmChainId, - encode: encodeAvaxcAddress, - decode: decodeAvaxcAddress, -} as const satisfies Coin; diff --git a/src/coin/bcd.ts b/src/coin/bcd.ts index 18f2ff5e..4964b5da 100644 --- a/src/coin/bcd.ts +++ b/src/coin/bcd.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const bcd = { coinType, encode: encodeBcdAddress, decode: decodeBcdAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bch.ts b/src/coin/bch.ts index 7af83a8e..c2836fd8 100644 --- a/src/coin/bch.ts +++ b/src/coin/bch.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder } from "../utils/base58.js"; import { decodeBchAddressToTypeAndHash, @@ -63,4 +63,4 @@ export const bch = { coinType, encode: encodeBchAddress, decode: decodeBchAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bcn.ts b/src/coin/bcn.ts index 81de7503..49bfae30 100644 --- a/src/coin/bcn.ts +++ b/src/coin/bcn.ts @@ -2,7 +2,7 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { keccak_256 } from "@noble/hashes/sha3"; import { concatBytes } from "@noble/hashes/utils"; import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js"; const name = "bcn"; @@ -34,4 +34,4 @@ export const bcn = { coinType, encode: encodeBcnAddress, decode: decodeBcnAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bdx.ts b/src/coin/bdx.ts index 94f2b675..1043083c 100644 --- a/src/coin/bdx.ts +++ b/src/coin/bdx.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js"; const name = "bdx"; @@ -12,4 +12,4 @@ export const bdx = { coinType, encode: encodeBdxAddress, decode: decodeBdxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bnb.ts b/src/coin/bnb.ts index 710b6303..8932162d 100644 --- a/src/coin/bnb.ts +++ b/src/coin/bnb.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "bnb"; @@ -14,4 +14,4 @@ export const bnb = { coinType, encode: encodeBnbAddress, decode: decodeBnbAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bps.ts b/src/coin/bps.ts index cc1e31b0..42597f82 100644 --- a/src/coin/bps.ts +++ b/src/coin/bps.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const bps = { coinType, encode: encodeBpsAddress, decode: decodeBpsAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bsc.test.ts b/src/coin/bsc.test.ts deleted file mode 100644 index 0b1703eb..00000000 --- a/src/coin/bsc.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeBscAddress, encodeBscAddress } from "./bsc.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("bsc address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeBscAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeBscAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/bsc.ts b/src/coin/bsc.ts deleted file mode 100644 index c1f7752e..00000000 --- a/src/coin/bsc.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "bsc"; -const evmChainId = 56; -const coinType = 2147483704; - -export const encodeBscAddress = createHexChecksummedEncoder(); -export const decodeBscAddress = createHexChecksummedDecoder(); - -export const bsc = { - name, - coinType, - evmChainId, - encode: encodeBscAddress, - decode: decodeBscAddress, -} as const satisfies Coin; diff --git a/src/coin/bsv.ts b/src/coin/bsv.ts index 397f411a..67f52a45 100644 --- a/src/coin/bsv.ts +++ b/src/coin/bsv.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "bsv"; @@ -23,4 +23,4 @@ export const bsv = { coinType, encode: encodeBsvAddress, decode: decodeBsvAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/btc.ts b/src/coin/btc.ts index c5015a6e..56a2864b 100644 --- a/src/coin/btc.ts +++ b/src/coin/btc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const btc = { coinType, encode: encodeBtcAddress, decode: decodeBtcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/btg.ts b/src/coin/btg.ts index 1ab509fe..8f439132 100644 --- a/src/coin/btg.ts +++ b/src/coin/btg.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const btg = { coinType, encode: encodeBtgAddress, decode: decodeBtgAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/btm.ts b/src/coin/btm.ts index 7dfb0d77..7ebbdf9f 100644 --- a/src/coin/btm.ts +++ b/src/coin/btm.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32SegwitDecoder, createBech32SegwitEncoder, @@ -17,4 +17,4 @@ export const btm = { coinType, encode: encodeBtmAddress, decode: decodeBtmAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/bts.ts b/src/coin/bts.ts index 1b57ac4d..0cbbc1e3 100644 --- a/src/coin/bts.ts +++ b/src/coin/bts.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "bts"; @@ -14,4 +14,4 @@ export const bts = { coinType, encode: encodeBtsAddress, decode: decodeBtsAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/cca.ts b/src/coin/cca.ts index 98a7cb1d..9bd89e5b 100644 --- a/src/coin/cca.ts +++ b/src/coin/cca.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const cca = { coinType, encode: encodeCcaAddress, decode: decodeCcaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ccxx.ts b/src/coin/ccxx.ts index 831e3e19..9eea44b2 100644 --- a/src/coin/ccxx.ts +++ b/src/coin/ccxx.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const ccxx = { coinType, encode: encodeCcxxAddress, decode: decodeCcxxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/celo.test.ts b/src/coin/celo.test.ts deleted file mode 100644 index 8f337b7a..00000000 --- a/src/coin/celo.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeCeloAddress, encodeCeloAddress } from "./celo.js"; - -describe.each([ - { - text: "0x67316300f17f063085Ca8bCa4bd3f7a5a3C66275", - hex: "67316300f17f063085ca8bca4bd3f7a5a3c66275", - }, -])("celo address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeCeloAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeCeloAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/celo.ts b/src/coin/celo.ts deleted file mode 100644 index 74190c57..00000000 --- a/src/coin/celo.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "celo"; -const evmChainId = 42220; -const coinType = 2147525868; - -export const encodeCeloAddress = createHexChecksummedEncoder(); -export const decodeCeloAddress = createHexChecksummedDecoder(); - -export const celo = { - name, - coinType, - evmChainId, - encode: encodeCeloAddress, - decode: decodeCeloAddress, -} as const satisfies Coin; diff --git a/src/coin/celoLegacy.ts b/src/coin/celoLegacy.ts index f021d262..8b47be63 100644 --- a/src/coin/celoLegacy.ts +++ b/src/coin/celoLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const celoLegacy = { coinType, encode: encodeCeloLegacyAddress, decode: decodeCeloLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ckb.ts b/src/coin/ckb.ts index 7eb49eab..6ac4790c 100644 --- a/src/coin/ckb.ts +++ b/src/coin/ckb.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "ckb"; @@ -14,4 +14,4 @@ export const ckb = { coinType, encode: encodeCkbAddress, decode: decodeCkbAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/clo.test.ts b/src/coin/clo.test.ts deleted file mode 100644 index 71cc9e01..00000000 --- a/src/coin/clo.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeCloAddress, encodeCloAddress } from "./clo.js"; - -describe.each([ - { - text: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", - hex: "5aaeb6053f3e94c9b9a09f33669435e7ef1beaed", - }, -])("clo address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeCloAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeCloAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/clo.ts b/src/coin/clo.ts deleted file mode 100644 index e8be2e62..00000000 --- a/src/coin/clo.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "clo"; -const evmChainId = 820; -const coinType = 2147484468; - -export const encodeCloAddress = createHexChecksummedEncoder(); -export const decodeCloAddress = createHexChecksummedDecoder(); - -export const clo = { - name, - coinType, - evmChainId, - encode: encodeCloAddress, - decode: decodeCloAddress, -} as const satisfies Coin; diff --git a/src/coin/cloLegacy.ts b/src/coin/cloLegacy.ts index a76a41b6..b327b0c3 100644 --- a/src/coin/cloLegacy.ts +++ b/src/coin/cloLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const cloLegacy = { coinType, encode: encodeCloLegacyAddress, decode: decodeCloLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/cro.test.ts b/src/coin/cro.test.ts deleted file mode 100644 index fdec5042..00000000 --- a/src/coin/cro.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeCroAddress, encodeCroAddress } from "./cro.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("cro address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeCroAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeCroAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/cro.ts b/src/coin/cro.ts deleted file mode 100644 index 6d495675..00000000 --- a/src/coin/cro.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "cro"; -const evmChainId = 25; -const coinType = 2147483673; - -export const encodeCroAddress = createHexChecksummedEncoder(); -export const decodeCroAddress = createHexChecksummedDecoder(); - -export const cro = { - name, - coinType, - evmChainId, - encode: encodeCroAddress, - decode: decodeCroAddress, -} as const satisfies Coin; diff --git a/src/coin/dash.ts b/src/coin/dash.ts index c6e608d4..3aa84c80 100644 --- a/src/coin/dash.ts +++ b/src/coin/dash.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const dash = { coinType, encode: encodeDashAddress, decode: decodeDashAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/dcr.ts b/src/coin/dcr.ts index 3aaf59cf..54502a28 100644 --- a/src/coin/dcr.ts +++ b/src/coin/dcr.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -15,4 +15,4 @@ export const dcr = { coinType, encode: encodeDcrAddress, decode: decodeDcrAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/dgb.ts b/src/coin/dgb.ts index 3fd8a40f..d355eb2f 100644 --- a/src/coin/dgb.ts +++ b/src/coin/dgb.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const dgb = { coinType, encode: encodeDgbAddress, decode: decodeDgbAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/divi.ts b/src/coin/divi.ts index ad9903bc..0daa216f 100644 --- a/src/coin/divi.ts +++ b/src/coin/divi.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const divi = { coinType, encode: encodeDiviAddress, decode: decodeDiviAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/doge.ts b/src/coin/doge.ts index e9b3cc46..4ef845b9 100644 --- a/src/coin/doge.ts +++ b/src/coin/doge.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const doge = { coinType, encode: encodeDogeAddress, decode: decodeDogeAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/dot.ts b/src/coin/dot.ts index c07c6566..8611d4c1 100644 --- a/src/coin/dot.ts +++ b/src/coin/dot.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createDotAddressDecoder, createDotAddressEncoder, @@ -17,4 +17,4 @@ export const dot = { coinType, encode: encodeDotAddress, decode: decodeDotAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/egld.ts b/src/coin/egld.ts index 6b2bd3d1..ce525d7c 100644 --- a/src/coin/egld.ts +++ b/src/coin/egld.ts @@ -1,8 +1,8 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "egld"; -const coinType = 120; +const coinType = 508; export const encodeEgldAddress = createBech32Encoder("erd"); export const decodeEgldAddress = createBech32Decoder("erd"); @@ -12,4 +12,4 @@ export const egld = { coinType, encode: encodeEgldAddress, decode: decodeEgldAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ela.ts b/src/coin/ela.ts index 88b13c79..801670c0 100644 --- a/src/coin/ela.ts +++ b/src/coin/ela.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -15,4 +15,4 @@ export const ela = { coinType, encode: encodeElaAddress, decode: decodeElaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/eos.ts b/src/coin/eos.ts index e5caea9c..8169698a 100644 --- a/src/coin/eos.ts +++ b/src/coin/eos.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "eos"; @@ -14,4 +14,4 @@ export const eos = { coinType, encode: encodeEosAddress, decode: decodeEosAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/etc.test.ts b/src/coin/etc.test.ts deleted file mode 100644 index 3b107a47..00000000 --- a/src/coin/etc.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeEtcAddress, encodeEtcAddress } from "./etc.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("etc address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeEtcAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeEtcAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/etc.ts b/src/coin/etc.ts deleted file mode 100644 index f8677355..00000000 --- a/src/coin/etc.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "etc"; -const evmChainId = 61; -const coinType = 2147483709; - -export const encodeEtcAddress = createHexChecksummedEncoder(); -export const decodeEtcAddress = createHexChecksummedDecoder(); - -export const etc = { - name, - coinType, - evmChainId, - encode: encodeEtcAddress, - decode: decodeEtcAddress, -} as const satisfies Coin; diff --git a/src/coin/etcLegacy.ts b/src/coin/etcLegacy.ts index a972d7d8..c19fcc48 100644 --- a/src/coin/etcLegacy.ts +++ b/src/coin/etcLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const etcLegacy = { coinType, encode: encodeEtcLegacyAddress, decode: decodeEtcLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/eth.ts b/src/coin/eth.ts index f9990feb..0d04356f 100644 --- a/src/coin/eth.ts +++ b/src/coin/eth.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const eth = { coinType, encode: encodeEthAddress, decode: decodeEthAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/etn.ts b/src/coin/etn.ts index 5560a6df..f9852d5a 100644 --- a/src/coin/etn.ts +++ b/src/coin/etn.ts @@ -1,7 +1,7 @@ import { keccak_256 } from "@noble/hashes/sha3"; import { concatBytes } from "@noble/hashes/utils"; import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js"; const name = "etn"; @@ -31,4 +31,4 @@ export const etn = { coinType, encode: encodeEtnAddress, decode: decodeEtnAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ewt.test.ts b/src/coin/ewt.test.ts deleted file mode 100644 index 396c6d8a..00000000 --- a/src/coin/ewt.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeEwtAddress, encodeEwtAddress } from "./ewt.js"; - -describe.each([ - { - text: "0x2ce42c2B3aCff7eddcfd32DCB0703F1870b0eBe1", - hex: "2ce42c2b3acff7eddcfd32dcb0703f1870b0ebe1", - }, -])("ewt address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeEwtAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeEwtAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/ewt.ts b/src/coin/ewt.ts deleted file mode 100644 index f51b20ea..00000000 --- a/src/coin/ewt.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "ewt"; -const evmChainId = 246; -const coinType = 2147483894; - -export const encodeEwtAddress = createHexChecksummedEncoder(); -export const decodeEwtAddress = createHexChecksummedDecoder(); - -export const ewt = { - name, - coinType, - evmChainId, - encode: encodeEwtAddress, - decode: decodeEwtAddress, -} as const satisfies Coin; diff --git a/src/coin/ewtLegacy.ts b/src/coin/ewtLegacy.ts index f196ac57..6fb49feb 100644 --- a/src/coin/ewtLegacy.ts +++ b/src/coin/ewtLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const ewtLegacy = { coinType, encode: encodeEwtLegacyAddress, decode: decodeEwtLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/fil.ts b/src/coin/fil.ts index 499653c2..431d437d 100644 --- a/src/coin/fil.ts +++ b/src/coin/fil.ts @@ -1,7 +1,7 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base32UnpaddedDecode, base32UnpaddedEncode } from "../utils/base32.js"; import { decodeLeb128, encodeLeb128 } from "../utils/leb128.js"; @@ -69,4 +69,4 @@ export const fil = { coinType, encode: encodeFilAddress, decode: decodeFilAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/fio.ts b/src/coin/fio.ts index f740f20b..b8b19d18 100644 --- a/src/coin/fio.ts +++ b/src/coin/fio.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "fio"; @@ -14,4 +14,4 @@ export const fio = { coinType, encode: encodeFioAddress, decode: decodeFioAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/firo.ts b/src/coin/firo.ts index 9613bec7..2108a83a 100644 --- a/src/coin/firo.ts +++ b/src/coin/firo.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const firo = { coinType, encode: encodeFiroAddress, decode: decodeFiroAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/flow.ts b/src/coin/flow.ts index 169d0c7d..1fede0ca 100644 --- a/src/coin/flow.ts +++ b/src/coin/flow.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHex, hexWithoutPrefixToBytes } from "../utils/bytes.js"; import { validateFlowAddress } from "../utils/flow.js"; @@ -30,4 +30,4 @@ export const flow = { coinType, encode: encodeFlowAddress, decode: decodeFlowAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/zel.test.ts b/src/coin/flux.test.ts similarity index 71% rename from src/coin/zel.test.ts rename to src/coin/flux.test.ts index 4262708b..392369fc 100644 --- a/src/coin/zel.test.ts +++ b/src/coin/flux.test.ts @@ -1,6 +1,6 @@ import { hexToBytes } from "@noble/hashes/utils"; import { describe, expect, test } from "bun:test"; -import { decodeZelAddress, encodeZelAddress } from "./zel.js"; +import { decodeFluxAddress, encodeFluxAddress } from "./flux.js"; describe.each([ { @@ -13,9 +13,9 @@ describe.each([ }, ])("zel address", ({ text, hex }) => { test(`encode: ${text}`, () => { - expect(encodeZelAddress(hexToBytes(hex))).toEqual(text); + expect(encodeFluxAddress(hexToBytes(hex))).toEqual(text); }); test(`decode: ${text}`, () => { - expect(decodeZelAddress(text)).toEqual(hexToBytes(hex)); + expect(decodeFluxAddress(text)).toEqual(hexToBytes(hex)); }); }); diff --git a/src/coin/zel.ts b/src/coin/flux.ts similarity index 53% rename from src/coin/zel.ts rename to src/coin/flux.ts index 636c4cc9..98a6ab45 100644 --- a/src/coin/zel.ts +++ b/src/coin/flux.ts @@ -1,27 +1,27 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createZcashDecoder, createZcashEncoder } from "../utils/zcash.js"; -const name = "zel"; +const name = "flux"; const coinType = 19167; const hrp = "za"; const p2pkhVersions = [new Uint8Array([0x1c, 0xb8])]; const p2shVersions = [new Uint8Array([0x1c, 0xbd])]; -export const encodeZelAddress = createZcashEncoder({ +export const encodeFluxAddress = createZcashEncoder({ hrp, p2pkhVersions, p2shVersions, }); -export const decodeZelAddress = createZcashDecoder({ +export const decodeFluxAddress = createZcashDecoder({ hrp, p2pkhVersions, p2shVersions, }); -export const zel = { +export const flux = { name, coinType, - encode: encodeZelAddress, - decode: decodeZelAddress, -} as const satisfies Coin; + encode: encodeFluxAddress, + decode: decodeFluxAddress, +} as const satisfies CheckedCoin; diff --git a/src/coin/ftm.test.ts b/src/coin/ftm.test.ts deleted file mode 100644 index 0e61dad9..00000000 --- a/src/coin/ftm.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeFtmAddress, encodeFtmAddress } from "./ftm.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("ftm address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeFtmAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeFtmAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/ftm.ts b/src/coin/ftm.ts deleted file mode 100644 index 83fae686..00000000 --- a/src/coin/ftm.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "ftm"; -const evmChainId = 250; -const coinType = 2147483898; - -export const encodeFtmAddress = createHexChecksummedEncoder(); -export const decodeFtmAddress = createHexChecksummedDecoder(); - -export const ftm = { - name, - coinType, - evmChainId, - encode: encodeFtmAddress, - decode: decodeFtmAddress, -} as const satisfies Coin; diff --git a/src/coin/ftmLegacy.ts b/src/coin/ftmLegacy.ts index fc87499a..bd3d04ed 100644 --- a/src/coin/ftmLegacy.ts +++ b/src/coin/ftmLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const ftmLegacy = { coinType, encode: encodeFtmLegacyAddress, decode: decodeFtmLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/gno.test.ts b/src/coin/gno.test.ts deleted file mode 100644 index a659a40f..00000000 --- a/src/coin/gno.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeGnoAddress, encodeGnoAddress } from "./gno.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("gno address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeGnoAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeGnoAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/gno.ts b/src/coin/gno.ts deleted file mode 100644 index 020e50a1..00000000 --- a/src/coin/gno.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "gno"; -const evmChainId = 100; -const coinType = 2147483748; - -export const encodeGnoAddress = createHexChecksummedEncoder(); -export const decodeGnoAddress = createHexChecksummedDecoder(); - -export const gno = { - name, - coinType, - evmChainId, - encode: encodeGnoAddress, - decode: decodeGnoAddress, -} as const satisfies Coin; diff --git a/src/coin/gnoLegacy.ts b/src/coin/gnoLegacy.ts index 04180269..43789cdb 100644 --- a/src/coin/gnoLegacy.ts +++ b/src/coin/gnoLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const gnoLegacy = { coinType, encode: encodeGnoLegacyAddress, decode: decodeGnoLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/go.test.ts b/src/coin/go.test.ts deleted file mode 100644 index 239b77e8..00000000 --- a/src/coin/go.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeGoAddress, encodeGoAddress } from "./go.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("go address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeGoAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeGoAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/go.ts b/src/coin/go.ts deleted file mode 100644 index d96da7a4..00000000 --- a/src/coin/go.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "go"; -const evmChainId = 60; -const coinType = 2147483708; - -export const encodeGoAddress = createHexChecksummedEncoder(); -export const decodeGoAddress = createHexChecksummedDecoder(); - -export const go = { - name, - coinType, - evmChainId, - encode: encodeGoAddress, - decode: decodeGoAddress, -} as const satisfies Coin; diff --git a/src/coin/goLegacy.ts b/src/coin/goLegacy.ts index 8d4b0737..148d7ceb 100644 --- a/src/coin/goLegacy.ts +++ b/src/coin/goLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const goLegacy = { coinType, encode: encodeGoLegacyAddress, decode: decodeGoLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/grin.ts b/src/coin/grin.ts index e7deddb0..0a81d0a5 100644 --- a/src/coin/grin.ts +++ b/src/coin/grin.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "grin"; @@ -14,4 +14,4 @@ export const grin = { coinType, encode: encodeGrinAddress, decode: decodeGrinAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/gxc.ts b/src/coin/gxc.ts index a439b2a9..e47e19b9 100644 --- a/src/coin/gxc.ts +++ b/src/coin/gxc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "gxc"; @@ -14,4 +14,4 @@ export const gxc = { coinType, encode: encodeGxcAddress, decode: decodeGxcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/hbar.ts b/src/coin/hbar.ts index a5123edb..46ccc91d 100644 --- a/src/coin/hbar.ts +++ b/src/coin/hbar.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "hbar"; const coinType = 3030; @@ -36,4 +36,4 @@ export const hbar = { coinType, encode: encodeHbarAddress, decode: decodeHbarAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/hive.ts b/src/coin/hive.ts index f68e7a57..608e833c 100644 --- a/src/coin/hive.ts +++ b/src/coin/hive.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "hive"; @@ -14,4 +14,4 @@ export const hive = { coinType, encode: encodeHiveAddress, decode: decodeHiveAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/hns.ts b/src/coin/hns.ts index 619f9b1d..11715a02 100644 --- a/src/coin/hns.ts +++ b/src/coin/hns.ts @@ -1,5 +1,5 @@ import { bech32 } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "hns"; const coinType = 5353; @@ -31,4 +31,4 @@ export const hns = { coinType, encode: encodeHnsAddress, decode: decodeHnsAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/hnt.ts b/src/coin/hnt.ts index 5adab41f..cb1b03e5 100644 --- a/src/coin/hnt.ts +++ b/src/coin/hnt.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "hnt"; @@ -23,4 +23,4 @@ export const hnt = { coinType, encode: encodeHntAddress, decode: decodeHntAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/icx.ts b/src/coin/icx.ts index bc161269..e28cb08e 100644 --- a/src/coin/icx.ts +++ b/src/coin/icx.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHexWithoutPrefix, hexWithoutPrefixToBytes, @@ -31,4 +31,4 @@ export const icx = { coinType, encode: encodeIcxAddress, decode: decodeIcxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/iost.ts b/src/coin/iost.ts index f8ae7810..43f33e51 100644 --- a/src/coin/iost.ts +++ b/src/coin/iost.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -15,4 +15,4 @@ export const iost = { coinType, encode: encodeIostAddress, decode: decodeIostAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/iota.ts b/src/coin/iota.ts index 8d03361c..eb0a2cb5 100644 --- a/src/coin/iota.ts +++ b/src/coin/iota.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "iota"; @@ -24,4 +24,4 @@ export const iota = { coinType, encode: encodeIotaAddress, decode: decodeIotaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/iotx.ts b/src/coin/iotx.ts index 890ccbd0..6b3394f1 100644 --- a/src/coin/iotx.ts +++ b/src/coin/iotx.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "iotx"; @@ -14,4 +14,4 @@ export const iotx = { coinType, encode: encodeIotxAddress, decode: decodeIotxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/iris.ts b/src/coin/iris.ts index 1743e858..d51f8fff 100644 --- a/src/coin/iris.ts +++ b/src/coin/iris.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "iris"; @@ -14,4 +14,4 @@ export const iris = { coinType, encode: encodeIrisAddress, decode: decodeIrisAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/kava.ts b/src/coin/kava.ts index da599fdc..b9f828ae 100644 --- a/src/coin/kava.ts +++ b/src/coin/kava.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "kava"; @@ -14,4 +14,4 @@ export const kava = { coinType, encode: encodeKavaAddress, decode: decodeKavaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/kmd.ts b/src/coin/kmd.ts index b65c62de..333f6478 100644 --- a/src/coin/kmd.ts +++ b/src/coin/kmd.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const kmd = { coinType, encode: encodeKmdAddress, decode: decodeKmdAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ksm.ts b/src/coin/ksm.ts index d32224c9..67d74aba 100644 --- a/src/coin/ksm.ts +++ b/src/coin/ksm.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createDotAddressDecoder, createDotAddressEncoder, @@ -17,4 +17,4 @@ export const ksm = { coinType, encode: encodeKsmAddress, decode: decodeKsmAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/lcc.ts b/src/coin/lcc.ts index 1d838bd7..a170db70 100644 --- a/src/coin/lcc.ts +++ b/src/coin/lcc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const lcc = { coinType, encode: encodeLccAddress, decode: decodeLccAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/lrg.ts b/src/coin/lrg.ts index f2c43c3b..2c8d90d7 100644 --- a/src/coin/lrg.ts +++ b/src/coin/lrg.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const lrg = { coinType, encode: encodeLrgAddress, decode: decodeLrgAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/lsk.ts b/src/coin/lsk.ts index d518d5bf..0116ea7b 100644 --- a/src/coin/lsk.ts +++ b/src/coin/lsk.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base10ToBytes, bytesToBase10 } from "../utils/bytes.js"; const name = "lsk"; @@ -22,4 +22,4 @@ export const lsk = { coinType, encode: encodeLskAddress, decode: decodeLskAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ltc.ts b/src/coin/ltc.ts index fda6404b..514f41f6 100644 --- a/src/coin/ltc.ts +++ b/src/coin/ltc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const ltc = { coinType, encode: encodeLtcAddress, decode: decodeLtcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/luna.ts b/src/coin/luna.ts index 52de9de5..4ce1333f 100644 --- a/src/coin/luna.ts +++ b/src/coin/luna.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "luna"; @@ -14,4 +14,4 @@ export const luna = { coinType, encode: encodeLunaAddress, decode: decodeLunaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/matic.test.ts b/src/coin/matic.test.ts deleted file mode 100644 index 348bd4ce..00000000 --- a/src/coin/matic.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeMaticAddress, encodeMaticAddress } from "./matic.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("matic address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeMaticAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeMaticAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/matic.ts b/src/coin/matic.ts deleted file mode 100644 index 72e31a1b..00000000 --- a/src/coin/matic.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "matic"; -const evmChainId = 137; -const coinType = 2147483785; - -export const encodeMaticAddress = createHexChecksummedEncoder(); -export const decodeMaticAddress = createHexChecksummedDecoder(); - -export const matic = { - name, - coinType, - evmChainId, - encode: encodeMaticAddress, - decode: decodeMaticAddress, -} as const satisfies Coin; diff --git a/src/coin/mona.ts b/src/coin/mona.ts index ad952783..8dccd1cc 100644 --- a/src/coin/mona.ts +++ b/src/coin/mona.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const mona = { coinType, encode: encodeMonaAddress, decode: decodeMonaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/mrx.ts b/src/coin/mrx.ts index 669fc469..9d8b66b4 100644 --- a/src/coin/mrx.ts +++ b/src/coin/mrx.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "mrx"; @@ -12,4 +12,4 @@ export const mrx = { coinType, encode: encodeMrxAddress, decode: decodeMrxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nano.ts b/src/coin/nano.ts index 7c2a0bb5..1cbcaadf 100644 --- a/src/coin/nano.ts +++ b/src/coin/nano.ts @@ -1,6 +1,6 @@ import { blake2b } from "@noble/hashes/blake2b"; import { utils, type Coder } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "nano"; const coinType = 165; @@ -69,4 +69,4 @@ export const nano = { coinType, encode: encodeNanoAddress, decode: decodeNanoAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nas.ts b/src/coin/nas.ts index b4a862b0..5d5539ec 100644 --- a/src/coin/nas.ts +++ b/src/coin/nas.ts @@ -1,6 +1,6 @@ import { sha3_256 } from "@noble/hashes/sha3"; import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -33,4 +33,4 @@ export const nas = { coinType, encode: encodeNasAddress, decode: decodeNasAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/near.ts b/src/coin/near.ts index 54578b0f..69890f7f 100644 --- a/src/coin/near.ts +++ b/src/coin/near.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToString, stringToBytes } from "../utils/bytes.js"; import { validateNearAddress } from "../utils/near.js"; @@ -22,4 +22,4 @@ export const near = { coinType, encode: encodeNearAddress, decode: decodeNearAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/neo.ts b/src/coin/neo.ts index 3a5c701a..7483eed3 100644 --- a/src/coin/neo.ts +++ b/src/coin/neo.ts @@ -1,8 +1,8 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "neo"; -const coinType = 239; +const coinType = 888; export const encodeNeoAddress = base58CheckEncode; export const decodeNeoAddress = base58CheckDecode; @@ -12,4 +12,4 @@ export const neo = { coinType, encode: encodeNeoAddress, decode: decodeNeoAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nim.ts b/src/coin/nim.ts index 0aa746ff..213e8f60 100644 --- a/src/coin/nim.ts +++ b/src/coin/nim.ts @@ -1,5 +1,5 @@ import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "nim"; const coinType = 242; @@ -63,4 +63,4 @@ export const nim = { coinType, encode: encodeNimAddress, decode: decodeNimAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nmc.ts b/src/coin/nmc.ts index f34f2a80..2f989525 100644 --- a/src/coin/nmc.ts +++ b/src/coin/nmc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "nmc"; @@ -12,4 +12,4 @@ export const nmc = { coinType, encode: encodeNmcAddress, decode: decodeNmcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nostr.ts b/src/coin/nostr.ts index 4d2133cb..5102aace 100644 --- a/src/coin/nostr.ts +++ b/src/coin/nostr.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "nostr"; @@ -14,4 +14,4 @@ export const nostr = { coinType, encode: encodeNostrAddress, decode: decodeNostrAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nrg.test.ts b/src/coin/nrg.test.ts deleted file mode 100644 index 9bfffd64..00000000 --- a/src/coin/nrg.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeNrgAddress, encodeNrgAddress } from "./nrg.js"; - -describe.each([ - { - text: "0x7e534bc64A80e56dB3eEDBd1b54639C3A9a7CDEA", - hex: "7e534bc64a80e56db3eedbd1b54639c3a9a7cdea", - }, -])("nrg address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeNrgAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeNrgAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/nrg.ts b/src/coin/nrg.ts deleted file mode 100644 index c3c1013c..00000000 --- a/src/coin/nrg.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "nrg"; -const evmChainId = 39797; -const coinType = 2147523445; - -export const encodeNrgAddress = createHexChecksummedEncoder(); -export const decodeNrgAddress = createHexChecksummedDecoder(); - -export const nrg = { - name, - coinType, - evmChainId, - encode: encodeNrgAddress, - decode: decodeNrgAddress, -} as const satisfies Coin; diff --git a/src/coin/nrgLegacy.ts b/src/coin/nrgLegacy.ts index cdc87470..fae9134c 100644 --- a/src/coin/nrgLegacy.ts +++ b/src/coin/nrgLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const nrgLegacy = { coinType, encode: encodeNrgLegacyAddress, decode: decodeNrgLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/nuls.ts b/src/coin/nuls.ts index 669573d9..ba3bbaf1 100644 --- a/src/coin/nuls.ts +++ b/src/coin/nuls.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -77,4 +77,4 @@ export const nuls = { coinType, encode: encodeNulsAddress, decode: decodeNulsAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/one.ts b/src/coin/one.ts index 97f8d177..6d2be923 100644 --- a/src/coin/one.ts +++ b/src/coin/one.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "one"; @@ -14,4 +14,4 @@ export const one = { coinType, encode: encodeOneAddress, decode: decodeOneAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ont.ts b/src/coin/ont.ts index ea771216..ef064f2b 100644 --- a/src/coin/ont.ts +++ b/src/coin/ont.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "ont"; @@ -23,4 +23,4 @@ export const ont = { coinType, encode: encodeOntAddress, decode: decodeOntAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/op.test.ts b/src/coin/op.test.ts deleted file mode 100644 index a0072027..00000000 --- a/src/coin/op.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeOpAddress, encodeOpAddress } from "./op.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("op address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeOpAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeOpAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/op.ts b/src/coin/op.ts deleted file mode 100644 index 5f705e1b..00000000 --- a/src/coin/op.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "op"; -const evmChainId = 10; -const coinType = 2147483658; - -export const encodeOpAddress = createHexChecksummedEncoder(); -export const decodeOpAddress = createHexChecksummedDecoder(); - -export const op = { - name, - coinType, - evmChainId, - encode: encodeOpAddress, - decode: decodeOpAddress, -} as const satisfies Coin; diff --git a/src/coin/poa.test.ts b/src/coin/poa.test.ts deleted file mode 100644 index 26cb6785..00000000 --- a/src/coin/poa.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodePoaAddress, encodePoaAddress } from "./poa.js"; - -describe.each([ - { - text: "0xF977814e90dA44bFA03b6295A0616a897441aceC", - hex: "f977814e90da44bfa03b6295a0616a897441acec", - }, - { - text: "0xBE0eB53F46cd790Cd13851d5EFf43D12404d33E8", - hex: "be0eb53f46cd790cd13851d5eff43d12404d33e8", - }, -])("poa address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodePoaAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodePoaAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/poa.ts b/src/coin/poa.ts deleted file mode 100644 index cb520a53..00000000 --- a/src/coin/poa.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "poa"; -const evmChainId = 99; -const coinType = 2147483747; - -export const encodePoaAddress = createHexChecksummedEncoder(); -export const decodePoaAddress = createHexChecksummedDecoder(); - -export const poa = { - name, - coinType, - evmChainId, - encode: encodePoaAddress, - decode: decodePoaAddress, -} as const satisfies Coin; diff --git a/src/coin/poaLegacy.ts b/src/coin/poaLegacy.ts index 90e839d5..0be872ae 100644 --- a/src/coin/poaLegacy.ts +++ b/src/coin/poaLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const poaLegacy = { coinType, encode: encodePoaLegacyAddress, decode: decodePoaLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/ppc.ts b/src/coin/ppc.ts index ba5aa136..64f333e2 100644 --- a/src/coin/ppc.ts +++ b/src/coin/ppc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const ppc = { coinType, encode: encodePpcAddress, decode: decodePpcAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/qtum.ts b/src/coin/qtum.ts index 15a8f1a7..6d0f48e5 100644 --- a/src/coin/qtum.ts +++ b/src/coin/qtum.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "qtum"; @@ -12,4 +12,4 @@ export const qtum = { coinType, encode: encodeQtumAddress, decode: decodeQtumAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/rsk.test.ts b/src/coin/rbtc.test.ts similarity index 65% rename from src/coin/rsk.test.ts rename to src/coin/rbtc.test.ts index 307ba77b..4230c448 100644 --- a/src/coin/rsk.test.ts +++ b/src/coin/rbtc.test.ts @@ -1,6 +1,6 @@ import { hexToBytes } from "@noble/hashes/utils"; import { describe, expect, test } from "bun:test"; -import { decodeRskAddress, encodeRskAddress } from "./rsk.js"; +import { decodeRbtcAddress, encodeRbtcAddress } from "./rbtc.js"; describe.each([ { @@ -9,9 +9,9 @@ describe.each([ }, ])("rsk address", ({ text, hex }) => { test(`encode: ${text}`, () => { - expect(encodeRskAddress(hexToBytes(hex))).toEqual(text); + expect(encodeRbtcAddress(hexToBytes(hex))).toEqual(text); }); test(`decode: ${text}`, () => { - expect(decodeRskAddress(text)).toEqual(hexToBytes(hex)); + expect(decodeRbtcAddress(text)).toEqual(hexToBytes(hex)); }); }); diff --git a/src/coin/rbtc.ts b/src/coin/rbtc.ts new file mode 100644 index 00000000..cf4dad1b --- /dev/null +++ b/src/coin/rbtc.ts @@ -0,0 +1,20 @@ +import type { CheckedCoin } from "../types.js"; +import { + createHexChecksummedDecoder, + createHexChecksummedEncoder, +} from "../utils/hex.js"; + +const name = "rbtc"; +const coinType = 137; + +const chainId = 30; + +export const encodeRbtcAddress = createHexChecksummedEncoder(chainId); +export const decodeRbtcAddress = createHexChecksummedDecoder(chainId); + +export const rbtc = { + name, + coinType, + encode: encodeRbtcAddress, + decode: decodeRbtcAddress, +} as const satisfies CheckedCoin; diff --git a/src/coin/rdd.ts b/src/coin/rdd.ts index b21321da..5dd5a154 100644 --- a/src/coin/rdd.ts +++ b/src/coin/rdd.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const rdd = { coinType, encode: encodeRddAddress, decode: decodeRddAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/rsk.ts b/src/coin/rsk.ts deleted file mode 100644 index 7dc7cbeb..00000000 --- a/src/coin/rsk.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "rsk"; -const coinType = 137; - -const chainId = 30; - -export const encodeRskAddress = createHexChecksummedEncoder(chainId); -export const decodeRskAddress = createHexChecksummedDecoder(chainId); - -export const rsk = { - name, - coinType, - encode: encodeRskAddress, - decode: decodeRskAddress, -} as const satisfies Coin; diff --git a/src/coin/rune.ts b/src/coin/rune.ts index 4049e1a9..96902ffa 100644 --- a/src/coin/rune.ts +++ b/src/coin/rune.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "rune"; @@ -14,4 +14,4 @@ export const rune = { coinType, encode: encodeRuneAddress, decode: decodeRuneAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/rvn.ts b/src/coin/rvn.ts index 8da3d95d..b211a000 100644 --- a/src/coin/rvn.ts +++ b/src/coin/rvn.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const rvn = { coinType, encode: encodeRvnAddress, decode: decodeRvnAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/sc.ts b/src/coin/sc.ts index dd4686ae..d1b60ce9 100644 --- a/src/coin/sc.ts +++ b/src/coin/sc.ts @@ -1,7 +1,7 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHexWithoutPrefix, hexWithoutPrefixToBytes, @@ -39,4 +39,4 @@ export const sc = { coinType, encode: encodeScAddress, decode: decodeScAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/sero.ts b/src/coin/sero.ts index 5a377a65..585e8752 100644 --- a/src/coin/sero.ts +++ b/src/coin/sero.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -19,4 +19,4 @@ export const sero = { coinType, encode: encodeSeroAddress, decode: decodeSeroAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/sol.test.ts b/src/coin/sol.test.ts index 8fbd174e..0d374b28 100644 --- a/src/coin/sol.test.ts +++ b/src/coin/sol.test.ts @@ -18,11 +18,6 @@ describe.each([ text: "CNR8RPMxjY28VsPA6KFq3B8PUdZnrTSC5HSFwKPBR29Z", hex: "a8ed08e3e8fe204de45e7295cc1ad53db096621b878f8c546e5c09f5e48f70b4", }, - // The old test case (same as TRON and NMC), only keep it for reference purpose. - { - text: "TUrMmF9Gd4rzrXsQ34ui3Wou94E7HFuJQh", - hex: "41cf1ecacaf90a04bb0297f9991ae1262d0a3399e13d6d96c2", - }, ])("sol address", ({ text, hex }) => { test(`encode: ${text}`, () => { expect(encodeSolAddress(hexToBytes(hex))).toEqual(text); @@ -31,3 +26,17 @@ describe.each([ expect(decodeSolAddress(text)).toEqual(hexToBytes(hex)); }); }); + +test("SOL decoding - incorrect length", () => { + expect(() => + decodeSolAddress("CNR8RPMxjY28VsPA6KFq3B8PUdZnrTSC5HSFwKPBR2") + ).toThrow("Unrecognised address format"); +}); + +test("SOL encoding - incorrect length", () => { + expect(() => + encodeSolAddress( + hexToBytes("a8ed08e3e8fe204de45e7295cc1ad53db096621b878f8c546e5c09f5e48f") + ) + ).toThrow("Unrecognised address format"); +}); diff --git a/src/coin/sol.ts b/src/coin/sol.ts index c91b2203..06ca7625 100644 --- a/src/coin/sol.ts +++ b/src/coin/sol.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -7,12 +7,28 @@ import { const name = "sol"; const coinType = 501; -export const encodeSolAddress = base58UncheckedEncode; -export const decodeSolAddress = base58UncheckedDecode; +export const encodeSolAddress = (source: Uint8Array) => { + if (source.length !== 32) throw new Error("Unrecognised address format"); + + const encoded = base58UncheckedEncode(source); + if (encoded.length < 32 || encoded.length > 44) + throw new Error("Unrecognised address format"); + + return encoded; +}; +export const decodeSolAddress = (source: string) => { + if (source.length < 32 || source.length > 44) + throw new Error("Unrecognised address format"); + + const decoded = base58UncheckedDecode(source); + if (decoded.length !== 32) throw new Error("Unrecognised address format"); + + return decoded; +}; export const sol = { name, coinType, encode: encodeSolAddress, decode: decodeSolAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/srm.ts b/src/coin/srm.ts index 97d03878..511d3c73 100644 --- a/src/coin/srm.ts +++ b/src/coin/srm.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -15,4 +15,4 @@ export const srm = { coinType, encode: encodeSrmAddress, decode: decodeSrmAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/steem.ts b/src/coin/steem.ts index 5fee222f..2b3a801c 100644 --- a/src/coin/steem.ts +++ b/src/coin/steem.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createEosDecoder, createEosEncoder } from "../utils/eosio.js"; const name = "steem"; @@ -14,4 +14,4 @@ export const steem = { coinType, encode: encodeSteemAddress, decode: decodeSteemAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/strat.ts b/src/coin/strat.ts index 697540e6..06ad67da 100644 --- a/src/coin/strat.ts +++ b/src/coin/strat.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const strat = { coinType, encode: encodeStratAddress, decode: decodeStratAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/strk.ts b/src/coin/strk.ts index d3b35479..4a8f2003 100644 --- a/src/coin/strk.ts +++ b/src/coin/strk.ts @@ -1,5 +1,5 @@ import { keccak_256 } from "@noble/hashes/sha3"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHexWithoutPrefix, hexToBytes, @@ -47,4 +47,4 @@ export const strk = { coinType, encode: encodeStrkAddress, decode: decodeStrkAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/stx.ts b/src/coin/stx.ts index 99e0a7f1..207f754b 100644 --- a/src/coin/stx.ts +++ b/src/coin/stx.ts @@ -2,7 +2,7 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { sha256 } from "@noble/hashes/sha256"; import { concatBytes } from "@noble/hashes/utils"; import { utils, type Coder } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base32CrockfordNormalise } from "../utils/base32.js"; const name = "stx"; @@ -104,4 +104,4 @@ export const stx = { coinType, encode: encodeStxAddress, decode: decodeStxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/sys.ts b/src/coin/sys.ts index fe8cda06..a1ebbf3a 100644 --- a/src/coin/sys.ts +++ b/src/coin/sys.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBitcoinDecoder, createBitcoinEncoder, @@ -27,4 +27,4 @@ export const sys = { coinType, encode: encodeSysAddress, decode: decodeSysAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/tfuel.ts b/src/coin/tfuel.ts index 9a6b5ca2..56d64367 100644 --- a/src/coin/tfuel.ts +++ b/src/coin/tfuel.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const tfuel = { coinType, encode: encodeTfuelAddress, decode: decodeTfuelAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/theta.test.ts b/src/coin/theta.test.ts deleted file mode 100644 index 0024b94f..00000000 --- a/src/coin/theta.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeThetaAddress, encodeThetaAddress } from "./theta.js"; - -describe.each([ - { - text: "0x314159265dD8dbb310642f98f50C066173C1259b", - hex: "314159265dd8dbb310642f98f50c066173c1259b", - }, -])("theta address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeThetaAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeThetaAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/theta.ts b/src/coin/theta.ts deleted file mode 100644 index 7f832d70..00000000 --- a/src/coin/theta.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "theta"; -const evmChainId = 361; -const coinType = 2147484009; - -export const encodeThetaAddress = createHexChecksummedEncoder(); -export const decodeThetaAddress = createHexChecksummedDecoder(); - -export const theta = { - name, - coinType, - evmChainId, - encode: encodeThetaAddress, - decode: decodeThetaAddress, -} as const satisfies Coin; diff --git a/src/coin/thetaLegacy.ts b/src/coin/thetaLegacy.ts index 76ac15c7..2e6b1192 100644 --- a/src/coin/thetaLegacy.ts +++ b/src/coin/thetaLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const thetaLegacy = { coinType, encode: encodeThetaLegacyAddress, decode: decodeThetaLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/tomo.test.ts b/src/coin/tomo.test.ts deleted file mode 100644 index 7d27dbf6..00000000 --- a/src/coin/tomo.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeTomoAddress, encodeTomoAddress } from "./tomo.js"; - -describe.each([ - { - text: "0xf5C9206843DAe847DdFd551ef7b850895430EcA3", - hex: "f5c9206843dae847ddfd551ef7b850895430eca3", - }, - { - text: "0x15813DAE07E373DC800690031A1385eB7faDe49F", - hex: "15813dae07e373dc800690031a1385eb7fade49f", - }, -])("tomo address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeTomoAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeTomoAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/tomo.ts b/src/coin/tomo.ts deleted file mode 100644 index 12ff3ec6..00000000 --- a/src/coin/tomo.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "tomo"; -const evmChainId = 88; -const coinType = 2147483736; - -export const encodeTomoAddress = createHexChecksummedEncoder(); -export const decodeTomoAddress = createHexChecksummedDecoder(); - -export const tomo = { - name, - coinType, - evmChainId, - encode: encodeTomoAddress, - decode: decodeTomoAddress, -} as const satisfies Coin; diff --git a/src/coin/tomoLegacy.ts b/src/coin/tomoLegacy.ts index d51bcef1..4beee9fc 100644 --- a/src/coin/tomoLegacy.ts +++ b/src/coin/tomoLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const tomoLegacy = { coinType, encode: encodeTomoLegacyAddress, decode: decodeTomoLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/trx.ts b/src/coin/trx.ts index 5d9f19e1..98e5cd7c 100644 --- a/src/coin/trx.ts +++ b/src/coin/trx.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "trx"; @@ -12,4 +12,4 @@ export const trx = { coinType, encode: encodeTrxAddress, decode: decodeTrxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/tt.test.ts b/src/coin/tt.test.ts deleted file mode 100644 index 8505447e..00000000 --- a/src/coin/tt.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { hexToBytes } from "@noble/hashes/utils"; -import { describe, expect, test } from "bun:test"; -import { decodeTtAddress, encodeTtAddress } from "./tt.js"; - -describe.each([ - { - text: "0x1001EEc06f2aDff074fC2A9492e132c33d6bd54d", - hex: "1001eec06f2adff074fc2a9492e132c33d6bd54d", - }, -])("tt address", ({ text, hex }) => { - test(`encode: ${text}`, () => { - expect(encodeTtAddress(hexToBytes(hex))).toEqual(text); - }); - test(`decode: ${text}`, () => { - expect(decodeTtAddress(text)).toEqual(hexToBytes(hex)); - }); -}); diff --git a/src/coin/tt.ts b/src/coin/tt.ts deleted file mode 100644 index bcea0ea6..00000000 --- a/src/coin/tt.ts +++ /dev/null @@ -1,20 +0,0 @@ -import type { Coin } from "../types.js"; -import { - createHexChecksummedDecoder, - createHexChecksummedEncoder, -} from "../utils/hex.js"; - -const name = "tt"; -const evmChainId = 108; -const coinType = 2147483756; - -export const encodeTtAddress = createHexChecksummedEncoder(); -export const decodeTtAddress = createHexChecksummedDecoder(); - -export const tt = { - name, - coinType, - evmChainId, - encode: encodeTtAddress, - decode: decodeTtAddress, -} as const satisfies Coin; diff --git a/src/coin/ttLegacy.ts b/src/coin/ttLegacy.ts index 2cfb8ba5..776f337a 100644 --- a/src/coin/ttLegacy.ts +++ b/src/coin/ttLegacy.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, @@ -15,4 +15,4 @@ export const ttLegacy = { coinType, encode: encodeTtLegacyAddress, decode: decodeTtLegacyAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/vet.ts b/src/coin/vet.ts index 6d4e4b4c..97652d58 100644 --- a/src/coin/vet.ts +++ b/src/coin/vet.ts @@ -1,11 +1,11 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createHexChecksummedDecoder, createHexChecksummedEncoder, } from "../utils/hex.js"; const name = "vet"; -const coinType = 703; +const coinType = 818; export const encodeVetAddress = createHexChecksummedEncoder(); export const decodeVetAddress = createHexChecksummedDecoder(); @@ -15,4 +15,4 @@ export const vet = { coinType, encode: encodeVetAddress, decode: decodeVetAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/via.ts b/src/coin/via.ts index 1de7df2d..2c1a4d6b 100644 --- a/src/coin/via.ts +++ b/src/coin/via.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const via = { coinType, encode: encodeViaAddress, decode: decodeViaAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/vlx.ts b/src/coin/vlx.ts index 3fe2cfba..0e964cd4 100644 --- a/src/coin/vlx.ts +++ b/src/coin/vlx.ts @@ -1,11 +1,11 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, } from "../utils/base58.js"; const name = "vlx"; -const coinType = 574; +const coinType = 5655640; export const encodeVlxAddress = base58UncheckedEncode; export const decodeVlxAddress = base58UncheckedDecode; @@ -15,4 +15,4 @@ export const vlx = { coinType, encode: encodeVlxAddress, decode: decodeVlxAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/vlxLegacy.test.ts b/src/coin/vlxLegacy.test.ts new file mode 100644 index 00000000..9f85145b --- /dev/null +++ b/src/coin/vlxLegacy.test.ts @@ -0,0 +1,17 @@ +import { hexToBytes } from "@noble/hashes/utils"; +import { describe, expect, test } from "bun:test"; +import { decodeVlxAddress, encodeVlxAddress } from "./vlx.js"; + +describe.each([ + { + text: "VDTHiswjSTkLFbfh2S5XFsqkLzC11HoBD6", + hex: "461ea68e5e13c72abf1bd2f0bcae4650521712cdb76276f0d5", + }, +])("vlx address", ({ text, hex }) => { + test(`encode: ${text}`, () => { + expect(encodeVlxAddress(hexToBytes(hex))).toEqual(text); + }); + test(`decode: ${text}`, () => { + expect(decodeVlxAddress(text)).toEqual(hexToBytes(hex)); + }); +}); diff --git a/src/coin/vlxLegacy.ts b/src/coin/vlxLegacy.ts new file mode 100644 index 00000000..77efbdf7 --- /dev/null +++ b/src/coin/vlxLegacy.ts @@ -0,0 +1,18 @@ +import type { CheckedCoin } from "../types.js"; +import { + base58UncheckedDecode, + base58UncheckedEncode, +} from "../utils/base58.js"; + +const name = "vlxLegacy"; +const coinType = 574; + +export const encodeVlxLegacyAddress = base58UncheckedEncode; +export const decodeVlxLegacyAddress = base58UncheckedDecode; + +export const vlxLegacy = { + name, + coinType, + encode: encodeVlxLegacyAddress, + decode: decodeVlxLegacyAddress, +} as const satisfies CheckedCoin; diff --git a/src/coin/vsys.ts b/src/coin/vsys.ts index ba288717..232f74d9 100644 --- a/src/coin/vsys.ts +++ b/src/coin/vsys.ts @@ -1,7 +1,7 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { blake2b } from "@noble/hashes/blake2b"; import { keccak_256 } from "@noble/hashes/sha3"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -41,4 +41,4 @@ export const vsys = { coinType, encode: encodeVsysAddress, decode: decodeVsysAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/wan.ts b/src/coin/wan.ts index 83b1c631..57b70a71 100644 --- a/src/coin/wan.ts +++ b/src/coin/wan.ts @@ -1,5 +1,5 @@ import { keccak_256 } from "@noble/hashes/sha3"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { bytesToHexWithoutPrefix, hexToBytes, @@ -51,4 +51,4 @@ export const wan = { coinType, encode: encodeWanAddress, decode: decodeWanAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/waves.ts b/src/coin/waves.ts index 4c5206c1..fbb66c83 100644 --- a/src/coin/waves.ts +++ b/src/coin/waves.ts @@ -1,7 +1,7 @@ import { blake2b } from "@noble/hashes/blake2b"; import { keccak_256 } from "@noble/hashes/sha3"; import { utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58UncheckedDecode, base58UncheckedEncode, @@ -34,4 +34,4 @@ export const waves = { coinType, encode: encodeWavesAddress, decode: decodeWavesAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/wicc.ts b/src/coin/wicc.ts index ed030316..55dfd8db 100644 --- a/src/coin/wicc.ts +++ b/src/coin/wicc.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const wicc = { coinType, encode: encodeWiccAddress, decode: decodeWiccAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xch.ts b/src/coin/xch.ts index 508f8c2e..cca13e0d 100644 --- a/src/coin/xch.ts +++ b/src/coin/xch.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32mDecoder, createBech32mEncoder } from "../utils/bech32.js"; const name = "xch"; @@ -15,4 +15,4 @@ export const xch = { coinType, encode: encodeXchAddress, decode: decodeXchAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xem.ts b/src/coin/xem.ts index 7e312a23..5e9cb0df 100644 --- a/src/coin/xem.ts +++ b/src/coin/xem.ts @@ -1,5 +1,5 @@ import { keccak_256 } from "@noble/hashes/sha3"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base32Decode, base32Encode } from "../utils/base32.js"; import { bytesToHexWithoutPrefix } from "../utils/bytes.js"; @@ -30,4 +30,4 @@ export const xem = { coinType, encode: encodeXemAddress, decode: decodeXemAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xhv.ts b/src/coin/xhv.ts index fc36e45b..96893265 100644 --- a/src/coin/xhv.ts +++ b/src/coin/xhv.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { decodeXmrAddress, encodeXmrAddress } from "./xmr.js"; const name = "xhv"; @@ -12,4 +12,4 @@ export const xhv = { coinType, encode: encodeXhvAddress, decode: decodeXhvAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xlm.ts b/src/coin/xlm.ts index 5782549f..d878e0cb 100644 --- a/src/coin/xlm.ts +++ b/src/coin/xlm.ts @@ -1,6 +1,6 @@ import { equalBytes } from "@noble/curves/abstract/utils"; import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base32Decode, base32Encode } from "../utils/base32.js"; import { hexWithoutPrefixToBytes } from "../utils/bytes.js"; @@ -59,4 +59,4 @@ export const xlm = { coinType, encode: encodeXlmAddress, decode: decodeXlmAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xmr.ts b/src/coin/xmr.ts index b204692c..c1ec42c0 100644 --- a/src/coin/xmr.ts +++ b/src/coin/xmr.ts @@ -1,5 +1,5 @@ import { base58xmr } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "xmr"; const coinType = 128; @@ -12,4 +12,4 @@ export const xmr = { coinType, encode: encodeXmrAddress, decode: decodeXmrAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xrp.ts b/src/coin/xrp.ts index a025598e..e0f8b548 100644 --- a/src/coin/xrp.ts +++ b/src/coin/xrp.ts @@ -1,6 +1,6 @@ import { sha256 } from "@noble/hashes/sha256"; import { base58xrp, utils } from "@scure/base"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; const name = "xrp"; const coinType = 144; @@ -18,4 +18,4 @@ export const xrp = { coinType, encode: encodeXrpAddress, decode: decodeXrpAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xtz.ts b/src/coin/xtz.ts index 1d4871af..46dd85d2 100644 --- a/src/coin/xtz.ts +++ b/src/coin/xtz.ts @@ -1,5 +1,5 @@ import { concatBytes } from "@noble/hashes/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "xtz"; @@ -55,4 +55,4 @@ export const xtz = { coinType, encode: encodeXtzAddress, decode: decodeXtzAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/xvg.ts b/src/coin/xvg.ts index b57690c5..96fa3527 100644 --- a/src/coin/xvg.ts +++ b/src/coin/xvg.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBase58VersionedDecoder, createBase58VersionedEncoder, @@ -24,4 +24,4 @@ export const xvg = { coinType, encode: encodeXvgAddress, decode: decodeXvgAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/zec.ts b/src/coin/zec.ts index 7fa9f991..91b4c8c1 100644 --- a/src/coin/zec.ts +++ b/src/coin/zec.ts @@ -1,4 +1,4 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createZcashDecoder, createZcashEncoder } from "../utils/zcash.js"; const name = "zec"; @@ -24,4 +24,4 @@ export const zec = { coinType, encode: encodeZecAddress, decode: decodeZecAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/zen.ts b/src/coin/zen.ts index 4d283d59..f770c0b4 100644 --- a/src/coin/zen.ts +++ b/src/coin/zen.ts @@ -1,5 +1,5 @@ import { equalBytes } from "@noble/curves/abstract/utils"; -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { base58CheckDecode, base58CheckEncode } from "../utils/base58.js"; const name = "zen"; @@ -35,4 +35,4 @@ export const zen = { coinType, encode: encodeZenAddress, decode: decodeZenAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coin/zil.ts b/src/coin/zil.ts index 8c1123c6..09ee5edc 100644 --- a/src/coin/zil.ts +++ b/src/coin/zil.ts @@ -1,8 +1,8 @@ -import type { Coin } from "../types.js"; +import type { CheckedCoin } from "../types.js"; import { createBech32Decoder, createBech32Encoder } from "../utils/bech32.js"; const name = "zil"; -const coinType = 119; +const coinType = 313; export const encodeZilAddress = createBech32Encoder("zil"); export const decodeZilAddress = createBech32Decoder("zil"); @@ -12,4 +12,4 @@ export const zil = { coinType, encode: encodeZilAddress, decode: decodeZilAddress, -} as const satisfies Coin; +} as const satisfies CheckedCoin; diff --git a/src/coins.test.ts b/src/coins.test.ts new file mode 100644 index 00000000..9bb14e08 --- /dev/null +++ b/src/coins.test.ts @@ -0,0 +1,14 @@ +import { expect, test } from "bun:test"; +import * as coins from "./coins.js"; +import { nonEvmCoinNameToTypeMap } from "./consts/coinNameToTypeMap.js"; + +const coinNames = Object.keys(nonEvmCoinNameToTypeMap); + +test.each(coinNames)("coins.ts export - %s", (coinName) => { + const obj = coins[coinName]; + expect(obj).toBeObject(); + expect(obj.name).toBe(coinName); + expect(obj.coinType).toBe(nonEvmCoinNameToTypeMap[coinName]); + expect(obj.encode).toBeFunction(); + expect(obj.decode).toBeFunction(); +}); diff --git a/src/coins.ts b/src/coins.ts index 2f2b91b2..a17852aa 100644 --- a/src/coins.ts +++ b/src/coins.ts @@ -5,19 +5,16 @@ export { aib } from "./coin/aib.js"; export { aion } from "./coin/aion.js"; export { algo } from "./coin/algo.js"; export { ar } from "./coin/ar.js"; -export { arb1 } from "./coin/arb1.js"; export { ardr } from "./coin/ardr.js"; export { ark } from "./coin/ark.js"; export { atom } from "./coin/atom.js"; export { avax } from "./coin/avax.js"; -export { avaxc } from "./coin/avaxc.js"; export { bcd } from "./coin/bcd.js"; export { bch } from "./coin/bch.js"; export { bcn } from "./coin/bcn.js"; export { bdx } from "./coin/bdx.js"; export { bnb } from "./coin/bnb.js"; export { bps } from "./coin/bps.js"; -export { bsc } from "./coin/bsc.js"; export { bsv } from "./coin/bsv.js"; export { btc } from "./coin/btc.js"; export { btg } from "./coin/btg.js"; @@ -25,12 +22,9 @@ export { btm } from "./coin/btm.js"; export { bts } from "./coin/bts.js"; export { cca } from "./coin/cca.js"; export { ccxx } from "./coin/ccxx.js"; -export { celo } from "./coin/celo.js"; export { celoLegacy } from "./coin/celoLegacy.js"; export { ckb } from "./coin/ckb.js"; -export { clo } from "./coin/clo.js"; export { cloLegacy } from "./coin/cloLegacy.js"; -export { cro } from "./coin/cro.js"; export { dash } from "./coin/dash.js"; export { dcr } from "./coin/dcr.js"; export { dgb } from "./coin/dgb.js"; @@ -40,21 +34,17 @@ export { dot } from "./coin/dot.js"; export { egld } from "./coin/egld.js"; export { ela } from "./coin/ela.js"; export { eos } from "./coin/eos.js"; -export { etc } from "./coin/etc.js"; export { etcLegacy } from "./coin/etcLegacy.js"; export { eth } from "./coin/eth.js"; export { etn } from "./coin/etn.js"; -export { ewt } from "./coin/ewt.js"; export { ewtLegacy } from "./coin/ewtLegacy.js"; export { fil } from "./coin/fil.js"; export { fio } from "./coin/fio.js"; export { firo } from "./coin/firo.js"; export { flow } from "./coin/flow.js"; -export { ftm } from "./coin/ftm.js"; +export { flux } from "./coin/flux.js"; export { ftmLegacy } from "./coin/ftmLegacy.js"; -export { gno } from "./coin/gno.js"; export { gnoLegacy } from "./coin/gnoLegacy.js"; -export { go } from "./coin/go.js"; export { goLegacy } from "./coin/goLegacy.js"; export { grin } from "./coin/grin.js"; export { gxc } from "./coin/gxc.js"; @@ -75,7 +65,6 @@ export { lrg } from "./coin/lrg.js"; export { lsk } from "./coin/lsk.js"; export { ltc } from "./coin/ltc.js"; export { luna } from "./coin/luna.js"; -export { matic } from "./coin/matic.js"; export { mona } from "./coin/mona.js"; export { mrx } from "./coin/mrx.js"; export { nano } from "./coin/nano.js"; @@ -85,18 +74,15 @@ export { neo } from "./coin/neo.js"; export { nim } from "./coin/nim.js"; export { nmc } from "./coin/nmc.js"; export { nostr } from "./coin/nostr.js"; -export { nrg } from "./coin/nrg.js"; export { nrgLegacy } from "./coin/nrgLegacy.js"; export { nuls } from "./coin/nuls.js"; export { one } from "./coin/one.js"; export { ont } from "./coin/ont.js"; -export { op } from "./coin/op.js"; -export { poa } from "./coin/poa.js"; export { poaLegacy } from "./coin/poaLegacy.js"; export { ppc } from "./coin/ppc.js"; export { qtum } from "./coin/qtum.js"; +export { rbtc } from "./coin/rbtc.js"; export { rdd } from "./coin/rdd.js"; -export { rsk } from "./coin/rsk.js"; export { rune } from "./coin/rune.js"; export { rvn } from "./coin/rvn.js"; export { sc } from "./coin/sc.js"; @@ -109,16 +95,14 @@ export { strk } from "./coin/strk.js"; export { stx } from "./coin/stx.js"; export { sys } from "./coin/sys.js"; export { tfuel } from "./coin/tfuel.js"; -export { theta } from "./coin/theta.js"; export { thetaLegacy } from "./coin/thetaLegacy.js"; -export { tomo } from "./coin/tomo.js"; export { tomoLegacy } from "./coin/tomoLegacy.js"; export { trx } from "./coin/trx.js"; -export { tt } from "./coin/tt.js"; export { ttLegacy } from "./coin/ttLegacy.js"; export { vet } from "./coin/vet.js"; export { via } from "./coin/via.js"; export { vlx } from "./coin/vlx.js"; +export { vlxLegacy } from "./coin/vlxLegacy.js"; export { vsys } from "./coin/vsys.js"; export { wan } from "./coin/wan.js"; export { waves } from "./coin/waves.js"; @@ -132,6 +116,5 @@ export { xrp } from "./coin/xrp.js"; export { xtz } from "./coin/xtz.js"; export { xvg } from "./coin/xvg.js"; export { zec } from "./coin/zec.js"; -export { zel } from "./coin/zel.js"; export { zen } from "./coin/zen.js"; export { zil } from "./coin/zil.js"; diff --git a/src/consts/coinNameToTypeMap.ts b/src/consts/coinNameToTypeMap.ts new file mode 100644 index 00000000..13acf1b0 --- /dev/null +++ b/src/consts/coinNameToTypeMap.ts @@ -0,0 +1,26 @@ +import type { ParseInt } from "../types.js"; +import { + evmCoinTypeToNameMap, + nonEvmCoinTypeToNameMap, +} from "./coinTypeToNameMap.js"; + +export const evmCoinNameToTypeMap = Object.freeze( + Object.fromEntries( + Object.entries(evmCoinTypeToNameMap).map(([k, [v]]) => [v, parseInt(k)]) + ) as { + readonly [key in keyof typeof evmCoinTypeToNameMap as (typeof evmCoinTypeToNameMap)[key][0]]: ParseInt; + } +); + +export const nonEvmCoinNameToTypeMap = Object.freeze( + Object.fromEntries( + Object.entries(nonEvmCoinTypeToNameMap).map(([k, [v]]) => [v, parseInt(k)]) + ) as { + readonly [key in keyof typeof nonEvmCoinTypeToNameMap as (typeof nonEvmCoinTypeToNameMap)[key][0]]: ParseInt; + } +); + +export const coinNameToTypeMap = Object.freeze({ + ...evmCoinNameToTypeMap, + ...nonEvmCoinNameToTypeMap, +} as const); diff --git a/src/consts/coinTypeMap.ts b/src/consts/coinTypeMap.ts deleted file mode 100644 index eea60b79..00000000 --- a/src/consts/coinTypeMap.ts +++ /dev/null @@ -1,139 +0,0 @@ -export const coinTypeMap = Object.freeze({ - "0": "btc", - "2": "ltc", - "3": "doge", - "4": "rdd", - "5": "dash", - "6": "ppc", - "7": "nmc", - "14": "via", - "20": "dgb", - "22": "mona", - "42": "dcr", - "43": "xem", - "55": "aib", - "57": "sys", - "60": "eth", - "61": "etcLegacy", - "74": "icx", - "77": "xvg", - "105": "strat", - "111": "ark", - "118": "atom", - "119": "zil", - "120": "egld", - "121": "zen", - "128": "xmr", - "133": "zec", - "134": "lsk", - "135": "steem", - "136": "firo", - "137": "rsk", - "141": "kmd", - "144": "xrp", - "145": "bch", - "148": "xlm", - "153": "btm", - "156": "btg", - "165": "nano", - "175": "rvn", - "178": "poaLegacy", - "192": "lcc", - "194": "eos", - "195": "trx", - "204": "bcn", - "235": "fio", - "236": "bsv", - "239": "neo", - "242": "nim", - "246": "ewtLegacy", - "283": "algo", - "291": "iost", - "301": "divi", - "304": "iotx", - "308": "bts", - "309": "ckb", - "326": "mrx", - "330": "luna", - "354": "dot", - "360": "vsys", - "367": "abbc", - "397": "near", - "415": "etn", - "425": "aion", - "434": "ksm", - "457": "ae", - "459": "kava", - "461": "fil", - "472": "ar", - "489": "cca", - "500": "thetaLegacy", - "501": "sol", - "535": "xhv", - "539": "flow", - "566": "iris", - "568": "lrg", - "569": "sero", - "570": "bdx", - "571": "ccxx", - "573": "srm", - "574": "vlx", - "576": "bps", - "589": "tfuel", - "592": "grin", - "700": "gnoLegacy", - "703": "vet", - "714": "bnb", - "820": "cloLegacy", - "825": "hive", - "889": "tomoLegacy", - "904": "hnt", - "931": "rune", - "999": "bcd", - "1001": "ttLegacy", - "1007": "ftmLegacy", - "1023": "one", - "1024": "ont", - "1237": "nostr", - "1729": "xtz", - "1815": "ada", - "1991": "sc", - "2301": "qtum", - "2303": "gxc", - "2305": "ela", - "2718": "nas", - "3030": "hbar", - "4218": "iota", - "5353": "hns", - "5757": "stx", - "6060": "goLegacy", - "8444": "xch", - "8964": "nuls", - "9000": "avax", - "9004": "strk", - "9797": "nrgLegacy", - "16754": "ardr", - "19167": "zel", - "52752": "celoLegacy", - "99999": "wicc", - "5718350": "wan", - "5741564": "waves", - "2147483658": "op", - "2147483673": "cro", - "2147483704": "bsc", - "2147483708": "go", - "2147483709": "etc", - "2147483736": "tomo", - "2147483747": "poa", - "2147483748": "gno", - "2147483756": "tt", - "2147483785": "matic", - "2147483894": "ewt", - "2147483898": "ftm", - "2147484009": "theta", - "2147484468": "clo", - "2147523445": "nrg", - "2147525809": "arb1", - "2147525868": "celo", - "2147526762": "avaxc", -} as const); diff --git a/src/consts/coinTypeToNameMap.ts b/src/consts/coinTypeToNameMap.ts new file mode 100644 index 00000000..f0b0bf99 --- /dev/null +++ b/src/consts/coinTypeToNameMap.ts @@ -0,0 +1,184 @@ +export const evmCoinTypeToNameMap = Object.freeze({ + /* Chain ID: 0 */ + "2147483648": ["metis", "1088"], + /* Chain ID: 10 */ + "2147483658": ["op", "Optimism"], + /* Chain ID: 25 */ + "2147483673": ["cro", "Cronos"], + /* Chain ID: 56 */ + "2147483704": ["bsc", "BNB Smart Chain"], + /* Chain ID: 60 */ + "2147483708": ["go", "GoChain"], + /* Chain ID: 61 */ + "2147483709": ["etc", "Ethereum Classic"], + /* Chain ID: 88 */ + "2147483736": ["tomo", "TomoChain"], + /* Chain ID: 99 */ + "2147483747": ["poa", "POA"], + /* Chain ID: 100 */ + "2147483748": ["gno", "Gnosis"], + /* Chain ID: 108 */ + "2147483756": ["tt", "ThunderCore"], + /* Chain ID: 137 */ + "2147483785": ["matic", "Polygon"], + /* Chain ID: 169 */ + "2147483817": ["manta", "Manta Pacific"], + /* Chain ID: 246 */ + "2147483894": ["ewt", "Energy Web"], + /* Chain ID: 250 */ + "2147483898": ["ftm", "Fantom Opera"], + /* Chain ID: 288 */ + "2147483936": ["boba", "Boba"], + /* Chain ID: 324 */ + "2147483972": ["zksync", "zkSync"], + /* Chain ID: 361 */ + "2147484009": ["theta", "Theta"], + /* Chain ID: 820 */ + "2147484468": ["clo", "Callisto"], + /* Chain ID: 5000 */ + "2147488648": ["mantle", "Mantle"], + /* Chain ID: 8453 */ + "2147492101": ["base", "Base"], + /* Chain ID: 39797 */ + "2147523445": ["nrg", "Energi"], + /* Chain ID: 42161 */ + "2147525809": ["arb1", "Arbitrum One"], + /* Chain ID: 42220 */ + "2147525868": ["celo", "Celo"], + /* Chain ID: 43114 */ + "2147526762": ["avaxc", "Avalanche C-Chain"], + /* Chain ID: 59144 */ + "2147542792": ["linea", "Linea"], + /* Chain ID: 534352 */ + "2148018000": ["scr", "Scroll"], + /* Chain ID: 7777777 */ + "2155261425": ["zora", "Zora"], +} as const); + +export const nonEvmCoinTypeToNameMap = Object.freeze({ + "0": ["btc", "Bitcoin"], + "2": ["ltc", "Litecoin"], + "3": ["doge", "Dogecoin"], + "4": ["rdd", "Reddcoin"], + "5": ["dash", "Dash"], + "6": ["ppc", "Peercoin"], + "7": ["nmc", "Namecoin"], + "14": ["via", "Viacoin"], + "20": ["dgb", "DigiByte"], + "22": ["mona", "Monacoin"], + "42": ["dcr", "Decred"], + "43": ["xem", "NEM"], + "55": ["aib", "AIB"], + "57": ["sys", "Syscoin"], + "60": ["eth", "Ethereum"], + "61": ["etcLegacy", "[LEGACY] Ethereum Classic"], + "74": ["icx", "ICON"], + "77": ["xvg", "Verge"], + "105": ["strat", "Stratis"], + "111": ["ark", "ARK"], + "118": ["atom", "Atom"], + "121": ["zen", "Zencash"], + "128": ["xmr", "Monero"], + "133": ["zec", "Zcash"], + "134": ["lsk", "Lisk"], + "135": ["steem", "Steem"], + "136": ["firo", "Firo"], + "137": ["rbtc", "RSK"], + "141": ["kmd", "Komodo"], + "144": ["xrp", "Ripple"], + "145": ["bch", "Bitcoin Cash"], + "148": ["xlm", "Stellar Lumens"], + "153": ["btm", "Bytom"], + "156": ["btg", "Bitcoin Gold"], + "165": ["nano", "Nano"], + "175": ["rvn", "Ravencoin"], + "178": ["poaLegacy", "[LEGACY] POA"], + "192": ["lcc", "LitecoinCash"], + "194": ["eos", "EOS"], + "195": ["trx", "Tron"], + "204": ["bcn", "Bytecoin"], + "235": ["fio", "FIO"], + "236": ["bsv", "BitcoinSV"], + "242": ["nim", "Nimiq"], + "246": ["ewtLegacy", "[LEGACY] Energy Web"], + "283": ["algo", "Algorand"], + "291": ["iost", "IOST"], + "301": ["divi", "Divi Project"], + "304": ["iotx", "IoTeX"], + "308": ["bts", "Bitshares"], + "309": ["ckb", "Nervos CKB"], + "313": ["zil", "Zilliqa"], + "326": ["mrx", "Metrix Coin"], + "330": ["luna", "Terra"], + "354": ["dot", "Polkadot"], + "360": ["vsys", "V Systems"], + "367": ["abbc", "ABBC"], + "397": ["near", "NEAR Protocol"], + "415": ["etn", "Electroneum"], + "425": ["aion", "Aion"], + "434": ["ksm", "Kusama"], + "457": ["ae", "æternity"], + "459": ["kava", "Kava"], + "461": ["fil", "Filecoin"], + "472": ["ar", "Arweave"], + "489": ["cca", "Counos"], + "500": ["thetaLegacy", "[LEGACY] Theta"], + "501": ["sol", "Solana"], + "508": ["egld", "MultiversX"], + "535": ["xhv", "Haven Protocol"], + "539": ["flow", "Flow"], + "566": ["iris", "Irisnet"], + "568": ["lrg", "Large Coin"], + "569": ["sero", "Super Zero Protocol"], + "570": ["bdx", "Beldex"], + "571": ["ccxx", "Counos X"], + "573": ["srm", "Serum"], + "574": ["vlxLegacy", "[LEGACY] Velas"], + "576": ["bps", "BitcoinPoS"], + "589": ["tfuel", "Theta Fuel"], + "592": ["grin", "Grin"], + "700": ["gnoLegacy", "[LEGACY] Gnosis"], + "714": ["bnb", "BNB"], + "818": ["vet", "VeChain"], + "820": ["cloLegacy", "[LEGACY] Callisto"], + "825": ["hive", "Hive"], + "888": ["neo", "NEO"], + "889": ["tomoLegacy", "[LEGACY] TomoChain"], + "904": ["hnt", "Helium"], + "931": ["rune", "THORChain"], + "999": ["bcd", "Bitcoin Diamond"], + "1001": ["ttLegacy", "[LEGACY] ThunderCore"], + "1007": ["ftmLegacy", "[LEGACY] Fantom"], + "1023": ["one", "HARMONY-ONE"], + "1024": ["ont", "Ontology"], + "1237": ["nostr", "Nostr"], + "1729": ["xtz", "Tezos"], + "1815": ["ada", "Cardano"], + "1991": ["sc", "Sia"], + "2301": ["qtum", "QTUM"], + "2303": ["gxc", "GXChain"], + "2305": ["ela", "Elastos"], + "2718": ["nas", "Nebulas"], + "3030": ["hbar", "Hedera HBAR"], + "4218": ["iota", "IOTA"], + "5353": ["hns", "Handshake"], + "5757": ["stx", "Stacks"], + "6060": ["goLegacy", "[LEGACY] GoChain"], + "8444": ["xch", "Chia"], + "8964": ["nuls", "NULS"], + "9000": ["avax", "Avalanche"], + "9004": ["strk", "StarkNet"], + "9797": ["nrgLegacy", "[LEGACY] Energi"], + "16754": ["ardr", "Ardor"], + "19167": ["flux", "Flux"], + "52752": ["celoLegacy", "[LEGACY] Celo"], + "99999": ["wicc", "Waykichain"], + "5655640": ["vlx", "Velas"], + "5718350": ["wan", "Wanchain"], + "5741564": ["waves", "Waves"], +} as const); + +export const coinTypeToNameMap = Object.freeze({ + ...nonEvmCoinTypeToNameMap, + ...evmCoinTypeToNameMap, +} as const); diff --git a/src/index.test.ts b/src/index.test.ts index 69ebd3e6..297c7038 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,14 +1,85 @@ import { expect, test } from "bun:test"; +import { + evmCoinNameToTypeMap, + nonEvmCoinNameToTypeMap, +} from "./consts/coinNameToTypeMap.js"; +import { + evmCoinTypeToNameMap, + nonEvmCoinTypeToNameMap, +} from "./consts/coinTypeToNameMap.js"; import { getCoderByCoinName, getCoderByCoinType } from "./index.js"; +import { coinTypeToEvmChainId } from "./utils/evm.js"; test("coin name", () => { const coder = getCoderByCoinName("btc"); expect(coder.coinType).toBe(0); expect(coder.name).toBe("btc"); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); }); test("coin type", () => { const coder = getCoderByCoinType(0); expect(coder.coinType).toBe(0); expect(coder.name).toBe("btc"); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +test("evm coin name", () => { + const coder = getCoderByCoinName("op"); + expect(coder.coinType).toBe(2147483658); + expect(coder.name).toBe("op"); + expect(coder.evmChainId).toBe(10); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +test("evm coin type", () => { + const coder = getCoderByCoinType(2147483658); + expect(coder.coinType).toBe(2147483658); + expect(coder.name).toBe("op"); + expect(coder.evmChainId).toBe(10); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +const nonEvmCoinNames = Object.keys(nonEvmCoinNameToTypeMap); +const evmCoinNames = Object.keys(evmCoinNameToTypeMap); + +test.each(nonEvmCoinNames)('getCoderByCoinName("%s")', (coinName) => { + const coder = getCoderByCoinName(coinName); + expect(coder.name).toBe(coinName); + expect(coder.coinType).toBe(nonEvmCoinNameToTypeMap[coinName]); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +test.each(evmCoinNames)('getCoderByCoinName("%s")', (coinName) => { + const coder = getCoderByCoinName(coinName); + expect(coder.name).toBe(coinName); + expect(coder.coinType).toBe(evmCoinNameToTypeMap[coinName]); + expect(coder.evmChainId).toBe(coinTypeToEvmChainId(coder.coinType)); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +const nonEvmCoinTypes = Object.values(nonEvmCoinNameToTypeMap); +const evmCoinTypes = Object.values(evmCoinNameToTypeMap); + +test.each(nonEvmCoinTypes)("getCoderByCoinType(%d)", (coinType) => { + const coder = getCoderByCoinType(coinType); + expect(coder.name).toBe(nonEvmCoinTypeToNameMap[coinType][0]); + expect(coder.coinType).toBe(coinType); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); +}); + +test.each(evmCoinTypes)("getCoderByCoinType(%d)", (coinType) => { + const coder = getCoderByCoinType(coinType); + expect(coder.name).toBe(evmCoinTypeToNameMap[coinType][0]); + expect(coder.coinType).toBe(coinType); + expect(coder.evmChainId).toBe(coinTypeToEvmChainId(coinType)); + expect(coder.encode).toBeFunction(); + expect(coder.decode).toBeFunction(); }); diff --git a/src/index.ts b/src/index.ts index 609748d7..bd510ca0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,51 +1,93 @@ import * as formats from "./coins.js"; -import { coinTypeMap } from "./consts/coinTypeMap.js"; +import { + coinNameToTypeMap, + evmCoinNameToTypeMap, + nonEvmCoinNameToTypeMap, +} from "./consts/coinNameToTypeMap.js"; +import { + coinTypeToNameMap, + evmCoinTypeToNameMap, + nonEvmCoinTypeToNameMap, +} from "./consts/coinTypeToNameMap.js"; import type { Coin, CoinName, CoinType, - CoinTypeInvertedReference, DecoderFunction, EncoderFunction, - Formats, + EvmCoinName, + EvmCoinType, + GetCoderByCoinName, + GetCoderByCoinType, } from "./types.js"; +import { SLIP44_MSB, coinTypeToEvmChainId } from "./utils/evm.js"; export type { Coin, CoinName, CoinType, - CoinTypeInvertedReference, DecoderFunction, EncoderFunction, - Formats, + EvmCoinName, + EvmCoinType, +}; + +export { + coinNameToTypeMap, + coinTypeToNameMap, + evmCoinNameToTypeMap, + evmCoinTypeToNameMap, + nonEvmCoinNameToTypeMap, + nonEvmCoinTypeToNameMap, }; export const getCoderByCoinName = < - TCoinName extends CoinName | string = string + TCoinName extends CoinName | string = CoinName | string >( name: TCoinName -): TCoinName extends CoinName ? Formats[TCoinName] : Coin => { +): GetCoderByCoinName => { const format = formats[name as keyof typeof formats]; if (!format) { - throw new Error(`Unsupported coin: ${name}`); + // EVM coin + const coinType = coinNameToTypeMap[name as EvmCoinName]; + if (!coinType) throw new Error(`Unsupported coin: ${name}`); + + const evmChainId = coinTypeToEvmChainId(coinType); + const ethFormat = formats["eth"]; + return { + name: name as EvmCoinName, + coinType, + evmChainId, + encode: ethFormat.encode, + decode: ethFormat.decode, + } as GetCoderByCoinName; } - return format as TCoinName extends CoinName ? Formats[TCoinName] : Coin; + return format as GetCoderByCoinName; }; export const getCoderByCoinType = < - TCoinType extends CoinType | number = number + TCoinType extends CoinType | number = CoinType | number >( coinType: TCoinType -): TCoinType extends CoinType ? CoinTypeInvertedReference[TCoinType] : Coin => { - const name = coinTypeMap[String(coinType) as keyof typeof coinTypeMap]; - if (!name) { +): GetCoderByCoinType => { + const names = + coinTypeToNameMap[String(coinType) as keyof typeof coinTypeToNameMap]; + if (!names) { throw new Error(`Unsupported coin type: ${coinType}`); } - const format = formats[name]; - if (!format) { - throw new Error(`Unsupported coin type: ${coinType}`); + const [name] = names; + if (coinType >= SLIP44_MSB) { + // EVM coin + const evmChainId = coinTypeToEvmChainId(coinType); + const ethFormat = formats["eth"]; + return { + name, + coinType: coinType as EvmCoinType, + evmChainId, + encode: ethFormat.encode, + decode: ethFormat.decode, + } as GetCoderByCoinType; } - return format as TCoinType extends CoinType - ? CoinTypeInvertedReference[TCoinType] - : Coin; + const format = formats[name as keyof typeof formats]; + return format as GetCoderByCoinType; }; diff --git a/src/types.ts b/src/types.ts index e5159f3d..f6f71a58 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,11 +1,48 @@ -import * as formats from "./coins.js"; +import type { Subtract } from "ts-arithmetic"; +import type * as formats from "./coins.js"; +import type { + coinNameToTypeMap, + evmCoinNameToTypeMap, + nonEvmCoinNameToTypeMap, +} from "./consts/coinNameToTypeMap.js"; +import type { coinTypeToNameMap } from "./consts/coinTypeToNameMap.js"; +import type { SLIP44_MSB } from "./utils/evm.js"; export type Formats = typeof formats; -export type CoinName = keyof Formats; -export type CoinType = Formats[CoinName]["coinType"]; -export type CoinTypeInvertedReference = { - [key in CoinName as Formats[key]["coinType"]]: Formats[key]; +export type CoinNameToTypeMap = typeof coinNameToTypeMap; +export type CoinTypeToNameMap = typeof coinTypeToNameMap; + +export type CoinName = keyof CoinNameToTypeMap; +export type CoinType = CoinNameToTypeMap[CoinName]; +type NonEvmCoinTypeToFormat = { + [key in keyof Formats as Formats[key]["coinType"]]: Formats[key]; +}; +export type CoinTypeToFormatMap = { + [key in CoinType]: key extends EvmCoinType + ? Prettify> + : key extends keyof NonEvmCoinTypeToFormat + ? NonEvmCoinTypeToFormat[key] + : never; +}; +export type CoinNameToFormatMap = { + [key in CoinName]: CoinTypeToFormatMap[CoinNameToTypeMap[key]]; +}; + +export type EvmCoinMap = typeof evmCoinNameToTypeMap; +export type EvmCoinName = keyof EvmCoinMap; +export type EvmCoinType = EvmCoinMap[EvmCoinName]; +export type EvmChainId = Subtract; + +export type GetEvmCoin< + TEvmName extends EvmCoinName, + TCoinType extends CoinNameToTypeMap[TEvmName] = CoinNameToTypeMap[TEvmName] +> = { + name: TEvmName; + coinType: TCoinType; + evmChainId: Subtract; + encode: EncoderFunction; + decode: DecoderFunction; }; export type EncoderFunction = (source: Uint8Array) => string; @@ -23,3 +60,22 @@ export type CoinCoder = { }; export type Coin = CoinParameters & CoinCoder; + +export type CheckedCoin = { + [key in keyof typeof nonEvmCoinNameToTypeMap]: { + name: key; + coinType: (typeof nonEvmCoinNameToTypeMap)[key]; + } & CoinCoder; +}[keyof typeof nonEvmCoinNameToTypeMap]; + +export type GetCoderByCoinName = + TCoinName extends CoinName ? CoinNameToFormatMap[TCoinName] : Coin; + +export type GetCoderByCoinType = + TCoinType extends CoinType ? CoinTypeToFormatMap[TCoinType] : Coin; + +export type ParseInt = T extends `${infer N extends number}` ? N : never; + +export type Prettify = { + [K in keyof T]: T[K]; +} & {}; diff --git a/src/utils/evm.ts b/src/utils/evm.ts index da0ac355..d4b8416e 100644 --- a/src/utils/evm.ts +++ b/src/utils/evm.ts @@ -1,12 +1,36 @@ +import type { Add, Lt, Subtract } from "ts-arithmetic"; +import type { EvmChainId, EvmCoinType } from "../types.js"; + export const SLIP44_MSB = 0x80000000; -export const evmChainIdToCoinType = (chainId: number) => { +type EvmChainIdToCoinType< + TChainId extends EvmChainId | number = EvmChainId | number +> = Lt extends 1 + ? Add + : never; + +export const evmChainIdToCoinType = < + TChainId extends EvmChainId | number = EvmChainId | number +>( + chainId: TChainId +): EvmChainIdToCoinType => { if (chainId >= SLIP44_MSB) throw new Error("Invalid chainId"); - return (SLIP44_MSB | chainId) >>> 0; + return ((SLIP44_MSB | chainId) >>> 0) as EvmChainIdToCoinType; }; -export const coinTypeToEvmChainId = (coinType: number) => { +type CoinTypeToEvmChainId< + TCoinType extends EvmCoinType | number = EvmCoinType | number +> = Lt extends 1 + ? never + : Subtract; + +export const coinTypeToEvmChainId = < + TCoinType extends EvmCoinType | number = EvmCoinType | number +>( + coinType: TCoinType +): CoinTypeToEvmChainId => { if ((coinType & SLIP44_MSB) === 0) throw new Error("Coin type is not an EVM chain"); - return ((SLIP44_MSB - 1) & coinType) >> 0; + return (((SLIP44_MSB - 1) & coinType) >> + 0) as CoinTypeToEvmChainId; }; diff --git a/src/utils/index.ts b/src/utils/index.ts index 17bfbd48..a3aceaf2 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -32,6 +32,7 @@ export { type BitcoinCoderParameters, } from "./bitcoin.js"; export { byronDecode, byronEncode } from "./byron.js"; +export { bytesToHex, hexToBytes } from "./bytes.js"; export { SimpleValue, TaggedValue, cborDecode, cborEncode } from "./cbor.js"; export { crc32 } from "./crc32.js"; export { createDotAddressDecoder, createDotAddressEncoder } from "./dot.js"; diff --git a/tsconfig.bun.json b/tsconfig.bun.json index c0f4d2f7..390b384d 100644 --- a/tsconfig.bun.json +++ b/tsconfig.bun.json @@ -4,6 +4,7 @@ "compilerOptions": { "composite": true, "module": "NodeNext", + "resolveJsonModule": true, "types": ["bun-types"] } }