@massalabs/wallet-provider 1.2.1-dev.20230801093549 → 1.2.1-dev.20230803141012
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/bundle.js +5662 -5204
- package/bundle.min.js +3 -0
- package/dist/cmd/account/Account.d.ts +103 -0
- package/dist/cmd/account/Account.d.ts.map +1 -0
- package/dist/cmd/account/Account.js +179 -0
- package/dist/cmd/account/Account.js.map +1 -0
- package/dist/cmd/account/AccountBalance.d.ts +14 -0
- package/dist/cmd/account/AccountBalance.d.ts.map +1 -0
- package/dist/cmd/account/AccountBalance.js +3 -0
- package/dist/cmd/account/AccountBalance.js.map +1 -0
- package/dist/cmd/account/AccountSign.d.ts +16 -0
- package/dist/cmd/account/AccountSign.d.ts.map +1 -0
- package/dist/cmd/account/AccountSign.js +3 -0
- package/dist/cmd/account/AccountSign.js.map +1 -0
- package/dist/cmd/account/IAccount.d.ts +20 -0
- package/dist/cmd/account/IAccount.d.ts.map +1 -0
- package/dist/cmd/account/IAccount.js +3 -0
- package/dist/cmd/account/IAccount.js.map +1 -0
- package/dist/cmd/account/IAccountCallSCRequest.d.ts +25 -0
- package/dist/cmd/account/IAccountCallSCRequest.d.ts.map +1 -0
- package/dist/cmd/account/IAccountCallSCRequest.js +3 -0
- package/dist/cmd/account/IAccountCallSCRequest.js.map +1 -0
- package/dist/cmd/account/IAccountDetails.d.ts +8 -0
- package/dist/cmd/account/IAccountDetails.d.ts.map +1 -0
- package/dist/cmd/account/IAccountDetails.js +3 -0
- package/dist/cmd/account/IAccountDetails.js.map +1 -0
- package/dist/cmd/account/IAccountRolls.d.ts +8 -0
- package/dist/cmd/account/IAccountRolls.d.ts.map +1 -0
- package/dist/cmd/account/IAccountRolls.js +3 -0
- package/dist/cmd/account/IAccountRolls.js.map +1 -0
- package/dist/cmd/account/IAccountSendTransaction.d.ts +9 -0
- package/dist/cmd/account/IAccountSendTransaction.d.ts.map +1 -0
- package/dist/cmd/account/IAccountSendTransaction.js +3 -0
- package/dist/cmd/account/IAccountSendTransaction.js.map +1 -0
- package/dist/cmd/account/index.d.ts +9 -0
- package/dist/cmd/account/index.d.ts.map +1 -0
- package/dist/cmd/account/index.js +6 -0
- package/dist/cmd/account/index.js.map +1 -0
- package/dist/cmd/connector/Connector.d.ts +87 -0
- package/dist/cmd/connector/Connector.d.ts.map +1 -0
- package/dist/cmd/connector/Connector.js +173 -0
- package/dist/cmd/connector/Connector.js.map +1 -0
- package/dist/cmd/connector/ICustomEventMessageRequest.d.ts +10 -0
- package/dist/cmd/connector/ICustomEventMessageRequest.d.ts.map +1 -0
- package/dist/cmd/connector/ICustomEventMessageRequest.js +3 -0
- package/dist/cmd/connector/ICustomEventMessageRequest.js.map +1 -0
- package/dist/cmd/connector/ICustomEventMessageResponse.d.ts +11 -0
- package/dist/cmd/connector/ICustomEventMessageResponse.d.ts.map +1 -0
- package/dist/cmd/connector/ICustomEventMessageResponse.js +3 -0
- package/dist/cmd/connector/ICustomEventMessageResponse.js.map +1 -0
- package/dist/cmd/connector/IRegisterEvent.d.ts +8 -0
- package/dist/cmd/connector/IRegisterEvent.d.ts.map +1 -0
- package/dist/cmd/connector/IRegisterEvent.js +3 -0
- package/dist/cmd/connector/IRegisterEvent.js.map +1 -0
- package/dist/cmd/connector/index.d.ts +5 -0
- package/dist/cmd/connector/index.d.ts.map +1 -0
- package/dist/cmd/connector/index.js +7 -0
- package/dist/cmd/connector/index.js.map +1 -0
- package/dist/cmd/index.d.ts +48 -0
- package/dist/cmd/index.d.ts.map +1 -0
- package/dist/cmd/index.js +89 -0
- package/dist/cmd/index.js.map +1 -0
- package/dist/cmd/massaStation/MassaStationAccount.d.ts +103 -0
- package/dist/cmd/massaStation/MassaStationAccount.d.ts.map +1 -0
- package/dist/cmd/massaStation/MassaStationAccount.js +312 -0
- package/dist/cmd/massaStation/MassaStationAccount.js.map +1 -0
- package/dist/cmd/massaStation/MassaStationDiscovery.d.ts +57 -0
- package/dist/cmd/massaStation/MassaStationDiscovery.d.ts.map +1 -0
- package/dist/cmd/massaStation/MassaStationDiscovery.js +80 -0
- package/dist/cmd/massaStation/MassaStationDiscovery.js.map +1 -0
- package/dist/cmd/massaStation/MassaStationProvider.d.ts +91 -0
- package/dist/cmd/massaStation/MassaStationProvider.d.ts.map +1 -0
- package/dist/cmd/massaStation/MassaStationProvider.js +193 -0
- package/dist/cmd/massaStation/MassaStationProvider.js.map +1 -0
- package/dist/cmd/massaStation/RequestHandler.d.ts +47 -0
- package/dist/cmd/massaStation/RequestHandler.d.ts.map +1 -0
- package/dist/cmd/massaStation/RequestHandler.js +133 -0
- package/dist/cmd/massaStation/RequestHandler.js.map +1 -0
- package/dist/cmd/provider/AccountDeletion.d.ts +24 -0
- package/dist/cmd/provider/AccountDeletion.d.ts.map +1 -0
- package/dist/cmd/provider/AccountDeletion.js +14 -0
- package/dist/cmd/provider/AccountDeletion.js.map +1 -0
- package/dist/cmd/provider/AccountImport.d.ts +26 -0
- package/dist/cmd/provider/AccountImport.d.ts.map +1 -0
- package/dist/cmd/provider/AccountImport.js +14 -0
- package/dist/cmd/provider/AccountImport.js.map +1 -0
- package/dist/cmd/provider/AccoutGeneration.d.ts +8 -0
- package/dist/cmd/provider/AccoutGeneration.d.ts.map +1 -0
- package/dist/cmd/provider/AccoutGeneration.js +3 -0
- package/dist/cmd/provider/AccoutGeneration.js.map +1 -0
- package/dist/cmd/provider/IProvider.d.ts +16 -0
- package/dist/cmd/provider/IProvider.d.ts.map +1 -0
- package/dist/cmd/provider/IProvider.js +3 -0
- package/dist/cmd/provider/IProvider.js.map +1 -0
- package/dist/cmd/provider/Provider.d.ts +68 -0
- package/dist/cmd/provider/Provider.d.ts.map +1 -0
- package/dist/cmd/provider/Provider.js +126 -0
- package/dist/cmd/provider/Provider.js.map +1 -0
- package/dist/cmd/provider/index.d.ts +5 -0
- package/dist/cmd/provider/index.d.ts.map +1 -0
- package/dist/cmd/provider/index.js +10 -0
- package/dist/cmd/provider/index.js.map +1 -0
- package/dist/cmd/utils/argsToBase64.d.ts +16 -0
- package/dist/cmd/utils/argsToBase64.d.ts.map +1 -0
- package/dist/cmd/utils/argsToBase64.js +25 -0
- package/dist/cmd/utils/argsToBase64.js.map +1 -0
- package/dist/cmd/utils/time.d.ts +77 -0
- package/dist/cmd/utils/time.d.ts.map +1 -0
- package/dist/cmd/utils/time.js +120 -0
- package/dist/cmd/utils/time.js.map +1 -0
- package/dist/connector/Connector.d.ts +2 -0
- package/dist/connector/Connector.d.ts.map +1 -1
- package/dist/connector/Connector.js +13 -9
- package/dist/esm/account/Account.d.ts +103 -0
- package/dist/esm/account/Account.d.ts.map +1 -0
- package/dist/esm/account/Account.js +178 -0
- package/dist/esm/account/Account.js.map +1 -0
- package/dist/esm/account/AccountBalance.d.ts +14 -0
- package/dist/esm/account/AccountBalance.d.ts.map +1 -0
- package/dist/esm/account/AccountBalance.js +2 -0
- package/dist/esm/account/AccountBalance.js.map +1 -0
- package/dist/esm/account/AccountSign.d.ts +16 -0
- package/dist/esm/account/AccountSign.d.ts.map +1 -0
- package/dist/esm/account/AccountSign.js +2 -0
- package/dist/esm/account/AccountSign.js.map +1 -0
- package/dist/esm/account/IAccount.d.ts +20 -0
- package/dist/esm/account/IAccount.d.ts.map +1 -0
- package/dist/esm/account/IAccount.js +2 -0
- package/dist/esm/account/IAccount.js.map +1 -0
- package/dist/esm/account/IAccountCallSCRequest.d.ts +25 -0
- package/dist/esm/account/IAccountCallSCRequest.d.ts.map +1 -0
- package/dist/esm/account/IAccountCallSCRequest.js +2 -0
- package/dist/esm/account/IAccountCallSCRequest.js.map +1 -0
- package/dist/esm/account/IAccountDetails.d.ts +8 -0
- package/dist/esm/account/IAccountDetails.d.ts.map +1 -0
- package/dist/esm/account/IAccountDetails.js +2 -0
- package/dist/esm/account/IAccountDetails.js.map +1 -0
- package/dist/esm/account/IAccountRolls.d.ts +8 -0
- package/dist/esm/account/IAccountRolls.d.ts.map +1 -0
- package/dist/esm/account/IAccountRolls.js +2 -0
- package/dist/esm/account/IAccountRolls.js.map +1 -0
- package/dist/esm/account/IAccountSendTransaction.d.ts +9 -0
- package/dist/esm/account/IAccountSendTransaction.d.ts.map +1 -0
- package/dist/esm/account/IAccountSendTransaction.js +2 -0
- package/dist/esm/account/IAccountSendTransaction.js.map +1 -0
- package/dist/esm/account/index.d.ts +9 -0
- package/dist/esm/account/index.d.ts.map +1 -0
- package/dist/esm/account/index.js +2 -0
- package/dist/esm/account/index.js.map +1 -0
- package/dist/esm/connector/Connector.d.ts +87 -0
- package/dist/esm/connector/Connector.d.ts.map +1 -0
- package/dist/esm/connector/Connector.js +172 -0
- package/dist/esm/connector/Connector.js.map +1 -0
- package/dist/esm/connector/ICustomEventMessageRequest.d.ts +10 -0
- package/dist/esm/connector/ICustomEventMessageRequest.d.ts.map +1 -0
- package/dist/esm/connector/ICustomEventMessageRequest.js +2 -0
- package/dist/esm/connector/ICustomEventMessageRequest.js.map +1 -0
- package/dist/esm/connector/ICustomEventMessageResponse.d.ts +11 -0
- package/dist/esm/connector/ICustomEventMessageResponse.d.ts.map +1 -0
- package/dist/esm/connector/ICustomEventMessageResponse.js +2 -0
- package/dist/esm/connector/ICustomEventMessageResponse.js.map +1 -0
- package/dist/esm/connector/IRegisterEvent.d.ts +8 -0
- package/dist/esm/connector/IRegisterEvent.d.ts.map +1 -0
- package/dist/esm/connector/IRegisterEvent.js +2 -0
- package/dist/esm/connector/IRegisterEvent.js.map +1 -0
- package/dist/esm/connector/index.d.ts +5 -0
- package/dist/esm/connector/index.d.ts.map +1 -0
- package/dist/esm/connector/index.js +2 -0
- package/dist/esm/connector/index.js.map +1 -0
- package/dist/esm/index.d.ts +48 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +79 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/massaStation/MassaStationAccount.d.ts +103 -0
- package/dist/esm/massaStation/MassaStationAccount.d.ts.map +1 -0
- package/dist/esm/massaStation/MassaStationAccount.js +311 -0
- package/dist/esm/massaStation/MassaStationAccount.js.map +1 -0
- package/dist/esm/massaStation/MassaStationDiscovery.d.ts +57 -0
- package/dist/esm/massaStation/MassaStationDiscovery.d.ts.map +1 -0
- package/dist/esm/massaStation/MassaStationDiscovery.js +76 -0
- package/dist/esm/massaStation/MassaStationDiscovery.js.map +1 -0
- package/dist/esm/massaStation/MassaStationProvider.d.ts +91 -0
- package/dist/esm/massaStation/MassaStationProvider.d.ts.map +1 -0
- package/dist/esm/massaStation/MassaStationProvider.js +190 -0
- package/dist/esm/massaStation/MassaStationProvider.js.map +1 -0
- package/dist/esm/massaStation/RequestHandler.d.ts +47 -0
- package/dist/esm/massaStation/RequestHandler.d.ts.map +1 -0
- package/dist/esm/massaStation/RequestHandler.js +126 -0
- package/dist/esm/massaStation/RequestHandler.js.map +1 -0
- package/dist/esm/provider/AccountDeletion.d.ts +24 -0
- package/dist/esm/provider/AccountDeletion.d.ts.map +1 -0
- package/dist/esm/provider/AccountDeletion.js +11 -0
- package/dist/esm/provider/AccountDeletion.js.map +1 -0
- package/dist/esm/provider/AccountImport.d.ts +26 -0
- package/dist/esm/provider/AccountImport.d.ts.map +1 -0
- package/dist/esm/provider/AccountImport.js +11 -0
- package/dist/esm/provider/AccountImport.js.map +1 -0
- package/dist/esm/provider/AccoutGeneration.d.ts +8 -0
- package/dist/esm/provider/AccoutGeneration.d.ts.map +1 -0
- package/dist/esm/provider/AccoutGeneration.js +2 -0
- package/dist/esm/provider/AccoutGeneration.js.map +1 -0
- package/dist/esm/provider/IProvider.d.ts +16 -0
- package/dist/esm/provider/IProvider.d.ts.map +1 -0
- package/dist/esm/provider/IProvider.js +2 -0
- package/dist/esm/provider/IProvider.js.map +1 -0
- package/dist/esm/provider/Provider.d.ts +68 -0
- package/dist/esm/provider/Provider.d.ts.map +1 -0
- package/dist/esm/provider/Provider.js +123 -0
- package/dist/esm/provider/Provider.js.map +1 -0
- package/dist/esm/provider/index.d.ts +5 -0
- package/dist/esm/provider/index.d.ts.map +1 -0
- package/dist/esm/provider/index.js +4 -0
- package/dist/esm/provider/index.js.map +1 -0
- package/dist/esm/utils/argsToBase64.d.ts +16 -0
- package/dist/esm/utils/argsToBase64.d.ts.map +1 -0
- package/dist/esm/utils/argsToBase64.js +20 -0
- package/dist/esm/utils/argsToBase64.js.map +1 -0
- package/dist/esm/utils/time.d.ts +77 -0
- package/dist/esm/utils/time.d.ts.map +1 -0
- package/dist/esm/utils/time.js +119 -0
- package/dist/esm/utils/time.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/massaStation/MassaStationDiscovery.d.ts +2 -16
- package/dist/massaStation/MassaStationDiscovery.d.ts.map +1 -1
- package/dist/massaStation/MassaStationDiscovery.js +4 -30
- package/package.json +11 -8
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file defines a TypeScript class named MassaStationDiscovery.
|
|
4
|
+
* The class is being used to recursively search for a connection to MassaStation's server
|
|
5
|
+
* and if so report this via emitting messages.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* - If you are only looking to use our library, the connector MassaStationDiscovery will not be useful to you.
|
|
9
|
+
* - If you want to work on this repo, you will probably be interested in this object
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.MassaStationDiscovery = exports.ON_MASSA_STATION_DISCONNECTED = exports.ON_MASSA_STATION_DISCOVERED = exports.MASSA_STATION_DISCOVERY_URL = void 0;
|
|
14
|
+
const events_1 = require("events");
|
|
15
|
+
const RequestHandler_1 = require("./RequestHandler");
|
|
16
|
+
/**
|
|
17
|
+
* Url used for the MassaStation discovery and pinging the MassaStation server's index.html
|
|
18
|
+
*/
|
|
19
|
+
exports.MASSA_STATION_DISCOVERY_URL = 'https://station.massa/web/index';
|
|
20
|
+
/**
|
|
21
|
+
* A message emitted on successful MassaStation discovery
|
|
22
|
+
*/
|
|
23
|
+
exports.ON_MASSA_STATION_DISCOVERED = 'ON_MASSA_STATION_DISCOVERED';
|
|
24
|
+
/**
|
|
25
|
+
* A message emitted on MassaStation disconnect
|
|
26
|
+
*/
|
|
27
|
+
exports.ON_MASSA_STATION_DISCONNECTED = 'ON_MASSA_STATION_DISCONNECTED';
|
|
28
|
+
/**
|
|
29
|
+
* This file defines a TypeScript class named MassaStation.
|
|
30
|
+
* The class is being used to recursively ping MassaStation's server
|
|
31
|
+
* and if a response is received emit a message so MassaStation can be enlisted as
|
|
32
|
+
* a wallet provider in the `Connector` class.
|
|
33
|
+
*/
|
|
34
|
+
class MassaStationDiscovery extends events_1.EventEmitter {
|
|
35
|
+
/**
|
|
36
|
+
* MassaStation constructor
|
|
37
|
+
*
|
|
38
|
+
* @param pollIntervalMillis - Polling interval defined in milliseconds
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* - It creates a timeout using the given `pollIntervalMillis` argument on every trigger of which
|
|
42
|
+
* the MassaStation pinging is triggered and if a successful response is fetched,
|
|
43
|
+
* a message `ON_MASSA_STATION_DISCOVERED` is emitted that MassaStation has been discovered
|
|
44
|
+
* as a wallet provider upon which the `Connector` class will enlist MassaStation as a wallet provider
|
|
45
|
+
* - If once found, but then disconnected the following message `ON_MASSA_STATION_DISCONNECTED` is being emitted
|
|
46
|
+
* so that the `Connector` class delists MassaStation as a wallet provider
|
|
47
|
+
*
|
|
48
|
+
* @returns An instance of the MassaStation class.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
constructor() {
|
|
52
|
+
super();
|
|
53
|
+
this.isDiscovered = false;
|
|
54
|
+
this.startListening = this.startListening.bind(this);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A method to start listening for a connection to MassaStation's server.
|
|
58
|
+
*
|
|
59
|
+
* @returns void
|
|
60
|
+
*/
|
|
61
|
+
async startListening() {
|
|
62
|
+
let resp = null;
|
|
63
|
+
try {
|
|
64
|
+
resp = await (0, RequestHandler_1.getRequest)(exports.MASSA_STATION_DISCOVERY_URL);
|
|
65
|
+
}
|
|
66
|
+
catch (ex) {
|
|
67
|
+
console.error(`Error calling ${exports.MASSA_STATION_DISCOVERY_URL}`);
|
|
68
|
+
}
|
|
69
|
+
if (!resp.isError && !resp.error) {
|
|
70
|
+
this.isDiscovered = true;
|
|
71
|
+
this.emit(exports.ON_MASSA_STATION_DISCOVERED);
|
|
72
|
+
}
|
|
73
|
+
if ((resp.isError || resp.error) && this.isDiscovered) {
|
|
74
|
+
this.isDiscovered = false;
|
|
75
|
+
this.emit(exports.ON_MASSA_STATION_DISCONNECTED);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.MassaStationDiscovery = MassaStationDiscovery;
|
|
80
|
+
//# sourceMappingURL=MassaStationDiscovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MassaStationDiscovery.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationDiscovery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAEH,mCAAsC;AACtC,qDAAmE;AAEnE;;GAEG;AACU,QAAA,2BAA2B,GAAG,iCAAiC,CAAC;AAE7E;;GAEG;AACU,QAAA,2BAA2B,GAAG,6BAA6B,CAAC;AAEzE;;GAEG;AACU,QAAA,6BAA6B,GAAG,+BAA+B,CAAC;AAE7E;;;;;GAKG;AACH,MAAa,qBAAsB,SAAQ,qBAAY;IAGrD;;;;;;;;;;;;;;;OAeG;IACH;QACE,KAAK,EAAE,CAAC;QAnBF,iBAAY,GAAG,KAAK,CAAC;QAqB3B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc;QACzB,IAAI,IAAI,GAAiC,IAAI,CAAC;QAC9C,IAAI;YACF,IAAI,GAAG,MAAM,IAAA,2BAAU,EAAC,mCAA2B,CAAC,CAAC;SACtD;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,iBAAiB,mCAA2B,EAAE,CAAC,CAAC;SAC/D;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,mCAA2B,CAAC,CAAC;SACxC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE;YACrD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,qCAA6B,CAAC,CAAC;SAC1C;IACH,CAAC;CACF;AAhDD,sDAgDC","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 { JsonRpcResponseData, getRequest } from './RequestHandler';\n\n/**\n * Url used for the MassaStation discovery and pinging the MassaStation server's index.html\n */\nexport const MASSA_STATION_DISCOVERY_URL = 'https://station.massa/web/index';\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\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 * @param pollIntervalMillis - Polling interval defined in milliseconds\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 let resp: JsonRpcResponseData<unknown> = null;\n try {\n resp = await getRequest(MASSA_STATION_DISCOVERY_URL);\n } catch (ex) {\n console.error(`Error calling ${MASSA_STATION_DISCOVERY_URL}`);\n }\n\n if (!resp.isError && !resp.error) {\n this.isDiscovered = true;\n this.emit(ON_MASSA_STATION_DISCOVERED);\n }\n\n if ((resp.isError || resp.error) && this.isDiscovered) {\n this.isDiscovered = false;\n this.emit(ON_MASSA_STATION_DISCONNECTED);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { IAccountDeletionResponse } from '../provider/AccountDeletion';
|
|
2
|
+
import { IAccountImportResponse } from '../provider/AccountImport';
|
|
3
|
+
import { IProvider } from '../provider/IProvider';
|
|
4
|
+
import { IAccount } from '../account/IAccount';
|
|
5
|
+
import { IAccountDetails } from '../account';
|
|
6
|
+
/**
|
|
7
|
+
* MassaStation url
|
|
8
|
+
*/
|
|
9
|
+
export declare const MASSA_STATION_URL = "https://station.massa/";
|
|
10
|
+
/**
|
|
11
|
+
* The MassaStation accounts url
|
|
12
|
+
*/
|
|
13
|
+
export declare const MASSA_STATION_ACCOUNTS_URL: string;
|
|
14
|
+
/**
|
|
15
|
+
* MassaStation's url for importing accounts
|
|
16
|
+
*/
|
|
17
|
+
export declare const MASSA_STATION_IMPORT_ACCOUNTS_URL: string;
|
|
18
|
+
/**
|
|
19
|
+
* MassaStation's wallet provider name
|
|
20
|
+
*/
|
|
21
|
+
export declare const MASSA_STATION_PROVIDER_NAME = "MASSASTATION";
|
|
22
|
+
/**
|
|
23
|
+
* This interface represents the payload returned by making a call to MassaStation's accounts url.
|
|
24
|
+
*/
|
|
25
|
+
export interface IMassaStationWallet {
|
|
26
|
+
address: string;
|
|
27
|
+
nickname: string;
|
|
28
|
+
keyPair: {
|
|
29
|
+
nonce: string;
|
|
30
|
+
privateKey: string;
|
|
31
|
+
publicKey: string;
|
|
32
|
+
salt: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
37
|
+
* @remarks
|
|
38
|
+
* This class is used as a proxy to the MassaStation server for exchanging message over https calls.
|
|
39
|
+
*/
|
|
40
|
+
export declare class MassaStationProvider implements IProvider {
|
|
41
|
+
private providerName;
|
|
42
|
+
/**
|
|
43
|
+
* Provider constructor
|
|
44
|
+
*
|
|
45
|
+
* @param providerName - The name of the provider.
|
|
46
|
+
* @returns An instance of the Provider class.
|
|
47
|
+
*/
|
|
48
|
+
constructor();
|
|
49
|
+
/**
|
|
50
|
+
* This method returns the name of the provider.
|
|
51
|
+
* @returns The name of the provider.
|
|
52
|
+
*/
|
|
53
|
+
name(): string;
|
|
54
|
+
/**
|
|
55
|
+
* This method sends a message to the MassaStation server to get the list of accounts for the provider.
|
|
56
|
+
* It returns a Promise that resolves to an array of Account instances.
|
|
57
|
+
*
|
|
58
|
+
* @returns A promise that resolves to an array of Account instances.
|
|
59
|
+
*/
|
|
60
|
+
accounts(): Promise<IAccount[]>;
|
|
61
|
+
/**
|
|
62
|
+
* This method makes an http call to the MassaStation server to import an account with
|
|
63
|
+
* the given publicKey and privateKey.
|
|
64
|
+
*
|
|
65
|
+
* @param publicKey - The public key of the account.
|
|
66
|
+
* @param privateKey - The private key of the account.
|
|
67
|
+
*
|
|
68
|
+
* @returns a Promise that resolves to an instance of IAccountImportResponse.
|
|
69
|
+
*/
|
|
70
|
+
importAccount(publicKey: string, privateKey: string): Promise<IAccountImportResponse>;
|
|
71
|
+
/**
|
|
72
|
+
* This method sends an http call to the MassaStation server to delete the account associated with the given address.
|
|
73
|
+
*
|
|
74
|
+
* @param address - The address of the account.
|
|
75
|
+
* @returns a Promise that resolves to an instance of IAccountDeletionResponse.
|
|
76
|
+
*/
|
|
77
|
+
deleteAccount(address: string): Promise<IAccountDeletionResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* This method sends an http call to the MassaStation server to obtain node urls.
|
|
80
|
+
*
|
|
81
|
+
* @returns a Promise that resolves to a list of node urls.
|
|
82
|
+
*/
|
|
83
|
+
getNodesUrls(): Promise<string[]>;
|
|
84
|
+
/**
|
|
85
|
+
* This method sends an http call to the MassaStation server to create a new random account.
|
|
86
|
+
*
|
|
87
|
+
* @returns a Promise that resolves to the details of the newly generated account.
|
|
88
|
+
*/
|
|
89
|
+
generateNewAccount(name: string): Promise<IAccountDetails>;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=MassaStationProvider.d.ts.map
|
|
@@ -0,0 +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,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AASlD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;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;AAE1D;;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;CACH;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IACpD,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;;IAKH;;;OAGG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;;OAKG;IACU,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IA6B5C;;;;;;;;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;;;;OAIG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAkB9C;;;;OAIG;IACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAwBxE"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MassaStationProvider = exports.MASSA_STATION_PROVIDER_NAME = exports.MASSA_STATION_IMPORT_ACCOUNTS_URL = exports.MASSA_STATION_ACCOUNTS_URL = exports.MASSA_STATION_URL = void 0;
|
|
4
|
+
const AccountDeletion_1 = require("../provider/AccountDeletion");
|
|
5
|
+
const AccountImport_1 = require("../provider/AccountImport");
|
|
6
|
+
const RequestHandler_1 = require("./RequestHandler");
|
|
7
|
+
const MassaStationAccount_1 = require("./MassaStationAccount");
|
|
8
|
+
/**
|
|
9
|
+
* MassaStation url
|
|
10
|
+
*/
|
|
11
|
+
exports.MASSA_STATION_URL = 'https://station.massa/';
|
|
12
|
+
/**
|
|
13
|
+
* The MassaStation accounts url
|
|
14
|
+
*/
|
|
15
|
+
exports.MASSA_STATION_ACCOUNTS_URL = `${exports.MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;
|
|
16
|
+
/**
|
|
17
|
+
* MassaStation's url for importing accounts
|
|
18
|
+
*/
|
|
19
|
+
exports.MASSA_STATION_IMPORT_ACCOUNTS_URL = `${exports.MASSA_STATION_ACCOUNTS_URL}/import/`;
|
|
20
|
+
/**
|
|
21
|
+
* MassaStation's wallet provider name
|
|
22
|
+
*/
|
|
23
|
+
exports.MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';
|
|
24
|
+
/**
|
|
25
|
+
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
26
|
+
* @remarks
|
|
27
|
+
* This class is used as a proxy to the MassaStation server for exchanging message over https calls.
|
|
28
|
+
*/
|
|
29
|
+
class MassaStationProvider {
|
|
30
|
+
/**
|
|
31
|
+
* Provider constructor
|
|
32
|
+
*
|
|
33
|
+
* @param providerName - The name of the provider.
|
|
34
|
+
* @returns An instance of the Provider class.
|
|
35
|
+
*/
|
|
36
|
+
constructor() {
|
|
37
|
+
this.providerName = exports.MASSA_STATION_PROVIDER_NAME;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* This method returns the name of the provider.
|
|
41
|
+
* @returns The name of the provider.
|
|
42
|
+
*/
|
|
43
|
+
name() {
|
|
44
|
+
return this.providerName;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This method sends a message to the MassaStation server to get the list of accounts for the provider.
|
|
48
|
+
* It returns a Promise that resolves to an array of Account instances.
|
|
49
|
+
*
|
|
50
|
+
* @returns A promise that resolves to an array of Account instances.
|
|
51
|
+
*/
|
|
52
|
+
async accounts() {
|
|
53
|
+
let massaStationAccountsResponse = null;
|
|
54
|
+
try {
|
|
55
|
+
massaStationAccountsResponse = await (0, RequestHandler_1.getRequest)(exports.MASSA_STATION_ACCOUNTS_URL);
|
|
56
|
+
}
|
|
57
|
+
catch (ex) {
|
|
58
|
+
console.error(`MassaStation accounts retrieval error`);
|
|
59
|
+
throw ex;
|
|
60
|
+
}
|
|
61
|
+
if (massaStationAccountsResponse.isError ||
|
|
62
|
+
massaStationAccountsResponse.error) {
|
|
63
|
+
throw massaStationAccountsResponse.error.message;
|
|
64
|
+
}
|
|
65
|
+
return massaStationAccountsResponse.result.map((massaStationAccount) => {
|
|
66
|
+
return new MassaStationAccount_1.MassaStationAccount({
|
|
67
|
+
address: massaStationAccount.address,
|
|
68
|
+
name: massaStationAccount.nickname,
|
|
69
|
+
}, this.providerName);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* This method makes an http call to the MassaStation server to import an account with
|
|
74
|
+
* the given publicKey and privateKey.
|
|
75
|
+
*
|
|
76
|
+
* @param publicKey - The public key of the account.
|
|
77
|
+
* @param privateKey - The private key of the account.
|
|
78
|
+
*
|
|
79
|
+
* @returns a Promise that resolves to an instance of IAccountImportResponse.
|
|
80
|
+
*/
|
|
81
|
+
async importAccount(publicKey, privateKey) {
|
|
82
|
+
const accountImportRequest = {
|
|
83
|
+
publicKey,
|
|
84
|
+
privateKey,
|
|
85
|
+
};
|
|
86
|
+
let massaStationAccountsResponse = null;
|
|
87
|
+
try {
|
|
88
|
+
massaStationAccountsResponse = await (0, RequestHandler_1.putRequest)(exports.MASSA_STATION_ACCOUNTS_URL, accountImportRequest);
|
|
89
|
+
}
|
|
90
|
+
catch (ex) {
|
|
91
|
+
console.log(`MassaStation accounts retrieval error: ${ex}`);
|
|
92
|
+
throw ex;
|
|
93
|
+
}
|
|
94
|
+
if (massaStationAccountsResponse.isError ||
|
|
95
|
+
massaStationAccountsResponse.error) {
|
|
96
|
+
throw massaStationAccountsResponse.error.message;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
response: AccountImport_1.EAccountImportResponse.OK,
|
|
100
|
+
message: 'Account imported successfully',
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* This method sends an http call to the MassaStation server to delete the account associated with the given address.
|
|
105
|
+
*
|
|
106
|
+
* @param address - The address of the account.
|
|
107
|
+
* @returns a Promise that resolves to an instance of IAccountDeletionResponse.
|
|
108
|
+
*/
|
|
109
|
+
async deleteAccount(address) {
|
|
110
|
+
// get all accounts
|
|
111
|
+
let allAccounts = null;
|
|
112
|
+
try {
|
|
113
|
+
allAccounts = await (0, RequestHandler_1.getRequest)(exports.MASSA_STATION_ACCOUNTS_URL);
|
|
114
|
+
}
|
|
115
|
+
catch (ex) {
|
|
116
|
+
console.log(`MassaStation accounts retrieval error: ${ex}`);
|
|
117
|
+
throw ex;
|
|
118
|
+
}
|
|
119
|
+
if (allAccounts.isError || allAccounts.error) {
|
|
120
|
+
throw allAccounts.error.message;
|
|
121
|
+
}
|
|
122
|
+
// find the account with the desired address
|
|
123
|
+
const accountToDelete = allAccounts.result.find((account) => account.address.toLowerCase() === address.toLowerCase());
|
|
124
|
+
// delete the account in question
|
|
125
|
+
let massaStationAccountsResponse = null;
|
|
126
|
+
try {
|
|
127
|
+
massaStationAccountsResponse = await (0, RequestHandler_1.deleteRequest)(`${exports.MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`);
|
|
128
|
+
}
|
|
129
|
+
catch (ex) {
|
|
130
|
+
console.log(`MassaStation accounts deletion error`, ex);
|
|
131
|
+
return {
|
|
132
|
+
response: AccountDeletion_1.EAccountDeletionResponse.ERROR,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (massaStationAccountsResponse.isError ||
|
|
136
|
+
massaStationAccountsResponse.error) {
|
|
137
|
+
console.log(`MassaStation accounts deletion error`, massaStationAccountsResponse.error.message);
|
|
138
|
+
return {
|
|
139
|
+
response: AccountDeletion_1.EAccountDeletionResponse.ERROR,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
response: AccountDeletion_1.EAccountDeletionResponse.OK,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* This method sends an http call to the MassaStation server to obtain node urls.
|
|
148
|
+
*
|
|
149
|
+
* @returns a Promise that resolves to a list of node urls.
|
|
150
|
+
*/
|
|
151
|
+
async getNodesUrls() {
|
|
152
|
+
let nodesResponse = null;
|
|
153
|
+
try {
|
|
154
|
+
nodesResponse = await (0, RequestHandler_1.getRequest)(`${exports.MASSA_STATION_URL}massa/node`);
|
|
155
|
+
if (nodesResponse.isError || nodesResponse.error) {
|
|
156
|
+
throw nodesResponse.error.message;
|
|
157
|
+
}
|
|
158
|
+
// transform nodesResponse.result to a json and then get the "url" property
|
|
159
|
+
const nodes = nodesResponse.result;
|
|
160
|
+
return Array(nodes.url);
|
|
161
|
+
}
|
|
162
|
+
catch (ex) {
|
|
163
|
+
console.error(`MassaStation nodes retrieval error`, ex);
|
|
164
|
+
throw ex;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* This method sends an http call to the MassaStation server to create a new random account.
|
|
169
|
+
*
|
|
170
|
+
* @returns a Promise that resolves to the details of the newly generated account.
|
|
171
|
+
*/
|
|
172
|
+
async generateNewAccount(name) {
|
|
173
|
+
let massaStationAccountsResponse = null;
|
|
174
|
+
console.log(exports.MASSA_STATION_ACCOUNTS_URL + '/' + name);
|
|
175
|
+
try {
|
|
176
|
+
massaStationAccountsResponse = await (0, RequestHandler_1.postRequest)(exports.MASSA_STATION_ACCOUNTS_URL + '/' + name, {});
|
|
177
|
+
if (massaStationAccountsResponse.isError ||
|
|
178
|
+
massaStationAccountsResponse.error) {
|
|
179
|
+
throw massaStationAccountsResponse.error.message;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
address: massaStationAccountsResponse.result.address,
|
|
183
|
+
name: massaStationAccountsResponse.result.nickname,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (ex) {
|
|
187
|
+
console.error(`Error while generating account: ${ex}`);
|
|
188
|
+
throw ex;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.MassaStationProvider = MassaStationProvider;
|
|
193
|
+
//# sourceMappingURL=MassaStationProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"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","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';\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}\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: 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() {\n this.providerName = MASSA_STATION_PROVIDER_NAME;\n }\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.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 * @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 * 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"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface represents a payload returned by making an http call
|
|
3
|
+
*/
|
|
4
|
+
export interface JsonRpcResponseData<T> {
|
|
5
|
+
isError: boolean;
|
|
6
|
+
result: T | null;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* This method makes a GET request to an http rest point.
|
|
11
|
+
*
|
|
12
|
+
*
|
|
13
|
+
* @param url - The url to call.
|
|
14
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRequest<T>(url: string): Promise<JsonRpcResponseData<T>>;
|
|
18
|
+
/**
|
|
19
|
+
* This method makes a POST request to an http rest point.
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @param url - The url to call.
|
|
23
|
+
* @param body - The body of the request.
|
|
24
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export declare function postRequest<T>(url: string, body: object): Promise<JsonRpcResponseData<T>>;
|
|
28
|
+
/**
|
|
29
|
+
* This method makes a DELETE request to an http rest point.
|
|
30
|
+
*
|
|
31
|
+
*
|
|
32
|
+
* @param url - The url to call.
|
|
33
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare function deleteRequest<T>(url: string): Promise<JsonRpcResponseData<T>>;
|
|
37
|
+
/**
|
|
38
|
+
* This method makes a PUT request to an http rest point.
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* @param url - The url to call.
|
|
42
|
+
* @param body - The body of the request.
|
|
43
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
44
|
+
*
|
|
45
|
+
*/
|
|
46
|
+
export declare function putRequest<T>(url: string, body: object): Promise<JsonRpcResponseData<T>>;
|
|
47
|
+
//# sourceMappingURL=RequestHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestHandler.d.ts","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"AAsBA;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAiBjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAsBjC;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAoBjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAqBjC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.putRequest = exports.deleteRequest = exports.postRequest = exports.getRequest = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* - The methods implemented here are quite generic and might be useful in other contexts too
|
|
9
|
+
* but have been particularly developed for making http calls specific to MassaStation's server API
|
|
10
|
+
* - If you want to work on this repo, you will probably be interested in this object
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
const axios_1 = require("axios");
|
|
14
|
+
const requestHeaders = {
|
|
15
|
+
Accept: 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
16
|
+
'Access-Control-Allow-Origin': '*',
|
|
17
|
+
'Access-Control-Allow-Credentials': true,
|
|
18
|
+
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
'Access-Control-Allow-Headers': 'Accept,authorization,Authorization,Content-Type',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* This method makes a GET request to an http rest point.
|
|
24
|
+
*
|
|
25
|
+
*
|
|
26
|
+
* @param url - The url to call.
|
|
27
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
async function getRequest(url) {
|
|
31
|
+
let resp = null;
|
|
32
|
+
try {
|
|
33
|
+
resp = await axios_1.default.get(url, requestHeaders);
|
|
34
|
+
}
|
|
35
|
+
catch (ex) {
|
|
36
|
+
return {
|
|
37
|
+
isError: true,
|
|
38
|
+
result: null,
|
|
39
|
+
error: new Error('Axios Error: ' + String(ex)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
isError: false,
|
|
44
|
+
result: resp.data,
|
|
45
|
+
error: null,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.getRequest = getRequest;
|
|
49
|
+
/**
|
|
50
|
+
* This method makes a POST request to an http rest point.
|
|
51
|
+
*
|
|
52
|
+
*
|
|
53
|
+
* @param url - The url to call.
|
|
54
|
+
* @param body - The body of the request.
|
|
55
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
async function postRequest(url, body) {
|
|
59
|
+
try {
|
|
60
|
+
const resp = await axios_1.default.post(url, body, requestHeaders);
|
|
61
|
+
return {
|
|
62
|
+
isError: false,
|
|
63
|
+
result: resp.data,
|
|
64
|
+
error: null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (ex) {
|
|
68
|
+
return {
|
|
69
|
+
isError: true,
|
|
70
|
+
result: null,
|
|
71
|
+
error: ex.response?.data?.message
|
|
72
|
+
? new Error(String(ex.response.data.message))
|
|
73
|
+
: new Error('Axios error: ' + String(ex)),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.postRequest = postRequest;
|
|
78
|
+
/**
|
|
79
|
+
* This method makes a DELETE request to an http rest point.
|
|
80
|
+
*
|
|
81
|
+
*
|
|
82
|
+
* @param url - The url to call.
|
|
83
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
async function deleteRequest(url) {
|
|
87
|
+
let resp = null;
|
|
88
|
+
try {
|
|
89
|
+
resp = await axios_1.default.delete(url, requestHeaders);
|
|
90
|
+
}
|
|
91
|
+
catch (ex) {
|
|
92
|
+
return {
|
|
93
|
+
isError: true,
|
|
94
|
+
result: null,
|
|
95
|
+
error: new Error('Axios Error: ' + String(ex)),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
isError: false,
|
|
100
|
+
result: resp.data,
|
|
101
|
+
error: null,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
exports.deleteRequest = deleteRequest;
|
|
105
|
+
/**
|
|
106
|
+
* This method makes a PUT request to an http rest point.
|
|
107
|
+
*
|
|
108
|
+
*
|
|
109
|
+
* @param url - The url to call.
|
|
110
|
+
* @param body - The body of the request.
|
|
111
|
+
* @returns a Promise that resolves to an instance of JsonRpcResponseData.
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
async function putRequest(url, body) {
|
|
115
|
+
let resp = null;
|
|
116
|
+
try {
|
|
117
|
+
resp = await axios_1.default.put(url, body, requestHeaders);
|
|
118
|
+
}
|
|
119
|
+
catch (ex) {
|
|
120
|
+
return {
|
|
121
|
+
isError: true,
|
|
122
|
+
result: null,
|
|
123
|
+
error: new Error('Axios error: ' + String(ex)),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
isError: false,
|
|
128
|
+
result: resp.data,
|
|
129
|
+
error: null,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.putRequest = putRequest;
|
|
133
|
+
//# sourceMappingURL=RequestHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../../src/massaStation/RequestHandler.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * This file defines a TypeScript module with methods for performing GET, POST and DELETE http requests.\n *\n * @remarks\n * - The methods implemented here are quite generic and might be useful in other contexts too\n * but have been particularly developed for making http calls specific to MassaStation's server API\n * - If you want to work on this repo, you will probably be interested in this object\n *\n */\nimport axios, { AxiosResponse, AxiosRequestHeaders } from 'axios';\n\nconst requestHeaders = {\n Accept:\n 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',\n 'Access-Control-Allow-Origin': '*',\n 'Access-Control-Allow-Credentials': true,\n 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',\n 'Content-Type': 'application/json',\n 'Access-Control-Allow-Headers':\n 'Accept,authorization,Authorization,Content-Type',\n} as AxiosRequestHeaders;\n\n/**\n * This interface represents a payload returned by making an http call\n */\nexport interface JsonRpcResponseData<T> {\n isError: boolean;\n result: T | null;\n error: Error | null;\n}\n\n/**\n * This method makes a GET request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function getRequest<T>(\n url: string,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.get<unknown, AxiosResponse, object>(url, requestHeaders);\n } catch (ex) {\n return {\n isError: true,\n result: null,\n error: new Error('Axios Error: ' + String(ex)),\n } as JsonRpcResponseData<T>;\n }\n\n return {\n isError: false,\n result: resp.data as T,\n error: null,\n } as JsonRpcResponseData<T>;\n}\n\n/**\n * This method makes a POST request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function postRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n try {\n const resp = await axios.post<unknown, AxiosResponse, object>(\n url,\n body,\n requestHeaders,\n );\n\n return {\n isError: false,\n result: resp.data as T,\n error: null,\n } as JsonRpcResponseData<T>;\n } catch (ex) {\n return {\n isError: true,\n result: null,\n error: ex.response?.data?.message\n ? new Error(String(ex.response.data.message))\n : new Error('Axios error: ' + String(ex)),\n } as JsonRpcResponseData<T>;\n }\n}\n\n/**\n * This method makes a DELETE request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function deleteRequest<T>(\n url: string,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.delete<unknown, AxiosResponse, object>(\n url,\n requestHeaders,\n );\n } catch (ex) {\n return {\n isError: true,\n result: null,\n error: new Error('Axios Error: ' + String(ex)),\n } as JsonRpcResponseData<T>;\n }\n\n return {\n isError: false,\n result: resp.data as T,\n error: null,\n } as JsonRpcResponseData<T>;\n}\n\n/**\n * This method makes a PUT request to an http rest point.\n *\n *\n * @param url - The url to call.\n * @param body - The body of the request.\n * @returns a Promise that resolves to an instance of JsonRpcResponseData.\n *\n */\nexport async function putRequest<T>(\n url: string,\n body: object,\n): Promise<JsonRpcResponseData<T>> {\n let resp: AxiosResponse = null;\n try {\n resp = await axios.put<unknown, AxiosResponse, object>(\n url,\n body,\n requestHeaders,\n );\n } catch (ex) {\n return {\n isError: true,\n result: null,\n error: new Error('Axios error: ' + String(ex)),\n } as JsonRpcResponseData<T>;\n }\n\n return {\n isError: false,\n result: resp.data as T,\n error: null,\n } as JsonRpcResponseData<T>;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface represents the request object sent to the content script
|
|
3
|
+
* for deleting an account.
|
|
4
|
+
*/
|
|
5
|
+
export interface IAccountDeletionRequest {
|
|
6
|
+
address: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* This interface represents the response object sent by the content script,
|
|
10
|
+
* indicating the result of an account deletion request.
|
|
11
|
+
*/
|
|
12
|
+
export interface IAccountDeletionResponse {
|
|
13
|
+
response: EAccountDeletionResponse;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This enum represents the possible responses from the content script
|
|
17
|
+
* in response to an account deletion request.
|
|
18
|
+
*/
|
|
19
|
+
export declare enum EAccountDeletionResponse {
|
|
20
|
+
OK = 0,
|
|
21
|
+
REFUSED = 1,
|
|
22
|
+
ERROR = 2
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=AccountDeletion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletion.d.ts","sourceRoot":"","sources":["../../../src/provider/AccountDeletion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,wBAAwB,CAAC;CACpC;AAED;;;GAGG;AACH,oBAAY,wBAAwB;IAClC,EAAE,IAAA;IACF,OAAO,IAAA;IACP,KAAK,IAAA;CACN"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EAccountDeletionResponse = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* This enum represents the possible responses from the content script
|
|
6
|
+
* in response to an account deletion request.
|
|
7
|
+
*/
|
|
8
|
+
var EAccountDeletionResponse;
|
|
9
|
+
(function (EAccountDeletionResponse) {
|
|
10
|
+
EAccountDeletionResponse[EAccountDeletionResponse["OK"] = 0] = "OK";
|
|
11
|
+
EAccountDeletionResponse[EAccountDeletionResponse["REFUSED"] = 1] = "REFUSED";
|
|
12
|
+
EAccountDeletionResponse[EAccountDeletionResponse["ERROR"] = 2] = "ERROR";
|
|
13
|
+
})(EAccountDeletionResponse = exports.EAccountDeletionResponse || (exports.EAccountDeletionResponse = {}));
|
|
14
|
+
//# sourceMappingURL=AccountDeletion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountDeletion.js","sourceRoot":"","sources":["../../../src/provider/AccountDeletion.ts"],"names":[],"mappings":";;;AAgBA;;;GAGG;AACH,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,mEAAE,CAAA;IACF,6EAAO,CAAA;IACP,yEAAK,CAAA;AACP,CAAC,EAJW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAInC","sourcesContent":["/**\n * This interface represents the request object sent to the content script\n * for deleting an account.\n */\nexport interface IAccountDeletionRequest {\n address: string;\n}\n\n/**\n * This interface represents the response object sent by the content script,\n * indicating the result of an account deletion request.\n */\nexport interface IAccountDeletionResponse {\n response: EAccountDeletionResponse;\n}\n\n/**\n * This enum represents the possible responses from the content script\n * in response to an account deletion request.\n */\nexport enum EAccountDeletionResponse {\n OK,\n REFUSED,\n ERROR,\n}\n"]}
|