diff --git a/packages/extension-bridge/src/internal.ts b/packages/extension-bridge/src/internal.ts index 7bf26dadd..867d4d312 100644 --- a/packages/extension-bridge/src/internal.ts +++ b/packages/extension-bridge/src/internal.ts @@ -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); }); @@ -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); }); @@ -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 + } } }; diff --git a/packages/extension/package.json b/packages/extension/package.json index bc98a6844..3a4c226c1 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -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 *;", @@ -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", diff --git a/packages/extension/src/providers/ethereum/inject.ts b/packages/extension/src/providers/ethereum/inject.ts index b3f48c67a..46e4f0beb 100644 --- a/packages/extension/src/providers/ethereum/inject.ts +++ b/packages/extension/src/providers/ethereum/inject.ts @@ -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; @@ -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 = { diff --git a/packages/extension/src/providers/ethereum/libs/sanitize-typed-data.ts b/packages/extension/src/providers/ethereum/libs/sanitize-typed-data.ts new file mode 100644 index 000000000..e29cca001 --- /dev/null +++ b/packages/extension/src/providers/ethereum/libs/sanitize-typed-data.ts @@ -0,0 +1,53 @@ +import { + TypedDataUtils, + SignTypedDataVersion, + MessageTypeProperty, + MessageTypes, + TypedMessage, +} from "@metamask/eth-sig-util"; + +const encodeData = ( + primaryType: string, + data: Record, + types: Record, + version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4 +): Record => { + const retObject: Record = {}; + 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 = ( + typedData: TypedMessage, + version: SignTypedDataVersion.V3 | SignTypedDataVersion.V4 +): Record => { + 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 }; diff --git a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts index 144265d9c..dc756ed08 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts @@ -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; diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts index 2abf1411f..e65e439a7 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.events.mocha.ts @@ -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, @@ -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 () => { diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts index ec4feb9e5..04b90bb52 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.requests.mocha.ts @@ -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; @@ -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 () => { diff --git a/packages/extension/src/providers/ethereum/ui/eth-sign-typedata.vue b/packages/extension/src/providers/ethereum/ui/eth-sign-typedata.vue index d6481301e..b4e317519 100644 --- a/packages/extension/src/providers/ethereum/ui/eth-sign-typedata.vue +++ b/packages/extension/src/providers/ethereum/ui/eth-sign-typedata.vue @@ -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"; @@ -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); } }); diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index b410b5e23..480a6110f 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -391,6 +391,7 @@ const isInputsValid = computed(() => { return false; } if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; + if (gasCostValues.value.REGULAR.nativeValue === "0") return false; return true; }); diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/verify-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/verify-transaction/index.vue index bc58592d9..1cfddea00 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/verify-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/verify-transaction/index.vue @@ -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 { @@ -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; diff --git a/yarn.lock b/yarn.lock index a24df2e85..1bcadd17a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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 @@ -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" @@ -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" @@ -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 @@ -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 @@ -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 @@ -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" @@ -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" @@ -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 @@ -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"