User window seems to function properly. Can trust and untrust users.

This commit is contained in:
Robert C. Martin 2023-04-06 12:35:31 -05:00
parent c511a1566d
commit c9cf1dd360
2 changed files with 28 additions and 17 deletions

View File

@ -1,17 +1,17 @@
(ns more-speech.nostr.event-composers-spec (ns more-speech.nostr.event-composers-spec
(:require [speclj.core :refer :all] (:require [more-speech.bech32 :as bech32]
[more-speech.config :as config]
[more-speech.db.gateway :as gateway] [more-speech.db.gateway :as gateway]
[more-speech.db.in-memory :as in-memory] [more-speech.db.in-memory :as in-memory]
[more-speech.mem :refer :all]
[more-speech.nostr.elliptic-signature :refer :all]
[more-speech.nostr.event-composers :refer :all] [more-speech.nostr.event-composers :refer :all]
[more-speech.nostr.util :as util]
[more-speech.nostr.events :refer :all]
[more-speech.nostr.event-composers :refer :all] [more-speech.nostr.event-composers :refer :all]
[more-speech.nostr.event-handlers :refer :all] [more-speech.nostr.event-handlers :refer :all]
[more-speech.nostr.elliptic-signature :refer :all] [more-speech.nostr.events :refer :all]
[more-speech.nostr.util :as util]
[more-speech.nostr.util :refer :all] [more-speech.nostr.util :refer :all]
[more-speech.mem :refer :all] [speclj.core :refer :all])
[more-speech.config :as config]
[more-speech.bech32 :as bech32])
(:import (ecdhJava SECP256K1))) (:import (ecdhJava SECP256K1)))
(defn have-client-tag? [tags] (defn have-client-tag? [tags]
@ -26,18 +26,21 @@
(with db (in-memory/get-db)) (with db (in-memory/get-db))
(before-all (config/set-db! :in-memory)) (before-all (config/set-db! :in-memory))
(before (in-memory/clear-db @db)) (before (in-memory/clear-db @db))
(before (clear-mem))
(context "composing metadata (kind:0) messages" (context "composing metadata (kind:0) messages"
(it "composes using the keys data structure" (it "composes using the keys data structure"
(with-redefs [config/proof-of-work-default 0] (with-redefs [config/proof-of-work-default 0]
(let [private-key (num->bytes 64 314159) (let [private-key (num->bytes 64 314159)
public-key (get-pub-key private-key) public-key (get-pub-key private-key)
pubkey (bytes->num public-key)
keys {:private-key (bytes->hex-string private-key) keys {:private-key (bytes->hex-string private-key)
:public-key (bytes->hex-string public-key) :public-key (bytes->hex-string public-key)
:name "name" :name "name"
:about "about" :about "about"
:picture "picture"} :picture "picture"}
_ (reset! (get-mem) {:keys keys}) _ (set-mem :keys keys)
_ (set-mem :pubkey pubkey)
now (quot (System/currentTimeMillis) 1000) now (quot (System/currentTimeMillis) 1000)
event (compose-metadata-event) event (compose-metadata-event)
{:keys [pubkey created_at kind content id sig]} (second event) {:keys [pubkey created_at kind content id sig]} (second event)
@ -56,8 +59,10 @@
(with-redefs [config/proof-of-work-default 0] (with-redefs [config/proof-of-work-default 0]
(let [private-key (num->bytes 64 314159) (let [private-key (num->bytes 64 314159)
public-key (get-pub-key private-key) public-key (get-pub-key private-key)
_ (reset! (get-mem) {:keys {:private-key (bytes->hex-string private-key) pubkey (bytes->num public-key)
:public-key (bytes->hex-string public-key)}}) _ (set-mem :keys {:private-key (bytes->hex-string private-key)
:public-key (bytes->hex-string public-key)})
_ (set-mem :pubkey pubkey)
text "message text" text "message text"
subject "" subject ""
event (compose-text-event subject text) event (compose-text-event subject text)
@ -77,8 +82,10 @@
(with-redefs [config/proof-of-work-default 0] (with-redefs [config/proof-of-work-default 0]
(let [private-key (num->bytes 64 314159) (let [private-key (num->bytes 64 314159)
public-key (get-pub-key private-key) public-key (get-pub-key private-key)
_ (reset! (get-mem) {:keys {:private-key (bytes->hex-string private-key) pubkey (bytes->num public-key)
:public-key (bytes->hex-string public-key)}}) _ (set-mem :keys {:private-key (bytes->hex-string private-key)
:public-key (bytes->hex-string public-key)})
_ (set-mem :pubkey pubkey)
text "message text" text "message text"
subject "subject" subject "subject"
event (compose-text-event subject text) event (compose-text-event subject text)
@ -185,8 +192,10 @@
(with-redefs [config/proof-of-work-default 0] (with-redefs [config/proof-of-work-default 0]
(let [private-key (num->bytes 64 42) (let [private-key (num->bytes 64 42)
public-key (get-pub-key private-key) public-key (get-pub-key private-key)
_ (reset! (get-mem) {:keys {:private-key (bytes->hex-string private-key) pubkey (bytes->num public-key)
:public-key (bytes->hex-string public-key)}}) _ (set-mem :keys {:private-key (bytes->hex-string private-key)
:public-key (bytes->hex-string public-key)})
_ (set-mem :pubkey pubkey)
text "message/text" text "message/text"
event (compose-text-event "" text) event (compose-text-event "" text)
{:keys [pubkey created_at kind tags content id sig]} (second event) {:keys [pubkey created_at kind tags content id sig]} (second event)
@ -256,8 +265,10 @@
(with-redefs [config/proof-of-work-default 0] (with-redefs [config/proof-of-work-default 0]
(let [private-key (num->bytes 64 42) (let [private-key (num->bytes 64 42)
public-key (get-pub-key private-key) public-key (get-pub-key private-key)
_ (reset! (get-mem) {:keys {:private-key (bytes->hex-string private-key) pubkey (bytes->num public-key)
:public-key (bytes->hex-string public-key)}}) _ (set-mem :keys {:private-key (bytes->hex-string private-key)
:public-key (bytes->hex-string public-key)})
_ (set-mem :pubkey pubkey)
contact-list [{:pubkey 1} contact-list [{:pubkey 1}
{:pubkey 2 :petname "petname"}] {:pubkey 2 :petname "petname"}]
event (compose-contact-list contact-list) event (compose-contact-list contact-list)

View File

@ -21,7 +21,7 @@
(let [private-key (util/hex-string->bytes (get-mem [:keys :private-key])) (let [private-key (util/hex-string->bytes (get-mem [:keys :private-key]))
pubkey (get-mem :pubkey) pubkey (get-mem :pubkey)
now (quot (System/currentTimeMillis) 1000) now (quot (System/currentTimeMillis) 1000)
body (assoc body :pubkey (util/bytes->hex-string pubkey) body (assoc body :pubkey (util/hexify pubkey)
:created_at now) :created_at now)
[id body] (events/make-id-with-pow config/proof-of-work-default body) [id body] (events/make-id-with-pow config/proof-of-work-default body)
aux-rand (util/num->bytes 32 (biginteger (System/currentTimeMillis))) aux-rand (util/num->bytes 32 (biginteger (System/currentTimeMillis)))