@metamask/keyring-api 0.2.1 → 0.2.2

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 CHANGED
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.2]
10
+ ### Added
11
+ - Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86))
12
+ - Add `lastSelected` and `lastActive` to metadata ([#92](https://github.com/MetaMask/keyring-api/pull/92))
13
+
14
+ ### Changed
15
+ - Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96))
16
+ - Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95))
17
+ - Move request ID to outer request ([#94](https://github.com/MetaMask/keyring-api/pull/94))
18
+
9
19
  ## [0.2.1]
10
20
  ### Changed
11
21
  - Set `snap` object keys to be mandatory and move `name` to `metadata` ([#87](https://github.com/MetaMask/keyring-api/pull/87))
@@ -52,7 +62,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
52
62
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
53
63
  - Helper functions to create keyring handler in the snap.
54
64
 
55
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...HEAD
65
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.2...HEAD
66
+ [0.2.2]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...v0.2.2
56
67
  [0.2.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.0...v0.2.1
57
68
  [0.2.0]: https://github.com/MetaMask/keyring-api/compare/v0.1.3...v0.2.0
58
69
  [0.1.3]: https://github.com/MetaMask/keyring-api/compare/v0.1.2...v0.1.3
@@ -1,4 +1,4 @@
1
- import { type Infer } from 'superstruct';
1
+ import type { Infer } from 'superstruct';
2
2
  export declare const JsonRpcRequestStruct: import("superstruct").Struct<{
3
3
  jsonrpc: "2.0";
4
4
  id: string | number | null;
@@ -1 +1 @@
1
- {"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,6CAUqB;AAErB,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC,CAAC;IACzC,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;CACjE,CAAC;AAEW,QAAA,oBAAoB,GAAG,IAAA,mBAAK,EAAC;IACxC,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,CAAC;IACrB,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;CACjC,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport {\n type Infer,\n array,\n literal,\n nullable,\n number,\n object,\n record,\n string,\n union,\n} from 'superstruct';\n\nconst Common = {\n jsonrpc: literal('2.0'),\n id: nullable(union([string(), number()])),\n method: string(),\n};\n\nconst Params = {\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n};\n\nexport const JsonRpcRequestStruct = union([\n object({ ...Common }),\n object({ ...Common, ...Params }),\n]);\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
1
+ {"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CASqB;AAErB,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC,CAAC;IACzC,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;CACjE,CAAC;AAEW,QAAA,oBAAoB,GAAG,IAAA,mBAAK,EAAC;IACxC,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,CAAC;IACrB,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;CACjC,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n literal,\n nullable,\n number,\n object,\n record,\n string,\n union,\n} from 'superstruct';\n\nconst Common = {\n jsonrpc: literal('2.0'),\n id: nullable(union([string(), number()])),\n method: string(),\n};\n\nconst Params = {\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n};\n\nexport const JsonRpcRequestStruct = union([\n object({ ...Common }),\n object({ ...Common, ...Params }),\n]);\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AAExB,mCAAqD;AAMrD,MAAa,aAAa;IAGxB;;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C7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AAtJD,sCAsJC;;AA1IC;;;;;GAKG;AACH,KAAK,8BACH,OAAoD;IAEpD,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 { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { type OmitUnion, strictMask } from './utils';\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(\n partial: OmitUnion<JsonRpcRequest, 'jsonrpc' | 'id'>,\n ): 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: 'keyring_listAccounts',\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_getAccount',\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_exportAccount',\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: 'keyring_listRequests',\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_rejectRequest',\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AAGxB,mCAAqC;AAMrC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAkBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAsB;SAC/B,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,oBAAoB;YAC5B,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,UAAgC,EAAE;QAElC,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE,EAAE,OAAO,EAAE;SACpB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,EAAU,EAAE,MAAgB;QACpD,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EA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AM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,iCAA2B,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,wBAAwB;YAChC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,kCAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,uBAAuB;YAC/B,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AAtJD,sCAsJC;;AA1IC;;;;;GAKG;AACH,KAAK,8BACH,OAAoD;IAEpD,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 { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { OmitUnion } from './utils';\nimport { strictMask } from './utils';\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(\n partial: OmitUnion<JsonRpcRequest, 'jsonrpc' | 'id'>,\n ): 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: 'keyring_listAccounts',\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_getAccount',\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_exportAccount',\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: 'keyring_listRequests',\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_rejectRequest',\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { MetaMaskInpageProvider } from '@metamask/providers';
2
2
  import type { Json } from '@metamask/utils';
3
3
  import type { JsonRpcRequest } from './JsonRpcRequest';
4
- import { KeyringClient, type Sender } from './KeyringClient';
4
+ import type { Sender } from './KeyringClient';
5
+ import { KeyringClient } from './KeyringClient';
5
6
  /**
6
7
  * Implementation of the `Sender` interface that can be used to send requests
7
8
  * to a snap through the snap JSON-RPC API.
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,mDAA6D;AAE7D;;;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,mBAAmB;YAC3B,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 { MetaMaskInpageProvider } from '@metamask/providers';\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 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_invokeSnap',\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
+ {"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,mBAAmB;YAC3B,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 { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\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_invokeSnap',\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/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type Json } from '@metamask/utils';
2
- import { type Infer } from 'superstruct';
1
+ import type { Json } from '@metamask/utils';
2
+ import type { Infer } from 'superstruct';
3
3
  /**
4
4
  * Supported Ethereum methods.
5
5
  */
@@ -65,39 +65,34 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
65
65
  */
66
66
  export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
67
67
  export declare const KeyringRequestStruct: import("superstruct").Struct<{
68
- account: string;
68
+ id: string;
69
69
  scope: string;
70
+ account: string;
70
71
  request: {
71
- jsonrpc: "2.0";
72
- id: string | number | null;
73
72
  method: string;
74
73
  } | {
75
- jsonrpc: "2.0";
76
- id: string | number | null;
77
74
  method: string;
78
75
  params: Json[] | Record<string, Json>;
79
76
  };
80
77
  }, {
81
78
  /**
82
- * Account ID (UUIDv4).
79
+ * Keyring request ID (UUIDv4).
83
80
  */
84
- account: import("superstruct").Struct<string, null>;
81
+ id: import("superstruct").Struct<string, null>;
85
82
  /**
86
83
  * Request's scope (CAIP-2 chain ID).
87
84
  */
88
85
  scope: import("superstruct").Struct<string, null>;
89
86
  /**
90
- * JSON-RPC request sent by the client application.
91
- *
92
- * Note: The request ID must be a string.
87
+ * Account ID (UUIDv4).
88
+ */
89
+ account: import("superstruct").Struct<string, null>;
90
+ /**
91
+ * Inner request sent by the client application.
93
92
  */
94
93
  request: import("superstruct").Struct<{
95
- jsonrpc: "2.0";
96
- id: string | number | null;
97
94
  method: string;
98
95
  } | {
99
- jsonrpc: "2.0";
100
- id: string | number | null;
101
96
  method: string;
102
97
  params: Json[] | Record<string, Json>;
103
98
  }, null>;
package/dist/api.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.EthAccountType = exports.EthMethod = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const superstruct_1 = require("superstruct");
6
- const JsonRpcRequest_1 = require("./JsonRpcRequest");
7
6
  const utils_2 = require("./utils");
8
7
  /**
9
8
  * Supported Ethereum methods.
@@ -58,19 +57,29 @@ exports.KeyringAccountStruct = (0, superstruct_1.object)({
58
57
  });
59
58
  exports.KeyringRequestStruct = (0, superstruct_1.object)({
60
59
  /**
61
- * Account ID (UUIDv4).
60
+ * Keyring request ID (UUIDv4).
62
61
  */
63
- account: utils_2.UuidStruct,
62
+ id: utils_2.UuidStruct,
64
63
  /**
65
64
  * Request's scope (CAIP-2 chain ID).
66
65
  */
67
66
  scope: (0, superstruct_1.string)(),
68
67
  /**
69
- * JSON-RPC request sent by the client application.
70
- *
71
- * Note: The request ID must be a string.
68
+ * Account ID (UUIDv4).
69
+ */
70
+ account: utils_2.UuidStruct,
71
+ /**
72
+ * Inner request sent by the client application.
72
73
  */
73
- request: JsonRpcRequest_1.JsonRpcRequestStruct,
74
+ request: (0, superstruct_1.union)([
75
+ (0, superstruct_1.object)({
76
+ method: (0, superstruct_1.string)(),
77
+ }),
78
+ (0, superstruct_1.object)({
79
+ method: (0, superstruct_1.string)(),
80
+ params: (0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)]),
81
+ }),
82
+ ]),
74
83
  });
75
84
  exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
76
85
  exports.KeyringResponseStruct = (0, superstruct_1.union)([
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,6CAUqB;AAErB,qDAAwD;AACxD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,aAAa,EAAE;QAC5B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;KAC/B,CAAC,CACH;IAED;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;CACpE,CAAC,CAAC;AASU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;;;OAIG;IACH,OAAO,EAAE,qCAAoB;CAC9B,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;KAC7B,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { type Json, JsonStruct } from '@metamask/utils';\nimport {\n type Infer,\n array,\n enums,\n literal,\n object,\n record,\n string,\n union,\n nullable,\n} from 'superstruct';\n\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * JSON-RPC request sent by the client application.\n *\n * Note: The request ID must be a string.\n */\n request: JsonRpcRequestStruct,\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: nullable(string()),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL to be shown\n * to the user. The user can choose to follow the link or cancel the request.\n * The main use case for this is to redirect the user to a third-party service\n * to approve the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CASqB;AAErB,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,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC;QACb,IAAA,oBAAM,EAAC;YACL,MAAM,EAAE,IAAA,oBAAM,GAAE;SACjB,CAAC;QACF,IAAA,oBAAM,EAAC;YACL,MAAM,EAAE,IAAA,oBAAM,GAAE;YAChB,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;SACjE,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AASU,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC;AASxD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;KAC7B,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n enums,\n literal,\n object,\n record,\n string,\n union,\n nullable,\n} from 'superstruct';\n\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: union([\n object({\n method: string(),\n }),\n object({\n method: string(),\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n }),\n ]),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: nullable(string()),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL to be shown\n * to the user. The user can choose to follow the link or cancel the request.\n * The main use case for this is to redirect the user to a third-party service\n * to approve the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { type Infer } from 'superstruct';
1
+ import type { Infer } from 'superstruct';
2
2
  export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
3
3
  jsonrpc: "2.0";
4
4
  id: string;
@@ -255,41 +255,32 @@ export declare const ListRequestsRequestStruct: import("superstruct").Struct<{
255
255
  }>;
256
256
  export declare type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;
257
257
  export declare const ListRequestsResponseStruct: import("superstruct").Struct<{
258
- account: string;
258
+ id: string;
259
259
  scope: string;
260
+ account: string;
260
261
  request: {
261
- jsonrpc: "2.0";
262
- id: string | number | null;
263
262
  method: string;
264
263
  } | {
265
- jsonrpc: "2.0";
266
- id: string | number | null;
267
264
  method: string;
268
265
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
269
266
  };
270
267
  }[], import("superstruct").Struct<{
271
- account: string;
268
+ id: string;
272
269
  scope: string;
270
+ account: string;
273
271
  request: {
274
- jsonrpc: "2.0";
275
- id: string | number | null;
276
272
  method: string;
277
273
  } | {
278
- jsonrpc: "2.0";
279
- id: string | number | null;
280
274
  method: string;
281
275
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
282
276
  };
283
277
  }, {
284
- account: import("superstruct").Struct<string, null>;
278
+ id: import("superstruct").Struct<string, null>;
285
279
  scope: import("superstruct").Struct<string, null>;
280
+ account: import("superstruct").Struct<string, null>;
286
281
  request: import("superstruct").Struct<{
287
- jsonrpc: "2.0";
288
- id: string | number | null;
289
282
  method: string;
290
283
  } | {
291
- jsonrpc: "2.0";
292
- id: string | number | null;
293
284
  method: string;
294
285
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
295
286
  }, null>;
@@ -314,28 +305,22 @@ export declare const GetRequestRequestStruct: import("superstruct").Struct<{
314
305
  }>;
315
306
  export declare type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;
316
307
  export declare const GetRequestResponseStruct: import("superstruct").Struct<{
317
- account: string;
308
+ id: string;
318
309
  scope: string;
310
+ account: string;
319
311
  request: {
320
- jsonrpc: "2.0";
321
- id: string | number | null;
322
312
  method: string;
323
313
  } | {
324
- jsonrpc: "2.0";
325
- id: string | number | null;
326
314
  method: string;
327
315
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
328
316
  };
329
317
  }, {
330
- account: import("superstruct").Struct<string, null>;
318
+ id: import("superstruct").Struct<string, null>;
331
319
  scope: import("superstruct").Struct<string, null>;
320
+ account: import("superstruct").Struct<string, null>;
332
321
  request: import("superstruct").Struct<{
333
- jsonrpc: "2.0";
334
- id: string | number | null;
335
322
  method: string;
336
323
  } | {
337
- jsonrpc: "2.0";
338
- id: string | number | null;
339
324
  method: string;
340
325
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
341
326
  }, null>;
@@ -346,15 +331,12 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
346
331
  id: string;
347
332
  method: "keyring_submitRequest";
348
333
  params: {
349
- account: string;
334
+ id: string;
350
335
  scope: string;
336
+ account: string;
351
337
  request: {
352
- jsonrpc: "2.0";
353
- id: string | number | null;
354
338
  method: string;
355
339
  } | {
356
- jsonrpc: "2.0";
357
- id: string | number | null;
358
340
  method: string;
359
341
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
360
342
  };
@@ -362,28 +344,22 @@ export declare const SubmitRequestRequestStruct: import("superstruct").Struct<{
362
344
  }, {
363
345
  method: import("superstruct").Struct<"keyring_submitRequest", "keyring_submitRequest">;
364
346
  params: import("superstruct").Struct<{
365
- account: string;
347
+ id: string;
366
348
  scope: string;
349
+ account: string;
367
350
  request: {
368
- jsonrpc: "2.0";
369
- id: string | number | null;
370
351
  method: string;
371
352
  } | {
372
- jsonrpc: "2.0";
373
- id: string | number | null;
374
353
  method: string;
375
354
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
376
355
  };
377
356
  }, {
378
- account: import("superstruct").Struct<string, null>;
357
+ id: import("superstruct").Struct<string, null>;
379
358
  scope: import("superstruct").Struct<string, null>;
359
+ account: import("superstruct").Struct<string, null>;
380
360
  request: import("superstruct").Struct<{
381
- jsonrpc: "2.0";
382
- id: string | number | null;
383
361
  method: string;
384
362
  } | {
385
- jsonrpc: "2.0";
386
- id: string | number | null;
387
363
  method: string;
388
364
  params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
389
365
  }, null>;
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,6CAOqB;AAErB,gCAKgB;AAChB,oCAAsC;AAEtC,MAAM,YAAY,GAAG;IACnB,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,kBAAU;CACf,CAAC;AAEF,+EAA+E;AAC/E,gBAAgB;AAEH,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,sBAAsB,CAAC;CACxC,CAAC,CAAC;AAIU,QAAA,0BAA0B,GAAG,IAAA,mBAAK,EAAC,0BAAoB,CAAC,CAAC;AAItE,+EAA+E;AAC/E,cAAc;AAED,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,oBAAoB,CAAC;IACrC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,wBAAwB,GAAG,0BAAoB,CAAC;AAI7D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBA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AAC;AAIU,QAAA,4BAA4B,GAAG,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC;AAI1D,+EAA+E;AAC/E,iBAAiB;AAEJ,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,GAAG,YAAY;IACf,MAAM,EAAE,IAAA,qBAAO,EAAC,uBAAuB,CAAC;IACxC,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,EAAE,EAAE,IAAA,oBAAM,GAAE;KACb,CAAC;CACH,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport {\n array,\n literal,\n object,\n record,\n string,\n type Infer,\n} from 'superstruct';\n\nimport {\n KeyringAccountDataStruct,\n KeyringAccountStruct,\n KeyringRequestStruct,\n KeyringResponseStruct,\n} from '../api';\nimport { UuidStruct } from '../utils';\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: UuidStruct,\n};\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_createAccount'),\n params: object({\n options: record(string(), JsonStruct),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n ...CommonHeader,\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: string(),\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = literal(null);\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_deleteAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_exportAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = KeyringAccountDataStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = KeyringResponseStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_approveRequest'),\n params: object({\n id: string(),\n data: record(string(), JsonStruct),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = literal(null);\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_rejectRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = literal(null);\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/internal/api.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAAqE;AAErE,g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O,EAAC,IAAI,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, literal, object, record, string } from 'superstruct';\n\nimport {\n KeyringAccountDataStruct,\n KeyringAccountStruct,\n KeyringRequestStruct,\n KeyringResponseStruct,\n} from '../api';\nimport { UuidStruct } from '../utils';\n\nconst CommonHeader = {\n jsonrpc: literal('2.0'),\n id: UuidStruct,\n};\n\n// ----------------------------------------------------------------------------\n// List accounts\n\nexport const ListAccountsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listAccounts'),\n});\n\nexport type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;\n\nexport const ListAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create account\n\nexport const CreateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_createAccount'),\n params: object({\n options: record(string(), JsonStruct),\n }),\n});\n\nexport type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;\n\nexport const CreateAccountResponseStruct = KeyringAccountStruct;\n\nexport type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Filter account chains\n\nexport const FilterAccountChainsStruct = object({\n ...CommonHeader,\n method: literal('keyring_filterAccountChains'),\n params: object({\n id: string(),\n chains: array(string()),\n }),\n});\n\nexport type FilterAccountChainsRequest = Infer<\n typeof FilterAccountChainsStruct\n>;\n\nexport const FilterAccountChainsResponseStruct = array(string());\n\nexport type FilterAccountChainsResponse = Infer<\n typeof FilterAccountChainsResponseStruct\n>;\n\n// ----------------------------------------------------------------------------\n// Update account\n\nexport const UpdateAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_updateAccount'),\n params: object({\n account: KeyringAccountStruct,\n }),\n});\n\nexport type UpdateAccountRequest = Infer<typeof UpdateAccountRequestStruct>;\n\nexport const UpdateAccountResponseStruct = literal(null);\n\nexport type UpdateAccountResponse = Infer<typeof UpdateAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_deleteAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_exportAccount'),\n params: object({\n id: string(),\n }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = KeyringAccountDataStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// List requests\n\nexport const ListRequestsRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_listRequests'),\n});\n\nexport type ListRequestsRequest = Infer<typeof ListRequestsRequestStruct>;\n\nexport const ListRequestsResponseStruct = array(KeyringRequestStruct);\n\nexport type ListRequestsResponse = Infer<typeof ListRequestsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get request\n\nexport const GetRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_getRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type GetRequestRequest = Infer<typeof GetRequestRequestStruct>;\n\nexport const GetRequestResponseStruct = KeyringRequestStruct;\n\nexport type GetRequestResponse = Infer<typeof GetRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_submitRequest'),\n params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = KeyringResponseStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Approve request\n\nexport const ApproveRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_approveRequest'),\n params: object({\n id: string(),\n data: record(string(), JsonStruct),\n }),\n});\n\nexport type ApproveRequestRequest = Infer<typeof ApproveRequestRequestStruct>;\n\nexport const ApproveRequestResponseStruct = literal(null);\n\nexport type ApproveRequestResponse = Infer<typeof ApproveRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Reject request\n\nexport const RejectRequestRequestStruct = object({\n ...CommonHeader,\n method: literal('keyring_rejectRequest'),\n params: object({\n id: string(),\n }),\n});\n\nexport type RejectRequestRequest = Infer<typeof RejectRequestRequestStruct>;\n\nexport const RejectRequestResponseStruct = literal(null);\n\nexport type RejectRequestResponse = Infer<typeof RejectRequestResponseStruct>;\n"]}
@@ -32,8 +32,7 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
32
32
  }, {
33
33
  id: import("superstruct").Struct<string, null>;
34
34
  address: import("superstruct").Struct<string, null>;
35
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
36
- /**
35
+ options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>; /**
37
36
  * Request result.
38
37
  */
39
38
  methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
@@ -86,8 +85,7 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
86
85
  }, {
87
86
  id: import("superstruct").Struct<string, null>;
88
87
  address: import("superstruct").Struct<string, null>;
89
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
90
- /**
88
+ options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>; /**
91
89
  * Request result.
92
90
  */
93
91
  methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
@@ -1,4 +1,4 @@
1
- import { type Infer } from 'superstruct';
1
+ import type { Infer } from 'superstruct';
2
2
  export declare const InternalAccountStruct: import("superstruct").Struct<{
3
3
  id: string;
4
4
  address: string;
@@ -15,6 +15,7 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
15
15
  enabled: boolean;
16
16
  name: string;
17
17
  } | undefined;
18
+ lastSelected?: number | undefined;
18
19
  };
19
20
  }, {
20
21
  metadata: import("superstruct").Struct<{
@@ -27,6 +28,7 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
27
28
  enabled: boolean;
28
29
  name: string;
29
30
  } | undefined;
31
+ lastSelected?: number | undefined;
30
32
  }, {
31
33
  snap: import("superstruct").Struct<{
32
34
  id: string;
@@ -38,6 +40,7 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
38
40
  name: import("superstruct").Struct<string, null>;
39
41
  }>;
40
42
  name: import("superstruct").Struct<string, null>;
43
+ lastSelected: import("superstruct").Struct<number | undefined, null>;
41
44
  keyring: import("superstruct").Struct<{
42
45
  type: string;
43
46
  }, {
@@ -12,6 +12,7 @@ exports.InternalAccountStruct = (0, superstruct_1.object)({
12
12
  name: (0, superstruct_1.string)(),
13
13
  })),
14
14
  name: (0, superstruct_1.string)(),
15
+ lastSelected: (0, superstruct_1.optional)((0, superstruct_1.number)()),
15
16
  keyring: (0, superstruct_1.object)({
16
17
  type: (0, superstruct_1.string)(),
17
18
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AAAA,6CAA4E;AAE5E,gCAA8C;AAEjC,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,sBAAQ,EACZ,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { boolean, object, optional, string, type Infer } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n metadata: object({\n snap: optional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n name: string(),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAAwE;AAExE,gCAA8C;AAEjC,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,sBAAQ,EACZ,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,YAAY,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;QAChC,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { boolean, object, optional, string, number } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n metadata: object({\n snap: optional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n name: string(),\n lastSelected: optional(number()),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { OnRpcRequestHandler } from '@metamask/snaps-utils';
2
2
  import type { Json } from '@metamask/utils';
3
3
  import type { Keyring } from './api';
4
- import { type JsonRpcRequest } from './JsonRpcRequest';
4
+ import type { JsonRpcRequest } from './JsonRpcRequest';
5
5
  /**
6
6
  * Error thrown when a keyring JSON-RPC method is not supported.
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAEA,6CAAqC;AAGrC,wCAawB;AACxB,qDAA6E;AAE7E;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc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;YACnC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE;gBACvC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AA3FD,oDA2FC","sourcesContent":["import type { OnRpcRequestHandler } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n} from './internal/api';\nimport { type JsonRpcRequest, JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Build a chain of handlers for a JSON-RPC request.\n *\n * If a handler throws a MethodNotSupportedError, the next handler in the chain\n * is called. If all handlers throw a MethodNotSupportedError, the error is re-\n * thrown.\n *\n * Any other error thrown by a handler is re-thrown.\n *\n * @param handlers - Handlers to chain.\n * @returns A handler that chains the given handlers.\n */\nexport function buildHandlersChain(\n ...handlers: OnRpcRequestHandler[]\n): OnRpcRequestHandler {\n return async ({ origin, request }) => {\n for (const handler of handlers) {\n try {\n return await handler({ origin, request });\n } catch (error) {\n if (!(error instanceof MethodNotSupportedError)) {\n throw error;\n }\n }\n }\n\n // All handlers failed to handle the request.\n throw new MethodNotSupportedError(request.method);\n };\n}\n\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAEA,6CAAqC;AAGrC,wCAawB;AAExB,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,GAAG,QAA+B;IAElC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE;QACnC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,IAAI;gBACF,OAAO,MAAM,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;aAC3C;YAAC,OAAO,K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CAAC;AA3FD,oDA2FC","sourcesContent":["import type { OnRpcRequestHandler } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n} from './internal/api';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Build a chain of handlers for a JSON-RPC request.\n *\n * If a handler throws a MethodNotSupportedError, the next handler in the chain\n * is called. If all handlers throw a MethodNotSupportedError, the error is re-\n * thrown.\n *\n * Any other error thrown by a handler is re-thrown.\n *\n * @param handlers - Handlers to chain.\n * @returns A handler that chains the given handlers.\n */\nexport function buildHandlersChain(\n ...handlers: OnRpcRequestHandler[]\n): OnRpcRequestHandler {\n return async ({ origin, request }) => {\n for (const handler of handlers) {\n try {\n return await handler({ origin, request });\n } catch (error) {\n if (!(error instanceof MethodNotSupportedError)) {\n throw error;\n }\n }\n }\n\n // All handlers failed to handle the request.\n throw new MethodNotSupportedError(request.method);\n };\n}\n\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n"]}
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Struct } from 'superstruct';
1
+ import type { Struct } from 'superstruct';
2
2
  /**
3
3
  * UUIDv4 struct.
4
4
  */
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AAEnE;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAO,EAC/B,IAAA,oBAAM,GAAE,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { type Struct, assert, pattern, string } from 'superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = pattern(\n string(),\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAGtD;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAO,EAC/B,IAAA,oBAAM,GAAE,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert, pattern, string } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = pattern(\n string(),\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",