@massalabs/wallet-provider 0.0.0 → 0.0.1-dev.20230424074402

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +2 -5
  2. package/bundle.js +3738 -0
  3. package/dist/account/Account.d.ts +80 -0
  4. package/dist/account/Account.js +139 -0
  5. package/dist/account/Account.js.map +1 -0
  6. package/dist/account/AccountBalance.d.ts +13 -0
  7. package/dist/account/AccountBalance.js +3 -0
  8. package/dist/account/AccountBalance.js.map +1 -0
  9. package/dist/account/AccountSign.d.ts +15 -0
  10. package/dist/account/AccountSign.js +3 -0
  11. package/dist/account/AccountSign.js.map +1 -0
  12. package/dist/account/IAccount.d.ts +16 -0
  13. package/dist/account/IAccount.js +3 -0
  14. package/dist/account/IAccount.js.map +1 -0
  15. package/dist/account/IAccountDetails.d.ts +7 -0
  16. package/dist/account/IAccountDetails.js +3 -0
  17. package/dist/account/IAccountDetails.js.map +1 -0
  18. package/dist/account/IAccountRolls.d.ts +7 -0
  19. package/dist/account/IAccountRolls.js +3 -0
  20. package/dist/account/IAccountRolls.js.map +1 -0
  21. package/dist/account/IAccountSendTransaction.d.ts +8 -0
  22. package/dist/account/IAccountSendTransaction.js +3 -0
  23. package/dist/account/IAccountSendTransaction.js.map +1 -0
  24. package/dist/account/index.d.ts +7 -0
  25. package/dist/account/index.js +6 -0
  26. package/dist/account/index.js.map +1 -0
  27. package/dist/connector/Connector.d.ts +79 -0
  28. package/dist/connector/Connector.js +164 -0
  29. package/dist/connector/Connector.js.map +1 -0
  30. package/dist/connector/ICustomEventMessageRequest.d.ts +9 -0
  31. package/dist/connector/ICustomEventMessageRequest.js +3 -0
  32. package/dist/connector/ICustomEventMessageRequest.js.map +1 -0
  33. package/dist/connector/ICustomEventMessageResponse.d.ts +10 -0
  34. package/dist/connector/ICustomEventMessageResponse.js +3 -0
  35. package/dist/connector/ICustomEventMessageResponse.js.map +1 -0
  36. package/dist/connector/IRegisterEvent.d.ts +7 -0
  37. package/dist/connector/IRegisterEvent.js +3 -0
  38. package/dist/connector/IRegisterEvent.js.map +1 -0
  39. package/dist/connector/index.d.ts +4 -0
  40. package/dist/connector/index.js +6 -0
  41. package/dist/connector/index.js.map +1 -0
  42. package/dist/index.d.ts +20 -0
  43. package/dist/index.js +41 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/provider/AccountDeletion.d.ts +23 -0
  46. package/dist/provider/AccountDeletion.js +14 -0
  47. package/dist/provider/AccountDeletion.js.map +1 -0
  48. package/dist/provider/AccountImport.d.ts +25 -0
  49. package/dist/provider/AccountImport.js +14 -0
  50. package/dist/provider/AccountImport.js.map +1 -0
  51. package/dist/provider/AccoutGeneration.d.ts +7 -0
  52. package/dist/provider/AccoutGeneration.js +3 -0
  53. package/dist/provider/AccoutGeneration.js.map +1 -0
  54. package/dist/provider/IProvider.d.ts +15 -0
  55. package/dist/provider/IProvider.js +3 -0
  56. package/dist/provider/IProvider.js.map +1 -0
  57. package/dist/provider/Provider.d.ts +67 -0
  58. package/dist/provider/Provider.js +126 -0
  59. package/dist/provider/Provider.js.map +1 -0
  60. package/dist/provider/index.d.ts +4 -0
  61. package/dist/provider/index.js +10 -0
  62. package/dist/provider/index.js.map +1 -0
  63. package/dist/thyra/RequestHandler.d.ts +35 -0
  64. package/dist/thyra/RequestHandler.js +103 -0
  65. package/dist/thyra/RequestHandler.js.map +1 -0
  66. package/dist/thyra/ThyraAccount.d.ts +77 -0
  67. package/dist/thyra/ThyraAccount.js +132 -0
  68. package/dist/thyra/ThyraAccount.js.map +1 -0
  69. package/dist/thyra/ThyraDiscovery.d.ts +69 -0
  70. package/dist/thyra/ThyraDiscovery.js +107 -0
  71. package/dist/thyra/ThyraDiscovery.js.map +1 -0
  72. package/dist/thyra/ThyraProvider.d.ts +87 -0
  73. package/dist/thyra/ThyraProvider.js +137 -0
  74. package/dist/thyra/ThyraProvider.js.map +1 -0
  75. package/dist/utils/time.d.ts +76 -0
  76. package/dist/utils/time.js +120 -0
  77. package/dist/utils/time.js.map +1 -0
  78. package/package.json +6 -2
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ICustomEventMessageResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ICustomEventMessageResponse.js","sourceRoot":"","sources":["../../src/connector/ICustomEventMessageResponse.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This interface represents the object that is used to register an event.
3
+ */
4
+ export interface IRegisterEvent {
5
+ providerName: string;
6
+ eventTarget: string;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IRegisterEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IRegisterEvent.js","sourceRoot":"","sources":["../../src/connector/IRegisterEvent.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export { connector, AllowedRequests, AllowedResponses } from './Connector';
2
+ export { ICustomEventMessageRequest } from './ICustomEventMessageRequest';
3
+ export { ICustomEventMessageResponse } from './ICustomEventMessageResponse';
4
+ export { IRegisterEvent } from './IRegisterEvent';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.connector = void 0;
4
+ var Connector_1 = require("./Connector");
5
+ Object.defineProperty(exports, "connector", { enumerable: true, get: function () { return Connector_1.connector; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2E;AAAlE,sGAAA,SAAS,OAAA"}
@@ -0,0 +1,20 @@
1
+ import { IProvider } from './provider/IProvider';
2
+ export declare enum AvailableCommands {
3
+ ProviderListAccounts = "LIST_ACCOUNTS",
4
+ ProviderDeleteAccount = "DELETE_ACCOUNT",
5
+ ProviderImportAccount = "IMPORT_ACCOUNT",
6
+ ProviderGetNodesUrls = "GET_NODES_URLS",
7
+ AccountBalance = "ACCOUNT_BALANCE",
8
+ AccountSign = "ACCOUNT_SIGN",
9
+ ProviderGenerateNewAccount = "GENERATE_NEW_ACCOUNT",
10
+ AccountSellRolls = "ACCOUNT_SELL_ROLLS",
11
+ AccountBuyRolls = "ACCOUNT_BUY_ROLLS",
12
+ AccountSendTransaction = "ACCOUNT_SEND_TRANSACTION"
13
+ }
14
+ export interface ITransactionDetails {
15
+ operationId: string;
16
+ }
17
+ export declare function providers(): IProvider[];
18
+ export { AllowedRequests, AllowedResponses } from './connector';
19
+ export { IAccountDetails, IAccountBalanceRequest, IAccountBalanceResponse, IAccountSignRequest, IAccountSignResponse, IAccount, Account, IAccountRollsRequest, IAccountSendTransactionRequest, } from './account';
20
+ export { EAccountDeletionResponse, EAccountImportResponse, IAccountDeletionRequest, IAccountDeletionResponse, IAccountImportRequest, IAccountImportResponse, IProvider, Provider, } from './provider';
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.providers = exports.AvailableCommands = void 0;
4
+ const Connector_1 = require("./connector/Connector");
5
+ const Provider_1 = require("./provider/Provider");
6
+ const ThyraProvider_1 = require("./thyra/ThyraProvider");
7
+ var AvailableCommands;
8
+ (function (AvailableCommands) {
9
+ AvailableCommands["ProviderListAccounts"] = "LIST_ACCOUNTS";
10
+ AvailableCommands["ProviderDeleteAccount"] = "DELETE_ACCOUNT";
11
+ AvailableCommands["ProviderImportAccount"] = "IMPORT_ACCOUNT";
12
+ AvailableCommands["ProviderGetNodesUrls"] = "GET_NODES_URLS";
13
+ AvailableCommands["AccountBalance"] = "ACCOUNT_BALANCE";
14
+ AvailableCommands["AccountSign"] = "ACCOUNT_SIGN";
15
+ AvailableCommands["ProviderGenerateNewAccount"] = "GENERATE_NEW_ACCOUNT";
16
+ AvailableCommands["AccountSellRolls"] = "ACCOUNT_SELL_ROLLS";
17
+ AvailableCommands["AccountBuyRolls"] = "ACCOUNT_BUY_ROLLS";
18
+ AvailableCommands["AccountSendTransaction"] = "ACCOUNT_SEND_TRANSACTION";
19
+ })(AvailableCommands = exports.AvailableCommands || (exports.AvailableCommands = {}));
20
+ function providers() {
21
+ let providers = [];
22
+ for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
23
+ if (providerName === ThyraProvider_1.THYRA_PROVIDER_NAME) {
24
+ const p = new ThyraProvider_1.ThyraProvider();
25
+ providers.push(p);
26
+ }
27
+ else {
28
+ const p = new Provider_1.Provider(providerName);
29
+ providers.push(p);
30
+ }
31
+ }
32
+ return providers;
33
+ }
34
+ exports.providers = providers;
35
+ var account_1 = require("./account");
36
+ Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
37
+ var provider_1 = require("./provider");
38
+ Object.defineProperty(exports, "EAccountDeletionResponse", { enumerable: true, get: function () { return provider_1.EAccountDeletionResponse; } });
39
+ Object.defineProperty(exports, "EAccountImportResponse", { enumerable: true, get: function () { return provider_1.EAccountImportResponse; } });
40
+ Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return provider_1.Provider; } });
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD,kDAA+C;AAC/C,yDAA2E;AAE3E,IAAY,iBAWX;AAXD,WAAY,iBAAiB;IAC3B,2DAAsC,CAAA;IACtC,6DAAwC,CAAA;IACxC,6DAAwC,CAAA;IACxC,4DAAuC,CAAA;IACvC,uDAAkC,CAAA;IAClC,iDAA4B,CAAA;IAC5B,wEAAmD,CAAA;IACnD,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IACrC,wEAAmD,CAAA;AACrD,CAAC,EAXW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAW5B;AAMD,SAAgB,SAAS;IACvB,IAAI,SAAS,GAAgB,EAAE,CAAC;IAChC,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,qBAAS,CAAC,kBAAkB,EAAE,CAAC,EAAE;QACtE,IAAI,YAAY,KAAK,mCAAmB,EAAE;YACxC,MAAM,CAAC,GAAG,IAAI,6BAAa,EAAE,CAAC;YAC9B,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;aAAM;YACL,MAAM,CAAC,GAAG,IAAI,mBAAQ,CAAC,YAAY,CAAC,CAAC;YACrC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACnB;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,8BAYC;AAID,qCAUmB;AAHjB,kGAAA,OAAO,OAAA;AAKT,uCASoB;AARlB,oHAAA,wBAAwB,OAAA;AACxB,kHAAA,sBAAsB,OAAA;AAMtB,oGAAA,QAAQ,OAAA"}
@@ -0,0 +1,23 @@
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
+ }
@@ -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"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * This interface represents the request object sent to the content script
3
+ * for importing an account.
4
+ */
5
+ export interface IAccountImportRequest {
6
+ privateKey: string;
7
+ publicKey: string;
8
+ }
9
+ /**
10
+ * This interface represents the response object sent by the content script,
11
+ * indicating the result of an account import request.
12
+ */
13
+ export interface IAccountImportResponse {
14
+ response: EAccountImportResponse;
15
+ message: string;
16
+ }
17
+ /**
18
+ * This enum represents the possible responses from the content script
19
+ * in response to an account import request.
20
+ */
21
+ export declare enum EAccountImportResponse {
22
+ OK = 0,
23
+ REFUSED = 1,
24
+ ERROR = 2
25
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EAccountImportResponse = void 0;
4
+ /**
5
+ * This enum represents the possible responses from the content script
6
+ * in response to an account import request.
7
+ */
8
+ var EAccountImportResponse;
9
+ (function (EAccountImportResponse) {
10
+ EAccountImportResponse[EAccountImportResponse["OK"] = 0] = "OK";
11
+ EAccountImportResponse[EAccountImportResponse["REFUSED"] = 1] = "REFUSED";
12
+ EAccountImportResponse[EAccountImportResponse["ERROR"] = 2] = "ERROR";
13
+ })(EAccountImportResponse = exports.EAccountImportResponse || (exports.EAccountImportResponse = {}));
14
+ //# sourceMappingURL=AccountImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountImport.js","sourceRoot":"","sources":["../../src/provider/AccountImport.ts"],"names":[],"mappings":";;;AAkBA;;;GAGG;AACH,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,+DAAE,CAAA;IACF,yEAAO,CAAA;IACP,qEAAK,CAAA;AACP,CAAC,EAJW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAIjC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This interface represents the request object sent to the content script
3
+ * for generation a new random account.
4
+ */
5
+ export interface IAccountGenerationRequest {
6
+ name: string;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AccoutGeneration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccoutGeneration.js","sourceRoot":"","sources":["../../src/provider/AccoutGeneration.ts"],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { IAccountDeletionResponse } from './AccountDeletion';
2
+ import { IAccountImportResponse } from './AccountImport';
3
+ import { IAccount } from '../account/IAccount';
4
+ import { IAccountDetails } from '../account';
5
+ /**
6
+ * This interface represents a general provider definition with its methods
7
+ */
8
+ export interface IProvider {
9
+ name(): string;
10
+ accounts(): Promise<IAccount[]>;
11
+ importAccount(publicKey: string, privateKey: string): Promise<IAccountImportResponse>;
12
+ deleteAccount(address: string): Promise<IAccountDeletionResponse>;
13
+ getNodesUrls(): Promise<string[]>;
14
+ generateNewAccount(name: string): Promise<IAccountDetails>;
15
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../src/provider/IProvider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,67 @@
1
+ import { IAccountDeletionResponse } from './AccountDeletion';
2
+ import { IAccountImportResponse } from './AccountImport';
3
+ import { IAccountDetails } from '../account/IAccountDetails';
4
+ import { IProvider } from './IProvider';
5
+ import { IAccount } from '../account/IAccount';
6
+ /**
7
+ * The Provider class provides a simple and intuitive interface for interacting with a specific
8
+ * wallet service.
9
+ *
10
+ */
11
+ export declare class Provider implements IProvider {
12
+ private providerName;
13
+ /**
14
+ * Provider constructor
15
+ *
16
+ * @param providerName - The name of the provider.
17
+ * @returns An instance of the Provider class.
18
+ */
19
+ constructor(providerName: string);
20
+ /**
21
+ * This method returns the name of the provider.
22
+ * @returns The name of the provider.
23
+ */
24
+ name(): string;
25
+ /**
26
+ * This method sends a message to the content script to get the list of accounts for the provider.
27
+ * It returns a Promise that resolves to an array of Account instances.
28
+ *
29
+ * @returns A promise that resolves to an array of Account instances.
30
+ */
31
+ accounts(): Promise<IAccount[]>;
32
+ /**
33
+ * This method sends a message to the content script to import an account with the given publicKey and privateKey.
34
+ *
35
+ * @remarks
36
+ * - The IAccountImportResponse object contains the address of the imported account.
37
+ * - The address is generated from the public key.
38
+ *
39
+ * @param publicKey - The public key of the account.
40
+ * @param privateKey - The private key of the account.
41
+ * @returns a Promise that resolves to an instance of IAccountImportResponse.
42
+ *
43
+ */
44
+ importAccount(publicKey: string, privateKey: string): Promise<IAccountImportResponse>;
45
+ /**
46
+ * This method sends a message to the content script to delete the account associated with the given address.
47
+ *
48
+ * @param address - The address of the account.
49
+ * @returns a Promise that resolves to an instance of IAccountDeletionResponse.
50
+ */
51
+ deleteAccount(address: string): Promise<IAccountDeletionResponse>;
52
+ /**
53
+ * This method sends a message to the content script to get the list of nodes urls
54
+ * used to connect the front end to the Massa network.
55
+ *
56
+ * @returns a Promise that resolves to an array of nodes urls (string).
57
+ *
58
+ */
59
+ getNodesUrls(): Promise<string[]>;
60
+ /**
61
+ * This method generates a new account by a given name and adds it to the wallet.
62
+ *
63
+ * @param name - The account name
64
+ * @returns a Promise that resolves to an instance of IAccountDetails.
65
+ */
66
+ generateNewAccount(name?: string): Promise<IAccountDetails>;
67
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = void 0;
4
+ const Connector_1 = require("../connector/Connector");
5
+ const Account_1 = require("../account/Account");
6
+ const __1 = require("..");
7
+ /**
8
+ * The Provider class provides a simple and intuitive interface for interacting with a specific
9
+ * wallet service.
10
+ *
11
+ */
12
+ class Provider {
13
+ /**
14
+ * Provider constructor
15
+ *
16
+ * @param providerName - The name of the provider.
17
+ * @returns An instance of the Provider class.
18
+ */
19
+ constructor(providerName) {
20
+ this.providerName = providerName;
21
+ }
22
+ /**
23
+ * This method returns the name of the provider.
24
+ * @returns The name of the provider.
25
+ */
26
+ name() {
27
+ return this.providerName;
28
+ }
29
+ /**
30
+ * This method sends a message to the content script to get the list of accounts for the provider.
31
+ * It returns a Promise that resolves to an array of Account instances.
32
+ *
33
+ * @returns A promise that resolves to an array of Account instances.
34
+ */
35
+ async accounts() {
36
+ const providersPromise = new Promise((resolve, reject) => {
37
+ Connector_1.connector.sendMessageToContentScript(this.providerName, __1.AvailableCommands.ProviderListAccounts, {}, (result, err) => {
38
+ if (err)
39
+ return reject(err);
40
+ return resolve(result);
41
+ });
42
+ });
43
+ const providerAccounts = await providersPromise;
44
+ let accounts = [];
45
+ for (const providerAccount of providerAccounts) {
46
+ const accInstance = new Account_1.Account(providerAccount, this.providerName);
47
+ accounts.push(accInstance);
48
+ }
49
+ return accounts;
50
+ }
51
+ /**
52
+ * This method sends a message to the content script to import an account with the given publicKey and privateKey.
53
+ *
54
+ * @remarks
55
+ * - The IAccountImportResponse object contains the address of the imported account.
56
+ * - The address is generated from the public key.
57
+ *
58
+ * @param publicKey - The public key of the account.
59
+ * @param privateKey - The private key of the account.
60
+ * @returns a Promise that resolves to an instance of IAccountImportResponse.
61
+ *
62
+ */
63
+ async importAccount(publicKey, privateKey) {
64
+ const accountImportRequest = {
65
+ publicKey,
66
+ privateKey,
67
+ };
68
+ return new Promise((resolve, reject) => {
69
+ Connector_1.connector.sendMessageToContentScript(this.providerName, __1.AvailableCommands.ProviderImportAccount, accountImportRequest, (result, err) => {
70
+ if (err)
71
+ return reject(err);
72
+ return resolve(result);
73
+ });
74
+ });
75
+ }
76
+ /**
77
+ * This method sends a message to the content script to delete the account associated with the given address.
78
+ *
79
+ * @param address - The address of the account.
80
+ * @returns a Promise that resolves to an instance of IAccountDeletionResponse.
81
+ */
82
+ async deleteAccount(address) {
83
+ const accountDeletionRequest = { address };
84
+ return new Promise((resolve, reject) => {
85
+ Connector_1.connector.sendMessageToContentScript(this.providerName, __1.AvailableCommands.ProviderDeleteAccount, accountDeletionRequest, (result, err) => {
86
+ if (err)
87
+ return reject(err);
88
+ return resolve(result);
89
+ });
90
+ });
91
+ }
92
+ /**
93
+ * This method sends a message to the content script to get the list of nodes urls
94
+ * used to connect the front end to the Massa network.
95
+ *
96
+ * @returns a Promise that resolves to an array of nodes urls (string).
97
+ *
98
+ */
99
+ async getNodesUrls() {
100
+ return new Promise((resolve, reject) => {
101
+ Connector_1.connector.sendMessageToContentScript(this.providerName, __1.AvailableCommands.ProviderGetNodesUrls, {}, (result, err) => {
102
+ if (err)
103
+ return reject(err);
104
+ return resolve(result);
105
+ });
106
+ });
107
+ }
108
+ /**
109
+ * This method generates a new account by a given name and adds it to the wallet.
110
+ *
111
+ * @param name - The account name
112
+ * @returns a Promise that resolves to an instance of IAccountDetails.
113
+ */
114
+ async generateNewAccount(name) {
115
+ const accountGenerationRequest = { name };
116
+ return new Promise((resolve, reject) => {
117
+ Connector_1.connector.sendMessageToContentScript(this.providerName, __1.AvailableCommands.ProviderGenerateNewAccount, accountGenerationRequest, (result, err) => {
118
+ if (err)
119
+ return reject(err);
120
+ return resolve(result);
121
+ });
122
+ });
123
+ }
124
+ }
125
+ exports.Provider = Provider;
126
+ //# sourceMapp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G;IACI,KAAK,CAAC,kBAAkB,CAAC,IAAa;QAC3C,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAA+B,CAAC;QACvE,OAAO,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACtD,qBAAS,CAAC,0BAA0B,CAClC,IAAI,CAAC,YAAY,EACjB,qBAAiB,CAAC,0BAA0B,EAC5C,wBAAwB,EACxB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;gBACd,IAAI,GAAG;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5B,OAAO,OAAO,CAAC,MAAyB,CAAC,CAAC;YAC5C,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtJD,4BAsJC"}
@@ -0,0 +1,4 @@
1
+ export { EAccountDeletionResponse, IAccountDeletionRequest, IAccountDeletionResponse, } from './AccountDeletion';
2
+ export { IAccountImportRequest, IAccountImportResponse, EAccountImportResponse, } from './AccountImport';
3
+ export { IProvider } from './IProvider';
4
+ export { Provider } from './Provider';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = void 0;
4
+ var AccountDeletion_1 = require("./AccountDeletion");
5
+ Object.defineProperty(exports, "EAccountDeletionResponse", { enumerable: true, get: function () { return AccountDeletion_1.EAccountDeletionResponse; } });
6
+ var AccountImport_1 = require("./AccountImport");
7
+ Object.defineProperty(exports, "EAccountImportResponse", { enumerable: true, get: function () { return AccountImport_1.EAccountImportResponse; } });
8
+ var Provider_1 = require("./Provider");
9
+ Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return Provider_1.Provider; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/provider/index.ts"],"names":[],"mappings":";;;AAAA,qDAI2B;AAHzB,2HAAA,wBAAwB,OAAA;AAI1B,iDAIyB;AADvB,uHAAA,sBAAsB,OAAA;AAGxB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
@@ -0,0 +1,35 @@
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
+ * @returns a Promise that resolves to an instance of JsonRpcResponseData.
24
+ *
25
+ */
26
+ export declare function postRequest<T>(url: string, body: object): Promise<JsonRpcResponseData<T>>;
27
+ /**
28
+ * This method makes a DELETE request to an http rest point.
29
+ *
30
+ *
31
+ * @param url - The url to call.
32
+ * @returns a Promise that resolves to an instance of JsonRpcResponseData.
33
+ *
34
+ */
35
+ export declare function deleteRequest<T>(url: string): Promise<JsonRpcResponseData<T>>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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 Thyra'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
+ * @returns a Promise that resolves to an instance of JsonRpcResponseData.
55
+ *
56
+ */
57
+ async function postRequest(url, body) {
58
+ let resp = null;
59
+ try {
60
+ resp = await axios_1.default.post(url, body, requestHeaders);
61
+ }
62
+ catch (ex) {
63
+ return {
64
+ isError: true,
65
+ result: null,
66
+ error: new Error('Axios error: ' + String(ex)),
67
+ };
68
+ }
69
+ return {
70
+ isError: false,
71
+ result: resp.data,
72
+ error: null,
73
+ };
74
+ }
75
+ exports.postRequest = postRequest;
76
+ /**
77
+ * This method makes a DELETE request to an http rest point.
78
+ *
79
+ *
80
+ * @param url - The url to call.
81
+ * @returns a Promise that resolves to an instance of JsonRpcResponseData.
82
+ *
83
+ */
84
+ async function deleteRequest(url) {
85
+ let resp = null;
86
+ try {
87
+ resp = await axios_1.default.delete(url, requestHeaders);
88
+ }
89
+ catch (ex) {
90
+ return {
91
+ isError: true,
92
+ result: null,
93
+ error: new Error('Axios Error: ' + String(ex)),
94
+ };
95
+ }
96
+ return {
97
+ isError: false,
98
+ result: resp.data,
99
+ error: null,
100
+ };
101
+ }
102
+ exports.deleteRequest = deleteRequest;
103
+ //# sourceMappingURL=RequestHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequestHandler.js","sourceRoot":"","sources":["../../src/thyra/RequestHandler.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,iCAAkE;AAElE,MAAM,cAAc,GAAG;IACrB,MAAM,EACJ,kFAAkF;IACpF,6BAA6B,EAAE,GAAG;IAClC,kCAAkC,EAAE,IAAI;IACxC,8BAA8B,EAAE,mCAAmC;IACnE,cAAc,EAAE,kBAAkB;IAClC,8BAA8B,EAC5B,iDAAiD;CAC7B,CAAC;AAWzB;;;;;;;GAOG;AACI,KAAK,UAAU,UAAU,CAC9B,GAAW;IAEX,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,eAAK,CAAC,GAAG,CAAiC,GAAG,EAAE,cAAc,CAAC,CAAC;KAC7E;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;SACrB,CAAC;KAC7B;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,IAAI,CAAC,IAAS;QACtB,KAAK,EAAE,IAAI;KACc,CAAC;AAC9B,CAAC;AAnBD,gCAmBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,WAAW,CAC/B,GAAW,EACX,IAAY;IAEZ,IAAI,IAAI,GAAkB,IAAI,CAAC;IAC/B,IAAI;QACF,IAAI,GAAG,MAAM,eAAK,CAAC,IAAI,CACrB,GAAG,EACH,IAAI,EACJ,cAAc,CACf,CAAC;KACH;IAAC,OAAO,EAAE,EAAE;QACX,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,IAAI;YACZ,KAAK,EAAE,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,E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