2024-03-21 14:25:07 -04:00
|
|
|
import {LitElement, html} from './lit-all.min.js';
|
|
|
|
import * as tfrpc from '/static/tfrpc.js';
|
|
|
|
|
|
|
|
class TfIdentityManagerElement extends LitElement {
|
|
|
|
static get properties() {
|
|
|
|
return {
|
|
|
|
ids: {type: Array},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.ids = [];
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
|
|
|
this.ids = await tfrpc.rpc.getIdentities();
|
|
|
|
}
|
|
|
|
|
|
|
|
async createIdentity() {
|
|
|
|
try {
|
2024-03-21 15:10:35 -04:00
|
|
|
const id = await tfrpc.rpc.createID();
|
2024-03-21 14:25:07 -04:00
|
|
|
alert('Successfully created: ' + id);
|
|
|
|
await tfrpc.rpc.reload();
|
|
|
|
} catch (err) {
|
|
|
|
alert('Error creating identity: ' + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 15:10:35 -04:00
|
|
|
async importIdentity() {
|
|
|
|
const words = this.renderRoot?.querySelector('#import-id-textarea').value;
|
|
|
|
if (!words) return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const newID = await tfrpc.rpc.addID(words);
|
|
|
|
|
2024-03-21 17:29:39 -04:00
|
|
|
if (newID) alert('Successfully imported a new identity.');
|
2024-03-21 15:10:35 -04:00
|
|
|
else alert('This identity already exists or is invalid.');
|
|
|
|
await tfrpc.rpc.reload();
|
|
|
|
} catch (err) {
|
|
|
|
alert('Error importing identity: ' + err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 14:25:07 -04:00
|
|
|
async exportIdentity(id) {
|
2024-03-21 15:10:35 -04:00
|
|
|
alert(
|
|
|
|
'Your private key is:\n' +
|
|
|
|
(await tfrpc.rpc.getPrivateKey(id)) +
|
|
|
|
'\nDo not share it with anyone!'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteIdentity(id) {
|
|
|
|
try {
|
|
|
|
if (
|
|
|
|
prompt(
|
|
|
|
'Are you sure you want to delete "' +
|
|
|
|
id +
|
|
|
|
'"? It cannot be recovered without the exported phrase.\\n\\nEnter the word "DELETE" to confirm you wish to delete it.'
|
|
|
|
) === 'DELETE'
|
|
|
|
) {
|
|
|
|
if (await tfrpc.rpc.deleteID(id)) {
|
|
|
|
alert('Successfully deleted ID: ' + id);
|
|
|
|
}
|
|
|
|
await tfrpc.rpc.reload();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
alert('Error deleting ID: ' + e);
|
|
|
|
}
|
2024-03-21 14:25:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2024-03-21 15:10:35 -04:00
|
|
|
return html` <link rel="stylesheet" href="/static/tildefriends-v1.css" />
|
2024-03-21 14:25:07 -04:00
|
|
|
<style>
|
|
|
|
.id-span {
|
|
|
|
font-family: monospace;
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<h4>Create a new identity</h4>
|
2024-03-21 15:10:35 -04:00
|
|
|
<button id="create-id" class="green" @click=${this.createIdentity}>
|
|
|
|
Create Identity
|
|
|
|
</button>
|
2024-03-21 14:25:07 -04:00
|
|
|
|
|
|
|
<h4>Import an SSB Identity from 12 BIP39 English Words</h4>
|
2024-03-21 15:10:35 -04:00
|
|
|
<textarea id="import-id-textarea" style="width: 100%" rows="4"></textarea>
|
|
|
|
<button class="green" @click=${this.importIdentity}>
|
|
|
|
Import Identity
|
|
|
|
</button>
|
2024-03-21 14:25:07 -04:00
|
|
|
|
|
|
|
<h4>Warning !</h4>
|
2024-03-21 15:10:35 -04:00
|
|
|
<strong
|
|
|
|
>Anybody that knows your private key can gain total access over your
|
|
|
|
account.</strong
|
|
|
|
>
|
|
|
|
<br /><br />
|
2024-03-21 14:25:07 -04:00
|
|
|
Tilde Friends' contributors will never ask you for your private key !
|
|
|
|
|
|
|
|
<ul>
|
2024-03-21 15:10:35 -04:00
|
|
|
${this.ids.map(
|
|
|
|
(id) =>
|
|
|
|
html` <li>
|
|
|
|
<button class="blue" @click=${() => this.exportIdentity(id)}>
|
|
|
|
Export Identity
|
|
|
|
</button>
|
|
|
|
<button class="red" @click=${() => this.deleteIdentity(id)}>
|
|
|
|
Delete Identity
|
|
|
|
</button>
|
|
|
|
<span class="id-span">${id}</span>
|
|
|
|
</li>`
|
|
|
|
)}
|
2024-03-21 14:25:07 -04:00
|
|
|
</ul>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 15:10:35 -04:00
|
|
|
customElements.define('tf-identity-manager', TfIdentityManagerElement);
|