@massalabs/wallet-provider 1.5.2-dev.20240112111518 → 1.5.2-dev.20240112130554
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/massaStation/MassaStationDiscovery.d.ts +0 -2
- package/dist/cmd/massaStation/MassaStationDiscovery.d.ts.map +1 -1
- package/dist/cmd/massaStation/MassaStationDiscovery.js +0 -2
- package/dist/cmd/massaStation/MassaStationDiscovery.js.map +1 -1
- package/dist/cmd/massaStation/MassaStationProvider.d.ts +2 -0
- package/dist/cmd/massaStation/MassaStationProvider.d.ts.map +1 -1
- package/dist/cmd/massaStation/MassaStationProvider.js +31 -4
- package/dist/cmd/massaStation/MassaStationProvider.js.map +1 -1
- package/dist/cmd/massaStation/types.d.ts +6 -0
- package/dist/cmd/massaStation/types.d.ts.map +1 -1
- package/dist/cmd/massaStation/types.js.map +1 -1
- package/dist/cmd/provider/IProvider.d.ts +6 -0
- package/dist/cmd/provider/IProvider.d.ts.map +1 -1
- package/dist/cmd/provider/IProvider.js.map +1 -1
- package/dist/esm/massaStation/MassaStationDiscovery.d.ts +0 -2
- package/dist/esm/massaStation/MassaStationDiscovery.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationDiscovery.js +0 -2
- package/dist/esm/massaStation/MassaStationDiscovery.js.map +1 -1
- package/dist/esm/massaStation/MassaStationProvider.d.ts +2 -0
- package/dist/esm/massaStation/MassaStationProvider.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationProvider.js +32 -4
- package/dist/esm/massaStation/MassaStationProvider.js.map +1 -1
- package/dist/esm/massaStation/types.d.ts +6 -0
- package/dist/esm/massaStation/types.d.ts.map +1 -1
- package/dist/esm/massaStation/types.js.map +1 -1
- package/dist/esm/provider/IProvider.d.ts +6 -0
- package/dist/esm/provider/IProvider.d.ts.map +1 -1
- package/dist/esm/provider/IProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -33,8 +33,6 @@ export declare class MassaStationDiscovery extends EventEmitter {
|
|
|
33
33
|
/**
|
|
34
34
|
* MassaStation constructor
|
|
35
35
|
*
|
|
36
|
-
* @param pollIntervalMillis - Polling interval defined in milliseconds
|
|
37
|
-
*
|
|
38
36
|
* @remarks
|
|
39
37
|
* - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which
|
|
40
38
|
* the MassaStation pinging is triggered and if a successful response is fetched,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC;;GAEG;AACH,eAAO,MAAM,2BAA2B,yCACA,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAI7E;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,YAAY,CAAS;IAE7B
|
|
1
|
+
{"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC;;GAEG;AACH,eAAO,MAAM,2BAA2B,yCACA,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAI7E;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;;;;;;;;;OAaG;;IAOH;;;;OAIG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB7C"}
|
|
@@ -37,8 +37,6 @@ class MassaStationDiscovery extends events_1.EventEmitter {
|
|
|
37
37
|
/**
|
|
38
38
|
* MassaStation constructor
|
|
39
39
|
*
|
|
40
|
-
* @param pollIntervalMillis - Polling interval defined in milliseconds
|
|
41
|
-
*
|
|
42
40
|
* @remarks
|
|
43
41
|
* - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which
|
|
44
42
|
* the MassaStation pinging is triggered and if a successful response is fetched,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAsC;AACtC,qDAA8C;AAG9C;;GAEG;AACU,QAAA,2BAA2B,GACtC,sCAAsC,CAAC;AAEzC;;GAEG;AACU,QAAA,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE;;GAEG;AACU,QAAA,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAC7C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,qBAAY;IAGrD
|
|
1
|
+
{"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAsC;AACtC,qDAA8C;AAG9C;;GAEG;AACU,QAAA,2BAA2B,GACtC,sCAAsC,CAAC;AAEzC;;GAEG;AACU,QAAA,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE;;GAEG;AACU,QAAA,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAC7C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,qBAAY;IAGrD;;;;;;;;;;;;;OAaG;IACH;QACE,KAAK,EAAE,CAAC;QAjBF,iBAAY,GAAG,KAAK,CAAC;QAmB3B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc;QACzB,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAU,EAC3B,mCAA2B,EAC3B,IAAI,CACL,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CACnC,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,IAAI,KAAK,qBAAqB;gBACrC,MAAM,CAAC,MAAM,KAAK,uBAAuB,CAC5C,CAAC;YACF,IAAI,YAAY,EAAE;gBAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;gBACzB,IAAI,CAAC,IAAI,CAAC,mCAA2B,EAAE,YAAY,CAAC,CAAC;aACtD;SACF;aAAM,IAAI,IAAI,CAAC,YAAY,EAAE;YAC5B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,qCAA6B,CAAC,CAAC;SAC1C;IACH,CAAC;CACF;AAjDD,sDAiDC","sourcesContent":["/**\n * This file defines a TypeScript class named MassaStationDiscovery.\n * The class is being used to recursively search for a connection to MassaStation's server\n * and if so report this via emitting messages.\n *\n * @remarks\n * - If you are only looking to use our library, the connector MassaStationDiscovery will not be useful to you.\n * - If you want to work on this repo, you will probably be interested in this object\n *\n */\n\nimport { EventEmitter } from 'events';\nimport { getRequest } from './RequestHandler';\nimport { PluginManagerBody } from './types';\n\n/**\n * Url used for the MassaStation discovery and pinging the MassaStation server's index.html\n */\nexport const MASSA_STATION_DISCOVERY_URL =\n 'https://station.massa/plugin-manager';\n\n/**\n * A message emitted on successful MassaStation discovery\n */\nexport const ON_MASSA_STATION_DISCOVERED = 'ON_MASSA_STATION_DISCOVERED';\n\n/**\n * A message emitted on MassaStation disconnect\n */\nexport const ON_MASSA_STATION_DISCONNECTED = 'ON_MASSA_STATION_DISCONNECTED';\n\nconst MS_WALLET_PLUGIN_NAME = 'Massa Wallet';\nconst MS_WALLET_PLUGIN_AUTHOR = 'Massa Labs';\n/**\n * This file defines a TypeScript class named MassaStation.\n * The class is being used to recursively ping MassaStation's server\n * and if a response is received emit a message so MassaStation can be enlisted as\n * a wallet provider in the `Connector` class.\n */\nexport class MassaStationDiscovery extends EventEmitter {\n private isDiscovered = false;\n\n /**\n * MassaStation constructor\n *\n * @remarks\n * - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which\n * the MassaStation pinging is triggered and if a successful response is fetched,\n * a message `ON_MASSA_STATION_DISCOVERED` is emitted that MassaStation has been discovered\n * as a wallet provider upon which the `Connector` class will enlist MassaStation as a wallet provider\n * - If once found, but then disconnected the following message `ON_MASSA_STATION_DISCONNECTED` is being emitted\n * so that the `Connector` class delists MassaStation as a wallet provider\n *\n * @returns An instance of the MassaStation class.\n *\n */\n public constructor() {\n super();\n\n this.startListening = this.startListening.bind(this);\n }\n\n /**\n * A method to start listening for a connection to MassaStation's server.\n *\n * @returns void\n */\n public async startListening(): Promise<void> {\n const resp = await getRequest<PluginManagerBody>(\n MASSA_STATION_DISCOVERY_URL,\n 2000,\n );\n\n if (!resp.isError) {\n const walletModule = resp.result.find(\n (module) =>\n module.name === MS_WALLET_PLUGIN_NAME &&\n module.author === MS_WALLET_PLUGIN_AUTHOR,\n );\n if (walletModule) {\n this.isDiscovered = true;\n this.emit(ON_MASSA_STATION_DISCOVERED, walletModule);\n }\n } else if (this.isDiscovered) {\n this.isDiscovered = false;\n this.emit(ON_MASSA_STATION_DISCONNECTED);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationProvider.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EAGvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EAGvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAY,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAS5D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAsB,MAAM,SAAS,CAAC;AAGzD;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAoE,CAAC;AAE5G;;GAEG;AACH,eAAO,MAAM,iCAAiC,QAA0C,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,2BAA2B,iBAAiB,CAAC;AAO1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED,aAAK,yBAAyB;IAC5B,EAAE,OAAO;IACT,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IAYjC,OAAO,CAAC,KAAK;IAXhC,OAAO,CAAC,YAAY,CAA+B;IAEnD,OAAO,CAAC,0BAA0B,CAAsB;IACxD,OAAO,CAAC,cAAc,CAAW;IAEjC;;;;;OAKG;gBACwB,KAAK,EAAE,UAAU;IAE5C;;;OAGG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;;OAKG;IACU,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiC5C;;;;;;;;OAQG;IACU,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IA2BlC;;;;;OAKG;IACU,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAgDpC;;;;;;OAMG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAkB9C;;;;;;OAMG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAyB1C;;;;OAIG;IACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAyBhE,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;IAOnC,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;CA4B3C"}
|
|
@@ -5,6 +5,7 @@ const AccountDeletion_1 = require("../provider/AccountDeletion");
|
|
|
5
5
|
const AccountImport_1 = require("../provider/AccountImport");
|
|
6
6
|
const RequestHandler_1 = require("./RequestHandler");
|
|
7
7
|
const MassaStationAccount_1 = require("./MassaStationAccount");
|
|
8
|
+
const events_1 = require("events");
|
|
8
9
|
/**
|
|
9
10
|
* MassaStation url
|
|
10
11
|
*/
|
|
@@ -21,6 +22,10 @@ exports.MASSA_STATION_IMPORT_ACCOUNTS_URL = `${exports.MASSA_STATION_ACCOUNTS_UR
|
|
|
21
22
|
* MassaStation's wallet provider name
|
|
22
23
|
*/
|
|
23
24
|
exports.MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';
|
|
25
|
+
/**
|
|
26
|
+
* Events emitted by MassaStation
|
|
27
|
+
*/
|
|
28
|
+
const MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';
|
|
24
29
|
var MassaStationAccountStatus;
|
|
25
30
|
(function (MassaStationAccountStatus) {
|
|
26
31
|
MassaStationAccountStatus["OK"] = "ok";
|
|
@@ -41,6 +46,7 @@ class MassaStationProvider {
|
|
|
41
46
|
constructor(infos) {
|
|
42
47
|
this.infos = infos;
|
|
43
48
|
this.providerName = exports.MASSA_STATION_PROVIDER_NAME;
|
|
49
|
+
this.massaStationEventsListener = new events_1.default();
|
|
44
50
|
}
|
|
45
51
|
/**
|
|
46
52
|
* This method returns the name of the provider.
|
|
@@ -184,12 +190,18 @@ class MassaStationProvider {
|
|
|
184
190
|
* @returns a Promise that resolves to a network.
|
|
185
191
|
*/
|
|
186
192
|
async getNetwork() {
|
|
187
|
-
let nodesResponse = null;
|
|
188
193
|
try {
|
|
189
|
-
nodesResponse = await (0, RequestHandler_1.getRequest)(`${exports.MASSA_STATION_URL}massa/node`);
|
|
194
|
+
const nodesResponse = await (0, RequestHandler_1.getRequest)(`${exports.MASSA_STATION_URL}massa/node`);
|
|
190
195
|
if (nodesResponse.isError || nodesResponse.error) {
|
|
191
196
|
throw nodesResponse.error.message;
|
|
192
197
|
}
|
|
198
|
+
if (this.currentNetwork?.name !== nodesResponse.result.network) {
|
|
199
|
+
this.currentNetwork = {
|
|
200
|
+
name: nodesResponse.result.network,
|
|
201
|
+
url: nodesResponse.result.url,
|
|
202
|
+
chainId: BigInt(nodesResponse.result.chainId),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
193
205
|
const nodes = nodesResponse.result;
|
|
194
206
|
return nodes.network;
|
|
195
207
|
}
|
|
@@ -227,8 +239,23 @@ class MassaStationProvider {
|
|
|
227
239
|
return undefined;
|
|
228
240
|
}
|
|
229
241
|
listenNetworkChanges(callback) {
|
|
230
|
-
|
|
231
|
-
|
|
242
|
+
this.massaStationEventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) => callback(evt));
|
|
243
|
+
// check periodically if network changed
|
|
244
|
+
const intervalId = setInterval(async () => {
|
|
245
|
+
const currentNetwork = this.currentNetwork?.name;
|
|
246
|
+
const network = await this.getNetwork();
|
|
247
|
+
if (currentNetwork !== network) {
|
|
248
|
+
this.massaStationEventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);
|
|
249
|
+
}
|
|
250
|
+
}, 500);
|
|
251
|
+
return {
|
|
252
|
+
unsubscribe: () => {
|
|
253
|
+
clearInterval(intervalId);
|
|
254
|
+
this.massaStationEventsListener.removeListener(MASSA_STATION_NETWORK_CHANGED,
|
|
255
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
256
|
+
() => { });
|
|
257
|
+
},
|
|
258
|
+
};
|
|
232
259
|
}
|
|
233
260
|
}
|
|
234
261
|
exports.MassaStationProvider = MassaStationProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":";;;AAAA,iEAGqC;AACrC,6DAImC;AAEnC,qDAM0B;AAC1B,+DAA4D;AAK5D;;GAEG;AACU,QAAA,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AACU,QAAA,0BAA0B,GAAG,GAAG,yBAAiB,6CAA6C,CAAC;AAE5G;;GAEG;AACU,QAAA,iCAAiC,GAAG,GAAG,kCAA0B,UAAU,CAAC;AAEzF;;GAEG;AACU,QAAA,2BAA2B,GAAG,cAAc,CAAC;AAiB1D,IAAK,yBAGJ;AAHD,WAAK,yBAAyB;IAC5B,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHI,yBAAyB,KAAzB,yBAAyB,QAG7B;AAED;;;;GAIG;AACH,MAAa,oBAAoB;IAG/B;;;;;OAKG;IACH,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,CAAC,KAAK,CAAC,oCAAoC,EAAE,EAAE,CAAC,CAAC;YACxD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,IAAI,4BAA4B,GAC9B,IAAI,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,kCAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrD,IAAI;YACF,4BAA4B,GAAG,MAAM,IAAA,4BAAW,EAC9C,kCAA0B,GAAG,GAAG,GAAG,IAAI,EACvC,EAAE,CACH,CAAC;YACF,IACE,4BAA4B,CAAC,OAAO;gBACpC,4BAA4B,CAAC,KAAK,EAClC;gBACA,MAAM,4BAA4B,CAAC,KAAK,CAAC,OAAO,CAAC;aAClD;YACD,OAAO;gBACL,OAAO,EAAE,4BAA4B,CAAC,MAAM,CAAC,OAAO;gBACpD,IAAI,EAAE,4BAA4B,CAAC,MAAM,CAAC,QAAQ;aAChC,CAAC;SACtB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA1PD,oDA0PC","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo } from './types';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\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\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\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(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\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<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n\n public listenNetworkChanges(\n callback: (network: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Network Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":";;;AAAA,iEAGqC;AACrC,6DAImC;AAEnC,qDAM0B;AAC1B,+DAA4D;AAI5D,mCAAkC;AAElC;;GAEG;AACU,QAAA,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AACU,QAAA,0BAA0B,GAAG,GAAG,yBAAiB,6CAA6C,CAAC;AAE5G;;GAEG;AACU,QAAA,iCAAiC,GAAG,GAAG,kCAA0B,UAAU,CAAC;AAEzF;;GAEG;AACU,QAAA,2BAA2B,GAAG,cAAc,CAAC;AAE1D;;GAEG;AACH,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAiBtE,IAAK,yBAGJ;AAHD,WAAK,yBAAyB;I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mC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,IAAI,CAAC,0BAA0B,CAAC,EAAE,CAAC,6BAA6B,EAAE,CAAC,GAAG,EAAE,EAAE,CACxE,QAAQ,CAAC,GAAG,CAAC,CACd,CAAC;QAEF,wCAAwC;QACxC,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;YACxC,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC;YACjD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;YACxC,IAAI,cAAc,KAAK,OAAO,EAAE;gBAC9B,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,6BAA6B,EAC7B,OAAO,CACR,CAAC;aACH;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC1B,IAAI,CAAC,0BAA0B,CAAC,cAAc,CAC5C,6BAA6B;gBAC7B,gEAAgE;gBAChE,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AA1RD,oDA0RC","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { INetwork, IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo, getNetworkInfoBody } from './types';\nimport EventEmitter from 'events';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\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\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\n\n private massaStationEventsListener = new EventEmitter();\n private currentNetwork: INetwork;\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(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n try {\n const nodesResponse = await getRequest<getNetworkInfoBody>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n\n if (this.currentNetwork?.name !== nodesResponse.result.network) {\n this.currentNetwork = {\n name: nodesResponse.result.network,\n url: nodesResponse.result.url,\n chainId: BigInt(nodesResponse.result.chainId),\n };\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\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<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n\n public listenNetworkChanges(\n callback: (network: string) => void,\n ): { unsubscribe: () => void } | undefined {\n this.massaStationEventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const currentNetwork = this.currentNetwork?.name;\n const network = await this.getNetwork();\n if (currentNetwork !== network) {\n this.massaStationEventsListener.emit(\n MASSA_STATION_NETWORK_CHANGED,\n network,\n );\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.massaStationEventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { INetworkName } from '../provider/IProvider';
|
|
1
2
|
export type ExecuteFunctionBody = {
|
|
2
3
|
nickname: string;
|
|
3
4
|
name: string;
|
|
@@ -17,4 +18,9 @@ export type PluginInfo = {
|
|
|
17
18
|
version: string;
|
|
18
19
|
};
|
|
19
20
|
export type PluginManagerBody = PluginInfo[];
|
|
21
|
+
export type getNetworkInfoBody = {
|
|
22
|
+
chainId: number | string;
|
|
23
|
+
network: INetworkName;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
20
26
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,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,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"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,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,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,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,EAAE,YAAY,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"","sourcesContent":["import { INetworkName } from '../provider/IProvider';\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 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 getNetworkInfoBody = {\n chainId: number | string;\n network: INetworkName;\n url: string;\n};\n"]}
|
|
@@ -2,6 +2,12 @@ import { IAccountDeletionResponse } from './AccountDeletion';
|
|
|
2
2
|
import { IAccountImportResponse } from './AccountImport';
|
|
3
3
|
import { IAccount } from '../account/IAccount';
|
|
4
4
|
import { IAccountDetails } from '../account';
|
|
5
|
+
export type INetworkName = 'mainnet' | 'buildnet' | 'labnet';
|
|
6
|
+
export type INetwork = {
|
|
7
|
+
name: INetworkName;
|
|
8
|
+
url: string;
|
|
9
|
+
chainId: bigint;
|
|
10
|
+
};
|
|
5
11
|
/**
|
|
6
12
|
* This interface represents a general provider definition with its methods
|
|
7
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3D,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACnD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;IAEd,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,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EAAE,MAAM,KAAK,IAAI,GACpD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n\n listenNetworkChanges(callback: (network: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\nexport type INetworkName = 'mainnet' | 'buildnet' | 'labnet';\n\nexport type INetwork = {\n name: INetworkName;\n url: string;\n chainId: bigint;\n};\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n\n listenNetworkChanges(callback: (network: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
|
|
@@ -33,8 +33,6 @@ export declare class MassaStationDiscovery extends EventEmitter {
|
|
|
33
33
|
/**
|
|
34
34
|
* MassaStation constructor
|
|
35
35
|
*
|
|
36
|
-
* @param pollIntervalMillis - Polling interval defined in milliseconds
|
|
37
|
-
*
|
|
38
36
|
* @remarks
|
|
39
37
|
* - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which
|
|
40
38
|
* the MassaStation pinging is triggered and if a successful response is fetched,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC;;GAEG;AACH,eAAO,MAAM,2BAA2B,yCACA,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAI7E;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,YAAY,CAAS;IAE7B
|
|
1
|
+
{"version":3,"file":"MassaStationDiscovery.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC;;GAEG;AACH,eAAO,MAAM,2BAA2B,yCACA,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,2BAA2B,gCAAgC,CAAC;AAEzE;;GAEG;AACH,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAI7E;;;;;GAKG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;IACrD,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;;;;;;;;;OAaG;;IAOH;;;;OAIG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAqB7C"}
|
|
@@ -35,8 +35,6 @@ export class MassaStationDiscovery extends EventEmitter {
|
|
|
35
35
|
/**
|
|
36
36
|
* MassaStation constructor
|
|
37
37
|
*
|
|
38
|
-
* @param pollIntervalMillis - Polling interval defined in milliseconds
|
|
39
|
-
*
|
|
40
38
|
* @remarks
|
|
41
39
|
* - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which
|
|
42
40
|
* the MassaStation pinging is triggered and if a successful response is fetched,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,sCAAsC,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAC7C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAC7C,YAAY,GAAG,KAAK,CAAC;IAE7B
|
|
1
|
+
{"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GACtC,sCAAsC,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAC7C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C;;;;;GAKG;AACH,MAAM,OAAO,qBAAsB,SAAQ,YAAY;IAC7C,YAAY,GAAG,KAAK,CAAC;IAE7B;;;;;;;;;;;;;OAaG;IACH;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc;QACzB,MAAM,IAAI,GAAG,MAAM,UAAU,CAC3B,2BAA2B,EAC3B,IAAI,CACL,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CACnC,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,IAAI,KAAK,qBAAqB;gBACrC,MAAM,CAAC,MAAM,KAAK,uBAAuB,CAC5C,CAAC;YACF,IAAI,YAAY,EAAE;gBAChB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;gBACzB,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;aACtD;SACF;aAAM,IAAI,IAAI,CAAC,YAAY,EAAE;YAC5B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;SAC1C;IACH,CAAC;CACF","sourcesContent":["/**\n * This file defines a TypeScript class named MassaStationDiscovery.\n * The class is being used to recursively search for a connection to MassaStation's server\n * and if so report this via emitting messages.\n *\n * @remarks\n * - If you are only looking to use our library, the connector MassaStationDiscovery will not be useful to you.\n * - If you want to work on this repo, you will probably be interested in this object\n *\n */\n\nimport { EventEmitter } from 'events';\nimport { getRequest } from './RequestHandler';\nimport { PluginManagerBody } from './types';\n\n/**\n * Url used for the MassaStation discovery and pinging the MassaStation server's index.html\n */\nexport const MASSA_STATION_DISCOVERY_URL =\n 'https://station.massa/plugin-manager';\n\n/**\n * A message emitted on successful MassaStation discovery\n */\nexport const ON_MASSA_STATION_DISCOVERED = 'ON_MASSA_STATION_DISCOVERED';\n\n/**\n * A message emitted on MassaStation disconnect\n */\nexport const ON_MASSA_STATION_DISCONNECTED = 'ON_MASSA_STATION_DISCONNECTED';\n\nconst MS_WALLET_PLUGIN_NAME = 'Massa Wallet';\nconst MS_WALLET_PLUGIN_AUTHOR = 'Massa Labs';\n/**\n * This file defines a TypeScript class named MassaStation.\n * The class is being used to recursively ping MassaStation's server\n * and if a response is received emit a message so MassaStation can be enlisted as\n * a wallet provider in the `Connector` class.\n */\nexport class MassaStationDiscovery extends EventEmitter {\n private isDiscovered = false;\n\n /**\n * MassaStation constructor\n *\n * @remarks\n * - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which\n * the MassaStation pinging is triggered and if a successful response is fetched,\n * a message `ON_MASSA_STATION_DISCOVERED` is emitted that MassaStation has been discovered\n * as a wallet provider upon which the `Connector` class will enlist MassaStation as a wallet provider\n * - If once found, but then disconnected the following message `ON_MASSA_STATION_DISCONNECTED` is being emitted\n * so that the `Connector` class delists MassaStation as a wallet provider\n *\n * @returns An instance of the MassaStation class.\n *\n */\n public constructor() {\n super();\n\n this.startListening = this.startListening.bind(this);\n }\n\n /**\n * A method to start listening for a connection to MassaStation's server.\n *\n * @returns void\n */\n public async startListening(): Promise<void> {\n const resp = await getRequest<PluginManagerBody>(\n MASSA_STATION_DISCOVERY_URL,\n 2000,\n );\n\n if (!resp.isError) {\n const walletModule = resp.result.find(\n (module) =>\n module.name === MS_WALLET_PLUGIN_NAME &&\n module.author === MS_WALLET_PLUGIN_AUTHOR,\n );\n if (walletModule) {\n this.isDiscovered = true;\n this.emit(ON_MASSA_STATION_DISCOVERED, walletModule);\n }\n } else if (this.isDiscovered) {\n this.isDiscovered = false;\n this.emit(ON_MASSA_STATION_DISCONNECTED);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationProvider.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EAGvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.d.ts","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,sBAAsB,EAGvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAY,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAS5D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAsB,MAAM,SAAS,CAAC;AAGzD;;GAEG;AACH,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,0BAA0B,QAAoE,CAAC;AAE5G;;GAEG;AACH,eAAO,MAAM,iCAAiC,QAA0C,CAAC;AAEzF;;GAEG;AACH,eAAO,MAAM,2BAA2B,iBAAiB,CAAC;AAO1D;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE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from '../provider/AccountDeletion';
|
|
|
2
2
|
import { EAccountImportResponse, } from '../provider/AccountImport';
|
|
3
3
|
import { deleteRequest, getRequest, postRequest, putRequest, } from './RequestHandler';
|
|
4
4
|
import { MassaStationAccount } from './MassaStationAccount';
|
|
5
|
+
import EventEmitter from 'events';
|
|
5
6
|
/**
|
|
6
7
|
* MassaStation url
|
|
7
8
|
*/
|
|
@@ -18,6 +19,10 @@ export const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/
|
|
|
18
19
|
* MassaStation's wallet provider name
|
|
19
20
|
*/
|
|
20
21
|
export const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';
|
|
22
|
+
/**
|
|
23
|
+
* Events emitted by MassaStation
|
|
24
|
+
*/
|
|
25
|
+
const MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';
|
|
21
26
|
var MassaStationAccountStatus;
|
|
22
27
|
(function (MassaStationAccountStatus) {
|
|
23
28
|
MassaStationAccountStatus["OK"] = "ok";
|
|
@@ -31,6 +36,8 @@ var MassaStationAccountStatus;
|
|
|
31
36
|
export class MassaStationProvider {
|
|
32
37
|
infos;
|
|
33
38
|
providerName = MASSA_STATION_PROVIDER_NAME;
|
|
39
|
+
massaStationEventsListener = new EventEmitter();
|
|
40
|
+
currentNetwork;
|
|
34
41
|
/**
|
|
35
42
|
* Provider constructor
|
|
36
43
|
*
|
|
@@ -182,12 +189,18 @@ export class MassaStationProvider {
|
|
|
182
189
|
* @returns a Promise that resolves to a network.
|
|
183
190
|
*/
|
|
184
191
|
async getNetwork() {
|
|
185
|
-
let nodesResponse = null;
|
|
186
192
|
try {
|
|
187
|
-
nodesResponse = await getRequest(`${MASSA_STATION_URL}massa/node`);
|
|
193
|
+
const nodesResponse = await getRequest(`${MASSA_STATION_URL}massa/node`);
|
|
188
194
|
if (nodesResponse.isError || nodesResponse.error) {
|
|
189
195
|
throw nodesResponse.error.message;
|
|
190
196
|
}
|
|
197
|
+
if (this.currentNetwork?.name !== nodesResponse.result.network) {
|
|
198
|
+
this.currentNetwork = {
|
|
199
|
+
name: nodesResponse.result.network,
|
|
200
|
+
url: nodesResponse.result.url,
|
|
201
|
+
chainId: BigInt(nodesResponse.result.chainId),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
191
204
|
const nodes = nodesResponse.result;
|
|
192
205
|
return nodes.network;
|
|
193
206
|
}
|
|
@@ -225,8 +238,23 @@ export class MassaStationProvider {
|
|
|
225
238
|
return undefined;
|
|
226
239
|
}
|
|
227
240
|
listenNetworkChanges(callback) {
|
|
228
|
-
|
|
229
|
-
|
|
241
|
+
this.massaStationEventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) => callback(evt));
|
|
242
|
+
// check periodically if network changed
|
|
243
|
+
const intervalId = setInterval(async () => {
|
|
244
|
+
const currentNetwork = this.currentNetwork?.name;
|
|
245
|
+
const network = await this.getNetwork();
|
|
246
|
+
if (currentNetwork !== network) {
|
|
247
|
+
this.massaStationEventsListener.emit(MASSA_STATION_NETWORK_CHANGED, network);
|
|
248
|
+
}
|
|
249
|
+
}, 500);
|
|
250
|
+
return {
|
|
251
|
+
unsubscribe: () => {
|
|
252
|
+
clearInterval(intervalId);
|
|
253
|
+
this.massaStationEventsListener.removeListener(MASSA_STATION_NETWORK_CHANGED,
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
255
|
+
() => { });
|
|
256
|
+
},
|
|
257
|
+
};
|
|
230
258
|
}
|
|
231
259
|
}
|
|
232
260
|
//# sourceMappingURL=MassaStationProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAEL,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CAAmC,EAAE,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo } from './types';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\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\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\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(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\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<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n\n public listenNetworkChanges(\n callback: (network: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Network Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAEL,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,iBAAiB,6CAA6C,CAAC;AAE5G;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,0BAA0B,UAAU,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CAAC;AAE1D;;GAEG;AACH,MAAM,6BAA6B,GAAG,+BAA+B,CAAC;AAiBtE,IAAK,yBAGJ;AAHD,WAAK,yBAAyB;IAC5B,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHI,yBAAyB,KAAzB,yBAAyB,QAG7B;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IAYJ;IAXnB,YAAY,GAAG,2BAA2B,CAAC;IAE3C,0BAA0B,GAAG,IAAI,YAAY,EAAE,CAAC;IAChD,cAAc,CAAW;IAEjC;;;;;OAKG;IACH,YAA2B,KAAiB;QAAjB,UAAK,GAAL,KAAK,CAAY;IAAG,CAAC;IAEhD;;;OAGG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,QAAQ;QACnB,IAAI,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AO,EAAE;gBAC9B,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAClC,6BAA6B,EAC7B,OAAO,CACR,CAAC;aACH;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO;YACL,WAAW,EAAE,GAAG,EAAE;gBAChB,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC1B,IAAI,CAAC,0BAA0B,CAAC,cAAc,CAC5C,6BAA6B;gBAC7B,gEAAgE;gBAChE,GAAG,EAAE,GAAE,CAAC,CACT,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { INetwork, IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo, getNetworkInfoBody } from './types';\nimport EventEmitter from 'events';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * Events emitted by MassaStation\n */\nconst MASSA_STATION_NETWORK_CHANGED = 'MASSA_STATION_NETWORK_CHANGED';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\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\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\n\n private massaStationEventsListener = new EventEmitter();\n private currentNetwork: INetwork;\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(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n try {\n const nodesResponse = await getRequest<getNetworkInfoBody>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n\n if (this.currentNetwork?.name !== nodesResponse.result.network) {\n this.currentNetwork = {\n name: nodesResponse.result.network,\n url: nodesResponse.result.url,\n chainId: BigInt(nodesResponse.result.chainId),\n };\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\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<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n\n public listenNetworkChanges(\n callback: (network: string) => void,\n ): { unsubscribe: () => void } | undefined {\n this.massaStationEventsListener.on(MASSA_STATION_NETWORK_CHANGED, (evt) =>\n callback(evt),\n );\n\n // check periodically if network changed\n const intervalId = setInterval(async () => {\n const currentNetwork = this.currentNetwork?.name;\n const network = await this.getNetwork();\n if (currentNetwork !== network) {\n this.massaStationEventsListener.emit(\n MASSA_STATION_NETWORK_CHANGED,\n network,\n );\n }\n }, 500);\n\n return {\n unsubscribe: () => {\n clearInterval(intervalId);\n this.massaStationEventsListener.removeListener(\n MASSA_STATION_NETWORK_CHANGED,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n () => {},\n );\n },\n };\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { INetworkName } from '../provider/IProvider';
|
|
1
2
|
export type ExecuteFunctionBody = {
|
|
2
3
|
nickname: string;
|
|
3
4
|
name: string;
|
|
@@ -17,4 +18,9 @@ export type PluginInfo = {
|
|
|
17
18
|
version: string;
|
|
18
19
|
};
|
|
19
20
|
export type PluginManagerBody = PluginInfo[];
|
|
21
|
+
export type getNetworkInfoBody = {
|
|
22
|
+
chainId: number | string;
|
|
23
|
+
network: INetworkName;
|
|
24
|
+
url: string;
|
|
25
|
+
};
|
|
20
26
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,IA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MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,EAAE,YAAY,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/massaStation/types.ts"],"names":[],"mappings":"","sourcesContent":["import { INetworkName } from '../provider/IProvider';\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 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 getNetworkInfoBody = {\n chainId: number | string;\n network: INetworkName;\n url: string;\n};\n"]}
|
|
@@ -2,6 +2,12 @@ import { IAccountDeletionResponse } from './AccountDeletion';
|
|
|
2
2
|
import { IAccountImportResponse } from './AccountImport';
|
|
3
3
|
import { IAccount } from '../account/IAccount';
|
|
4
4
|
import { IAccountDetails } from '../account';
|
|
5
|
+
export type INetworkName = 'mainnet' | 'buildnet' | 'labnet';
|
|
6
|
+
export type INetwork = {
|
|
7
|
+
name: INetworkName;
|
|
8
|
+
url: string;
|
|
9
|
+
chainId: bigint;
|
|
10
|
+
};
|
|
5
11
|
/**
|
|
6
12
|
* This interface represents a general provider definition with its methods
|
|
7
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAA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G;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3D,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACnD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;IAEd,oBAAoB,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACpD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n\n listenNetworkChanges(callback: (network: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\nexport type INetworkName = 'mainnet' | 'buildnet' | 'labnet';\n\nexport type INetwork = {\n name: INetworkName;\n url: string;\n chainId: bigint;\n};\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n\n listenNetworkChanges(callback: (network: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
|