From bf13c95fb0a800b8d40b2c8ee0826a49b17ccd7d Mon Sep 17 00:00:00 2001 From: Pawel Cioch Date: Tue, 16 Apr 2019 23:17:16 -0500 Subject: new Crown address format. May not be elegant solution, but bitcoinjs has limitation of network prefix length and I don't want to modify it. This approach is isolated and does not affect others --- src/js/bitcoinjs-extensions.js | 22 +++++++++++++++++++++- src/js/index.js | 12 ++++++++++++ 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 = { }, 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 = { 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 @@ 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(); @@ -1874,6 +1879,13 @@ setHdCoin(186); }, }, + { + name: "CRW - Crown (Legacy)", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.crown; + setHdCoin(72); + }, + }, { name: "CRW - Crown", onSelect: function() { 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 @@ -472,10 +472,17 @@ it('Allows selection of clam', function(done) { }; testNetwork(done, params); }); +it('Allows selection of crown', function(done) { + var params = { + selectText: "CRW - Crown (Legacy)", + firstAddress: "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5", + }; + testNetwork(done, params); +}); it('Allows selection of crown', function(done) { var params = { selectText: "CRW - Crown", - firstAddress: "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5", + firstAddress: "CRWKnVmVhvH1KWTYe6sq8xV4dFGcFpBEEkPQ", }; testNetwork(done, params); }); -- cgit v1.2.3