@massalabs/wallet-provider 1.5.2-dev.20240104220542 → 1.5.2-dev.20240111154114

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 (39) hide show
  1. package/dist/cmd/bearbyWallet/BearbyProvider.d.ts +24 -0
  2. package/dist/cmd/bearbyWallet/BearbyProvider.d.ts.map +1 -1
  3. package/dist/cmd/bearbyWallet/BearbyProvider.js +24 -0
  4. package/dist/cmd/bearbyWallet/BearbyProvider.js.map +1 -1
  5. package/dist/cmd/index.d.ts +1 -0
  6. package/dist/cmd/index.d.ts.map +1 -1
  7. package/dist/cmd/index.js +6 -1
  8. package/dist/cmd/index.js.map +1 -1
  9. package/dist/cmd/massaStation/MassaStationProvider.d.ts +3 -0
  10. package/dist/cmd/massaStation/MassaStationProvider.d.ts.map +1 -1
  11. package/dist/cmd/massaStation/MassaStationProvider.js +4 -0
  12. package/dist/cmd/massaStation/MassaStationProvider.js.map +1 -1
  13. package/dist/cmd/provider/IProvider.d.ts +3 -0
  14. package/dist/cmd/provider/IProvider.d.ts.map +1 -1
  15. package/dist/cmd/provider/IProvider.js.map +1 -1
  16. package/dist/cmd/provider/Provider.d.ts +3 -0
  17. package/dist/cmd/provider/Provider.d.ts.map +1 -1
  18. package/dist/cmd/provider/Provider.js +4 -0
  19. package/dist/cmd/provider/Provider.js.map +1 -1
  20. package/dist/esm/bearbyWallet/BearbyProvider.d.ts +24 -0
  21. package/dist/esm/bearbyWallet/BearbyProvider.d.ts.map +1 -1
  22. package/dist/esm/bearbyWallet/BearbyProvider.js +24 -0
  23. package/dist/esm/bearbyWallet/BearbyProvider.js.map +1 -1
  24. package/dist/esm/index.d.ts +1 -0
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/index.js +4 -0
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/massaStation/MassaStationProvider.d.ts +3 -0
  29. package/dist/esm/massaStation/MassaStationProvider.d.ts.map +1 -1
  30. package/dist/esm/massaStation/MassaStationProvider.js +4 -0
  31. package/dist/esm/massaStation/MassaStationProvider.js.map +1 -1
  32. package/dist/esm/provider/IProvider.d.ts +3 -0
  33. package/dist/esm/provider/IProvider.d.ts.map +1 -1
  34. package/dist/esm/provider/IProvider.js.map +1 -1
  35. package/dist/esm/provider/Provider.d.ts +3 -0
  36. package/dist/esm/provider/Provider.d.ts.map +1 -1
  37. package/dist/esm/provider/Provider.js +4 -0
  38. package/dist/esm/provider/Provider.js.map +1 -1
  39. package/package.json +1 -1
@@ -16,5 +16,29 @@ export declare class BearbyProvider implements IProvider {
16
16
  getNodesUrls(): Promise<string[]>;
17
17
  getNetwork(): Promise<string>;
18
18
  generateNewAccount(name: string): Promise<IAccountDetails>;
19
+ /**
20
+ * Subscribes to account changes.
21
+ *
22
+ * @param callback - Callback to be called when the account changes.
23
+ *
24
+ * @returns A promise that resolves to a function that can be called to unsubscribe.
25
+ *
26
+ * @remarks
27
+ * Don't forget to unsubscribe to avoid memory leaks.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Subscribe
32
+ * const observer = await provider.listenAccountChanges((base58) => {
33
+ * console.log(base58);
34
+ * });
35
+ *
36
+ * // Unsubscribe
37
+ * observer.unsubscribe();
38
+ * ```
39
+ */
40
+ listenAccountChanges(callback: (base58: string) => void): {
41
+ unsubscribe: () => void;
42
+ };
19
43
  }
20
44
  //# sourceMappingURL=BearbyProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,SAAS,EACV,MAAM,aAAa,CAAC;AAGrB,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAA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M,EAAE,MAAM,KAAK,IAAI,GAAG;QAC/D,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB;CAGF"}
@@ -43,6 +43,30 @@ class BearbyProvider {
43
43
  async generateNewAccount(name) {
44
44
  throw new Error('Method not implemented.');
45
45
  }
46
+ /**
47
+ * Subscribes to account changes.
48
+ *
49
+ * @param callback - Callback to be called when the account changes.
50
+ *
51
+ * @returns A promise that resolves to a function that can be called to unsubscribe.
52
+ *
53
+ * @remarks
54
+ * Don't forget to unsubscribe to avoid memory leaks.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // Subscribe
59
+ * const observer = await provider.listenAccountChanges((base58) => {
60
+ * console.log(base58);
61
+ * });
62
+ *
63
+ * // Unsubscribe
64
+ * observer.unsubscribe();
65
+ * ```
66
+ */
67
+ listenAccountChanges(callback) {
68
+ return bearby_js_1.web3.wallet.account.subscribe((base58) => callback(base58));
69
+ }
46
70
  }
47
71
  exports.BearbyProvider = BearbyProvider;
48
72
  //# sourceMappingURL=BearbyProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAOzC,mDAAgD;AAEhD,MAAa,cAAc;IAGzB;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,gBAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;YACzC,IAAI,EAAE,QAAQ;SACf,CAAC;QACF,OAAO,CAAC,IAAI,6BAAa,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,SAAiB,EACjB,UAAkB;QAElB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,OAAe;QAEf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,OAAO,GAAG,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF;AAxDD,wCAwDC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\n\nexport class BearbyProvider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n return ['https://buildnet.massa.net/api/v2'];\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n\n return network.net;\n }\n\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n}\n"]}
1
+ {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":";;;AAAA,iDAAyC;AAOzC,mDAAgD;AAEhD,MAAa,cAAc;IAGzB;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,gBAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;YACzC,IAAI,EAAE,QAAQ;SACf,CAAC;QACF,OAAO,CAAC,IAAI,6BAAa,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,SAAiB,EACjB,UAAkB;QAElB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,OAAe;QAEf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,OAAO,GAAG,MAAM,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAkC;QAG5D,OAAO,gBAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACrE,CAAC;CACF;AAnFD,wCAmFC","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\n\nexport class BearbyProvider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n return ['https://buildnet.massa.net/api/v2'];\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n\n return network.net;\n }\n\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Subscribes to account changes.\n *\n * @param callback - Callback to be called when the account changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenAccountChanges((base58) => {\n * console.log(base58);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenAccountChanges(callback: (base58: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.account.subscribe((base58) => callback(base58));\n }\n}\n"]}
@@ -42,6 +42,7 @@ export declare function providers(retry?: boolean, timeout?: number, pollInterva
42
42
  * @param id - The id of the HTML element that is used to communicate with the provider.
43
43
  */
44
44
  export declare function registerProvider(name: string, id?: string): void;
45
+ export declare function getProviderByName(providerName: string): Promise<IProvider | undefined>;
45
46
  export { AllowedRequests, AllowedResponses } from './connector';
46
47
  export { IAccountDetails, IAccountBalanceRequest, IAccountBalanceResponse, IAccountSignRequest, IAccountSignResponse, IAccount, Account, IAccountRollsRequest, IAccountSendTransactionRequest, IAccountCallSCRequest, } from './account';
47
48
  export { EAccountDeletionResponse, EAccountImportResponse, IAccountDeletionRequest, IAccountDeletionResponse, IAccountImportRequest, IAccountImportResponse, IProvider, Provider, } from './provider';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAUjD,oBAAY,iBAAiB;IAC3B,oBAAoB,kBAAkB;IACtC,qBAAqB,mBAAmB;IACxC,qBAAqB,mBAAmB;IACxC,oBAAoB,mBAAmB;IACvC,kBAAkB,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,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/cmd/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.disconnectBearby = exports.connectBearby = exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.registerProvider = exports.providers = exports.AvailableCommands = void 0;
3
+ exports.disconnectBearby = exports.connectBearby = exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.getProviderByName = exports.registerProvider = exports.providers = exports.AvailableCommands = void 0;
4
4
  /** Polyfills */
5
5
  const buffer_1 = require("buffer");
6
6
  // Check if we are on browser
@@ -86,6 +86,11 @@ function registerProvider(name, id = Connector_1.MASSA_WINDOW_OBJECT) {
86
86
  }
87
87
  }
88
88
  exports.registerProvider = registerProvider;
89
+ async function getProviderByName(providerName) {
90
+ const providersList = await providers();
91
+ return providersList.find((p) => p.name() === providerName);
92
+ }
93
+ exports.getProviderByName = getProviderByName;
89
94
  var account_1 = require("./account");
90
95
  Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
91
96
  var provider_1 = require("./provider");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AAChB,mCAAgC;AAShC,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,MAAM,GAAG,eAAM,CAAC;CACxB;AAED,qDAAuE;AAEvE,kDAA+C;AAC/C,8EAG6C;AAC7C,gEAA4D;AAC5D,kEAA+D;AAC/D,uCAAoC;AAEpC,IAAY,iBAaX;AAbD,WAAY,iBAAiB;IAC3B,2DAAsC,CAAA;IACtC,6DAAwC,CAAA;IACxC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AE;YAChD,OAAO,IAAI,2CAAoB,CAC7B,qBAAS,CAAC,eAAe,CAAC,YAAY,CAAC,CACxC,CAAC;SACH;aAAM;YACL,OAAO,IAAI,mBAAQ,CAAC,YAAY,CAAC,CAAC;SACnC;IACH,CAAC,CACF,CAAC;IACF,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,EAAE,GAAG,+BAAmB;IACrE,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QACnC,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC,UAAU,EAAE;YAChD,MAAM,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;SAC/B,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,QAAQ,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;SACtC;KACF;AACH,CAAC;AAVD,4CAUC;AAID,qCAWmB;AAJjB,kGAAA,OAAO,OAAA;AAMT,uCASoB;AARlB,oHAAA,wBAAwB,OAAA;AACxB,kHAAA,sBAAsB,OAAA;AAMtB,oGAAA,QAAQ,OAAA;AAKV,0EAAyE;AAAhE,0HAAA,mBAAmB,OAAA;AAE5B,8DAA+E;AAAtE,8GAAA,aAAa,OAAA;AAAE,iHAAA,gBAAgB,OAAA","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nimport { MASSA_WINDOW_OBJECT, connector } from './connector/Connector';\nimport { IProvider } from './provider/IProvider';\nimport { Provider } from './provider/Provider';\nimport {\n MASSA_STATION_PROVIDER_NAME,\n MassaStationProvider,\n} from './massaStation/MassaStationProvider';\nimport { detectBearby } from './bearbyWallet/BearbyConnect';\nimport { BearbyProvider } from './bearbyWallet/BearbyProvider';\nimport { wait } from './utils/time';\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport interface ITransactionDetails {\n operationId: string;\n}\n\n/**\n * Get the list of providers that are available to interact with.\n *\n * @param retry - If true, will retry to get the list of providers if none are available.\n * @param pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.\n * @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.\n *\n * @returns An array of providers.\n */\nexport async function providers(\n retry = true,\n timeout = 3000,\n pollInterval = 500,\n): Promise<IProvider[]> {\n const startTime = Date.now();\n\n await connector.startMassaStationDiscovery();\n\n let bearby: BearbyProvider | undefined;\n if (await detectBearby()) {\n bearby = new BearbyProvider('BEARBY');\n }\n\n while (Date.now() - startTime < timeout) {\n const providerInstances: IProvider[] = getProviderInstances();\n\n if (bearby) providerInstances.push(bearby);\n\n if (!retry || providerInstances.length > 0) {\n return providerInstances;\n }\n\n await wait(pollInterval);\n }\n\n return [];\n}\n\nfunction getProviderInstances() {\n const availableProviders = Object.keys(connector.getWalletProviders());\n\n const providerInstances: IProvider[] = availableProviders.map(\n (providerName) => {\n if (providerName === MASSA_STATION_PROVIDER_NAME) {\n return new MassaStationProvider(\n connector.getProviderInfo(providerName),\n );\n } else {\n return new Provider(providerName);\n }\n },\n );\n return providerInstances;\n}\n\n/**\n * Manually register a provider to interact with.\n *\n * @param name - The name of the provider.\n * @param id - The id of the HTML element that is used to communicate with the provider.\n */\nexport function registerProvider(name: string, id = MASSA_WINDOW_OBJECT): void {\n if (typeof document !== 'undefined') {\n const registerEvent = new CustomEvent('register', {\n detail: { providerName: name },\n });\n const element = document?.getElementById(id);\n if (element) {\n element.dispatchEvent(registerEvent);\n }\n }\n}\n\nexport { AllowedRequests, AllowedResponses } from './connector';\n\nexport {\n IAccountDetails,\n IAccountBalanceRequest,\n IAccountBalanceResponse,\n IAccountSignRequest,\n IAccountSignResponse,\n IAccount,\n Account,\n IAccountRollsRequest,\n IAccountSendTransactionRequest,\n IAccountCallSCRequest,\n} from './account';\n\nexport {\n EAccountDeletionResponse,\n EAccountImportResponse,\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n IAccountImportRequest,\n IAccountImportResponse,\n IProvider,\n Provider,\n} from './provider';\n\nexport { IMassaStationWallet } from './massaStation/MassaStationProvider';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { connectBearby, disconnectBearby } from './bearbyWallet/BearbyConnect';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gBAAgB;AAChB,mCAAgC;AAShC,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,MAAM,GAAG,eAAM,CAAC;CACxB;AAED,qDAAuE;AAEvE,kDAA+C;AAC/C,8EAG6C;AAC7C,gEAA4D;AAC5D,kEAA+D;AAC/D,uCAAoC;AAEpC,IAAY,iBAaX;AAbD,WAAY,iBAAiB;IAC3B,2DAAsC,CAAA;IACtC,6DAAwC,CAAA;IACxC,6DAAwC,CAAA;IACxC,4DAAuC,CAAA;IACvC,uDAAkC,CAAA;IAClC,uDAAkC,CAAA;IAClC,iDAA4B,CAAA;IAC5B,wEAAmD,CAAA;IACnD,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IAC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,CACF,CAAC;IACF,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAY,EAAE,EAAE,GAAG,+BAAmB;IACrE,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;QACnC,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC,UAAU,EAAE;YAChD,MAAM,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;SAC/B,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,QAAQ,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;SACtC;KACF;AACH,CAAC;AAVD,4CAUC;AAEM,KAAK,UAAU,iBAAiB,CACrC,YAAoB;IAEpB,MAAM,aAAa,GAAG,MAAM,SAAS,EAAE,CAAC;IACxC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC,CAAC;AAC9D,CAAC;AALD,8CAKC;AAID,qCAWmB;AAJjB,kGAAA,OAAO,OAAA;AAMT,uCASoB;AARlB,oHAAA,wBAAwB,OAAA;AACxB,kHAAA,sBAAsB,OAAA;AAMtB,oGAAA,QAAQ,OAAA;AAKV,0EAAyE;AAAhE,0HAAA,mBAAmB,OAAA;AAE5B,8DAA+E;AAAtE,8GAAA,aAAa,OAAA;AAAE,iHAAA,gBAAgB,OAAA","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nimport { MASSA_WINDOW_OBJECT, connector } from './connector/Connector';\nimport { IProvider } from './provider/IProvider';\nimport { Provider } from './provider/Provider';\nimport {\n MASSA_STATION_PROVIDER_NAME,\n MassaStationProvider,\n} from './massaStation/MassaStationProvider';\nimport { detectBearby } from './bearbyWallet/BearbyConnect';\nimport { BearbyProvider } from './bearbyWallet/BearbyProvider';\nimport { wait } from './utils/time';\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport interface ITransactionDetails {\n operationId: string;\n}\n\n/**\n * Get the list of providers that are available to interact with.\n *\n * @param retry - If true, will retry to get the list of providers if none are available.\n * @param pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.\n * @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.\n *\n * @returns An array of providers.\n */\nexport async function providers(\n retry = true,\n timeout = 3000,\n pollInterval = 500,\n): Promise<IProvider[]> {\n const startTime = Date.now();\n\n await connector.startMassaStationDiscovery();\n\n let bearby: BearbyProvider | undefined;\n if (await detectBearby()) {\n bearby = new BearbyProvider('BEARBY');\n }\n\n while (Date.now() - startTime < timeout) {\n const providerInstances: IProvider[] = getProviderInstances();\n\n if (bearby) providerInstances.push(bearby);\n\n if (!retry || providerInstances.length > 0) {\n return providerInstances;\n }\n\n await wait(pollInterval);\n }\n\n return [];\n}\n\nfunction getProviderInstances() {\n const availableProviders = Object.keys(connector.getWalletProviders());\n\n const providerInstances: IProvider[] = availableProviders.map(\n (providerName) => {\n if (providerName === MASSA_STATION_PROVIDER_NAME) {\n return new MassaStationProvider(\n connector.getProviderInfo(providerName),\n );\n } else {\n return new Provider(providerName);\n }\n },\n );\n return providerInstances;\n}\n\n/**\n * Manually register a provider to interact with.\n *\n * @param name - The name of the provider.\n * @param id - The id of the HTML element that is used to communicate with the provider.\n */\nexport function registerProvider(name: string, id = MASSA_WINDOW_OBJECT): void {\n if (typeof document !== 'undefined') {\n const registerEvent = new CustomEvent('register', {\n detail: { providerName: name },\n });\n const element = document?.getElementById(id);\n if (element) {\n element.dispatchEvent(registerEvent);\n }\n }\n}\n\nexport async function getProviderByName(\n providerName: string,\n): Promise<IProvider | undefined> {\n const providersList = await providers();\n return providersList.find((p) => p.name() === providerName);\n}\n\nexport { AllowedRequests, AllowedResponses } from './connector';\n\nexport {\n IAccountDetails,\n IAccountBalanceRequest,\n IAccountBalanceResponse,\n IAccountSignRequest,\n IAccountSignResponse,\n IAccount,\n Account,\n IAccountRollsRequest,\n IAccountSendTransactionRequest,\n IAccountCallSCRequest,\n} from './account';\n\nexport {\n EAccountDeletionResponse,\n EAccountImportResponse,\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n IAccountImportRequest,\n IAccountImportResponse,\n IProvider,\n Provider,\n} from './provider';\n\nexport { IMassaStationWallet } from './massaStation/MassaStationProvider';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { connectBearby, disconnectBearby } from './bearbyWallet/BearbyConnect';\n"]}
@@ -104,6 +104,9 @@ export declare class MassaStationProvider implements IProvider {
104
104
  * @returns a Promise that resolves to the details of the newly generated account.
105
105
  */
106
106
  generateNewAccount(name: string): Promise<IAccountDetails>;
107
+ listenAccountChanges(callback: (address: string) => void): {
108
+ unsubscribe: () => void;
109
+ } | undefined;
107
110
  }
108
111
  export {};
109
112
  //# 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,MAA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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"}
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;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;IAyBhE,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;CAM3C"}
@@ -222,6 +222,10 @@ class MassaStationProvider {
222
222
  throw ex;
223
223
  }
224
224
  }
225
+ listenAccountChanges(callback) {
226
+ console.log('The listen Account Change functionality is not yet implemented for the current provider.');
227
+ return undefined;
228
+ }
225
229
  }
226
230
  exports.MassaStationProvider = MassaStationProvider;
227
231
  //# sourceMappingURL=MassaStationProvider.js.map
@@ -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,wBAAw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,KAAK,CAAC,UAAU;QACrB,IAAI,aAAa,GAAiC,IAAI,CAAC;QACvD,IAAI;YACF,aAAa,GAAG,MAAM,IAAA,2BAAU,EAC9B,GAAG,yBAAiB,YAAY,CACjC,CAAC;YACF,IAAI,aAAa,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,kCAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrD,IAAI;YACF,4BAA4B,GAAG,MAAM,IAAA,4BAAW,EAC9C,kCAA0B,GAAG,GAAG,GAAG,IAAI,EACvC,EAAE,CACH,CAAC;YACF,IACE,4BAA4B,CAAC,OAAO;gBACpC,4BAA4B,CAAC,KAAK,EAClC;gBACA,MAAM,4BAA4B,CAAC,KAAK,CAAC,OAAO,CAAC;aAClD;YACD,OAAO;gBACL,OAAO,EAAE,4BAA4B,CAAC,MAAM,CAAC,OAAO;gBACpD,IAAI,EAAE,4BAA4B,CAAC,MAAM,CAAC,QAAQ;aAChC,CAAC;SACtB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;CACF;AAxOD,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"]}
1
+ {"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":";;;AAAA,iEAGqC;AACrC,6DAImC;AAEnC,qDAM0B;AAC1B,+DAA4D;AAK5D;;GAEG;AACU,QAAA,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D;;GAEG;AACU,QAAA,0BAA0B,GAAG,GAAG,yBAAiB,6CAA6C,CAAC;AAE5G;;GAEG;AACU,QAAA,iCAAiC,GAAG,GAAG,kCAA0B,UAAU,CAAC;AAEzF;;GAEG;AACU,QAAA,2BAA2B,GAAG,cAAc,CAAC;AAiB1D,IAAK,yBAGJ;AAHD,WAAK,yBAAyB;IAC5B,sCAAS,CAAA;IACT,oDAAuB,CAAA;AACzB,CAAC,EAHI,yBAAyB,KAAzB,yBAAyB,QAG7B;AAED;;;;GAIG;AACH,MAAa,oBAAoB;IAG/B;;;;;OAKG;IACH,YAA2B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,KAAK,CAAC,oCAAoC,EAAE,EAAE,CAAC,CAAC;YACxD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,IAAI,4BAA4B,GAC9B,IAAI,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,kCAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QACrD,IAAI;YACF,4BAA4B,GAAG,MAAM,IAAA,4BAAW,EAC9C,kCAA0B,GAAG,GAAG,GAAG,IAAI,EACvC,EAAE,CACH,CAAC;YACF,IACE,4BAA4B,CAAC,OAAO;gBACpC,4BAA4B,CAAC,KAAK,EAClC;gBACA,MAAM,4BAA4B,CAAC,KAAK,CAAC,OAAO,CAAC;aAClD;YACD,OAAO;gBACL,OAAO,EAAE,4BAA4B,CAAC,MAAM,CAAC,OAAO;gBACpD,IAAI,EAAE,4BAA4B,CAAC,MAAM,CAAC,QAAQ;aAChC,CAAC;SACtB;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;YACvD,MAAM,EAAE,CAAC;SACV;IACH,CAAC;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAjPD,oDAiPC","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo } from './types';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\n address: string;\n nickname: string;\n keyPair: {\n nonce: string;\n privateKey: string;\n publicKey: string;\n salt: string;\n };\n status: MassaStationAccountStatus;\n}\n\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
@@ -13,5 +13,8 @@ export interface IProvider {
13
13
  getNodesUrls(): Promise<string[]>;
14
14
  getNetwork(): Promise<string>;
15
15
  generateNewAccount(name: string): Promise<IAccountDetails>;
16
+ listenAccountChanges(callback: (base58: string) => void): {
17
+ unsubscribe: () => void;
18
+ } | undefined;
16
19
  }
17
20
  //# sourceMappingURL=IProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC5D"}
1
+ {"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3D,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACnD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n}\n"]}
1
+ {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
@@ -70,5 +70,8 @@ export declare class Provider implements IProvider {
70
70
  * @returns a Promise that resolves to an instance of IAccountDetails.
71
71
  */
72
72
  generateNewAccount(name?: string): Promise<IAccountDetails>;
73
+ listenAccountChanges(callback: (address: string) => void): {
74
+ unsubscribe: () => void;
75
+ } | undefined;
73
76
  }
74
77
  //# sourceMappingURL=Provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EAC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;GAIG;AACH,qBAAa,QAAS,YAAW,SAAS;IACxC,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM;IAIvC;;;OAGG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;;OAKG;IACU,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IA0B5C;;;;;;;;;;;OAWG;IACU,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAkBlC;;;;;OAKG;IACU,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAepC;;;;;;OAMG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAc9C;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAmB1C;;;;;OAKG;IACU,kBAAkB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAejE,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;CAM3C"}
@@ -138,6 +138,10 @@ class Provider {
138
138
  });
139
139
  });
140
140
  }
141
+ listenAccountChanges(callback) {
142
+ console.error('The listen Account Change functionality is not yet implemented for the current provider.');
143
+ return undefined;
144
+ }
141
145
  }
142
146
  exports.Provider = Provider;
143
147
  //# sourceMappingURL=Provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":";;;AAKA,sDAAmD;AACnD,gDAA6C;AAC7C,0BAAuC;AAMvC;;;;GAIG;AACH,MAAa,QAAQ;IAGnB;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;O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C;qBACvB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;oBACnC,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,6BAA6B,OAAO,MAAM,UAAU,CAAC,CAChE,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;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;AA9KD,4BA8KC","sourcesContent":["import {\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n} from './AccountDeletion';\nimport { IAccountImportRequest, IAccountImportResponse } from './AccountImport';\nimport { connector } from '../connector/Connector';\nimport { Account } from '../account/Account';\nimport { AvailableCommands } from '..';\nimport { IAccountDetails } from '../account/IAccountDetails';\nimport { IProvider } from './IProvider';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountGenerationRequest } from './AccoutGeneration';\n\n/**\n * The Provider class provides a simple and intuitive interface for interacting with a specific\n * wallet service.\n *\n */\nexport class Provider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n /**\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 content script 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 const providersPromise = new Promise<IAccountDetails[]>(\n (resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderListAccounts,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails[]);\n },\n );\n },\n );\n\n const providerAccounts: IAccountDetails[] = await providersPromise;\n\n let accounts: Account[] = [];\n for (const providerAccount of providerAccounts) {\n const accInstance = new Account(providerAccount, this.providerName);\n accounts.push(accInstance);\n }\n\n return accounts;\n }\n\n /**\n * This method sends a message to the content script to import an account with the given publicKey and privateKey.\n *\n * @remarks\n * - The IAccountImportResponse object contains the address of the imported account.\n * - The address is generated from the public key.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n *\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest = {\n publicKey,\n privateKey,\n } as IAccountImportRequest;\n return new Promise<IAccountImportResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderImportAccount,\n accountImportRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountImportResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script 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 const accountDeletionRequest = { address } as IAccountDeletionRequest;\n return new Promise<IAccountDeletionResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderDeleteAccount,\n accountDeletionRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDeletionResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script to get the list of nodes urls\n * used to connect the front end to the Massa network.\n *\n * @returns a Promise that resolves to an array of nodes urls (string).\n *\n */\n public async getNodesUrls(): Promise<string[]> {\n return new Promise<string[]>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNodesUrls,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as string[]);\n },\n );\n });\n }\n\n /**\n * Returns the name of the network the provider is connected to.\n *\n * @returns a Promise that resolves to the network name (string).\n */\n public async getNetwork(): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNetwork,\n {},\n (result, err) => {\n if (err) return reject(err);\n else if (typeof result !== 'string') {\n return reject(\n new Error(`Expected a string but got ${typeof result} instead`),\n );\n }\n return resolve(result);\n },\n );\n });\n }\n\n /**\n * This method generates a new account by a given name and adds it to the wallet.\n *\n * @param name - The account name\n * @returns a Promise that resolves to an instance of IAccountDetails.\n */\n public async generateNewAccount(name?: string): Promise<IAccountDetails> {\n const accountGenerationRequest = { name } as IAccountGenerationRequest;\n return new Promise<IAccountDetails>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGenerateNewAccount,\n accountGenerationRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails);\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":";;;AAKA,sDAAmD;AACnD,gDAA6C;AAC7C,0BAAuC;AAMvC;;;;GAIG;AACH,MAAa,QAAQ;IAGnB;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IA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CACX,IAAI,KAAK,CAAC,6BAA6B,OAAO,MAAM,UAAU,CAAC,CAChE,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;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;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,KAAK,CACX,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAvLD,4BAuLC","sourcesContent":["import {\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n} from './AccountDeletion';\nimport { IAccountImportRequest, IAccountImportResponse } from './AccountImport';\nimport { connector } from '../connector/Connector';\nimport { Account } from '../account/Account';\nimport { AvailableCommands } from '..';\nimport { IAccountDetails } from '../account/IAccountDetails';\nimport { IProvider } from './IProvider';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountGenerationRequest } from './AccoutGeneration';\n\n/**\n * The Provider class provides a simple and intuitive interface for interacting with a specific\n * wallet service.\n *\n */\nexport class Provider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n /**\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 content script 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 const providersPromise = new Promise<IAccountDetails[]>(\n (resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderListAccounts,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails[]);\n },\n );\n },\n );\n\n const providerAccounts: IAccountDetails[] = await providersPromise;\n\n let accounts: Account[] = [];\n for (const providerAccount of providerAccounts) {\n const accInstance = new Account(providerAccount, this.providerName);\n accounts.push(accInstance);\n }\n\n return accounts;\n }\n\n /**\n * This method sends a message to the content script to import an account with the given publicKey and privateKey.\n *\n * @remarks\n * - The IAccountImportResponse object contains the address of the imported account.\n * - The address is generated from the public key.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n *\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest = {\n publicKey,\n privateKey,\n } as IAccountImportRequest;\n return new Promise<IAccountImportResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderImportAccount,\n accountImportRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountImportResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script 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 const accountDeletionRequest = { address } as IAccountDeletionRequest;\n return new Promise<IAccountDeletionResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderDeleteAccount,\n accountDeletionRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDeletionResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script to get the list of nodes urls\n * used to connect the front end to the Massa network.\n *\n * @returns a Promise that resolves to an array of nodes urls (string).\n *\n */\n public async getNodesUrls(): Promise<string[]> {\n return new Promise<string[]>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNodesUrls,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as string[]);\n },\n );\n });\n }\n\n /**\n * Returns the name of the network the provider is connected to.\n *\n * @returns a Promise that resolves to the network name (string).\n */\n public async getNetwork(): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNetwork,\n {},\n (result, err) => {\n if (err) return reject(err);\n else if (typeof result !== 'string') {\n return reject(\n new Error(`Expected a string but got ${typeof result} instead`),\n );\n }\n return resolve(result);\n },\n );\n });\n }\n\n /**\n * This method generates a new account by a given name and adds it to the wallet.\n *\n * @param name - The account name\n * @returns a Promise that resolves to an instance of IAccountDetails.\n */\n public async generateNewAccount(name?: string): Promise<IAccountDetails> {\n const accountGenerationRequest = { name } as IAccountGenerationRequest;\n return new Promise<IAccountDetails>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGenerateNewAccount,\n accountGenerationRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails);\n },\n );\n });\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.error(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
@@ -16,5 +16,29 @@ export declare class BearbyProvider implements IProvider {
16
16
  getNodesUrls(): Promise<string[]>;
17
17
  getNetwork(): Promise<string>;
18
18
  generateNewAccount(name: string): Promise<IAccountDetails>;
19
+ /**
20
+ * Subscribes to account changes.
21
+ *
22
+ * @param callback - Callback to be called when the account changes.
23
+ *
24
+ * @returns A promise that resolves to a function that can be called to unsubscribe.
25
+ *
26
+ * @remarks
27
+ * Don't forget to unsubscribe to avoid memory leaks.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Subscribe
32
+ * const observer = await provider.listenAccountChanges((base58) => {
33
+ * console.log(base58);
34
+ * });
35
+ *
36
+ * // Unsubscribe
37
+ * observer.unsubscribe();
38
+ * ```
39
+ */
40
+ listenAccountChanges(callback: (base58: string) => void): {
41
+ unsubscribe: () => void;
42
+ };
19
43
  }
20
44
  //# sourceMappingURL=BearbyProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,SAAS,EACV,MAAM,aAAa,CAAC;AAGrB,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM;IAIhC,IAAI,IAAI,MAAM;IAIR,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAa/B,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAIrB,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIjC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;CAGxE"}
1
+ {"version":3,"file":"BearbyProvider.d.ts","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,SAAS,EACV,MAAM,aAAa,CAAC;AAGrB,qBAAa,cAAe,YAAW,SAAS;IAC9C,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM;IAIhC,IAAI,IAAI,MAAM;IAIR,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAa/B,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAIrB,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAIvB,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIjC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAIvE;;;;;;;;;;;;;;;;;;;;OAoBG;IACI,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG;QAC/D,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB;CAGF"}
@@ -41,5 +41,29 @@ export class BearbyProvider {
41
41
  async generateNewAccount(name) {
42
42
  throw new Error('Method not implemented.');
43
43
  }
44
+ /**
45
+ * Subscribes to account changes.
46
+ *
47
+ * @param callback - Callback to be called when the account changes.
48
+ *
49
+ * @returns A promise that resolves to a function that can be called to unsubscribe.
50
+ *
51
+ * @remarks
52
+ * Don't forget to unsubscribe to avoid memory leaks.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Subscribe
57
+ * const observer = await provider.listenAccountChanges((base58) => {
58
+ * console.log(base58);
59
+ * });
60
+ *
61
+ * // Unsubscribe
62
+ * observer.unsubscribe();
63
+ * ```
64
+ */
65
+ listenAccountChanges(callback) {
66
+ return web3.wallet.account.subscribe((base58) => callback(base58));
67
+ }
44
68
  }
45
69
  //# sourceMappingURL=BearbyProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAOzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,OAAO,cAAc;IACjB,YAAY,CAAS;IAE7B;;;;;OAKG;IACH,YAAmB,YAAoB;QACrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAEM,IAAI;QACT,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,8BAA8B;QAC9B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC1B,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC7B;QAED,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM;YACzC,IAAI,EAAE,QAAQ;SACf,CAAC;QACF,OAAO,CAAC,IAAI,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,SAAiB,EACjB,UAAkB;QAElB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,aAAa,CACxB,OAAe;QAEf,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK,CAAC,UAAU;QACrB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;QAE1C,OAAO,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,IAAY;QAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\n\nexport class BearbyProvider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n return ['https://buildnet.massa.net/api/v2'];\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n\n return network.net;\n }\n\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n}\n"]}
1
+ {"version":3,"file":"BearbyProvider.js","sourceRoot":"","sources":["../../../src/bearbyWallet/BearbyProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAOzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,OAAO,cAAc;IACjB,YAAY,CAAS;IAE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AC,CAAC,CAAC;IACrE,CAAC;CACF","sourcesContent":["import { web3 } from '@hicaru/bearby.js';\nimport { IAccount, IAccountDetails } from '../account';\nimport {\n IAccountDeletionResponse,\n IAccountImportResponse,\n IProvider,\n} from '../provider';\nimport { BearbyAccount } from './BearbyAccount';\n\nexport class BearbyProvider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n public name(): string {\n return this.providerName;\n }\n\n public async accounts(): Promise<IAccount[]> {\n // check if bearby is unlocked\n if (!web3.wallet.connected) {\n await web3.wallet.connect();\n }\n\n const account = {\n address: await web3.wallet.account.base58,\n name: 'BEARBY',\n };\n return [new BearbyAccount(account, this.providerName)];\n }\n\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n throw new Error('Method not implemented.');\n }\n\n public async getNodesUrls(): Promise<string[]> {\n return ['https://buildnet.massa.net/api/v2'];\n }\n\n public async getNetwork(): Promise<string> {\n const network = await web3.wallet.network;\n\n return network.net;\n }\n\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n throw new Error('Method not implemented.');\n }\n\n /**\n * Subscribes to account changes.\n *\n * @param callback - Callback to be called when the account changes.\n *\n * @returns A promise that resolves to a function that can be called to unsubscribe.\n *\n * @remarks\n * Don't forget to unsubscribe to avoid memory leaks.\n *\n * @example\n * ```typescript\n * // Subscribe\n * const observer = await provider.listenAccountChanges((base58) => {\n * console.log(base58);\n * });\n *\n * // Unsubscribe\n * observer.unsubscribe();\n * ```\n */\n public listenAccountChanges(callback: (base58: string) => void): {\n unsubscribe: () => void;\n } {\n return web3.wallet.account.subscribe((base58) => callback(base58));\n }\n}\n"]}
@@ -42,6 +42,7 @@ export declare function providers(retry?: boolean, timeout?: number, pollInterva
42
42
  * @param id - The id of the HTML element that is used to communicate with the provider.
43
43
  */
44
44
  export declare function registerProvider(name: string, id?: string): void;
45
+ export declare function getProviderByName(providerName: string): Promise<IProvider | undefined>;
45
46
  export { AllowedRequests, AllowedResponses } from './connector';
46
47
  export { IAccountDetails, IAccountBalanceRequest, IAccountBalanceResponse, IAccountSignRequest, IAccountSignResponse, IAccount, Account, IAccountRollsRequest, IAccountSendTransactionRequest, IAccountCallSCRequest, } from './account';
47
48
  export { EAccountDeletionResponse, EAccountImportResponse, IAccountDeletionRequest, IAccountDeletionResponse, IAccountImportRequest, IAccountImportResponse, IProvider, Provider, } from './provider';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAUjD,oBAAY,iBAAiB;IAC3B,oBAAoB,kBAAkB;IACtC,qBAAqB,mBAAmB;IACxC,qBAAqB,mBAAmB;IACxC,oBAAoB,mBAAmB;IACvC,kBAAkB,gBAAgB;IAClC,cAAc,oBAAoB;IAClC,WAAW,iBAAiB;IAC5B,0BAA0B,yBAAyB;IACnD,gBAAgB,uBAAuB;IACvC,eAAe,sBAAsB;IACrC,sBAAsB,6BAA6B;IACnD,aAAa,oBAAoB;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,KAAK,UAAO,EACZ,OAAO,SAAO,EACd,YAAY,SAAM,GACjB,OAAO,CAAC,SAAS,EAAE,CAAC,CAuBtB;AAmBD;;;;;GAKG;AACH,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oB;CAClC;AAED,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,KAAK,UAAO,EACZ,OAAO,SAAO,EACd,YAAY,SAAM,GACjB,OAAO,CAAC,SAAS,EAAE,CAAC,CAuBtB;AAmBD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAsB,GAAG,IAAI,CAU7E;AAED,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAGhC;AAED,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,QAAQ,EACR,OAAO,EACP,oBAAoB,EACpB,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,SAAS,EACT,QAAQ,GACT,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC"}
package/dist/esm/index.js CHANGED
@@ -81,6 +81,10 @@ export function registerProvider(name, id = MASSA_WINDOW_OBJECT) {
81
81
  }
82
82
  }
83
83
  }
84
+ export async function getProviderByName(providerName) {
85
+ const providersList = await providers();
86
+ return providersList.find((p) => p.name() === providerName);
87
+ }
84
88
  export { Account, } from './account';
85
89
  export { EAccountDeletionResponse, EAccountImportResponse, Provider, } from './provider';
86
90
  export { MassaStationAccount } from './massa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CAAC,aAAa,CAAC,CAAC;SACtC;KACF;AACH,CAAC;AAID,OAAO,EAOL,OAAO,GAIR,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EAMtB,QAAQ,GACT,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nimport { MASSA_WINDOW_OBJECT, connector } from './connector/Connector';\nimport { IProvider } from './provider/IProvider';\nimport { Provider } from './provider/Provider';\nimport {\n MASSA_STATION_PROVIDER_NAME,\n MassaStationProvider,\n} from './massaStation/MassaStationProvider';\nimport { detectBearby } from './bearbyWallet/BearbyConnect';\nimport { BearbyProvider } from './bearbyWallet/BearbyProvider';\nimport { wait } from './utils/time';\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport interface ITransactionDetails {\n operationId: string;\n}\n\n/**\n * Get the list of providers that are available to interact with.\n *\n * @param retry - If true, will retry to get the list of providers if none are available.\n * @param pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.\n * @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.\n *\n * @returns An array of providers.\n */\nexport async function providers(\n retry = true,\n timeout = 3000,\n pollInterval = 500,\n): Promise<IProvider[]> {\n const startTime = Date.now();\n\n await connector.startMassaStationDiscovery();\n\n let bearby: BearbyProvider | undefined;\n if (await detectBearby()) {\n bearby = new BearbyProvider('BEARBY');\n }\n\n while (Date.now() - startTime < timeout) {\n const providerInstances: IProvider[] = getProviderInstances();\n\n if (bearby) providerInstances.push(bearby);\n\n if (!retry || providerInstances.length > 0) {\n return providerInstances;\n }\n\n await wait(pollInterval);\n }\n\n return [];\n}\n\nfunction getProviderInstances() {\n const availableProviders = Object.keys(connector.getWalletProviders());\n\n const providerInstances: IProvider[] = availableProviders.map(\n (providerName) => {\n if (providerName === MASSA_STATION_PROVIDER_NAME) {\n return new MassaStationProvider(\n connector.getProviderInfo(providerName),\n );\n } else {\n return new Provider(providerName);\n }\n },\n );\n return providerInstances;\n}\n\n/**\n * Manually register a provider to interact with.\n *\n * @param name - The name of the provider.\n * @param id - The id of the HTML element that is used to communicate with the provider.\n */\nexport function registerProvider(name: string, id = MASSA_WINDOW_OBJECT): void {\n if (typeof document !== 'undefined') {\n const registerEvent = new CustomEvent('register', {\n detail: { providerName: name },\n });\n const element = document?.getElementById(id);\n if (element) {\n element.dispatchEvent(registerEvent);\n }\n }\n}\n\nexport { AllowedRequests, AllowedResponses } from './connector';\n\nexport {\n IAccountDetails,\n IAccountBalanceRequest,\n IAccountBalanceResponse,\n IAccountSignRequest,\n IAccountSignResponse,\n IAccount,\n Account,\n IAccountRollsRequest,\n IAccountSendTransactionRequest,\n IAccountCallSCRequest,\n} from './account';\n\nexport {\n EAccountDeletionResponse,\n EAccountImportResponse,\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n IAccountImportRequest,\n IAccountImportResponse,\n IProvider,\n Provider,\n} from './provider';\n\nexport { IMassaStationWallet } from './massaStation/MassaStationProvider';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { connectBearby, disconnectBearby } from './bearbyWallet/BearbyConnect';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAShC,6BAA6B;AAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;CACxB;AAED,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,MAAM,CAAN,IAAY,iBAaX;AAbD,WAAY,iBAAiB;IAC3B,2DAAsC,CAAA;IACtC,6DAAwC,CAAA;IACxC,6DAAwC,CAAA;IACxC,4DAAuC,CAAA;IACvC,uDAAkC,CAAA;IAClC,uDAAkC,CAAA;IAClC,iDAA4B,CAAA;IAC5B,wEAAmD,CAAA;IACnD,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IACrC,wEAAmD,CAAA;IACnD,sDAAiC,CAAA;AACnC,CAAC,EAbW,iBAAiB,KAAjB,iBAAiB,QAa5B;AAMD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAK,GAAG,IAAI,EACZ,OAAO,GAAG,IAAI,EACd,YAAY,GAAG,GAAG;IAElB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,MAAM,SAAS,CAA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cAAc,CAAC,EAAE,CAAC,CAAC;QAC7C,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;SACtC;KACF;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,YAAoB;IAEpB,MAAM,aAAa,GAAG,MAAM,SAAS,EAAE,CAAC;IACxC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC,CAAC;AAC9D,CAAC;AAID,OAAO,EAOL,OAAO,GAIR,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EAMtB,QAAQ,GACT,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["/** Polyfills */\nimport { Buffer } from 'buffer';\n\ndeclare global {\n interface Window {\n Buffer: typeof Buffer;\n bearby?: unknown;\n }\n}\n\n// Check if we are on browser\nif (typeof window !== 'undefined') {\n window.Buffer = Buffer;\n}\n\nimport { MASSA_WINDOW_OBJECT, connector } from './connector/Connector';\nimport { IProvider } from './provider/IProvider';\nimport { Provider } from './provider/Provider';\nimport {\n MASSA_STATION_PROVIDER_NAME,\n MassaStationProvider,\n} from './massaStation/MassaStationProvider';\nimport { detectBearby } from './bearbyWallet/BearbyConnect';\nimport { BearbyProvider } from './bearbyWallet/BearbyProvider';\nimport { wait } from './utils/time';\n\nexport enum AvailableCommands {\n ProviderListAccounts = 'LIST_ACCOUNTS',\n ProviderDeleteAccount = 'DELETE_ACCOUNT',\n ProviderImportAccount = 'IMPORT_ACCOUNT',\n ProviderGetNodesUrls = 'GET_NODES_URLS',\n ProviderGetNetwork = 'GET_NETWORK',\n AccountBalance = 'ACCOUNT_BALANCE',\n AccountSign = 'ACCOUNT_SIGN',\n ProviderGenerateNewAccount = 'GENERATE_NEW_ACCOUNT',\n AccountSellRolls = 'ACCOUNT_SELL_ROLLS',\n AccountBuyRolls = 'ACCOUNT_BUY_ROLLS',\n AccountSendTransaction = 'ACCOUNT_SEND_TRANSACTION',\n AccountCallSC = 'ACCOUNT_CALL_SC',\n}\n\nexport interface ITransactionDetails {\n operationId: string;\n}\n\n/**\n * Get the list of providers that are available to interact with.\n *\n * @param retry - If true, will retry to get the list of providers if none are available.\n * @param pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.\n * @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.\n *\n * @returns An array of providers.\n */\nexport async function providers(\n retry = true,\n timeout = 3000,\n pollInterval = 500,\n): Promise<IProvider[]> {\n const startTime = Date.now();\n\n await connector.startMassaStationDiscovery();\n\n let bearby: BearbyProvider | undefined;\n if (await detectBearby()) {\n bearby = new BearbyProvider('BEARBY');\n }\n\n while (Date.now() - startTime < timeout) {\n const providerInstances: IProvider[] = getProviderInstances();\n\n if (bearby) providerInstances.push(bearby);\n\n if (!retry || providerInstances.length > 0) {\n return providerInstances;\n }\n\n await wait(pollInterval);\n }\n\n return [];\n}\n\nfunction getProviderInstances() {\n const availableProviders = Object.keys(connector.getWalletProviders());\n\n const providerInstances: IProvider[] = availableProviders.map(\n (providerName) => {\n if (providerName === MASSA_STATION_PROVIDER_NAME) {\n return new MassaStationProvider(\n connector.getProviderInfo(providerName),\n );\n } else {\n return new Provider(providerName);\n }\n },\n );\n return providerInstances;\n}\n\n/**\n * Manually register a provider to interact with.\n *\n * @param name - The name of the provider.\n * @param id - The id of the HTML element that is used to communicate with the provider.\n */\nexport function registerProvider(name: string, id = MASSA_WINDOW_OBJECT): void {\n if (typeof document !== 'undefined') {\n const registerEvent = new CustomEvent('register', {\n detail: { providerName: name },\n });\n const element = document?.getElementById(id);\n if (element) {\n element.dispatchEvent(registerEvent);\n }\n }\n}\n\nexport async function getProviderByName(\n providerName: string,\n): Promise<IProvider | undefined> {\n const providersList = await providers();\n return providersList.find((p) => p.name() === providerName);\n}\n\nexport { AllowedRequests, AllowedResponses } from './connector';\n\nexport {\n IAccountDetails,\n IAccountBalanceRequest,\n IAccountBalanceResponse,\n IAccountSignRequest,\n IAccountSignResponse,\n IAccount,\n Account,\n IAccountRollsRequest,\n IAccountSendTransactionRequest,\n IAccountCallSCRequest,\n} from './account';\n\nexport {\n EAccountDeletionResponse,\n EAccountImportResponse,\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n IAccountImportRequest,\n IAccountImportResponse,\n IProvider,\n Provider,\n} from './provider';\n\nexport { IMassaStationWallet } from './massaStation/MassaStationProvider';\n\nexport { MassaStationAccount } from './massaStation/MassaStationAccount';\n\nexport { connectBearby, disconnectBearby } from './bearbyWallet/BearbyConnect';\n"]}
@@ -104,6 +104,9 @@ export declare class MassaStationProvider implements IProvider {
104
104
  * @returns a Promise that resolves to the details of the newly generated account.
105
105
  */
106
106
  generateNewAccount(name: string): Promise<IAccountDetails>;
107
+ listenAccountChanges(callback: (address: string) => void): {
108
+ unsubscribe: () => void;
109
+ } | undefined;
107
110
  }
108
111
  export {};
109
112
  //# 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,e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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;IAyBhE,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;CAM3C"}
@@ -220,5 +220,9 @@ export class MassaStationProvider {
220
220
  throw ex;
221
221
  }
222
222
  }
223
+ listenAccountChanges(callback) {
224
+ console.log('The listen Account Change functionality is not yet implemented for the current provider.');
225
+ return undefined;
226
+ }
223
227
  }
224
228
  //# sourceMappingURL=MassaStationProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MassaStationProvider.js","sourceRoot":"","sources":["../../../src/massaStation/MassaStationProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,GAEzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAEL,sBAAsB,GAEvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAEL,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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,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 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"]}
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,o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AK,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;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,GAAG,CACT,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import {\n EAccountDeletionResponse,\n IAccountDeletionResponse,\n} from '../provider/AccountDeletion';\nimport {\n IAccountImportResponse,\n EAccountImportResponse,\n IAccountImportRequest,\n} from '../provider/AccountImport';\nimport { IProvider } from '../provider/IProvider';\nimport {\n JsonRpcResponseData,\n deleteRequest,\n getRequest,\n postRequest,\n putRequest,\n} from './RequestHandler';\nimport { MassaStationAccount } from './MassaStationAccount';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\nimport { PluginInfo } from './types';\n\n/**\n * MassaStation url\n */\nexport const MASSA_STATION_URL = 'https://station.massa/';\n\n/**\n * The MassaStation accounts url\n */\nexport const MASSA_STATION_ACCOUNTS_URL = `${MASSA_STATION_URL}plugin/massa-labs/massa-wallet/api/accounts`;\n\n/**\n * MassaStation's url for importing accounts\n */\nexport const MASSA_STATION_IMPORT_ACCOUNTS_URL = `${MASSA_STATION_ACCOUNTS_URL}/import/`;\n\n/**\n * MassaStation's wallet provider name\n */\nexport const MASSA_STATION_PROVIDER_NAME = 'MASSASTATION';\n\n/**\n * This interface represents the payload returned by making a call to MassaStation's accounts url.\n */\nexport interface IMassaStationWallet {\n address: string;\n nickname: string;\n keyPair: {\n nonce: string;\n privateKey: string;\n publicKey: string;\n salt: string;\n };\n status: MassaStationAccountStatus;\n}\n\nenum MassaStationAccountStatus {\n OK = 'ok',\n CORRUPTED = 'corrupted',\n}\n\n/**\n * This class provides an implementation for communicating with the MassaStation wallet provider.\n * @remarks\n * This class is used as a proxy to the MassaStation server for exchanging message over https calls.\n */\nexport class MassaStationProvider implements IProvider {\n private providerName = MASSA_STATION_PROVIDER_NAME;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(private infos: PluginInfo) {}\n\n /**\n * This method returns the name of the provider.\n * @returns The name of the provider.\n */\n public name(): string {\n return this.providerName;\n }\n\n /**\n * This method sends a message to the MassaStation server to get the list of accounts for the provider.\n * It returns a Promise that resolves to an array of Account instances.\n *\n * @returns A promise that resolves to an array of Account instances.\n */\n public async accounts(): Promise<IAccount[]> {\n let massaStationAccountsResponse: JsonRpcResponseData<\n Array<IMassaStationWallet>\n > = null;\n try {\n massaStationAccountsResponse = await getRequest<\n Array<IMassaStationWallet>\n >(MASSA_STATION_ACCOUNTS_URL);\n } catch (ex) {\n console.error(`MassaStation accounts retrieval error`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return massaStationAccountsResponse.result\n .filter((massaStationAccount) => {\n return massaStationAccount.status === MassaStationAccountStatus.OK;\n })\n .map((massaStationAccount) => {\n return new MassaStationAccount(\n {\n address: massaStationAccount.address,\n name: massaStationAccount.nickname,\n },\n this.providerName,\n );\n });\n }\n\n /**\n * This method makes an http call to the MassaStation server to import an account with\n * the given publicKey and privateKey.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n *\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest: IAccountImportRequest = {\n publicKey,\n privateKey,\n };\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await putRequest<unknown>(\n MASSA_STATION_ACCOUNTS_URL,\n accountImportRequest,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n response: EAccountImportResponse.OK,\n message: 'Account imported successfully',\n } as IAccountImportResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to delete the account associated with the given address.\n *\n * @param address - The address of the account.\n * @returns a Promise that resolves to an instance of IAccountDeletionResponse.\n */\n public async deleteAccount(\n address: string,\n ): Promise<IAccountDeletionResponse> {\n // get all accounts\n let allAccounts: JsonRpcResponseData<Array<IMassaStationWallet>> = null;\n try {\n allAccounts = await getRequest<Array<IMassaStationWallet>>(\n MASSA_STATION_ACCOUNTS_URL,\n );\n } catch (ex) {\n console.log(`MassaStation accounts retrieval error: ${ex}`);\n throw ex;\n }\n if (allAccounts.isError || allAccounts.error) {\n throw allAccounts.error.message;\n }\n // find the account with the desired address\n const accountToDelete = allAccounts.result.find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n\n // delete the account in question\n let massaStationAccountsResponse: JsonRpcResponseData<unknown> = null;\n try {\n massaStationAccountsResponse = await deleteRequest<unknown>(\n `${MASSA_STATION_ACCOUNTS_URL}/${accountToDelete.nickname}`,\n );\n } catch (ex) {\n console.log(`MassaStation accounts deletion error`, ex);\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n console.log(\n `MassaStation accounts deletion error`,\n massaStationAccountsResponse.error.message,\n );\n return {\n response: EAccountDeletionResponse.ERROR,\n } as IAccountDeletionResponse;\n }\n return {\n response: EAccountDeletionResponse.OK,\n } as IAccountDeletionResponse;\n }\n\n /**\n * This method sends an http call to the MassaStation server to obtain node urls.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a list of node urls.\n */\n public async getNodesUrls(): Promise<string[]> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n // transform nodesResponse.result to a json and then get the \"url\" property\n const nodes = nodesResponse.result as { url: string };\n return Array(nodes.url);\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * Returns the name of the network MassaStation is connected to.\n *\n * @throws an error if the call fails.\n *\n * @returns a Promise that resolves to a network.\n */\n public async getNetwork(): Promise<string> {\n let nodesResponse: JsonRpcResponseData<unknown> = null;\n try {\n nodesResponse = await getRequest<unknown>(\n `${MASSA_STATION_URL}massa/node`,\n );\n if (nodesResponse.isError || nodesResponse.error) {\n throw nodesResponse.error.message;\n }\n const nodes = nodesResponse.result as { network: string };\n\n return nodes.network;\n } catch (ex) {\n console.error(`MassaStation nodes retrieval error`, ex);\n throw ex;\n }\n }\n\n /**\n * This method sends an http call to the MassaStation server to create a new random account.\n *\n * @returns a Promise that resolves to the details of the newly generated account.\n */\n public async generateNewAccount(name: string): Promise<IAccountDetails> {\n let massaStationAccountsResponse: JsonRpcResponseData<IMassaStationWallet> =\n null;\n console.log(MASSA_STATION_ACCOUNTS_URL + '/' + name);\n try {\n massaStationAccountsResponse = await postRequest<IMassaStationWallet>(\n MASSA_STATION_ACCOUNTS_URL + '/' + name,\n {},\n );\n if (\n massaStationAccountsResponse.isError ||\n massaStationAccountsResponse.error\n ) {\n throw massaStationAccountsResponse.error.message;\n }\n return {\n address: massaStationAccountsResponse.result.address,\n name: massaStationAccountsResponse.result.nickname,\n } as IAccountDetails;\n } catch (ex) {\n console.error(`Error while generating account: ${ex}`);\n throw ex;\n }\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.log(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
@@ -13,5 +13,8 @@ export interface IProvider {
13
13
  getNodesUrls(): Promise<string[]>;
14
14
  getNetwork(): Promise<string>;
15
15
  generateNewAccount(name: string): Promise<IAccountDetails>;
16
+ listenAccountChanges(callback: (base58: string) => void): {
17
+ unsubscribe: () => void;
18
+ } | undefined;
16
19
  }
17
20
  //# sourceMappingURL=IProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC5D"}
1
+ {"version":3,"file":"IProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,IAAI,MAAM,CAAC;IACf,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3D,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GACnD;QACE,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,GACD,SAAS,CAAC;CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n}\n"]}
1
+ {"version":3,"file":"IProvider.js","sourceRoot":"","sources":["../../../src/provider/IProvider.ts"],"names":[],"mappings":"","sourcesContent":["import { IAccountDeletionResponse } from './AccountDeletion';\nimport { IAccountImportResponse } from './AccountImport';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountDetails } from '../account';\n\n/**\n * This interface represents a general provider definition with its methods\n */\nexport interface IProvider {\n name(): string;\n accounts(): Promise<IAccount[]>;\n importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse>;\n deleteAccount(address: string): Promise<IAccountDeletionResponse>;\n getNodesUrls(): Promise<string[]>;\n getNetwork(): Promise<string>;\n generateNewAccount(name: string): Promise<IAccountDetails>;\n listenAccountChanges(callback: (base58: string) => void):\n | {\n unsubscribe: () => void;\n }\n | undefined;\n}\n"]}
@@ -70,5 +70,8 @@ export declare class Provider implements IProvider {
70
70
  * @returns a Promise that resolves to an instance of IAccountDetails.
71
71
  */
72
72
  generateNewAccount(name?: string): Promise<IAccountDetails>;
73
+ listenAccountChanges(callback: (address: string) => void): {
74
+ unsubscribe: () => void;
75
+ } | undefined;
73
76
  }
74
77
  //# sourceMappingURL=Provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACzB,MAAM,mBAAmB,CAAC;AA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AAW,SAAS;IACxC,OAAO,CAAC,YAAY,CAAS;IAE7B;;;;;OAKG;gBACgB,YAAY,EAAE,MAAM;IAIvC;;;OAGG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;;OAKG;IACU,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IA0B5C;;;;;;;;;;;OAWG;IACU,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,sBAAsB,CAAC;IAkBlC;;;;;OAKG;IACU,aAAa,CACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,wBAAwB,CAAC;IAepC;;;;;;OAMG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAc9C;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAmB1C;;;;;OAKG;IACU,kBAAkB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAejE,oBAAoB,CACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC;QAAE,WAAW,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,SAAS;CAM3C"}
@@ -136,5 +136,9 @@ export class Provider {
136
136
  });
137
137
  });
138
138
  }
139
+ listenAccountChanges(callback) {
140
+ console.error('The listen Account Change functionality is not yet implemented for the current provider.');
141
+ return undefined;
142
+ }
139
143
  }
140
144
  //# sourceMappingURL=Provider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAMvC;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IACX,YAAY,CAAS;IAE7B;;;;;OAKG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AAG,EAAE,EAAE;gBACd,IAAI,GAAG;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;qBACvB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;oBACnC,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,6BAA6B,OAAO,MAAM,UAAU,CAAC,CAChE,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;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,SAAS,CAAC,0BAA0B,CAClC,IAAI,CAAC,YAAY,EACjB,iBAAiB,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","sourcesContent":["import {\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n} from './AccountDeletion';\nimport { IAccountImportRequest, IAccountImportResponse } from './AccountImport';\nimport { connector } from '../connector/Connector';\nimport { Account } from '../account/Account';\nimport { AvailableCommands } from '..';\nimport { IAccountDetails } from '../account/IAccountDetails';\nimport { IProvider } from './IProvider';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountGenerationRequest } from './AccoutGeneration';\n\n/**\n * The Provider class provides a simple and intuitive interface for interacting with a specific\n * wallet service.\n *\n */\nexport class Provider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n /**\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 content script 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 const providersPromise = new Promise<IAccountDetails[]>(\n (resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderListAccounts,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails[]);\n },\n );\n },\n );\n\n const providerAccounts: IAccountDetails[] = await providersPromise;\n\n let accounts: Account[] = [];\n for (const providerAccount of providerAccounts) {\n const accInstance = new Account(providerAccount, this.providerName);\n accounts.push(accInstance);\n }\n\n return accounts;\n }\n\n /**\n * This method sends a message to the content script to import an account with the given publicKey and privateKey.\n *\n * @remarks\n * - The IAccountImportResponse object contains the address of the imported account.\n * - The address is generated from the public key.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n *\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest = {\n publicKey,\n privateKey,\n } as IAccountImportRequest;\n return new Promise<IAccountImportResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderImportAccount,\n accountImportRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountImportResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script 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 const accountDeletionRequest = { address } as IAccountDeletionRequest;\n return new Promise<IAccountDeletionResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderDeleteAccount,\n accountDeletionRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDeletionResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script to get the list of nodes urls\n * used to connect the front end to the Massa network.\n *\n * @returns a Promise that resolves to an array of nodes urls (string).\n *\n */\n public async getNodesUrls(): Promise<string[]> {\n return new Promise<string[]>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNodesUrls,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as string[]);\n },\n );\n });\n }\n\n /**\n * Returns the name of the network the provider is connected to.\n *\n * @returns a Promise that resolves to the network name (string).\n */\n public async getNetwork(): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNetwork,\n {},\n (result, err) => {\n if (err) return reject(err);\n else if (typeof result !== 'string') {\n return reject(\n new Error(`Expected a string but got ${typeof result} instead`),\n );\n }\n return resolve(result);\n },\n );\n });\n }\n\n /**\n * This method generates a new account by a given name and adds it to the wallet.\n *\n * @param name - The account name\n * @returns a Promise that resolves to an instance of IAccountDetails.\n */\n public async generateNewAccount(name?: string): Promise<IAccountDetails> {\n const accountGenerationRequest = { name } as IAccountGenerationRequest;\n return new Promise<IAccountDetails>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGenerateNewAccount,\n accountGenerationRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails);\n },\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/provider/Provider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAMvC;;;;GAIG;AACH,MAAM,OAAO,QA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B,EACpC,EAAE,EACF,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;gBACd,IAAI,GAAG;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;qBACvB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;oBACnC,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,6BAA6B,OAAO,MAAM,UAAU,CAAC,CAChE,CAAC;iBACH;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;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,SAAS,CAAC,0BAA0B,CAClC,IAAI,CAAC,YAAY,EACjB,iBAAiB,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;IAEM,oBAAoB,CACzB,QAAmC;QAEnC,OAAO,CAAC,KAAK,CACX,0FAA0F,CAC3F,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import {\n IAccountDeletionRequest,\n IAccountDeletionResponse,\n} from './AccountDeletion';\nimport { IAccountImportRequest, IAccountImportResponse } from './AccountImport';\nimport { connector } from '../connector/Connector';\nimport { Account } from '../account/Account';\nimport { AvailableCommands } from '..';\nimport { IAccountDetails } from '../account/IAccountDetails';\nimport { IProvider } from './IProvider';\nimport { IAccount } from '../account/IAccount';\nimport { IAccountGenerationRequest } from './AccoutGeneration';\n\n/**\n * The Provider class provides a simple and intuitive interface for interacting with a specific\n * wallet service.\n *\n */\nexport class Provider implements IProvider {\n private providerName: string;\n\n /**\n * Provider constructor\n *\n * @param providerName - The name of the provider.\n * @returns An instance of the Provider class.\n */\n public constructor(providerName: string) {\n this.providerName = providerName;\n }\n\n /**\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 content script 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 const providersPromise = new Promise<IAccountDetails[]>(\n (resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderListAccounts,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails[]);\n },\n );\n },\n );\n\n const providerAccounts: IAccountDetails[] = await providersPromise;\n\n let accounts: Account[] = [];\n for (const providerAccount of providerAccounts) {\n const accInstance = new Account(providerAccount, this.providerName);\n accounts.push(accInstance);\n }\n\n return accounts;\n }\n\n /**\n * This method sends a message to the content script to import an account with the given publicKey and privateKey.\n *\n * @remarks\n * - The IAccountImportResponse object contains the address of the imported account.\n * - The address is generated from the public key.\n *\n * @param publicKey - The public key of the account.\n * @param privateKey - The private key of the account.\n * @returns a Promise that resolves to an instance of IAccountImportResponse.\n *\n */\n public async importAccount(\n publicKey: string,\n privateKey: string,\n ): Promise<IAccountImportResponse> {\n const accountImportRequest = {\n publicKey,\n privateKey,\n } as IAccountImportRequest;\n return new Promise<IAccountImportResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderImportAccount,\n accountImportRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountImportResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script 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 const accountDeletionRequest = { address } as IAccountDeletionRequest;\n return new Promise<IAccountDeletionResponse>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderDeleteAccount,\n accountDeletionRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDeletionResponse);\n },\n );\n });\n }\n\n /**\n * This method sends a message to the content script to get the list of nodes urls\n * used to connect the front end to the Massa network.\n *\n * @returns a Promise that resolves to an array of nodes urls (string).\n *\n */\n public async getNodesUrls(): Promise<string[]> {\n return new Promise<string[]>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNodesUrls,\n {},\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as string[]);\n },\n );\n });\n }\n\n /**\n * Returns the name of the network the provider is connected to.\n *\n * @returns a Promise that resolves to the network name (string).\n */\n public async getNetwork(): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGetNetwork,\n {},\n (result, err) => {\n if (err) return reject(err);\n else if (typeof result !== 'string') {\n return reject(\n new Error(`Expected a string but got ${typeof result} instead`),\n );\n }\n return resolve(result);\n },\n );\n });\n }\n\n /**\n * This method generates a new account by a given name and adds it to the wallet.\n *\n * @param name - The account name\n * @returns a Promise that resolves to an instance of IAccountDetails.\n */\n public async generateNewAccount(name?: string): Promise<IAccountDetails> {\n const accountGenerationRequest = { name } as IAccountGenerationRequest;\n return new Promise<IAccountDetails>((resolve, reject) => {\n connector.sendMessageToContentScript(\n this.providerName,\n AvailableCommands.ProviderGenerateNewAccount,\n accountGenerationRequest,\n (result, err) => {\n if (err) return reject(err);\n return resolve(result as IAccountDetails);\n },\n );\n });\n }\n\n public listenAccountChanges(\n callback: (address: string) => void,\n ): { unsubscribe: () => void } | undefined {\n console.error(\n 'The listen Account Change functionality is not yet implemented for the current provider.',\n );\n return undefined;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massalabs/wallet-provider",
3
- "version": "1.5.2-dev.20240104220542",
3
+ "version": "1.5.2-dev.20240111154114",
4
4
  "description": "massa's wallet provider",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",