UNPKG

heimdall-tide

Version:

SDK for communicating with a Tide Enclave

48 lines 1.65 kB
import { windowType } from "../heimdall"; import { RequestEnclave } from "./RequestEnclave"; export class ApprovalEnclaveNew extends RequestEnclave { constructor() { super(...arguments); this.name = "approvalNew"; this._windowType = windowType.Popup; } init(data) { return super.init(data); } async approve(requestsToApprove) { // return fully serialized approved requests this.checkEnclaveOpen(); await this.initDone; const pre_resp = this.recieve("approvals"); this.send({ type: "approvalRequests", message: { requests: requestsToApprove, } }); const resp = await pre_resp; if (!Array.isArray(resp)) throw 'Expecting request completed data to be an array, not' + resp; if (!resp.every((d) => OperatorApprovalResponse.isOperatorApprovalResponse(d))) throw 'Expecting all entries in response to be OperatorApprovalResponse'; this.close(); return resp; } } class RequestToApprove { } class OperatorApprovalResponse extends RequestToApprove { static isOperatorApprovalResponse(object) { return (object != null && typeof object.id === 'string' && (object.request instanceof Uint8Array || object.request == null) && Object.values(Status).includes(object.status)); } } var Status; (function (Status) { Status["Approved"] = "approved"; Status["Denied"] = "denied"; Status["Pending"] = "pending"; })(Status || (Status = {})); //# sourceMappingURL=ApprovalEnclaveNEW.js.map