UNPKG

@eversurf/dengine-js

Version:

Debot engine for Java Script

659 lines 25.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DebotModule = exports.resultOfAppDebotBrowserGetEncryptionBoxInfo = exports.resultOfAppDebotBrowserGetSigningBoxInfo = exports.resultOfAppDebotBrowserQueryTransactionTree = exports.resultOfAppDebotBrowserWaitForTransaction = exports.resultOfAppDebotBrowserWaitForCollection = exports.resultOfAppDebotBrowserQueryCollection = exports.resultOfAppDebotBrowserQuery = exports.resultOfAppDebotBrowserSendMessage = exports.resultOfAppDebotBrowserSign = exports.resultOfAppDebotBrowserDecrypt = exports.resultOfAppDebotBrowserEncrypt = exports.resultOfAppDebotBrowserFetch = exports.resultOfAppDebotBrowserApprove = exports.resultOfAppDebotBrowserGetSigningBox = exports.paramsOfAppDebotBrowserGetEncryptionBoxInfo = exports.paramsOfAppDebotBrowserGetSigningBoxInfo = exports.paramsOfAppDebotBrowserQueryTransactionTree = exports.paramsOfAppDebotBrowserWaitForTransaction = exports.paramsOfAppDebotBrowserWaitForCollection = exports.paramsOfAppDebotBrowserQueryCollection = exports.paramsOfAppDebotBrowserQuery = exports.paramsOfAppDebotBrowserSendMessage = exports.paramsOfAppDebotBrowserSign = exports.paramsOfAppDebotBrowserDecrypt = exports.paramsOfAppDebotBrowserEncrypt = exports.paramsOfAppDebotBrowserFetch = exports.paramsOfAppDebotBrowserApprove = exports.paramsOfAppDebotBrowserSend = exports.paramsOfAppDebotBrowserGetSigningBox = exports.paramsOfAppDebotBrowserLog = exports.LogLevel = exports.MessageBodyType = exports.abiSerialized = exports.abiHandle = exports.abiJson = exports.abiContract = exports.SortDirection = exports.debotActivityTransaction = exports.DebotErrorCode = exports.ClientModule = exports.appRequestResultOk = exports.appRequestResultError = exports.ClientErrorCode = void 0; // client module var ClientErrorCode; (function (ClientErrorCode) { ClientErrorCode[ClientErrorCode["NotImplemented"] = 1] = "NotImplemented"; ClientErrorCode[ClientErrorCode["InvalidHex"] = 2] = "InvalidHex"; ClientErrorCode[ClientErrorCode["InvalidBase64"] = 3] = "InvalidBase64"; ClientErrorCode[ClientErrorCode["InvalidAddress"] = 4] = "InvalidAddress"; ClientErrorCode[ClientErrorCode["CallbackParamsCantBeConvertedToJson"] = 5] = "CallbackParamsCantBeConvertedToJson"; ClientErrorCode[ClientErrorCode["WebsocketConnectError"] = 6] = "WebsocketConnectError"; ClientErrorCode[ClientErrorCode["WebsocketReceiveError"] = 7] = "WebsocketReceiveError"; ClientErrorCode[ClientErrorCode["WebsocketSendError"] = 8] = "WebsocketSendError"; ClientErrorCode[ClientErrorCode["HttpClientCreateError"] = 9] = "HttpClientCreateError"; ClientErrorCode[ClientErrorCode["HttpRequestCreateError"] = 10] = "HttpRequestCreateError"; ClientErrorCode[ClientErrorCode["HttpRequestSendError"] = 11] = "HttpRequestSendError"; ClientErrorCode[ClientErrorCode["HttpRequestParseError"] = 12] = "HttpRequestParseError"; ClientErrorCode[ClientErrorCode["CallbackNotRegistered"] = 13] = "CallbackNotRegistered"; ClientErrorCode[ClientErrorCode["NetModuleNotInit"] = 14] = "NetModuleNotInit"; ClientErrorCode[ClientErrorCode["InvalidConfig"] = 15] = "InvalidConfig"; ClientErrorCode[ClientErrorCode["CannotCreateRuntime"] = 16] = "CannotCreateRuntime"; ClientErrorCode[ClientErrorCode["InvalidContextHandle"] = 17] = "InvalidContextHandle"; ClientErrorCode[ClientErrorCode["CannotSerializeResult"] = 18] = "CannotSerializeResult"; ClientErrorCode[ClientErrorCode["CannotSerializeError"] = 19] = "CannotSerializeError"; ClientErrorCode[ClientErrorCode["CannotConvertJsValueToJson"] = 20] = "CannotConvertJsValueToJson"; ClientErrorCode[ClientErrorCode["CannotReceiveSpawnedResult"] = 21] = "CannotReceiveSpawnedResult"; ClientErrorCode[ClientErrorCode["SetTimerError"] = 22] = "SetTimerError"; ClientErrorCode[ClientErrorCode["InvalidParams"] = 23] = "InvalidParams"; ClientErrorCode[ClientErrorCode["ContractsAddressConversionFailed"] = 24] = "ContractsAddressConversionFailed"; ClientErrorCode[ClientErrorCode["UnknownFunction"] = 25] = "UnknownFunction"; ClientErrorCode[ClientErrorCode["AppRequestError"] = 26] = "AppRequestError"; ClientErrorCode[ClientErrorCode["NoSuchRequest"] = 27] = "NoSuchRequest"; ClientErrorCode[ClientErrorCode["CanNotSendRequestResult"] = 28] = "CanNotSendRequestResult"; ClientErrorCode[ClientErrorCode["CanNotReceiveRequestResult"] = 29] = "CanNotReceiveRequestResult"; ClientErrorCode[ClientErrorCode["CanNotParseRequestResult"] = 30] = "CanNotParseRequestResult"; ClientErrorCode[ClientErrorCode["UnexpectedCallbackResponse"] = 31] = "UnexpectedCallbackResponse"; ClientErrorCode[ClientErrorCode["CanNotParseNumber"] = 32] = "CanNotParseNumber"; ClientErrorCode[ClientErrorCode["InternalError"] = 33] = "InternalError"; ClientErrorCode[ClientErrorCode["InvalidHandle"] = 34] = "InvalidHandle"; ClientErrorCode[ClientErrorCode["LocalStorageError"] = 35] = "LocalStorageError"; ClientErrorCode[ClientErrorCode["InvalidData"] = 36] = "InvalidData"; ClientErrorCode[ClientErrorCode["DebotStartFailed"] = 801] = "DebotStartFailed"; ClientErrorCode[ClientErrorCode["DebotFetchFailed"] = 802] = "DebotFetchFailed"; ClientErrorCode[ClientErrorCode["DebotExecutionFailed"] = 803] = "DebotExecutionFailed"; ClientErrorCode[ClientErrorCode["DebotInvalidHandle"] = 804] = "DebotInvalidHandle"; ClientErrorCode[ClientErrorCode["DebotInvalidJsonParams"] = 805] = "DebotInvalidJsonParams"; ClientErrorCode[ClientErrorCode["DebotInvalidFunctionId"] = 806] = "DebotInvalidFunctionId"; ClientErrorCode[ClientErrorCode["DebotInvalidAbi"] = 807] = "DebotInvalidAbi"; ClientErrorCode[ClientErrorCode["DebotGetMethodFailed"] = 808] = "DebotGetMethodFailed"; ClientErrorCode[ClientErrorCode["DebotInvalidMsg"] = 809] = "DebotInvalidMsg"; ClientErrorCode[ClientErrorCode["DebotExternalCallFailed"] = 810] = "DebotExternalCallFailed"; ClientErrorCode[ClientErrorCode["DebotBrowserCallbackFailed"] = 811] = "DebotBrowserCallbackFailed"; ClientErrorCode[ClientErrorCode["DebotOperationRejected"] = 812] = "DebotOperationRejected"; ClientErrorCode[ClientErrorCode["DebotNoCode"] = 813] = "DebotNoCode"; })(ClientErrorCode = exports.ClientErrorCode || (exports.ClientErrorCode = {})); function appRequestResultError(text) { return { type: 'Error', text, }; } exports.appRequestResultError = appRequestResultError; function appRequestResultOk(result) { return { type: 'Ok', result, }; } exports.appRequestResultOk = appRequestResultOk; /** * Provides information about library. */ class ClientModule { constructor(client) { this.client = client; } /** * Returns Core Library API reference * @returns ResultOfGetApiReference */ get_api_reference() { return this.client.request('client.get_api_reference'); } /** * Returns Core Library API reference * * NOTE: Available only for `lib-node` binding. * * * @returns ResultOfGetApiReference */ get_api_reference_sync() { return this.client.requestSync('client.get_api_reference'); } /** * Resolves application request processing result * * @param {ParamsOfResolveAppRequest} params * @returns */ resolve_app_request(params) { return this.client.request('client.resolve_app_request', params); } /** * Resolves application request processing result * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfResolveAppRequest} params * @returns */ resolve_app_request_sync(params) { this.client.requestSync('client.resolve_app_request', params); } } exports.ClientModule = ClientModule; // debot module var DebotErrorCode; (function (DebotErrorCode) { DebotErrorCode[DebotErrorCode["DebotStartFailed"] = 801] = "DebotStartFailed"; DebotErrorCode[DebotErrorCode["DebotFetchFailed"] = 802] = "DebotFetchFailed"; DebotErrorCode[DebotErrorCode["DebotExecutionFailed"] = 803] = "DebotExecutionFailed"; DebotErrorCode[DebotErrorCode["DebotInvalidHandle"] = 804] = "DebotInvalidHandle"; DebotErrorCode[DebotErrorCode["DebotInvalidJsonParams"] = 805] = "DebotInvalidJsonParams"; DebotErrorCode[DebotErrorCode["DebotInvalidFunctionId"] = 806] = "DebotInvalidFunctionId"; DebotErrorCode[DebotErrorCode["DebotInvalidAbi"] = 807] = "DebotInvalidAbi"; DebotErrorCode[DebotErrorCode["DebotGetMethodFailed"] = 808] = "DebotGetMethodFailed"; DebotErrorCode[DebotErrorCode["DebotInvalidMsg"] = 809] = "DebotInvalidMsg"; DebotErrorCode[DebotErrorCode["DebotExternalCallFailed"] = 810] = "DebotExternalCallFailed"; DebotErrorCode[DebotErrorCode["DebotBrowserCallbackFailed"] = 811] = "DebotBrowserCallbackFailed"; DebotErrorCode[DebotErrorCode["DebotOperationRejected"] = 812] = "DebotOperationRejected"; DebotErrorCode[DebotErrorCode["DebotNoCode"] = 813] = "DebotNoCode"; })(DebotErrorCode = exports.DebotErrorCode || (exports.DebotErrorCode = {})); function debotActivityTransaction(msg, dst, out, fee, setcode, signkey, signing_box_handle) { return { type: 'Transaction', msg, dst, out, fee, setcode, signkey, signing_box_handle, }; } exports.debotActivityTransaction = debotActivityTransaction; var SortDirection; (function (SortDirection) { SortDirection["ASC"] = "ASC"; SortDirection["DESC"] = "DESC"; })(SortDirection = exports.SortDirection || (exports.SortDirection = {})); function abiContract(value) { return { type: 'Contract', value, }; } exports.abiContract = abiContract; function abiJson(value) { return { type: 'Json', value, }; } exports.abiJson = abiJson; function abiHandle(value) { return { type: 'Handle', value, }; } exports.abiHandle = abiHandle; function abiSerialized(value) { return { type: 'Serialized', value, }; } exports.abiSerialized = abiSerialized; var MessageBodyType; (function (MessageBodyType) { MessageBodyType["Input"] = "Input"; MessageBodyType["Output"] = "Output"; MessageBodyType["InternalOutput"] = "InternalOutput"; MessageBodyType["Event"] = "Event"; })(MessageBodyType = exports.MessageBodyType || (exports.MessageBodyType = {})); var LogLevel; (function (LogLevel) { LogLevel["User"] = "User"; LogLevel["Error"] = "Error"; LogLevel["Warn"] = "Warn"; LogLevel["Debug"] = "Debug"; LogLevel["Trace"] = "Trace"; })(LogLevel = exports.LogLevel || (exports.LogLevel = {})); function paramsOfAppDebotBrowserLog(level, msg) { return { type: 'Log', level, msg, }; } exports.paramsOfAppDebotBrowserLog = paramsOfAppDebotBrowserLog; function paramsOfAppDebotBrowserGetSigningBox() { return { type: 'GetSigningBox', }; } exports.paramsOfAppDebotBrowserGetSigningBox = paramsOfAppDebotBrowserGetSigningBox; function paramsOfAppDebotBrowserSend(message) { return { type: 'Send', message, }; } exports.paramsOfAppDebotBrowserSend = paramsOfAppDebotBrowserSend; function paramsOfAppDebotBrowserApprove(activity) { return { type: 'Approve', activity, }; } exports.paramsOfAppDebotBrowserApprove = paramsOfAppDebotBrowserApprove; function paramsOfAppDebotBrowserFetch(url, method, headers, body) { return { type: 'Fetch', url, method, headers, body, }; } exports.paramsOfAppDebotBrowserFetch = paramsOfAppDebotBrowserFetch; function paramsOfAppDebotBrowserEncrypt(handle, data) { return { type: 'Encrypt', handle, data, }; } exports.paramsOfAppDebotBrowserEncrypt = paramsOfAppDebotBrowserEncrypt; function paramsOfAppDebotBrowserDecrypt(handle, data) { return { type: 'Decrypt', handle, data, }; } exports.paramsOfAppDebotBrowserDecrypt = paramsOfAppDebotBrowserDecrypt; function paramsOfAppDebotBrowserSign(handle, data) { return { type: 'Sign', handle, data, }; } exports.paramsOfAppDebotBrowserSign = paramsOfAppDebotBrowserSign; function paramsOfAppDebotBrowserSendMessage(message) { return { type: 'SendMessage', message, }; } exports.paramsOfAppDebotBrowserSendMessage = paramsOfAppDebotBrowserSendMessage; function paramsOfAppDebotBrowserQuery(params) { return { type: 'Query', params, }; } exports.paramsOfAppDebotBrowserQuery = paramsOfAppDebotBrowserQuery; function paramsOfAppDebotBrowserQueryCollection(params) { return { type: 'QueryCollection', params, }; } exports.paramsOfAppDebotBrowserQueryCollection = paramsOfAppDebotBrowserQueryCollection; function paramsOfAppDebotBrowserWaitForCollection(params) { return { type: 'WaitForCollection', params, }; } exports.paramsOfAppDebotBrowserWaitForCollection = paramsOfAppDebotBrowserWaitForCollection; function paramsOfAppDebotBrowserWaitForTransaction(params) { return { type: 'WaitForTransaction', params, }; } exports.paramsOfAppDebotBrowserWaitForTransaction = paramsOfAppDebotBrowserWaitForTransaction; function paramsOfAppDebotBrowserQueryTransactionTree(params) { return { type: 'QueryTransactionTree', params, }; } exports.paramsOfAppDebotBrowserQueryTransactionTree = paramsOfAppDebotBrowserQueryTransactionTree; function paramsOfAppDebotBrowserGetSigningBoxInfo(handle) { return { type: 'GetSigningBoxInfo', handle, }; } exports.paramsOfAppDebotBrowserGetSigningBoxInfo = paramsOfAppDebotBrowserGetSigningBoxInfo; function paramsOfAppDebotBrowserGetEncryptionBoxInfo(handle) { return { type: 'GetEncryptionBoxInfo', handle, }; } exports.paramsOfAppDebotBrowserGetEncryptionBoxInfo = paramsOfAppDebotBrowserGetEncryptionBoxInfo; function resultOfAppDebotBrowserGetSigningBox(signing_box) { return { type: 'GetSigningBox', signing_box, }; } exports.resultOfAppDebotBrowserGetSigningBox = resultOfAppDebotBrowserGetSigningBox; function resultOfAppDebotBrowserApprove(approved) { return { type: 'Approve', approved, }; } exports.resultOfAppDebotBrowserApprove = resultOfAppDebotBrowserApprove; function resultOfAppDebotBrowserFetch(response) { return { type: 'Fetch', response, }; } exports.resultOfAppDebotBrowserFetch = resultOfAppDebotBrowserFetch; function resultOfAppDebotBrowserEncrypt(encrypted) { return { type: 'Encrypt', encrypted, }; } exports.resultOfAppDebotBrowserEncrypt = resultOfAppDebotBrowserEncrypt; function resultOfAppDebotBrowserDecrypt(decrypted) { return { type: 'Decrypt', decrypted, }; } exports.resultOfAppDebotBrowserDecrypt = resultOfAppDebotBrowserDecrypt; function resultOfAppDebotBrowserSign(signature) { return { type: 'Sign', signature, }; } exports.resultOfAppDebotBrowserSign = resultOfAppDebotBrowserSign; function resultOfAppDebotBrowserSendMessage(shard_block_id, sending_endpoints) { return { type: 'SendMessage', shard_block_id, sending_endpoints, }; } exports.resultOfAppDebotBrowserSendMessage = resultOfAppDebotBrowserSendMessage; function resultOfAppDebotBrowserQuery(result) { return { type: 'Query', result, }; } exports.resultOfAppDebotBrowserQuery = resultOfAppDebotBrowserQuery; function resultOfAppDebotBrowserQueryCollection(result) { return { type: 'QueryCollection', result, }; } exports.resultOfAppDebotBrowserQueryCollection = resultOfAppDebotBrowserQueryCollection; function resultOfAppDebotBrowserWaitForCollection(result) { return { type: 'WaitForCollection', result, }; } exports.resultOfAppDebotBrowserWaitForCollection = resultOfAppDebotBrowserWaitForCollection; function resultOfAppDebotBrowserWaitForTransaction(result) { return { type: 'WaitForTransaction', result, }; } exports.resultOfAppDebotBrowserWaitForTransaction = resultOfAppDebotBrowserWaitForTransaction; function resultOfAppDebotBrowserQueryTransactionTree(result) { return { type: 'QueryTransactionTree', result, }; } exports.resultOfAppDebotBrowserQueryTransactionTree = resultOfAppDebotBrowserQueryTransactionTree; function resultOfAppDebotBrowserGetSigningBoxInfo(pubkey) { return { type: 'GetSigningBoxInfo', pubkey, }; } exports.resultOfAppDebotBrowserGetSigningBoxInfo = resultOfAppDebotBrowserGetSigningBoxInfo; function resultOfAppDebotBrowserGetEncryptionBoxInfo(result) { return { type: 'GetEncryptionBoxInfo', result, }; } exports.resultOfAppDebotBrowserGetEncryptionBoxInfo = resultOfAppDebotBrowserGetEncryptionBoxInfo; function dispatchAppDebotBrowser(obj, params, app_request_id, client) { return __awaiter(this, void 0, void 0, function* () { try { let result = {}; switch (params.type) { case 'Log': obj.log(params); break; case 'GetSigningBox': result = yield obj.get_signing_box(); break; case 'Send': obj.send(params); break; case 'Approve': result = yield obj.approve(params); break; case 'Fetch': result = yield obj.fetch(params); break; case 'Encrypt': result = yield obj.encrypt(params); break; case 'Decrypt': result = yield obj.decrypt(params); break; case 'Sign': result = yield obj.sign(params); break; case 'SendMessage': result = yield obj.send_message(params); break; case 'Query': result = yield obj.query(params); break; case 'QueryCollection': result = yield obj.query_collection(params); break; case 'WaitForCollection': result = yield obj.wait_for_collection(params); break; case 'WaitForTransaction': result = yield obj.wait_for_transaction(params); break; case 'QueryTransactionTree': result = yield obj.query_transaction_tree(params); break; case 'GetSigningBoxInfo': result = yield obj.get_signing_box_info(params); break; case 'GetEncryptionBoxInfo': result = yield obj.get_encryption_box_info(params); break; } client.resolve_app_request(app_request_id, Object.assign({ type: params.type }, result)); } catch (error) { client.reject_app_request(app_request_id, error); } }); } /** * [DEPRECATED](DEPRECATED.md) Module for working with debot. */ class DebotModule { constructor(client) { this.client = client; } /** * Creates and instance of DeBot. * * @remarks * Downloads debot smart contract (code and data) from blockchain and creates * an instance of Debot Engine for it. * * # Remarks * It does not switch debot to context 0. Browser Callbacks are not called. * * @param {ParamsOfInit} params * @returns RegisteredDebot */ init(params, obj) { return this.client.request('debot.init', params, (params, responseType) => { if (responseType === 3) { dispatchAppDebotBrowser(obj, params.request_data, params.app_request_id, this.client); } else if (responseType === 4) { dispatchAppDebotBrowser(obj, params, null, this.client); } }); } /** * Creates and instance of DeBot. * * @remarks * Downloads debot smart contract (code and data) from blockchain and creates * an instance of Debot Engine for it. * * # Remarks * It does not switch debot to context 0. Browser Callbacks are not called. * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfInit} params * @returns RegisteredDebot */ init_sync(params) { return this.client.requestSync('debot.init', params); } /** * Starts the DeBot. * * @remarks * This function must be used by Debot Browser to start a dialog with debot. * While the function is executing, several Browser Callbacks can be called. * * When the debot starts SDK registers `BrowserCallbacks` AppObject. * Therefore when `debote.remove` is called the debot is being deleted and the callback is called * with `finish`=`true` which indicates that it will never be used again. * * @param {ParamsOfStart} params * @returns */ start(params) { return this.client.request('debot.start', params); } /** * Starts the DeBot. * * @remarks * This function must be used by Debot Browser to start a dialog with debot. * While the function is executing, several Browser Callbacks can be called. * * When the debot starts SDK registers `BrowserCallbacks` AppObject. * Therefore when `debote.remove` is called the debot is being deleted and the callback is called * with `finish`=`true` which indicates that it will never be used again. * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfStart} params * @returns */ start_sync(params) { this.client.requestSync('debot.start', params); } /** * Fetches DeBot metadata from blockchain. * * @remarks * Downloads DeBot from blockchain and creates and fetches its metadata. * * @param {ParamsOfFetch} params * @returns ResultOfFetch */ fetch(params) { return this.client.request('debot.fetch', params); } /** * Fetches DeBot metadata from blockchain. * * @remarks * Downloads DeBot from blockchain and creates and fetches its metadata. * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfFetch} params * @returns ResultOfFetch */ fetch_sync(params) { return this.client.requestSync('debot.fetch', params); } /** * Sends message to Debot. * * @remarks * Used by Debot Browser to send response on Dinterface call or from other Debots. * * @param {ParamsOfSend} params * @returns */ send(params) { return this.client.request('debot.send', params); } /** * Sends message to Debot. * * @remarks * Used by Debot Browser to send response on Dinterface call or from other Debots. * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfSend} params * @returns */ send_sync(params) { this.client.requestSync('debot.send', params); } /** * Destroys debot handle. * * @remarks * Removes handle from Client Context and drops debot engine referenced by that handle. * * @param {ParamsOfRemove} params * @returns */ remove(params) { return this.client.request('debot.remove', params); } /** * Destroys debot handle. * * @remarks * Removes handle from Client Context and drops debot engine referenced by that handle. * * NOTE: Available only for `lib-node` binding. * * * * @param {ParamsOfRemove} params * @returns */ remove_sync(params) { this.client.requestSync('debot.remove', params); } } exports.DebotModule = DebotModule; //# sourceMappingURL=modules.js.map