Looks like I can round-trip an SSB identity, now.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4733 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-04 01:17:30 +00:00
parent 8ab53f2da3
commit d89a7a5556
6 changed files with 104 additions and 17 deletions

View File

@ -1,5 +1,5 @@
{
"type": "tildefriends-app",
"emoji": "🪪",
"previous": "&XHcSLE9zb9QH0hFGAza/5wuIv8jj2NKARlOvMBpMAzc=.sha256"
"previous": "&1RskhkBW1UheJRrw7xcTjS8ELDMnBXNAuKqW5BiT72c=.sha256"
}

View File

@ -3,33 +3,35 @@ 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 words = 'body hair useful camp warm into cause riot two bamboo kick educate dinosaur advice seed type crisp where guilt avocado output rely lunch goddess';
let bytes = base64Decode('GO0Lv5BvcuuJJdHrokHoo0PmCDC/XjO/SZ6H+ddq4UvWd/VPW1RJrjd1aCUIfPIojFXrWMb8R54vVerU2TwjdQ==').slice(0, 32);
let data = {
ids: ids,
words: bip39Words(bytes),
bytes: base64Encode(bip39Bytes(words)),
round: bip39Words((await bip39Bytes(words)).slice(0, 32)),
privates: (await Promise.all(ids.map(id => ssb.getPrivateKey(id)))).map(x => bip39Words(x)),
};*/
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;
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')) {
button.onclick = export_id;
if (button.id == "add") {
button.onclick = add_id;
} else {
button.onclick = export_id;
}
}
});
</script>`+
</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>`);
}