@massalabs/wallet-provider 0.0.2-dev.20230710163418 → 0.0.2-dev.20230719135650
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle.js +49 -19
- package/dist/connector/Connector.d.ts +5 -0
- package/dist/connector/Connector.d.ts.map +1 -1
- package/dist/connector/Connector.js +8 -8
- package/dist/connector/index.d.ts +1 -1
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +2 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -11
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -180,7 +180,7 @@ Object.defineProperty(exports, "Account", { enumerable: true, get: function () {
|
|
|
180
180
|
},{"./Account":1}],3:[function(require,module,exports){
|
|
181
181
|
"use strict";
|
|
182
182
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
183
|
-
exports.connector = void 0;
|
|
183
|
+
exports.connector = exports.MASSA_WINDOW_OBJECT = void 0;
|
|
184
184
|
/**
|
|
185
185
|
* This file defines a TypeScript module named connector.
|
|
186
186
|
* It is the tool that allows the 'provider' and 'account' objects to communicate with the web page script.
|
|
@@ -198,7 +198,7 @@ const MassaStationProvider_1 = require("../massaStation/MassaStationProvider");
|
|
|
198
198
|
* A constant string that is used to identify the HTML element that is used for
|
|
199
199
|
* communication between the web page script and the content script.
|
|
200
200
|
*/
|
|
201
|
-
|
|
201
|
+
exports.MASSA_WINDOW_OBJECT = 'massaWalletProvider';
|
|
202
202
|
/**
|
|
203
203
|
* This class enables communication with the content script by sending and receiving messages.
|
|
204
204
|
* @remarks
|
|
@@ -225,7 +225,7 @@ class Connector {
|
|
|
225
225
|
this.register();
|
|
226
226
|
// start listening to messages from content script
|
|
227
227
|
document
|
|
228
|
-
.getElementById(MASSA_WINDOW_OBJECT)
|
|
228
|
+
.getElementById(exports.MASSA_WINDOW_OBJECT)
|
|
229
229
|
.addEventListener('message', this.handleResponseFromContentScript.bind(this));
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
@@ -241,19 +241,19 @@ class Connector {
|
|
|
241
241
|
*/
|
|
242
242
|
register() {
|
|
243
243
|
// global event target to use for all wallet provider
|
|
244
|
-
if (!document.getElementById(MASSA_WINDOW_OBJECT)) {
|
|
244
|
+
if (!document.getElementById(exports.MASSA_WINDOW_OBJECT)) {
|
|
245
245
|
const inv = document.createElement('p');
|
|
246
|
-
inv.id = MASSA_WINDOW_OBJECT;
|
|
246
|
+
inv.id = exports.MASSA_WINDOW_OBJECT;
|
|
247
247
|
inv.setAttribute('style', 'display:none');
|
|
248
248
|
document.body.appendChild(inv);
|
|
249
249
|
}
|
|
250
250
|
// add an invisible HTML element and set a listener to it like the following
|
|
251
251
|
// hook up register handler
|
|
252
252
|
document
|
|
253
|
-
.getElementById(MASSA_WINDOW_OBJECT)
|
|
253
|
+
.getElementById(exports.MASSA_WINDOW_OBJECT)
|
|
254
254
|
.addEventListener('register', (evt) => {
|
|
255
255
|
const payload = evt.detail;
|
|
256
|
-
const providerEventTargetName = `${MASSA_WINDOW_OBJECT}_${payload.providerName}`;
|
|
256
|
+
const providerEventTargetName = `${exports.MASSA_WINDOW_OBJECT}_${payload.providerName}`;
|
|
257
257
|
this.registeredProviders[payload.providerName] =
|
|
258
258
|
providerEventTargetName;
|
|
259
259
|
});
|
|
@@ -261,7 +261,7 @@ class Connector {
|
|
|
261
261
|
this.massaStationListener = new MassaStationDiscovery_1.MassaStationDiscovery(1000);
|
|
262
262
|
this.massaStationListener.startListening();
|
|
263
263
|
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCOVERED, () => {
|
|
264
|
-
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
264
|
+
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${exports.MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
265
265
|
});
|
|
266
266
|
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCONNECTED, () => {
|
|
267
267
|
delete this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME];
|
|
@@ -345,7 +345,7 @@ exports.connector = new Connector();
|
|
|
345
345
|
},{"..":4,"../massaStation/MassaStationDiscovery":6,"../massaStation/MassaStationProvider":7,"uid":50}],4:[function(require,module,exports){
|
|
346
346
|
"use strict";
|
|
347
347
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
348
|
-
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.providers = exports.AvailableCommands = void 0;
|
|
348
|
+
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.registerProvider = exports.providers = exports.AvailableCommands = void 0;
|
|
349
349
|
/** Polyfills */
|
|
350
350
|
const buffer_1 = require("buffer");
|
|
351
351
|
// Check if we are on browser
|
|
@@ -369,21 +369,51 @@ var AvailableCommands;
|
|
|
369
369
|
AvailableCommands["AccountSendTransaction"] = "ACCOUNT_SEND_TRANSACTION";
|
|
370
370
|
AvailableCommands["AccountCallSC"] = "ACCOUNT_CALL_SC";
|
|
371
371
|
})(AvailableCommands = exports.AvailableCommands || (exports.AvailableCommands = {}));
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Get the list of providers that are available to interact with.
|
|
374
|
+
*
|
|
375
|
+
* @param retry - If true, will retry to get the list of providers if none are available.
|
|
376
|
+
* @param timeout - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
377
|
+
*
|
|
378
|
+
* @returns An array of providers.
|
|
379
|
+
*/
|
|
380
|
+
async function providers(retry = true, timeout = 500) {
|
|
381
|
+
let provider = [];
|
|
382
|
+
while (provider.length === 0) {
|
|
383
|
+
for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
|
|
384
|
+
if (providerName === MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME) {
|
|
385
|
+
const p = new MassaStationProvider_1.MassaStationProvider();
|
|
386
|
+
provider.push(p);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
const p = new Provider_1.Provider(providerName);
|
|
390
|
+
provider.push(p);
|
|
391
|
+
}
|
|
378
392
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
393
|
+
// If no providers are available, wait and try again
|
|
394
|
+
if (retry && provider.length === 0) {
|
|
395
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
382
396
|
}
|
|
383
397
|
}
|
|
384
|
-
return
|
|
398
|
+
return provider;
|
|
385
399
|
}
|
|
386
400
|
exports.providers = providers;
|
|
401
|
+
/**
|
|
402
|
+
* Manually register a provider to interact with.
|
|
403
|
+
*
|
|
404
|
+
* @param name - The name of the provider.
|
|
405
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
406
|
+
*/
|
|
407
|
+
function registerProvider(name, id = Connector_1.MASSA_WINDOW_OBJECT) {
|
|
408
|
+
const registerEvent = new CustomEvent('register', {
|
|
409
|
+
detail: { providerName: name },
|
|
410
|
+
});
|
|
411
|
+
const element = document.getElementById(id);
|
|
412
|
+
if (element) {
|
|
413
|
+
element.dispatchEvent(registerEvent);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
exports.registerProvider = registerProvider;
|
|
387
417
|
var account_1 = require("./account");
|
|
388
418
|
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
|
|
389
419
|
var provider_1 = require("./provider");
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AvailableCommands, IAccountBalanceRequest, IAccountBalanceResponse, IAccountDeletionRequest, IAccountDeletionResponse, IAccountImportRequest, IAccountImportResponse, IAccountSignRequest, IAccountSignResponse } from '..';
|
|
2
2
|
import { IAccount } from '../account/IAccount';
|
|
3
|
+
/**
|
|
4
|
+
* A constant string that is used to identify the HTML element that is used for
|
|
5
|
+
* communication between the web page script and the content script.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MASSA_WINDOW_OBJECT = "massaWalletProvider";
|
|
3
8
|
type CallbackFunction = (result: AllowedResponses, error: Error | null) => unknown;
|
|
4
9
|
export type AllowedRequests = object | IAccountBalanceRequest | IAccountSignRequest | IAccountImportRequest | IAccountDeletionRequest;
|
|
5
10
|
export type AllowedResponses = object | IAccountBalanceResponse | IAccountSignResponse | IAccountImportResponse | IAccountDeletionResponse | IAccount[] | string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Connector.d.ts","sourceRoot":"","sources":["../../src/connector/Connector.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,IAAI,CAAC;AAOZ,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"Connector.d.ts","sourceRoot":"","sources":["../../src/connector/Connector.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,IAAI,CAAC;AAOZ,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,KAAK,gBAAgB,GAAG,CACtB,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,KAAK,GAAG,IAAI,KAChB,OAAO,CAAC;AAEb,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,sBAAsB,GACtB,mBAAmB,GACnB,qBAAqB,GACrB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,uBAAuB,GACvB,oBAAoB,GACpB,sBAAsB,GACtB,wBAAwB,GACxB,QAAQ,EAAE,GACV,MAAM,CAAC;AAEX;;;;;;GAMG;AACH,cAAM,SAAS;IACb,OAAO,CAAC,mBAAmB,CAAiC;IAC5D,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,oBAAoB,CAAwB;IAEpD;;;;;;;;;;;OAWG;;IAcH;;;;;;;;;;OAUG;IACH,OAAO,CAAC,QAAQ;IAiChB;;;;;;;;;;;;;;;OAeG;IAEI,0BAA0B,CAC/B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,eAAe,EACvB,gBAAgB,EAAE,gBAAgB;IAgCpC;;;;;OAKG;IACI,kBAAkB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAItD;;;;;;;OAOG;IACH,OAAO,CAAC,+BAA+B;CAuBxC;AAED,eAAO,MAAM,SAAS,WAAkB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.connector = void 0;
|
|
3
|
+
exports.connector = exports.MASSA_WINDOW_OBJECT = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* This file defines a TypeScript module named connector.
|
|
6
6
|
* It is the tool that allows the 'provider' and 'account' objects to communicate with the web page script.
|
|
@@ -18,7 +18,7 @@ const MassaStationProvider_1 = require("../massaStation/MassaStationProvider");
|
|
|
18
18
|
* A constant string that is used to identify the HTML element that is used for
|
|
19
19
|
* communication between the web page script and the content script.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
exports.MASSA_WINDOW_OBJECT = 'massaWalletProvider';
|
|
22
22
|
/**
|
|
23
23
|
* This class enables communication with the content script by sending and receiving messages.
|
|
24
24
|
* @remarks
|
|
@@ -45,7 +45,7 @@ class Connector {
|
|
|
45
45
|
this.register();
|
|
46
46
|
// start listening to messages from content script
|
|
47
47
|
document
|
|
48
|
-
.getElementById(MASSA_WINDOW_OBJECT)
|
|
48
|
+
.getElementById(exports.MASSA_WINDOW_OBJECT)
|
|
49
49
|
.addEventListener('message', this.handleResponseFromContentScript.bind(this));
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -61,19 +61,19 @@ class Connector {
|
|
|
61
61
|
*/
|
|
62
62
|
register() {
|
|
63
63
|
// global event target to use for all wallet provider
|
|
64
|
-
if (!document.getElementById(MASSA_WINDOW_OBJECT)) {
|
|
64
|
+
if (!document.getElementById(exports.MASSA_WINDOW_OBJECT)) {
|
|
65
65
|
const inv = document.createElement('p');
|
|
66
|
-
inv.id = MASSA_WINDOW_OBJECT;
|
|
66
|
+
inv.id = exports.MASSA_WINDOW_OBJECT;
|
|
67
67
|
inv.setAttribute('style', 'display:none');
|
|
68
68
|
document.body.appendChild(inv);
|
|
69
69
|
}
|
|
70
70
|
// add an invisible HTML element and set a listener to it like the following
|
|
71
71
|
// hook up register handler
|
|
72
72
|
document
|
|
73
|
-
.getElementById(MASSA_WINDOW_OBJECT)
|
|
73
|
+
.getElementById(exports.MASSA_WINDOW_OBJECT)
|
|
74
74
|
.addEventListener('register', (evt) => {
|
|
75
75
|
const payload = evt.detail;
|
|
76
|
-
const providerEventTargetName = `${MASSA_WINDOW_OBJECT}_${payload.providerName}`;
|
|
76
|
+
const providerEventTargetName = `${exports.MASSA_WINDOW_OBJECT}_${payload.providerName}`;
|
|
77
77
|
this.registeredProviders[payload.providerName] =
|
|
78
78
|
providerEventTargetName;
|
|
79
79
|
});
|
|
@@ -81,7 +81,7 @@ class Connector {
|
|
|
81
81
|
this.massaStationListener = new MassaStationDiscovery_1.MassaStationDiscovery(1000);
|
|
82
82
|
this.massaStationListener.startListening();
|
|
83
83
|
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCOVERED, () => {
|
|
84
|
-
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
84
|
+
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${exports.MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
85
85
|
});
|
|
86
86
|
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCONNECTED, () => {
|
|
87
87
|
delete this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { connector, AllowedRequests, AllowedResponses } from './Connector';
|
|
1
|
+
export { connector, AllowedRequests, AllowedResponses, MASSA_WINDOW_OBJECT, } from './Connector';
|
|
2
2
|
export { ICustomEventMessageRequest } from './ICustomEventMessageRequest';
|
|
3
3
|
export { ICustomEventMessageResponse } from './ICustomEventMessageResponse';
|
|
4
4
|
export { IRegisterEvent } from './IRegisterEvent';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/connector/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.connector = void 0;
|
|
3
|
+
exports.MASSA_WINDOW_OBJECT = exports.connector = void 0;
|
|
4
4
|
var Connector_1 = require("./Connector");
|
|
5
5
|
Object.defineProperty(exports, "connector", { enumerable: true, get: function () { return Connector_1.connector; } });
|
|
6
|
+
Object.defineProperty(exports, "MASSA_WINDOW_OBJECT", { enumerable: true, get: function () { return Connector_1.MASSA_WINDOW_OBJECT; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,22 @@ export declare enum AvailableCommands {
|
|
|
23
23
|
export interface ITransactionDetails {
|
|
24
24
|
operationId: string;
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Get the list of providers that are available to interact with.
|
|
28
|
+
*
|
|
29
|
+
* @param retry - If true, will retry to get the list of providers if none are available.
|
|
30
|
+
* @param timeout - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
31
|
+
*
|
|
32
|
+
* @returns An array of providers.
|
|
33
|
+
*/
|
|
34
|
+
export declare function providers(retry?: boolean, timeout?: number): Promise<IProvider[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Manually register a provider to interact with.
|
|
37
|
+
*
|
|
38
|
+
* @param name - The name of the provider.
|
|
39
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
40
|
+
*/
|
|
41
|
+
export declare function registerProvider(name: string, id?: string): void;
|
|
27
42
|
export { AllowedRequests, AllowedResponses } from './connector';
|
|
28
43
|
export { IAccountDetails, IAccountBalanceRequest, IAccountBalanceResponse, IAccountSignRequest, IAccountSignResponse, IAccount, Account, IAccountRollsRequest, IAccountSendTransactionRequest, IAccountCallSCRequest, } from './account';
|
|
29
44
|
export { EAccountDeletionResponse, EAccountImportResponse, IAccountDeletionRequest, IAccountDeletionResponse, IAccountImportRequest, IAccountImportResponse, IProvider, Provider, } from './provider';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;KACvB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAOjD,oBAAY,iBAAiB;IAC3B,oBAAoB,kBAAkB;IACtC,qBAAqB,mBAAmB;IACxC,qBAAqB,mBAAmB;IACxC,oBAAoB,mBAAmB;IACvC,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,
|
|
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;KACvB;CACF;AAQD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAOjD,oBAAY,iBAAiB;IAC3B,oBAAoB,kBAAkB;IACtC,qBAAqB,mBAAmB;IACxC,qBAAqB,mBAAmB;IACxC,oBAAoB,mBAAmB;IACvC,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;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,KAAK,UAAO,EACZ,OAAO,SAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC,CAmBtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,SAAsB,GAAG,IAAI,CAQ7E;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"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.providers = exports.AvailableCommands = void 0;
|
|
3
|
+
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = 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
|
|
@@ -24,21 +24,51 @@ var AvailableCommands;
|
|
|
24
24
|
AvailableCommands["AccountSendTransaction"] = "ACCOUNT_SEND_TRANSACTION";
|
|
25
25
|
AvailableCommands["AccountCallSC"] = "ACCOUNT_CALL_SC";
|
|
26
26
|
})(AvailableCommands = exports.AvailableCommands || (exports.AvailableCommands = {}));
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Get the list of providers that are available to interact with.
|
|
29
|
+
*
|
|
30
|
+
* @param retry - If true, will retry to get the list of providers if none are available.
|
|
31
|
+
* @param timeout - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
32
|
+
*
|
|
33
|
+
* @returns An array of providers.
|
|
34
|
+
*/
|
|
35
|
+
async function providers(retry = true, timeout = 500) {
|
|
36
|
+
let provider = [];
|
|
37
|
+
while (provider.length === 0) {
|
|
38
|
+
for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
|
|
39
|
+
if (providerName === MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME) {
|
|
40
|
+
const p = new MassaStationProvider_1.MassaStationProvider();
|
|
41
|
+
provider.push(p);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const p = new Provider_1.Provider(providerName);
|
|
45
|
+
provider.push(p);
|
|
46
|
+
}
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
// If no providers are available, wait and try again
|
|
49
|
+
if (retry && provider.length === 0) {
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, timeout));
|
|
37
51
|
}
|
|
38
52
|
}
|
|
39
|
-
return
|
|
53
|
+
return provider;
|
|
40
54
|
}
|
|
41
55
|
exports.providers = providers;
|
|
56
|
+
/**
|
|
57
|
+
* Manually register a provider to interact with.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The name of the provider.
|
|
60
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
61
|
+
*/
|
|
62
|
+
function registerProvider(name, id = Connector_1.MASSA_WINDOW_OBJECT) {
|
|
63
|
+
const registerEvent = new CustomEvent('register', {
|
|
64
|
+
detail: { providerName: name },
|
|
65
|
+
});
|
|
66
|
+
const element = document.getElementById(id);
|
|
67
|
+
if (element) {
|
|
68
|
+
element.dispatchEvent(registerEvent);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.registerProvider = registerProvider;
|
|
42
72
|
var account_1 = require("./account");
|
|
43
73
|
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
|
|
44
74
|
var provider_1 = require("./provider");
|