@massalabs/wallet-provider 1.4.2-dev.20230929135423 → 1.4.2-dev.20231121110235
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/MassaStationProvider.d.ts +6 -0
- package/dist/cmd/massaStation/MassaStationProvider.d.ts.map +1 -1
- package/dist/cmd/massaStation/MassaStationProvider.js +10 -1
- package/dist/cmd/massaStation/MassaStationProvider.js.map +1 -1
- package/dist/esm/massaStation/MassaStationProvider.d.ts +6 -0
- package/dist/esm/massaStation/MassaStationProvider.d.ts.map +1 -1
- package/dist/esm/massaStation/MassaStationProvider.js +10 -1
- package/dist/esm/massaStation/MassaStationProvider.js.map +1 -1
- package/package.json +1 -1
|
@@ -32,6 +32,11 @@ export interface IMassaStationWallet {
|
|
|
32
32
|
publicKey: string;
|
|
33
33
|
salt: string;
|
|
34
34
|
};
|
|
35
|
+
status: MassaStationAccountStatus;
|
|
36
|
+
}
|
|
37
|
+
declare enum MassaStationAccountStatus {
|
|
38
|
+
OK = "ok",
|
|
39
|
+
CORRUPTED = "corrupted"
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
@@ -100,4 +105,5 @@ export declare class MassaStationProvider implements IProvider {
|
|
|
100
105
|
*/
|
|
101
106
|
generateNewAccount(name: string): Promise<IAccountDetails>;
|
|
102
107
|
}
|
|
108
|
+
export {};
|
|
103
109
|
//# sourceMappingURL=MassaStationProvider.d.ts.map
|
|
@@ -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,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAS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D;;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;IASjC,OAAO,CAAC,KAAK;IARhC,OAAO,CAAC,YAAY,CAA+B;IAEnD;;;;;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;IAkB1C;;;;OAIG;IACU,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAwBxE"}
|
|
@@ -21,6 +21,11 @@ exports.MASSA_STATION_IMPORT_ACCOUNTS_URL = `${exports.MASSA_STATION_ACCOUNTS_UR
|
|
|
21
21
|
* MassaStation's wallet provider name
|
|
22
22
|
*/
|
|
23
23
|
exports.MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';
|
|
24
|
+
var MassaStationAccountStatus;
|
|
25
|
+
(function (MassaStationAccountStatus) {
|
|
26
|
+
MassaStationAccountStatus["OK"] = "ok";
|
|
27
|
+
MassaStationAccountStatus["CORRUPTED"] = "corrupted";
|
|
28
|
+
})(MassaStationAccountStatus || (MassaStationAccountStatus = {}));
|
|
24
29
|
/**
|
|
25
30
|
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
26
31
|
* @remarks
|
|
@@ -63,7 +68,11 @@ class MassaStationProvider {
|
|
|
63
68
|
massaStationAccountsResponse.error) {
|
|
64
69
|
throw massaStationAccountsResponse.error.message;
|
|
65
70
|
}
|
|
66
|
-
return massaStationAccountsResponse.result
|
|
71
|
+
return massaStationAccountsResponse.result
|
|
72
|
+
.filter((massaStationAccount) => {
|
|
73
|
+
return massaStationAccount.status === MassaStationAccountStatus.OK;
|
|
74
|
+
})
|
|
75
|
+
.map((massaStationAccount) => {
|
|
67
76
|
return new MassaStationAccount_1.MassaStationAccount({
|
|
68
77
|
address: massaStationAccount.address,
|
|
69
78
|
name: massaStationAccount.nickname,
|
|
@@ -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;AAgB1D;;;;GAIG;AACH,MAAa,oBAAoB;IAG/B;;;;;OAKG;IACH,YAA2B,KAAiB;QAAjB,UAAK,GAAL,KAAK,CAAY;QARpC,iBAAY,GAAG,mCAA2B,CAAC;IAQJ,CAAC;IAEhD;;;OAG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AAG,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;CACF;AApOD,oDAoOC","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}\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.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"]}
|
|
1
|
+
{"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":";;;AAAA,iEAG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AxOD,oDAwOC","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"]}
|
|
@@ -32,6 +32,11 @@ export interface IMassaStationWallet {
|
|
|
32
32
|
publicKey: string;
|
|
33
33
|
salt: string;
|
|
34
34
|
};
|
|
35
|
+
status: MassaStationAccountStatus;
|
|
36
|
+
}
|
|
37
|
+
declare enum MassaStationAccountStatus {
|
|
38
|
+
OK = "ok",
|
|
39
|
+
CORRUPTED = "corrupted"
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
@@ -100,4 +105,5 @@ export declare class MassaStationProvider implements IProvider {
|
|
|
100
105
|
*/
|
|
101
106
|
generateNewAccount(name: string): Promise<IAccountDetails>;
|
|
102
107
|
}
|
|
108
|
+
export {};
|
|
103
109
|
//# sourceMappingURL=MassaStationProvider.d.ts.map
|
|
@@ -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,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AASlD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;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;
|
|
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,YAA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C,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAwBxE"}
|
|
@@ -18,6 +18,11 @@ export const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/
|
|
|
18
18
|
* MassaStation's wallet provider name
|
|
19
19
|
*/
|
|
20
20
|
export const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';
|
|
21
|
+
var MassaStationAccountStatus;
|
|
22
|
+
(function (MassaStationAccountStatus) {
|
|
23
|
+
MassaStationAccountStatus["OK"] = "ok";
|
|
24
|
+
MassaStationAccountStatus["CORRUPTED"] = "corrupted";
|
|
25
|
+
})(MassaStationAccountStatus || (MassaStationAccountStatus = {}));
|
|
21
26
|
/**
|
|
22
27
|
* This class provides an implementation for communicating with the MassaStation wallet provider.
|
|
23
28
|
* @remarks
|
|
@@ -61,7 +66,11 @@ export class MassaStationProvider {
|
|
|
61
66
|
massaStationAccountsResponse.error) {
|
|
62
67
|
throw massaStationAccountsResponse.error.message;
|
|
63
68
|
}
|
|
64
|
-
return massaStationAccountsResponse.result
|
|
69
|
+
return massaStationAccountsResponse.result
|
|
70
|
+
.filter((massaStationAccount) => {
|
|
71
|
+
return massaStationAccount.status === MassaStationAccountStatus.OK;
|
|
72
|
+
})
|
|
73
|
+
.map((massaStationAccount) => {
|
|
65
74
|
return new MassaStationAccount({
|
|
66
75
|
address: massaStationAccount.address,
|
|
67
76
|
name: massaStationAccount.nickname,
|
|
@@ -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,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE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CAAC,OAAO,IAAI,aAAa,CAAC,KAAK,EAAE;gBAChD,MAAM,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC;aACnC;YACD,MAAM,KAAK,GAAG,aAAa,CAAC,MAA6B,CAAC;YAE1D,OAAO,KAAK,CAAC,OAAO,CAAC;SACtB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,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,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrD,IAAI;YACF,4BAA4B,GAAG,MAAM,WAAW,CAC9C,0BAA0B,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;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}\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.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"]}
|
|
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;AAK5D;;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;AAiB1D,IAAK,yBAGJ;AAHD,WAAK,yBAAyB;IAC5B,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHI,yBAAyB,KAAzB,yBAAyB,QAG7B;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAoB;IASJ;IARnB,YAAY,GAAG,2BAA2B,CAAC;IAEnD;;;;;OAKG;IACH,YAA2B,KAAiB;QAAjB,UAAK,GAAL,KAAK,CAA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,kBAAkB,CAAC,IAAY;QAC1C,IAAI,4BAA4B,GAC9B,IAAI,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrD,IAAI;YACF,4BAA4B,GAAG,MAAM,WAAW,CAC9C,0BAA0B,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;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"]}
|