@alephium/web3 2.0.0-rc.0 → 2.0.0-rc.2
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.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +7 -17
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/contract/contract.js +3 -9
- package/dist/src/signer/signer.js +51 -31
- package/dist/src/signer/tx-builder.js +28 -24
- package/dist/src/signer/types.d.ts +20 -12
- package/dist/src/signer/types.js +9 -0
- package/dist/src/utils/sign.js +7 -0
- package/package.json +2 -2
- package/src/api/api-alephium.ts +7 -20
- package/src/contract/contract.ts +3 -9
- package/src/signer/signer.ts +54 -32
- package/src/signer/tx-builder.ts +28 -24
- package/src/signer/types.ts +32 -15
- package/src/utils/sign.ts +8 -0
|
@@ -268,7 +268,7 @@ export interface BuildGrouplessDeployContractTxResult {
|
|
|
268
268
|
txId: string;
|
|
269
269
|
/** @format address */
|
|
270
270
|
contractAddress: string;
|
|
271
|
-
|
|
271
|
+
fundingTxs?: BuildSimpleTransferTxResult[];
|
|
272
272
|
}
|
|
273
273
|
/** BuildGrouplessExecuteScriptTxResult */
|
|
274
274
|
export interface BuildGrouplessExecuteScriptTxResult {
|
|
@@ -284,7 +284,7 @@ export interface BuildGrouplessExecuteScriptTxResult {
|
|
|
284
284
|
/** @format 32-byte-hash */
|
|
285
285
|
txId: string;
|
|
286
286
|
simulationResult: SimulationResult;
|
|
287
|
-
|
|
287
|
+
fundingTxs?: BuildSimpleTransferTxResult[];
|
|
288
288
|
}
|
|
289
289
|
/** BuildGrouplessTransferTxResult */
|
|
290
290
|
export interface BuildGrouplessTransferTxResult {
|
|
@@ -299,7 +299,7 @@ export interface BuildGrouplessTransferTxResult {
|
|
|
299
299
|
fromGroup: number;
|
|
300
300
|
/** @format int32 */
|
|
301
301
|
toGroup: number;
|
|
302
|
-
|
|
302
|
+
fundingTxs?: BuildSimpleTransferTxResult[];
|
|
303
303
|
}
|
|
304
304
|
/** BuildInfo */
|
|
305
305
|
export interface BuildInfo {
|
|
@@ -328,7 +328,7 @@ export interface BuildMultisig {
|
|
|
328
328
|
gasPrice?: string;
|
|
329
329
|
/** @format group-index */
|
|
330
330
|
group?: number;
|
|
331
|
-
multiSigType?:
|
|
331
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH';
|
|
332
332
|
}
|
|
333
333
|
/** BuildMultisigAddress */
|
|
334
334
|
export interface BuildMultisigAddress {
|
|
@@ -336,7 +336,7 @@ export interface BuildMultisigAddress {
|
|
|
336
336
|
keyTypes?: string[];
|
|
337
337
|
/** @format int32 */
|
|
338
338
|
mrequired: number;
|
|
339
|
-
multiSigType?:
|
|
339
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH';
|
|
340
340
|
}
|
|
341
341
|
/** BuildMultisigAddressResult */
|
|
342
342
|
export interface BuildMultisigAddressResult {
|
|
@@ -442,7 +442,7 @@ export interface BuildSweepMultisig {
|
|
|
442
442
|
targetBlockHash?: string;
|
|
443
443
|
/** @format group-index */
|
|
444
444
|
group?: number;
|
|
445
|
-
multiSigType?:
|
|
445
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH';
|
|
446
446
|
}
|
|
447
447
|
/** BuildTransferTx */
|
|
448
448
|
export interface BuildTransferTx {
|
|
@@ -849,8 +849,6 @@ export interface MinerAddressesInfo {
|
|
|
849
849
|
}
|
|
850
850
|
/** MisbehaviorAction */
|
|
851
851
|
export type MisbehaviorAction = Ban | Unban;
|
|
852
|
-
/** MultiSigType */
|
|
853
|
-
export type MultiSigType = P2HMPK | P2MPKH;
|
|
854
852
|
/** MultipleCallContract */
|
|
855
853
|
export interface MultipleCallContract {
|
|
856
854
|
calls: CallContract[];
|
|
@@ -889,14 +887,6 @@ export interface OutputRef {
|
|
|
889
887
|
/** @format 32-byte-hash */
|
|
890
888
|
key: string;
|
|
891
889
|
}
|
|
892
|
-
/** P2HMPK */
|
|
893
|
-
export interface P2HMPK {
|
|
894
|
-
type: string;
|
|
895
|
-
}
|
|
896
|
-
/** P2MPKH */
|
|
897
|
-
export interface P2MPKH {
|
|
898
|
-
type: string;
|
|
899
|
-
}
|
|
900
890
|
/** PeerAddress */
|
|
901
891
|
export interface PeerAddress {
|
|
902
892
|
/** @format inet-address */
|
|
@@ -1431,7 +1421,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1431
1421
|
}
|
|
1432
1422
|
/**
|
|
1433
1423
|
* @title Alephium API
|
|
1434
|
-
* @version 3.15.
|
|
1424
|
+
* @version 3.15.2
|
|
1435
1425
|
* @baseUrl ../
|
|
1436
1426
|
*/
|
|
1437
1427
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -694,8 +694,8 @@ class ContractFactory {
|
|
|
694
694
|
const result = await signer.signAndSubmitDeployContractTx(signerParams);
|
|
695
695
|
if ('transferTxs' in result) {
|
|
696
696
|
return {
|
|
697
|
-
...result
|
|
698
|
-
contractInstance: this.at(result.
|
|
697
|
+
...result,
|
|
698
|
+
contractInstance: this.at(result.contractAddress)
|
|
699
699
|
};
|
|
700
700
|
}
|
|
701
701
|
else {
|
|
@@ -733,13 +733,7 @@ class ExecutableScript {
|
|
|
733
733
|
}
|
|
734
734
|
async execute(params) {
|
|
735
735
|
const signerParams = await this.script.txParamsForExecution(params);
|
|
736
|
-
|
|
737
|
-
if ('transferTxs' in result) {
|
|
738
|
-
return result.tx;
|
|
739
|
-
}
|
|
740
|
-
else {
|
|
741
|
-
return result;
|
|
742
|
-
}
|
|
736
|
+
return await params.signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
743
737
|
}
|
|
744
738
|
async call(params) {
|
|
745
739
|
const mainFunc = this.script.functions.find((f) => f.name === 'main');
|
|
@@ -48,6 +48,7 @@ const crypto_1 = require("crypto");
|
|
|
48
48
|
const api_1 = require("../api");
|
|
49
49
|
const utils = __importStar(require("../utils"));
|
|
50
50
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
51
|
+
const types_1 = require("./types");
|
|
51
52
|
const tx_builder_1 = require("./tx-builder");
|
|
52
53
|
const address_1 = require("../address");
|
|
53
54
|
class SignerProvider {
|
|
@@ -59,7 +60,7 @@ class SignerProvider {
|
|
|
59
60
|
static validateAccount(account) {
|
|
60
61
|
const derivedAddress = (0, address_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
61
62
|
const derivedGroup = (0, address_1.groupOfAddress)(derivedAddress);
|
|
62
|
-
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
63
|
+
if (derivedAddress !== account.address || ((0, types_1.isGroupedAccount)(account) && derivedGroup !== account.group)) {
|
|
63
64
|
throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
|
|
64
65
|
}
|
|
65
66
|
}
|
|
@@ -81,11 +82,11 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
81
82
|
}
|
|
82
83
|
async signAndSubmitTransferTx(params) {
|
|
83
84
|
const signResult = await this.signTransferTx(params);
|
|
84
|
-
if ('
|
|
85
|
-
for (const r of signResult.
|
|
85
|
+
if ('fundingTxs' in signResult && signResult.fundingTxs !== undefined) {
|
|
86
|
+
for (const r of signResult.fundingTxs) {
|
|
86
87
|
await this.submitTransaction(r);
|
|
87
88
|
}
|
|
88
|
-
await this.submitTransaction(signResult
|
|
89
|
+
await this.submitTransaction(signResult);
|
|
89
90
|
}
|
|
90
91
|
else {
|
|
91
92
|
await this.submitTransaction(signResult);
|
|
@@ -94,11 +95,11 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
94
95
|
}
|
|
95
96
|
async signAndSubmitDeployContractTx(params) {
|
|
96
97
|
const signResult = await this.signDeployContractTx(params);
|
|
97
|
-
if ('
|
|
98
|
-
for (const r of signResult.
|
|
98
|
+
if ('fundingTxs' in signResult && signResult.fundingTxs !== undefined) {
|
|
99
|
+
for (const r of signResult.fundingTxs) {
|
|
99
100
|
await this.submitTransaction(r);
|
|
100
101
|
}
|
|
101
|
-
await this.submitTransaction(signResult
|
|
102
|
+
await this.submitTransaction(signResult);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
105
|
await this.submitTransaction(signResult);
|
|
@@ -107,11 +108,11 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
107
108
|
}
|
|
108
109
|
async signAndSubmitExecuteScriptTx(params) {
|
|
109
110
|
const signResult = await this.signExecuteScriptTx(params);
|
|
110
|
-
if ('
|
|
111
|
-
for (const r of signResult.
|
|
111
|
+
if ('fundingTxs' in signResult && signResult.fundingTxs !== undefined) {
|
|
112
|
+
for (const r of signResult.fundingTxs) {
|
|
112
113
|
await this.submitTransaction(r);
|
|
113
114
|
}
|
|
114
|
-
await this.submitTransaction(signResult
|
|
115
|
+
await this.submitTransaction(signResult);
|
|
115
116
|
}
|
|
116
117
|
else {
|
|
117
118
|
await this.submitTransaction(signResult);
|
|
@@ -132,19 +133,25 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
132
133
|
}
|
|
133
134
|
async signTransferTx(params) {
|
|
134
135
|
const response = await this.buildTransferTx(params);
|
|
135
|
-
if ('
|
|
136
|
+
if ('fundingTxs' in response && response.fundingTxs !== undefined) {
|
|
136
137
|
const transferTxs = [];
|
|
137
|
-
for (let i = 0; i < response.
|
|
138
|
-
const txSignature = await this.signRaw(params.signerAddress, response.
|
|
138
|
+
for (let i = 0; i < response.fundingTxs.length; i++) {
|
|
139
|
+
const txSignature = await this.signRaw(params.signerAddress, response.fundingTxs[i].txId);
|
|
139
140
|
transferTxs.push({
|
|
140
|
-
...response.
|
|
141
|
+
...response.fundingTxs[i],
|
|
141
142
|
signature: txSignature
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
145
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
145
146
|
return {
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
fromGroup: response.fromGroup,
|
|
148
|
+
toGroup: response.toGroup,
|
|
149
|
+
gasAmount: response.gasAmount,
|
|
150
|
+
gasPrice: response.gasPrice,
|
|
151
|
+
txId: response.txId,
|
|
152
|
+
unsignedTx: response.unsignedTx,
|
|
153
|
+
signature,
|
|
154
|
+
fundingTxs: transferTxs
|
|
148
155
|
};
|
|
149
156
|
}
|
|
150
157
|
else {
|
|
@@ -157,19 +164,26 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
157
164
|
}
|
|
158
165
|
async signDeployContractTx(params) {
|
|
159
166
|
const response = await this.buildDeployContractTx(params);
|
|
160
|
-
if ('
|
|
167
|
+
if ('fundingTxs' in response && response.fundingTxs !== undefined) {
|
|
161
168
|
const transferTxs = [];
|
|
162
|
-
for (let i = 0; i < response.
|
|
163
|
-
const txSignature = await this.signRaw(params.signerAddress, response.
|
|
169
|
+
for (let i = 0; i < response.fundingTxs.length; i++) {
|
|
170
|
+
const txSignature = await this.signRaw(params.signerAddress, response.fundingTxs[i].txId);
|
|
164
171
|
transferTxs.push({
|
|
165
|
-
...response.
|
|
172
|
+
...response.fundingTxs[i],
|
|
166
173
|
signature: txSignature
|
|
167
174
|
});
|
|
168
175
|
}
|
|
169
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
176
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
170
177
|
return {
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
contractAddress: response.contractAddress,
|
|
179
|
+
contractId: response.contractId,
|
|
180
|
+
gasAmount: response.gasAmount,
|
|
181
|
+
gasPrice: response.gasPrice,
|
|
182
|
+
groupIndex: response.groupIndex,
|
|
183
|
+
unsignedTx: response.unsignedTx,
|
|
184
|
+
txId: response.txId,
|
|
185
|
+
signature,
|
|
186
|
+
fundingTxs: transferTxs
|
|
173
187
|
};
|
|
174
188
|
}
|
|
175
189
|
else {
|
|
@@ -182,19 +196,25 @@ class SignerProviderSimple extends SignerProvider {
|
|
|
182
196
|
}
|
|
183
197
|
async signExecuteScriptTx(params) {
|
|
184
198
|
const response = await this.buildExecuteScriptTx(params);
|
|
185
|
-
if ('
|
|
199
|
+
if ('fundingTxs' in response && response.fundingTxs !== undefined) {
|
|
186
200
|
const transferTxs = [];
|
|
187
|
-
for (let i = 0; i < response.
|
|
188
|
-
const txSignature = await this.signRaw(params.signerAddress, response.
|
|
201
|
+
for (let i = 0; i < response.fundingTxs.length; i++) {
|
|
202
|
+
const txSignature = await this.signRaw(params.signerAddress, response.fundingTxs[i].txId);
|
|
189
203
|
transferTxs.push({
|
|
190
|
-
...response.
|
|
204
|
+
...response.fundingTxs[i],
|
|
191
205
|
signature: txSignature
|
|
192
206
|
});
|
|
193
207
|
}
|
|
194
|
-
const signature = await this.signRaw(params.signerAddress, response.
|
|
208
|
+
const signature = await this.signRaw(params.signerAddress, response.txId);
|
|
195
209
|
return {
|
|
196
|
-
|
|
197
|
-
|
|
210
|
+
gasAmount: response.gasAmount,
|
|
211
|
+
gasPrice: response.gasPrice,
|
|
212
|
+
groupIndex: response.groupIndex,
|
|
213
|
+
unsignedTx: response.unsignedTx,
|
|
214
|
+
txId: response.txId,
|
|
215
|
+
simulationResult: response.simulationResult,
|
|
216
|
+
signature,
|
|
217
|
+
fundingTxs: transferTxs
|
|
198
218
|
};
|
|
199
219
|
}
|
|
200
220
|
else {
|
|
@@ -161,16 +161,18 @@ class TransactionBuilder {
|
|
|
161
161
|
}
|
|
162
162
|
convertTransferTxResult(result) {
|
|
163
163
|
// BuildGrouplessTransferTxResult
|
|
164
|
-
if ('
|
|
164
|
+
if ('fundingTxs' in result) {
|
|
165
165
|
return {
|
|
166
|
-
|
|
166
|
+
unsignedTx: result.unsignedTx,
|
|
167
|
+
gasAmount: result.gasAmount,
|
|
168
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
169
|
+
txId: result.txId,
|
|
170
|
+
fromGroup: result.fromGroup,
|
|
171
|
+
toGroup: result.toGroup,
|
|
172
|
+
fundingTxs: result.fundingTxs?.map((r) => ({
|
|
167
173
|
...r,
|
|
168
174
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
169
|
-
}))
|
|
170
|
-
tx: {
|
|
171
|
-
...result,
|
|
172
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
173
|
-
}
|
|
175
|
+
}))
|
|
174
176
|
};
|
|
175
177
|
}
|
|
176
178
|
return {
|
|
@@ -179,19 +181,20 @@ class TransactionBuilder {
|
|
|
179
181
|
};
|
|
180
182
|
}
|
|
181
183
|
convertDeployContractTxResult(result) {
|
|
182
|
-
if ('
|
|
184
|
+
if ('fundingTxs' in result) {
|
|
183
185
|
const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.contractAddress));
|
|
184
186
|
return {
|
|
185
|
-
|
|
187
|
+
groupIndex: result.fromGroup,
|
|
188
|
+
unsignedTx: result.unsignedTx,
|
|
189
|
+
gasAmount: result.gasAmount,
|
|
190
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
191
|
+
txId: result.txId,
|
|
192
|
+
contractAddress: result.contractAddress,
|
|
193
|
+
contractId,
|
|
194
|
+
fundingTxs: result.fundingTxs?.map((r) => ({
|
|
186
195
|
...r,
|
|
187
196
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
188
|
-
}))
|
|
189
|
-
tx: {
|
|
190
|
-
...result,
|
|
191
|
-
groupIndex: result.fromGroup,
|
|
192
|
-
contractId,
|
|
193
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
194
|
-
}
|
|
197
|
+
}))
|
|
195
198
|
};
|
|
196
199
|
}
|
|
197
200
|
const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.contractAddress));
|
|
@@ -203,17 +206,18 @@ class TransactionBuilder {
|
|
|
203
206
|
};
|
|
204
207
|
}
|
|
205
208
|
convertExecuteScriptTxResult(result) {
|
|
206
|
-
if ('
|
|
209
|
+
if ('fundingTxs' in result) {
|
|
207
210
|
return {
|
|
208
|
-
|
|
211
|
+
groupIndex: result.fromGroup,
|
|
212
|
+
unsignedTx: result.unsignedTx,
|
|
213
|
+
txId: result.txId,
|
|
214
|
+
gasAmount: result.gasAmount,
|
|
215
|
+
simulationResult: result.simulationResult,
|
|
216
|
+
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice),
|
|
217
|
+
fundingTxs: result.fundingTxs?.map((r) => ({
|
|
209
218
|
...r,
|
|
210
219
|
gasPrice: (0, api_1.fromApiNumber256)(r.gasPrice)
|
|
211
|
-
}))
|
|
212
|
-
tx: {
|
|
213
|
-
...result,
|
|
214
|
-
groupIndex: result.fromGroup,
|
|
215
|
-
gasPrice: (0, api_1.fromApiNumber256)(result.gasPrice)
|
|
216
|
-
}
|
|
220
|
+
}))
|
|
217
221
|
};
|
|
218
222
|
}
|
|
219
223
|
return {
|
|
@@ -11,13 +11,23 @@ export interface Destination {
|
|
|
11
11
|
lockTime?: number;
|
|
12
12
|
message?: string;
|
|
13
13
|
}
|
|
14
|
-
export type
|
|
15
|
-
export
|
|
16
|
-
|
|
14
|
+
export type GroupedKeyType = 'default' | 'bip340-schnorr';
|
|
15
|
+
export type GrouplessKeyType = 'gl-secp256k1' | 'gl-secp256r1' | 'gl-ed25519' | 'gl-webauthn';
|
|
16
|
+
export type KeyType = GroupedKeyType | GrouplessKeyType;
|
|
17
|
+
export interface GroupedAccount {
|
|
18
|
+
keyType: GroupedKeyType;
|
|
17
19
|
address: string;
|
|
18
20
|
group: number;
|
|
19
21
|
publicKey: string;
|
|
20
22
|
}
|
|
23
|
+
export interface GrouplessAccount {
|
|
24
|
+
keyType: GrouplessKeyType;
|
|
25
|
+
address: string;
|
|
26
|
+
publicKey: string;
|
|
27
|
+
}
|
|
28
|
+
export type Account = GroupedAccount | GrouplessAccount;
|
|
29
|
+
export declare function isGroupedAccount(account: Account): account is GroupedAccount;
|
|
30
|
+
export declare function isGrouplessAccount(account: Account): account is GrouplessAccount;
|
|
21
31
|
export type SignerAddress = {
|
|
22
32
|
signerAddress: string;
|
|
23
33
|
signerKeyType?: KeyType;
|
|
@@ -82,16 +92,14 @@ export interface SignExecuteScriptTxResult {
|
|
|
82
92
|
gasPrice: Number256;
|
|
83
93
|
simulationResult: SimulationResult;
|
|
84
94
|
}
|
|
85
|
-
export
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
95
|
+
export type GrouplessBuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = {
|
|
96
|
+
fundingTxs?: Omit<SignTransferTxResult, 'signature'>[];
|
|
97
|
+
} & Omit<T, 'signature'>;
|
|
89
98
|
export type BuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessBuildTxResult<T> | Omit<T, 'signature'>;
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = GrouplessSignTxResult<T> | T;
|
|
99
|
+
export type GrouplessSignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = {
|
|
100
|
+
fundingTxs?: SignTransferTxResult[];
|
|
101
|
+
} & T;
|
|
102
|
+
export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> = T | GrouplessSignTxResult<T>;
|
|
95
103
|
export interface SignUnsignedTxParams {
|
|
96
104
|
signerAddress: string;
|
|
97
105
|
signerKeyType?: KeyType;
|
package/dist/src/signer/types.js
CHANGED
|
@@ -17,8 +17,17 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.isGrouplessAccount = exports.isGroupedAccount = void 0;
|
|
20
21
|
const utils_1 = require("../utils");
|
|
21
22
|
utils_1.assertType;
|
|
23
|
+
function isGroupedAccount(account) {
|
|
24
|
+
return account.keyType === 'default' || account.keyType === 'bip340-schnorr';
|
|
25
|
+
}
|
|
26
|
+
exports.isGroupedAccount = isGroupedAccount;
|
|
27
|
+
function isGrouplessAccount(account) {
|
|
28
|
+
return account.keyType !== 'default' && account.keyType !== 'bip340-schnorr';
|
|
29
|
+
}
|
|
30
|
+
exports.isGrouplessAccount = isGrouplessAccount;
|
|
22
31
|
(0, utils_1.assertType)();
|
|
23
32
|
(0, utils_1.assertType)();
|
|
24
33
|
(0, utils_1.assertType)();
|
package/dist/src/utils/sign.js
CHANGED
|
@@ -57,9 +57,15 @@ necc.utils.hmacSha256Sync = (key, ...messages) => {
|
|
|
57
57
|
messages.forEach((m) => hash.update(m));
|
|
58
58
|
return Uint8Array.from(hash.digest());
|
|
59
59
|
};
|
|
60
|
+
function checkKeyType(keyType) {
|
|
61
|
+
if (keyType !== 'default' && keyType !== 'bip340-schnorr' && keyType !== 'gl-secp256k1') {
|
|
62
|
+
throw new Error(`Invalid key type ${keyType}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
60
65
|
// hash has to be 32 bytes
|
|
61
66
|
function sign(hash, privateKey, _keyType) {
|
|
62
67
|
const keyType = _keyType ?? 'default';
|
|
68
|
+
checkKeyType(keyType);
|
|
63
69
|
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
64
70
|
const key = ec.keyFromPrivate(privateKey);
|
|
65
71
|
const signature = key.sign(hash);
|
|
@@ -73,6 +79,7 @@ function sign(hash, privateKey, _keyType) {
|
|
|
73
79
|
exports.sign = sign;
|
|
74
80
|
function verifySignature(hash, publicKey, signature, _keyType) {
|
|
75
81
|
const keyType = _keyType ?? 'default';
|
|
82
|
+
checkKeyType(keyType);
|
|
76
83
|
try {
|
|
77
84
|
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
78
85
|
const key = ec.keyFromPublic(publicKey, 'hex');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"author": "Alephium dev <dev@alephium.org>",
|
|
35
35
|
"config": {
|
|
36
|
-
"alephium_version": "3.15.
|
|
36
|
+
"alephium_version": "3.15.2",
|
|
37
37
|
"explorer_backend_version": "2.3.2"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -312,7 +312,7 @@ export interface BuildGrouplessDeployContractTxResult {
|
|
|
312
312
|
txId: string
|
|
313
313
|
/** @format address */
|
|
314
314
|
contractAddress: string
|
|
315
|
-
|
|
315
|
+
fundingTxs?: BuildSimpleTransferTxResult[]
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
/** BuildGrouplessExecuteScriptTxResult */
|
|
@@ -329,7 +329,7 @@ export interface BuildGrouplessExecuteScriptTxResult {
|
|
|
329
329
|
/** @format 32-byte-hash */
|
|
330
330
|
txId: string
|
|
331
331
|
simulationResult: SimulationResult
|
|
332
|
-
|
|
332
|
+
fundingTxs?: BuildSimpleTransferTxResult[]
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
/** BuildGrouplessTransferTxResult */
|
|
@@ -345,7 +345,7 @@ export interface BuildGrouplessTransferTxResult {
|
|
|
345
345
|
fromGroup: number
|
|
346
346
|
/** @format int32 */
|
|
347
347
|
toGroup: number
|
|
348
|
-
|
|
348
|
+
fundingTxs?: BuildSimpleTransferTxResult[]
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
/** BuildInfo */
|
|
@@ -377,7 +377,7 @@ export interface BuildMultisig {
|
|
|
377
377
|
gasPrice?: string
|
|
378
378
|
/** @format group-index */
|
|
379
379
|
group?: number
|
|
380
|
-
multiSigType?:
|
|
380
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH'
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
/** BuildMultisigAddress */
|
|
@@ -386,7 +386,7 @@ export interface BuildMultisigAddress {
|
|
|
386
386
|
keyTypes?: string[]
|
|
387
387
|
/** @format int32 */
|
|
388
388
|
mrequired: number
|
|
389
|
-
multiSigType?:
|
|
389
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH'
|
|
390
390
|
}
|
|
391
391
|
|
|
392
392
|
/** BuildMultisigAddressResult */
|
|
@@ -499,7 +499,7 @@ export interface BuildSweepMultisig {
|
|
|
499
499
|
targetBlockHash?: string
|
|
500
500
|
/** @format group-index */
|
|
501
501
|
group?: number
|
|
502
|
-
multiSigType?:
|
|
502
|
+
multiSigType?: 'P2HMPK' | 'P2MPKH'
|
|
503
503
|
}
|
|
504
504
|
|
|
505
505
|
/** BuildTransferTx */
|
|
@@ -958,9 +958,6 @@ export interface MinerAddressesInfo {
|
|
|
958
958
|
/** MisbehaviorAction */
|
|
959
959
|
export type MisbehaviorAction = Ban | Unban
|
|
960
960
|
|
|
961
|
-
/** MultiSigType */
|
|
962
|
-
export type MultiSigType = P2HMPK | P2MPKH
|
|
963
|
-
|
|
964
961
|
/** MultipleCallContract */
|
|
965
962
|
export interface MultipleCallContract {
|
|
966
963
|
calls: CallContract[]
|
|
@@ -1006,16 +1003,6 @@ export interface OutputRef {
|
|
|
1006
1003
|
key: string
|
|
1007
1004
|
}
|
|
1008
1005
|
|
|
1009
|
-
/** P2HMPK */
|
|
1010
|
-
export interface P2HMPK {
|
|
1011
|
-
type: string
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
/** P2MPKH */
|
|
1015
|
-
export interface P2MPKH {
|
|
1016
|
-
type: string
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
1006
|
/** PeerAddress */
|
|
1020
1007
|
export interface PeerAddress {
|
|
1021
1008
|
/** @format inet-address */
|
|
@@ -1767,7 +1754,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1767
1754
|
|
|
1768
1755
|
/**
|
|
1769
1756
|
* @title Alephium API
|
|
1770
|
-
* @version 3.15.
|
|
1757
|
+
* @version 3.15.2
|
|
1771
1758
|
* @baseUrl ../
|
|
1772
1759
|
*/
|
|
1773
1760
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/contract/contract.ts
CHANGED
|
@@ -1111,8 +1111,8 @@ export abstract class ContractFactory<I extends ContractInstance, F extends Fiel
|
|
|
1111
1111
|
const result = await signer.signAndSubmitDeployContractTx(signerParams)
|
|
1112
1112
|
if ('transferTxs' in result) {
|
|
1113
1113
|
return {
|
|
1114
|
-
...result
|
|
1115
|
-
contractInstance: this.at(result.
|
|
1114
|
+
...result,
|
|
1115
|
+
contractInstance: this.at(result.contractAddress)
|
|
1116
1116
|
}
|
|
1117
1117
|
} else {
|
|
1118
1118
|
return {
|
|
@@ -1160,13 +1160,7 @@ export class ExecutableScript<P extends Fields = Fields, R extends Val | null =
|
|
|
1160
1160
|
|
|
1161
1161
|
async execute(params: ExecuteScriptParams<P>): Promise<ExecuteScriptResult> {
|
|
1162
1162
|
const signerParams = await this.script.txParamsForExecution(params)
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
if ('transferTxs' in result) {
|
|
1166
|
-
return result.tx
|
|
1167
|
-
} else {
|
|
1168
|
-
return result
|
|
1169
|
-
}
|
|
1163
|
+
return await params.signer.signAndSubmitExecuteScriptTx(signerParams)
|
|
1170
1164
|
}
|
|
1171
1165
|
|
|
1172
1166
|
async call(params: CallScriptParams<P>): Promise<CallScriptResult<R>> {
|