mirror of
https://github.com/status-im/js-waku-examples.git
synced 2025-01-12 23:14:32 +00:00
add import / export
This commit is contained in:
parent
75438f31df
commit
1789b78987
@ -122,6 +122,10 @@
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -142,6 +146,7 @@
|
||||
<h2>Keystore</h2>
|
||||
<div>
|
||||
<button id="import">Import</button>
|
||||
<input id="import-file" class="hidden" type="file" />
|
||||
<button id="export">Export</button>
|
||||
</div>
|
||||
</div>
|
||||
|
14
examples/rln-identity/package-lock.json
generated
14
examples/rln-identity/package-lock.json
generated
@ -8,7 +8,7 @@
|
||||
"name": "rln-chat",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@waku/rln": "0.1.1-bafbe01",
|
||||
"@waku/rln": "0.1.1-77ba0a6",
|
||||
"@waku/sdk": "^0.0.22",
|
||||
"@waku/utils": "^0.0.14",
|
||||
"ethers": "^5.7.2",
|
||||
@ -2209,9 +2209,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@waku/rln": {
|
||||
"version": "0.1.1-bafbe01",
|
||||
"resolved": "https://registry.npmjs.org/@waku/rln/-/rln-0.1.1-bafbe01.tgz",
|
||||
"integrity": "sha512-2KZ/1EbJH+Q/scW1rO/MemfRaWrygHr3+9lL2CQSMbbB0w9r4zU9w9o1W2VmOlj/KUZUjhVLoCNY5PpzcK3Ayw==",
|
||||
"version": "0.1.1-77ba0a6",
|
||||
"resolved": "https://registry.npmjs.org/@waku/rln/-/rln-0.1.1-77ba0a6.tgz",
|
||||
"integrity": "sha512-qJGlTsL9xosrF9uNtzfKFa60ouOs2i0LidfolF2S381TZqq1vBa+mullLol5m7XMgvL8ULpKd+1KasXd0lKjMA==",
|
||||
"dependencies": {
|
||||
"@chainsafe/bls-keystore": "^3.0.0",
|
||||
"@waku/utils": "^0.0.13",
|
||||
@ -11607,9 +11607,9 @@
|
||||
}
|
||||
},
|
||||
"@waku/rln": {
|
||||
"version": "0.1.1-bafbe01",
|
||||
"resolved": "https://registry.npmjs.org/@waku/rln/-/rln-0.1.1-bafbe01.tgz",
|
||||
"integrity": "sha512-2KZ/1EbJH+Q/scW1rO/MemfRaWrygHr3+9lL2CQSMbbB0w9r4zU9w9o1W2VmOlj/KUZUjhVLoCNY5PpzcK3Ayw==",
|
||||
"version": "0.1.1-77ba0a6",
|
||||
"resolved": "https://registry.npmjs.org/@waku/rln/-/rln-0.1.1-77ba0a6.tgz",
|
||||
"integrity": "sha512-qJGlTsL9xosrF9uNtzfKFa60ouOs2i0LidfolF2S381TZqq1vBa+mullLol5m7XMgvL8ULpKd+1KasXd0lKjMA==",
|
||||
"requires": {
|
||||
"@chainsafe/bls-keystore": "^3.0.0",
|
||||
"@waku/utils": "^0.0.13",
|
||||
|
@ -7,7 +7,7 @@
|
||||
"start": "webpack-dev-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@waku/rln": "0.1.1-bafbe01",
|
||||
"@waku/rln": "0.1.1-77ba0a6",
|
||||
"@waku/sdk": "^0.0.22",
|
||||
"@waku/utils": "^0.0.14",
|
||||
"ethers": "^5.7.2",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { createRLN, Keystore } from "@waku/rln";
|
||||
import { createRLN, Keystore, extractMetaMaskSigner } from "@waku/rln";
|
||||
import { randomNumber } from "./utils";
|
||||
import { SIGNATURE_MESSAGE } from "./const";
|
||||
|
||||
@ -70,7 +70,7 @@ export async function initRLN({ onStatusChange }) {
|
||||
};
|
||||
|
||||
const importLocalKeystore = (keystoreStr) => {
|
||||
rln.keystore = Keystore.fromString(keystoreStr);
|
||||
rln.keystore = Keystore.fromString(keystoreStr) || Keystore.create();
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -2,8 +2,9 @@ import { renderBytes } from "./utils";
|
||||
|
||||
const status = document.getElementById("status");
|
||||
const connectWalletButton = document.getElementById("connect");
|
||||
const importKeystore = document.getElementById("import");
|
||||
const exportKeystore = document.getElementById("export");
|
||||
const importKeystoreButton = document.getElementById("import");
|
||||
const importFileInput = document.getElementById("import-file");
|
||||
const exportKeystoreButton = document.getElementById("export");
|
||||
const keystoreOptions = document.getElementById("keystore");
|
||||
const keystorePassword = document.getElementById("password");
|
||||
const readCredentialButton = document.getElementById("read-credential");
|
||||
@ -105,6 +106,37 @@ export function initUI() {
|
||||
const credential = await readCredential(currentHash, password);
|
||||
_renderCredential(currentHash, credential);
|
||||
});
|
||||
|
||||
importFileInput.addEventListener("change", async (event) => {
|
||||
const file = event.currentTarget.files[0];
|
||||
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
const text = await file.text();
|
||||
importLocalKeystore(text);
|
||||
|
||||
const keystoreOptions = readKeystoreOptions();
|
||||
_renderKeystoreOptions(keystoreOptions);
|
||||
});
|
||||
|
||||
importKeystoreButton.addEventListener("click", async () => {
|
||||
importFileInput.click();
|
||||
});
|
||||
|
||||
exportKeystoreButton.addEventListener("click", () => {
|
||||
const filename = "keystore.json";
|
||||
const text = saveLocalKeystore();
|
||||
const file = new File([text], filename, {
|
||||
type: "application/json",
|
||||
});
|
||||
|
||||
const link = document.createElement("a");
|
||||
link.href = URL.createObjectURL(file);
|
||||
link.download = filename;
|
||||
link.click();
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user