Merge pull request #368 from johnnynanjiang/elastos-pr

Add Elastos
This commit is contained in:
iancoleman
2019-11-11 09:47:35 +11:00
committed by GitHub
6 changed files with 181 additions and 7 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,5 @@
node_modules
bip39-standalone.html
.idea
.DS_Store
package-lock.json

View File

@@ -930,6 +930,9 @@
<script src="js/bitcoinjs-3.3.2.js"></script>
<script src="js/bitcoinjs-extensions.js"></script>
<script src="js/bitcoinjs-bip38-2.0.2.js"></script>
<script src="js/groestlcoinjs-3.3.2.js"></script>
<script src="js/groestlcoinjs-bip38-2.0.2.js"></script>
<script src="js/elastos-1.0.9.min.js"></script>
<script src="js/segwit-parameters.js"></script>
<script src="js/ethereumjs-util.js"></script>
<script src="js/ripple-util.js"></script>
@@ -952,7 +955,5 @@
<script src="js/entropy.js"></script>
<script src="js/stellar-util.js"></script>
<script src="js/index.js"></script>
<script src="js/groestlcoinjs-3.3.2.js"></script>
<script src="js/groestlcoinjs-bip38-2.0.2.js"></script>
</body>
</html>

View File

@@ -1716,3 +1716,14 @@ bitcoinjs.bitcoin.networks.aryacoin = {
scriptHash: 0x6f,
wif: 0x97
};
bitcoinjs.bitcoin.networks.elastos = {
messagePrefix: 'unused',
bip32: {
public: 0x0488B21E,
private: 0x0488ADE4,
},
pubKeyHash: 0x21,
scriptHash: 0xc4, // TODO set this correctly, same as BTC for now
wif: 0xef // TODO set this correctly, same as BTC for now
};

69
src/js/elastos-1.0.9.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -607,7 +607,7 @@
extendedKey = extendedKey.derive(index);
}
}
return extendedKey
return extendedKey;
}
function showValidationError(errorText) {
@@ -650,9 +650,9 @@
}
function validateRootKey(rootKeyBase58) {
if(isGRS())
if(isGRS())
return validateRootKeyGRS(rootKeyBase58);
// try various segwit network params since this extended key may be from
// any one of them.
if (networkHasSegwit()) {
@@ -848,6 +848,10 @@
return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
}
function isELA() {
return networks[DOM.network.val()].name == "ELA - Elastos"
}
function displayBip44Info() {
// Get the derivation path for the account
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -861,9 +865,14 @@
var accountExtendedKey = calcBip32ExtendedKey(path);
var accountXprv = accountExtendedKey.toBase58();
var accountXpub = accountExtendedKey.neutered().toBase58();
// Display the extended keys
DOM.bip44accountXprv.val(accountXprv);
DOM.bip44accountXpub.val(accountXpub);
if (isELA()) {
displayBip44InfoForELA();
}
}
function displayBip49Info() {
@@ -919,6 +928,10 @@
clearAddressesList();
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
displayAddresses(0, initialAddressCount);
if (isELA()) {
displayBip32InfoForELA();
}
}
function displayAddresses(start, total) {
@@ -1004,7 +1017,7 @@
privkey = keyPair.toWIF();
// BIP38 encode private key if required
if (useBip38) {
if(isGRS())
if(isGRS())
privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
}, null, networks[DOM.network.val()].name.includes("Testnet"));
@@ -1135,10 +1148,23 @@
else if (isP2wpkhInP2sh) {
address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
}
}
}
//non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
}
if (isELA()) {
let elaAddress = calcAddressForELA(
seed,
parseIntNoNaN(DOM.bip44coin.val(), 0),
parseIntNoNaN(DOM.bip44account.val(), 0),
parseIntNoNaN(DOM.bip44change.val(), 0),
index
);
address = elaAddress.address;
privkey = elaAddress.privateKey;
pubkey = elaAddress.publicKey;
}
addAddressToList(indexText, address, pubkey, privkey);
if (isLast) {
hidePending();
@@ -2211,6 +2237,13 @@
setHdCoin(78);
},
},
{
name: "ELA - Elastos",
onSelect: function () {
network = bitcoinjs.bitcoin.networks.elastos;
setHdCoin(2305);
},
},
{
name: "ELLA - Ellaism",
segwitAvailable: false,
@@ -3119,6 +3152,56 @@
}
]
// ELA - Elastos functions - begin
function displayBip44InfoForELA() {
if (!isELA()) {
return;
}
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
// Calculate the account extended keys
var accountXprv = elastosjs.getAccountExtendedPrivateKey(seed, coin, account);
var accountXpub = elastosjs.getAccountExtendedPublicKey(seed, coin, account);
// Display the extended keys
DOM.bip44accountXprv.val(accountXprv);
DOM.bip44accountXpub.val(accountXpub);
}
function displayBip32InfoForELA() {
if (!isELA()) {
return;
}
var coin = parseIntNoNaN(DOM.bip44coin.val(), 0);
var account = parseIntNoNaN(DOM.bip44account.val(), 0);
var change = parseIntNoNaN(DOM.bip44change.val(), 0);
DOM.extendedPrivKey.val(elastosjs.getBip32ExtendedPrivateKey(seed, coin, account, change));
DOM.extendedPubKey.val(elastosjs.getBip32ExtendedPublicKey(seed, coin, account, change));
// Display the addresses and privkeys
clearAddressesList();
var initialAddressCount = parseInt(DOM.rowsToAdd.val());
displayAddresses(0, initialAddressCount);
}
function calcAddressForELA(seed, coin, account, change, index) {
if (!isELA()) {
return;
}
var publicKey = elastosjs.getDerivedPublicKey(elastosjs.getMasterPublicKey(seed), change, index);
return {
privateKey: elastosjs.getDerivedPrivateKey(seed, coin, account, change, index),
publicKey: publicKey,
address: elastosjs.getAddress(publicKey.toString('hex'))
};
}
// ELA - Elastos functions - end
init();
})();

View File

@@ -1608,6 +1608,13 @@ it('Allows selection of Groestlcoin Testnet', function(done) {
};
testNetwork(done, params);
});
it('Allows selection of Elastos', function(done) {
var params = {
selectText: "ELA - Elastos",
firstAddress: "EYmqntM99tr4NJJs2G5Nr93pqsh9cdTCkS",
};
testNetwork(done, params);
});
// BIP39 seed is set from phrase
it('Sets the bip39 seed from the prhase', function(done) {