]> zoso.dev Git - libnemo.git/commitdiff
TweetNaCl expects 64-byte secret keys and signatures, and in Nano this is accomplishe...
authorChris Duncan <chris@zoso.dev>
Mon, 25 Nov 2024 20:50:59 +0000 (12:50 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 25 Nov 2024 20:50:59 +0000 (12:50 -0800)
src/lib/block.ts
src/lib/tools.ts

index a0d706f3802337b3ef01b6c916dd029c4378237b..164b787e33d4c01001c6b7b91c72635e4c88e5f0 100644 (file)
@@ -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}`)
+                       }
                }
        }
 
index 510eb11fd5dfa53547cb6f40c20b9505cd5cfb1b..bc76205526f86fe6d22584ff727877925c38711d 100644 (file)
@@ -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))
 }
 
 /**