Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Oct 17, 2023
1 parent dc20e03 commit ec24419
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/lib/contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DEFAULT_DEADLINE } from '../config.js'
import { create_txhex } from './tx.js'
import { now } from './util.js'
import { DEFAULT_DEADLINE } from '../config.js'
import { init_vm } from '../vm/main.js'

import {
Expand Down Expand Up @@ -84,8 +85,9 @@ export function get_spend_outputs (
const path_names = get_path_names(paths)
const outputs : SpendOutput[] = []
for (const name of path_names) {
const vouts = get_path_vouts(name, paths, total_fees)
outputs.push([ name, vouts ])
const vout = get_path_vouts(name, paths, total_fees)
const txhex = create_txhex(vout)
outputs.push([ name, txhex ])
}
return outputs
}
4 changes: 2 additions & 2 deletions src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@cmdcode/musig2'

import {
TxOutput,
TxBytes,
TxPrevout
} from '@scrow/tapscript'

Expand Down Expand Up @@ -83,7 +83,7 @@ export function get_mutex_entries (

export function get_mutex_ctx (
context : DepositContext,
output : TxOutput[],
output : TxBytes,
pnonces : Bytes[],
sid : Bytes,
txinput : TxPrevout
Expand Down
15 changes: 5 additions & 10 deletions src/lib/spend.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@

import { combine_psigs } from '@cmdcode/musig2'
import { create_tx } from '@scrow/tapscript/tx'
import { TxData } from '@scrow/tapscript'
import { decode_tx } from '@scrow/tapscript/tx'
import { get_deposit_ctx } from './deposit.js'
import { Signer } from '../signer.js'
import { get_entry } from './util.js'

import {
TxData,
TxPrevout
} from '@scrow/tapscript'

import {
create_path_psig,
get_mutex_ctx
Expand All @@ -33,14 +29,13 @@ export function create_settlment (
const { outputs, session } = contract
const output = outputs.find(e => e[0] === pathname)
assert.exists(output)
const vin : TxPrevout[] = []
const vout = output[1]
const tx = decode_tx(output[1], false)
for (const fund of deposits) {
const txin = fund.txinput
const sig = sign_txinput(agent, fund, output, session)
vin.push({ ...txin, witness : [ sig ] })
tx.vin.push({ ...txin, witness : [ sig ] })
}
return create_tx({ vin, vout })
return tx
}

export function sign_txinput (
Expand Down
14 changes: 11 additions & 3 deletions src/lib/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
create_tx,
encode_tx,
parse_tx,
parse_txid
parse_txid,
decode_tx
} from '@scrow/tapscript/tx'

import {
Expand Down Expand Up @@ -76,11 +77,18 @@ export function get_signed_tx (
return encode_tx(txdata)
}

export function create_txhex (
vout : TxOutput[]
) {
const txdata = create_tx({ vout })
return encode_tx(txdata).hex
}

export function create_sighash (
txinput : TxInput,
vout : TxOutput[]
txbytes : TxBytes
) {
const txdata = create_tx({ vout })
const txdata = decode_tx(txbytes, false)
return taproot.hash_tx(txdata, { sigflag : 0x81, txinput }).hex
}

Expand Down
3 changes: 1 addition & 2 deletions src/schema/contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { z } from 'zod'
import { proposal } from './proposal.js'
import { vout } from './tx.js'

import * as base from './base.js'

Expand All @@ -13,7 +12,7 @@ const status = z.enum([ 'published', 'active', 'closed', 'canceled', 'expired' ]

const vm_status = z.enum([ 'init', 'open', 'hold', 'disputed', 'closed' ])

const output = z.tuple([ label, vout.array() ])
const output = z.tuple([ label, hex ])

const session = z.object({
agent_id : hash,
Expand Down
4 changes: 2 additions & 2 deletions src/types/contract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TxOutput } from '@scrow/tapscript'
import { TxBytes } from '@scrow/tapscript'
import { AgentSession } from './session.js'
import { ContractState } from './vm.js'

Expand All @@ -11,7 +11,7 @@ export type ContractStatus = 'published' | 'active' | 'closed' | 'canceled' | 'e

export type SpendOutput = [
label : string,
vout : TxOutput[]
txhex : TxBytes
]

export interface ContractConfig {
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './base.js'
export * from './contract.js'
export * from './deposit.js'
export * from './proof.js'
export * from './proposal.js'
export * from './session.js'
export * from './signer.js'
Expand Down
19 changes: 19 additions & 0 deletions src/types/proof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Literal } from './base.js'

export interface ProofData {
ref : string
pub : string
pid : string
sig : string
params : string[][]
}

export interface SignedEvent {
pubkey : string
created_at : number
id : string
sig : string
kind : number
content : string
tags : Literal[][]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": ["node_modules", "test"],
"include": ["src/**/*.ts"]
"exclude": [ "dist", "node_modules", "test" ],
"include": [ "src/**/*.ts" ]
}
11 changes: 10 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,16 @@
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.1.4.tgz#482022c71466e653aa6e1afc7a8323298743609b"
integrity sha512-ANFqWYPwkhIqPmXw8vm0GpBEHiPpqcm99jiiAp71DbCSqLDhrtr019C5vhD0Bw4My+LmMvciZq6IsWHqQpl2ZQ==

"@scrow/tapscript@2.0.24", "@scrow/tapscript@^2.0.17":
"@scrow/tapscript@2.0.25":
version "2.0.25"
resolved "https://registry.yarnpkg.com/@scrow/tapscript/-/tapscript-2.0.25.tgz#f60deffda0cd628665a39fee0967d4cb4b2ffb76"
integrity sha512-oRUjJUrR5Cpdfk6tPIidFhzdETXo6MBlkBvH6V8XFrtAsCzscIJ7ImpQWUpr8O8xM/KgYBdAJTXZrn/1bZSqMA==
dependencies:
"@cmdcode/buff" "^2.0.4"
"@cmdcode/crypto-tools" "^2.5.1"
zod "^3.22.2"

"@scrow/tapscript@^2.0.17":
version "2.0.24"
resolved "https://registry.yarnpkg.com/@scrow/tapscript/-/tapscript-2.0.24.tgz#02b84db85ce92ab169981cee9864d1bc2b277fab"
integrity sha512-9wzQcaU0aw3U7UT2kdvbSunsmKo7p6UJ0TEn88yZ+YK1LbxAPtjZx+XSPsBTClLXhjXe9sjj+O8lJx5bAoku9w==
Expand Down

0 comments on commit ec24419

Please sign in to comment.