aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <ian@iancoleman.io>2021-02-11 02:13:23 +0000
committerIan Coleman <ian@iancoleman.io>2021-02-11 02:34:38 +0000
commitd9ad938b521ad316f5fb6a80f260b77b80a0e864 (patch)
treed89b46939007577d965f092d9f0fe8199bcc99f3
parentf7f579f5f5239ef94d9fa34c77085bd19c5178e9 (diff)
downloadBIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.tar.gz
BIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.tar.zst
BIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.zip
Add Cosmos Hub (ATOM) support
Closes #452, thanks @conr2d
-rw-r--r--libs/combined/index.js4
-rw-r--r--libs/combined/package.json1
-rw-r--r--src/index.html1
-rw-r--r--src/js/cosmos-util.js13
-rw-r--r--src/js/index.js13
-rw-r--r--tests/spec/tests.js10
6 files changed, 42 insertions, 0 deletions
diff --git a/libs/combined/index.js b/libs/combined/index.js
index d3bc7a5..b020f59 100644
--- a/libs/combined/index.js
+++ b/libs/combined/index.js
@@ -14,6 +14,10 @@ module.exports.bchaddr = require('bchaddrjs')
14 14
15module.exports.bchaddrSlp = require('bchaddrjs-slp') 15module.exports.bchaddrSlp = require('bchaddrjs-slp')
16 16
17/* bech32 */
18
19module.exports.bech32 = require('bech32')
20
17/* biginteger */ 21/* biginteger */
18 22
19module.exports.BigInteger = require('javascript-biginteger') 23module.exports.BigInteger = require('javascript-biginteger')
diff --git a/libs/combined/package.json b/libs/combined/package.json
index 5b47f74..ed60059 100644
--- a/libs/combined/package.json
+++ b/libs/combined/package.json
@@ -8,6 +8,7 @@
8 "base-x": "3.0.7", 8 "base-x": "3.0.7",
9 "bchaddrjs": "0.4.4", 9 "bchaddrjs": "0.4.4",
10 "bchaddrjs-slp": "git://github.com/simpleledger/bchaddrjs.git#af16e44a6bfbe4b3980a62dba50e2f68ed864c6b", 10 "bchaddrjs-slp": "git://github.com/simpleledger/bchaddrjs.git#af16e44a6bfbe4b3980a62dba50e2f68ed864c6b",
11 "bech32": "1.1.4",
11 "bip38": "2.0.2", 12 "bip38": "2.0.2",
12 "bip38grs": "git://github.com/Groestlcoin/bip38grs.git#091975b01679b74dc0a4136bb743fe17791b0151", 13 "bip38grs": "git://github.com/Groestlcoin/bip38grs.git#091975b01679b74dc0a4136bb743fe17791b0151",
13 "bip85": "0.0.3", 14 "bip85": "0.0.3",
diff --git a/src/index.html b/src/index.html
index 4b61424..34b43ec 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1101,6 +1101,7 @@
1101 <script src="js/ripple-util.js"></script> 1101 <script src="js/ripple-util.js"></script>
1102 <script src="js/jingtum-util.js"></script> 1102 <script src="js/jingtum-util.js"></script>
1103 <script src="js/casinocoin-util.js"></script> 1103 <script src="js/casinocoin-util.js"></script>
1104 <script src="js/cosmos-util.js"></script>
1104 <script src="js/eos-util.js"></script> 1105 <script src="js/eos-util.js"></script>
1105 <script src="js/fio-util.js"></script> 1106 <script src="js/fio-util.js"></script>
1106 <script src="js/sjcl-bip39.js"></script> 1107 <script src="js/sjcl-bip39.js"></script>
diff --git a/src/js/cosmos-util.js b/src/js/cosmos-util.js
new file mode 100644
index 0000000..a7f4605
--- /dev/null
+++ b/src/js/cosmos-util.js
@@ -0,0 +1,13 @@
1function CosmosBufferToPublic(pubBuf) {
2 const Buffer = libs.buffer.Buffer;
3 const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex");
4 const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex");
5 pubBuf = Buffer.concat([AminoSecp256k1PubkeyPrefix, AminoSecp256k1PubkeyLength, pubBuf]);
6 return libs.bech32.encode("cosmospub", libs.bech32.toWords(pubBuf));
7}
8
9function CosmosBufferToAddress(pubBuf) {
10 const sha256_ed = libs.createHash("sha256").update(pubBuf).digest();
11 const ripemd160_ed = libs.createHash("rmd160").update(sha256_ed).digest();
12 return libs.bech32.encode("cosmos", libs.bech32.toWords(ripemd160_ed));
13}
diff --git a/src/js/index.js b/src/js/index.js
index 713b5e8..96fc451 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -1419,6 +1419,12 @@
1419 privkey = FIObufferToPrivate(keyPair.d.toBuffer(32)); 1419 privkey = FIObufferToPrivate(keyPair.d.toBuffer(32));
1420 } 1420 }
1421 1421
1422 if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") {
1423 address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer());
1424 pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer());
1425 privkey = keyPair.d.toBuffer().toString("base64");
1426 }
1427
1422 //Groestlcoin Addresses are different 1428 //Groestlcoin Addresses are different
1423 if(isGRS()) { 1429 if(isGRS()) {
1424 1430
@@ -2235,6 +2241,13 @@
2235 }, 2241 },
2236 }, 2242 },
2237 { 2243 {
2244 name: "ATOM - Cosmos Hub",
2245 onSelect: function() {
2246 network = libs.bitcoin.networks.bitcoin;
2247 setHdCoin(118);
2248 },
2249 },
2250 {
2238 name: "AUR - Auroracoin", 2251 name: "AUR - Auroracoin",
2239 onSelect: function() { 2252 onSelect: function() {
2240 network = libs.bitcoin.networks.auroracoin; 2253 network = libs.bitcoin.networks.auroracoin;
diff --git a/tests/spec/tests.js b/tests/spec/tests.js
index f350fa7..7e553af 100644
--- a/tests/spec/tests.js
+++ b/tests/spec/tests.js
@@ -917,6 +917,16 @@ it('Allows selection of Aryacoin', function(done) {
917 }; 917 };
918 testNetwork(done, params); 918 testNetwork(done, params);
919}); 919});
920it('Allows selection of Cosmos Hub', function(done) {
921 var params = {
922 selectText: "ATOM - Cosmos Hub",
923 phrase: "abandon abandon ability",
924 firstAddress: "cosmos17mkch9syem8gtf6wh7p38thdgav6dwezpkylny",
925 firstPubKey: "cosmospub1addwnpepq0sgn66ty4suk5vx3hsmxxqd5z3amegqwlu59funrzyz5u8r9758qhl84ys",
926 firstPrivKey: "zUnETPxmE2vkHzLHTAlO9wg8PL/GEEBc1I4yVwvSV8M=",
927 };
928 testNetwork(done, params);
929});
920it('Allows selection of Auroracoin', function(done) { 930it('Allows selection of Auroracoin', function(done) {
921 var params = { 931 var params = {
922 selectText: "AUR - Auroracoin", 932 selectText: "AUR - Auroracoin",