@massalabs/wallet-provider 0.0.2-dev.20230710163418 → 0.0.2-dev.20230720090542
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 +67 -27
- package/dist/connector/Connector.d.ts +5 -0
- package/dist/connector/Connector.d.ts.map +1 -1
- package/dist/connector/Connector.js +21 -16
- 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 +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -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,31 +241,36 @@ 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
|
});
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
this.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
260
|
+
try {
|
|
261
|
+
// start MassaStation discovery
|
|
262
|
+
this.massaStationListener = new MassaStationDiscovery_1.MassaStationDiscovery(1000);
|
|
263
|
+
this.massaStationListener.startListening();
|
|
264
|
+
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCOVERED, () => {
|
|
265
|
+
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${exports.MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
266
|
+
});
|
|
267
|
+
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCONNECTED, () => {
|
|
268
|
+
delete this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME];
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
console.log('MassaStation is not detected');
|
|
273
|
+
}
|
|
269
274
|
}
|
|
270
275
|
/**
|
|
271
276
|
* This method sends a message from the webpage script to the content script.
|
|
@@ -345,7 +350,7 @@ exports.connector = new Connector();
|
|
|
345
350
|
},{"..":4,"../massaStation/MassaStationDiscovery":6,"../massaStation/MassaStationProvider":7,"uid":50}],4:[function(require,module,exports){
|
|
346
351
|
"use strict";
|
|
347
352
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
348
|
-
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.providers = exports.AvailableCommands = void 0;
|
|
353
|
+
exports.MassaStationAccount = exports.Provider = exports.EAccountImportResponse = exports.EAccountDeletionResponse = exports.Account = exports.registerProvider = exports.providers = exports.AvailableCommands = void 0;
|
|
349
354
|
/** Polyfills */
|
|
350
355
|
const buffer_1 = require("buffer");
|
|
351
356
|
// Check if we are on browser
|
|
@@ -369,21 +374,56 @@ var AvailableCommands;
|
|
|
369
374
|
AvailableCommands["AccountSendTransaction"] = "ACCOUNT_SEND_TRANSACTION";
|
|
370
375
|
AvailableCommands["AccountCallSC"] = "ACCOUNT_CALL_SC";
|
|
371
376
|
})(AvailableCommands = exports.AvailableCommands || (exports.AvailableCommands = {}));
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
377
|
+
/**
|
|
378
|
+
* Get the list of providers that are available to interact with.
|
|
379
|
+
*
|
|
380
|
+
* @param retry - If true, will retry to get the list of providers if none are available.
|
|
381
|
+
* @param pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
382
|
+
* @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.
|
|
383
|
+
*
|
|
384
|
+
* @returns An array of providers.
|
|
385
|
+
*/
|
|
386
|
+
async function providers(retry = true, pollInterval = 500, timeout = 3000) {
|
|
387
|
+
let provider = [];
|
|
388
|
+
while (provider.length === 0) {
|
|
389
|
+
for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
|
|
390
|
+
if (providerName === MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME) {
|
|
391
|
+
const p = new MassaStationProvider_1.MassaStationProvider();
|
|
392
|
+
provider.push(p);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
const p = new Provider_1.Provider(providerName);
|
|
396
|
+
provider.push(p);
|
|
397
|
+
}
|
|
378
398
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
399
|
+
// If no providers are available, wait and try again
|
|
400
|
+
if (retry && provider.length === 0) {
|
|
401
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
402
|
+
}
|
|
403
|
+
timeout -= pollInterval;
|
|
404
|
+
if (timeout <= 0) {
|
|
405
|
+
break;
|
|
382
406
|
}
|
|
383
407
|
}
|
|
384
|
-
return
|
|
408
|
+
return provider;
|
|
385
409
|
}
|
|
386
410
|
exports.providers = providers;
|
|
411
|
+
/**
|
|
412
|
+
* Manually register a provider to interact with.
|
|
413
|
+
*
|
|
414
|
+
* @param name - The name of the provider.
|
|
415
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
416
|
+
*/
|
|
417
|
+
function registerProvider(name, id = Connector_1.MASSA_WINDOW_OBJECT) {
|
|
418
|
+
const registerEvent = new CustomEvent('register', {
|
|
419
|
+
detail: { providerName: name },
|
|
420
|
+
});
|
|
421
|
+
const element = document.getElementById(id);
|
|
422
|
+
if (element) {
|
|
423
|
+
element.dispatchEvent(registerEvent);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
exports.registerProvider = registerProvider;
|
|
387
427
|
var account_1 = require("./account");
|
|
388
428
|
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
|
|
389
429
|
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;IAoChB;;;;;;;;;;;;;;;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,31 +61,36 @@ 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
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
try {
|
|
81
|
+
// start MassaStation discovery
|
|
82
|
+
this.massaStationListener = new MassaStationDiscovery_1.MassaStationDiscovery(1000);
|
|
83
|
+
this.massaStationListener.startListening();
|
|
84
|
+
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCOVERED, () => {
|
|
85
|
+
this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME] = `${exports.MASSA_WINDOW_OBJECT}_${MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME}`;
|
|
86
|
+
});
|
|
87
|
+
this.massaStationListener.on(MassaStationDiscovery_1.ON_MASSA_STATION_DISCONNECTED, () => {
|
|
88
|
+
delete this.registeredProviders[MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.log('MassaStation is not detected');
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
/**
|
|
91
96
|
* This method sends a message from the webpage script to the content script.
|
|
@@ -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,23 @@ 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 pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
31
|
+
* @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.
|
|
32
|
+
*
|
|
33
|
+
* @returns An array of providers.
|
|
34
|
+
*/
|
|
35
|
+
export declare function providers(retry?: boolean, pollInterval?: number, timeout?: number): Promise<IProvider[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Manually register a provider to interact with.
|
|
38
|
+
*
|
|
39
|
+
* @param name - The name of the provider.
|
|
40
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerProvider(name: string, id?: string): void;
|
|
27
43
|
export { AllowedRequests, AllowedResponses } from './connector';
|
|
28
44
|
export { IAccountDetails, IAccountBalanceRequest, IAccountBalanceResponse, IAccountSignRequest, IAccountSignResponse, IAccount, Account, IAccountRollsRequest, IAccountSendTransactionRequest, IAccountCallSCRequest, } from './account';
|
|
29
45
|
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;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAC7B,KAAK,UAAO,EACZ,YAAY,SAAM,EAClB,OAAO,SAAO,GACb,OAAO,CAAC,SAAS,EAAE,CAAC,CAuBtB;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,56 @@ 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 pollInterval - The timeout in milliseconds to wait between retries. default is 2000ms.
|
|
32
|
+
* @param timeout - The timeout in milliseconds to wait before giving up. default is 3000ms.
|
|
33
|
+
*
|
|
34
|
+
* @returns An array of providers.
|
|
35
|
+
*/
|
|
36
|
+
async function providers(retry = true, pollInterval = 500, timeout = 3000) {
|
|
37
|
+
let provider = [];
|
|
38
|
+
while (provider.length === 0) {
|
|
39
|
+
for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
|
|
40
|
+
if (providerName === MassaStationProvider_1.MASSA_STATION_PROVIDER_NAME) {
|
|
41
|
+
const p = new MassaStationProvider_1.MassaStationProvider();
|
|
42
|
+
provider.push(p);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const p = new Provider_1.Provider(providerName);
|
|
46
|
+
provider.push(p);
|
|
47
|
+
}
|
|
33
48
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
// If no providers are available, wait and try again
|
|
50
|
+
if (retry && provider.length === 0) {
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
52
|
+
}
|
|
53
|
+
timeout -= pollInterval;
|
|
54
|
+
if (timeout <= 0) {
|
|
55
|
+
break;
|
|
37
56
|
}
|
|
38
57
|
}
|
|
39
|
-
return
|
|
58
|
+
return provider;
|
|
40
59
|
}
|
|
41
60
|
exports.providers = providers;
|
|
61
|
+
/**
|
|
62
|
+
* Manually register a provider to interact with.
|
|
63
|
+
*
|
|
64
|
+
* @param name - The name of the provider.
|
|
65
|
+
* @param id - The id of the HTML element that is used to communicate with the provider.
|
|
66
|
+
*/
|
|
67
|
+
function registerProvider(name, id = Connector_1.MASSA_WINDOW_OBJECT) {
|
|
68
|
+
const registerEvent = new CustomEvent('register', {
|
|
69
|
+
detail: { providerName: name },
|
|
70
|
+
});
|
|
71
|
+
const element = document.getElementById(id);
|
|
72
|
+
if (element) {
|
|
73
|
+
element.dispatchEvent(registerEvent);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.registerProvider = registerProvider;
|
|
42
77
|
var account_1 = require("./account");
|
|
43
78
|
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return account_1.Account; } });
|
|
44
79
|
var provider_1 = require("./provider");
|