浏览代码

Complete 1st HUSH CoinJoin.

Shomari 1 月之前
父节点
当前提交
7d3cb67db6
共有 4 个文件被更改,包括 34 次插入57 次删除
  1. 2 2
      web/handlers/buildSharedTx.ts
  2. 2 2
      web/handlers/signSharedTx.ts
  3. 28 51
      web/server/routes/v1.post.ts
  4. 2 2
      web/stores/wallet/signFusion.ts

+ 2 - 2
web/handlers/buildSharedTx.ts

@@ -71,10 +71,10 @@ console.log('DO WE HAVE FUSION INPUTS??', this.fusionInputs)
     // console.log('OUR INPUTS INDEX', ownedInputs)
 
     /* Set protocol ID. */
-    protocolId = '1337'
+    protocolId = 'HUSH'
 
     /* Set protocol message. */
-    msg = 'FINAL!'
+    msg = 'f35a93da-237c-5dba-a1e9-96d109bc10e0'
 
     script = [
         utf8ToBin(protocolId),

+ 2 - 2
web/handlers/signSharedTx.ts

@@ -72,10 +72,10 @@ console.log('DO WE HAVE FUSION INPUTS??', this.fusionInputs)
     // console.log('OUR INPUTS INDEX', ownedInputs)
 
     /* Set protocol ID. */
-    protocolId = '1337'
+    protocolId = 'HUSH'
 
     /* Set protocol message. */
-    msg = 'FINAL!'
+    msg = 'f35a93da-237c-5dba-a1e9-96d109bc10e0'
 
     script = [
         utf8ToBin(protocolId),

+ 28 - 51
web/server/routes/v1.post.ts

@@ -23,11 +23,8 @@ export default defineEventHandler(async (event) => {
     /* Initialize locals. */
     let componentid
     let components
-    let params
     let profile
     let response
-    let session
-    let success
     let unlocked
 
     /* Set database. */
@@ -53,19 +50,13 @@ export default defineEventHandler(async (event) => {
     const actionid = body.actionid
     // console.log('ACTION ID', actionid)
 
-    // const sessionid = body.sessionid
-    // console.log('SESSION ID', sessionid)
-
-    // const rawTx = body.rawTx
-    // console.log('RAW TRANSACTION', rawTx)
-
     /* Validate components. */
     if (body.components) {
         components = body.components
         components = decryptForPubkey(binToHex(Wallet.privateKey), components)
         components = binToUtf8(components)
         components = JSON.parse(components)
-        console.log('COMPONENTS', components)
+        // console.log('COMPONENTS', components)
     }
 
     /* Validate unlocked. */
@@ -74,7 +65,7 @@ export default defineEventHandler(async (event) => {
         unlocked = decryptForPubkey(binToHex(Wallet.privateKey), unlocked)
         unlocked = binToUtf8(unlocked)
         unlocked = JSON.parse(unlocked)
-        console.log('UNLOCKED', unlocked)
+        // console.log('UNLOCKED', unlocked)
     }
 
     /* Validate auth ID. */
@@ -94,11 +85,6 @@ console.log('FUSION', fusion)
 
     /* Validate profile id. */
     if (typeof profile === 'undefined' || profile === null) {
-        /* Set status code. */
-        // setResponseStatus(event, 404)
-
-        // return 'Oops! Something went wrong..'
-
         /* Build profile. */
         profile = {
             _id: authid,
@@ -131,8 +117,7 @@ console.log('FUSION', fusion)
         return 'Oops! Authorization failed!'
     }
 
-
-
+    /* Handle component unlocking. */
     if (actionid === 'unlock-components') {
         /* Update progress. */
         // fusion.progress = 75.5
@@ -141,42 +126,34 @@ console.log('FUSION', fusion)
         fusion.updatedAt = moment().unix()
 
         console.log('***UNLOCK COMPONENT(S)***', unlocked)
-        // await Db.put('fusions', '4e9654f9-3de9-4f9a-8169-3834f40847f5', fusion)
 
         const inputs = fusion.inputs
         console.log('INPUTS', inputs)
 
         /* Handle inputs. */
-        Object.keys(inputs).forEach(_outpoint => {
-console.log('OUTPOINT', _outpoint)
-
-            /* Add unlocking script to input. */
-            inputs[_outpoint].unlocking = unlocked[_outpoint].unlocking
-
-//             /* Handle unlocked (scripts). */
-//             Object.keys(unlocked).forEach(_lockpoint => {
-// console.log('LOCKPOINT', _lockpoint)
-//                 const unlock = unlocked[_lockpoint]
-// console.log('UNLOCK', unlock)
-//                 /* Validate transaction hash. */
-//                 if (inputs[_outpoint].tx_hash === unlock.tx_hash) {
-// console.log('FOUND A MATCH', unlock.tx_hash)
-//                     /* Set unlocking script. */
-//                     inputs[_outpoint].unlocking = unlock.unlocking
-//                 }
-//             })
-        })
-console.log('UPDATED FUSION', fusion)
-        return 'almost there...'
-    }
+        for (let i = 0; i < Object.keys(inputs).length; i++) {
+            const outpoint = Object.keys(inputs)[i]
+            console.log('UNLOCKING OUTPOINT', outpoint)
 
+            const input = inputs[outpoint]
+            console.log('UNLOCKING INPUT', input)
+
+// FIXME WE MUST VALIDATE THE OUTPOINT AUTH BEFORE UPDATING...
+            if (unlocked && unlocked[outpoint] && unlocked[outpoint].unlocking) {
+                /* Add unlocking script to input. */
+                input.unlocking = unlocked[outpoint].unlocking
+            }
+        }
+        console.log('UPDATED FUSION', fusion)
+
+        return fusion
+    }
 
     fusion.numGuests = Object.keys(fusion.guests).length
 
     /* Update progress. */
     fusion.progress = 12.5
 
-
     components.forEach(_component => {
         /* Validate inputs. */
         if (_component.tx_hash) {
@@ -198,17 +175,17 @@ console.log('UPDATED FUSION', fusion)
 
     fusion.numOutputs = Object.keys(fusion.outputs).length
 
-/* Calculate session contents. */
-const sessionContents = JSON.stringify({ ...fusion.inputs, ...fusion.outputs })
-// console.log('SESSION CONTENTS', sessionContents)
+    /* Calculate session contents. */
+    const sessionContents = JSON.stringify({ ...fusion.inputs, ...fusion.outputs })
+    // console.log('SESSION CONTENTS', sessionContents)
 
-/* Calculate (UUIDv5) session hash. */
-const sessionHash = sha256(sessionContents)
-// console.log('SESSION HASH', sessionHash)
+    /* Calculate (UUIDv5) session hash. */
+    const sessionHash = sha256(sessionContents)
+    // console.log('SESSION HASH', sessionHash)
 
-/* Calculate session ID. */
-const sessionid = uuidv5(sessionHash, HUSH_NAMESPACE)
-// console.log('SESSION (uuid v5)', sessionid)
+    /* Calculate session ID. */
+    const sessionid = uuidv5(sessionHash, HUSH_NAMESPACE)
+    // console.log('SESSION (uuid v5)', sessionid)
 
     /* Set session ID. */
     fusion.sessionid = sessionid

+ 2 - 2
web/stores/wallet/signFusion.ts

@@ -119,8 +119,8 @@ export default async function () {
 
     transaction.ins.forEach(_input => {
 console.log('INS (input)', _input)
-        /* Validate (unlocked) script. */
-        if (_input.script) {
+        /* Validate (unlocking) script. */
+        if (_input.script.length > 0) {
             outpoint = sha256(binToHex(_input.hash.reverse()) + ':' + _input.index)
             console.log('INS (outpoint)', outpoint)