@metamask/keyring-api 2.0.0 → 4.0.0
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 +32 -1
- package/dist/eth/erc4337/types.d.ts +6 -0
- package/dist/eth/erc4337/types.js +3 -0
- package/dist/eth/erc4337/types.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/KeyringSnapControllerClient.d.ts +0 -45
- package/dist/KeyringSnapControllerClient.js +0 -104
- package/dist/KeyringSnapControllerClient.js.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [4.0.0]
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- **BREAKING** Update node min version to 18.x ([#247](https://github.com/MetaMask/keyring-api/pull/247))
|
15
|
+
- Update `eth_patchUserOperation` to return optional gas limit values ([#250](https://github.com/MetaMask/keyring-api/pull/250))
|
16
|
+
- Bump `ip` from 2.0.0 to 2.0.1 ([#253](https://github.com/MetaMask/keyring-api/pull/253))
|
17
|
+
- Bump `@metamask/json-rpc-engine` from 7.3.1 to 7.3.2 ([#246](https://github.com/MetaMask/keyring-api/pull/246))
|
18
|
+
- Bump `@metamask/snaps-sdk` from 1.3.2 to 1.4.0 ([#243](https://github.com/MetaMask/keyring-api/pull/243))
|
19
|
+
|
20
|
+
## [3.0.0]
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- Bump `@metamask/utils` from 8.2.1 to 8.3.0 ([#238](https://github.com/MetaMask/keyring-api/pull/238))
|
25
|
+
- Bump Snap dependencies ([#236](https://github.com/MetaMask/keyring-api/pull/236))
|
26
|
+
- Bump `@metamask/snaps-controllers` to ^4.0.0
|
27
|
+
- Bump `@metamask/snaps-sdk` to ^1.3.2
|
28
|
+
- Bump `@metamask/snaps-utils` to ^5.1.2
|
29
|
+
- Bump `@metamask/approval-controller` from 5.0.0 to 5.1.1 ([#225](https://github.com/MetaMask/keyring-api/pull/225))
|
30
|
+
- Bump `@metamask/base-controller` from 4.0.0 to 4.0.1 ([#226](https://github.com/MetaMask/keyring-api/pull/226))
|
31
|
+
- Bump `@metamask/json-rpc-engine` from 7.3.0 to 7.3.1 ([#227](https://github.com/MetaMask/keyring-api/pull/227))
|
32
|
+
- Bump `@metamask/auto-changelog` from 3.4.3 to 3.4.4 ([#223](https://github.com/MetaMask/keyring-api/pull/223))
|
33
|
+
- Bump `@metamask/snaps-sdk` from 1.3.0 to 1.3.1 ([#222](https://github.com/MetaMask/keyring-api/pull/222))
|
34
|
+
|
35
|
+
### Removed
|
36
|
+
|
37
|
+
- **BREAKING**: remove `KeyringSnapControllerClient` class to fix dependency problems ([#241](https://github.com/MetaMask/keyring-api/pull/241))
|
38
|
+
|
10
39
|
## [2.0.0]
|
11
40
|
|
12
41
|
### Added
|
@@ -188,7 +217,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
188
217
|
- SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
|
189
218
|
- Helper functions to create keyring handler in the snap.
|
190
219
|
|
191
|
-
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/
|
220
|
+
[Unreleased]: https://github.com/MetaMask/keyring-api/compare/v4.0.0...HEAD
|
221
|
+
[4.0.0]: https://github.com/MetaMask/keyring-api/compare/v3.0.0...v4.0.0
|
222
|
+
[3.0.0]: https://github.com/MetaMask/keyring-api/compare/v2.0.0...v3.0.0
|
192
223
|
[2.0.0]: https://github.com/MetaMask/keyring-api/compare/v1.1.0...v2.0.0
|
193
224
|
[1.1.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0...v1.1.0
|
194
225
|
[1.0.0]: https://github.com/MetaMask/keyring-api/compare/v1.0.0-rc.1...v1.0.0
|
@@ -84,7 +84,13 @@ export declare const EthBaseUserOperationStruct: import("superstruct").Struct<{
|
|
84
84
|
export declare type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;
|
85
85
|
export declare const EthUserOperationPatchStruct: import("superstruct").Struct<{
|
86
86
|
paymasterAndData: string;
|
87
|
+
callGasLimit?: string;
|
88
|
+
verificationGasLimit?: string;
|
89
|
+
preVerificationGas?: string;
|
87
90
|
}, {
|
88
91
|
paymasterAndData: import("superstruct").Struct<string, null>;
|
92
|
+
callGasLimit: import("superstruct").Struct<string | import("../../superstruct").ExactOptionalTag, null>;
|
93
|
+
verificationGasLimit: import("superstruct").Struct<string | import("../../superstruct").ExactOptionalTag, null>;
|
94
|
+
preVerificationGas: import("superstruct").Struct<string | import("../../superstruct").ExactOptionalTag, null>;
|
89
95
|
}>;
|
90
96
|
export declare type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;
|
@@ -54,5 +54,8 @@ exports.EthBaseUserOperationStruct = (0, superstruct_2.object)({
|
|
54
54
|
});
|
55
55
|
exports.EthUserOperationPatchStruct = (0, superstruct_2.object)({
|
56
56
|
paymasterAndData: types_1.EthBytesStruct,
|
57
|
+
callGasLimit: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
|
58
|
+
verificationGasLimit: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
|
59
|
+
preVerificationGas: (0, superstruct_2.exactOptional)(types_1.EthUint256Struct),
|
57
60
|
});
|
58
61
|
//# sourceMappingURL=types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/eth/erc4337/types.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,mDAA0D;AAC1D,oCAA8E;AAE9E;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAAC;IAC3C,MAAM,EAAE,wBAAgB;IACxB,KAAK,EAAE,wBAAgB;IACvB,QAAQ,EAAE,sBAAc;IACxB,QAAQ,EAAE,sBAAc;IACxB,YAAY,EAAE,wBAAgB;IAC9B,oBAAoB,EAAE,wBAAgB;IACtC,kBAAkB,EAAE,wBAAgB;IACpC,YAAY,EAAE,wBAAgB;IAC9B,oBAAoB,EAAE,wBAAgB;IACtC,gBAAgB,EAAE,sBAAc;IAChC,SAAS,EAAE,sBAAc;CAC1B,CAAC,CAAC;AAIH;;;GAGG;AACU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IAC7C;;OAEG;IACH,EAAE,EAAE,wBAAgB;IAEpB;;OAEG;IACH,KAAK,EAAE,wBAAgB;IAEvB;;OAEG;IACH,IAAI,EAAE,sBAAc;CACrB,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,KAAK,EAAE,wBAAgB;IACvB,QAAQ,EAAE,sBAAc;IACxB,QAAQ,EAAE,sBAAc;IACxB,SAAS,EAAE,IAAA,2BAAa,EACtB,IAAA,oBAAM,EAAC;QACL,YAAY,EAAE,wBAAgB;QAC9B,oBAAoB,EAAE,wBAAgB;QACtC,kBAAkB,EAAE,wBAAgB;KACrC,CAAC,CACH;IACD,qBAAqB,EAAE,sBAAc;IACrC,cAAc,EAAE,sBAAc;IAC9B,UAAU,EAAE,IAAA,oBAAM,GAAE;CACrB,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,oBAAM,EAAC;IAChD,gBAAgB,EAAE,sBAAc;
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/eth/erc4337/types.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,mDAA0D;AAC1D,oCAA8E;AAE9E;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAAC;IAC3C,MAAM,EAAE,wBAAgB;IACxB,KAAK,EAAE,wBAAgB;IACvB,QAAQ,EAAE,sBAAc;IACxB,QAAQ,EAAE,sBAAc;IACxB,YAAY,EAAE,wBAAgB;IAC9B,oBAAoB,EAAE,wBAAgB;IACtC,kBAAkB,EAAE,wBAAgB;IACpC,YAAY,EAAE,wBAAgB;IAC9B,oBAAoB,EAAE,wBAAgB;IACtC,gBAAgB,EAAE,sBAAc;IAChC,SAAS,EAAE,sBAAc;CAC1B,CAAC,CAAC;AAIH;;;GAGG;AACU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IAC7C;;OAEG;IACH,EAAE,EAAE,wBAAgB;IAEpB;;OAEG;IACH,KAAK,EAAE,wBAAgB;IAEvB;;OAEG;IACH,IAAI,EAAE,sBAAc;CACrB,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,KAAK,EAAE,wBAAgB;IACvB,QAAQ,EAAE,sBAAc;IACxB,QAAQ,EAAE,sBAAc;IACxB,SAAS,EAAE,IAAA,2BAAa,EACtB,IAAA,oBAAM,EAAC;QACL,YAAY,EAAE,wBAAgB;QAC9B,oBAAoB,EAAE,wBAAgB;QACtC,kBAAkB,EAAE,wBAAgB;KACrC,CAAC,CACH;IACD,qBAAqB,EAAE,sBAAc;IACrC,cAAc,EAAE,sBAAc;IAC9B,UAAU,EAAE,IAAA,oBAAM,GAAE;CACrB,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,oBAAM,EAAC;IAChD,gBAAgB,EAAE,sBAAc;IAChC,YAAY,EAAE,IAAA,2BAAa,EAAC,wBAAgB,CAAC;IAC7C,oBAAoB,EAAE,IAAA,2BAAa,EAAC,wBAAgB,CAAC;IACrD,kBAAkB,EAAE,IAAA,2BAAa,EAAC,wBAAgB,CAAC;CACpD,CAAC,CAAC","sourcesContent":["import { string, type Infer } from 'superstruct';\n\nimport { exactOptional, object } from '../../superstruct';\nimport { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';\n\n/**\n * Struct of a UserOperation as defined by ERC-4337.\n * @see https://eips.ethereum.org/EIPS/eip-4337#definitions\n */\nexport const EthUserOperationStruct = object({\n sender: EthAddressStruct,\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n maxFeePerGas: EthUint256Struct,\n maxPriorityFeePerGas: EthUint256Struct,\n paymasterAndData: EthBytesStruct,\n signature: EthBytesStruct,\n});\n\nexport type EthUserOperation = Infer<typeof EthUserOperationStruct>;\n\n/**\n * Struct containing the most basic transaction information required to\n * construct a UserOperation.\n */\nexport const EthBaseTransactionStruct = object({\n /**\n * Address of the transaction recipient.\n */\n to: EthAddressStruct,\n\n /**\n * Amount of wei to transfer to the recipient.\n */\n value: EthUint256Struct,\n\n /**\n * Data to pass to the recipient.\n */\n data: EthBytesStruct,\n});\n\nexport type EthBaseTransaction = Infer<typeof EthBaseTransactionStruct>;\n\nexport const EthBaseUserOperationStruct = object({\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n gasLimits: exactOptional(\n object({\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n }),\n ),\n dummyPaymasterAndData: EthBytesStruct,\n dummySignature: EthBytesStruct,\n bundlerUrl: string(),\n});\n\nexport type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;\n\nexport const EthUserOperationPatchStruct = object({\n paymasterAndData: EthBytesStruct,\n callGasLimit: exactOptional(EthUint256Struct),\n verificationGasLimit: exactOptional(EthUint256Struct),\n preVerificationGas: exactOptional(EthUint256Struct),\n});\n\nexport type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;\n"]}
|
package/dist/index.d.ts
CHANGED
@@ -3,7 +3,6 @@ export * from './eth';
|
|
3
3
|
export * from './events';
|
4
4
|
export * from './internal';
|
5
5
|
export * from './KeyringClient';
|
6
|
-
export * from './KeyringSnapControllerClient';
|
7
6
|
export * from './KeyringSnapRpcClient';
|
8
7
|
export * from './rpc-handler';
|
9
8
|
export * from './snap-utils';
|
package/dist/index.js
CHANGED
@@ -19,7 +19,6 @@ __exportStar(require("./eth"), exports);
|
|
19
19
|
__exportStar(require("./events"), exports);
|
20
20
|
__exportStar(require("./internal"), exports);
|
21
21
|
__exportStar(require("./KeyringClient"), exports);
|
22
|
-
__exportStar(require("./KeyringSnapControllerClient"), exports);
|
23
22
|
__exportStar(require("./KeyringSnapRpcClient"), exports);
|
24
23
|
__exportStar(require("./rpc-handler"), exports);
|
25
24
|
__exportStar(require("./snap-utils"), exports);
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,2CAAyB;AACzB,6CAA2B;AAC3B,kDAAgC;AAChC,yDAAuC;AACvC,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B","sourcesContent":["export * from './api';\nexport * from './eth';\nexport * from './events';\nexport * from './internal';\nexport * from './KeyringClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './rpc-handler';\nexport * from './snap-utils';\nexport * from './superstruct';\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/keyring-api",
|
3
|
-
"version": "
|
3
|
+
"version": "4.0.0",
|
4
4
|
"description": "MetaMask Keyring API",
|
5
5
|
"keywords": [
|
6
6
|
"metamask",
|
@@ -39,9 +39,7 @@
|
|
39
39
|
},
|
40
40
|
"dependencies": {
|
41
41
|
"@metamask/providers": "^14.0.1",
|
42
|
-
"@metamask/snaps-
|
43
|
-
"@metamask/snaps-sdk": "^1.2.0",
|
44
|
-
"@metamask/snaps-utils": "^5.0.0",
|
42
|
+
"@metamask/snaps-sdk": "^1.3.2",
|
45
43
|
"@metamask/utils": "^8.1.0",
|
46
44
|
"@types/uuid": "^9.0.1",
|
47
45
|
"superstruct": "^1.0.3",
|
@@ -81,7 +79,7 @@
|
|
81
79
|
},
|
82
80
|
"packageManager": "yarn@3.2.1",
|
83
81
|
"engines": {
|
84
|
-
"node": ">=
|
82
|
+
"node": "^18.18 || >=20"
|
85
83
|
},
|
86
84
|
"publishConfig": {
|
87
85
|
"access": "public",
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import type { SnapController } from '@metamask/snaps-controllers';
|
2
|
-
import type { SnapId } from '@metamask/snaps-sdk';
|
3
|
-
import type { HandlerType } from '@metamask/snaps-utils';
|
4
|
-
import { KeyringClient } from './KeyringClient';
|
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
|
-
}
|
@@ -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 KeyringClient_1 = require("./KeyringClient");
|
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 KeyringClient_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.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"KeyringSnapControllerClient.js","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,mDAA6D;AAE7D;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBtB,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgBpB,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,6BAAa;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;QA1BvE,0DAA4B;QA2B1B,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 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\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringClient, type Sender } from './KeyringClient';\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 #snapId: SnapId;\n\n #origin: string;\n\n #controller: SnapController;\n\n #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 #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"]}
|