diff options
author | yamada <oukinshu@gmail.com> | 2019-04-17 00:02:00 +0900 |
---|---|---|
committer | yamada <oukinshu@gmail.com> | 2019-04-17 00:02:00 +0900 |
commit | d0889ab9dee263494bcf50dc6c5a25a249c8ffe1 (patch) | |
tree | 38bd53ba754067bfa8500e53e728326850766737 | |
parent | 478e54ad478c3c4c775f12f2e6bdfa0ca5947b18 (diff) | |
download | BIP39-d0889ab9dee263494bcf50dc6c5a25a249c8ffe1.tar.gz BIP39-d0889ab9dee263494bcf50dc6c5a25a249c8ffe1.tar.zst BIP39-d0889ab9dee263494bcf50dc6c5a25a249c8ffe1.zip |
add SLP Token Type https://github.com/simpleledger/slp-specifications/blob/master/slp-token-type-1.md
-rw-r--r-- | src/js/bchaddrjs-0.2.1.js | 53 | ||||
-rw-r--r-- | src/js/index.js | 16 | ||||
-rw-r--r-- | tests/spec/tests.js | 9 |
3 files changed, 66 insertions, 12 deletions
diff --git a/src/js/bchaddrjs-0.2.1.js b/src/js/bchaddrjs-0.2.1.js index 8356f10..28f67e9 100644 --- a/src/js/bchaddrjs-0.2.1.js +++ b/src/js/bchaddrjs-0.2.1.js | |||
@@ -3356,7 +3356,7 @@ var validate = validation.validate; | |||
3356 | 3356 | ||
3357 | /** | 3357 | /** |
3358 | * Encodes a hash from a given type into a Bitcoin Cash address with the given prefix. | 3358 | * Encodes a hash from a given type into a Bitcoin Cash address with the given prefix. |
3359 | * | 3359 | * |
3360 | * @static | 3360 | * @static |
3361 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | 3361 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. |
3362 | * @param {string} type Type of address to generate. Either 'P2PKH' or 'P2SH'. | 3362 | * @param {string} type Type of address to generate. Either 'P2PKH' or 'P2SH'. |
@@ -3378,7 +3378,7 @@ function encode(prefix, type, hash) { | |||
3378 | 3378 | ||
3379 | /** | 3379 | /** |
3380 | * Decodes the given address into its constituting prefix, type and hash. See [#encode()]{@link encode}. | 3380 | * Decodes the given address into its constituting prefix, type and hash. See [#encode()]{@link encode}. |
3381 | * | 3381 | * |
3382 | * @static | 3382 | * @static |
3383 | * @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'. | 3383 | * @param {string} address Address to decode. E.g.: 'bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a'. |
3384 | * @returns {object} | 3384 | * @returns {object} |
@@ -3416,14 +3416,14 @@ var ValidationError = validation.ValidationError; | |||
3416 | * | 3416 | * |
3417 | * @private | 3417 | * @private |
3418 | */ | 3418 | */ |
3419 | var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg']; | 3419 | var VALID_PREFIXES = ['bitcoincash', 'bchtest', 'bchreg', 'simpleledger', 'slptest']; |
3420 | 3420 | ||
3421 | /** | 3421 | /** |
3422 | * Checks whether a string is a valid prefix; ie., it has a single letter case | 3422 | * Checks whether a string is a valid prefix; ie., it has a single letter case |
3423 | * and is one of 'bitcoincash', 'bchtest', or 'bchreg'. | 3423 | * and is one of 'bitcoincash', 'bchtest', or 'bchreg', 'simpleledger' or 'slptest'. |
3424 | * | 3424 | * |
3425 | * @private | 3425 | * @private |
3426 | * @param {string} prefix | 3426 | * @param {string} prefix |
3427 | * @returns {boolean} | 3427 | * @returns {boolean} |
3428 | */ | 3428 | */ |
3429 | function isValidPrefix(prefix) { | 3429 | function isValidPrefix(prefix) { |
@@ -3435,7 +3435,7 @@ function isValidPrefix(prefix) { | |||
3435 | * of the address' checksum. | 3435 | * of the address' checksum. |
3436 | * | 3436 | * |
3437 | * @private | 3437 | * @private |
3438 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | 3438 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. |
3439 | * @returns {Uint8Array} | 3439 | * @returns {Uint8Array} |
3440 | */ | 3440 | */ |
3441 | function prefixToUint5Array(prefix) { | 3441 | function prefixToUint5Array(prefix) { |
@@ -3594,8 +3594,8 @@ function fromUint5Array(data) { | |||
3594 | * Returns the concatenation a and b. | 3594 | * Returns the concatenation a and b. |
3595 | * | 3595 | * |
3596 | * @private | 3596 | * @private |
3597 | * @param {Uint8Array} a | 3597 | * @param {Uint8Array} a |
3598 | * @param {Uint8Array} b | 3598 | * @param {Uint8Array} b |
3599 | * @returns {Uint8Array} | 3599 | * @returns {Uint8Array} |
3600 | * @throws {ValidationError} | 3600 | * @throws {ValidationError} |
3601 | */ | 3601 | */ |
@@ -3633,7 +3633,7 @@ function polymod(data) { | |||
3633 | /** | 3633 | /** |
3634 | * Verify that the payload has not been corrupted by checking that the | 3634 | * Verify that the payload has not been corrupted by checking that the |
3635 | * checksum is valid. | 3635 | * checksum is valid. |
3636 | * | 3636 | * |
3637 | * @private | 3637 | * @private |
3638 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. | 3638 | * @param {string} prefix Network prefix. E.g.: 'bitcoincash'. |
3639 | * @param {Uint8Array} payload Array of 5-bit integers containing the address' payload. | 3639 | * @param {Uint8Array} payload Array of 5-bit integers containing the address' payload. |
@@ -9012,6 +9012,21 @@ function toCashAddress (address) { | |||
9012 | } | 9012 | } |
9013 | 9013 | ||
9014 | /** | 9014 | /** |
9015 | * Translates the given address into SLP format. | ||
9016 | * @static | ||
9017 | * @param {string} address - A valid SLP address in any format. | ||
9018 | * @return {string} | ||
9019 | * @throws {InvalidAddressError} | ||
9020 | */ | ||
9021 | function toSlpAddress (address) { | ||
9022 | var decoded = decodeAddress(address) | ||
9023 | return encodeAsSlpaddr(decoded) | ||
9024 | } | ||
9025 | |||
9026 | |||
9027 | |||
9028 | |||
9029 | /** | ||
9015 | * Version byte table for base58 formats. | 9030 | * Version byte table for base58 formats. |
9016 | * @private | 9031 | * @private |
9017 | */ | 9032 | */ |
@@ -9125,7 +9140,7 @@ function decodeCashAddress (address) { | |||
9125 | } catch (error) { | 9140 | } catch (error) { |
9126 | } | 9141 | } |
9127 | } else { | 9142 | } else { |
9128 | var prefixes = ['bitcoincash', 'bchtest', 'regtest'] | 9143 | var prefixes = ['bitcoincash', 'bchtest', 'regtest', 'simpleledger', 'slptest'] |
9129 | for (var i = 0; i < prefixes.length; ++i) { | 9144 | for (var i = 0; i < prefixes.length; ++i) { |
9130 | try { | 9145 | try { |
9131 | var prefix = prefixes[i] | 9146 | var prefix = prefixes[i] |
@@ -9151,6 +9166,7 @@ function decodeCashAddressWithPrefix (address) { | |||
9151 | var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH | 9166 | var type = decoded.type === 'P2PKH' ? Type.P2PKH : Type.P2SH |
9152 | switch (decoded.prefix) { | 9167 | switch (decoded.prefix) { |
9153 | case 'bitcoincash': | 9168 | case 'bitcoincash': |
9169 | case 'simpleledger': | ||
9154 | return { | 9170 | return { |
9155 | hash: hash, | 9171 | hash: hash, |
9156 | format: Format.Cashaddr, | 9172 | format: Format.Cashaddr, |
@@ -9158,6 +9174,7 @@ function decodeCashAddressWithPrefix (address) { | |||
9158 | type: type | 9174 | type: type |
9159 | } | 9175 | } |
9160 | case 'bchtest': | 9176 | case 'bchtest': |
9177 | case 'slptest': | ||
9161 | case 'regtest': | 9178 | case 'regtest': |
9162 | return { | 9179 | return { |
9163 | hash: hash, | 9180 | hash: hash, |
@@ -9212,6 +9229,19 @@ function encodeAsCashaddr (decoded) { | |||
9212 | return cashaddr.encode(prefix, type, hash) | 9229 | return cashaddr.encode(prefix, type, hash) |
9213 | } | 9230 | } |
9214 | 9231 | ||
9232 | /** | ||
9233 | * Encodes the given decoded address into slp addr format. | ||
9234 | * @private | ||
9235 | * @param {object} decoded | ||
9236 | * @returns {string} | ||
9237 | */ | ||
9238 | function encodeAsSlpaddr (decoded) { | ||
9239 | var prefix = decoded.network === Network.Mainnet ? 'simpleledger' : 'slptest' | ||
9240 | var type = decoded.type === Type.P2PKH ? 'P2PKH' : 'P2SH' | ||
9241 | var hash = Uint8Array.from(decoded.hash) | ||
9242 | return cashaddr.encode(prefix, type, hash) | ||
9243 | } | ||
9244 | |||
9215 | /** | 9245 | /** |
9216 | * Returns a boolean indicating whether the address is in legacy format. | 9246 | * Returns a boolean indicating whether the address is in legacy format. |
9217 | * @static | 9247 | * @static |
@@ -9313,6 +9343,7 @@ module.exports = { | |||
9313 | toLegacyAddress: toLegacyAddress, | 9343 | toLegacyAddress: toLegacyAddress, |
9314 | toBitpayAddress: toBitpayAddress, | 9344 | toBitpayAddress: toBitpayAddress, |
9315 | toCashAddress: toCashAddress, | 9345 | toCashAddress: toCashAddress, |
9346 | toSlpAddress: toSlpAddress, | ||
9316 | isLegacyAddress: isLegacyAddress, | 9347 | isLegacyAddress: isLegacyAddress, |
9317 | isBitpayAddress: isBitpayAddress, | 9348 | isBitpayAddress: isBitpayAddress, |
9318 | isCashAddress: isCashAddress, | 9349 | isCashAddress: isCashAddress, |
@@ -9325,4 +9356,4 @@ module.exports = { | |||
9325 | 9356 | ||
9326 | }).call(this,require("buffer").Buffer) | 9357 | }).call(this,require("buffer").Buffer) |
9327 | },{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52) | 9358 | },{"bs58check":7,"buffer":8,"cashaddrjs":10}]},{},[52])(52) |
9328 | }); \ No newline at end of file | 9359 | }); |
diff --git a/src/js/index.js b/src/js/index.js index 8c23e61..057d709 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -952,6 +952,13 @@ | |||
952 | address = bchaddr.toBitpayAddress(address); | 952 | address = bchaddr.toBitpayAddress(address); |
953 | } | 953 | } |
954 | } | 954 | } |
955 | // Bitcoin Cash address format may vary | ||
956 | if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") { | ||
957 | var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val(); | ||
958 | if (bchAddrType == "cashaddr") { | ||
959 | address = bchaddr.toSlpAddress(address); | ||
960 | } | ||
961 | } | ||
955 | // Segwit addresses are different | 962 | // Segwit addresses are different |
956 | if (isSegwit) { | 963 | if (isSegwit) { |
957 | if (!segwitAvailable) { | 964 | if (!segwitAvailable) { |
@@ -1718,7 +1725,7 @@ | |||
1718 | network = bitcoinjs.bitcoin.networks.blocknode; | 1725 | network = bitcoinjs.bitcoin.networks.blocknode; |
1719 | setHdCoin(2941); | 1726 | setHdCoin(2941); |
1720 | }, | 1727 | }, |
1721 | }, | 1728 | }, |
1722 | { | 1729 | { |
1723 | name: "tBND - Blocknode Testnet", | 1730 | name: "tBND - Blocknode Testnet", |
1724 | onSelect: function() { | 1731 | onSelect: function() { |
@@ -2487,6 +2494,13 @@ | |||
2487 | }, | 2494 | }, |
2488 | }, | 2495 | }, |
2489 | { | 2496 | { |
2497 | name: "SLP - Simple Ledger Protocol", | ||
2498 | onSelect: function() { | ||
2499 | DOM.bitcoinCashAddressTypeContainer.removeClass("hidden"); | ||
2500 | setHdCoin(245); | ||
2501 | }, | ||
2502 | }, | ||
2503 | { | ||
2490 | name: "SLR - Solarcoin", | 2504 | name: "SLR - Solarcoin", |
2491 | onSelect: function() { | 2505 | onSelect: function() { |
2492 | network = bitcoinjs.bitcoin.networks.solarcoin; | 2506 | network = bitcoinjs.bitcoin.networks.solarcoin; |
diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 364349c..d71a61c 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js | |||
@@ -564,6 +564,15 @@ it('Allows selection of bitcoin cash', function(done) { | |||
564 | }; | 564 | }; |
565 | testNetwork(done, params); | 565 | testNetwork(done, params); |
566 | }); | 566 | }); |
567 | |||
568 | it('Allows selection of simpleledger(SLP)', function(done) { | ||
569 | var params = { | ||
570 | selectText: "SLP - Simple Ledger Protocol", | ||
571 | firstAddress: "simpleledger:qrtffz6ajfsn74gpur7y3epjquz42pvww5acewqmre", | ||
572 | }; | ||
573 | testNetwork(done, params); | ||
574 | }); | ||
575 | |||
567 | it('Allows selection of myriadcoin', function(done) { | 576 | it('Allows selection of myriadcoin', function(done) { |
568 | var params = { | 577 | var params = { |
569 | selectText: "XMY - Myriadcoin", | 578 | selectText: "XMY - Myriadcoin", |