UNPKG

@interchainjs/injective

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"> </p>

157 lines (156 loc) 4.47 kB
import { defaultAccountParser as parseCosmosAccount, defaultSignerConfig as CosmosSignerConfig, } from '@interchainjs/cosmos/defaults'; import { toDecoder } from '@interchainjs/cosmos/utils'; import { PubKey as Secp256k1PubKey } from '@interchainjs/cosmos-types/cosmos/crypto/secp256k1/keys'; import { EthAccount } from '@interchainjs/cosmos-types/injective/types/v1beta1/account'; import { EthereumChainId } from './types'; import { bytesToHex as assertBytes } from '@noble/hashes/utils'; import { keccak_256 } from '@noble/hashes/sha3'; import { computeAddress } from '@ethersproject/transactions'; import { Key } from '@interchainjs/utils'; import { InjAccount } from './accounts/inj-account'; import { EthSecp256k1Auth } from '@interchainjs/auth/ethSecp256k1'; export const defaultPublicKeyConfig = { isCompressed: CosmosSignerConfig.publicKey.isCompressed, hash: (publicKey) => Key.fromHex(computeAddress(publicKey.value)) }; export const defaultEncodePublicKey = (key) => { return { typeUrl: '/injective.crypto.v1beta1.ethsecp256k1.PubKey', value: Secp256k1PubKey.encode(Secp256k1PubKey.fromPartial({ key: key.value })).finish(), }; }; export const defaultAccountParser = (encodedAccount) => { try { return parseCosmosAccount(encodedAccount); } catch (error) { const decoder = toDecoder(EthAccount); const account = decoder.fromPartial(decoder.decode(encodedAccount.value)); return account.baseAccount; } }; export const defaultSignerOptions = { Cosmos: { ...CosmosSignerConfig, message: { ...CosmosSignerConfig.message, hash: (message) => { const hashed = keccak_256(message); assertBytes(hashed); return hashed; }, }, publicKey: defaultPublicKeyConfig, encodePublicKey: defaultEncodePublicKey, parseAccount: defaultAccountParser, createAccount: InjAccount, prefix: 'inj', }, }; export const defaultWalletOptions = { bip39Password: undefined, createAuthsFromMnemonic: EthSecp256k1Auth.fromMnemonic, signerConfig: defaultSignerOptions.Cosmos, }; export const defaultTimeoutHeight = { type: 'relative', value: 90n, }; export const defaultDomainOptions = { name: 'Injective Web3', version: '1.0.0', ethereumChainId: EthereumChainId.Injective, salt: '0', verifyingContract: 'cosmos', }; export const defaultEip712Types = { primaryType: 'Tx', types: { EIP712Domain: [ { name: 'name', type: 'string', }, { name: 'version', type: 'string', }, { name: 'chainId', type: 'uint256', }, { name: 'verifyingContract', type: 'string', }, { name: 'salt', type: 'string', }, ], Tx: [ { name: 'account_number', type: 'string', }, { name: 'chain_id', type: 'string', }, { name: 'fee', type: 'Fee', }, { name: 'memo', type: 'string', }, { name: 'msgs', type: 'Msg[]', }, { name: 'sequence', type: 'string', }, { name: 'timeout_height', type: 'string', }, ], Fee: [ { name: 'feePayer', type: 'string', }, { name: 'amount', type: 'Coin[]', }, { name: 'gas', type: 'string', }, ], Coin: [ { name: 'denom', type: 'string', }, { name: 'amount', type: 'string', }, ], Msg: [ { name: 'type', type: 'string', }, { name: 'value', type: 'MsgValue', }, ], }, };