package main import ( "smesh.lol/web/common/helpers" "smesh.lol/web/common/jsbridge/schnorr" "smesh.lol/web/common/nostr" ) // Identity: key management and signing. var ( seckey [32]byte hasKey bool myPubkey string ) func identitySetKey(hexKey string) { // Wipe prior backing before replacing. On JS, seckey = newValue swaps the // underlying array reference, leaving the old 32-byte backing abandoned // un-wiped. clear(seckey[:]) seckey = hexTo32(hexKey) hasKey = true pk, ok := schnorr.PubKeyFromSecKey(seckey[:]) if ok { myPubkey = helpers.HexEncode(pk) } } func identitySetPubkey(hex string) { myPubkey = hex } func identityClearKey() { clear(seckey[:]) seckey = [32]byte{} hasKey = false myPubkey = "" } func identitySignEvent(ev *nostr.Event) bool { if !hasKey { return false } aux := random32() return ev.Sign(seckey, aux) }