42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
|
import { assert } from "https://deno.land/std@0.224.0/assert/mod.ts";
|
||
|
|
||
|
import {
|
||
|
NSchema,
|
||
|
NSecSigner,
|
||
|
NRelay1
|
||
|
} from '@nostrify/nostrify';
|
||
|
|
||
|
import * as nip19 from 'nostr-tools/nip19'
|
||
|
|
||
|
console.log("\nUse at your own risk!\n");
|
||
|
console.log("Considering trying it out with a throwaway nsec.");
|
||
|
console.log("All data will be public. Anything you upload is hard to delete.\n");
|
||
|
|
||
|
const nsec_str = prompt("Please enter your nsec:");
|
||
|
|
||
|
// Sanity check format
|
||
|
NSchema.bech32('nsec').parse(nsec_str);
|
||
|
|
||
|
// Actually parse nsec
|
||
|
const { type, data } = nip19.decode(nsec_str);
|
||
|
assert(type === 'nsec');
|
||
|
|
||
|
const signer = new NSecSigner(data);
|
||
|
const pubkey_hex = await signer.getPublicKey();
|
||
|
const npub = nip19.npubEncode(pubkey_hex);
|
||
|
console.log("\nYour npub: ", npub);
|
||
|
console.log("In hex format: ", pubkey_hex);
|
||
|
|
||
|
// TODO: get relays from profile and/or allow multiple
|
||
|
const relay_str = prompt("Pick a relay:");
|
||
|
const relay = new NRelay1(relay_str);
|
||
|
|
||
|
console.log("\nAs a sanity check, here's your last message (if any):");
|
||
|
|
||
|
for await (const msg of relay.req([{ kinds: [1], limit: 1, authors: [pubkey_hex] }])) {
|
||
|
if (msg[0] === 'EVENT') console.log(msg[2].content);
|
||
|
if (msg[0] === 'EOSE') break;
|
||
|
}
|
||
|
|
||
|
await relay.close()
|