aboutsummaryrefslogtreecommitdiff
path: root/src/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/index.js')
-rw-r--r--src/js/index.js83
1 files changed, 79 insertions, 4 deletions
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()) {