Skip to content

Commit

Permalink
derivable evm coin name
Browse files Browse the repository at this point in the history
  • Loading branch information
adraffy committed Feb 11, 2024
1 parent 455a334 commit 8a72eb8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ export const getCoderByCoinType = <
>(
coinType: TCoinType
): GetCoderByCoinType<TCoinType> => {
const names =
coinTypeToNameMap[String(coinType) as keyof typeof coinTypeToNameMap];
if (!names) {
throw new Error(`Unsupported coin type: ${coinType}`);
}
const [name] = names;
const names = coinTypeToNameMap[String(coinType) as keyof typeof coinTypeToNameMap];
// https://docs.ens.domains/ens-improvement-proposals/ensip-11-evmchain-address-resolution
if (coinType >= SLIP44_MSB) {
// EVM coin
const evmChainId = coinTypeToEvmChainId(coinType);
const name = names ? names[0] : `Chain(${evmChainId})`; // name is derivable
const ethFormat = formats["eth"];
return {
name,
Expand All @@ -87,7 +84,12 @@ export const getCoderByCoinType = <
encode: ethFormat.encode,
decode: ethFormat.decode,
} as GetCoderByCoinType<TCoinType>;
} else {
if (!names) {
throw new Error(`Unsupported coin type: ${coinType}`);
}
const [name] = names;
const format = formats[name as keyof typeof formats];
return format as GetCoderByCoinType<TCoinType>;
}
const format = formats[name as keyof typeof formats];
return format as GetCoderByCoinType<TCoinType>;
};

0 comments on commit 8a72eb8

Please sign in to comment.