implement private key import and export

This commit is contained in:
liamcottle 2025-02-21 16:58:17 +13:00
parent a95402c68b
commit a04a3a9b19
3 changed files with 148 additions and 0 deletions

View file

@ -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();