@massalabs/wallet-provider 1.5.3-dev.20240129123549 → 1.5.3-dev.20240202153424

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 (109) hide show
  1. package/dist/cmd/bearbyWallet/BearbyAccount.d.ts +4 -46
  2. package/dist/cmd/bearbyWallet/BearbyAccount.d.ts.map +1 -1
  3. package/dist/cmd/bearbyWallet/BearbyAccount.js +19 -109
  4. package/dist/cmd/bearbyWallet/BearbyAccount.js.map +1 -1
  5. package/dist/cmd/bearbyWallet/BearbyConnect.d.ts.map +1 -1
  6. package/dist/cmd/bearbyWallet/BearbyConnect.js +0 -1
  7. package/dist/cmd/bearbyWallet/BearbyConnect.js.map +1 -1
  8. package/dist/cmd/bearbyWallet/BearbyProvider.d.ts +6 -10
  9. package/dist/cmd/bearbyWallet/BearbyProvider.d.ts.map +1 -1
  10. package/dist/cmd/bearbyWallet/BearbyProvider.js +18 -12
  11. package/dist/cmd/bearbyWallet/BearbyProvider.js.map +1 -1
  12. package/dist/cmd/connector/Connector.d.ts +0 -3
  13. package/dist/cmd/connector/Connector.d.ts.map +1 -1
  14. package/dist/cmd/connector/Connector.js +0 -21
  15. package/dist/cmd/connector/Connector.js.map +1 -1
  16. package/dist/cmd/index.d.ts +2 -19
  17. package/dist/cmd/index.d.ts.map +1 -1
  18. package/dist/cmd/index.js +8 -73
  19. package/dist/cmd/index.js.map +1 -1
  20. package/dist/cmd/massaStation/MassaStationAccount.d.ts.map +1 -1
  21. package/dist/cmd/massaStation/MassaStationAccount.js.map +1 -1
  22. package/dist/cmd/massaStation/MassaStationDiscovery.d.ts +1 -50
  23. package/dist/cmd/massaStation/MassaStationDiscovery.d.ts.map +1 -1
  24. package/dist/cmd/massaStation/MassaStationDiscovery.js +11 -66
  25. package/dist/cmd/massaStation/MassaStationDiscovery.js.map +1 -1
  26. package/dist/cmd/massaStation/MassaStationProvider.d.ts +9 -10
  27. package/dist/cmd/massaStation/MassaStationProvider.d.ts.map +1 -1
  28. package/dist/cmd/massaStation/MassaStationProvider.js +23 -9
  29. package/dist/cmd/massaStation/MassaStationProvider.js.map +1 -1
  30. package/dist/cmd/provider/IProvider.d.ts +1 -0
  31. package/dist/cmd/provider/IProvider.d.ts.map +1 -1
  32. package/dist/cmd/provider/IProvider.js.map +1 -1
  33. package/dist/cmd/provider/Provider.d.ts +8 -2
  34. package/dist/cmd/provider/Provider.d.ts.map +1 -1
  35. package/dist/cmd/provider/Provider.js +21 -2
  36. package/dist/cmd/provider/Provider.js.map +1 -1
  37. package/dist/cmd/providersManager/ProvidersListener.d.ts +13 -0
  38. package/dist/cmd/providersManager/ProvidersListener.d.ts.map +1 -0
  39. package/dist/cmd/providersManager/ProvidersListener.js +49 -0
  40. package/dist/cmd/providersManager/ProvidersListener.js.map +1 -0
  41. package/dist/cmd/providersManager/index.d.ts +3 -0
  42. package/dist/cmd/providersManager/index.d.ts.map +1 -0
  43. package/dist/cmd/providersManager/index.js +6 -0
  44. package/dist/cmd/providersManager/index.js.map +1 -0
  45. package/dist/cmd/providersManager/providerList.d.ts +9 -0
  46. package/dist/cmd/providersManager/providerList.d.ts.map +1 -0
  47. package/dist/cmd/providersManager/providerList.js +22 -0
  48. package/dist/cmd/providersManager/providerList.js.map +1 -0
  49. package/dist/cmd/providersManager/providers.d.ts +3 -0
  50. package/dist/cmd/providersManager/providers.d.ts.map +1 -0
  51. package/dist/cmd/providersManager/providers.js +33 -0
  52. package/dist/cmd/providersManager/providers.js.map +1 -0
  53. package/dist/cmd/utils/time.js +1 -1
  54. package/dist/cmd/utils/time.js.map +1 -1
  55. package/dist/esm/bearbyWallet/BearbyAccount.d.ts +4 -46
  56. package/dist/esm/bearbyWallet/BearbyAccount.d.ts.map +1 -1
  57. package/dist/esm/bearbyWallet/BearbyAccount.js +19 -109
  58. package/dist/esm/bearbyWallet/BearbyAccount.js.map +1 -1
  59. package/dist/esm/bearbyWallet/BearbyConnect.d.ts.map +1 -1
  60. package/dist/esm/bearbyWallet/BearbyConnect.js +0 -1
  61. package/dist/esm/bearbyWallet/BearbyConnect.js.map +1 -1
  62. package/dist/esm/bearbyWallet/BearbyProvider.d.ts +6 -10
  63. package/dist/esm/bearbyWallet/BearbyProvider.d.ts.map +1 -1
  64. package/dist/esm/bearbyWallet/BearbyProvider.js +18 -15
  65. package/dist/esm/bearbyWallet/BearbyProvider.js.map +1 -1
  66. package/dist/esm/connector/Connector.d.ts +0 -3
  67. package/dist/esm/connector/Connector.d.ts.map +1 -1
  68. package/dist/esm/connector/Connector.js +0 -22
  69. package/dist/esm/connector/Connector.js.map +1 -1
  70. package/dist/esm/index.d.ts +2 -19
  71. package/dist/esm/index.d.ts.map +1 -1
  72. package/dist/esm/index.js +2 -66
  73. package/dist/esm/index.js.map +1 -1
  74. package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -1
  75. package/dist/esm/massaStation/MassaStationAccount.js.map +1 -1
  76. package/dist/esm/massaStation/MassaStationDiscovery.d.ts +1 -50
  77. package/dist/esm/massaStation/MassaStationDiscovery.d.ts.map +1 -1
  78. package/dist/esm/massaStation/MassaStationDiscovery.js +9 -64
  79. package/dist/esm/massaStation/MassaStationDiscovery.js.map +1 -1
  80. package/dist/esm/massaStation/MassaStationProvider.d.ts +9 -10
  81. package/dist/esm/massaStation/MassaStationProvider.d.ts.map +1 -1
  82. package/dist/esm/massaStation/MassaStationProvider.js +22 -11
  83. package/dist/esm/massaStation/MassaStationProvider.js.map +1 -1
  84. package/dist/esm/provider/IProvider.d.ts +1 -0
  85. package/dist/esm/provider/IProvider.d.ts.map +1 -1
  86. package/dist/esm/provider/IProvider.js.map +1 -1
  87. package/dist/esm/provider/Provider.d.ts +8 -2
  88. package/dist/esm/provider/Provider.d.ts.map +1 -1
  89. package/dist/esm/provider/Provider.js +21 -2
  90. package/dist/esm/provider/Provider.js.map +1 -1
  91. package/dist/esm/providersManager/ProvidersListener.d.ts +13 -0
  92. package/dist/esm/providersManager/ProvidersListener.d.ts.map +1 -0
  93. package/dist/esm/providersManager/ProvidersListener.js +47 -0
  94. package/dist/esm/providersManager/ProvidersListener.js.map +1 -0
  95. package/dist/esm/providersManager/index.d.ts +3 -0
  96. package/dist/esm/providersManager/index.d.ts.map +1 -0
  97. package/dist/esm/providersManager/index.js +3 -0
  98. package/dist/esm/providersManager/index.js.map +1 -0
  99. package/dist/esm/providersManager/providerList.d.ts +9 -0
  100. package/dist/esm/providersManager/providerList.d.ts.map +1 -0
  101. package/dist/esm/providersManager/providerList.js +19 -0
  102. package/dist/esm/providersManager/providerList.js.map +1 -0
  103. package/dist/esm/providersManager/providers.d.ts +3 -0
  104. package/dist/esm/providersManager/providers.d.ts.map +1 -0
  105. package/dist/esm/providersManager/providers.js +29 -0
  106. package/dist/esm/providersManager/providers.js.map +1 -0
  107. package/dist/esm/utils/time.js +1 -1
  108. package/dist/esm/utils/time.js.map +1 -1
  109. package/package.json +3 -5
@@ -3,13 +3,10 @@ import { Args, IContractReadOperationResponse } from '@massalabs/web3-utils';
3
3
  import { ITransactionDetails } from '..';
4
4
  import { IAccountBalanceResponse, IAccountDetails } from '../account';
5
5
  import { IAccount } from '../account/IAccount';
6
- import { NodeStatus } from './NodeStatus';
7
- import { JSON_RPC_REQUEST_METHOD } from './jsonRpcMethods';
8
6
  import { IAccountSignOutput } from '../account/AccountSign';
9
7
  /**
10
- * The RPC we are using to query the node
8
+ * The maximum allowed gas for a read operation
11
9
  */
12
- export declare const PUBLIC_NODE_RPC = "https://buildnet.massa.net/api/v2";
13
10
  export declare enum OperationsType {
14
11
  Payment = 0,
15
12
  RollBuy = 1,
@@ -31,7 +28,6 @@ export declare class BearbyAccount implements IAccount {
31
28
  private _providerName;
32
29
  private _address;
33
30
  private _name;
34
- private _nodeUrl;
35
31
  constructor({ address, name }: IAccountDetails, providerName: string);
36
32
  address(): string;
37
33
  name(): string;
@@ -39,48 +35,10 @@ export declare class BearbyAccount implements IAccount {
39
35
  connect(): Promise<void>;
40
36
  balance(): Promise<IAccountBalanceResponse>;
41
37
  sign(data: Buffer | Uint8Array | string): Promise<IAccountSignOutput>;
42
- buyRolls(amount: bigint, fee: bigint): Promise<ITransactionDetails>;
43
- sellRolls(amount: bigint, fee: bigint): Promise<ITransactionDetails>;
44
- sendTransaction(amount: bigint, recipientAddress: string, fee: bigint): Promise<ITransactionDetails>;
38
+ buyRolls(amount: bigint): Promise<ITransactionDetails>;
39
+ sellRolls(amount: bigint): Promise<ITransactionDetails>;
40
+ sendTransaction(amount: bigint, recipientAddress: string): Promise<ITransactionDetails>;
45
41
  callSC(contractAddress: string, functionName: string, parameter: Args | Uint8Array, amount: bigint, fee: bigint, maxGas: bigint, nonPersistentExecution?: boolean): Promise<ITransactionDetails | IContractReadOperationResponse>;
46
- /**
47
- * Retrieves the node's status.
48
- *
49
- * @remarks
50
- * The returned information includes:
51
- * - Whether the node is reachable
52
- * - The number of connected peers
53
- * - The node's version
54
- * - The node's configuration parameters
55
- *
56
- * @returns A promise that resolves to the node's status information.
57
- */
58
- getNodeStatus(): Promise<NodeStatus>;
59
- /**
60
- * Sends a post JSON rpc request to the node.
61
- *
62
- * @param resource - The rpc method to call.
63
- * @param params - The parameters to pass to the rpc method.
64
- *
65
- * @throws An error if the rpc method returns an error.
66
- *
67
- * @returns A promise that resolves as the result of the rpc method.
68
- */
69
- protected sendJsonRPCRequest<T>(resource: JSON_RPC_REQUEST_METHOD, params: object): Promise<T>;
70
- /**
71
- * Converts a json rpc call to a promise that resolves as a JsonRpcResponseData
72
- *
73
- * @privateRemarks
74
- * If there is an error while sending the request, the function catches the error, the isError
75
- * property is set to true, the result property set to null, and the error property set to a
76
- * new Error object with a message indicating that there was an error.
77
- *
78
- * @param resource - The rpc method to call.
79
- * @param params - The parameters to pass to the rpc method.
80
- *
81
- * @returns A promise that resolves as a JsonRpcResponseData.
82
- */
83
- private promisifyJsonRpcCall;
84
42
  nonPersistentCallSC(contractAddress: string, functionName: string, parameter: Uint8Array | Args, amount: bigint, fee: bigint, maxGas: bigint): Promise<IContractReadOperationResponse>;
85
43
  }
86
44
  //# sourceMappingURL=BearbyAccount.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyAccount.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EAEJ,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,IAAI,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAO/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAM5D;;GAEG;AACH,eAAO,MAAM,eAAe,sCAAsC,CAAC;AAEnE,oBAAY,cAAc;IACxB,OAAO,IAAA;IACP,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,SAAS,IAAA;IACT,MAAM,IAAA;CACP;AAED;;GAEG;AACH,oBAAY,eAAe;IACzB,WAAW,IAAI;IACf,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,SAAS,IAAI;IACb,MAAM,IAAI;CACX;AAQD,qBAAa,aAAc,YAAW,QAAQ;IAC5C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAmB;gBAEhB,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM;IAMpE,OAAO,IAAI,MAAM;IAIjB,IAAI,IAAI,MAAM;IAId,YAAY,IAAI,MAAM;IAKhB,OAAO;IASP,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAyB3C,IAAI,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AE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,sBAAsB,UAAQ,GAC7B,OAAO,CAAC,mBAAmB,GAAG,8BAA8B,CAAC;IAiCnD,mBAAmB,CAC9B,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,UAAU,GAAG,IAAI,EAC5B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,8BAA8B,CAAC;CAkE3C"}
@@ -1,18 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BearbyAccount = exports.OperationTypeId = exports.OperationsType = exports.PUBLIC_NODE_RPC = void 0;
3
+ exports.BearbyAccount = exports.OperationTypeId = exports.OperationsType = void 0;
4
+ const web3_utils_1 = require("@massalabs/web3-utils");
4
5
  const bearby_js_1 = require("@hicaru/bearby.js");
5
6
  const RequestHandler_1 = require("../massaStation/RequestHandler");
6
- const jsonRpcMethods_1 = require("./jsonRpcMethods");
7
- const axios_1 = require("axios");
8
7
  /**
9
8
  * The maximum allowed gas for a read operation
10
9
  */
11
- const MAX_READ_BLOCK_GAS = BigInt(4294967295);
12
- /**
13
- * The RPC we are using to query the node
14
- */
15
- exports.PUBLIC_NODE_RPC = 'https://buildnet.massa.net/api/v2';
16
10
  var OperationsType;
17
11
  (function (OperationsType) {
18
12
  OperationsType[OperationsType["Payment"] = 0] = "Payment";
@@ -32,13 +26,8 @@ var OperationTypeId;
32
26
  OperationTypeId[OperationTypeId["ExecuteSC"] = 3] = "ExecuteSC";
33
27
  OperationTypeId[OperationTypeId["CallSC"] = 4] = "CallSC";
34
28
  })(OperationTypeId = exports.OperationTypeId || (exports.OperationTypeId = {}));
35
- const requestHeaders = {
36
- Accept: 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
37
- 'Content-Type': 'application/json',
38
- };
39
29
  class BearbyAccount {
40
30
  constructor({ address, name }, providerName) {
41
- this._nodeUrl = exports.PUBLIC_NODE_RPC;
42
31
  this._address = address;
43
32
  this._name = name ?? 'Bearby_account';
44
33
  this._providerName = providerName;
@@ -52,7 +41,6 @@ class BearbyAccount {
52
41
  providerName() {
53
42
  return this._providerName;
54
43
  }
55
- // TODO: Should be removed from account interface as it more a provider method
56
44
  async connect() {
57
45
  try {
58
46
  await bearby_js_1.web3.wallet.connect();
@@ -61,8 +49,8 @@ class BearbyAccount {
61
49
  console.log('Bearby connection error: ', ex);
62
50
  }
63
51
  }
64
- // needs testing
65
52
  async balance() {
53
+ // TODO: check if we need to connect every time
66
54
  await this.connect();
67
55
  // Not available on bearby. we have to manually call the api
68
56
  const body = {
@@ -71,7 +59,9 @@ class BearbyAccount {
71
59
  params: [[this._address]],
72
60
  id: 0,
73
61
  };
74
- const addressInfos = await (0, RequestHandler_1.postRequest)(exports.PUBLIC_NODE_RPC, body);
62
+ // get node url: This is a temporary solution. We should get the balance from the provider
63
+ const nodeUrl = await getNodesUrl();
64
+ const addressInfos = await (0, RequestHandler_1.postRequest)(nodeUrl, body);
75
65
  if (addressInfos.isError || addressInfos.error) {
76
66
  throw addressInfos.error.message;
77
67
  }
@@ -96,28 +86,24 @@ class BearbyAccount {
96
86
  base58Encoded: signature.signature,
97
87
  };
98
88
  }
99
- // need testing
100
- async buyRolls(amount, fee) {
89
+ async buyRolls(amount) {
101
90
  await this.connect();
102
91
  const operationId = await bearby_js_1.web3.massa.buyRolls(amount.toString());
103
92
  return {
104
93
  operationId,
105
94
  };
106
95
  }
107
- // need testing
108
- async sellRolls(amount, fee) {
96
+ async sellRolls(amount) {
109
97
  await this.connect();
110
98
  const operationId = await bearby_js_1.web3.massa.sellRolls(amount.toString());
111
99
  return {
112
100
  operationId,
113
101
  };
114
102
  }
115
- async sendTransaction(amount, recipientAddress, fee) {
103
+ async sendTransaction(amount, recipientAddress) {
116
104
  await this.connect();
117
105
  const operationId = await bearby_js_1.web3.massa.payment(amount.toString(), recipientAddress);
118
- return {
119
- operationId,
120
- };
106
+ return { operationId };
121
107
  }
122
108
  async callSC(contractAddress, functionName, parameter, amount, fee, maxGas, nonPersistentExecution = false) {
123
109
  await this.connect();
@@ -141,94 +127,12 @@ class BearbyAccount {
141
127
  });
142
128
  return { operationId };
143
129
  }
144
- /**
145
- * Retrieves the node's status.
146
- *
147
- * @remarks
148
- * The returned information includes:
149
- * - Whether the node is reachable
150
- * - The number of connected peers
151
- * - The node's version
152
- * - The node's configuration parameters
153
- *
154
- * @returns A promise that resolves to the node's status information.
155
- */
156
- async getNodeStatus() {
157
- const jsonRpcRequestMethod = jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STATUS;
158
- return await this.sendJsonRPCRequest(jsonRpcRequestMethod, []);
159
- }
160
- /**
161
- * Sends a post JSON rpc request to the node.
162
- *
163
- * @param resource - The rpc method to call.
164
- * @param params - The parameters to pass to the rpc method.
165
- *
166
- * @throws An error if the rpc method returns an error.
167
- *
168
- * @returns A promise that resolves as the result of the rpc method.
169
- */
170
- async sendJsonRPCRequest(resource, params) {
171
- let resp = null;
172
- resp = await this.promisifyJsonRpcCall(resource, params);
173
- // in case of rpc error, rethrow the error.
174
- if (resp.isError || resp.error) {
175
- throw resp.error;
176
- }
177
- return resp.result;
178
- }
179
- /**
180
- * Converts a json rpc call to a promise that resolves as a JsonRpcResponseData
181
- *
182
- * @privateRemarks
183
- * If there is an error while sending the request, the function catches the error, the isError
184
- * property is set to true, the result property set to null, and the error property set to a
185
- * new Error object with a message indicating that there was an error.
186
- *
187
- * @param resource - The rpc method to call.
188
- * @param params - The parameters to pass to the rpc method.
189
- *
190
- * @returns A promise that resolves as a JsonRpcResponseData.
191
- */
192
- async promisifyJsonRpcCall(resource, params) {
193
- let resp = null;
194
- const body = {
195
- jsonrpc: '2.0',
196
- method: resource,
197
- params: params,
198
- id: 0,
199
- };
200
- try {
201
- resp = await axios_1.default.post(this._nodeUrl, body, { headers: requestHeaders });
202
- }
203
- catch (ex) {
204
- return {
205
- isError: true,
206
- result: null,
207
- error: new Error('JSON.parse error: ' + String(ex)),
208
- };
209
- }
210
- const responseData = resp.data;
211
- if (responseData.error) {
212
- return {
213
- isError: true,
214
- result: null,
215
- error: new Error(responseData.error.message),
216
- };
217
- }
218
- return {
219
- isError: false,
220
- result: responseData.result,
221
- error: null,
222
- };
223
- }
224
130
  async nonPersistentCallSC(contractAddress, functionName, parameter, amount, fee, maxGas) {
225
- // not clean but bearby doesn't allow us to get its node urls
226
- const node = exports.PUBLIC_NODE_RPC;
227
131
  // Gas amount check
228
- if (maxGas > MAX_READ_BLOCK_GAS) {
132
+ if (maxGas > web3_utils_1.MAX_GAS_CALL) {
229
133
  throw new Error(`
230
134
  The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of
231
- ${MAX_READ_BLOCK_GAS.toString()}
135
+ ${web3_utils_1.MAX_GAS_CALL.toString()}
232
136
  `);
233
137
  }
234
138
  // convert parameter to an array of numbers
@@ -259,8 +163,9 @@ class BearbyAccount {
259
163
  ];
260
164
  // returns operation ids
261
165
  let jsonRpcCallResult = [];
166
+ const nodeUrl = await getNodesUrl();
262
167
  try {
263
- let resp = await (0, RequestHandler_1.postRequest)(node, body);
168
+ let resp = await (0, RequestHandler_1.postRequest)(nodeUrl, body);
264
169
  if (resp.isError || resp.error) {
265
170
  throw resp.error.message;
266
171
  }
@@ -282,4 +187,9 @@ class BearbyAccount {
282
187
  }
283
188
  }
284
189
  exports.BearbyAccount = BearbyAccount;
190
+ // TODO: Should be removed from account when bearby.js is updated
191
+ async function getNodesUrl() {
192
+ const info = (await bearby_js_1.web3.massa.getNodesStatus());
193
+ return web3_utils_1.CHAIN_ID_RPC_URL_MAP[info.result.chain_id];
194
+ }
285
195
  //# sourceMappingURL=BearbyAccount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":";;;AAQA,iDAAyC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AiB,CAAC,CAAC,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF;AA1UD,sCA0UC","sourcesContent":["import {\n Args,\n IContractReadOperationData,\n IContractReadOperationResponse,\n} from '@massalabs/web3-utils';\nimport { ITransactionDetails } from '..';\nimport { IAccountBalanceResponse, IAccountDetails } from '../account';\nimport { IAccount } from '../account/IAccount';\nimport { web3 } from '@hicaru/bearby.js';\nimport {\n postRequest,\n JsonRpcResponseData,\n} from '../massaStation/RequestHandler';\nimport { BalanceResponse } from './BalanceResponse';\nimport { NodeStatus } from './NodeStatus';\nimport { JSON_RPC_REQUEST_METHOD } from './jsonRpcMethods';\nimport axios, { AxiosRequestHeaders, AxiosResponse } from 'axios';\nimport { IAccountSignOutput } from '../account/AccountSign';\n/**\n * The maximum allowed gas for a read operation\n */\nconst MAX_READ_BLOCK_GAS = BigInt(4_294_967_295);\n\n/**\n * The RPC we are using to query the node\n */\nexport const PUBLIC_NODE_RPC = 'https://buildnet.massa.net/api/v2';\n\nexport enum OperationsType {\n Payment,\n RollBuy,\n RollSell,\n ExecuteSC,\n CallSC,\n}\n\n/**\n * Associates an operation type with a number.\n */\nexport enum OperationTypeId {\n Transaction = 0,\n RollBuy = 1,\n RollSell = 2,\n ExecuteSC = 3,\n CallSC = 4,\n}\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} as AxiosRequestHeaders;\n\nexport class BearbyAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n private _nodeUrl = PUBLIC_NODE_RPC;\n\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name ?? 'Bearby_account';\n this._providerName = providerName;\n }\n\n public address(): string {\n return this._address;\n }\n\n public name(): string {\n return this._name;\n }\n\n public providerName(): string {\n return this._providerName;\n }\n\n // TODO: Should be removed from account interface as it more a provider method\n public async connect() {\n try {\n await web3.wallet.connect();\n } catch (ex) {\n console.log('Bearby connection error: ', ex);\n }\n }\n\n // needs testing\n public async balance(): Promise<IAccountBalanceResponse> {\n await this.connect();\n // Not available on bearby. we have to manually call the api\n const body = {\n jsonrpc: '2.0',\n method: 'get_addresses',\n params: [[this._address]],\n id: 0,\n };\n\n const addressInfos = await postRequest<BalanceResponse>(\n PUBLIC_NODE_RPC,\n body,\n );\n\n if (addressInfos.isError || addressInfos.error) {\n throw addressInfos.error.message;\n }\n return {\n finalBalance: addressInfos.result.result[0].final_balance,\n candidateBalance: addressInfos.result.result[0].candidate_balance,\n } as IAccountBalanceResponse;\n }\n\n // need testing\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n await this.connect();\n\n let strData: string;\n if (data instanceof Uint8Array) {\n strData = new TextDecoder().decode(data);\n }\n if (data instanceof Buffer) {\n strData = data.toString();\n }\n const signature = await web3.wallet.signMessage(strData);\n return {\n publicKey: signature.publicKey,\n base58Encoded: signature.signature,\n };\n }\n\n // need testing\n public async buyRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n await this.connect();\n const operationId = await web3.massa.buyRolls(amount.toString());\n\n return {\n operationId,\n } as ITransactionDetails;\n }\n\n // need testing\n public async sellRolls(\n amount: bigint,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n await this.connect();\n const operationId = await web3.massa.sellRolls(amount.toString());\n\n return {\n operationId,\n } as ITransactionDetails;\n }\n\n public async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n fee: bigint,\n ): Promise<ITransactionDetails> {\n await this.connect();\n\n const operationId = await web3.massa.payment(\n amount.toString(),\n recipientAddress,\n );\n\n return {\n operationId,\n } as ITransactionDetails;\n }\n\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Args | Uint8Array,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n await this.connect();\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n amount,\n fee,\n maxGas,\n );\n }\n\n let unsafeParameters: Uint8Array;\n if (parameter instanceof Uint8Array) {\n unsafeParameters = parameter;\n } else {\n unsafeParameters = Uint8Array.from(parameter.serialize());\n }\n\n const operationId = await web3.contract.call({\n maxGas: Number(maxGas),\n coins: Number(amount),\n fee: Number(fee),\n targetAddress: contractAddress,\n functionName: functionName,\n unsafeParameters,\n });\n\n return { operationId };\n }\n\n /**\n * Retrieves the node's status.\n *\n * @remarks\n * The returned information includes:\n * - Whether the node is reachable\n * - The number of connected peers\n * - The node's version\n * - The node's configuration parameters\n *\n * @returns A promise that resolves to the node's status information.\n */\n public async getNodeStatus(): Promise<NodeStatus> {\n const jsonRpcRequestMethod = JSON_RPC_REQUEST_METHOD.GET_STATUS;\n return await this.sendJsonRPCRequest<NodeStatus>(jsonRpcRequestMethod, []);\n }\n\n /**\n * Sends a post JSON rpc request to the node.\n *\n * @param resource - The rpc method to call.\n * @param params - The parameters to pass to the rpc method.\n *\n * @throws An error if the rpc method returns an error.\n *\n * @returns A promise that resolves as the result of the rpc method.\n */\n protected async sendJsonRPCRequest<T>(\n resource: JSON_RPC_REQUEST_METHOD,\n params: object,\n ): Promise<T> {\n let resp: JsonRpcResponseData<T> = null;\n resp = await this.promisifyJsonRpcCall(resource, params);\n\n // in case of rpc error, rethrow the error.\n if (resp.isError || resp.error) {\n throw resp.error;\n }\n\n return resp.result;\n }\n\n /**\n * Converts a json rpc call to a promise that resolves as a JsonRpcResponseData\n *\n * @privateRemarks\n * If there is an error while sending the request, the function catches the error, the isError\n * property is set to true, the result property set to null, and the error property set to a\n * new Error object with a message indicating that there was an error.\n *\n * @param resource - The rpc method to call.\n * @param params - The parameters to pass to the rpc method.\n *\n * @returns A promise that resolves as a JsonRpcResponseData.\n */\n private async promisifyJsonRpcCall<T>(\n resource: JSON_RPC_REQUEST_METHOD,\n params: object,\n ): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse<JsonRpcResponseData<T>> = null;\n\n const body = {\n jsonrpc: '2.0',\n method: resource,\n params: params,\n id: 0,\n };\n\n try {\n resp = await axios.post(this._nodeUrl, body, { headers: requestHeaders });\n } catch (ex) {\n return {\n isError: true,\n result: null,\n error: new Error('JSON.parse error: ' + String(ex)),\n } as JsonRpcResponseData<T>;\n }\n\n const responseData: JsonRpcResponseData<T> = resp.data;\n\n if (responseData.error) {\n return {\n isError: true,\n result: null,\n error: new Error(responseData.error.message),\n } as JsonRpcResponseData<T>;\n }\n\n return {\n isError: false,\n result: responseData.result as T,\n error: null,\n } as JsonRpcResponseData<T>;\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n ): Promise<IContractReadOperationResponse> {\n // not clean but bearby doesn't allow us to get its node urls\n const node = PUBLIC_NODE_RPC;\n // Gas amount check\n if (maxGas > MAX_READ_BLOCK_GAS) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_READ_BLOCK_GAS.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: Number(maxGas),\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n coins: Number(amount),\n fee: Number(fee),\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n node,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n"]}
1
+ {"version":3,"file":"BearbyAccount.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyAccount.ts"],"names":[],"mappings":";;;AAAA,sDAM+B;AAI/B,iDAAyC;AACzC,mEAA6D;AAG7D;;GAEG;AAEH,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,yDAAO,CAAA;IACP,yDAAO,CAAA;IACP,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,uDAAM,CAAA;AACR,CAAC,EANW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAMzB;AAED;;GAEG;AACH,IAAY,eAMX;AAND,WAAY,eAAe;IACzB,mEAAe,CAAA;IACf,2DAAW,CAAA;IACX,6DAAY,CAAA;IACZ,+DAAa,CAAA;IACb,yDAAU,CAAA;AACZ,CAAC,EANW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAM1B;AAED,MAAa,aAAa;IAKxB,YAAmB,EAAE,OAAO,EAAE,IAAI,EAAmB,EAAE,YAAoB;QACzE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,IAAI,gBAAgB,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI;YACF,MAAM,gBAAI,CAAC,MAAM,CAAC,OAA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,EAAE,CAAQ,CAAC;IACxD,OAAO,iCAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import {\n Args,\n CHAIN_ID_RPC_URL_MAP,\n IContractReadOperationData,\n IContractReadOperationResponse,\n MAX_GAS_CALL,\n} from '@massalabs/web3-utils';\nimport { ITransactionDetails } from '..';\nimport { IAccountBalanceResponse, IAccountDetails } from '../account';\nimport { IAccount } from '../account/IAccount';\nimport { web3 } from '@hicaru/bearby.js';\nimport { postRequest } from '../massaStation/RequestHandler';\nimport { BalanceResponse } from './BalanceResponse';\nimport { IAccountSignOutput } from '../account/AccountSign';\n/**\n * The maximum allowed gas for a read operation\n */\n\nexport enum OperationsType {\n Payment,\n RollBuy,\n RollSell,\n ExecuteSC,\n CallSC,\n}\n\n/**\n * Associates an operation type with a number.\n */\nexport enum OperationTypeId {\n Transaction = 0,\n RollBuy = 1,\n RollSell = 2,\n ExecuteSC = 3,\n CallSC = 4,\n}\n\nexport class BearbyAccount implements IAccount {\n private _providerName: string;\n private _address: string;\n private _name: string;\n\n public constructor({ address, name }: IAccountDetails, providerName: string) {\n this._address = address;\n this._name = name ?? 'Bearby_account';\n this._providerName = providerName;\n }\n\n public address(): string {\n return this._address;\n }\n\n public name(): string {\n return this._name;\n }\n\n public providerName(): string {\n return this._providerName;\n }\n\n public async connect() {\n try {\n await web3.wallet.connect();\n } catch (ex) {\n console.log('Bearby connection error: ', ex);\n }\n }\n\n public async balance(): Promise<IAccountBalanceResponse> {\n // TODO: check if we need to connect every time\n await this.connect();\n // Not available on bearby. we have to manually call the api\n const body = {\n jsonrpc: '2.0',\n method: 'get_addresses',\n params: [[this._address]],\n id: 0,\n };\n\n // get node url: This is a temporary solution. We should get the balance from the provider\n const nodeUrl = await getNodesUrl();\n\n const addressInfos = await postRequest<BalanceResponse>(nodeUrl, body);\n\n if (addressInfos.isError || addressInfos.error) {\n throw addressInfos.error.message;\n }\n\n return {\n finalBalance: addressInfos.result.result[0].final_balance,\n candidateBalance: addressInfos.result.result[0].candidate_balance,\n } as IAccountBalanceResponse;\n }\n\n // need testing\n public async sign(\n data: Buffer | Uint8Array | string,\n ): Promise<IAccountSignOutput> {\n await this.connect();\n\n let strData: string;\n if (data instanceof Uint8Array) {\n strData = new TextDecoder().decode(data);\n }\n if (data instanceof Buffer) {\n strData = data.toString();\n }\n const signature = await web3.wallet.signMessage(strData);\n return {\n publicKey: signature.publicKey,\n base58Encoded: signature.signature,\n };\n }\n\n public async buyRolls(amount: bigint): Promise<ITransactionDetails> {\n await this.connect();\n const operationId = await web3.massa.buyRolls(amount.toString());\n\n return {\n operationId,\n } as ITransactionDetails;\n }\n\n public async sellRolls(amount: bigint): Promise<ITransactionDetails> {\n await this.connect();\n const operationId = await web3.massa.sellRolls(amount.toString());\n\n return {\n operationId,\n } as ITransactionDetails;\n }\n\n public async sendTransaction(\n amount: bigint,\n recipientAddress: string,\n ): Promise<ITransactionDetails> {\n await this.connect();\n\n const operationId = await web3.massa.payment(\n amount.toString(),\n recipientAddress,\n );\n\n return { operationId };\n }\n\n public async callSC(\n contractAddress: string,\n functionName: string,\n parameter: Args | Uint8Array,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n nonPersistentExecution = false,\n ): Promise<ITransactionDetails | IContractReadOperationResponse> {\n await this.connect();\n\n if (nonPersistentExecution) {\n return this.nonPersistentCallSC(\n contractAddress,\n functionName,\n parameter,\n amount,\n fee,\n maxGas,\n );\n }\n\n let unsafeParameters: Uint8Array;\n if (parameter instanceof Uint8Array) {\n unsafeParameters = parameter;\n } else {\n unsafeParameters = Uint8Array.from(parameter.serialize());\n }\n\n const operationId = await web3.contract.call({\n maxGas: Number(maxGas),\n coins: Number(amount),\n fee: Number(fee),\n targetAddress: contractAddress,\n functionName: functionName,\n unsafeParameters,\n });\n\n return { operationId };\n }\n\n public async nonPersistentCallSC(\n contractAddress: string,\n functionName: string,\n parameter: Uint8Array | Args,\n amount: bigint,\n fee: bigint,\n maxGas: bigint,\n ): Promise<IContractReadOperationResponse> {\n // Gas amount check\n if (maxGas > MAX_GAS_CALL) {\n throw new Error(\n `\n The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of \n ${MAX_GAS_CALL.toString()}\n `,\n );\n }\n\n // convert parameter to an array of numbers\n let argumentArray = [];\n if (parameter instanceof Uint8Array) {\n argumentArray = Array.from(parameter);\n } else {\n argumentArray = Array.from(parameter.serialize());\n }\n // setup the request body\n const data = {\n max_gas: Number(maxGas),\n target_address: contractAddress,\n target_function: functionName,\n parameter: argumentArray,\n caller_address: this._address,\n coins: Number(amount),\n fee: Number(fee),\n };\n const body = [\n {\n jsonrpc: '2.0',\n method: 'execute_read_only_call',\n params: [[data]],\n id: 0,\n },\n ];\n // returns operation ids\n let jsonRpcCallResult: Array<IContractReadOperationData> = [];\n const nodeUrl = await getNodesUrl();\n try {\n let resp = await postRequest<Array<IContractReadOperationData>>(\n nodeUrl,\n body,\n );\n if (resp.isError || resp.error) {\n throw resp.error.message;\n }\n jsonRpcCallResult = resp.result;\n } catch (ex) {\n throw new Error(\n `MassaStation account: error while interacting with smart contract: ${ex}`,\n );\n }\n if (jsonRpcCallResult.length <= 0) {\n throw new Error(\n `Read operation bad response. No results array in json rpc response. Inspect smart contract`,\n );\n }\n if (jsonRpcCallResult[0].result.Error) {\n throw new Error(jsonRpcCallResult[0].result.Error);\n }\n return {\n returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),\n info: jsonRpcCallResult[0],\n };\n }\n}\n\n// TODO: Should be removed from account when bearby.js is updated\nasync function getNodesUrl(): Promise<string> {\n const info = (await web3.massa.getNodesStatus()) as any;\n return CHAIN_ID_RPC_URL_MAP[info.result.chain_id];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyConnect.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyConnect.ts"],"names":[],"mappings":"AAEA,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAErD;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAGtD"}
1
+ {"version":3,"file":"BearbyConnect.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyConnect.ts"],"names":[],"mappings":"AAEA,wBAAsB,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAErD;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAMnD;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEtD"}
@@ -17,7 +17,6 @@ async function connectBearby() {
17
17
  exports.connectBearby = connectBearby;
18
18
  async function disconnectBearby() {
19
19
  await bearby_js_1.web3.wallet.disconnect();
20
- console.log('Bearby disconnected');
21
20
  }
22
21
  exports.disconnectBearby = disconnectBearby;
23
22
  //# sourceMappingURL=BearbyConnect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyConnect.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyConnect.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAElC,KAAK,UAAU,YAAY;IAChC,OAAO,gBAAI,CAAC,MAAM,CAAC,SAAS,CAAC;AAC/B,CAAC;AAFD,oCAEC;AAEM,KAAK,UAAU,aAAa;IACjC,IAAI;QACF,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;KAC7B;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KACjB;AACH,CAAC;AAND,sCAMC;AAEM,KAAK,UAAU,gBAAgB;IACpC,MAAM,gBAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAC/B,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AACrC,CAAC;AAHD,4CAGC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\n\nexport async function detectBearby(): Promise<boolean> {\n return web3.wallet.installed;\n}\n\nexport async function connectBearby(): Promise<void> {\n try {\n await web3.wallet.connect();\n } catch (ex) {\n console.log(ex);\n }\n}\n\nexport async function disconnectBearby(): Promise<void> {\n await web3.wallet.disconnect();\n console.log('Bearby disconnected');\n}\n"]}
1
+ {"version":3,"file":"BearbyConnect.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyConnect.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAElC,KAAK,UAAU,YAAY;IAChC,OAAO,gBAAI,CAAC,MAAM,CAAC,SAAS,CAAC;AAC/B,CAAC;AAFD,oCAEC;AAEM,KAAK,UAAU,aAAa;IACjC,IAAI;QACF,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;KAC7B;IAAC,OAAO,EAAE,EAAE;QACX,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KACjB;AACH,CAAC;AAND,sCAMC;AAEM,KAAK,UAAU,gBAAgB;IACpC,MAAM,gBAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;AACjC,CAAC;AAFD,4CAEC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\n\nexport async function detectBearby(): Promise<boolean> {\n return web3.wallet.installed;\n}\n\nexport async function connectBearby(): Promise<void> {\n try {\n await web3.wallet.connect();\n } catch (ex) {\n console.log(ex);\n }\n}\n\nexport async function disconnectBearby(): Promise<void> {\n await web3.wallet.disconnect();\n}\n"]}
@@ -1,21 +1,17 @@
1
+ import { JsonRPCResponse, JsonRPCResponseNodeStatus } from '@hicaru/bearby.js';
1
2
  import { IAccount, IAccountDetails } from '../account';
2
3
  import { IAccountDeletionResponse, IAccountImportResponse, IProvider } from '../provider';
3
4
  export declare class BearbyProvider implements IProvider {
4
5
  private providerName;
5
- /**
6
- * Provider constructor
7
- *
8
- * @param providerName - The name of the provider.
9
- * @returns An instance of the Provider class.
10
- */
11
- constructor(providerName: string);
12
6
  name(): string;
13
7
  accounts(): Promise<IAccount[]>;
14
- importAccount(publicKey: string, privateKey: string): Promise<IAccountImportResponse>;
15
- deleteAccount(address: string): Promise<IAccountDeletionResponse>;
8
+ importAccount(): Promise<IAccountImportResponse>;
9
+ deleteAccount(): Promise<IAccountDeletionResponse>;
16
10
  getNodesUrls(): Promise<string[]>;
11
+ getChainId(): Promise<bigint>;
17
12
  getNetwork(): Promise<string>;
18
- generateNewAccount(name: string): Promise<IAccountDetails>;
13
+ getNodeStatus(): Promise<JsonRPCResponse<JsonRPCResponseNodeStatus>>;
14
+ generateNewAccount(): Promise<IAccountDetails>;
19
15
  /**
20
16
  * Subscribes to account changes.
21
17
  *
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,SAAS,EACV,MAAM,aAAa,CAAC;AAGrB,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM;IAIhC,IAAI,IAAI,MAAM;IAIR,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAa/B,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAIrB,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIjC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIvE;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,I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;QAC/D,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB;IAID;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG;QAChE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB;IAID;;;;;;OAMG;IACU,OAAO;IAIpB;;;;;;OAMG;IACU,UAAU;IAIvB;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAI3B;;;;OAIG;IACI,OAAO,IAAI,OAAO;CAG1B"}
@@ -3,15 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BearbyProvider = void 0;
4
4
  const bearby_js_1 = require("@hicaru/bearby.js");
5
5
  const BearbyAccount_1 = require("./BearbyAccount");
6
+ const web3_utils_1 = require("@massalabs/web3-utils");
6
7
  class BearbyProvider {
7
- /**
8
- * Provider constructor
9
- *
10
- * @param providerName - The name of the provider.
11
- * @returns An instance of the Provider class.
12
- */
13
- constructor(providerName) {
14
- this.providerName = providerName;
8
+ constructor() {
9
+ this.providerName = 'BEARBY';
15
10
  }
16
11
  name() {
17
12
  return this.providerName;
@@ -27,20 +22,31 @@ class BearbyProvider {
27
22
  };
28
23
  return [new BearbyAccount_1.BearbyAccount(account, this.providerName)];
29
24
  }
30
- async importAccount(publicKey, privateKey) {
25
+ async importAccount() {
31
26
  throw new Error('Method not implemented.');
32
27
  }
33
- async deleteAccount(address) {
28
+ async deleteAccount() {
34
29
  throw new Error('Method not implemented.');
35
30
  }
36
31
  async getNodesUrls() {
37
- return ['https://buildnet.massa.net/api/v2'];
32
+ const chainId = await this.getChainId();
33
+ // TODO: Check why we need to put in an array
34
+ return [web3_utils_1.CHAIN_ID_RPC_URL_MAP[chainId.toString()]];
35
+ }
36
+ async getChainId() {
37
+ // TODO: remove any when bearby.js is updated https://github.com/bearby-wallet/bearby-web3/issues/10
38
+ const info = (await bearby_js_1.web3.massa.getNodesStatus());
39
+ return BigInt(info.result.chain_id);
38
40
  }
39
41
  async getNetwork() {
40
42
  const network = await bearby_js_1.web3.wallet.network;
41
43
  return network.net;
42
44
  }
43
- async generateNewAccount(name) {
45
+ // TODO: Harmonize the response with other providers
46
+ async getNodeStatus() {
47
+ return bearby_js_1.web3.massa.getNodesStatus();
48
+ }
49
+ async generateNewAccount() {
44
50
  throw new Error('Method not implemented.');
45
51
  }
46
52
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAOzC,mDAAgD;AAEhD,MAAa,cAAc;IAGzB;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,gBAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;YACzC,IAAI,EAAE,QAAQ;SACf,CAAC;QACF,OAAO,CAAC,IAAI,6BAAa,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,SAAiB,EACjB,UAAkB;QAElB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,OAAe;QAEf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,OAAO,GAAG,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAkC;QAG5D,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAmC;QAG7D,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,gBAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,gBAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,OAAO;QACZ,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;CACF;AAtJD,wCAsJC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\n\nexport class BearbyProvider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n return ['https://buildnet.massa.net/api/v2'];\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n\n return network.net;\n }\n\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Subscribes to account changes.\n *\n * @param callback - Callback to be called when the account changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenAccountChanges((base58) => {\n * console.log(base58);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenAccountChanges(callback: (base58: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.account.subscribe((base58) => callback(base58));\n }\n\n /**\n * Subscribes to network changes.\n *\n * @param callback - Callback to be called when the network changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenNetworkChanges((network) => {\n * console.log(network);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenNetworkChanges(callback: (network: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.network.subscribe((network) => callback(network));\n }\n\n /**\n * Connects to the wallet.\n *\n * @remarks\n * This method will attempt to establish a connection with the wallet.\n * If the connection fails, it will log the error message.\n */\n public async connect() {\n return web3.wallet.connect();\n }\n\n /**\n * Disconnects from the wallet.\n *\n * @remarks\n * This method will attempt to disconnect from the wallet.\n * If the disconnection fails, it will log the error message.\n */\n public async disconnect() {\n return web3.wallet.disconnect();\n }\n\n /**\n * Checks if the wallet is connected.\n *\n * @returns a boolean indicating whether the wallet is connected.\n */\n public connected(): boolean {\n return web3.wallet.connected;\n }\n\n /**\n * Checks if the wallet is enabled.\n *\n * @returns a boolean indicating whether the wallet is enabled.\n */\n public enabled(): boolean {\n return web3.wallet.enabled;\n }\n}\n"]}
1
+ {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":";;;AAAA,iDAI2B;AAO3B,mDAAgD;AAChD,sDAA6D;AAE7D,MAAa,cAAc;IAA3B;QACU,iBAAY,GAAG,QAAQ,CAAC;IAqJlC,CAAC;IAnJQ,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,gBAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;YACzC,IAAI,EAAE,QAAQ;SACf,CAAC;QAEF,OAAO,CAAC,IAAI,6BAAa,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,aAAa;QACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,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AMG;IACI,KAAK,CAAC,OAAO;QAClB,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,UAAU;QACrB,OAAO,gBAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,gBAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,OAAO;QACZ,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7B,CAAC;CACF;AAtJD,wCAsJC","sourcesContent":["import {\n JsonRPCResponse,\n JsonRPCResponseNodeStatus,\n web3,\n} from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\nimport { CHAIN_ID_RPC_URL_MAP } from '@massalabs/web3-utils';\n\nexport class BearbyProvider implements IProvider {\n private providerName = 'BEARBY';\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n const chainId = await this.getChainId();\n // TODO: Check why we need to put in an array\n return [CHAIN_ID_RPC_URL_MAP[chainId.toString()]];\n }\n\n public async getChainId(): Promise<bigint> {\n // TODO: remove any when bearby.js is updated https://github.com/bearby-wallet/bearby-web3/issues/10\n const info = (await web3.massa.getNodesStatus()) as any;\n return BigInt(info.result.chain_id);\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n return network.net;\n }\n\n // TODO: Harmonize the response with other providers\n public async getNodeStatus(): Promise<\n JsonRPCResponse<JsonRPCResponseNodeStatus>\n > {\n return web3.massa.getNodesStatus();\n }\n\n public async generateNewAccount(): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Subscribes to account changes.\n *\n * @param callback - Callback to be called when the account changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenAccountChanges((base58) => {\n * console.log(base58);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenAccountChanges(callback: (base58: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.account.subscribe((base58) => callback(base58));\n }\n\n /**\n * Subscribes to network changes.\n *\n * @param callback - Callback to be called when the network changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenNetworkChanges((network) => {\n * console.log(network);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenNetworkChanges(callback: (network: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.network.subscribe((network) => callback(network));\n }\n\n /**\n * Connects to the wallet.\n *\n * @remarks\n * This method will attempt to establish a connection with the wallet.\n * If the connection fails, it will log the error message.\n */\n public async connect() {\n return web3.wallet.connect();\n }\n\n /**\n * Disconnects from the wallet.\n *\n * @remarks\n * This method will attempt to disconnect from the wallet.\n * If the disconnection fails, it will log the error message.\n */\n public async disconnect() {\n return web3.wallet.disconnect();\n }\n\n /**\n * Checks if the wallet is connected.\n *\n * @returns a boolean indicating whether the wallet is connected.\n */\n public connected(): boolean {\n return web3.wallet.connected;\n }\n\n /**\n * Checks if the wallet is enabled.\n *\n * @returns a boolean indicating whether the wallet is enabled.\n */\n public enabled(): boolean {\n return web3.wallet.enabled;\n }\n}\n"]}
@@ -19,7 +19,6 @@ export type AllowedResponses = object | IAccountBalanceResponse | IAccountSignRe
19
19
  declare class Connector {
20
20
  private registeredProviders;
21
21
  private pendingRequests;
22
- private massaStationListener;
23
22
  private providersInfo;
24
23
  /**
25
24
  * Connector constructor
@@ -46,8 +45,6 @@ declare class Connector {
46
45
  *
47
46
  */
48
47
  private register;
49
- private initMassaStationListener;
50
- startMassaStationDiscovery(): Promise<void>;
51
48
  /**
52
49
  * This method sends a message from the webpage script to the content script.
53
50
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Connector.d.ts","sourceRoot":"","sources":["../../../src/connector/Connector.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,IAAI,CAAC;AAOZ,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,KAAK,gBAAgB,GAAG,CACtB,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,KAAK,GAAG,IAAI,KAChB,OAAO,CAAC;AAEb,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,sBAAsB,GACtB,mBAAmB,GACnB,qBAAqB,GACrB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,uBAAuB,GACvB,oBAAoB,GACpB,sBAAsB,GACtB,wBAAwB,GACxB,QAAQ,EAAE,GACV,MAAM,CAAC;AAEX;;;;;;GAMG;AACH,cAAM,SAAS;IACb,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,eAA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,GACN,uBAAuB,GACvB,oBAAoB,GACpB,sBAAsB,GACtB,wBAAwB,GACxB,QAAQ,EAAE,GACV,MAAM,CAAC;AAEX;;;;;;GAMG;AACH,cAAM,SAAS;IACb,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,aAAa,CAAkC;IAEvD;;;;;;;;;;;OAWG;;IAgBH;;;;;;;;;;OAUG;IACH,OAAO,CAAC,QAAQ;IAwBhB;;;;;;;;;;;;;;;OAeG;IAEI,0BAA0B,CAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,eAAe,EACvB,gBAAgB,EAAE,gBAAgB;IAgCpC;;;;;OAKG;IACI,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAInD;;;OAGG;IACI,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIpE;;;;;;;OAOG;IACH,OAAO,CAAC,+BAA+B;CAuBxC;AAED,eAAO,MAAM,SAAS,WAAkB,CAAC"}
@@ -12,8 +12,6 @@ exports.connector = exports.MASSA_WINDOW_OBJECT = void 0;
12
12
  */
13
13
  const uid_1 = require("uid");
14
14
  const __1 = require("..");
15
- const MassaStationDiscovery_1 = require("../massaStation/MassaStationDiscovery");
16
- const MassaStationProvider_1 = require("../massaStation/MassaStationProvider");
17
15
  /**
18
16
  * A constant string that is used to identify the HTML element that is used for
19
17
  * communication between the web page script and the content script.
@@ -44,8 +42,6 @@ class Connector {
44
42
  this.providersInfo = {};
45
43
  if (typeof document !== 'undefined') {
46
44
  this.pendingRequests = new Map();
47
- this.massaStationListener = new MassaStationDiscovery_1.MassaStationDiscovery();
48
- this.initMassaStationListener();
49
45
  this.register();
50
46
  // start listening to messages from content script
51
47
  document
@@ -86,23 +82,6 @@ class Connector {
86
82
  });
87
83
  }
88
84
  }
89
- initMassaStationListener() {
90
- this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCOVERED, (walletModule) => {
91
- this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${exports.MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
92
- this.providersInfo[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = walletModule;
93
- });
94
- this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCONNECTED, () => {
95
- delete this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME];
96
- });
97
- }
98
- async startMassaStationDiscovery() {
99
- try {
100
- await this.massaStationListener.startListening();
101
- }
102
- catch (e) {
103
- console.log('get MassaStation provider error: ', e);
104
- }
105
- }
106
85
  /**
107
86
  * This method sends a message from the webpage script to the content script.
108
87
  *