From: Chris Duncan <chris@zoso.dev>
Date: Mon, 25 Nov 2024 20:50:59 +0000 (-0800)
Subject: TweetNaCl expects 64-byte secret keys and signatures, and in Nano this is accomplishe... 
X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=050be4cb4c294f65c52eaa4e045a8056889b008d;p=libnemo.git

TweetNaCl expects 64-byte secret keys and signatures, and in Nano this is accomplished by concatenating private key and public key, so update sign functions to align.
---

diff --git a/src/lib/block.ts b/src/lib/block.ts
index a0d706f..164b787 100644
--- a/src/lib/block.ts
+++ b/src/lib/block.ts
@@ -136,14 +136,19 @@ abstract class Block {
 			this.signature = result.signature
 		} else {
 			const key = input ?? this.account.privateKey
-			if (!key) {
+			if (key == null) {
 				throw new Error('No valid key found to sign block')
 			}
+			const account = await Account.fromPrivateKey(key)
+			try {
 			const signature = Ed25519.sign(
 					hex.toBytes(await this.hash()),
-				hex.toBytes(key)
+					hex.toBytes(`${account.privateKey}${account.publicKey}`)
 			)
-			this.signature = bytes.toHex(signature)
+				this.signature = bytes.toHex(signature.subarray(0, 64))
+			} 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 510eb11..bc76205 100644
--- a/src/lib/tools.ts
+++ b/src/lib/tools.ts
@@ -90,7 +90,7 @@ export async function sign (key: string, ...input: string[]): Promise<string> {
 	const signature = Ed25519.sign(
 		hex.toBytes(data),
 		hex.toBytes(key))
-	return bytes.toHex(signature)
+	return bytes.toHex(signature.subarray(0, 64))
 }
 
 /**