Merge branch 'master' into master

This commit is contained in:
Suat Özgür
2019-05-25 14:18:15 +02:00
committed by GitHub
9 changed files with 28076 additions and 67 deletions

View File

@@ -3356,7 +3356,7 @@ var validate = validation.validate;
/**
* Encodes a hash from a given type into a Bitcoin Cash address with the given prefix.
*
*
* @static
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
* @param {string} type Type of address to generate. Either 'P2PKH' or 'P2SH'.
@@ -3378,7 +3378,7 @@ function encode(prefix, type, hash) {
/**
* Decodes the given address into its constituting prefix, type and hash. See [#encode()]{@link encode}.
*
*
* @static
* @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'.
* @returns {object}
@@ -3416,14 +3416,14 @@ var ValidationError = validation.ValidationError;
*
* @private
*/
var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg'];
var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg', 'simpleledger', 'slptest'];
/**
* Checks whether a string is a valid prefix; ie., it has a single letter case
* and is one of 'bitcoincash', 'bchtest', or 'bchreg'.
* and is one of 'bitcoincash', 'bchtest', or 'bchreg', 'simpleledger' or 'slptest'.
*
* @private
* @param {string} prefix
* @param {string} prefix
* @returns {boolean}
*/
function isValidPrefix(prefix) {
@@ -3435,7 +3435,7 @@ function isValidPrefix(prefix) {
* of the address' checksum.
*
* @private
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
* @returns {Uint8Array}
*/
function prefixToUint5Array(prefix) {
@@ -3594,8 +3594,8 @@ function fromUint5Array(data) {
* Returns the concatenation a and b.
*
* @private
* @param {Uint8Array} a
* @param {Uint8Array} b
* @param {Uint8Array} a
* @param {Uint8Array} b
* @returns {Uint8Array}
* @throws {ValidationError}
*/
@@ -3633,7 +3633,7 @@ function polymod(data) {
/**
* Verify that the payload has not been corrupted by checking that the
* checksum is valid.
*
*
* @private
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
* @param {Uint8Array} payload Array of 5-bit integers containing the address' payload.
@@ -9011,6 +9011,21 @@ function toCashAddress (address) {
return encodeAsCashaddr(decoded)
}
/**
* Translates the given address into SLP format.
* @static
* @param {string} address - A valid SLP address in any format.
* @return {string}
* @throws {InvalidAddressError}
*/
function toSlpAddress (address) {
var decoded = decodeAddress(address)
return encodeAsSlpaddr(decoded)
}
/**
* Version byte table for base58 formats.
* @private
@@ -9125,7 +9140,7 @@ function decodeCashAddress (address) {
} catch (error) {
}
} else {
var prefixes = ['bitcoincash', 'bchtest', 'regtest']
var prefixes = ['bitcoincash', 'bchtest', 'regtest', 'simpleledger', 'slptest']
for (var i = 0; i < prefixes.length; ++i) {
try {
var prefix = prefixes[i]
@@ -9151,6 +9166,7 @@ function decodeCashAddressWithPrefix (address) {
var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH
switch (decoded.prefix) {
case 'bitcoincash':
case 'simpleledger':
return {
hash: hash,
format: Format.Cashaddr,
@@ -9158,6 +9174,7 @@ function decodeCashAddressWithPrefix (address) {
type: type
}
case 'bchtest':
case 'slptest':
case 'regtest':
return {
hash: hash,
@@ -9212,6 +9229,19 @@ function encodeAsCashaddr (decoded) {
return cashaddr.encode(prefix, type, hash)
}
/**
* Encodes the given decoded address into slp addr format.
* @private
* @param {object} decoded
* @returns {string}
*/
function encodeAsSlpaddr (decoded) {
var prefix = decoded.network === Network.Mainnet ? 'simpleledger' : 'slptest'
var type = decoded.type === Type.P2PKH ? 'P2PKH' : 'P2SH'
var hash = Uint8Array.from(decoded.hash)
return cashaddr.encode(prefix, type, hash)
}
/**
* Returns a boolean indicating whether the address is in legacy format.
* @static
@@ -9313,6 +9343,7 @@ module.exports = {
toLegacyAddress: toLegacyAddress,
toBitpayAddress: toBitpayAddress,
toCashAddress: toCashAddress,
toSlpAddress: toSlpAddress,
isLegacyAddress: isLegacyAddress,
isBitpayAddress: isBitpayAddress,
isCashAddress: isCashAddress,
@@ -9325,4 +9356,4 @@ module.exports = {
}).call(this,require("buffer").Buffer)
},{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52)
});
});

View File

@@ -27,7 +27,7 @@ bitcoinjs.bitcoin.networks.clam = {
private: 0xa8c17826
},
pubKeyHash: 0x89,
scriptHash: 0x00, // TODO set this correctly
scriptHash: 0x0D,
wif: 0x85
};
@@ -39,7 +39,27 @@ bitcoinjs.bitcoin.networks.crown = {
},
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80
wif: 0x80,
toNewAddress: function(oldAddress)
{
var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var b58 = basex(ALPHABET);
var addrBytes = b58.decode(oldAddress);
var hash160 = new Uint16Array(23);
hash160[0]= 0x01; //C
hash160[1]= 0x75; //R
hash160[2]= 0x07; //W
addrBytes.copy(hash160, 3, 1, 21);
var checksum = bitcoinjs.bitcoin.crypto.hash256(hash160).subarray(0, 4);
var binaryAddr = new Uint16Array(27);
binaryAddr.set(hash160,0);
checksum.copy(binaryAddr, 23, 0, 4);
var newAddress = b58.encode(binaryAddr);
return newAddress;
}
};
bitcoinjs.bitcoin.networks.dash = {
@@ -93,7 +113,7 @@ bitcoinjs.bitcoin.networks.namecoin = {
private: 0x0488ade4
},
pubKeyHash: 0x34,
scriptHash: 0x00, // TODO set this correctly
scriptHash: 0x0D,
wif: 0x80
};
@@ -104,7 +124,7 @@ bitcoinjs.bitcoin.networks.peercoin = {
private: 0x0488ade4
},
pubKeyHash: 0x37,
scriptHash: 0x00, // TODO set this correctly
scriptHash: 0x75,
wif: 0xb7
};
@@ -236,20 +256,42 @@ bitcoinjs.bitcoin.networks.myriadcoin = {
private: 0x0488ade4
},
pubKeyHash: 0x32,
scriptHash: 0x00, // TODO set this correctly
scriptHash: 0x09,
wif: 0xb2
};
bitcoinjs.bitcoin.networks.bolivarcoin = {
messagePrefix: 'Bolivarcoin Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4
},
pubKeyHash: 0x55,
scriptHash: 0x05,
wif: 0xD5
};
bitcoinjs.bitcoin.networks.onixcoin = {
messagePrefix: 'unused',
messagePrefix: 'ONIX Signed Message:\n',
bip32: {
public: 0x049d7cb2,
private: 0x049d7878
public: 0x0488b21e,
private: 0x0488ade4
},
pubKeyHash: 0x4B,
scriptHash: 0x05,
wif: 0x80
wif: 0xCB
};
bitcoinjs.bitcoin.networks.lkrcoin = {
messagePrefix: '\x18LKRcoin Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
},
pubKeyHash: 0x30,
scriptHash: 0x55,
wif: 0xB0
};
bitcoinjs.bitcoin.networks.pivx = {
@@ -902,6 +944,17 @@ bitcoinjs.bitcoin.networks.neoscoin = {
wif: 0xb1,
};
bitcoinjs.bitcoin.networks.nix = {
messagePrefix: '\x18Nix Signed Message:\n',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
},
pubKeyHash: 0x26,
scriptHash: 0x35,
wif: 0x80,
};
bitcoinjs.bitcoin.networks.neurocoin = {
messagePrefix: '\x18PPCoin Signed Message:\n',
bip32: {
@@ -1473,4 +1526,15 @@ bitcoinjs.bitcoin.networks.litecoinz = {
pubKeyHash: 0x0AB3,
scriptHash: 0x0AB8,
wif: 0x80,
};
bitcoinjs.bitcoin.networks.blockstamp = {
messagePrefix: '\x18BlockStamp Signed Message:\n',
bip32: {
public: 0x0488B21E,
private: 0x0488ADE4,
},
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80,
};

View File

@@ -917,7 +917,11 @@
|| (networks[DOM.network.val()].name == "MUSIC - Musicoin")
|| (networks[DOM.network.val()].name == "POA - Poa")
|| (networks[DOM.network.val()].name == "EXP - Expanse")
|| (networks[DOM.network.val()].name == "CLO - Callisto")) {
|| (networks[DOM.network.val()].name == "CLO - Callisto")
|| (networks[DOM.network.val()].name == "DXN - DEXON")
|| (networks[DOM.network.val()].name == "ELLA - Ellaism")
|| (networks[DOM.network.val()].name == "ESN - Ethersocial Network")
) {
var privKeyBuffer = keyPair.d.toBuffer(32);
privkey = privKeyBuffer.toString('hex');
var addressBuffer = ethUtil.privateToAddress(privKeyBuffer);
@@ -927,6 +931,7 @@
privkey = ethUtil.addHexPrefix(privkey);
pubkey = ethUtil.addHexPrefix(pubkey);
}
// Stellar is different
if (networks[DOM.network.val()].name == "XLM - Stellar") {
var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -939,6 +944,15 @@
privkey = keypair.secret();
pubkey = address = keypair.publicKey();
}
if ((networks[DOM.network.val()].name == "NAS - Nebulas")) {
var NasAccount = require("nebulas-account");
var privKeyBuffer = keyPair.d.toBuffer(32);
var nebulasAccount = new NasAccount();
nebulasAccount.setPrivateKey(privKeyBuffer);
address = nebulasAccount.getAddressString();
privkey = nebulasAccount.getPrivateKeyString();
pubkey = nebulasAccount.getPublicKeyString();
}
// Ripple values are different
if (networks[DOM.network.val()].name == "XRP - Ripple") {
privkey = convertRipplePriv(privkey);
@@ -954,6 +968,13 @@
address = bchaddr.toBitpayAddress(address);
}
}
// Bitcoin Cash address format may vary
if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") {
var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val();
if (bchAddrType == "cashaddr") {
address = bchaddr.toSlpAddress(address);
}
}
// Segwit addresses are different
if (isSegwit) {
if (!segwitAvailable) {
@@ -972,6 +993,11 @@
address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
}
}
if ((networks[DOM.network.val()].name == "CRW - Crown")) {
address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address);
}
addAddressToList(indexText, address, pubkey, privkey);
if (isLast) {
hidePending();
@@ -1679,6 +1705,13 @@
setHdCoin(220);
},
},
{
name: "BOLI - Bolivarcoin",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bolivarcoin;
setHdCoin(278);
},
},
{
name: "BCA - Bitcoin Atom",
onSelect: function() {
@@ -1720,7 +1753,7 @@
network = bitcoinjs.bitcoin.networks.blocknode;
setHdCoin(2941);
},
},
},
{
name: "tBND - Blocknode Testnet",
onSelect: function() {
@@ -1741,6 +1774,13 @@
network = bitcoinjs.bitcoin.networks.bitsend;
setHdCoin(91);
},
},
{
name: "BST - BlockStamp",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.blockstamp;
setHdCoin(254);
},
},
{
name: "BTA - Bata",
@@ -1862,6 +1902,13 @@
setHdCoin(186);
},
},
{
name: "CRW - Crown (Legacy)",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.crown;
setHdCoin(72);
},
},
{
name: "CRW - Crown",
onSelect: function() {
@@ -1925,6 +1972,13 @@
setHdCoin(3);
},
},
{
name: "DXN - DEXON",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bitcoin;
setHdCoin(237);
},
},
{
name: "ECN - Ecoin",
onSelect: function() {
@@ -1946,6 +2000,14 @@
setHdCoin(78);
},
},
{
name: "ELLA - Ellaism",
segwitAvailable: false,
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bitcoin;
setHdCoin(163);
},
},
{
name: "EMC2 - Einsteinium",
onSelect: function() {
@@ -1960,6 +2022,14 @@
setHdCoin(151);
},
},
{
name: "ESN - Ethersocial Network",
segwitAvailable: false,
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bitcoin;
setHdCoin(31102);
},
},
{
name: "ETC - Ethereum Classic",
segwitAvailable: false,
@@ -2139,6 +2209,14 @@
setHdCoin(114);
},
},
{
name: "LKR - Lkrcoin",
segwitAvailable: false,
onSelect: function() {
network = bitcoinjs.bitcoin.networks.lkrcoin;
setHdCoin(557);
},
},
{
name: "LTC - Litecoin",
onSelect: function() {
@@ -2212,6 +2290,13 @@
setHdCoin(130);
},
},
{
name: "NAS - Nebulas",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.bitcoin;
setHdCoin(2718);
},
},
{
name: "NEBL - Neblio",
onSelect: function() {
@@ -2226,6 +2311,13 @@
setHdCoin(25);
},
},
{
name: "NIX - NIX Platform",
onSelect: function() {
network = bitcoinjs.bitcoin.networks.nix;
setHdCoin(400);
},
},
{
name: "NLG - Gulden",
onSelect: function() {
@@ -2452,6 +2544,13 @@
setHdCoin(111);
},
},
{
name: "SLP - Simple Ledger Protocol",
onSelect: function() {
DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
setHdCoin(245);
},
},
{
name: "SLR - Solarcoin",
onSelect: function() {

27697
src/js/nebulas-account.js Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -184,29 +184,56 @@ bitcoinjs.bitcoin.networks.digibyte.p2wpkhInP2sh = {
scriptHash: 0x3f,
wif: 0x80
};
bitcoinjs.bitcoin.networks.deimos.p2wpkh = {
baseNetwork: "deimos",
messagePrefix: '\x18Deimos Signed Message:\n',
bech32: 'dei',
bitcoinjs.bitcoin.networks.blockstamp.p2wpkh = {
baseNetwork: "blockstamp",
messagePrefix: '\x18BlockStamp Signed Message:\n',
bech32: 'bc',
bip32: {
public: 0x0488B21E,
private: 0x0488ADE4
public: 0x0488B21E,
private: 0x0488ADE4,
},
pubKeyHash: 0x1f,
scriptHash: 0x21,
wif: 0x8a
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80,
};
bitcoinjs.bitcoin.networks.deimos.p2wpkhInP2sh = {
baseNetwork: "deimos",
messagePrefix: '\x18Deimos Signed Message:\n',
bech32: 'dei',
bitcoinjs.bitcoin.networks.blockstamp.p2wpkhInP2sh = {
baseNetwork: "blockstamp",
messagePrefix: '\x18BlockStamp Signed Message:\n',
bech32: 'bc',
bip32: {
public: 0x0488B21E,
private: 0x0488ADE4
public: 0x0488B21E,
private: 0x0488ADE4,
},
pubKeyHash: 0x1f,
scriptHash: 0x21,
wif: 0x8a
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80,
};
bitcoinjs.bitcoin.networks.nix.p2wpkh = {
baseNetwork: "nix",
messagePrefix: '\x18Nix Signed Message:\n',
bech32: 'nix',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
},
pubKeyHash: 0x26,
scriptHash: 0x35,
wif: 0x80,
};
bitcoinjs.bitcoin.networks.nix.p2wpkhInP2sh = {
baseNetwork: "nix",
messagePrefix: '\x18Nix Signed Message:\n',
bech32: 'nix',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
},
pubKeyHash: 0x26,
scriptHash: 0x35,
wif: 0x80,
};
})();