aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriancoleman <1281387+iancoleman@users.noreply.github.com>2020-05-11 09:06:02 +1000
committerGitHub <noreply@github.com>2020-05-11 09:06:02 +1000
commitf3051a6a9f72c16b5b964d8cc7a23a3553d08dd2 (patch)
tree5cce946484a90d8ab7b4e9703be165391548bd68
parent5699633538863463319542926dc46cf3cbf9d1a3 (diff)
parentbf528f65f411daec8735d25ca30e01fc1dd33e6e (diff)
downloadBIP39-f3051a6a9f72c16b5b964d8cc7a23a3553d08dd2.tar.gz
BIP39-f3051a6a9f72c16b5b964d8cc7a23a3553d08dd2.tar.zst
BIP39-f3051a6a9f72c16b5b964d8cc7a23a3553d08dd2.zip
Merge pull request #409 from bguiz/feat/rsk-network
feat: rsk network
-rw-r--r--src/js/bitcoinjs-extensions.js25
-rw-r--r--src/js/index.js83
2 files changed, 104 insertions, 4 deletions
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js
index 2792e13..e67996c 100644
--- a/src/js/bitcoinjs-extensions.js
+++ b/src/js/bitcoinjs-extensions.js
@@ -1175,6 +1175,31 @@ libs.bitcoin.networks.revolutionvr = {
1175 wif: 0xc6, 1175 wif: 0xc6,
1176}; 1176};
1177 1177
1178libs.bitcoin.networks.rsk = {
1179 messagePrefix: '\x18RSK Signed Message:\n',
1180 bip32: {
1181 public: 0x0488b21e,
1182 private: 0x0488ade4
1183 },
1184 // TODO defaulting to Bitcoin value, check this
1185 pubKeyHash: 0x00,
1186 // TODO defaulting to Bitcoin value, check this
1187 scriptHash: 0x05,
1188 // TODO defaulting to Bitcoin value, check this
1189 wif: 0x80
1190};
1191
1192libs.bitcoin.networks.rsktestnet = {
1193 messagePrefix: '\x18RSK Testnet Signed Message:\n',
1194 bip32: {
1195 public: 0x043587cf,
1196 private: 0x04358394
1197 },
1198 pubKeyHash: 0x6f,
1199 scriptHash: 0xc4,
1200 wif: 0xef
1201};
1202
1178libs.bitcoin.networks.rubycoin = { 1203libs.bitcoin.networks.rubycoin = {
1179 messagePrefix: '\x18Rubycoin Signed Message:\n', 1204 messagePrefix: '\x18Rubycoin Signed Message:\n',
1180 bip32: { 1205 bip32: {
diff --git a/src/js/index.js b/src/js/index.js
index e8072e4..43c6955 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1140,11 +1140,40 @@
1140 } 1140 }
1141 } 1141 }
1142 1142
1143 // RSK values are different
1144 if (networkIsRsk()) {
1145 var pubkeyBuffer = keyPair.getPublicKeyBuffer();
1146 var ethPubkey = libs.ethUtil.importPublic(pubkeyBuffer);
1147 var addressBuffer = libs.ethUtil.publicToAddress(ethPubkey);
1148 var hexAddress = addressBuffer.toString('hex');
1149 // Use chainId based on selected network
1150 // Ref: https://developers.rsk.co/rsk/architecture/account-based/#chainid
1151 var chainId;
1152 var rskNetworkName = networks[DOM.network.val()].name;
1153 switch (rskNetworkName) {
1154 case "R-BTC - RSK":
1155 chainId = 30;
1156 break;
1157 case "tR-BTC - RSK Testnet":
1158 chainId = 31;
1159 break;
1160 default:
1161 chainId = null;
1162 }
1163 var checksumAddress = toChecksumAddressForRsk(hexAddress, chainId);
1164 address = libs.ethUtil.addHexPrefix(checksumAddress);
1165 pubkey = libs.ethUtil.addHexPrefix(pubkey);
1166 if (hasPrivkey) {
1167 privkey = libs.ethUtil.bufferToHex(keyPair.d.toBuffer());
1168 }
1169 }
1170
1143 // Handshake values are different 1171 // Handshake values are different
1144 if (networks[DOM.network.val()].name == "HNS - Handshake") { 1172 if (networks[DOM.network.val()].name == "HNS - Handshake") {
1145 var ring = libs.handshake.KeyRing.fromPublic(keyPair.getPublicKeyBuffer()) 1173 var ring = libs.handshake.KeyRing.fromPublic(keyPair.getPublicKeyBuffer())
1146 address = ring.getAddress().toString(); 1174 address = ring.getAddress().toString();
1147 } 1175 }
1176
1148 // Stellar is different 1177 // Stellar is different
1149 if (networks[DOM.network.val()].name == "XLM - Stellar") { 1178 if (networks[DOM.network.val()].name == "XLM - Stellar") {
1150 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); 1179 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -1860,6 +1889,12 @@
1860 || (name == "ERE - EtherCore") 1889 || (name == "ERE - EtherCore")
1861 } 1890 }
1862 1891
1892 function networkIsRsk() {
1893 var name = networks[DOM.network.val()].name;
1894 return (name == "R-BTC - RSK")
1895 || (name == "tR-BTC - RSK Testnet");
1896 }
1897
1863 function networkHasSegwit() { 1898 function networkHasSegwit() {
1864 var n = network; 1899 var n = network;
1865 if ("baseNetwork" in network) { 1900 if ("baseNetwork" in network) {
@@ -3004,16 +3039,16 @@
3004 }, 3039 },
3005 }, 3040 },
3006 { 3041 {
3007 name: "RBTC - RSK", 3042 name: "R-BTC - RSK",
3008 onSelect: function() { 3043 onSelect: function() {
3009 network = libs.bitcoin.networks.rubycoin; 3044 network = libs.bitcoin.networks.rsk;
3010 setHdCoin(137); 3045 setHdCoin(137);
3011 }, 3046 },
3012 }, 3047 },
3013 { 3048 {
3014 name: "tRBTC - RSK Testnet", 3049 name: "tR-BTC - RSK Testnet",
3015 onSelect: function() { 3050 onSelect: function() {
3016 network = libs.bitcoin.networks.rubycoin; 3051 network = libs.bitcoin.networks.rsktestnet;
3017 setHdCoin(37310); 3052 setHdCoin(37310);
3018 }, 3053 },
3019 }, 3054 },
@@ -3394,6 +3429,46 @@
3394 } 3429 }
3395 ] 3430 ]
3396 3431
3432 // RSK - RSK functions - begin
3433 function stripHexPrefix(address) {
3434 if (typeof address !== "string") {
3435 throw new Error("address parameter should be a string.");
3436 }
3437
3438 var hasPrefix = (address.substring(0, 2) === "0x" ||
3439 address.substring(0, 2) === "0X");
3440
3441 return hasPrefix ? address.slice(2) : address;
3442 };
3443
3444 function toChecksumAddressForRsk(address, chainId = null) {
3445 if (typeof address !== "string") {
3446 throw new Error("address parameter should be a string.");
3447 }
3448
3449 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
3450 throw new Error("Given address is not a valid RSK address: " + address);
3451 }
3452
3453 var stripAddress = stripHexPrefix(address).toLowerCase();
3454 var prefix = chainId != null ? chainId.toString() + "0x" : "";
3455 var keccakHash = libs.ethUtil.keccak256(prefix + stripAddress)
3456 .toString("hex")
3457 .replace(/^0x/i, "");
3458 var checksumAddress = "0x";
3459
3460 for (var i = 0; i < stripAddress.length; i++) {
3461 checksumAddress +=
3462 parseInt(keccakHash[i], 16) >= 8 ?
3463 stripAddress[i].toUpperCase() :
3464 stripAddress[i];
3465 }
3466
3467 return checksumAddress;
3468 }
3469
3470 // RSK - RSK functions - end
3471
3397 // ELA - Elastos functions - begin 3472 // ELA - Elastos functions - begin
3398 function displayBip44InfoForELA() { 3473 function displayBip44InfoForELA() {
3399 if (!isELA()) { 3474 if (!isELA()) {