UNPKG

@microsoft/useragent-sdk

Version:

SDK for building decentralized identity wallets and enterprise agents.

84 lines (83 loc) 3.01 kB
import HubCommitWriteRequest from './requests/HubCommitWriteRequest'; import HubWriteResponse from './responses/HubWriteResponse'; import HubObjectQueryRequest from './requests/HubObjectQueryRequest'; import HubObjectQueryResponse from './responses/HubObjectQueryResponse'; import HubCommitQueryRequest from './requests/HubCommitQueryRequest'; import HubCommitQueryResponse from './responses/HubCommitQueryResponse'; import Identifier from '../Identifier'; /** * Options for instantiating a new Hub session. */ export declare class HubSessionOptions { /** * The DID of the client, i.e the identity of the user/app using this SDK. */ client?: Identifier; /** * The reference to the private key to use for signing when communicating with the Hub. Must be * registered in the DID document of the clientDid. */ signingKeyReference: string | undefined; /** * The reference to the private key to use for decrypting the hub communication. Must be * registered in the DID document of the clientDid. */ encryptionKeyReference: string | undefined; /** * The Identfier of the owner of the Hub with which we will be communicating. */ hubOwner?: Identifier; /** * The Identifier of the Hub, for addressing request envelopes. */ hubId: string; /** * The HTTPS endpoint of the Hub. */ hubEndpoint: string; } /** * Represents a communication session with a particular Hub instance. */ export default class HubSession { private client?; private hubId; private hubEndpoint; private hubOwner?; private signingKeyReference; private encryptionKeyReference; constructor(options: HubSessionOptions); /** * Sends the given request to the Hub instance, and returns the associated response. * * @param request An instance or subclass of HubRequest to be sent. */ send(request: HubCommitWriteRequest): Promise<HubWriteResponse>; send(request: HubObjectQueryRequest): Promise<HubObjectQueryResponse>; send(request: HubCommitQueryRequest): Promise<HubCommitQueryResponse>; /** * Sends a raw (string) request body to the Hub and receives a response. * * @param message The raw request body to send. * @param accessToken The access token to include in the request, if any. */ private makeRequest; /** * Fetch API wrapper, to allow unit testing. * * @param url The URL to make a request to. * @param init Request initialization details. */ private callFetch; /** * Mapping of known response types. */ private static responseTypes; /** * Transforms a JSON blob returned by the Hub into a subclass of HubResponse, based on the `@type` * field of the response. * * @param response The Hub response to be transformed. */ private static mapResponseToObject; }