@alephium/web3 0.5.0-rc.2 → 0.5.0-rc.21

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 (51) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.LICENSE.txt +2 -0
  3. package/dist/alephium-web3.min.js.map +1 -1
  4. package/dist/src/api/api-alephium.d.ts +113 -26
  5. package/dist/src/api/api-alephium.js +62 -18
  6. package/dist/src/api/api-explorer.d.ts +222 -52
  7. package/dist/src/api/api-explorer.js +17 -15
  8. package/dist/src/api/explorer-provider.d.ts +18 -0
  9. package/dist/src/api/explorer-provider.js +65 -0
  10. package/dist/src/api/index.d.ts +2 -41
  11. package/dist/src/api/index.js +6 -116
  12. package/dist/src/api/node-provider.d.ts +21 -0
  13. package/dist/src/api/node-provider.js +68 -0
  14. package/dist/src/api/types.d.ts +10 -2
  15. package/dist/src/api/types.js +23 -3
  16. package/dist/src/contract/contract.d.ts +15 -7
  17. package/dist/src/contract/contract.js +62 -42
  18. package/dist/src/signer/signer.d.ts +25 -30
  19. package/dist/src/signer/signer.js +57 -30
  20. package/dist/src/signer/tx-builder.d.ts +2 -7
  21. package/dist/src/signer/tx-builder.js +10 -7
  22. package/dist/src/signer/types.d.ts +12 -16
  23. package/dist/src/transaction/sign-verify.d.ts +3 -2
  24. package/dist/src/transaction/sign-verify.js +4 -14
  25. package/dist/src/utils/index.d.ts +2 -0
  26. package/dist/src/utils/index.js +2 -0
  27. package/dist/src/utils/number.d.ts +18 -0
  28. package/dist/src/utils/number.fixture.d.ts +12 -0
  29. package/dist/src/utils/number.fixture.js +189 -0
  30. package/dist/src/utils/number.js +148 -0
  31. package/dist/src/utils/sign.d.ts +3 -0
  32. package/dist/src/utils/sign.js +89 -0
  33. package/dist/src/utils/utils.d.ts +4 -3
  34. package/dist/src/utils/utils.js +25 -10
  35. package/package.json +7 -5
  36. package/src/api/api-alephium.ts +260 -207
  37. package/src/api/api-explorer.ts +327 -126
  38. package/src/api/explorer-provider.ts +78 -0
  39. package/src/api/index.ts +2 -146
  40. package/src/api/node-provider.ts +84 -0
  41. package/src/api/types.ts +36 -3
  42. package/src/contract/contract.ts +80 -49
  43. package/src/signer/signer.ts +87 -66
  44. package/src/signer/tx-builder.ts +13 -7
  45. package/src/signer/types.ts +22 -11
  46. package/src/transaction/sign-verify.ts +10 -15
  47. package/src/utils/index.ts +2 -0
  48. package/src/utils/number.fixture.ts +187 -0
  49. package/src/utils/number.ts +162 -0
  50. package/src/utils/sign.ts +66 -0
  51. package/src/utils/utils.ts +26 -10
@@ -141,13 +141,16 @@ export interface BrokerInfo {
141
141
  /** @format inet-socket-address */
142
142
  address: {
143
143
  addr: string;
144
+ /** @format int32 */
144
145
  port: number;
145
146
  };
146
147
  }
147
148
  export interface BuildDeployContractTx {
148
- /** @format public-key */
149
+ /** @format hex-string */
149
150
  fromPublicKey: string;
150
151
  /** @format hex-string */
152
+ fromPublicKeyType?: string;
153
+ /** @format hex-string */
151
154
  bytecode: string;
152
155
  /** @format uint256 */
153
156
  initialAttoAlphAmount?: string;
@@ -177,9 +180,11 @@ export interface BuildDeployContractTxResult {
177
180
  contractAddress: string;
178
181
  }
179
182
  export interface BuildExecuteScriptTx {
180
- /** @format public-key */
183
+ /** @format hex-string */
181
184
  fromPublicKey: string;
182
185
  /** @format hex-string */
186
+ fromPublicKeyType?: string;
187
+ /** @format hex-string */
183
188
  bytecode: string;
184
189
  /** @format uint256 */
185
190
  attoAlphAmount?: string;
@@ -249,8 +254,10 @@ export interface BuildSweepAddressTransactionsResult {
249
254
  toGroup: number;
250
255
  }
251
256
  export interface BuildTransaction {
252
- /** @format public-key */
257
+ /** @format hex-string */
253
258
  fromPublicKey: string;
259
+ /** @format hex-string */
260
+ fromPublicKeyType?: string;
254
261
  destinations: Destination[];
255
262
  utxos?: OutputRef[];
256
263
  /** @format gas */
@@ -508,6 +515,7 @@ export interface InterCliquePeerInfo {
508
515
  /** @format inet-socket-address */
509
516
  address: {
510
517
  addr: string;
518
+ /** @format int32 */
511
519
  port: number;
512
520
  };
513
521
  isSynced: boolean;
@@ -519,6 +527,13 @@ export interface InternalServerError {
519
527
  export interface MemPooled {
520
528
  type: string;
521
529
  }
530
+ export interface MempoolTransactions {
531
+ /** @format int32 */
532
+ fromGroup: number;
533
+ /** @format int32 */
534
+ toGroup: number;
535
+ transactions: TransactionTemplate[];
536
+ }
522
537
  export interface MinerAddresses {
523
538
  addresses: string[];
524
539
  }
@@ -532,6 +547,7 @@ export interface NodeInfo {
532
547
  /** @format inet-socket-address */
533
548
  externalAddress?: {
534
549
  addr: string;
550
+ /** @format int32 */
535
551
  port: number;
536
552
  };
537
553
  }
@@ -756,13 +772,6 @@ export interface Unban {
756
772
  peers: string[];
757
773
  type: string;
758
774
  }
759
- export interface UnconfirmedTransactions {
760
- /** @format int32 */
761
- fromGroup: number;
762
- /** @format int32 */
763
- toGroup: number;
764
- unconfirmedTransactions: TransactionTemplate[];
765
- }
766
775
  export interface Unreachable {
767
776
  peers: string[];
768
777
  type: string;
@@ -886,7 +895,8 @@ declare type CancelToken = Symbol | string | number;
886
895
  export declare enum ContentType {
887
896
  Json = "application/json",
888
897
  FormData = "multipart/form-data",
889
- UrlEncoded = "application/x-www-form-urlencoded"
898
+ UrlEncoded = "application/x-www-form-urlencoded",
899
+ Text = "text/plain"
890
900
  }
891
901
  export declare class HttpClient<SecurityDataType = unknown> {
892
902
  baseUrl: string;
@@ -897,20 +907,20 @@ export declare class HttpClient<SecurityDataType = unknown> {
897
907
  private baseApiParams;
898
908
  constructor(apiConfig?: ApiConfig<SecurityDataType>);
899
909
  setSecurityData: (data: SecurityDataType | null) => void;
900
- private encodeQueryParam;
901
- private addQueryParam;
902
- private addArrayQueryParam;
910
+ protected encodeQueryParam(key: string, value: any): string;
911
+ protected addQueryParam(query: QueryParamsType, key: string): string;
912
+ protected addArrayQueryParam(query: QueryParamsType, key: string): any;
903
913
  protected toQueryString(rawQuery?: QueryParamsType): string;
904
914
  protected addQueryParams(rawQuery?: QueryParamsType): string;
905
915
  private contentFormatters;
906
- private mergeRequestParams;
907
- private createAbortSignal;
916
+ protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams;
917
+ protected createAbortSignal: (cancelToken: CancelToken) => AbortSignal | undefined;
908
918
  abortRequest: (cancelToken: CancelToken) => void;
909
919
  request: <T = any, E = any>({ body, secure, path, type, query, format, baseUrl, cancelToken, ...params }: FullRequestParams) => Promise<HttpResponse<T, E>>;
910
920
  }
911
921
  /**
912
922
  * @title Alephium API
913
- * @version 1.7.0
923
+ * @version 1.7.1
914
924
  * @baseUrl ../
915
925
  */
916
926
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -1068,6 +1078,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1068
1078
  * @request POST:/wallets/{wallet_name}/derive-next-address
1069
1079
  */
1070
1080
  postWalletsWalletNameDeriveNextAddress: (walletName: string, query?: {
1081
+ /** @format int32 */
1071
1082
  group?: number;
1072
1083
  }, params?: RequestParams) => Promise<AddressInfo>;
1073
1084
  /**
@@ -1189,7 +1200,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1189
1200
  * @request GET:/infos/history-hashrate
1190
1201
  */
1191
1202
  getInfosHistoryHashrate: (query: {
1203
+ /**
1204
+ * @format int64
1205
+ * @min 0
1206
+ */
1192
1207
  fromTs: number;
1208
+ /**
1209
+ * @format int64
1210
+ * @min 0
1211
+ */
1193
1212
  toTs?: number;
1194
1213
  }, params?: RequestParams) => Promise<string>;
1195
1214
  /**
@@ -1201,6 +1220,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1201
1220
  * @request GET:/infos/current-hashrate
1202
1221
  */
1203
1222
  getInfosCurrentHashrate: (query?: {
1223
+ /**
1224
+ * @format int64
1225
+ * @min 1
1226
+ */
1204
1227
  timespan?: number;
1205
1228
  }, params?: RequestParams) => Promise<string>;
1206
1229
  };
@@ -1214,7 +1237,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1214
1237
  * @request GET:/blockflow/blocks
1215
1238
  */
1216
1239
  getBlockflowBlocks: (query: {
1240
+ /**
1241
+ * @format int64
1242
+ * @min 0
1243
+ */
1217
1244
  fromTs: number;
1245
+ /**
1246
+ * @format int64
1247
+ * @min 0
1248
+ */
1218
1249
  toTs?: number;
1219
1250
  }, params?: RequestParams) => Promise<BlocksPerTimeStampRange>;
1220
1251
  /**
@@ -1226,7 +1257,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1226
1257
  * @request GET:/blockflow/blocks-with-events
1227
1258
  */
1228
1259
  getBlockflowBlocksWithEvents: (query: {
1260
+ /**
1261
+ * @format int64
1262
+ * @min 0
1263
+ */
1229
1264
  fromTs: number;
1265
+ /**
1266
+ * @format int64
1267
+ * @min 0
1268
+ */
1230
1269
  toTs?: number;
1231
1270
  }, params?: RequestParams) => Promise<BlocksAndEventsPerTimeStampRange>;
1232
1271
  /**
@@ -1267,8 +1306,11 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1267
1306
  * @request GET:/blockflow/hashes
1268
1307
  */
1269
1308
  getBlockflowHashes: (query: {
1309
+ /** @format int32 */
1270
1310
  fromGroup: number;
1311
+ /** @format int32 */
1271
1312
  toGroup: number;
1313
+ /** @format int32 */
1272
1314
  height: number;
1273
1315
  }, params?: RequestParams) => Promise<HashesAtHeight>;
1274
1316
  /**
@@ -1280,7 +1322,9 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1280
1322
  * @request GET:/blockflow/chain-info
1281
1323
  */
1282
1324
  getBlockflowChainInfo: (query: {
1325
+ /** @format int32 */
1283
1326
  fromGroup: number;
1327
+ /** @format int32 */
1284
1328
  toGroup: number;
1285
1329
  }, params?: RequestParams) => Promise<ChainInfo>;
1286
1330
  /**
@@ -1323,15 +1367,6 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1323
1367
  getAddressesAddressGroup: (address: string, params?: RequestParams) => Promise<Group>;
1324
1368
  };
1325
1369
  transactions: {
1326
- /**
1327
- * No description
1328
- *
1329
- * @tags Transactions
1330
- * @name GetTransactionsUnconfirmed
1331
- * @summary List unconfirmed transactions
1332
- * @request GET:/transactions/unconfirmed
1333
- */
1334
- getTransactionsUnconfirmed: (params?: RequestParams) => Promise<UnconfirmedTransactions[]>;
1335
1370
  /**
1336
1371
  * No description
1337
1372
  *
@@ -1377,7 +1412,9 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1377
1412
  * @request GET:/transactions/details/{txId}
1378
1413
  */
1379
1414
  getTransactionsDetailsTxid: (txId: string, query?: {
1415
+ /** @format int32 */
1380
1416
  fromGroup?: number;
1417
+ /** @format int32 */
1381
1418
  toGroup?: number;
1382
1419
  }, params?: RequestParams) => Promise<Transaction>;
1383
1420
  /**
@@ -1390,10 +1427,52 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1390
1427
  */
1391
1428
  getTransactionsStatus: (query: {
1392
1429
  txId: string;
1430
+ /** @format int32 */
1393
1431
  fromGroup?: number;
1432
+ /** @format int32 */
1394
1433
  toGroup?: number;
1395
1434
  }, params?: RequestParams) => Promise<Confirmed | MemPooled | TxNotFound>;
1396
1435
  };
1436
+ mempool: {
1437
+ /**
1438
+ * No description
1439
+ *
1440
+ * @tags Mempool
1441
+ * @name GetMempoolTransactions
1442
+ * @summary List mempool transactions
1443
+ * @request GET:/mempool/transactions
1444
+ */
1445
+ getMempoolTransactions: (params?: RequestParams) => Promise<MempoolTransactions[]>;
1446
+ /**
1447
+ * No description
1448
+ *
1449
+ * @tags Mempool
1450
+ * @name DeleteMempoolTransactions
1451
+ * @summary Remove all transactions from mempool
1452
+ * @request DELETE:/mempool/transactions
1453
+ */
1454
+ deleteMempoolTransactions: (params?: RequestParams) => Promise<void>;
1455
+ /**
1456
+ * No description
1457
+ *
1458
+ * @tags Mempool
1459
+ * @name PutMempoolTransactionsRebroadcast
1460
+ * @summary Rebroadcase a mempool transaction to the network
1461
+ * @request PUT:/mempool/transactions/rebroadcast
1462
+ */
1463
+ putMempoolTransactionsRebroadcast: (query: {
1464
+ txId: string;
1465
+ }, params?: RequestParams) => Promise<void>;
1466
+ /**
1467
+ * No description
1468
+ *
1469
+ * @tags Mempool
1470
+ * @name PutMempoolTransactionsValidate
1471
+ * @summary Validate all mempool transactions and remove invalid ones
1472
+ * @request PUT:/mempool/transactions/validate
1473
+ */
1474
+ putMempoolTransactionsValidate: (params?: RequestParams) => Promise<void>;
1475
+ };
1397
1476
  contracts: {
1398
1477
  /**
1399
1478
  * No description
@@ -1449,6 +1528,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1449
1528
  * @request GET:/contracts/{address}/state
1450
1529
  */
1451
1530
  getContractsAddressState: (address: string, query: {
1531
+ /** @format int32 */
1452
1532
  group: number;
1453
1533
  }, params?: RequestParams) => Promise<ContractState>;
1454
1534
  /**
@@ -1540,7 +1620,9 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1540
1620
  * @request POST:/miners/cpu-mining/mine-one-block
1541
1621
  */
1542
1622
  postMinersCpuMiningMineOneBlock: (query: {
1623
+ /** @format int32 */
1543
1624
  fromGroup: number;
1625
+ /** @format int32 */
1544
1626
  toGroup: number;
1545
1627
  }, params?: RequestParams) => Promise<boolean>;
1546
1628
  /**
@@ -1572,8 +1654,11 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1572
1654
  * @request GET:/events/contract/{contractAddress}
1573
1655
  */
1574
1656
  getEventsContractContractaddress: (contractAddress: string, query: {
1657
+ /** @format int32 */
1575
1658
  start: number;
1659
+ /** @format int32 */
1576
1660
  limit?: number;
1661
+ /** @format int32 */
1577
1662
  group?: number;
1578
1663
  }, params?: RequestParams) => Promise<ContractEvents>;
1579
1664
  /**
@@ -1594,6 +1679,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1594
1679
  * @request GET:/events/tx-id/{txId}
1595
1680
  */
1596
1681
  getEventsTxIdTxid: (txId: string, query?: {
1682
+ /** @format int32 */
1597
1683
  group?: number;
1598
1684
  }, params?: RequestParams) => Promise<ContractEventsByTxId>;
1599
1685
  /**
@@ -1605,6 +1691,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1605
1691
  * @request GET:/events/block-hash/{blockHash}
1606
1692
  */
1607
1693
  getEventsBlockHashBlockhash: (blockHash: string, query?: {
1694
+ /** @format int32 */
1608
1695
  group?: number;
1609
1696
  }, params?: RequestParams) => Promise<ContractEventsByBlockHash>;
1610
1697
  };
@@ -18,6 +18,7 @@ var ContentType;
18
18
  ContentType["Json"] = "application/json";
19
19
  ContentType["FormData"] = "multipart/form-data";
20
20
  ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
21
+ ContentType["Text"] = "text/plain";
21
22
  })(ContentType = exports.ContentType || (exports.ContentType = {}));
22
23
  class HttpClient {
23
24
  constructor(apiConfig = {}) {
@@ -36,6 +37,7 @@ class HttpClient {
36
37
  };
37
38
  this.contentFormatters = {
38
39
  [ContentType.Json]: (input) => input !== null && (typeof input === 'object' || typeof input === 'string') ? JSON.stringify(input) : input,
40
+ [ContentType.Text]: (input) => (input !== null && typeof input !== 'string' ? JSON.stringify(input) : input),
39
41
  [ContentType.FormData]: (input) => Object.keys(input || {}).reduce((formData, key) => {
40
42
  const property = input[key];
41
43
  formData.append(key, property instanceof Blob
@@ -78,10 +80,10 @@ class HttpClient {
78
80
  return this.customFetch(`${baseUrl || this.baseUrl || ''}${path}${queryString ? `?${queryString}` : ''}`, {
79
81
  ...requestParams,
80
82
  headers: {
81
- ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
82
- ...(requestParams.headers || {})
83
+ ...(requestParams.headers || {}),
84
+ ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {})
83
85
  },
84
- signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0,
86
+ signal: cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal,
85
87
  body: typeof body === 'undefined' || body === null ? null : payloadFormatter(body)
86
88
  }).then(async (response) => {
87
89
  const r = response;
@@ -149,7 +151,7 @@ class HttpClient {
149
151
  exports.HttpClient = HttpClient;
150
152
  /**
151
153
  * @title Alephium API
152
- * @version 1.7.0
154
+ * @version 1.7.1
153
155
  * @baseUrl ../
154
156
  */
155
157
  class Api extends HttpClient {
@@ -778,20 +780,6 @@ class Api extends HttpClient {
778
780
  }).then(utils_1.convertHttpResponse)
779
781
  };
780
782
  this.transactions = {
781
- /**
782
- * No description
783
- *
784
- * @tags Transactions
785
- * @name GetTransactionsUnconfirmed
786
- * @summary List unconfirmed transactions
787
- * @request GET:/transactions/unconfirmed
788
- */
789
- getTransactionsUnconfirmed: (params = {}) => this.request({
790
- path: `/transactions/unconfirmed`,
791
- method: 'GET',
792
- format: 'json',
793
- ...params
794
- }).then(utils_1.convertHttpResponse),
795
783
  /**
796
784
  * No description
797
785
  *
@@ -887,6 +875,62 @@ class Api extends HttpClient {
887
875
  ...params
888
876
  }).then(utils_1.convertHttpResponse)
889
877
  };
878
+ this.mempool = {
879
+ /**
880
+ * No description
881
+ *
882
+ * @tags Mempool
883
+ * @name GetMempoolTransactions
884
+ * @summary List mempool transactions
885
+ * @request GET:/mempool/transactions
886
+ */
887
+ getMempoolTransactions: (params = {}) => this.request({
888
+ path: `/mempool/transactions`,
889
+ method: 'GET',
890
+ format: 'json',
891
+ ...params
892
+ }).then(utils_1.convertHttpResponse),
893
+ /**
894
+ * No description
895
+ *
896
+ * @tags Mempool
897
+ * @name DeleteMempoolTransactions
898
+ * @summary Remove all transactions from mempool
899
+ * @request DELETE:/mempool/transactions
900
+ */
901
+ deleteMempoolTransactions: (params = {}) => this.request({
902
+ path: `/mempool/transactions`,
903
+ method: 'DELETE',
904
+ ...params
905
+ }).then(utils_1.convertHttpResponse),
906
+ /**
907
+ * No description
908
+ *
909
+ * @tags Mempool
910
+ * @name PutMempoolTransactionsRebroadcast
911
+ * @summary Rebroadcase a mempool transaction to the network
912
+ * @request PUT:/mempool/transactions/rebroadcast
913
+ */
914
+ putMempoolTransactionsRebroadcast: (query, params = {}) => this.request({
915
+ path: `/mempool/transactions/rebroadcast`,
916
+ method: 'PUT',
917
+ query: query,
918
+ ...params
919
+ }).then(utils_1.convertHttpResponse),
920
+ /**
921
+ * No description
922
+ *
923
+ * @tags Mempool
924
+ * @name PutMempoolTransactionsValidate
925
+ * @summary Validate all mempool transactions and remove invalid ones
926
+ * @request PUT:/mempool/transactions/validate
927
+ */
928
+ putMempoolTransactionsValidate: (params = {}) => this.request({
929
+ path: `/mempool/transactions/validate`,
930
+ method: 'PUT',
931
+ ...params
932
+ }).then(utils_1.convertHttpResponse)
933
+ };
890
934
  this.contracts = {
891
935
  /**
892
936
  * No description