Refactor Nostr settings/connect
* Use NIP-42 auth event instead of short text note * Verify event ID and signature using the nostr gem instead of custom code
This commit is contained in:
@@ -3,7 +3,12 @@ import { Controller } from "@hotwired/stimulus"
|
||||
// Connects to data-controller="settings--nostr-pubkey"
|
||||
export default class extends Controller {
|
||||
static targets = [ "noExtension", "setPubkey", "pubkeyBech32Input" ]
|
||||
static values = { userAddress: String, pubkeyHex: String, sharedSecret: String }
|
||||
static values = {
|
||||
userAddress: String,
|
||||
pubkeyHex: String,
|
||||
site: String,
|
||||
sharedSecret: String
|
||||
}
|
||||
|
||||
connect () {
|
||||
if (window.nostr) {
|
||||
@@ -19,11 +24,15 @@ export default class extends Controller {
|
||||
this.setPubkeyTarget.disabled = true
|
||||
|
||||
try {
|
||||
// Auth based on NIP-42
|
||||
const signedEvent = await window.nostr.signEvent({
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
kind: 1,
|
||||
tags: [],
|
||||
content: `Connect my public key to ${this.userAddressValue} (confirmation ${this.sharedSecretValue})`
|
||||
kind: 22242,
|
||||
tags: [
|
||||
["site", this.siteValue],
|
||||
["challenge", this.sharedSecretValue]
|
||||
],
|
||||
content: ""
|
||||
})
|
||||
|
||||
const res = await fetch("/settings/set_nostr_pubkey", {
|
||||
|
||||
Reference in New Issue
Block a user