Skip to main content

Class: DIDSession

did-session.DIDSession

DID Session

import { DIDSession } from 'did-session'

Constructors​

constructor​

• new DIDSession(params): DIDSession

Parameters​

NameType
paramsSessionParams

Returns​

DIDSession

Accessors​

authorizations​

• get authorizations(): string[]

Get the list of resources a session is authorized for

Returns​

string[]


cacao​

• get cacao(): Cacao

Get the session CACAO

Returns​

Cacao


did​

• get did(): DID

Get DID instance, if authorized

Returns​

DID


expireInSecs​

• get expireInSecs(): number

Number of seconds until a session expires

Returns​

number


hasSession​

• get hasSession(): boolean

Returns​

boolean


id​

• get id(): string

DID string associated to the session instance. session.id == session.getDID().parent

Returns​

string


isExpired​

• get isExpired(): boolean

Determine if a session is expired or not

Returns​

boolean

Methods​

isAuthorized​

▸ isAuthorized(resources?): boolean

Determine if session is available and optionally if authorized for given resources

Parameters​

NameType
resources?string[]

Returns​

boolean


serialize​

▸ serialize(): string

Serialize session into string, can store and initalize the same session again while valid

Returns​

string


authorize​

▸ authorize(authMethod, authOpts?): Promise<DIDSession>

Request authorization for session

Parameters​

NameType
authMethodAuthMethod
authOptsAuthOpts

Returns​

Promise<DIDSession>


fromSession​

▸ fromSession(session): Promise<DIDSession>

Initialize a session from a serialized session string

Parameters​

NameType
sessionstring

Returns​

Promise<DIDSession>


get​

▸ get(account, authMethod, authOpts?): Promise<DIDSession>

Get a session for the given accountId, if one exists, otherwise creates a new one.

Parameters​

NameType
accountAccountId
authMethodAuthMethod
authOptsAuthOpts

Returns​

Promise<DIDSession>


hasSessionFor​

▸ hasSessionFor(account, resources): Promise<boolean>

Check if there is an active session for a given account.

Parameters​

NameType
accountAccountId
resourcesstring[]

Returns​

Promise<boolean>


initDID​

▸ initDID(didKey, cacao): Promise<DID>

Parameters​

NameType
didKeyDID
cacaoCacao

Returns​

Promise<DID>


remove​

▸ remove(account): Promise<void>

Removes a session from storage for a given account (if created using DIDSession.get)

Parameters​

NameType
accountAccountId

Returns​

Promise<void>