@ -1,10 +1,10 @@
import { relayPool , generatePrivateKey , getPublicKey , signEvent } from 'nostr-tools' ;
import { zeroLeadingBitsCount } from './cryptoutils' ;
import { elem , parseTextContent } from './domutil.js' ;
import { dateTime , formatTime } from './timeutil.js' ;
// curl -H 'accept: application/nostr+json' https://relay.nostr.ch/
const pool = relayPool ( ) ;
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});
@ -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 ) {
const tag = evt . tags . find ( tag => tag [ 0 ] === 'nonce' ) ;
if ( ! tag ) {
return false ;
}
const [ , , difficulty2 ] = tag ;
if ( difficulty2 < 16 ) {
return false ;
}
return evt . id . substring ( 0 , difficulty2 / 4 ) === '00' . repeat ( difficulty2 / 8 ) ;
const [ , , difficultyCommitment ] = tag ;
return zeroLeadingBitsCount ( evt . id ) === difficultyCommitment ;
}
/ * *
@ -988,10 +990,7 @@ function validatePow(evt) {
* a zero timeout makes mineEvent run without a time limit .
* /
function powEvent ( evt , difficulty , timeout ) {
const privatekey = localStorage . getItem ( 'private_key' ) ;
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' ) ;
worker . onmessage = ( msg ) => {
@ -1008,7 +1007,6 @@ function powEvent(evt, difficulty, timeout) {
reject ( err ) ;
} ;
worker . postMessage ( { event : evt , difficulty , privatekey , timeout } ) ;
// URL.revokeObjectURL(webWorkerURL); // one-time worker; no longer need the URL obj
worker . postMessage ( { event : evt , difficulty , timeout } ) ;
} ) ;
}