hive-keychain-commons 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # hive-keychain-commons
2
+ Platform agnostic functions used in Hive Keychain mobile and extensions
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './interfaces/keychain';
2
+ export { LeaseKeys } from './lease-market/lease-keys';
3
+ export { AcceptRequestJSON, CancelDelegationJSON, CancelRequestJSON, PaymentJSON, ReimbursmentJSON, RequestCancelRequestJSON, RequestJSON, } from './lease-market/lease-market.interface';
4
+ export * from './swaps/config.interface';
5
+ export * from './swaps/swap-api.interface';
6
+ export * from './swaps/swap.interface';
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.LeaseKeys = void 0;
14
+ __exportStar(require("./interfaces/keychain"), exports);
15
+ var lease_keys_1 = require("./lease-market/lease-keys");
16
+ Object.defineProperty(exports, "LeaseKeys", { enumerable: true, get: function () { return lease_keys_1.LeaseKeys; } });
17
+ __exportStar(require("./swaps/config.interface"), exports);
18
+ __exportStar(require("./swaps/swap-api.interface"), exports);
19
+ __exportStar(require("./swaps/swap.interface"), exports);
@@ -0,0 +1,278 @@
1
+ import { Operation, Transaction } from '@hiveio/dhive';
2
+ export declare enum KeychainRequestTypes {
3
+ decode = "decode",
4
+ encode = "encode",
5
+ signBuffer = "signBuffer",
6
+ broadcast = "broadcast",
7
+ addAccountAuthority = "addAccountAuthority",
8
+ removeAccountAuthority = "removeAccountAuthority",
9
+ removeKeyAuthority = "removeKeyAuthority",
10
+ addKeyAuthority = "addKeyAuthority",
11
+ signTx = "signTx",
12
+ post = "post",
13
+ vote = "vote",
14
+ custom = "custom",
15
+ signedCall = "signedCall",
16
+ transfer = "transfer",
17
+ sendToken = "sendToken",
18
+ delegation = "delegation",
19
+ witnessVote = "witnessVote",
20
+ proxy = "proxy",
21
+ powerUp = "powerUp",
22
+ powerDown = "powerDown",
23
+ createClaimedAccount = "createClaimedAccount",
24
+ createProposal = "createProposal",
25
+ removeProposal = "removeProposal",
26
+ updateProposalVote = "updateProposalVote",
27
+ addAccount = "addAccount",
28
+ convert = "convert",
29
+ recurrentTransfer = "recurrentTransfer"
30
+ }
31
+ export declare enum KeychainKeyTypes {
32
+ posting = "Posting",
33
+ active = "Active",
34
+ memo = "Memo"
35
+ }
36
+ export declare enum KeychainKeyTypesLC {
37
+ posting = "posting",
38
+ active = "active",
39
+ memo = "memo"
40
+ }
41
+ declare type CommonRequestParams = {
42
+ rpc?: string;
43
+ domain: string;
44
+ key?: string;
45
+ };
46
+ export declare type RequestDecode = CommonRequestParams & {
47
+ type: KeychainRequestTypes.decode;
48
+ username: string;
49
+ message: string;
50
+ method: KeychainKeyTypes;
51
+ };
52
+ export declare type RequestEncode = CommonRequestParams & {
53
+ type: KeychainRequestTypes.encode;
54
+ username: string;
55
+ receiver: string;
56
+ message: string;
57
+ method: KeychainKeyTypes;
58
+ };
59
+ export declare type ExcludeCommonParams<T> = Omit<T, 'rpc' | 'type' | 'key' | 'domain'>;
60
+ export declare type RequestSignBuffer = CommonRequestParams & {
61
+ type: KeychainRequestTypes.signBuffer;
62
+ username?: string;
63
+ message: string;
64
+ method: KeychainKeyTypes;
65
+ title?: string;
66
+ };
67
+ export declare type RequestBroadcast = CommonRequestParams & {
68
+ type: KeychainRequestTypes.broadcast;
69
+ username: string;
70
+ operations: string | Operation[];
71
+ method: KeychainKeyTypes;
72
+ };
73
+ export declare type RequestAddAccountAuthority = CommonRequestParams & {
74
+ type: KeychainRequestTypes.addAccountAuthority;
75
+ authorizedUsername: string;
76
+ role: KeychainKeyTypes;
77
+ weight: number;
78
+ username: string;
79
+ };
80
+ export declare type RequestRemoveAccountAuthority = CommonRequestParams & {
81
+ type: KeychainRequestTypes.removeAccountAuthority;
82
+ authorizedUsername: string;
83
+ role: KeychainKeyTypes;
84
+ username: string;
85
+ };
86
+ export declare type RequestAddKeyAuthority = CommonRequestParams & {
87
+ type: KeychainRequestTypes.addKeyAuthority;
88
+ authorizedKey: string;
89
+ role: KeychainKeyTypes;
90
+ username: string;
91
+ weight: number;
92
+ };
93
+ export declare type RequestRemoveKeyAuthority = CommonRequestParams & {
94
+ type: KeychainRequestTypes.removeKeyAuthority;
95
+ authorizedKey: string;
96
+ role: KeychainKeyTypes;
97
+ username: string;
98
+ };
99
+ export declare type RequestSignTx = CommonRequestParams & {
100
+ type: KeychainRequestTypes.signTx;
101
+ username: string;
102
+ tx: Transaction;
103
+ method: KeychainKeyTypes;
104
+ };
105
+ export declare type RequestPost = CommonRequestParams & {
106
+ type: KeychainRequestTypes.post;
107
+ username: string;
108
+ title?: string;
109
+ body: string;
110
+ parent_perm: string;
111
+ parent_username?: string;
112
+ json_metadata: string;
113
+ permlink: string;
114
+ comment_options: string;
115
+ };
116
+ export declare type RequestVote = CommonRequestParams & {
117
+ type: KeychainRequestTypes.vote;
118
+ username: string;
119
+ permlink: string;
120
+ author: string;
121
+ weight: string | number;
122
+ };
123
+ export declare type RequestCustomJSON = CommonRequestParams & {
124
+ type: KeychainRequestTypes.custom;
125
+ username?: string;
126
+ id: string;
127
+ method: KeychainKeyTypes;
128
+ json: string;
129
+ display_msg: string;
130
+ };
131
+ export declare type RequestSignedCall = CommonRequestParams & {
132
+ type: KeychainRequestTypes.signedCall;
133
+ username: string;
134
+ method: string;
135
+ params: string;
136
+ typeWif: KeychainKeyTypes;
137
+ };
138
+ export declare type RequestTransfer = CommonRequestParams & {
139
+ type: KeychainRequestTypes.transfer;
140
+ username?: string;
141
+ to: string;
142
+ amount: string;
143
+ memo: string;
144
+ enforce: boolean;
145
+ currency: string;
146
+ };
147
+ export declare type RequestSendToken = CommonRequestParams & {
148
+ type: KeychainRequestTypes.sendToken;
149
+ username: string;
150
+ to: string;
151
+ amount: string;
152
+ memo: string;
153
+ currency: string;
154
+ };
155
+ export declare type RequestDelegation = CommonRequestParams & {
156
+ type: KeychainRequestTypes.delegation;
157
+ username?: string;
158
+ delegatee: string;
159
+ amount: string;
160
+ unit: string;
161
+ };
162
+ export declare type RequestWitnessVote = CommonRequestParams & {
163
+ type: KeychainRequestTypes.witnessVote;
164
+ username?: string;
165
+ witness: string;
166
+ vote: boolean;
167
+ };
168
+ export declare type RequestProxy = CommonRequestParams & {
169
+ type: KeychainRequestTypes.proxy;
170
+ username?: string;
171
+ proxy: string;
172
+ };
173
+ export declare type RequestPowerUp = CommonRequestParams & {
174
+ type: KeychainRequestTypes.powerUp;
175
+ username: string;
176
+ recipient: string;
177
+ hive: string;
178
+ };
179
+ export declare type RequestPowerDown = CommonRequestParams & {
180
+ type: KeychainRequestTypes.powerDown;
181
+ username: string;
182
+ hive_power: string;
183
+ };
184
+ export declare type RequestCreateClaimedAccount = CommonRequestParams & {
185
+ type: KeychainRequestTypes.createClaimedAccount;
186
+ username: string;
187
+ new_account: string;
188
+ owner: string;
189
+ active: string;
190
+ posting: string;
191
+ memo: string;
192
+ };
193
+ export declare type RequestUpdateProposalVote = CommonRequestParams & {
194
+ type: KeychainRequestTypes.updateProposalVote;
195
+ username: string;
196
+ proposal_ids: string | number[];
197
+ approve: boolean;
198
+ extensions: string | any[];
199
+ };
200
+ export declare type RequestCreateProposal = CommonRequestParams & {
201
+ type: KeychainRequestTypes.createProposal;
202
+ username: string;
203
+ receiver: string;
204
+ subject: string;
205
+ permlink: string;
206
+ start: string;
207
+ end: string;
208
+ daily_pay: string;
209
+ extensions: string;
210
+ };
211
+ export declare type RequestRemoveProposal = CommonRequestParams & {
212
+ type: KeychainRequestTypes.removeProposal;
213
+ username: string;
214
+ proposal_ids: string | number[];
215
+ extensions: string;
216
+ };
217
+ export declare type RequestAddAccountKeys = {
218
+ posting?: string;
219
+ active?: string;
220
+ memo?: string;
221
+ };
222
+ export declare type RequestAddAccount = CommonRequestParams & {
223
+ type: KeychainRequestTypes.addAccount;
224
+ username: string;
225
+ keys: RequestAddAccountKeys;
226
+ };
227
+ export declare type RequestConvert = CommonRequestParams & {
228
+ type: KeychainRequestTypes.convert;
229
+ username: string;
230
+ amount: string;
231
+ collaterized: boolean;
232
+ };
233
+ export declare type RequestRecurrentTransfer = CommonRequestParams & {
234
+ type: KeychainRequestTypes.recurrentTransfer;
235
+ username?: string;
236
+ to: string;
237
+ amount: string;
238
+ currency: string;
239
+ memo: string;
240
+ recurrence: number;
241
+ executions: number;
242
+ };
243
+ export declare type KeychainRequestData = (RequestDecode | RequestEncode | RequestSignBuffer | RequestBroadcast | RequestAddAccountAuthority | RequestRemoveAccountAuthority | RequestAddKeyAuthority | RequestRemoveKeyAuthority | RequestSignTx | RequestPost | RequestVote | RequestCustomJSON | RequestSignedCall | RequestTransfer | RequestSendToken | RequestDelegation | RequestWitnessVote | RequestProxy | RequestPowerUp | RequestPowerDown | RequestCreateClaimedAccount | RequestUpdateProposalVote | RequestCreateProposal | RequestRemoveProposal | RequestAddAccount | RequestConvert | RequestRecurrentTransfer) & {
244
+ redirect_uri?: string;
245
+ };
246
+ export declare type RequestId = {
247
+ request_id: number;
248
+ };
249
+ export declare type KeychainRequest = KeychainRequestData & RequestId;
250
+ export declare type HiveErrorMessage = {
251
+ message: string;
252
+ code: number;
253
+ data?: any;
254
+ };
255
+ export declare type RequestSuccess = {
256
+ data: KeychainRequestData;
257
+ request_id: number;
258
+ result: any;
259
+ message: string;
260
+ };
261
+ export declare type RequestError = {
262
+ data: KeychainRequestData;
263
+ request_id: number;
264
+ error: any;
265
+ message: string;
266
+ };
267
+ export declare type RequestResponse = {
268
+ success: boolean;
269
+ error: any | null;
270
+ result: any | null;
271
+ } & (RequestSuccess | RequestError);
272
+ export declare type KeychainRequestWrapper = {
273
+ command: string;
274
+ domain: string;
275
+ request: KeychainRequest;
276
+ request_id: number;
277
+ };
278
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeychainKeyTypesLC = exports.KeychainKeyTypes = exports.KeychainRequestTypes = void 0;
4
+ var KeychainRequestTypes;
5
+ (function (KeychainRequestTypes) {
6
+ KeychainRequestTypes["decode"] = "decode";
7
+ KeychainRequestTypes["encode"] = "encode";
8
+ KeychainRequestTypes["signBuffer"] = "signBuffer";
9
+ KeychainRequestTypes["broadcast"] = "broadcast";
10
+ KeychainRequestTypes["addAccountAuthority"] = "addAccountAuthority";
11
+ KeychainRequestTypes["removeAccountAuthority"] = "removeAccountAuthority";
12
+ KeychainRequestTypes["removeKeyAuthority"] = "removeKeyAuthority";
13
+ KeychainRequestTypes["addKeyAuthority"] = "addKeyAuthority";
14
+ KeychainRequestTypes["signTx"] = "signTx";
15
+ KeychainRequestTypes["post"] = "post";
16
+ KeychainRequestTypes["vote"] = "vote";
17
+ KeychainRequestTypes["custom"] = "custom";
18
+ KeychainRequestTypes["signedCall"] = "signedCall";
19
+ KeychainRequestTypes["transfer"] = "transfer";
20
+ KeychainRequestTypes["sendToken"] = "sendToken";
21
+ KeychainRequestTypes["delegation"] = "delegation";
22
+ KeychainRequestTypes["witnessVote"] = "witnessVote";
23
+ KeychainRequestTypes["proxy"] = "proxy";
24
+ KeychainRequestTypes["powerUp"] = "powerUp";
25
+ KeychainRequestTypes["powerDown"] = "powerDown";
26
+ KeychainRequestTypes["createClaimedAccount"] = "createClaimedAccount";
27
+ KeychainRequestTypes["createProposal"] = "createProposal";
28
+ KeychainRequestTypes["removeProposal"] = "removeProposal";
29
+ KeychainRequestTypes["updateProposalVote"] = "updateProposalVote";
30
+ KeychainRequestTypes["addAccount"] = "addAccount";
31
+ KeychainRequestTypes["convert"] = "convert";
32
+ KeychainRequestTypes["recurrentTransfer"] = "recurrentTransfer";
33
+ })(KeychainRequestTypes = exports.KeychainRequestTypes || (exports.KeychainRequestTypes = {}));
34
+ var KeychainKeyTypes;
35
+ (function (KeychainKeyTypes) {
36
+ KeychainKeyTypes["posting"] = "Posting";
37
+ KeychainKeyTypes["active"] = "Active";
38
+ KeychainKeyTypes["memo"] = "Memo";
39
+ })(KeychainKeyTypes = exports.KeychainKeyTypes || (exports.KeychainKeyTypes = {}));
40
+ var KeychainKeyTypesLC;
41
+ (function (KeychainKeyTypesLC) {
42
+ KeychainKeyTypesLC["posting"] = "posting";
43
+ KeychainKeyTypesLC["active"] = "active";
44
+ KeychainKeyTypesLC["memo"] = "memo";
45
+ })(KeychainKeyTypesLC = exports.KeychainKeyTypesLC || (exports.KeychainKeyTypesLC = {}));
@@ -0,0 +1,13 @@
1
+ export declare enum LeaseKeys {
2
+ CANCEL_REQUEST = "kc_lease_cancel_request",
3
+ REQUEST = "kc_lease_request",
4
+ ACCEPT_REQUEST = "kc_lease_accept_request",
5
+ UNDELEGATE = "kc_lease_undelegate_request",
6
+ FEE_PAYMENT = "kc_lease_fee_payment",
7
+ PAYOUT_PAYMENT = "kc_lease_payout_payment",
8
+ REIMBURSMENT_CREATOR_CANCEL = "kc_lease_reimbursment_creator",
9
+ REIMBURSMENT_DELEGATOR_CANCEL = "kc_lease_reimbursment_del_can",
10
+ REIMBURSMENT_UNSUFFICIENT_DELEGATION = "kc_lease_reimbursment_del",
11
+ REIMBURSMENT_DUE_TO_ERROR = "kc_lease_reimbursment_error",
12
+ CANCEL_DELEGATION = "kc_lease_cancel_delegation"
13
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LeaseKeys = void 0;
4
+ var LeaseKeys;
5
+ (function (LeaseKeys) {
6
+ LeaseKeys["CANCEL_REQUEST"] = "kc_lease_cancel_request";
7
+ LeaseKeys["REQUEST"] = "kc_lease_request";
8
+ LeaseKeys["ACCEPT_REQUEST"] = "kc_lease_accept_request";
9
+ LeaseKeys["UNDELEGATE"] = "kc_lease_undelegate_request";
10
+ LeaseKeys["FEE_PAYMENT"] = "kc_lease_fee_payment";
11
+ LeaseKeys["PAYOUT_PAYMENT"] = "kc_lease_payout_payment";
12
+ LeaseKeys["REIMBURSMENT_CREATOR_CANCEL"] = "kc_lease_reimbursment_creator";
13
+ LeaseKeys["REIMBURSMENT_DELEGATOR_CANCEL"] = "kc_lease_reimbursment_del_can";
14
+ LeaseKeys["REIMBURSMENT_UNSUFFICIENT_DELEGATION"] = "kc_lease_reimbursment_del";
15
+ LeaseKeys["REIMBURSMENT_DUE_TO_ERROR"] = "kc_lease_reimbursment_error";
16
+ LeaseKeys["CANCEL_DELEGATION"] = "kc_lease_cancel_delegation";
17
+ })(LeaseKeys = exports.LeaseKeys || (exports.LeaseKeys = {}));
@@ -0,0 +1,38 @@
1
+ export interface CancelRequestJSON {
2
+ leaseId: string;
3
+ }
4
+ export interface CancelDelegationJSON {
5
+ leaseId: string;
6
+ }
7
+ export interface RequestCancelRequestJSON {
8
+ leaseId: string;
9
+ }
10
+ export interface AcceptRequestJSON {
11
+ leaseId: string;
12
+ token: string;
13
+ }
14
+ export interface RequestJSON {
15
+ key: string;
16
+ id: string;
17
+ delegationValue: number;
18
+ weeklyPay: string;
19
+ weeklyPayCurrency: string;
20
+ duration: string;
21
+ totalCost: string;
22
+ }
23
+ export interface ReimbursmentJSON {
24
+ leaseId: string;
25
+ }
26
+ export interface PaymentJSON {
27
+ paymentNumber: string;
28
+ }
29
+ export interface LeaseLockResponse {
30
+ success: boolean;
31
+ message?: string;
32
+ data?: any;
33
+ }
34
+ export interface LockLeaseData {
35
+ signedMessage: string;
36
+ username: string;
37
+ leaseId: string;
38
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import * as winston from 'winston';
2
+ export declare const LoggerFormats: {
3
+ logFormat: winston.Logform.Format;
4
+ colorFormat: winston.Logform.Colorizer;
5
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /* istanbul ignore file */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LoggerFormats = void 0;
5
+ const moment = require("moment");
6
+ const winston = require("winston");
7
+ const logFormat = winston.format.printf((info) => {
8
+ const timestamp = moment(info.timestamp);
9
+ return `[${timestamp.format('L') + ' ' + timestamp.format('HH:mm:ss')}][${info.level}] ${info.message}`;
10
+ });
11
+ const colorFormat = winston.format.colorize({
12
+ level: true,
13
+ colors: {
14
+ INFO: 'blue',
15
+ ERROR: 'red',
16
+ OPERATION: 'green',
17
+ TECHNICAL: 'cyan',
18
+ DEBUG: 'magenta',
19
+ WARN: 'yellow',
20
+ },
21
+ });
22
+ exports.LoggerFormats = {
23
+ logFormat,
24
+ colorFormat,
25
+ };
@@ -0,0 +1,18 @@
1
+ interface LoggerLevel {
2
+ [level: string]: number;
3
+ }
4
+ export interface LoggerConfig {
5
+ levels: LoggerLevel;
6
+ folder?: string;
7
+ file?: string;
8
+ }
9
+ declare const Logger: {
10
+ info: (message: string) => void;
11
+ warn: (message: string) => void;
12
+ error: (message: any, stacktrace?: Error | undefined) => void;
13
+ technical: (message: string) => void;
14
+ operation: (message: string) => void;
15
+ debug: (message: string) => void;
16
+ initLogger: (config: LoggerConfig, env: string) => void;
17
+ };
18
+ export default Logger;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /* istanbul ignore file */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const winston = require("winston");
6
+ const transports_1 = require("./transports");
7
+ let winstonLogger;
8
+ let environment;
9
+ const initLogger = (config, env) => {
10
+ transports_1.LoggerTransports.initTransport(config);
11
+ const transports = [transports_1.LoggerTransports.getConsoleTransport()];
12
+ if (config.file && config.folder) {
13
+ transports.push(transports_1.LoggerTransports.getFileRotationTransport());
14
+ }
15
+ environment = env;
16
+ winstonLogger = winston.createLogger({
17
+ levels: config.levels,
18
+ level: 'DEBUG',
19
+ transports,
20
+ });
21
+ };
22
+ const info = (message) => {
23
+ if (environment === 'TEST')
24
+ return;
25
+ winstonLogger.log('INFO', message);
26
+ };
27
+ const debug = (message) => {
28
+ if (environment === 'TEST')
29
+ return;
30
+ if (environment === 'DEBUG') {
31
+ winstonLogger.log('DEBUG', message);
32
+ }
33
+ };
34
+ const operation = (message) => {
35
+ if (environment === 'TEST')
36
+ return;
37
+ winstonLogger.log('OPERATION', message);
38
+ };
39
+ const warn = (message) => {
40
+ if (environment === 'TEST')
41
+ return;
42
+ winstonLogger.log('WARN', message);
43
+ };
44
+ const technical = (message) => {
45
+ if (environment === 'TEST')
46
+ return;
47
+ winstonLogger.log('TECHNICAL', message);
48
+ };
49
+ const error = (message, stacktrace) => {
50
+ if (environment === 'TEST')
51
+ return;
52
+ winstonLogger.log('ERROR', `${message}`);
53
+ if (stacktrace)
54
+ winstonLogger.log('ERROR', stacktrace.message + '\r\n' + stacktrace.stack);
55
+ };
56
+ const Logger = { info, warn, error, technical, operation, debug, initLogger };
57
+ exports.default = Logger;
@@ -0,0 +1,7 @@
1
+ import { LoggerConfig } from './logger';
2
+ import DailyRotateFile = require('winston-daily-rotate-file');
3
+ export declare const LoggerTransports: {
4
+ getConsoleTransport: () => any;
5
+ getFileRotationTransport: () => DailyRotateFile;
6
+ initTransport: (config: LoggerConfig) => void;
7
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /* istanbul ignore file */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LoggerTransports = void 0;
5
+ const winston = require("winston");
6
+ const formats_1 = require("./formats");
7
+ const DailyRotateFile = require("winston-daily-rotate-file");
8
+ const path = require("path");
9
+ let fileRotationTransport;
10
+ let consoleTransport;
11
+ const initTransport = (config) => {
12
+ if (config.file && config.folder) {
13
+ fileRotationTransport = new DailyRotateFile({
14
+ filename: path.join(config.folder, config.file),
15
+ datePattern: 'YYYY-MM-DD',
16
+ maxSize: '20m',
17
+ maxFiles: '7',
18
+ format: winston.format.combine(formats_1.LoggerFormats.logFormat),
19
+ });
20
+ }
21
+ consoleTransport = new winston.transports.Console({
22
+ format: winston.format.combine(formats_1.LoggerFormats.colorFormat, formats_1.LoggerFormats.logFormat),
23
+ });
24
+ };
25
+ const getConsoleTransport = () => {
26
+ return consoleTransport;
27
+ };
28
+ const getFileRotationTransport = () => {
29
+ return fileRotationTransport;
30
+ };
31
+ exports.LoggerTransports = {
32
+ getConsoleTransport,
33
+ getFileRotationTransport,
34
+ initTransport,
35
+ };
@@ -0,0 +1,8 @@
1
+ export declare enum PluginMessage {
2
+ SAVE_PLUGIN_DATA = "SAVE_PLUGIN_DATA",
3
+ IS_INSTALLED = "IS_INSTALLED",
4
+ ACK_PLUGIN_INSTALL = "ACK_PLUGIN_INSTALL",
5
+ GET_PLUGIN_INFO = "GET_PLUGIN_INFO",
6
+ ACK_PLUGIN_DATA_SAVED = "ACK_PLUGIN_DATA_SAVED",
7
+ HIVE_KEYCHAIN_RESPONSE = "HIVE_KEYCHAIN_RESPONSE"
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginMessage = void 0;
4
+ var PluginMessage;
5
+ (function (PluginMessage) {
6
+ PluginMessage["SAVE_PLUGIN_DATA"] = "SAVE_PLUGIN_DATA";
7
+ PluginMessage["IS_INSTALLED"] = "IS_INSTALLED";
8
+ PluginMessage["ACK_PLUGIN_INSTALL"] = "ACK_PLUGIN_INSTALL";
9
+ PluginMessage["GET_PLUGIN_INFO"] = "GET_PLUGIN_INFO";
10
+ PluginMessage["ACK_PLUGIN_DATA_SAVED"] = "ACK_PLUGIN_DATA_SAVED";
11
+ PluginMessage["HIVE_KEYCHAIN_RESPONSE"] = "HIVE_KEYCHAIN_RESPONSE";
12
+ })(PluginMessage = exports.PluginMessage || (exports.PluginMessage = {}));
@@ -0,0 +1,61 @@
1
+ import { LoggerConfig } from '../logger/logger';
2
+ import { Provider } from './swap.interface';
3
+ export interface SwapServerConfig {
4
+ rpc: string[];
5
+ hiveEngineRpc: string[];
6
+ logger?: LoggerConfig;
7
+ swaps: SwapConfig;
8
+ priceRefreshIntervalInMinutes: number;
9
+ }
10
+ export interface SwapConfig {
11
+ account: string;
12
+ marketPool: MarketPoolConfig;
13
+ blockInfoFilePath: string;
14
+ fee: SwapFeeConfig;
15
+ expiration: SwapExpirationConfig;
16
+ slippage: SwapSlippageConfig;
17
+ providers: IProviderItem;
18
+ maxDelayLayerTwo: number;
19
+ maxDelayLayerTwoWithLayerOne: number;
20
+ }
21
+ export interface SwapExpirationConfig {
22
+ expiresAfterXDays: number;
23
+ clearingRoutineFrequencyInHours: number;
24
+ }
25
+ export interface SwapFeeConfig {
26
+ account: string;
27
+ amount: number;
28
+ }
29
+ export interface SwapSlippageConfig {
30
+ min: number;
31
+ default: number;
32
+ }
33
+ export interface MarketPoolConfig {
34
+ deactivated?: boolean;
35
+ }
36
+ export interface PublicConfig {
37
+ account: string;
38
+ fee: SwapFeeConfig;
39
+ slippage: SwapSlippageConfig;
40
+ }
41
+ export declare type IProviderItem = {
42
+ [p in Provider]?: IProvider;
43
+ };
44
+ export interface IProvider {
45
+ name: Provider;
46
+ fullName: string;
47
+ accountName: string;
48
+ withdrawal: IConvertOptions;
49
+ deposit: IConvertOptions;
50
+ deactivated?: boolean;
51
+ rewardAccountName?: string;
52
+ rewardToken?: string;
53
+ }
54
+ export interface IConvertOptions {
55
+ minimumAmount?: number;
56
+ fee: number;
57
+ minimumFee: number;
58
+ balancedFreeFee: boolean;
59
+ skipBalanceCheck?: boolean;
60
+ memoRegex?: string;
61
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ export interface SwapApiResponse {
2
+ result?: SwapApiResult;
3
+ error?: SwapApiError;
4
+ }
5
+ export declare type SwapApiResult = any;
6
+ export interface SwapApiError {
7
+ code: number;
8
+ message: string;
9
+ reason?: SwapApiErrorReason;
10
+ }
11
+ export interface SwapApiErrorReason {
12
+ template: string;
13
+ params?: string[];
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,86 @@
1
+ export interface EstimateSwapStep {
2
+ type: SwapStepType;
3
+ amountStartToken: number;
4
+ estimate: number;
5
+ startToken: string;
6
+ endToken: string;
7
+ provider: Provider;
8
+ }
9
+ export declare enum SwapStepType {
10
+ DEPOSIT_TO_HIVE_ENGINE = "DEPOSIT_TO_HIVE_ENGINE",
11
+ WITHDRAWAL_FROM_HIVE_ENGINE = "WITHDRAWAL_FROM_HIVE_ENGINE",
12
+ SWAP_TOKEN = "SWAP_TOKEN",
13
+ BUY_ON_HIVE_ENGINE_MARKET = "BUY_ON_HIVE_ENGINE_MARKET",
14
+ SELL_ON_HIVE_ENGINE_MARKET = "SELL_ON_HIVE_ENGINE_MARKET",
15
+ BUY_ON_MARKET = "BUY_ON_MARKET",
16
+ SELL_ON_MARKET = "SELL_ON_MARKET"
17
+ }
18
+ export declare enum Provider {
19
+ HIVE_INTERNAL_MARKET = "HIVE_INTERNAL_MARKET",
20
+ BEESWAP = "BEESWAP",
21
+ HIVE_PAY = "HIVE_PAY",
22
+ DISCOUNTED_BRIDGE = "DISCOUNTED_BRIDGE",
23
+ LEODEX = "LEODEX",
24
+ HIVE_ENGINE = "HIVE_ENGINE",
25
+ LIQUIDITY_POOL = "LIQUIDITY_POOL",
26
+ HIVE_ENGINE_INTERNAL_MARKET = "HIVE_ENGINE_INTERNAL_MARKET",
27
+ NULL = "NULL"
28
+ }
29
+ export declare enum SwapStatus {
30
+ PENDING = "PENDING",
31
+ STARTED = "STARTED",
32
+ CANCELED_DUE_TO_ERROR = "CANCELED_DUE_TO_ERROR",
33
+ REFUNDED_SLIPPAGE = "REFUND_SLIPPAGE",
34
+ COMPLETED = "COMPLETED",
35
+ FUNDS_RETURNED = "FUNDS_RETURNED"
36
+ }
37
+ export declare enum StepHistoryStatus {
38
+ PENDING = "pending",
39
+ SUCCESS = "success",
40
+ FAILED = "failed"
41
+ }
42
+ export interface ISwap {
43
+ id: string;
44
+ username: string;
45
+ startToken: string;
46
+ endToken: string;
47
+ amount: number;
48
+ expectedAmountAfterFee: number;
49
+ expectedAmountBeforeFee: number;
50
+ slipperage: number;
51
+ status: SwapStatus;
52
+ received: number;
53
+ fee: number;
54
+ feeTransactionId: string;
55
+ transferTransactionId: string;
56
+ steps: IStep[];
57
+ history: IStepHistory[];
58
+ createdAt: Date;
59
+ updatedAt: Date;
60
+ transferInitiated: boolean;
61
+ }
62
+ export interface IStepHistory {
63
+ id: number;
64
+ transactionId: string;
65
+ status: StepHistoryStatus;
66
+ type: SwapStepType;
67
+ stepNumber: number;
68
+ startToken: string;
69
+ amountStartToken: number;
70
+ endToken: string;
71
+ amountEndToken: number;
72
+ minimumExpectedAmount: number;
73
+ provider: Provider;
74
+ createdAt: Date;
75
+ updatedAt: Date;
76
+ }
77
+ export interface IStep {
78
+ id: number;
79
+ type: SwapStepType;
80
+ stepNumber: number;
81
+ amountStartToken: number;
82
+ startToken: string;
83
+ estimate: number;
84
+ endToken: string;
85
+ provider: Provider;
86
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StepHistoryStatus = exports.SwapStatus = exports.Provider = exports.SwapStepType = void 0;
4
+ var SwapStepType;
5
+ (function (SwapStepType) {
6
+ SwapStepType["DEPOSIT_TO_HIVE_ENGINE"] = "DEPOSIT_TO_HIVE_ENGINE";
7
+ SwapStepType["WITHDRAWAL_FROM_HIVE_ENGINE"] = "WITHDRAWAL_FROM_HIVE_ENGINE";
8
+ SwapStepType["SWAP_TOKEN"] = "SWAP_TOKEN";
9
+ SwapStepType["BUY_ON_HIVE_ENGINE_MARKET"] = "BUY_ON_HIVE_ENGINE_MARKET";
10
+ SwapStepType["SELL_ON_HIVE_ENGINE_MARKET"] = "SELL_ON_HIVE_ENGINE_MARKET";
11
+ SwapStepType["BUY_ON_MARKET"] = "BUY_ON_MARKET";
12
+ SwapStepType["SELL_ON_MARKET"] = "SELL_ON_MARKET";
13
+ })(SwapStepType = exports.SwapStepType || (exports.SwapStepType = {}));
14
+ var Provider;
15
+ (function (Provider) {
16
+ Provider["HIVE_INTERNAL_MARKET"] = "HIVE_INTERNAL_MARKET";
17
+ Provider["BEESWAP"] = "BEESWAP";
18
+ Provider["HIVE_PAY"] = "HIVE_PAY";
19
+ Provider["DISCOUNTED_BRIDGE"] = "DISCOUNTED_BRIDGE";
20
+ Provider["LEODEX"] = "LEODEX";
21
+ Provider["HIVE_ENGINE"] = "HIVE_ENGINE";
22
+ Provider["LIQUIDITY_POOL"] = "LIQUIDITY_POOL";
23
+ Provider["HIVE_ENGINE_INTERNAL_MARKET"] = "HIVE_ENGINE_INTERNAL_MARKET";
24
+ Provider["NULL"] = "NULL";
25
+ })(Provider = exports.Provider || (exports.Provider = {}));
26
+ var SwapStatus;
27
+ (function (SwapStatus) {
28
+ SwapStatus["PENDING"] = "PENDING";
29
+ SwapStatus["STARTED"] = "STARTED";
30
+ SwapStatus["CANCELED_DUE_TO_ERROR"] = "CANCELED_DUE_TO_ERROR";
31
+ SwapStatus["REFUNDED_SLIPPAGE"] = "REFUND_SLIPPAGE";
32
+ SwapStatus["COMPLETED"] = "COMPLETED";
33
+ SwapStatus["FUNDS_RETURNED"] = "FUNDS_RETURNED";
34
+ })(SwapStatus = exports.SwapStatus || (exports.SwapStatus = {}));
35
+ var StepHistoryStatus;
36
+ (function (StepHistoryStatus) {
37
+ StepHistoryStatus["PENDING"] = "pending";
38
+ StepHistoryStatus["SUCCESS"] = "success";
39
+ StepHistoryStatus["FAILED"] = "failed";
40
+ })(StepHistoryStatus = exports.StepHistoryStatus || (exports.StepHistoryStatus = {}));
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "hive-keychain-commons",
3
+ "version": "1.1.0",
4
+ "description": "Platform agnostic functions used in Hive Keychain mobile and extensions",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "format": "prettier --write \"src/**/*.ts\" ",
13
+ "lint": "tslint -p tsconfig.json",
14
+ "prepare": "npm run build",
15
+ "prepublishOnly": "npm run lint",
16
+ "preversion": "npm run lint",
17
+ "version": "npm run format && git add -A src",
18
+ "postversion": "git push && git push --tags"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/stoodkev/hive-keychain-commons.git"
23
+ },
24
+ "keywords": [
25
+ "hive",
26
+ "keychain",
27
+ "commons",
28
+ "blockchain",
29
+ "crypto",
30
+ "wallet"
31
+ ],
32
+ "author": "stoodkev",
33
+ "license": "ISC",
34
+ "bugs": {
35
+ "url": "https://github.com/stoodkev/hive-keychain-commons/issues"
36
+ },
37
+ "homepage": "https://github.com/stoodkev/hive-keychain-commons#readme",
38
+ "devDependencies": {
39
+ "@types/bytebuffer": "^5.0.44",
40
+ "@types/node": "^18.11.19",
41
+ "prettier": "^2.4.1",
42
+ "tslint": "^6.1.3",
43
+ "tslint-config-prettier": "^1.18.0",
44
+ "typescript": "^4.5.2"
45
+ },
46
+ "dependencies": {
47
+ "@hiveio/dhive": "^1.2.5",
48
+ "moment": "^2.29.4",
49
+ "winston": "^3.8.1",
50
+ "winston-daily-rotate-file": "^4.7.1"
51
+ }
52
+ }