@@ -11,6 +11,7 @@ import {
11
11
GroupMessageKind ,
12
12
SignatureRequestType ,
13
13
type ConsentEntityType ,
14
+ type Identifier ,
14
15
} from "@xmtp/wasm-bindings" ;
15
16
import { ClientWorkerClass } from "@/ClientWorkerClass" ;
16
17
import { Conversations } from "@/Conversations" ;
@@ -24,7 +25,6 @@ import {
24
25
import { type Signer } from "@/utils/signer" ;
25
26
26
27
export class Client extends ClientWorkerClass {
27
- #accountAddress: string ;
28
28
#codecs: Map < string , ContentCodec > ;
29
29
#conversations: Conversations ;
30
30
#encryptionKey: Uint8Array ;
@@ -37,7 +37,6 @@ export class Client extends ClientWorkerClass {
37
37
38
38
constructor (
39
39
signer : Signer ,
40
- accountAddress : string ,
41
40
encryptionKey : Uint8Array ,
42
41
options ?: ClientOptions ,
43
42
) {
@@ -48,7 +47,6 @@ export class Client extends ClientWorkerClass {
48
47
worker ,
49
48
options ?. loggingLevel !== undefined && options . loggingLevel !== "off" ,
50
49
) ;
51
- this . #accountAddress = accountAddress ;
52
50
this . options = options ;
53
51
this . #encryptionKey = encryptionKey ;
54
52
this . #signer = signer ;
@@ -63,13 +61,9 @@ export class Client extends ClientWorkerClass {
63
61
) ;
64
62
}
65
63
66
- get accountAddress ( ) {
67
- return this . #accountAddress;
68
- }
69
-
70
64
async init ( ) {
71
65
const result = await this . sendMessage ( "init" , {
72
- address : this . accountAddress ,
66
+ identifier : await this . #signer . getIdentifier ( ) ,
73
67
encryptionKey : this . #encryptionKey,
74
68
options : this . options ,
75
69
} ) ;
@@ -84,8 +78,7 @@ export class Client extends ClientWorkerClass {
84
78
encryptionKey : Uint8Array ,
85
79
options ?: ClientOptions ,
86
80
) {
87
- const address = await signer . getAddress ( ) ;
88
- const client = new Client ( signer , address , encryptionKey , options ) ;
81
+ const client = new Client ( signer , encryptionKey , options ) ;
89
82
90
83
await client . init ( ) ;
91
84
@@ -104,6 +97,10 @@ export class Client extends ClientWorkerClass {
104
97
return this . #inboxId;
105
98
}
106
99
100
+ async accountIdentifier ( ) {
101
+ return this . #signer. getIdentifier ( ) ;
102
+ }
103
+
107
104
get installationId ( ) {
108
105
return this . #installationId;
109
106
}
@@ -134,7 +131,7 @@ export class Client extends ClientWorkerClass {
134
131
* throw an error.
135
132
*/
136
133
async unsafe_addAccountSignatureText (
137
- newAccountAddress : string ,
134
+ newIdentifier : Identifier ,
138
135
allowInboxReassign : boolean = false ,
139
136
) {
140
137
if ( ! allowInboxReassign ) {
@@ -144,7 +141,7 @@ export class Client extends ClientWorkerClass {
144
141
}
145
142
146
143
return this . sendMessage ( "addAccountSignatureText" , {
147
- newAccountAddress ,
144
+ newIdentifier ,
148
145
} ) ;
149
146
}
150
147
@@ -155,8 +152,10 @@ export class Client extends ClientWorkerClass {
155
152
*
156
153
* It is highly recommended to use the `removeAccount` function instead.
157
154
*/
158
- async unsafe_removeAccountSignatureText ( accountAddress : string ) {
159
- return this . sendMessage ( "removeAccountSignatureText" , { accountAddress } ) ;
155
+ async unsafe_removeAccountSignatureText ( identifier : Identifier ) {
156
+ return this . sendMessage ( "removeAccountSignatureText" , {
157
+ identifier,
158
+ } ) ;
160
159
}
161
160
162
161
/**
@@ -203,18 +202,21 @@ export class Client extends ClientWorkerClass {
203
202
) {
204
203
const signature = await signer . signMessage ( signatureText ) ;
205
204
206
- if ( signer . walletType === "SCW" ) {
207
- await this . sendMessage ( "addScwSignature" , {
208
- type : signatureType ,
209
- bytes : signature ,
210
- chainId : signer . getChainId ( ) ,
211
- blockNumber : signer . getBlockNumber ?.( ) ,
212
- } ) ;
213
- } else {
214
- await this . sendMessage ( "addSignature" , {
215
- type : signatureType ,
216
- bytes : signature ,
217
- } ) ;
205
+ switch ( signer . type ) {
206
+ case "SCW" :
207
+ await this . sendMessage ( "addScwSignature" , {
208
+ type : signatureType ,
209
+ bytes : signature ,
210
+ chainId : signer . getChainId ( ) ,
211
+ blockNumber : signer . getBlockNumber ?.( ) ,
212
+ } ) ;
213
+ break ;
214
+ case "EOA" :
215
+ await this . sendMessage ( "addEcdsaSignature" , {
216
+ type : signatureType ,
217
+ bytes : signature ,
218
+ } ) ;
219
+ break ;
218
220
}
219
221
}
220
222
@@ -261,8 +263,8 @@ export class Client extends ClientWorkerClass {
261
263
allowInboxReassign : boolean = false ,
262
264
) {
263
265
// check for existing inbox id
264
- const existingInboxId = await this . findInboxIdByAddress (
265
- await newAccountSigner . getAddress ( ) ,
266
+ const existingInboxId = await this . findInboxIdByIdentifier (
267
+ await newAccountSigner . getIdentifier ( ) ,
266
268
) ;
267
269
268
270
if ( existingInboxId && ! allowInboxReassign ) {
@@ -272,7 +274,7 @@ export class Client extends ClientWorkerClass {
272
274
}
273
275
274
276
const signatureText = await this . unsafe_addAccountSignatureText (
275
- await newAccountSigner . getAddress ( ) ,
277
+ await newAccountSigner . getIdentifier ( ) ,
276
278
true ,
277
279
) ;
278
280
@@ -289,9 +291,9 @@ export class Client extends ClientWorkerClass {
289
291
await this . unsafe_applySignatures ( ) ;
290
292
}
291
293
292
- async removeAccount ( accountAddress : string ) {
294
+ async removeAccount ( accountIdentifier : Identifier ) {
293
295
const signatureText =
294
- await this . unsafe_removeAccountSignatureText ( accountAddress ) ;
296
+ await this . unsafe_removeAccountSignatureText ( accountIdentifier ) ;
295
297
296
298
if ( ! signatureText ) {
297
299
throw new Error ( "Unable to generate remove account signature text" ) ;
@@ -346,15 +348,17 @@ export class Client extends ClientWorkerClass {
346
348
return this . sendMessage ( "isRegistered" , undefined ) ;
347
349
}
348
350
349
- async canMessage ( accountAddresses : string [ ] ) {
350
- return this . sendMessage ( "canMessage" , { accountAddresses } ) ;
351
+ async canMessage ( identifiers : Identifier [ ] ) {
352
+ return this . sendMessage ( "canMessage" , { identifiers } ) ;
351
353
}
352
354
353
- static async canMessage ( accountAddresses : string [ ] , env ?: XmtpEnv ) {
354
- const accountAddress = "0x0000000000000000000000000000000000000000" ;
355
+ static async canMessage ( identifiers : Identifier [ ] , env ?: XmtpEnv ) {
355
356
const signer : Signer = {
356
- walletType : "EOA" ,
357
- getAddress : ( ) => accountAddress ,
357
+ type : "EOA" ,
358
+ getIdentifier : ( ) => ( {
359
+ identifier : "0x0000000000000000000000000000000000000000" ,
360
+ identifierKind : "Ethereum" ,
361
+ } ) ,
358
362
signMessage : ( ) => new Uint8Array ( ) ,
359
363
} ;
360
364
const client = await Client . create (
@@ -365,11 +369,11 @@ export class Client extends ClientWorkerClass {
365
369
env,
366
370
} ,
367
371
) ;
368
- return client . canMessage ( accountAddresses ) ;
372
+ return client . canMessage ( identifiers ) ;
369
373
}
370
374
371
- async findInboxIdByAddress ( address : string ) {
372
- return this . sendMessage ( "findInboxIdByAddress " , { address } ) ;
375
+ async findInboxIdByIdentifier ( identifier : Identifier ) {
376
+ return this . sendMessage ( "findInboxIdByIdentifier " , { identifier } ) ;
373
377
}
374
378
375
379
async inboxState ( refreshFromNetwork ?: boolean ) {
0 commit comments