@metamask-previews/keyring-snap-client 0.0.1-672cc7b → 0.0.1-b250745

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.
Files changed (38) hide show
  1. package/dist/{KeyringClient.js → KeyringClient.cjs} +15 -14
  2. package/dist/KeyringClient.cjs.map +1 -0
  3. package/dist/{KeyringClient.d.ts → KeyringClient.d.cts} +5 -4
  4. package/dist/KeyringClient.d.cts.map +1 -0
  5. package/dist/KeyringClient.d.mts +29 -0
  6. package/dist/KeyringClient.d.mts.map +1 -0
  7. package/dist/KeyringClient.mjs +120 -0
  8. package/dist/KeyringClient.mjs.map +1 -0
  9. package/dist/{KeyringSnapControllerClient.js → KeyringSnapControllerClient.cjs} +2 -2
  10. package/dist/KeyringSnapControllerClient.cjs.map +1 -0
  11. package/dist/{KeyringSnapControllerClient.d.ts → KeyringSnapControllerClient.d.cts} +5 -4
  12. package/dist/KeyringSnapControllerClient.d.cts.map +1 -0
  13. package/dist/KeyringSnapControllerClient.d.mts +46 -0
  14. package/dist/KeyringSnapControllerClient.d.mts.map +1 -0
  15. package/dist/KeyringSnapControllerClient.mjs +100 -0
  16. package/dist/KeyringSnapControllerClient.mjs.map +1 -0
  17. package/dist/{KeyringSnapRpcClient.js → KeyringSnapRpcClient.cjs} +2 -2
  18. package/dist/KeyringSnapRpcClient.cjs.map +1 -0
  19. package/dist/{KeyringSnapRpcClient.d.ts → KeyringSnapRpcClient.d.cts} +6 -5
  20. package/dist/KeyringSnapRpcClient.d.cts.map +1 -0
  21. package/dist/KeyringSnapRpcClient.d.mts +40 -0
  22. package/dist/KeyringSnapRpcClient.d.mts.map +1 -0
  23. package/dist/KeyringSnapRpcClient.mjs +63 -0
  24. package/dist/KeyringSnapRpcClient.mjs.map +1 -0
  25. package/dist/{index.js → index.cjs} +4 -4
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +4 -0
  28. package/dist/index.d.cts.map +1 -0
  29. package/dist/index.d.mts +4 -0
  30. package/dist/index.d.mts.map +1 -0
  31. package/dist/index.mjs +4 -0
  32. package/dist/index.mjs.map +1 -0
  33. package/package.json +35 -20
  34. package/dist/KeyringClient.js.map +0 -1
  35. package/dist/KeyringSnapControllerClient.js.map +0 -1
  36. package/dist/KeyringSnapRpcClient.js.map +0 -1
  37. package/dist/index.d.ts +0 -3
  38. package/dist/index.js.map +0 -1
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _KeyringClient_instances, _KeyringClient_sender, _KeyringClient_send;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.KeyringClient = void 0;
16
+ const keyring_api_1 = require("@metamask/keyring-api");
16
17
  const keyring_internal_api_1 = require("@metamask/keyring-internal-api");
17
18
  const keyring_utils_1 = require("@metamask/keyring-utils");
18
19
  const superstruct_1 = require("@metamask/superstruct");
@@ -30,77 +31,77 @@ class KeyringClient {
30
31
  }
31
32
  async listAccounts() {
32
33
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
33
- method: keyring_internal_api_1.KeyringRpcMethod.ListAccounts,
34
+ method: keyring_api_1.KeyringRpcMethod.ListAccounts,
34
35
  }), keyring_internal_api_1.ListAccountsResponseStruct);
35
36
  }
36
37
  async getAccount(id) {
37
38
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
38
- method: keyring_internal_api_1.KeyringRpcMethod.GetAccount,
39
+ method: keyring_api_1.KeyringRpcMethod.GetAccount,
39
40
  params: { id },
40
41
  }), keyring_internal_api_1.GetAccountResponseStruct);
41
42
  }
42
43
  async getAccountBalances(id, assets) {
43
44
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
44
- method: keyring_internal_api_1.KeyringRpcMethod.GetAccountBalances,
45
+ method: keyring_api_1.KeyringRpcMethod.GetAccountBalances,
45
46
  params: { id, assets },
46
47
  }), keyring_internal_api_1.GetAccountBalancesResponseStruct);
47
48
  }
48
49
  async createAccount(options = {}) {
49
50
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
50
- method: keyring_internal_api_1.KeyringRpcMethod.CreateAccount,
51
+ method: keyring_api_1.KeyringRpcMethod.CreateAccount,
51
52
  params: { options },
52
53
  }), keyring_internal_api_1.CreateAccountResponseStruct);
53
54
  }
54
55
  async filterAccountChains(id, chains) {
55
56
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
56
- method: keyring_internal_api_1.KeyringRpcMethod.FilterAccountChains,
57
+ method: keyring_api_1.KeyringRpcMethod.FilterAccountChains,
57
58
  params: { id, chains },
58
59
  }), keyring_internal_api_1.FilterAccountChainsResponseStruct);
59
60
  }
60
61
  async updateAccount(account) {
61
62
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
62
- method: keyring_internal_api_1.KeyringRpcMethod.UpdateAccount,
63
+ method: keyring_api_1.KeyringRpcMethod.UpdateAccount,
63
64
  params: { account },
64
65
  }), keyring_internal_api_1.UpdateAccountResponseStruct);
65
66
  }
66
67
  async deleteAccount(id) {
67
68
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
68
- method: keyring_internal_api_1.KeyringRpcMethod.DeleteAccount,
69
+ method: keyring_api_1.KeyringRpcMethod.DeleteAccount,
69
70
  params: { id },
70
71
  }), keyring_internal_api_1.DeleteAccountResponseStruct);
71
72
  }
72
73
  async exportAccount(id) {
73
74
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
74
- method: keyring_internal_api_1.KeyringRpcMethod.ExportAccount,
75
+ method: keyring_api_1.KeyringRpcMethod.ExportAccount,
75
76
  params: { id },
76
77
  }), keyring_internal_api_1.ExportAccountResponseStruct);
77
78
  }
78
79
  async listRequests() {
79
80
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
80
- method: keyring_internal_api_1.KeyringRpcMethod.ListRequests,
81
+ method: keyring_api_1.KeyringRpcMethod.ListRequests,
81
82
  }), keyring_internal_api_1.ListRequestsResponseStruct);
82
83
  }
83
84
  async getRequest(id) {
84
85
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
85
- method: keyring_internal_api_1.KeyringRpcMethod.GetRequest,
86
+ method: keyring_api_1.KeyringRpcMethod.GetRequest,
86
87
  params: { id },
87
88
  }), keyring_internal_api_1.GetRequestResponseStruct);
88
89
  }
89
90
  async submitRequest(request) {
90
91
  return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
91
- method: keyring_internal_api_1.KeyringRpcMethod.SubmitRequest,
92
+ method: keyring_api_1.KeyringRpcMethod.SubmitRequest,
92
93
  params: request,
93
94
  }), keyring_internal_api_1.SubmitRequestResponseStruct);
94
95
  }
95
96
  async approveRequest(id, data = {}) {
96
97
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
97
- method: keyring_internal_api_1.KeyringRpcMethod.ApproveRequest,
98
+ method: keyring_api_1.KeyringRpcMethod.ApproveRequest,
98
99
  params: { id, data },
99
100
  }), keyring_internal_api_1.ApproveRequestResponseStruct);
100
101
  }
101
102
  async rejectRequest(id) {
102
103
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
103
- method: keyring_internal_api_1.KeyringRpcMethod.RejectRequest,
104
+ method: keyring_api_1.KeyringRpcMethod.RejectRequest,
104
105
  params: { id },
105
106
  }), keyring_internal_api_1.RejectRequestResponseStruct);
106
107
  }
@@ -120,4 +121,4 @@ async function _KeyringClient_send(partial) {
120
121
  ...partial,
121
122
  });
122
123
  };
123
- //# sourceMappingURL=KeyringClient.js.map
124
+ //# sourceMappingURL=KeyringClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.cjs","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,uDAAyD;AACzD,yEAcwC;AAExC,2DAAqD;AACrD,uDAA+C;AAE/C,+BAAkC;AAMlC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,0BAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,YAAY;SACtC,CAAC,EACF,iDAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,0BAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,+CAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,EAAU,EACV,MAAuB;QAEvB,OAAO,IAAA,0BAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,CAAC,kBAAkB;YAC3C,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;SACvB,CAAC,EACF,uDAAgC,CACjC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,UA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E;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from '@metamask/keyring-api';\nimport { KeyringRpcMethod } from '@metamask/keyring-api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from '@metamask/keyring-internal-api';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance } from '@metamask/keyring-api';
2
- import type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';
3
- import type { Json } from '@metamask/utils';
4
- export declare type Sender = {
1
+ import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance } from "@metamask/keyring-api";
2
+ import type { JsonRpcRequest } from "@metamask/keyring-snap-sdk";
3
+ import type { Json } from "@metamask/utils";
4
+ export type Sender = {
5
5
  send(request: JsonRpcRequest): Promise<Json>;
6
6
  };
7
7
  export declare class KeyringClient implements Keyring {
@@ -26,3 +26,4 @@ export declare class KeyringClient implements Keyring {
26
26
  approveRequest(id: string, data?: Record<string, Json>): Promise<void>;
27
27
  rejectRequest(id: string): Promise<void>;
28
28
  }
29
+ //# sourceMappingURL=KeyringClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.d.cts","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACR,8BAA8B;AAiB/B,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAmC;AAGjE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,qBAAa,aAAc,YAAW,OAAO;;IAG3C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAkBpB,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,aAAa,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAUpC,aAAa,CACjB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GACjC,OAAO,CAAC,cAAc,CAAC;IAUpB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpE,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUtD,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAUhE,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUV,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/C"}
@@ -0,0 +1,29 @@
1
+ import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance } from "@metamask/keyring-api";
2
+ import type { JsonRpcRequest } from "@metamask/keyring-snap-sdk";
3
+ import type { Json } from "@metamask/utils";
4
+ export type Sender = {
5
+ send(request: JsonRpcRequest): Promise<Json>;
6
+ };
7
+ export declare class KeyringClient implements Keyring {
8
+ #private;
9
+ /**
10
+ * Create a new instance of `KeyringClient`.
11
+ *
12
+ * @param sender - The `Sender` instance to use to send requests to the snap.
13
+ */
14
+ constructor(sender: Sender);
15
+ listAccounts(): Promise<KeyringAccount[]>;
16
+ getAccount(id: string): Promise<KeyringAccount>;
17
+ getAccountBalances(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
18
+ createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
19
+ filterAccountChains(id: string, chains: string[]): Promise<string[]>;
20
+ updateAccount(account: KeyringAccount): Promise<void>;
21
+ deleteAccount(id: string): Promise<void>;
22
+ exportAccount(id: string): Promise<KeyringAccountData>;
23
+ listRequests(): Promise<KeyringRequest[]>;
24
+ getRequest(id: string): Promise<KeyringRequest>;
25
+ submitRequest(request: KeyringRequest): Promise<KeyringResponse>;
26
+ approveRequest(id: string, data?: Record<string, Json>): Promise<void>;
27
+ rejectRequest(id: string): Promise<void>;
28
+ }
29
+ //# sourceMappingURL=KeyringClient.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.d.mts","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACR,8BAA8B;AAiB/B,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAmC;AAGjE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,qBAAa,aAAc,YAAW,OAAO;;IAG3C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAkBpB,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,aAAa,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAUpC,aAAa,CACjB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GACjC,OAAO,CAAC,cAAc,CAAC;IAUpB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpE,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUtD,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAUhE,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUV,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/C"}
@@ -0,0 +1,120 @@
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 _KeyringClient_instances, _KeyringClient_sender, _KeyringClient_send;
13
+ import { KeyringRpcMethod } from "@metamask/keyring-api";
14
+ import { ApproveRequestResponseStruct, CreateAccountResponseStruct, DeleteAccountResponseStruct, ExportAccountResponseStruct, FilterAccountChainsResponseStruct, GetAccountBalancesResponseStruct, GetAccountResponseStruct, GetRequestResponseStruct, ListAccountsResponseStruct, ListRequestsResponseStruct, RejectRequestResponseStruct, SubmitRequestResponseStruct, UpdateAccountResponseStruct } from "@metamask/keyring-internal-api";
15
+ import { strictMask } from "@metamask/keyring-utils";
16
+ import { assert } from "@metamask/superstruct";
17
+ import { v4 as uuid } from "uuid";
18
+ export class KeyringClient {
19
+ /**
20
+ * Create a new instance of `KeyringClient`.
21
+ *
22
+ * @param sender - The `Sender` instance to use to send requests to the snap.
23
+ */
24
+ constructor(sender) {
25
+ _KeyringClient_instances.add(this);
26
+ _KeyringClient_sender.set(this, void 0);
27
+ __classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
28
+ }
29
+ async listAccounts() {
30
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
31
+ method: KeyringRpcMethod.ListAccounts,
32
+ }), ListAccountsResponseStruct);
33
+ }
34
+ async getAccount(id) {
35
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
36
+ method: KeyringRpcMethod.GetAccount,
37
+ params: { id },
38
+ }), GetAccountResponseStruct);
39
+ }
40
+ async getAccountBalances(id, assets) {
41
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
42
+ method: KeyringRpcMethod.GetAccountBalances,
43
+ params: { id, assets },
44
+ }), GetAccountBalancesResponseStruct);
45
+ }
46
+ async createAccount(options = {}) {
47
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
48
+ method: KeyringRpcMethod.CreateAccount,
49
+ params: { options },
50
+ }), CreateAccountResponseStruct);
51
+ }
52
+ async filterAccountChains(id, chains) {
53
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
54
+ method: KeyringRpcMethod.FilterAccountChains,
55
+ params: { id, chains },
56
+ }), FilterAccountChainsResponseStruct);
57
+ }
58
+ async updateAccount(account) {
59
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
60
+ method: KeyringRpcMethod.UpdateAccount,
61
+ params: { account },
62
+ }), UpdateAccountResponseStruct);
63
+ }
64
+ async deleteAccount(id) {
65
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
66
+ method: KeyringRpcMethod.DeleteAccount,
67
+ params: { id },
68
+ }), DeleteAccountResponseStruct);
69
+ }
70
+ async exportAccount(id) {
71
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
72
+ method: KeyringRpcMethod.ExportAccount,
73
+ params: { id },
74
+ }), ExportAccountResponseStruct);
75
+ }
76
+ async listRequests() {
77
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
78
+ method: KeyringRpcMethod.ListRequests,
79
+ }), ListRequestsResponseStruct);
80
+ }
81
+ async getRequest(id) {
82
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
83
+ method: KeyringRpcMethod.GetRequest,
84
+ params: { id },
85
+ }), GetRequestResponseStruct);
86
+ }
87
+ async submitRequest(request) {
88
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
89
+ method: KeyringRpcMethod.SubmitRequest,
90
+ params: request,
91
+ }), SubmitRequestResponseStruct);
92
+ }
93
+ async approveRequest(id, data = {}) {
94
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
95
+ method: KeyringRpcMethod.ApproveRequest,
96
+ params: { id, data },
97
+ }), ApproveRequestResponseStruct);
98
+ }
99
+ async rejectRequest(id) {
100
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
101
+ method: KeyringRpcMethod.RejectRequest,
102
+ params: { id },
103
+ }), RejectRequestResponseStruct);
104
+ }
105
+ }
106
+ _KeyringClient_sender = new WeakMap(), _KeyringClient_instances = new WeakSet(), _KeyringClient_send =
107
+ /**
108
+ * Send a request to the snap and return the response.
109
+ *
110
+ * @param partial - A partial JSON-RPC request (method and params).
111
+ * @returns A promise that resolves to the response to the request.
112
+ */
113
+ async function _KeyringClient_send(partial) {
114
+ return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
115
+ jsonrpc: '2.0',
116
+ id: uuid(),
117
+ ...partial,
118
+ });
119
+ };
120
+ //# sourceMappingURL=KeyringClient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.mjs","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,2BAA2B,EAC3B,iCAAiC,EACjC,gCAAgC,EAChC,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,2BAA2B,EAC5B,uCAAuC;AAExC,OAAO,EAAE,UAAU,EAAE,gCAAgC;AACr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AAC,OAAuB;QACzC,OAAO,UAAU,CACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;QAE/B,MAAM,CACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,gBAAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,4BAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,MAAM,CACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;;AArJC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAI,EAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from '@metamask/keyring-api';\nimport { KeyringRpcMethod } from '@metamask/keyring-api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from '@metamask/keyring-internal-api';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _SnapControllerSender_snapId, _SnapControllerSender_origin, _SnapControllerSender_controller, _SnapControllerSender_handler, _KeyringSnapControllerClient_controller;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.KeyringSnapControllerClient = void 0;
16
- const KeyringClient_1 = require("./KeyringClient");
16
+ const KeyringClient_1 = require("./KeyringClient.cjs");
17
17
  /**
18
18
  * Implementation of the `Sender` interface that can be used to send requests
19
19
  * to a snap through a `SnapController`.
@@ -101,4 +101,4 @@ class KeyringSnapControllerClient extends KeyringClient_1.KeyringClient {
101
101
  }
102
102
  exports.KeyringSnapControllerClient = KeyringSnapControllerClient;
103
103
  _KeyringSnapControllerClient_controller = new WeakMap();
104
- //# sourceMappingURL=KeyringSnapControllerClient.js.map
104
+ //# sourceMappingURL=KeyringSnapControllerClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapControllerClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,uDAA6D;AAE7D;;;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,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;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 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\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 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,7 +1,7 @@
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';
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.cjs";
5
5
  /**
6
6
  * A `KeyringClient` that allows the communication with a snap through the
7
7
  * `SnapController`.
@@ -43,3 +43,4 @@ export declare class KeyringSnapControllerClient extends KeyringClient {
43
43
  */
44
44
  getController(): SnapController;
45
45
  }
46
+ //# sourceMappingURL=KeyringSnapControllerClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapControllerClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAGzD,OAAO,EAAE,aAAa,EAAe,4BAAwB;AAmD7D;;;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 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.mjs";
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":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAGzD,OAAO,EAAE,aAAa,EAAe,4BAAwB;AAmD7D;;;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 "./KeyringClient.mjs";
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":";;;;;;;;;;;;AAMA,OAAO,EAAE,aAAa,EAAe,4BAAwB;AAE7D;;;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 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\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 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"]}
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _SnapRpcSender_origin, _SnapRpcSender_provider;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.KeyringSnapRpcClient = exports.SnapRpcSender = void 0;
16
- const KeyringClient_1 = require("./KeyringClient");
16
+ const KeyringClient_1 = require("./KeyringClient.cjs");
17
17
  /**
18
18
  * Implementation of the `Sender` interface that can be used to send requests
19
19
  * to a snap through the snap JSON-RPC API.
@@ -65,4 +65,4 @@ class KeyringSnapRpcClient extends KeyringClient_1.KeyringClient {
65
65
  }
66
66
  }
67
67
  exports.KeyringSnapRpcClient = KeyringSnapRpcClient;
68
- //# sourceMappingURL=KeyringSnapRpcClient.js.map
68
+ //# sourceMappingURL=KeyringSnapRpcClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,uDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAVnD,wCAAgB;QAEhB,0CAAkC;QASzC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n readonly #origin: string;\n\n readonly #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The 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.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
- import type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';
2
- import type { MetaMaskInpageProvider } from '@metamask/providers';
3
- import type { Json } from '@metamask/utils';
4
- import type { Sender } from './KeyringClient';
5
- import { KeyringClient } from './KeyringClient';
1
+ import type { JsonRpcRequest } from "@metamask/keyring-snap-sdk";
2
+ import type { MetaMaskInpageProvider } from "@metamask/providers";
3
+ import type { Json } from "@metamask/utils";
4
+ import type { Sender } from "./KeyringClient.cjs";
5
+ import { KeyringClient } from "./KeyringClient.cjs";
6
6
  /**
7
7
  * Implementation of the `Sender` interface that can be used to send requests
8
8
  * to a snap through the snap JSON-RPC API.
@@ -37,3 +37,4 @@ export declare class KeyringSnapRpcClient extends KeyringClient {
37
37
  */
38
38
  constructor(origin: string, provider: MetaMaskInpageProvider);
39
39
  }
40
+ //# sourceMappingURL=KeyringSnapRpcClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAmC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,4BAA4B;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,4BAAwB;AAC9C,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAK1C;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAK5D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASnD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;CAG7D"}
@@ -0,0 +1,40 @@
1
+ import type { JsonRpcRequest } from "@metamask/keyring-snap-sdk";
2
+ import type { MetaMaskInpageProvider } from "@metamask/providers";
3
+ import type { Json } from "@metamask/utils";
4
+ import type { Sender } from "./KeyringClient.mjs";
5
+ import { KeyringClient } from "./KeyringClient.mjs";
6
+ /**
7
+ * Implementation of the `Sender` interface that can be used to send requests
8
+ * to a snap through the snap JSON-RPC API.
9
+ */
10
+ export declare class SnapRpcSender implements Sender {
11
+ #private;
12
+ /**
13
+ * Create a new instance of `SnapRpcSender`.
14
+ *
15
+ * @param origin - The caller's origin.
16
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
17
+ */
18
+ constructor(origin: string, provider: MetaMaskInpageProvider);
19
+ /**
20
+ * Send a request to the snap and return the response.
21
+ *
22
+ * @param request - The JSON-RPC request to send to the snap.
23
+ * @returns A promise that resolves to the response of the request.
24
+ */
25
+ send(request: JsonRpcRequest): Promise<Json>;
26
+ }
27
+ /**
28
+ * A `KeyringClient` that allows the communication with a snap through the snap
29
+ * JSON-RPC API.
30
+ */
31
+ export declare class KeyringSnapRpcClient extends KeyringClient {
32
+ /**
33
+ * Create a new instance of `KeyringSnapRpcClient`.
34
+ *
35
+ * @param origin - Caller's origin.
36
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
37
+ */
38
+ constructor(origin: string, provider: MetaMaskInpageProvider);
39
+ }
40
+ //# sourceMappingURL=KeyringSnapRpcClient.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.d.mts","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAmC;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,4BAA4B;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,4BAAwB;AAC9C,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAK1C;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAK5D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASnD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;CAG7D"}
@@ -0,0 +1,63 @@
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 _SnapRpcSender_origin, _SnapRpcSender_provider;
13
+ import { KeyringClient } from "./KeyringClient.mjs";
14
+ /**
15
+ * Implementation of the `Sender` interface that can be used to send requests
16
+ * to a snap through the snap JSON-RPC API.
17
+ */
18
+ export class SnapRpcSender {
19
+ /**
20
+ * Create a new instance of `SnapRpcSender`.
21
+ *
22
+ * @param origin - The caller's origin.
23
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
24
+ */
25
+ constructor(origin, provider) {
26
+ _SnapRpcSender_origin.set(this, void 0);
27
+ _SnapRpcSender_provider.set(this, void 0);
28
+ __classPrivateFieldSet(this, _SnapRpcSender_origin, origin, "f");
29
+ __classPrivateFieldSet(this, _SnapRpcSender_provider, provider, "f");
30
+ }
31
+ /**
32
+ * Send a request to the snap and return the response.
33
+ *
34
+ * @param request - The JSON-RPC request to send to the snap.
35
+ * @returns A promise that resolves to the response of the request.
36
+ */
37
+ async send(request) {
38
+ return __classPrivateFieldGet(this, _SnapRpcSender_provider, "f").request({
39
+ method: 'wallet_invokeKeyring',
40
+ params: {
41
+ snapId: __classPrivateFieldGet(this, _SnapRpcSender_origin, "f"),
42
+ request,
43
+ },
44
+ });
45
+ }
46
+ }
47
+ _SnapRpcSender_origin = new WeakMap(), _SnapRpcSender_provider = new WeakMap();
48
+ /**
49
+ * A `KeyringClient` that allows the communication with a snap through the snap
50
+ * JSON-RPC API.
51
+ */
52
+ export class KeyringSnapRpcClient extends KeyringClient {
53
+ /**
54
+ * Create a new instance of `KeyringSnapRpcClient`.
55
+ *
56
+ * @param origin - Caller's origin.
57
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
58
+ */
59
+ constructor(origin, provider) {
60
+ super(new SnapRpcSender(origin, provider));
61
+ }
62
+ }
63
+ //# sourceMappingURL=KeyringSnapRpcClient.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.mjs","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD;;;GAGG;AACH,MAAM,OAAO,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAVnD,wCAAgB;QAEhB,0CAAkC;QASzC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n readonly #origin: string;\n\n readonly #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The 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.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./KeyringClient"), exports);
18
- __exportStar(require("./KeyringSnapControllerClient"), exports);
19
- __exportStar(require("./KeyringSnapRpcClient"), exports);
20
- //# sourceMappingURL=index.js.map
17
+ __exportStar(require("./KeyringClient.cjs"), exports);
18
+ __exportStar(require("./KeyringSnapControllerClient.cjs"), exports);
19
+ __exportStar(require("./KeyringSnapRpcClient.cjs"), exports);
20
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAgC;AAChC,oEAA8C;AAC9C,6DAAuC","sourcesContent":["export * from './KeyringClient';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./KeyringClient.cjs";
2
+ export * from "./KeyringSnapControllerClient.cjs";
3
+ export * from "./KeyringSnapRpcClient.cjs";
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kDAA8C;AAC9C,2CAAuC"}
@@ -0,0 +1,4 @@
1
+ export * from "./KeyringClient.mjs";
2
+ export * from "./KeyringSnapControllerClient.mjs";
3
+ export * from "./KeyringSnapRpcClient.mjs";
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kDAA8C;AAC9C,2CAAuC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./KeyringClient.mjs";
2
+ export * from "./KeyringSnapControllerClient.mjs";
3
+ export * from "./KeyringSnapRpcClient.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kDAA8C;AAC9C,2CAAuC","sourcesContent":["export * from './KeyringClient';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/keyring-snap-client",
3
- "version": "0.0.1-672cc7b",
3
+ "version": "0.0.1-b250745",
4
4
  "description": "MetaMask Keyring Snap clients",
5
5
  "keywords": [
6
6
  "metamask",
@@ -14,56 +14,71 @@
14
14
  "type": "git",
15
15
  "url": "https://github.com/MetaMask/accounts.git"
16
16
  },
17
- "main": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
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",
19
31
  "files": [
20
32
  "dist/"
21
33
  ],
22
34
  "scripts": {
23
- "build": "tsc --build tsconfig.build.json",
24
- "build:clean": "rimraf dist && yarn build",
35
+ "build": "ts-bridge --project tsconfig.build.json --no-references",
36
+ "build:clean": "yarn build --clean",
25
37
  "build:docs": "typedoc",
26
- "build:force": "tsc --build tsconfig.build.json --force",
27
38
  "changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-snap-client",
28
39
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-snap-client",
29
40
  "publish:preview": "yarn npm publish --tag preview",
30
41
  "test": "yarn test:source && yarn test:types",
31
42
  "test:clean": "jest --clearCache",
32
43
  "test:source": "jest && jest-it-up",
33
- "test:types": "tsd",
34
- "test:verbose": "jest --verbose",
44
+ "test:types": "echo 'No tests to run for now'",
35
45
  "test:watch": "jest --watch"
36
46
  },
37
47
  "dependencies": {
38
- "@metamask/keyring-api": "^8.1.0",
48
+ "@metamask/keyring-api": "11.0.0",
39
49
  "@metamask/keyring-internal-api": "0.0.1",
40
50
  "@metamask/keyring-snap-sdk": "0.0.1",
41
51
  "@metamask/keyring-utils": "0.0.1",
52
+ "@metamask/snaps-controllers": "^9.10.0",
53
+ "@metamask/snaps-sdk": "^6.7.0",
54
+ "@metamask/snaps-utils": "^8.3.0",
42
55
  "@metamask/superstruct": "^3.1.0",
43
56
  "@types/uuid": "^9.0.8",
44
57
  "deepmerge": "^4.2.2",
45
- "uuid": "^9.0.1"
58
+ "uuid": "^9.0.1",
59
+ "webextension-polyfill": "^0.12.0"
46
60
  },
47
61
  "devDependencies": {
48
- "@lavamoat/allow-scripts": "^3.0.4",
49
- "@lavamoat/preinstall-always-fail": "^2.0.0",
62
+ "@lavamoat/allow-scripts": "^3.2.1",
63
+ "@lavamoat/preinstall-always-fail": "^2.1.0",
50
64
  "@metamask/auto-changelog": "^3.4.4",
51
- "@metamask/providers": "^17.1.1",
52
- "@metamask/snaps-controllers": "^9.3.0",
53
- "@metamask/snaps-sdk": "^6.1.0",
54
- "@metamask/snaps-utils": "^7.8.0",
55
- "@metamask/utils": "^9.1.0",
65
+ "@metamask/providers": "^18.1.0",
66
+ "@metamask/utils": "^9.2.1",
67
+ "@ts-bridge/cli": "^0.6.0",
56
68
  "@types/jest": "^29.5.12",
57
69
  "@types/node": "^20.12.12",
58
70
  "depcheck": "^1.4.7",
59
- "jest": "^28.1.3",
71
+ "jest": "^29.5.0",
60
72
  "jest-it-up": "^3.1.0",
61
73
  "rimraf": "^5.0.7",
62
- "ts-jest": "^28.0.8",
74
+ "ts-jest": "^29.0.5",
63
75
  "ts-node": "^10.9.2",
64
76
  "tsd": "^0.31.0",
65
77
  "typedoc": "^0.25.13",
66
- "typescript": "~4.8.4"
78
+ "typescript": "~5.6.3"
79
+ },
80
+ "peerDependencies": {
81
+ "@metamask/providers": "^18.1.0"
67
82
  },
68
83
  "engines": {
69
84
  "node": "^18.18 || >=20"
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,yEAewC;AAExC,2DAAqD;AACrD,uDAA+C;AAE/C,+BAAkC;AAMlC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAA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AAO;SAChB,CAAC,EACF,kDAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;QAE/B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uCAAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,mDAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uCAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,kDAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AAjKD,sCAiKC;;AArJC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n} from '@metamask/keyring-api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n KeyringRpcMethod,\n} from '@metamask/keyring-internal-api';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -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 { 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\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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n #origin: string;\n\n #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The 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.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './KeyringClient';
2
- export * from './KeyringSnapControllerClient';
3
- export * from './KeyringSnapRpcClient';
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,gEAA8C;AAC9C,yDAAuC","sourcesContent":["export * from './KeyringClient';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\n"]}