From 956a351feac24d30c9996e0480a444769c10bb79 Mon Sep 17 00:00:00 2001 From: cmd Date: Mon, 4 Mar 2024 16:40:28 -0600 Subject: [PATCH] update --- demo/draft/alice/init.ts | 28 ++++++++++++---------------- demo/draft/alice/leave.ts | 4 ++-- demo/draft/alice/start.ts | 4 ++-- demo/draft/bob/start.ts | 6 +++--- demo/draft/escrow/view.ts | 5 +---- package.json | 2 +- src/client/class/draft.ts | 10 +++++----- yarn.lock | 8 ++++---- 8 files changed, 30 insertions(+), 37 deletions(-) diff --git a/demo/draft/alice/init.ts b/demo/draft/alice/init.ts index e4b29a2a..682ee572 100644 --- a/demo/draft/alice/init.ts +++ b/demo/draft/alice/init.ts @@ -1,11 +1,15 @@ -import { DraftSession } from '@scrow/core' -import { alias, role, signer } from './config.js' -import { agent_draft, secret_id } from '../terms.js' +import { DraftSession } from '@scrow/core' +import { signer } from './config.js' + +import { + agent_draft, + secret_id +} from '../terms.js' /** ========== [ Draft Session ] ========== **/ // Create a draft session -const session = new DraftSession(secret_id, signer, { +const session = new DraftSession(signer, { debug : true, verbose : true }) @@ -16,17 +20,9 @@ session.on('reject', console.log) // When the session is ready: session.on('ready', () => { console.log('alice ready') - // If we are not a member: - if (!session.is_member) { - // Grab the buyer policy from the roles list. - console.log(`fetching role "${role}"...`) - const policy = session.get_role(role) - // Join the session as the buyer. - console.log('joining the session...') - session.join(policy.id) - // Print to console. - console.log(`${alias} joined the draft as role ${policy.title}`) - } }) -await session.init('wss://relay.damus.io', agent_draft) +await session.init('wss://relay.damus.io', secret_id, agent_draft) + +console.log('session id :', session.id) +console.log('session sec :', session.secret) diff --git a/demo/draft/alice/leave.ts b/demo/draft/alice/leave.ts index 3522fafa..9408b25e 100644 --- a/demo/draft/alice/leave.ts +++ b/demo/draft/alice/leave.ts @@ -2,7 +2,7 @@ import { DraftSession } from '@scrow/core' import { signer } from './config.js' import { secret_id } from '../terms.js' -const session = new DraftSession(secret_id, signer, { +const session = new DraftSession(signer, { debug : false, verbose : false }) @@ -18,4 +18,4 @@ session.on('leave', (data) => { console.log('left:', data) }) -await session.connect('wss://relay.damus.io') +await session.connect('wss://relay.damus.io', secret_id) diff --git a/demo/draft/alice/start.ts b/demo/draft/alice/start.ts index 08f8ef7f..eb1e0417 100644 --- a/demo/draft/alice/start.ts +++ b/demo/draft/alice/start.ts @@ -20,7 +20,7 @@ import { alias, fund_amt, role, signer, wit_tmpl } from './config.js' /** ========== [ Draft Session ] ========== **/ // Create a draft session -const session = new DraftSession(secret_id, signer, { +const session = new DraftSession(signer, { debug : false, verbose : false }) @@ -176,4 +176,4 @@ session.on('error', console.log) console.log('draft:', agent_draft) -await session.init('wss://relay.damus.io', agent_draft) \ No newline at end of file +await session.init('wss://relay.damus.io', secret_id, agent_draft) diff --git a/demo/draft/bob/start.ts b/demo/draft/bob/start.ts index 30f99c56..55627430 100644 --- a/demo/draft/bob/start.ts +++ b/demo/draft/bob/start.ts @@ -10,14 +10,14 @@ import { config } from '@scrow/demo/00_demo_config.js' import { print_banner } from '@scrow/test' import { secret_id } from '../terms.js' -import { fund_mutiny_address, fund_regtest_address, sleep } from '@scrow/demo/util.js' +import { fund_mutiny_address, fund_regtest_address } from '@scrow/demo/util.js' import { alias, fund_amt, role, signer, wit_tmpl } from './config.js' /** ========== [ Draft Session ] ========== **/ // Create a draft session -const session = new DraftSession(secret_id, signer, { +const session = new DraftSession(signer, { debug : false, verbose : false }) @@ -162,4 +162,4 @@ session.on('published', async (cid) => { session.on('error', console.log) -await session.connect('wss://relay.damus.io') +await session.connect('wss://relay.damus.io', secret_id) diff --git a/demo/draft/escrow/view.ts b/demo/draft/escrow/view.ts index b780eaf0..1f020899 100644 --- a/demo/draft/escrow/view.ts +++ b/demo/draft/escrow/view.ts @@ -1,13 +1,10 @@ -import { DraftSession } from '@scrow/core' +import { DraftSession } from '@scrow/core' import { secret_id, signer } from '../terms.js' -import { client } from '@scrow/demo/01_create_client.js' /** ========== [ Draft Session ] ========== **/ // Create a draft session const session = new DraftSession(signer, { - socket_config : { verbose : true, debug : false }, - store_config : { verbose : true, debug : false }, verbose : true }) diff --git a/package.json b/package.json index 2272055a..4cbf3a13 100644 --- a/package.json +++ b/package.json @@ -122,7 +122,7 @@ "@cmdcode/buff": "2.2.5", "@cmdcode/crypto-tools": "2.7.6", "@cmdcode/musig2": "2.4.3", - "@cmdcode/nostr-sdk": "^0.0.11", + "@cmdcode/nostr-sdk": "^0.1.0", "@cmdcode/signer": "1.4.2", "@scrow/tapscript": "2.2.2", "zod": "^3.22.4" diff --git a/src/client/class/draft.ts b/src/client/class/draft.ts index 6b0aad05..6ca1ad90 100644 --- a/src/client/class/draft.ts +++ b/src/client/class/draft.ts @@ -91,7 +91,6 @@ export class DraftSession extends EventEmitter <{ _init : boolean constructor ( - secret : string, signer : EscrowSigner, options ?: Partial ) { @@ -99,7 +98,7 @@ export class DraftSession extends EventEmitter <{ this._opt = { debug : false, verbose : false, ...options } this._signer = signer - this._room = new NostrRoom(secret, signer._signer, options) + this._room = new NostrRoom(signer._signer, options) this._agreed = false this._full = false @@ -446,8 +445,8 @@ export class DraftSession extends EventEmitter <{ return true } - async connect (address : string) { - await this._room.connect(address) + async connect (address : string, secret : string) { + await this._room.connect(address, secret) return this } @@ -510,11 +509,12 @@ export class DraftSession extends EventEmitter <{ async init ( address : string, + secret : string, session : DraftData ) { validate_draft(session) verify_draft(session) - return this._room.init(address, session) + return this._room.init(address, session, secret) } join (policy_id : string, index ?: number) { diff --git a/yarn.lock b/yarn.lock index 87c44c2f..d302d9ea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -37,10 +37,10 @@ "@cmdcode/buff" "^2.2.5" "@cmdcode/crypto-tools" "^2.7.6" -"@cmdcode/nostr-sdk@^0.0.11": - version "0.0.11" - resolved "https://registry.yarnpkg.com/@cmdcode/nostr-sdk/-/nostr-sdk-0.0.11.tgz#ef9fa2321ca55c933c02a05315ef5cf49638e21e" - integrity sha512-foimrnYq4+P5qw8M32ujja9INkNAlwnQqvH+NdPlFuMwhn5DfSNIW7lSIS6fSVkGOCvGUhwCgE+XATuJ6GqxVA== +"@cmdcode/nostr-sdk@^0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@cmdcode/nostr-sdk/-/nostr-sdk-0.1.0.tgz#4ca253cddf3d9505d86bda38bc864699f41e10b8" + integrity sha512-ykQmLbgQxoF56473jjQAC5y6KdsAFTAPDPwhR1YpbCXoDBGghwuLAMhoGHysAh1PbKYccVY6Re69wKlHgZQMJA== dependencies: "@cmdcode/buff" "2.2.5" "@cmdcode/crypto-tools" "2.7.6"