UNPKG

@enbox/api

Version:

SDK for accessing the features and capabilities of Web5

108 lines 4.66 kB
import { DwnDataEncodedRecordsWriteMessage, DwnPermissionConditions, DwnPermissionScope, DwnResponseStatus, Web5Agent } from '@enbox/agent'; import { PermissionGrant } from './permission-grant.js'; /** * Represents the structured data model of a PermissionsRequest record, encapsulating the essential fields that define * the request's data and payload within a Decentralized Web Node (DWN). */ export interface PermissionRequestModel { /** * The ID of the permission request, which is the record ID DWN message. */ readonly id: string; /** * The requester for of the permission. */ readonly requester: string; /** * Optional string that communicates what the requested grant would be used for. */ readonly description?: string; /** * Whether the requested grant is delegated or not. * If `true`, the `requestor` will be able to act as the grantor of the permission within the scope of the requested grant. */ readonly delegated?: boolean; /** * The scope of the allowed access. */ readonly scope: DwnPermissionScope; /** * Optional conditions that must be met when the requested grant is used. */ readonly conditions?: DwnPermissionConditions; } /** * The `PermissionRequest` class encapsulates a permissions protocol `request` record, providing a more * developer-friendly interface for working with Decentralized Web Node (DWN) records. * * Methods are provided to grant the request and manage the request's lifecycle, including writing to remote DWNs. * * @beta */ export declare class PermissionRequest implements PermissionRequestModel { /** The PermissionsAPI used to interact with the underlying permission request */ private _permissions; /** The DID to use as the author and default target for the underlying permission request */ private _connectedDid; /** The underlying DWN `RecordsWrite` message along with encoded data that represent the request */ private _message; /** The parsed permission request object */ private _request; private constructor(); /** parses the request given an agent, connectedDid and data encoded records write message */ static parse({ connectedDid, agent, message }: { connectedDid: string; agent: Web5Agent; message: DwnDataEncodedRecordsWriteMessage; }): Promise<PermissionRequest>; /** The agent to use for this instantiation of the request */ private get agent(); /** The request's ID, which is also the underlying record's ID */ get id(): string; /** The DID that is requesting a permission */ get requester(): string; /** (optional) Description of the permission request */ get description(): string; /** Whether or not the permission request can be used to impersonate the grantor */ get delegated(): boolean; /** The permission scope under which the requested grant would be valid */ get scope(): DwnPermissionScope; /** The conditions under which the requested grant would be valid */ get conditions(): DwnPermissionConditions; /** The `RecordsWrite` DWN message with encoded data that was used to instantiate this request */ get rawMessage(): DwnDataEncodedRecordsWriteMessage; /** * Send the current permission request 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 permission request to, if none is set it is sent to the connectedDid * @returns the status of the send permission request * * @beta */ send(target?: string): Promise<DwnResponseStatus>; /** * Stores the current permission request to the owner's DWN. * * @param importGrant - if true, the permission request 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(): Promise<DwnResponseStatus>; /** * Grants the permission request to the requester. * * @param dateExpires - the date when the permission grant will expire. * @param store - if true, the permission grant will be stored in the owner's DWN. Defaults to true. * @returns {PermissionGrant} the granted permission. * * @beta */ grant(dateExpires: string, store?: boolean): Promise<PermissionGrant>; /** * @returns the JSON representation of the permission request */ toJSON(): PermissionRequestModel; } //# sourceMappingURL=permission-request.d.ts.map