From 9ce3047ece04c044432e4491a0d3d9476b1e32cb Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 4 Dec 2024 06:30:04 -0800 Subject: [PATCH] Fix call to wrong function for getting a signature rather than the signed message itself. --- src/lib/block.ts | 6 +++--- src/lib/tools.ts | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/block.ts b/src/lib/block.ts index 36dda5a..ccb7cfd 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -4,7 +4,7 @@ import { BURN_ADDRESS, PREAMBLE, THRESHOLD_RECEIVE, THRESHOLD_SEND } from './constants.js' import { Account } from './account.js' import { Blake2b } from './blake2b.js' -import { bytes, dec, hex } from './convert.js' +import { dec, hex } from './convert.js' import { NanoNaCl } from './nano-nacl.js' import { Pool } from './pool.js' import { Rpc } from './rpc.js' @@ -141,11 +141,11 @@ abstract class Block { } const account = await Account.fromPrivateKey(key) try { - const signature = NanoNaCl.sign( + const signature = NanoNaCl.detached( hex.toBytes(await this.hash()), hex.toBytes(`${account.privateKey}${account.publicKey}`) ) - this.signature = bytes.toHex(signature.subarray(0, 64)) + this.signature = signature } catch (err) { throw new Error(`Failed to sign block with key ${key}: ${err}`) } diff --git a/src/lib/tools.ts b/src/lib/tools.ts index d9146b4..5db2619 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -4,7 +4,7 @@ import { Account } from './account.js' import { Blake2b } from './blake2b.js' import { UNITS } from './constants.js' -import { bytes, hex } from './convert.js' +import { hex } from './convert.js' import { Rpc } from './rpc.js' import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './wallet.js' import { SendBlock } from './block.js' @@ -82,10 +82,9 @@ export async function convert (amount: bigint | string, inputUnit: string, outpu export async function sign (key: string, ...input: string[]): Promise { const account = await Account.fromPrivateKey(key) const data = hash(input) - const signature = NanoNaCl.sign( + return NanoNaCl.detached( hex.toBytes(data), hex.toBytes(`${account.privateKey}${account.publicKey}`)) - return bytes.toHex(signature.subarray(0, 64)) } /** -- 2.34.1