@alephium/web3 0.2.0-test.0 → 0.2.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.
Files changed (126) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/dist/alephium-web3.min.js +1 -1
  4. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  5. package/dist/alephium-web3.min.js.map +1 -1
  6. package/dist/src/api/api-alephium.d.ts +152 -24
  7. package/dist/src/api/api-alephium.js +163 -82
  8. package/dist/src/api/api-explorer.d.ts +192 -49
  9. package/dist/src/api/api-explorer.js +195 -34
  10. package/dist/src/api/index.d.ts +40 -5
  11. package/dist/src/api/index.js +115 -7
  12. package/dist/src/api/types.d.ts +23 -0
  13. package/dist/src/api/types.js +235 -0
  14. package/dist/src/api/utils.d.ts +6 -0
  15. package/dist/{scripts/rename-gitignore.js → src/api/utils.js} +11 -6
  16. package/dist/src/contract/contract.d.ts +127 -80
  17. package/dist/src/contract/contract.js +425 -467
  18. package/dist/src/contract/events.d.ts +4 -4
  19. package/dist/src/contract/events.js +2 -1
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/contract/ralph.d.ts +5 -4
  22. package/dist/src/contract/ralph.js +27 -1
  23. package/dist/src/global.d.ts +7 -0
  24. package/dist/src/global.js +54 -0
  25. package/dist/src/index.d.ts +2 -0
  26. package/dist/src/index.js +23 -1
  27. package/dist/src/signer/index.d.ts +0 -1
  28. package/dist/src/signer/index.js +5 -2
  29. package/dist/src/signer/signer.d.ts +59 -60
  30. package/dist/src/signer/signer.js +99 -69
  31. package/dist/src/transaction/index.d.ts +0 -1
  32. package/dist/src/transaction/index.js +5 -2
  33. package/dist/src/transaction/status.d.ts +2 -1
  34. package/dist/src/transaction/status.js +2 -1
  35. package/dist/src/utils/bs58.d.ts +1 -0
  36. package/dist/src/utils/bs58.js +13 -1
  37. package/dist/src/utils/index.d.ts +0 -1
  38. package/dist/src/utils/index.js +5 -2
  39. package/dist/src/utils/subscription.d.ts +0 -3
  40. package/dist/src/utils/subscription.js +0 -1
  41. package/dist/src/utils/utils.d.ts +6 -11
  42. package/dist/src/utils/utils.js +22 -26
  43. package/jest-config.json +11 -0
  44. package/package.json +11 -47
  45. package/src/api/api-alephium.ts +219 -33
  46. package/src/api/api-explorer.ts +275 -52
  47. package/src/api/index.ts +140 -6
  48. package/src/api/types.ts +229 -0
  49. package/{scripts/rename-gitignore.js → src/api/utils.ts} +7 -6
  50. package/src/contract/contract.ts +663 -581
  51. package/src/contract/events.ts +8 -7
  52. package/src/contract/ralph.ts +29 -4
  53. package/src/global.ts +56 -0
  54. package/src/index.ts +7 -0
  55. package/src/signer/index.ts +0 -1
  56. package/src/signer/signer.ts +165 -134
  57. package/src/transaction/index.ts +0 -1
  58. package/src/transaction/status.ts +6 -3
  59. package/src/utils/bs58.ts +11 -0
  60. package/src/utils/index.ts +0 -1
  61. package/src/utils/subscription.ts +1 -5
  62. package/src/utils/utils.ts +15 -23
  63. package/webpack.config.js +3 -0
  64. package/.eslintrc.json +0 -21
  65. package/LICENSE +0 -165
  66. package/contracts/add/add.ral +0 -16
  67. package/contracts/greeter/greeter.ral +0 -7
  68. package/contracts/greeter/greeter_interface.ral +0 -3
  69. package/contracts/greeter_main.ral +0 -9
  70. package/contracts/main.ral +0 -6
  71. package/contracts/sub/sub.ral +0 -9
  72. package/dev/user.conf +0 -29
  73. package/dist/scripts/create-project.d.ts +0 -2
  74. package/dist/scripts/create-project.js +0 -124
  75. package/dist/scripts/rename-gitignore.d.ts +0 -1
  76. package/dist/scripts/start-devnet.d.ts +0 -1
  77. package/dist/scripts/start-devnet.js +0 -131
  78. package/dist/scripts/stop-devnet.d.ts +0 -1
  79. package/dist/scripts/stop-devnet.js +0 -32
  80. package/dist/src/signer/node-wallet.d.ts +0 -13
  81. package/dist/src/signer/node-wallet.js +0 -60
  82. package/dist/src/test/index.d.ts +0 -7
  83. package/dist/src/test/index.js +0 -41
  84. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  85. package/dist/src/test/privatekey-wallet.js +0 -68
  86. package/dist/src/transaction/sign-verify.d.ts +0 -2
  87. package/dist/src/transaction/sign-verify.js +0 -58
  88. package/dist/src/utils/password-crypto.d.ts +0 -2
  89. package/dist/src/utils/password-crypto.js +0 -69
  90. package/gitignore +0 -10
  91. package/scripts/create-project.ts +0 -136
  92. package/scripts/start-devnet.js +0 -141
  93. package/scripts/stop-devnet.js +0 -32
  94. package/src/contract/ralph.test.ts +0 -178
  95. package/src/fixtures/address.json +0 -36
  96. package/src/fixtures/balance.json +0 -9
  97. package/src/fixtures/self-clique.json +0 -19
  98. package/src/fixtures/transaction.json +0 -13
  99. package/src/fixtures/transactions.json +0 -179
  100. package/src/signer/fixtures/genesis.json +0 -26
  101. package/src/signer/fixtures/wallets.json +0 -26
  102. package/src/signer/node-wallet.ts +0 -74
  103. package/src/test/index.ts +0 -32
  104. package/src/test/privatekey-wallet.ts +0 -58
  105. package/src/transaction/sign-verify.test.ts +0 -50
  106. package/src/transaction/sign-verify.ts +0 -39
  107. package/src/utils/address.test.ts +0 -47
  108. package/src/utils/djb2.test.ts +0 -35
  109. package/src/utils/password-crypto.test.ts +0 -27
  110. package/src/utils/password-crypto.ts +0 -77
  111. package/src/utils/utils.test.ts +0 -161
  112. package/templates/base/README.md +0 -34
  113. package/templates/base/package.json +0 -35
  114. package/templates/base/src/greeter.ts +0 -41
  115. package/templates/base/tsconfig.json +0 -19
  116. package/templates/react/README.md +0 -34
  117. package/templates/react/config-overrides.js +0 -18
  118. package/templates/react/package.json +0 -66
  119. package/templates/react/src/App.tsx +0 -42
  120. package/templates/react/src/artifacts/greeter.ral.json +0 -26
  121. package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
  122. package/templates/shared/.eslintrc.json +0 -12
  123. package/templates/shared/scripts/header.js +0 -0
  124. package/test/contract.test.ts +0 -178
  125. package/test/events.test.ts +0 -138
  126. package/test/transaction.test.ts +0 -72
@@ -12,14 +12,7 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.Api = exports.HttpClient = exports.ContentType = void 0;
14
14
  require("cross-fetch/polyfill");
15
- function convertHttpResponse(response) {
16
- if (response.error) {
17
- throw new Error(response.error.detail);
18
- }
19
- else {
20
- return response.data;
21
- }
22
- }
15
+ const utils_1 = require("./utils");
23
16
  var ContentType;
24
17
  (function (ContentType) {
25
18
  ContentType["Json"] = "application/json";
@@ -113,8 +106,6 @@ class HttpClient {
113
106
  if (cancelToken) {
114
107
  this.abortControllers.delete(cancelToken);
115
108
  }
116
- if (!response.ok)
117
- throw data;
118
109
  return data;
119
110
  });
120
111
  };
@@ -177,26 +168,26 @@ class Api extends HttpClient {
177
168
  query: query,
178
169
  format: 'json',
179
170
  ...params
180
- }).then(convertHttpResponse),
171
+ }).then(utils_1.convertHttpResponse),
181
172
  /**
182
173
  * @description Get a block with hash
183
174
  *
184
175
  * @tags Blocks
185
176
  * @name GetBlocksBlockHash
186
- * @request GET:/blocks/{block-hash}
177
+ * @request GET:/blocks/{block_hash}
187
178
  */
188
179
  getBlocksBlockHash: (blockHash, params = {}) => this.request({
189
180
  path: `/blocks/${blockHash}`,
190
181
  method: 'GET',
191
182
  format: 'json',
192
183
  ...params
193
- }).then(convertHttpResponse),
184
+ }).then(utils_1.convertHttpResponse),
194
185
  /**
195
186
  * @description Get block's transactions
196
187
  *
197
188
  * @tags Blocks
198
189
  * @name GetBlocksBlockHashTransactions
199
- * @request GET:/blocks/{block-hash}/transactions
190
+ * @request GET:/blocks/{block_hash}/transactions
200
191
  */
201
192
  getBlocksBlockHashTransactions: (blockHash, query, params = {}) => this.request({
202
193
  path: `/blocks/${blockHash}/transactions`,
@@ -204,7 +195,7 @@ class Api extends HttpClient {
204
195
  query: query,
205
196
  format: 'json',
206
197
  ...params
207
- }).then(convertHttpResponse)
198
+ }).then(utils_1.convertHttpResponse)
208
199
  };
209
200
  this.transactions = {
210
201
  /**
@@ -212,14 +203,27 @@ class Api extends HttpClient {
212
203
  *
213
204
  * @tags Transactions
214
205
  * @name GetTransactionsTransactionHash
215
- * @request GET:/transactions/{transaction-hash}
206
+ * @request GET:/transactions/{transaction_hash}
216
207
  */
217
208
  getTransactionsTransactionHash: (transactionHash, params = {}) => this.request({
218
209
  path: `/transactions/${transactionHash}`,
219
210
  method: 'GET',
220
211
  format: 'json',
221
212
  ...params
222
- }).then(convertHttpResponse)
213
+ }).then(utils_1.convertHttpResponse),
214
+ /**
215
+ * @description Get a transaction from a output reference key
216
+ *
217
+ * @tags Transactions
218
+ * @name GetTransactionsByOutputRefKeyOutputRefKey
219
+ * @request GET:/transactions/by/output-ref-key/{output_ref_key}
220
+ */
221
+ getTransactionsByOutputRefKeyOutputRefKey: (outputRefKey, params = {}) => this.request({
222
+ path: `/transactions/by/output-ref-key/${outputRefKey}`,
223
+ method: 'GET',
224
+ format: 'json',
225
+ ...params
226
+ }).then(utils_1.convertHttpResponse)
223
227
  };
224
228
  this.addresses = {
225
229
  /**
@@ -234,7 +238,7 @@ class Api extends HttpClient {
234
238
  method: 'GET',
235
239
  format: 'json',
236
240
  ...params
237
- }).then(convertHttpResponse),
241
+ }).then(utils_1.convertHttpResponse),
238
242
  /**
239
243
  * @description List transactions of a given address
240
244
  *
@@ -248,7 +252,21 @@ class Api extends HttpClient {
248
252
  query: query,
249
253
  format: 'json',
250
254
  ...params
251
- }).then(convertHttpResponse),
255
+ }).then(utils_1.convertHttpResponse),
256
+ /**
257
+ * @description List transactions of a given address within a time-range
258
+ *
259
+ * @tags Addresses
260
+ * @name GetAddressesAddressTimerangedTransactions
261
+ * @request GET:/addresses/{address}/timeranged-transactions
262
+ */
263
+ getAddressesAddressTimerangedTransactions: (address, query, params = {}) => this.request({
264
+ path: `/addresses/${address}/timeranged-transactions`,
265
+ method: 'GET',
266
+ query: query,
267
+ format: 'json',
268
+ ...params
269
+ }).then(utils_1.convertHttpResponse),
252
270
  /**
253
271
  * @description Get total transactions of a given address
254
272
  *
@@ -261,7 +279,20 @@ class Api extends HttpClient {
261
279
  method: 'GET',
262
280
  format: 'json',
263
281
  ...params
264
- }).then(convertHttpResponse),
282
+ }).then(utils_1.convertHttpResponse),
283
+ /**
284
+ * @description List unconfirmed transactions of a given address
285
+ *
286
+ * @tags Addresses
287
+ * @name GetAddressesAddressUnconfirmedTransactions
288
+ * @request GET:/addresses/{address}/unconfirmed-transactions
289
+ */
290
+ getAddressesAddressUnconfirmedTransactions: (address, params = {}) => this.request({
291
+ path: `/addresses/${address}/unconfirmed-transactions`,
292
+ method: 'GET',
293
+ format: 'json',
294
+ ...params
295
+ }).then(utils_1.convertHttpResponse),
265
296
  /**
266
297
  * @description Get address balance
267
298
  *
@@ -274,7 +305,64 @@ class Api extends HttpClient {
274
305
  method: 'GET',
275
306
  format: 'json',
276
307
  ...params
277
- }).then(convertHttpResponse)
308
+ }).then(utils_1.convertHttpResponse),
309
+ /**
310
+ * @description List address tokens
311
+ *
312
+ * @tags Addresses
313
+ * @name GetAddressesAddressTokens
314
+ * @request GET:/addresses/{address}/tokens
315
+ */
316
+ getAddressesAddressTokens: (address, params = {}) => this.request({
317
+ path: `/addresses/${address}/tokens`,
318
+ method: 'GET',
319
+ format: 'json',
320
+ ...params
321
+ }).then(utils_1.convertHttpResponse),
322
+ /**
323
+ * @description List address tokens
324
+ *
325
+ * @tags Addresses
326
+ * @name GetAddressesAddressTokensTokenIdTransactions
327
+ * @request GET:/addresses/{address}/tokens/{token_id}/transactions
328
+ */
329
+ getAddressesAddressTokensTokenIdTransactions: (address, tokenId, query, params = {}) => this.request({
330
+ path: `/addresses/${address}/tokens/${tokenId}/transactions`,
331
+ method: 'GET',
332
+ query: query,
333
+ format: 'json',
334
+ ...params
335
+ }).then(utils_1.convertHttpResponse),
336
+ /**
337
+ * @description Get address balance of given token
338
+ *
339
+ * @tags Addresses
340
+ * @name GetAddressesAddressTokensTokenIdBalance
341
+ * @request GET:/addresses/{address}/tokens/{token_id}/balance
342
+ */
343
+ getAddressesAddressTokensTokenIdBalance: (address, tokenId, params = {}) => this.request({
344
+ path: `/addresses/${address}/tokens/${tokenId}/balance`,
345
+ method: 'GET',
346
+ format: 'json',
347
+ ...params
348
+ }).then(utils_1.convertHttpResponse)
349
+ };
350
+ this.addressesActive = {
351
+ /**
352
+ * @description Are the addresses active (at least 1 transaction)
353
+ *
354
+ * @tags Addresses
355
+ * @name PostAddressesActive
356
+ * @request POST:/addresses-active
357
+ */
358
+ postAddressesActive: (data, params = {}) => this.request({
359
+ path: `/addresses-active`,
360
+ method: 'POST',
361
+ body: data,
362
+ type: ContentType.Json,
363
+ format: 'json',
364
+ ...params
365
+ }).then(utils_1.convertHttpResponse)
278
366
  };
279
367
  this.infos = {
280
368
  /**
@@ -289,7 +377,7 @@ class Api extends HttpClient {
289
377
  method: 'GET',
290
378
  format: 'json',
291
379
  ...params
292
- }).then(convertHttpResponse),
380
+ }).then(utils_1.convertHttpResponse),
293
381
  /**
294
382
  * @description List latest height for each chain
295
383
  *
@@ -302,7 +390,7 @@ class Api extends HttpClient {
302
390
  method: 'GET',
303
391
  format: 'json',
304
392
  ...params
305
- }).then(convertHttpResponse),
393
+ }).then(utils_1.convertHttpResponse),
306
394
  /**
307
395
  * @description Get token supply list
308
396
  *
@@ -316,7 +404,7 @@ class Api extends HttpClient {
316
404
  query: query,
317
405
  format: 'json',
318
406
  ...params
319
- }).then(convertHttpResponse),
407
+ }).then(utils_1.convertHttpResponse),
320
408
  /**
321
409
  * @description Get the ALPH total supply
322
410
  *
@@ -328,7 +416,7 @@ class Api extends HttpClient {
328
416
  path: `/infos/supply/total-alph`,
329
417
  method: 'GET',
330
418
  ...params
331
- }).then(convertHttpResponse),
419
+ }).then(utils_1.convertHttpResponse),
332
420
  /**
333
421
  * @description Get the ALPH circulating supply
334
422
  *
@@ -340,7 +428,7 @@ class Api extends HttpClient {
340
428
  path: `/infos/supply/circulating-alph`,
341
429
  method: 'GET',
342
430
  ...params
343
- }).then(convertHttpResponse),
431
+ }).then(utils_1.convertHttpResponse),
344
432
  /**
345
433
  * @description Get the ALPH reserved supply
346
434
  *
@@ -352,7 +440,7 @@ class Api extends HttpClient {
352
440
  path: `/infos/supply/reserved-alph`,
353
441
  method: 'GET',
354
442
  ...params
355
- }).then(convertHttpResponse),
443
+ }).then(utils_1.convertHttpResponse),
356
444
  /**
357
445
  * @description Get the ALPH locked supply
358
446
  *
@@ -364,7 +452,7 @@ class Api extends HttpClient {
364
452
  path: `/infos/supply/locked-alph`,
365
453
  method: 'GET',
366
454
  ...params
367
- }).then(convertHttpResponse),
455
+ }).then(utils_1.convertHttpResponse),
368
456
  /**
369
457
  * @description Get the total number of transactions
370
458
  *
@@ -376,7 +464,7 @@ class Api extends HttpClient {
376
464
  path: `/infos/total-transactions`,
377
465
  method: 'GET',
378
466
  ...params
379
- }).then(convertHttpResponse),
467
+ }).then(utils_1.convertHttpResponse),
380
468
  /**
381
469
  * @description Get the average block time for each chain
382
470
  *
@@ -389,7 +477,53 @@ class Api extends HttpClient {
389
477
  method: 'GET',
390
478
  format: 'json',
391
479
  ...params
392
- }).then(convertHttpResponse)
480
+ }).then(utils_1.convertHttpResponse)
481
+ };
482
+ this.unconfirmedTransactions = {
483
+ /**
484
+ * @description list unconfirmed transactions
485
+ *
486
+ * @tags Transactions
487
+ * @name GetUnconfirmedTransactions
488
+ * @request GET:/unconfirmed-transactions
489
+ */
490
+ getUnconfirmedTransactions: (query, params = {}) => this.request({
491
+ path: `/unconfirmed-transactions`,
492
+ method: 'GET',
493
+ query: query,
494
+ format: 'json',
495
+ ...params
496
+ }).then(utils_1.convertHttpResponse)
497
+ };
498
+ this.tokens = {
499
+ /**
500
+ * @description List tokens
501
+ *
502
+ * @tags Tokens
503
+ * @name GetTokens
504
+ * @request GET:/tokens
505
+ */
506
+ getTokens: (query, params = {}) => this.request({
507
+ path: `/tokens`,
508
+ method: 'GET',
509
+ query: query,
510
+ format: 'json',
511
+ ...params
512
+ }).then(utils_1.convertHttpResponse),
513
+ /**
514
+ * @description List token transactions
515
+ *
516
+ * @tags Tokens
517
+ * @name GetTokensTokenIdTransactions
518
+ * @request GET:/tokens/{token_id}/transactions
519
+ */
520
+ getTokensTokenIdTransactions: (tokenId, query, params = {}) => this.request({
521
+ path: `/tokens/${tokenId}/transactions`,
522
+ method: 'GET',
523
+ query: query,
524
+ format: 'json',
525
+ ...params
526
+ }).then(utils_1.convertHttpResponse)
393
527
  };
394
528
  this.charts = {
395
529
  /**
@@ -406,7 +540,7 @@ class Api extends HttpClient {
406
540
  query: query,
407
541
  format: 'json',
408
542
  ...params
409
- }).then(convertHttpResponse),
543
+ }).then(utils_1.convertHttpResponse),
410
544
  /**
411
545
  * @description `interval-type` query param: hourly, daily
412
546
  *
@@ -421,7 +555,7 @@ class Api extends HttpClient {
421
555
  query: query,
422
556
  format: 'json',
423
557
  ...params
424
- }).then(convertHttpResponse),
558
+ }).then(utils_1.convertHttpResponse),
425
559
  /**
426
560
  * @description `interval-type` query param: hourly, daily
427
561
  *
@@ -436,7 +570,7 @@ class Api extends HttpClient {
436
570
  query: query,
437
571
  format: 'json',
438
572
  ...params
439
- }).then(convertHttpResponse)
573
+ }).then(utils_1.convertHttpResponse)
440
574
  };
441
575
  this.utils = {
442
576
  /**
@@ -450,7 +584,34 @@ class Api extends HttpClient {
450
584
  path: `/utils/sanity-check`,
451
585
  method: 'PUT',
452
586
  ...params
453
- }).then(convertHttpResponse)
587
+ }).then(utils_1.convertHttpResponse),
588
+ /**
589
+ * @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
590
+ *
591
+ * @tags Utils
592
+ * @name PutUtilsUpdateGlobalLoglevel
593
+ * @request PUT:/utils/update-global-loglevel
594
+ */
595
+ putUtilsUpdateGlobalLoglevel: (data, params = {}) => this.request({
596
+ path: `/utils/update-global-loglevel`,
597
+ method: 'PUT',
598
+ body: data,
599
+ ...params
600
+ }).then(utils_1.convertHttpResponse),
601
+ /**
602
+ * @description Update logback values
603
+ *
604
+ * @tags Utils
605
+ * @name PutUtilsUpdateLogConfig
606
+ * @request PUT:/utils/update-log-config
607
+ */
608
+ putUtilsUpdateLogConfig: (data, params = {}) => this.request({
609
+ path: `/utils/update-log-config`,
610
+ method: 'PUT',
611
+ body: data,
612
+ type: ContentType.Json,
613
+ ...params
614
+ }).then(utils_1.convertHttpResponse)
454
615
  };
455
616
  }
456
617
  }
@@ -1,10 +1,45 @@
1
1
  import { Api as NodeApi } from './api-alephium';
2
- import { Api as ExplorerApi } from './api-explorer';
3
- export declare class NodeProvider extends NodeApi<null> {
4
- constructor(baseUrl: string);
2
+ export interface ApiRequestArguments {
3
+ path: string;
4
+ method: string;
5
+ params: any[];
5
6
  }
6
- export declare class ExplorerProvider extends ExplorerApi<null> {
7
- constructor(baseUrl: string);
7
+ export declare type ApiRequestHandler = (args: ApiRequestArguments) => Promise<any>;
8
+ export declare class NodeProvider {
9
+ readonly wallets: NodeApi<string>['wallets'];
10
+ readonly infos: NodeApi<string>['infos'];
11
+ readonly blockflow: NodeApi<string>['blockflow'];
12
+ readonly addresses: NodeApi<string>['addresses'];
13
+ readonly transactions: NodeApi<string>['transactions'];
14
+ readonly contracts: NodeApi<string>['contracts'];
15
+ readonly multisig: NodeApi<string>['multisig'];
16
+ readonly utils: NodeApi<string>['utils'];
17
+ readonly miners: NodeApi<string>['miners'];
18
+ readonly events: NodeApi<string>['events'];
19
+ constructor(baseUrl: string, apiKey?: string);
20
+ constructor(provider: NodeProvider);
21
+ constructor(handler: ApiRequestHandler);
22
+ request: (args: ApiRequestArguments) => Promise<any>;
23
+ static Proxy(nodeProvider: NodeProvider): NodeProvider;
24
+ static Remote(handler: ApiRequestHandler): NodeProvider;
25
+ }
26
+ export declare class ExplorerProvider {
27
+ readonly blocks: any;
28
+ readonly transactions: any;
29
+ readonly addresses: any;
30
+ readonly addressesActive: any;
31
+ readonly infos: any;
32
+ readonly unconfirmedTransactions: any;
33
+ readonly tokens: any;
34
+ readonly charts: any;
35
+ readonly utils: any;
36
+ constructor(baseUrl: string, apiKey?: string);
37
+ constructor(provider: ExplorerProvider);
38
+ constructor(handler: ApiRequestHandler);
39
+ request: (args: ApiRequestArguments) => Promise<any>;
40
+ static Proxy(explorerProvider: ExplorerProvider): ExplorerProvider;
41
+ static Remote(handler: ApiRequestHandler): ExplorerProvider;
8
42
  }
9
43
  export * as node from './api-alephium';
10
44
  export * as explorer from './api-explorer';
45
+ export * from './types';
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -35,21 +39,125 @@ var __importStar = (this && this.__importStar) || function (mod) {
35
39
  __setModuleDefault(result, mod);
36
40
  return result;
37
41
  };
42
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
43
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
44
+ };
38
45
  Object.defineProperty(exports, "__esModule", { value: true });
39
46
  exports.explorer = exports.node = exports.ExplorerProvider = exports.NodeProvider = void 0;
40
47
  const api_alephium_1 = require("./api-alephium");
41
48
  const api_explorer_1 = require("./api-explorer");
42
- class NodeProvider extends api_alephium_1.Api {
43
- constructor(baseUrl) {
44
- super({ baseUrl: baseUrl });
49
+ function forwardRequests(api, handler) {
50
+ // Update class properties to forward requests
51
+ for (const [path, pathObject] of Object.entries(api)) {
52
+ for (const method of Object.keys(pathObject)) {
53
+ pathObject[`${method}`] = async (...params) => {
54
+ return handler({ path, method, params });
55
+ };
56
+ }
57
+ }
58
+ }
59
+ async function request(provider, args) {
60
+ const call = provider[`${args.path}`][`${args.method}`];
61
+ return call(...args.params);
62
+ }
63
+ function initializeNodeApi(baseUrl, apiKey) {
64
+ const nodeApi = new api_alephium_1.Api({
65
+ baseUrl: baseUrl,
66
+ baseApiParams: { secure: true },
67
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
68
+ });
69
+ nodeApi.setSecurityData(apiKey ?? null);
70
+ return nodeApi;
71
+ }
72
+ class NodeProvider {
73
+ constructor(param0, apiKey) {
74
+ this.request = (args) => {
75
+ return request(this, args);
76
+ };
77
+ let nodeApi;
78
+ if (typeof param0 === 'string') {
79
+ nodeApi = initializeNodeApi(param0, apiKey);
80
+ }
81
+ else if (typeof param0 === 'function') {
82
+ nodeApi = new NodeProvider('https://1.2.3.4:0');
83
+ forwardRequests(nodeApi, param0);
84
+ }
85
+ else {
86
+ nodeApi = param0;
87
+ }
88
+ this.wallets = { ...nodeApi.wallets };
89
+ this.infos = { ...nodeApi.infos };
90
+ this.blockflow = { ...nodeApi.blockflow };
91
+ this.addresses = { ...nodeApi.addresses };
92
+ this.transactions = { ...nodeApi.transactions };
93
+ this.contracts = { ...nodeApi.contracts };
94
+ this.multisig = { ...nodeApi.multisig };
95
+ this.utils = { ...nodeApi.utils };
96
+ this.miners = { ...nodeApi.miners };
97
+ this.events = { ...nodeApi.events };
98
+ }
99
+ // This can prevent the proxied node provider from being modified
100
+ static Proxy(nodeProvider) {
101
+ return new NodeProvider(nodeProvider);
102
+ }
103
+ static Remote(handler) {
104
+ return new NodeProvider(handler);
45
105
  }
46
106
  }
47
107
  exports.NodeProvider = NodeProvider;
48
- class ExplorerProvider extends api_explorer_1.Api {
49
- constructor(baseUrl) {
50
- super({ baseUrl: baseUrl });
108
+ function initializeExplorerApi(baseUrl, apiKey) {
109
+ const explorerApi = new api_explorer_1.Api({
110
+ baseUrl: baseUrl,
111
+ baseApiParams: { secure: true },
112
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
113
+ });
114
+ explorerApi.setSecurityData(apiKey ?? null);
115
+ return explorerApi;
116
+ }
117
+ class ExplorerProvider {
118
+ constructor(param0, apiKey) {
119
+ this.blocks = api_explorer_1.Api['blocks'];
120
+ this.transactions = api_explorer_1.Api['transactions'];
121
+ this.addresses = api_explorer_1.Api['addresses'];
122
+ this.addressesActive = api_explorer_1.Api['addressesActive'];
123
+ this.infos = api_explorer_1.Api['infos'];
124
+ this.unconfirmedTransactions = api_explorer_1.Api['unconfirmedTransactions'];
125
+ this.tokens = api_explorer_1.Api['tokens'];
126
+ this.charts = api_explorer_1.Api['charts'];
127
+ this.utils = api_explorer_1.Api['utils'];
128
+ this.request = (args) => {
129
+ return request(this, args);
130
+ };
131
+ let explorerApi;
132
+ if (typeof param0 === 'string') {
133
+ explorerApi = initializeExplorerApi(param0, apiKey);
134
+ }
135
+ else if (typeof param0 === 'function') {
136
+ explorerApi = new ExplorerProvider('https://1.2.3.4:0');
137
+ forwardRequests(explorerApi, param0);
138
+ }
139
+ else {
140
+ explorerApi = param0;
141
+ }
142
+ this.blocks = { ...explorerApi.blocks };
143
+ this.transactions = { ...explorerApi.transactions };
144
+ this.addresses = { ...explorerApi.addresses };
145
+ this.addressesActive = { ...explorerApi.addressesActive };
146
+ this.infos = { ...explorerApi.infos };
147
+ this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
148
+ this.tokens = { ...explorerApi.tokens };
149
+ this.charts = { ...explorerApi.charts };
150
+ this.utils = { ...explorerApi.utils };
151
+ }
152
+ // This can prevent the proxied explorer provider from being modified
153
+ static Proxy(explorerProvider) {
154
+ return new ExplorerProvider(explorerProvider);
155
+ }
156
+ static Remote(handler) {
157
+ return new ExplorerProvider(handler);
51
158
  }
52
159
  }
53
160
  exports.ExplorerProvider = ExplorerProvider;
54
161
  exports.node = __importStar(require("./api-alephium"));
55
162
  exports.explorer = __importStar(require("./api-explorer"));
163
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,23 @@
1
+ import * as node from './api-alephium';
2
+ export declare type Number256 = bigint;
3
+ export declare type Val = Number256 | boolean | string | Val[];
4
+ export declare type NamedVals = Record<string, Val>;
5
+ export interface Token {
6
+ id: string;
7
+ amount: Number256;
8
+ }
9
+ export declare function toApiToken(token: Token): node.Token;
10
+ export declare function toApiTokens(tokens?: Token[]): node.Token[] | undefined;
11
+ export declare function fromApiToken(token: node.Token): Token;
12
+ export declare function fromApiTokens(tokens?: node.Token[]): Token[] | undefined;
13
+ export declare function toApiBoolean(v: Val): boolean;
14
+ export declare function toApiNumber256(v: Val): string;
15
+ export declare function toApiNumber256Optional(v?: Val): string | undefined;
16
+ export declare function fromApiNumber256(n: string): bigint;
17
+ export declare function toApiByteVec(v: Val): string;
18
+ export declare function toApiAddress(v: Val): string;
19
+ export declare function toApiArray(tpe: string, v: Val): node.Val;
20
+ export declare function toApiVal(v: Val, tpe: string): node.Val;
21
+ export declare function fromApiVals(vals: node.Val[], names: string[], types: string[]): NamedVals;
22
+ export declare function fromApiArray(vals: node.Val[], types: string[]): Val[];
23
+ export declare function fromApiVal(v: node.Val, tpe: string): Val;