new Crown address format. May not be elegant solution, but bitcoinjs has limitation...
authorPawel Cioch <pawel@greenhex.net>
Wed, 17 Apr 2019 04:17:16 +0000 (23:17 -0500)
committerPawel Cioch <pawel@greenhex.net>
Wed, 17 Apr 2019 04:17:16 +0000 (23:17 -0500)
src/js/bitcoinjs-extensions.js
src/js/index.js
tests/spec/tests.js

index 5347e83901557447323ee0b1108fa54775ac039a..e4eef0c1a7b9c59aba4db296599e5437ab4ebafd 100644 (file)
@@ -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 = {
index 057d7093402b8f7d47359608a0903add76f06f22..8262947a64aa82a967566e6549370dcbef5a83c8 100644 (file)
                         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();
                 setHdCoin(186);
             },
         },
+        {
+            name: "CRW - Crown (Legacy)",
+            onSelect: function() {
+                network = bitcoinjs.bitcoin.networks.crown;
+                setHdCoin(72);
+            },
+        },
         {
             name: "CRW - Crown",
             onSelect: function() {
index d71a61c9c1966a10b260d7a1d2157c1e30cae14e..a22d749e7ab05b1180a51a8e1ec18e218de7f339 100644 (file)
@@ -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);
 });