damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

commit 897d837bf2e50cba4aaf4a48aa54da4ebc6f3d27
parent d63c15c8e8374da889762050ee22ab3d8499c167
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 12 Nov 2022 10:37:19 -0800

web: allow pubkey override via ?pk=....

Diffstat:
Mweb/damus.js | 24+++++++++++++++++++-----
Mweb/index.html | 2+-
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/web/damus.js b/web/damus.js @@ -1215,9 +1215,27 @@ function set_local_state(key, val) { localStorage.setItem(key, val) } +function get_qs(loc=location.href) { + return new URL(loc).searchParams +} + +function handle_pubkey(pubkey) { + if (pubkey[0] === "n") + pubkey = bech32_decode(pubkey) + + set_local_state('pubkey', pubkey) + + return pubkey +} + async function get_pubkey() { let pubkey = get_local_state('pubkey') + // qs pk overrides stored key + const qs_pk = get_qs().get("pk") + if (qs_pk) + return handle_pubkey(qs_pk) + if (pubkey) return pubkey @@ -1232,11 +1250,7 @@ async function get_pubkey() { if (!pubkey) throw new Error("Need pubkey to continue") - if (pubkey[0] === "n") - pubkey = bech32_decode(pubkey) - - set_local_state('pubkey', pubkey) - return pubkey + return handle_pubkey(pubkey) } function get_privkey() { diff --git a/web/index.html b/web/index.html @@ -66,7 +66,7 @@ <script src="noble-secp256k1.js?v=1"></script> <script src="bech32.js?v=1"></script> <script src="nostr.js?v=6"></script> - <script src="damus.js?v=67"></script> + <script src="damus.js?v=68"></script> <script> // I have to delay loading to wait for nos2x const relay = setTimeout(damus_web_init, 100)