diff options
author | iancoleman <1281387+iancoleman@users.noreply.github.com> | 2019-04-23 09:01:11 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-23 09:01:11 +1000 |
commit | c4a09d67eb944be6536702f7a511f2601ec3e27e (patch) | |
tree | 37ff44938213a0fdc5dab82b0cf036ff73b1ffba | |
parent | 30d6779baae16a8290fea4c2859b98c73b377617 (diff) | |
parent | bf13c95fb0a800b8d40b2c8ee0826a49b17ccd7d (diff) | |
download | BIP39-c4a09d67eb944be6536702f7a511f2601ec3e27e.tar.gz BIP39-c4a09d67eb944be6536702f7a511f2601ec3e27e.tar.zst BIP39-c4a09d67eb944be6536702f7a511f2601ec3e27e.zip |
Merge pull request #317 from skironDotNet/Crown_new_address_format
new Crown public address format (priv key not changed)
-rw-r--r-- | src/js/bitcoinjs-extensions.js | 22 | ||||
-rw-r--r-- | src/js/index.js | 12 | ||||
-rw-r--r-- | tests/spec/tests.js | 9 |
3 files changed, 41 insertions, 2 deletions
diff --git a/src/js/bitcoinjs-extensions.js b/src/js/bitcoinjs-extensions.js index 5347e83..e4eef0c 100644 --- a/src/js/bitcoinjs-extensions.js +++ b/src/js/bitcoinjs-extensions.js | |||
@@ -39,7 +39,27 @@ bitcoinjs.bitcoin.networks.crown = { | |||
39 | }, | 39 | }, |
40 | pubKeyHash: 0x00, | 40 | pubKeyHash: 0x00, |
41 | scriptHash: 0x05, | 41 | scriptHash: 0x05, |
42 | wif: 0x80 | 42 | wif: 0x80, |
43 | toNewAddress: function(oldAddress) | ||
44 | { | ||
45 | var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' | ||
46 | var b58 = basex(ALPHABET); | ||
47 | |||
48 | var addrBytes = b58.decode(oldAddress); | ||
49 | |||
50 | var hash160 = new Uint16Array(23); | ||
51 | hash160[0]= 0x01; //C | ||
52 | hash160[1]= 0x75; //R | ||
53 | hash160[2]= 0x07; //W | ||
54 | addrBytes.copy(hash160, 3, 1, 21); | ||
55 | |||
56 | var checksum = bitcoinjs.bitcoin.crypto.hash256(hash160).subarray(0, 4); | ||
57 | var binaryAddr = new Uint16Array(27); | ||
58 | binaryAddr.set(hash160,0); | ||
59 | checksum.copy(binaryAddr, 23, 0, 4); | ||
60 | var newAddress = b58.encode(binaryAddr); | ||
61 | return newAddress; | ||
62 | } | ||
43 | }; | 63 | }; |
44 | 64 | ||
45 | bitcoinjs.bitcoin.networks.dash = { | 65 | bitcoinjs.bitcoin.networks.dash = { |
diff --git a/src/js/index.js b/src/js/index.js index 057d709..8262947 100644 --- a/src/js/index.js +++ b/src/js/index.js | |||
@@ -977,6 +977,11 @@ | |||
977 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) | 977 | address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) |
978 | } | 978 | } |
979 | } | 979 | } |
980 | |||
981 | if ((networks[DOM.network.val()].name == "CRW - Crown")) { | ||
982 | address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address); | ||
983 | } | ||
984 | |||
980 | addAddressToList(indexText, address, pubkey, privkey); | 985 | addAddressToList(indexText, address, pubkey, privkey); |
981 | if (isLast) { | 986 | if (isLast) { |
982 | hidePending(); | 987 | hidePending(); |
@@ -1875,6 +1880,13 @@ | |||
1875 | }, | 1880 | }, |
1876 | }, | 1881 | }, |
1877 | { | 1882 | { |
1883 | name: "CRW - Crown (Legacy)", | ||
1884 | onSelect: function() { | ||
1885 | network = bitcoinjs.bitcoin.networks.crown; | ||
1886 | setHdCoin(72); | ||
1887 | }, | ||
1888 | }, | ||
1889 | { | ||
1878 | name: "CRW - Crown", | 1890 | name: "CRW - Crown", |
1879 | onSelect: function() { | 1891 | onSelect: function() { |
1880 | network = bitcoinjs.bitcoin.networks.crown; | 1892 | network = bitcoinjs.bitcoin.networks.crown; |
diff --git a/tests/spec/tests.js b/tests/spec/tests.js index d71a61c..a22d749 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js | |||
@@ -474,8 +474,15 @@ it('Allows selection of clam', function(done) { | |||
474 | }); | 474 | }); |
475 | it('Allows selection of crown', function(done) { | 475 | it('Allows selection of crown', function(done) { |
476 | var params = { | 476 | var params = { |
477 | selectText: "CRW - Crown (Legacy)", | ||
478 | firstAddress: "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5", | ||
479 | }; | ||
480 | testNetwork(done, params); | ||
481 | }); | ||
482 | it('Allows selection of crown', function(done) { | ||
483 | var params = { | ||
477 | selectText: "CRW - Crown", | 484 | selectText: "CRW - Crown", |
478 | firstAddress: "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5", | 485 | firstAddress: "CRWKnVmVhvH1KWTYe6sq8xV4dFGcFpBEEkPQ", |
479 | }; | 486 | }; |
480 | testNetwork(done, params); | 487 | testNetwork(done, params); |
481 | }); | 488 | }); |