aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2017-08-02 17:02:43 +1000
committerIan Coleman <coleman.ian@gmail.com>2017-08-02 17:28:39 +1000
commit6c08f364b30e711feac698546041388325a11834 (patch)
tree0625dc7834d8ae290e6dd6bb735f5d820c7b5367 /src/js
parentfa2e4e936eea702d9e3ea56b256bbd886ca26bdf (diff)
downloadBIP39-6c08f364b30e711feac698546041388325a11834.tar.gz
BIP39-6c08f364b30e711feac698546041388325a11834.tar.zst
BIP39-6c08f364b30e711feac698546041388325a11834.zip
Add BIP49 tab
Diffstat (limited to 'src/js')
-rw-r--r--src/js/bitcoinjs-extensions.js4
-rw-r--r--src/js/index.js167
2 files changed, 145 insertions, 26 deletions
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js
index ac2123c..1b40135 100644
--- a/src/js/bitcoinjs-extensions.js
+++ b/src/js/bitcoinjs-extensions.js
@@ -31,7 +31,7 @@ bitcoinjs.bitcoin.networks.clam = {
31 wif: 0x85, 31 wif: 0x85,
32}; 32};
33 33
34bitcoin.networks.crown = { 34bitcoinjs.bitcoin.networks.crown = {
35 messagePrefix: "unused", 35 messagePrefix: "unused",
36 bip32: { 36 bip32: {
37 public: 0x0488b21e, 37 public: 0x0488b21e,
@@ -42,7 +42,7 @@ bitcoin.networks.crown = {
42 wif: 0x80, 42 wif: 0x80,
43}; 43};
44 44
45bitcoin.networks.dash = { 45bitcoinjs.bitcoin.networks.dash = {
46 messagePrefix: "unused", 46 messagePrefix: "unused",
47 bip32: { 47 bip32: {
48 public: 0x0488b21e, 48 public: 0x0488b21e,
diff --git a/src/js/index.js b/src/js/index.js
index 763967c..0129808 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -47,8 +47,10 @@
47 DOM.extendedPubKey = $(".extended-pub-key"); 47 DOM.extendedPubKey = $(".extended-pub-key");
48 DOM.bip32tab = $("#bip32-tab"); 48 DOM.bip32tab = $("#bip32-tab");
49 DOM.bip44tab = $("#bip44-tab"); 49 DOM.bip44tab = $("#bip44-tab");
50 DOM.bip49tab = $("#bip49-tab");
50 DOM.bip32panel = $("#bip32"); 51 DOM.bip32panel = $("#bip32");
51 DOM.bip44panel = $("#bip44"); 52 DOM.bip44panel = $("#bip44");
53 DOM.bip49panel = $("#bip49");
52 DOM.bip32path = $("#bip32-path"); 54 DOM.bip32path = $("#bip32-path");
53 DOM.bip44path = $("#bip44-path"); 55 DOM.bip44path = $("#bip44-path");
54 DOM.bip44purpose = $("#bip44 .purpose"); 56 DOM.bip44purpose = $("#bip44 .purpose");
@@ -57,6 +59,15 @@
57 DOM.bip44accountXprv = $("#bip44 .account-xprv"); 59 DOM.bip44accountXprv = $("#bip44 .account-xprv");
58 DOM.bip44accountXpub = $("#bip44 .account-xpub"); 60 DOM.bip44accountXpub = $("#bip44 .account-xpub");
59 DOM.bip44change = $("#bip44 .change"); 61 DOM.bip44change = $("#bip44 .change");
62 DOM.bip49unavailable = $("#bip49 .unavailable");
63 DOM.bip49available = $("#bip49 .available");
64 DOM.bip49path = $("#bip49-path");
65 DOM.bip49purpose = $("#bip49 .purpose");
66 DOM.bip49coin = $("#bip49 .coin");
67 DOM.bip49account = $("#bip49 .account");
68 DOM.bip49accountXprv = $("#bip49 .account-xprv");
69 DOM.bip49accountXpub = $("#bip49 .account-xpub");
70 DOM.bip49change = $("#bip49 .change");
60 DOM.generatedStrength = $(".generate-container .strength"); 71 DOM.generatedStrength = $(".generate-container .strength");
61 DOM.hardenedAddresses = $(".hardened-addresses"); 72 DOM.hardenedAddresses = $(".hardened-addresses");
62 DOM.addresses = $(".addresses"); 73 DOM.addresses = $(".addresses");
@@ -90,6 +101,8 @@
90 DOM.bip32path.on("input", calcForDerivationPath); 101 DOM.bip32path.on("input", calcForDerivationPath);
91 DOM.bip44account.on("input", calcForDerivationPath); 102 DOM.bip44account.on("input", calcForDerivationPath);
92 DOM.bip44change.on("input", calcForDerivationPath); 103 DOM.bip44change.on("input", calcForDerivationPath);
104 DOM.bip49account.on("input", calcForDerivationPath);
105 DOM.bip49change.on("input", calcForDerivationPath);
93 DOM.tab.on("shown.bs.tab", calcForDerivationPath); 106 DOM.tab.on("shown.bs.tab", calcForDerivationPath);
94 DOM.hardenedAddresses.on("change", calcForDerivationPath); 107 DOM.hardenedAddresses.on("change", calcForDerivationPath);
95 DOM.indexToggle.on("click", toggleIndexes); 108 DOM.indexToggle.on("click", toggleIndexes);
@@ -108,8 +121,17 @@
108 // Event handlers 121 // Event handlers
109 122
110 function networkChanged(e) { 123 function networkChanged(e) {
124 clearDerivedKeys();
125 clearAddressesList();
111 var networkIndex = e.target.value; 126 var networkIndex = e.target.value;
112 networks[networkIndex].onSelect(); 127 var network = networks[networkIndex];
128 network.onSelect();
129 if (network.bip49available) {
130 showBip49();
131 }
132 else {
133 hideBip49();
134 }
113 if (seed != null) { 135 if (seed != null) {
114 phraseChanged(); 136 phraseChanged();
115 } 137 }
@@ -252,8 +274,13 @@
252 274
253 function calcForDerivationPath() { 275 function calcForDerivationPath() {
254 showPending(); 276 showPending();
277 clearDerivedKeys();
255 clearAddressesList(); 278 clearAddressesList();
256 hideValidationError(); 279 hideValidationError();
280 // Don't show bip49 if it's selected but network doesn't support it
281 if (bip49TabSelected() && !networkHasBip49()) {
282 return;
283 }
257 // Get the derivation path 284 // Get the derivation path
258 var derivationPath = getDerivationPath(); 285 var derivationPath = getDerivationPath();
259 var errorText = findDerivationPathErrors(derivationPath); 286 var errorText = findDerivationPathErrors(derivationPath);
@@ -265,6 +292,9 @@
265 if (bip44TabSelected()) { 292 if (bip44TabSelected()) {
266 displayBip44Info(); 293 displayBip44Info();
267 } 294 }
295 if (bip49TabSelected()) {
296 displayBip49Info();
297 }
268 displayBip32Info(); 298 displayBip32Info();
269 hidePending(); 299 hidePending();
270 } 300 }
@@ -438,6 +468,21 @@
438 console.log("Using derivation path from BIP44 tab: " + derivationPath); 468 console.log("Using derivation path from BIP44 tab: " + derivationPath);
439 return derivationPath; 469 return derivationPath;
440 } 470 }
471 if (bip49TabSelected()) {
472 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
473 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
474 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
475 var change = parseIntNoNaN(DOM.bip49change.val(), 0);
476 var path = "m/";
477 path += purpose + "'/";
478 path += coin + "'/";
479 path += account + "'/";
480 path += change;
481 DOM.bip49path.val(path);
482 var derivationPath = DOM.bip49path.val();
483 console.log("Using derivation path from BIP49 tab: " + derivationPath);
484 return derivationPath;
485 }
441 else if (bip32TabSelected()) { 486 else if (bip32TabSelected()) {
442 var derivationPath = DOM.bip32path.val(); 487 var derivationPath = DOM.bip32path.val();
443 console.log("Using derivation path from BIP32 tab: " + derivationPath); 488 console.log("Using derivation path from BIP32 tab: " + derivationPath);
@@ -513,6 +558,24 @@
513 DOM.bip44accountXpub.val(accountXpub); 558 DOM.bip44accountXpub.val(accountXpub);
514 } 559 }
515 560
561 function displayBip49Info() {
562 // Get the derivation path for the account
563 var purpose = parseIntNoNaN(DOM.bip49purpose.val(), 49);
564 var coin = parseIntNoNaN(DOM.bip49coin.val(), 0);
565 var account = parseIntNoNaN(DOM.bip49account.val(), 0);
566 var path = "m/";
567 path += purpose + "'/";
568 path += coin + "'/";
569 path += account + "'/";
570 // Calculate the account extended keys
571 var accountExtendedKey = calcBip32ExtendedKey(path);
572 var accountXprv = accountExtendedKey.toBase58();
573 var accountXpub = accountExtendedKey.neutered().toBase58();
574 // Display the extended keys
575 DOM.bip49accountXprv.val(accountXprv);
576 DOM.bip49accountXpub.val(accountXpub);
577 }
578
516 function displayBip32Info() { 579 function displayBip32Info() {
517 // Display the key 580 // Display the key
518 DOM.seed.val(seed); 581 DOM.seed.val(seed);
@@ -555,6 +618,8 @@
555 var self = this; 618 var self = this;
556 this.shouldGenerate = true; 619 this.shouldGenerate = true;
557 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked"); 620 var useHardenedAddresses = DOM.hardenedAddresses.prop("checked");
621 var isBip49 = bip49TabSelected();
622 var bip49available = networkHasBip49();
558 623
559 function init() { 624 function init() {
560 calculateValues(); 625 calculateValues();
@@ -598,6 +663,17 @@
598 privkey = convertRipplePriv(privkey); 663 privkey = convertRipplePriv(privkey);
599 address = convertRippleAdrr(address); 664 address = convertRippleAdrr(address);
600 } 665 }
666 // BIP49 addresses are different
667 if (isBip49) {
668 if (!bip49available) {
669 return;
670 }
671 var keyhash = bitcoinjs.bitcoin.crypto.hash160(key.getPublicKeyBuffer());
672 var scriptsig = bitcoinjs.bitcoin.script.witnessPubKeyHash.output.encode(keyhash);
673 var addressbytes = bitcoinjs.bitcoin.crypto.hash160(scriptsig);
674 var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
675 address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
676 }
601 addAddressToList(indexText, address, pubkey, privkey); 677 addAddressToList(indexText, address, pubkey, privkey);
602 }, 50) 678 }, 50)
603 } 679 }
@@ -1063,145 +1139,188 @@
1063 return DOM.bip32tab.hasClass("active"); 1139 return DOM.bip32tab.hasClass("active");
1064 } 1140 }
1065 1141
1142 function networkHasBip49() {
1143 return networks[DOM.network.val()].bip49available;
1144 }
1145
1146 function bip49TabSelected() {
1147 return DOM.bip49tab.hasClass("active");
1148 }
1149
1150 function setHdCoin(coinValue) {
1151 DOM.bip44coin.val(coinValue);
1152 DOM.bip49coin.val(coinValue);
1153 }
1154
1155 function showBip49() {
1156 DOM.bip49unavailable.addClass("hidden");
1157 DOM.bip49available.removeClass("hidden");
1158 }
1159
1160 function hideBip49() {
1161 DOM.bip49available.addClass("hidden");
1162 DOM.bip49unavailable.removeClass("hidden");
1163 }
1164
1066 var networks = [ 1165 var networks = [
1067 { 1166 {
1068 name: "BTC - Bitcoin", 1167 name: "BTC - Bitcoin",
1168 bip49available: true,
1069 onSelect: function() { 1169 onSelect: function() {
1070 network = bitcoinjs.bitcoin.networks.bitcoin; 1170 network = bitcoinjs.bitcoin.networks.bitcoin;
1071 DOM.bip44coin.val(0); 1171 setHdCoin(0);
1072 }, 1172 },
1073 }, 1173 },
1074 { 1174 {
1075 name: "BTC - Bitcoin Testnet", 1175 name: "BTC - Bitcoin Testnet",
1176 bip49available: true,
1076 onSelect: function() { 1177 onSelect: function() {
1077 network = bitcoinjs.bitcoin.networks.testnet; 1178 network = bitcoinjs.bitcoin.networks.testnet;
1078 DOM.bip44coin.val(1); 1179 setHdCoin(1);
1079 }, 1180 },
1080 }, 1181 },
1081 { 1182 {
1082 name: "CLAM - Clams", 1183 name: "CLAM - Clams",
1184 bip49available: false,
1083 onSelect: function() { 1185 onSelect: function() {
1084 network = bitcoinjs.bitcoin.networks.clam; 1186 network = bitcoinjs.bitcoin.networks.clam;
1085 DOM.bip44coin.val(23); 1187 setHdCoin(23);
1086 }, 1188 },
1087 }, 1189 },
1088 { 1190 {
1089 name: "CRW - Crown", 1191 name: "CRW - Crown",
1192 bip49available: false,
1090 onSelect: function() { 1193 onSelect: function() {
1091 network = bitcoin.networks.crown; 1194 network = bitcoinjs.bitcoin.networks.crown;
1092 DOM.bip44coin.val(72); 1195 setHdCoin(72);
1093 }, 1196 },
1094 }, 1197 },
1095 { 1198 {
1096 name: "DASH - Dash", 1199 name: "DASH - Dash",
1200 bip49available: false,
1097 onSelect: function() { 1201 onSelect: function() {
1098 network = bitcoinjs.bitcoin.networks.dash; 1202 network = bitcoinjs.bitcoin.networks.dash;
1099 DOM.bip44coin.val(5); 1203 setHdCoin(5);
1100 }, 1204 },
1101 }, 1205 },
1102 { 1206 {
1103 name: "DASH - Dash Testnet", 1207 name: "DASH - Dash Testnet",
1208 bip49available: false,
1104 onSelect: function() { 1209 onSelect: function() {
1105 network = bitcoinjs.bitcoin.networks.dashtn; 1210 network = bitcoinjs.bitcoin.networks.dashtn;
1106 DOM.bip44coin.val(1); 1211 setHdCoin(1);
1107 }, 1212 },
1108 }, 1213 },
1109 { 1214 {
1110 name: "DOGE - Dogecoin", 1215 name: "DOGE - Dogecoin",
1216 bip49available: false,
1111 onSelect: function() { 1217 onSelect: function() {
1112 network = bitcoin.networks.dogecoin; 1218 network = bitcoinjs.bitcoin.networks.dogecoin;
1113 DOM.bip44coin.val(3); 1219 setHdCoin(3);
1114 }, 1220 },
1115 }, 1221 },
1116 { 1222 {
1117 name: "ETH - Ethereum", 1223 name: "ETH - Ethereum",
1224 bip49available: false,
1118 onSelect: function() { 1225 onSelect: function() {
1119 network = bitcoinjs.bitcoin.networks.bitcoin; 1226 network = bitcoinjs.bitcoin.networks.bitcoin;
1120 DOM.bip44coin.val(60); 1227 setHdCoin(60);
1121 }, 1228 },
1122 }, 1229 },
1123 { 1230 {
1124 name: "GAME - GameCredits", 1231 name: "GAME - GameCredits",
1232 bip49available: false,
1125 onSelect: function() { 1233 onSelect: function() {
1126 network = bitcoinjs.bitcoin.networks.game; 1234 network = bitcoinjs.bitcoin.networks.game;
1127 DOM.bip44coin.val(101); 1235 setHdCoin(101);
1128 }, 1236 },
1129 }, 1237 },
1130 { 1238 {
1131 name: "JBS - Jumbucks", 1239 name: "JBS - Jumbucks",
1240 bip49available: false,
1132 onSelect: function() { 1241 onSelect: function() {
1133 network = bitcoinjs.bitcoin.networks.jumbucks; 1242 network = bitcoinjs.bitcoin.networks.jumbucks;
1134 DOM.bip44coin.val(26); 1243 setHdCoin(26);
1135 }, 1244 },
1136 }, 1245 },
1137 { 1246 {
1138 name: "LTC - Litecoin", 1247 name: "LTC - Litecoin",
1248 bip49available: false,
1139 onSelect: function() { 1249 onSelect: function() {
1140 network = bitcoinjs.bitcoin.networks.litecoin; 1250 network = bitcoinjs.bitcoin.networks.litecoin;
1141 DOM.bip44coin.val(2); 1251 setHdCoin(2);
1142 }, 1252 },
1143 }, 1253 },
1144 { 1254 {
1145 name: "NMC - Namecoin", 1255 name: "NMC - Namecoin",
1256 bip49available: false,
1146 onSelect: function() { 1257 onSelect: function() {
1147 network = bitcoinjs.bitcoin.networks.namecoin; 1258 network = bitcoinjs.bitcoin.networks.namecoin;
1148 DOM.bip44coin.val(7); 1259 setHdCoin(7);
1149 }, 1260 },
1150 }, 1261 },
1151 { 1262 {
1152 name: "PPC - Peercoin", 1263 name: "PPC - Peercoin",
1264 bip49available: false,
1153 onSelect: function() { 1265 onSelect: function() {
1154 network = bitcoinjs.bitcoin.networks.peercoin; 1266 network = bitcoinjs.bitcoin.networks.peercoin;
1155 DOM.bip44coin.val(6); 1267 setHdCoin(6);
1156 }, 1268 },
1157 }, 1269 },
1158 { 1270 {
1159 name: "SDC - ShadowCash", 1271 name: "SDC - ShadowCash",
1272 bip49available: false,
1160 onSelect: function() { 1273 onSelect: function() {
1161 network = bitcoinjs.bitcoin.networks.shadow; 1274 network = bitcoinjs.bitcoin.networks.shadow;
1162 DOM.bip44coin.val(35); 1275 setHdCoin(35);
1163 }, 1276 },
1164 }, 1277 },
1165 { 1278 {
1166 name: "SDC - ShadowCash Testnet", 1279 name: "SDC - ShadowCash Testnet",
1280 bip49available: false,
1167 onSelect: function() { 1281 onSelect: function() {
1168 network = bitcoinjs.bitcoin.networks.shadowtn; 1282 network = bitcoinjs.bitcoin.networks.shadowtn;
1169 DOM.bip44coin.val(1); 1283 setHdCoin(1);
1170 }, 1284 },
1171 }, 1285 },
1172 { 1286 {
1173 name: "SLM - Slimcoin", 1287 name: "SLM - Slimcoin",
1288 bip49available: false,
1174 onSelect: function() { 1289 onSelect: function() {
1175 network = bitcoinjs.bitcoin.networks.slimcoin; 1290 network = bitcoinjs.bitcoin.networks.slimcoin;
1176 DOM.bip44coin.val(63); 1291 setHdCoin(63);
1177 }, 1292 },
1178 }, 1293 },
1179 { 1294 {
1180 name: "SLM - Slimcoin Testnet", 1295 name: "SLM - Slimcoin Testnet",
1296 bip49available: false,
1181 onSelect: function() { 1297 onSelect: function() {
1182 network = bitcoinjs.bitcoin.networks.slimcointn; 1298 network = bitcoinjs.bitcoin.networks.slimcointn;
1183 DOM.bip44coin.val(111); 1299 setHdCoin(111);
1184 }, 1300 },
1185 }, 1301 },
1186 { 1302 {
1187 name: "VIA - Viacoin", 1303 name: "VIA - Viacoin",
1304 bip49available: false,
1188 onSelect: function() { 1305 onSelect: function() {
1189 network = bitcoinjs.bitcoin.networks.viacoin; 1306 network = bitcoinjs.bitcoin.networks.viacoin;
1190 DOM.bip44coin.val(14); 1307 setHdCoin(14);
1191 }, 1308 },
1192 }, 1309 },
1193 { 1310 {
1194 name: "VIA - Viacoin Testnet", 1311 name: "VIA - Viacoin Testnet",
1312 bip49available: false,
1195 onSelect: function() { 1313 onSelect: function() {
1196 network = bitcoinjs.bitcoin.networks.viacointestnet; 1314 network = bitcoinjs.bitcoin.networks.viacointestnet;
1197 DOM.bip44coin.val(1); 1315 setHdCoin(1);
1198 }, 1316 },
1199 }, 1317 },
1200 { 1318 {
1201 name: "XRP - Ripple", 1319 name: "XRP - Ripple",
1320 bip49available: false,
1202 onSelect: function() { 1321 onSelect: function() {
1203 network = bitcoin.networks.bitcoin; 1322 network = bitcoinjs.bitcoin.networks.bitcoin;
1204 DOM.bip44coin.val(144); 1323 setHdCoin(144);
1205 }, 1324 },
1206 } 1325 }
1207 ] 1326 ]