@metamask-previews/eth-snap-keyring 6.0.0-b85bfaa → 6.0.0-e345222

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.
@@ -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 keyring_snap_client_1 = require("@metamask/keyring-snap-client");
16
+ const keyring_api_1 = require("@metamask/keyring-api");
17
17
  /**
18
18
  * Implementation of the `Sender` interface that can be used to send requests
19
19
  * to a snap through a `SnapController`.
@@ -57,7 +57,7 @@ _SnapControllerSender_snapId = new WeakMap(), _SnapControllerSender_origin = new
57
57
  * A `KeyringClient` that allows the communication with a snap through the
58
58
  * `SnapController`.
59
59
  */
60
- class KeyringSnapControllerClient extends keyring_snap_client_1.KeyringClient {
60
+ class KeyringSnapControllerClient extends keyring_api_1.KeyringClient {
61
61
  /**
62
62
  * Create a new instance of `KeyringSnapControllerClient`.
63
63
  *
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uEAA2E;AAO3E;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBb,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgB7B,uBAAA,IAAI,oCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,wCAAY,CAAC,aAAa,CAAC;YACpC,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,OAAO,EAAE,uBAAA,IAAI,qCAAS;YACtB,OAAO;SACR,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAa,2BAA4B,SAAQ,mCAAa;IAG5D;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,EACV,MAAM,GAAG,WAAqB,EAC9B,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,kBAAiC,GAM5C;QACC,KAAK,CAAC,IAAI,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QA1B9D,0DAA4B;QA2BnC,uBAAA,IAAI,2CAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,uBAAA,IAAI,+CAAY;YAC5B,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,uBAAA,IAAI,+CAAY,CAAC;IAC1B,CAAC;CACF;AAtDD,kEAsDC","sourcesContent":["import { KeyringClient, type Sender } from '@metamask/keyring-snap-client';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringSnapControllerClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAAsD;AAMtD;;;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,2BAAa;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, Sender } from '@metamask/keyring-api';\nimport { KeyringClient } from '@metamask/keyring-api';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { KeyringClient } from "@metamask/keyring-snap-client";
1
+ import { KeyringClient } from "@metamask/keyring-api";
2
2
  import type { SnapController } from "@metamask/snaps-controllers";
3
3
  import type { SnapId } from "@metamask/snaps-sdk";
4
4
  import type { HandlerType } from "@metamask/snaps-utils";
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
1
+ {"version":3,"file":"KeyringSnapControllerClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
@@ -1,4 +1,4 @@
1
- import { KeyringClient } from "@metamask/keyring-snap-client";
1
+ import { KeyringClient } from "@metamask/keyring-api";
2
2
  import type { SnapController } from "@metamask/snaps-controllers";
3
3
  import type { SnapId } from "@metamask/snaps-sdk";
4
4
  import type { HandlerType } from "@metamask/snaps-utils";
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.d.mts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
1
+ {"version":3,"file":"KeyringSnapControllerClient.d.mts","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAoDzD;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,aAAa;;IAG5D;;;;;;;;;;;;OAYG;gBACS,EACV,UAAU,EACV,MAA8B,EAC9B,MAAmB,EACnB,OAA2C,GAC5C,EAAE;QACD,UAAU,EAAE,cAAc,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB;IAKD;;;;;;;OAOG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,2BAA2B;IAOvD;;;;OAIG;IACH,aAAa,IAAI,cAAc;CAGhC"}
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _SnapControllerSender_snapId, _SnapControllerSender_origin, _SnapControllerSender_controller, _SnapControllerSender_handler, _KeyringSnapControllerClient_controller;
13
- import { KeyringClient } from "@metamask/keyring-snap-client";
13
+ import { KeyringClient } from "@metamask/keyring-api";
14
14
  /**
15
15
  * Implementation of the `Sender` interface that can be used to send requests
16
16
  * to a snap through a `SnapController`.
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapControllerClient.mjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAe,sCAAsC;AAO3E;;;GAGG;AACH,MAAM,oBAAoB;IASxB;;;;;;;OAOG;IACH,YACE,UAAe,EACf,MAAc,EACd,MAAc,EACd,OAAoB;QApBb,+CAAgB;QAEhB,+CAAgB;QAEhB,mDAA4B;QAE5B,gDAAsB;QAgB7B,uBAAA,IAAI,oCAAe,UAAU,MAAA,CAAC;QAC9B,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,gCAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,iCAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,wCAAY,CAAC,aAAa,CAAC;YACpC,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,MAAM,EAAE,uBAAA,IAAI,oCAAQ;YACpB,OAAO,EAAE,uBAAA,IAAI,qCAAS;YACtB,OAAO;SACR,CAAkB,CAAC;IACtB,CAAC;CACF;;AAED;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,aAAa;IAG5D;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,UAAU,EACV,MAAM,GAAG,WAAqB,EAC9B,MAAM,GAAG,UAAU,EACnB,OAAO,GAAG,kBAAiC,GAM5C;QACC,KAAK,CAAC,IAAI,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QA1B9D,0DAA4B;QA2BnC,uBAAA,IAAI,2CAAe,UAAU,MAAA,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,2BAA2B,CAAC;YACrC,UAAU,EAAE,uBAAA,IAAI,+CAAY;YAC5B,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,aAAa;QACX,OAAO,uBAAA,IAAI,+CAAY,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { KeyringClient, type Sender } from '@metamask/keyring-snap-client';\nimport type { JsonRpcRequest } from '@metamask/keyring-snap-sdk';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
1
+ {"version":3,"file":"KeyringSnapControllerClient.mjs","sourceRoot":"","sources":["../src/KeyringSnapControllerClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,aAAa,EAAE,8BAA8B;AAMtD;;;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, Sender } from '@metamask/keyring-api';\nimport { KeyringClient } from '@metamask/keyring-api';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through a `SnapController`.\n */\nclass SnapControllerSender implements Sender {\n readonly #snapId: SnapId;\n\n readonly #origin: string;\n\n readonly #controller: SnapController;\n\n readonly #handler: HandlerType;\n\n /**\n * Create a new instance of `SnapControllerSender`.\n *\n * @param controller - The `SnapController` instance to send requests to.\n * @param snapId - The ID of the snap to use.\n * @param origin - The sender's origin.\n * @param handler - The handler type.\n */\n constructor(\n controller: any,\n snapId: SnapId,\n origin: string,\n handler: HandlerType,\n ) {\n this.#controller = controller;\n this.#snapId = snapId;\n this.#origin = origin;\n this.#handler = handler;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#controller.handleRequest({\n snapId: this.#snapId,\n origin: this.#origin,\n handler: this.#handler,\n request,\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the\n * `SnapController`.\n */\nexport class KeyringSnapControllerClient extends KeyringClient {\n readonly #controller: SnapController;\n\n /**\n * Create a new instance of `KeyringSnapControllerClient`.\n *\n * The `handlerType` argument has a hard-coded default `string` value instead\n * of a `HandlerType` value to prevent the `@metamask/snaps-utils` module\n * from being required at runtime.\n *\n * @param args - Constructor arguments.\n * @param args.controller - The `SnapController` instance to use.\n * @param args.snapId - The ID of the snap to use (default: `'undefined'`).\n * @param args.origin - The sender's origin (default: `'metamask'`).\n * @param args.handler - The handler type (default: `'onKeyringRequest'`).\n */\n constructor({\n controller,\n snapId = 'undefined' as SnapId,\n origin = 'metamask',\n handler = 'onKeyringRequest' as HandlerType,\n }: {\n controller: SnapController;\n snapId?: SnapId;\n origin?: string;\n handler?: HandlerType;\n }) {\n super(new SnapControllerSender(controller, snapId, origin, handler));\n this.#controller = controller;\n }\n\n /**\n * Create a new instance of `KeyringSnapControllerClient` with the specified\n * `snapId`.\n *\n * @param snapId - The ID of the snap to use in the new instance.\n * @returns A new instance of `KeyringSnapControllerClient` with the\n * specified snap ID.\n */\n withSnapId(snapId: SnapId): KeyringSnapControllerClient {\n return new KeyringSnapControllerClient({\n controller: this.#controller,\n snapId,\n });\n }\n\n /**\n * Get the `SnapController` instance used by this client.\n *\n * @returns The `SnapController` instance used by this client.\n */\n getController(): SnapController {\n return this.#controller;\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
3
3
  // This rule seems to be triggering a false positive. Possibly eslint is not
4
- // inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.
4
+ // inferring the EthMethod, BtcMethod, and InternalAccount types correctly.
5
5
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6
6
  if (kind === "m") throw new TypeError("Private method is not writable");
7
7
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -18,13 +18,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SnapKeyring = exports.SNAP_KEYRING_TYPE = void 0;
19
19
  const tx_1 = require("@ethereumjs/tx");
20
20
  const eth_sig_util_1 = require("@metamask/eth-sig-util");
21
- const keyring_internal_api_1 = require("@metamask/keyring-internal-api");
22
- const keyring_snap_client_1 = require("@metamask/keyring-snap-client");
21
+ const keyring_api_1 = require("@metamask/keyring-api");
23
22
  const superstruct_1 = require("@metamask/superstruct");
24
23
  const utils_1 = require("@metamask/utils");
25
24
  const events_1 = require("events");
26
25
  const uuid_1 = require("uuid");
27
26
  const DeferredPromise_1 = require("./DeferredPromise.cjs");
27
+ const KeyringSnapControllerClient_1 = require("./KeyringSnapControllerClient.cjs");
28
28
  const logger_1 = require("./logger.cjs");
29
29
  const SnapIdMap_1 = require("./SnapIdMap.cjs");
30
30
  const types_1 = require("./types.cjs");
@@ -40,7 +40,7 @@ function normalizeAccountAddress(account) {
40
40
  // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior
41
41
  // only for Ethereum addresses and use the original address for other non-EVM accounts.
42
42
  // For example, Solana addresses are case-sensitives.
43
- return (0, keyring_internal_api_1.isEvmAccountType)(account.type)
43
+ return (0, keyring_api_1.isEvmAccountType)(account.type)
44
44
  ? account.address.toLowerCase()
45
45
  : account.address;
46
46
  }
@@ -76,7 +76,7 @@ class SnapKeyring extends events_1.EventEmitter {
76
76
  */
77
77
  _SnapKeyring_callbacks.set(this, void 0);
78
78
  this.type = SnapKeyring.type;
79
- __classPrivateFieldSet(this, _SnapKeyring_snapClient, new keyring_snap_client_1.KeyringSnapControllerClient({ controller }), "f");
79
+ __classPrivateFieldSet(this, _SnapKeyring_snapClient, new KeyringSnapControllerClient_1.KeyringSnapControllerClient({ controller }), "f");
80
80
  __classPrivateFieldSet(this, _SnapKeyring_requests, new SnapIdMap_1.SnapIdMap(), "f");
81
81
  __classPrivateFieldSet(this, _SnapKeyring_accounts, new SnapIdMap_1.SnapIdMap(), "f");
82
82
  __classPrivateFieldSet(this, _SnapKeyring_callbacks, callbacks, "f");
@@ -91,19 +91,19 @@ class SnapKeyring extends events_1.EventEmitter {
91
91
  async handleKeyringSnapMessage(snapId, message) {
92
92
  (0, superstruct_1.assert)(message, types_1.SnapMessageStruct);
93
93
  switch (message.method) {
94
- case `${keyring_internal_api_1.KeyringEvent.AccountCreated}`: {
94
+ case `${keyring_api_1.KeyringEvent.AccountCreated}`: {
95
95
  return __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_handleAccountCreated).call(this, snapId, message);
96
96
  }
97
- case `${keyring_internal_api_1.KeyringEvent.AccountUpdated}`: {
97
+ case `${keyring_api_1.KeyringEvent.AccountUpdated}`: {
98
98
  return __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_handleAccountUpdated).call(this, snapId, message);
99
99
  }
100
- case `${keyring_internal_api_1.KeyringEvent.AccountDeleted}`: {
100
+ case `${keyring_api_1.KeyringEvent.AccountDeleted}`: {
101
101
  return __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_handleAccountDeleted).call(this, snapId, message);
102
102
  }
103
- case `${keyring_internal_api_1.KeyringEvent.RequestApproved}`: {
103
+ case `${keyring_api_1.KeyringEvent.RequestApproved}`: {
104
104
  return __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_handleRequestApproved).call(this, snapId, message);
105
105
  }
106
- case `${keyring_internal_api_1.KeyringEvent.RequestRejected}`: {
106
+ case `${keyring_api_1.KeyringEvent.RequestRejected}`: {
107
107
  return __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_handleRequestRejected).call(this, snapId, message);
108
108
  }
109
109
  default:
@@ -170,7 +170,7 @@ class SnapKeyring extends events_1.EventEmitter {
170
170
  });
171
171
  const signedTx = await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
172
172
  address,
173
- method: keyring_internal_api_1.EthMethod.SignTransaction,
173
+ method: keyring_api_1.EthMethod.SignTransaction,
174
174
  params: [tx],
175
175
  chainId: (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, `${chainId}`),
176
176
  });
@@ -198,13 +198,13 @@ class SnapKeyring extends events_1.EventEmitter {
198
198
  */
199
199
  async signTypedData(address, data, opts = { version: eth_sig_util_1.SignTypedDataVersion.V1 }) {
200
200
  const methods = {
201
- [eth_sig_util_1.SignTypedDataVersion.V1]: keyring_internal_api_1.EthMethod.SignTypedDataV1,
202
- [eth_sig_util_1.SignTypedDataVersion.V3]: keyring_internal_api_1.EthMethod.SignTypedDataV3,
203
- [eth_sig_util_1.SignTypedDataVersion.V4]: keyring_internal_api_1.EthMethod.SignTypedDataV4,
201
+ [eth_sig_util_1.SignTypedDataVersion.V1]: keyring_api_1.EthMethod.SignTypedDataV1,
202
+ [eth_sig_util_1.SignTypedDataVersion.V3]: keyring_api_1.EthMethod.SignTypedDataV3,
203
+ [eth_sig_util_1.SignTypedDataVersion.V4]: keyring_api_1.EthMethod.SignTypedDataV4,
204
204
  };
205
205
  // Use 'V1' by default to match other keyring implementations. V1 will be
206
206
  // used if the version is not specified or not supported.
207
- const method = methods[opts.version] || keyring_internal_api_1.EthMethod.SignTypedDataV1;
207
+ const method = methods[opts.version] || keyring_api_1.EthMethod.SignTypedDataV1;
208
208
  // Extract chain ID as if it was a typed message (as defined by EIP-712), if
209
209
  // input is not a typed message, then chain ID will be undefined!
210
210
  const chainId = data.domain?.chainId;
@@ -217,7 +217,7 @@ class SnapKeyring extends events_1.EventEmitter {
217
217
  : {
218
218
  chainId: (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, `${chainId}`),
219
219
  }),
220
- }), keyring_internal_api_1.EthBytesStruct);
220
+ }), keyring_api_1.EthBytesStruct);
221
221
  }
222
222
  /**
223
223
  * Sign a message.
@@ -229,9 +229,9 @@ class SnapKeyring extends events_1.EventEmitter {
229
229
  async signMessage(address, hash) {
230
230
  return (0, util_1.strictMask)(await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
231
231
  address,
232
- method: keyring_internal_api_1.EthMethod.Sign,
232
+ method: keyring_api_1.EthMethod.Sign,
233
233
  params: (0, util_1.toJson)([address, hash]),
234
- }), keyring_internal_api_1.EthBytesStruct);
234
+ }), keyring_api_1.EthBytesStruct);
235
235
  }
236
236
  /**
237
237
  * Sign a personal message.
@@ -246,9 +246,9 @@ class SnapKeyring extends events_1.EventEmitter {
246
246
  async signPersonalMessage(address, data) {
247
247
  return (0, util_1.strictMask)(await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
248
248
  address,
249
- method: keyring_internal_api_1.EthMethod.PersonalSign,
249
+ method: keyring_api_1.EthMethod.PersonalSign,
250
250
  params: (0, util_1.toJson)([data, address]),
251
- }), keyring_internal_api_1.EthBytesStruct);
251
+ }), keyring_api_1.EthBytesStruct);
252
252
  }
253
253
  /**
254
254
  * Convert a base transaction to a base UserOperation.
@@ -261,12 +261,12 @@ class SnapKeyring extends events_1.EventEmitter {
261
261
  async prepareUserOperation(address, transactions, context) {
262
262
  return (0, util_1.strictMask)(await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
263
263
  address,
264
- method: keyring_internal_api_1.EthMethod.PrepareUserOperation,
264
+ method: keyring_api_1.EthMethod.PrepareUserOperation,
265
265
  params: (0, util_1.toJson)(transactions),
266
266
  noPending: true,
267
267
  // We assume the chain ID is already well formatted
268
268
  chainId: (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, context.chainId),
269
- }), keyring_internal_api_1.EthBaseUserOperationStruct);
269
+ }), keyring_api_1.EthBaseUserOperationStruct);
270
270
  }
271
271
  /**
272
272
  * Patches properties of a UserOperation. Currently, only the
@@ -280,12 +280,12 @@ class SnapKeyring extends events_1.EventEmitter {
280
280
  async patchUserOperation(address, userOp, context) {
281
281
  return (0, util_1.strictMask)(await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
282
282
  address,
283
- method: keyring_internal_api_1.EthMethod.PatchUserOperation,
283
+ method: keyring_api_1.EthMethod.PatchUserOperation,
284
284
  params: (0, util_1.toJson)([userOp]),
285
285
  noPending: true,
286
286
  // We assume the chain ID is already well formatted
287
287
  chainId: (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, context.chainId),
288
- }), keyring_internal_api_1.EthUserOperationPatchStruct);
288
+ }), keyring_api_1.EthUserOperationPatchStruct);
289
289
  }
290
290
  /**
291
291
  * Signs an UserOperation.
@@ -298,11 +298,11 @@ class SnapKeyring extends events_1.EventEmitter {
298
298
  async signUserOperation(address, userOp, context) {
299
299
  return (0, util_1.strictMask)(await __classPrivateFieldGet(this, _SnapKeyring_instances, "m", _SnapKeyring_submitRequest).call(this, {
300
300
  address,
301
- method: keyring_internal_api_1.EthMethod.SignUserOperation,
301
+ method: keyring_api_1.EthMethod.SignUserOperation,
302
302
  params: (0, util_1.toJson)([userOp]),
303
303
  // We assume the chain ID is already well formatted
304
304
  chainId: (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, context.chainId),
305
- }), keyring_internal_api_1.EthBytesStruct);
305
+ }), keyring_api_1.EthBytesStruct);
306
306
  }
307
307
  /**
308
308
  * Gets the private data associated with the given address so
@@ -390,7 +390,7 @@ _SnapKeyring_snapClient = new WeakMap(), _SnapKeyring_accounts = new WeakMap(),
390
390
  * @returns `null`.
391
391
  */
392
392
  async function _SnapKeyring_handleAccountCreated(snapId, message) {
393
- (0, superstruct_1.assert)(message, keyring_internal_api_1.AccountCreatedEventStruct);
393
+ (0, superstruct_1.assert)(message, keyring_api_1.AccountCreatedEventStruct);
394
394
  const { account, accountNameSuggestion, displayConfirmation } = message.params;
395
395
  // The UI still uses the account address to identify accounts, so we need
396
396
  // to block the creation of duplicate accounts for now to prevent accounts
@@ -420,7 +420,7 @@ async function _SnapKeyring_handleAccountCreated(snapId, message) {
420
420
  * @returns `null`.
421
421
  */
422
422
  async function _SnapKeyring_handleAccountUpdated(snapId, message) {
423
- (0, superstruct_1.assert)(message, keyring_internal_api_1.AccountUpdatedEventStruct);
423
+ (0, superstruct_1.assert)(message, keyring_api_1.AccountUpdatedEventStruct);
424
424
  const { account: newAccount } = message.params;
425
425
  const { account: oldAccount } = __classPrivateFieldGet(this, _SnapKeyring_accounts, "f").get(snapId, newAccount.id) ??
426
426
  (0, util_1.throwError)(`Account '${newAccount.id}' not found`);
@@ -442,7 +442,7 @@ async function _SnapKeyring_handleAccountUpdated(snapId, message) {
442
442
  * @returns `null`.
443
443
  */
444
444
  async function _SnapKeyring_handleAccountDeleted(snapId, message) {
445
- (0, superstruct_1.assert)(message, keyring_internal_api_1.AccountDeletedEventStruct);
445
+ (0, superstruct_1.assert)(message, keyring_api_1.AccountDeletedEventStruct);
446
446
  const { id } = message.params;
447
447
  const entry = __classPrivateFieldGet(this, _SnapKeyring_accounts, "f").get(snapId, id);
448
448
  // We can ignore the case where the account was already removed from the
@@ -471,7 +471,7 @@ async function _SnapKeyring_handleAccountDeleted(snapId, message) {
471
471
  * @returns `null`.
472
472
  */
473
473
  async function _SnapKeyring_handleRequestApproved(snapId, message) {
474
- (0, superstruct_1.assert)(message, keyring_internal_api_1.RequestApprovedEventStruct);
474
+ (0, superstruct_1.assert)(message, keyring_api_1.RequestApprovedEventStruct);
475
475
  const { id, result } = message.params;
476
476
  const { promise } = __classPrivateFieldGet(this, _SnapKeyring_requests, "f").get(snapId, id) ?? (0, util_1.throwError)(`Request '${id}' not found`);
477
477
  __classPrivateFieldGet(this, _SnapKeyring_requests, "f").delete(snapId, id);
@@ -486,7 +486,7 @@ async function _SnapKeyring_handleRequestApproved(snapId, message) {
486
486
  * @returns `null`.
487
487
  */
488
488
  async function _SnapKeyring_handleRequestRejected(snapId, message) {
489
- (0, superstruct_1.assert)(message, keyring_internal_api_1.RequestRejectedEventStruct);
489
+ (0, superstruct_1.assert)(message, keyring_api_1.RequestRejectedEventStruct);
490
490
  const { id } = message.params;
491
491
  const { promise } = __classPrivateFieldGet(this, _SnapKeyring_requests, "f").get(snapId, id) ?? (0, util_1.throwError)(`Request '${id}' not found`);
492
492
  __classPrivateFieldGet(this, _SnapKeyring_requests, "f").delete(snapId, id);
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,iFAAiF;;;;;;;;;;;;;;;AAGjF,uCAAoD;AAEpD,yDAA8D;AAc9D,yEAYwC;AACxC,uEAA4E;AAI5E,uDAAqE;AAErE,2CAIyB;AACzB,mCAAsC;AACtC,+BAAkC;AAElC,2DAAoD;AACpD,yCAAgD;AAChD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AAwB,MAAM,uCAAuC,MAAM,GAAG,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,IAAA,uBAAgB,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,IAAA,iBAAU,EAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,+BAAY,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AAjyBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n} from '@metamask/keyring-api';\nimport type {\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport {\n AccountCreatedEventStruct,\n AccountDeletedEventStruct,\n AccountUpdatedEventStruct,\n EthBaseUserOperationStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from '@metamask/keyring-internal-api';\nimport { KeyringSnapControllerClient } from '@metamask/keyring-snap-client';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport { projectLogger as log } from './logger';\nimport { SnapIdMap } from './SnapIdMap';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n strictMask,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n accountNameSuggestion?: string,\n displayConfirmation?: boolean,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringSnapControllerClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param controller - Snaps controller.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(controller: SnapController, callbacks: SnapKeyringCallbacks) {\n super();\n this.type = SnapKeyring.type;\n this.#snapClient = new KeyringSnapControllerClient({ controller });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const { account, accountNameSuggestion, displayConfirmation } =\n message.params;\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccount } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccount.id) ??\n throwError(`Account '${newAccount.id}' not found`);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Handle a message from a Snap.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n this.#accounts = SnapIdMap.fromObject(state.accounts);\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n [...this.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#snapClient.getController().get(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\n }\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\n );\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#snapClient.getController().get(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\n []\n );\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n });\n }\n}\n"]}
1
+ {"version":3,"file":"SnapKeyring.cjs","sourceRoot":"","sources":["../src/SnapKey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,KAAK,CAAC,SAAS,MAAM,cAAc,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,cAAc,GAAG,uBAAA,IAAI,kEAAuB,MAA3B,IAAI,EAAwB,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,uCAAuC,MAAM,GAAG,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,IAAA,uBAAgB,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,IAAA,iBAAU,EAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,+BAAY,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AAjyBM,gBAAI,GAAW,yBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the EthMethod, BtcMethod, and InternalAccount types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n InternalAccount,\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n} from '@metamask/keyring-api';\nimport {\n AccountCreatedEventStruct,\n AccountDeletedEventStruct,\n AccountUpdatedEventStruct,\n EthBaseUserOperationStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from '@metamask/keyring-api';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport { KeyringSnapControllerClient } from './KeyringSnapControllerClient';\nimport { projectLogger as log } from './logger';\nimport { SnapIdMap } from './SnapIdMap';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n strictMask,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n accountNameSuggestion?: string,\n displayConfirmation?: boolean,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringSnapControllerClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param controller - Snaps controller.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(controller: SnapController, callbacks: SnapKeyringCallbacks) {\n super();\n this.type = SnapKeyring.type;\n this.#snapClient = new KeyringSnapControllerClient({ controller });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const { account, accountNameSuggestion, displayConfirmation } =\n message.params;\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccount } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccount.id) ??\n throwError(`Account '${newAccount.id}' not found`);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Handle a message from a Snap.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n this.#accounts = SnapIdMap.fromObject(state.accounts);\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n [...this.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#snapClient.getController().get(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\n }\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\n );\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#snapClient.getController().get(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\n []\n );\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n });\n }\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  import type { TypedTransaction } from "@ethereumjs/tx";
2
2
  import type { TypedDataV1, TypedMessage } from "@metamask/eth-sig-util";
3
3
  import { SignTypedDataVersion } from "@metamask/eth-sig-util";
4
- import type { KeyringAccount, KeyringExecutionContext } from "@metamask/keyring-api";
5
- import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, InternalAccount } from "@metamask/keyring-internal-api";
4
+ import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, InternalAccount, KeyringAccount, KeyringExecutionContext } from "@metamask/keyring-api";
6
5
  import type { SnapController } from "@metamask/snaps-controllers";
7
6
  import type { SnapId } from "@metamask/snaps-sdk";
8
7
  import type { Json } from "@metamask/utils";
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.d.cts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EAExB,8BAA8B;AAC/B,OAAO,KAAK,EAEV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EAChB,uCAAuC;AAexC,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,EAAE,YAAY,EAAE,eAAe;AAMtC,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AA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M,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEnD;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAOjE;;;;OAIG;IACH,YAAY,IAAI,eAAe,EAAE;CA0BlC"}
@@ -1,8 +1,7 @@
1
1
  import type { TypedTransaction } from "@ethereumjs/tx";
2
2
  import type { TypedDataV1, TypedMessage } from "@metamask/eth-sig-util";
3
3
  import { SignTypedDataVersion } from "@metamask/eth-sig-util";
4
- import type { KeyringAccount, KeyringExecutionContext } from "@metamask/keyring-api";
5
- import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, InternalAccount } from "@metamask/keyring-internal-api";
4
+ import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, InternalAccount, KeyringAccount, KeyringExecutionContext } from "@metamask/keyring-api";
6
5
  import type { SnapController } from "@metamask/snaps-controllers";
7
6
  import type { SnapId } from "@metamask/snaps-sdk";
8
7
  import type { Json } from "@metamask/utils";
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.d.mts","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,+BAA+B;AACxE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAC9D,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EAExB,8BAA8B;AAC/B,OAAO,KAAK,EAEV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EAChB,uCAAuC;AAexC,OAAO,KAAK,EAAE,cAAc,EAAE,oCAAoC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAM5C,OAAO,EAAE,YAAY,EAAE,eAAe;AAMtC,OAAO,KA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IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkEnD;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAOjE;;;;OAIG;IACH,YAAY,IAAI,eAAe,EAAE;CA0BlC"}
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
2
2
  // This rule seems to be triggering a false positive. Possibly eslint is not
3
- // inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.
3
+ // inferring the EthMethod, BtcMethod, and InternalAccount types correctly.
4
4
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
5
5
  if (kind === "m") throw new TypeError("Private method is not writable");
6
6
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -16,13 +16,13 @@ var _SnapKeyring_instances, _SnapKeyring_snapClient, _SnapKeyring_accounts, _Sna
16
16
  import { TransactionFactory } from "@ethereumjs/tx";
17
17
  import $metamaskethsigutil from "@metamask/eth-sig-util";
18
18
  const { SignTypedDataVersion } = $metamaskethsigutil;
19
- import { AccountCreatedEventStruct, AccountDeletedEventStruct, AccountUpdatedEventStruct, EthBaseUserOperationStruct, EthBytesStruct, EthMethod, EthUserOperationPatchStruct, isEvmAccountType, KeyringEvent, RequestApprovedEventStruct, RequestRejectedEventStruct } from "@metamask/keyring-internal-api";
20
- import { KeyringSnapControllerClient } from "@metamask/keyring-snap-client";
19
+ import { AccountCreatedEventStruct, AccountDeletedEventStruct, AccountUpdatedEventStruct, EthBaseUserOperationStruct, EthBytesStruct, EthMethod, EthUserOperationPatchStruct, isEvmAccountType, KeyringEvent, RequestApprovedEventStruct, RequestRejectedEventStruct } from "@metamask/keyring-api";
21
20
  import { assert, mask, object, string } from "@metamask/superstruct";
22
21
  import { bigIntToHex, KnownCaipNamespace, toCaipChainId } from "@metamask/utils";
23
22
  import { EventEmitter } from "events";
24
23
  import { v4 as uuid } from "uuid";
25
24
  import { DeferredPromise } from "./DeferredPromise.mjs";
25
+ import { KeyringSnapControllerClient } from "./KeyringSnapControllerClient.mjs";
26
26
  import { projectLogger as log } from "./logger.mjs";
27
27
  import { SnapIdMap } from "./SnapIdMap.mjs";
28
28
  import { SnapMessageStruct } from "./types.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"SnapKeyring.mjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,iFAAiF;;;;;;;;;;;;;AAGjF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB;;;AAgBpD,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,cAAc,EACd,SAAS,EACT,2BAA2B,EAC3B,gBAAgB,EAChB,YAAY,EACZ,0BAA0B,EAC1B,0BAA0B,EAC3B,uCAAuC;AACxC,OAAO,EAAE,2BAA2B,EAAE,sCAAsC;AAI5E,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAErE,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC,OAAO,EAAE,eAAe,EAAE,8BAA0B;AACpD,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,qBAAiB;AAChD,OAAO,EAAE,SAAS,EAAE,wBAAoB;AAExC,OAAO,EAAE,iBAAiB,EAAE,oBAAgB;AAC5C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,MAAM,EACN,MAAM,EACP,mBAAe;AAEhB,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AA2ChD;;;;;GAKG;AACH,SAAS,uBAAuB,CAAC,OAAuB;IACtD,wFAAwF;I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ACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AAjyBM,gBAAI,GAAW,iBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the `EthMethod`, `BtcMethod`, and `InternalAccount` types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n} from '@metamask/keyring-api';\nimport type {\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n InternalAccount,\n} from '@metamask/keyring-internal-api';\nimport {\n AccountCreatedEventStruct,\n AccountDeletedEventStruct,\n AccountUpdatedEventStruct,\n EthBaseUserOperationStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from '@metamask/keyring-internal-api';\nimport { KeyringSnapControllerClient } from '@metamask/keyring-snap-client';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport { projectLogger as log } from './logger';\nimport { SnapIdMap } from './SnapIdMap';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n strictMask,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n accountNameSuggestion?: string,\n displayConfirmation?: boolean,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringSnapControllerClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param controller - Snaps controller.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(controller: SnapController, callbacks: SnapKeyringCallbacks) {\n super();\n this.type = SnapKeyring.type;\n this.#snapClient = new KeyringSnapControllerClient({ controller });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const { account, accountNameSuggestion, displayConfirmation } =\n message.params;\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccount } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccount.id) ??\n throwError(`Account '${newAccount.id}' not found`);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Handle a message from a Snap.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n this.#accounts = SnapIdMap.fromObject(state.accounts);\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n [...this.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#snapClient.getController().get(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\n }\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\n );\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#snapClient.getController().get(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\n []\n );\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n });\n }\n}\n"]}
1
+ {"version":3,"file":"SnapKeyring.mjs","sourceRoot":"","sources":["../src/SnapKeyring.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,2EAA2E;;;;;;;;;;;;;AAG3E,OAAO,EAAE,kBAAkB,EAAE,uBAAuB;;;AAcpD,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,cAAc,EACd,SAAS,EACT,2BAA2B,EAC3B,gBAAgB,EAChB,YAAY,EACZ,0BAA0B,EAC1B,0BAA0B,EAC3B,8BAA8B;AAI/B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAErE,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,aAAa,EACd,wBAAwB;AACzB,OAAO,EAAE,YAAY,EAAE,eAAe;AACtC,OAA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uCAAuC,MAAM,GAAG,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC,qEA+Pe,OAAe;IAI7B,OAAO,CACL,CAAC,GAAG,uBAAA,IAAI,6BAAU,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAChD,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAC3C,IAAI,UAAU,CAAC,YAAY,OAAO,aAAa,CAAC,CAClD,CAAC;AACJ,CAAC,uEASC,MAAc;IAEd,MAAM,IAAI,GAAG,uBAAA,IAAI,+BAAY,CAAC,aAAa,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,IAAI;QACT,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;QACzE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC,mFAQsB,IAAU;IAC/B,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,EAAE,cAAc;QACrE,EAAE,CACH,CAAC;AACJ,CAAC;AAjyBM,gBAAI,GAAW,iBAAiB,AAA5B,CAA6B","sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\n// This rule seems to be triggering a false positive. Possibly eslint is not\n// inferring the EthMethod, BtcMethod, and InternalAccount types correctly.\n\nimport type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { TypedDataV1, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type {\n BtcMethod,\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n InternalAccount,\n KeyringAccount,\n KeyringExecutionContext,\n KeyringResponse,\n} from '@metamask/keyring-api';\nimport {\n AccountCreatedEventStruct,\n AccountDeletedEventStruct,\n AccountUpdatedEventStruct,\n EthBaseUserOperationStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n isEvmAccountType,\n KeyringEvent,\n RequestApprovedEventStruct,\n RequestRejectedEventStruct,\n} from '@metamask/keyring-api';\nimport type { SnapController } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport { assert, mask, object, string } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n toCaipChainId,\n} from '@metamask/utils';\nimport { EventEmitter } from 'events';\nimport { v4 as uuid } from 'uuid';\n\nimport { DeferredPromise } from './DeferredPromise';\nimport { KeyringSnapControllerClient } from './KeyringSnapControllerClient';\nimport { projectLogger as log } from './logger';\nimport { SnapIdMap } from './SnapIdMap';\nimport type { SnapMessage } from './types';\nimport { SnapMessageStruct } from './types';\nimport {\n equalsIgnoreCase,\n sanitizeUrl,\n strictMask,\n throwError,\n toJson,\n unique,\n} from './util';\n\nexport const SNAP_KEYRING_TYPE = 'Snap Keyring';\n\n// TODO: to be removed when this is added to the keyring-api\n\ntype AccountMethod = EthMethod | BtcMethod;\n\n/**\n * Snap keyring state.\n *\n * This state is persisted by the keyring controller and passed to the Snap\n * keyring when it's created.\n */\nexport type KeyringState = {\n accounts: Record<string, { account: KeyringAccount; snapId: SnapId }>;\n};\n\n/**\n * Snap keyring callbacks.\n *\n * These callbacks are used to interact with other components.\n */\nexport type SnapKeyringCallbacks = {\n saveState: () => Promise<void>;\n\n addressExists(address: string): Promise<boolean>;\n\n addAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n accountNameSuggestion?: string,\n displayConfirmation?: boolean,\n ): Promise<void>;\n\n removeAccount(\n address: string,\n snapId: SnapId,\n handleUserInput: (accepted: boolean) => Promise<void>,\n ): Promise<void>;\n\n redirectUser(snapId: SnapId, url: string, message: string): Promise<void>;\n};\n\n/**\n * Normalize account's address.\n *\n * @param account - The account.\n * @returns The normalized account address.\n */\nfunction normalizeAccountAddress(account: KeyringAccount): string {\n // FIXME: Is it required to lowercase the address here? For now we'll keep this behavior\n // only for Ethereum addresses and use the original address for other non-EVM accounts.\n // For example, Solana addresses are case-sensitives.\n return isEvmAccountType(account.type)\n ? account.address.toLowerCase()\n : account.address;\n}\n\n/**\n * Keyring bridge implementation to support Snaps.\n */\nexport class SnapKeyring extends EventEmitter {\n static type: string = SNAP_KEYRING_TYPE;\n\n type: string;\n\n /**\n * Client used to call the Snap keyring.\n */\n readonly #snapClient: KeyringSnapControllerClient;\n\n /**\n * Mapping between account IDs and an object that contains the associated\n * account object and Snap ID.\n */\n #accounts: SnapIdMap<{\n account: KeyringAccount;\n snapId: SnapId;\n }>;\n\n /**\n * Mapping between request IDs and their deferred promises.\n */\n readonly #requests: SnapIdMap<{\n promise: DeferredPromise<any>;\n snapId: SnapId;\n }>;\n\n /**\n * Callbacks used to interact with other components.\n */\n readonly #callbacks: SnapKeyringCallbacks;\n\n /**\n * Create a new Snap keyring.\n *\n * @param controller - Snaps controller.\n * @param callbacks - Callbacks used to interact with other components.\n * @returns A new Snap keyring.\n */\n constructor(controller: SnapController, callbacks: SnapKeyringCallbacks) {\n super();\n this.type = SnapKeyring.type;\n this.#snapClient = new KeyringSnapControllerClient({ controller });\n this.#requests = new SnapIdMap();\n this.#accounts = new SnapIdMap();\n this.#callbacks = callbacks;\n }\n\n /**\n * Handle an Account Created event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountCreated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountCreatedEventStruct);\n const { account, accountNameSuggestion, displayConfirmation } =\n message.params;\n\n // The UI still uses the account address to identify accounts, so we need\n // to block the creation of duplicate accounts for now to prevent accounts\n // from being overwritten.\n const address = normalizeAccountAddress(account);\n if (await this.#callbacks.addressExists(address)) {\n throw new Error(`Account address '${address}' already exists`);\n }\n\n // A Snap could try to create an account with a different address but with\n // an existing ID, so the above test only is not enough.\n if (this.#accounts.has(snapId, account.id)) {\n throw new Error(`Account '${account.id}' already exists`);\n }\n\n await this.#callbacks.addAccount(\n address,\n snapId,\n async (accepted: boolean) => {\n if (accepted) {\n this.#accounts.set(account.id, { account, snapId });\n await this.#callbacks.saveState();\n }\n },\n accountNameSuggestion,\n displayConfirmation,\n );\n return null;\n }\n\n /**\n * Handle an Account Updated event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountUpdated(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountUpdatedEventStruct);\n const { account: newAccount } = message.params;\n const { account: oldAccount } =\n this.#accounts.get(snapId, newAccount.id) ??\n throwError(`Account '${newAccount.id}' not found`);\n\n // The address of the account cannot be changed. In the future, we will\n // support changing the address of an account since it will be required to\n // support UTXO-based chains.\n if (!equalsIgnoreCase(oldAccount.address, newAccount.address)) {\n throw new Error(`Cannot change address of account '${newAccount.id}'`);\n }\n\n this.#accounts.set(newAccount.id, { account: newAccount, snapId });\n await this.#callbacks.saveState();\n return null;\n }\n\n /**\n * Handle an Account Deleted event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleAccountDeleted(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, AccountDeletedEventStruct);\n const { id } = message.params;\n const entry = this.#accounts.get(snapId, id);\n\n // We can ignore the case where the account was already removed from the\n // keyring, making the deletion idempotent.\n //\n // This happens when the keyring calls the Snap to delete an account, and\n // the Snap calls the keyring back with an `AccountDeleted` event.\n if (entry === undefined) {\n return null;\n }\n\n // At this point we know that the account exists, so we can safely\n // destructure it.\n const { account } = entry;\n\n await this.#callbacks.removeAccount(\n normalizeAccountAddress(account),\n snapId,\n async (accepted) => {\n if (accepted) {\n await this.#callbacks.saveState();\n }\n },\n );\n return null;\n }\n\n /**\n * Handle an Request Approved event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestApproved(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestApprovedEventStruct);\n const { id, result } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.resolve(result);\n return null;\n }\n\n /**\n * Handle an Request Rejected event from a Snap.\n *\n * @param snapId - Snap ID.\n * @param message - Event message.\n * @returns `null`.\n */\n async #handleRequestRejected(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<null> {\n assert(message, RequestRejectedEventStruct);\n const { id } = message.params;\n const { promise } =\n this.#requests.get(snapId, id) ?? throwError(`Request '${id}' not found`);\n\n this.#requests.delete(snapId, id);\n promise.reject(new Error(`Request rejected by user or snap.`));\n return null;\n }\n\n /**\n * Handle a message from a Snap.\n *\n * @param snapId - ID of the Snap.\n * @param message - Message sent by the Snap.\n * @returns The execution result.\n */\n async handleKeyringSnapMessage(\n snapId: SnapId,\n message: SnapMessage,\n ): Promise<Json> {\n assert(message, SnapMessageStruct);\n switch (message.method) {\n case `${KeyringEvent.AccountCreated}`: {\n return this.#handleAccountCreated(snapId, message);\n }\n\n case `${KeyringEvent.AccountUpdated}`: {\n return this.#handleAccountUpdated(snapId, message);\n }\n\n case `${KeyringEvent.AccountDeleted}`: {\n return this.#handleAccountDeleted(snapId, message);\n }\n\n case `${KeyringEvent.RequestApproved}`: {\n return this.#handleRequestApproved(snapId, message);\n }\n\n case `${KeyringEvent.RequestRejected}`: {\n return this.#handleRequestRejected(snapId, message);\n }\n\n default:\n throw new Error(`Method not supported: ${message.method}`);\n }\n }\n\n /**\n * Serialize the keyring state.\n *\n * @returns Serialized keyring state.\n */\n async serialize(): Promise<KeyringState> {\n return {\n accounts: this.#accounts.toObject(),\n };\n }\n\n /**\n * Deserialize the keyring state into this keyring.\n *\n * @param state - Serialized keyring state.\n */\n async deserialize(state: KeyringState | undefined): Promise<void> {\n // If the state is undefined, it means that this is a new keyring, so we\n // don't need to do anything.\n if (state === undefined) {\n return;\n }\n this.#accounts = SnapIdMap.fromObject(state.accounts);\n }\n\n /**\n * Get the addresses of the accounts in this keyring.\n *\n * @returns The addresses of the accounts in this keyring.\n */\n async getAccounts(): Promise<string[]> {\n return unique(\n [...this.#accounts.values()].map(({ account }) =>\n normalizeAccountAddress(account),\n ),\n );\n }\n\n /**\n * Get the addresses of the accounts associated with a given Snap.\n *\n * @param snapId - Snap ID to filter by.\n * @returns The addresses of the accounts associated with the given Snap.\n */\n async getAccountsBySnapId(snapId: SnapId): Promise<string[]> {\n return unique(\n [...this.#accounts.values()]\n .filter(({ snapId: accountSnapId }) => accountSnapId === snapId)\n .map(({ account }) => normalizeAccountAddress(account)),\n );\n }\n\n /**\n * Submit a request to a Snap.\n *\n * @param opts - Request options.\n * @param opts.address - Account address.\n * @param opts.method - Method to call.\n * @param opts.params - Method parameters.\n * @param opts.chainId - Selected chain ID (CAIP-2).\n * @param opts.noPending - Whether the response is allowed to be pending.\n * @returns Promise that resolves to the result of the method call.\n */\n async #submitRequest<Response extends Json>({\n address,\n method,\n params,\n chainId = '',\n noPending = false,\n }: {\n address: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n chainId?: string;\n noPending?: boolean;\n }): Promise<Json> {\n const { account, snapId } = this.#resolveAddress(address);\n if (!this.#hasMethod(account, method as AccountMethod)) {\n throw new Error(\n `Method '${method}' not supported for account ${account.address}`,\n );\n }\n\n const requestId = uuid();\n\n // Create the promise before calling the Snap to prevent a race condition\n // where the Snap responds before we have a chance to create it.\n const promise = this.#createRequestPromise<Response>(requestId, snapId);\n\n const response = await this.#submitSnapRequest({\n snapId,\n requestId,\n account,\n method: method as AccountMethod,\n params,\n chainId,\n });\n\n // Some methods, like the ones used to prepare and patch user operations,\n // require the Snap to answer synchronously in order to work with the\n // confirmation flow. This check lets the caller enforce this behavior.\n if (noPending && response.pending) {\n throw new Error(\n `Request '${requestId}' to snap '${snapId}' is pending and noPending is true.`,\n );\n }\n\n // If the Snap answers synchronously, the promise must be removed from the\n // map to prevent a leak.\n if (!response.pending) {\n return this.#handleSyncResponse(response, requestId, snapId);\n }\n\n // If the Snap answers asynchronously, we will inform the user with a redirect\n if (response.redirect?.message || response.redirect?.url) {\n await this.#handleAsyncResponse(response.redirect, snapId);\n }\n\n return promise.promise;\n }\n\n /**\n * Check if an account supports the given method.\n *\n * @param account - The account object to check for method support.\n * @param method - The Ethereum method to validate.\n * @returns `true` if the method is supported, `false` otherwise.\n */\n #hasMethod(account: KeyringAccount, method: AccountMethod): boolean {\n return (account.methods as AccountMethod[]).includes(method);\n }\n\n /**\n * Creates a promise for a request and adds it to the map of requests.\n *\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns A DeferredPromise instance.\n */\n #createRequestPromise<Response>(\n requestId: string,\n snapId: SnapId,\n ): DeferredPromise<Response> {\n const promise = new DeferredPromise<Response>();\n this.#requests.set(requestId, { promise, snapId });\n return promise;\n }\n\n /**\n * Submits a request to a Snap.\n *\n * @param options - The options for the Snap request.\n * @param options.snapId - The Snap ID to submit the request to.\n * @param options.requestId - The unique identifier for the request.\n * @param options.account - The account to use for the request.\n * @param options.method - The Ethereum method to call.\n * @param options.params - The parameters to pass to the method, can be undefined.\n * @param options.chainId - The chain ID to use for the request, can be an empty string.\n * @returns A promise that resolves to the keyring response from the Snap.\n * @throws An error if the Snap fails to respond or if there's an issue with the request submission.\n */\n async #submitSnapRequest({\n snapId,\n requestId,\n account,\n method,\n params,\n chainId,\n }: {\n snapId: SnapId;\n requestId: string;\n account: KeyringAccount;\n method: AccountMethod;\n params?: Json[] | Record<string, Json> | undefined;\n chainId: string;\n }): Promise<KeyringResponse> {\n try {\n const request = {\n id: requestId,\n scope: chainId,\n account: account.id,\n request: {\n method,\n ...(params !== undefined && { params }),\n },\n };\n\n log('Submit Snap request: ', request);\n\n return await this.#snapClient.withSnapId(snapId).submitRequest(request);\n } catch (error) {\n log('Snap Request failed: ', { requestId });\n\n // If the Snap failed to respond, delete the promise to prevent a leak.\n this.#requests.delete(snapId, requestId);\n throw error;\n }\n }\n\n /**\n * Handles the synchronous response from a Snap. If the response indicates the request is not pending, it removes the request from the map.\n *\n * @param response - The response from the Snap.\n * @param response.pending - A boolean indicating if the request is pending should always be false in this context.\n * @param response.result - The result data from the Snap response.\n * @param requestId - The unique identifier for the request.\n * @param snapId - The Snap ID associated with the request.\n * @returns The result from the Snap response.\n */\n #handleSyncResponse(\n response: { pending: false; result: Json },\n requestId: string,\n snapId: SnapId,\n ): Json {\n this.#requests.delete(snapId, requestId);\n return response.result;\n }\n\n /**\n * Handles the async redirect and response from a Snap. Validates the redirect URL and informs the user with a message and URL if provided.\n *\n * @param redirect - The redirect information including message and URL.\n * @param redirect.message - The message to show to the user if provided.\n * @param redirect.url - The URL to redirect the user to if provided.\n * @param snapId - The Snap ID associated with the request.\n * @throws An error if the redirect URL is not an allowed origin for the Snap.\n */\n async #handleAsyncResponse(\n redirect: { message?: string; url?: string },\n snapId: SnapId,\n ): Promise<void> {\n const { message = '', url: redirectUrl = '' } = redirect;\n const url = this.#sanitizeRedirectUrl(redirectUrl);\n if (url) {\n this.#validateRedirectUrl(url, snapId);\n }\n await this.#callbacks.redirectUser(snapId, url, message);\n }\n\n /**\n * Sanitize a redirect URL.\n *\n * @param url - The URL to sanitize.\n * @returns The new sanitized redirect URL.\n */\n #sanitizeRedirectUrl(url: string): string {\n // We do check if the URL is empty or not since the Snap might not returns any URL at all.\n return url ? sanitizeUrl(url) : url;\n }\n\n /**\n * Validates if the redirect URL is in the Snap's allowed origins.\n *\n * @param url - The URL to validate.\n * @param snapId - The Snap ID to check allowed origins for.\n * @throws An error if the URL's origin is not in the Snap's allowed origins.\n */\n #validateRedirectUrl(url: string, snapId: SnapId): void {\n const { origin } = new URL(url);\n const snap = this.#snapClient.getController().get(snapId);\n if (!snap) {\n throw new Error(`Snap '${snapId}' not found.`);\n }\n const allowedOrigins = this.#getSnapAllowedOrigins(snap);\n if (!allowedOrigins.includes(origin)) {\n throw new Error(\n `Redirect URL domain '${origin}' is not an allowed origin by snap '${snapId}'`,\n );\n }\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @param _opts - Transaction options (not used).\n * @returns A promise that resolves to the signed transaction.\n */\n async signTransaction(\n address: string,\n transaction: TypedTransaction,\n _opts = {},\n ): Promise<Json | TypedTransaction> {\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: address,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest({\n address,\n method: EthMethod.SignTransaction,\n params: [tx],\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n });\n\n // ! It's *** CRITICAL *** that we mask the signature here, otherwise the\n // ! Snap could overwrite the transaction.\n const signature = mask(\n signedTx,\n object({\n r: string(),\n s: string(),\n v: string(),\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @param opts - Signing options.\n * @returns The signature.\n */\n async signTypedData(\n address: string,\n data: Record<string, unknown>[] | TypedDataV1 | TypedMessage<any>,\n opts = { version: SignTypedDataVersion.V1 },\n ): Promise<string> {\n const methods = {\n [SignTypedDataVersion.V1]: EthMethod.SignTypedDataV1,\n [SignTypedDataVersion.V3]: EthMethod.SignTypedDataV3,\n [SignTypedDataVersion.V4]: EthMethod.SignTypedDataV4,\n };\n\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n const method = methods[opts.version] || EthMethod.SignTypedDataV1;\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (data as TypedMessage<any>).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest({\n address,\n method,\n params: toJson<Json[]>([address, data]),\n ...(chainId === undefined\n ? {}\n : {\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, `${chainId}`),\n }),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param hash - Data to sign.\n * @returns The signature.\n */\n async signMessage(address: string, hash: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.Sign,\n params: toJson<Json[]>([address, hash]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns Promise of the signature.\n */\n async signPersonalMessage(address: string, data: any): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PersonalSign,\n params: toJson<Json[]>([data, address]),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PrepareUserOperation,\n params: toJson<Json[]>(transactions),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n */\n async patchUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.PatchUserOperation,\n params: toJson<Json[]>([userOp]),\n noPending: true,\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param context - Leyring execution context.\n * @returns The signature of the UserOperation.\n */\n async signUserOperation(\n address: string,\n userOp: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n return strictMask(\n await this.#submitRequest({\n address,\n method: EthMethod.SignUserOperation,\n params: toJson<Json[]>([userOp]),\n // We assume the chain ID is already well formatted\n chainId: toCaipChainId(KnownCaipNamespace.Eip155, context.chainId),\n }),\n EthBytesStruct,\n );\n }\n\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * If this keyring contains duplicate public keys the first\n * matching address is exported.\n *\n * Used by the UI to export an account.\n *\n * @param _address - Address of the account to export.\n */\n exportAccount(_address: string): [Uint8Array, Json] | undefined {\n throw new Error('Exporting accounts from snaps is not supported.');\n }\n\n /**\n * Removes the account matching the given address.\n *\n * @param address - Address of the account to remove.\n */\n async removeAccount(address: string): Promise<void> {\n const { account, snapId } = this.#resolveAddress(address);\n\n // Always remove the account from the maps, even if the Snap is going to\n // fail to delete it.\n this.#accounts.delete(snapId, account.id);\n\n try {\n await this.#snapClient.withSnapId(snapId).deleteAccount(account.id);\n } catch (error) {\n // If the Snap failed to delete the account, log the error and continue\n // with the account deletion, otherwise the account will be stuck in the\n // keyring.\n console.error(\n `Account '${address}' may not have been removed from snap '${snapId}':`,\n error,\n );\n }\n }\n\n /**\n * Resolve an address to an account and Snap ID.\n *\n * @param address - Address of the account to resolve.\n * @returns Account and Snap ID. Throws if the account or Snap ID is not\n * found.\n */\n #resolveAddress(address: string): {\n account: KeyringAccount;\n snapId: SnapId;\n } {\n return (\n [...this.#accounts.values()].find(({ account }) =>\n equalsIgnoreCase(account.address, address),\n ) ?? throwError(`Account '${address}' not found`)\n );\n }\n\n /**\n * Get the metadata of a Snap keyring account.\n *\n * @param snapId - Snap ID.\n * @returns The Snap metadata or undefined if the Snap cannot be found.\n */\n #getSnapMetadata(\n snapId: SnapId,\n ): InternalAccount['metadata']['snap'] | undefined {\n const snap = this.#snapClient.getController().get(snapId);\n return snap\n ? { id: snapId, name: snap.manifest.proposedName, enabled: snap.enabled }\n : undefined;\n }\n\n /**\n * Get the allowed origins of a Snap.\n *\n * @param snap - Snap.\n * @returns The allowed origins of the Snap.\n */\n #getSnapAllowedOrigins(snap: Snap): string[] {\n return (\n snap.manifest.initialPermissions['endowment:keyring']?.allowedOrigins ??\n []\n );\n }\n\n /**\n * Return an internal account object for a given address.\n *\n * @param address - Address of the account to return.\n * @returns An internal account object for the given address.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n const accounts = this.listAccounts();\n return accounts.find(({ address: accountAddress }) =>\n equalsIgnoreCase(accountAddress, address),\n );\n }\n\n /**\n * List all Snap keyring accounts.\n *\n * @returns An array containing all Snap keyring accounts.\n */\n listAccounts(): InternalAccount[] {\n return [...this.#accounts.values()].map(({ account, snapId }) => {\n const snap = this.#getSnapMetadata(snapId);\n return {\n ...account,\n // TODO: Do not convert the address to lowercase.\n //\n // This is a workaround to support the current UI which expects the\n // account address to be lowercase. This workaround should be removed\n // once we migrated the UI to use the account ID instead of the account\n // address.\n //\n // NOTE: We convert the address only for EVM accounts, see\n // `normalizeAccountAddress`.\n address: normalizeAccountAddress(account),\n metadata: {\n name: '',\n importTime: 0,\n keyring: {\n type: this.type,\n },\n ...(snap !== undefined && { snap }),\n },\n };\n });\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types.cjs"), exports);
18
18
  __exportStar(require("./SnapKeyring.cjs"), exports);
19
+ __exportStar(require("./KeyringSnapControllerClient.cjs"), exports);
19
20
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,oDAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,oDAA8B;AAC9B,oEAA8C","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\nexport * from './KeyringSnapControllerClient';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.cjs";
2
2
  export * from "./SnapKeyring.cjs";
3
+ export * from "./KeyringSnapControllerClient.cjs";
3
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B;AAC9B,kDAA8C"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.mjs";
2
2
  export * from "./SnapKeyring.mjs";
3
+ export * from "./KeyringSnapControllerClient.mjs";
3
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B;AAC9B,kDAA8C"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./types.mjs";
2
2
  export * from "./SnapKeyring.mjs";
3
+ export * from "./KeyringSnapControllerClient.mjs";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,kCAA8B;AAC9B,kDAA8C","sourcesContent":["export * from './types';\nexport * from './SnapKeyring';\nexport * from './KeyringSnapControllerClient';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/eth-snap-keyring",
3
- "version": "6.0.0-b85bfaa",
3
+ "version": "6.0.0-e345222",
4
4
  "description": "Snaps keyring bridge.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,15 +37,12 @@
37
37
  "dependencies": {
38
38
  "@ethereumjs/tx": "^4.2.0",
39
39
  "@metamask/eth-sig-util": "^8.0.0",
40
- "@metamask/keyring-api": "11.0.0",
41
- "@metamask/keyring-internal-api": "0.0.1",
42
- "@metamask/keyring-snap-client": "0.0.1",
43
- "@metamask/keyring-snap-sdk": "0.0.1",
40
+ "@metamask/keyring-api": "11.1.0",
44
41
  "@metamask/snaps-controllers": "^9.10.0",
45
42
  "@metamask/snaps-sdk": "^6.7.0",
46
43
  "@metamask/snaps-utils": "^8.3.0",
47
44
  "@metamask/superstruct": "^3.1.0",
48
- "@metamask/utils": "^9.2.1",
45
+ "@metamask/utils": "^9.3.0",
49
46
  "@types/uuid": "^9.0.8",
50
47
  "uuid": "^9.0.1"
51
48
  },