mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-18 16:32:18 +00:00
Merge pull request #316 from passionofvc/master
add SLP Token Type https://github.com/simpleledger/slp-specifications…
This commit is contained in:
@@ -3356,7 +3356,7 @@ var validate = validation.validate;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes a hash from a given type into a Bitcoin Cash address with the given prefix.
|
* Encodes a hash from a given type into a Bitcoin Cash address with the given prefix.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
||||||
* @param {string} type Type of address to generate. Either 'P2PKH' or 'P2SH'.
|
* @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}.
|
* Decodes the given address into its constituting prefix, type and hash. See [#encode()]{@link encode}.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'.
|
* @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'.
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
@@ -3416,14 +3416,14 @@ var ValidationError = validation.ValidationError;
|
|||||||
*
|
*
|
||||||
* @private
|
* @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
|
* 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
|
* @private
|
||||||
* @param {string} prefix
|
* @param {string} prefix
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function isValidPrefix(prefix) {
|
function isValidPrefix(prefix) {
|
||||||
@@ -3435,7 +3435,7 @@ function isValidPrefix(prefix) {
|
|||||||
* of the address' checksum.
|
* of the address' checksum.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
*/
|
*/
|
||||||
function prefixToUint5Array(prefix) {
|
function prefixToUint5Array(prefix) {
|
||||||
@@ -3594,8 +3594,8 @@ function fromUint5Array(data) {
|
|||||||
* Returns the concatenation a and b.
|
* Returns the concatenation a and b.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Uint8Array} a
|
* @param {Uint8Array} a
|
||||||
* @param {Uint8Array} b
|
* @param {Uint8Array} b
|
||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
* @throws {ValidationError}
|
* @throws {ValidationError}
|
||||||
*/
|
*/
|
||||||
@@ -3633,7 +3633,7 @@ function polymod(data) {
|
|||||||
/**
|
/**
|
||||||
* Verify that the payload has not been corrupted by checking that the
|
* Verify that the payload has not been corrupted by checking that the
|
||||||
* checksum is valid.
|
* checksum is valid.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
* @param {string} prefix Network prefix. E.g.: 'bitcoincash'.
|
||||||
* @param {Uint8Array} payload Array of 5-bit integers containing the address' payload.
|
* @param {Uint8Array} payload Array of 5-bit integers containing the address' payload.
|
||||||
@@ -9011,6 +9011,21 @@ function toCashAddress (address) {
|
|||||||
return encodeAsCashaddr(decoded)
|
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.
|
* Version byte table for base58 formats.
|
||||||
* @private
|
* @private
|
||||||
@@ -9125,7 +9140,7 @@ function decodeCashAddress (address) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var prefixes = ['bitcoincash', 'bchtest', 'regtest']
|
var prefixes = ['bitcoincash', 'bchtest', 'regtest', 'simpleledger', 'slptest']
|
||||||
for (var i = 0; i < prefixes.length; ++i) {
|
for (var i = 0; i < prefixes.length; ++i) {
|
||||||
try {
|
try {
|
||||||
var prefix = prefixes[i]
|
var prefix = prefixes[i]
|
||||||
@@ -9151,6 +9166,7 @@ function decodeCashAddressWithPrefix (address) {
|
|||||||
var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH
|
var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH
|
||||||
switch (decoded.prefix) {
|
switch (decoded.prefix) {
|
||||||
case 'bitcoincash':
|
case 'bitcoincash':
|
||||||
|
case 'simpleledger':
|
||||||
return {
|
return {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
format: Format.Cashaddr,
|
format: Format.Cashaddr,
|
||||||
@@ -9158,6 +9174,7 @@ function decodeCashAddressWithPrefix (address) {
|
|||||||
type: type
|
type: type
|
||||||
}
|
}
|
||||||
case 'bchtest':
|
case 'bchtest':
|
||||||
|
case 'slptest':
|
||||||
case 'regtest':
|
case 'regtest':
|
||||||
return {
|
return {
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@@ -9212,6 +9229,19 @@ function encodeAsCashaddr (decoded) {
|
|||||||
return cashaddr.encode(prefix, type, hash)
|
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.
|
* Returns a boolean indicating whether the address is in legacy format.
|
||||||
* @static
|
* @static
|
||||||
@@ -9313,6 +9343,7 @@ module.exports = {
|
|||||||
toLegacyAddress: toLegacyAddress,
|
toLegacyAddress: toLegacyAddress,
|
||||||
toBitpayAddress: toBitpayAddress,
|
toBitpayAddress: toBitpayAddress,
|
||||||
toCashAddress: toCashAddress,
|
toCashAddress: toCashAddress,
|
||||||
|
toSlpAddress: toSlpAddress,
|
||||||
isLegacyAddress: isLegacyAddress,
|
isLegacyAddress: isLegacyAddress,
|
||||||
isBitpayAddress: isBitpayAddress,
|
isBitpayAddress: isBitpayAddress,
|
||||||
isCashAddress: isCashAddress,
|
isCashAddress: isCashAddress,
|
||||||
@@ -9325,4 +9356,4 @@ module.exports = {
|
|||||||
|
|
||||||
}).call(this,require("buffer").Buffer)
|
}).call(this,require("buffer").Buffer)
|
||||||
},{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52)
|
},{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -952,6 +952,13 @@
|
|||||||
address = bchaddr.toBitpayAddress(address);
|
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
|
// Segwit addresses are different
|
||||||
if (isSegwit) {
|
if (isSegwit) {
|
||||||
if (!segwitAvailable) {
|
if (!segwitAvailable) {
|
||||||
@@ -1718,7 +1725,7 @@
|
|||||||
network = bitcoinjs.bitcoin.networks.blocknode;
|
network = bitcoinjs.bitcoin.networks.blocknode;
|
||||||
setHdCoin(2941);
|
setHdCoin(2941);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "tBND - Blocknode Testnet",
|
name: "tBND - Blocknode Testnet",
|
||||||
onSelect: function() {
|
onSelect: function() {
|
||||||
@@ -2486,6 +2493,13 @@
|
|||||||
setHdCoin(111);
|
setHdCoin(111);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "SLP - Simple Ledger Protocol",
|
||||||
|
onSelect: function() {
|
||||||
|
DOM.bitcoinCashAddressTypeContainer.removeClass("hidden");
|
||||||
|
setHdCoin(245);
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "SLR - Solarcoin",
|
name: "SLR - Solarcoin",
|
||||||
onSelect: function() {
|
onSelect: function() {
|
||||||
|
|||||||
@@ -564,6 +564,15 @@ it('Allows selection of bitcoin cash', function(done) {
|
|||||||
};
|
};
|
||||||
testNetwork(done, params);
|
testNetwork(done, params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Allows selection of simpleledger(SLP)', function(done) {
|
||||||
|
var params = {
|
||||||
|
selectText: "SLP - Simple Ledger Protocol",
|
||||||
|
firstAddress: "simpleledger:qrtffz6ajfsn74gpur7y3epjquz42pvww5acewqmre",
|
||||||
|
};
|
||||||
|
testNetwork(done, params);
|
||||||
|
});
|
||||||
|
|
||||||
it('Allows selection of myriadcoin', function(done) {
|
it('Allows selection of myriadcoin', function(done) {
|
||||||
var params = {
|
var params = {
|
||||||
selectText: "XMY - Myriadcoin",
|
selectText: "XMY - Myriadcoin",
|
||||||
|
|||||||
Reference in New Issue
Block a user