@metamask-previews/eth-snap-keyring 6.0.0-1c468fa → 6.0.0-388ed88
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/package.json +2 -4
- package/dist/KeyringSnapControllerClient.cjs +0 -104
- package/dist/KeyringSnapControllerClient.cjs.map +0 -1
- package/dist/KeyringSnapControllerClient.d.cts +0 -46
- package/dist/KeyringSnapControllerClient.d.cts.map +0 -1
- package/dist/KeyringSnapControllerClient.d.mts +0 -46
- package/dist/KeyringSnapControllerClient.d.mts.map +0 -1
- package/dist/KeyringSnapControllerClient.mjs +0 -100
- package/dist/KeyringSnapControllerClient.mjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eth-snap-keyring",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-388ed88",
|
|
4
4
|
"description": "Snaps keyring bridge.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,15 +40,13 @@
|
|
|
40
40
|
"@metamask/keyring-api": "11.1.0",
|
|
41
41
|
"@metamask/keyring-internal-api": "0.0.1",
|
|
42
42
|
"@metamask/keyring-snap-internal-client": "0.0.1",
|
|
43
|
-
"@metamask/keyring-snap-sdk": "0.0.1",
|
|
44
43
|
"@metamask/snaps-controllers": "^9.10.0",
|
|
45
44
|
"@metamask/snaps-sdk": "^6.7.0",
|
|
46
45
|
"@metamask/snaps-utils": "^8.3.0",
|
|
47
46
|
"@metamask/superstruct": "^3.1.0",
|
|
48
47
|
"@metamask/utils": "^9.3.0",
|
|
49
48
|
"@types/uuid": "^9.0.8",
|
|
50
|
-
"uuid": "^9.0.1"
|
|
51
|
-
"webextension-polyfill": "^0.12.0"
|
|
49
|
+
"uuid": "^9.0.1"
|
|
52
50
|
},
|
|
53
51
|
"devDependencies": {
|
|
54
52
|
"@lavamoat/allow-scripts": "^3.2.1",
|
|
@@ -1,104 +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 _SnapControllerSender_snapId, _SnapControllerSender_origin, _SnapControllerSender_controller, _SnapControllerSender_handler, _KeyringSnapControllerClient_controller;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.KeyringSnapControllerClient = void 0;
|
|
16
|
-
const keyring_snap_client_1 = require("@metamask/keyring-snap-client");
|
|
17
|
-
/**
|
|
18
|
-
* Implementation of the `Sender` interface that can be used to send requests
|
|
19
|
-
* to a snap through a `SnapController`.
|
|
20
|
-
*/
|
|
21
|
-
class SnapControllerSender {
|
|
22
|
-
/**
|
|
23
|
-
* Create a new instance of `SnapControllerSender`.
|
|
24
|
-
*
|
|
25
|
-
* @param controller - The `SnapController` instance to send requests to.
|
|
26
|
-
* @param snapId - The ID of the snap to use.
|
|
27
|
-
* @param origin - The sender's origin.
|
|
28
|
-
* @param handler - The handler type.
|
|
29
|
-
*/
|
|
30
|
-
constructor(controller, snapId, origin, handler) {
|
|
31
|
-
_SnapControllerSender_snapId.set(this, void 0);
|
|
32
|
-
_SnapControllerSender_origin.set(this, void 0);
|
|
33
|
-
_SnapControllerSender_controller.set(this, void 0);
|
|
34
|
-
_SnapControllerSender_handler.set(this, void 0);
|
|
35
|
-
__classPrivateFieldSet(this, _SnapControllerSender_controller, controller, "f");
|
|
36
|
-
__classPrivateFieldSet(this, _SnapControllerSender_snapId, snapId, "f");
|
|
37
|
-
__classPrivateFieldSet(this, _SnapControllerSender_origin, origin, "f");
|
|
38
|
-
__classPrivateFieldSet(this, _SnapControllerSender_handler, handler, "f");
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Send a request to the snap and return the response.
|
|
42
|
-
*
|
|
43
|
-
* @param request - JSON-RPC request to send to the snap.
|
|
44
|
-
* @returns A promise that resolves to the response of the request.
|
|
45
|
-
*/
|
|
46
|
-
async send(request) {
|
|
47
|
-
return __classPrivateFieldGet(this, _SnapControllerSender_controller, "f").handleRequest({
|
|
48
|
-
snapId: __classPrivateFieldGet(this, _SnapControllerSender_snapId, "f"),
|
|
49
|
-
origin: __classPrivateFieldGet(this, _SnapControllerSender_origin, "f"),
|
|
50
|
-
handler: __classPrivateFieldGet(this, _SnapControllerSender_handler, "f"),
|
|
51
|
-
request,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
_SnapControllerSender_snapId = new WeakMap(), _SnapControllerSender_origin = new WeakMap(), _SnapControllerSender_controller = new WeakMap(), _SnapControllerSender_handler = new WeakMap();
|
|
56
|
-
/**
|
|
57
|
-
* A `KeyringClient` that allows the communication with a snap through the
|
|
58
|
-
* `SnapController`.
|
|
59
|
-
*/
|
|
60
|
-
class KeyringSnapControllerClient extends keyring_snap_client_1.KeyringClient {
|
|
61
|
-
/**
|
|
62
|
-
* Create a new instance of `KeyringSnapControllerClient`.
|
|
63
|
-
*
|
|
64
|
-
* The `handlerType` argument has a hard-coded default `string` value instead
|
|
65
|
-
* of a `HandlerType` value to prevent the `@metamask/snaps-utils` module
|
|
66
|
-
* from being required at runtime.
|
|
67
|
-
*
|
|
68
|
-
* @param args - Constructor arguments.
|
|
69
|
-
* @param args.controller - The `SnapController` instance to use.
|
|
70
|
-
* @param args.snapId - The ID of the snap to use (default: `'undefined'`).
|
|
71
|
-
* @param args.origin - The sender's origin (default: `'metamask'`).
|
|
72
|
-
* @param args.handler - The handler type (default: `'onKeyringRequest'`).
|
|
73
|
-
*/
|
|
74
|
-
constructor({ controller, snapId = 'undefined', origin = 'metamask', handler = 'onKeyringRequest', }) {
|
|
75
|
-
super(new SnapControllerSender(controller, snapId, origin, handler));
|
|
76
|
-
_KeyringSnapControllerClient_controller.set(this, void 0);
|
|
77
|
-
__classPrivateFieldSet(this, _KeyringSnapControllerClient_controller, controller, "f");
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Create a new instance of `KeyringSnapControllerClient` with the specified
|
|
81
|
-
* `snapId`.
|
|
82
|
-
*
|
|
83
|
-
* @param snapId - The ID of the snap to use in the new instance.
|
|
84
|
-
* @returns A new instance of `KeyringSnapControllerClient` with the
|
|
85
|
-
* specified snap ID.
|
|
86
|
-
*/
|
|
87
|
-
withSnapId(snapId) {
|
|
88
|
-
return new KeyringSnapControllerClient({
|
|
89
|
-
controller: __classPrivateFieldGet(this, _KeyringSnapControllerClient_controller, "f"),
|
|
90
|
-
snapId,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get the `SnapController` instance used by this client.
|
|
95
|
-
*
|
|
96
|
-
* @returns The `SnapController` instance used by this client.
|
|
97
|
-
*/
|
|
98
|
-
getController() {
|
|
99
|
-
return __classPrivateFieldGet(this, _KeyringSnapControllerClient_controller, "f");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.KeyringSnapControllerClient = KeyringSnapControllerClient;
|
|
103
|
-
_KeyringSnapControllerClient_controller = new WeakMap();
|
|
104
|
-
//# sourceMappingURL=KeyringSnapControllerClient.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringSnapControllerClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA2E;AAO3E;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBb,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgB7B,uBAAA,IAAI,oCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,wCAAY,CAAC,aAAa,CAAC;YACpC,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,OAAO,EAAE,uBAAA,IAAI,qCAAS;YACtB,OAAO;SACR,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,mCAAa;IAG5D;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,EACV,MAAM,GAAG,WAAqB,EAC9B,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,kBAAiC,GAM5C;QACC,KAAK,CAAC,IAAI,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QA1B9D,0DAA4B;QA2BnC,uBAAA,IAAI,2CAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,uBAAA,IAAI,+CAAY;YAC5B,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,uBAAA,IAAI,+CAAY,CAAC;IAC1B,CAAC;CACF;AAtDD,kEAsDC","sourcesContent":["import { KeyringClient, type Sender } from '@metamask/keyring-snap-client';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
2
|
-
import type { SnapController } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { SnapId } from "@metamask/snaps-sdk";
|
|
4
|
-
import type { HandlerType } from "@metamask/snaps-utils";
|
|
5
|
-
/**
|
|
6
|
-
* A `KeyringClient` that allows the communication with a snap through the
|
|
7
|
-
* `SnapController`.
|
|
8
|
-
*/
|
|
9
|
-
export declare class KeyringSnapControllerClient extends KeyringClient {
|
|
10
|
-
#private;
|
|
11
|
-
/**
|
|
12
|
-
* Create a new instance of `KeyringSnapControllerClient`.
|
|
13
|
-
*
|
|
14
|
-
* The `handlerType` argument has a hard-coded default `string` value instead
|
|
15
|
-
* of a `HandlerType` value to prevent the `@metamask/snaps-utils` module
|
|
16
|
-
* from being required at runtime.
|
|
17
|
-
*
|
|
18
|
-
* @param args - Constructor arguments.
|
|
19
|
-
* @param args.controller - The `SnapController` instance to use.
|
|
20
|
-
* @param args.snapId - The ID of the snap to use (default: `'undefined'`).
|
|
21
|
-
* @param args.origin - The sender's origin (default: `'metamask'`).
|
|
22
|
-
* @param args.handler - The handler type (default: `'onKeyringRequest'`).
|
|
23
|
-
*/
|
|
24
|
-
constructor({ controller, snapId, origin, handler, }: {
|
|
25
|
-
controller: SnapController;
|
|
26
|
-
snapId?: SnapId;
|
|
27
|
-
origin?: string;
|
|
28
|
-
handler?: HandlerType;
|
|
29
|
-
});
|
|
30
|
-
/**
|
|
31
|
-
* Create a new instance of `KeyringSnapControllerClient` with the specified
|
|
32
|
-
* `snapId`.
|
|
33
|
-
*
|
|
34
|
-
* @param snapId - The ID of the snap to use in the new instance.
|
|
35
|
-
* @returns A new instance of `KeyringSnapControllerClient` with the
|
|
36
|
-
* specified snap ID.
|
|
37
|
-
*/
|
|
38
|
-
withSnapId(snapId: SnapId): KeyringSnapControllerClient;
|
|
39
|
-
/**
|
|
40
|
-
* Get the `SnapController` instance used by this client.
|
|
41
|
-
*
|
|
42
|
-
* @returns The `SnapController` instance used by this client.
|
|
43
|
-
*/
|
|
44
|
-
getController(): SnapController;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=KeyringSnapControllerClient.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringSnapControllerClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
2
|
-
import type { SnapController } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { SnapId } from "@metamask/snaps-sdk";
|
|
4
|
-
import type { HandlerType } from "@metamask/snaps-utils";
|
|
5
|
-
/**
|
|
6
|
-
* A `KeyringClient` that allows the communication with a snap through the
|
|
7
|
-
* `SnapController`.
|
|
8
|
-
*/
|
|
9
|
-
export declare class KeyringSnapControllerClient extends KeyringClient {
|
|
10
|
-
#private;
|
|
11
|
-
/**
|
|
12
|
-
* Create a new instance of `KeyringSnapControllerClient`.
|
|
13
|
-
*
|
|
14
|
-
* The `handlerType` argument has a hard-coded default `string` value instead
|
|
15
|
-
* of a `HandlerType` value to prevent the `@metamask/snaps-utils` module
|
|
16
|
-
* from being required at runtime.
|
|
17
|
-
*
|
|
18
|
-
* @param args - Constructor arguments.
|
|
19
|
-
* @param args.controller - The `SnapController` instance to use.
|
|
20
|
-
* @param args.snapId - The ID of the snap to use (default: `'undefined'`).
|
|
21
|
-
* @param args.origin - The sender's origin (default: `'metamask'`).
|
|
22
|
-
* @param args.handler - The handler type (default: `'onKeyringRequest'`).
|
|
23
|
-
*/
|
|
24
|
-
constructor({ controller, snapId, origin, handler, }: {
|
|
25
|
-
controller: SnapController;
|
|
26
|
-
snapId?: SnapId;
|
|
27
|
-
origin?: string;
|
|
28
|
-
handler?: HandlerType;
|
|
29
|
-
});
|
|
30
|
-
/**
|
|
31
|
-
* Create a new instance of `KeyringSnapControllerClient` with the specified
|
|
32
|
-
* `snapId`.
|
|
33
|
-
*
|
|
34
|
-
* @param snapId - The ID of the snap to use in the new instance.
|
|
35
|
-
* @returns A new instance of `KeyringSnapControllerClient` with the
|
|
36
|
-
* specified snap ID.
|
|
37
|
-
*/
|
|
38
|
-
withSnapId(snapId: SnapId): KeyringSnapControllerClient;
|
|
39
|
-
/**
|
|
40
|
-
* Get the `SnapController` instance used by this client.
|
|
41
|
-
*
|
|
42
|
-
* @returns The `SnapController` instance used by this client.
|
|
43
|
-
*/
|
|
44
|
-
getController(): SnapController;
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=KeyringSnapControllerClient.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringSnapControllerClient.d.mts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
|
|
@@ -1,100 +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 _SnapControllerSender_snapId, _SnapControllerSender_origin, _SnapControllerSender_controller, _SnapControllerSender_handler, _KeyringSnapControllerClient_controller;
|
|
13
|
-
import { KeyringClient } from "@metamask/keyring-snap-client";
|
|
14
|
-
/**
|
|
15
|
-
* Implementation of the `Sender` interface that can be used to send requests
|
|
16
|
-
* to a snap through a `SnapController`.
|
|
17
|
-
*/
|
|
18
|
-
class SnapControllerSender {
|
|
19
|
-
/**
|
|
20
|
-
* Create a new instance of `SnapControllerSender`.
|
|
21
|
-
*
|
|
22
|
-
* @param controller - The `SnapController` instance to send requests to.
|
|
23
|
-
* @param snapId - The ID of the snap to use.
|
|
24
|
-
* @param origin - The sender's origin.
|
|
25
|
-
* @param handler - The handler type.
|
|
26
|
-
*/
|
|
27
|
-
constructor(controller, snapId, origin, handler) {
|
|
28
|
-
_SnapControllerSender_snapId.set(this, void 0);
|
|
29
|
-
_SnapControllerSender_origin.set(this, void 0);
|
|
30
|
-
_SnapControllerSender_controller.set(this, void 0);
|
|
31
|
-
_SnapControllerSender_handler.set(this, void 0);
|
|
32
|
-
__classPrivateFieldSet(this, _SnapControllerSender_controller, controller, "f");
|
|
33
|
-
__classPrivateFieldSet(this, _SnapControllerSender_snapId, snapId, "f");
|
|
34
|
-
__classPrivateFieldSet(this, _SnapControllerSender_origin, origin, "f");
|
|
35
|
-
__classPrivateFieldSet(this, _SnapControllerSender_handler, handler, "f");
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Send a request to the snap and return the response.
|
|
39
|
-
*
|
|
40
|
-
* @param request - JSON-RPC request to send to the snap.
|
|
41
|
-
* @returns A promise that resolves to the response of the request.
|
|
42
|
-
*/
|
|
43
|
-
async send(request) {
|
|
44
|
-
return __classPrivateFieldGet(this, _SnapControllerSender_controller, "f").handleRequest({
|
|
45
|
-
snapId: __classPrivateFieldGet(this, _SnapControllerSender_snapId, "f"),
|
|
46
|
-
origin: __classPrivateFieldGet(this, _SnapControllerSender_origin, "f"),
|
|
47
|
-
handler: __classPrivateFieldGet(this, _SnapControllerSender_handler, "f"),
|
|
48
|
-
request,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
_SnapControllerSender_snapId = new WeakMap(), _SnapControllerSender_origin = new WeakMap(), _SnapControllerSender_controller = new WeakMap(), _SnapControllerSender_handler = new WeakMap();
|
|
53
|
-
/**
|
|
54
|
-
* A `KeyringClient` that allows the communication with a snap through the
|
|
55
|
-
* `SnapController`.
|
|
56
|
-
*/
|
|
57
|
-
export class KeyringSnapControllerClient extends KeyringClient {
|
|
58
|
-
/**
|
|
59
|
-
* Create a new instance of `KeyringSnapControllerClient`.
|
|
60
|
-
*
|
|
61
|
-
* The `handlerType` argument has a hard-coded default `string` value instead
|
|
62
|
-
* of a `HandlerType` value to prevent the `@metamask/snaps-utils` module
|
|
63
|
-
* from being required at runtime.
|
|
64
|
-
*
|
|
65
|
-
* @param args - Constructor arguments.
|
|
66
|
-
* @param args.controller - The `SnapController` instance to use.
|
|
67
|
-
* @param args.snapId - The ID of the snap to use (default: `'undefined'`).
|
|
68
|
-
* @param args.origin - The sender's origin (default: `'metamask'`).
|
|
69
|
-
* @param args.handler - The handler type (default: `'onKeyringRequest'`).
|
|
70
|
-
*/
|
|
71
|
-
constructor({ controller, snapId = 'undefined', origin = 'metamask', handler = 'onKeyringRequest', }) {
|
|
72
|
-
super(new SnapControllerSender(controller, snapId, origin, handler));
|
|
73
|
-
_KeyringSnapControllerClient_controller.set(this, void 0);
|
|
74
|
-
__classPrivateFieldSet(this, _KeyringSnapControllerClient_controller, controller, "f");
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Create a new instance of `KeyringSnapControllerClient` with the specified
|
|
78
|
-
* `snapId`.
|
|
79
|
-
*
|
|
80
|
-
* @param snapId - The ID of the snap to use in the new instance.
|
|
81
|
-
* @returns A new instance of `KeyringSnapControllerClient` with the
|
|
82
|
-
* specified snap ID.
|
|
83
|
-
*/
|
|
84
|
-
withSnapId(snapId) {
|
|
85
|
-
return new KeyringSnapControllerClient({
|
|
86
|
-
controller: __classPrivateFieldGet(this, _KeyringSnapControllerClient_controller, "f"),
|
|
87
|
-
snapId,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Get the `SnapController` instance used by this client.
|
|
92
|
-
*
|
|
93
|
-
* @returns The `SnapController` instance used by this client.
|
|
94
|
-
*/
|
|
95
|
-
getController() {
|
|
96
|
-
return __classPrivateFieldGet(this, _KeyringSnapControllerClient_controller, "f");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
_KeyringSnapControllerClient_controller = new WeakMap();
|
|
100
|
-
//# sourceMappingURL=KeyringSnapControllerClient.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KeyringSnapControllerClient.mjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAO3E;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBb,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgB7B,uBAAA,IAAI,oCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,wCAAY,CAAC,aAAa,CAAC;YACpC,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,OAAO,EAAE,uBAAA,IAAI,qCAAS;YACtB,OAAO;SACR,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,aAAa;IAG5D;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,EACV,MAAM,GAAG,WAAqB,EAC9B,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,kBAAiC,GAM5C;QACC,KAAK,CAAC,IAAI,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QA1B9D,0DAA4B;QA2BnC,uBAAA,IAAI,2CAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,uBAAA,IAAI,+CAAY;YAC5B,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,uBAAA,IAAI,+CAAY,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { KeyringClient, type Sender } from '@metamask/keyring-snap-client';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
|