Skip to main content

Class: DID

dids.DID

Interact with DIDs.

Constructors

constructor

new DID(«destructured»?): DID

Parameters

NameType
«destructured»DIDOptions

Returns

DID

Accessors

authenticated

get authenticated(): boolean

Check if user is authenticated.

Returns

boolean


capability

get capability(): Cacao

Get attached capability

Returns

Cacao


hasCapability

get hasCapability(): boolean

Check if the DID has a capability attached

Returns

boolean


hasParent

get hasParent(): boolean

Check if DID has parent DID

Returns

boolean


id

get id(): string

Get the DID identifier of the user.

Returns

string


parent

get parent(): string

Get parent DID, parent DID is the capability issuer

Returns

string

Methods

authenticate

authenticate(«destructured»?): Promise<string>

Authenticate the user.

Parameters

NameType
«destructured»AuthenticateOptions

Returns

Promise<string>


createDagJWE

createDagJWE(cleartext, recipients, options?): Promise<JWE>

Create an IPFS compatibe DagJWE encrypted to the given recipients.

Parameters

NameTypeDescription
cleartextRecord<string, any>The cleartext to be encrypted, may include ipld links
recipientsstring[]An array of DIDs
optionsCreateJWEOptionsOptional parameters

Returns

Promise<JWE>


createDagJWS

createDagJWS(payload, options?): Promise<DagJWSResult>

Create an IPFS compatibe DagJWS encoded signature over the given payload. Will be signed by the currently authenticated DID.

Parameters

NameTypeDescription
payloadRecord<string, any>The payload to sign, may include ipld links
optionsCreateJWSOptionsOptional parameters

Returns

Promise<DagJWSResult>


createJWE

createJWE(cleartext, recipients, options?): Promise<JWE>

Create a JWE encrypted to the given recipients.

Parameters

NameTypeDescription
cleartextUint8ArrayThe cleartext to be encrypted
recipientsstring[]An array of DIDs
optionsCreateJWEOptionsOptional parameters

Returns

Promise<JWE>


createJWS

createJWS<T>(payload, options?): Promise<DagJWS>

Create a JWS encoded signature over the given payload. Will be signed by the currently authenticated DID.

Type parameters

NameType
Textends string | Record<string, any>

Parameters

NameTypeDescription
payloadTThe payload to sign
optionsCreateJWSOptionsOptional parameters

Returns

Promise<DagJWS>


decryptDagJWE

decryptDagJWE(jwe): Promise<Record<string, any>>

Try to decrypt the given DagJWE with the currently authenticated user.

Parameters

NameTypeDescription
jweJWEThe JWE to decrypt

Returns

Promise<Record<string, any>>

An ipld object


decryptJWE

decryptJWE(jwe, options?): Promise<Uint8Array>

Try to decrypt the given JWE with the currently authenticated user.

Parameters

NameTypeDescription
jweJWEThe JWE to decrypt
optionsDecryptJWEOptionsOptional parameters

Returns

Promise<Uint8Array>


resolve

resolve(didUrl): Promise<DIDResolutionResult>

Resolve the DID Document of the given DID.

Parameters

NameTypeDescription
didUrlstringThe DID to resolve

Returns

Promise<DIDResolutionResult>


setProvider

setProvider(provider): void

Set the DID provider of this instance. Only callable if provider not already set.

Parameters

NameTypeDescription
providerDIDProviderThe DIDProvider to use

Returns

void


setResolver

setResolver(resolver, resolverOptions?): void

Set the DID-resolver user by this instance

Parameters

NameTypeDescription
resolverResolverRegistry | ResolverEither a Resolver instance or an object with specific resolvers
resolverOptions?ResolverOptionsOptions to use for the created resolver. Will be ignored if a Resolver instance is passed

Returns

void


verifyJWS

verifyJWS(jws, options?): Promise<VerifyJWSResult>

Verify a JWS. Uses the 'kid' in the header as the way to resolve the author public key.

Parameters

NameTypeDescription
jwsstring | DagJWSThe JWS to verify
optionsVerifyJWSOptionsOptional arguments for verification

Returns

Promise<VerifyJWSResult>

Information about the signed JWS


withCapability

withCapability(cap): DID

Attach a capability to the DID instance

Parameters

NameTypeDescription
capCacaoThe capability to attach

Returns

DID

A new DID instance with the capability attached