aboutsummaryrefslogtreecommitdiff
path: root/src/js/cosmos-util.js
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 /src/js/cosmos-util.js
parentf7f579f5f5239ef94d9fa34c77085bd19c5178e9 (diff)
downloadBIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.tar.gz
BIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.tar.zst
BIP39-d9ad938b521ad316f5fb6a80f260b77b80a0e864.zip
Add Cosmos Hub (ATOM) support
Closes #452, thanks @conr2d
Diffstat (limited to 'src/js/cosmos-util.js')
-rw-r--r--src/js/cosmos-util.js13
1 files changed, 13 insertions, 0 deletions
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}