-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add utils for verifying 6492 sigs and ensip-11 utils
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as chains from "viem/chains"; | ||
import { mainnet, type Chain } from "viem/chains"; | ||
|
||
export const ChainsById: Map<number, chains.Chain> = new Map( | ||
Object.values(chains).map((x) => [x.id, x]) | ||
); | ||
|
||
export const convertChainIdToCoinType = (chainId: number): number => { | ||
if (chainId === mainnet.id) { | ||
// this comes from [ensip-9](https://docs.ens.domains/ens-improvement-proposals/ensip-9-multichain-address-resolution) | ||
return 60; | ||
} | ||
|
||
// this is using [ENSIP-11](https://docs.ens.domains/ens-improvement-proposals/ensip-11-evmchain-address-resolution) and assumes this is how mappings are stored for non mainnet chains | ||
return (0x80000000 | chainId) >>> 0; | ||
}; | ||
|
||
export const convertCoinTypeToChainId = (coinType: number): number => { | ||
if (coinType === 60) { | ||
// this comes from [ensip-9](https://docs.ens.domains/ens-improvement-proposals/ensip-9-multichain-address-resolution) | ||
return mainnet.id; | ||
} | ||
|
||
// this is using [ENSIP-11](https://docs.ens.domains/ens-improvement-proposals/ensip-11-evmchain-address-resolution) and assumes this is how mappings are stored for non mainnet chains | ||
return (0x7fffffff & coinType) >> 0; | ||
}; | ||
|
||
export const convertCoinTypeToChain = (coinType: number): Chain => { | ||
const chainId = convertCoinTypeToChainId(coinType); | ||
const chain = ChainsById.get(chainId); | ||
if (!chain) { | ||
throw new Error("CoinType does not map to a supported chain"); | ||
} | ||
|
||
return chain; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters