@alephium/web3 0.2.0-rc.11 → 0.2.0-rc.12

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.
@@ -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,7 +168,7 @@ 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
  *
@@ -190,7 +181,7 @@ class Api extends HttpClient {
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
  *
@@ -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
  /**
@@ -219,7 +210,7 @@ class Api extends HttpClient {
219
210
  method: 'GET',
220
211
  format: 'json',
221
212
  ...params
222
- }).then(convertHttpResponse)
213
+ }).then(utils_1.convertHttpResponse)
223
214
  };
224
215
  this.addresses = {
225
216
  /**
@@ -234,7 +225,7 @@ class Api extends HttpClient {
234
225
  method: 'GET',
235
226
  format: 'json',
236
227
  ...params
237
- }).then(convertHttpResponse),
228
+ }).then(utils_1.convertHttpResponse),
238
229
  /**
239
230
  * @description List transactions of a given address
240
231
  *
@@ -248,7 +239,7 @@ class Api extends HttpClient {
248
239
  query: query,
249
240
  format: 'json',
250
241
  ...params
251
- }).then(convertHttpResponse),
242
+ }).then(utils_1.convertHttpResponse),
252
243
  /**
253
244
  * @description Get total transactions of a given address
254
245
  *
@@ -261,7 +252,7 @@ class Api extends HttpClient {
261
252
  method: 'GET',
262
253
  format: 'json',
263
254
  ...params
264
- }).then(convertHttpResponse),
255
+ }).then(utils_1.convertHttpResponse),
265
256
  /**
266
257
  * @description Get address balance
267
258
  *
@@ -274,7 +265,7 @@ class Api extends HttpClient {
274
265
  method: 'GET',
275
266
  format: 'json',
276
267
  ...params
277
- }).then(convertHttpResponse)
268
+ }).then(utils_1.convertHttpResponse)
278
269
  };
279
270
  this.infos = {
280
271
  /**
@@ -289,7 +280,7 @@ class Api extends HttpClient {
289
280
  method: 'GET',
290
281
  format: 'json',
291
282
  ...params
292
- }).then(convertHttpResponse),
283
+ }).then(utils_1.convertHttpResponse),
293
284
  /**
294
285
  * @description List latest height for each chain
295
286
  *
@@ -302,7 +293,7 @@ class Api extends HttpClient {
302
293
  method: 'GET',
303
294
  format: 'json',
304
295
  ...params
305
- }).then(convertHttpResponse),
296
+ }).then(utils_1.convertHttpResponse),
306
297
  /**
307
298
  * @description Get token supply list
308
299
  *
@@ -316,7 +307,7 @@ class Api extends HttpClient {
316
307
  query: query,
317
308
  format: 'json',
318
309
  ...params
319
- }).then(convertHttpResponse),
310
+ }).then(utils_1.convertHttpResponse),
320
311
  /**
321
312
  * @description Get the ALPH total supply
322
313
  *
@@ -328,7 +319,7 @@ class Api extends HttpClient {
328
319
  path: `/infos/supply/total-alph`,
329
320
  method: 'GET',
330
321
  ...params
331
- }).then(convertHttpResponse),
322
+ }).then(utils_1.convertHttpResponse),
332
323
  /**
333
324
  * @description Get the ALPH circulating supply
334
325
  *
@@ -340,7 +331,7 @@ class Api extends HttpClient {
340
331
  path: `/infos/supply/circulating-alph`,
341
332
  method: 'GET',
342
333
  ...params
343
- }).then(convertHttpResponse),
334
+ }).then(utils_1.convertHttpResponse),
344
335
  /**
345
336
  * @description Get the ALPH reserved supply
346
337
  *
@@ -352,7 +343,7 @@ class Api extends HttpClient {
352
343
  path: `/infos/supply/reserved-alph`,
353
344
  method: 'GET',
354
345
  ...params
355
- }).then(convertHttpResponse),
346
+ }).then(utils_1.convertHttpResponse),
356
347
  /**
357
348
  * @description Get the ALPH locked supply
358
349
  *
@@ -364,7 +355,7 @@ class Api extends HttpClient {
364
355
  path: `/infos/supply/locked-alph`,
365
356
  method: 'GET',
366
357
  ...params
367
- }).then(convertHttpResponse),
358
+ }).then(utils_1.convertHttpResponse),
368
359
  /**
369
360
  * @description Get the total number of transactions
370
361
  *
@@ -376,7 +367,7 @@ class Api extends HttpClient {
376
367
  path: `/infos/total-transactions`,
377
368
  method: 'GET',
378
369
  ...params
379
- }).then(convertHttpResponse),
370
+ }).then(utils_1.convertHttpResponse),
380
371
  /**
381
372
  * @description Get the average block time for each chain
382
373
  *
@@ -389,7 +380,7 @@ class Api extends HttpClient {
389
380
  method: 'GET',
390
381
  format: 'json',
391
382
  ...params
392
- }).then(convertHttpResponse)
383
+ }).then(utils_1.convertHttpResponse)
393
384
  };
394
385
  this.charts = {
395
386
  /**
@@ -406,7 +397,7 @@ class Api extends HttpClient {
406
397
  query: query,
407
398
  format: 'json',
408
399
  ...params
409
- }).then(convertHttpResponse),
400
+ }).then(utils_1.convertHttpResponse),
410
401
  /**
411
402
  * @description `interval-type` query param: hourly, daily
412
403
  *
@@ -421,7 +412,7 @@ class Api extends HttpClient {
421
412
  query: query,
422
413
  format: 'json',
423
414
  ...params
424
- }).then(convertHttpResponse),
415
+ }).then(utils_1.convertHttpResponse),
425
416
  /**
426
417
  * @description `interval-type` query param: hourly, daily
427
418
  *
@@ -436,7 +427,7 @@ class Api extends HttpClient {
436
427
  query: query,
437
428
  format: 'json',
438
429
  ...params
439
- }).then(convertHttpResponse)
430
+ }).then(utils_1.convertHttpResponse)
440
431
  };
441
432
  this.utils = {
442
433
  /**
@@ -450,7 +441,7 @@ class Api extends HttpClient {
450
441
  path: `/utils/sanity-check`,
451
442
  method: 'PUT',
452
443
  ...params
453
- }).then(convertHttpResponse),
444
+ }).then(utils_1.convertHttpResponse),
454
445
  /**
455
446
  * @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
456
447
  *
@@ -463,7 +454,7 @@ class Api extends HttpClient {
463
454
  method: 'PUT',
464
455
  body: data,
465
456
  ...params
466
- }).then(convertHttpResponse),
457
+ }).then(utils_1.convertHttpResponse),
467
458
  /**
468
459
  * @description Update logging file, only logback.xml is accepted
469
460
  *
@@ -476,7 +467,7 @@ class Api extends HttpClient {
476
467
  method: 'PUT',
477
468
  body: data,
478
469
  ...params
479
- }).then(convertHttpResponse)
470
+ }).then(utils_1.convertHttpResponse)
480
471
  };
481
472
  }
482
473
  }
@@ -0,0 +1,6 @@
1
+ export declare function convertHttpResponse<T>(response: {
2
+ data: T;
3
+ error?: {
4
+ detail: string;
5
+ };
6
+ }): T;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.convertHttpResponse = void 0;
21
+ function convertHttpResponse(response) {
22
+ if (response.error) {
23
+ throw new Error(`[Node API Error] - ${response.error.detail}`);
24
+ }
25
+ else {
26
+ return response.data;
27
+ }
28
+ }
29
+ exports.convertHttpResponse = convertHttpResponse;
@@ -1,11 +1,4 @@
1
1
  import { ec as EC, SignatureInput } from 'elliptic';
2
- import * as node from '../api/api-alephium';
3
- import * as explorer from '../api/api-explorer';
4
- export declare function convertHttpResponse<T>(response: node.HttpResponse<T, {
5
- detail: string;
6
- }> | explorer.HttpResponse<T, {
7
- detail: string;
8
- }>): T;
9
2
  export declare function signatureEncode(signature: EC.Signature): string;
10
3
  export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
11
4
  export declare function xorByte(intValue: number): number;
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = exports.convertHttpResponse = void 0;
23
+ exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = void 0;
24
24
  const elliptic_1 = require("elliptic");
25
25
  const bn_js_1 = __importDefault(require("bn.js"));
26
26
  const blakejs_1 = __importDefault(require("blakejs"));
@@ -29,15 +29,6 @@ const buffer_1 = require("buffer/");
29
29
  const constants_1 = require("../constants");
30
30
  const djb2_1 = __importDefault(require("./djb2"));
31
31
  const ec = new elliptic_1.ec('secp256k1');
32
- function convertHttpResponse(response) {
33
- if (response.error) {
34
- throw new Error(response.error.detail);
35
- }
36
- else {
37
- return response.data;
38
- }
39
- }
40
- exports.convertHttpResponse = convertHttpResponse;
41
32
  function signatureEncode(signature) {
42
33
  let sNormalized = signature.s;
43
34
  if (ec.n && signature.s.cmp(ec.nh) === 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.0-rc.11",
3
+ "version": "0.2.0-rc.12",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -34,8 +34,8 @@
34
34
  "build": "rm -rf dist/* && npx tsc --build . && webpack",
35
35
  "test": "jest -i --config ./jest-config.json",
36
36
  "update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
37
- "update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
38
- "update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
37
+ "update-schema:alephium": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
38
+ "update-schema:explorer": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
39
39
  "check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}",
40
40
  "start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
41
41
  "restart-devnet": "npm run start-devnet",
@@ -1085,16 +1085,7 @@ export interface WalletUnlock {
1085
1085
  }
1086
1086
 
1087
1087
  import 'cross-fetch/polyfill'
1088
-
1089
- function convertHttpResponse<T>(
1090
- response: HttpResponse<T, { detail: string }> | HttpResponse<T, { detail: string }>
1091
- ): T {
1092
- if (response.error) {
1093
- throw new Error(response.error.detail)
1094
- } else {
1095
- return response.data
1096
- }
1097
- }
1088
+ import { convertHttpResponse } from './utils'
1098
1089
 
1099
1090
  export type QueryParamsType = Record<string | number, any>
1100
1091
  export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
@@ -1298,7 +1289,6 @@ export class HttpClient<SecurityDataType = unknown> {
1298
1289
  this.abortControllers.delete(cancelToken)
1299
1290
  }
1300
1291
 
1301
- if (!response.ok) throw data
1302
1292
  return data
1303
1293
  })
1304
1294
  }
@@ -278,16 +278,7 @@ export interface UnconfirmedTransaction {
278
278
  }
279
279
 
280
280
  import 'cross-fetch/polyfill'
281
-
282
- function convertHttpResponse<T>(
283
- response: HttpResponse<T, { detail: string }> | HttpResponse<T, { detail: string }>
284
- ): T {
285
- if (response.error) {
286
- throw new Error(response.error.detail)
287
- } else {
288
- return response.data
289
- }
290
- }
281
+ import { convertHttpResponse } from './utils'
291
282
 
292
283
  export type QueryParamsType = Record<string | number, any>
293
284
  export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
@@ -491,7 +482,6 @@ export class HttpClient<SecurityDataType = unknown> {
491
482
  this.abortControllers.delete(cancelToken)
492
483
  }
493
484
 
494
- if (!response.ok) throw data
495
485
  return data
496
486
  })
497
487
  }
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2018 - 2022 The Alephium Authors
3
+ This file is part of the alephium project.
4
+
5
+ The library is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ The library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ export function convertHttpResponse<T>(response: { data: T; error?: { detail: string } }): T {
20
+ if (response.error) {
21
+ throw new Error(`[Node API Error] - ${response.error.detail}`)
22
+ } else {
23
+ return response.data
24
+ }
25
+ }
@@ -29,16 +29,6 @@ import * as explorer from '../api/api-explorer'
29
29
 
30
30
  const ec = new EC('secp256k1')
31
31
 
32
- export function convertHttpResponse<T>(
33
- response: node.HttpResponse<T, { detail: string }> | explorer.HttpResponse<T, { detail: string }>
34
- ): T {
35
- if (response.error) {
36
- throw new Error(response.error.detail)
37
- } else {
38
- return response.data
39
- }
40
- }
41
-
42
32
  export function signatureEncode(signature: EC.Signature): string {
43
33
  let sNormalized = signature.s
44
34
  if (ec.n && signature.s.cmp(ec.nh) === 1) {
@@ -12,7 +12,7 @@
12
12
  "stop-devnet": "node scripts/stop-devnet.js"
13
13
  },
14
14
  "dependencies": {
15
- "@alephium/web3": "0.2.0-rc.11"
15
+ "@alephium/web3": "0.2.0-rc.12"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/elliptic": "^6.4.13",
@@ -12,7 +12,7 @@
12
12
  "@types/node": "^16.11.26",
13
13
  "@types/react": "^18.0.3",
14
14
  "@types/react-dom": "^18.0.0",
15
- "@alephium/web3": "0.2.0-rc.11",
15
+ "@alephium/web3": "0.2.0-rc.12",
16
16
  "react": "^18.0.0",
17
17
  "react-dom": "^18.0.0",
18
18
  "react-scripts": "5.0.1",