UNPKG

@steeveproject/ngx-steem-keychain

Version:
529 lines (514 loc) 17.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs')) : typeof define === 'function' && define.amd ? define('ngx-steem-keychain', ['exports', '@angular/core', 'rxjs'], factory) : (factory((global.ng = global.ng || {}, global.ng.angularLibraryStarter = {}),global.ng.core,global.rxjs)); }(this, (function (exports,core,rxjs) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * @license ngx-steem-keychain * MIT license */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var SteemKeychainError = /** @class */ (function (_super) { __extends(SteemKeychainError, _super); function SteemKeychainError(response) { var _this = _super.call(this, response.message) || this; _this.response = response; Object.setPrototypeOf(_this, SteemKeychainError.prototype); return _this; } return SteemKeychainError; }(Error)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var SteemKeychainService = /** @class */ (function () { function SteemKeychainService(ngZone) { this.ngZone = ngZone; } Object.defineProperty(SteemKeychainService.prototype, "steemKeychainAvailable", { get: /** * @return {?} */ function () { return ((/** @type {?} */ (window))).steem_keychain !== undefined; }, enumerable: true, configurable: true }); /** * @return {?} */ SteemKeychainService.prototype.requestHandshake = /** * @return {?} */ function () { return this.call('requestHandshake', []); }; /** * @param {?} account * @param {?} encryptedMessage * @param {?} keyType * @return {?} */ SteemKeychainService.prototype.requestVerifyKey = /** * @param {?} account * @param {?} encryptedMessage * @param {?} keyType * @return {?} */ function (account, encryptedMessage, keyType) { return this.call('requestVerifyKey', [ account, encryptedMessage, keyType ]); }; /** * @param {?} account * @param {?} message * @param {?} keyType * @return {?} */ SteemKeychainService.prototype.requestSignBuffer = /** * @param {?} account * @param {?} message * @param {?} keyType * @return {?} */ function (account, message, keyType) { return this.call('requestSignBuffer', [ account, message, keyType ]); }; /** * @param {?} account * @param {?} operations * @param {?} keyType * @return {?} */ SteemKeychainService.prototype.requestBroadcast = /** * @param {?} account * @param {?} operations * @param {?} keyType * @return {?} */ function (account, operations, keyType) { return this.call('requestBroadcast', [ account, operations.map(function (op) { return op.toArray(); }), keyType ]); }; /** * @param {?} account * @param {?} method * @param {?} params * @param {?} keyType * @return {?} */ SteemKeychainService.prototype.requestSignedCall = /** * @param {?} account * @param {?} method * @param {?} params * @param {?} keyType * @return {?} */ function (account, method, params, keyType) { return this.call('requestSignedCall', [ account, method, params, keyType ]); }; /** * @param {?} parentAuthor * @param {?} parentPermlink * @param {?} author * @param {?} permlink * @param {?} title * @param {?} body * @param {?=} jsonMetadata * @param {?=} options * @return {?} */ SteemKeychainService.prototype.requestPost = /** * @param {?} parentAuthor * @param {?} parentPermlink * @param {?} author * @param {?} permlink * @param {?} title * @param {?} body * @param {?=} jsonMetadata * @param {?=} options * @return {?} */ function (parentAuthor, parentPermlink, author, permlink, title, body, jsonMetadata, options) { if (jsonMetadata === void 0) { jsonMetadata = ''; } if (options === void 0) { options = ''; } return this.call('requestPost', [ author, title, body, parentPermlink, parentAuthor, jsonMetadata, permlink, options ]); }; /** * @param {?} voter * @param {?} author * @param {?} permlink * @param {?} weight * @return {?} */ SteemKeychainService.prototype.requestVote = /** * @param {?} voter * @param {?} author * @param {?} permlink * @param {?} weight * @return {?} */ function (voter, author, permlink, weight) { return this.call('requestVote', [ voter, permlink, author, weight ]); }; /** * @param {?} account * @param {?} displayMessage * @param {?} id * @param {?} customJson * @param {?=} key * @return {?} */ SteemKeychainService.prototype.requestCustomJson = /** * @param {?} account * @param {?} displayMessage * @param {?} id * @param {?} customJson * @param {?=} key * @return {?} */ function (account, displayMessage, id, customJson, key) { if (key === void 0) { key = 'Posting'; } return this.call('requestCustomJson', [ account, id, ((/** @type {?} */ (key))).toLowerCase(), customJson, displayMessage ]); }; /** * @param {?} from * @param {?} to * @param {?} amount * @param {?} memo * @param {?} currency * @param {?=} enforce * @return {?} */ SteemKeychainService.prototype.requestTransfer = /** * @param {?} from * @param {?} to * @param {?} amount * @param {?} memo * @param {?} currency * @param {?=} enforce * @return {?} */ function (from, to, amount, memo, currency, enforce) { if (enforce === void 0) { enforce = false; } return this.call('requestTransfer', [ from, to, amount, memo, currency, enforce, ], 4); }; /** * @param {?} delegator * @param {?} delegatee * @param {?} amount * @param {?} unit * @return {?} */ SteemKeychainService.prototype.requestDelegation = /** * @param {?} delegator * @param {?} delegatee * @param {?} amount * @param {?} unit * @return {?} */ function (delegator, delegatee, amount, unit) { return this.call('requestDelegation', [ delegator, delegatee, amount, unit ]); }; /* * call is invoked by all other methods to call Steem Keychain. * It should not be used directly since it is not type-safe, * but it can be bandy in case there is a method not implemented yet. */ /* * call is invoked by all other methods to call Steem Keychain. * It should not be used directly since it is not type-safe, * but it can be bandy in case there is a method not implemented yet. */ /** * @param {?} method * @param {?} args * @param {?=} callbackIndex * @return {?} */ SteemKeychainService.prototype.call = /* * call is invoked by all other methods to call Steem Keychain. * It should not be used directly since it is not type-safe, * but it can be bandy in case there is a method not implemented yet. */ /** * @param {?} method * @param {?} args * @param {?=} callbackIndex * @return {?} */ function (method, args, callbackIndex) { var _this = this; return rxjs.Observable.create(function (observer) { var _a; // Make sure the extension is available. if (!_this.steemKeychainAvailable) { observer.error(new Error('Steem Keychain not available')); observer.complete(); return; } // Push the callback to the argument list. /** @type {?} */ var cb = function (res) { return _this.ngZone.run(function () { if (res.success) { observer.next(res); observer.complete(); } else { observer.error(new SteemKeychainError(res)); } }); }; if (callbackIndex) { args.splice(callbackIndex, 0, cb); } else { args.push(cb); } // Send the request. (_a = ((/** @type {?} */ (window))).steem_keychain)[method].apply(_a, args); }); }; SteemKeychainService.decorators = [ { type: core.Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ SteemKeychainService.ctorParameters = function () { return [ { type: core.NgZone } ]; }; /** @nocollapse */ SteemKeychainService.ngInjectableDef = core.defineInjectable({ factory: function SteemKeychainService_Factory() { return new SteemKeychainService(core.inject(core.NgZone)); }, token: SteemKeychainService, providedIn: "root" }); return SteemKeychainService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var SteemKeychainModule = /** @class */ (function () { function SteemKeychainModule() { } /** * Use in AppModule: new instance of SteemKeychainService. */ /** * Use in AppModule: new instance of SteemKeychainService. * @return {?} */ SteemKeychainModule.forRoot = /** * Use in AppModule: new instance of SteemKeychainService. * @return {?} */ function () { return { ngModule: SteemKeychainModule, providers: [SteemKeychainService] }; }; /** * Use in features modules with lazy loading: new instance of SteemKeychainService. */ /** * Use in features modules with lazy loading: new instance of SteemKeychainService. * @return {?} */ SteemKeychainModule.forChild = /** * Use in features modules with lazy loading: new instance of SteemKeychainService. * @return {?} */ function () { return { ngModule: SteemKeychainModule, providers: [SteemKeychainService] }; }; SteemKeychainModule.decorators = [ { type: core.NgModule } ]; return SteemKeychainModule; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ var InvalidArgumentsError = /** @class */ (function (_super) { __extends(InvalidArgumentsError, _super); function InvalidArgumentsError(message) { var _this = _super.call(this, message) || this; _this.message = message; Object.setPrototypeOf(_this, InvalidArgumentsError.prototype); return _this; } return InvalidArgumentsError; }(Error)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /* * Operation represents a blockchain operation, * which has a name and some parameters. */ var /* * Operation represents a blockchain operation, * which has a name and some parameters. */ Operation = /** @class */ (function () { function Operation(name, params) { this.name = name; this.params = params; } /* * fromArray can be used to convert [operationName, operationParams] into an Operation. */ /* * fromArray can be used to convert [operationName, operationParams] into an Operation. */ /** * @param {?} operation * @return {?} */ Operation.fromArray = /* * fromArray can be used to convert [operationName, operationParams] into an Operation. */ /** * @param {?} operation * @return {?} */ function (operation) { if (!operation) { throw new InvalidArgumentsError('operation array is unset'); } if (operation.length !== 2) { throw new InvalidArgumentsError('operation array length invalid (must be 2)'); } var name = operation[0], params = operation[1]; if (typeof name !== 'string') { throw new InvalidArgumentsError('operation[0] (operation name) must be a string'); } if (typeof params !== 'object') { throw new InvalidArgumentsError('operation[1] (operation params) must be an object'); } return new Operation(name, params); }; /* * toArray turns [operationName, operationParams]. */ /* * toArray turns [operationName, operationParams]. */ /** * @return {?} */ Operation.prototype.toArray = /* * toArray turns [operationName, operationParams]. */ /** * @return {?} */ function () { return [this.name, this.params]; }; /* * toJSON implements custom JSON serialization. * It simply calls toArray() and returns the result. */ /* * toJSON implements custom JSON serialization. * It simply calls toArray() and returns the result. */ /** * @return {?} */ Operation.prototype.toJSON = /* * toJSON implements custom JSON serialization. * It simply calls toArray() and returns the result. */ /** * @return {?} */ function () { return this.toArray(); }; return Operation; }()); exports.SteemKeychainModule = SteemKeychainModule; exports.SteemKeychainError = SteemKeychainError; exports.InvalidArgumentsError = InvalidArgumentsError; exports.Operation = Operation; exports.SteemKeychainService = SteemKeychainService; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-steem-keychain.umd.js.map