@@ -5,7 +5,7 @@ import { IdentityContext } from "../providers/IdentityProvider"
55import { MinerMessage , WORKER_COUNT , BATCH_SIZE , serializeEvent , getNonceBounds , calculateHashrate , convertNumberToUint8Array , MinerCommand } from "../libraries/Miner"
66import { encoder , decoder , uint8ToHex } from "../libraries/Hash"
77import Worker from '../workers/ConstructMiner.worker?worker'
8- import { UnsignedEvent , getEventHash , validateEvent , verifySignature } from "nostr-tools"
8+ import { Event , UnsignedEvent , getEventHash , validateEvent , verifySignature } from "nostr-tools"
99import { signEvent } from "../libraries/NIP-07"
1010import { UnpublishedConstructType } from "../types/Construct"
1111import { UnpublishedConstruct } from "./Construct"
@@ -25,7 +25,15 @@ type MinerProps = {
2525 targetWork : number
2626}
2727
28- const constructsReducer = ( state , action ) => {
28+ type ConstructsReducerState = {
29+ [ key : string ] : UnpublishedConstructType
30+ }
31+ type ConstructsReducerAction = {
32+ type : 'add' ,
33+ construct : UnpublishedConstructType
34+ }
35+
36+ const constructsReducer = ( state : ConstructsReducerState , action : ConstructsReducerAction ) => {
2937 switch ( action . type ) {
3038 case 'add' :
3139 return {
@@ -63,7 +71,7 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
6371 useEffect ( ( ) => {
6472 const storedConstructs = localStorage . getItem ( 'constructs' )
6573 if ( storedConstructs ) {
66- const parsedConstructs = JSON . parse ( storedConstructs )
74+ const parsedConstructs = JSON . parse ( storedConstructs ) as { [ key : string ] : UnpublishedConstructType }
6775 Object . keys ( parsedConstructs ) . forEach ( key => {
6876 constructsDispatch ( { type : 'add' , construct : parsedConstructs [ key ] } )
6977 } )
@@ -120,12 +128,14 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
120128 work,
121129 } = msg . data
122130
131+ const eventWithID = event as Event < 37515 >
132+
123133 const decoded = JSON . parse ( decoder . decode ( binaryEvent ) )
124- event . tags [ 0 ] [ 1 ] = decoded [ 4 ] [ 0 ] [ 1 ]
134+ eventWithID . tags [ 0 ] [ 1 ] = decoded [ 4 ] [ 0 ] [ 1 ]
125135 const id = bytesToHex ( hash )
126- event . id = id
127- console . log ( work , event )
128- if ( ! validateEvent ( event ) ) {
136+ eventWithID . id = id
137+ console . log ( work , eventWithID )
138+ if ( ! validateEvent ( eventWithID ) ) {
129139 // console.log()
130140 throw new Error ( 'invalid event' )
131141 }
@@ -138,7 +148,7 @@ export const Miner = ({targetHex, targetWork}: MinerProps) => {
138148 // all good
139149
140150 const construct : UnpublishedConstructType = {
141- readyForSignature : event ,
151+ readyForSignature : eventWithID ,
142152 workCompleted : work ,
143153 createdAt,
144154 id,
0 commit comments