| 
									
										
										
										
											2024-01-04 00:21:15 +00:00
										 |  |  | import * as tfrpc from '/tfrpc.js'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tfrpc.register(async function get_private_key(id) { | 
					
						
							|  |  |  | 	return bip39Words(await ssb.getPrivateKey(id)); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-01-04 01:17:30 +00:00
										 |  |  | tfrpc.register(async function add_id(id) { | 
					
						
							|  |  |  | 	return await ssb.addIdentity(bip39Bytes(id)); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-01-04 00:21:15 +00: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-04 01:17:30 +00:00
										 |  |  | 				let id = event.srcElement.innerHTML; | 
					
						
							| 
									
										
										
										
											2024-01-04 00:21:15 +00:00
										 |  |  | 				document.body.insertBefore(document.createTextNode(await tfrpc.rpc.get_private_key(id)), event.srcElement.parentNode.nextSibling); | 
					
						
							|  |  |  | 				event.srcElement.disabled = true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-01-04 01:17:30 +00:00
										 |  |  | 			async function add_id(event) { | 
					
						
							|  |  |  | 				let id = document.getElementById('add_id').value; | 
					
						
							|  |  |  | 				await tfrpc.rpc.add_id(id); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2024-01-04 00:21:15 +00:00
										 |  |  | 			window.addEventListener('load', function() { | 
					
						
							|  |  |  | 				for (let button of document.getElementsByTagName('button')) { | 
					
						
							| 
									
										
										
										
											2024-01-04 01:17:30 +00:00
										 |  |  | 					if (button.id == "add") { | 
					
						
							|  |  |  | 						button.onclick = add_id; | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						button.onclick = export_id; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2024-01-04 00:21:15 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2024-01-04 01:17:30 +00:00
										 |  |  | 		</script> | 
					
						
							|  |  |  | 		<input type="text" id="add_id"></input><button id="add">Add ID</button>`+ | 
					
						
							| 
									
										
										
										
											2024-01-04 00:21:15 +00:00
										 |  |  | 		ids.map(id => `<div><button>${id}</button></div>`).join('\n')+ | 
					
						
							|  |  |  | 	`</body>`); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | main(); |