Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit ac10ac9

Browse files
author
cmd
committed
update
1 parent efe93de commit ac10ac9

File tree

5 files changed

+28
-39
lines changed

5 files changed

+28
-39
lines changed

src/schema/deposit.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@ const covenant = z.object({
4343
psigs : z.tuple([ str, psig ]).array()
4444
})
4545

46-
const account_req = z.object({
46+
const acct_req = z.object({
4747
deposit_pk : hash,
4848
locktime : locktime.optional(),
4949
spend_xpub : str
5050
})
5151

52-
const register_req = z.object({
52+
const reg_req = z.object({
5353
covenant : covenant.optional(),
5454
deposit_pk : hash,
5555
return_psig : hex.optional(),
5656
sequence : num,
57-
spend_xpub : str
57+
spend_xpub : str,
58+
utxo : txspend
5859
})
5960

6061
const data = z.object({
@@ -72,4 +73,4 @@ const data = z.object({
7273
updated_at : stamp
7374
}).and(state).and(spend_state).and(close_state).and(txspend)
7475

75-
export default { account, covenant, data, state, account_req, register_req, status }
76+
export default { account, covenant, data, state, acct_req, reg_req, status }

src/types/deposit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface RegisterRequest {
9898
return_psig ?: string
9999
sequence : number
100100
spend_xpub : string
101+
utxo : TxOutput
101102
}
102103

103104
export interface ExtendedKey {

src/validators/deposit.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { taproot } from '@scrow/tapscript/sighash'
1+
import { parse_script } from '@scrow/tapscript/script'
22
import { parse_sequence } from '@scrow/tapscript/tx'
33

44
import {
55
DepositContext,
66
DepositData,
77
RegisterRequest,
8-
ReturnContext,
98
TxOutput
109
} from '../types/index.js'
1110

@@ -15,13 +14,13 @@ import * as schema from '../schema/index.js'
1514
export function validate_account_req (
1615
template : unknown
1716
) : asserts template is RegisterRequest {
18-
schema.deposit.account_req.parse(template)
17+
schema.deposit.acct_req.parse(template)
1918
}
2019

2120
export function validate_register_req (
2221
template : unknown
2322
) : asserts template is RegisterRequest {
24-
schema.deposit.register_req.parse(template)
23+
schema.deposit.reg_req.parse(template)
2524
}
2625

2726
export function validate_deposit (
@@ -32,25 +31,14 @@ export function validate_deposit (
3231

3332
export function verify_deposit (
3433
deposit_ctx : DepositContext,
35-
return_ctx : ReturnContext,
36-
txout : TxOutput
34+
utxo : TxOutput
3735
) {
3836
// Unpack our transaction template.
3937
const { sequence, tap_data } = deposit_ctx
40-
const { pubkey, tapkey, tx } = return_ctx
41-
const { txid, vout, value, scriptkey } = txout
42-
// Assert that the sequence value is valid.
43-
const sdata = parse_sequence(sequence)
44-
assert.ok(sdata.enabled, 'Sequence field timelock is not enabled.')
45-
assert.ok(sdata.type === 'stamp', 'Sequence field is not configured for timelock.')
46-
// Get the deposit context.
47-
assert.ok(tap_data.tapkey === tapkey, 'Deposit tapkey does not match return tapkey!')
48-
// Prepare recovery tx for signature verification.
49-
const opt = { pubkey, txindex : 0, throws : true }
50-
const txin = tx.vin[0]
51-
assert.ok(txin.txid === txid, 'recovery txid does not match utxo')
52-
assert.ok(txin.vout === vout, 'recovery vout does not match utxo')
53-
tx.vin[0].prevout = { value : BigInt(value), scriptPubKey : scriptkey }
54-
// Assert that the recovery tx is fully valid for broadcast.
55-
taproot.verify_tx(tx, opt)
38+
const { scriptkey } = utxo
39+
const sdata = parse_sequence(sequence)
40+
const tapkey = parse_script(scriptkey).asm[1]
41+
assert.ok(sdata.enabled, 'sequence field timelock is not enabled.')
42+
assert.ok(sdata.type === 'stamp', 'sequence field is not configured for timelock.')
43+
assert.ok(tapkey === tap_data.tapkey, 'utxo scriptkey does not match tapkey')
5644
}

test/src/tests/e2e.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import {
3737
verify_covenant,
3838
validate_register_req,
3939
verify_witness,
40-
validate_witness
40+
validate_witness,
41+
verify_deposit
4142
} from '@scrow/core/validate'
4243

4344
import { PaymentEntry } from '@/types/index.js'
@@ -92,23 +93,21 @@ export default async function (client : CoreClient, tape : Test) {
9293
const registrations = await register_funds(contract, members)
9394

9495
const promises = registrations.map(async tmpl => {
95-
const { utxo, ...template } = tmpl
96-
const { deposit_pk, sequence, spend_xpub } = template
96+
const { covenant, deposit_pk, sequence, spend_xpub, utxo } = tmpl
9797
const { txid, vout } = utxo
98-
validate_register_req(template)
99-
const agent_id = agent.signer.id
98+
validate_register_req(tmpl)
10099
const agent_pk = agent.signer.pubkey
101100
const return_pk = parse_extkey(spend_xpub).pubkey
102101
const dep_ctx = get_deposit_ctx(agent_pk, deposit_pk, return_pk, sequence)
103102
const tx_data = await client.get_txinput(txid, vout)
104103
assert.ok(tx_data !== null, 'there is no tx data')
105-
const spendout = prevout_to_txspend(tx_data.txinput)
106-
// verify_deposit(dep_ctx, return_ctx, spendout)
107-
const dpid = Buff.random(32).hex
108-
const state = get_spend_state(sequence, tx_data.status)
109-
const session = create_session(agent.signer, dpid)
110-
const agent_pn = session.agent_pn
111-
const deposit = create_deposit({ ...dep_ctx, dpid, agent_id, agent_pn, ...template, ...spendout, ...state })
104+
const spendout = prevout_to_txspend(tx_data.txinput)
105+
verify_deposit(dep_ctx, utxo)
106+
const dpid = Buff.random(32).hex
107+
const state = get_spend_state(sequence, tx_data.status)
108+
const session = create_session(agent.signer, dpid)
109+
const full_ctx = { ...dep_ctx, ...session, ...spendout, ...state }
110+
const deposit = create_deposit({ ...full_ctx, covenant, dpid, spend_xpub })
112111
// const deposit = register_deposit(dep_ctx, dpid, pnonce, tmpl, spendout, state)
113112
verify_covenant(dep_ctx, contract, deposit, agent.signer, agent.signer)
114113
return deposit

test/tape.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import e2e_test from './src/tests/e2e.test.js'
55
import vm_test from './src/vm/vm.test.js'
66

77
tape('Escrow Core Test Suite', async t => {
8-
vm_test(t)
8+
// vm_test(t)
99
const core = get_daemon()
1010
const client = await core.startup()
1111
await e2e_test(client, t)

0 commit comments

Comments
 (0)