diff --git a/demo/client/alice/00_config.ts b/demo/client/alice/00_config.ts index e345dcc9..da4259f0 100644 --- a/demo/client/alice/00_config.ts +++ b/demo/client/alice/00_config.ts @@ -2,7 +2,6 @@ import { Buff } from '@cmdcode/buff' import { EscrowSigner, - RoleTemplate, WitnessTemplate, create_policy, } from '@scrow/core' @@ -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 = { @@ -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. diff --git a/demo/client/bob/00_config.ts b/demo/client/bob/00_config.ts index 49c02ef3..ed29173e 100644 --- a/demo/client/bob/00_config.ts +++ b/demo/client/bob/00_config.ts @@ -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 = { diff --git a/demo/client/escrow/00_config.ts b/demo/client/escrow/00_config.ts deleted file mode 100644 index c152f42b..00000000 --- a/demo/client/escrow/00_config.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Buff } from '@cmdcode/buff' - -import { - EscrowSigner, - ProposalTemplate, - RoleTemplate, - WitnessTemplate, - create_policy, - create_proposal -} from '@scrow/core' - -import { config } from '@scrow/demo/00_demo_config.js' - -/** ========== [ USER CONFIG ] ========== **/ - -const SECRET_PASS : string = 'test_draft3' - -const USER_ALIAS : string = 'carol' - -const ROLE_POLICY : RoleTemplate = { - title : 'escrow', - payment : 3000, - programs : [ - [ 'endorse', 'resolve', '*', 1 ] - ] -} - -const PROP_TEMPLATE : ProposalTemplate = { - title : 'Basic two-party contract with third-party arbitration.', - duration : 14400, - schedule : [[ 7200, 'close|resolve', '*' ]], - value : 15000, -} - -const WIT_STATEMENT : WitnessTemplate = { - action : 'resolve', - method : 'endorse', - path : 'return' -} - -/** ========== [ MAIN EXPORT ] ========== **/ - -export const alias = USER_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(USER_ALIAS) -// Define a proposal template. -export const template = create_proposal({ - ...PROP_TEMPLATE, - network : config.network, - moderator : signer.pubkey -}) -// Define a role policy for yourself. -export const policy = create_policy(ROLE_POLICY) -// -export const wit_tmpl = WIT_STATEMENT diff --git a/demo/client/terms.ts b/demo/client/terms.ts new file mode 100644 index 00000000..64703692 --- /dev/null +++ b/demo/client/terms.ts @@ -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)) +}) diff --git a/package.json b/package.json index 9375fc94..eddabd10 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/plat/script.html b/test/plat/script.html index 2eace630..1b3a0067 100644 --- a/test/plat/script.html +++ b/test/plat/script.html @@ -9,31 +9,16 @@