@pioneer-platform/pioneer-sdk 0.0.82 → 4.13.30

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/lib/index.js DELETED
@@ -1,493 +0,0 @@
1
- "use strict";
2
- /*
3
-
4
- Pioneer SDK
5
- A typescript sdk for integration for apps
6
-
7
- */
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- var __generator = (this && this.__generator) || function (thisArg, body) {
18
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
19
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
20
- function verb(n) { return function (v) { return step([n, v]); }; }
21
- function step(op) {
22
- if (f) throw new TypeError("Generator is already executing.");
23
- while (_) try {
24
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
25
- if (y = 0, t) op = [op[0] & 2, t.value];
26
- switch (op[0]) {
27
- case 0: case 1: t = op; break;
28
- case 4: _.label++; return { value: op[1], done: false };
29
- case 5: _.label++; y = op[1]; op = [0]; continue;
30
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
31
- default:
32
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
33
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
34
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
35
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
36
- if (t[2]) _.ops.pop();
37
- _.trys.pop(); continue;
38
- }
39
- op = body.call(thisArg, _);
40
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
41
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
42
- }
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.SDK = void 0;
46
- var TAG = " | Pioneer-sdk | ";
47
- var log = require("@pioneer-platform/loggerdog")();
48
- //Pioneer follows OpenAPI spec
49
- var Pioneer = require('openapi-client-axios').default;
50
- var Events = require("@pioneer-platform/pioneer-events");
51
- var _a = require('@pioneer-platform/pioneer-coins'), supportedBlockchains = _a.supportedBlockchains, supportedAssets = _a.supportedAssets;
52
- //xchain adapter
53
- var XchainClass = require("@pioneer-platform/pioneer-xchain-client");
54
- var SDK = /** @class */ (function () {
55
- function SDK(spec, config, isTestnet) {
56
- this.service = config.service || 'unknown';
57
- this.url = config.url || 'unknown';
58
- if (isTestnet) {
59
- this.isTestnet = true;
60
- }
61
- else {
62
- this.isTestnet = false;
63
- }
64
- this.isPaired = false;
65
- this.config = config;
66
- this.username = config.username;
67
- this.spec = spec || config.spec;
68
- this.wss = config.wss || 'wss://pioneers.dev';
69
- this.queryKey = config.queryKey;
70
- this.spec = config.spec;
71
- this.clients = {};
72
- this.context = "";
73
- this.invocationContext = "";
74
- this.assetContext = "";
75
- this.assetBalanceNativeContext = "";
76
- this.assetBalanceUsdValueContext = "";
77
- this.wallets = [];
78
- this.events = {};
79
- this.totalValueUsd = 0;
80
- this.blockchains = [];
81
- this.init = function (blockchains) {
82
- return __awaiter(this, void 0, void 0, function () {
83
- var tag, i, blockchain, _a, userInfo, e_1;
84
- return __generator(this, function (_b) {
85
- switch (_b.label) {
86
- case 0:
87
- tag = TAG + " | init_wallet | ";
88
- _b.label = 1;
89
- case 1:
90
- _b.trys.push([1, 4, , 5]);
91
- log.debug(tag, "blockchains: ", blockchains);
92
- if (!blockchains)
93
- blockchains = [];
94
- if (!this.queryKey)
95
- throw Error(" You must create an api key! ");
96
- this.pioneerApi = new Pioneer({
97
- definition: spec,
98
- axiosConfigDefaults: {
99
- headers: {
100
- 'Authorization': this.queryKey,
101
- },
102
- }
103
- });
104
- //init blockchains
105
- for (i = 0; i < blockchains.length; i++) {
106
- blockchain = blockchains[i];
107
- this.blockchains.push(blockchain.toLowerCase());
108
- }
109
- if (this.blockchains.length === 0)
110
- throw Error("Failed to init! must have blockchains!");
111
- _a = this;
112
- return [4 /*yield*/, this.pioneerApi.init()
113
- //get global info
114
- ];
115
- case 2:
116
- _a.pioneerApi = _b.sent();
117
- return [4 /*yield*/, this.pioneerApi.User()];
118
- case 3:
119
- userInfo = _b.sent();
120
- userInfo = userInfo.data;
121
- if (!this.username)
122
- this.username = userInfo.username;
123
- this.wallets = userInfo.wallets;
124
- this.totalValueUsd = parseFloat(userInfo.totalValueUsd);
125
- this.context = userInfo.context;
126
- this.invocationContext = userInfo.invocationContext;
127
- this.assetContext = userInfo.assetContext;
128
- this.assetBalanceNativeContext = userInfo.assetBalanceNativeContext;
129
- this.assetBalanceUsdValueContext = userInfo.assetBalanceUsdValueContext;
130
- return [2 /*return*/, this.pioneerApi];
131
- case 4:
132
- e_1 = _b.sent();
133
- log.error(tag, e_1);
134
- throw e_1;
135
- case 5: return [2 /*return*/];
136
- }
137
- });
138
- });
139
- };
140
- this.startSocket = function () {
141
- var tag = TAG + " | startSocket | ";
142
- try {
143
- var configEvents = {
144
- queryKey: this.queryKey,
145
- pioneerWs: this.wss
146
- };
147
- if (this.username)
148
- configEvents.username = this.username;
149
- //sub to events
150
- this.events = new Events.Events(configEvents.pioneerWs, config);
151
- this.events.init();
152
- return this.events.events;
153
- }
154
- catch (e) {
155
- log.error(tag, "e: ", e);
156
- }
157
- };
158
- this.createPairingCode = function () {
159
- return __awaiter(this, void 0, void 0, function () {
160
- var tag, pairingBody, result, e_2;
161
- return __generator(this, function (_a) {
162
- switch (_a.label) {
163
- case 0:
164
- tag = TAG + " | createPairingCode | ";
165
- _a.label = 1;
166
- case 1:
167
- _a.trys.push([1, 3, , 4]);
168
- pairingBody = {
169
- service: this.service,
170
- url: this.url
171
- };
172
- //sub to pairings
173
- this.events.subscribeToKey();
174
- return [4 /*yield*/, this.pioneerApi.CreatePairingCode(null, pairingBody)];
175
- case 2:
176
- result = _a.sent();
177
- return [2 /*return*/, result.data];
178
- case 3:
179
- e_2 = _a.sent();
180
- log.error(tag, "e: ", e_2);
181
- return [3 /*break*/, 4];
182
- case 4: return [2 /*return*/];
183
- }
184
- });
185
- });
186
- };
187
- this.getUserInfo = function () {
188
- return __awaiter(this, void 0, void 0, function () {
189
- var tag, result, e_3;
190
- return __generator(this, function (_a) {
191
- switch (_a.label) {
192
- case 0:
193
- tag = TAG + " | getUserInfo | ";
194
- _a.label = 1;
195
- case 1:
196
- _a.trys.push([1, 3, , 4]);
197
- return [4 /*yield*/, this.pioneerApi.User()];
198
- case 2:
199
- result = _a.sent();
200
- return [2 /*return*/, result.data];
201
- case 3:
202
- e_3 = _a.sent();
203
- log.error(tag, "e: ", e_3);
204
- return [3 /*break*/, 4];
205
- case 4: return [2 /*return*/];
206
- }
207
- });
208
- });
209
- };
210
- this.setContext = function (context) {
211
- return __awaiter(this, void 0, void 0, function () {
212
- var tag, result, e_4;
213
- return __generator(this, function (_a) {
214
- switch (_a.label) {
215
- case 0:
216
- tag = TAG + " | setContext | ";
217
- _a.label = 1;
218
- case 1:
219
- _a.trys.push([1, 5, , 6]);
220
- if (!(this.wallets.indexOf(context) >= 0)) return [3 /*break*/, 3];
221
- this.context = context;
222
- return [4 /*yield*/, this.pioneerApi.SetContext(null, { context: this.context })];
223
- case 2:
224
- result = _a.sent();
225
- return [2 /*return*/, result.data];
226
- case 3: return [2 /*return*/, { success: false, error: "unknown context! context: " + context, options: this.wallets }];
227
- case 4: return [3 /*break*/, 6];
228
- case 5:
229
- e_4 = _a.sent();
230
- log.error(tag, "e: ", e_4);
231
- return [3 /*break*/, 6];
232
- case 6: return [2 /*return*/];
233
- }
234
- });
235
- });
236
- };
237
- this.getInvocation = function (invocationId) {
238
- return __awaiter(this, void 0, void 0, function () {
239
- var tag, result, e_5;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- tag = TAG + " | getInvocations | ";
244
- _a.label = 1;
245
- case 1:
246
- _a.trys.push([1, 3, , 4]);
247
- if (!invocationId)
248
- invocationId = this.invocationContext;
249
- return [4 /*yield*/, this.pioneerApi.Invocation(invocationId)];
250
- case 2:
251
- result = _a.sent();
252
- return [2 /*return*/, result.data];
253
- case 3:
254
- e_5 = _a.sent();
255
- log.error(tag, "e: ", e_5);
256
- return [3 /*break*/, 4];
257
- case 4: return [2 /*return*/];
258
- }
259
- });
260
- });
261
- };
262
- this.getInvocations = function () {
263
- return __awaiter(this, void 0, void 0, function () {
264
- var tag, result, e_6;
265
- return __generator(this, function (_a) {
266
- switch (_a.label) {
267
- case 0:
268
- tag = TAG + " | getInvocations | ";
269
- _a.label = 1;
270
- case 1:
271
- _a.trys.push([1, 3, , 4]);
272
- return [4 /*yield*/, this.pioneerApi.Invocations()];
273
- case 2:
274
- result = _a.sent();
275
- return [2 /*return*/, result.data];
276
- case 3:
277
- e_6 = _a.sent();
278
- log.error(tag, "e: ", e_6);
279
- return [3 /*break*/, 4];
280
- case 4: return [2 /*return*/];
281
- }
282
- });
283
- });
284
- };
285
- this.getWalletInfo = function () {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var tag, result, e_7;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0:
291
- tag = TAG + " | getWalletInfo | ";
292
- _a.label = 1;
293
- case 1:
294
- _a.trys.push([1, 3, , 4]);
295
- return [4 /*yield*/, this.pioneerApi.Info(this.context)];
296
- case 2:
297
- result = _a.sent();
298
- return [2 /*return*/, result.data];
299
- case 3:
300
- e_7 = _a.sent();
301
- log.error(tag, "e: ", e_7);
302
- return [3 /*break*/, 4];
303
- case 4: return [2 /*return*/];
304
- }
305
- });
306
- });
307
- };
308
- // @ts-ignore
309
- this.sendToAddress = function (intent) {
310
- return __awaiter(this, void 0, void 0, function () {
311
- var tag, txInput, txid, e_8;
312
- return __generator(this, function (_a) {
313
- switch (_a.label) {
314
- case 0:
315
- tag = TAG + " | sendToAddress | ";
316
- _a.label = 1;
317
- case 1:
318
- _a.trys.push([1, 3, , 4]);
319
- txInput = {
320
- "asset": {
321
- "chain": intent.blockchain,
322
- "symbol": intent.asset,
323
- "ticker": intent.asset
324
- },
325
- "amount": {
326
- "type": "BASE",
327
- "decimal": 18,
328
- amount: function () {
329
- return intent.amount;
330
- }
331
- },
332
- "recipient": intent.address,
333
- };
334
- if (intent.memo)
335
- txInput.memo = intent.memo;
336
- //ETH
337
- if (this.isTestnet && intent.blockchain === 'ETH') {
338
- txInput.chainId = 3; //ropsten
339
- }
340
- if (intent.noBroadcast) {
341
- txInput.noBroadcast = true;
342
- }
343
- return [4 /*yield*/, this.clients[intent.blockchain].transfer(txInput)];
344
- case 2:
345
- txid = _a.sent();
346
- log.debug("txid", txid);
347
- return [2 /*return*/, txid];
348
- case 3:
349
- e_8 = _a.sent();
350
- log.error(tag, "e: ", e_8);
351
- return [3 /*break*/, 4];
352
- case 4: return [2 /*return*/];
353
- }
354
- });
355
- });
356
- };
357
- //X-chain
358
- this.getUserParams = function () {
359
- return __awaiter(this, void 0, void 0, function () {
360
- var tag, userInfo, result, thorAddress, binance, bitcoin, thorchain, ethereum, bitcoin, bitcoin, output, e_9;
361
- return __generator(this, function (_a) {
362
- switch (_a.label) {
363
- case 0:
364
- tag = TAG + " | getUserParams | ";
365
- _a.label = 1;
366
- case 1:
367
- _a.trys.push([1, 17, , 18]);
368
- if (!!this.context) return [3 /*break*/, 3];
369
- return [4 /*yield*/, this.pioneerApi.User()];
370
- case 2:
371
- userInfo = _a.sent();
372
- userInfo = userInfo.data;
373
- log.info(tag, "userInfo: ", userInfo);
374
- this.context = userInfo.context;
375
- _a.label = 3;
376
- case 3:
377
- if (!this.context)
378
- throw Error("can not start without context! ");
379
- if (!this.blockchains)
380
- throw Error("can not start without blockchains");
381
- log.info(tag, "context: ", this.context);
382
- log.info(tag, "blockchains: ", this.blockchains);
383
- return [4 /*yield*/, this.pioneerApi.Info(this.context)];
384
- case 4:
385
- result = _a.sent();
386
- result = result.data;
387
- log.info(tag, "result: ", result);
388
- if (!result.masters.RUNE)
389
- throw Error("102: RUNE required asset! ");
390
- thorAddress = result.masters.RUNE;
391
- log.debug(tag, "this.spec: ", this.spec);
392
- log.debug(tag, "supportedBlockchains: ", supportedBlockchains);
393
- if (!this.spec)
394
- throw Error("103: Pioneer Service required for sdk! ");
395
- if (!(this.blockchains.indexOf('binance') >= 0)) return [3 /*break*/, 6];
396
- binance = new XchainClass(this.spec, {
397
- network: 'mainnet',
398
- blockchain: 'binance',
399
- nativeAsset: 'BNB',
400
- queryKey: this.queryKey
401
- });
402
- return [4 /*yield*/, binance.init(this.context)];
403
- case 5:
404
- _a.sent();
405
- this.clients['binance'] = binance;
406
- _a.label = 6;
407
- case 6:
408
- if (!(this.blockchains.indexOf('bitcoin') >= 0)) return [3 /*break*/, 8];
409
- bitcoin = new XchainClass(this.spec, {
410
- network: 'mainnet',
411
- blockchain: 'bitcoin',
412
- nativeAsset: 'BTC',
413
- queryKey: this.queryKey
414
- });
415
- return [4 /*yield*/, bitcoin.init(this.context)];
416
- case 7:
417
- _a.sent();
418
- this.clients['bitcoin'] = bitcoin;
419
- _a.label = 8;
420
- case 8:
421
- if (!(this.blockchains.indexOf('thorchain') >= 0)) return [3 /*break*/, 10];
422
- thorchain = new XchainClass(this.spec, {
423
- network: 'mainnet',
424
- blockchain: 'thorchain',
425
- nativeAsset: 'RUNE',
426
- queryKey: this.queryKey
427
- });
428
- return [4 /*yield*/, thorchain.init(this.context)];
429
- case 9:
430
- _a.sent();
431
- this.clients['thorchain'] = thorchain;
432
- _a.label = 10;
433
- case 10:
434
- if (!(this.blockchains.indexOf('ethereum') >= 0)) return [3 /*break*/, 12];
435
- ethereum = new XchainClass(this.spec, {
436
- network: 'mainnet',
437
- blockchain: 'ethereum',
438
- nativeAsset: 'ETH',
439
- queryKey: this.queryKey
440
- });
441
- return [4 /*yield*/, ethereum.init(this.context)];
442
- case 11:
443
- _a.sent();
444
- this.clients['ethereum'] = ethereum;
445
- _a.label = 12;
446
- case 12:
447
- if (!(this.blockchains.indexOf('bitcoincash') >= 0)) return [3 /*break*/, 14];
448
- bitcoin = new XchainClass(this.spec, {
449
- network: 'mainnet',
450
- blockchain: 'bitcoinCash',
451
- nativeAsset: 'BCH',
452
- queryKey: this.queryKey
453
- });
454
- return [4 /*yield*/, bitcoin.init(this.context)];
455
- case 13:
456
- _a.sent();
457
- this.clients['bitcoinCash'] = bitcoin;
458
- _a.label = 14;
459
- case 14:
460
- if (!(this.blockchains.indexOf('litecoin') >= 0)) return [3 /*break*/, 16];
461
- bitcoin = new XchainClass(this.spec, {
462
- network: 'mainnet',
463
- blockchain: 'litecoin',
464
- nativeAsset: 'LTC',
465
- queryKey: this.queryKey
466
- });
467
- return [4 /*yield*/, bitcoin.init(this.context)];
468
- case 15:
469
- _a.sent();
470
- this.clients['litecoin'] = bitcoin;
471
- _a.label = 16;
472
- case 16:
473
- output = {
474
- type: 'pioneer',
475
- context: this.context,
476
- wallet: thorAddress,
477
- keystore: {},
478
- clients: this.clients
479
- };
480
- return [2 /*return*/, output];
481
- case 17:
482
- e_9 = _a.sent();
483
- log.error(tag, "e: ", e_9);
484
- return [3 /*break*/, 18];
485
- case 18: return [2 /*return*/];
486
- }
487
- });
488
- });
489
- };
490
- }
491
- return SDK;
492
- }());
493
- exports.SDK = SDK;
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "commonjs",
5
- "lib": ["es6", "es2015", "dom"],
6
- "declaration": true,
7
- "outDir": "lib",
8
- "rootDir": "src",
9
- "strict": true,
10
- "types": ["node"],
11
- "esModuleInterop": true
12
- }
13
- }