Client
Class: Client
Client class initiates connection to the XMTP network.
Should be created with await Client.create(options)
Constructors
constructor
new Client(publicKeyBundle
, apiClient
, backupClient
, keystore
)
Parameters
Name | Type |
---|---|
publicKeyBundle | PublicKeyBundle |
apiClient | default |
backupClient | default |
keystore | Keystore |
Defined in
Properties
_backupClient
Private
_backupClient: default
Defined in
_codecs
Private
_codecs: Map
<string
, ContentCodec
<any
>>
Defined in
_conversations
Private
_conversations: Conversations
Defined in
_maxContentSize
Private
_maxContentSize: number
Defined in
address
address: string
Defined in
apiClient
apiClient: default
Defined in
contacts
contacts: Set
<string
>
Defined in
keystore
keystore: Keystore
Defined in
knownPublicKeyBundles
Private
knownPublicKeyBundles: Map
<string
, SignedPublicKeyBundle
| PublicKeyBundle
>
Defined in
publicKeyBundle
publicKeyBundle: PublicKeyBundle
Defined in
Accessors
backupType
get
backupType(): BackupType
Returns
BackupType
Defined in
conversations
get
conversations(): Conversations
Returns
Defined in
signedPublicKeyBundle
get
signedPublicKeyBundle(): SignedPublicKeyBundle
Returns
Defined in
Methods
canMessage
canMessage(peerAddress
): Promise
<boolean
>
Check if
Peer Address
can be messaged, specifically it checks that a PublicKeyBundle can be found for the given address
Parameters
Name | Type |
---|---|
peerAddress | string |
Returns
Promise
<boolean
>
Defined in
canMessage(peerAddress
): Promise
<boolean
[]>
Check if
Peer Address
can be messaged, specifically it checks that a PublicKeyBundle can be found for the given address
Parameters
Name | Type |
---|---|
peerAddress | string [] |
Returns
Promise
<boolean
[]>
Defined in
close
close(): Promise
<void
>
Returns
Promise
<void
>
Defined in
codecFor
codecFor(contentType
): undefined
| ContentCodec
<any
>
Find a matching codec for a given ContentTypeId
from the
client's codec registry
Parameters
Name | Type |
---|---|
contentType | ContentTypeId |
Returns
undefined
| ContentCodec
<any
>
Defined in
encodeContent
encodeContent(content
, options?
): Promise
<Uint8Array
>
Convert arbitrary content into a serialized EncodedContent
instance
with the given options
Parameters
Name | Type |
---|---|
content | any |
options? | SendOptions |
Returns
Promise
<Uint8Array
>
Defined in
ensureUserContactPublished
Private
ensureUserContactPublished(legacy?
): Promise
<void
>
Parameters
Name | Type | Default value |
---|---|---|
legacy | boolean | false |
Returns
Promise
<void
>
Defined in
forgetContact
forgetContact(peerAddress
): void
Used to force getUserContact fetch contact from the network.
Parameters
Name | Type |
---|---|
peerAddress | string |
Returns
void
Defined in
getUserContact
getUserContact(peerAddress
): Promise
<undefined
| SignedPublicKeyBundle
| PublicKeyBundle
>
Returns the cached PublicKeyBundle if one is known for the given address or fetches one from the network
This throws if either the address is invalid or the contact is not published. See also [#canMessage].
Parameters
Name | Type |
---|---|
peerAddress | string |
Returns
Promise
<undefined
| SignedPublicKeyBundle
| PublicKeyBundle
>
Defined in
getUserContacts
getUserContacts(peerAddresses
): Promise
<(undefined
| SignedPublicKeyBundle
| PublicKeyBundle
)[]>
Identical to getUserContact but for multiple peer addresses
Parameters
Name | Type |
---|---|
peerAddresses | string [] |
Returns
Promise
<(undefined
| SignedPublicKeyBundle
| PublicKeyBundle
)[]>
Defined in
init
Private
init(options
): Promise
<void
>
Parameters
Name | Type |
---|---|
options | Flatten <NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions > |
Returns
Promise
<void
>
Defined in
listEnvelopes
listEnvelopes<Out
>(topic
, mapper
, opts?
): Promise
<Out
[]>
List stored messages from the specified topic.
A specified mapper function will be applied to each envelope. If the mapper function throws an error during processing, the envelope will be discarded.
Type parameters
Name |
---|
Out |
Parameters
Name | Type |
---|---|
topic | string |
mapper | EnvelopeMapper <Out > |
opts? | ListMessagesOptions |
Returns
Promise
<Out
[]>
Defined in
listEnvelopesPaginated
listEnvelopesPaginated<Out
>(contentTopic
, mapper
, opts?
): AsyncGenerator
<Out
[], any
, unknown
>
List messages on a given set of content topics, yielding one page at a time
Type parameters
Name |
---|
Out |
Parameters
Name | Type |
---|---|
contentTopic | string |
mapper | EnvelopeMapper <Out > |
opts? | ListMessagesPaginatedOptions |
Returns
AsyncGenerator
<Out
[], any
, unknown
>
Defined in
listInvitations
listInvitations(opts?
): Promise
<Envelope
[]>
Parameters
Name | Type |
---|---|
opts? | ListMessagesOptions |
Returns
Promise
<Envelope
[]>
Defined in
publishEnvelopes
publishEnvelopes(envelopes
): Promise
<void
>
Low level method for publishing envelopes to the XMTP network with no pre-processing or encryption applied.
Primarily used internally
Parameters
Name | Type | Description |
---|---|---|
envelopes | PublishParams [] | PublishParams[] |
Returns
Promise
<void
>
Defined in
publishUserContact
publishUserContact(legacy?
): Promise
<void
>
Parameters
Name | Type | Default value |
---|---|---|
legacy | boolean | false |
Returns
Promise
<void
>
Defined in
registerCodec
registerCodec(codec
): void
Register a codec to be automatically used for encoding/decoding messages of the given Content Type
Parameters
Name | Type |
---|---|
codec | ContentCodec <any > |
Returns
void
Defined in
validateEnvelope
Private
validateEnvelope(env
): void
Parameters
Name | Type |
---|---|
env | PublishParams |
Returns
void
Defined in
canMessage
Static
canMessage(peerAddress
, opts?
): Promise
<boolean
>
Parameters
Name | Type |
---|---|
peerAddress | string |
opts? | Partial <NetworkOptions > |
Returns
Promise
<boolean
>
Defined in
Static
canMessage(peerAddress
, opts?
): Promise
<boolean
[]>
Parameters
Name | Type |
---|---|
peerAddress | string [] |
opts? | Partial <NetworkOptions > |
Returns
Promise
<boolean
[]>
Defined in
create
Static
create(wallet
, opts?
): Promise
<Client
>
Create and start a client associated with given wallet.
Parameters
Name | Type | Description |
---|---|---|
wallet | null | Signer | the wallet as a Signer instance |
opts? | Partial <Flatten <NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions >> | specify how to to connect to the network |
Returns
Promise
<Client
>
Defined in
getKeys
Static
getKeys(wallet
, opts?
): Promise
<Uint8Array
>
Export the XMTP PrivateKeyBundle from the SDK as a Uint8Array
.
This bundle can then be provided as privateKeyOverride
in a
subsequent call to Client.create(...)
Be very careful with these keys, as they can be used to impersonate a user on the XMTP network and read the user's messages.
Parameters
Name | Type |
---|---|
wallet | null | Signer |
opts? | Partial <Flatten <NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions >> |
Returns
Promise
<Uint8Array
>
Defined in
setupBackupClient
Static
Private
setupBackupClient(walletAddress
, env
): Promise
<default
>
Parameters
Name | Type |
---|---|
walletAddress | string |
env | "local" | "dev" | "production" |
Returns
Promise
<default
>