@metamask-previews/keyring-internal-snap-client 1.0.0-4685a87
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 +19 -0
- package/README.md +15 -0
- package/dist/KeyringSnapControllerClient.cjs +104 -0
- package/dist/KeyringSnapControllerClient.cjs.map +1 -0
- package/dist/KeyringSnapControllerClient.d.cts +46 -0
- package/dist/KeyringSnapControllerClient.d.cts.map +1 -0
- package/dist/KeyringSnapControllerClient.d.mts +46 -0
- package/dist/KeyringSnapControllerClient.d.mts.map +1 -0
- package/dist/KeyringSnapControllerClient.mjs +100 -0
- package/dist/KeyringSnapControllerClient.mjs.map +1 -0
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +95 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Use `ts-bridge/cli@0.6.1` ([#118](https://github.com/MetaMask/accounts/pull/118))
|
|
15
|
+
- This new version fixes a bug with CJS re-exports.
|
|
16
|
+
- Initial release ([#24](https://github.com/MetaMask/accounts/pull/24))
|
|
17
|
+
|
|
18
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-internal-snap-client@1.0.0...HEAD
|
|
19
|
+
[1.0.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/keyring-internal-snap-client@1.0.0
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# MetaMask Keyring Snap Clients
|
|
2
|
+
|
|
3
|
+
Clients that can be used to communicate with a Snap Account using various providers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
`yarn add @metamask/keyring-internal-snap-client`
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
`npm install @metamask/keyring-internal-snap-client`
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/accounts#readme).
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringSnapControllerClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA2E;AAO3E;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAA0B,EAC1B,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-utils';\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: SnapController,\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"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,UAA0B,EAC1B,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-utils';\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: SnapController,\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"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./KeyringSnapControllerClient.cjs"), exports);
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAA8C","sourcesContent":["export * from './KeyringSnapControllerClient';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAA8C"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAA8C"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAA8C","sourcesContent":["export * from './KeyringSnapControllerClient';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/keyring-internal-snap-client",
|
|
3
|
+
"version": "1.0.0-4685a87",
|
|
4
|
+
"description": "MetaMask Keyring Snap internal clients",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"metamask",
|
|
7
|
+
"keyring"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/accounts/tree/main/packages/keyring-internal-snap-client#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/accounts/issues"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/MetaMask/accounts.git"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"default": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"default": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.cjs",
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "ts-bridge --project tsconfig.build.json --no-references",
|
|
36
|
+
"build:clean": "yarn build --clean",
|
|
37
|
+
"build:docs": "typedoc",
|
|
38
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-internal-snap-client",
|
|
39
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-internal-snap-client",
|
|
40
|
+
"publish:preview": "yarn npm publish --tag preview",
|
|
41
|
+
"test": "yarn test:source && yarn test:types",
|
|
42
|
+
"test:clean": "jest --clearCache",
|
|
43
|
+
"test:source": "jest && jest-it-up",
|
|
44
|
+
"test:types": "../../scripts/tsd-test.sh ./src",
|
|
45
|
+
"test:watch": "jest --watch"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@metamask/keyring-api": "12.0.0",
|
|
49
|
+
"@metamask/keyring-snap-client": "1.0.0",
|
|
50
|
+
"@metamask/keyring-utils": "1.0.0",
|
|
51
|
+
"webextension-polyfill": "^0.12.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@lavamoat/allow-scripts": "^3.2.1",
|
|
55
|
+
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
56
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
57
|
+
"@metamask/keyring-api": "12.0.0",
|
|
58
|
+
"@metamask/providers": "^18.1.0",
|
|
59
|
+
"@metamask/snaps-controllers": "^9.10.0",
|
|
60
|
+
"@metamask/snaps-sdk": "^6.7.0",
|
|
61
|
+
"@metamask/snaps-utils": "^8.3.0",
|
|
62
|
+
"@metamask/utils": "^9.3.0",
|
|
63
|
+
"@ts-bridge/cli": "^0.6.1",
|
|
64
|
+
"@types/jest": "^29.5.12",
|
|
65
|
+
"@types/node": "^20.12.12",
|
|
66
|
+
"deepmerge": "^4.2.2",
|
|
67
|
+
"depcheck": "^1.4.7",
|
|
68
|
+
"jest": "^29.5.0",
|
|
69
|
+
"jest-it-up": "^3.1.0",
|
|
70
|
+
"rimraf": "^5.0.7",
|
|
71
|
+
"ts-jest": "^29.0.5",
|
|
72
|
+
"ts-node": "^10.9.2",
|
|
73
|
+
"tsd": "^0.31.0",
|
|
74
|
+
"typedoc": "^0.25.13",
|
|
75
|
+
"typescript": "~5.6.3"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": "^18.18 || >=20"
|
|
79
|
+
},
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public",
|
|
82
|
+
"registry": "https://registry.npmjs.org/"
|
|
83
|
+
},
|
|
84
|
+
"lavamoat": {
|
|
85
|
+
"allowScripts": {
|
|
86
|
+
"@lavamoat/preinstall-always-fail": false
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"tsd": {
|
|
90
|
+
"directory": "src",
|
|
91
|
+
"compilerOptions": {
|
|
92
|
+
"composite": "false"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|