UNPKG

@steeveproject/ngx-steem-keychain

Version:
508 lines (497 loc) 14.3 kB
/** * @license ngx-steem-keychain * MIT license */ import { __extends } from 'tslib'; import { Injectable, NgZone, NgModule, defineInjectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; /** * @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 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: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ SteemKeychainService.ctorParameters = function () { return [ { type: NgZone } ]; }; /** @nocollapse */ SteemKeychainService.ngInjectableDef = defineInjectable({ factory: function SteemKeychainService_Factory() { return new SteemKeychainService(inject(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: 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; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ export { SteemKeychainModule, SteemKeychainError, InvalidArgumentsError, Operation, SteemKeychainService }; //# sourceMappingURL=ngx-steem-keychain.js.map