Class: DIDSession
did-session.DIDSession
DID Session
import { DIDSession } from 'did-session'
Constructors
constructor
• new DIDSession(params
): DIDSession
Parameters
Name | Type |
---|---|
params | SessionParams |
Returns
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
Name | Type |
---|---|
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
Name | Type |
---|---|
authMethod | AuthMethod |
authOpts | AuthOpts |
Returns
Promise
<DIDSession
>
fromSession
▸ fromSession(session
): Promise
<DIDSession
>
Initialize a session from a serialized session string
Parameters
Name | Type |
---|---|
session | string |
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
Name | Type |
---|---|
account | AccountId |
authMethod | AuthMethod |
authOpts | AuthOpts |
Returns
Promise
<DIDSession
>
hasSessionFor
▸ hasSessionFor(account
, resources
): Promise
<boolean
>
Check if there is an active session for a given account.
Parameters
Name | Type |
---|---|
account | AccountId |
resources | string [] |
Returns
Promise
<boolean
>
initDID
▸ initDID(didKey
, cacao
): Promise
<DID
>
Parameters
Name | Type |
---|---|
didKey | DID |
cacao | Cacao |
Returns
Promise
<DID
>
remove
▸ remove(account
): Promise
<void
>
Removes a session from storage for a given account (if created using DIDSession.get
)
Parameters
Name | Type |
---|---|
account | AccountId |
Returns
Promise
<void
>