Skip to main content

Class: Client

client.Client

Hierarchy

Constructors

constructor

new Client(agentData, options?)

Parameters

NameType
agentDataAgentData
options?Object
options.serviceConfundefined | ServiceConf

Overrides

Base.constructor

Defined in

src/client.js:16

Properties

_agent

Protected _agent: Agent

Inherited from

Base._agent

Defined in

src/base.js:9


_serviceConf

Protected _serviceConf: ServiceConf

Inherited from

Base._serviceConf

Defined in

src/base.js:15


capability

capability: Object

Type declaration

NameType
spaceSpaceClient
storeStoreClient
uploadUploadClient

Defined in

src/client.js:18

Methods

_invocationConfig

Protected _invocationConfig(abilities): Promise<{ audience: Principal<`did:${string}:${string}`> ; issuer: Signer<`did:${string}:${string}`, SigAlg> ; proofs: Delegation<Capabilities>[] ; with: `did:${string}:${string}` = resource }>

Parameters

NameType
abilitiesAbility[]

Returns

Promise<{ audience: Principal<`did:${string}:${string}`> ; issuer: Signer<`did:${string}:${string}`, SigAlg> ; proofs: Delegation<Capabilities>[] ; with: `did:${string}:${string}` = resource }>

Inherited from

Base._invocationConfig

Defined in

src/base.js:36


addProof

addProof(proof): Promise<void>

Add a proof to the agent. Proofs are delegations with an audience matching the agent DID.

Parameters

NameType
proofDelegation<Capabilities>

Returns

Promise<void>

Defined in

src/client.js:157


addSpace

addSpace(proof): Promise<Space>

Add a space from a received proof.

Parameters

NameType
proofDelegation<Capabilities>

Returns

Promise<Space>

Defined in

src/client.js:134


agent

agent(): Signer<`did:${string}:${string}`, SigAlg>

The current user agent (this device).

Returns

Signer<`did:${string}:${string}`, SigAlg>

Defined in

src/client.js:73


createDelegation

createDelegation(audience, abilities, options?): Promise<Delegation<Capabilities>>

Create a delegation to the passed audience for the given abilities with the current space as the resource.

Parameters

NameType
audiencePrincipal<`did:${string}:${string}`>
abilitiesTupleToUnion<AbilitiesArray>[]
options?Omit<UCANOptions, "audience"> & { audienceMeta?: AgentMeta }

Returns

Promise<Delegation<Capabilities>>

Defined in

src/client.js:183


createSpace

createSpace(name?): Promise<Space>

Create a new space with an optional name.

Parameters

NameType
name?string

Returns

Promise<Space>

Defined in

src/client.js:106


currentSpace

currentSpace(): undefined | Space

The current space.

Returns

undefined | Space

Defined in

src/client.js:80


delegations

delegations(caps?): Delegation<Capabilities>[]

Get delegations created by the agent for others.

Parameters

NameTypeDescription
caps?Capability<Ability, `${string}:${string}`, any>[]Capabilities to filter by. Empty or undefined caps with return all the delegations.

Returns

Delegation<Capabilities>[]

Defined in

src/client.js:167


proofs

proofs(caps?): Delegation<Capabilities>[]

Get all the proofs matching the capabilities.

Proofs are delegations with an audience matching the agent DID.

Parameters

NameTypeDescription
caps?Capability<Ability, `${string}:${string}`, any>[]Capabilities to filter by. Empty or undefined caps with return all the proofs.

Returns

Delegation<Capabilities>[]

Defined in

src/client.js:147


registerSpace

registerSpace(email, options?): Promise<void>

Register the current space with the service.

Invokes voucher/redeem for the free tier, waits on the websocket for the voucher/claim and invokes it.

It also adds a full space delegation to the service in the voucher/claim invocation to allow for recovery.

Parameters

NameType
emailstring
options?Object
options.signalundefined | AbortSignal

Returns

Promise<void>

Defined in

src/client.js:125


setCurrentSpace

setCurrentSpace(did): Promise<void>

Use a specific space.

Parameters

NameType
did`did:${string}:${string}`

Returns

Promise<void>

Defined in

src/client.js:90


spaces

spaces(): Space[]

Spaces available to this agent.

Returns

Space[]

Defined in

src/client.js:97


uploadCAR

uploadCAR(car, options?): Promise<AnyLink>

Uploads a CAR file to the service.

The difference between this function and capability.store.add is that the CAR file is automatically sharded and an "upload" is registered, linking the individual shards (see capability.upload.add).

Use the onShardStored callback to obtain the CIDs of the CAR file shards.

Parameters

NameTypeDescription
carBlobLikeCAR file.
options?UploadOptions

Returns

Promise<AnyLink>

Defined in

src/client.js:64


uploadDirectory

uploadDirectory(files, options?): Promise<AnyLink>

Uploads a directory of files to the service and returns the root data CID for the generated DAG. All files are added to a container directory, with paths in file names preserved.

Parameters

NameTypeDescription
filesFileLike[]File data.
options?UploadOptions

Returns

Promise<AnyLink>

Defined in

src/client.js:46


uploadFile

uploadFile(file, options?): Promise<AnyLink>

Uploads a file to the service and returns the root data CID for the generated DAG.

Parameters

NameTypeDescription
fileBlobLikeFile data.
options?UploadOptions

Returns

Promise<AnyLink>

Defined in

src/client.js:32