forked from cory/tildefriends
Cory McWilliams
d89a7a5556
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4733 ed5197a5-7fde-0310-b194-c3ffbd925b24
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import * as tfrpc from '/tfrpc.js';
|
|
|
|
tfrpc.register(async function get_private_key(id) {
|
|
return bip39Words(await ssb.getPrivateKey(id));
|
|
});
|
|
tfrpc.register(async function add_id(id) {
|
|
return await ssb.addIdentity(bip39Bytes(id));
|
|
});
|
|
|
|
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) {
|
|
let id = event.srcElement.innerHTML;
|
|
document.body.insertBefore(document.createTextNode(await tfrpc.rpc.get_private_key(id)), event.srcElement.parentNode.nextSibling);
|
|
event.srcElement.disabled = true;
|
|
}
|
|
async function add_id(event) {
|
|
let id = document.getElementById('add_id').value;
|
|
await tfrpc.rpc.add_id(id);
|
|
}
|
|
window.addEventListener('load', function() {
|
|
for (let button of document.getElementsByTagName('button')) {
|
|
if (button.id == "add") {
|
|
button.onclick = add_id;
|
|
} else {
|
|
button.onclick = export_id;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
<input type="text" id="add_id"></input><button id="add">Add ID</button>`+
|
|
ids.map(id => `<div><button>${id}</button></div>`).join('\n')+
|
|
`</body>`);
|
|
}
|
|
|
|
main(); |