corrected ECKey.isCompressedWalletImportFormat error for flo mainnet

This commit is contained in:
Abhishek Sinha 2019-12-19 22:08:07 +05:30
parent ddb3b2ae0f
commit 10f8270b43
2 changed files with 71 additions and 21 deletions

View File

@ -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

View File

@ -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);