浏览代码

Re-order WIFs for sorted inputs.

Shomari 1 月之前
父节点
当前提交
b048526b32
共有 2 个文件被更改,包括 46 次插入21 次删除
  1. 32 20
      web/handlers/signSharedTx.ts
  2. 14 1
      web/stores/wallet/completeFusion.ts

+ 32 - 20
web/handlers/signSharedTx.ts

@@ -7,6 +7,10 @@ import { utf8ToBin } from '@nexajs/utils'
 
 const bchjs = new BCHJS()
 
+/* Initialize constants. */
+const HUSH_PROTOCOL_ID = 0x48555348
+
+
 /**
  * Build Shared Transaction
  *
@@ -18,9 +22,10 @@ console.log('SIGN SHARED TX', _sessionid, _inputs, _outputs)
     let accountIdx
     let addressIdx
     let changeIdx
-    let chidleNode
+    let childNode
     let data
     let ecPair
+    let hushIndexes
     let ownedInputs
     let protocolId
     let msg
@@ -78,33 +83,40 @@ console.log('SIGN SHARED TX', _sessionid, _inputs, _outputs)
     /* Generate master node. */
     const masterNode = bchjs.HDNode.fromSeed(seedBuffer)
 
-/* Set account index. */
-accountIdx = 0
-/* Set change index. */
-changeIdx = 0
-/* Set address index. */
-addressIdx = 0
-
-    /* Generate child node. */
-    chidleNode = masterNode
-        .derivePath(`m/44'/145'/${accountIdx}'/${changeIdx}/${addressIdx}`)
-
-    /* Generate wallet import format (WIF). */
-    wif = bchjs.HDNode.toWIF(chidleNode)
-    // console.log('BCH WIF', wif)
-
-    /* Generate elliptic pair. */
-    ecPair = bchjs.ECPair.fromWIF(wif)
-
 // FIXME Identify our owned inputs.
 ownedInputs = [ 0, 1, 2, 3, 4, 5, 6 ]
-
+// hushIndexes = [ 0, 1, 2, 3, 4, 5, 6 ]
+// 0 - L58m5XW3cYG84ZN5Cbqqap7Mvx1TihNNMPSq7Vw9W7t3oHeuS36q
+// 1 - L2qsjy4xprtF2hocseepEtKM3V6y5hHjvkX5K7zedeBjmd6forbb
+// 2 - L4FmiWogy4THbosEUHbfLgxgTQpZ1e4dFDrAoik2fvoQ9TNKCsRe
     for (let i = 0; i < _inputs.length; i++) {
         /* Verify input ownership. */
         if (!ownedInputs.includes(i)) {
             continue
         }
 
+        /* Set account index. */
+        // accountIdx = 0
+        accountIdx = HUSH_PROTOCOL_ID
+        /* Set change index. */
+        changeIdx = 0
+        /* Set address index. */
+        // addressIdx = 0
+        // addressIdx = hushIndexes[i]
+        addressIdx = _inputs[i].address_idx
+        console.log('ADDRESS IDX')
+
+        /* Generate child node. */
+        childNode = masterNode
+            .derivePath(`m/44'/145'/${accountIdx}'/${changeIdx}/${addressIdx}`)
+
+        /* Generate wallet import format (WIF). */
+        wif = bchjs.HDNode.toWIF(childNode)
+        // console.log('BCH WIF', i, wif)
+
+        /* Generate elliptic pair. */
+        ecPair = bchjs.ECPair.fromWIF(wif)
+console.log('PARAMS', i, redeemScript, _inputs[i].value)
         /* Sign (our own) input. */
         transactionBuilder.sign(
             i,

+ 14 - 1
web/stores/wallet/completeFusion.ts

@@ -43,8 +43,21 @@ export default async function () {
 
     /* Handle (input) keys. */
     keys.forEach(_keyid => {
+        /* Set input. */
+        const input = inputs[_keyid]
+        console.log('HANDLE INPUT', input)
+
+        /* Find address index for input. */
+        for (let i = 0; i < this.fusionInputs.length; i++) {
+            if (this.fusionInputs[i].address === input.address) {
+                input.address_idx = i
+                console.log('ADDRESS INDEX', i)
+                break
+            }
+        }
+
         /* Add input. */
-        sortedInputs.push(inputs[_keyid])
+        sortedInputs.push(input)
     })
     // console.log('INPUTS (sorted)', sortedInputs)