Skip to content

Commit 8d56fed

Browse files
Pass originator into contacts manager
1 parent 2549fbc commit 8d56fed

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/identity/ContactsManager.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export class ContactsManager {
3232
private readonly wallet: WalletInterface
3333
private readonly cache = new MemoryCache()
3434
private readonly CONTACTS_CACHE_KEY = 'metanet-contacts'
35+
private readonly originator?: string
3536

36-
constructor (wallet?: WalletInterface) {
37+
constructor (wallet?: WalletInterface, originator?: string) {
3738
this.wallet = wallet ?? new WalletClient()
39+
this.originator = originator
3840
}
3941

4042
/**
@@ -68,7 +70,7 @@ export class ContactsManager {
6870
keyID: identityKey,
6971
counterparty: 'self',
7072
data: Utils.toArray(identityKey, 'utf8')
71-
})
73+
}, this.originator)
7274
tags.push(`identityKey ${Utils.toHex(hashedIdentityKey)}`)
7375
}
7476

@@ -79,7 +81,7 @@ export class ContactsManager {
7981
includeCustomInstructions: true,
8082
tags,
8183
limit
82-
})
84+
}, this.originator)
8385

8486
if (outputs.outputs == null || outputs.outputs.length === 0) {
8587
this.cache.setItem(this.CONTACTS_CACHE_KEY, JSON.stringify([]))
@@ -104,7 +106,7 @@ export class ContactsManager {
104106
protocolID: CONTACT_PROTOCOL_ID,
105107
keyID,
106108
counterparty: 'self'
107-
})
109+
}, this.originator)
108110

109111
// Parse the contact data
110112
const contactData: Contact = JSON.parse(Utils.toUTF8(plaintext))
@@ -157,7 +159,7 @@ export class ContactsManager {
157159
keyID: contact.identityKey,
158160
counterparty: 'self',
159161
data: Utils.toArray(contact.identityKey, 'utf8')
160-
})
162+
}, this.originator)
161163

162164
// Check if this contact already exists (to update it)
163165
const outputs = await this.wallet.listOutputs({
@@ -166,7 +168,7 @@ export class ContactsManager {
166168
includeCustomInstructions: true,
167169
tags: [`identityKey ${Utils.toHex(hashedIdentityKey)}`],
168170
limit: 100 // Should only be one contact!
169-
})
171+
}, this.originator)
170172

171173
let existingOutput: any = null
172174
let keyID = Utils.toBase64(Random(32))
@@ -185,7 +187,7 @@ export class ContactsManager {
185187
protocolID: CONTACT_PROTOCOL_ID,
186188
keyID,
187189
counterparty: 'self'
188-
})
190+
}, this.originator)
189191

190192
const storedContact: Contact = JSON.parse(Utils.toUTF8(plaintext))
191193
if (storedContact.identityKey === contact.identityKey) {
@@ -209,7 +211,7 @@ export class ContactsManager {
209211
protocolID: CONTACT_PROTOCOL_ID,
210212
keyID,
211213
counterparty: 'self'
212-
})
214+
}, this.originator)
213215

214216
// Create locking script for the new contact token
215217
const lockingScript = await new PushDrop(this.wallet).lock(
@@ -242,7 +244,7 @@ export class ContactsManager {
242244
customInstructions: JSON.stringify({ keyID })
243245
}],
244246
options: { acceptDelayedBroadcast: false, randomizeOutputs: false } // TODO: Support custom config as needed.
245-
})
247+
}, this.originator)
246248

247249
if (signableTransaction == null) throw new Error('Unable to update contact')
248250

@@ -255,7 +257,7 @@ export class ContactsManager {
255257
const { tx } = await this.wallet.signAction({
256258
reference: signableTransaction.reference,
257259
spends: { 0: { unlockingScript: unlockingScript.toHex() } }
258-
})
260+
}, this.originator)
259261

260262
if (tx == null) throw new Error('Failed to update contact output')
261263
} else {
@@ -271,7 +273,7 @@ export class ContactsManager {
271273
customInstructions: JSON.stringify({ keyID })
272274
}],
273275
options: { acceptDelayedBroadcast: false, randomizeOutputs: false } // TODO: Support custom config as needed.
274-
})
276+
}, this.originator)
275277

276278
if (tx == null) throw new Error('Failed to create contact output')
277279
}
@@ -302,7 +304,7 @@ export class ContactsManager {
302304
keyID: identityKey,
303305
counterparty: 'self',
304306
data: Utils.toArray(identityKey, 'utf8')
305-
})
307+
}, this.originator)
306308
tags.push(`identityKey ${Utils.toHex(hashedIdentityKey)}`)
307309

308310
// Find and spend the contact's output
@@ -312,7 +314,7 @@ export class ContactsManager {
312314
includeCustomInstructions: true,
313315
tags,
314316
limit: 100 // Should only be one contact!
315-
})
317+
}, this.originator)
316318

317319
if (outputs.outputs == null) return
318320

@@ -330,7 +332,7 @@ export class ContactsManager {
330332
protocolID: CONTACT_PROTOCOL_ID,
331333
keyID,
332334
counterparty: 'self'
333-
})
335+
}, this.originator)
334336

335337
const storedContact: Contact = JSON.parse(Utils.toUTF8(plaintext))
336338
if (storedContact.identityKey === identityKey) {
@@ -348,7 +350,7 @@ export class ContactsManager {
348350
}],
349351
outputs: [], // No outputs = deletion
350352
options: { acceptDelayedBroadcast: false, randomizeOutputs: false } // TODO: Support custom config as needed.
351-
})
353+
}, this.originator)
352354

353355
if (signableTransaction == null) throw new Error('Unable to delete contact')
354356

@@ -361,7 +363,7 @@ export class ContactsManager {
361363
const { tx: deleteTx } = await this.wallet.signAction({
362364
reference: signableTransaction.reference,
363365
spends: { 0: { unlockingScript: unlockingScript.toHex() } }
364-
})
366+
}, this.originator)
365367

366368
if (deleteTx == null) throw new Error('Failed to delete contact output')
367369
return

src/identity/IdentityClient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { AuthFetch } from '../auth/clients/index.js'
21
import { DEFAULT_IDENTITY_CLIENT_OPTIONS, defaultIdentity, DisplayableIdentity, KNOWN_IDENTITY_TYPES } from './types/index.js'
32
import {
43
Base64String,
@@ -23,17 +22,16 @@ import { ContactsManager, Contact } from './ContactsManager.js'
2322
* IdentityClient lets you discover who others are, and let the world know who you are.
2423
*/
2524
export class IdentityClient {
26-
private readonly authClient: AuthFetch
2725
private readonly wallet: WalletInterface
2826
private readonly contactsManager: ContactsManager
2927
constructor (
3028
wallet?: WalletInterface,
3129
private readonly options = DEFAULT_IDENTITY_CLIENT_OPTIONS,
3230
private readonly originator?: OriginatorDomainNameStringUnder250Bytes
3331
) {
32+
this.originator = originator
3433
this.wallet = wallet ?? new WalletClient()
35-
this.authClient = new AuthFetch(this.wallet)
36-
this.contactsManager = new ContactsManager(this.wallet)
34+
this.contactsManager = new ContactsManager(this.wallet, this.originator)
3735
}
3836

3937
/**

0 commit comments

Comments
 (0)