@massalabs/wallet-provider 3.1.2-dev.20250207102809 → 3.1.2-dev.20250212094426

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.
Files changed (35) hide show
  1. package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -1
  2. package/dist/esm/massaStation/MassaStationAccount.js +35 -31
  3. package/dist/esm/massaStation/MassaStationAccount.js.map +1 -1
  4. package/dist/esm/massaStation/MassaStationDiscovery.d.ts.map +1 -1
  5. package/dist/esm/massaStation/MassaStationDiscovery.js +15 -9
  6. package/dist/esm/massaStation/MassaStationDiscovery.js.map +1 -1
  7. package/dist/esm/massaStation/MassaStationWallet.d.ts +34 -0
  8. package/dist/esm/massaStation/MassaStationWallet.d.ts.map +1 -1
  9. package/dist/esm/massaStation/MassaStationWallet.js +62 -19
  10. package/dist/esm/massaStation/MassaStationWallet.js.map +1 -1
  11. package/dist/esm/massaStation/RequestHandler.d.ts +0 -6
  12. package/dist/esm/massaStation/RequestHandler.d.ts.map +1 -1
  13. package/dist/esm/massaStation/RequestHandler.js +23 -25
  14. package/dist/esm/massaStation/RequestHandler.js.map +1 -1
  15. package/dist/esm/massaStation/types.d.ts +22 -0
  16. package/dist/esm/massaStation/types.d.ts.map +1 -1
  17. package/dist/esm/massaStation/types.js +5 -0
  18. package/dist/esm/massaStation/types.js.map +1 -1
  19. package/dist/esm/massaStation/utils/network.d.ts.map +1 -1
  20. package/dist/esm/massaStation/utils/network.js +16 -7
  21. package/dist/esm/massaStation/utils/network.js.map +1 -1
  22. package/dist/esm/massaStation/utils/standalone.d.ts +2 -0
  23. package/dist/esm/massaStation/utils/standalone.d.ts.map +1 -0
  24. package/dist/esm/massaStation/utils/standalone.js +5 -0
  25. package/dist/esm/massaStation/utils/standalone.js.map +1 -0
  26. package/dist/esm/metamaskSnap/snap.d.ts.map +1 -1
  27. package/dist/esm/metamaskSnap/snap.js +2 -1
  28. package/dist/esm/metamaskSnap/snap.js.map +1 -1
  29. package/dist/esm/walletsManager/walletList.d.ts.map +1 -1
  30. package/dist/esm/walletsManager/walletList.js +1 -0
  31. package/dist/esm/walletsManager/walletList.js.map +1 -1
  32. package/dist/esm/walletsManager/walletsListener.d.ts.map +1 -1
  33. package/dist/esm/walletsManager/walletsListener.js +1 -0
  34. package/dist/esm/walletsManager/walletsListener.js.map +1 -1
  35. package/package.json +1 -1
@@ -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,MAAM,CAEzB;IAEY,OAAO,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAY9C,SAAS,CACb,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,UAAQ,GACZ,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAwBrC,IAAI,CACf,IAAI,EAAE,UAAU,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,UAAU,CAAC;YA2BR,UAAU;YAKV,aAAa;IAwBd,QAAQ,CACnB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,gBAAgB,GACtB,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OAAO,CAAC,aAAa,CAAC;IA4CrE,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAIlB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAM1D,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAM9D,aAAa,IAAI,OAAO,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,UAAU,EAAE,CAAC;CASzB"}
@@ -27,10 +27,8 @@ export class MassaStationAccount {
27
27
  return this._providerName;
28
28
  }
29
29
  async balance(final = false) {
30
- const res = await getRequest(`${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`);
31
- if (res.isError)
32
- throw res.error;
33
- const balances = res.result.addressesAttributes[this.address].balance;
30
+ const { result } = await getRequest(`${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`);
31
+ const balances = result.addressesAttributes[this.address].balance;
34
32
  return Mas.fromString(final ? balances.final : balances.pending);
35
33
  }
36
34
  async balanceOf(addresses, final = false) {
@@ -39,11 +37,9 @@ export class MassaStationAccount {
39
37
  addresses.forEach((address) => {
40
38
  queryParams.append('addresses', address);
41
39
  });
42
- const res = await getRequest(`${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`);
43
- if (res.isError)
44
- throw res.error;
40
+ const { result } = await getRequest(`${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`);
45
41
  return addresses.map((address) => {
46
- const balance = res.result.addressesAttributes[address].balance;
42
+ const balance = result.addressesAttributes[address].balance;
47
43
  return {
48
44
  address,
49
45
  balance: Mas.fromString(final ? balance.final : balance.pending),
@@ -56,16 +52,18 @@ export class MassaStationAccount {
56
52
  message: typeof data === 'string' ? data : new TextDecoder().decode(data),
57
53
  DisplayData: opts?.displayData ?? true,
58
54
  };
59
- const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/signMessage`, signData);
60
- if (res.isError) {
61
- throw errorHandler(operationType.Sign, res.error);
55
+ try {
56
+ const { result } = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/signMessage`, signData);
57
+ // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58
58
+ const signature = bs58check.encode(await base64ToByteArray(result.signature));
59
+ return {
60
+ publicKey: result.publicKey,
61
+ signature,
62
+ };
63
+ }
64
+ catch (error) {
65
+ throw errorHandler(operationType.Sign, error);
62
66
  }
63
- // MS Wallet encodes signature in base64... so we need to decode it en re-encode it in base58
64
- const signature = bs58check.encode(await base64ToByteArray(res.result.signature));
65
- return {
66
- publicKey: res.result.publicKey,
67
- signature,
68
- };
69
67
  }
70
68
  async minimalFee() {
71
69
  const client = await getClient();
@@ -78,11 +76,13 @@ export class MassaStationAccount {
78
76
  amount: amount.toString(),
79
77
  side: type === operationType.BuyRolls ? 'buy' : 'sell',
80
78
  };
81
- const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/rolls`, body);
82
- if (res.isError) {
83
- throw errorHandler(type, res.error);
79
+ try {
80
+ const { result } = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/rolls`, body);
81
+ return new Operation(this, result.operationId);
82
+ }
83
+ catch (error) {
84
+ throw errorHandler(type, error);
84
85
  }
85
- return new Operation(this, res.result.operationId);
86
86
  }
87
87
  async buyRolls(amount, opts) {
88
88
  return this.rollOperation(operationType.BuyRolls, amount, opts);
@@ -97,11 +97,13 @@ export class MassaStationAccount {
97
97
  amount: amount.toString(),
98
98
  recipientAddress: to.toString(),
99
99
  };
100
- const res = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/transfer`, body);
101
- if (res.isError) {
102
- throw errorHandler(operationType.SendTransaction, res.error);
100
+ try {
101
+ const { result } = await postRequest(`${walletApiUrl()}/accounts/${this.accountName}/transfer`, body);
102
+ return new Operation(this, result.operationId);
103
+ }
104
+ catch (error) {
105
+ throw errorHandler(operationType.SendTransaction, error);
103
106
  }
104
- return new Operation(this, res.result.operationId);
105
107
  }
106
108
  async callSC(params) {
107
109
  // convert parameter to base64
@@ -124,11 +126,13 @@ export class MassaStationAccount {
124
126
  maxGas: params.maxGas ? params.maxGas.toString() : '',
125
127
  async: true,
126
128
  };
127
- const res = await postRequest(`${MASSA_STATION_URL}cmd/executeFunction`, body);
128
- if (res.isError) {
129
- throw errorHandler('callSmartContract', res.error);
129
+ try {
130
+ const { result } = await postRequest(`${MASSA_STATION_URL}cmd/executeFunction`, body);
131
+ return new Operation(this, result.operationId);
132
+ }
133
+ catch (error) {
134
+ throw errorHandler('callSmartContract', error);
130
135
  }
131
- return new Operation(this, res.result.operationId);
132
136
  }
133
137
  async networkInfos() {
134
138
  return networkInfos();
@@ -171,8 +175,8 @@ export class MassaStationAccount {
171
175
  parameters: uint8ArrayToBase64(parameters),
172
176
  description: `${formatMas(coins)} $MAS coins allocated to datastore + ${formatMas(fee)} $MAS fee for operation`,
173
177
  };
174
- const res = await postRequest(`${MASSA_STATION_URL}cmd/deploySC`, body);
175
- const operationId = res.result?.operationId;
178
+ const { result } = await postRequest(`${MASSA_STATION_URL}cmd/deploySC`, body);
179
+ const operationId = result?.operationId;
176
180
  if (!operationId)
177
181
  throw new Error('Operation ID not found');
178
182
  const operation = new Operation(this, operationId);
@@ -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,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EACL,YAAY,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,MAAM,EAAE,CAAC;QACrC,OAAO,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAEM,KAAK,CAAC,cAAc,CACzB,OAAe,EACf,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 res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?attributes=balance&addresses=${this.address}`,\n );\n\n if (res.isError) throw res.error;\n\n const balances = res.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 res = await getRequest<MSBalancesResp>(\n `${MASSA_STATION_URL}massa/addresses?${queryParams.toString()}`,\n );\n\n if (res.isError) throw res.error;\n\n return addresses.map((address) => {\n const balance = res.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 const res = await postRequest<MSAccountSignResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/signMessage`,\n signData,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.Sign, res.error);\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(res.result.signature),\n );\n\n return {\n publicKey: res.result.publicKey,\n signature,\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\n const res = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/rolls`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(type, res.error);\n }\n return new Operation(this, res.result.operationId);\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 const res = await postRequest<MSSendOperationResp>(\n `${walletApiUrl()}/accounts/${this.accountName}/transfer`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler(operationType.SendTransaction, res.error);\n }\n\n return new Operation(this, res.result.operationId);\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 const res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/executeFunction`,\n body,\n );\n\n if (res.isError) {\n throw errorHandler('callSmartContract', res.error);\n }\n return new Operation(this, res.result.operationId);\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 res = await postRequest<MSSendOperationResp>(\n `${MASSA_STATION_URL}cmd/deploySC`,\n body,\n );\n\n const operationId = res.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,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AM,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 +1 @@
1
- {"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAmBA,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC,CAGhE;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAU7D"}
1
+ {"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAsBA,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,OAAO,CAAC,CAOhE;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ7D"}
@@ -1,26 +1,32 @@
1
+ import { MASSA_STATION_URL } from './MassaStationWallet';
1
2
  import { getRequest } from './RequestHandler';
2
3
  // Constants for URLs and plugin information
3
- const MASSA_STATION_URL = 'https://station.massa/plugin-manager';
4
4
  const PLUGIN_NAME = 'Massa Wallet';
5
5
  const PLUGIN_AUTHOR = 'Massa Labs';
6
6
  const TIMEOUT = 4000;
7
7
  async function fetchPluginData() {
8
- return getRequest(MASSA_STATION_URL, TIMEOUT);
8
+ return getRequest(MASSA_STATION_URL + 'plugin-manager', TIMEOUT);
9
9
  }
10
10
  function findWalletPlugin(plugins) {
11
11
  return plugins.find((plugin) => plugin.name === PLUGIN_NAME && plugin.author === PLUGIN_AUTHOR);
12
12
  }
13
13
  export async function isMassaStationAvailable() {
14
- const response = await fetchPluginData();
15
- return !response.isError;
14
+ try {
15
+ await fetchPluginData();
16
+ return true;
17
+ }
18
+ catch (_) {
19
+ return false;
20
+ }
16
21
  }
17
22
  export async function isMassaWalletEnabled() {
18
- const response = await fetchPluginData();
19
- if (response.isError) {
20
- console.warn('Error fetching plugin data:', response.error);
23
+ try {
24
+ const { result } = await fetchPluginData();
25
+ const walletPlugin = findWalletPlugin(result);
26
+ return walletPlugin && walletPlugin.status === 'Up';
27
+ }
28
+ catch (_) {
21
29
  return false;
22
30
  }
23
- const walletPlugin = findWalletPlugin(response.result);
24
- return walletPlugin && walletPlugin.status === 'Up';
25
31
  }
26
32
  //# sourceMappingURL=MassaStationDiscovery.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnE,4CAA4C;AAC5C,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AACjE,MAAM,WAAW,GAAG,cAAc,CAAC;AACnC,MAAM,aAAa,GAAG,YAAY,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,KAAK,UAAU,eAAe;IAC5B,OAAO,UAAU,CAAe,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAqB;IAC7C,OAAO,OAAO,CAAC,IAAI,CACjB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,CAC3E,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,MAAM,QAAQ,GAAG,MAAM,eAAe,EAAE,CAAC;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;AAC3B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,QAAQ,GAAG,MAAM,eAAe,EAAE,CAAC;IAEzC,IAAI,QAAQ,CAAC,OAAO,EAAE;QACpB,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC5D,OAAO,KAAK,CAAC;KACd;IAED,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvD,OAAO,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,IAAI,CAAC;AACtD,CAAC","sourcesContent":["import { JsonRpcResponseData, getRequest } from './RequestHandler';\nimport { PluginInfo } from './types';\n\n// Constants for URLs and plugin information\nconst MASSA_STATION_URL = 'https://station.massa/plugin-manager';\nconst PLUGIN_NAME = 'Massa Wallet';\nconst PLUGIN_AUTHOR = 'Massa Labs';\nconst TIMEOUT = 4000;\n\nasync function fetchPluginData(): Promise<JsonRpcResponseData<PluginInfo[]>> {\n return getRequest<PluginInfo[]>(MASSA_STATION_URL, TIMEOUT);\n}\n\nfunction findWalletPlugin(plugins: PluginInfo[]): PluginInfo | undefined {\n return plugins.find(\n (plugin) => plugin.name === PLUGIN_NAME && plugin.author === PLUGIN_AUTHOR,\n );\n}\n\nexport async function isMassaStationAvailable(): Promise<boolean> {\n const response = await fetchPluginData();\n return !response.isError;\n}\n\nexport async function isMassaWalletEnabled(): Promise<boolean> {\n const response = await fetchPluginData();\n\n if (response.isError) {\n console.warn('Error fetching plugin data:', response.error);\n return false;\n }\n\n const walletPlugin = findWalletPlugin(response.result);\n return walletPlugin && walletPlugin.status === 'Up';\n}\n"]}
1
+ {"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAuB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnE,4CAA4C;AAC5C,MAAM,WAAW,GAAG,cAAc,CAAC;AACnC,MAAM,aAAa,GAAG,YAAY,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,KAAK,UAAU,eAAe;IAC5B,OAAO,UAAU,CACf,iBAAiB,GAAG,gBAAgB,EACpC,OAAO,CACR,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAqB;IAC7C,OAAO,OAAO,CAAC,IAAI,CACjB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,MAAM,KAAK,aAAa,CAC3E,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,IAAI;QACF,MAAM,eAAe,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,eAAe,EAAE,CAAC;QAC3C,MAAM,YAAY,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC9C,OAAO,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,IAAI,CAAC;KACrD;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC","sourcesContent":["import { MASSA_STATION_URL } from './MassaStationWallet';\nimport { JsonRpcResponseData, getRequest } from './RequestHandler';\nimport { PluginInfo } from './types';\n\n// Constants for URLs and plugin information\nconst PLUGIN_NAME = 'Massa Wallet';\nconst PLUGIN_AUTHOR = 'Massa Labs';\nconst TIMEOUT = 4000;\n\nasync function fetchPluginData(): Promise<JsonRpcResponseData<PluginInfo[]>> {\n return getRequest<PluginInfo[]>(\n MASSA_STATION_URL + 'plugin-manager',\n TIMEOUT,\n );\n}\n\nfunction findWalletPlugin(plugins: PluginInfo[]): PluginInfo | undefined {\n return plugins.find(\n (plugin) => plugin.name === PLUGIN_NAME && plugin.author === PLUGIN_AUTHOR,\n );\n}\n\nexport async function isMassaStationAvailable(): Promise<boolean> {\n try {\n await fetchPluginData();\n return true;\n } catch (_) {\n return false;\n }\n}\n\nexport async function isMassaWalletEnabled(): Promise<boolean> {\n try {\n const { result } = await fetchPluginData();\n const walletPlugin = findWalletPlugin(result);\n return walletPlugin && walletPlugin.status === 'Up';\n } catch (_) {\n return false;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { MassaStationAccount } from './MassaStationAccount';
2
+ import { AddUpdateSignRuleResponse, Config, SignRule } from './types';
2
3
  import { Wallet } from '../wallet/interface';
3
4
  import { Network } from '@massalabs/massa-web3';
4
5
  import { WalletName } from '../wallet';
@@ -58,5 +59,38 @@ export declare class MassaStationWallet implements Wallet {
58
59
  * Always returns `true` because the station is always enabled by default.
59
60
  */
60
61
  enabled(): boolean;
62
+ /**
63
+ * Retrieves the configuration from the MS Wallet api.
64
+ *
65
+ * @returns The configuration of MS wallet.
66
+ */
67
+ getConfig(): Promise<Config>;
68
+ /**
69
+ * Adds a new signing rule to the MassaStation wallet.
70
+ *
71
+ * @param accountName - The name of the account.
72
+ * @param rule - The signing rule to add.
73
+ * @param desc - Custom description of the new rule creation.
74
+ * @returns A Promise that resolves when the rule is successfully added.
75
+ */
76
+ addSignRule(accountName: string, rule: SignRule, desc?: string): Promise<AddUpdateSignRuleResponse>;
77
+ /**
78
+ * Edits an existing signing rule in the MassaStation wallet.
79
+ * Modifying the contract or ruleType will result in a new rule being created with a new Id.
80
+ *
81
+ * @param accountName - The name of the account.
82
+ * @param rule - The updated signing rule.
83
+ * @param desc - Custom description of the rule update.
84
+ * @returns A Promise that resolves when the rule is successfully edited.
85
+ */
86
+ editSignRule(accountName: string, rule: SignRule, desc?: string): Promise<AddUpdateSignRuleResponse>;
87
+ /**
88
+ * Deletes a signing rule from the MassaStation wallet.
89
+ *
90
+ * @param accountName - The name of the account.
91
+ * @param ruleId - The Id of the sign rule.
92
+ * @returns A Promise that resolves when the rule is successfully deleted.
93
+ */
94
+ deleteSignRule(accountName: string, ruleId: string): Promise<void>;
61
95
  }
62
96
  //# sourceMappingURL=MassaStationWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationWallet.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D;;GAEG;AAEH,wBAAgB,YAAY,IAAI,MAAM,CAOrC;AAMD;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,MAAM;IAC/C,OAAO,CAAC,UAAU,CAA0B;IAE5C,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,cAAc,CAAU;IAEzB,IAAI,IAAI,UAAU;WAIZ,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAO3C,QAAQ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AM,EACnB,IAAI,EAAE,QAAQ,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,yBAAyB,CAAC;IAcrC;;;;;;;;OAQG;IACU,YAAY,CACvB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,QAAQ,EACd,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,yBAAyB,CAAC;IAerC;;;;;;OAMG;IACU,cAAc,CACzB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;CAKjB"}
@@ -1,10 +1,11 @@
1
1
  import { deleteRequest, getRequest, postRequest, putRequest, } from './RequestHandler';
2
2
  import { MassaStationAccount } from './MassaStationAccount';
3
- import { MassaStationAccountStatus } from './types';
3
+ import { MassaStationAccountStatus, } from './types';
4
4
  import { EventEmitter } from 'eventemitter3';
5
5
  import { networkInfos } from './utils/network';
6
6
  import { WalletName } from '../wallet';
7
7
  import { isMassaWalletEnabled } from './MassaStationDiscovery';
8
+ import { isStandalone } from './utils/standalone';
8
9
  /**
9
10
  * MassaStation url
10
11
  */
@@ -14,8 +15,7 @@ export const MASSA_STATION_URL = 'https://station.massa/';
14
15
  */
15
16
  export function walletApiUrl() {
16
17
  // This is a hack to detect that MS wallet is working in standalone mode
17
- // dev only usage
18
- if (typeof window !== 'undefined' && window.massaWallet?.standalone) {
18
+ if (isStandalone()) {
19
19
  return `http://localhost:8080/api`;
20
20
  }
21
21
  return `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api`;
@@ -37,16 +37,13 @@ export class MassaStationWallet {
37
37
  return this.walletName;
38
38
  }
39
39
  static async createIfInstalled() {
40
- if (await isMassaWalletEnabled()) {
40
+ if (isStandalone() || (await isMassaWalletEnabled())) {
41
41
  return new MassaStationWallet();
42
42
  }
43
43
  return null;
44
44
  }
45
45
  async accounts() {
46
46
  const res = await getRequest(walletApiUrl() + '/accounts');
47
- if (res.isError) {
48
- throw res.error;
49
- }
50
47
  return res.result
51
48
  .filter((account) => {
52
49
  return account.status === MassaStationAccountStatus.OK;
@@ -56,27 +53,19 @@ export class MassaStationWallet {
56
53
  });
57
54
  }
58
55
  async importAccount(publicKey, privateKey) {
59
- const res = await putRequest(walletApiUrl() + '/accounts', {
56
+ await putRequest(walletApiUrl() + '/accounts', {
60
57
  publicKey,
61
58
  privateKey,
62
59
  });
63
- if (res.isError) {
64
- throw res.error;
65
- }
66
60
  }
67
61
  async deleteAccount(address) {
68
62
  // get all accounts and find the account to delete
69
63
  const allAccounts = await getRequest(walletApiUrl() + '/accounts');
70
- if (allAccounts.isError)
71
- throw allAccounts.error;
72
64
  const accountToDelete = allAccounts.result.find((account) => account.address === address);
73
65
  if (!accountToDelete) {
74
66
  throw new Error('Account not found');
75
67
  }
76
- const res = await deleteRequest(`${walletApiUrl()}/accounts/${accountToDelete.nickname}`);
77
- if (res.isError) {
78
- throw res.error;
79
- }
68
+ await deleteRequest(`${walletApiUrl()}/accounts/${accountToDelete.nickname}`);
80
69
  }
81
70
  async networkInfos() {
82
71
  return networkInfos();
@@ -92,8 +81,6 @@ export class MassaStationWallet {
92
81
  */
93
82
  async generateNewAccount(name) {
94
83
  const response = await postRequest(walletApiUrl() + '/accounts/' + name, {});
95
- if (response.isError)
96
- throw response.error;
97
84
  return new MassaStationAccount(response.result.address, response.result.nickname);
98
85
  }
99
86
  listenAccountChanges() {
@@ -150,5 +137,61 @@ export class MassaStationWallet {
150
137
  enabled() {
151
138
  return true;
152
139
  }
140
+ /**
141
+ * Retrieves the configuration from the MS Wallet api.
142
+ *
143
+ * @returns The configuration of MS wallet.
144
+ */
145
+ async getConfig() {
146
+ const { result } = await getRequest(walletApiUrl() + '/config');
147
+ return result;
148
+ }
149
+ /**
150
+ * Adds a new signing rule to the MassaStation wallet.
151
+ *
152
+ * @param accountName - The name of the account.
153
+ * @param rule - The signing rule to add.
154
+ * @param desc - Custom description of the new rule creation.
155
+ * @returns A Promise that resolves when the rule is successfully added.
156
+ */
157
+ async addSignRule(accountName, rule, desc) {
158
+ const { result } = await postRequest(walletApiUrl() + '/accounts/' + accountName + '/signrules', {
159
+ description: desc,
160
+ name: rule.name,
161
+ ruleType: rule.ruleType,
162
+ contract: rule.contract,
163
+ enabled: rule.enabled,
164
+ });
165
+ return result;
166
+ }
167
+ /**
168
+ * Edits an existing signing rule in the MassaStation wallet.
169
+ * Modifying the contract or ruleType will result in a new rule being created with a new Id.
170
+ *
171
+ * @param accountName - The name of the account.
172
+ * @param rule - The updated signing rule.
173
+ * @param desc - Custom description of the rule update.
174
+ * @returns A Promise that resolves when the rule is successfully edited.
175
+ */
176
+ async editSignRule(accountName, rule, desc) {
177
+ const { result } = await putRequest(walletApiUrl() + '/accounts/' + accountName + '/signrules/' + rule.id, {
178
+ description: desc,
179
+ name: rule.name,
180
+ ruleType: rule.ruleType,
181
+ contract: rule.contract,
182
+ enabled: rule.enabled,
183
+ });
184
+ return result;
185
+ }
186
+ /**
187
+ * Deletes a signing rule from the MassaStation wallet.
188
+ *
189
+ * @param accountName - The name of the account.
190
+ * @param ruleId - The Id of the sign rule.
191
+ * @returns A Promise that resolves when the rule is successfully deleted.
192
+ */
193
+ async deleteSignRule(accountName, ruleId) {
194
+ await deleteRequest(walletApiUrl() + '/accounts/' + accountName + '/signrules/' + ruleId);
195
+ }
153
196
  }
154
197
  //# sourceMappingURL=MassaStationWallet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationWallet.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAA6B,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,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ED;;;OAGG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,SAAS;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { MassaStationAccountStatus, MSAccount, MSAccountsResp } from './types';\nimport { EventEmitter } from 'eventemitter3';\nimport { Wallet } from '../wallet/interface';\nimport { Network } from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport { isMassaWalletEnabled } from './MassaStationDiscovery';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\n\nexport function walletApiUrl(): string {\n // This is a hack to detect that MS wallet is working in standalone mode\n // dev only usage\n if (typeof window !== 'undefined' && window.massaWallet?.standalone) {\n return `http://localhost:8080/api`;\n }\n return `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api`;\n}\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationWallet implements Wallet {\n private walletName = WalletName.MassaWallet;\n\n private eventsListener = new EventEmitter();\n private currentNetwork: Network;\n\n public name(): WalletName {\n return this.walletName;\n }\n\n static async createIfInstalled(): Promise<Wallet | null> {\n if (await isMassaWalletEnabled()) {\n return new MassaStationWallet();\n }\n return null;\n }\n\n public async accounts(): Promise<MassaStationAccount[]> {\n const res = await getRequest<MSAccountsResp>(walletApiUrl() + '/accounts');\n\n if (res.isError) {\n throw res.error;\n }\n return res.result\n .filter((account) => {\n return account.status === MassaStationAccountStatus.OK;\n })\n .map((account) => {\n return new MassaStationAccount(account.address, account.nickname);\n });\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<void> {\n const res = await putRequest(walletApiUrl() + '/accounts', {\n publicKey,\n privateKey,\n });\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async deleteAccount(address: string): Promise<void> {\n // get all accounts and find the account to delete\n const allAccounts = await getRequest<MSAccountsResp>(\n walletApiUrl() + '/accounts',\n );\n\n if (allAccounts.isError) throw allAccounts.error;\n\n const accountToDelete = allAccounts.result.find(\n (account) => account.address === address,\n );\n\n if (!accountToDelete) {\n throw new Error('Account not found');\n }\n\n const res = await deleteRequest<unknown>(\n `${walletApiUrl()}/accounts/${accountToDelete.nickname}`,\n );\n\n if (res.isError) {\n throw res.error;\n }\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async setRpcUrl(url: string): Promise<void> {\n throw new Error(\n 'setRpcUrl is not yet implemented for the current provider.',\n );\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<MassaStationAccount> {\n const response = await postRequest<MSAccount>(\n walletApiUrl() + '/accounts/' + name,\n {},\n );\n\n if (response.isError) throw response.error;\n\n return new MassaStationAccount(\n response.result.address,\n response.result.nickname,\n );\n }\n\n public listenAccountChanges(): { unsubscribe: () => void } | undefined {\n throw new Error(\n 'listenAccountChanges is not yet implemented for the current provider.',\n );\n }\n\n public listenNetworkChanges(\n callback: (network: Network) => void,\n ): { unsubscribe: () => void } | undefined {\n this.eventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const network = await this.networkInfos();\n if (!this.currentNetwork) {\n this.currentNetwork = network;\n return;\n }\n if (this.currentNetwork.name !== network.name) {\n this.currentNetwork = network;\n this.eventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.eventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n\n /**\n * Simulates connecting to the station.\n * This method always returns `true` because the station is inherently connected.\n */\n public async connect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Simulates disconnecting from the station.\n * This method always returns `true` because the station cannot be disconnected.\n */\n public async disconnect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is connected.\n * Always returns `true` because the station is always connected when running.\n */\n public async connected(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is enabled.\n * Always returns `true` because the station is always enabled by default.\n */\n public enabled(): boolean {\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"MassaStationWallet.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAGL,yBAAyB,GAI1B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AAEH,MAAM,UAAU,YAAY;IAC1B,wEAAwE;IACxE,IAAI,YAAY,EAAE,EAAE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AAO,EAAE,IAAI,CAAC,OAAO;SACtB,CACF,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,YAAY,CACvB,WAAmB,EACnB,IAAc,EACd,IAAa;QAEb,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CACjC,YAAY,EAAE,GAAG,YAAY,GAAG,WAAW,GAAG,aAAa,GAAG,IAAI,CAAC,EAAE,EACrE;YACE,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CACF,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CACzB,WAAmB,EACnB,MAAc;QAEd,MAAM,aAAa,CACjB,YAAY,EAAE,GAAG,YAAY,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,CACrE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport {\n AddUpdateSignRuleResponse,\n Config,\n MassaStationAccountStatus,\n MSAccount,\n MSAccountsResp,\n SignRule,\n} from './types';\nimport { EventEmitter } from 'eventemitter3';\nimport { Wallet } from '../wallet/interface';\nimport { Network } from '@massalabs/massa-web3';\nimport { networkInfos } from './utils/network';\nimport { WalletName } from '../wallet';\nimport { isMassaWalletEnabled } from './MassaStationDiscovery';\nimport { isStandalone } from './utils/standalone';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\n\nexport function walletApiUrl(): string {\n // This is a hack to detect that MS wallet is working in standalone mode\n if (isStandalone()) {\n return `http://localhost:8080/api`;\n }\n return `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api`;\n}\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationWallet implements Wallet {\n private walletName = WalletName.MassaWallet;\n\n private eventsListener = new EventEmitter();\n private currentNetwork: Network;\n\n public name(): WalletName {\n return this.walletName;\n }\n\n static async createIfInstalled(): Promise<Wallet | null> {\n if (isStandalone() || (await isMassaWalletEnabled())) {\n return new MassaStationWallet();\n }\n return null;\n }\n\n public async accounts(): Promise<MassaStationAccount[]> {\n const res = await getRequest<MSAccountsResp>(walletApiUrl() + '/accounts');\n\n return res.result\n .filter((account) => {\n return account.status === MassaStationAccountStatus.OK;\n })\n .map((account) => {\n return new MassaStationAccount(account.address, account.nickname);\n });\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<void> {\n await putRequest(walletApiUrl() + '/accounts', {\n publicKey,\n privateKey,\n });\n }\n\n public async deleteAccount(address: string): Promise<void> {\n // get all accounts and find the account to delete\n const allAccounts = await getRequest<MSAccountsResp>(\n walletApiUrl() + '/accounts',\n );\n\n const accountToDelete = allAccounts.result.find(\n (account) => account.address === address,\n );\n\n if (!accountToDelete) {\n throw new Error('Account not found');\n }\n\n await deleteRequest<unknown>(\n `${walletApiUrl()}/accounts/${accountToDelete.nickname}`,\n );\n }\n\n public async networkInfos(): Promise<Network> {\n return networkInfos();\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public async setRpcUrl(url: string): Promise<void> {\n throw new Error(\n 'setRpcUrl is not yet implemented for the current provider.',\n );\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<MassaStationAccount> {\n const response = await postRequest<MSAccount>(\n walletApiUrl() + '/accounts/' + name,\n {},\n );\n\n return new MassaStationAccount(\n response.result.address,\n response.result.nickname,\n );\n }\n\n public listenAccountChanges(): { unsubscribe: () => void } | undefined {\n throw new Error(\n 'listenAccountChanges is not yet implemented for the current provider.',\n );\n }\n\n public listenNetworkChanges(\n callback: (network: Network) => void,\n ): { unsubscribe: () => void } | undefined {\n this.eventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const network = await this.networkInfos();\n if (!this.currentNetwork) {\n this.currentNetwork = network;\n return;\n }\n if (this.currentNetwork.name !== network.name) {\n this.currentNetwork = network;\n this.eventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.eventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n\n /**\n * Simulates connecting to the station.\n * This method always returns `true` because the station is inherently connected.\n */\n public async connect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Simulates disconnecting from the station.\n * This method always returns `true` because the station cannot be disconnected.\n */\n public async disconnect(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is connected.\n * Always returns `true` because the station is always connected when running.\n */\n public async connected(): Promise<boolean> {\n return true;\n }\n\n /**\n * Indicates if the station is enabled.\n * Always returns `true` because the station is always enabled by default.\n */\n public enabled(): boolean {\n return true;\n }\n /**\n * Retrieves the configuration from the MS Wallet api.\n *\n * @returns The configuration of MS wallet.\n */\n public async getConfig(): Promise<Config> {\n const { result } = await getRequest<Config>(walletApiUrl() + '/config');\n return result;\n }\n\n /**\n * Adds a new signing rule to the MassaStation wallet.\n *\n * @param accountName - The name of the account.\n * @param rule - The signing rule to add.\n * @param desc - Custom description of the new rule creation.\n * @returns A Promise that resolves when the rule is successfully added.\n */\n public async addSignRule(\n accountName: string,\n rule: SignRule,\n desc?: string,\n ): Promise<AddUpdateSignRuleResponse> {\n const { result } = await postRequest<AddUpdateSignRuleResponse>(\n walletApiUrl() + '/accounts/' + accountName + '/signrules',\n {\n description: desc,\n name: rule.name,\n ruleType: rule.ruleType,\n contract: rule.contract,\n enabled: rule.enabled,\n },\n );\n return result;\n }\n\n /**\n * Edits an existing signing rule in the MassaStation wallet.\n * Modifying the contract or ruleType will result in a new rule being created with a new Id.\n *\n * @param accountName - The name of the account.\n * @param rule - The updated signing rule.\n * @param desc - Custom description of the rule update.\n * @returns A Promise that resolves when the rule is successfully edited.\n */\n public async editSignRule(\n accountName: string,\n rule: SignRule,\n desc?: string,\n ): Promise<AddUpdateSignRuleResponse> {\n const { result } = await putRequest<AddUpdateSignRuleResponse>(\n walletApiUrl() + '/accounts/' + accountName + '/signrules/' + rule.id,\n {\n description: desc,\n name: rule.name,\n ruleType: rule.ruleType,\n contract: rule.contract,\n enabled: rule.enabled,\n },\n );\n\n return result;\n }\n\n /**\n * Deletes a signing rule from the MassaStation wallet.\n *\n * @param accountName - The name of the account.\n * @param ruleId - The Id of the sign rule.\n * @returns A Promise that resolves when the rule is successfully deleted.\n */\n public async deleteSignRule(\n accountName: string,\n ruleId: string,\n ): Promise<void> {\n await deleteRequest(\n walletApiUrl() + '/accounts/' + accountName + '/signrules/' + ruleId,\n );\n }\n}\n"]}
@@ -2,13 +2,7 @@
2
2
  * This interface represents a payload returned by making an http call
3
3
  */
4
4
  export type JsonRpcResponseData<T> = {
5
- isError: false;
6
5
  result: T;
7
- error?: never;
8
- } | {
9
- isError: true;
10
- result?: never;
11
- error: Error;
12
6
  };
13
7
  /**
14
8
  * This method makes a GET request to an http rest point.
@@ -1 +1 @@
1
- {"version":3,"file":"RequestHandler.d.ts","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC7B;IACE,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,GACD;IACE,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AACN;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAa,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAcjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAejC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAcjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAcjC"}
1
+ {"version":3,"file":"RequestHandler.d.ts","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI;IACnC,MAAM,EAAE,CAAC,CAAC;CACX,CAAC;AAeF;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,MAAa,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAWjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAUjC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAWjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAWjC"}
@@ -12,6 +12,18 @@ const requestHeaders = {
12
12
  Accept: 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
13
13
  'Content-Type': 'application/json',
14
14
  };
15
+ /**
16
+ * Handles errors from Axios requests.
17
+ *
18
+ * @param error - The error object thrown by Axios.
19
+ * @throws a formatted error message.
20
+ */
21
+ function handleAxiosError(error) {
22
+ const err = error.response?.data?.message
23
+ ? new Error(String(error.response.data.message))
24
+ : new Error('Axios error: ' + String(error));
25
+ throw err;
26
+ }
15
27
  /**
16
28
  * This method makes a GET request to an http rest point.
17
29
  *
@@ -27,13 +39,10 @@ export async function getRequest(url, timeout = null) {
27
39
  headers: requestHeaders,
28
40
  timeout,
29
41
  });
30
- return { isError: false, result: resp.data };
42
+ return { result: resp.data };
31
43
  }
32
- catch (ex) {
33
- return {
34
- isError: true,
35
- error: new Error('Axios Error: ' + String(ex)),
36
- };
44
+ catch (error) {
45
+ handleAxiosError(error);
37
46
  }
38
47
  }
39
48
  /**
@@ -50,15 +59,10 @@ export async function postRequest(url, body) {
50
59
  const resp = await axios.post(url, body, {
51
60
  headers: requestHeaders,
52
61
  });
53
- return { isError: false, result: resp.data };
62
+ return { result: resp.data };
54
63
  }
55
64
  catch (error) {
56
- return {
57
- isError: true,
58
- error: error.response?.data?.message
59
- ? new Error(String(error.response.data.message))
60
- : new Error('Axios error: ' + String(error)),
61
- };
65
+ handleAxiosError(error);
62
66
  }
63
67
  }
64
68
  /**
@@ -75,13 +79,10 @@ export async function deleteRequest(url) {
75
79
  resp = await axios.delete(url, {
76
80
  headers: requestHeaders,
77
81
  });
78
- return { isError: false, result: resp.data };
82
+ return { result: resp.data };
79
83
  }
80
- catch (ex) {
81
- return {
82
- isError: true,
83
- error: new Error('Axios Error: ' + String(ex)),
84
- };
84
+ catch (error) {
85
+ handleAxiosError(error);
85
86
  }
86
87
  }
87
88
  /**
@@ -99,13 +100,10 @@ export async function putRequest(url, body) {
99
100
  resp = await axios.put(url, body, {
100
101
  headers: requestHeaders,
101
102
  });
102
- return { isError: false, result: resp.data };
103
+ return { result: resp.data };
103
104
  }
104
- catch (ex) {
105
- return {
106
- isError: true,
107
- error: new Error('Axios error: ' + String(ex)),
108
- };
105
+ catch (error) {
106
+ handleAxiosError(error);
109
107
  }
110
108
  }
111
109
  //# sourceMappingURL=RequestHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,MAAM,cAAc,GAAG;IACrB,MAAM,EACJ,kFAAkF;IACpF,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAeF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,UAAkB,IAAI;IAEtB,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,CAAiC,GAAG,EAAE;YAC1D,OAAO,EAAE,cAAc;YACvB,OAAO;SACR,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KAC9C;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CA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AAY;IAEZ,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,CAAiC,GAAG,EAAE,IAAI,EAAE;YAChE,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KAC9C;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;SAC/C,CAAC;KACH;AACH,CAAC","sourcesContent":["/**\n * This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.\n *\n * @remarks\n * - The methods implemented here are quite generic and might be useful in other contexts too\n * but have been particularly developed for making http calls specific to MassaStation's server API\n * - If you want to work on this repo, you will probably be interested in this object\n *\n */\nimport axios, { AxiosResponse } from 'axios';\n\nconst requestHeaders = {\n Accept:\n 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Content-Type': 'application/json',\n};\n/**\n * This interface represents a payload returned by making an http call\n */\nexport type JsonRpcResponseData<T> =\n | {\n isError: false;\n result: T;\n error?: never;\n }\n | {\n isError: true;\n result?: never;\n error: Error;\n };\n/**\n * This method makes a GET request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function getRequest<T>(\n url: string,\n timeout: number = null,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.get<unknown, AxiosResponse, object>(url, {\n headers: requestHeaders,\n timeout,\n });\n return { isError: false, result: resp.data };\n } catch (ex) {\n return {\n isError: true,\n error: new Error('Axios Error: ' + String(ex)),\n };\n }\n}\n\n/**\n * This method makes a POST request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function postRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n try {\n const resp = await axios.post<unknown, AxiosResponse, object>(url, body, {\n headers: requestHeaders,\n });\n\n return { isError: false, result: resp.data };\n } catch (error) {\n return {\n isError: true,\n error: error.response?.data?.message\n ? new Error(String(error.response.data.message))\n : new Error('Axios error: ' + String(error)),\n };\n }\n}\n\n/**\n * This method makes a DELETE request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function deleteRequest<T>(\n url: string,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.delete<unknown, AxiosResponse, object>(url, {\n headers: requestHeaders,\n });\n\n return { isError: false, result: resp.data };\n } catch (ex) {\n return {\n isError: true,\n error: new Error('Axios Error: ' + String(ex)),\n };\n }\n}\n\n/**\n * This method makes a PUT request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function putRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.put<unknown, AxiosResponse, object>(url, body, {\n headers: requestHeaders,\n });\n\n return { isError: false, result: resp.data };\n } catch (ex) {\n return {\n isError: true,\n error: new Error('Axios error: ' + String(ex)),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,MAAM,cAAc,GAAG;IACrB,MAAM,EACJ,kFAAkF;IACpF,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAQF;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAU;IAClC,MAAM,GAAG,GAAG,KAAK,C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QAEH,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KAC9B;IAAC,OAAO,KAAK,EAAE;QACd,gBAAgB,CAAC,KAAK,CAAC,CAAC;KACzB;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAW,EACX,IAAY;IAEZ,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,CAAiC,GAAG,EAAE,IAAI,EAAE;YAChE,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;KAC9B;IAAC,OAAO,KAAK,EAAE;QACd,gBAAgB,CAAC,KAAK,CAAC,CAAC;KACzB;AACH,CAAC","sourcesContent":["/**\n * This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.\n *\n * @remarks\n * - The methods implemented here are quite generic and might be useful in other contexts too\n * but have been particularly developed for making http calls specific to MassaStation's server API\n * - If you want to work on this repo, you will probably be interested in this object\n *\n */\nimport axios, { AxiosResponse } from 'axios';\n\nconst requestHeaders = {\n Accept:\n 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Content-Type': 'application/json',\n};\n/**\n * This interface represents a payload returned by making an http call\n */\nexport type JsonRpcResponseData<T> = {\n result: T;\n};\n\n/**\n * Handles errors from Axios requests.\n *\n * @param error - The error object thrown by Axios.\n * @throws a formatted error message.\n */\nfunction handleAxiosError(error: any): never {\n const err = error.response?.data?.message\n ? new Error(String(error.response.data.message))\n : new Error('Axios error: ' + String(error));\n throw err;\n}\n\n/**\n * This method makes a GET request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function getRequest<T>(\n url: string,\n timeout: number = null,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.get<unknown, AxiosResponse, object>(url, {\n headers: requestHeaders,\n timeout,\n });\n return { result: resp.data };\n } catch (error) {\n handleAxiosError(error);\n }\n}\n\n/**\n * This method makes a POST request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function postRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n try {\n const resp = await axios.post<unknown, AxiosResponse, object>(url, body, {\n headers: requestHeaders,\n });\n\n return { result: resp.data };\n } catch (error) {\n handleAxiosError(error);\n }\n}\n\n/**\n * This method makes a DELETE request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function deleteRequest<T>(\n url: string,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.delete<unknown, AxiosResponse, object>(url, {\n headers: requestHeaders,\n });\n\n return { result: resp.data };\n } catch (error) {\n handleAxiosError(error);\n }\n}\n\n/**\n * This method makes a PUT request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function putRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.put<unknown, AxiosResponse, object>(url, body, {\n headers: requestHeaders,\n });\n\n return { result: resp.data };\n } catch (error) {\n handleAxiosError(error);\n }\n}\n"]}
@@ -84,4 +84,26 @@ export type MSAccountSignResp = {
84
84
  export type MSSendOperationResp = {
85
85
  operationId: string;
86
86
  };
87
+ export interface AccountConfig {
88
+ signRules: SignRule[];
89
+ }
90
+ export interface Config {
91
+ accounts: {
92
+ [key: string]: AccountConfig;
93
+ };
94
+ }
95
+ export declare enum RuleType {
96
+ DisablePasswordPrompt = "DISABLE_PASSWORD_PROMPT",
97
+ AutoSign = "AUTO_SIGN"
98
+ }
99
+ export interface SignRule {
100
+ id?: string;
101
+ ruleType: RuleType;
102
+ name?: string;
103
+ contract: string;
104
+ enabled: boolean;
105
+ }
106
+ export type AddUpdateSignRuleResponse = {
107
+ id: string;
108
+ };
87
109
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,UAAU,EAAE,CAAC;AAE7C,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC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,9 @@ export var MassaStationAccountStatus;
3
3
  MassaStationAccountStatus["OK"] = "ok";
4
4
  MassaStationAccountStatus["CORRUPTED"] = "corrupted";
5
5
  })(MassaStationAccountStatus || (MassaStationAccountStatus = {}));
6
+ export var RuleType;
7
+ (function (RuleType) {
8
+ RuleType["DisablePasswordPrompt"] = "DISABLE_PASSWORD_PROMPT";
9
+ RuleType["AutoSign"] = "AUTO_SIGN";
10
+ })(RuleType || (RuleType = {}));
6
11
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAN,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACnC,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHW,yBAAyB,KAAzB,yBAAyB,QAGpC","sourcesContent":["import { NetworkName } from '@massalabs/massa-web3';\n\nexport type ExecuteFunctionBody = {\n nickname: string;\n name: string;\n at: string;\n args?: string;\n fee?: string;\n maxGas?: string;\n coins?: number; // number type keeped for backward compatibility\n async?: boolean;\n};\n\nexport type DeploySCFunctionBody = {\n nickname: string;\n smartContract: string;\n maxCoins: string;\n coins: string;\n parameters: string;\n fee: string;\n description: string;\n};\n\nexport type PluginInfo = {\n author: string;\n description: string;\n home: string;\n name: string;\n status: string;\n version: string;\n};\n\nexport type PluginManagerBody = PluginInfo[];\n\nexport type MSNetworksResp = {\n chainId: number | string;\n network: NetworkName;\n url: string;\n};\n\nexport enum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\nexport type MSAccountsResp = MSAccount[];\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport type MSAccount = {\n address: string;\n nickname: string;\n keyPair: {\n nonce: string;\n privateKey: string;\n publicKey: string;\n salt: string;\n };\n status: MassaStationAccountStatus;\n};\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\nexport type MSBalancesResp = {\n addressesAttributes: {\n [key: string]: {\n balance: {\n pending: string;\n final: string;\n };\n };\n };\n};\n\n/**\n * Payload for a sign message request.\n */\nexport type MSAccountSignPayload = {\n description: string;\n message: string;\n DisplayData: boolean;\n};\n\n/**\n * Response from the content script after a signing operation.\n */\nexport type MSAccountSignResp = {\n /** Public key of the account */\n publicKey: string;\n /** Signed message data */\n signature: string;\n};\n\nexport type MSSendOperationResp = {\n operationId: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAwCA,MAAM,CAAN,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACnC,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHW,yBAAyB,KAAzB,yBAAyB,QAGpC;AAkED,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,6DAAiD,CAAA;IACjD,kCAAsB,CAAA;AACxB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB","sourcesContent":["import { NetworkName } from '@massalabs/massa-web3';\n\nexport type ExecuteFunctionBody = {\n nickname: string;\n name: string;\n at: string;\n args?: string;\n fee?: string;\n maxGas?: string;\n coins?: number; // number type keeped for backward compatibility\n async?: boolean;\n};\n\nexport type DeploySCFunctionBody = {\n nickname: string;\n smartContract: string;\n maxCoins: string;\n coins: string;\n parameters: string;\n fee: string;\n description: string;\n};\n\nexport type PluginInfo = {\n author: string;\n description: string;\n home: string;\n name: string;\n status: string;\n version: string;\n};\n\nexport type PluginManagerBody = PluginInfo[];\n\nexport type MSNetworksResp = {\n chainId: number | string;\n network: NetworkName;\n url: string;\n};\n\nexport enum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\nexport type MSAccountsResp = MSAccount[];\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport type MSAccount = {\n address: string;\n nickname: string;\n keyPair: {\n nonce: string;\n privateKey: string;\n publicKey: string;\n salt: string;\n };\n status: MassaStationAccountStatus;\n};\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's get balances url.\n */\nexport type MSBalancesResp = {\n addressesAttributes: {\n [key: string]: {\n balance: {\n pending: string;\n final: string;\n };\n };\n };\n};\n\n/**\n * Payload for a sign message request.\n */\nexport type MSAccountSignPayload = {\n description: string;\n message: string;\n DisplayData: boolean;\n};\n\n/**\n * Response from the content script after a signing operation.\n */\nexport type MSAccountSignResp = {\n /** Public key of the account */\n publicKey: string;\n /** Signed message data */\n signature: string;\n};\n\nexport type MSSendOperationResp = {\n operationId: string;\n};\n\nexport interface AccountConfig {\n signRules: SignRule[];\n}\n\nexport interface Config {\n accounts: {\n [key: string]: AccountConfig;\n };\n}\n\nexport enum RuleType {\n DisablePasswordPrompt = 'DISABLE_PASSWORD_PROMPT',\n AutoSign = 'AUTO_SIGN',\n}\n\nexport interface SignRule {\n id?: string;\n ruleType: RuleType;\n name?: string;\n contract: string;\n enabled: boolean;\n}\n\nexport type AddUpdateSignRuleResponse = {\n id: string;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAU/D,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAkBrD;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAMxD"}
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,OAAO,EAGR,MAAM,uBAAuB,CAAC;AAW/B,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CA4BrD;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAMxD"}
@@ -1,23 +1,32 @@
1
- import { JsonRPCClient } from '@massalabs/massa-web3';
1
+ import { CHAIN_ID, JsonRPCClient, NetworkName, PublicApiUrl, } from '@massalabs/massa-web3';
2
2
  import { MASSA_STATION_URL } from '../MassaStationWallet';
3
3
  import { getRequest } from '../RequestHandler';
4
+ import { isStandalone } from './standalone';
4
5
  // Use client singleton to benefit from caching
5
6
  let client;
6
7
  // Use rpcUrl to check if node has changed
7
8
  let rpcUrl;
8
9
  export async function networkInfos() {
9
- const nodesResponse = await getRequest(`${MASSA_STATION_URL}massa/node`);
10
- if (nodesResponse.isError)
11
- throw nodesResponse.error.message;
12
- const url = nodesResponse.result.url;
10
+ if (isStandalone()) {
11
+ rpcUrl = PublicApiUrl.Buildnet;
12
+ client = new JsonRPCClient(rpcUrl);
13
+ return {
14
+ name: NetworkName.Buildnet,
15
+ url: rpcUrl,
16
+ chainId: CHAIN_ID.Buildnet,
17
+ minimalFee: await client.getMinimalFee(),
18
+ };
19
+ }
20
+ const { result } = await getRequest(`${MASSA_STATION_URL}massa/node`);
21
+ const url = result.url;
13
22
  if (!client || rpcUrl !== url) {
14
23
  client = new JsonRPCClient(url);
15
24
  rpcUrl = url;
16
25
  }
17
26
  return {
18
- name: nodesResponse.result.network,
27
+ name: result.network,
19
28
  url,
20
- chainId: BigInt(nodesResponse.result.chainId),
29
+ chainId: BigInt(result.chainId),
21
30
  minimalFee: await client.getMinimalFee(),
22
31
  };
23
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAW,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,+CAA+C;AAC/C,IAAI,MAAqB,CAAC;AAC1B,0CAA0C;AAC1C,IAAI,MAAc,CAAC;AAEnB,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,aAAa,GAAG,MAAM,UAAU,CACpC,GAAG,iBAAiB,YAAY,CACjC,CAAC;IACF,IAAI,aAAa,CAAC,OAAO;QAAE,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC;IAE7D,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC;IACrC,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE;QAC7B,MAAM,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,CAAC;KACd;IAED,OAAO;QACL,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,OAAO;QAClC,GAAG;QACH,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7C,UAAU,EAAE,MAAM,MAAM,CAAC,aAAa,EAAE;KACzC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,CAAC,MAAM,EAAE;QACX,yBAAyB;QACzB,MAAM,YAAY,EAAE,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { JsonRPCClient, Network } from '@massalabs/massa-web3';\nimport { MSNetworksResp } from '../types';\nimport { MASSA_STATION_URL } from '../MassaStationWallet';\nimport { getRequest } from '../RequestHandler';\n\n// Use client singleton to benefit from caching\nlet client: JsonRPCClient;\n// Use rpcUrl to check if node has changed\nlet rpcUrl: string;\n\nexport async function networkInfos(): Promise<Network> {\n const nodesResponse = await getRequest<MSNetworksResp>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError) throw nodesResponse.error.message;\n\n const url = nodesResponse.result.url;\n if (!client || rpcUrl !== url) {\n client = new JsonRPCClient(url);\n rpcUrl = url;\n }\n\n return {\n name: nodesResponse.result.network,\n url,\n chainId: BigInt(nodesResponse.result.chainId),\n minimalFee: await client.getMinimalFee(),\n };\n}\n\nexport async function getClient(): Promise<JsonRPCClient> {\n if (!client) {\n // this initialize client\n await networkInfos();\n }\n return client;\n}\n"]}
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/massaStation/utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,aAAa,EAEb,WAAW,EACX,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,+CAA+C;AAC/C,IAAI,MAAqB,CAAC;AAC1B,0CAA0C;AAC1C,IAAI,MAAc,CAAC;AAEnB,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,YAAY,EAAE,EAAE;QAClB,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC;QAC/B,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO;YACL,IAAI,EAAE,WAAW,CAAC,QAAQ;YAC1B,GAAG,EAAE,MAAM;YACX,OAAO,EAAE,QAAQ,CAAC,QAAQ;YAC1B,UAAU,EAAE,MAAM,MAAM,CAAC,aAAa,EAAE;SACzC,CAAC;KACH;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,UAAU,CACjC,GAAG,iBAAiB,YAAY,CACjC,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IACvB,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,GAAG,EAAE;QAC7B,MAAM,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,CAAC;KACd;IAED,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,OAAO;QACpB,GAAG;QACH,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,UAAU,EAAE,MAAM,MAAM,CAAC,aAAa,EAAE;KACzC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,CAAC,MAAM,EAAE;QACX,yBAAyB;QACzB,MAAM,YAAY,EAAE,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n CHAIN_ID,\n JsonRPCClient,\n Network,\n NetworkName,\n PublicApiUrl,\n} from '@massalabs/massa-web3';\nimport { MSNetworksResp } from '../types';\nimport { MASSA_STATION_URL } from '../MassaStationWallet';\nimport { getRequest } from '../RequestHandler';\nimport { isStandalone } from './standalone';\n\n// Use client singleton to benefit from caching\nlet client: JsonRPCClient;\n// Use rpcUrl to check if node has changed\nlet rpcUrl: string;\n\nexport async function networkInfos(): Promise<Network> {\n if (isStandalone()) {\n rpcUrl = PublicApiUrl.Buildnet;\n client = new JsonRPCClient(rpcUrl);\n return {\n name: NetworkName.Buildnet,\n url: rpcUrl,\n chainId: CHAIN_ID.Buildnet,\n minimalFee: await client.getMinimalFee(),\n };\n }\n\n const { result } = await getRequest<MSNetworksResp>(\n `${MASSA_STATION_URL}massa/node`,\n );\n\n const url = result.url;\n if (!client || rpcUrl !== url) {\n client = new JsonRPCClient(url);\n rpcUrl = url;\n }\n\n return {\n name: result.network,\n url,\n chainId: BigInt(result.chainId),\n minimalFee: await client.getMinimalFee(),\n };\n}\n\nexport async function getClient(): Promise<JsonRPCClient> {\n if (!client) {\n // this initialize client\n await networkInfos();\n }\n return client;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function isStandalone(): boolean;
2
+ //# sourceMappingURL=standalone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../../../../src/massaStation/utils/standalone.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,IAAI,OAAO,CAGtC"}
@@ -0,0 +1,5 @@
1
+ export function isStandalone() {
2
+ // this is eventually set by wallet web-app
3
+ return typeof window !== 'undefined' && window.massaWallet?.standalone;
4
+ }
5
+ //# sourceMappingURL=standalone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.js","sourceRoot":"","sources":["../../../../src/massaStation/utils/standalone.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY;IAC1B,2CAA2C;IAC3C,OAAO,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC;AACzE,CAAC","sourcesContent":["export function isStandalone(): boolean {\n // this is eventually set by wallet web-app\n return typeof window !== 'undefined' && window.massaWallet?.standalone;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../../src/metamaskSnap/snap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,EAAE,KAAK,gBAAgB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,iBAAiB,aAClB,sBAAsB,KAC/B,QAAQ,gBAAgB,CAGvB,CAAC;AAEL,eAAO,MAAM,gBAAgB,aACjB,sBAAsB,YACtB,MAAM,KACf,QAAQ,IAAI,GAAG,SAAS,CAY1B,CAAC;AAEF,eAAO,MAAM,WAAW,aACZ,sBAAsB,KAC/B,QAAQ,OAAO,CAGjB,CAAC;AAEF,eAAO,MAAM,WAAW,aACZ,sBAAsB,WACxB,OAAO,SAAS,GAAG,MAAM,EAAE,OAAO,CAAC,8BAQ5C,CAAC;AAEF,eAAO,MAAM,cAAc,aAAoB,sBAAsB,8BAKpE,CAAC"}
1
+ {"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../../src/metamaskSnap/snap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,EAAE,KAAK,gBAAgB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,iBAAiB,aAClB,sBAAsB,KAC/B,QAAQ,gBAAgB,CAGvB,CAAC;AAEL,eAAO,MAAM,gBAAgB,aACjB,sBAAsB,YACtB,MAAM,KACf,QAAQ,IAAI,GAAG,SAAS,CAa1B,CAAC;AAEF,eAAO,MAAM,WAAW,aACZ,sBAAsB,KAC/B,QAAQ,OAAO,CAGjB,CAAC;AAEF,eAAO,MAAM,WAAW,aACZ,sBAAsB,WACxB,OAAO,SAAS,GAAG,MAAM,EAAE,OAAO,CAAC,8BAQ5C,CAAC;AAEF,eAAO,MAAM,cAAc,aAAoB,sBAAsB,8BAKpE,CAAC"}
@@ -8,7 +8,8 @@ export const getMassaSnapInfo = async (provider, version) => {
8
8
  return Object.values(snaps).find((snap) => snap.id === MASSA_SNAP_ID && (!version || snap.version === version));
9
9
  }
10
10
  catch (error) {
11
- console.error('Failed to obtain installed snap', error);
11
+ // eslint-disable-next-line no-console
12
+ console.error('Failed to get installed snap', error);
12
13
  return undefined;
13
14
  }
14
15
  };
@@ -1 +1 @@
1
- {"version":3,"file":"snap.js","sourceRoot":"","sources":["../../../src/metamaskSnap/snap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,QAAgC,EACL,EAAE,CAC7B,QAAQ,CAAC,OAAO,CAAC;IACf,MAAM,EAAE,iBAAiB;CAC1B,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,QAAgC,EAChC,OAAgB,EACW,EAAE;IAC7B,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAC9B,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,EAAE,KAAK,aAAa,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CACtE,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACxD,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgC,EACd,EAAE;IACpB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,CAAC,CAAC,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgC,EAChC,SAA8C,EAAE,EAChD,EAAE;IACF,OAAO,QAAQ,CAAC,OAAO,CAAC;QACtB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,aAAa,CAAC,EAAE,MAAM;SACxB;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,QAAgC,EAAE,EAAE;IACvE,OAAO,QAAQ,CAAC,OAAO,CAAC;QACtB,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;KACxE,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\n\nimport { MASSA_SNAP_ID } from './config';\nimport { type GetSnapsResponse, Snap } from './types';\n\nexport const getInstalledSnaps = async (\n provider: MetaMaskInpageProvider,\n): Promise<GetSnapsResponse> =>\n provider.request({\n method: 'wallet_getSnaps',\n });\n\nexport const getMassaSnapInfo = async (\n provider: MetaMaskInpageProvider,\n version?: string,\n): Promise<Snap | undefined> => {\n try {\n const snaps = await getInstalledSnaps(provider);\n\n return Object.values(snaps).find(\n (snap) =>\n snap.id === MASSA_SNAP_ID && (!version || snap.version === version),\n );\n } catch (error) {\n console.error('Failed to obtain installed snap', error);\n return undefined;\n }\n};\n\nexport const isConnected = async (\n provider: MetaMaskInpageProvider,\n): Promise<boolean> => {\n const snap = await getMassaSnapInfo(provider);\n return !!snap;\n};\n\nexport const connectSnap = async (\n provider: MetaMaskInpageProvider,\n params: Record<'version' | string, unknown> = {},\n) => {\n return provider.request({\n method: 'wallet_requestSnaps',\n params: {\n [MASSA_SNAP_ID]: params,\n },\n });\n};\n\nexport const showPrivateKey = async (provider: MetaMaskInpageProvider) => {\n return provider.request({\n method: 'wallet_invokeSnap',\n params: { snapId: MASSA_SNAP_ID, request: { method: 'showSecretKey' } },\n });\n};\n"]}
1
+ {"version":3,"file":"snap.js","sourceRoot":"","sources":["../../../src/metamaskSnap/snap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,QAAgC,EACL,EAAE,CAC7B,QAAQ,CAAC,OAAO,CAAC;IACf,MAAM,EAAE,iBAAiB;CAC1B,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,QAAgC,EAChC,OAAgB,EACW,EAAE;IAC7B,IAAI;QACF,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAC9B,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,EAAE,KAAK,aAAa,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,CAAC,CACtE,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACrD,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgC,EACd,EAAE;IACpB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,CAAC,CAAC,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAgC,EAChC,SAA8C,EAAE,EAChD,EAAE;IACF,OAAO,QAAQ,CAAC,OAAO,CAAC;QACtB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,CAAC,aAAa,CAAC,EAAE,MAAM;SACxB;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,QAAgC,EAAE,EAAE;IACvE,OAAO,QAAQ,CAAC,OAAO,CAAC;QACtB,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE;KACxE,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\n\nimport { MASSA_SNAP_ID } from './config';\nimport { type GetSnapsResponse, Snap } from './types';\n\nexport const getInstalledSnaps = async (\n provider: MetaMaskInpageProvider,\n): Promise<GetSnapsResponse> =>\n provider.request({\n method: 'wallet_getSnaps',\n });\n\nexport const getMassaSnapInfo = async (\n provider: MetaMaskInpageProvider,\n version?: string,\n): Promise<Snap | undefined> => {\n try {\n const snaps = await getInstalledSnaps(provider);\n\n return Object.values(snaps).find(\n (snap) =>\n snap.id === MASSA_SNAP_ID && (!version || snap.version === version),\n );\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to get installed snap', error);\n return undefined;\n }\n};\n\nexport const isConnected = async (\n provider: MetaMaskInpageProvider,\n): Promise<boolean> => {\n const snap = await getMassaSnapInfo(provider);\n return !!snap;\n};\n\nexport const connectSnap = async (\n provider: MetaMaskInpageProvider,\n params: Record<'version' | string, unknown> = {},\n) => {\n return provider.request({\n method: 'wallet_requestSnaps',\n params: {\n [MASSA_SNAP_ID]: params,\n },\n });\n};\n\nexport const showPrivateKey = async (provider: MetaMaskInpageProvider) => {\n return provider.request({\n method: 'wallet_invokeSnap',\n params: { snapId: MASSA_SNAP_ID, request: { method: 'showSecretKey' } },\n });\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"walletList.d.ts","sourceRoot":"","sources":["../../../src/walletsManager/walletList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,eAAO,MAAM,gBAAgB,EAAE,gBAI9B,CAAC;AAEF,wBAAsB,UAAU,CAAC,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAc/D;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,UAAU,EAChB,KAAK,SAAM,GACV,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG7B"}
1
+ {"version":3,"file":"walletList.d.ts","sourceRoot":"","sources":["../../../src/walletsManager/walletList.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,eAAO,MAAM,gBAAgB,EAAE,gBAI9B,CAAC;AAEF,wBAAsB,UAAU,CAAC,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAe/D;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,UAAU,EAChB,KAAK,SAAM,GACV,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG7B"}
@@ -14,6 +14,7 @@ export async function getWallets(delay = 200) {
14
14
  return await WalletClass.createIfInstalled();
15
15
  }
16
16
  catch (error) {
17
+ // eslint-disable-next-line no-console
17
18
  console.error(`Error initializing wallet ${WalletClass.name}:`, error);
18
19
  }
19
20
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"walletList.js","sourceRoot":"","sources":["../../../src/walletsManager/walletList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,YAAY;IACZ,kBAAkB;IAClB,cAAc;CACf,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAK,GAAG,GAAG;IAC1C,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;IAElB,MAAM,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAChE,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;SAC9C;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,6BAA6B,WAAW,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1D,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAgB,EAChB,KAAK,GAAG,GAAG;IAEX,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { BearbyWallet } from '../bearbyWallet/BearbyWallet';\nimport { WalletInterfaces } from './types';\nimport { Wallet } from '../wallet/interface';\nimport { wait } from '../utils/time';\nimport { MassaStationWallet } from '../massaStation/MassaStationWallet';\nimport { WalletName } from '../wallet/types';\nimport { MetamaskWallet } from '../metamaskSnap/MetamaskWallet';\n\nexport const supportedWallets: WalletInterfaces = [\n BearbyWallet,\n MassaStationWallet,\n MetamaskWallet,\n];\n\nexport async function getWallets(delay = 200): Promise<Wallet[]> {\n await wait(delay);\n\n const walletPromises = supportedWallets.map(async (WalletClass) => {\n try {\n return await WalletClass.createIfInstalled();\n } catch (error) {\n console.error(`Error initializing wallet ${WalletClass.name}:`, error);\n }\n return null;\n });\n\n const resolvedWallets = await Promise.all(walletPromises);\n return resolvedWallets.filter((wallet) => !!wallet);\n}\n\nexport async function getWallet(\n name: WalletName,\n delay = 200,\n): Promise<Wallet | undefined> {\n const wallets = await getWallets(delay);\n return wallets.find((p) => p.name() === name);\n}\n"]}
1
+ {"version":3,"file":"walletList.js","sourceRoot":"","sources":["../../../src/walletsManager/walletList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAqB;IAChD,YAAY;IACZ,kBAAkB;IAClB,cAAc;CACf,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAK,GAAG,GAAG;IAC1C,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;IAElB,MAAM,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QAChE,IAAI;YACF,OAAO,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;SAC9C;QAAC,OAAO,KAAK,EAAE;YACd,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,6BAA6B,WAAW,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1D,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAgB,EAChB,KAAK,GAAG,GAAG;IAEX,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import { BearbyWallet } from '../bearbyWallet/BearbyWallet';\nimport { WalletInterfaces } from './types';\nimport { Wallet } from '../wallet/interface';\nimport { wait } from '../utils/time';\nimport { MassaStationWallet } from '../massaStation/MassaStationWallet';\nimport { WalletName } from '../wallet/types';\nimport { MetamaskWallet } from '../metamaskSnap/MetamaskWallet';\n\nexport const supportedWallets: WalletInterfaces = [\n BearbyWallet,\n MassaStationWallet,\n MetamaskWallet,\n];\n\nexport async function getWallets(delay = 200): Promise<Wallet[]> {\n await wait(delay);\n\n const walletPromises = supportedWallets.map(async (WalletClass) => {\n try {\n return await WalletClass.createIfInstalled();\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`Error initializing wallet ${WalletClass.name}:`, error);\n }\n return null;\n });\n\n const resolvedWallets = await Promise.all(walletPromises);\n return resolvedWallets.filter((wallet) => !!wallet);\n}\n\nexport async function getWallet(\n name: WalletName,\n delay = 200,\n): Promise<Wallet | undefined> {\n const wallets = await getWallets(delay);\n return wallets.find((p) => p.name() === name);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"walletsListener.d.ts","sourceRoot":"","sources":["../../../src/walletsManager/walletsListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,qBAAa,eAAe;IAIP,aAAa;IAHhC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,cAAc,CAAgB;gBAEnB,aAAa,SAAO;YAEzB,eAAe;IAc7B,OAAO,CAAC,iBAAiB;IAcZ,SAAS,CACpB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,GACpC,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CAiBxC"}
1
+ {"version":3,"file":"walletsListener.d.ts","sourceRoot":"","sources":["../../../src/walletsManager/walletsListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,qBAAa,eAAe;IAIP,aAAa;IAHhC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,cAAc,CAAgB;gBAEnB,aAAa,SAAO;YAEzB,eAAe;IAe7B,OAAO,CAAC,iBAAiB;IAcZ,SAAS,CACpB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,GACpC,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;CAiBxC"}
@@ -15,6 +15,7 @@ export class WalletsListener {
15
15
  }
16
16
  }
17
17
  catch (error) {
18
+ // eslint-disable-next-line no-console
18
19
  console.error('Error checking wallet list changes:', error);
19
20
  }
20
21
  }
@@ -1 +1 @@
1
- {"version":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AAI,CAAC,cAAc,GAAG,MAAM,UAAU,EAAE,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAE9B,IAAI,CAAC,UAAU,GAAG,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EACpC,IAAI,CAAC,aAAa,CACnB,CAAC;QAEF,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBAChC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Wallet } from '../wallet/interface';\nimport { getWallets } from './walletList';\n\nexport class WalletsListener {\n private intervalId: NodeJS.Timeout | null;\n private currentWallets: Wallet[] = [];\n\n constructor(public intervalDelay = 1000) {}\n\n private async checkForChanges(\n callback: (wallets: Wallet[]) => void,\n ): Promise<void> {\n try {\n const newWallets = await getWallets(0);\n if (this.hasWalletsChanged(newWallets)) {\n this.currentWallets = newWallets;\n callback(newWallets);\n }\n } catch (error) {\n console.error('Error checking wallet list changes:', error);\n }\n }\n\n private hasWalletsChanged(newWallets: Wallet[]): boolean {\n const newList = new Set(newWallets.map((p) => p.name));\n const currentList = new Set(this.currentWallets.map((p) => p.name));\n\n if (\n newList.size !== currentList.size ||\n [...newList].some((name) => !currentList.has(name))\n ) {\n return true;\n }\n\n return false;\n }\n\n public async subscribe(\n callback: (wallets: Wallet[]) => void,\n ): Promise<{ unsubscribe: () => void }> {\n this.currentWallets = await getWallets();\n callback(this.currentWallets);\n\n this.intervalId = setInterval(\n () => this.checkForChanges(callback),\n this.intervalDelay,\n );\n\n return {\n unsubscribe: () => {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"walletsListener.js","sourceRoot":"","sources":["../../../src/walletsManager/walletsListener.ts"],"names":[],"mappings":"AACA,OAAO,EA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I,CAAC,cAAc,CAAC,CAAC;QAE9B,IAAI,CAAC,UAAU,GAAG,WAAW,CAC3B,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EACpC,IAAI,CAAC,aAAa,CACnB,CAAC;QAEF,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBAChC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { Wallet } from '../wallet/interface';\nimport { getWallets } from './walletList';\n\nexport class WalletsListener {\n private intervalId: NodeJS.Timeout | null;\n private currentWallets: Wallet[] = [];\n\n constructor(public intervalDelay = 1000) {}\n\n private async checkForChanges(\n callback: (wallets: Wallet[]) => void,\n ): Promise<void> {\n try {\n const newWallets = await getWallets(0);\n if (this.hasWalletsChanged(newWallets)) {\n this.currentWallets = newWallets;\n callback(newWallets);\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error checking wallet list changes:', error);\n }\n }\n\n private hasWalletsChanged(newWallets: Wallet[]): boolean {\n const newList = new Set(newWallets.map((p) => p.name));\n const currentList = new Set(this.currentWallets.map((p) => p.name));\n\n if (\n newList.size !== currentList.size ||\n [...newList].some((name) => !currentList.has(name))\n ) {\n return true;\n }\n\n return false;\n }\n\n public async subscribe(\n callback: (wallets: Wallet[]) => void,\n ): Promise<{ unsubscribe: () => void }> {\n this.currentWallets = await getWallets();\n callback(this.currentWallets);\n\n this.intervalId = setInterval(\n () => this.checkForChanges(callback),\n this.intervalDelay,\n );\n\n return {\n unsubscribe: () => {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n }\n },\n };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massalabs/wallet-provider",
3
- "version": "3.1.2-dev.20250207102809",
3
+ "version": "3.1.2-dev.20250212094426",
4
4
  "description": "massa's wallet provider",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",