From: Chris Duncan Date: Wed, 4 Dec 2024 14:30:04 +0000 (-0800) Subject: Fix call to wrong function for getting a signature rather than the signed message... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=9ce3047ece04c044432e4491a0d3d9476b1e32cb;p=libnemo.git Fix call to wrong function for getting a signature rather than the signed message itself. --- 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)) } /**