@ -2,9 +2,12 @@ import {relayPool, generatePrivateKey, getPublicKey} from 'nostr-tools';
import { elem } from './domutil.js' ;
import { elem } from './domutil.js' ;
const pool = relayPool ( ) ;
const pool = relayPool ( ) ;
pool . addRelay ( 'wss://nostr.x1ddos.ch' , { read : true , write : true } ) ;
// pool.addRelay('wss://nostr.x1ddos.ch', {read: true, write: true});
pool . addRelay ( 'wss://nostr.bitcoiner.social/' , { read : true , write : true } ) ;
pool . addRelay ( 'wss://nostr.bitcoiner.social/' , { read : true , write : true } ) ;
pool . addRelay ( 'wss://relay.nostr.info' , { read : true , write : true } ) ;
pool . addRelay ( 'wss://relay.nostr.info' , { read : true , write : true } ) ;
pool . addRelay ( 'wss://nostr.openchain.fr' , { read : true , write : true } ) ;
pool . addRelay ( 'wss://relay.damus.io' , { read : true , write : true } ) ;
const feedlist = document . querySelector ( '#feedlist' ) ;
const feedlist = document . querySelector ( '#feedlist' ) ;
@ -14,8 +17,11 @@ const dateTime = new Intl.DateTimeFormat(navigator.language, {
} ) ;
} ) ;
const userList = [ ] ;
const userList = [ ] ;
let max = 0 ;
function onEvent ( evt , relay ) {
function onEvent ( evt , relay ) {
if ( max ++ >= 7 ) {
return subscription . unsub ( ) ;
}
switch ( evt . kind ) {
switch ( evt . kind ) {
case 0 :
case 0 :
try {
try {
@ -36,7 +42,7 @@ function onEvent(evt, relay) {
}
}
}
}
pool . sub ( {
const subscription = pool . sub ( {
cb : onEvent ,
cb : onEvent ,
filter : {
filter : {
authors : [
authors : [
@ -53,7 +59,7 @@ function renderTextNote(evt, relay) {
const body = elem ( 'div' , { className : 'mbox-body' , title : dateTime . format ( time ) } , [
const body = elem ( 'div' , { className : 'mbox-body' , title : dateTime . format ( time ) } , [
elem ( 'header' , { className : 'mbox-header' } , [
elem ( 'header' , { className : 'mbox-header' } , [
elem ( 'strong' , { } , userName ) ,
elem ( 'strong' , { } , userName ) ,
` on ${ host } :`
elem ( 'small' , { } , ` on ${ host } `) ,
] ) ,
] ) ,
evt . content // text
evt . content // text
] ) ;
] ) ;
@ -65,7 +71,7 @@ function renderRecommendServer(evt, relay) {
const body = elem ( 'div' , { className : 'mbox-body' , title : dateTime . format ( time ) } , [
const body = elem ( 'div' , { className : 'mbox-body' , title : dateTime . format ( time ) } , [
elem ( 'header' , { className : 'mbox-header' } , [
elem ( 'header' , { className : 'mbox-header' } , [
elem ( 'strong' , { } , userName ) ,
elem ( 'strong' , { } , userName ) ,
` on ${ host } `
elem ( 'small' , { } , ` on ${ host } ` ) ,
] ) ,
] ) ,
` recommends server: ${ evt . content } `
` recommends server: ${ evt . content } `
] ) ;
] ) ;
@ -116,32 +122,30 @@ function setMetadata(userList, relay, evt, content) {
const form = document . querySelector ( 'form[name="settings"]' ) ;
const form = document . querySelector ( 'form[name="settings"]' ) ;
const privateKeyInput = form . querySelector ( '#privatekey' ) ;
const privateKeyInput = form . querySelector ( '#privatekey' ) ;
const pubKeyInput = form . querySelector ( '#pubkey' ) ;
const pubKeyInput = form . querySelector ( '#pubkey' ) ;
const keyError = form . querySelector ( '#keyError ') ;
const statusMessage = form . querySelector ( '#keystatus ') ;
const generateBtn = form . querySelector ( 'button[name="generate"]' ) ;
const generateBtn = form . querySelector ( 'button[name="generate"]' ) ;
const importBtn = form . querySelector ( 'button[name="import"]' ) ;
const importBtn = form . querySelector ( 'button[name="import"]' ) ;
const privateTgl = form . querySelector ( 'button[name="privatekey-toggle"]' )
generateBtn . addEventListener ( 'click' , ( evt ) => {
generateBtn . addEventListener ( 'click' , ( ) => {
evt . preventDefault ( ) ;
const privateKey = generatePrivateKey ( ) ;
const privateKey = generatePrivateKey ( ) ;
const pubKey = getPublicKey ( privateKey ) ;
const pubKey = getPublicKey ( privateKey ) ;
if ( validKeys ( privateKey , pubKey ) ) {
if ( validKeys ( privateKey , pubKey ) ) {
localStorage . setItem ( 'privateKey' , privateKey ) ;
localStorage . setItem ( 'pubKey' , pubKey ) ;
privateKeyInput . value = privateKey ;
privateKeyInput . value = privateKey ;
pubKeyInput . value = pubKey ;
pubKeyInput . value = pubKey ;
statusMessage . textContent = 'private-key created!' ;
statusMessage . hidden = false ;
}
}
} ) ;
} ) ;
privateKeyInput . value = localStorage . getItem ( 'privateKey' ) ;
importBtn . addEventListener ( 'click' , ( ) => {
pubKeyInput . value = localStorage . getItem ( 'pubKey' ) ;
importBtn . addEventListener ( 'click' , ( evt ) => {
evt . preventDefault ( ) ;
const privateKey = privateKeyInput . value ;
const privateKey = privateKeyInput . value ;
const pubKey = pubKeyInput . value ;
const pubKey = pubKeyInput . value ;
if ( validKeys ( privateKey , pubKey ) ) {
if ( validKeys ( privateKey , pubKey ) ) {
localStorage . setItem ( 'privateKey' , privateKey ) ;
localStorage . setItem ( 'privateKey' , privateKey ) ;
localStorage . setItem ( 'pubKey' , pubKey ) ;
localStorage . setItem ( 'pubKey' , pubKey ) ;
statusMessage . textContent = 'private-key saved in local storage!' ;
statusMessage . hidden = false ;
}
}
} ) ;
} ) ;
@ -151,22 +155,25 @@ function validKeys(privateKey, pubKey) {
if ( pubKey && privateKey ) {
if ( pubKey && privateKey ) {
try {
try {
if ( getPublicKey ( privateKey ) === pubKey ) {
if ( getPublicKey ( privateKey ) === pubKey ) {
keyError . hidden = true ;
statusMessage . hidden = true ;
keyError . textContent = ' ';
statusMessage . textContent = ' public-key corresponds to private-key ';
importBtn . removeAttribute ( 'disabled' ) ;
importBtn . removeAttribute ( 'disabled' ) ;
return true ;
return true ;
} else {
} else {
keyError. textContent = 'private key does not correspond to public key!'
statusMessage. textContent = 'private-key does not correspond to public- key!'
}
}
} catch ( e ) {
} catch ( e ) {
keyError. textContent = ` not a valid private key: ${ e . message || e } ` ;
statusMessage. textContent = ` not a valid private- key: ${ e . message || e } ` ;
}
}
}
}
keyError . hidden = false ;
statusMessage . hidden = false ;
importBtn . setAttribute ( 'disabled' , true ) ;
importBtn . setAttribute ( 'disabled' , true ) ;
return false ;
return false ;
}
}
document . body . addEventListener ( ' keyup ', ( ) => {
privateTgl . addEventListener ( ' clic k', ( ) => {
console. log ( document . activeElemen )
privateKeyInput. type = privateKeyInput . type === 'text' ? 'password' : 'text' ;
} ) ;
} ) ;
privateKeyInput . value = localStorage . getItem ( 'privateKey' ) ;
pubKeyInput . value = localStorage . getItem ( 'pubKey' ) ;