Support THORChain (RUNE) m/44/931

This commit is contained in:
Hildisvíni Óttar
2021-04-23 14:22:42 +09:30
parent 23f393acfb
commit 02eeb81713
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,10 +1420,18 @@
} }
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 == "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 //Groestlcoin Addresses are different
if(isGRS()) { if(isGRS()) {
@@ -3259,6 +3267,13 @@
setHdCoin(19169); setHdCoin(19169);
}, },
}, },
{
name: "RUNE - THORChain",
onSelect: function() {
network = libs.bitcoin.networks.bitcoin;
setHdCoin(931);
},
},
{ {
name: "RVR - RevolutionVR", name: "RVR - RevolutionVR",
onSelect: function() { onSelect: function() {

View File

@@ -1665,6 +1665,16 @@ it('Allows selection of Rubycoin', function(done) {
}; };
testNetwork(done, params); 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) { it('Allows selection of Salus', function(done) {
var params = { var params = {
selectText: "SLS - Salus", selectText: "SLS - Salus",