2024-01-03 19:21:15 -05:00
|
|
|
import * as tfrpc from '/tfrpc.js';
|
|
|
|
|
|
|
|
tfrpc.register(async function get_private_key(id) {
|
|
|
|
return bip39Words(await ssb.getPrivateKey(id));
|
|
|
|
});
|
2024-01-03 20:17:30 -05:00
|
|
|
tfrpc.register(async function add_id(id) {
|
|
|
|
return await ssb.addIdentity(bip39Bytes(id));
|
|
|
|
});
|
2024-01-03 19:21:15 -05:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
let ids = await ssb.getIdentities();
|
|
|
|
await app.setDocument(`<body style="color: #fff">
|
|
|
|
<script type="module">
|
|
|
|
import * as tfrpc from '/static/tfrpc.js';
|
|
|
|
async function export_id(event) {
|
2024-01-03 20:17:30 -05:00
|
|
|
let id = event.srcElement.innerHTML;
|
2024-01-06 13:40:57 -05:00
|
|
|
let element = document.createElement('textarea');
|
|
|
|
element.value = await tfrpc.rpc.get_private_key(id);
|
|
|
|
element.style = 'width: 100%; read-only: true';
|
|
|
|
element.readOnly = true;
|
|
|
|
document.body.insertBefore(element, event.srcElement.parentNode.nextSibling);
|
|
|
|
event.srcElement.onclick = event => hide_id(event, element);
|
2024-01-03 19:21:15 -05:00
|
|
|
}
|
2024-01-03 20:17:30 -05:00
|
|
|
async function add_id(event) {
|
|
|
|
let id = document.getElementById('add_id').value;
|
|
|
|
await tfrpc.rpc.add_id(id);
|
|
|
|
}
|
2024-01-06 13:40:57 -05:00
|
|
|
function hide_id(event, element) {
|
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
event.srcElement.onclick = export_id;
|
|
|
|
}
|
2024-01-03 19:21:15 -05:00
|
|
|
window.addEventListener('load', function() {
|
|
|
|
for (let button of document.getElementsByTagName('button')) {
|
2024-01-03 20:17:30 -05:00
|
|
|
if (button.id == "add") {
|
|
|
|
button.onclick = add_id;
|
|
|
|
} else {
|
|
|
|
button.onclick = export_id;
|
|
|
|
}
|
2024-01-03 19:21:15 -05:00
|
|
|
}
|
|
|
|
});
|
2024-01-03 20:17:30 -05:00
|
|
|
</script>
|
2024-01-06 13:40:57 -05:00
|
|
|
<h1>SSB Identity Management</h1>
|
|
|
|
<h2>Import an SSB Identity from 12 BIP39 English Words</h2>
|
|
|
|
<textarea id="add_id" style="width: 100%" rows="4"></textarea><button id="add">Add ID</button>
|
|
|
|
<h2>Export Identities</h2>`+
|
2024-01-03 19:21:15 -05:00
|
|
|
ids.map(id => `<div><button>${id}</button></div>`).join('\n')+
|
|
|
|
`</body>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|