Add Terra (LUNA) support

This commit is contained in:
a00a63
2021-03-27 14:04:07 +01:00
parent 23f393acfb
commit 43bef4e19d
3 changed files with 31 additions and 6 deletions

View File

@@ -1,13 +1,13 @@
function CosmosBufferToPublic(pubBuf) { function CosmosBufferToPublic(pubBuf, hrp = "cosmos") {
const Buffer = libs.buffer.Buffer; const Buffer = libs.buffer.Buffer;
const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex"); const AminoSecp256k1PubkeyPrefix = Buffer.from("EB5AE987", "hex");
const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex"); const AminoSecp256k1PubkeyLength = Buffer.from("21", "hex");
pubBuf = Buffer.concat([AminoSecp256k1PubkeyPrefix, AminoSecp256k1PubkeyLength, pubBuf]); 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 sha256_ed = libs.createHash("sha256").update(pubBuf).digest();
const ripemd160_ed = libs.createHash("rmd160").update(sha256_ed).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));
} }

View File

@@ -1420,11 +1420,19 @@
} }
if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") { if (networks[DOM.network.val()].name == "ATOM - Cosmos Hub") {
address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer()); const hrp = "cosmos";
pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer()); address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp);
pubkey = CosmosBufferToPublic(keyPair.getPublicKeyBuffer(), hrp);
privkey = keyPair.d.toBuffer().toString("base64"); privkey = keyPair.d.toBuffer().toString("base64");
} }
if (networks[DOM.network.val()].name == "LUNA - Terra") {
const hrp = "terra";
address = CosmosBufferToAddress(keyPair.getPublicKeyBuffer(), hrp);
pubkey = keyPair.getPublicKeyBuffer().toString("hex");
privkey = keyPair.d.toBuffer().toString("hex");
}
//Groestlcoin Addresses are different //Groestlcoin Addresses are different
if(isGRS()) { if(isGRS()) {
@@ -2939,6 +2947,13 @@
setHdCoin(221); setHdCoin(221);
}, },
}, },
{
name: "LUNA - Terra",
onSelect: function() {
network = libs.bitcoin.networks.bitcoin;
setHdCoin(330);
},
},
{ {
name: "LYNX - Lynx", name: "LYNX - Lynx",
onSelect: function() { onSelect: function() {

View File

@@ -927,6 +927,16 @@ it('Allows selection of Cosmos Hub', function(done) {
}; };
testNetwork(done, params); testNetwork(done, params);
}); });
it('Allows selection of Terra', function(done) {
var params = {
selectText: "LUNA - Terra",
phrase: "abandon abandon ability",
firstAddress: "terra1txr4jwel3vjl64vrc08pljnjryqkhtffmyp265",
firstPubKey: "028e7658e3debb2d9d458919bfba0e85b0220e845f7552176f30a52acd0f809d71",
firstPrivKey: "d611b211e370aa1edd9743acd6ce537d16fade85d7ae7e88b32f3a0483f52535",
};
testNetwork(done, params);
});
it('Allows selection of Auroracoin', function(done) { it('Allows selection of Auroracoin', function(done) {
var params = { var params = {
selectText: "AUR - Auroracoin", selectText: "AUR - Auroracoin",