@alephium/web3 0.3.0-rc.5 → 0.3.0-rc.7

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.
@@ -908,7 +908,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
908
908
  }
909
909
  /**
910
910
  * @title Alephium API
911
- * @version 1.6.1
911
+ * @version 1.6.2
912
912
  * @baseUrl ../
913
913
  */
914
914
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -149,7 +149,7 @@ class HttpClient {
149
149
  exports.HttpClient = HttpClient;
150
150
  /**
151
151
  * @title Alephium API
152
- * @version 1.6.1
152
+ * @version 1.6.2
153
153
  * @baseUrl ../
154
154
  */
155
155
  class Api extends HttpClient {
@@ -62,6 +62,7 @@ export interface ConfirmedTransaction {
62
62
  gasAmount: number;
63
63
  /** @format uint256 */
64
64
  gasPrice: string;
65
+ coinbase: boolean;
65
66
  type: string;
66
67
  }
67
68
  export interface ContractOutput {
@@ -77,6 +78,17 @@ export interface ContractOutput {
77
78
  spent?: string;
78
79
  type: string;
79
80
  }
81
+ export interface Event {
82
+ /** @format block-hash */
83
+ blockHash: string;
84
+ /** @format 32-byte-hash */
85
+ txHash: string;
86
+ contractAddress: string;
87
+ inputAddress?: string;
88
+ /** @format int32 */
89
+ eventIndex: number;
90
+ fields?: Val[];
91
+ }
80
92
  export interface ExplorerInfo {
81
93
  releaseVersion: string;
82
94
  commit: string;
@@ -101,6 +113,10 @@ export interface Input {
101
113
  export interface InternalServerError {
102
114
  detail: string;
103
115
  }
116
+ export declare enum IntervalType {
117
+ Daily = "daily",
118
+ Hourly = "hourly"
119
+ }
104
120
  export interface ListBlocks {
105
121
  /** @format int32 */
106
122
  total: number;
@@ -196,6 +212,7 @@ export interface Transaction {
196
212
  gasAmount: number;
197
213
  /** @format uint256 */
198
214
  gasPrice: string;
215
+ coinbase: boolean;
199
216
  }
200
217
  export declare type TransactionLike = ConfirmedTransaction | UnconfirmedTransaction;
201
218
  export interface Unauthorized {
@@ -218,6 +235,35 @@ export interface UnconfirmedTransaction {
218
235
  lastSeen: number;
219
236
  type: string;
220
237
  }
238
+ export declare type Val = ValAddress | ValArray | ValBool | ValByteVec | ValI256 | ValU256;
239
+ export interface ValAddress {
240
+ /** @format address */
241
+ value: string;
242
+ type: string;
243
+ }
244
+ export interface ValArray {
245
+ value: Val[];
246
+ type: string;
247
+ }
248
+ export interface ValBool {
249
+ value: boolean;
250
+ type: string;
251
+ }
252
+ export interface ValByteVec {
253
+ /** @format hex-string */
254
+ value: string;
255
+ type: string;
256
+ }
257
+ export interface ValI256 {
258
+ /** @format bigint */
259
+ value: string;
260
+ type: string;
261
+ }
262
+ export interface ValU256 {
263
+ /** @format uint256 */
264
+ value: string;
265
+ type: string;
266
+ }
221
267
  import 'cross-fetch/polyfill';
222
268
  export declare type QueryParamsType = Record<string | number, any>;
223
269
  export declare type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>;
@@ -324,14 +370,6 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
324
370
  * @request GET:/transactions/{transaction_hash}
325
371
  */
326
372
  getTransactionsTransactionHash: (transactionHash: string, params?: RequestParams) => Promise<ConfirmedTransaction | UnconfirmedTransaction>;
327
- /**
328
- * @description Get a transaction from a output reference key
329
- *
330
- * @tags Transactions
331
- * @name GetTransactionsByOutputRefKeyOutputRefKey
332
- * @request GET:/transactions/by/output-ref-key/{output_ref_key}
333
- */
334
- getTransactionsByOutputRefKeyOutputRefKey: (outputRefKey: string, params?: RequestParams) => Promise<Transaction>;
335
373
  };
336
374
  addresses: {
337
375
  /**
@@ -432,6 +470,14 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
432
470
  * @request GET:/addresses/{address}/tokens/{token_id}/balance
433
471
  */
434
472
  getAddressesAddressTokensTokenIdBalance: (address: string, tokenId: string, params?: RequestParams) => Promise<AddressBalance>;
473
+ /**
474
+ * @description Are the addresses used (at least 1 transaction)
475
+ *
476
+ * @tags Addresses, Addresses
477
+ * @name PostAddressesUsed
478
+ * @request POST:/addresses/used
479
+ */
480
+ postAddressesUsed: (data?: string[], params?: RequestParams) => Promise<boolean[]>;
435
481
  /**
436
482
  * No description
437
483
  *
@@ -444,16 +490,6 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
444
490
  toTs: number;
445
491
  }, params?: RequestParams) => Promise<string>;
446
492
  };
447
- addressesActive: {
448
- /**
449
- * @description Are the addresses active (at least 1 transaction)
450
- *
451
- * @tags Addresses
452
- * @name PostAddressesActive
453
- * @request POST:/addresses-active
454
- */
455
- postAddressesActive: (data?: string[], params?: RequestParams) => Promise<boolean[]>;
456
- };
457
493
  infos: {
458
494
  /**
459
495
  * @description Get explorer informations
@@ -584,7 +620,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
584
620
  getChartsHashrates: (query: {
585
621
  fromTs: number;
586
622
  toTs: number;
587
- 'interval-type': string;
623
+ 'interval-type': IntervalType;
588
624
  }, params?: RequestParams) => Promise<Hashrate[]>;
589
625
  /**
590
626
  * @description `interval-type` query param: hourly, daily
@@ -597,7 +633,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
597
633
  getChartsTransactionsCount: (query: {
598
634
  fromTs: number;
599
635
  toTs: number;
600
- 'interval-type': string;
636
+ 'interval-type': IntervalType;
601
637
  }, params?: RequestParams) => Promise<TimedCount[]>;
602
638
  /**
603
639
  * @description `interval-type` query param: hourly, daily
@@ -610,9 +646,43 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
610
646
  getChartsTransactionsCountPerChain: (query: {
611
647
  fromTs: number;
612
648
  toTs: number;
613
- 'interval-type': string;
649
+ 'interval-type': IntervalType;
614
650
  }, params?: RequestParams) => Promise<PerChainTimedCount[]>;
615
651
  };
652
+ contractEvents: {
653
+ /**
654
+ * @description Get contract events by transaction id
655
+ *
656
+ * @tags Contract events
657
+ * @name GetContractEventsTransactionIdTransactionId
658
+ * @request GET:/contract-events/transaction-id/{transaction_id}
659
+ */
660
+ getContractEventsTransactionIdTransactionId: (transactionId: string, params?: RequestParams) => Promise<Event[]>;
661
+ /**
662
+ * @description Get contract events by contract address
663
+ *
664
+ * @tags Contract events
665
+ * @name GetContractEventsContractAddressContractAddress
666
+ * @request GET:/contract-events/contract-address/{contract_address}
667
+ */
668
+ getContractEventsContractAddressContractAddress: (contractAddress: string, query?: {
669
+ page?: number;
670
+ limit?: number;
671
+ reverse?: boolean;
672
+ }, params?: RequestParams) => Promise<Event[]>;
673
+ /**
674
+ * @description Get contract events by contract and input addresses
675
+ *
676
+ * @tags Contract events
677
+ * @name GetContractEventsContractAddressContractAddressInputAddressInputAddress
678
+ * @request GET:/contract-events/contract-address/{contract_address}/input-address/{input_address}
679
+ */
680
+ getContractEventsContractAddressContractAddressInputAddressInputAddress: (contractAddress: string, inputAddress: string, query?: {
681
+ page?: number;
682
+ limit?: number;
683
+ reverse?: boolean;
684
+ }, params?: RequestParams) => Promise<Event[]>;
685
+ };
616
686
  utils: {
617
687
  /**
618
688
  * @description Perform a sanity check
@@ -10,7 +10,12 @@
10
10
  * ---------------------------------------------------------------
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Api = exports.HttpClient = exports.ContentType = void 0;
13
+ exports.Api = exports.HttpClient = exports.ContentType = exports.IntervalType = void 0;
14
+ var IntervalType;
15
+ (function (IntervalType) {
16
+ IntervalType["Daily"] = "daily";
17
+ IntervalType["Hourly"] = "hourly";
18
+ })(IntervalType = exports.IntervalType || (exports.IntervalType = {}));
14
19
  require("cross-fetch/polyfill");
15
20
  const utils_1 = require("./utils");
16
21
  var ContentType;
@@ -210,19 +215,6 @@ class Api extends HttpClient {
210
215
  method: 'GET',
211
216
  format: 'json',
212
217
  ...params
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
218
  }).then(utils_1.convertHttpResponse)
227
219
  };
228
220
  this.addresses = {
@@ -362,6 +354,21 @@ class Api extends HttpClient {
362
354
  format: 'json',
363
355
  ...params
364
356
  }).then(utils_1.convertHttpResponse),
357
+ /**
358
+ * @description Are the addresses used (at least 1 transaction)
359
+ *
360
+ * @tags Addresses, Addresses
361
+ * @name PostAddressesUsed
362
+ * @request POST:/addresses/used
363
+ */
364
+ postAddressesUsed: (data, params = {}) => this.request({
365
+ path: `/addresses/used`,
366
+ method: 'POST',
367
+ body: data,
368
+ type: ContentType.Json,
369
+ format: 'json',
370
+ ...params
371
+ }).then(utils_1.convertHttpResponse),
365
372
  /**
366
373
  * No description
367
374
  *
@@ -376,23 +383,6 @@ class Api extends HttpClient {
376
383
  ...params
377
384
  }).then(utils_1.convertHttpResponse)
378
385
  };
379
- this.addressesActive = {
380
- /**
381
- * @description Are the addresses active (at least 1 transaction)
382
- *
383
- * @tags Addresses
384
- * @name PostAddressesActive
385
- * @request POST:/addresses-active
386
- */
387
- postAddressesActive: (data, params = {}) => this.request({
388
- path: `/addresses-active`,
389
- method: 'POST',
390
- body: data,
391
- type: ContentType.Json,
392
- format: 'json',
393
- ...params
394
- }).then(utils_1.convertHttpResponse)
395
- };
396
386
  this.infos = {
397
387
  /**
398
388
  * @description Get explorer informations
@@ -601,6 +591,49 @@ class Api extends HttpClient {
601
591
  ...params
602
592
  }).then(utils_1.convertHttpResponse)
603
593
  };
594
+ this.contractEvents = {
595
+ /**
596
+ * @description Get contract events by transaction id
597
+ *
598
+ * @tags Contract events
599
+ * @name GetContractEventsTransactionIdTransactionId
600
+ * @request GET:/contract-events/transaction-id/{transaction_id}
601
+ */
602
+ getContractEventsTransactionIdTransactionId: (transactionId, params = {}) => this.request({
603
+ path: `/contract-events/transaction-id/${transactionId}`,
604
+ method: 'GET',
605
+ format: 'json',
606
+ ...params
607
+ }).then(utils_1.convertHttpResponse),
608
+ /**
609
+ * @description Get contract events by contract address
610
+ *
611
+ * @tags Contract events
612
+ * @name GetContractEventsContractAddressContractAddress
613
+ * @request GET:/contract-events/contract-address/{contract_address}
614
+ */
615
+ getContractEventsContractAddressContractAddress: (contractAddress, query, params = {}) => this.request({
616
+ path: `/contract-events/contract-address/${contractAddress}`,
617
+ method: 'GET',
618
+ query: query,
619
+ format: 'json',
620
+ ...params
621
+ }).then(utils_1.convertHttpResponse),
622
+ /**
623
+ * @description Get contract events by contract and input addresses
624
+ *
625
+ * @tags Contract events
626
+ * @name GetContractEventsContractAddressContractAddressInputAddressInputAddress
627
+ * @request GET:/contract-events/contract-address/{contract_address}/input-address/{input_address}
628
+ */
629
+ getContractEventsContractAddressContractAddressInputAddressInputAddress: (contractAddress, inputAddress, query, params = {}) => this.request({
630
+ path: `/contract-events/contract-address/${contractAddress}/input-address/${inputAddress}`,
631
+ method: 'GET',
632
+ query: query,
633
+ format: 'json',
634
+ ...params
635
+ }).then(utils_1.convertHttpResponse)
636
+ };
604
637
  this.utils = {
605
638
  /**
606
639
  * @description Perform a sanity check
@@ -27,7 +27,6 @@ export declare class ExplorerProvider {
27
27
  readonly blocks: any;
28
28
  readonly transactions: any;
29
29
  readonly addresses: any;
30
- readonly addressesActive: any;
31
30
  readonly infos: any;
32
31
  readonly unconfirmedTransactions: any;
33
32
  readonly tokens: any;
@@ -119,7 +119,6 @@ class ExplorerProvider {
119
119
  this.blocks = api_explorer_1.Api['blocks'];
120
120
  this.transactions = api_explorer_1.Api['transactions'];
121
121
  this.addresses = api_explorer_1.Api['addresses'];
122
- this.addressesActive = api_explorer_1.Api['addressesActive'];
123
122
  this.infos = api_explorer_1.Api['infos'];
124
123
  this.unconfirmedTransactions = api_explorer_1.Api['unconfirmedTransactions'];
125
124
  this.tokens = api_explorer_1.Api['tokens'];
@@ -142,7 +141,6 @@ class ExplorerProvider {
142
141
  this.blocks = { ...explorerApi.blocks };
143
142
  this.transactions = { ...explorerApi.transactions };
144
143
  this.addresses = { ...explorerApi.addresses };
145
- this.addressesActive = { ...explorerApi.addressesActive };
146
144
  this.infos = { ...explorerApi.infos };
147
145
  this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
148
146
  this.tokens = { ...explorerApi.tokens };
@@ -1,2 +1,3 @@
1
1
  export * from './signer';
2
2
  export * from './types';
3
+ export * from './tx-builder';
@@ -33,3 +33,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  __exportStar(require("./signer"), exports);
35
35
  __exportStar(require("./types"), exports);
36
+ __exportStar(require("./tx-builder"), exports);
@@ -1,6 +1,7 @@
1
1
  import { ExplorerProvider, NodeProvider } from '../api';
2
2
  import { node } from '../api';
3
- import { Account, Address, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams } from './types';
3
+ import { Account, Address, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams } from './types';
4
+ import { TransactionBuilder } from './tx-builder';
4
5
  export interface SignerProvider {
5
6
  get nodeProvider(): NodeProvider | undefined;
6
7
  get explorerProvider(): ExplorerProvider | undefined;
@@ -13,15 +14,19 @@ export interface SignerProvider {
13
14
  signMessage(params: SignMessageParams): Promise<SignMessageResult>;
14
15
  }
15
16
  export interface InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase> extends SignerProvider {
16
- enable(opt?: EnableOptions): Promise<void>;
17
+ enable(opt?: EnableOptions): Promise<Address>;
17
18
  disconnect(): Promise<void>;
19
+ signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>;
20
+ signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>;
21
+ signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
22
+ signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
23
+ signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
24
+ signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>;
18
25
  }
19
- export declare abstract class SignerProviderSimple implements SignerProvider {
20
- abstract get nodeProvider(): NodeProvider | undefined;
26
+ export declare abstract class SignerProviderSimple extends TransactionBuilder implements SignerProvider {
21
27
  abstract get explorerProvider(): ExplorerProvider | undefined;
22
28
  abstract getSelectedAccount(): Promise<Account>;
23
29
  getSelectedAddress(): Promise<Address>;
24
- private getNodeProvider;
25
30
  submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
26
31
  signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
27
32
  signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
@@ -30,11 +35,11 @@ export declare abstract class SignerProviderSimple implements SignerProvider {
30
35
  protected abstract getPublicKey(address: string): Promise<string>;
31
36
  private usePublicKey;
32
37
  signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
33
- buildTransferTx(params: SignTransferTxParams): Promise<node.BuildTransactionResult>;
38
+ buildTransferTx(params: SignTransferTxParams): Promise<Omit<SignTransferTxResult, 'signature'>>;
34
39
  signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
35
- buildContractCreationTx(params: SignDeployContractTxParams): Promise<node.BuildDeployContractTxResult>;
40
+ buildDeployContractTx(params: SignDeployContractTxParams): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
36
41
  signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
37
- buildScriptTx(params: SignExecuteScriptTxParams): Promise<node.BuildExecuteScriptTxResult>;
42
+ buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
38
43
  signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
39
44
  signMessage(params: SignMessageParams): Promise<SignMessageResult>;
40
45
  abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
@@ -48,21 +48,16 @@ const elliptic_1 = require("elliptic");
48
48
  const api_1 = require("../api");
49
49
  const utils = __importStar(require("../utils"));
50
50
  const blakejs_1 = __importDefault(require("blakejs"));
51
+ const tx_builder_1 = require("./tx-builder");
51
52
  const ec = new elliptic_1.ec('secp256k1');
52
- class SignerProviderSimple {
53
+ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
53
54
  async getSelectedAddress() {
54
55
  const account = await this.getSelectedAccount();
55
56
  return account.address;
56
57
  }
57
- getNodeProvider() {
58
- if (this.nodeProvider === undefined) {
59
- throw Error('The signer does not contain a node provider');
60
- }
61
- return this.nodeProvider;
62
- }
63
58
  async submitTransaction(params) {
64
59
  const data = { unsignedTx: params.unsignedTx, signature: params.signature };
65
- return this.getNodeProvider().transactions.postTransactionsSubmit(data);
60
+ return this.nodeProvider.transactions.postTransactionsSubmit(data);
66
61
  }
67
62
  async signAndSubmitTransferTx(params) {
68
63
  const signResult = await this.signTransferTx(params);
@@ -92,61 +87,33 @@ class SignerProviderSimple {
92
87
  async signTransferTx(params) {
93
88
  const response = await this.buildTransferTx(params);
94
89
  const signature = await this.signRaw(params.signerAddress, response.txId);
95
- return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
90
+ return { signature, ...response };
96
91
  }
97
92
  async buildTransferTx(params) {
98
- const data = {
99
- ...(await this.usePublicKey(params)),
100
- destinations: toApiDestinations(params.destinations),
101
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
102
- };
103
- return this.getNodeProvider().transactions.postTransactionsBuild(data);
93
+ return super.buildTransferTx(params, await this.getPublicKey(params.signerAddress));
104
94
  }
105
95
  async signDeployContractTx(params) {
106
- const response = await this.buildContractCreationTx(params);
96
+ const response = await this.buildDeployContractTx(params);
107
97
  const signature = await this.signRaw(params.signerAddress, response.txId);
108
- const contractId = utils.binToHex(utils.contractIdFromAddress(response.contractAddress));
109
- return { ...response, contractId, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
110
- }
111
- async buildContractCreationTx(params) {
112
- const data = {
113
- ...(await this.usePublicKey(params)),
114
- initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(params.initialAttoAlphAmount),
115
- initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
116
- issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
117
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
118
- };
119
- return this.getNodeProvider().contracts.postContractsUnsignedTxDeployContract(data);
98
+ return { signature, ...response };
99
+ }
100
+ async buildDeployContractTx(params) {
101
+ return super.buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
120
102
  }
121
103
  async signExecuteScriptTx(params) {
122
- const response = await this.buildScriptTx(params);
104
+ const response = await this.buildExecuteScriptTx(params);
123
105
  const signature = await this.signRaw(params.signerAddress, response.txId);
124
- return { ...response, signature, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
106
+ return { signature, ...response };
125
107
  }
126
- async buildScriptTx(params) {
127
- const data = {
128
- ...(await this.usePublicKey(params)),
129
- attoAlphAmount: (0, api_1.toApiNumber256Optional)(params.attoAlphAmount),
130
- tokens: (0, api_1.toApiTokens)(params.tokens),
131
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
132
- };
133
- return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data);
108
+ async buildExecuteScriptTx(params) {
109
+ return super.buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
134
110
  }
135
111
  // in general, wallet should show the decoded information to user for confirmation
136
112
  // please overwrite this function for real wallet
137
113
  async signUnsignedTx(params) {
138
- const data = { unsignedTx: params.unsignedTx };
139
- const decoded = await this.getNodeProvider().transactions.postTransactionsDecodeUnsignedTx(data);
140
- const signature = await this.signRaw(params.signerAddress, decoded.unsignedTx.txId);
141
- return {
142
- fromGroup: decoded.fromGroup,
143
- toGroup: decoded.toGroup,
144
- unsignedTx: params.unsignedTx,
145
- txId: decoded.unsignedTx.txId,
146
- signature,
147
- gasAmount: decoded.unsignedTx.gasAmount,
148
- gasPrice: (0, api_1.fromApiNumber256)(decoded.unsignedTx.gasPrice)
149
- };
114
+ const response = await this.buildUnsignedTx(params);
115
+ const signature = await this.signRaw(params.signerAddress, response.txId);
116
+ return { signature, ...response };
150
117
  }
151
118
  async signMessage(params) {
152
119
  const extendedMessage = extendMessage(params.message);
@@ -0,0 +1,17 @@
1
+ import { NodeProvider } from '../api';
2
+ import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult } from './types';
3
+ export declare abstract class TransactionBuilder {
4
+ abstract get nodeProvider(): NodeProvider;
5
+ static create(baseUrl: string, apiKey?: string): {
6
+ readonly nodeProvider: NodeProvider;
7
+ buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, "signature">>;
8
+ buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, "signature">>;
9
+ buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<Omit<SignExecuteScriptTxResult, "signature">>;
10
+ buildUnsignedTx(params: SignUnsignedTxParams): Promise<Omit<SignUnsignedTxResult, "signature">>;
11
+ };
12
+ private static validatePublicKey;
13
+ buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, 'signature'>>;
14
+ buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
15
+ buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
16
+ buildUnsignedTx(params: SignUnsignedTxParams): Promise<Omit<SignUnsignedTxResult, 'signature'>>;
17
+ }
@@ -0,0 +1,93 @@
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.TransactionBuilder = void 0;
21
+ const __1 = require("..");
22
+ const api_1 = require("../api");
23
+ const utils_1 = require("../utils");
24
+ const signer_1 = require("./signer");
25
+ class TransactionBuilder {
26
+ static create(baseUrl, apiKey) {
27
+ const nodeProvider = new api_1.NodeProvider(baseUrl, apiKey);
28
+ return new (class extends TransactionBuilder {
29
+ get nodeProvider() {
30
+ return nodeProvider;
31
+ }
32
+ })();
33
+ }
34
+ static validatePublicKey(params, publicKey) {
35
+ const address = (0, utils_1.addressFromPublicKey)(publicKey);
36
+ if (address !== params.signerAddress) {
37
+ throw new Error('Unmatched public key');
38
+ }
39
+ }
40
+ async buildTransferTx(params, publicKey) {
41
+ TransactionBuilder.validatePublicKey(params, publicKey);
42
+ const { destinations, gasPrice, ...rest } = params;
43
+ const data = {
44
+ fromPublicKey: publicKey,
45
+ destinations: (0, signer_1.toApiDestinations)(destinations),
46
+ gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
47
+ ...rest
48
+ };
49
+ const response = await this.nodeProvider.transactions.postTransactionsBuild(data);
50
+ return { ...response, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
51
+ }
52
+ async buildDeployContractTx(params, publicKey) {
53
+ TransactionBuilder.validatePublicKey(params, publicKey);
54
+ const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params;
55
+ const data = {
56
+ fromPublicKey: publicKey,
57
+ initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(initialAttoAlphAmount),
58
+ initialTokenAmounts: (0, api_1.toApiTokens)(initialTokenAmounts),
59
+ issueTokenAmount: (0, api_1.toApiNumber256Optional)(issueTokenAmount),
60
+ gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
61
+ ...rest
62
+ };
63
+ const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data);
64
+ const contractId = __1.utils.binToHex(__1.utils.contractIdFromAddress(response.contractAddress));
65
+ return { ...response, contractId, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
66
+ }
67
+ async buildExecuteScriptTx(params, publicKey) {
68
+ TransactionBuilder.validatePublicKey(params, publicKey);
69
+ const { attoAlphAmount, tokens, gasPrice, ...rest } = params;
70
+ const data = {
71
+ fromPublicKey: publicKey,
72
+ attoAlphAmount: (0, api_1.toApiNumber256Optional)(attoAlphAmount),
73
+ tokens: (0, api_1.toApiTokens)(tokens),
74
+ gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
75
+ ...rest
76
+ };
77
+ const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data);
78
+ return { ...response, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
79
+ }
80
+ async buildUnsignedTx(params) {
81
+ const data = { unsignedTx: params.unsignedTx };
82
+ const decoded = await this.nodeProvider.transactions.postTransactionsDecodeUnsignedTx(data);
83
+ return {
84
+ fromGroup: decoded.fromGroup,
85
+ toGroup: decoded.toGroup,
86
+ unsignedTx: params.unsignedTx,
87
+ txId: decoded.unsignedTx.txId,
88
+ gasAmount: decoded.unsignedTx.gasAmount,
89
+ gasPrice: (0, api_1.fromApiNumber256)(decoded.unsignedTx.gasPrice)
90
+ };
91
+ }
92
+ }
93
+ exports.TransactionBuilder = TransactionBuilder;
@@ -101,9 +101,21 @@ export interface SubmissionResult {
101
101
  }
102
102
  export interface EnableOptionsBase {
103
103
  chainGroup?: number;
104
+ networkId: string;
104
105
  onDisconnected: () => Promise<void>;
105
- onNetworkChanged: (network: {
106
- networkName: string;
107
- networkId: number;
108
- }) => Promise<void>;
109
106
  }
107
+ export declare type ExtSignTransferTxParams = SignTransferTxParams & {
108
+ networkId: string;
109
+ };
110
+ export declare type ExtSignDeployContractTxParams = SignDeployContractTxParams & {
111
+ networkId: string;
112
+ };
113
+ export declare type ExtSignExecuteScriptTxParams = SignExecuteScriptTxParams & {
114
+ networkId: string;
115
+ };
116
+ export declare type ExtSignUnsignedTxParams = SignUnsignedTxParams & {
117
+ networkId: string;
118
+ };
119
+ export declare type ExtSignMessageParams = SignMessageParams & {
120
+ networkId: string;
121
+ };