Skip to content

Commit

Permalink
Merge pull request #309 from enkryptcom/develop
Browse files Browse the repository at this point in the history
Release: v1.21.0
  • Loading branch information
kvhnuke authored Jun 13, 2023
2 parents edd64de + 51ecc0f commit 6d1a6c8
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 85 deletions.
7 changes: 5 additions & 2 deletions packages/extension-bridge/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const initIntercoms = () => {
const { tabId } = browser.devtools.inspectedWindow;
const name = `devtools@${tabId}`;
const connectToBackgroundWithDisconnect = () => {
port = browser.runtime.connect(undefined, { name });
port = browser.runtime.connect({ name });
port.onMessage.addListener((message: IInternalMessage) => {
routeMessage(message);
});
Expand All @@ -172,7 +172,7 @@ const initIntercoms = () => {
) {
const name = `${context}`;
const connectToBackgroundWithDisconnect = () => {
port = browser.runtime.connect(undefined, { name });
port = browser.runtime.connect({ name });
port.onMessage.addListener((message: IInternalMessage) => {
routeMessage(message);
});
Expand Down Expand Up @@ -237,6 +237,9 @@ const initIntercoms = () => {
}
});
});
if (chrome) {
setInterval(chrome.runtime.getPlatformInfo, 20e3); // on chrome force reconnect as this is a way of keeping the background running forever //https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@enkryptcom/extension",
"version": "1.20.0",
"version": "1.21.0",
"private": true,
"scripts": {
"zip": "cd dist; zip -r release.zip *;",
Expand Down Expand Up @@ -30,7 +30,7 @@
"@ethereumjs/common": "^3.1.2",
"@ethereumjs/tx": "^4.1.2",
"@ledgerhq/hw-transport-webusb": "^6.27.13",
"@metamask/eth-sig-util": "^5.0.2",
"@metamask/eth-sig-util": "^5.1.0",
"@types/chrome": "^0.0.233",
"@types/events": "^3.0.0",
"@types/less": "^3.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { EXTENSION_VERSION } from "@/configs/constants";
import { SettingsType } from "@/libs/settings-state/types";
import { EnkryptWindow } from "@/types/globals";
import { v4 as randomUUID } from "uuid";

export class Provider extends EventEmitter implements ProviderInterface {
chainId: string | null;
Expand Down Expand Up @@ -148,7 +149,7 @@ const injectDocument = (
if (!globalSettings.evm.inject.disabled)
document[options.name] = proxiedProvider; //proxy is needed due to web3js 1.3.0 callbackify issue. Used in superrare
document["enkrypt"]["providers"][options.name] = provider;
const ENKRYPT_UUID_V4 = document.crypto.randomUUID();
const ENKRYPT_UUID_V4 = randomUUID();
// EIP-6963
const eip6963AnnounceProvider = () => {
const info: EIP6963ProviderInfo = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
TypedDataUtils,
SignTypedDataVersion,
MessageTypeProperty,
MessageTypes,
TypedMessage,
} from "@metamask/eth-sig-util";

const encodeData = (
primaryType: string,
data: Record<string, unknown>,
types: Record<string, MessageTypeProperty[]>,
version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4
): Record<string, unknown> => {
const retObject: Record<string, unknown> = {};
for (const field of types[primaryType]) {
if (version === SignTypedDataVersion.V3 && data[field.name] === undefined) {
continue;
}
retObject[field.name] = data[field.name];
}
return retObject;
};

const sanitizeData = <T extends MessageTypes>(
typedData: TypedMessage<T>,
version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4
): Record<string, unknown> => {
const sanitizedData = TypedDataUtils.sanitizeData(typedData);
const { domain, types, primaryType, message } = sanitizedData;
const domainType = { EIP712Domain: sanitizedData.types.EIP712Domain };
const domainData = encodeData("EIP712Domain", domain, domainType, version);

if (sanitizedData.primaryType !== "EIP712Domain") {
const messageData = encodeData(
primaryType as string,
message,
types,
version
);
return {
domain: domainData,
message: messageData,
primaryType,
};
}
return {
domain: domainData,
primaryType,
};
};

export { sanitizeData };
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ const formatFeeHistory = (
number: blockNum,
baseFeePerGas: blockBaseFee,
gasUsedRatio: feeHistory.gasUsedRatio[index],
priorityFeePerGas: feeHistory.reward[index].map((x) => toBN(x)),
priorityFeePerGas: feeHistory.reward[index]
.map((x) => toBN(x))
.sort((a, b) => a.sub(b).toNumber()),
});
blockNum += 1;
index += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import EthereumInject from "../inject";
import { MessageMethod, EmitEvent } from "../types";
import { OnMessageResponse } from "@enkryptcom/types";
import { EnkryptWindow } from "@/types/globals";
import { randomUUID } from "crypto";

const providerSendMessage = async (
provider: ProviderName,
Expand Down Expand Up @@ -40,9 +39,6 @@ const tempWindow: EnkryptWindow = {
CustomEvent: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
dispatchEvent: () => {},
crypto: {
randomUUID: () => randomUUID(),
},
};
describe("Test injected Ethereum", () => {
it("should have default values", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { EthereumRequest } from "../types";
import { OnMessageResponse } from "@enkryptcom/types";
import { getError } from "@/libs/error";
import { EnkryptWindow } from "@/types/globals";
import { randomUUID } from "crypto";

const requestHandler = (request: string): OnMessageResponse => {
const req = JSON.parse(request) as EthereumRequest;
Expand Down Expand Up @@ -61,9 +60,6 @@ const tempWindow: EnkryptWindow = {
CustomEvent: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
dispatchEvent: () => {},
crypto: {
randomUUID: () => randomUUID(),
},
};
describe("Test Ethereum reponses", () => {
it("should send proper responses", async () => {
Expand Down
17 changes: 11 additions & 6 deletions packages/extension/src/providers/ethereum/ui/eth-sign-typedata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
TypedDataUtils,
SignTypedDataVersion,
} from "@metamask/eth-sig-util";
import { sanitizeData } from "@/providers/ethereum/libs/sanitize-typed-data";
import { bufferToHex } from "@enkryptcom/utils";
import { EvmNetwork } from "../types/evm-network";
import { EnkryptAccount } from "@enkryptcom/types";
Expand Down Expand Up @@ -86,13 +87,17 @@ onMounted(async () => {
identicon.value = network.value.identicon(account.value.address);
Options.value = options;
try {
message.value = JSON.stringify(
JSON.parse(Request.value.params![0]),
null,
2
);
const version = Request.value.params![2] as SignTypedDataVersion;
if (version === SignTypedDataVersion.V1) {
message.value = JSON.stringify(Request.value.params![0]);
} else {
let parsedJSON = Request.value.params![0];
if (typeof parsedJSON === "string") parsedJSON = JSON.parse(parsedJSON);
const sanitized = sanitizeData(parsedJSON, version);
message.value = JSON.stringify(sanitized);
}
} catch (e) {
message.value = JSON.stringify(Request.value.params![0], null, 2);
console.error(e);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ const isInputsValid = computed<boolean>(() => {
return false;
}
if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false;
if (gasCostValues.value.REGULAR.nativeValue === "0") return false;
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const isHasScroll = () => {
font-size: 16px;
line-height: 24px;
color: @secondaryLabel;
padding: 4px 141px 16px 32px;
padding: 4px 141px 13px 32px;
margin: 0;
&.popup {
Expand All @@ -319,7 +319,7 @@ const isHasScroll = () => {
position: absolute;
left: 0;
bottom: 0;
padding: 0 32px 32px 32px;
padding: 10px 32px 14px 32px;
display: flex;
justify-content: space-between;
align-items: center;
Expand Down
74 changes: 11 additions & 63 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2440,7 +2440,7 @@ __metadata:
"@ethereumjs/common": ^3.1.2
"@ethereumjs/tx": ^4.1.2
"@ledgerhq/hw-transport-webusb": ^6.27.13
"@metamask/eth-sig-util": ^5.0.2
"@metamask/eth-sig-util": ^5.1.0
"@polkadot/api": ^9.14.2
"@polkadot/extension-inject": ^0.44.9
"@polkadot/keyring": ^10.4.2
Expand Down Expand Up @@ -3158,15 +3158,6 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/rlp@npm:^4.0.0-beta.2":
version: 4.0.0
resolution: "@ethereumjs/rlp@npm:4.0.0"
bin:
rlp: bin/rlp
checksum: 407dfb8b1e09b4282e6be561e8d74f8939da78f460c08456c7ba2fb273fc42ee16027955a07085abfd7600ffb466c4c4add159885e67abb91bc85db9dd81ffb5
languageName: node
linkType: hard

"@ethereumjs/rlp@npm:^4.0.1":
version: 4.0.1
resolution: "@ethereumjs/rlp@npm:4.0.1"
Expand Down Expand Up @@ -3214,16 +3205,6 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/util@npm:^8.0.0":
version: 8.0.0
resolution: "@ethereumjs/util@npm:8.0.0"
dependencies:
"@ethereumjs/rlp": ^4.0.0-beta.2
ethereum-cryptography: ^1.1.2
checksum: 360e9795e120f15eba4d683260eca64071f9020eaa9d7276c0cdd80d837933757c0c089ba578a10ad0cfef51118d87649e1c6722a10385991590c4cf51eba62b
languageName: node
linkType: hard

"@ethereumjs/util@npm:^8.0.6":
version: 8.0.6
resolution: "@ethereumjs/util@npm:8.0.6"
Expand Down Expand Up @@ -4802,17 +4783,17 @@ __metadata:
languageName: node
linkType: hard

"@metamask/eth-sig-util@npm:^5.0.2":
version: 5.0.2
resolution: "@metamask/eth-sig-util@npm:5.0.2"
"@metamask/eth-sig-util@npm:^5.1.0":
version: 5.1.0
resolution: "@metamask/eth-sig-util@npm:5.1.0"
dependencies:
"@ethereumjs/util": ^8.0.0
bn.js: ^4.11.8
ethereum-cryptography: ^1.1.2
"@ethereumjs/util": ^8.0.6
bn.js: ^4.12.0
ethereum-cryptography: ^2.0.0
ethjs-util: ^0.1.6
tweetnacl: ^1.0.3
tweetnacl-util: ^0.15.1
checksum: 1fbf1a0f5e654058f0219c9018dbebadf53036c9c3b47c8faf1cac54816532bb18996821736f526ac4e3d579afcaf502af4ad07e88158a50f015141858b08a90
checksum: c639e3bf91625faeb0230a6314f0b2d05e8f5e2989542d3e0eed1d21b7b286e1860f68629870fd7e568c1a599b3993c4210403fb4c84a625fb1e75ef676eab4f
languageName: node
linkType: hard

Expand All @@ -4832,7 +4813,7 @@ __metadata:
languageName: node
linkType: hard

"@noble/hashes@npm:1.1.2, @noble/hashes@npm:^1, @noble/hashes@npm:^1.0.0, @noble/hashes@npm:~1.1.1":
"@noble/hashes@npm:1.1.2, @noble/hashes@npm:^1, @noble/hashes@npm:^1.0.0":
version: 1.1.2
resolution: "@noble/hashes@npm:1.1.2"
checksum: 3c2a8cb7c2e053811032f242155d870c5eb98844d924d69702244d48804cb03b42d4a666c49c2b71164420d8229cb9a6f242b972d50d5bb2f1d673b98b041de2
Expand Down Expand Up @@ -4867,7 +4848,7 @@ __metadata:
languageName: node
linkType: hard

"@noble/secp256k1@npm:1.6.3, @noble/secp256k1@npm:~1.6.0":
"@noble/secp256k1@npm:1.6.3":
version: 1.6.3
resolution: "@noble/secp256k1@npm:1.6.3"
checksum: 16eb3242533e645deb64444c771515f66bdc2ee0759894efd42fdeed4ab226ed29827aaaf6caa27d3d95b831452fd4246aa1007cd688aa462ad48fc084ab76e6
Expand Down Expand Up @@ -6686,17 +6667,6 @@ __metadata:
languageName: node
linkType: hard

"@scure/bip32@npm:1.1.0":
version: 1.1.0
resolution: "@scure/bip32@npm:1.1.0"
dependencies:
"@noble/hashes": ~1.1.1
"@noble/secp256k1": ~1.6.0
"@scure/base": ~1.1.0
checksum: e6102ab9038896861fca5628b8a97f3c4cb24a073cc9f333c71c747037d82e4423d1d111fd282ba212efaf73cbc5875702567fb4cf13b5f0eb23a5bab402e37e
languageName: node
linkType: hard

"@scure/bip32@npm:1.1.5":
version: 1.1.5
resolution: "@scure/bip32@npm:1.1.5"
Expand All @@ -6719,16 +6689,6 @@ __metadata:
languageName: node
linkType: hard

"@scure/bip39@npm:1.1.0":
version: 1.1.0
resolution: "@scure/bip39@npm:1.1.0"
dependencies:
"@noble/hashes": ~1.1.1
"@scure/base": ~1.1.0
checksum: c4361406f092a45e511dc572c89f497af6665ad81cb3fd7bf78e6772f357f7ae885e129ef0b985cb3496a460b4811318f77bc61634d9b0a8446079a801b6003c
languageName: node
linkType: hard

"@scure/bip39@npm:1.1.1":
version: 1.1.1
resolution: "@scure/bip39@npm:1.1.1"
Expand Down Expand Up @@ -10838,7 +10798,7 @@ __metadata:
languageName: node
linkType: hard

"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.11.0, bn.js@npm:^4.11.6, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9, bn.js@npm:^4.4.0":
"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.11.0, bn.js@npm:^4.11.6, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9, bn.js@npm:^4.12.0, bn.js@npm:^4.4.0":
version: 4.12.0
resolution: "bn.js@npm:4.12.0"
checksum: 39afb4f15f4ea537b55eaf1446c896af28ac948fdcf47171961475724d1bb65118cca49fa6e3d67706e4790955ec0e74de584e45c8f1ef89f46c812bee5b5a12
Expand Down Expand Up @@ -14304,18 +14264,6 @@ __metadata:
languageName: node
linkType: hard

"ethereum-cryptography@npm:^1.1.2":
version: 1.1.2
resolution: "ethereum-cryptography@npm:1.1.2"
dependencies:
"@noble/hashes": 1.1.2
"@noble/secp256k1": 1.6.3
"@scure/bip32": 1.1.0
"@scure/bip39": 1.1.0
checksum: 0ef55f141acad45b1ba1db58ce3d487155eb2d0b14a77b3959167a36ad324f46762873257def75e7f00dbe8ac78aabc323d2207830f85e63a42a1fb67063a6ba
languageName: node
linkType: hard

"ethereum-cryptography@npm:^1.2.0":
version: 1.2.0
resolution: "ethereum-cryptography@npm:1.2.0"
Expand Down

2 comments on commit 6d1a6c8

@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.