From 9f7afef8847d2fc0dd66c6bb5777cc0aef2fbf81 Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Sun, 15 Dec 2019 22:07:36 +0100
Subject: [PATCH] [fix] block local check: auto use new verify fn when dubp
 jump to v12

---
 app/lib/rules/local_rules.ts | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/app/lib/rules/local_rules.ts b/app/lib/rules/local_rules.ts
index 64eb5fe4d..eb71d674c 100644
--- a/app/lib/rules/local_rules.ts
+++ b/app/lib/rules/local_rules.ts
@@ -16,7 +16,7 @@ import {ConfDTO} from "../dto/ConfDTO"
 import {CindexEntry, IndexEntry, Indexer, MindexEntry, SindexEntry} from "../indexer"
 import {BaseDTO, TransactionDTO} from "../dto/TransactionDTO"
 import {DBBlock} from "../db/DBBlock"
-import {verifyBuggy} from "../common-libs/crypto/keyring"
+import {verify, verifyBuggy} from "../common-libs/crypto/keyring"
 import {hashf} from "../common"
 import {CommonConstants} from "../common-libs/constants"
 import {IdentityDTO} from "../dto/IdentityDTO"
@@ -87,8 +87,13 @@ export const LOCAL_RULES_FUNCTIONS = {
   },
 
   checkBlockSignature: async (block:BlockDTO) => {
-    if (!verifyBuggy(block.getSignedPart(), block.signature, block.issuer))
+    // Historically, Duniter used a buggy version of TweetNaCl (see #1390)
+    // Starting with the v12 blocks, Duniter uses a fixed version of TweetNaCl. 
+    if (block.version >= 12 && !verify(block.getSignedPart(), block.signature, block.issuer)) {
       throw Error('Block\'s signature must match');
+    } else if (!verifyBuggy(block.getSignedPart(), block.signature, block.issuer)) {
+      throw Error('Block\'s signature must match');
+    }
     return true;
   },
 
-- 
GitLab