Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Feb 10, 2024
1 parent 92e2ce3 commit ce34191
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 112 deletions.
18 changes: 0 additions & 18 deletions demo/client/alice/00_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Buff } from '@cmdcode/buff'

import {
EscrowSigner,
RoleTemplate,
WitnessTemplate,
create_policy,
} from '@scrow/core'
Expand All @@ -11,21 +10,8 @@ import { config } from '@scrow/demo/00_demo_config.js'

/** ========== [ USER CONFIG ] ========== **/

const SECRET_PASS : string = 'test_draft3'

const USER_ALIAS : string = 'alice'

const ROLE_POLICY : RoleTemplate = {
title : 'buyer',
paths : [
[ 'return', 10000 ]
],
programs : [
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', '*', 1 ]
]
}

const FUND_AMOUNT : number = 15_000

const WIT_STATEMENT : WitnessTemplate = {
Expand All @@ -37,12 +23,8 @@ const WIT_STATEMENT : WitnessTemplate = {
/** ========== [ MAIN EXPORT ] ========== **/

export const alias = USER_ALIAS
// Compute secret id for nostr session.
export const secret_id = Buff.str(SECRET_PASS).digest.hex
// Derive signing device from the user alias.
export const signer = EscrowSigner.import(config).from_phrase(USER_ALIAS)
// Define a role policy for yourself.
export const policy = create_policy(ROLE_POLICY)
// Export the funding amount.
export const fund_amt = FUND_AMOUNT
// Export the witness template.
Expand Down
12 changes: 0 additions & 12 deletions demo/client/bob/00_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ const SECRET_PASS : string = 'test_draft3'

const USER_ALIAS : string = 'bob'

const ROLE_POLICY : RoleTemplate = {
title : 'seller',
paths : [
[ 'payout', 10000 ]
],
payment : 2000,
programs : [
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', '*', 1 ]
]
}

const FUND_AMOUNT : number = 15_000

const WIT_STATEMENT : WitnessTemplate = {
Expand Down
57 changes: 0 additions & 57 deletions demo/client/escrow/00_config.ts

This file was deleted.

53 changes: 53 additions & 0 deletions demo/client/terms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { EscrowSigner, ProposalTemplate, RoleTemplate, create_policy, create_proposal } from "@/index.js"
import { Buff } from "@cmdcode/buff"
import { config } from "../00_demo_config.js"
import { create_draft } from "@/lib/proposal.js"

const AGENT_ALIAS : string = 'carol'
const SECRET_PASS : string = 'test_draft4'

const PROP_TEMPLATE : ProposalTemplate = {
title : 'Basic two-party contract with third-party arbitration.',
duration : 14400,
schedule : [[ 7200, 'close|resolve', '*' ]],
value : 15000,
}

const PROP_ROLES : RoleTemplate[] = [
{
title : 'buyer',
paths : [
[ 'return', 10000 ]
],
programs : [
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', '*', 1 ]
]
},
{
title : 'seller',
paths : [
[ 'payout', 10000 ]
],
payment : 2000,
programs : [
[ 'endorse', 'close', '*', 2 ],
[ 'endorse', 'dispute', '*', 1 ]
]
},
]

export const alias = AGENT_ALIAS
// Compute draft id for nostr store.
export const secret_id = Buff.str(SECRET_PASS).digest.hex
// Derive signing device from the user alias.
export const signer = EscrowSigner.import(config).from_phrase(AGENT_ALIAS)
//
export const draft = create_draft({
proposal : create_proposal({
...PROP_TEMPLATE,
network : config.network,
moderator : signer.pubkey
}),
roles : PROP_ROLES.map(e => create_policy(e))
})
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"import": "./dist/assert.js",
"types": "./dist/assert.d.ts"
},
"./client": {
"import": "./dist/lib/client.js",
"types": "./dist/lib/client.d.ts"
},
"./contract": {
"import": "./dist/lib/contract.js",
"types": "./dist/lib/contract.d.ts"
Expand Down
35 changes: 10 additions & 25 deletions test/plat/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,16 @@
</head>
<body>
<script>
const { lib } = window.escrow_core
const prop = lib.proposal.create_proposal({
title : 'Basic two-party contract with third-party dispute resolution.',
expires : 14400,
details : 'n/a',
network : 'regtest',
paths: [
[ 'payout', 90000, 'bcrt1p4pks09mtefdk96nhnk7y6j4shp9z86qqw2rzsuvq6gfurtsmx9ksn04zpc' ],
[ 'return', 90000, 'bcrt1p4pks09mtefdk96nhnk7y6j4shp9z86qqw2rzsuvq6gfurtsmx9ksn04zpc' ]
],
payments : [
[ 10000, 'bcrt1p4pks09mtefdk96nhnk7y6j4shp9z86qqw2rzsuvq6gfurtsmx9ksn04zpc' ]
],
programs : [
[ "dispute", "*", "proof", 1, "9997a497d964fc1a62885b05a51166a65a90df00492c8d7cf61d6accf54803be" ],
[ "resolve", "*", "proof", 1, "9094567ba7245794198952f68e5723ac5866ad2f67dd97223db40e14c15b092e" ],
[ "close|resolve", "*", "proof", 2, "9997a497d964fc1a62885b05a51166a65a90df00492c8d7cf61d6accf54803be", "4edfcf9dfe6c0b5c83d1ab3f78d1b39a46ebac6798e08e19761f5ed89ec83c10" ]
],
schedule: [
[ 7200, 'close', 'payout|return' ]
],
value : 100000,
version : 1
})
console.log('proposal:', prop)
const { lib, EscrowClient } = window.escrow_core

const config = {
hostname : 'https://bitescrow-mutiny.vercel.app',
oracle : 'https://mutinynet.com',
network : 'mutiny'
}

const client = new EscrowClient(config)
console.log('client:', client)
</script>
</body>
</html>

0 comments on commit ce34191

Please sign in to comment.