UNPKG

@airgap/etherlink

Version:

The @airgap/etherlink package is an implementation of the ICoinProtocol interface from @airgap/coinlib-core.

42 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.canSerializeProtocols = exports.protocolSerializerSchema = exports.createSupportedProtocols = void 0; var interface_1 = require("./interface"); function createSupportedProtocols(online, offline) { var onlineIdentifiers = new Set(Object.keys(online)); var offlineIdentifiers = offline ? new Set(offline) : onlineIdentifiers; var identifiers = new Set(Array.from(onlineIdentifiers).concat(Array.from(onlineIdentifiers))); return Array.from(identifiers).reduce(function (obj, next) { var _a; var offlineConfiguration = offlineIdentifiers.has(next) ? { type: 'offline' } : undefined; var onlineConfiguration = online[next] ? createOnlineProtocolConfiguration(online[next]) : undefined; var configuration = offlineConfiguration !== undefined && onlineConfiguration !== undefined ? { type: 'full', offline: offlineConfiguration, online: onlineConfiguration } : (offlineConfiguration !== null && offlineConfiguration !== void 0 ? offlineConfiguration : onlineConfiguration); return Object.assign(obj, (_a = {}, _a[next] = configuration, _a)); // tslint:disable-next-line: no-object-literal-type-assertion }, {}); } exports.createSupportedProtocols = createSupportedProtocols; function createOnlineProtocolConfiguration(networks) { var _a; return { type: 'online', networks: (_a = networks.supportedNetworks) !== null && _a !== void 0 ? _a : networks }; } // Schemas exports.protocolSerializerSchema = { serializeOfflineProtocol: 'required', deserializeOfflineProtocol: 'required', serializeOnlineProtocol: 'required', deserializeOnlineProtocol: 'required' }; // Implementation Checks function canSerializeProtocols(module) { return (0, interface_1.implementsInterface)(module, exports.protocolSerializerSchema); } exports.canSerializeProtocols = canSerializeProtocols; //# sourceMappingURL=module.js.map