Skip to content

Commit

Permalink
fix: removes mnemonic-keyring and reintroduces tezos & cosmos integ…
Browse files Browse the repository at this point in the history
…rations (#440)

Co-authored-by: Gancho Radkov <ganchoradkov@gmail.com>
  • Loading branch information
ganchoradkov and Gancho Radkov authored Feb 1, 2024
1 parent 68c95a9 commit 46bfda7
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 346 deletions.
1 change: 0 additions & 1 deletion advanced/wallets/react-wallet-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"cosmos-wallet": "1.2.0",
"ethers": "5.7.2",
"framer-motion": "6.5.1",
"mnemonic-keyring": "1.4.0",
"near-api-js": "^0.45.0",
"next": "12.1.5",
"permissionless": "0.0.20",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { cosmosAddresses } from '@/utils/CosmosWalletUtil'
import { eip155Addresses } from '@/utils/EIP155WalletUtil'
import { polkadotAddresses } from '@/utils/PolkadotWalletUtil'
import { multiversxAddresses } from '@/utils/MultiversxWalletUtil'
import { tronAddresses } from '@/utils/TronWalletUtil'
import { tezosAddresses } from '@/utils/TezosWalletUtil'
import { solanaAddresses } from '@/utils/SolanaWalletUtil'
import { nearAddresses } from '@/utils/NearWalletUtil'
import { kadenaAddresses } from '@/utils/KadenaWalletUtil'
Expand Down
13 changes: 11 additions & 2 deletions advanced/wallets/react-wallet-v2/src/components/ChainDataMini.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData'
import { EIP155_CHAINS } from '@/data/EIP155Data'
import { KADENA_CHAINS } from '@/data/KadenaData'
import { MULTIVERSX_CHAINS } from '@/data/MultiversxData'
import { NEAR_CHAINS } from '@/data/NEARData'
import { POLKADOT_CHAINS } from '@/data/PolkadotData'
import { SOLANA_CHAINS } from '@/data/SolanaData'
import { TEZOS_CHAINS } from '@/data/TezosData'
import { TRON_CHAINS } from '@/data/TronData'
import { getChainData } from '@/data/chainsUtil'
import { Row, Avatar } from '@nextui-org/react'
import { useMemo } from 'react'
import { Card, Row, styled, Image, Avatar } from '@nextui-org/react'
import { ReactNode, useMemo } from 'react'

interface Props {
chainId?: string // namespace + ":" + reference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { COSMOS_MAINNET_CHAINS, TCosmosChain } from '@/data/COSMOSData'
import { EIP155_CHAINS, TEIP155Chain } from '@/data/EIP155Data'
import { KADENA_CHAINS, TKadenaChain } from '@/data/KadenaData'
import { NEAR_TEST_CHAINS, TNearChain } from '@/data/NEARData'
Expand Down Expand Up @@ -29,6 +30,7 @@ export default function RequestDetailsCard({ chains, protocol }: IProps) {
.map(
chain =>
EIP155_CHAINS[chain as TEIP155Chain]?.name ??
COSMOS_MAINNET_CHAINS[chain as TCosmosChain]?.name ??
SOLANA_CHAINS[chain as TSolanaChain]?.name ??
NEAR_TEST_CHAINS[chain as TNearChain]?.name ??
MULTIVERSX_CHAINS[chain as TMultiversxChain]?.name ??
Expand All @@ -46,9 +48,7 @@ export default function RequestDetailsCard({ chains, protocol }: IProps) {
<Row>
<Col>
<Text h5>Relay Protocol</Text>
<Text color="$gray400" data-testid="request-detauls-realy-protocol">
{protocol}
</Text>
<Text color="$gray400" data-testid="request-detauls-realy-protocol">{protocol}</Text>
</Col>
</Row>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ChainCard from '@/components/ChainCard'
import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData'
import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data'
import { NEAR_TEST_CHAINS } from '@/data/NEARData'
import { SOLANA_MAINNET_CHAINS, SOLANA_TEST_CHAINS } from '@/data/SolanaData'
Expand All @@ -13,6 +14,7 @@ import { Fragment } from 'react'
* Utilities
*/
const CHAIN_METADATA = {
...COSMOS_MAINNET_CHAINS,
...SOLANA_MAINNET_CHAINS,
...MULTIVERSX_MAINNET_CHAINS,
...TRON_MAINNET_CHAINS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ChainCard from '@/components/ChainCard'
import { COSMOS_MAINNET_CHAINS } from '@/data/COSMOSData'
import { EIP155_MAINNET_CHAINS, EIP155_TEST_CHAINS } from '@/data/EIP155Data'
import { NEAR_TEST_CHAINS } from '@/data/NEARData'
import { SOLANA_MAINNET_CHAINS, SOLANA_TEST_CHAINS } from '@/data/SolanaData'
Expand All @@ -13,6 +14,7 @@ import { Fragment } from 'react'
* Utilities
*/
const CHAIN_METADATA = {
...COSMOS_MAINNET_CHAINS,
...SOLANA_MAINNET_CHAINS,
...MULTIVERSX_MAINNET_CHAINS,
...TRON_MAINNET_CHAINS,
Expand Down
26 changes: 26 additions & 0 deletions advanced/wallets/react-wallet-v2/src/data/COSMOSData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Types
*/
export type TCosmosChain = keyof typeof COSMOS_MAINNET_CHAINS

/**
* Chains
*/
export const COSMOS_MAINNET_CHAINS = {
'cosmos:cosmoshub-4': {
chainId: 'cosmoshub-4',
name: 'Cosmos Hub',
logo: '/chain-logos/cosmos-cosmoshub-4.png',
rgb: '107, 111, 147',
rpc: '',
namespace: 'cosmos'
}
}

/**
* Methods
*/
export const COSMOS_SIGNING_METHODS = {
COSMOS_SIGN_DIRECT: 'cosmos_signDirect',
COSMOS_SIGN_AMINO: 'cosmos_signAmino'
}
49 changes: 49 additions & 0 deletions advanced/wallets/react-wallet-v2/src/data/TezosData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
type ChainMetadata = {
chainId: string
name: string
logo: string
rgb: string
rpc: string
namespace: string
}

/**
* Types
*/
export type TTezosChain = keyof typeof TEZOS_MAINNET_CHAINS

/**
* Chains
*/
export const TEZOS_MAINNET_CHAINS: Record<string, ChainMetadata> = {
'tezos:mainnet': {
chainId: 'mainnet',
name: 'Tezos',
logo: '/chain-logos/tezos.svg',
rgb: '44, 125, 247',
rpc: 'https://mainnet.api.tez.ie',
namespace: 'tezos'
}
}

export const TEZOS_TEST_CHAINS: Record<string, ChainMetadata> = {
'tezos:testnet': {
chainId: 'testnet',
name: 'Tezos Testnet',
logo: '/chain-logos/tezos.svg',
rgb: '44, 125, 247',
rpc: 'https://ghostnet.ecadinfra.com',
namespace: 'tezos'
}
}

export const TEZOS_CHAINS = { ...TEZOS_MAINNET_CHAINS, ...TEZOS_TEST_CHAINS }

/**
* Methods
*/
export const TEZOS_SIGNING_METHODS = {
TEZOS_GET_ACCOUNTS: 'tezos_getAccounts',
TEZOS_SEND: 'tezos_send',
TEZOS_SIGN: 'tezos_sign'
}
4 changes: 4 additions & 0 deletions advanced/wallets/react-wallet-v2/src/data/chainsUtil.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { COSMOS_MAINNET_CHAINS } from './COSMOSData'
import { EIP155_CHAINS } from './EIP155Data'
import { KADENA_CHAINS } from './KadenaData'
import { MULTIVERSX_CHAINS } from './MultiversxData'
import { NEAR_CHAINS } from './NEARData'
import { POLKADOT_CHAINS } from './PolkadotData'
import { SOLANA_CHAINS } from './SolanaData'
import { TEZOS_CHAINS } from './TezosData'
import { TRON_CHAINS } from './TronData'

export const ALL_CHAINS = {
...EIP155_CHAINS,
...COSMOS_MAINNET_CHAINS,
...KADENA_CHAINS,
...MULTIVERSX_CHAINS,
...NEAR_CHAINS,
...POLKADOT_CHAINS,
...SOLANA_CHAINS,
...TEZOS_CHAINS,
...TRON_CHAINS
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Web3WalletTypes } from '@walletconnect/web3wallet'
import { COSMOS_SIGNING_METHODS } from '@/data/COSMOSData'
import { EIP155_SIGNING_METHODS } from '@/data/EIP155Data'
import { SOLANA_SIGNING_METHODS } from '@/data/SolanaData'
import { POLKADOT_SIGNING_METHODS } from '@/data/PolkadotData'
Expand All @@ -11,6 +12,7 @@ import { SignClientTypes } from '@walletconnect/types'
import { useCallback, useEffect } from 'react'
import { NEAR_SIGNING_METHODS } from '@/data/NEARData'
import { approveNearRequest } from '@/utils/NearRequestHandlerUtil'
import { TEZOS_SIGNING_METHODS } from '@/data/TezosData'
import { KADENA_SIGNING_METHODS } from '@/data/KadenaData'

export default function useWalletConnectEventsManager(initialized: boolean) {
Expand Down Expand Up @@ -58,6 +60,10 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
case EIP155_SIGNING_METHODS.ETH_SIGN_TRANSACTION:
return ModalStore.open('SessionSendTransactionModal', { requestEvent, requestSession })

case COSMOS_SIGNING_METHODS.COSMOS_SIGN_DIRECT:
case COSMOS_SIGNING_METHODS.COSMOS_SIGN_AMINO:
return ModalStore.open('SessionSignCosmosModal', { requestEvent, requestSession })

case SOLANA_SIGNING_METHODS.SOLANA_SIGN_MESSAGE:
case SOLANA_SIGNING_METHODS.SOLANA_SIGN_TRANSACTION:
return ModalStore.open('SessionSignSolanaModal', { requestEvent, requestSession })
Expand Down Expand Up @@ -92,6 +98,10 @@ export default function useWalletConnectEventsManager(initialized: boolean) {
case TRON_SIGNING_METHODS.TRON_SIGN_MESSAGE:
case TRON_SIGNING_METHODS.TRON_SIGN_TRANSACTION:
return ModalStore.open('SessionSignTronModal', { requestEvent, requestSession })
case TEZOS_SIGNING_METHODS.TEZOS_GET_ACCOUNTS:
case TEZOS_SIGNING_METHODS.TEZOS_SEND:
case TEZOS_SIGNING_METHODS.TEZOS_SIGN:
return ModalStore.open('SessionSignTezosModal', { requestEvent, requestSession })
case KADENA_SIGNING_METHODS.KADENA_GET_ACCOUNTS:
case KADENA_SIGNING_METHODS.KADENA_SIGN:
case KADENA_SIGNING_METHODS.KADENA_QUICKSIGN:
Expand Down
18 changes: 10 additions & 8 deletions advanced/wallets/react-wallet-v2/src/lib/CosmosLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fromHex } from '@cosmjs/encoding'
import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing'
// @ts-expect-error
import { SignDoc } from '@cosmjs/proto-signing/build/codec/cosmos/tx/v1beta1/tx'
import Keyring from 'mnemonic-keyring'
import { Wallet } from 'ethers'

/**
* Constants
Expand All @@ -24,27 +24,29 @@ interface IInitArguments {
* Library
*/
export default class CosmosLib {
private keyring: Keyring
private mnemonic: string
private directSigner: DirectSecp256k1Wallet
private aminoSigner: Secp256k1Wallet

constructor(keyring: Keyring, directSigner: DirectSecp256k1Wallet, aminoSigner: Secp256k1Wallet) {
constructor(mnemonic: string, directSigner: DirectSecp256k1Wallet, aminoSigner: Secp256k1Wallet) {
this.directSigner = directSigner
this.keyring = keyring
this.mnemonic = mnemonic
this.aminoSigner = aminoSigner
}

static async init({ mnemonic, path, prefix }: IInitArguments) {
const keyring = await Keyring.init({ mnemonic: mnemonic ?? Keyring.generateMnemonic() })
const privateKey = fromHex(keyring.getPrivateKey(path ?? DEFAULT_PATH))
const wallet = mnemonic
? Wallet.fromMnemonic(mnemonic, path ?? DEFAULT_PATH)
: Wallet.createRandom({ path: path ?? DEFAULT_PATH })
const privateKey = fromHex(wallet.privateKey.replace('0x', ''))
const directSigner = await DirectSecp256k1Wallet.fromKey(privateKey, prefix ?? DEFAULT_PREFIX)
const aminoSigner = await Secp256k1Wallet.fromKey(privateKey, prefix ?? DEFAULT_PREFIX)

return new CosmosLib(keyring, directSigner, aminoSigner)
return new CosmosLib(wallet.mnemonic.phrase, directSigner, aminoSigner)
}

public getMnemonic() {
return this.keyring.mnemonic
return this.mnemonic
}

public async getAddress() {
Expand Down
4 changes: 2 additions & 2 deletions advanced/wallets/react-wallet-v2/src/lib/TezosLib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TezosToolkit } from '@taquito/taquito'
import { InMemorySigner } from '@taquito/signer'
import { localForger } from '@taquito/local-forging'
import Keyring from 'mnemonic-keyring'
import { Wallet } from 'ethers/'

/**
* Constants
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class TezosLib {

static async init({ mnemonic, path, curve }: IInitArguments) {
const params = {
mnemonic: mnemonic ?? Keyring.generateMnemonic(),
mnemonic: mnemonic ?? Wallet.createRandom().mnemonic.phrase,
derivationPath: path ?? DEFAULT_PATH,
curve: curve ?? DEFAULT_CURVE
}
Expand Down
Loading

0 comments on commit 46bfda7

Please sign in to comment.