@ -1,10 +1,10 @@
import { relayPool , generatePrivateKey , getPublicKey , signEvent } from 'nostr-tools' ;
import { relayPool , generatePrivateKey , getPublicKey , signEvent } from 'nostr-tools' ;
import { zeroLeadingBitsCount } from './cryptoutils' ;
import { elem , parseTextContent } from './domutil.js' ;
import { elem , parseTextContent } from './domutil.js' ;
import { dateTime , formatTime } from './timeutil.js' ;
import { dateTime , formatTime } from './timeutil.js' ;
// curl -H 'accept: application/nostr+json' https://relay.nostr.ch/
// curl -H 'accept: application/nostr+json' https://relay.nostr.ch/
const pool = relayPool ( ) ;
const pool = relayPool ( ) ;
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://nostr.openchain.fr' , { read : true , write : true } ) ;
// pool.addRelay('wss://relay.damus.io', {read: true, write: true});
// pool.addRelay('wss://relay.damus.io', {read: true, write: true});
@ -967,16 +967,18 @@ profileForm.addEventListener('submit', async (e) => {
}
}
} ) ;
} ) ;
/ * *
* check that the event has the id has the desired number of leading zero bits
* @ param { EventObj } evt to validate
* @ returns boolean
* /
function validatePow ( evt ) {
function validatePow ( evt ) {
const tag = evt . tags . find ( tag => tag [ 0 ] === 'nonce' ) ;
const tag = evt . tags . find ( tag => tag [ 0 ] === 'nonce' ) ;
if ( ! tag ) {
if ( ! tag ) {
return false ;
return false ;
}
}
const [ , , difficulty2 ] = tag ;
const [ , , difficultyCommitment ] = tag ;
if ( difficulty2 < 16 ) {
return zeroLeadingBitsCount ( evt . id ) === difficultyCommitment ;
return false ;
}
return evt . id . substring ( 0 , difficulty2 / 4 ) === '00' . repeat ( difficulty2 / 8 ) ;
}
}
/ * *
/ * *
@ -988,10 +990,7 @@ function validatePow(evt) {
* a zero timeout makes mineEvent run without a time limit .
* a zero timeout makes mineEvent run without a time limit .
* /
* /
function powEvent ( evt , difficulty , timeout ) {
function powEvent ( evt , difficulty , timeout ) {
const privatekey = localStorage . getItem ( 'private_key' ) ;
return new Promise ( ( resolve , reject ) => {
return new Promise ( ( resolve , reject ) => {
// const webWorkerURL = URL.createObjectURL(new Blob(['(', powEventWorker(), ')()'], {type: 'application/javascript'}));
// const worker = new Worker(webWorkerURL);
const worker = new Worker ( './worker.js' ) ;
const worker = new Worker ( './worker.js' ) ;
worker . onmessage = ( msg ) => {
worker . onmessage = ( msg ) => {
@ -1008,7 +1007,6 @@ function powEvent(evt, difficulty, timeout) {
reject ( err ) ;
reject ( err ) ;
} ;
} ;
worker . postMessage ( { event : evt , difficulty , privatekey , timeout } ) ;
worker . postMessage ( { event : evt , difficulty , timeout } ) ;
// URL.revokeObjectURL(webWorkerURL); // one-time worker; no longer need the URL obj
} ) ;
} ) ;
}
}