Class: DID
dids.DID
Interact with DIDs.
Constructors
constructor
• new DID(«destructured»?
)
Parameters
Name | Type |
---|---|
«destructured» | DIDOptions |
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
Name | Type |
---|---|
«destructured» | AuthenticateOptions |
Returns
Promise
<string
>
createDagJWE
▸ createDagJWE(cleartext
, recipients
, options?
): Promise
<JWE
>
Create an IPFS compatibe DagJWE encrypted to the given recipients.
Parameters
Name | Type | Description |
---|---|---|
cleartext | Record <string , any > | The cleartext to be encrypted, may include ipld links |
recipients | string [] | An array of DIDs |
options | CreateJWEOptions | Optional 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
Name | Type | Description |
---|---|---|
payload | Record <string , any > | The payload to sign, may include ipld links |
options | CreateJWSOptions | Optional parameters |
Returns
Promise
<DagJWSResult
>
createJWE
▸ createJWE(cleartext
, recipients
, options?
): Promise
<JWE
>
Create a JWE encrypted to the given recipients.
Parameters
Name | Type | Description |
---|---|---|
cleartext | Uint8Array | The cleartext to be encrypted |
recipients | string [] | An array of DIDs |
options | CreateJWEOptions | Optional 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
Name | Type |
---|---|
T | extends string | Record <string , any > |
Parameters
Name | Type | Description |
---|---|---|
payload | T | The payload to sign |
options | CreateJWSOptions | Optional parameters |
Returns
Promise
<DagJWS
>
decryptDagJWE
▸ decryptDagJWE(jwe
): Promise
<Record
<string
, any
>>
Try to decrypt the given DagJWE with the currently authenticated user.
Parameters
Name | Type | Description |
---|---|---|
jwe | JWE | The 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
Name | Type | Description |
---|---|---|
jwe | JWE | The JWE to decrypt |
options | DecryptJWEOptions | Optional parameters |
Returns
Promise
<Uint8Array
>
resolve
▸ resolve(didUrl
): Promise
<DIDResolutionResult
>
Resolve the DID Document of the given DID.
Parameters
Name | Type | Description |
---|---|---|
didUrl | string | The 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
Name | Type | Description |
---|---|---|
provider | DIDProvider | The DIDProvider to use |
Returns
void
setResolver
▸ setResolver(resolver
, resolverOptions?
): void
Set the DID-resolver user by this instance
Parameters
Name | Type | Description |
---|---|---|
resolver | ResolverRegistry | Resolver | Either a Resolver instance or an object with specific resolvers |
resolverOptions? | ResolverOptions | Options 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
Name | Type | Description |
---|---|---|
jws | string | DagJWS | The JWS to verify |
options | VerifyJWSOptions | Optional arguments for verification |
Returns
Promise
<VerifyJWSResult
>
Information about the signed JWS
withCapability
▸ withCapability(cap
): DID
Attach a capability to the DID instance
Parameters
Name | Type | Description |
---|---|---|
cap | Cacao | The capability to attach |
Returns
A new DID instance with the capability attached