/**
* 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'.
/**
* 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}
*
* @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) {
* 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) {
* Returns the concatenation a and b.
*
* @private
- * @param {Uint8Array} a
- * @param {Uint8Array} b
+ * @param {Uint8Array} a
+ * @param {Uint8Array} b
* @returns {Uint8Array}
* @throws {ValidationError}
*/
/**
* 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.
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
} 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]
var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH
switch (decoded.prefix) {
case 'bitcoincash':
+ case 'simpleledger':
return {
hash: hash,
format: Format.Cashaddr,
type: type
}
case 'bchtest':
+ case 'slptest':
case 'regtest':
return {
hash: 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.
* @static
toLegacyAddress: toLegacyAddress,
toBitpayAddress: toBitpayAddress,
toCashAddress: toCashAddress,
+ toSlpAddress: toSlpAddress,
isLegacyAddress: isLegacyAddress,
isBitpayAddress: isBitpayAddress,
isCashAddress: isCashAddress,
}).call(this,require("buffer").Buffer)
},{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52)
-});
\ No newline at end of file
+});