Skip to content

Commit f4cb184

Browse files
Merge pull request #3 from AndriianChestnykh/origin/feature/diffie-hellman
Origin/feature/diffie hellman
2 parents 6d74d81 + 0c6d3f2 commit f4cb184

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

contracts/Hub.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ contract Hub {
1212
mapping (address => Request) public requests;
1313
mapping (address => bytes) public registeredKeys;
1414

15+
mapping (address => bool) public isHeir;
16+
1517
event PublicKeyRegistered(address indexed user, bytes publicKey);
1618
event EIMSentToOracle(address indexed owner, address indexed heir, bytes encryptedData);
1719
event EIMRequestedByHeir(address indexed heir);
@@ -33,6 +35,7 @@ contract Hub {
3335

3436
function registerPubKeyHeir(address heir, bytes calldata publicKey) public {
3537
registeredKeys[heir] = publicKey;
38+
isHeir[msg.sender] = true;
3639
emit PublicKeyRegistered(heir, publicKey);
3740
}
3841

@@ -70,4 +73,10 @@ contract Hub {
7073
require(registeredKeys[msg.sender].length > 0, "Oracle public key not registered");
7174
emit EIMSentToHeir(heir, encryptedData);
7275
}
76+
77+
function getPublicKeyHeir(string memory heirAddressStr) public view returns (bytes memory) {
78+
address heirAddress = address(bytes20(bytes(heirAddressStr)));
79+
require(isHeir[heirAddress], "Addres is not Heir");
80+
return registeredKeys[heirAddress];
81+
}
7382
}

dapps/ui/src/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { ethers } from "ethers";
2-
1+
import { ethers } from 'ethers'
32
import './index.css';
43

54
import WalletArtifact from '../../../artifacts/contracts/Wallet.sol/Wallet.json'
5+
import HubArtifact from '../../../artifacts/contracts/Hub.sol/Hub.json'
66
import DeployInfo from '../../../deployInfo.json'
77
import { splitSignature } from "ethers/lib/utils";
88

99
const { abi: walletAbi } = WalletArtifact
10+
const { abi: hubAbi } = HubArtifact
1011

1112
let wallet;
1213
let accounts
@@ -71,6 +72,12 @@ const popupText = document.getElementById('popup-text')
7172

7273
const provider = new ethers.providers.Web3Provider(window.ethereum)
7374

75+
const hubProvider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
76+
const hubAddress = DeployInfo.hubAddress
77+
78+
const hubContract = new ethers.Contract(hubAbi, hubAddress, hubProvider)
79+
80+
7481
let walletInfo = {
7582
ownershipStatus: undefined,
7683
address: undefined,
@@ -137,6 +144,19 @@ async function onClickSignTypedData() {
137144
const heirAddress = document.getElementById('heirAddress')
138145
const heir = provider.getSigner(heirAddress.value)
139146

147+
//todo - get public key from heir
148+
async function getPublicKeyFromHeir(address) {
149+
try {
150+
const publicKey = await hubContract.getPublicKeyHeir(address)
151+
return publicKey
152+
} catch {
153+
console.error("Error getting public key:", error)
154+
return null
155+
}
156+
}
157+
158+
const publicKeyHeir = getPublicKeyFromHeir(heirAddress.value)
159+
140160
const im = {
141161
types: {
142162
InheritanceMessage: [
@@ -560,6 +580,8 @@ const initialize = async () => {
560580
updateButtons()
561581
}
562582

583+
getGreetingFromContractHub()
584+
563585
// assign events
564586
connectWalletButton.onclick = onClickConnectWallet
565587
disconnectWalletButton.onclick = onClickDisconnectWallet

dapps/ui/src/test-file.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { HDNodeWallet } from 'ethers';
2+
3+
const mnemonic = 'test test test test test test test test test test test junk';
4+
5+
const message = "Hello World!";
6+
7+
(async () => {
8+
const hdwallet = HDNodeWallet.fromPhrase(mnemonic);
9+
console.log("Private key0: ", hdwallet.privateKey); // default path m/44'/60'/0'/0/0
10+
console.log("Address0: ", hdwallet.address);
11+
console.log("Signature0: ", await hdwallet.signMessage(message));
12+
13+
const hdwallet1 = HDNodeWallet.fromPhrase(mnemonic, null, "m/44'/60'/0'/0/1");
14+
console.log("\nPrivate key1: ", hdwallet1.privateKey);
15+
console.log("Address1: ", hdwallet1.address);
16+
console.log("Signature1: ", await hdwallet1.signMessage(message));
17+
})();

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@
2828
"crypto": "^1.0.1",
2929
"css-loader": "^6.8.1",
3030
"eth-sig-util": "^3.0.1",
31+
"fs": "^0.0.1-security",
3132
"hardhat": "^2.12.7",
3233
"mini-css-extract-plugin": "^2.7.6",
3334
"mocha": "^10.3.0",
3435
"node-polyfill-webpack-plugin": "^2.0.1",
36+
"secp256k1": "^5.0.0",
3537
"serve": "^14.2.0",
3638
"sodium": "^3.0.2",
3739
"style-loader": "^3.3.3",
3840
"webpack": "^5.75.0",
3941
"webpack-cli": "^5.0.1",
40-
"webpack-dev-server": "^4.11.1"
42+
"webpack-dev-server": "^4.11.1",
43+
"yaml": "^2.3.4"
4144
}
4245
}

0 commit comments

Comments
 (0)