@alephium/web3 0.5.0-rc.7 → 0.5.0-rc.9

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.
@@ -145,9 +145,11 @@ export interface BrokerInfo {
145
145
  };
146
146
  }
147
147
  export interface BuildDeployContractTx {
148
- /** @format public-key */
148
+ /** @format hex-string */
149
149
  fromPublicKey: string;
150
150
  /** @format hex-string */
151
+ fromPublicKeyType?: string;
152
+ /** @format hex-string */
151
153
  bytecode: string;
152
154
  /** @format uint256 */
153
155
  initialAttoAlphAmount?: string;
@@ -177,9 +179,11 @@ export interface BuildDeployContractTxResult {
177
179
  contractAddress: string;
178
180
  }
179
181
  export interface BuildExecuteScriptTx {
180
- /** @format public-key */
182
+ /** @format hex-string */
181
183
  fromPublicKey: string;
182
184
  /** @format hex-string */
185
+ fromPublicKeyType?: string;
186
+ /** @format hex-string */
183
187
  bytecode: string;
184
188
  /** @format uint256 */
185
189
  attoAlphAmount?: string;
@@ -249,8 +253,10 @@ export interface BuildSweepAddressTransactionsResult {
249
253
  toGroup: number;
250
254
  }
251
255
  export interface BuildTransaction {
252
- /** @format public-key */
256
+ /** @format hex-string */
253
257
  fromPublicKey: string;
258
+ /** @format hex-string */
259
+ fromPublicKeyType?: string;
254
260
  destinations: Destination[];
255
261
  utxos?: OutputRef[];
256
262
  /** @format gas */
@@ -519,6 +525,13 @@ export interface InternalServerError {
519
525
  export interface MemPooled {
520
526
  type: string;
521
527
  }
528
+ export interface MempoolTransactions {
529
+ /** @format int32 */
530
+ fromGroup: number;
531
+ /** @format int32 */
532
+ toGroup: number;
533
+ transactions: TransactionTemplate[];
534
+ }
522
535
  export interface MinerAddresses {
523
536
  addresses: string[];
524
537
  }
@@ -756,13 +769,6 @@ export interface Unban {
756
769
  peers: string[];
757
770
  type: string;
758
771
  }
759
- export interface UnconfirmedTransactions {
760
- /** @format int32 */
761
- fromGroup: number;
762
- /** @format int32 */
763
- toGroup: number;
764
- unconfirmedTransactions: TransactionTemplate[];
765
- }
766
772
  export interface Unreachable {
767
773
  peers: string[];
768
774
  type: string;
@@ -910,7 +916,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
910
916
  }
911
917
  /**
912
918
  * @title Alephium API
913
- * @version 1.7.0
919
+ * @version 1.7.1
914
920
  * @baseUrl ../
915
921
  */
916
922
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -1323,15 +1329,6 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1323
1329
  getAddressesAddressGroup: (address: string, params?: RequestParams) => Promise<Group>;
1324
1330
  };
1325
1331
  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
1332
  /**
1336
1333
  * No description
1337
1334
  *
@@ -1394,6 +1391,46 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1394
1391
  toGroup?: number;
1395
1392
  }, params?: RequestParams) => Promise<Confirmed | MemPooled | TxNotFound>;
1396
1393
  };
1394
+ mempool: {
1395
+ /**
1396
+ * No description
1397
+ *
1398
+ * @tags Mempool
1399
+ * @name GetMempoolTransactions
1400
+ * @summary List mempool transactions
1401
+ * @request GET:/mempool/transactions
1402
+ */
1403
+ getMempoolTransactions: (params?: RequestParams) => Promise<MempoolTransactions[]>;
1404
+ /**
1405
+ * No description
1406
+ *
1407
+ * @tags Mempool
1408
+ * @name DeleteMempoolTransactions
1409
+ * @summary Remove all transactions from mempool
1410
+ * @request DELETE:/mempool/transactions
1411
+ */
1412
+ deleteMempoolTransactions: (params?: RequestParams) => Promise<void>;
1413
+ /**
1414
+ * No description
1415
+ *
1416
+ * @tags Mempool
1417
+ * @name PutMempoolTransactionsRebroadcast
1418
+ * @summary Rebroadcase a mempool transaction to the network
1419
+ * @request PUT:/mempool/transactions/rebroadcast
1420
+ */
1421
+ putMempoolTransactionsRebroadcast: (query: {
1422
+ txId: string;
1423
+ }, params?: RequestParams) => Promise<void>;
1424
+ /**
1425
+ * No description
1426
+ *
1427
+ * @tags Mempool
1428
+ * @name PutMempoolTransactionsValidate
1429
+ * @summary Validate all mempool transactions and remove invalid ones
1430
+ * @request PUT:/mempool/transactions/validate
1431
+ */
1432
+ putMempoolTransactionsValidate: (params?: RequestParams) => Promise<void>;
1433
+ };
1397
1434
  contracts: {
1398
1435
  /**
1399
1436
  * No description
@@ -149,7 +149,7 @@ class HttpClient {
149
149
  exports.HttpClient = HttpClient;
150
150
  /**
151
151
  * @title Alephium API
152
- * @version 1.7.0
152
+ * @version 1.7.1
153
153
  * @baseUrl ../
154
154
  */
155
155
  class Api extends HttpClient {
@@ -778,20 +778,6 @@ class Api extends HttpClient {
778
778
  }).then(utils_1.convertHttpResponse)
779
779
  };
780
780
  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
781
  /**
796
782
  * No description
797
783
  *
@@ -887,6 +873,62 @@ class Api extends HttpClient {
887
873
  ...params
888
874
  }).then(utils_1.convertHttpResponse)
889
875
  };
876
+ this.mempool = {
877
+ /**
878
+ * No description
879
+ *
880
+ * @tags Mempool
881
+ * @name GetMempoolTransactions
882
+ * @summary List mempool transactions
883
+ * @request GET:/mempool/transactions
884
+ */
885
+ getMempoolTransactions: (params = {}) => this.request({
886
+ path: `/mempool/transactions`,
887
+ method: 'GET',
888
+ format: 'json',
889
+ ...params
890
+ }).then(utils_1.convertHttpResponse),
891
+ /**
892
+ * No description
893
+ *
894
+ * @tags Mempool
895
+ * @name DeleteMempoolTransactions
896
+ * @summary Remove all transactions from mempool
897
+ * @request DELETE:/mempool/transactions
898
+ */
899
+ deleteMempoolTransactions: (params = {}) => this.request({
900
+ path: `/mempool/transactions`,
901
+ method: 'DELETE',
902
+ ...params
903
+ }).then(utils_1.convertHttpResponse),
904
+ /**
905
+ * No description
906
+ *
907
+ * @tags Mempool
908
+ * @name PutMempoolTransactionsRebroadcast
909
+ * @summary Rebroadcase a mempool transaction to the network
910
+ * @request PUT:/mempool/transactions/rebroadcast
911
+ */
912
+ putMempoolTransactionsRebroadcast: (query, params = {}) => this.request({
913
+ path: `/mempool/transactions/rebroadcast`,
914
+ method: 'PUT',
915
+ query: query,
916
+ ...params
917
+ }).then(utils_1.convertHttpResponse),
918
+ /**
919
+ * No description
920
+ *
921
+ * @tags Mempool
922
+ * @name PutMempoolTransactionsValidate
923
+ * @summary Validate all mempool transactions and remove invalid ones
924
+ * @request PUT:/mempool/transactions/validate
925
+ */
926
+ putMempoolTransactionsValidate: (params = {}) => this.request({
927
+ path: `/mempool/transactions/validate`,
928
+ method: 'PUT',
929
+ ...params
930
+ }).then(utils_1.convertHttpResponse)
931
+ };
890
932
  this.contracts = {
891
933
  /**
892
934
  * No description
@@ -11,6 +11,7 @@ export declare class NodeProvider {
11
11
  readonly blockflow: NodeApi<string>['blockflow'];
12
12
  readonly addresses: NodeApi<string>['addresses'];
13
13
  readonly transactions: NodeApi<string>['transactions'];
14
+ readonly mempool: NodeApi<string>['mempool'];
14
15
  readonly contracts: NodeApi<string>['contracts'];
15
16
  readonly multisig: NodeApi<string>['multisig'];
16
17
  readonly utils: NodeApi<string>['utils'];
@@ -90,6 +90,7 @@ class NodeProvider {
90
90
  this.blockflow = { ...nodeApi.blockflow };
91
91
  this.addresses = { ...nodeApi.addresses };
92
92
  this.transactions = { ...nodeApi.transactions };
93
+ this.mempool = { ...nodeApi.mempool };
93
94
  this.contracts = { ...nodeApi.contracts };
94
95
  this.multisig = { ...nodeApi.multisig };
95
96
  this.utils = { ...nodeApi.utils };
@@ -625,8 +625,10 @@ class Contract extends Artifact {
625
625
  }
626
626
  async txParamsForDeployment(signer, params) {
627
627
  const bytecode = this.buildByteCodeToDeploy(params.initialFields ?? {});
628
+ const selectedAccount = await signer.getSelectedAccount();
628
629
  const signerParams = {
629
- signerAddress: await signer.getSelectedAddress(),
630
+ signerAddress: selectedAccount.address,
631
+ signerKeyType: selectedAccount.keyType,
630
632
  bytecode: bytecode,
631
633
  initialAttoAlphAmount: params?.initialAttoAlphAmount,
632
634
  issueTokenAmount: params?.issueTokenAmount,
@@ -730,8 +732,10 @@ class Script extends Artifact {
730
732
  return JSON.stringify(object, null, 2);
731
733
  }
732
734
  async txParamsForExecution(signer, params) {
735
+ const selectedAccount = await signer.getSelectedAccount();
733
736
  const signerParams = {
734
- signerAddress: await signer.getSelectedAddress(),
737
+ signerAddress: selectedAccount.address,
738
+ signerKeyType: selectedAccount.keyType,
735
739
  bytecode: this.buildByteCodeToDeploy(params.initialFields ?? {}),
736
740
  attoAlphAmount: params.attoAlphAmount,
737
741
  tokens: params.tokens,
@@ -1,32 +1,32 @@
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, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams } from './types';
4
- import { TransactionBuilder } from './tx-builder';
5
- export interface SignerProvider {
6
- get nodeProvider(): NodeProvider | undefined;
7
- get explorerProvider(): ExplorerProvider | undefined;
8
- getSelectedAddress(): Promise<Address>;
9
- signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
10
- signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
11
- signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
12
- signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
13
- signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
14
- signMessage(params: SignMessageParams): Promise<SignMessageResult>;
3
+ import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, ExtSignTransferTxParams, ExtSignDeployContractTxParams, ExtSignExecuteScriptTxParams, ExtSignUnsignedTxParams, ExtSignMessageParams, KeyType } from './types';
4
+ export declare abstract class SignerProvider {
5
+ abstract get nodeProvider(): NodeProvider | undefined;
6
+ abstract get explorerProvider(): ExplorerProvider | undefined;
7
+ protected abstract unsafeGetSelectedAccount(): Promise<Account>;
8
+ getSelectedAccount(): Promise<Account>;
9
+ static validateAccount(account: Account): void;
10
+ abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
11
+ abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
12
+ abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
13
+ abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
14
+ abstract signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
15
+ abstract signMessage(params: SignMessageParams): Promise<SignMessageResult>;
15
16
  }
16
- export interface InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase> extends SignerProvider {
17
- enable(opt?: EnableOptions): Promise<Address>;
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>;
17
+ export declare abstract class InteractiveSignerProvider<EnableOptions extends EnableOptionsBase = EnableOptionsBase> extends SignerProvider {
18
+ protected abstract unsafeEnable(opt?: EnableOptions): Promise<Account>;
19
+ enable(opt?: EnableOptions): Promise<Account>;
20
+ abstract disconnect(): Promise<void>;
21
+ abstract signAndSubmitTransferTx(params: ExtSignTransferTxParams): Promise<SignTransferTxResult>;
22
+ abstract signAndSubmitDeployContractTx(params: ExtSignDeployContractTxParams): Promise<SignDeployContractTxResult>;
23
+ abstract signAndSubmitExecuteScriptTx(params: ExtSignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
24
+ abstract signAndSubmitUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
25
+ abstract signUnsignedTx(params: ExtSignUnsignedTxParams): Promise<SignUnsignedTxResult>;
26
+ abstract signMessage(params: ExtSignMessageParams): Promise<SignMessageResult>;
25
27
  }
26
- export declare abstract class SignerProviderSimple extends TransactionBuilder implements SignerProvider {
27
- abstract get explorerProvider(): ExplorerProvider | undefined;
28
- abstract getSelectedAccount(): Promise<Account>;
29
- getSelectedAddress(): Promise<Address>;
28
+ export declare abstract class SignerProviderSimple extends SignerProvider {
29
+ abstract get nodeProvider(): NodeProvider;
30
30
  submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
31
31
  signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
32
32
  signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
@@ -45,7 +45,7 @@ export declare abstract class SignerProviderSimple extends TransactionBuilder im
45
45
  abstract signRaw(signerAddress: string, hexString: string): Promise<string>;
46
46
  }
47
47
  export declare abstract class SignerProviderWithMultipleAccounts extends SignerProviderSimple {
48
- abstract setSelectedAddress(address: string): Promise<void>;
48
+ abstract setSelectedAccount(address: string): Promise<void>;
49
49
  abstract getAccounts(): Promise<Account[]>;
50
50
  getAccount(signerAddress: string): Promise<Account>;
51
51
  getPublicKey(signerAddress: string): Promise<string>;
@@ -53,13 +53,12 @@ export declare abstract class SignerProviderWithMultipleAccounts extends SignerP
53
53
  export declare abstract class SignerProviderWithCachedAccounts<T extends Account> extends SignerProviderWithMultipleAccounts {
54
54
  private _selectedAccount;
55
55
  protected readonly _accounts: Map<string, T>;
56
- getSelectedAccount(): Promise<T>;
57
- setSelectedAddress(address: string): Promise<void>;
56
+ protected unsafeGetSelectedAccount(): Promise<T>;
57
+ setSelectedAccount(address: string): Promise<void>;
58
58
  getAccounts(): Promise<T[]>;
59
59
  getAccount(address: string): Promise<T>;
60
60
  }
61
- export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
62
- export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
61
+ export declare function verifySignedMessage(message: string, publicKey: string, signature: string, keyType?: KeyType): boolean;
63
62
  export declare function toApiDestination(data: Destination): node.Destination;
64
63
  export declare function toApiDestinations(data: Destination[]): node.Destination[];
65
64
  export declare function fromApiDestination(data: node.Destination): Destination;
@@ -43,18 +43,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
43
43
  return (mod && mod.__esModule) ? mod : { "default": mod };
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = void 0;
47
- const elliptic_1 = require("elliptic");
46
+ exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
48
47
  const api_1 = require("../api");
49
48
  const utils = __importStar(require("../utils"));
50
49
  const blakejs_1 = __importDefault(require("blakejs"));
51
50
  const tx_builder_1 = require("./tx-builder");
52
- const ec = new elliptic_1.ec('secp256k1');
53
- class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
54
- async getSelectedAddress() {
55
- const account = await this.getSelectedAccount();
56
- return account.address;
51
+ const utils_1 = require("../utils");
52
+ class SignerProvider {
53
+ async getSelectedAccount() {
54
+ const account = await this.unsafeGetSelectedAccount();
55
+ SignerProvider.validateAccount(account);
56
+ return account;
57
+ }
58
+ static validateAccount(account) {
59
+ const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
60
+ const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
61
+ if (derivedAddress !== account.address || derivedGroup !== account.group) {
62
+ throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
63
+ }
64
+ }
65
+ }
66
+ exports.SignerProvider = SignerProvider;
67
+ // Abstraction for interactive signer (e.g. WalletConnect instance, Extension wallet object)
68
+ class InteractiveSignerProvider extends SignerProvider {
69
+ async enable(opt) {
70
+ const account = await this.unsafeEnable(opt);
71
+ SignerProvider.validateAccount(account);
72
+ return account;
57
73
  }
74
+ }
75
+ exports.InteractiveSignerProvider = InteractiveSignerProvider;
76
+ class SignerProviderSimple extends SignerProvider {
58
77
  async submitTransaction(params) {
59
78
  const data = { unsignedTx: params.unsignedTx, signature: params.signature };
60
79
  return this.nodeProvider.transactions.postTransactionsSubmit(data);
@@ -90,7 +109,7 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
90
109
  return { signature, ...response };
91
110
  }
92
111
  async buildTransferTx(params) {
93
- return super.buildTransferTx(params, await this.getPublicKey(params.signerAddress));
112
+ return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildTransferTx(params, await this.getPublicKey(params.signerAddress));
94
113
  }
95
114
  async signDeployContractTx(params) {
96
115
  const response = await this.buildDeployContractTx(params);
@@ -98,7 +117,7 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
98
117
  return { signature, ...response };
99
118
  }
100
119
  async buildDeployContractTx(params) {
101
- return super.buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
120
+ return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
102
121
  }
103
122
  async signExecuteScriptTx(params) {
104
123
  const response = await this.buildExecuteScriptTx(params);
@@ -106,12 +125,12 @@ class SignerProviderSimple extends tx_builder_1.TransactionBuilder {
106
125
  return { signature, ...response };
107
126
  }
108
127
  async buildExecuteScriptTx(params) {
109
- return super.buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
128
+ return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
110
129
  }
111
130
  // in general, wallet should show the decoded information to user for confirmation
112
131
  // please overwrite this function for real wallet
113
132
  async signUnsignedTx(params) {
114
- const response = await this.buildUnsignedTx(params);
133
+ const response = await tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildUnsignedTx(params);
115
134
  const signature = await this.signRaw(params.signerAddress, response.txId);
116
135
  return { signature, ...response };
117
136
  }
@@ -146,7 +165,7 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
146
165
  this._selectedAccount = undefined;
147
166
  this._accounts = new Map();
148
167
  }
149
- getSelectedAccount() {
168
+ unsafeGetSelectedAccount() {
150
169
  if (this._selectedAccount === undefined) {
151
170
  throw Error('No account is selected yet');
152
171
  }
@@ -154,7 +173,7 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
154
173
  return Promise.resolve(this._selectedAccount);
155
174
  }
156
175
  }
157
- setSelectedAddress(address) {
176
+ setSelectedAccount(address) {
158
177
  const accountOpt = this._accounts.get(address);
159
178
  if (accountOpt === undefined) {
160
179
  throw Error('The address is not in the accounts');
@@ -176,23 +195,13 @@ class SignerProviderWithCachedAccounts extends SignerProviderWithMultipleAccount
176
195
  }
177
196
  }
178
197
  exports.SignerProviderWithCachedAccounts = SignerProviderWithCachedAccounts;
179
- function verifyHexString(hexString, publicKey, signature) {
180
- try {
181
- const key = ec.keyFromPublic(publicKey, 'hex');
182
- return key.verify(hexString, utils.signatureDecode(ec, signature));
183
- }
184
- catch (error) {
185
- return false;
186
- }
187
- }
188
- exports.verifyHexString = verifyHexString;
189
198
  function extendMessage(message) {
190
199
  return 'Alephium Signed Message: ' + message;
191
200
  }
192
- function verifySignedMessage(message, publicKey, signature) {
201
+ function verifySignedMessage(message, publicKey, signature, keyType) {
193
202
  const extendedMessage = extendMessage(message);
194
203
  const messageHash = blakejs_1.default.blake2b(extendedMessage, undefined, 32);
195
- return verifyHexString(utils.binToHex(messageHash), publicKey, signature);
204
+ return utils.verifySignature(utils.binToHex(messageHash), publicKey, signature, keyType);
196
205
  }
197
206
  exports.verifySignedMessage = verifySignedMessage;
198
207
  function toApiDestination(data) {
@@ -2,13 +2,8 @@ import { NodeProvider } from '../api';
2
2
  import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult } from './types';
3
3
  export declare abstract class TransactionBuilder {
4
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
- };
5
+ static from(nodeProvider: NodeProvider): TransactionBuilder;
6
+ static from(baseUrl: string, apiKey?: string): TransactionBuilder;
12
7
  private static validatePublicKey;
13
8
  buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, 'signature'>>;
14
9
  buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
@@ -23,25 +23,26 @@ const api_1 = require("../api");
23
23
  const utils_1 = require("../utils");
24
24
  const signer_1 = require("./signer");
25
25
  class TransactionBuilder {
26
- static create(baseUrl, apiKey) {
27
- const nodeProvider = new api_1.NodeProvider(baseUrl, apiKey);
26
+ static from(param0, param1) {
27
+ const nodeProvider = typeof param0 === 'string' ? new api_1.NodeProvider(param0, param1) : param0;
28
28
  return new (class extends TransactionBuilder {
29
29
  get nodeProvider() {
30
30
  return nodeProvider;
31
31
  }
32
32
  })();
33
33
  }
34
- static validatePublicKey(params, publicKey) {
35
- const address = (0, utils_1.addressFromPublicKey)(publicKey);
34
+ static validatePublicKey(params, publicKey, keyType) {
35
+ const address = (0, utils_1.addressFromPublicKey)(publicKey, keyType);
36
36
  if (address !== params.signerAddress) {
37
37
  throw new Error('Unmatched public key');
38
38
  }
39
39
  }
40
40
  async buildTransferTx(params, publicKey) {
41
- TransactionBuilder.validatePublicKey(params, publicKey);
41
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
42
42
  const { destinations, gasPrice, ...rest } = params;
43
43
  const data = {
44
44
  fromPublicKey: publicKey,
45
+ fromPublicKeyType: params.signerKeyType,
45
46
  destinations: (0, signer_1.toApiDestinations)(destinations),
46
47
  gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
47
48
  ...rest
@@ -50,10 +51,11 @@ class TransactionBuilder {
50
51
  return { ...response, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
51
52
  }
52
53
  async buildDeployContractTx(params, publicKey) {
53
- TransactionBuilder.validatePublicKey(params, publicKey);
54
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
54
55
  const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params;
55
56
  const data = {
56
57
  fromPublicKey: publicKey,
58
+ fromPublicKeyType: params.signerKeyType,
57
59
  initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(initialAttoAlphAmount),
58
60
  initialTokenAmounts: (0, api_1.toApiTokens)(initialTokenAmounts),
59
61
  issueTokenAmount: (0, api_1.toApiNumber256Optional)(issueTokenAmount),
@@ -65,10 +67,11 @@ class TransactionBuilder {
65
67
  return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: (0, api_1.fromApiNumber256)(response.gasPrice) };
66
68
  }
67
69
  async buildExecuteScriptTx(params, publicKey) {
68
- TransactionBuilder.validatePublicKey(params, publicKey);
70
+ TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
69
71
  const { attoAlphAmount, tokens, gasPrice, ...rest } = params;
70
72
  const data = {
71
73
  fromPublicKey: publicKey,
74
+ fromPublicKeyType: params.signerKeyType,
72
75
  attoAlphAmount: (0, api_1.toApiNumber256Optional)(attoAlphAmount),
73
76
  tokens: (0, api_1.toApiTokens)(tokens),
74
77
  gasPrice: (0, api_1.toApiNumber256Optional)(gasPrice),
@@ -9,16 +9,20 @@ export interface Destination {
9
9
  lockTime?: number;
10
10
  message?: string;
11
11
  }
12
+ export declare type KeyType = 'default' | 'bip340-schnorr';
12
13
  export interface Account {
14
+ keyType: KeyType;
13
15
  address: string;
14
16
  group: number;
15
17
  publicKey: string;
16
18
  }
17
19
  export declare type SignerAddress = {
18
20
  signerAddress: string;
21
+ signerKeyType?: KeyType;
19
22
  };
20
23
  export interface SignTransferTxParams {
21
24
  signerAddress: string;
25
+ signerKeyType?: KeyType;
22
26
  destinations: Destination[];
23
27
  utxos?: OutputRef[];
24
28
  gasAmount?: number;
@@ -35,6 +39,7 @@ export interface SignTransferTxResult {
35
39
  }
36
40
  export interface SignDeployContractTxParams {
37
41
  signerAddress: string;
42
+ signerKeyType?: KeyType;
38
43
  bytecode: string;
39
44
  initialAttoAlphAmount?: Number256;
40
45
  initialTokenAmounts?: Token[];
@@ -54,6 +59,7 @@ export interface SignDeployContractTxResult {
54
59
  }
55
60
  export interface SignExecuteScriptTxParams {
56
61
  signerAddress: string;
62
+ signerKeyType?: KeyType;
57
63
  bytecode: string;
58
64
  attoAlphAmount?: Number256;
59
65
  tokens?: Token[];
@@ -70,6 +76,7 @@ export interface SignExecuteScriptTxResult {
70
76
  }
71
77
  export interface SignUnsignedTxParams {
72
78
  signerAddress: string;
79
+ signerKeyType?: KeyType;
73
80
  unsignedTx: string;
74
81
  }
75
82
  export interface SignUnsignedTxResult {
@@ -83,6 +90,7 @@ export interface SignUnsignedTxResult {
83
90
  }
84
91
  export interface SignMessageParams {
85
92
  signerAddress: string;
93
+ signerKeyType?: KeyType;
86
94
  message: string;
87
95
  }
88
96
  export interface SignMessageResult {
@@ -1,2 +1,3 @@
1
- export declare function transactionSign(txHash: string, privateKey: string): string;
2
- export declare function transactionVerifySignature(txHash: string, publicKey: string, signature: string): boolean;
1
+ import { KeyType } from '../signer';
2
+ export declare function transactionSign(txId: string, privateKey: string, keyType?: KeyType): string;
3
+ export declare function transactionVerifySignature(txId: string, publicKey: string, signature: string, keyType?: KeyType): boolean;
@@ -42,21 +42,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.transactionVerifySignature = exports.transactionSign = void 0;
44
44
  const utils = __importStar(require("../utils"));
45
- const elliptic_1 = require("elliptic");
46
- const ec = new elliptic_1.ec('secp256k1');
47
- function transactionSign(txHash, privateKey) {
48
- const keyPair = ec.keyFromPrivate(privateKey);
49
- const signature = keyPair.sign(txHash);
50
- return utils.encodeSignature(signature);
45
+ function transactionSign(txId, privateKey, keyType) {
46
+ return utils.sign(txId, privateKey, keyType);
51
47
  }
52
48
  exports.transactionSign = transactionSign;
53
- function transactionVerifySignature(txHash, publicKey, signature) {
54
- try {
55
- const key = ec.keyFromPublic(publicKey, 'hex');
56
- return key.verify(txHash, utils.signatureDecode(ec, signature));
57
- }
58
- catch (error) {
59
- return false;
60
- }
49
+ function transactionVerifySignature(txId, publicKey, signature, keyType) {
50
+ return utils.verifySignature(txId, publicKey, signature, keyType);
61
51
  }
62
52
  exports.transactionVerifySignature = transactionVerifySignature;
@@ -3,3 +3,4 @@ export * from './bs58';
3
3
  export * from './djb2';
4
4
  export * from './utils';
5
5
  export * from './subscription';
6
+ export * from './sign';
@@ -36,3 +36,4 @@ __exportStar(require("./bs58"), exports);
36
36
  __exportStar(require("./djb2"), exports);
37
37
  __exportStar(require("./utils"), exports);
38
38
  __exportStar(require("./subscription"), exports);
39
+ __exportStar(require("./sign"), exports);
@@ -0,0 +1,3 @@
1
+ import { KeyType } from '../signer';
2
+ export declare function sign(hash: string, privateKey: string, _keyType?: KeyType): string;
3
+ export declare function verifySignature(hash: string, publicKey: string, signature: string, _keyType?: KeyType): boolean;