diff --git a/src/js/cosmos-util.js b/src/js/cosmos-util.js index a7f4605..e3a0ddf 100644 --- a/src/js/cosmos-util.js +++ b/src/js/cosmos-util.js @@ -1,13 +1,13 @@ -function CosmosBufferToPublic(pubBuf) { +function CosmosBufferToPublic(pubBuf, hrp = "cosmos") { const Buffer = libs.buffer.Buffer; const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex"); const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex"); pubBuf = Buffer.concat([AminoSecp256k1PubkeyPrefix, AminoSecp256k1PubkeyLength, pubBuf]); - return libs.bech32.encode("cosmospub", libs.bech32.toWords(pubBuf)); + return libs.bech32.encode(`${hrp}pub`, libs.bech32.toWords(pubBuf)); } -function CosmosBufferToAddress(pubBuf) { +function CosmosBufferToAddress(pubBuf, hrp = "cosmos") { const sha256_ed = libs.createHash("sha256").update(pubBuf).digest(); const ripemd160_ed = libs.createHash("rmd160").update(sha256_ed).digest(); - return libs.bech32.encode("cosmos", libs.bech32.toWords(ripemd160_ed)); + return libs.bech32.encode(hrp, libs.bech32.toWords(ripemd160_ed)); } diff --git a/src/js/index.js b/src/js/index.js index c502208..8e103e4 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1420,10 +1420,18 @@ } if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") { - address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer()); - pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer()); + const hrp = "cosmos"; + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp); + pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer(), hrp); privkey = keyPair.d.toBuffer().toString("base64"); } + + if (networks[DOM.network.val()].name == "RUNE - THORChain") { + const hrp = "thor"; + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp); + pubkey = keyPair.getPublicKeyBuffer().toString("hex"); + privkey = keyPair.d.toBuffer().toString("hex"); + } //Groestlcoin Addresses are different if(isGRS()) { @@ -3259,6 +3267,13 @@ setHdCoin(19169); }, }, + { + name: "RUNE - THORChain", + onSelect: function() { + network = libs.bitcoin.networks.bitcoin; + setHdCoin(931); + }, + }, { name: "RVR - RevolutionVR", onSelect: function() { diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 257cd7b..523f076 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -1665,6 +1665,16 @@ it('Allows selection of Rubycoin', function(done) { }; testNetwork(done, params); }); +it('Allows selection of THORChain', function(done) { + var params = { + selectText: "RUNE - THORChain", + phrase: "flip vicious divorce angle toward say derive blue refuse load word creek once expire bounce", + firstAddress: "thor1zp3yx758t64vqvu8776vnwd0udrs2vwuxhc4ep", + firstPubKey: "02fa85b75ef37fe3a4f4a6d62352aa7de070d2b39af9c55be26f079d01f406851d", + firstPrivKey: "6020c0d5a9a8689c491c6a8f36beb70bf459e129e1428fed64aaf594beee54a6", + }; + testNetwork(done, params); +}); it('Allows selection of Salus', function(done) { var params = { selectText: "SLS - Salus",