From d9ad938b521ad316f5fb6a80f260b77b80a0e864 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Thu, 11 Feb 2021 02:13:23 +0000 Subject: Add Cosmos Hub (ATOM) support Closes #452, thanks @conr2d --- src/index.html | 1 + src/js/cosmos-util.js | 13 +++++++++++++ src/js/index.js | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/js/cosmos-util.js (limited to 'src') 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 @@ + 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 @@ +function CosmosBufferToPublic(pubBuf) { + 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)); +} + +function CosmosBufferToAddress(pubBuf) { + 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)); +} 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 @@ privkey = FIObufferToPrivate(keyPair.d.toBuffer(32)); } + if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") { + address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer()); + pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer()); + privkey = keyPair.d.toBuffer().toString("base64"); + } + //Groestlcoin Addresses are different if(isGRS()) { @@ -2234,6 +2240,13 @@ setHdCoin(357); }, }, + { + name: "ATOM - Cosmos Hub", + onSelect: function() { + network = libs.bitcoin.networks.bitcoin; + setHdCoin(118); + }, + }, { name: "AUR - Auroracoin", onSelect: function() { -- cgit v1.2.3