From 10f8270b431b492a8cf2668451325688f43f565e Mon Sep 17 00:00:00 2001 From: Abhishek Sinha Date: Thu, 19 Dec 2019 22:08:07 +0530 Subject: [PATCH] corrected ECKey.isCompressedWalletImportFormat error for flo mainnet --- supernode/cash_payments_handler.html | 41 +++++++++++++++++----- supernode/index.html | 51 +++++++++++++++++++++------- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/supernode/cash_payments_handler.html b/supernode/cash_payments_handler.html index 8f05913..c3c06fb 100644 --- a/supernode/cash_payments_handler.html +++ b/supernode/cash_payments_handler.html @@ -8349,13 +8349,34 @@ // 52 characters base58 ECKey.isCompressedWalletImportFormat = function(key) { key = key.toString(); - return ECKey.privateKeyPrefix == 0x80 - ? /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( - key - ) - : /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( - key - ); + // return ECKey.privateKeyPrefix == 0x80 + // ? /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + // key + // ) + // : /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + // key + // ); + switch (ECKey.currentBlockchain) { + case "BTC": + return /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + key + ) + break; + case "BTC_TEST": + return /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + key + ); + break; + case "FLO": + return /^R[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key); + break; + case "FLO_TEST": + return /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key); + break; + + default: + break; + } }; // 44 characters @@ -12066,9 +12087,11 @@ ); // changesMadeByAbhishek: Change private key prefix before initing key Bitcoin.ECKey.privateKeyPrefix = privKeyPrefix; + Bitcoin.ECKey.currentBlockchain = crypto; var key = new Bitcoin.ECKey(privateKey); - key.setCompressed(true); + if(key.compressed!==true) key.setCompressed(true); + var privateKeyHex = key.getBitcoinHexFormat(); var privateKeyWIF = key.getBitcoinWalletImportFormat(); @@ -12087,7 +12110,7 @@ address }; }, - sign: function(msg, privateKeyHex) { + sign: function(msg, privateKeyHex, crypto = "FLO_TEST") { if (crypto == "BTC") { privKeyPrefix = 0x80; //mainnet 0x80, testnet: 0xEF networkVersion = 0x00; //mainnet 0x23, testnet: 0x6F diff --git a/supernode/index.html b/supernode/index.html index a3f9caa..d664dab 100644 --- a/supernode/index.html +++ b/supernode/index.html @@ -8450,6 +8450,9 @@ bytes = Crypto.util.hexToBytes(input); } else if (ECKey.isBase64Format(input)) { bytes = Crypto.util.base64ToBytes(input); + } else { + bytes = ECKey.decodeCompressedWalletImportFormat(input); + this.compressed = true; } } catch (exc1) { this.setError(exc1); @@ -8746,13 +8749,35 @@ // 52 characters base58 ECKey.isCompressedWalletImportFormat = function(key) { key = key.toString(); - return ECKey.privateKeyPrefix == 0x80 - ? /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( - key - ) - : /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( - key - ); + // return ECKey.privateKeyPrefix == 0x80 + // ? /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + // key + // ) + // : /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + // key + // ); + switch (ECKey.currentBlockchain) { + case "BTC": + return /^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + key + ) + break; + case "BTC_TEST": + return /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test( + key + ); + break; + case "FLO": + return /^R[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key); + break; + case "FLO_TEST": + return /^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key); + break; + + default: + break; + } + }; // 44 characters @@ -14579,9 +14604,11 @@ ); // changesMadeByAbhishek: Change private key prefix before initing key Bitcoin.ECKey.privateKeyPrefix = privKeyPrefix; + Bitcoin.ECKey.currentBlockchain = crypto; var key = new Bitcoin.ECKey(privateKey); - key.setCompressed(true); + if(key.compressed!==true) key.setCompressed(true); + var privateKeyHex = key.getBitcoinHexFormat(); var privateKeyWIF = key.getBitcoinWalletImportFormat(); @@ -14600,7 +14627,7 @@ address }; }, - sign: function(msg, privateKeyHex) { + sign: function(msg, privateKeyHex, crypto = "FLO_TEST") { if (crypto == "BTC") { privKeyPrefix = 0x80; //mainnet 0x80, testnet: 0xEF networkVersion = 0x00; //mainnet 0x23, testnet: 0x6F @@ -14614,14 +14641,14 @@ privKeyPrefix = 0xef; networkVersion = 0x73; } else { - privKeyPrefix = 0xef; - networkVersion = 0x73; + privKeyPrefix = 0xa3; + networkVersion = 0x23; } Bitcoin.ECKey.privateKeyPrefix = privKeyPrefix; var key = new Bitcoin.ECKey(privateKeyHex); - key.setCompressed(true); + if(key.compressed!==true) key.setCompressed(true); var privateKeyArr = key.getBitcoinPrivateKeyByteArray(privateKeyHex); privateKey = BigInteger.fromByteArrayUnsigned(privateKeyArr);