Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Mar 4, 2024
1 parent 4acb3bb commit 956a351
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 37 deletions.
28 changes: 12 additions & 16 deletions demo/draft/alice/init.ts
Original file line number Diff line number Diff line change
@@ -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
})
Expand All @@ -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)
4 changes: 2 additions & 2 deletions demo/draft/alice/leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand All @@ -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)
4 changes: 2 additions & 2 deletions demo/draft/alice/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -176,4 +176,4 @@ session.on('error', console.log)

console.log('draft:', agent_draft)

await session.init('wss://relay.damus.io', agent_draft)
await session.init('wss://relay.damus.io', secret_id, agent_draft)
6 changes: 3 additions & 3 deletions demo/draft/bob/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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)
5 changes: 1 addition & 4 deletions demo/draft/escrow/view.ts
Original file line number Diff line number Diff line change
@@ -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
})

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions src/client/class/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ export class DraftSession extends EventEmitter <{
_init : boolean

constructor (
secret : string,
signer : EscrowSigner,
options ?: Partial<SessionConfig>
) {
super()

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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 956a351

Please sign in to comment.