mirror of
https://github.com/meshcore-dev/meshcore.js.git
synced 2026-04-20 22:13:49 +00:00
implement private key import and export
This commit is contained in:
parent
a95402c68b
commit
a04a3a9b19
3 changed files with 148 additions and 0 deletions
31
index.html
31
index.html
|
|
@ -104,6 +104,12 @@
|
|||
<button @click="getBatteryVoltage" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
|
||||
GetBatteryVoltage
|
||||
</button>
|
||||
<button @click="exportPrivateKey" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
|
||||
ExportPrivateKey
|
||||
</button>
|
||||
<button @click="importPrivateKey" class="border border-gray-500 px-2 bg-gray-100 hover:bg-gray-200 rounded">
|
||||
ImportPrivateKey
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -388,6 +394,31 @@
|
|||
0xd2,
|
||||
]);
|
||||
},
|
||||
async exportPrivateKey() {
|
||||
try {
|
||||
const response = await this.connection.exportPrivateKey();
|
||||
console.log(response);
|
||||
console.log(this.bytesToHex(response.privateKey));
|
||||
} catch(e) {
|
||||
alert(`Failed to export private key: ${e}`);
|
||||
}
|
||||
},
|
||||
async importPrivateKey() {
|
||||
|
||||
const privateKeyHex = prompt("Enter private key encoded in hex");
|
||||
if(!privateKeyHex){
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const privateKey = this.hexToBytes(privateKeyHex);
|
||||
await this.connection.importPrivateKey(privateKey);
|
||||
alert("Private key imported!")
|
||||
} catch(e) {
|
||||
alert(`Failed to export private key: ${e}`);
|
||||
}
|
||||
|
||||
},
|
||||
async reboot() {
|
||||
try {
|
||||
await this.connection.reboot();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue