X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=blobdiff_plain;f=src%2Fjs%2Fcosmos-util.js;fp=src%2Fjs%2Fcosmos-util.js;h=a7f460569a3135eaf56363f139415638d958b00e;hp=0000000000000000000000000000000000000000;hb=d9ad938b521ad316f5fb6a80f260b77b80a0e864;hpb=f7f579f5f5239ef94d9fa34c77085bd19c5178e9 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)); +}