@metamask-previews/snap-account-service 0.0.0-preview-8f8f607 → 0.0.0-preview-2b316ced3
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/CHANGELOG.md +0 -8
- package/dist/SnapAccountService.cjs +4 -21
- package/dist/SnapAccountService.cjs.map +1 -1
- package/dist/SnapAccountService.d.cts +6 -32
- package/dist/SnapAccountService.d.cts.map +1 -1
- package/dist/SnapAccountService.d.mts +6 -32
- package/dist/SnapAccountService.d.mts.map +1 -1
- package/dist/SnapAccountService.mjs +4 -21
- package/dist/SnapAccountService.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
- package/dist/SnapAccountService-method-action-types.cjs +0 -7
- package/dist/SnapAccountService-method-action-types.cjs.map +0 -1
- package/dist/SnapAccountService-method-action-types.d.cts +0 -22
- package/dist/SnapAccountService-method-action-types.d.cts.map +0 -1
- package/dist/SnapAccountService-method-action-types.d.mts +0 -22
- package/dist/SnapAccountService-method-action-types.d.mts.map +0 -1
- package/dist/SnapAccountService-method-action-types.mjs +0 -6
- package/dist/SnapAccountService-method-action-types.mjs.map +0 -1
- package/dist/SnapPlatformWatcher.cjs +0 -124
- package/dist/SnapPlatformWatcher.cjs.map +0 -1
- package/dist/SnapPlatformWatcher.d.cts +0 -22
- package/dist/SnapPlatformWatcher.d.cts.map +0 -1
- package/dist/SnapPlatformWatcher.d.mts +0 -22
- package/dist/SnapPlatformWatcher.d.mts.map +0 -1
- package/dist/SnapPlatformWatcher.mjs +0 -121
- package/dist/SnapPlatformWatcher.mjs.map +0 -1
- package/dist/logger.cjs +0 -9
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -6
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -6
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -6
- package/dist/logger.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,17 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
12
|
- Add `SnapAccountService` ([#8414](https://github.com/MetaMask/core/pull/8414))
|
|
13
|
-
- Add `SnapPlatformWatcher`, which waits for the Snap platform to be ready and for a Snap keyring to appear in `KeyringController` state before allowing Snap account operations ([#8715](https://github.com/MetaMask/core/pull/8715))
|
|
14
|
-
- `SnapAccountService.ensureReady` now awaits the watcher, so it only resolves once both conditions hold (or rejects if the Snap keyring does not appear within the configured timeout).
|
|
15
|
-
- Add `config` option to `SnapAccountService` constructor with a `snapPlatformWatcher` field exposing `ensureOnboardingComplete` and `snapKeyringWaitTimeoutMs` ([#8715](https://github.com/MetaMask/core/pull/8715))
|
|
16
|
-
- Export `SnapAccountServiceConfig` and `SnapPlatformWatcherConfig` types.
|
|
17
|
-
- Add `@metamask/keyring-controller` dependency ([#8715](https://github.com/MetaMask/core/pull/8715))
|
|
18
|
-
- The service messenger now requires the `KeyringController:getState` action and `KeyringController:stateChange` event.
|
|
19
13
|
|
|
20
14
|
### Changed
|
|
21
15
|
|
|
22
16
|
- Bump `@metamask/messenger` from `^1.1.1` to `^1.2.0` ([#8632](https://github.com/MetaMask/core/pull/8632))
|
|
23
|
-
- **BREAKING:** Remove the top-level `ensureOnboardingComplete` option from `SnapAccountServiceOptions` ([#8715](https://github.com/MetaMask/core/pull/8715))
|
|
24
|
-
- Pass the callback via `config.snapPlatformWatcher.ensureOnboardingComplete` instead.
|
|
25
17
|
|
|
26
18
|
[Unreleased]: https://github.com/MetaMask/core/
|
|
@@ -10,10 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SnapAccountService_messenger
|
|
13
|
+
var _SnapAccountService_messenger;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SnapAccountService = exports.serviceName = void 0;
|
|
16
|
-
const SnapPlatformWatcher_1 = require("./SnapPlatformWatcher.cjs");
|
|
17
16
|
/**
|
|
18
17
|
* The name of the {@link SnapAccountService}, used to namespace the service's
|
|
19
18
|
* actions and events.
|
|
@@ -23,7 +22,7 @@ exports.serviceName = 'SnapAccountService';
|
|
|
23
22
|
* All of the methods within {@link SnapAccountService} that are exposed via
|
|
24
23
|
* the messenger.
|
|
25
24
|
*/
|
|
26
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
25
|
+
const MESSENGER_EXPOSED_METHODS = [];
|
|
27
26
|
/**
|
|
28
27
|
* Service responsible for managing account management snaps.
|
|
29
28
|
*/
|
|
@@ -33,14 +32,11 @@ class SnapAccountService {
|
|
|
33
32
|
*
|
|
34
33
|
* @param args - The constructor arguments.
|
|
35
34
|
* @param args.messenger - The messenger suited for this service.
|
|
36
|
-
* @param args.config - Optional service configuration.
|
|
37
35
|
*/
|
|
38
|
-
constructor({ messenger
|
|
36
|
+
constructor({ messenger }) {
|
|
39
37
|
_SnapAccountService_messenger.set(this, void 0);
|
|
40
|
-
_SnapAccountService_watcher.set(this, void 0);
|
|
41
38
|
this.name = exports.serviceName;
|
|
42
39
|
__classPrivateFieldSet(this, _SnapAccountService_messenger, messenger, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _SnapAccountService_watcher, new SnapPlatformWatcher_1.SnapPlatformWatcher(messenger, config?.snapPlatformWatcher), "f");
|
|
44
40
|
__classPrivateFieldGet(this, _SnapAccountService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
@@ -49,20 +45,7 @@ class SnapAccountService {
|
|
|
49
45
|
async init() {
|
|
50
46
|
// TODO: Add initialization logic here.
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
54
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
55
|
-
*
|
|
56
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
57
|
-
*
|
|
58
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
59
|
-
*/
|
|
60
|
-
async ensureReady(_snapId) {
|
|
61
|
-
// Lastly, before doing anything with our Snap, we need to make sure the
|
|
62
|
-
// platform is ready to process requests.
|
|
63
|
-
await __classPrivateFieldGet(this, _SnapAccountService_watcher, "f").ensureCanUseSnapPlatform();
|
|
64
|
-
}
|
|
65
48
|
}
|
|
66
49
|
exports.SnapAccountService = SnapAccountService;
|
|
67
|
-
_SnapAccountService_messenger = new WeakMap()
|
|
50
|
+
_SnapAccountService_messenger = new WeakMap();
|
|
68
51
|
//# sourceMappingURL=SnapAccountService.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService.cjs","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SnapAccountService.cjs","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA;;;GAGG;AACU,QAAA,WAAW,GAAG,oBAAoB,CAAC;AAEhD;;;GAGG;AACH,MAAM,yBAAyB,GAAG,EAAW,CAAC;AAgC9C;;GAEG;AACH,MAAa,kBAAkB;IAQ7B;;;;;OAKG;IACH,YAAY,EAAE,SAAS,EAA8C;QAR5D,gDAAwC;QAS/C,IAAI,CAAC,IAAI,GAAG,mBAAW,CAAC;QACxB,uBAAA,IAAI,iCAAc,SAAS,MAAA,CAAC;QAE5B,uBAAA,IAAI,qCAAW,CAAC,4BAA4B,CAC1C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,uCAAuC;IACzC,CAAC;CACF;AA9BD,gDA8BC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The name of the {@link SnapAccountService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'SnapAccountService';\n\n/**\n * All of the methods within {@link SnapAccountService} that are exposed via\n * the messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [] as const;\n\n/**\n * Actions that {@link SnapAccountService} exposes to other consumers.\n */\nexport type SnapAccountServiceActions = never;\n\n/**\n * Actions from other messengers that {@link SnapAccountService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link SnapAccountService} exposes to other consumers.\n */\nexport type SnapAccountServiceEvents = never;\n\n/**\n * Events from other messengers that {@link SnapAccountService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SnapAccountService}.\n */\nexport type SnapAccountServiceMessenger = Messenger<\n typeof serviceName,\n SnapAccountServiceActions | AllowedActions,\n SnapAccountServiceEvents | AllowedEvents\n>;\n\n/**\n * Service responsible for managing account management snaps.\n */\nexport class SnapAccountService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n readonly #messenger: SnapAccountServiceMessenger;\n\n /**\n * Constructs a new {@link SnapAccountService}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n */\n constructor({ messenger }: { messenger: SnapAccountServiceMessenger }) {\n this.name = serviceName;\n this.#messenger = messenger;\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the snap account service.\n */\n async init(): Promise<void> {\n // TODO: Add initialization logic here.\n }\n}\n"]}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type { KeyringControllerGetStateAction, KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
|
|
2
1
|
import type { Messenger } from "@metamask/messenger";
|
|
3
|
-
import type { SnapControllerGetStateAction, SnapControllerStateChangeEvent } from "@metamask/snaps-controllers";
|
|
4
|
-
import { SnapId } from "@metamask/snaps-sdk";
|
|
5
|
-
import type { SnapAccountServiceEnsureReadyAction } from "./SnapAccountService-method-action-types.cjs";
|
|
6
|
-
import type { SnapPlatformWatcherConfig } from "./SnapPlatformWatcher.cjs";
|
|
7
2
|
/**
|
|
8
3
|
* The name of the {@link SnapAccountService}, used to namespace the service's
|
|
9
4
|
* actions and events.
|
|
@@ -12,11 +7,11 @@ export declare const serviceName = "SnapAccountService";
|
|
|
12
7
|
/**
|
|
13
8
|
* Actions that {@link SnapAccountService} exposes to other consumers.
|
|
14
9
|
*/
|
|
15
|
-
export type SnapAccountServiceActions =
|
|
10
|
+
export type SnapAccountServiceActions = never;
|
|
16
11
|
/**
|
|
17
12
|
* Actions from other messengers that {@link SnapAccountService} calls.
|
|
18
13
|
*/
|
|
19
|
-
type AllowedActions =
|
|
14
|
+
type AllowedActions = never;
|
|
20
15
|
/**
|
|
21
16
|
* Events that {@link SnapAccountService} exposes to other consumers.
|
|
22
17
|
*/
|
|
@@ -24,25 +19,12 @@ export type SnapAccountServiceEvents = never;
|
|
|
24
19
|
/**
|
|
25
20
|
* Events from other messengers that {@link SnapAccountService} subscribes to.
|
|
26
21
|
*/
|
|
27
|
-
type AllowedEvents =
|
|
22
|
+
type AllowedEvents = never;
|
|
28
23
|
/**
|
|
29
24
|
* The messenger which is restricted to actions and events accessed by
|
|
30
25
|
* {@link SnapAccountService}.
|
|
31
26
|
*/
|
|
32
27
|
export type SnapAccountServiceMessenger = Messenger<typeof serviceName, SnapAccountServiceActions | AllowedActions, SnapAccountServiceEvents | AllowedEvents>;
|
|
33
|
-
/**
|
|
34
|
-
* Configuration for the {@link SnapAccountService}.
|
|
35
|
-
*/
|
|
36
|
-
export type SnapAccountServiceConfig = {
|
|
37
|
-
snapPlatformWatcher?: SnapPlatformWatcherConfig;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* The options that {@link SnapAccountService} takes.
|
|
41
|
-
*/
|
|
42
|
-
export type SnapAccountServiceOptions = {
|
|
43
|
-
messenger: SnapAccountServiceMessenger;
|
|
44
|
-
config?: SnapAccountServiceConfig;
|
|
45
|
-
};
|
|
46
28
|
/**
|
|
47
29
|
* Service responsible for managing account management snaps.
|
|
48
30
|
*/
|
|
@@ -57,22 +39,14 @@ export declare class SnapAccountService {
|
|
|
57
39
|
*
|
|
58
40
|
* @param args - The constructor arguments.
|
|
59
41
|
* @param args.messenger - The messenger suited for this service.
|
|
60
|
-
* @param args.config - Optional service configuration.
|
|
61
42
|
*/
|
|
62
|
-
constructor({ messenger
|
|
43
|
+
constructor({ messenger }: {
|
|
44
|
+
messenger: SnapAccountServiceMessenger;
|
|
45
|
+
});
|
|
63
46
|
/**
|
|
64
47
|
* Initializes the snap account service.
|
|
65
48
|
*/
|
|
66
49
|
init(): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
69
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
70
|
-
*
|
|
71
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
72
|
-
*
|
|
73
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
74
|
-
*/
|
|
75
|
-
ensureReady(_snapId: SnapId): Promise<void>;
|
|
76
50
|
}
|
|
77
51
|
export {};
|
|
78
52
|
//# sourceMappingURL=SnapAccountService.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService.d.cts","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SnapAccountService.d.cts","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;;GAGG;AACH,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAQhD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE9C;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE7C;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,SAAS,CACjD,OAAO,WAAW,EAClB,yBAAyB,GAAG,cAAc,EAC1C,wBAAwB,GAAG,aAAa,CACzC,CAAC;AAEF;;GAEG;AACH,qBAAa,kBAAkB;;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IAIlC;;;;;OAKG;gBACS,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,2BAA2B,CAAA;KAAE;IAUrE;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import type { KeyringControllerGetStateAction, KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
|
|
2
1
|
import type { Messenger } from "@metamask/messenger";
|
|
3
|
-
import type { SnapControllerGetStateAction, SnapControllerStateChangeEvent } from "@metamask/snaps-controllers";
|
|
4
|
-
import { SnapId } from "@metamask/snaps-sdk";
|
|
5
|
-
import type { SnapAccountServiceEnsureReadyAction } from "./SnapAccountService-method-action-types.mjs";
|
|
6
|
-
import type { SnapPlatformWatcherConfig } from "./SnapPlatformWatcher.mjs";
|
|
7
2
|
/**
|
|
8
3
|
* The name of the {@link SnapAccountService}, used to namespace the service's
|
|
9
4
|
* actions and events.
|
|
@@ -12,11 +7,11 @@ export declare const serviceName = "SnapAccountService";
|
|
|
12
7
|
/**
|
|
13
8
|
* Actions that {@link SnapAccountService} exposes to other consumers.
|
|
14
9
|
*/
|
|
15
|
-
export type SnapAccountServiceActions =
|
|
10
|
+
export type SnapAccountServiceActions = never;
|
|
16
11
|
/**
|
|
17
12
|
* Actions from other messengers that {@link SnapAccountService} calls.
|
|
18
13
|
*/
|
|
19
|
-
type AllowedActions =
|
|
14
|
+
type AllowedActions = never;
|
|
20
15
|
/**
|
|
21
16
|
* Events that {@link SnapAccountService} exposes to other consumers.
|
|
22
17
|
*/
|
|
@@ -24,25 +19,12 @@ export type SnapAccountServiceEvents = never;
|
|
|
24
19
|
/**
|
|
25
20
|
* Events from other messengers that {@link SnapAccountService} subscribes to.
|
|
26
21
|
*/
|
|
27
|
-
type AllowedEvents =
|
|
22
|
+
type AllowedEvents = never;
|
|
28
23
|
/**
|
|
29
24
|
* The messenger which is restricted to actions and events accessed by
|
|
30
25
|
* {@link SnapAccountService}.
|
|
31
26
|
*/
|
|
32
27
|
export type SnapAccountServiceMessenger = Messenger<typeof serviceName, SnapAccountServiceActions | AllowedActions, SnapAccountServiceEvents | AllowedEvents>;
|
|
33
|
-
/**
|
|
34
|
-
* Configuration for the {@link SnapAccountService}.
|
|
35
|
-
*/
|
|
36
|
-
export type SnapAccountServiceConfig = {
|
|
37
|
-
snapPlatformWatcher?: SnapPlatformWatcherConfig;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* The options that {@link SnapAccountService} takes.
|
|
41
|
-
*/
|
|
42
|
-
export type SnapAccountServiceOptions = {
|
|
43
|
-
messenger: SnapAccountServiceMessenger;
|
|
44
|
-
config?: SnapAccountServiceConfig;
|
|
45
|
-
};
|
|
46
28
|
/**
|
|
47
29
|
* Service responsible for managing account management snaps.
|
|
48
30
|
*/
|
|
@@ -57,22 +39,14 @@ export declare class SnapAccountService {
|
|
|
57
39
|
*
|
|
58
40
|
* @param args - The constructor arguments.
|
|
59
41
|
* @param args.messenger - The messenger suited for this service.
|
|
60
|
-
* @param args.config - Optional service configuration.
|
|
61
42
|
*/
|
|
62
|
-
constructor({ messenger
|
|
43
|
+
constructor({ messenger }: {
|
|
44
|
+
messenger: SnapAccountServiceMessenger;
|
|
45
|
+
});
|
|
63
46
|
/**
|
|
64
47
|
* Initializes the snap account service.
|
|
65
48
|
*/
|
|
66
49
|
init(): Promise<void>;
|
|
67
|
-
/**
|
|
68
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
69
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
70
|
-
*
|
|
71
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
72
|
-
*
|
|
73
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
74
|
-
*/
|
|
75
|
-
ensureReady(_snapId: SnapId): Promise<void>;
|
|
76
50
|
}
|
|
77
51
|
export {};
|
|
78
52
|
//# sourceMappingURL=SnapAccountService.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService.d.mts","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"SnapAccountService.d.mts","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD;;;GAGG;AACH,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAQhD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAAC;AAE9C;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE7C;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,SAAS,CACjD,OAAO,WAAW,EAClB,yBAAyB,GAAG,cAAc,EAC1C,wBAAwB,GAAG,aAAa,CACzC,CAAC;AAEF;;GAEG;AACH,qBAAa,kBAAkB;;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IAIlC;;;;;OAKG;gBACS,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,2BAA2B,CAAA;KAAE;IAUrE;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B"}
|
|
@@ -9,8 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _SnapAccountService_messenger
|
|
13
|
-
import { SnapPlatformWatcher } from "./SnapPlatformWatcher.mjs";
|
|
12
|
+
var _SnapAccountService_messenger;
|
|
14
13
|
/**
|
|
15
14
|
* The name of the {@link SnapAccountService}, used to namespace the service's
|
|
16
15
|
* actions and events.
|
|
@@ -20,7 +19,7 @@ export const serviceName = 'SnapAccountService';
|
|
|
20
19
|
* All of the methods within {@link SnapAccountService} that are exposed via
|
|
21
20
|
* the messenger.
|
|
22
21
|
*/
|
|
23
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
22
|
+
const MESSENGER_EXPOSED_METHODS = [];
|
|
24
23
|
/**
|
|
25
24
|
* Service responsible for managing account management snaps.
|
|
26
25
|
*/
|
|
@@ -30,14 +29,11 @@ export class SnapAccountService {
|
|
|
30
29
|
*
|
|
31
30
|
* @param args - The constructor arguments.
|
|
32
31
|
* @param args.messenger - The messenger suited for this service.
|
|
33
|
-
* @param args.config - Optional service configuration.
|
|
34
32
|
*/
|
|
35
|
-
constructor({ messenger
|
|
33
|
+
constructor({ messenger }) {
|
|
36
34
|
_SnapAccountService_messenger.set(this, void 0);
|
|
37
|
-
_SnapAccountService_watcher.set(this, void 0);
|
|
38
35
|
this.name = serviceName;
|
|
39
36
|
__classPrivateFieldSet(this, _SnapAccountService_messenger, messenger, "f");
|
|
40
|
-
__classPrivateFieldSet(this, _SnapAccountService_watcher, new SnapPlatformWatcher(messenger, config?.snapPlatformWatcher), "f");
|
|
41
37
|
__classPrivateFieldGet(this, _SnapAccountService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
@@ -46,19 +42,6 @@ export class SnapAccountService {
|
|
|
46
42
|
async init() {
|
|
47
43
|
// TODO: Add initialization logic here.
|
|
48
44
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
51
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
52
|
-
*
|
|
53
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
54
|
-
*
|
|
55
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
56
|
-
*/
|
|
57
|
-
async ensureReady(_snapId) {
|
|
58
|
-
// Lastly, before doing anything with our Snap, we need to make sure the
|
|
59
|
-
// platform is ready to process requests.
|
|
60
|
-
await __classPrivateFieldGet(this, _SnapAccountService_watcher, "f").ensureCanUseSnapPlatform();
|
|
61
|
-
}
|
|
62
45
|
}
|
|
63
|
-
_SnapAccountService_messenger = new WeakMap()
|
|
46
|
+
_SnapAccountService_messenger = new WeakMap();
|
|
64
47
|
//# sourceMappingURL=SnapAccountService.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService.mjs","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SnapAccountService.mjs","sourceRoot":"","sources":["../src/SnapAccountService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEhD;;;GAGG;AACH,MAAM,yBAAyB,GAAG,EAAW,CAAC;AAgC9C;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAQ7B;;;;;OAKG;IACH,YAAY,EAAE,SAAS,EAA8C;QAR5D,gDAAwC;QAS/C,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,uBAAA,IAAI,iCAAc,SAAS,MAAA,CAAC;QAE5B,uBAAA,IAAI,qCAAW,CAAC,4BAA4B,CAC1C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,uCAAuC;IACzC,CAAC;CACF","sourcesContent":["import type { Messenger } from '@metamask/messenger';\n\n/**\n * The name of the {@link SnapAccountService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'SnapAccountService';\n\n/**\n * All of the methods within {@link SnapAccountService} that are exposed via\n * the messenger.\n */\nconst MESSENGER_EXPOSED_METHODS = [] as const;\n\n/**\n * Actions that {@link SnapAccountService} exposes to other consumers.\n */\nexport type SnapAccountServiceActions = never;\n\n/**\n * Actions from other messengers that {@link SnapAccountService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link SnapAccountService} exposes to other consumers.\n */\nexport type SnapAccountServiceEvents = never;\n\n/**\n * Events from other messengers that {@link SnapAccountService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link SnapAccountService}.\n */\nexport type SnapAccountServiceMessenger = Messenger<\n typeof serviceName,\n SnapAccountServiceActions | AllowedActions,\n SnapAccountServiceEvents | AllowedEvents\n>;\n\n/**\n * Service responsible for managing account management snaps.\n */\nexport class SnapAccountService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n readonly #messenger: SnapAccountServiceMessenger;\n\n /**\n * Constructs a new {@link SnapAccountService}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n */\n constructor({ messenger }: { messenger: SnapAccountServiceMessenger }) {\n this.name = serviceName;\n this.#messenger = messenger;\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the snap account service.\n */\n async init(): Promise<void> {\n // TODO: Add initialization logic here.\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SnapAccountService = void 0;
|
|
4
4
|
var SnapAccountService_1 = require("./SnapAccountService.cjs");
|
|
5
5
|
Object.defineProperty(exports, "SnapAccountService", { enumerable: true, get: function () { return SnapAccountService_1.SnapAccountService; } });
|
|
6
|
-
var SnapPlatformWatcher_1 = require("./SnapPlatformWatcher.cjs");
|
|
7
|
-
Object.defineProperty(exports, "SnapPlatformWatcher", { enumerable: true, get: function () { return SnapPlatformWatcher_1.SnapPlatformWatcher; } });
|
|
8
6
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAAjD,wHAAA,kBAAkB,OAAA
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA0D;AAAjD,wHAAA,kBAAkB,OAAA","sourcesContent":["export { SnapAccountService } from './SnapAccountService';\nexport type {\n SnapAccountServiceActions,\n SnapAccountServiceEvents,\n SnapAccountServiceMessenger,\n} from './SnapAccountService';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { SnapAccountService } from "./SnapAccountService.cjs";
|
|
2
|
-
export type { SnapAccountServiceActions,
|
|
3
|
-
export type { SnapAccountServiceEnsureReadyAction } from "./SnapAccountService-method-action-types.cjs";
|
|
4
|
-
export { SnapPlatformWatcher } from "./SnapPlatformWatcher.cjs";
|
|
5
|
-
export type { SnapPlatformWatcherConfig } from "./SnapPlatformWatcher.cjs";
|
|
2
|
+
export type { SnapAccountServiceActions, SnapAccountServiceEvents, SnapAccountServiceMessenger, } from "./SnapAccountService.cjs";
|
|
6
3
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,GAC5B,iCAA6B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { SnapAccountService } from "./SnapAccountService.mjs";
|
|
2
|
-
export type { SnapAccountServiceActions,
|
|
3
|
-
export type { SnapAccountServiceEnsureReadyAction } from "./SnapAccountService-method-action-types.mjs";
|
|
4
|
-
export { SnapPlatformWatcher } from "./SnapPlatformWatcher.mjs";
|
|
5
|
-
export type { SnapPlatformWatcherConfig } from "./SnapPlatformWatcher.mjs";
|
|
2
|
+
export type { SnapAccountServiceActions, SnapAccountServiceEvents, SnapAccountServiceMessenger, } from "./SnapAccountService.mjs";
|
|
6
3
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,EACxB,2BAA2B,GAC5B,iCAA6B"}
|
package/dist/index.mjs
CHANGED
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iCAA6B","sourcesContent":["export { SnapAccountService } from './SnapAccountService';\nexport type {\n SnapAccountServiceActions,\n SnapAccountServiceEvents,\n SnapAccountServiceMessenger,\n} from './SnapAccountService';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/snap-account-service",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-2b316ced3",
|
|
4
4
|
"description": "Service for Account Management Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -53,12 +53,7 @@
|
|
|
53
53
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@metamask/
|
|
57
|
-
"@metamask/messenger": "^1.2.0",
|
|
58
|
-
"@metamask/snaps-controllers": "^19.0.0",
|
|
59
|
-
"@metamask/snaps-sdk": "^11.0.0",
|
|
60
|
-
"@metamask/utils": "^11.9.0",
|
|
61
|
-
"lodash": "^4.17.21"
|
|
56
|
+
"@metamask/messenger": "^1.2.0"
|
|
62
57
|
},
|
|
63
58
|
"devDependencies": {
|
|
64
59
|
"@metamask/auto-changelog": "^6.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService-method-action-types.cjs","sourceRoot":"","sources":["../src/SnapAccountService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SnapAccountService } from './SnapAccountService';\n\n/**\n * Ensures everything is ready to use Snap accounts for the given Snap.\n * 1. Waits for the Snap platform to be fully started.\n *\n * Safe to call concurrently — each step is idempotent or mutex-protected.\n *\n * @param _snapId - ID of the Snap to ensure readiness for.\n */\nexport type SnapAccountServiceEnsureReadyAction = {\n type: `SnapAccountService:ensureReady`;\n handler: SnapAccountService['ensureReady'];\n};\n\n/**\n * Union of all SnapAccountService action types.\n */\nexport type SnapAccountServiceMethodActions =\n SnapAccountServiceEnsureReadyAction;\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { SnapAccountService } from "./SnapAccountService.cjs";
|
|
6
|
-
/**
|
|
7
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
8
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
9
|
-
*
|
|
10
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
11
|
-
*
|
|
12
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
13
|
-
*/
|
|
14
|
-
export type SnapAccountServiceEnsureReadyAction = {
|
|
15
|
-
type: `SnapAccountService:ensureReady`;
|
|
16
|
-
handler: SnapAccountService['ensureReady'];
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Union of all SnapAccountService action types.
|
|
20
|
-
*/
|
|
21
|
-
export type SnapAccountServiceMethodActions = SnapAccountServiceEnsureReadyAction;
|
|
22
|
-
//# sourceMappingURL=SnapAccountService-method-action-types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService-method-action-types.d.cts","sourceRoot":"","sources":["../src/SnapAccountService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAA6B;AAE/D;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,mCAAmC,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { SnapAccountService } from "./SnapAccountService.mjs";
|
|
6
|
-
/**
|
|
7
|
-
* Ensures everything is ready to use Snap accounts for the given Snap.
|
|
8
|
-
* 1. Waits for the Snap platform to be fully started.
|
|
9
|
-
*
|
|
10
|
-
* Safe to call concurrently — each step is idempotent or mutex-protected.
|
|
11
|
-
*
|
|
12
|
-
* @param _snapId - ID of the Snap to ensure readiness for.
|
|
13
|
-
*/
|
|
14
|
-
export type SnapAccountServiceEnsureReadyAction = {
|
|
15
|
-
type: `SnapAccountService:ensureReady`;
|
|
16
|
-
handler: SnapAccountService['ensureReady'];
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Union of all SnapAccountService action types.
|
|
20
|
-
*/
|
|
21
|
-
export type SnapAccountServiceMethodActions = SnapAccountServiceEnsureReadyAction;
|
|
22
|
-
//# sourceMappingURL=SnapAccountService-method-action-types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService-method-action-types.d.mts","sourceRoot":"","sources":["../src/SnapAccountService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,iCAA6B;AAE/D;;;;;;;GAOG;AACH,MAAM,MAAM,mCAAmC,GAAG;IAChD,IAAI,EAAE,gCAAgC,CAAC;IACvC,OAAO,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACzC,mCAAmC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapAccountService-method-action-types.mjs","sourceRoot":"","sources":["../src/SnapAccountService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SnapAccountService } from './SnapAccountService';\n\n/**\n * Ensures everything is ready to use Snap accounts for the given Snap.\n * 1. Waits for the Snap platform to be fully started.\n *\n * Safe to call concurrently — each step is idempotent or mutex-protected.\n *\n * @param _snapId - ID of the Snap to ensure readiness for.\n */\nexport type SnapAccountServiceEnsureReadyAction = {\n type: `SnapAccountService:ensureReady`;\n handler: SnapAccountService['ensureReady'];\n};\n\n/**\n * Union of all SnapAccountService action types.\n */\nexport type SnapAccountServiceMethodActions =\n SnapAccountServiceEnsureReadyAction;\n"]}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _SnapPlatformWatcher_instances, _SnapPlatformWatcher_messenger, _SnapPlatformWatcher_ensureOnboardingComplete, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, _SnapPlatformWatcher_isReadyOnce, _SnapPlatformWatcher_isReady, _SnapPlatformWatcher_waitForSnapKeyring, _SnapPlatformWatcher_hasSnapKeyring, _SnapPlatformWatcher_waitForSnapKeyringViaStateChange, _SnapPlatformWatcher_watch;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SnapPlatformWatcher = exports.DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = void 0;
|
|
16
|
-
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
17
|
-
const utils_1 = require("@metamask/utils");
|
|
18
|
-
const lodash_1 = require("lodash");
|
|
19
|
-
const logger_1 = require("./logger.cjs");
|
|
20
|
-
/** Default wait for Snap keyring to appear before rejecting (ms). */
|
|
21
|
-
exports.DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5000;
|
|
22
|
-
/** Error message when Snap keyring does not appear within the timeout. */
|
|
23
|
-
const SNAP_KEYRING_TIMEOUT_MESSAGE = 'Snap platform or keyrings still not ready. Aborting.';
|
|
24
|
-
/**
|
|
25
|
-
* Returns true if the given KeyringController state slice contains a Snap keyring.
|
|
26
|
-
*
|
|
27
|
-
* @param state - KeyringController state.
|
|
28
|
-
* @returns True if state.keyrings contains a keyring with type KeyringTypes.snap.
|
|
29
|
-
*/
|
|
30
|
-
function stateHasSnapKeyring(state) {
|
|
31
|
-
return state.keyrings.some((k) => k.type === keyring_controller_1.KeyringTypes.snap);
|
|
32
|
-
}
|
|
33
|
-
class SnapPlatformWatcher {
|
|
34
|
-
constructor(messenger, config = {}) {
|
|
35
|
-
_SnapPlatformWatcher_instances.add(this);
|
|
36
|
-
_SnapPlatformWatcher_messenger.set(this, void 0);
|
|
37
|
-
_SnapPlatformWatcher_ensureOnboardingComplete.set(this, void 0);
|
|
38
|
-
_SnapPlatformWatcher_snapKeyringWaitTimeoutMs.set(this, void 0);
|
|
39
|
-
_SnapPlatformWatcher_isReadyOnce.set(this, void 0);
|
|
40
|
-
_SnapPlatformWatcher_isReady.set(this, void 0);
|
|
41
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_messenger, messenger, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_ensureOnboardingComplete, config.ensureOnboardingComplete, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, config.snapKeyringWaitTimeoutMs ?? exports.DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS, "f");
|
|
44
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, false, "f");
|
|
45
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReadyOnce, (0, utils_1.createDeferredPromise)(), "f");
|
|
46
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_watch).call(this);
|
|
47
|
-
}
|
|
48
|
-
get isReady() {
|
|
49
|
-
return __classPrivateFieldGet(this, _SnapPlatformWatcher_isReady, "f");
|
|
50
|
-
}
|
|
51
|
-
async ensureCanUseSnapPlatform() {
|
|
52
|
-
// When ensureOnboardingComplete is provided, wait for the onboarding first.
|
|
53
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_ensureOnboardingComplete, "f")?.call(this);
|
|
54
|
-
// In all cases, we also require the Snap platform to be ready and available.
|
|
55
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").promise;
|
|
56
|
-
if (!__classPrivateFieldGet(this, _SnapPlatformWatcher_isReady, "f")) {
|
|
57
|
-
throw new Error('Snap platform cannot be used now.');
|
|
58
|
-
}
|
|
59
|
-
// After a restore/reset, the Snap keyring is created lazily by the client (e.g. when
|
|
60
|
-
// getSnapKeyring() is called). Non-EVM account creation needs the keyring to exist, so we
|
|
61
|
-
// wait for it here with a timeout to avoid "Keyring not found" errors.
|
|
62
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_waitForSnapKeyring).call(this);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.SnapPlatformWatcher = SnapPlatformWatcher;
|
|
66
|
-
_SnapPlatformWatcher_messenger = new WeakMap(), _SnapPlatformWatcher_ensureOnboardingComplete = new WeakMap(), _SnapPlatformWatcher_snapKeyringWaitTimeoutMs = new WeakMap(), _SnapPlatformWatcher_isReadyOnce = new WeakMap(), _SnapPlatformWatcher_isReady = new WeakMap(), _SnapPlatformWatcher_instances = new WeakSet(), _SnapPlatformWatcher_waitForSnapKeyring =
|
|
67
|
-
/**
|
|
68
|
-
* Waits for KeyringController to have a Snap keyring available.
|
|
69
|
-
* Checks once, then subscribes to KeyringController:stateChange until the keyring
|
|
70
|
-
* appears or the timeout is reached (then throws).
|
|
71
|
-
*/
|
|
72
|
-
async function _SnapPlatformWatcher_waitForSnapKeyring() {
|
|
73
|
-
if (__classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_hasSnapKeyring).call(this)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_waitForSnapKeyringViaStateChange).call(this);
|
|
77
|
-
}, _SnapPlatformWatcher_hasSnapKeyring = function _SnapPlatformWatcher_hasSnapKeyring() {
|
|
78
|
-
try {
|
|
79
|
-
const state = __classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").call('KeyringController:getState');
|
|
80
|
-
return stateHasSnapKeyring(state);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
(0, logger_1.projectLogger)(`${logger_1.WARNING_PREFIX} KeyringController error while waiting for Snap keyring:`, error);
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
}, _SnapPlatformWatcher_waitForSnapKeyringViaStateChange =
|
|
87
|
-
/**
|
|
88
|
-
* Subscribes to KeyringController:stateChange and resolves when a Snap keyring
|
|
89
|
-
* appears in state, or rejects with an error after the timeout.
|
|
90
|
-
*/
|
|
91
|
-
async function _SnapPlatformWatcher_waitForSnapKeyringViaStateChange() {
|
|
92
|
-
await new Promise((resolve, reject) => {
|
|
93
|
-
const timeoutRef = {
|
|
94
|
-
id: undefined,
|
|
95
|
-
};
|
|
96
|
-
const listener = (keyrings) => {
|
|
97
|
-
if (stateHasSnapKeyring({ keyrings })) {
|
|
98
|
-
clearTimeout(timeoutRef.id);
|
|
99
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").unsubscribe('KeyringController:stateChange', listener);
|
|
100
|
-
resolve();
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
timeoutRef.id = setTimeout(() => {
|
|
104
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").unsubscribe('KeyringController:stateChange', listener);
|
|
105
|
-
reject(new Error(SNAP_KEYRING_TIMEOUT_MESSAGE));
|
|
106
|
-
}, __classPrivateFieldGet(this, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, "f"));
|
|
107
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").subscribe('KeyringController:stateChange', listener, (state) => state.keyrings);
|
|
108
|
-
});
|
|
109
|
-
}, _SnapPlatformWatcher_watch = function _SnapPlatformWatcher_watch() {
|
|
110
|
-
const logReadyOnce = (0, lodash_1.once)(() => (0, logger_1.projectLogger)('Snap platform is ready!'));
|
|
111
|
-
const initialState = __classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").call('SnapController:getState');
|
|
112
|
-
if (initialState.isReady) {
|
|
113
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, true, "f");
|
|
114
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").resolve();
|
|
115
|
-
}
|
|
116
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").subscribe('SnapController:stateChange', (isReady) => {
|
|
117
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, isReady, "f");
|
|
118
|
-
if (isReady) {
|
|
119
|
-
logReadyOnce();
|
|
120
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").resolve();
|
|
121
|
-
}
|
|
122
|
-
}, (state) => state.isReady);
|
|
123
|
-
};
|
|
124
|
-
//# sourceMappingURL=SnapPlatformWatcher.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapPlatformWatcher.cjs","sourceRoot":"","sources":["../src/SnapPlatformWatcher.ts"],"names":[],"mappings":"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","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport { createDeferredPromise, DeferredPromise } from '@metamask/utils';\nimport { once } from 'lodash';\n\nimport { projectLogger as log, WARNING_PREFIX } from './logger';\nimport type { SnapAccountServiceMessenger } from './SnapAccountService';\n\n/** Minimal KeyringController state shape needed to detect Snap keyring. */\ntype KeyringControllerStateSlice = {\n keyrings: { type: string }[];\n};\n\n/** Default wait for Snap keyring to appear before rejecting (ms). */\nexport const DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5_000;\n\n/** Error message when Snap keyring does not appear within the timeout. */\nconst SNAP_KEYRING_TIMEOUT_MESSAGE =\n 'Snap platform or keyrings still not ready. Aborting.';\n\n/**\n * Returns true if the given KeyringController state slice contains a Snap keyring.\n *\n * @param state - KeyringController state.\n * @returns True if state.keyrings contains a keyring with type KeyringTypes.snap.\n */\nfunction stateHasSnapKeyring(state: KeyringControllerStateSlice): boolean {\n return state.keyrings.some((k) => k.type === KeyringTypes.snap);\n}\n\nexport type SnapPlatformWatcherConfig = {\n /**\n * Resolves when onboarding is complete.\n */\n ensureOnboardingComplete?: () => Promise<void>;\n /**\n * How long to wait for the Snap keyring to appear before rejecting (ms).\n *\n * @default DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS\n */\n snapKeyringWaitTimeoutMs?: number;\n};\n\nexport class SnapPlatformWatcher {\n readonly #messenger: SnapAccountServiceMessenger;\n\n readonly #ensureOnboardingComplete?: () => Promise<void>;\n\n readonly #snapKeyringWaitTimeoutMs: number;\n\n readonly #isReadyOnce: DeferredPromise<void>;\n\n #isReady: boolean;\n\n constructor(\n messenger: SnapAccountServiceMessenger,\n config: SnapPlatformWatcherConfig = {},\n ) {\n this.#messenger = messenger;\n this.#ensureOnboardingComplete = config.ensureOnboardingComplete;\n this.#snapKeyringWaitTimeoutMs =\n config.snapKeyringWaitTimeoutMs ?? DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS;\n\n this.#isReady = false;\n this.#isReadyOnce = createDeferredPromise<void>();\n\n this.#watch();\n }\n\n get isReady(): boolean {\n return this.#isReady;\n }\n\n async ensureCanUseSnapPlatform(): Promise<void> {\n // When ensureOnboardingComplete is provided, wait for the onboarding first.\n await this.#ensureOnboardingComplete?.();\n\n // In all cases, we also require the Snap platform to be ready and available.\n await this.#isReadyOnce.promise;\n\n if (!this.#isReady) {\n throw new Error('Snap platform cannot be used now.');\n }\n\n // After a restore/reset, the Snap keyring is created lazily by the client (e.g. when\n // getSnapKeyring() is called). Non-EVM account creation needs the keyring to exist, so we\n // wait for it here with a timeout to avoid \"Keyring not found\" errors.\n await this.#waitForSnapKeyring();\n }\n\n /**\n * Waits for KeyringController to have a Snap keyring available.\n * Checks once, then subscribes to KeyringController:stateChange until the keyring\n * appears or the timeout is reached (then throws).\n */\n async #waitForSnapKeyring(): Promise<void> {\n if (this.#hasSnapKeyring()) {\n return;\n }\n await this.#waitForSnapKeyringViaStateChange();\n }\n\n /**\n * Returns true if KeyringController already has a Snap keyring.\n * Logs and returns false on error.\n *\n * @returns True if a Snap keyring exists, false otherwise or on error.\n */\n #hasSnapKeyring(): boolean {\n try {\n const state = this.#messenger.call(\n 'KeyringController:getState',\n ) as KeyringControllerStateSlice;\n return stateHasSnapKeyring(state);\n } catch (error) {\n log(\n `${WARNING_PREFIX} KeyringController error while waiting for Snap keyring:`,\n error,\n );\n return false;\n }\n }\n\n /**\n * Subscribes to KeyringController:stateChange and resolves when a Snap keyring\n * appears in state, or rejects with an error after the timeout.\n */\n async #waitForSnapKeyringViaStateChange(): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const timeoutRef: { id: ReturnType<typeof setTimeout> | undefined } = {\n id: undefined,\n };\n\n const listener = (\n keyrings: KeyringControllerStateSlice['keyrings'],\n ): void => {\n if (stateHasSnapKeyring({ keyrings })) {\n clearTimeout(timeoutRef.id);\n this.#messenger.unsubscribe(\n 'KeyringController:stateChange',\n listener,\n );\n resolve();\n }\n };\n\n timeoutRef.id = setTimeout(() => {\n this.#messenger.unsubscribe('KeyringController:stateChange', listener);\n reject(new Error(SNAP_KEYRING_TIMEOUT_MESSAGE));\n }, this.#snapKeyringWaitTimeoutMs);\n\n this.#messenger.subscribe(\n 'KeyringController:stateChange',\n listener,\n (state) => state.keyrings,\n );\n });\n }\n\n #watch(): void {\n const logReadyOnce = once(() => log('Snap platform is ready!'));\n\n const initialState = this.#messenger.call('SnapController:getState');\n if (initialState.isReady) {\n this.#isReady = true;\n this.#isReadyOnce.resolve();\n }\n\n this.#messenger.subscribe(\n 'SnapController:stateChange',\n (isReady: boolean) => {\n this.#isReady = isReady;\n\n if (isReady) {\n logReadyOnce();\n this.#isReadyOnce.resolve();\n }\n },\n (state) => state.isReady,\n );\n }\n}\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { SnapAccountServiceMessenger } from "./SnapAccountService.cjs";
|
|
2
|
-
/** Default wait for Snap keyring to appear before rejecting (ms). */
|
|
3
|
-
export declare const DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5000;
|
|
4
|
-
export type SnapPlatformWatcherConfig = {
|
|
5
|
-
/**
|
|
6
|
-
* Resolves when onboarding is complete.
|
|
7
|
-
*/
|
|
8
|
-
ensureOnboardingComplete?: () => Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* How long to wait for the Snap keyring to appear before rejecting (ms).
|
|
11
|
-
*
|
|
12
|
-
* @default DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS
|
|
13
|
-
*/
|
|
14
|
-
snapKeyringWaitTimeoutMs?: number;
|
|
15
|
-
};
|
|
16
|
-
export declare class SnapPlatformWatcher {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(messenger: SnapAccountServiceMessenger, config?: SnapPlatformWatcherConfig);
|
|
19
|
-
get isReady(): boolean;
|
|
20
|
-
ensureCanUseSnapPlatform(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=SnapPlatformWatcher.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapPlatformWatcher.d.cts","sourceRoot":"","sources":["../src/SnapPlatformWatcher.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,2BAA2B,EAAE,iCAA6B;AAOxE,qEAAqE;AACrE,eAAO,MAAM,oCAAoC,OAAQ,CAAC;AAgB1D,MAAM,MAAM,yBAAyB,GAAG;IACtC;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF,qBAAa,mBAAmB;;gBAY5B,SAAS,EAAE,2BAA2B,EACtC,MAAM,GAAE,yBAA8B;IAaxC,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;CA4GhD"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { SnapAccountServiceMessenger } from "./SnapAccountService.mjs";
|
|
2
|
-
/** Default wait for Snap keyring to appear before rejecting (ms). */
|
|
3
|
-
export declare const DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5000;
|
|
4
|
-
export type SnapPlatformWatcherConfig = {
|
|
5
|
-
/**
|
|
6
|
-
* Resolves when onboarding is complete.
|
|
7
|
-
*/
|
|
8
|
-
ensureOnboardingComplete?: () => Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* How long to wait for the Snap keyring to appear before rejecting (ms).
|
|
11
|
-
*
|
|
12
|
-
* @default DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS
|
|
13
|
-
*/
|
|
14
|
-
snapKeyringWaitTimeoutMs?: number;
|
|
15
|
-
};
|
|
16
|
-
export declare class SnapPlatformWatcher {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(messenger: SnapAccountServiceMessenger, config?: SnapPlatformWatcherConfig);
|
|
19
|
-
get isReady(): boolean;
|
|
20
|
-
ensureCanUseSnapPlatform(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=SnapPlatformWatcher.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapPlatformWatcher.d.mts","sourceRoot":"","sources":["../src/SnapPlatformWatcher.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,2BAA2B,EAAE,iCAA6B;AAOxE,qEAAqE;AACrE,eAAO,MAAM,oCAAoC,OAAQ,CAAC;AAgB1D,MAAM,MAAM,yBAAyB,GAAG;IACtC;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF,qBAAa,mBAAmB;;gBAY5B,SAAS,EAAE,2BAA2B,EACtC,MAAM,GAAE,yBAA8B;IAaxC,IAAI,OAAO,IAAI,OAAO,CAErB;IAEK,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;CA4GhD"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _SnapPlatformWatcher_instances, _SnapPlatformWatcher_messenger, _SnapPlatformWatcher_ensureOnboardingComplete, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, _SnapPlatformWatcher_isReadyOnce, _SnapPlatformWatcher_isReady, _SnapPlatformWatcher_waitForSnapKeyring, _SnapPlatformWatcher_hasSnapKeyring, _SnapPlatformWatcher_waitForSnapKeyringViaStateChange, _SnapPlatformWatcher_watch;
|
|
13
|
-
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
14
|
-
import { createDeferredPromise } from "@metamask/utils";
|
|
15
|
-
import $lodash from "lodash";
|
|
16
|
-
const { once } = $lodash;
|
|
17
|
-
import { projectLogger as log, WARNING_PREFIX } from "./logger.mjs";
|
|
18
|
-
/** Default wait for Snap keyring to appear before rejecting (ms). */
|
|
19
|
-
export const DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5000;
|
|
20
|
-
/** Error message when Snap keyring does not appear within the timeout. */
|
|
21
|
-
const SNAP_KEYRING_TIMEOUT_MESSAGE = 'Snap platform or keyrings still not ready. Aborting.';
|
|
22
|
-
/**
|
|
23
|
-
* Returns true if the given KeyringController state slice contains a Snap keyring.
|
|
24
|
-
*
|
|
25
|
-
* @param state - KeyringController state.
|
|
26
|
-
* @returns True if state.keyrings contains a keyring with type KeyringTypes.snap.
|
|
27
|
-
*/
|
|
28
|
-
function stateHasSnapKeyring(state) {
|
|
29
|
-
return state.keyrings.some((k) => k.type === KeyringTypes.snap);
|
|
30
|
-
}
|
|
31
|
-
export class SnapPlatformWatcher {
|
|
32
|
-
constructor(messenger, config = {}) {
|
|
33
|
-
_SnapPlatformWatcher_instances.add(this);
|
|
34
|
-
_SnapPlatformWatcher_messenger.set(this, void 0);
|
|
35
|
-
_SnapPlatformWatcher_ensureOnboardingComplete.set(this, void 0);
|
|
36
|
-
_SnapPlatformWatcher_snapKeyringWaitTimeoutMs.set(this, void 0);
|
|
37
|
-
_SnapPlatformWatcher_isReadyOnce.set(this, void 0);
|
|
38
|
-
_SnapPlatformWatcher_isReady.set(this, void 0);
|
|
39
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_messenger, messenger, "f");
|
|
40
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_ensureOnboardingComplete, config.ensureOnboardingComplete, "f");
|
|
41
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, config.snapKeyringWaitTimeoutMs ?? DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, false, "f");
|
|
43
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReadyOnce, createDeferredPromise(), "f");
|
|
44
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_watch).call(this);
|
|
45
|
-
}
|
|
46
|
-
get isReady() {
|
|
47
|
-
return __classPrivateFieldGet(this, _SnapPlatformWatcher_isReady, "f");
|
|
48
|
-
}
|
|
49
|
-
async ensureCanUseSnapPlatform() {
|
|
50
|
-
// When ensureOnboardingComplete is provided, wait for the onboarding first.
|
|
51
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_ensureOnboardingComplete, "f")?.call(this);
|
|
52
|
-
// In all cases, we also require the Snap platform to be ready and available.
|
|
53
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").promise;
|
|
54
|
-
if (!__classPrivateFieldGet(this, _SnapPlatformWatcher_isReady, "f")) {
|
|
55
|
-
throw new Error('Snap platform cannot be used now.');
|
|
56
|
-
}
|
|
57
|
-
// After a restore/reset, the Snap keyring is created lazily by the client (e.g. when
|
|
58
|
-
// getSnapKeyring() is called). Non-EVM account creation needs the keyring to exist, so we
|
|
59
|
-
// wait for it here with a timeout to avoid "Keyring not found" errors.
|
|
60
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_waitForSnapKeyring).call(this);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
_SnapPlatformWatcher_messenger = new WeakMap(), _SnapPlatformWatcher_ensureOnboardingComplete = new WeakMap(), _SnapPlatformWatcher_snapKeyringWaitTimeoutMs = new WeakMap(), _SnapPlatformWatcher_isReadyOnce = new WeakMap(), _SnapPlatformWatcher_isReady = new WeakMap(), _SnapPlatformWatcher_instances = new WeakSet(), _SnapPlatformWatcher_waitForSnapKeyring =
|
|
64
|
-
/**
|
|
65
|
-
* Waits for KeyringController to have a Snap keyring available.
|
|
66
|
-
* Checks once, then subscribes to KeyringController:stateChange until the keyring
|
|
67
|
-
* appears or the timeout is reached (then throws).
|
|
68
|
-
*/
|
|
69
|
-
async function _SnapPlatformWatcher_waitForSnapKeyring() {
|
|
70
|
-
if (__classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_hasSnapKeyring).call(this)) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
await __classPrivateFieldGet(this, _SnapPlatformWatcher_instances, "m", _SnapPlatformWatcher_waitForSnapKeyringViaStateChange).call(this);
|
|
74
|
-
}, _SnapPlatformWatcher_hasSnapKeyring = function _SnapPlatformWatcher_hasSnapKeyring() {
|
|
75
|
-
try {
|
|
76
|
-
const state = __classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").call('KeyringController:getState');
|
|
77
|
-
return stateHasSnapKeyring(state);
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
log(`${WARNING_PREFIX} KeyringController error while waiting for Snap keyring:`, error);
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}, _SnapPlatformWatcher_waitForSnapKeyringViaStateChange =
|
|
84
|
-
/**
|
|
85
|
-
* Subscribes to KeyringController:stateChange and resolves when a Snap keyring
|
|
86
|
-
* appears in state, or rejects with an error after the timeout.
|
|
87
|
-
*/
|
|
88
|
-
async function _SnapPlatformWatcher_waitForSnapKeyringViaStateChange() {
|
|
89
|
-
await new Promise((resolve, reject) => {
|
|
90
|
-
const timeoutRef = {
|
|
91
|
-
id: undefined,
|
|
92
|
-
};
|
|
93
|
-
const listener = (keyrings) => {
|
|
94
|
-
if (stateHasSnapKeyring({ keyrings })) {
|
|
95
|
-
clearTimeout(timeoutRef.id);
|
|
96
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").unsubscribe('KeyringController:stateChange', listener);
|
|
97
|
-
resolve();
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
timeoutRef.id = setTimeout(() => {
|
|
101
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").unsubscribe('KeyringController:stateChange', listener);
|
|
102
|
-
reject(new Error(SNAP_KEYRING_TIMEOUT_MESSAGE));
|
|
103
|
-
}, __classPrivateFieldGet(this, _SnapPlatformWatcher_snapKeyringWaitTimeoutMs, "f"));
|
|
104
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").subscribe('KeyringController:stateChange', listener, (state) => state.keyrings);
|
|
105
|
-
});
|
|
106
|
-
}, _SnapPlatformWatcher_watch = function _SnapPlatformWatcher_watch() {
|
|
107
|
-
const logReadyOnce = once(() => log('Snap platform is ready!'));
|
|
108
|
-
const initialState = __classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").call('SnapController:getState');
|
|
109
|
-
if (initialState.isReady) {
|
|
110
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, true, "f");
|
|
111
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").resolve();
|
|
112
|
-
}
|
|
113
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_messenger, "f").subscribe('SnapController:stateChange', (isReady) => {
|
|
114
|
-
__classPrivateFieldSet(this, _SnapPlatformWatcher_isReady, isReady, "f");
|
|
115
|
-
if (isReady) {
|
|
116
|
-
logReadyOnce();
|
|
117
|
-
__classPrivateFieldGet(this, _SnapPlatformWatcher_isReadyOnce, "f").resolve();
|
|
118
|
-
}
|
|
119
|
-
}, (state) => state.isReady);
|
|
120
|
-
};
|
|
121
|
-
//# sourceMappingURL=SnapPlatformWatcher.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SnapPlatformWatcher.mjs","sourceRoot":"","sources":["../src/SnapPlatformWatcher.ts"],"names":[],"mappings":"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","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport { createDeferredPromise, DeferredPromise } from '@metamask/utils';\nimport { once } from 'lodash';\n\nimport { projectLogger as log, WARNING_PREFIX } from './logger';\nimport type { SnapAccountServiceMessenger } from './SnapAccountService';\n\n/** Minimal KeyringController state shape needed to detect Snap keyring. */\ntype KeyringControllerStateSlice = {\n keyrings: { type: string }[];\n};\n\n/** Default wait for Snap keyring to appear before rejecting (ms). */\nexport const DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS = 5_000;\n\n/** Error message when Snap keyring does not appear within the timeout. */\nconst SNAP_KEYRING_TIMEOUT_MESSAGE =\n 'Snap platform or keyrings still not ready. Aborting.';\n\n/**\n * Returns true if the given KeyringController state slice contains a Snap keyring.\n *\n * @param state - KeyringController state.\n * @returns True if state.keyrings contains a keyring with type KeyringTypes.snap.\n */\nfunction stateHasSnapKeyring(state: KeyringControllerStateSlice): boolean {\n return state.keyrings.some((k) => k.type === KeyringTypes.snap);\n}\n\nexport type SnapPlatformWatcherConfig = {\n /**\n * Resolves when onboarding is complete.\n */\n ensureOnboardingComplete?: () => Promise<void>;\n /**\n * How long to wait for the Snap keyring to appear before rejecting (ms).\n *\n * @default DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS\n */\n snapKeyringWaitTimeoutMs?: number;\n};\n\nexport class SnapPlatformWatcher {\n readonly #messenger: SnapAccountServiceMessenger;\n\n readonly #ensureOnboardingComplete?: () => Promise<void>;\n\n readonly #snapKeyringWaitTimeoutMs: number;\n\n readonly #isReadyOnce: DeferredPromise<void>;\n\n #isReady: boolean;\n\n constructor(\n messenger: SnapAccountServiceMessenger,\n config: SnapPlatformWatcherConfig = {},\n ) {\n this.#messenger = messenger;\n this.#ensureOnboardingComplete = config.ensureOnboardingComplete;\n this.#snapKeyringWaitTimeoutMs =\n config.snapKeyringWaitTimeoutMs ?? DEFAULT_SNAP_KEYRING_WAIT_TIMEOUT_MS;\n\n this.#isReady = false;\n this.#isReadyOnce = createDeferredPromise<void>();\n\n this.#watch();\n }\n\n get isReady(): boolean {\n return this.#isReady;\n }\n\n async ensureCanUseSnapPlatform(): Promise<void> {\n // When ensureOnboardingComplete is provided, wait for the onboarding first.\n await this.#ensureOnboardingComplete?.();\n\n // In all cases, we also require the Snap platform to be ready and available.\n await this.#isReadyOnce.promise;\n\n if (!this.#isReady) {\n throw new Error('Snap platform cannot be used now.');\n }\n\n // After a restore/reset, the Snap keyring is created lazily by the client (e.g. when\n // getSnapKeyring() is called). Non-EVM account creation needs the keyring to exist, so we\n // wait for it here with a timeout to avoid \"Keyring not found\" errors.\n await this.#waitForSnapKeyring();\n }\n\n /**\n * Waits for KeyringController to have a Snap keyring available.\n * Checks once, then subscribes to KeyringController:stateChange until the keyring\n * appears or the timeout is reached (then throws).\n */\n async #waitForSnapKeyring(): Promise<void> {\n if (this.#hasSnapKeyring()) {\n return;\n }\n await this.#waitForSnapKeyringViaStateChange();\n }\n\n /**\n * Returns true if KeyringController already has a Snap keyring.\n * Logs and returns false on error.\n *\n * @returns True if a Snap keyring exists, false otherwise or on error.\n */\n #hasSnapKeyring(): boolean {\n try {\n const state = this.#messenger.call(\n 'KeyringController:getState',\n ) as KeyringControllerStateSlice;\n return stateHasSnapKeyring(state);\n } catch (error) {\n log(\n `${WARNING_PREFIX} KeyringController error while waiting for Snap keyring:`,\n error,\n );\n return false;\n }\n }\n\n /**\n * Subscribes to KeyringController:stateChange and resolves when a Snap keyring\n * appears in state, or rejects with an error after the timeout.\n */\n async #waitForSnapKeyringViaStateChange(): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n const timeoutRef: { id: ReturnType<typeof setTimeout> | undefined } = {\n id: undefined,\n };\n\n const listener = (\n keyrings: KeyringControllerStateSlice['keyrings'],\n ): void => {\n if (stateHasSnapKeyring({ keyrings })) {\n clearTimeout(timeoutRef.id);\n this.#messenger.unsubscribe(\n 'KeyringController:stateChange',\n listener,\n );\n resolve();\n }\n };\n\n timeoutRef.id = setTimeout(() => {\n this.#messenger.unsubscribe('KeyringController:stateChange', listener);\n reject(new Error(SNAP_KEYRING_TIMEOUT_MESSAGE));\n }, this.#snapKeyringWaitTimeoutMs);\n\n this.#messenger.subscribe(\n 'KeyringController:stateChange',\n listener,\n (state) => state.keyrings,\n );\n });\n }\n\n #watch(): void {\n const logReadyOnce = once(() => log('Snap platform is ready!'));\n\n const initialState = this.#messenger.call('SnapController:getState');\n if (initialState.isReady) {\n this.#isReady = true;\n this.#isReadyOnce.resolve();\n }\n\n this.#messenger.subscribe(\n 'SnapController:stateChange',\n (isReady: boolean) => {\n this.#isReady = isReady;\n\n if (isReady) {\n logReadyOnce();\n this.#isReadyOnce.resolve();\n }\n },\n (state) => state.isReady,\n );\n }\n}\n"]}
|
package/dist/logger.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* istanbul ignore file */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.WARNING_PREFIX = exports.createModuleLogger = exports.projectLogger = void 0;
|
|
5
|
-
const utils_1 = require("@metamask/utils");
|
|
6
|
-
Object.defineProperty(exports, "createModuleLogger", { enumerable: true, get: function () { return utils_1.createModuleLogger; } });
|
|
7
|
-
exports.projectLogger = (0, utils_1.createProjectLogger)('snap-account-service');
|
|
8
|
-
exports.WARNING_PREFIX = 'WARNING --';
|
|
9
|
-
//# sourceMappingURL=logger.cjs.map
|
package/dist/logger.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.cjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;AAE1B,2CAA0E;AAIjE,mGAJqB,0BAAkB,OAIrB;AAFd,QAAA,aAAa,GAAG,IAAA,2BAAmB,EAAC,sBAAsB,CAAC,CAAC;AAI5D,QAAA,cAAc,GAAG,YAAY,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('snap-account-service');\n\nexport { createModuleLogger };\n\nexport const WARNING_PREFIX = 'WARNING --';\n"]}
|
package/dist/logger.d.cts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="debug" />
|
|
2
|
-
import { createModuleLogger } from "@metamask/utils";
|
|
3
|
-
export declare const projectLogger: import("debug").Debugger;
|
|
4
|
-
export { createModuleLogger };
|
|
5
|
-
export declare const WARNING_PREFIX = "WARNING --";
|
|
6
|
-
//# sourceMappingURL=logger.d.cts.map
|
package/dist/logger.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.cts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAA8C,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,cAAc,eAAe,CAAC"}
|
package/dist/logger.d.mts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="debug" />
|
|
2
|
-
import { createModuleLogger } from "@metamask/utils";
|
|
3
|
-
export declare const projectLogger: import("debug").Debugger;
|
|
4
|
-
export { createModuleLogger };
|
|
5
|
-
export declare const WARNING_PREFIX = "WARNING --";
|
|
6
|
-
//# sourceMappingURL=logger.d.mts.map
|
package/dist/logger.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAEA,OAAO,EAAuB,kBAAkB,EAAE,wBAAwB;AAE1E,eAAO,MAAM,aAAa,0BAA8C,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,cAAc,eAAe,CAAC"}
|
package/dist/logger.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { createProjectLogger, createModuleLogger } from "@metamask/utils";
|
|
3
|
-
export const projectLogger = createProjectLogger('snap-account-service');
|
|
4
|
-
export { createModuleLogger };
|
|
5
|
-
export const WARNING_PREFIX = 'WARNING --';
|
|
6
|
-
//# sourceMappingURL=logger.mjs.map
|
package/dist/logger.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,wBAAwB;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('snap-account-service');\n\nexport { createModuleLogger };\n\nexport const WARNING_PREFIX = 'WARNING --';\n"]}
|