Use method from cosmjs to get address prefix
This commit is contained in:
parent
f8a7f14077
commit
ff733cac96
@ -3,13 +3,14 @@ For more information, "visit https://docs.ethers.org/v5/cookbook/react-native/#c
|
||||
import 'react-native-get-random-values';
|
||||
|
||||
import '@ethersproject/shims';
|
||||
import { fromBech32 } from '@cosmjs/encoding';
|
||||
|
||||
import { Wallet } from 'ethers';
|
||||
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
||||
|
||||
import { SignMessageParams } from '../types';
|
||||
import { getDirectWallet, getMnemonic, getPathKey } from './misc';
|
||||
import { getCosmosAccounts, retrieveNetworksData } from './accounts';
|
||||
import { getCosmosAccounts } from './accounts';
|
||||
import { COSMOS, EIP155 } from './constants';
|
||||
|
||||
const signMessage = async ({
|
||||
@ -55,13 +56,9 @@ const signCosmosMessage = async (
|
||||
): Promise<string | undefined> => {
|
||||
try {
|
||||
const mnemonic = await getMnemonic();
|
||||
const networks = await retrieveNetworksData();
|
||||
const addressPrefix = fromBech32(cosmosAddress).prefix
|
||||
|
||||
const currentNetwork = networks.filter(network => {
|
||||
return network.namespace === COSMOS && cosmosAddress.startsWith(network.addressPrefix ?? '')
|
||||
});
|
||||
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, path, currentNetwork[0].addressPrefix);
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, path, addressPrefix);
|
||||
const address = cosmosAccount.data.address;
|
||||
const cosmosSignature = await cosmosAccount.cosmosWallet.signAmino(
|
||||
address,
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
StdFee,
|
||||
MsgSendEncodeObject
|
||||
} from '@cosmjs/stargate';
|
||||
import { fromBech32 } from '@cosmjs/encoding';
|
||||
import { EncodeObject } from '@cosmjs/proto-signing';
|
||||
import { LaconicClient } from '@cerc-io/registry-sdk';
|
||||
import { Buffer } from 'buffer';
|
||||
@ -17,7 +18,7 @@ import { EIP155_SIGNING_METHODS } from './EIP155Data';
|
||||
import { signDirectMessage, signEthMessage } from '../sign-message';
|
||||
import { Account } from '../../types';
|
||||
import { getMnemonic, getPathKey } from '../misc';
|
||||
import { getCosmosAccounts, retrieveNetworksData } from '../accounts';
|
||||
import { getCosmosAccounts } from '../accounts';
|
||||
import { COSMOS_METHODS } from './COSMOSData';
|
||||
import { COSMOS } from '../constants';
|
||||
|
||||
@ -81,13 +82,13 @@ export async function approveWalletConnectRequest(
|
||||
const path = (await getPathKey(`${namespace}:${chainId}`, account.index))
|
||||
.path;
|
||||
const mnemonic = await getMnemonic();
|
||||
const networks = await retrieveNetworksData();
|
||||
|
||||
const currentNetwork = networks.filter(network => {
|
||||
return network.namespace === COSMOS && account.address.startsWith(network.addressPrefix ?? '')
|
||||
});
|
||||
let addressPrefix: string | undefined
|
||||
if (namespace === COSMOS) {
|
||||
addressPrefix = fromBech32(account.address).prefix
|
||||
}
|
||||
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, path, currentNetwork[0]?.addressPrefix);
|
||||
const cosmosAccount = await getCosmosAccounts(mnemonic, path, addressPrefix);
|
||||
const address = account.address;
|
||||
|
||||
switch (request.method) {
|
||||
|
Loading…
Reference in New Issue
Block a user