Update nostr gem, switch to Ruby for bech32 encoding
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { bech32 } from "bech32"
|
||||
|
||||
function hexToBytes (hex) {
|
||||
let bytes = []
|
||||
@@ -15,10 +14,6 @@ export default class extends Controller {
|
||||
static values = { userAddress: String, pubkeyHex: String, sharedSecret: String }
|
||||
|
||||
connect () {
|
||||
if (this.hasPubkeyHexValue && this.pubkeyHexValue.length > 0) {
|
||||
this.pubkeyBech32InputTarget.value = this.pubkeyBech32
|
||||
}
|
||||
|
||||
if (window.nostr) {
|
||||
if (this.hasSetPubkeyTarget) {
|
||||
this.setPubkeyTarget.disabled = false
|
||||
@@ -53,11 +48,6 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
get pubkeyBech32 () {
|
||||
const words = bech32.toWords(hexToBytes(this.pubkeyHexValue))
|
||||
return bech32.encode('npub', words)
|
||||
}
|
||||
|
||||
get csrfToken () {
|
||||
const element = document.head.querySelector('meta[name="csrf-token"]')
|
||||
return element.getAttribute("content")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'nostr'
|
||||
|
||||
class User < ApplicationRecord
|
||||
include EmailValidatable
|
||||
|
||||
@@ -185,6 +187,11 @@ class User < ApplicationRecord
|
||||
ldap.delete_attribute(dn,:service)
|
||||
end
|
||||
|
||||
def nostr_pubkey_bech32
|
||||
return nil unless nostr_pubkey.present?
|
||||
Nostr::PublicKey.new(nostr_pubkey).to_bech32
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ldap
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
data-settings--nostr-pubkey-pubkey-hex-value="<%= current_user.nostr_pubkey %>">
|
||||
|
||||
<p class="<%= current_user.nostr_pubkey.present? ? '' : 'hidden' %> mt-2 flex gap-1">
|
||||
<input type="text" value="<%= current_user.nostr_pubkey %>" disabled
|
||||
<input type="text" value="<%= current_user.nostr_pubkey_bech32 %>" disabled
|
||||
data-settings--nostr-pubkey-target="pubkeyBech32Input"
|
||||
name="nostr_public_key" class="relative grow" />
|
||||
<%= link_to nostr_pubkey_settings_path,
|
||||
|
||||
Reference in New Issue
Block a user