Skip to content

Commit

Permalink
Merge pull request #186 from enkryptcom/develop
Browse files Browse the repository at this point in the history
Release: v1.7.0
  • Loading branch information
kvhnuke authored Nov 1, 2022
2 parents 15176ae + 38d9a3d commit d3d5641
Show file tree
Hide file tree
Showing 97 changed files with 2,105 additions and 192 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"packages/extension",
"packages/storage",
"packages/request",
"packages/hw-wallets"
"packages/hw-wallets",
"packages/name-resolution"
],
"scripts": {
"test": "yarn workspaces foreach -pv run test",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@enkryptcom/extension",
"version": "1.6.0",
"version": "1.7.0",
"private": true,
"scripts": {
"zip": "cd dist; zip -r release.zip *;",
Expand Down
36 changes: 22 additions & 14 deletions packages/extension/src/libs/dapp-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@ import { NetworkNames } from "@enkryptcom/types";

const lists: Partial<Record<NetworkNames, string>> = {
[NetworkNames.Ethereum]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/eth.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/eth.json",
[NetworkNames.Binance]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/bsc.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/bsc.json",
[NetworkNames.Matic]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/matic.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/matic.json",
[NetworkNames.EthereumClassic]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/etc.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/etc.json",
[NetworkNames.Kusama]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/ksm.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/ksm.json",
[NetworkNames.Polkadot]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/dot.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/dot.json",
[NetworkNames.Acala]:
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/aca.json",
[NetworkNames.Karura]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/kar.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/kar.json",
[NetworkNames.Moonbeam]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/glmr.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/glmr.json",
[NetworkNames.Moonriver]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/movr.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/movr.json",
[NetworkNames.Astar]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/astr.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/astr.json",
[NetworkNames.AstarEVM]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/astr.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/astr.json",
[NetworkNames.Shiden]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/sdn.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/sdn.json",
[NetworkNames.ShidenEVM]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/sdn.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/sdn.json",
[NetworkNames.Okc]:
"https://github.com/enkryptcom/dynamic-data/raw/main/dapps/okc.json",
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/okc.json",
[NetworkNames.Optimism]:
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/op.json",
[NetworkNames.Canto]:
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/canto.json",
[NetworkNames.Bifrost]:
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/bifrost.json",
[NetworkNames.BifrostKusama]:
"https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/dapps/bifrost.json",
};

export default lists;
23 changes: 23 additions & 0 deletions packages/extension/src/libs/name-resolver/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import NameResolver, { CoinType } from "@enkryptcom/name-resolution";
class GenericNameResolver {
nameResolver: NameResolver;

constructor() {
this.nameResolver = new NameResolver({
ens: { node: "https://nodes.mewapi.io/rpc/eth" },
});
}

async resolveName(name: string, coins: CoinType[]): Promise<string | null> {
let response: string | null = null;
for (const coin of coins) {
response = await this.nameResolver
.resolveAddress(name, coin)
.catch(() => null);
if (response) return response;
}
return response;
}
}

export { CoinType, GenericNameResolver };
2 changes: 1 addition & 1 deletion packages/extension/src/manifest/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "https://www.enkrypt.com",
"homepage_url": "https://www.enkrypt.com",
"version": "",
"name": "Enkrypt: Ethereum, Polkadot and OKX Wallet",
"name": "Enkrypt: Ethereum, Polkadot and Canto Wallet",
"short_name": "Enkrypt",
"permissions": [
"storage",
Expand Down
7 changes: 6 additions & 1 deletion packages/extension/src/providers/ethereum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ class EthereumProvider
this.middlewares = Middlewares.map((mw) => mw.bind(this));
}
setRequestProvider(network: BaseNetwork): void {
const prevURL = new URL(this.network.node);
const newURL = new URL(network.node);
this.network = network as EvmNetwork;
this.requestProvider.changeNetwork(network.node);
if (prevURL.protocol === newURL.protocol)
this.requestProvider.changeNetwork(network.node);
else
this.requestProvider = getRequestProvider(network.node, this.middlewares);
}
async isPersistentEvent(request: ProviderRPCRequest): Promise<boolean> {
if (request.method === "eth_subscribe") return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const NetworkEndpoints = {
[NetworkNames.KaruraEVM]: "https://blockscout.karura.network/",
[NetworkNames.AstarEVM]: "https://blockscout.com/astar/",
[NetworkNames.ShidenEVM]: "https://blockscout.com/shiden/",
[NetworkNames.Optimism]: "https://api-optimistic.etherscan.io/",
[NetworkNames.Canto]: "https://evm.explorer.canto.io/",
};

export { NetworkEndpoints };
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface SupportedNetwork {
cgPlatform: string;
}
export interface CGToken {
chainId: number;
chainId: `0x${string}`;
address: string;
name: string;
symbol: string;
Expand Down
28 changes: 28 additions & 0 deletions packages/extension/src/providers/ethereum/libs/tx-broadcaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { NetworkNames } from "@enkryptcom/types";
import { v4 } from "uuid";

const broadcastTx = (hexTx: string, network: NetworkNames): Promise<string> => {
if (network === NetworkNames.Ethereum) {
const burl = "https://broadcast.mewapi.io/eth?product=enkrypt";
return fetch(burl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "eth_sendRawTransaction",
params: [hexTx],
id: v4(),
}),
})
.then((response) => response.json())
.then((jRes) => {
if (jRes.error) return Promise.reject(jRes.error);
else return jRes.result as string;
});
}
return Promise.reject("Not valid network");
};

export default broadcastTx;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getCustomError } from "@/libs/error";
import { MiddlewareFunction } from "@enkryptcom/types";
import EthereumProvider from "..";
import broadcastTx from "../libs/tx-broadcaster";
const method: MiddlewareFunction = function (
this: EthereumProvider,
payload,
res,
next
): void {
if (payload.method !== "eth_sendRawTransaction") return next();
else {
if (!payload.params || payload.params.length < 1) {
return res(
getCustomError("eth_sendTransaction: invalid request not enough params")
);
}
broadcastTx(payload.params[0], this.network.name)
.then((hash) => {
res(null, hash);
})
.catch(() => next());
}
};
export default method;
2 changes: 2 additions & 0 deletions packages/extension/src/providers/ethereum/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import addEthereumChain from "./wallet_addEthereumChain";
import switchEthereumChain from "./wallet_switchEthereumChain";
import watchAsset from "./wallet_watchAsset";
import walletRequestPermissions from "./wallet_requestPermissions";
import ethSendRawTransaction from "./eth_sendRawTransaction";
export default [
ethSendTransaction,
ethSign,
Expand All @@ -25,4 +26,5 @@ export default [
switchEthereumChain,
addEthereumChain,
walletRequestPermissions,
ethSendRawTransaction,
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { getCustomError } from "@/libs/error";
import { MiddlewareFunction } from "@enkryptcom/types";
import EthNetworks from "../networks";
import EthereumProvider from "..";
import { numberToHex } from "web3-utils";
import { sendToBackgroundFromBackground } from "@/libs/messenger/extension";
import { InternalMethods } from "@/types/messenger";
import { ProviderRPCRequest } from "@/types/provider";
Expand All @@ -26,7 +25,7 @@ const method: MiddlewareFunction = function (
}
const allNetworks = Object.values(EthNetworks);
const validNetwork = allNetworks.find(
(net) => numberToHex(net.chainID) === payload.params![0].chainId
(net) => net.chainID === payload.params![0].chainId
);
if (validNetwork) {
sendToBackgroundFromBackground({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ProviderRPCRequest } from "@/types/provider";
import { MiddlewareFunction } from "@enkryptcom/types";
import EthNetworks from "../networks";
import EthereumProvider from "..";
import { numberToHex } from "web3-utils";
import { MessageMethod } from "../types";
import DomainState from "@/libs/domain-state";
const method: MiddlewareFunction = function (
Expand All @@ -25,7 +24,7 @@ const method: MiddlewareFunction = function (
}
const allNetworks = Object.values(EthNetworks);
const validNetwork = allNetworks.find(
(net) => numberToHex(net.chainID) === payload.params![0].chainId
(net) => net.chainID === payload.params![0].chainId
);
if (validNetwork) {
sendToBackgroundFromBackground({
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/astr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const astrOptions: EvmNetworkOptions = {
homePage: "https://astar.network/",
blockExplorerTX: "https://blockscout.com/astar/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.com/astar/address/[[address]]",
chainID: 592,
chainID: "0x250",
isTestNetwork: false,
currencyName: "ASTR",
currencyNameLong: "Astar",
node: "wss://astar.public.blastapi.io/",
icon: require("./icons/astr.png"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/bsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const bscOptions: EvmNetworkOptions = {
homePage: "https://www.binance.org/en/smartChain",
blockExplorerTX: "https://bscscan.com/tx/[[txHash]]",
blockExplorerAddr: "https://bscscan.com/address/[[address]]",
chainID: 56,
chainID: "0x38",
isTestNetwork: false,
currencyName: "BNB",
currencyNameLong: "Binance",
node: "wss://nodes.mewapi.io/ws/bsc",
icon: require("./icons/bsc.svg"),
gradient: "#F0B90B",
Expand Down
26 changes: 26 additions & 0 deletions packages/extension/src/providers/ethereum/networks/canto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler";
import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types";
import { EtherscanActivity } from "../libs/activity-handlers";
import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network";

const cantoOptions: EvmNetworkOptions = {
name: NetworkNames.Canto,
name_long: "Canto",
homePage: "https://canto.io/",
blockExplorerTX: "https://evm.explorer.canto.io/tx/[[txHash]]",
blockExplorerAddr: "https://evm.explorer.canto.io/address/[[address]]",
chainID: "0x1e14",
isTestNetwork: false,
currencyName: "CANTO",
currencyNameLong: "Canto",
node: "https://canto.evm.chandrastation.com/",
icon: require("./icons/canto.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
coingeckoID: "canto",
coingeckoPlatform: CoingeckoPlatform.Canto,
activityHandler: wrapActivityHandler(EtherscanActivity),
};

const canto = new EvmNetwork(cantoOptions);

export default canto;
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const etcOptions: EvmNetworkOptions = {
homePage: "https://ethereumclassic.org/",
blockExplorerTX: "https://blockscout.com/etc/mainnet/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.com/etc/mainnet/address/[[address]]",
chainID: 61,
chainID: "0x3d",
isTestNetwork: false,
currencyName: "ETC",
currencyNameLong: "Ethereum Classic",
node: "wss://nodes.mewapi.io/ws/etc",
icon: require("./icons/etc.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const ethOptions: EvmNetworkOptions = {
homePage: "https://ethereum.org",
blockExplorerTX: "https://www.ethvm.com/tx/[[txHash]]",
blockExplorerAddr: "https://www.ethvm.com/address/[[address]]",
chainID: 1,
chainID: "0x1",
isTestNetwork: false,
currencyName: "ETH",
currencyNameLong: "Ethereum",
node: "wss://nodes.mewapi.io/ws/eth",
icon: require("./icons/eth.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/goerli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const goerliOptions: EvmNetworkOptions = {
homePage: "https://github.com/goerli/testnet",
blockExplorerTX: "https://goerli.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://goerli.etherscan.io/address/[[address]]",
chainID: 5,
chainID: "0x5",
isTestNetwork: true,
currencyName: "GöETH",
currencyNameLong: "Goerli",
node: "wss://nodes.mewapi.io/ws/goerli",
icon: require("./icons/eth.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/extension/src/providers/ethereum/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import karuraEvmNode from "./karura";
import okcNode from "./okc";
import shidenEvmNode from "./sdn";
import astarEvmNode from "./astr";
import optimismNode from "./op";
import cantoNode from "./canto";

export default {
goerli: goerliNode,
Expand All @@ -28,4 +30,6 @@ export default {
okc: okcNode,
shidenEvm: shidenEvmNode,
astarEvm: astarEvmNode,
op: optimismNode,
canto: cantoNode,
};
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/karura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const karuraOptions: EvmNetworkOptions = {
homePage: "https://karura.network",
blockExplorerTX: "https://blockscout.karura.network/tx/[[txHash]]",
blockExplorerAddr: "https://blockscout.karura.network/address/[[address]]",
chainID: 686,
chainID: "0x2ae",
isTestNetwork: false,
currencyName: "KAR",
currencyNameLong: "Karura",
node: "wss://eth-rpc-karura.aca-api.network/ws",
icon: require("./icons/karura-evm.svg"),
gradient: "linear-gradient(330.21deg, #E40C5B -26.31%, #FF4C3B 88.17%)",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/kov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const kovOptions: EvmNetworkOptions = {
homePage: "https://github.com/kovan-testnet",
blockExplorerTX: "https://kovan.etherscan.io/tx/[[txHash]]",
blockExplorerAddr: "https://kovan.etherscan.io/address/[[address]]",
chainID: 42,
chainID: "0x2a",
isTestNetwork: true,
currencyName: "KOV",
currencyNameLong: "Kovan",
node: "wss://nodes.mewapi.io/ws/kovan",
icon: require("./icons/eth.svg"),
gradient: "linear-gradient(180deg, #C549FF 0%, #684CFF 100%)",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/matic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ const maticOptions: EvmNetworkOptions = {
homePage: "https://polygonscan.com/",
blockExplorerTX: "https://polygonscan.com/tx/[[txHash]]",
blockExplorerAddr: "https://polygonscan.com/address/[[address]]",
chainID: 137,
chainID: "0x89",
isTestNetwork: false,
currencyName: "MATIC",
currencyNameLong: "Polygon Matic",
node: "wss://nodes.mewapi.io/ws/matic",
icon: require("./icons/matic.svg"),
gradient: "#7B3FE4",
Expand Down
Loading

2 comments on commit d3d5641

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.