@metamask-previews/delegation-controller 0.1.0-preview-c555b24d → 0.1.0-preview-bb41e02a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.0]
11
+
10
12
  ### Added
11
13
 
12
14
  - Initial release ([#5592](https://github.com/MetaMask/core/pull/5592))
13
15
 
14
- [Unreleased]: https://github.com/MetaMask/core/
16
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/delegation-controller@0.1.0...HEAD
17
+ [0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/delegation-controller@0.1.0
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _DelegationController_hashDelegation, _DelegationController_getDelegationEnvironment;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.DelegationController = exports.controllerName = void 0;
4
16
  const base_controller_1 = require("@metamask/base-controller");
@@ -31,7 +43,16 @@ function getDefaultDelegationControllerState() {
31
43
  * This controller is meant to be a centralized place to store and sign delegations.
32
44
  */
33
45
  class DelegationController extends base_controller_1.BaseController {
34
- constructor({ messenger, state, hashDelegation, }) {
46
+ /**
47
+ * Constructs a new {@link DelegationController} instance.
48
+ *
49
+ * @param params - The parameters for constructing the controller.
50
+ * @param params.messenger - The messenger instance to use for the controller.
51
+ * @param params.state - The initial state for the controller.
52
+ * @param params.hashDelegation - A function to hash delegations.
53
+ * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
54
+ */
55
+ constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }) {
35
56
  super({
36
57
  messenger,
37
58
  metadata: delegationControllerMetadata,
@@ -41,7 +62,10 @@ class DelegationController extends base_controller_1.BaseController {
41
62
  ...state,
42
63
  },
43
64
  });
44
- this.hashDelegation = hashDelegation;
65
+ _DelegationController_hashDelegation.set(this, void 0);
66
+ _DelegationController_getDelegationEnvironment.set(this, void 0);
67
+ __classPrivateFieldSet(this, _DelegationController_hashDelegation, hashDelegation, "f");
68
+ __classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
45
69
  }
46
70
  /**
47
71
  * Signs a delegation.
@@ -49,20 +73,19 @@ class DelegationController extends base_controller_1.BaseController {
49
73
  * @param params - The parameters for signing the delegation.
50
74
  * @param params.delegation - The delegation to sign.
51
75
  * @param params.chainId - The chainId of the chain to sign the delegation for.
52
- * @param params.verifyingContract - The address of the verifying contract (DelegationManager).
53
76
  * @returns The signature of the delegation.
54
77
  */
55
78
  async signDelegation(params) {
56
- const { delegation, verifyingContract, chainId } = params;
57
- const account = this.messagingSystem.call('AccountsController:getSelectedAccount');
79
+ const { delegation, chainId } = params;
80
+ const { DelegationManager } = __classPrivateFieldGet(this, _DelegationController_getDelegationEnvironment, "f").call(this, chainId);
58
81
  const data = (0, utils_2.createTypedMessageParams)({
59
82
  chainId: (0, utils_1.hexToNumber)(chainId),
60
- from: account.address,
83
+ from: delegation.delegator,
61
84
  delegation: {
62
85
  ...delegation,
63
86
  signature: '0x',
64
87
  },
65
- verifyingContract,
88
+ verifyingContract: DelegationManager,
66
89
  });
67
90
  // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.
68
91
  // Waiting on confirmations team to implement this.
@@ -77,7 +100,7 @@ class DelegationController extends base_controller_1.BaseController {
77
100
  */
78
101
  store(params) {
79
102
  const { entry } = params;
80
- const hash = this.hashDelegation(entry.delegation);
103
+ const hash = __classPrivateFieldGet(this, _DelegationController_hashDelegation, "f").call(this, entry.delegation);
81
104
  // If the authority is not the root authority, validate that the
82
105
  // parent entry does exist.
83
106
  if (!(0, utils_2.isHexEqual)(entry.delegation.authority, constants_1.ROOT_AUTHORITY) &&
@@ -161,7 +184,6 @@ class DelegationController extends base_controller_1.BaseController {
161
184
  return 0;
162
185
  }
163
186
  const entries = Object.entries(this.state.delegations);
164
- let count = 0;
165
187
  const nextHashes = [hash];
166
188
  const deletedHashes = [];
167
189
  while (nextHashes.length > 0) {
@@ -173,7 +195,6 @@ class DelegationController extends base_controller_1.BaseController {
173
195
  nextHashes.push(k);
174
196
  });
175
197
  deletedHashes.push(currentHash);
176
- count += 1;
177
198
  }
178
199
  // Delete delegations
179
200
  this.update((state) => {
@@ -181,8 +202,9 @@ class DelegationController extends base_controller_1.BaseController {
181
202
  delete state.delegations[h];
182
203
  });
183
204
  });
184
- return count;
205
+ return deletedHashes.length;
185
206
  }
186
207
  }
187
208
  exports.DelegationController = DelegationController;
209
+ _DelegationController_hashDelegation = new WeakMap(), _DelegationController_getDelegationEnvironment = new WeakMap();
188
210
  //# sourceMappingURL=DelegationController.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController.cjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":";;;AACA,+DAA2D;AAC3D,qEAAoE;AACpE,2CAA8C;AAE9C,+CAA6C;AAW7C,uCAA+D;AAElD,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,4BA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L,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1ND,oDA0NC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport { hexToNumber } from '@metamask/utils';\n\nimport { ROOT_AUTHORITY } from './constants';\nimport type {\n Address,\n Delegation,\n DelegationControllerMessenger,\n DelegationControllerState,\n DelegationEntry,\n DelegationFilter,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams, isHexEqual } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst delegationControllerMetadata = {\n delegations: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<DelegationControllerState>;\n\n/**\n * Constructs the default {@link DelegationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link DelegationController} state.\n */\nfunction getDefaultDelegationControllerState(): DelegationControllerState {\n return {\n delegations: {},\n };\n}\n\n/**\n * The {@link DelegationController} class.\n * This controller is meant to be a centralized place to store and sign delegations.\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\n> {\n private readonly hashDelegation: (delegation: Delegation) => Hex;\n\n constructor({\n messenger,\n state,\n hashDelegation,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\n hashDelegation: (delegation: Delegation) => Hex;\n }) {\n super({\n messenger,\n metadata: delegationControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultDelegationControllerState(),\n ...state,\n },\n });\n this.hashDelegation = hashDelegation;\n }\n\n /**\n * Signs a delegation.\n *\n * @param params - The parameters for signing the delegation.\n * @param params.delegation - The delegation to sign.\n * @param params.chainId - The chainId of the chain to sign the delegation for.\n * @param params.verifyingContract - The address of the verifying contract (DelegationManager).\n * @returns The signature of the delegation.\n */\n async signDelegation(params: {\n delegation: UnsignedDelegation;\n chainId: Hex;\n verifyingContract: Address;\n }) {\n const { delegation, verifyingContract, chainId } = params;\n\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n\n const data = createTypedMessageParams({\n chainId: hexToNumber(chainId),\n from: account.address as Address,\n delegation: {\n ...delegation,\n signature: '0x',\n },\n verifyingContract,\n });\n\n // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.\n // Waiting on confirmations team to implement this.\n const signature: string = await this.messagingSystem.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n\n /**\n * Stores a delegation in storage.\n *\n * @param params - The parameters for storing the delegation.\n * @param params.entry - The delegation entry to store.\n */\n store(params: { entry: DelegationEntry }) {\n const { entry } = params;\n const hash = this.hashDelegation(entry.delegation);\n\n // If the authority is not the root authority, validate that the\n // parent entry does exist.\n if (\n !isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&\n !this.state.delegations[entry.delegation.authority]\n ) {\n throw new Error('Invalid authority');\n }\n this.update((state) => {\n state.delegations[hash] = entry;\n });\n }\n\n /**\n * Lists delegation entries.\n *\n * @param filter - The filter to use to list the delegation entries.\n * @returns A list of delegation entries that match the filter.\n */\n list(filter?: DelegationFilter) {\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const requester = account.address as Address;\n\n let list: DelegationEntry[] = Object.values(this.state.delegations);\n\n if (filter?.from) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegator, filter.from as Address),\n );\n }\n\n if (\n !filter?.from ||\n (filter?.from && !isHexEqual(filter.from, requester))\n ) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegate, requester),\n );\n }\n\n const filterChainId = filter?.chainId;\n if (filterChainId) {\n list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));\n }\n\n const tags = filter?.tags;\n if (tags && tags.length > 0) {\n // Filter entries that contain all of the filter tags\n list = list.filter((entry) =>\n tags.every((tag) => entry.tags.includes(tag)),\n );\n }\n\n return list;\n }\n\n /**\n * Retrieves the delegation entry for a given delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation entry, or null if not found.\n */\n retrieve(hash: Hex) {\n return this.state.delegations[hash] ?? null;\n }\n\n /**\n * Retrieves a delegation chain from a delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation chain, or null if not found.\n */\n chain(hash: Hex) {\n const chain: DelegationEntry[] = [];\n\n const entry = this.retrieve(hash);\n if (!entry) {\n return null;\n }\n chain.push(entry);\n\n for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY; ) {\n const parent = this.retrieve(_hash);\n if (!parent) {\n throw new Error('Invalid delegation chain');\n }\n chain.push(parent);\n _hash = parent.delegation.authority;\n }\n\n return chain;\n }\n\n /**\n * Deletes a delegation entrie from storage, along with any other entries\n * that are redelegated from it.\n *\n * @param hash - The hash of the delegation to delete.\n * @returns The number of entries deleted.\n */\n delete(hash: Hex): number {\n const root = this.retrieve(hash);\n if (!root) {\n return 0;\n }\n\n const entries = Object.entries(this.state.delegations);\n let count = 0;\n const nextHashes: Hex[] = [hash];\n const deletedHashes: Hex[] = [];\n\n while (nextHashes.length > 0) {\n const currentHash = nextHashes.pop() as Hex;\n\n // Find all delegations that have this hash as their authority\n const children = entries.filter(\n ([_, v]) => v.delegation.authority === currentHash,\n );\n\n // Add the hashes of all child delegations to be processed next\n children.forEach(([k]) => {\n nextHashes.push(k as Hex);\n });\n\n deletedHashes.push(currentHash);\n count += 1;\n }\n\n // Delete delegations\n this.update((state) => {\n deletedHashes.forEach((h) => {\n delete state.delegations[h];\n });\n });\n\n return count;\n }\n}\n"]}
1
+ {"version":3,"file":"DelegationController.cjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+DAA2D;AAC3D,qEAAoE;AACpE,2CAA8C;AAE9C,+CAA6C;AAY7C,uCAA+D;AAElD,QAAA,cAAc,GAA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C,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC1B,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC,MAAM,CAAC;IAC9B,CAAC;CACF;AAjOD,oDAiOC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport { hexToNumber } from '@metamask/utils';\n\nimport { ROOT_AUTHORITY } from './constants';\nimport type {\n Address,\n Delegation,\n DelegationControllerMessenger,\n DelegationControllerState,\n DelegationEntry,\n DelegationFilter,\n DeleGatorEnvironment,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams, isHexEqual } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst delegationControllerMetadata = {\n delegations: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<DelegationControllerState>;\n\n/**\n * Constructs the default {@link DelegationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link DelegationController} state.\n */\nfunction getDefaultDelegationControllerState(): DelegationControllerState {\n return {\n delegations: {},\n };\n}\n\n/**\n * The {@link DelegationController} class.\n * This controller is meant to be a centralized place to store and sign delegations.\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\n> {\n readonly #hashDelegation: (delegation: Delegation) => Hex;\n\n readonly #getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n\n /**\n * Constructs a new {@link DelegationController} instance.\n *\n * @param params - The parameters for constructing the controller.\n * @param params.messenger - The messenger instance to use for the controller.\n * @param params.state - The initial state for the controller.\n * @param params.hashDelegation - A function to hash delegations.\n * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.\n */\n constructor({\n messenger,\n state,\n hashDelegation,\n getDelegationEnvironment,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\n hashDelegation: (delegation: Delegation) => Hex;\n getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n }) {\n super({\n messenger,\n metadata: delegationControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultDelegationControllerState(),\n ...state,\n },\n });\n this.#hashDelegation = hashDelegation;\n this.#getDelegationEnvironment = getDelegationEnvironment;\n }\n\n /**\n * Signs a delegation.\n *\n * @param params - The parameters for signing the delegation.\n * @param params.delegation - The delegation to sign.\n * @param params.chainId - The chainId of the chain to sign the delegation for.\n * @returns The signature of the delegation.\n */\n async signDelegation(params: {\n delegation: UnsignedDelegation;\n chainId: Hex;\n }) {\n const { delegation, chainId } = params;\n const { DelegationManager } = this.#getDelegationEnvironment(chainId);\n\n const data = createTypedMessageParams({\n chainId: hexToNumber(chainId),\n from: delegation.delegator,\n delegation: {\n ...delegation,\n signature: '0x',\n },\n verifyingContract: DelegationManager,\n });\n\n // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.\n // Waiting on confirmations team to implement this.\n const signature: string = await this.messagingSystem.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n\n /**\n * Stores a delegation in storage.\n *\n * @param params - The parameters for storing the delegation.\n * @param params.entry - The delegation entry to store.\n */\n store(params: { entry: DelegationEntry }) {\n const { entry } = params;\n const hash = this.#hashDelegation(entry.delegation);\n\n // If the authority is not the root authority, validate that the\n // parent entry does exist.\n if (\n !isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&\n !this.state.delegations[entry.delegation.authority]\n ) {\n throw new Error('Invalid authority');\n }\n this.update((state) => {\n state.delegations[hash] = entry;\n });\n }\n\n /**\n * Lists delegation entries.\n *\n * @param filter - The filter to use to list the delegation entries.\n * @returns A list of delegation entries that match the filter.\n */\n list(filter?: DelegationFilter) {\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const requester = account.address as Address;\n\n let list: DelegationEntry[] = Object.values(this.state.delegations);\n\n if (filter?.from) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegator, filter.from as Address),\n );\n }\n\n if (\n !filter?.from ||\n (filter?.from && !isHexEqual(filter.from, requester))\n ) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegate, requester),\n );\n }\n\n const filterChainId = filter?.chainId;\n if (filterChainId) {\n list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));\n }\n\n const tags = filter?.tags;\n if (tags && tags.length > 0) {\n // Filter entries that contain all of the filter tags\n list = list.filter((entry) =>\n tags.every((tag) => entry.tags.includes(tag)),\n );\n }\n\n return list;\n }\n\n /**\n * Retrieves the delegation entry for a given delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation entry, or null if not found.\n */\n retrieve(hash: Hex) {\n return this.state.delegations[hash] ?? null;\n }\n\n /**\n * Retrieves a delegation chain from a delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation chain, or null if not found.\n */\n chain(hash: Hex) {\n const chain: DelegationEntry[] = [];\n\n const entry = this.retrieve(hash);\n if (!entry) {\n return null;\n }\n chain.push(entry);\n\n for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY; ) {\n const parent = this.retrieve(_hash);\n if (!parent) {\n throw new Error('Invalid delegation chain');\n }\n chain.push(parent);\n _hash = parent.delegation.authority;\n }\n\n return chain;\n }\n\n /**\n * Deletes a delegation entrie from storage, along with any other entries\n * that are redelegated from it.\n *\n * @param hash - The hash of the delegation to delete.\n * @returns The number of entries deleted.\n */\n delete(hash: Hex): number {\n const root = this.retrieve(hash);\n if (!root) {\n return 0;\n }\n\n const entries = Object.entries(this.state.delegations);\n const nextHashes: Hex[] = [hash];\n const deletedHashes: Hex[] = [];\n\n while (nextHashes.length > 0) {\n const currentHash = nextHashes.pop() as Hex;\n\n // Find all delegations that have this hash as their authority\n const children = entries.filter(\n ([_, v]) => v.delegation.authority === currentHash,\n );\n\n // Add the hashes of all child delegations to be processed next\n children.forEach(([k]) => {\n nextHashes.push(k as Hex);\n });\n\n deletedHashes.push(currentHash);\n }\n\n // Delete delegations\n this.update((state) => {\n deletedHashes.forEach((h) => {\n delete state.delegations[h];\n });\n });\n\n return deletedHashes.length;\n }\n}\n"]}
@@ -1,16 +1,26 @@
1
1
  import { BaseController } from "@metamask/base-controller";
2
- import type { Address, Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, Hex, UnsignedDelegation } from "./types.cjs";
2
+ import type { Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.cjs";
3
3
  export declare const controllerName = "DelegationController";
4
4
  /**
5
5
  * The {@link DelegationController} class.
6
6
  * This controller is meant to be a centralized place to store and sign delegations.
7
7
  */
8
8
  export declare class DelegationController extends BaseController<typeof controllerName, DelegationControllerState, DelegationControllerMessenger> {
9
- private readonly hashDelegation;
10
- constructor({ messenger, state, hashDelegation, }: {
9
+ #private;
10
+ /**
11
+ * Constructs a new {@link DelegationController} instance.
12
+ *
13
+ * @param params - The parameters for constructing the controller.
14
+ * @param params.messenger - The messenger instance to use for the controller.
15
+ * @param params.state - The initial state for the controller.
16
+ * @param params.hashDelegation - A function to hash delegations.
17
+ * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
18
+ */
19
+ constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }: {
11
20
  messenger: DelegationControllerMessenger;
12
21
  state?: Partial<DelegationControllerState>;
13
22
  hashDelegation: (delegation: Delegation) => Hex;
23
+ getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;
14
24
  });
15
25
  /**
16
26
  * Signs a delegation.
@@ -18,13 +28,11 @@ export declare class DelegationController extends BaseController<typeof controll
18
28
  * @param params - The parameters for signing the delegation.
19
29
  * @param params.delegation - The delegation to sign.
20
30
  * @param params.chainId - The chainId of the chain to sign the delegation for.
21
- * @param params.verifyingContract - The address of the verifying contract (DelegationManager).
22
31
  * @returns The signature of the delegation.
23
32
  */
24
33
  signDelegation(params: {
25
34
  delegation: UnsignedDelegation;
26
35
  chainId: Hex;
27
- verifyingContract: Address;
28
36
  }): Promise<string>;
29
37
  /**
30
38
  * Stores a delegation in storage.
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController.d.cts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAuBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;IACC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkC;gBAErD,EACV,SAAS,EACT,KAAK,EACL,cAAc,GACf,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,cAAc,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,GAAG,CAAC;KACjD;IAaD;;;;;;;;OAQG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;QACb,iBAAiB,EAAE,OAAO,CAAC;KAC5B;IA4BD;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE;IAiBxC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB;IAuC9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG;IAIlB;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,GAAG;IAqBf;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAqC1B"}
1
+ {"version":3,"file":"DelegationController.d.cts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,KAAK,EAEV,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAuBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAKC;;;;;;;;OAQG;gBACS,EACV,SAAS,EACT,KAAK,EACL,cAAc,EACd,wBAAwB,GACzB,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,cAAc,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,GAAG,CAAC;QAChD,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,oBAAoB,CAAC;KAClE;IAcD;;;;;;;OAOG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;KACd;IAyBD;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE;IAiBxC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB;IAuC9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG;IAIlB;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,GAAG;IAqBf;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAmC1B"}
@@ -1,16 +1,26 @@
1
1
  import { BaseController } from "@metamask/base-controller";
2
- import type { Address, Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, Hex, UnsignedDelegation } from "./types.mjs";
2
+ import type { Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.mjs";
3
3
  export declare const controllerName = "DelegationController";
4
4
  /**
5
5
  * The {@link DelegationController} class.
6
6
  * This controller is meant to be a centralized place to store and sign delegations.
7
7
  */
8
8
  export declare class DelegationController extends BaseController<typeof controllerName, DelegationControllerState, DelegationControllerMessenger> {
9
- private readonly hashDelegation;
10
- constructor({ messenger, state, hashDelegation, }: {
9
+ #private;
10
+ /**
11
+ * Constructs a new {@link DelegationController} instance.
12
+ *
13
+ * @param params - The parameters for constructing the controller.
14
+ * @param params.messenger - The messenger instance to use for the controller.
15
+ * @param params.state - The initial state for the controller.
16
+ * @param params.hashDelegation - A function to hash delegations.
17
+ * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
18
+ */
19
+ constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }: {
11
20
  messenger: DelegationControllerMessenger;
12
21
  state?: Partial<DelegationControllerState>;
13
22
  hashDelegation: (delegation: Delegation) => Hex;
23
+ getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;
14
24
  });
15
25
  /**
16
26
  * Signs a delegation.
@@ -18,13 +28,11 @@ export declare class DelegationController extends BaseController<typeof controll
18
28
  * @param params - The parameters for signing the delegation.
19
29
  * @param params.delegation - The delegation to sign.
20
30
  * @param params.chainId - The chainId of the chain to sign the delegation for.
21
- * @param params.verifyingContract - The address of the verifying contract (DelegationManager).
22
31
  * @returns The signature of the delegation.
23
32
  */
24
33
  signDelegation(params: {
25
34
  delegation: UnsignedDelegation;
26
35
  chainId: Hex;
27
- verifyingContract: Address;
28
36
  }): Promise<string>;
29
37
  /**
30
38
  * Stores a delegation in storage.
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController.d.mts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAuBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;IACC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAkC;gBAErD,EACV,SAAS,EACT,KAAK,EACL,cAAc,GACf,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,cAAc,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,GAAG,CAAC;KACjD;IAaD;;;;;;;;OAQG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;QACb,iBAAiB,EAAE,OAAO,CAAC;KAC5B;IA4BD;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE;IAiBxC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB;IAuC9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG;IAIlB;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,GAAG;IAqBf;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAqC1B"}
1
+ {"version":3,"file":"DelegationController.d.mts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,KAAK,EAEV,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAuBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAKC;;;;;;;;OAQG;gBACS,EACV,SAAS,EACT,KAAK,EACL,cAAc,EACd,wBAAwB,GACzB,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,cAAc,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,GAAG,CAAC;QAChD,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,oBAAoB,CAAC;KAClE;IAcD;;;;;;;OAOG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;KACd;IAyBD;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,eAAe,CAAA;KAAE;IAiBxC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,gBAAgB;IAuC9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,GAAG;IAIlB;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,GAAG;IAqBf;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM;CAmC1B"}
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _DelegationController_hashDelegation, _DelegationController_getDelegationEnvironment;
1
13
  import { BaseController } from "@metamask/base-controller";
2
14
  import { SignTypedDataVersion } from "@metamask/keyring-controller";
3
15
  import { hexToNumber } from "@metamask/utils";
@@ -28,7 +40,16 @@ function getDefaultDelegationControllerState() {
28
40
  * This controller is meant to be a centralized place to store and sign delegations.
29
41
  */
30
42
  export class DelegationController extends BaseController {
31
- constructor({ messenger, state, hashDelegation, }) {
43
+ /**
44
+ * Constructs a new {@link DelegationController} instance.
45
+ *
46
+ * @param params - The parameters for constructing the controller.
47
+ * @param params.messenger - The messenger instance to use for the controller.
48
+ * @param params.state - The initial state for the controller.
49
+ * @param params.hashDelegation - A function to hash delegations.
50
+ * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
51
+ */
52
+ constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }) {
32
53
  super({
33
54
  messenger,
34
55
  metadata: delegationControllerMetadata,
@@ -38,7 +59,10 @@ export class DelegationController extends BaseController {
38
59
  ...state,
39
60
  },
40
61
  });
41
- this.hashDelegation = hashDelegation;
62
+ _DelegationController_hashDelegation.set(this, void 0);
63
+ _DelegationController_getDelegationEnvironment.set(this, void 0);
64
+ __classPrivateFieldSet(this, _DelegationController_hashDelegation, hashDelegation, "f");
65
+ __classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
42
66
  }
43
67
  /**
44
68
  * Signs a delegation.
@@ -46,20 +70,19 @@ export class DelegationController extends BaseController {
46
70
  * @param params - The parameters for signing the delegation.
47
71
  * @param params.delegation - The delegation to sign.
48
72
  * @param params.chainId - The chainId of the chain to sign the delegation for.
49
- * @param params.verifyingContract - The address of the verifying contract (DelegationManager).
50
73
  * @returns The signature of the delegation.
51
74
  */
52
75
  async signDelegation(params) {
53
- const { delegation, verifyingContract, chainId } = params;
54
- const account = this.messagingSystem.call('AccountsController:getSelectedAccount');
76
+ const { delegation, chainId } = params;
77
+ const { DelegationManager } = __classPrivateFieldGet(this, _DelegationController_getDelegationEnvironment, "f").call(this, chainId);
55
78
  const data = createTypedMessageParams({
56
79
  chainId: hexToNumber(chainId),
57
- from: account.address,
80
+ from: delegation.delegator,
58
81
  delegation: {
59
82
  ...delegation,
60
83
  signature: '0x',
61
84
  },
62
- verifyingContract,
85
+ verifyingContract: DelegationManager,
63
86
  });
64
87
  // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.
65
88
  // Waiting on confirmations team to implement this.
@@ -74,7 +97,7 @@ export class DelegationController extends BaseController {
74
97
  */
75
98
  store(params) {
76
99
  const { entry } = params;
77
- const hash = this.hashDelegation(entry.delegation);
100
+ const hash = __classPrivateFieldGet(this, _DelegationController_hashDelegation, "f").call(this, entry.delegation);
78
101
  // If the authority is not the root authority, validate that the
79
102
  // parent entry does exist.
80
103
  if (!isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&
@@ -158,7 +181,6 @@ export class DelegationController extends BaseController {
158
181
  return 0;
159
182
  }
160
183
  const entries = Object.entries(this.state.delegations);
161
- let count = 0;
162
184
  const nextHashes = [hash];
163
185
  const deletedHashes = [];
164
186
  while (nextHashes.length > 0) {
@@ -170,7 +192,6 @@ export class DelegationController extends BaseController {
170
192
  nextHashes.push(k);
171
193
  });
172
194
  deletedHashes.push(currentHash);
173
- count += 1;
174
195
  }
175
196
  // Delete delegations
176
197
  this.update((state) => {
@@ -178,7 +199,8 @@ export class DelegationController extends BaseController {
178
199
  delete state.delegations[h];
179
200
  });
180
201
  });
181
- return count;
202
+ return deletedHashes.length;
182
203
  }
183
204
  }
205
+ _DelegationController_hashDelegation = new WeakMap(), _DelegationController_getDelegationEnvironment = new WeakMap();
184
206
  //# sourceMappingURL=DelegationController.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController.mjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,qCAAqC;AACpE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EAAE,cAAc,EAAE,wBAAoB;AAW7C,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,oBAAgB;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,4BAA4B,GAAG;IACnC,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACiD,CAAC;AAErD;;;;;;;GAOG;AACH,SAAS,mCAAmC;IAC1C,OAAO;QACL,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAIzC;IAGC,YAAY,EACV,SAAS,EACT,KAAK,EACL,cAAc,GAKf;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,4BAA4B;YACtC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,mCAAmC,EAAE;gBACxC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,cAAc,CAAC,MAIpB;QACC,MAAM,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,G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B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,KAAK,WAAW,CACnD,CAAC;YAEF,+DAA+D;YAC/D,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvB,UAAU,CAAC,IAAI,CAAC,CAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAChC,KAAK,IAAI,CAAC,CAAC;SACZ;QAED,qBAAqB;QACrB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC1B,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport { hexToNumber } from '@metamask/utils';\n\nimport { ROOT_AUTHORITY } from './constants';\nimport type {\n Address,\n Delegation,\n DelegationControllerMessenger,\n DelegationControllerState,\n DelegationEntry,\n DelegationFilter,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams, isHexEqual } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst delegationControllerMetadata = {\n delegations: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<DelegationControllerState>;\n\n/**\n * Constructs the default {@link DelegationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link DelegationController} state.\n */\nfunction getDefaultDelegationControllerState(): DelegationControllerState {\n return {\n delegations: {},\n };\n}\n\n/**\n * The {@link DelegationController} class.\n * This controller is meant to be a centralized place to store and sign delegations.\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\n> {\n private readonly hashDelegation: (delegation: Delegation) => Hex;\n\n constructor({\n messenger,\n state,\n hashDelegation,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\n hashDelegation: (delegation: Delegation) => Hex;\n }) {\n super({\n messenger,\n metadata: delegationControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultDelegationControllerState(),\n ...state,\n },\n });\n this.hashDelegation = hashDelegation;\n }\n\n /**\n * Signs a delegation.\n *\n * @param params - The parameters for signing the delegation.\n * @param params.delegation - The delegation to sign.\n * @param params.chainId - The chainId of the chain to sign the delegation for.\n * @param params.verifyingContract - The address of the verifying contract (DelegationManager).\n * @returns The signature of the delegation.\n */\n async signDelegation(params: {\n delegation: UnsignedDelegation;\n chainId: Hex;\n verifyingContract: Address;\n }) {\n const { delegation, verifyingContract, chainId } = params;\n\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n\n const data = createTypedMessageParams({\n chainId: hexToNumber(chainId),\n from: account.address as Address,\n delegation: {\n ...delegation,\n signature: '0x',\n },\n verifyingContract,\n });\n\n // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.\n // Waiting on confirmations team to implement this.\n const signature: string = await this.messagingSystem.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n\n /**\n * Stores a delegation in storage.\n *\n * @param params - The parameters for storing the delegation.\n * @param params.entry - The delegation entry to store.\n */\n store(params: { entry: DelegationEntry }) {\n const { entry } = params;\n const hash = this.hashDelegation(entry.delegation);\n\n // If the authority is not the root authority, validate that the\n // parent entry does exist.\n if (\n !isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&\n !this.state.delegations[entry.delegation.authority]\n ) {\n throw new Error('Invalid authority');\n }\n this.update((state) => {\n state.delegations[hash] = entry;\n });\n }\n\n /**\n * Lists delegation entries.\n *\n * @param filter - The filter to use to list the delegation entries.\n * @returns A list of delegation entries that match the filter.\n */\n list(filter?: DelegationFilter) {\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const requester = account.address as Address;\n\n let list: DelegationEntry[] = Object.values(this.state.delegations);\n\n if (filter?.from) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegator, filter.from as Address),\n );\n }\n\n if (\n !filter?.from ||\n (filter?.from && !isHexEqual(filter.from, requester))\n ) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegate, requester),\n );\n }\n\n const filterChainId = filter?.chainId;\n if (filterChainId) {\n list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));\n }\n\n const tags = filter?.tags;\n if (tags && tags.length > 0) {\n // Filter entries that contain all of the filter tags\n list = list.filter((entry) =>\n tags.every((tag) => entry.tags.includes(tag)),\n );\n }\n\n return list;\n }\n\n /**\n * Retrieves the delegation entry for a given delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation entry, or null if not found.\n */\n retrieve(hash: Hex) {\n return this.state.delegations[hash] ?? null;\n }\n\n /**\n * Retrieves a delegation chain from a delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation chain, or null if not found.\n */\n chain(hash: Hex) {\n const chain: DelegationEntry[] = [];\n\n const entry = this.retrieve(hash);\n if (!entry) {\n return null;\n }\n chain.push(entry);\n\n for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY; ) {\n const parent = this.retrieve(_hash);\n if (!parent) {\n throw new Error('Invalid delegation chain');\n }\n chain.push(parent);\n _hash = parent.delegation.authority;\n }\n\n return chain;\n }\n\n /**\n * Deletes a delegation entrie from storage, along with any other entries\n * that are redelegated from it.\n *\n * @param hash - The hash of the delegation to delete.\n * @returns The number of entries deleted.\n */\n delete(hash: Hex): number {\n const root = this.retrieve(hash);\n if (!root) {\n return 0;\n }\n\n const entries = Object.entries(this.state.delegations);\n let count = 0;\n const nextHashes: Hex[] = [hash];\n const deletedHashes: Hex[] = [];\n\n while (nextHashes.length > 0) {\n const currentHash = nextHashes.pop() as Hex;\n\n // Find all delegations that have this hash as their authority\n const children = entries.filter(\n ([_, v]) => v.delegation.authority === currentHash,\n );\n\n // Add the hashes of all child delegations to be processed next\n children.forEach(([k]) => {\n nextHashes.push(k as Hex);\n });\n\n deletedHashes.push(currentHash);\n count += 1;\n }\n\n // Delete delegations\n this.update((state) => {\n deletedHashes.forEach((h) => {\n delete state.delegations[h];\n });\n });\n\n return count;\n }\n}\n"]}
1
+ {"version":3,"file":"DelegationController.mjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,qCAAqC;AACpE,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EAAE,cAAc,EAAE,wBAAoB;AAY7C,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,oBAAgB;AAE/D,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,4BAA4B,GAAG;IACnC,WAAW,EAAE;QACX,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACiD,CAAC;AAErD;;;;;;;GAOG;AACH,SAAS,mCAAmC;IAC1C,OAAO;QACL,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAIzC;IAKC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,cAAc,EACd,wBAAwB,GAMzB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,4BAA4B;YACtC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,mCAAmC,EAAE;gBACxC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QAhCI,uDAAiD;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GAAU,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,aAAa,GAAU,EAAE,CAAC;QAEhC,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,EAAS,CAAC;YAE5C,8DAA8D;YAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAC7B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,KAAK,WAAW,CACnD,CAAC;YAEF,+DAA+D;YAC/D,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvB,UAAU,CAAC,IAAI,CAAC,CAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SACjC;QAED,qBAAqB;QACrB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC1B,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC,MAAM,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport { hexToNumber } from '@metamask/utils';\n\nimport { ROOT_AUTHORITY } from './constants';\nimport type {\n Address,\n Delegation,\n DelegationControllerMessenger,\n DelegationControllerState,\n DelegationEntry,\n DelegationFilter,\n DeleGatorEnvironment,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams, isHexEqual } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst delegationControllerMetadata = {\n delegations: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<DelegationControllerState>;\n\n/**\n * Constructs the default {@link DelegationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link DelegationController} state.\n */\nfunction getDefaultDelegationControllerState(): DelegationControllerState {\n return {\n delegations: {},\n };\n}\n\n/**\n * The {@link DelegationController} class.\n * This controller is meant to be a centralized place to store and sign delegations.\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\n> {\n readonly #hashDelegation: (delegation: Delegation) => Hex;\n\n readonly #getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n\n /**\n * Constructs a new {@link DelegationController} instance.\n *\n * @param params - The parameters for constructing the controller.\n * @param params.messenger - The messenger instance to use for the controller.\n * @param params.state - The initial state for the controller.\n * @param params.hashDelegation - A function to hash delegations.\n * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.\n */\n constructor({\n messenger,\n state,\n hashDelegation,\n getDelegationEnvironment,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\n hashDelegation: (delegation: Delegation) => Hex;\n getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n }) {\n super({\n messenger,\n metadata: delegationControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultDelegationControllerState(),\n ...state,\n },\n });\n this.#hashDelegation = hashDelegation;\n this.#getDelegationEnvironment = getDelegationEnvironment;\n }\n\n /**\n * Signs a delegation.\n *\n * @param params - The parameters for signing the delegation.\n * @param params.delegation - The delegation to sign.\n * @param params.chainId - The chainId of the chain to sign the delegation for.\n * @returns The signature of the delegation.\n */\n async signDelegation(params: {\n delegation: UnsignedDelegation;\n chainId: Hex;\n }) {\n const { delegation, chainId } = params;\n const { DelegationManager } = this.#getDelegationEnvironment(chainId);\n\n const data = createTypedMessageParams({\n chainId: hexToNumber(chainId),\n from: delegation.delegator,\n delegation: {\n ...delegation,\n signature: '0x',\n },\n verifyingContract: DelegationManager,\n });\n\n // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.\n // Waiting on confirmations team to implement this.\n const signature: string = await this.messagingSystem.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n\n /**\n * Stores a delegation in storage.\n *\n * @param params - The parameters for storing the delegation.\n * @param params.entry - The delegation entry to store.\n */\n store(params: { entry: DelegationEntry }) {\n const { entry } = params;\n const hash = this.#hashDelegation(entry.delegation);\n\n // If the authority is not the root authority, validate that the\n // parent entry does exist.\n if (\n !isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&\n !this.state.delegations[entry.delegation.authority]\n ) {\n throw new Error('Invalid authority');\n }\n this.update((state) => {\n state.delegations[hash] = entry;\n });\n }\n\n /**\n * Lists delegation entries.\n *\n * @param filter - The filter to use to list the delegation entries.\n * @returns A list of delegation entries that match the filter.\n */\n list(filter?: DelegationFilter) {\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const requester = account.address as Address;\n\n let list: DelegationEntry[] = Object.values(this.state.delegations);\n\n if (filter?.from) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegator, filter.from as Address),\n );\n }\n\n if (\n !filter?.from ||\n (filter?.from && !isHexEqual(filter.from, requester))\n ) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegate, requester),\n );\n }\n\n const filterChainId = filter?.chainId;\n if (filterChainId) {\n list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));\n }\n\n const tags = filter?.tags;\n if (tags && tags.length > 0) {\n // Filter entries that contain all of the filter tags\n list = list.filter((entry) =>\n tags.every((tag) => entry.tags.includes(tag)),\n );\n }\n\n return list;\n }\n\n /**\n * Retrieves the delegation entry for a given delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation entry, or null if not found.\n */\n retrieve(hash: Hex) {\n return this.state.delegations[hash] ?? null;\n }\n\n /**\n * Retrieves a delegation chain from a delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation chain, or null if not found.\n */\n chain(hash: Hex) {\n const chain: DelegationEntry[] = [];\n\n const entry = this.retrieve(hash);\n if (!entry) {\n return null;\n }\n chain.push(entry);\n\n for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY; ) {\n const parent = this.retrieve(_hash);\n if (!parent) {\n throw new Error('Invalid delegation chain');\n }\n chain.push(parent);\n _hash = parent.delegation.authority;\n }\n\n return chain;\n }\n\n /**\n * Deletes a delegation entrie from storage, along with any other entries\n * that are redelegated from it.\n *\n * @param hash - The hash of the delegation to delete.\n * @returns The number of entries deleted.\n */\n delete(hash: Hex): number {\n const root = this.retrieve(hash);\n if (!root) {\n return 0;\n }\n\n const entries = Object.entries(this.state.delegations);\n const nextHashes: Hex[] = [hash];\n const deletedHashes: Hex[] = [];\n\n while (nextHashes.length > 0) {\n const currentHash = nextHashes.pop() as Hex;\n\n // Find all delegations that have this hash as their authority\n const children = entries.filter(\n ([_, v]) => v.delegation.authority === currentHash,\n );\n\n // Add the hashes of all child delegations to be processed next\n children.forEach(([k]) => {\n nextHashes.push(k as Hex);\n });\n\n deletedHashes.push(currentHash);\n }\n\n // Delete delegations\n this.update((state) => {\n deletedHashes.forEach((h) => {\n delete state.delegations[h];\n });\n });\n\n return deletedHashes.length;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\n/**\n * A version agnostic blob of contract addresses required for the DeleGator system to function.\n */\nexport type DeleGatorEnvironment = {\n DelegationManager: Hex;\n EntryPoint: Hex;\n SimpleFactory: Hex;\n implementations: {\n [implementation: string]: Hex;\n };\n caveatEnforcers: {\n [enforcer: string]: Hex;\n };\n};\n\n/**\n * A delegation caveat is a condition that must be met in order for a delegation\n * to be valid. The caveat is defined by an enforcer, terms, and arguments.\n *\n * @see https://docs.gator.metamask.io/concepts/caveat-enforcers\n */\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
package/dist/types.d.cts CHANGED
@@ -5,6 +5,26 @@ import type { controllerName, DelegationController } from "./DelegationControlle
5
5
  type Hex = `0x${string}`;
6
6
  type Address = `0x${string}`;
7
7
  export type { Address, Hex };
8
+ /**
9
+ * A version agnostic blob of contract addresses required for the DeleGator system to function.
10
+ */
11
+ export type DeleGatorEnvironment = {
12
+ DelegationManager: Hex;
13
+ EntryPoint: Hex;
14
+ SimpleFactory: Hex;
15
+ implementations: {
16
+ [implementation: string]: Hex;
17
+ };
18
+ caveatEnforcers: {
19
+ [enforcer: string]: Hex;
20
+ };
21
+ };
22
+ /**
23
+ * A delegation caveat is a condition that must be met in order for a delegation
24
+ * to be valid. The caveat is defined by an enforcer, terms, and arguments.
25
+ *
26
+ * @see https://docs.gator.metamask.io/concepts/caveat-enforcers
27
+ */
8
28
  export type Caveat = {
9
29
  enforcer: Hex;
10
30
  terms: Hex;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CAA0C,EAAE,sCAAsC;AAChG,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,qCAAqC;AAE5F,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,mCAA+B;AAEhC,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AACzB,KAAK,OAAO,GAAG,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Controller } from "./DelegationControlle
5
5
  type Hex = `0x${string}`;
6
6
  type Address = `0x${string}`;
7
7
  export type { Address, Hex };
8
+ /**
9
+ * A version agnostic blob of contract addresses required for the DeleGator system to function.
10
+ */
11
+ export type DeleGatorEnvironment = {
12
+ DelegationManager: Hex;
13
+ EntryPoint: Hex;
14
+ SimpleFactory: Hex;
15
+ implementations: {
16
+ [implementation: string]: Hex;
17
+ };
18
+ caveatEnforcers: {
19
+ [enforcer: string]: Hex;
20
+ };
21
+ };
22
+ /**
23
+ * A delegation caveat is a condition that must be met in order for a delegation
24
+ * to be valid. The caveat is defined by an enforcer, terms, and arguments.
25
+ *
26
+ * @see https://docs.gator.metamask.io/concepts/caveat-enforcers
27
+ */
8
28
  export type Caveat = {
9
29
  enforcer: Hex;
10
30
  terms: Hex;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0CAA0C,EAAE,sCAAsC;AAChG,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,qCAAqC;AAE5F,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,mCAA+B;AAEhC,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AACzB,KAAK,OAAO,GAAG,KAAK,MAAM,EAAE,CAAC;AAE7B,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAE7B,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,mCAAmC;IACnC,QAAQ,EAAE,GAAG,CAAC;IACd,oCAAoC;IACpC,SAAS,EAAE,GAAG,CAAC;IACf,+FAA+F;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A+B,GAAG;IAC5C,IAAI,EAAE,GAAG,OAAO,cAAc,QAAQ,CAAC;IACvC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,GAAG,OAAO,cAAc,SAAS,CAAC;IACxC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,kCAAkC,GAClC,wCAAwC,GACxC,+BAA+B,GAC/B,8BAA8B,GAC9B,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,CAAC;AAErC,MAAM,MAAM,oCAAoC,GAAG,0BAA0B,CAC3E,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E,KAAK,cAAc,GACf,uCAAuC,GACvC,0CAA0C,CAAC;AAE/C,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,6BAA6B,GAAG,mBAAmB,CAC7D,OAAO,cAAc,EACrB,2BAA2B,GAAG,cAAc,EAC5C,0BAA0B,GAAG,aAAa,EAC1C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\n/**\n * A version agnostic blob of contract addresses required for the DeleGator system to function.\n */\nexport type DeleGatorEnvironment = {\n DelegationManager: Hex;\n EntryPoint: Hex;\n SimpleFactory: Hex;\n implementations: {\n [implementation: string]: Hex;\n };\n caveatEnforcers: {\n [enforcer: string]: Hex;\n };\n};\n\n/**\n * A delegation caveat is a condition that must be met in order for a delegation\n * to be valid. The caveat is defined by an enforcer, terms, and arguments.\n *\n * @see https://docs.gator.metamask.io/concepts/caveat-enforcers\n */\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/delegation-controller",
3
- "version": "0.1.0-preview-c555b24d",
3
+ "version": "0.1.0-preview-bb41e02a",
4
4
  "description": "Manages delegations for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -48,12 +48,12 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@metamask/base-controller": "^8.0.0",
51
- "@metamask/keyring-controller": "^21.0.2",
52
51
  "@metamask/utils": "^11.2.0"
53
52
  },
54
53
  "devDependencies": {
55
54
  "@metamask/accounts-controller": "^27.0.0",
56
55
  "@metamask/auto-changelog": "^3.4.4",
56
+ "@metamask/keyring-controller": "^21.0.3",
57
57
  "@ts-bridge/cli": "^0.6.1",
58
58
  "@types/jest": "^27.4.1",
59
59
  "deepmerge": "^4.2.2",
@@ -64,7 +64,8 @@
64
64
  "typescript": "~5.2.2"
65
65
  },
66
66
  "peerDependencies": {
67
- "@metamask/accounts-controller": "^27.0.0"
67
+ "@metamask/accounts-controller": "^27.0.0",
68
+ "@metamask/keyring-controller": "^21.0.2"
68
69
  },
69
70
  "engines": {
70
71
  "node": "^18.18 || >=20"