@alephium/web3 1.12.0-beta.0 → 1.12.0-danube.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -309,16 +309,17 @@ class Contract extends Artifact {
309
309
  blockHash: params.blockHash,
310
310
  blockTimeStamp: params.blockTimeStamp,
311
311
  txId: params.txId,
312
- address: params.address,
312
+ address: params.contractAddress,
313
313
  callerContractAddress: params.callerContractAddress,
314
314
  bytecode: this.isInlineFunc(methodIndex) ? this.getByteCodeForTesting() : this.bytecodeDebug,
315
315
  initialImmFields: immFields,
316
316
  initialMutFields: mutFields,
317
317
  initialAsset: typeof params.initialAsset !== 'undefined' ? toApiAsset(params.initialAsset) : undefined,
318
318
  methodIndex,
319
- args: this.toApiArgs(funcName, params.testArgs),
319
+ args: this.toApiArgs(funcName, params.args),
320
320
  existingContracts: this.toApiContractStates(params.existingContracts),
321
- inputAssets: toApiInputAssets(params.inputAssets)
321
+ inputAssets: toApiInputAssets(params.inputAssets),
322
+ dustAmount: params.dustAmount?.toString()
322
323
  };
323
324
  }
324
325
  fromApiContractState(state) {
@@ -387,15 +388,13 @@ class Contract extends Artifact {
387
388
  const initialFields = params.initialFields ?? {};
388
389
  const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet, params.exposePrivateFunctions ?? false);
389
390
  const selectedAccount = await signer.getSelectedAccount();
390
- let signerAddress = selectedAccount.address;
391
- if ((0, address_1.isGrouplessAddressWithoutGroupIndex)(selectedAccount.address)) {
391
+ if (selectedAccount.keyType === 'gl-secp256k1') {
392
392
  if (group === undefined) {
393
393
  throw new Error('Groupless address requires explicit group number for contract deployment');
394
394
  }
395
- signerAddress = `${selectedAccount.address}:${group}`;
396
395
  }
397
396
  const signerParams = {
398
- signerAddress,
397
+ signerAddress: selectedAccount.address,
399
398
  signerKeyType: selectedAccount.keyType,
400
399
  bytecode: bytecode,
401
400
  initialAttoAlphAmount: params?.initialAttoAlphAmount,
@@ -403,7 +402,8 @@ class Contract extends Artifact {
403
402
  issueTokenTo: params?.issueTokenTo,
404
403
  initialTokenAmounts: params?.initialTokenAmounts,
405
404
  gasAmount: params?.gasAmount,
406
- gasPrice: params?.gasPrice
405
+ gasPrice: params?.gasPrice,
406
+ group: group
407
407
  };
408
408
  return signerParams;
409
409
  }
@@ -519,8 +519,8 @@ class Script extends Artifact {
519
519
  };
520
520
  return JSON.stringify(object, null, 2);
521
521
  }
522
- async txParamsForExecution(signer, params) {
523
- const selectedAccount = await signer.getSelectedAccount();
522
+ async txParamsForExecution(params) {
523
+ const selectedAccount = await params.signer.getSelectedAccount();
524
524
  const signerParams = {
525
525
  signerAddress: selectedAccount.address,
526
526
  signerKeyType: selectedAccount.keyType,
@@ -691,10 +691,18 @@ class ContractFactory {
691
691
  initialFields: addStdIdToFields(this.contract, deployParams.initialFields)
692
692
  }, group);
693
693
  const result = await signer.signAndSubmitDeployContractTx(signerParams);
694
- return {
695
- ...result,
696
- contractInstance: this.at(result.contractAddress)
697
- };
694
+ if ('transferTxs' in result) {
695
+ return {
696
+ ...result.tx,
697
+ contractInstance: this.at(result.tx.contractAddress)
698
+ };
699
+ }
700
+ else {
701
+ return {
702
+ ...result,
703
+ contractInstance: this.at(result.contractAddress)
704
+ };
705
+ }
698
706
  }
699
707
  async deployTemplate(signer) {
700
708
  return this.deploy(signer, {
@@ -722,9 +730,15 @@ class ExecutableScript {
722
730
  this.script = script;
723
731
  this.getContractByCodeHash = getContractByCodeHash;
724
732
  }
725
- async execute(signer, params) {
726
- const signerParams = await this.script.txParamsForExecution(signer, params);
727
- return await signer.signAndSubmitExecuteScriptTx(signerParams);
733
+ async execute(params) {
734
+ const signerParams = await this.script.txParamsForExecution(params);
735
+ const result = await params.signer.signAndSubmitExecuteScriptTx(signerParams);
736
+ if ('transferTxs' in result) {
737
+ return result.tx;
738
+ }
739
+ else {
740
+ return result;
741
+ }
728
742
  }
729
743
  async call(params) {
730
744
  const mainFunc = this.script.functions.find((f) => f.name === 'main');
@@ -971,16 +985,16 @@ exports.extractMapsFromApiResult = extractMapsFromApiResult;
971
985
  async function testMethod(factory, methodName, params, getContractByCodeHash) {
972
986
  const txId = params?.txId ?? randomTxId();
973
987
  const selfContract = factory.contract;
974
- const selfAddress = params.address ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
988
+ const selfAddress = params.contractAddress ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
975
989
  const selfContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(selfAddress));
976
990
  const group = params.group ?? 0;
977
991
  const existingContracts = getTestExistingContracts(selfContract, selfContractId, group, params, getContractByCodeHash);
978
992
  const apiParams = selfContract.toApiTestContractParams(methodName, {
979
993
  ...params,
980
- address: selfAddress,
994
+ contractAddress: selfAddress,
981
995
  txId: txId,
982
996
  initialFields: addStdIdToFields(selfContract, params.initialFields ?? {}),
983
- testArgs: params.testArgs === undefined ? {} : params.testArgs,
997
+ args: params.args === undefined ? {} : params.args,
984
998
  existingContracts
985
999
  });
986
1000
  const apiResult = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsTestContract(apiParams);
@@ -1258,7 +1272,7 @@ async function signExecuteMethod(contract, instance, methodName, params) {
1258
1272
  gasAmount: params.gasAmount,
1259
1273
  gasPrice: params.gasPrice
1260
1274
  };
1261
- const result = await signer.signAndSubmitExecuteScriptTx(signerParams);
1275
+ const result = (await signer.signAndSubmitExecuteScriptTx(signerParams));
1262
1276
  if ((0, debug_1.isContractDebugMessageEnabled)() && isDevnet) {
1263
1277
  await printDebugMessagesFromTx(result.txId, signer.nodeProvider);
1264
1278
  }
@@ -1,3 +1,4 @@
1
+ import { SimulationResult } from '../api/api-alephium';
1
2
  import { ContractInstance } from './contract';
2
3
  export interface ExecutionResult {
3
4
  txId: string;
@@ -16,4 +17,5 @@ export interface DeployContractExecutionResult<I extends ContractInstance = Cont
16
17
  }
17
18
  export interface RunScriptResult extends ExecutionResult {
18
19
  groupIndex: number;
20
+ simulationResult: SimulationResult;
19
21
  }
@@ -1,15 +1,15 @@
1
1
  import { ExplorerProvider, NodeProvider } from '../api';
2
2
  import { node } from '../api';
3
- import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType, MessageHasher, SignChainedTxParams, SignChainedTxResult } from './types';
3
+ import { Account, EnableOptionsBase, Destination, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignMessageParams, SignMessageResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SubmissionResult, SubmitTransactionParams, KeyType, MessageHasher, SignChainedTxParams, SignChainedTxResult, BuildTxResult, SignTxResult } from './types';
4
4
  export declare abstract class SignerProvider {
5
5
  abstract get nodeProvider(): NodeProvider | undefined;
6
6
  abstract get explorerProvider(): ExplorerProvider | undefined;
7
7
  protected abstract unsafeGetSelectedAccount(): Promise<Account>;
8
8
  getSelectedAccount(): Promise<Account>;
9
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>;
10
+ abstract signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
11
+ abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
12
+ abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
13
13
  abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
14
14
  abstract signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
15
15
  abstract signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
@@ -23,18 +23,18 @@ export declare abstract class InteractiveSignerProvider<EnableOptions extends En
23
23
  export declare abstract class SignerProviderSimple extends SignerProvider {
24
24
  abstract get nodeProvider(): NodeProvider;
25
25
  submitTransaction(params: SubmitTransactionParams): Promise<SubmissionResult>;
26
- signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
27
- signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
28
- signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
26
+ signAndSubmitTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
27
+ signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
28
+ signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
29
29
  signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
30
30
  signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
31
31
  protected abstract getPublicKey(address: string): Promise<string>;
32
- signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
33
- buildTransferTx(params: SignTransferTxParams): Promise<Omit<SignTransferTxResult, 'signature'>>;
34
- signDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>;
35
- buildDeployContractTx(params: SignDeployContractTxParams): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
36
- signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>;
37
- buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
32
+ signTransferTx(params: SignTransferTxParams): Promise<SignTxResult<SignTransferTxResult>>;
33
+ buildTransferTx(params: SignTransferTxParams): Promise<BuildTxResult<SignTransferTxResult>>;
34
+ signDeployContractTx(params: SignDeployContractTxParams): Promise<SignTxResult<SignDeployContractTxResult>>;
35
+ buildDeployContractTx(params: SignDeployContractTxParams): Promise<BuildTxResult<SignDeployContractTxResult>>;
36
+ signExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignTxResult<SignExecuteScriptTxResult>>;
37
+ buildExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<BuildTxResult<SignExecuteScriptTxResult>>;
38
38
  signChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>;
39
39
  buildChainedTx(params: SignChainedTxParams[]): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
40
40
  signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>;
@@ -81,17 +81,41 @@ class SignerProviderSimple extends SignerProvider {
81
81
  }
82
82
  async signAndSubmitTransferTx(params) {
83
83
  const signResult = await this.signTransferTx(params);
84
- await this.submitTransaction(signResult);
84
+ if ('transferTxs' in signResult) {
85
+ for (const r of signResult.transferTxs) {
86
+ await this.submitTransaction(r);
87
+ }
88
+ await this.submitTransaction(signResult.tx);
89
+ }
90
+ else {
91
+ await this.submitTransaction(signResult);
92
+ }
85
93
  return signResult;
86
94
  }
87
95
  async signAndSubmitDeployContractTx(params) {
88
96
  const signResult = await this.signDeployContractTx(params);
89
- await this.submitTransaction(signResult);
97
+ if ('transferTxs' in signResult) {
98
+ for (const r of signResult.transferTxs) {
99
+ await this.submitTransaction(r);
100
+ }
101
+ await this.submitTransaction(signResult.tx);
102
+ }
103
+ else {
104
+ await this.submitTransaction(signResult);
105
+ }
90
106
  return signResult;
91
107
  }
92
108
  async signAndSubmitExecuteScriptTx(params) {
93
109
  const signResult = await this.signExecuteScriptTx(params);
94
- await this.submitTransaction(signResult);
110
+ if ('transferTxs' in signResult) {
111
+ for (const r of signResult.transferTxs) {
112
+ await this.submitTransaction(r);
113
+ }
114
+ await this.submitTransaction(signResult.tx);
115
+ }
116
+ else {
117
+ await this.submitTransaction(signResult);
118
+ }
95
119
  return signResult;
96
120
  }
97
121
  async signAndSubmitUnsignedTx(params) {
@@ -108,24 +132,75 @@ class SignerProviderSimple extends SignerProvider {
108
132
  }
109
133
  async signTransferTx(params) {
110
134
  const response = await this.buildTransferTx(params);
111
- const signature = await this.signRaw(params.signerAddress, response.txId);
112
- return { signature, ...response };
135
+ if ('transferTxs' in response) {
136
+ const transferTxs = [];
137
+ for (let i = 0; i < response.transferTxs.length; i++) {
138
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
139
+ transferTxs.push({
140
+ ...response.transferTxs[i],
141
+ signature: txSignature
142
+ });
143
+ }
144
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId);
145
+ return {
146
+ transferTxs,
147
+ tx: { ...response.tx, signature }
148
+ };
149
+ }
150
+ else {
151
+ const signature = await this.signRaw(params.signerAddress, response.txId);
152
+ return { signature, ...response };
153
+ }
113
154
  }
114
155
  async buildTransferTx(params) {
115
156
  return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildTransferTx(params, await this.getPublicKey(params.signerAddress));
116
157
  }
117
158
  async signDeployContractTx(params) {
118
159
  const response = await this.buildDeployContractTx(params);
119
- const signature = await this.signRaw(params.signerAddress, response.txId);
120
- return { signature, ...response };
160
+ if ('transferTxs' in response) {
161
+ const transferTxs = [];
162
+ for (let i = 0; i < response.transferTxs.length; i++) {
163
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
164
+ transferTxs.push({
165
+ ...response.transferTxs[i],
166
+ signature: txSignature
167
+ });
168
+ }
169
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId);
170
+ return {
171
+ transferTxs,
172
+ tx: { ...response.tx, signature }
173
+ };
174
+ }
175
+ else {
176
+ const signature = await this.signRaw(params.signerAddress, response.txId);
177
+ return { signature, ...response };
178
+ }
121
179
  }
122
180
  async buildDeployContractTx(params) {
123
181
  return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildDeployContractTx(params, await this.getPublicKey(params.signerAddress));
124
182
  }
125
183
  async signExecuteScriptTx(params) {
126
184
  const response = await this.buildExecuteScriptTx(params);
127
- const signature = await this.signRaw(params.signerAddress, response.txId);
128
- return { signature, ...response };
185
+ if ('transferTxs' in response) {
186
+ const transferTxs = [];
187
+ for (let i = 0; i < response.transferTxs.length; i++) {
188
+ const txSignature = await this.signRaw(params.signerAddress, response.transferTxs[i].txId);
189
+ transferTxs.push({
190
+ ...response.transferTxs[i],
191
+ signature: txSignature
192
+ });
193
+ }
194
+ const signature = await this.signRaw(params.signerAddress, response.tx.txId);
195
+ return {
196
+ transferTxs,
197
+ tx: { ...response.tx, signature }
198
+ };
199
+ }
200
+ else {
201
+ const signature = await this.signRaw(params.signerAddress, response.txId);
202
+ return { signature, ...response };
203
+ }
129
204
  }
130
205
  async buildExecuteScriptTx(params) {
131
206
  return tx_builder_1.TransactionBuilder.from(this.nodeProvider).buildExecuteScriptTx(params, await this.getPublicKey(params.signerAddress));
@@ -1,22 +1,16 @@
1
1
  import { NodeProvider } from '../api';
2
- import { SignChainedTxParams, SignChainedTxResult, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, SignGrouplessTransferTxParams, SignGrouplessDeployContractTxParams, SignGrouplessExecuteScriptTxParams } from './types';
2
+ import { SignChainedTxParams, SignChainedTxResult, SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignExecuteScriptTxResult, SignTransferTxParams, SignTransferTxResult, SignUnsignedTxParams, SignUnsignedTxResult, BuildTxResult } from './types';
3
3
  export declare abstract class TransactionBuilder {
4
4
  abstract get nodeProvider(): NodeProvider;
5
5
  static from(nodeProvider: NodeProvider): TransactionBuilder;
6
6
  static from(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): TransactionBuilder;
7
7
  private static validatePublicKey;
8
- buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<Omit<SignTransferTxResult, 'signature'>>;
9
- buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<Omit<SignDeployContractTxResult, 'signature'>>;
10
- buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<Omit<SignExecuteScriptTxResult, 'signature'>>;
8
+ buildTransferTx(params: SignTransferTxParams, publicKey: string): Promise<BuildTxResult<SignTransferTxResult>>;
9
+ buildDeployContractTx(params: SignDeployContractTxParams, publicKey: string): Promise<BuildTxResult<SignDeployContractTxResult>>;
10
+ buildExecuteScriptTx(params: SignExecuteScriptTxParams, publicKey: string): Promise<BuildTxResult<SignExecuteScriptTxResult>>;
11
11
  buildChainedTx(params: SignChainedTxParams[], publicKeys: string[]): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
12
- buildGrouplessTransferTx(params: SignGrouplessTransferTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
13
- buildGrouplessDeployContractTx(params: SignGrouplessDeployContractTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
14
- buildGrouplessExecuteScriptTx(params: SignGrouplessExecuteScriptTxParams): Promise<Omit<SignChainedTxResult, 'signature'>[]>;
15
12
  static buildUnsignedTx(params: SignUnsignedTxParams): Omit<SignUnsignedTxResult, 'signature'>;
16
13
  private buildTransferTxParams;
17
- private buildGrouplessTransferTxParams;
18
- private buildGrouplessDeployContractTxParams;
19
- private buildGrouplessExecuteScriptTxParams;
20
14
  private buildDeployContractTxParams;
21
15
  private buildExecuteScriptTxParams;
22
16
  private convertTransferTxResult;
@@ -109,42 +109,6 @@ class TransactionBuilder {
109
109
  });
110
110
  return results;
111
111
  }
112
- async buildGrouplessTransferTx(params) {
113
- const data = this.buildGrouplessTransferTxParams(params);
114
- const response = await this.nodeProvider.groupless.postGrouplessTransfer(data);
115
- return response.map((result) => {
116
- return {
117
- ...this.convertTransferTxResult(result),
118
- type: 'Transfer'
119
- };
120
- });
121
- }
122
- async buildGrouplessDeployContractTx(params) {
123
- const data = this.buildGrouplessDeployContractTxParams(params);
124
- const response = await this.nodeProvider.groupless.postGrouplessDeployContract(data);
125
- const transferTxs = response.transferTxs.map((result) => ({
126
- ...this.convertTransferTxResult(result),
127
- type: 'Transfer'
128
- }));
129
- const deployContractTx = {
130
- ...this.convertDeployContractTxResult(response.deployContractTx),
131
- type: 'DeployContract'
132
- };
133
- return [...transferTxs, deployContractTx];
134
- }
135
- async buildGrouplessExecuteScriptTx(params) {
136
- const data = this.buildGrouplessExecuteScriptTxParams(params);
137
- const response = await this.nodeProvider.groupless.postGrouplessExecuteScript(data);
138
- const transferTxs = response.transferTxs.map((result) => ({
139
- ...this.convertTransferTxResult(result),
140
- type: 'Transfer'
141
- }));
142
- const executeScriptTx = {
143
- ...this.convertExecuteScriptTxResult(response.executeScriptTx),
144
- type: 'ExecuteScript'
145
- };
146
- return [...transferTxs, executeScriptTx];
147
- }
148
112
  static buildUnsignedTx(params) {
149
113
  const unsignedTxBin = (0, utils_1.hexToBinUnsafe)(params.unsignedTx);
150
114
  const decoded = codec_1.unsignedTxCodec.decode(unsignedTxBin);
@@ -170,37 +134,6 @@ class TransactionBuilder {
170
134
  ...rest
171
135
  };
172
136
  }
173
- buildGrouplessTransferTxParams(params) {
174
- return {
175
- fromAddress: params.fromAddress,
176
- destinations: (0, signer_1.toApiDestinations)(params.destinations),
177
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice),
178
- targetBlockHash: params.targetBlockHash
179
- };
180
- }
181
- buildGrouplessDeployContractTxParams(params) {
182
- return {
183
- fromAddress: params.fromAddress,
184
- bytecode: params.bytecode,
185
- initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(params.initialAttoAlphAmount),
186
- initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
187
- issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
188
- issueTokenTo: params.issueTokenTo,
189
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice),
190
- targetBlockHash: params.targetBlockHash
191
- };
192
- }
193
- buildGrouplessExecuteScriptTxParams(params) {
194
- return {
195
- fromAddress: params.fromAddress,
196
- bytecode: params.bytecode,
197
- attoAlphAmount: (0, api_1.toApiNumber256Optional)(params.attoAlphAmount),
198
- tokens: (0, api_1.toApiTokens)(params.tokens),
199
- gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice),
200
- targetBlockHash: params.targetBlockHash,
201
- gasEstimationMultiplier: params.gasEstimationMultiplier
202
- };
203
- }
204
137
  buildDeployContractTxParams(params, publicKey) {
205
138
  TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType);
206
139
  const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params;
@@ -227,12 +160,40 @@ class TransactionBuilder {
227
160
  };
228
161
  }
229
162
  convertTransferTxResult(result) {
163
+ // BuildGrouplessTransferTxResult
164
+ if ('transferTxs' in result) {
165
+ return {
166
+ transferTxs: result.transferTxs.map((r) => ({
167
+ ...r,
168
+ gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
169
+ })),
170
+ tx: {
171
+ ...result.transferTx,
172
+ gasPrice: (0, api_1.fromApiNumber256)(result.transferTx.gasPrice)
173
+ }
174
+ };
175
+ }
230
176
  return {
231
177
  ...result,
232
178
  gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
233
179
  };
234
180
  }
235
181
  convertDeployContractTxResult(result) {
182
+ if ('transferTxs' in result) {
183
+ const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.deployContractTx.contractAddress));
184
+ return {
185
+ transferTxs: result.transferTxs.map((r) => ({
186
+ ...r,
187
+ gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
188
+ })),
189
+ tx: {
190
+ ...result.deployContractTx,
191
+ groupIndex: result.deployContractTx.fromGroup,
192
+ contractId,
193
+ gasPrice: (0, api_1.fromApiNumber256)(result.deployContractTx.gasPrice)
194
+ }
195
+ };
196
+ }
236
197
  const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.contractAddress));
237
198
  return {
238
199
  ...result,
@@ -242,6 +203,19 @@ class TransactionBuilder {
242
203
  };
243
204
  }
244
205
  convertExecuteScriptTxResult(result) {
206
+ if ('transferTxs' in result) {
207
+ return {
208
+ transferTxs: result.transferTxs.map((r) => ({
209
+ ...r,
210
+ gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
211
+ })),
212
+ tx: {
213
+ ...result.executeScriptTx,
214
+ groupIndex: result.executeScriptTx.fromGroup,
215
+ gasPrice: (0, api_1.fromApiNumber256)(result.executeScriptTx.gasPrice)
216
+ }
217
+ };
218
+ }
245
219
  return {
246
220
  ...result,
247
221
  groupIndex: result.fromGroup,
@@ -11,7 +11,7 @@ export interface Destination {
11
11
  lockTime?: number;
12
12
  message?: string;
13
13
  }
14
- export type KeyType = 'default' | 'bip340-schnorr' | 'groupless';
14
+ export type KeyType = 'default' | 'bip340-schnorr' | 'gl-secp256k1';
15
15
  export interface Account {
16
16
  keyType: KeyType;
17
17
  address: string;
@@ -29,6 +29,7 @@ export interface SignTransferTxParams {
29
29
  utxos?: OutputRef[];
30
30
  gasAmount?: number;
31
31
  gasPrice?: Number256;
32
+ group?: number;
32
33
  }
33
34
  export interface SignTransferTxResult {
34
35
  fromGroup: number;
@@ -49,6 +50,7 @@ export interface SignDeployContractTxParams {
49
50
  issueTokenTo?: string;
50
51
  gasAmount?: number;
51
52
  gasPrice?: Number256;
53
+ group?: number;
52
54
  }
53
55
  export interface SignDeployContractTxResult {
54
56
  groupIndex: number;
@@ -69,6 +71,7 @@ export interface SignExecuteScriptTxParams {
69
71
  gasAmount?: number;
70
72
  gasPrice?: Number256;
71
73
  gasEstimationMultiplier?: number;
74
+ group?: number;
72
75
  }
73
76
  export interface SignExecuteScriptTxResult {
74
77
  groupIndex: number;
@@ -79,6 +82,16 @@ export interface SignExecuteScriptTxResult {
79
82
  gasPrice: Number256;
80
83
  simulationResult: SimulationResult;
81
84
  }
85
+ export interface GrouplessBuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> {
86
+ transferTxs: Omit<SignTransferTxResult, 'signature'>[];
87
+ tx: Omit<T, 'signature'>;
88
+ }
89
+ export type BuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessBuildTxResult<T> | Omit<T, 'signature'>;
90
+ export interface GrouplessSignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> {
91
+ transferTxs: SignTransferTxResult[];
92
+ tx: T;
93
+ }
94
+ export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessSignTxResult<T> | T;
82
95
  export interface SignUnsignedTxParams {
83
96
  signerAddress: string;
84
97
  signerKeyType?: KeyType;
@@ -113,32 +126,6 @@ export type SignExecuteScriptChainedTxResult = SignExecuteScriptTxResult & {
113
126
  type: 'ExecuteScript';
114
127
  };
115
128
  export type SignChainedTxResult = SignTransferChainedTxResult | SignDeployContractChainedTxResult | SignExecuteScriptChainedTxResult;
116
- export interface SignGrouplessTransferTxParams {
117
- fromAddress: string;
118
- destinations: Destination[];
119
- gasPrice?: Number256;
120
- targetBlockHash?: string;
121
- }
122
- export interface SignGrouplessDeployContractTxParams {
123
- fromAddress: string;
124
- bytecode: string;
125
- initialAttoAlphAmount?: Number256;
126
- initialTokenAmounts?: Token[];
127
- issueTokenAmount?: Number256;
128
- issueTokenTo?: string;
129
- gasPrice?: Number256;
130
- targetBlockHash?: string;
131
- }
132
- export interface SignGrouplessExecuteScriptTxParams {
133
- fromAddress: string;
134
- bytecode: string;
135
- attoAlphAmount?: Number256;
136
- tokens?: Token[];
137
- gasPrice?: Number256;
138
- targetBlockHash?: string;
139
- gasEstimationMultiplier?: number;
140
- }
141
- export type SignGrouplessTxParams = SignGrouplessTransferTxParams | SignGrouplessDeployContractTxParams | SignGrouplessExecuteScriptTxParams;
142
129
  export type MessageHasher = 'alephium' | 'sha256' | 'blake2b' | 'identity';
143
130
  export interface SignMessageParams {
144
131
  signerAddress: string;
@@ -28,6 +28,3 @@ utils_1.assertType;
28
28
  (0, utils_1.assertType)();
29
29
  utils_1.assertType;
30
30
  (0, utils_1.assertType)();
31
- (0, utils_1.assertType)();
32
- (0, utils_1.assertType)();
33
- (0, utils_1.assertType)();
@@ -60,7 +60,7 @@ necc.utils.hmacSha256Sync = (key, ...messages) => {
60
60
  // hash has to be 32 bytes
61
61
  function sign(hash, privateKey, _keyType) {
62
62
  const keyType = _keyType ?? 'default';
63
- if (keyType === 'default' || keyType === 'groupless') {
63
+ if (keyType === 'default' || keyType === 'gl-secp256k1') {
64
64
  const key = ec.keyFromPrivate(privateKey);
65
65
  const signature = key.sign(hash);
66
66
  return (0, utils_1.encodeSignature)(signature);
@@ -74,7 +74,7 @@ exports.sign = sign;
74
74
  function verifySignature(hash, publicKey, signature, _keyType) {
75
75
  const keyType = _keyType ?? 'default';
76
76
  try {
77
- if (keyType === 'default' || keyType === 'groupless') {
77
+ if (keyType === 'default' || keyType === 'gl-secp256k1') {
78
78
  const key = ec.keyFromPublic(publicKey, 'hex');
79
79
  return key.verify(hash, (0, utils_1.signatureDecode)(ec, signature));
80
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "1.12.0-beta.0",
3
+ "version": "1.12.0-danube.0",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",