Skip to content

Instantly share code, notes, and snippets.

@0xpatrickdev
Created April 24, 2024 23:30
Show Gist options
  • Save 0xpatrickdev/8fdd882a232cbae3d4d65e1eb4403a81 to your computer and use it in GitHub Desktop.
Save 0xpatrickdev/8fdd882a232cbae3d4d65e1eb4403a81 to your computer and use it in GitHub Desktop.
attempt at a universal type for BlockchainAddress, with some mock data
enum ChainId {
Ethereum = 1,
Bitcoin = 0,
Cosmos = 'cosmoshub-4',
Injective = 'injective-1',
Evmos = 'evmos_9001-2',
Polkadot = 0,
Kusama = 2,
Moonbeam = 1284,
Polygon = 137,
// Solana = undefined, // seemingly, no concept of chainId? Just a url for the cluster?
}
// see [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)
enum CoinType {
Ethereum = 60,
Solana = 501,
Bitcoin = 0,
Cosmos = 118,
Injective = 60,
Evmos = 60,
Polkadot = 354,
Kusama = 434,
Moonbeam = 60,
Polygon = 60,
}
enum PublicKeyType {
Secp256k1 = 'secp256k1',
Ed25519 = 'ed25519',
Sr25519 = 'sr25519',
}
enum AddressFormat {
Base58 = 'base58',
Bech32 = 'bech32',
Hexadecimal = 'hex',
}
interface BlockchainAddress {
chainId: ChainId | undefined;
coinType: CoinType;
publicKeyType: PublicKeyType;
addressFormat: AddressFormat;
address: string;
}
const mockAddresses: BlockchainAddress[] = [
{
chainId: ChainId.Ethereum,
coinType: CoinType.Ethereum,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Hexadecimal,
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
},
{
chainId: undefined,
coinType: CoinType.Solana,
publicKeyType: PublicKeyType.Ed25519,
addressFormat: AddressFormat.Base58,
address: 'GKNcUmNacSJo4S2Kq3DuYRYRGw3sNUfJ4tyqd198t6vQ',
},
{
chainId: ChainId.Bitcoin,
coinType: CoinType.Bitcoin,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Base58,
address: '1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2',
},
{
chainId: ChainId.Bitcoin,
coinType: CoinType.Bitcoin,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Bech32,
address: 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
},
{
chainId: ChainId.Bitcoin,
coinType: CoinType.Bitcoin,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Bech32,
address: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
},
{
chainId: ChainId.Cosmos,
coinType: CoinType.Cosmos,
// module/interchain accounts probably don't have a concept of pubkey?
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Bech32,
// + ICA/ModuleAccount addresses, which can be longer (up to [90 chars](https://github.com/bitcoin/bips/blob/e1e7b77c027b3d40d07d306cc75c2b5859c91db2/bip-0173.mediawiki#bech32))
// + validator addresses, which have a different prefix (cosmosvaloper)
address: 'cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r',
},
{
chainId: ChainId.Injective,
coinType: CoinType.Injective,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Bech32,
address: 'inj1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r',
},
{
chainId: ChainId.Injective,
coinType: CoinType.Injective,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Hexadecimal,
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
},
{
chainId: ChainId.Evmos,
coinType: CoinType.Evmos,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Bech32,
address: 'evmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r',
},
{
chainId: ChainId.Evmos,
coinType: CoinType.Evmos,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Hexadecimal,
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
},
{
chainId: ChainId.Polkadot,
coinType: CoinType.Polkadot,
publicKeyType: PublicKeyType.Sr25519,
addressFormat: AddressFormat.Bech32,
address: '12gX42C4Fj1wBxsKpxhfLTsJGTgTRTRjTcrwBhPYUPa9Q6kT',
},
{
chainId: ChainId.Kusama,
coinType: CoinType.Kusama,
publicKeyType: PublicKeyType.Sr25519,
addressFormat: AddressFormat.Bech32,
address: 'ELmaX1aPkyEF7TSmYbbyCjmSgrBpGHv9EtpwR2tk1kmpwvG',
},
{
chainId: ChainId.Moonbeam,
coinType: CoinType.Moonbeam,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Hexadecimal,
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
},
{
chainId: ChainId.Polygon,
coinType: CoinType.Polygon,
publicKeyType: PublicKeyType.Secp256k1,
addressFormat: AddressFormat.Hexadecimal,
address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment