web: nip05 profile loading
This commit is contained in:
parent
9230a11a72
commit
72346522eb
2 changed files with 33 additions and 10 deletions
|
@ -12,7 +12,7 @@
|
||||||
<script defer src="js/noble-secp256k1.js?v=1"></script>
|
<script defer src="js/noble-secp256k1.js?v=1"></script>
|
||||||
<script defer src="js/bech32.js?v=1"></script>
|
<script defer src="js/bech32.js?v=1"></script>
|
||||||
<script defer src="js/nostr.js?v=6"></script>
|
<script defer src="js/nostr.js?v=6"></script>
|
||||||
<script defer src="js/damus.js?v=89"></script>
|
<script defer src="js/damus.js?v=90"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -640,6 +640,10 @@ function load_our_relays(our_pubkey, pool, ev) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function log_error(fmt, ...args) {
|
||||||
|
console.log("[ERROR] " + fmt, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
function log_debug(fmt, ...args) {
|
function log_debug(fmt, ...args) {
|
||||||
console.log("[debug] " + fmt, ...args)
|
console.log("[debug] " + fmt, ...args)
|
||||||
}
|
}
|
||||||
|
@ -1212,10 +1216,29 @@ function get_qs(loc=location.href) {
|
||||||
return new URL(loc).searchParams
|
return new URL(loc).searchParams
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_pubkey(pubkey) {
|
async function get_nip05_pubkey(email) {
|
||||||
|
const [user, host] = email.split("@")
|
||||||
|
const url = `https://${host}/.well-known/nostr.json?name=${user}`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(url)
|
||||||
|
const json = await res.json()
|
||||||
|
|
||||||
|
log_debug("nip05 data", json)
|
||||||
|
return json.names[user]
|
||||||
|
} catch (e) {
|
||||||
|
log_error("fetching nip05 entry for %s", email, e)
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handle_pubkey(pubkey) {
|
||||||
if (pubkey[0] === "n")
|
if (pubkey[0] === "n")
|
||||||
pubkey = bech32_decode(pubkey)
|
pubkey = bech32_decode(pubkey)
|
||||||
|
|
||||||
|
if (pubkey.includes("@"))
|
||||||
|
pubkey = await get_nip05_pubkey(pubkey)
|
||||||
|
|
||||||
set_local_state('pubkey', pubkey)
|
set_local_state('pubkey', pubkey)
|
||||||
|
|
||||||
return pubkey
|
return pubkey
|
||||||
|
@ -1227,7 +1250,7 @@ async function get_pubkey() {
|
||||||
// qs pk overrides stored key
|
// qs pk overrides stored key
|
||||||
const qs_pk = get_qs().get("pk")
|
const qs_pk = get_qs().get("pk")
|
||||||
if (qs_pk)
|
if (qs_pk)
|
||||||
return handle_pubkey(qs_pk)
|
return await handle_pubkey(qs_pk)
|
||||||
|
|
||||||
if (pubkey)
|
if (pubkey)
|
||||||
return pubkey
|
return pubkey
|
||||||
|
@ -1237,15 +1260,15 @@ async function get_pubkey() {
|
||||||
console.log("calling window.nostr.getPublicKey()...")
|
console.log("calling window.nostr.getPublicKey()...")
|
||||||
const pubkey = await window.nostr.getPublicKey()
|
const pubkey = await window.nostr.getPublicKey()
|
||||||
console.log("got %s pubkey from nos2x", pubkey)
|
console.log("got %s pubkey from nos2x", pubkey)
|
||||||
return handle_pubkey(pubkey)
|
return await handle_pubkey(pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
pubkey = prompt("Enter pubkey (hex or npub)")
|
pubkey = prompt("Enter nostr id (eg: jb55@jb55.com) or pubkey (hex or npub)")
|
||||||
|
|
||||||
if (!pubkey)
|
if (!pubkey)
|
||||||
throw new Error("Need pubkey to continue")
|
throw new Error("Need pubkey to continue")
|
||||||
|
|
||||||
return handle_pubkey(pubkey)
|
return await handle_pubkey(pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_privkey() {
|
function get_privkey() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue