UNPKG

@enbox/api

Version:

SDK for accessing the features and capabilities of Web5

157 lines 6.46 kB
import type { DwnDataEncodedRecordsWriteMessage, DwnPermissionConditions, DwnPermissionScope, DwnResponseStatus, Web5Agent } from '@enbox/agent'; import { DwnPermissionGrant } from '@enbox/agent'; import { PermissionGrantRevocation } from './grant-revocation.js'; /** * Represents the structured data model of a PermissionGrant record, encapsulating the essential fields that define */ export interface PermissionGrantModel { /** * The ID of the permission grant, which is the record ID DWN message. */ readonly id: string; /** * The grantor of the permission. */ readonly grantor: string; /** * The grantee of the permission. */ readonly grantee: string; /** * The date at which the grant was given. */ readonly dateGranted: string; /** * Optional string that communicates what the grant would be used for */ readonly description?: string; /** * Optional CID of a permission request. This is optional because grants may be given without being officially requested */ readonly requestId?: string; /** * Timestamp at which this grant will no longer be active. */ readonly dateExpires: string; /** * Whether this grant is delegated or not. If `true`, the `grantedTo` will be able to act as the `grantedTo` within the scope of this grant. */ readonly delegated?: boolean; /** * The scope of the allowed access. */ readonly scope: DwnPermissionScope; /** * Optional conditions that must be met when the grant is used. */ readonly conditions?: DwnPermissionConditions; } /** * Represents the options for creating a new PermissionGrant instance. */ export interface PermissionGrantOptions { /** The DID to use when interacting with the underlying DWN record representing the grant */ connectedDid: string; /** The underlying DWN `RecordsWrite` message along with encoded data that represent the grant */ message: DwnDataEncodedRecordsWriteMessage; /** The agent to use when interacting with the underlying DWN record representing the grant */ agent: Web5Agent; } /** * The `PermissionGrant` class encapsulates a permissions protocol `grant` record, providing a more * developer-friendly interface for working with Decentralized Web Node (DWN) records. * * Methods are provided to revoke, check if isRevoked, and manage the grant's lifecycle, including writing to remote DWNs. * * @beta */ export declare class PermissionGrant implements PermissionGrantModel { /** The PermissionsAPI used to interact with the underlying permission grant */ private _permissions; /** The DID to use as the author and default target for the underlying permission grant */ private _connectedDid; /** The underlying DWN `RecordsWrite` message along with encoded data that represent the grant */ private _message; /** The parsed grant object */ private _grant; private constructor(); /** parses the grant given an agent, connectedDid and data encoded records write message */ static parse(options: PermissionGrantOptions): Promise<PermissionGrant>; /** The agent to use for this instantiation of the grant */ private get agent(); /** The grant's ID, which is also the underlying record's ID */ get id(): string; /** The DID which granted the permission */ get grantor(): string; /** The DID which the permission was granted to */ get grantee(): string; /** The date the permission was granted */ get dateGranted(): string; /** (optional) Description of the permission grant */ get description(): string | undefined; /** (optional) The Id of the PermissionRequest if one was used */ get requestId(): string | undefined; /** The date on which the permission expires */ get dateExpires(): string; /** Whether or not the permission grant can be used to impersonate the grantor */ get delegated(): boolean | undefined; /** The permission scope under which the grant is valid */ get scope(): DwnPermissionScope; /** The conditions under which the grant is valid */ get conditions(): DwnPermissionConditions; /** The raw `RecordsWrite` DWN message with encoded data that was used to instantiate this grant */ get rawMessage(): DwnDataEncodedRecordsWriteMessage; /** * Send the current grant to a remote DWN by specifying their DID * If no DID is specified, the target is assumed to be the owner (connectedDID). * * @param target - the optional DID to send the grant to, if none is set it is sent to the connectedDid * @returns the status of the send grant request * * @beta */ send(target?: string): Promise<DwnResponseStatus>; /** * Stores the current grant to the owner's DWN. * * @param importGrant - if true, the grant will signed by the owner before storing it to the owner's DWN. Defaults to false. * @returns the status of the store request * * @beta */ store(importGrant?: boolean): Promise<DwnResponseStatus>; /** * Signs the current grant as the owner and optionally stores it to the owner's DWN. * This is useful when importing a grant that was signed by someone else into your own DWN. * * @param store - if true, the grant will be stored to the owner's DWN after signing. Defaults to true. * @returns the status of the import request * * @beta */ import(store?: boolean): Promise<DwnResponseStatus>; /** * Revokes the grant and optionally stores the revocation to the owner's DWN. * * @param store - if true, the revocation will be stored to the owner's DWN. Defaults to true. * @returns {PermissionGrantRevocation} the grant revocation object * * @beta */ revoke(store?: boolean): Promise<PermissionGrantRevocation>; /** * Checks if the grant has been revoked. * * @param remote - if true, the check will be made against the remote DWN. Defaults to false. * @returns true if the grant has been revoked, false otherwise. * @throws if there is an error checking the revocation status. * * @beta */ isRevoked(remote?: boolean): Promise<boolean>; /** * @returns the JSON representation of the grant */ toJSON(): DwnPermissionGrant; } //# sourceMappingURL=permission-grant.d.ts.map