@massalabs/wallet-provider 3.1.2-dev.20250214001557 → 3.1.2-dev.20250218144940
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/esm/bearbyWallet/BearbyAccount.d.ts +1 -0
- package/dist/esm/bearbyWallet/BearbyAccount.d.ts.map +1 -1
- package/dist/esm/bearbyWallet/BearbyAccount.js +48 -25
- package/dist/esm/bearbyWallet/BearbyAccount.js.map +1 -1
- package/dist/esm/bearbyWallet/BearbyWallet.d.ts.map +1 -1
- package/dist/esm/bearbyWallet/BearbyWallet.js +5 -2
- package/dist/esm/bearbyWallet/BearbyWallet.js.map +1 -1
- package/dist/esm/bearbyWallet/utils/network.d.ts.map +1 -1
- package/dist/esm/bearbyWallet/utils/network.js +3 -4
- package/dist/esm/bearbyWallet/utils/network.js.map +1 -1
- package/dist/esm/errors/base.js +1 -1
- package/dist/esm/errors/base.js.map +1 -1
- package/dist/esm/errors/utils/errorHandler.js +1 -1
- package/dist/esm/errors/utils/errorHandler.js.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.d.ts +1 -1
- package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationAccount.js +8 -6
- package/dist/esm/massaStation/MassaStationAccount.js.map +1 -1
- package/dist/esm/massaStation/MassaStationDiscovery.js +1 -1
- package/dist/esm/massaStation/MassaStationDiscovery.js.map +1 -1
- package/dist/esm/massaStation/RequestHandler.d.ts.map +1 -1
- package/dist/esm/massaStation/RequestHandler.js +4 -7
- package/dist/esm/massaStation/RequestHandler.js.map +1 -1
- package/dist/esm/massaStation/utils/standalone.d.ts.map +1 -1
- package/dist/esm/massaStation/utils/standalone.js +1 -1
- package/dist/esm/massaStation/utils/standalone.js.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.d.ts +1 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.d.ts.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskAccount.js +10 -10
- package/dist/esm/metamaskSnap/MetamaskAccount.js.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskWallet.d.ts.map +1 -1
- package/dist/esm/metamaskSnap/MetamaskWallet.js +3 -9
- package/dist/esm/metamaskSnap/MetamaskWallet.js.map +1 -1
- package/dist/esm/metamaskSnap/snap.d.ts +2 -2
- package/dist/esm/metamaskSnap/snap.d.ts.map +1 -1
- package/dist/esm/metamaskSnap/snap.js +9 -3
- package/dist/esm/metamaskSnap/snap.js.map +1 -1
- package/dist/esm/metamaskSnap/utils/network.d.ts +5 -0
- package/dist/esm/metamaskSnap/utils/network.d.ts.map +1 -0
- package/dist/esm/metamaskSnap/utils/network.js +29 -0
- package/dist/esm/metamaskSnap/utils/network.js.map +1 -0
- package/dist/esm/utils/time.d.ts.map +1 -1
- package/dist/esm/utils/time.js.map +1 -1
- package/dist/esm/walletsManager/walletList.d.ts.map +1 -1
- package/dist/esm/walletsManager/walletList.js +1 -0
- package/dist/esm/walletsManager/walletList.js.map +1 -1
- package/package.json +3 -3
|
@@ -4,6 +4,7 @@ export declare class BearbyAccount implements Provider {
|
|
|
4
4
|
constructor(address: string);
|
|
5
5
|
get accountName(): string;
|
|
6
6
|
get providerName(): string;
|
|
7
|
+
private getClient;
|
|
7
8
|
balance(final?: boolean): Promise<bigint>;
|
|
8
9
|
balanceOf(addresses: string[], final?: boolean): Promise<{
|
|
9
10
|
address: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyAccount.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,
|
|
1
|
+
{"version":3,"file":"BearbyAccount.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,EAKX,OAAO,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AAI,OAAO,CAAC,SAAS,CAAC;IAIlB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAmC1D,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IA0B9D,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC;IAQxC,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,UAAU,GAAG,MAAyB,EAC9C,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;IA0BX,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,EAC7B,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;CAkBzB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { web3, } from '@hicaru/bearby.js';
|
|
2
2
|
import { errorHandler } from '../errors/utils/errorHandler';
|
|
3
3
|
import { operationType } from '../utils/constants';
|
|
4
|
-
import { DEPLOYER_BYTECODE, formatNodeStatusObject,
|
|
4
|
+
import { DEPLOYER_BYTECODE, formatNodeStatusObject, Mas, MAX_GAS_CALL, MAX_GAS_DEPLOYMENT, Operation, OperationStatus, SmartContract, StorageCost, strToBytes, bytesToStr, JsonRpcPublicProvider, } from '@massalabs/massa-web3';
|
|
5
5
|
import { networkInfos } from './utils/network';
|
|
6
6
|
import { WalletName } from '../wallet';
|
|
7
7
|
import isEqual from 'lodash.isequal';
|
|
8
8
|
import { uint8ArrayToBase64 } from '../utils/base64';
|
|
9
|
+
let jsonClient;
|
|
9
10
|
export class BearbyAccount {
|
|
10
11
|
address;
|
|
11
12
|
constructor(address) {
|
|
@@ -24,12 +25,21 @@ export class BearbyAccount {
|
|
|
24
25
|
// console.log('Bearby connection error: ', ex);
|
|
25
26
|
// }
|
|
26
27
|
// }
|
|
28
|
+
async getClient() {
|
|
29
|
+
if (!jsonClient) {
|
|
30
|
+
const network = await networkInfos();
|
|
31
|
+
jsonClient = (network.name === 'mainnet'
|
|
32
|
+
? JsonRpcPublicProvider.mainnet()
|
|
33
|
+
: JsonRpcPublicProvider.buildnet());
|
|
34
|
+
}
|
|
35
|
+
return jsonClient;
|
|
36
|
+
}
|
|
27
37
|
async balance(final = false) {
|
|
28
38
|
// // TODO: check if we need to connect every time
|
|
29
39
|
// await this.connect();
|
|
30
40
|
try {
|
|
31
41
|
const res = await web3.massa.getAddresses(this.address);
|
|
32
|
-
if (res.error) {
|
|
42
|
+
if (res.error || !res.result) {
|
|
33
43
|
throw new Error(res.error?.message || 'Bearby getAddresses error');
|
|
34
44
|
}
|
|
35
45
|
const { final_balance, candidate_balance } = res.result[0];
|
|
@@ -42,7 +52,7 @@ export class BearbyAccount {
|
|
|
42
52
|
}
|
|
43
53
|
async balanceOf(addresses, final) {
|
|
44
54
|
const res = await web3.massa.getAddresses(...addresses);
|
|
45
|
-
if (res.error) {
|
|
55
|
+
if (res.error || !res.result) {
|
|
46
56
|
throw new Error(res.error?.message || 'Bearby getAddresses error');
|
|
47
57
|
}
|
|
48
58
|
return res.result.map((addressInfo) => {
|
|
@@ -58,12 +68,11 @@ export class BearbyAccount {
|
|
|
58
68
|
}
|
|
59
69
|
async sign(data) {
|
|
60
70
|
// await this.connect();
|
|
61
|
-
let strData;
|
|
62
71
|
if (data instanceof Uint8Array) {
|
|
63
|
-
|
|
72
|
+
data = bytesToStr(data);
|
|
64
73
|
}
|
|
65
74
|
try {
|
|
66
|
-
const signature = await web3.wallet.signMessage(
|
|
75
|
+
const signature = await web3.wallet.signMessage(data);
|
|
67
76
|
return {
|
|
68
77
|
publicKey: signature.publicKey,
|
|
69
78
|
signature: signature.signature,
|
|
@@ -117,12 +126,19 @@ export class BearbyAccount {
|
|
|
117
126
|
// await this.connect();
|
|
118
127
|
const args = params.parameter ?? new Uint8Array();
|
|
119
128
|
const unsafeParameters = args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());
|
|
120
|
-
const fee = params
|
|
129
|
+
const fee = params.fee ?? (await this.minimalFee());
|
|
130
|
+
let maxGas = params.maxGas;
|
|
131
|
+
if (!maxGas) {
|
|
132
|
+
const client = await this.getClient();
|
|
133
|
+
maxGas = await client.getGasEstimation({
|
|
134
|
+
...params,
|
|
135
|
+
caller: this.address,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
121
138
|
try {
|
|
122
139
|
const operationId = await web3.contract.call({
|
|
123
140
|
// TODO: add bigint support in bearby.js
|
|
124
|
-
|
|
125
|
-
maxGas: Number(params.maxGas || MAX_GAS_CALL),
|
|
141
|
+
maxGas: Number(maxGas),
|
|
126
142
|
coins: Number(params.coins || 0),
|
|
127
143
|
fee: Number(fee),
|
|
128
144
|
targetAddress: params.target,
|
|
@@ -136,7 +152,7 @@ export class BearbyAccount {
|
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
async readSC(params) {
|
|
139
|
-
if (params
|
|
155
|
+
if (params.maxGas && params.maxGas > MAX_GAS_CALL) {
|
|
140
156
|
throw new Error(`Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}.`);
|
|
141
157
|
}
|
|
142
158
|
const args = params.parameter ?? new Uint8Array();
|
|
@@ -169,17 +185,14 @@ export class BearbyAccount {
|
|
|
169
185
|
// },
|
|
170
186
|
// };
|
|
171
187
|
// Temp implementation to remove when bearby.js is fixed
|
|
172
|
-
const
|
|
173
|
-
const client = network.name === 'mainnet'
|
|
174
|
-
? JsonRPCClient.mainnet()
|
|
175
|
-
: JsonRPCClient.buildnet();
|
|
188
|
+
const client = await this.getClient();
|
|
176
189
|
const readOnlyParams = {
|
|
177
190
|
...params,
|
|
178
191
|
caller,
|
|
179
192
|
fee,
|
|
180
193
|
parameter: unsafeParameters,
|
|
181
194
|
};
|
|
182
|
-
return client.
|
|
195
|
+
return client.readSC(readOnlyParams);
|
|
183
196
|
}
|
|
184
197
|
catch (error) {
|
|
185
198
|
throw new Error(`An error occurred while reading the smart contract: ${error.message}`);
|
|
@@ -188,15 +201,15 @@ export class BearbyAccount {
|
|
|
188
201
|
async deploySC(params) {
|
|
189
202
|
try {
|
|
190
203
|
const fee = Number(params.fee ?? (await this.minimalFee()));
|
|
204
|
+
const coins = params.coins ?? 0n;
|
|
191
205
|
const maxCoins = params.maxCoins ??
|
|
192
|
-
StorageCost.smartContract(params.byteCode.length) +
|
|
206
|
+
StorageCost.smartContract(params.byteCode.length) + coins;
|
|
193
207
|
const args = {
|
|
194
208
|
...params,
|
|
195
|
-
maxCoins
|
|
209
|
+
maxCoins,
|
|
196
210
|
maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,
|
|
197
|
-
coins
|
|
198
|
-
fee
|
|
199
|
-
gasPrice: 10000n,
|
|
211
|
+
coins,
|
|
212
|
+
fee,
|
|
200
213
|
contractDataBase64: uint8ArrayToBase64(params.byteCode),
|
|
201
214
|
deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),
|
|
202
215
|
};
|
|
@@ -216,10 +229,10 @@ export class BearbyAccount {
|
|
|
216
229
|
async getOperationStatus(opId) {
|
|
217
230
|
try {
|
|
218
231
|
const res = await web3.massa.getOperations(opId);
|
|
219
|
-
if (res.error) {
|
|
232
|
+
if (res.error || !res.result) {
|
|
220
233
|
throw new Error(res.error?.message || 'Bearby getOperations error');
|
|
221
234
|
}
|
|
222
|
-
const op = res.result[0];
|
|
235
|
+
const op = res.result[0];
|
|
223
236
|
if (op.op_exec_status === null) {
|
|
224
237
|
if (op.is_operation_final === null) {
|
|
225
238
|
return OperationStatus.NotFound;
|
|
@@ -253,8 +266,11 @@ export class BearbyAccount {
|
|
|
253
266
|
is_error: filter.isError,
|
|
254
267
|
};
|
|
255
268
|
try {
|
|
256
|
-
const
|
|
257
|
-
|
|
269
|
+
const { result } = await web3.contract.getFilteredSCOutputEvent(formattedFilter);
|
|
270
|
+
if (!result) {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
return result;
|
|
258
274
|
}
|
|
259
275
|
catch (error) {
|
|
260
276
|
throw new Error(`An error occurred while fetching the operation status: ${error.message}`);
|
|
@@ -262,10 +278,17 @@ export class BearbyAccount {
|
|
|
262
278
|
}
|
|
263
279
|
async getNodeStatus() {
|
|
264
280
|
const status = await web3.massa.getNodesStatus();
|
|
281
|
+
if (status.error || !status.result) {
|
|
282
|
+
throw new Error(status.error?.message || 'Bearby getNodeStatus error');
|
|
283
|
+
}
|
|
265
284
|
return formatNodeStatusObject(status.result);
|
|
266
285
|
}
|
|
267
286
|
async getStorageKeys(address, filter = new Uint8Array(), final = true) {
|
|
268
|
-
const
|
|
287
|
+
const res = await web3.massa.getAddresses(address);
|
|
288
|
+
if (res.error || !res.result) {
|
|
289
|
+
throw new Error(res.error?.message || 'Bearby getStorageKeys error');
|
|
290
|
+
}
|
|
291
|
+
const addressInfo = res.result[0];
|
|
269
292
|
const keys = final
|
|
270
293
|
? addressInfo.final_datastore_keys
|
|
271
294
|
: addressInfo.candidate_datastore_keys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,GAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAGL,iBAAiB,EAGjB,sBAAsB,EACtB,aAAa,EACb,GAAG,EACH,YAAY,EACZ,kBAAkB,EAGlB,SAAS,EAET,eAAe,EAKf,aAAa,EACb,WAAW,EACX,UAAU,GAEX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAA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CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC,CAAC;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,SAAS,GAAG,KAAK;gBACrB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;gBACxD,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,gDAAgD,KAAK,CAAC,OAAO,EAAE,CAChE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["import {\n EventFilterParam,\n web3,\n DatastoreEntryInputParam,\n} from '@hicaru/bearby.js';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DEPLOYER_BYTECODE,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n JsonRPCClient,\n Mas,\n MAX_GAS_CALL,\n MAX_GAS_DEPLOYMENT,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n StorageCost,\n strToBytes,\n rpcTypes,\n} from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport isEqual from 'lodash.isequal';\nimport { uint8ArrayToBase64 } from '../utils/base64';\n\nexport class BearbyAccount implements Provider {\n public constructor(public address: string) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Bearby;\n }\n\n // public async connect() {\n // try {\n // await web3.wallet.connect();\n // } catch (ex) {\n // console.log('Bearby connection error: ', ex);\n // }\n // }\n\n public async balance(final = false): Promise<bigint> {\n // // TODO: check if we need to connect every time\n // await this.connect();\n\n try {\n const res = await web3.massa.getAddresses(this.address);\n\n if (res.error) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n const { final_balance, candidate_balance } = res.result[0];\n\n return Mas.fromString(final ? final_balance : candidate_balance);\n } catch (error) {\n const errorMessage = `An unexpected error occurred while fetching the account balance: ${error.message}.`;\n\n throw new Error(errorMessage);\n }\n }\n\n public async balanceOf(\n addresses: string[],\n final?: boolean,\n ): Promise<{ address: string; balance: bigint }[]> {\n const res = await web3.massa.getAddresses(...addresses);\n if (res.error) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n return res.result.map((addressInfo) => {\n const { final_balance, candidate_balance } = addressInfo;\n return {\n address: addressInfo.address,\n balance: Mas.fromString(final ? final_balance : candidate_balance),\n };\n });\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async sign(data: Uint8Array | string): Promise<SignedData> {\n // await this.connect();\n\n let strData: string;\n if (data instanceof Uint8Array) {\n strData = new TextDecoder().decode(data);\n }\n try {\n const signature = await web3.wallet.signMessage(strData);\n\n return {\n publicKey: signature.publicKey,\n signature: signature.signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.buyRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.BuyRolls, error);\n }\n }\n\n public async sellRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.sellRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SellRolls, error);\n }\n }\n\n public async transfer(\n to: Address | string,\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n\n try {\n const operationId = await web3.massa.payment(\n amount.toString(),\n to.toString(),\n );\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const { minimalFee } = await this.networkInfos();\n return minimalFee;\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // await this.connect();\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params?.fee ?? (await this.minimalFee());\n\n try {\n const operationId = await web3.contract.call({\n // TODO: add bigint support in bearby.js\n // TODO add gas estimation here\n maxGas: Number(params.maxGas || MAX_GAS_CALL),\n coins: Number(params.coins || 0),\n fee: Number(fee),\n targetAddress: params.target,\n functionName: params.func,\n unsafeParameters,\n });\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n if (params?.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}.`,\n );\n }\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n\n try {\n // const res = await web3.contract.readSmartContract({\n // // TODO: add bigint support in bearby.js\n // maxGas: Number(params.maxGas),\n // coins: Number(params.coins),\n // fee: Number(fee),\n // targetAddress: params.target,\n // targetFunction: params.func,\n // // TODO: add unsafeParameters to bearby.js\n // // https://github.com/bearby-wallet/bearby-web3/pull/18\n // parameter: unsafeParameters as any,\n // });\n\n // console.log('bearby readSC res', res[0]);\n // const data = res[0].result[0];\n\n // return {\n // value: data.result.Ok ? Uint8Array.from(data.result.Ok): new Uint8Array(),\n // info: {\n // error: data.result.Error,\n // events: data.output_events.map((event: SCEvent) => ({\n // data: event.data,\n // context: event.context,\n // })),\n // gasCost: data.gas_cost,\n // },\n // };\n\n // Temp implementation to remove when bearby.js is fixed\n const network = await this.networkInfos();\n const client =\n network.name === 'mainnet'\n ? JsonRPCClient.mainnet()\n : JsonRPCClient.buildnet();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter: unsafeParameters,\n };\n return client.executeReadOnlyCall(readOnlyParams);\n } catch (error) {\n throw new Error(\n `An error occurred while reading the smart contract: ${error.message}`,\n );\n }\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const fee = Number(params.fee ?? (await this.minimalFee()));\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + params.coins;\n\n const args = {\n ...params,\n maxCoins: maxCoins,\n maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,\n coins: params.coins,\n fee: fee,\n gasPrice: 10000n, // dummy value waiting for (https://github.com/bearby-wallet/bearby-web3/pull/25)\n contractDataBase64: uint8ArrayToBase64(params.byteCode),\n deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),\n };\n\n const operationId = await web3.contract.deploy(args);\n\n const operation = new Operation(this, operationId);\n\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n console.error('Error deploying smart contract:', error);\n throw new Error(`Failed to deploy smart contract: ${error.message}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n try {\n const res = await web3.massa.getOperations(opId);\n\n if (res.error) {\n throw new Error(res.error?.message || 'Bearby getOperations error');\n }\n const op = res.result[0] as any; // cast to remove when bearby.js typings are fixed\n if (op.op_exec_status === null) {\n if (op.is_operation_final === null) {\n return OperationStatus.NotFound;\n }\n throw new Error('unexpected status');\n }\n\n if (op.in_pool) {\n return OperationStatus.PendingInclusion;\n }\n\n if (!op.is_operation_final) {\n return op.op_exec_status\n ? OperationStatus.SpeculativeSuccess\n : OperationStatus.SpeculativeError;\n }\n\n return op.op_exec_status\n ? OperationStatus.Success\n : OperationStatus.Error;\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const formattedFilter: EventFilterParam = {\n start: filter.start,\n end: filter.end,\n emitter_address: filter.smartContractAddress,\n original_caller_address: filter.callerAddress,\n original_operation_id: filter.operationId,\n is_final: filter.isFinal,\n is_error: filter.isError,\n };\n\n try {\n const res = await web3.contract.getFilteredSCOutputEvent(formattedFilter);\n\n return (res as any).result; // TODO: to remove when bearby.js typings are fixed\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const status = await web3.massa.getNodesStatus();\n return formatNodeStatusObject(status.result);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const addressInfo = (await web3.massa.getAddresses(address)).result[0];\n const keys = final\n ? addressInfo.final_datastore_keys\n : addressInfo.candidate_datastore_keys;\n\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n\n return keys\n .filter(\n (key) =>\n !filter.length ||\n isEqual(\n Uint8Array.from(key.slice(0, filterBytes.length)),\n filterBytes,\n ),\n )\n .map((d) => Uint8Array.from(d));\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n try {\n const input: DatastoreEntryInputParam[] = keys.map((key) => ({\n key,\n address,\n }));\n const data = await web3.contract.getDatastoreEntries(...input);\n const resultArray = data[0]['result'];\n const dataArray = final\n ? resultArray.map((d) => Uint8Array.from(d.final_value))\n : resultArray.map((d) => Uint8Array.from(d.candidate_value));\n return dataArray;\n } catch (error) {\n throw new Error(\n `An error occurred while reading the storage: ${error.message}`,\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,IAAI,GAEL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAGL,iBAAiB,EAGjB,sBAAsB,EACtB,GAAG,EACH,YAAY,EACZ,kBAAkB,EAGlB,SAAS,EAET,eAAe,EAKf,aAAa,EACb,WAAW,EACX,UAAU,EACV,UAAU,EAEV,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,IAAI,UAAiC,CAAC;AAEtC,MAAM,OAAO,aAAa;IACE;IAA1B,YAA0B,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAE7C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,YAAY;QACd,OAAO,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,2BAA2B;IAC3B,UAAU;IACV,mCAAmC;IACnC,mBAAmB;IACnB,oDAAoD;IACpD,MAAM;IACN,IAAI;IAEI,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,OAAO,GAAG,MAAM,YAAY,EAAE,CAAC;YACrC,UAAU,GAAG,CACX,OAAO,CAAC,I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,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,IAAI;YACF,MAAM,KAAK,GAA+B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;gBAC3D,GAAG;gBACH,OAAO;aACR,CAAC,CAAC,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,GAAG,KAAK,CAAC,CAAC;YAC/D,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACtC,MAAM,SAAS,GAAG,KAAK;gBACrB,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;gBACxD,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;YAC/D,OAAO,SAAS,CAAC;SAClB;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,KAAK,CACb,gDAAgD,KAAK,CAAC,OAAO,EAAE,CAChE,CAAC;SACH;IACH,CAAC;CACF","sourcesContent":["import {\n EventFilterParam,\n web3,\n DatastoreEntryInputParam,\n} from '@hicaru/bearby.js';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DEPLOYER_BYTECODE,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n MAX_GAS_DEPLOYMENT,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SmartContract,\n StorageCost,\n strToBytes,\n bytesToStr,\n rpcTypes,\n JsonRpcPublicProvider,\n} from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport isEqual from 'lodash.isequal';\nimport { uint8ArrayToBase64 } from '../utils/base64';\n\nlet jsonClient: JsonRpcPublicProvider;\n\nexport class BearbyAccount implements Provider {\n public constructor(public address: string) {}\n\n get accountName(): string {\n return this.address;\n }\n\n get providerName(): string {\n return WalletName.Bearby;\n }\n\n // public async connect() {\n // try {\n // await web3.wallet.connect();\n // } catch (ex) {\n // console.log('Bearby connection error: ', ex);\n // }\n // }\n\n private async getClient(): Promise<JsonRpcPublicProvider> {\n if (!jsonClient) {\n const network = await networkInfos();\n jsonClient = (\n network.name === 'mainnet'\n ? JsonRpcPublicProvider.mainnet()\n : JsonRpcPublicProvider.buildnet()\n ) as JsonRpcPublicProvider;\n }\n return jsonClient;\n }\n\n public async balance(final = false): Promise<bigint> {\n // // TODO: check if we need to connect every time\n // await this.connect();\n\n try {\n const res = await web3.massa.getAddresses(this.address);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n const { final_balance, candidate_balance } = res.result[0];\n\n return Mas.fromString(final ? final_balance : candidate_balance);\n } catch (error) {\n const errorMessage = `An unexpected error occurred while fetching the account balance: ${error.message}.`;\n\n throw new Error(errorMessage);\n }\n }\n\n public async balanceOf(\n addresses: string[],\n final?: boolean,\n ): Promise<{ address: string; balance: bigint }[]> {\n const res = await web3.massa.getAddresses(...addresses);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getAddresses error');\n }\n\n return res.result.map((addressInfo) => {\n const { final_balance, candidate_balance } = addressInfo;\n return {\n address: addressInfo.address,\n balance: Mas.fromString(final ? final_balance : candidate_balance),\n };\n });\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async sign(data: Uint8Array | string): Promise<SignedData> {\n // await this.connect();\n\n if (data instanceof Uint8Array) {\n data = bytesToStr(data);\n }\n\n try {\n const signature = await web3.wallet.signMessage(data);\n\n return {\n publicKey: signature.publicKey,\n signature: signature.signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.buyRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.BuyRolls, error);\n }\n }\n\n public async sellRolls(\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n try {\n const operationId = await web3.massa.sellRolls(amount.toString());\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SellRolls, error);\n }\n }\n\n public async transfer(\n to: Address | string,\n amount: bigint,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _opts?: OperationOptions,\n ): Promise<Operation> {\n // await this.connect();\n\n try {\n const operationId = await web3.massa.payment(\n amount.toString(),\n to.toString(),\n );\n\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const { minimalFee } = await this.networkInfos();\n return minimalFee;\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // await this.connect();\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params.fee ?? (await this.minimalFee());\n\n let maxGas = params.maxGas;\n if (!maxGas) {\n const client = await this.getClient();\n maxGas = await client.getGasEstimation({\n ...params,\n caller: this.address,\n });\n }\n\n try {\n const operationId = await web3.contract.call({\n // TODO: add bigint support in bearby.js\n maxGas: Number(maxGas),\n coins: Number(params.coins || 0),\n fee: Number(fee),\n targetAddress: params.target,\n functionName: params.func,\n unsafeParameters,\n });\n return new Operation(this, operationId);\n } catch (error) {\n throw errorHandler(operationType.CallSC, error);\n }\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `Gas amount ${params.maxGas} exceeds the maximum allowed ${MAX_GAS_CALL}.`,\n );\n }\n\n const args = params.parameter ?? new Uint8Array();\n const unsafeParameters =\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize());\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n\n try {\n // const res = await web3.contract.readSmartContract({\n // // TODO: add bigint support in bearby.js\n // maxGas: Number(params.maxGas),\n // coins: Number(params.coins),\n // fee: Number(fee),\n // targetAddress: params.target,\n // targetFunction: params.func,\n // // TODO: add unsafeParameters to bearby.js\n // // https://github.com/bearby-wallet/bearby-web3/pull/18\n // parameter: unsafeParameters as any,\n // });\n\n // console.log('bearby readSC res', res[0]);\n // const data = res[0].result[0];\n\n // return {\n // value: data.result.Ok ? Uint8Array.from(data.result.Ok): new Uint8Array(),\n // info: {\n // error: data.result.Error,\n // events: data.output_events.map((event: SCEvent) => ({\n // data: event.data,\n // context: event.context,\n // })),\n // gasCost: data.gas_cost,\n // },\n // };\n\n // Temp implementation to remove when bearby.js is fixed\n const client = await this.getClient();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter: unsafeParameters,\n };\n return client.readSC(readOnlyParams);\n } catch (error) {\n throw new Error(\n `An error occurred while reading the smart contract: ${error.message}`,\n );\n }\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const fee = Number(params.fee ?? (await this.minimalFee()));\n const coins = params.coins ?? 0n;\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + coins;\n\n const args = {\n ...params,\n maxCoins,\n maxGas: params.maxGas || MAX_GAS_DEPLOYMENT,\n coins,\n fee,\n contractDataBase64: uint8ArrayToBase64(params.byteCode),\n deployerBase64: uint8ArrayToBase64(DEPLOYER_BYTECODE),\n };\n\n const operationId = await web3.contract.deploy(args);\n\n const operation = new Operation(this, operationId);\n\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n console.error('Error deploying smart contract:', error);\n throw new Error(`Failed to deploy smart contract: ${error.message}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n try {\n const res = await web3.massa.getOperations(opId);\n\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getOperations error');\n }\n const op = res.result[0];\n if (op.op_exec_status === null) {\n if (op.is_operation_final === null) {\n return OperationStatus.NotFound;\n }\n throw new Error('unexpected status');\n }\n\n if (op.in_pool) {\n return OperationStatus.PendingInclusion;\n }\n\n if (!op.is_operation_final) {\n return op.op_exec_status\n ? OperationStatus.SpeculativeSuccess\n : OperationStatus.SpeculativeError;\n }\n\n return op.op_exec_status\n ? OperationStatus.Success\n : OperationStatus.Error;\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const formattedFilter: EventFilterParam = {\n start: filter.start,\n end: filter.end,\n emitter_address: filter.smartContractAddress,\n original_caller_address: filter.callerAddress,\n original_operation_id: filter.operationId,\n is_final: filter.isFinal,\n is_error: filter.isError,\n };\n\n try {\n const { result } =\n await web3.contract.getFilteredSCOutputEvent(formattedFilter);\n\n if (!result) {\n return [];\n }\n return result;\n } catch (error) {\n throw new Error(\n `An error occurred while fetching the operation status: ${error.message}`,\n );\n }\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const status = await web3.massa.getNodesStatus();\n if (status.error || !status.result) {\n throw new Error(status.error?.message || 'Bearby getNodeStatus error');\n }\n return formatNodeStatusObject(status.result);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n const res = await web3.massa.getAddresses(address);\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getStorageKeys error');\n }\n\n const addressInfo = res.result[0];\n const keys = final\n ? addressInfo.final_datastore_keys\n : addressInfo.candidate_datastore_keys;\n\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n\n return keys\n .filter(\n (key) =>\n !filter.length ||\n isEqual(\n Uint8Array.from(key.slice(0, filterBytes.length)),\n filterBytes,\n ),\n )\n .map((d) => Uint8Array.from(d));\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n try {\n const input: DatastoreEntryInputParam[] = keys.map((key) => ({\n key,\n address,\n }));\n const data = await web3.contract.getDatastoreEntries(...input);\n const resultArray = data[0]['result'];\n const dataArray = final\n ? resultArray.map((d) => Uint8Array.from(d.final_value))\n : resultArray.map((d) => Uint8Array.from(d.candidate_value));\n return dataArray;\n } catch (error) {\n throw new Error(\n `An error occurred while reading the storage: ${error.message}`,\n );\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyWallet.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyWallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,qBAAa,YAAa,YAAW,MAAM;IACzC,OAAO,CAAC,UAAU,CAAqB;IAEhC,IAAI,IAAI,UAAU;WAIZ,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAO3C,QAAQ,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;
|
|
1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{
|
|
|
18
18
|
if (!web3.wallet.connected) {
|
|
19
19
|
await web3.wallet.connect();
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
if (!web3.wallet.account.base58) {
|
|
22
|
+
throw new Error('No account found on Bearby');
|
|
23
|
+
}
|
|
24
|
+
return [new BearbyAccount(web3.wallet.account.base58)];
|
|
22
25
|
}
|
|
23
26
|
async importAccount() {
|
|
24
27
|
throw new Error('Method not implemented.');
|
|
@@ -60,7 +63,7 @@ export class BearbyWallet {
|
|
|
60
63
|
* ```
|
|
61
64
|
*/
|
|
62
65
|
listenAccountChanges(callback) {
|
|
63
|
-
return web3.wallet.account.subscribe((address) => callback(address));
|
|
66
|
+
return web3.wallet.account.subscribe((address) => address && callback(address));
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* Subscribes to network changes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BearbyWallet.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,OAAO,YAAY;IACf,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC;IAEhC,IAAI;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,iBAAiB;QAC5B,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACzB,OAAO,IAAI,YAAY,EAAE,CAAC;SAC3B;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM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;CACF","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { BearbyAccount } from './BearbyAccount';\nimport { Wallet } from '../wallet/interface';\nimport { Network, Provider } from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\n\nexport class BearbyWallet implements Wallet {\n private walletName = WalletName.Bearby;\n\n public name(): WalletName {\n return this.walletName;\n }\n\n static async createIfInstalled(): Promise<Wallet | null> {\n if (web3.wallet.installed) {\n return new BearbyWallet();\n }\n return null;\n }\n\n public async accounts(): Promise<BearbyAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n if (!web3.wallet.account.base58) {\n throw new Error('No account found on Bearby');\n }\n return [new BearbyAccount(web3.wallet.account.base58)];\n }\n\n public async importAccount(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(): Promise<void> {\n throw new Error('Method not implemented.');\n }\n\n public async networkInfos(): Promise<Network> {\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n return networkInfos();\n }\n\n public async setRpcUrl(): Promise<void> {\n throw new Error(\n 'setRpcUrl is not yet implemented for the current provider.',\n );\n }\n\n public async generateNewAccount(): Promise<Provider> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Subscribes to account changes.\n *\n * @param callback - Callback to be called when the account changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenAccountChanges((base58) => {\n * console.log(base58);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenAccountChanges(callback: (address: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.account.subscribe(\n (address) => address && callback(address),\n );\n }\n\n /**\n * Subscribes to network changes.\n *\n * @param callback - Callback to be called when the network changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenNetworkChanges((network) => {\n * console.log(network);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenNetworkChanges(callback: (network: Network) => void): {\n unsubscribe: () => void;\n } {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return web3.wallet.network.subscribe((_) =>\n networkInfos().then((network) => callback(network)),\n );\n }\n\n /**\n * Connects to the wallet.\n *\n * @remarks\n * This method will attempt to establish a connection with the wallet.\n * If the connection fails, it will log the error message.\n */\n public async connect() {\n return web3.wallet.connect();\n }\n\n /**\n * Disconnects from the wallet.\n *\n * @remarks\n * This method will attempt to disconnect from the wallet.\n * If the disconnection fails, it will log the error message.\n */\n public async disconnect() {\n return web3.wallet.disconnect();\n }\n\n /**\n * Checks if the wallet is connected.\n *\n * @returns a boolean indicating whether the wallet is connected.\n */\n public async connected(): Promise<boolean> {\n return web3.wallet.connected;\n }\n\n /**\n * Checks if the wallet is enabled.\n *\n * @returns a boolean indicating whether the wallet is enabled.\n */\n public enabled(): boolean {\n return web3.wallet.enabled;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/bearbyWallet/utils/network.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,eAAO,MAAM,YAAY,QAAa,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/bearbyWallet/utils/network.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,eAAO,MAAM,YAAY,QAAa,QAAQ,OAAO,CAWpD,CAAC"}
|
|
@@ -2,13 +2,12 @@ import { web3 } from '@hicaru/bearby.js';
|
|
|
2
2
|
import { Mas } from '@massalabs/massa-web3';
|
|
3
3
|
export const networkInfos = async () => {
|
|
4
4
|
const { net } = await web3.wallet.network;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (res.error) {
|
|
5
|
+
const res = await web3.massa.getNodesStatus();
|
|
6
|
+
if (res.error || !res.result) {
|
|
8
7
|
throw new Error(res.error?.message || 'Bearby getNodesStatus error');
|
|
9
8
|
}
|
|
10
9
|
return {
|
|
11
|
-
name: net,
|
|
10
|
+
name: net ?? '',
|
|
12
11
|
chainId: BigInt(res.result.chain_id),
|
|
13
12
|
minimalFee: Mas.fromString(res.result.minimal_fees),
|
|
14
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/bearbyWallet/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAW,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAsB,EAAE;IACvD,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC1C,
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/bearbyWallet/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAW,MAAM,uBAAuB,CAAC;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,IAAsB,EAAE;IACvD,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC1C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;IAC9C,IAAI,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,IAAI,6BAA6B,CAAC,CAAC;KACtE;IACD,OAAO;QACL,IAAI,EAAE,GAAG,IAAI,EAAE;QACf,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;QACpC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC;KACpD,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { Mas, Network } from '@massalabs/massa-web3';\n\nexport const networkInfos = async (): Promise<Network> => {\n const { net } = await web3.wallet.network;\n const res = await web3.massa.getNodesStatus();\n if (res.error || !res.result) {\n throw new Error(res.error?.message || 'Bearby getNodesStatus error');\n }\n return {\n name: net ?? '',\n chainId: BigInt(res.result.chain_id),\n minimalFee: Mas.fromString(res.result.minimal_fees),\n };\n};\n"]}
|
package/dist/esm/errors/base.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/errors/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAmB3C,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC,YAAY,CAAW;IACvB,QAAQ,CAAU;IAClB,IAAI,CAAa;IAER,IAAI,GAAG,qBAAqB,CAAC;IACtC,YACE,YAAoB,EACpB,OAA4B,EAAE,IAAI,EAAE,UAAU,CAAC,YAAY,EAAE;QAE7D,KAAK,EAAE,CAAC;QAER,MAAM,cAAc,GAClB,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACnE,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ;YAClC,CAAC,CAAC,SAAS,IAAI,CAAC,QAAQ,wBAAwB;YAChD,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,cAA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,cAAc;YACd,cAAc;YACd,cAAc;SACf;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,MAAM,CAAC,CAAC;QAEhB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,YAAY,CAAC;QACjD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { ErrorCodes } from './utils/codes';\n\nexport type BaseErrorParameters = {\n code?: ErrorCodes;\n docsPath?: string;\n metaMessages?: string[];\n} & (\n | {\n cause?: never;\n details?: string;\n }\n | {\n cause: BaseError | Error;\n details?: never;\n }\n);\n\nexport type BaseErrorType = BaseError & { name: 'WalletProviderError' };\n\nexport class BaseError extends Error {\n metaMessages: string[];\n docsPath?: string;\n code: ErrorCodes;\n\n override name = 'WalletProviderError';\n constructor(\n shortMessage: string,\n args: BaseErrorParameters = { code: ErrorCodes.UnknownError },\n ) {\n super();\n\n const metaMessageStr =\n args.metaMessages?.map((msg) => `Meta: ${msg}`).join('\\n') || '';\n const docsMessageStr = args.docsPath\n ? `Docs: ${args.docsPath} for more information.`\n : '';\n\n const detailsMessage = args.details ? `Details: ${args.details}` : '';\n\n this.message = [\n shortMessage,\n metaMessageStr,\n docsMessageStr,\n detailsMessage,\n ]\n .filter(Boolean)\n .join('\\n\\n');\n\n this.metaMessages = args.metaMessages || [];\n this.docsPath = args.docsPath;\n this.code = args.code ?? ErrorCodes.UnknownError;\n this.cause = args.cause;\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { UserRejectionError } from '../userRejection';
|
|
|
2
2
|
export function isUserRejectionError(error) {
|
|
3
3
|
const bearbyUserRejectionErrorMessage = 'User rejected';
|
|
4
4
|
const massaUserRejectionErrorMessage = 'Action canceled by user';
|
|
5
|
-
return (error.message &&
|
|
5
|
+
return (!!error.message &&
|
|
6
6
|
(error.message.includes(bearbyUserRejectionErrorMessage) ||
|
|
7
7
|
error.message.includes(massaUserRejectionErrorMessage)));
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../../../src/errors/utils/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,UAAU,oBAAoB,CAAC,KAAY;IAC/C,MAAM,+BAA+B,GAAG,eAAe,CAAC;IACxD,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;IACjE,OAAO,CACL,KAAK,CAAC,OAAO;
|
|
1
|
+
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../../../src/errors/utils/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,UAAU,oBAAoB,CAAC,KAAY;IAC/C,MAAM,+BAA+B,GAAG,eAAe,CAAC;IACxD,MAAM,8BAA8B,GAAG,yBAAyB,CAAC;IACjE,OAAO,CACL,CAAC,CAAC,KAAK,CAAC,OAAO;QACf,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,+BAA+B,CAAC;YACtD,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,CAC1D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,aAAqB,EAAE,KAAY;IAC9D,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE;QAC/B,OAAO,IAAI,kBAAkB,CAAC;YAC5B,aAAa,EAAE,aAAa;YAC5B,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;KACJ;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { UserRejectionError } from '../userRejection';\n\nexport function isUserRejectionError(error: Error): boolean {\n const bearbyUserRejectionErrorMessage = 'User rejected';\n const massaUserRejectionErrorMessage = 'Action canceled by user';\n return (\n !!error.message &&\n (error.message.includes(bearbyUserRejectionErrorMessage) ||\n error.message.includes(massaUserRejectionErrorMessage))\n );\n}\n\nexport function errorHandler(operationName: string, error: Error): Error {\n if (isUserRejectionError(error)) {\n return new UserRejectionError({\n operationName: operationName,\n cause: error,\n });\n }\n\n return error;\n}\n"]}
|
|
@@ -33,6 +33,6 @@ export declare class MassaStationAccount implements Provider {
|
|
|
33
33
|
getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents>;
|
|
34
34
|
getNodeStatus(): Promise<NodeStatusInfo>;
|
|
35
35
|
getStorageKeys(address: string, filter?: Uint8Array | string, final?: boolean): Promise<Uint8Array[]>;
|
|
36
|
-
readStorage(address: string, keys: Uint8Array[] | string[], final?: boolean): Promise<Uint8Array[]>;
|
|
36
|
+
readStorage(address: string, keys: Uint8Array[] | string[], final?: boolean): Promise<(Uint8Array | null)[]>;
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=MassaStationAccount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,OAAO,EACP,YAAY,EAEZ,cAAc,EACd,WAAW,EAIX,OAAO,EACP,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EACX,aAAa,EAEb,QAAQ,EAGT,MAAM,uBAAuB,CAAC;AAK/B;;;;;;;GAOG;AACH,qBAAa,mBAAoB,YAAW,QAAQ;IAIzC,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,MAAM;IAJ5B,OAAO,CAAC,aAAa,CAA0B;gBAGtC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM;IAG5B,IAAI,YAAY,IAAI,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AO,CAAC,cAAc,CAAC;IAMxC,cAAc,CACzB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,UAAU,GAAG,MAAyB,EAC9C,KAAK,UAAO,GACX,OAAO,CAAC,UAAU,EAAE,CAAC;IAQX,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,EAC7B,KAAK,UAAO,GACX,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC;CASlC"}
|
|
@@ -108,11 +108,13 @@ export class MassaStationAccount {
|
|
|
108
108
|
async callSC(params) {
|
|
109
109
|
// convert parameter to base64
|
|
110
110
|
let args = '';
|
|
111
|
-
if (params.parameter
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
if (params.parameter) {
|
|
112
|
+
if (params.parameter instanceof Uint8Array) {
|
|
113
|
+
args = uint8ArrayToBase64(params.parameter);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
args = argsToBase64(params.parameter);
|
|
117
|
+
}
|
|
116
118
|
}
|
|
117
119
|
let fee = params?.fee ?? (await this.minimalFee());
|
|
118
120
|
const body = {
|
|
@@ -139,7 +141,7 @@ export class MassaStationAccount {
|
|
|
139
141
|
}
|
|
140
142
|
async readSC(params) {
|
|
141
143
|
// Gas amount check
|
|
142
|
-
if (params.maxGas > MAX_GAS_CALL) {
|
|
144
|
+
if (params.maxGas && params.maxGas > MAX_GAS_CALL) {
|
|
143
145
|
throw new Error(`
|
|
144
146
|
The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of
|
|
145
147
|
${MAX_GAS_CALL.toString()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAA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ACf,SAA8B,IAAI,UAAU,EAAE,EAC9C,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,WAAW,GACf,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC3D,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnD,GAAG;YACH,OAAO;SACR,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n strToBytes,\n rpcTypes,\n StorageCost,\n formatMas,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n const balances = result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n return addresses.map((address) => {\n const balance = result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n try {\n const { result } = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(result.signature),\n );\n\n return {\n publicKey: result.publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n return client.getMinimalFee();\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(type, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler('callSmartContract', error);\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.executeReadOnlyCall(readOnlyParams);\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + coins;\n const fee = params.fee || (await this.minimalFee());\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n maxCoins: maxCoins.toString(), // SmartContract deployment costs\n coins: coins.toString(),\n fee: fee.toString(),\n parameters: uint8ArrayToBase64(parameters),\n description: `${formatMas(\n coins,\n )} $MAS coins allocated to datastore + ${formatMas(\n fee,\n )} $MAS fee for operation`,\n };\n\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationAccount.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;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AQ,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC3D,OAAO,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAK,GAAG,IAAI;QAEZ,mGAAmG;QACnG,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QACjC,MAAM,OAAO,GAAqB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACnD,GAAG;YACH,OAAO;SACR,CAAC,CAAC,CAAC;QACJ,OAAO,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["import { getRequest, postRequest } from './RequestHandler';\nimport { walletApiUrl, MASSA_STATION_URL } from './MassaStationWallet';\nimport {\n argsToBase64,\n base64ToByteArray,\n uint8ArrayToBase64,\n} from '../utils/base64';\nimport {\n DeploySCFunctionBody,\n ExecuteFunctionBody,\n MSAccountSignPayload,\n MSAccountSignResp,\n MSBalancesResp,\n MSSendOperationResp,\n} from './types';\nimport { errorHandler } from '../errors/utils/errorHandler';\nimport { operationType } from '../utils/constants';\nimport {\n Address,\n CallSCParams,\n DatastoreEntry,\n DeploySCParams,\n EventFilter,\n formatNodeStatusObject,\n Mas,\n MAX_GAS_CALL,\n Network,\n NodeStatusInfo,\n Operation,\n OperationOptions,\n OperationStatus,\n Provider,\n ReadSCData,\n ReadSCParams,\n SignedData,\n SignOptions,\n SmartContract,\n strToBytes,\n rpcTypes,\n StorageCost,\n formatMas,\n} from '@massalabs/massa-web3';\nimport { getClient, networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport bs58check from 'bs58check';\n\n/**\n * This module contains the MassaStationAccount class. It is responsible for representing an account in\n * the MassaStation wallet.\n *\n * @remarks\n * This class provides methods to interact with MassaStation account's {@link balance} and to {@link sign} messages.\n *\n */\nexport class MassaStationAccount implements Provider {\n private _providerName = WalletName.MassaWallet;\n\n constructor(\n public address: string,\n public accountName: string,\n ) {}\n\n get providerName(): string {\n return this._providerName;\n }\n\n public async balance(final = false): Promise<bigint> {\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n const balances = result.addressesAttributes[this.address].balance;\n\n return Mas.fromString(final ? balances.final : balances.pending);\n }\n\n async balanceOf(\n addresses: string[],\n final = false,\n ): Promise<{ address: string; balance: bigint }[]> {\n const queryParams = new URLSearchParams();\n\n queryParams.append('attributes', 'balance');\n addresses.forEach((address) => {\n queryParams.append('addresses', address);\n });\n\n const { result } = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n return addresses.map((address) => {\n const balance = result.addressesAttributes[address].balance;\n\n return {\n address,\n balance: Mas.fromString(final ? balance.final : balance.pending),\n };\n });\n }\n\n public async sign(\n data: Uint8Array | string,\n opts?: SignOptions,\n ): Promise<SignedData> {\n const signData: MSAccountSignPayload = {\n description: opts?.description ?? '',\n message: typeof data === 'string' ? data : new TextDecoder().decode(data),\n DisplayData: opts?.displayData ?? true,\n };\n\n try {\n const { result } = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58\n const signature = bs58check.encode(\n await base64ToByteArray(result.signature),\n );\n\n return {\n publicKey: result.publicKey,\n signature,\n };\n } catch (error) {\n throw errorHandler(operationType.Sign, error);\n }\n }\n\n private async minimalFee(): Promise<bigint> {\n const client = await getClient();\n return client.getMinimalFee();\n }\n\n private async rollOperation(\n type: operationType.BuyRolls | operationType.SellRolls,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n let fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n side: type === operationType.BuyRolls ? 'buy' : 'sell',\n };\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(type, error);\n }\n }\n\n public async buyRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.BuyRolls, amount, opts);\n }\n\n public async sellRolls(\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n return this.rollOperation(operationType.SellRolls, amount, opts);\n }\n\n async transfer(\n to: Address | string,\n amount: bigint,\n opts?: OperationOptions,\n ): Promise<Operation> {\n const fee = opts?.fee ?? (await this.minimalFee());\n\n const body = {\n fee: fee.toString(),\n amount: amount.toString(),\n recipientAddress: to.toString(),\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler(operationType.SendTransaction, error);\n }\n }\n\n public async callSC(params: CallSCParams): Promise<Operation> {\n // convert parameter to base64\n let args = '';\n if (params.parameter) {\n if (params.parameter instanceof Uint8Array) {\n args = uint8ArrayToBase64(params.parameter);\n } else {\n args = argsToBase64(params.parameter);\n }\n }\n\n let fee = params?.fee ?? (await this.minimalFee());\n\n const body: ExecuteFunctionBody = {\n nickname: this.accountName,\n name: params.func,\n at: params.target,\n args,\n coins: params.coins ? Number(params.coins) : 0,\n fee: fee.toString(),\n // If maxGas is not provided, estimation will be done by MS\n maxGas: params.maxGas ? params.maxGas.toString() : '',\n async: true,\n };\n\n try {\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n return new Operation(this, result.operationId);\n } catch (error) {\n throw errorHandler('callSmartContract', error);\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n public async readSC(params: ReadSCParams): Promise<ReadSCData> {\n // Gas amount check\n if (params.maxGas && params.maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${params.maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n const client = await getClient();\n\n const fee = params?.fee ?? (await this.minimalFee());\n const caller = params.caller ?? this.address;\n const args = params.parameter ?? new Uint8Array();\n const readOnlyParams = {\n ...params,\n caller,\n fee,\n parameter:\n args instanceof Uint8Array ? args : Uint8Array.from(args.serialize()),\n };\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.executeReadOnlyCall(readOnlyParams);\n }\n\n public async deploySC(params: DeploySCParams): Promise<SmartContract> {\n try {\n const args = params.parameter ?? new Uint8Array();\n const parameters = args instanceof Uint8Array ? args : args.serialize();\n const coins = params.coins ?? 0n; // If coins is undefined, some vesions of station will have a panic\n const maxCoins =\n params.maxCoins ??\n StorageCost.smartContract(params.byteCode.length) + coins;\n const fee = params.fee || (await this.minimalFee());\n\n const body: DeploySCFunctionBody = {\n nickname: this.accountName,\n smartContract: uint8ArrayToBase64(params.byteCode),\n maxCoins: maxCoins.toString(), // SmartContract deployment costs\n coins: coins.toString(),\n fee: fee.toString(),\n parameters: uint8ArrayToBase64(parameters),\n description: `${formatMas(\n coins,\n )} $MAS coins allocated to datastore + ${formatMas(\n fee,\n )} $MAS fee for operation`,\n };\n\n const { result } = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = result?.operationId;\n\n if (!operationId) throw new Error('Operation ID not found');\n\n const operation = new Operation(this, operationId);\n const deployedAddress = await operation.getDeployedAddress(\n params.waitFinalExecution,\n );\n\n return new SmartContract(this, deployedAddress);\n } catch (error) {\n throw new Error(`Error during smart contract deployment: ${error}`);\n }\n }\n\n executeSC(): Promise<Operation> {\n throw new Error('Method not implemented.');\n }\n\n public async getOperationStatus(opId: string): Promise<OperationStatus> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getOperationStatus(opId);\n }\n\n public async getEvents(filter: EventFilter): Promise<rpcTypes.OutputEvents> {\n const client = await getClient();\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n return client.getEvents(filter);\n }\n\n public async getNodeStatus(): Promise<NodeStatusInfo> {\n const client = await getClient();\n const status = await client.status();\n return formatNodeStatusObject(status);\n }\n\n public async getStorageKeys(\n address: string,\n filter: Uint8Array | string = new Uint8Array(),\n final = true,\n ): Promise<Uint8Array[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const filterBytes: Uint8Array =\n typeof filter === 'string' ? strToBytes(filter) : filter;\n return client.getDataStoreKeys(address, filterBytes, final);\n }\n\n public async readStorage(\n address: string,\n keys: Uint8Array[] | string[],\n final = true,\n ): Promise<(Uint8Array | null)[]> {\n // This implementation is wrong. We should use massaStation instead of targeting the node directly.\n const client = await getClient();\n const entries: DatastoreEntry[] = keys.map((key) => ({\n key,\n address,\n }));\n return client.getDatastoreEntries(entries, final);\n }\n}\n"]}
|
|
@@ -23,7 +23,7 @@ export async function isMassaWalletEnabled() {
|
|
|
23
23
|
try {
|
|
24
24
|
const { result } = await fetchPluginData();
|
|
25
25
|
const walletPlugin = findWalletPlugin(result);
|
|
26
|
-
return walletPlugin && walletPlugin.status === 'Up';
|
|
26
|
+
return !!walletPlugin && walletPlugin.status === 'Up';
|
|
27
27
|
}
|
|
28
28
|
catch (_) {
|
|
29
29
|
return false;
|