UNPKG

heimdall-tide

Version:

SDK for communicating with a Tide Enclave

52 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ApprovalEnclaveNew = void 0; const heimdall_1 = require("../heimdall"); const RequestEnclave_1 = require("./RequestEnclave"); class ApprovalEnclaveNew extends RequestEnclave_1.RequestEnclave { constructor() { super(...arguments); this.name = "approvalNew"; this._windowType = heimdall_1.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; } } exports.ApprovalEnclaveNew = ApprovalEnclaveNew; 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