]> git.codecow.com Git - libnemo.git/commitdiff
Use public key for open block pow per spec.
authorChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 01:05:04 +0000 (18:05 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 01:05:04 +0000 (18:05 -0700)
src/lib/block.ts

index 6bc6315497f4e2328872da329efd0b3a92a7e33c..4199f2911671fa3de906d5c7450cd35041742d7f 100644 (file)
@@ -229,8 +229,9 @@ export class Block {
                const difficulty: bigint = (this.subtype === 'send' || this.subtype === 'change')
                        ? DIFFICULTY_SEND
                        : DIFFICULTY_RECEIVE
+               const hash = +this.previous === 0 ? this.account.publicKey : this.previous
                if (work == null) {
-                       const result = await NanoPow.work_generate(this.previous, { difficulty })
+                       const result = await NanoPow.work_generate(hash, { difficulty })
                        if ('error' in result) {
                                throw new Error('Failed to generate work', { cause: result.error })
                        }
@@ -239,7 +240,7 @@ export class Block {
                if (typeof work !== 'string') {
                        throw new TypeError('Invalid work')
                }
-               const check = await NanoPow.work_validate(work, this.previous, { difficulty })
+               const check = await NanoPow.work_validate(work, hash, { difficulty })
                if ('error' in check) {
                        throw new Error('Failed to validate work generated', { cause: check.error })
                }