diff --git a/CHANGELOG.md b/CHANGELOG.md index 583fb1f88a..882da06c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Renamed `discover.getStatusFleetNodes` to `discovery.getBootstrapNodes`; Changed the API to allow retrieval of bootstrap nodes from other sources. -- Examples: Renamed `eth-dm` to `eth-pm`: "Direct Message" can lead to confusion with "Direct Connection" that +- Examples: Renamed `eth-dm` to `eth-pm`; "Direct Message" can lead to confusion with "Direct Connection" that refers to low latency network connections. +- Examples (eth-pm): Use sign typed data EIP-712 instead of personal sign. ### Removed - Examples (cli-chat): The focus of this library is Web environment; diff --git a/examples/eth-pm-wallet-encryption/src/App.tsx b/examples/eth-pm-wallet-encryption/src/App.tsx index a4f022818d..ab8590bc6f 100644 --- a/examples/eth-pm-wallet-encryption/src/App.tsx +++ b/examples/eth-pm-wallet-encryption/src/App.tsx @@ -3,7 +3,6 @@ import '@ethersproject/shims'; import React, { useEffect, useState } from 'react'; import './App.css'; import { Waku } from 'js-waku'; -import { Signer } from '@ethersproject/abstract-signer'; import { Message } from './messaging/Messages'; import 'fontsource-roboto'; import { AppBar, IconButton, Toolbar, Typography } from '@material-ui/core'; @@ -67,7 +66,6 @@ const useStyles = makeStyles({ function App() { const [waku, setWaku] = useState(); - const [signer, setSigner] = useState(); const [provider, setProvider] = useState(); const [encPublicKey, setEncPublicKey] = useState(); const [publicKeys, setPublicKeys] = useState>( @@ -193,7 +191,6 @@ function App() {
@@ -204,7 +201,6 @@ function App() { address={address} /> }) => Promise) @@ -17,7 +15,6 @@ interface Props { } export default function BroadcastPublicKey({ - signer, encryptionPublicKey, address, waku, @@ -25,18 +22,12 @@ export default function BroadcastPublicKey({ }: Props) { const broadcastPublicKey = () => { if (!encryptionPublicKey) return; - if (!signer) return; if (!address) return; if (!waku) return; if (!providerRequest) return; console.log('Creating Public Key Message'); - createPublicKeyMessage( - signer, - address, - encryptionPublicKey, - providerRequest - ) + createPublicKeyMessage(address, encryptionPublicKey, providerRequest) .then((msg) => { console.log('Public Key Message created'); encodePublicKeyWakuMessage(msg) @@ -63,7 +54,7 @@ export default function BroadcastPublicKey({ variant="contained" color="primary" onClick={broadcastPublicKey} - disabled={!encryptionPublicKey || !waku || !signer} + disabled={!encryptionPublicKey || !waku || !address || !providerRequest} > Broadcast Encryption Public Key diff --git a/examples/eth-pm-wallet-encryption/src/ConnectWallet.tsx b/examples/eth-pm-wallet-encryption/src/ConnectWallet.tsx index 7b5549014f..cb6cf9c44a 100644 --- a/examples/eth-pm-wallet-encryption/src/ConnectWallet.tsx +++ b/examples/eth-pm-wallet-encryption/src/ConnectWallet.tsx @@ -1,6 +1,5 @@ import { Button } from '@material-ui/core'; import React from 'react'; -import { Signer } from '@ethersproject/abstract-signer'; import { ethers } from 'ethers'; import { Web3Provider } from '@ethersproject/providers/src.ts/web3-provider'; @@ -8,15 +7,10 @@ declare let window: any; interface Props { setAddress: (address: string) => void; - setSigner: (signer: Signer) => void; setProvider: (provider: Web3Provider) => void; } -export default function ConnectWallet({ - setAddress, - setSigner, - setProvider, -}: Props) { +export default function ConnectWallet({ setAddress, setProvider }: Props) { const connectWallet = () => { try { window.ethereum @@ -25,7 +19,6 @@ export default function ConnectWallet({ const _provider = new ethers.providers.Web3Provider(window.ethereum); setAddress(accounts[0]); setProvider(_provider); - setSigner(_provider.getSigner()); }); } catch (e) { console.error('No web3 provider available'); diff --git a/examples/eth-pm-wallet-encryption/src/crypto.ts b/examples/eth-pm-wallet-encryption/src/crypto.ts index 1fc360d338..95053cda45 100644 --- a/examples/eth-pm-wallet-encryption/src/crypto.ts +++ b/examples/eth-pm-wallet-encryption/src/crypto.ts @@ -1,6 +1,5 @@ import '@ethersproject/shims'; -import { Signer } from '@ethersproject/abstract-signer'; import { PublicKeyMessage } from './messaging/wire'; import { hexToBuf, equalByteArrays, bufToHex } from 'js-waku/lib/utils'; import * as sigUtil from 'eth-sig-util'; @@ -11,7 +10,6 @@ import * as sigUtil from 'eth-sig-util'; * Ethereum Address holder. */ export async function createPublicKeyMessage( - web3Signer: Signer, address: string, encryptionPublicKey: Uint8Array, providerRequest: (request: { @@ -74,7 +72,7 @@ export async function signEncryptionKey( const msgParams = buildMsgParams(encryptionPublicKey, fromAddress); const result = await providerRequest({ - method: 'eth_signTypedData_v4', + method: 'eth_signTypedData_v3', params: [fromAddress, msgParams], from: fromAddress, }); diff --git a/examples/eth-pm/package-lock.json b/examples/eth-pm/package-lock.json index 79ee13258e..209e3f9b93 100644 --- a/examples/eth-pm/package-lock.json +++ b/examples/eth-pm/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "eth-pm", "version": "0.1.0", "dependencies": { "@material-ui/core": "^4.11.4", @@ -15,6 +16,7 @@ "@types/jest": "^26.0.15", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", + "eth-sig-util": "^3.0.1", "ethers": "^5.2.0", "fontsource-roboto": "^4.0.0", "js-waku": "../../build/main", @@ -4174,6 +4176,14 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/eslint": { "version": "7.2.13", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.13.tgz", @@ -4275,6 +4285,14 @@ "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==" }, + "node_modules/@types/pbkdf2": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@types/pbkdf2/-/pbkdf2-3.1.0.tgz", + "integrity": "sha512-Cf63Rv7jCQ0LaL8tNXmEyqTHuIJxRdlS5vMh1mj5voN4+QFhVZnlZruezqpWYDiJ8UTzhP0VmeLXCmBk66YrMQ==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/prettier": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.3.0.tgz", @@ -4329,6 +4347,14 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.1.tgz", "integrity": "sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==" }, + "node_modules/@types/secp256k1": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/secp256k1/-/secp256k1-4.0.3.tgz", + "integrity": "sha512-Da66lEIFeIz9ltsdMZcpQvmrmmoqrfju8pm1BH8WbYjZSwUgCwXLb9C+9XYogwBITnbsSaMdVPb2ekf7TV+03w==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/source-list-map": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz", @@ -5887,6 +5913,14 @@ "node": ">=0.10.0" } }, + "node_modules/base-x": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.8.tgz", + "integrity": "sha512-Rl/1AWP4J/zRrk54hhlxH4drNxPJXYUaKffODVI53/dAsV4t9fBxyxYKAVPU1XBHxYwOWP9h9H0hM2MVw4YfJA==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/base/node_modules/define-property": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/define-property/-/define-property-1.0.0.tgz", @@ -5967,6 +6001,11 @@ "file-uri-to-path": "1.0.0" } }, + "node_modules/blakejs": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.1.tgz", + "integrity": "sha512-bLG6PHOCZJKNshTjGRBvET0vTciwQE6zFKOKKXPDJfwFBd4Ac0yBfPZqcGvGJap50l7ktvlpFqc2jGVaUgbJgg==" + }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -6173,6 +6212,24 @@ "url": "https://opencollective.com/browserslist" } }, + "node_modules/bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", + "dependencies": { + "base-x": "^3.0.2" + } + }, + "node_modules/bs58check": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz", + "integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==", + "dependencies": { + "bs58": "^4.0.0", + "create-hash": "^1.1.0", + "safe-buffer": "^5.1.2" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -9676,6 +9733,76 @@ "node": ">= 0.6" } }, + "node_modules/eth-sig-util": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-3.0.1.tgz", + "integrity": "sha512-0Us50HiGGvZgjtWTyAI/+qTzYPMLy5Q451D0Xy68bxq1QMWdoOddDwGvsqcFT27uohKgalM9z/yxplyt+mY2iQ==", + "dependencies": { + "ethereumjs-abi": "^0.6.8", + "ethereumjs-util": "^5.1.1", + "tweetnacl": "^1.0.3", + "tweetnacl-util": "^0.15.0" + } + }, + "node_modules/ethereum-cryptography": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", + "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "dependencies": { + "@types/pbkdf2": "^3.0.0", + "@types/secp256k1": "^4.0.1", + "blakejs": "^1.1.0", + "browserify-aes": "^1.2.0", + "bs58check": "^2.1.2", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "hash.js": "^1.1.7", + "keccak": "^3.0.0", + "pbkdf2": "^3.0.17", + "randombytes": "^2.1.0", + "safe-buffer": "^5.1.2", + "scrypt-js": "^3.0.0", + "secp256k1": "^4.0.1", + "setimmediate": "^1.0.5" + } + }, + "node_modules/ethereumjs-abi": { + "version": "0.6.8", + "resolved": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz", + "integrity": "sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA==", + "dependencies": { + "bn.js": "^4.11.8", + "ethereumjs-util": "^6.0.0" + } + }, + "node_modules/ethereumjs-abi/node_modules/ethereumjs-util": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz", + "integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==", + "dependencies": { + "@types/bn.js": "^4.11.3", + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "elliptic": "^6.5.2", + "ethereum-cryptography": "^0.1.3", + "ethjs-util": "0.1.6", + "rlp": "^2.2.3" + } + }, + "node_modules/ethereumjs-util": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz", + "integrity": "sha512-v3kT+7zdyCm1HIqWlLNrHGqHGLpGYIhjeHxQjnDXjLT2FyGJDsd3LWMYUo7pAFRrk86CR3nUJfhC81CCoJNNGQ==", + "dependencies": { + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "elliptic": "^6.5.2", + "ethereum-cryptography": "^0.1.3", + "ethjs-util": "^0.1.3", + "rlp": "^2.0.0", + "safe-buffer": "^5.1.1" + } + }, "node_modules/ethers": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.3.1.tgz", @@ -9723,6 +9850,19 @@ "@ethersproject/wordlists": "5.3.0" } }, + "node_modules/ethjs-util": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", + "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", + "dependencies": { + "is-hex-prefixed": "1.0.0", + "strip-hex-prefix": "1.0.0" + }, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, "node_modules/eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -12144,6 +12284,15 @@ "node": ">=0.10.0" } }, + "node_modules/is-hex-prefixed": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, "node_modules/is-in-browser": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/is-in-browser/-/is-in-browser-1.1.3.tgz", @@ -13643,6 +13792,19 @@ "node": ">=4.0" } }, + "node_modules/keccak": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", + "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", + "hasInstallScript": true, + "dependencies": { + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/killable": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz", @@ -14422,6 +14584,11 @@ "tslib": "^2.0.3" } }, + "node_modules/node-addon-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", + "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" + }, "node_modules/node-forge": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz", @@ -14430,6 +14597,16 @@ "node": ">= 6.0.0" } }, + "node_modules/node-gyp-build": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", + "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -18371,6 +18548,17 @@ "inherits": "^2.0.1" } }, + "node_modules/rlp": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.6.tgz", + "integrity": "sha512-HAfAmL6SDYNWPUOJNrM500x4Thn4PZsEy5pijPh40U9WfNk0z15hUYzO9xVIMAdIHdFtD8CBDHd75Td1g36Mjg==", + "dependencies": { + "bn.js": "^4.11.1" + }, + "bin": { + "rlp": "bin/rlp" + } + }, "node_modules/rollup": { "version": "1.32.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", @@ -18864,6 +19052,20 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, + "node_modules/secp256k1": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", + "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", + "hasInstallScript": true, + "dependencies": { + "elliptic": "^6.5.2", + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/select-hose": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", @@ -19937,6 +20139,18 @@ "node": ">=6" } }, + "node_modules/strip-hex-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "dependencies": { + "is-hex-prefixed": "1.0.0" + }, + "engines": { + "node": ">=6.5.0", + "npm": ">=3" + } + }, "node_modules/strip-indent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", @@ -20742,6 +20956,16 @@ "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=" }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/tweetnacl-util": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + }, "node_modules/type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", @@ -25898,6 +26122,14 @@ "@babel/types": "^7.3.0" } }, + "@types/bn.js": { + "version": "4.11.6", + "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", + "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", + "requires": { + "@types/node": "*" + } + }, "@types/eslint": { "version": "7.2.13", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.2.13.tgz", @@ -25999,6 +26231,14 @@ "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==" }, + "@types/pbkdf2": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@types/pbkdf2/-/pbkdf2-3.1.0.tgz", + "integrity": "sha512-Cf63Rv7jCQ0LaL8tNXmEyqTHuIJxRdlS5vMh1mj5voN4+QFhVZnlZruezqpWYDiJ8UTzhP0VmeLXCmBk66YrMQ==", + "requires": { + "@types/node": "*" + } + }, "@types/prettier": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.3.0.tgz", @@ -26053,6 +26293,14 @@ "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.1.tgz", "integrity": "sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==" }, + "@types/secp256k1": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/secp256k1/-/secp256k1-4.0.3.tgz", + "integrity": "sha512-Da66lEIFeIz9ltsdMZcpQvmrmmoqrfju8pm1BH8WbYjZSwUgCwXLb9C+9XYogwBITnbsSaMdVPb2ekf7TV+03w==", + "requires": { + "@types/node": "*" + } + }, "@types/source-list-map": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz", @@ -27286,6 +27534,14 @@ } } }, + "base-x": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.8.tgz", + "integrity": "sha512-Rl/1AWP4J/zRrk54hhlxH4drNxPJXYUaKffODVI53/dAsV4t9fBxyxYKAVPU1XBHxYwOWP9h9H0hM2MVw4YfJA==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -27332,6 +27588,11 @@ "file-uri-to-path": "1.0.0" } }, + "blakejs": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.1.tgz", + "integrity": "sha512-bLG6PHOCZJKNshTjGRBvET0vTciwQE6zFKOKKXPDJfwFBd4Ac0yBfPZqcGvGJap50l7ktvlpFqc2jGVaUgbJgg==" + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -27522,6 +27783,24 @@ "node-releases": "^1.1.71" } }, + "bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", + "requires": { + "base-x": "^3.0.2" + } + }, + "bs58check": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz", + "integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==", + "requires": { + "bs58": "^4.0.0", + "create-hash": "^1.1.0", + "safe-buffer": "^5.1.2" + } + }, "bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -30212,6 +30491,78 @@ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, + "eth-sig-util": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eth-sig-util/-/eth-sig-util-3.0.1.tgz", + "integrity": "sha512-0Us50HiGGvZgjtWTyAI/+qTzYPMLy5Q451D0Xy68bxq1QMWdoOddDwGvsqcFT27uohKgalM9z/yxplyt+mY2iQ==", + "requires": { + "ethereumjs-abi": "^0.6.8", + "ethereumjs-util": "^5.1.1", + "tweetnacl": "^1.0.3", + "tweetnacl-util": "^0.15.0" + } + }, + "ethereum-cryptography": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", + "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "requires": { + "@types/pbkdf2": "^3.0.0", + "@types/secp256k1": "^4.0.1", + "blakejs": "^1.1.0", + "browserify-aes": "^1.2.0", + "bs58check": "^2.1.2", + "create-hash": "^1.2.0", + "create-hmac": "^1.1.7", + "hash.js": "^1.1.7", + "keccak": "^3.0.0", + "pbkdf2": "^3.0.17", + "randombytes": "^2.1.0", + "safe-buffer": "^5.1.2", + "scrypt-js": "^3.0.0", + "secp256k1": "^4.0.1", + "setimmediate": "^1.0.5" + } + }, + "ethereumjs-abi": { + "version": "0.6.8", + "resolved": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz", + "integrity": "sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA==", + "requires": { + "bn.js": "^4.11.8", + "ethereumjs-util": "^6.0.0" + }, + "dependencies": { + "ethereumjs-util": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz", + "integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==", + "requires": { + "@types/bn.js": "^4.11.3", + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "elliptic": "^6.5.2", + "ethereum-cryptography": "^0.1.3", + "ethjs-util": "0.1.6", + "rlp": "^2.2.3" + } + } + } + }, + "ethereumjs-util": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz", + "integrity": "sha512-v3kT+7zdyCm1HIqWlLNrHGqHGLpGYIhjeHxQjnDXjLT2FyGJDsd3LWMYUo7pAFRrk86CR3nUJfhC81CCoJNNGQ==", + "requires": { + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "elliptic": "^6.5.2", + "ethereum-cryptography": "^0.1.3", + "ethjs-util": "^0.1.3", + "rlp": "^2.0.0", + "safe-buffer": "^5.1.1" + } + }, "ethers": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.3.1.tgz", @@ -30249,6 +30600,15 @@ "@ethersproject/wordlists": "5.3.0" } }, + "ethjs-util": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", + "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", + "requires": { + "is-hex-prefixed": "1.0.0", + "strip-hex-prefix": "1.0.0" + } + }, "eventemitter3": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", @@ -32150,6 +32510,11 @@ "is-extglob": "^2.1.1" } }, + "is-hex-prefixed": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=" + }, "is-in-browser": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/is-in-browser/-/is-in-browser-1.1.3.tgz", @@ -33301,6 +33666,15 @@ "object.assign": "^4.1.2" } }, + "keccak": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.1.tgz", + "integrity": "sha512-epq90L9jlFWCW7+pQa6JOnKn2Xgl2mtI664seYR6MHskvI9agt7AnDqmAlp9TqU4/caMYbA08Hi5DMZAl5zdkA==", + "requires": { + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0" + } + }, "killable": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz", @@ -33928,11 +34302,21 @@ "tslib": "^2.0.3" } }, + "node-addon-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", + "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" + }, "node-forge": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz", "integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==" }, + "node-gyp-build": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.2.3.tgz", + "integrity": "sha512-MN6ZpzmfNCRM+3t57PTJHgHyw/h4OWnZ6mR8P5j/uZtqQr46RRuDE/P+g3n0YR/AiYXeWixZZzaip77gdICfRg==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -37038,6 +37422,14 @@ "inherits": "^2.0.1" } }, + "rlp": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.6.tgz", + "integrity": "sha512-HAfAmL6SDYNWPUOJNrM500x4Thn4PZsEy5pijPh40U9WfNk0z15hUYzO9xVIMAdIHdFtD8CBDHd75Td1g36Mjg==", + "requires": { + "bn.js": "^4.11.1" + } + }, "rollup": { "version": "1.32.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", @@ -37399,6 +37791,16 @@ "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==" }, + "secp256k1": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-4.0.2.tgz", + "integrity": "sha512-UDar4sKvWAksIlfX3xIaQReADn+WFnHvbVujpcbr+9Sf/69odMwy2MUsz5CKLQgX9nsIyrjuxL2imVyoNHa3fg==", + "requires": { + "elliptic": "^6.5.2", + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0" + } + }, "select-hose": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz", @@ -38312,6 +38714,14 @@ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" }, + "strip-hex-prefix": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", + "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "requires": { + "is-hex-prefixed": "1.0.0" + } + }, "strip-indent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", @@ -38937,6 +39347,16 @@ "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=" }, + "tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "tweetnacl-util": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + }, "type": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", diff --git a/examples/eth-pm/package.json b/examples/eth-pm/package.json index ee0b1b45a8..f92dc09106 100644 --- a/examples/eth-pm/package.json +++ b/examples/eth-pm/package.json @@ -12,6 +12,7 @@ "@types/jest": "^26.0.15", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", + "eth-sig-util": "^3.0.1", "ethers": "^5.2.0", "fontsource-roboto": "^4.0.0", "js-waku": "../../build/main", diff --git a/examples/eth-pm/src/App.tsx b/examples/eth-pm/src/App.tsx index 64d1ed9fba..8f5a15371e 100644 --- a/examples/eth-pm/src/App.tsx +++ b/examples/eth-pm/src/App.tsx @@ -3,7 +3,6 @@ import '@ethersproject/shims'; import React, { useEffect, useState } from 'react'; import './App.css'; import { Waku } from 'js-waku'; -import { Signer } from '@ethersproject/abstract-signer'; import { KeyPair } from './crypto'; import { Message } from './messaging/Messages'; import 'fontsource-roboto'; @@ -25,6 +24,7 @@ import { initWaku, PublicKeyContentTopic, } from './waku'; +import { Web3Provider } from '@ethersproject/providers/src.ts/web3-provider'; import ConnectWallet from './ConnectWallet'; const theme = createMuiTheme({ @@ -67,8 +67,8 @@ const useStyles = makeStyles({ function App() { const [waku, setWaku] = useState(); - const [signer, setSigner] = useState(); - const [EncryptionKeyPair, setEncryptionKeyPair] = useState< + const [provider, setProvider] = useState(); + const [encryptionKeyPair, setEncryptionKeyPair] = useState< KeyPair | undefined >(); const [publicKeys, setPublicKeys] = useState>( @@ -120,21 +120,21 @@ function App() { useEffect(() => { if (!waku) return; - if (!EncryptionKeyPair) return; + if (!encryptionKeyPair) return; - waku.relay.addDecryptionKey(EncryptionKeyPair.privateKey); + waku.relay.addDecryptionKey(encryptionKeyPair.privateKey); return function cleanUp() { if (!waku) return; - if (!EncryptionKeyPair) return; + if (!encryptionKeyPair) return; - waku.relay.deleteDecryptionKey(EncryptionKeyPair.privateKey); + waku.relay.deleteDecryptionKey(encryptionKeyPair.privateKey); }; - }, [waku, EncryptionKeyPair]); + }, [waku, encryptionKeyPair]); useEffect(() => { if (!waku) return; - if (!EncryptionKeyPair) return; + if (!encryptionKeyPair) return; if (!address) return; const observerPrivateMessage = handlePrivateMessage.bind( @@ -154,7 +154,7 @@ function App() { PrivateMessageContentTopic, ]); }; - }, [waku, address, EncryptionKeyPair]); + }, [waku, address, encryptionKeyPair]); useEffect(() => { if (!waku) return; @@ -204,18 +204,22 @@ function App() {
Wallet - +
Encryption Key Pair
diff --git a/examples/eth-pm/src/BroadcastPublicKey.tsx b/examples/eth-pm/src/BroadcastPublicKey.tsx index 518be119f0..3b8c781439 100644 --- a/examples/eth-pm/src/BroadcastPublicKey.tsx +++ b/examples/eth-pm/src/BroadcastPublicKey.tsx @@ -3,26 +3,30 @@ import React, { useState } from 'react'; import { createPublicKeyMessage, KeyPair } from './crypto'; import { PublicKeyMessage } from './messaging/wire'; import { WakuMessage, Waku } from 'js-waku'; -import { Signer } from '@ethersproject/abstract-signer'; import { PublicKeyContentTopic } from './waku'; interface Props { EncryptionKeyPair: KeyPair | undefined; waku: Waku | undefined; - signer: Signer | undefined; + address: string | undefined; + providerRequest: + | ((request: { method: string; params?: Array }) => Promise) + | undefined; } export default function BroadcastPublicKey({ - signer, EncryptionKeyPair, waku, + address, + providerRequest, }: Props) { const [publicKeyMsg, setPublicKeyMsg] = useState(); const broadcastPublicKey = () => { if (!EncryptionKeyPair) return; - if (!signer) return; + if (!address) return; if (!waku) return; + if (!providerRequest) return; if (publicKeyMsg) { encodePublicKeyWakuMessage(publicKeyMsg) @@ -35,7 +39,11 @@ export default function BroadcastPublicKey({ console.log('Failed to encode Public Key Message in Waku Message'); }); } else { - createPublicKeyMessage(signer, EncryptionKeyPair.publicKey) + createPublicKeyMessage( + address, + EncryptionKeyPair.publicKey, + providerRequest + ) .then((msg) => { setPublicKeyMsg(msg); encodePublicKeyWakuMessage(msg) @@ -64,7 +72,7 @@ export default function BroadcastPublicKey({ variant="contained" color="primary" onClick={broadcastPublicKey} - disabled={!EncryptionKeyPair || !waku} + disabled={!EncryptionKeyPair || !waku || !address || !providerRequest} > Broadcast Encryption Public Key diff --git a/examples/eth-pm/src/ConnectWallet.tsx b/examples/eth-pm/src/ConnectWallet.tsx index cd575e2da5..cb6cf9c44a 100644 --- a/examples/eth-pm/src/ConnectWallet.tsx +++ b/examples/eth-pm/src/ConnectWallet.tsx @@ -1,16 +1,16 @@ import { Button } from '@material-ui/core'; import React from 'react'; -import { Signer } from '@ethersproject/abstract-signer'; import { ethers } from 'ethers'; +import { Web3Provider } from '@ethersproject/providers/src.ts/web3-provider'; declare let window: any; interface Props { setAddress: (address: string) => void; - setSigner: (signer: Signer) => void; + setProvider: (provider: Web3Provider) => void; } -export default function ConnectWallet({ setAddress, setSigner }: Props) { +export default function ConnectWallet({ setAddress, setProvider }: Props) { const connectWallet = () => { try { window.ethereum @@ -18,7 +18,7 @@ export default function ConnectWallet({ setAddress, setSigner }: Props) { .then((accounts: string[]) => { const _provider = new ethers.providers.Web3Provider(window.ethereum); setAddress(accounts[0]); - setSigner(_provider.getSigner()); + setProvider(_provider); }); } catch (e) { console.error('No web3 provider available'); diff --git a/examples/eth-pm/src/crypto.ts b/examples/eth-pm/src/crypto.ts index b67df1940d..43c4205bd8 100644 --- a/examples/eth-pm/src/crypto.ts +++ b/examples/eth-pm/src/crypto.ts @@ -1,10 +1,9 @@ import '@ethersproject/shims'; -import { ethers } from 'ethers'; -import { Signer } from '@ethersproject/abstract-signer'; import { PublicKeyMessage } from './messaging/wire'; import { hexToBuf, equalByteArrays, bufToHex } from 'js-waku/lib/utils'; import { generatePrivateKey, getPublicKey } from 'js-waku'; +import * as sigUtil from 'eth-sig-util'; export interface KeyPair { privateKey: Uint8Array; @@ -22,52 +21,95 @@ export async function generateEncryptionKeyPair(): Promise { /** * Sign the encryption public key with Web3. This can then be published to let other - * users know to use this public key to encrypt messages for the + * users know to use this encryption public key to encrypt messages for the * Ethereum Address holder. */ export async function createPublicKeyMessage( - web3Signer: Signer, - encryptionPublicKey: Uint8Array + address: string, + encryptionPublicKey: Uint8Array, + providerRequest: (request: { + method: string; + params?: Array; + }) => Promise ): Promise { - const ethAddress = await web3Signer.getAddress(); - const signature = await web3Signer.signMessage( - formatPublicKeyForSignature(encryptionPublicKey) + const signature = await signEncryptionKey( + encryptionPublicKey, + address, + providerRequest ); + console.log('Asking wallet to sign Public Key Message'); + console.log('Public Key Message signed'); + return new PublicKeyMessage({ encryptionPublicKey: encryptionPublicKey, - ethAddress: hexToBuf(ethAddress), + ethAddress: hexToBuf(address), signature: hexToBuf(signature), }); } +function buildMsgParams(encryptionPublicKey: Uint8Array, fromAddress: string) { + return JSON.stringify({ + domain: { + chainId: 1, + name: 'Ethereum Private Message over Waku', + version: '1', + }, + message: { + encryptionPublicKey: bufToHex(encryptionPublicKey), + ownerAddress: fromAddress, + }, + // Refers to the keys of the *types* object below. + primaryType: 'PublishEncryptionPublicKey', + types: { + EIP712Domain: [ + { name: 'name', type: 'string' }, + { name: 'version', type: 'string' }, + { name: 'chainId', type: 'uint256' }, + ], + PublishEncryptionPublicKey: [ + { name: 'encryptionPublicKey', type: 'string' }, + { name: 'ownerAddress', type: 'string' }, + ], + }, + }); +} + +export async function signEncryptionKey( + encryptionPublicKey: Uint8Array, + fromAddress: string, + providerRequest: (request: { + method: string; + params?: Array; + from?: string; + }) => Promise +): Promise { + const msgParams = buildMsgParams(encryptionPublicKey, fromAddress); + + const result = await providerRequest({ + method: 'eth_signTypedData_v3', + params: [fromAddress, msgParams], + from: fromAddress, + }); + + console.log('TYPED SIGNED:' + JSON.stringify(result)); + + return hexToBuf(result); +} + /** * Validate that the Encryption Public Key was signed by the holder of the given Ethereum address. */ export function validatePublicKeyMessage(msg: PublicKeyMessage): boolean { - const formattedMsg = formatPublicKeyForSignature(msg.encryptionPublicKey); - try { - const sigAddress = ethers.utils.verifyMessage(formattedMsg, msg.signature); - return equalByteArrays(sigAddress, msg.ethAddress); - } catch (e) { - console.log( - 'Failed to verify signature for Public Key Message', - formattedMsg, - msg - ); - return false; - } -} - -/** - * Prepare encryption public key to be signed for publication. - * The public key is set in on Object `{ encryptionPublicKey: string; }`, converted - * to JSON and then hashed with Keccak256. - * The usage of the object helps ensure the signature is only used in an Eth-PM - * context. - */ -function formatPublicKeyForSignature(encryptionPublicKey: Uint8Array): string { - return JSON.stringify({ - encryptionPublicKey: bufToHex(encryptionPublicKey), + const recovered = sigUtil.recoverTypedSignature_v4({ + data: JSON.parse( + buildMsgParams(msg.encryptionPublicKey, '0x' + bufToHex(msg.ethAddress)) + ), + sig: '0x' + bufToHex(msg.signature), }); + + console.log('Recovered', recovered); + console.log('ethAddress', '0x' + bufToHex(msg.ethAddress)); + + return equalByteArrays(recovered, msg.ethAddress); }