@metamask-previews/delegation-controller 2.1.0-preview-dff83af4c → 2.1.0-preview-6b4f746

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +1 -1
  3. package/dist/DelegationController-method-action-types.cjs.map +1 -1
  4. package/dist/DelegationController-method-action-types.d.cts +1 -52
  5. package/dist/DelegationController-method-action-types.d.cts.map +1 -1
  6. package/dist/DelegationController-method-action-types.d.mts +1 -52
  7. package/dist/DelegationController-method-action-types.d.mts.map +1 -1
  8. package/dist/DelegationController-method-action-types.mjs.map +1 -1
  9. package/dist/DelegationController.cjs +7 -139
  10. package/dist/DelegationController.cjs.map +1 -1
  11. package/dist/DelegationController.d.cts +3 -43
  12. package/dist/DelegationController.d.cts.map +1 -1
  13. package/dist/DelegationController.d.mts +3 -43
  14. package/dist/DelegationController.d.mts.map +1 -1
  15. package/dist/DelegationController.mjs +8 -140
  16. package/dist/DelegationController.mjs.map +1 -1
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +2 -2
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/types.cjs.map +1 -1
  24. package/dist/types.d.cts +2 -18
  25. package/dist/types.d.cts.map +1 -1
  26. package/dist/types.d.mts +2 -18
  27. package/dist/types.d.mts.map +1 -1
  28. package/dist/types.mjs.map +1 -1
  29. package/dist/utils.cjs +1 -12
  30. package/dist/utils.cjs.map +1 -1
  31. package/dist/utils.d.cts +1 -9
  32. package/dist/utils.d.cts.map +1 -1
  33. package/dist/utils.d.mts +1 -9
  34. package/dist/utils.d.mts.map +1 -1
  35. package/dist/utils.mjs +0 -10
  36. package/dist/utils.mjs.map +1 -1
  37. package/package.json +1 -2
package/CHANGELOG.md CHANGED
@@ -9,10 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - Bump `@metamask/accounts-controller` from `^37.1.0` to `^37.2.0` ([#8325](https://github.com/MetaMask/core/pull/8325), [#8363](https://github.com/MetaMask/core/pull/8363))
13
12
  - Bump `@metamask/keyring-controller` from `^25.1.1` to `^25.2.0` ([#8363](https://github.com/MetaMask/core/pull/8363))
14
13
  - Bump `@metamask/messenger` from `^1.0.0` to `^1.1.1` ([#8364](https://github.com/MetaMask/core/pull/8364), [#8373](https://github.com/MetaMask/core/pull/8373))
15
14
 
15
+ ### Removed
16
+
17
+ - **BREAKING:** Remove persisted `delegations` state ([#8330](https://github.com/MetaMask/core/pull/8330))
18
+ - `store`, `list`, `retrieve`, `chain`, and `delete` methods (and related messenger action types)
19
+ - `DelegationEntry` type export
20
+ - Remove dependency on `@metamask/accounts-controller` - callers no longer need to delegate the `AccountsController:getSelectedAccount` action to the `DelegationController` messenger
21
+
16
22
  ## [2.1.0]
17
23
 
18
24
  ### Added
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # `@metamask/delegation-controller`
2
2
 
3
- Centralized place to store and sign delegations.
3
+ Signs delegations via the keyring using the Delegation Framework typed-data format.
4
4
 
5
5
  ## Installation
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController-method-action-types.cjs","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { DelegationController } from './DelegationController';\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 */\nexport type DelegationControllerSignDelegationAction = {\n type: `DelegationController:signDelegation`;\n handler: DelegationController['signDelegation'];\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 */\nexport type DelegationControllerStoreAction = {\n type: `DelegationController:store`;\n handler: DelegationController['store'];\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 */\nexport type DelegationControllerListAction = {\n type: `DelegationController:list`;\n handler: DelegationController['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 */\nexport type DelegationControllerRetrieveAction = {\n type: `DelegationController:retrieve`;\n handler: DelegationController['retrieve'];\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 */\nexport type DelegationControllerChainAction = {\n type: `DelegationController:chain`;\n handler: DelegationController['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 */\nexport type DelegationControllerDeleteAction = {\n type: `DelegationController:delete`;\n handler: DelegationController['delete'];\n};\n\n/**\n * Union of all DelegationController action types.\n */\nexport type DelegationControllerMethodActions =\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n"]}
1
+ {"version":3,"file":"DelegationController-method-action-types.cjs","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { DelegationController } from './DelegationController';\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 */\nexport type DelegationControllerSignDelegationAction = {\n type: `DelegationController:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\n/**\n * Union of all DelegationController action types.\n */\nexport type DelegationControllerMethodActions =\n DelegationControllerSignDelegationAction;\n"]}
@@ -15,59 +15,8 @@ export type DelegationControllerSignDelegationAction = {
15
15
  type: `DelegationController:signDelegation`;
16
16
  handler: DelegationController['signDelegation'];
17
17
  };
18
- /**
19
- * Stores a delegation in storage.
20
- *
21
- * @param params - The parameters for storing the delegation.
22
- * @param params.entry - The delegation entry to store.
23
- */
24
- export type DelegationControllerStoreAction = {
25
- type: `DelegationController:store`;
26
- handler: DelegationController['store'];
27
- };
28
- /**
29
- * Lists delegation entries.
30
- *
31
- * @param filter - The filter to use to list the delegation entries.
32
- * @returns A list of delegation entries that match the filter.
33
- */
34
- export type DelegationControllerListAction = {
35
- type: `DelegationController:list`;
36
- handler: DelegationController['list'];
37
- };
38
- /**
39
- * Retrieves the delegation entry for a given delegation hash.
40
- *
41
- * @param hash - The hash of the delegation to retrieve.
42
- * @returns The delegation entry, or null if not found.
43
- */
44
- export type DelegationControllerRetrieveAction = {
45
- type: `DelegationController:retrieve`;
46
- handler: DelegationController['retrieve'];
47
- };
48
- /**
49
- * Retrieves a delegation chain from a delegation hash.
50
- *
51
- * @param hash - The hash of the delegation to retrieve.
52
- * @returns The delegation chain, or null if not found.
53
- */
54
- export type DelegationControllerChainAction = {
55
- type: `DelegationController:chain`;
56
- handler: DelegationController['chain'];
57
- };
58
- /**
59
- * Deletes a delegation entrie from storage, along with any other entries
60
- * that are redelegated from it.
61
- *
62
- * @param hash - The hash of the delegation to delete.
63
- * @returns The number of entries deleted.
64
- */
65
- export type DelegationControllerDeleteAction = {
66
- type: `DelegationController:delete`;
67
- handler: DelegationController['delete'];
68
- };
69
18
  /**
70
19
  * Union of all DelegationController action types.
71
20
  */
72
- export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction | DelegationControllerStoreAction | DelegationControllerListAction | DelegationControllerRetrieveAction | DelegationControllerChainAction | DelegationControllerDeleteAction;
21
+ export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction;
73
22
  //# sourceMappingURL=DelegationController-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController-method-action-types.d.cts","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,wCAAwC,GACxC,+BAA+B,GAC/B,8BAA8B,GAC9B,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,CAAC"}
1
+ {"version":3,"file":"DelegationController-method-action-types.d.cts","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAC3C,wCAAwC,CAAC"}
@@ -15,59 +15,8 @@ export type DelegationControllerSignDelegationAction = {
15
15
  type: `DelegationController:signDelegation`;
16
16
  handler: DelegationController['signDelegation'];
17
17
  };
18
- /**
19
- * Stores a delegation in storage.
20
- *
21
- * @param params - The parameters for storing the delegation.
22
- * @param params.entry - The delegation entry to store.
23
- */
24
- export type DelegationControllerStoreAction = {
25
- type: `DelegationController:store`;
26
- handler: DelegationController['store'];
27
- };
28
- /**
29
- * Lists delegation entries.
30
- *
31
- * @param filter - The filter to use to list the delegation entries.
32
- * @returns A list of delegation entries that match the filter.
33
- */
34
- export type DelegationControllerListAction = {
35
- type: `DelegationController:list`;
36
- handler: DelegationController['list'];
37
- };
38
- /**
39
- * Retrieves the delegation entry for a given delegation hash.
40
- *
41
- * @param hash - The hash of the delegation to retrieve.
42
- * @returns The delegation entry, or null if not found.
43
- */
44
- export type DelegationControllerRetrieveAction = {
45
- type: `DelegationController:retrieve`;
46
- handler: DelegationController['retrieve'];
47
- };
48
- /**
49
- * Retrieves a delegation chain from a delegation hash.
50
- *
51
- * @param hash - The hash of the delegation to retrieve.
52
- * @returns The delegation chain, or null if not found.
53
- */
54
- export type DelegationControllerChainAction = {
55
- type: `DelegationController:chain`;
56
- handler: DelegationController['chain'];
57
- };
58
- /**
59
- * Deletes a delegation entrie from storage, along with any other entries
60
- * that are redelegated from it.
61
- *
62
- * @param hash - The hash of the delegation to delete.
63
- * @returns The number of entries deleted.
64
- */
65
- export type DelegationControllerDeleteAction = {
66
- type: `DelegationController:delete`;
67
- handler: DelegationController['delete'];
68
- };
69
18
  /**
70
19
  * Union of all DelegationController action types.
71
20
  */
72
- export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction | DelegationControllerStoreAction | DelegationControllerListAction | DelegationControllerRetrieveAction | DelegationControllerChainAction | DelegationControllerDeleteAction;
21
+ export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction;
73
22
  //# sourceMappingURL=DelegationController-method-action-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController-method-action-types.d.mts","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,wCAAwC,GACxC,+BAA+B,GAC/B,8BAA8B,GAC9B,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,CAAC"}
1
+ {"version":3,"file":"DelegationController-method-action-types.d.mts","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mCAA+B;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GAC3C,wCAAwC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DelegationController-method-action-types.mjs","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { DelegationController } from './DelegationController';\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 */\nexport type DelegationControllerSignDelegationAction = {\n type: `DelegationController:signDelegation`;\n handler: DelegationController['signDelegation'];\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 */\nexport type DelegationControllerStoreAction = {\n type: `DelegationController:store`;\n handler: DelegationController['store'];\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 */\nexport type DelegationControllerListAction = {\n type: `DelegationController:list`;\n handler: DelegationController['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 */\nexport type DelegationControllerRetrieveAction = {\n type: `DelegationController:retrieve`;\n handler: DelegationController['retrieve'];\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 */\nexport type DelegationControllerChainAction = {\n type: `DelegationController:chain`;\n handler: DelegationController['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 */\nexport type DelegationControllerDeleteAction = {\n type: `DelegationController:delete`;\n handler: DelegationController['delete'];\n};\n\n/**\n * Union of all DelegationController action types.\n */\nexport type DelegationControllerMethodActions =\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n"]}
1
+ {"version":3,"file":"DelegationController-method-action-types.mjs","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { DelegationController } from './DelegationController';\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 */\nexport type DelegationControllerSignDelegationAction = {\n type: `DelegationController:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\n/**\n * Union of all DelegationController action types.\n */\nexport type DelegationControllerMethodActions =\n DelegationControllerSignDelegationAction;\n"]}
@@ -10,31 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
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
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _DelegationController_hashDelegation, _DelegationController_getDelegationEnvironment;
13
+ var _DelegationController_getDelegationEnvironment;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.DelegationController = exports.controllerName = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
17
17
  const keyring_controller_1 = require("@metamask/keyring-controller");
18
18
  const utils_1 = require("@metamask/utils");
19
- const constants_1 = require("./constants.cjs");
20
19
  const utils_2 = require("./utils.cjs");
21
20
  exports.controllerName = 'DelegationController';
22
- const MESSENGER_EXPOSED_METHODS = [
23
- 'signDelegation',
24
- 'store',
25
- 'list',
26
- 'retrieve',
27
- 'chain',
28
- 'delete',
29
- ];
30
- const delegationControllerMetadata = {
31
- delegations: {
32
- includeInStateLogs: false,
33
- persist: true,
34
- includeInDebugSnapshot: false,
35
- usedInUi: false,
36
- },
37
- };
21
+ const MESSENGER_EXPOSED_METHODS = ['signDelegation'];
22
+ const delegationControllerMetadata = {};
38
23
  /**
39
24
  * Constructs the default {@link DelegationController} state. This allows
40
25
  * consumers to provide a partial state object when initializing the controller
@@ -44,13 +29,11 @@ const delegationControllerMetadata = {
44
29
  * @returns The default {@link DelegationController} state.
45
30
  */
46
31
  function getDefaultDelegationControllerState() {
47
- return {
48
- delegations: {},
49
- };
32
+ return {};
50
33
  }
51
34
  /**
52
35
  * The {@link DelegationController} class.
53
- * This controller is meant to be a centralized place to store and sign delegations.
36
+ * This controller signs delegations via the keyring (typed-data signing).
54
37
  */
55
38
  class DelegationController extends base_controller_1.BaseController {
56
39
  /**
@@ -59,10 +42,9 @@ class DelegationController extends base_controller_1.BaseController {
59
42
  * @param params - The parameters for constructing the controller.
60
43
  * @param params.messenger - The messenger instance to use for the controller.
61
44
  * @param params.state - The initial state for the controller.
62
- * @param params.hashDelegation - A function to hash delegations.
63
45
  * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
64
46
  */
65
- constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }) {
47
+ constructor({ messenger, state, getDelegationEnvironment, }) {
66
48
  super({
67
49
  messenger,
68
50
  metadata: delegationControllerMetadata,
@@ -72,9 +54,7 @@ class DelegationController extends base_controller_1.BaseController {
72
54
  ...state,
73
55
  },
74
56
  });
75
- _DelegationController_hashDelegation.set(this, void 0);
76
57
  _DelegationController_getDelegationEnvironment.set(this, void 0);
77
- __classPrivateFieldSet(this, _DelegationController_hashDelegation, hashDelegation, "f");
78
58
  __classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
79
59
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
80
60
  }
@@ -103,119 +83,7 @@ class DelegationController extends base_controller_1.BaseController {
103
83
  const signature = await this.messenger.call('KeyringController:signTypedMessage', data, keyring_controller_1.SignTypedDataVersion.V4);
104
84
  return signature;
105
85
  }
106
- /**
107
- * Stores a delegation in storage.
108
- *
109
- * @param params - The parameters for storing the delegation.
110
- * @param params.entry - The delegation entry to store.
111
- */
112
- store(params) {
113
- const { entry } = params;
114
- const hash = __classPrivateFieldGet(this, _DelegationController_hashDelegation, "f").call(this, entry.delegation);
115
- // If the authority is not the root authority, validate that the
116
- // parent entry does exist.
117
- if (!(0, utils_2.isHexEqual)(entry.delegation.authority, constants_1.ROOT_AUTHORITY) &&
118
- !this.state.delegations[entry.delegation.authority]) {
119
- throw new Error('Invalid authority');
120
- }
121
- this.update((state) => {
122
- state.delegations[hash] = entry;
123
- });
124
- }
125
- /**
126
- * Lists delegation entries.
127
- *
128
- * @param filter - The filter to use to list the delegation entries.
129
- * @returns A list of delegation entries that match the filter.
130
- */
131
- list(filter) {
132
- const account = this.messenger.call('AccountsController:getSelectedAccount');
133
- const requester = account.address;
134
- let list = Object.values(this.state.delegations);
135
- if (filter?.from) {
136
- list = list.filter((entry) => (0, utils_2.isHexEqual)(entry.delegation.delegator, filter.from));
137
- }
138
- if (!filter?.from ||
139
- (filter?.from && !(0, utils_2.isHexEqual)(filter.from, requester))) {
140
- list = list.filter((entry) => (0, utils_2.isHexEqual)(entry.delegation.delegate, requester));
141
- }
142
- const filterChainId = filter?.chainId;
143
- if (filterChainId) {
144
- list = list.filter((entry) => (0, utils_2.isHexEqual)(entry.chainId, filterChainId));
145
- }
146
- const tags = filter?.tags;
147
- if (tags && tags.length > 0) {
148
- // Filter entries that contain all of the filter tags
149
- list = list.filter((entry) => tags.every((tag) => entry.tags.includes(tag)));
150
- }
151
- return list;
152
- }
153
- /**
154
- * Retrieves the delegation entry for a given delegation hash.
155
- *
156
- * @param hash - The hash of the delegation to retrieve.
157
- * @returns The delegation entry, or null if not found.
158
- */
159
- retrieve(hash) {
160
- return this.state.delegations[hash] ?? null;
161
- }
162
- /**
163
- * Retrieves a delegation chain from a delegation hash.
164
- *
165
- * @param hash - The hash of the delegation to retrieve.
166
- * @returns The delegation chain, or null if not found.
167
- */
168
- chain(hash) {
169
- const chain = [];
170
- const entry = this.retrieve(hash);
171
- if (!entry) {
172
- return null;
173
- }
174
- chain.push(entry);
175
- for (let _hash = entry.delegation.authority; _hash !== constants_1.ROOT_AUTHORITY;) {
176
- const parent = this.retrieve(_hash);
177
- if (!parent) {
178
- throw new Error('Invalid delegation chain');
179
- }
180
- chain.push(parent);
181
- _hash = parent.delegation.authority;
182
- }
183
- return chain;
184
- }
185
- /**
186
- * Deletes a delegation entrie from storage, along with any other entries
187
- * that are redelegated from it.
188
- *
189
- * @param hash - The hash of the delegation to delete.
190
- * @returns The number of entries deleted.
191
- */
192
- delete(hash) {
193
- const root = this.retrieve(hash);
194
- if (!root) {
195
- return 0;
196
- }
197
- const entries = Object.entries(this.state.delegations);
198
- const nextHashes = [hash];
199
- const deletedHashes = [];
200
- while (nextHashes.length > 0) {
201
- const currentHash = nextHashes.pop();
202
- // Find all delegations that have this hash as their authority
203
- const children = entries.filter(([_, v]) => v.delegation.authority === currentHash);
204
- // Add the hashes of all child delegations to be processed next
205
- children.forEach(([k]) => {
206
- nextHashes.push(k);
207
- });
208
- deletedHashes.push(currentHash);
209
- }
210
- // Delete delegations
211
- this.update((state) => {
212
- deletedHashes.forEach((h) => {
213
- delete state.delegations[h];
214
- });
215
- });
216
- return deletedHashes.length;
217
- }
218
86
  }
219
87
  exports.DelegationController = DelegationController;
220
- _DelegationController_hashDelegation = new WeakMap(), _DelegationController_getDelegationEnvironment = new WeakMap();
88
+ _DelegationController_getDelegationEnvironment = new WeakMap();
221
89
  //# 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;AAY7C,uCAA+D;AAElD,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,yBAAyB,GAAG;IAChC,gBAAgB;IAChB,OAAO;IACP,MAAM;IACN,UAAU;IACV,OAAO;IACP,QAAQ;CACA,CAAC;AAEX,MAAM,4BAA4B,GAAG;IACnC,WAAW,EAAE;QACX,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;CACiD,CAAC;AAErD;;;;;;;GAOG;AACH,SAAS,mCAAmC;IAC1C,OAAO;QACL,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,gCAIzC;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,sBAAc;YACpB,KAAK,EAAE;gBACL,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aseController } 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 MESSENGER_EXPOSED_METHODS = [\n 'signDelegation',\n 'store',\n 'list',\n 'retrieve',\n 'chain',\n 'delete',\n] as const;\n\nconst delegationControllerMetadata = {\n delegations: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: 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 this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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.messenger.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.messenger.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
+ {"version":3,"file":"DelegationController.cjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+DAA2D;AAC3D,qEAAoE;AACpE,2CAA8C;AAS9C,uCAAmD;AAEtC,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAE9D,MAAM,4BAA4B,GAChC,EAAqD,CAAC;AAExD;;;;;;;GAOG;AACH,SAAS,mCAAmC;IAC1C,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,gCAIzC;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,wBAAwB,GAKzB;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,4BAA4B;YACtC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,mCAAmC,EAAE;gBACxC,GAAG,KAAK;aACT;SACF,CAAC,CAAC;QA3BI,iEAAkE;QA4BzE,uBAAA,IAAI,kDAA6B,wBAAwB,MAAA,CAAC;QAE1D,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,cAAc,CAAC,MAGpB;QACC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QACvC,MAAM,EAAE,iBAAiB,EAAE,GAAG,uBAAA,IAAI,sDAA0B,MAA9B,IAAI,EAA2B,OAAO,CAAC,CAAC;QAEtE,MAAM,IAAI,GAAG,IAAA,gCAAwB,EAAC;YACpC,OAAO,EAAE,IAAA,mBAAW,EAAC,OAAO,CAAC;YAC7B,IAAI,EAAE,UAAU,CAAC,SAAS;YAC1B,UAAU,EAAE;gBACV,GAAG,UAAU;gBACb,SAAS,EAAE,IAAI;aAChB;YACD,iBAAiB,EAAE,iBAAiB;SACrC,CAAC,CAAC;QAEH,qEAAqE;QACrE,mDAAmD;QACnD,MAAM,SAAS,GAAW,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,oCAAoC,EACpC,IAAI,EACJ,yCAAoB,CAAC,EAAE,CACxB,CAAC;QAEF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AA5ED,oDA4EC","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 type {\n DelegationControllerMessenger,\n DelegationControllerState,\n DeleGatorEnvironment,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst MESSENGER_EXPOSED_METHODS = ['signDelegation'] as const;\n\nconst delegationControllerMetadata =\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}\n\n/**\n * The {@link DelegationController} class.\n * This controller signs delegations via the keyring (typed-data signing).\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\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.getDelegationEnvironment - A function to get the delegation environment for a given chainId.\n */\n constructor({\n messenger,\n state,\n getDelegationEnvironment,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\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.#getDelegationEnvironment = getDelegationEnvironment;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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.messenger.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { BaseController } from "@metamask/base-controller";
2
- import type { Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.cjs";
2
+ import type { DelegationControllerMessenger, DelegationControllerState, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.cjs";
3
3
  export declare const controllerName = "DelegationController";
4
4
  /**
5
5
  * The {@link DelegationController} class.
6
- * This controller is meant to be a centralized place to store and sign delegations.
6
+ * This controller signs delegations via the keyring (typed-data signing).
7
7
  */
8
8
  export declare class DelegationController extends BaseController<typeof controllerName, DelegationControllerState, DelegationControllerMessenger> {
9
9
  #private;
@@ -13,13 +13,11 @@ export declare class DelegationController extends BaseController<typeof controll
13
13
  * @param params - The parameters for constructing the controller.
14
14
  * @param params.messenger - The messenger instance to use for the controller.
15
15
  * @param params.state - The initial state for the controller.
16
- * @param params.hashDelegation - A function to hash delegations.
17
16
  * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
18
17
  */
19
- constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }: {
18
+ constructor({ messenger, state, getDelegationEnvironment, }: {
20
19
  messenger: DelegationControllerMessenger;
21
20
  state?: Partial<DelegationControllerState>;
22
- hashDelegation: (delegation: Delegation) => Hex;
23
21
  getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;
24
22
  });
25
23
  /**
@@ -34,43 +32,5 @@ export declare class DelegationController extends BaseController<typeof controll
34
32
  delegation: UnsignedDelegation;
35
33
  chainId: Hex;
36
34
  }): Promise<string>;
37
- /**
38
- * Stores a delegation in storage.
39
- *
40
- * @param params - The parameters for storing the delegation.
41
- * @param params.entry - The delegation entry to store.
42
- */
43
- store(params: {
44
- entry: DelegationEntry;
45
- }): void;
46
- /**
47
- * Lists delegation entries.
48
- *
49
- * @param filter - The filter to use to list the delegation entries.
50
- * @returns A list of delegation entries that match the filter.
51
- */
52
- list(filter?: DelegationFilter): DelegationEntry[];
53
- /**
54
- * Retrieves the delegation entry for a given delegation hash.
55
- *
56
- * @param hash - The hash of the delegation to retrieve.
57
- * @returns The delegation entry, or null if not found.
58
- */
59
- retrieve(hash: Hex): DelegationEntry;
60
- /**
61
- * Retrieves a delegation chain from a delegation hash.
62
- *
63
- * @param hash - The hash of the delegation to retrieve.
64
- * @returns The delegation chain, or null if not found.
65
- */
66
- chain(hash: Hex): DelegationEntry[] | null;
67
- /**
68
- * Deletes a delegation entrie from storage, along with any other entries
69
- * that are redelegated from it.
70
- *
71
- * @param hash - The hash of the delegation to delete.
72
- * @returns The number of entries deleted.
73
- */
74
- delete(hash: Hex): number;
75
35
  }
76
36
  //# sourceMappingURL=DelegationController.d.cts.map
@@ -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,EAEV,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAkCrD;;;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;IAmBD;;;;;;;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
+ {"version":3,"file":"DelegationController.d.cts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAmBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAGC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,wBAAwB,GACzB,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,oBAAoB,CAAC;KAClE;IAkBD;;;;;;;OAOG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;KACd;CAwBF"}
@@ -1,9 +1,9 @@
1
1
  import { BaseController } from "@metamask/base-controller";
2
- import type { Delegation, DelegationControllerMessenger, DelegationControllerState, DelegationEntry, DelegationFilter, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.mjs";
2
+ import type { DelegationControllerMessenger, DelegationControllerState, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.mjs";
3
3
  export declare const controllerName = "DelegationController";
4
4
  /**
5
5
  * The {@link DelegationController} class.
6
- * This controller is meant to be a centralized place to store and sign delegations.
6
+ * This controller signs delegations via the keyring (typed-data signing).
7
7
  */
8
8
  export declare class DelegationController extends BaseController<typeof controllerName, DelegationControllerState, DelegationControllerMessenger> {
9
9
  #private;
@@ -13,13 +13,11 @@ export declare class DelegationController extends BaseController<typeof controll
13
13
  * @param params - The parameters for constructing the controller.
14
14
  * @param params.messenger - The messenger instance to use for the controller.
15
15
  * @param params.state - The initial state for the controller.
16
- * @param params.hashDelegation - A function to hash delegations.
17
16
  * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
18
17
  */
19
- constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }: {
18
+ constructor({ messenger, state, getDelegationEnvironment, }: {
20
19
  messenger: DelegationControllerMessenger;
21
20
  state?: Partial<DelegationControllerState>;
22
- hashDelegation: (delegation: Delegation) => Hex;
23
21
  getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;
24
22
  });
25
23
  /**
@@ -34,43 +32,5 @@ export declare class DelegationController extends BaseController<typeof controll
34
32
  delegation: UnsignedDelegation;
35
33
  chainId: Hex;
36
34
  }): Promise<string>;
37
- /**
38
- * Stores a delegation in storage.
39
- *
40
- * @param params - The parameters for storing the delegation.
41
- * @param params.entry - The delegation entry to store.
42
- */
43
- store(params: {
44
- entry: DelegationEntry;
45
- }): void;
46
- /**
47
- * Lists delegation entries.
48
- *
49
- * @param filter - The filter to use to list the delegation entries.
50
- * @returns A list of delegation entries that match the filter.
51
- */
52
- list(filter?: DelegationFilter): DelegationEntry[];
53
- /**
54
- * Retrieves the delegation entry for a given delegation hash.
55
- *
56
- * @param hash - The hash of the delegation to retrieve.
57
- * @returns The delegation entry, or null if not found.
58
- */
59
- retrieve(hash: Hex): DelegationEntry;
60
- /**
61
- * Retrieves a delegation chain from a delegation hash.
62
- *
63
- * @param hash - The hash of the delegation to retrieve.
64
- * @returns The delegation chain, or null if not found.
65
- */
66
- chain(hash: Hex): DelegationEntry[] | null;
67
- /**
68
- * Deletes a delegation entrie from storage, along with any other entries
69
- * that are redelegated from it.
70
- *
71
- * @param hash - The hash of the delegation to delete.
72
- * @returns The number of entries deleted.
73
- */
74
- delete(hash: Hex): number;
75
35
  }
76
36
  //# sourceMappingURL=DelegationController.d.mts.map
@@ -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,EAEV,UAAU,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAkCrD;;;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;IAmBD;;;;;;;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
+ {"version":3,"file":"DelegationController.d.mts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,oBAAgB;AAGjB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAmBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAGC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,wBAAwB,GACzB,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC3C,wBAAwB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,oBAAoB,CAAC;KAClE;IAkBD;;;;;;;OAOG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;KACd;CAwBF"}
@@ -9,29 +9,14 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
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
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _DelegationController_hashDelegation, _DelegationController_getDelegationEnvironment;
12
+ var _DelegationController_getDelegationEnvironment;
13
13
  import { BaseController } from "@metamask/base-controller";
14
14
  import { SignTypedDataVersion } from "@metamask/keyring-controller";
15
15
  import { hexToNumber } from "@metamask/utils";
16
- import { ROOT_AUTHORITY } from "./constants.mjs";
17
- import { createTypedMessageParams, isHexEqual } from "./utils.mjs";
16
+ import { createTypedMessageParams } from "./utils.mjs";
18
17
  export const controllerName = 'DelegationController';
19
- const MESSENGER_EXPOSED_METHODS = [
20
- 'signDelegation',
21
- 'store',
22
- 'list',
23
- 'retrieve',
24
- 'chain',
25
- 'delete',
26
- ];
27
- const delegationControllerMetadata = {
28
- delegations: {
29
- includeInStateLogs: false,
30
- persist: true,
31
- includeInDebugSnapshot: false,
32
- usedInUi: false,
33
- },
34
- };
18
+ const MESSENGER_EXPOSED_METHODS = ['signDelegation'];
19
+ const delegationControllerMetadata = {};
35
20
  /**
36
21
  * Constructs the default {@link DelegationController} state. This allows
37
22
  * consumers to provide a partial state object when initializing the controller
@@ -41,13 +26,11 @@ const delegationControllerMetadata = {
41
26
  * @returns The default {@link DelegationController} state.
42
27
  */
43
28
  function getDefaultDelegationControllerState() {
44
- return {
45
- delegations: {},
46
- };
29
+ return {};
47
30
  }
48
31
  /**
49
32
  * The {@link DelegationController} class.
50
- * This controller is meant to be a centralized place to store and sign delegations.
33
+ * This controller signs delegations via the keyring (typed-data signing).
51
34
  */
52
35
  export class DelegationController extends BaseController {
53
36
  /**
@@ -56,10 +39,9 @@ export class DelegationController extends BaseController {
56
39
  * @param params - The parameters for constructing the controller.
57
40
  * @param params.messenger - The messenger instance to use for the controller.
58
41
  * @param params.state - The initial state for the controller.
59
- * @param params.hashDelegation - A function to hash delegations.
60
42
  * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
61
43
  */
62
- constructor({ messenger, state, hashDelegation, getDelegationEnvironment, }) {
44
+ constructor({ messenger, state, getDelegationEnvironment, }) {
63
45
  super({
64
46
  messenger,
65
47
  metadata: delegationControllerMetadata,
@@ -69,9 +51,7 @@ export class DelegationController extends BaseController {
69
51
  ...state,
70
52
  },
71
53
  });
72
- _DelegationController_hashDelegation.set(this, void 0);
73
54
  _DelegationController_getDelegationEnvironment.set(this, void 0);
74
- __classPrivateFieldSet(this, _DelegationController_hashDelegation, hashDelegation, "f");
75
55
  __classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
76
56
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
77
57
  }
@@ -100,118 +80,6 @@ export class DelegationController extends BaseController {
100
80
  const signature = await this.messenger.call('KeyringController:signTypedMessage', data, SignTypedDataVersion.V4);
101
81
  return signature;
102
82
  }
103
- /**
104
- * Stores a delegation in storage.
105
- *
106
- * @param params - The parameters for storing the delegation.
107
- * @param params.entry - The delegation entry to store.
108
- */
109
- store(params) {
110
- const { entry } = params;
111
- const hash = __classPrivateFieldGet(this, _DelegationController_hashDelegation, "f").call(this, entry.delegation);
112
- // If the authority is not the root authority, validate that the
113
- // parent entry does exist.
114
- if (!isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&
115
- !this.state.delegations[entry.delegation.authority]) {
116
- throw new Error('Invalid authority');
117
- }
118
- this.update((state) => {
119
- state.delegations[hash] = entry;
120
- });
121
- }
122
- /**
123
- * Lists delegation entries.
124
- *
125
- * @param filter - The filter to use to list the delegation entries.
126
- * @returns A list of delegation entries that match the filter.
127
- */
128
- list(filter) {
129
- const account = this.messenger.call('AccountsController:getSelectedAccount');
130
- const requester = account.address;
131
- let list = Object.values(this.state.delegations);
132
- if (filter?.from) {
133
- list = list.filter((entry) => isHexEqual(entry.delegation.delegator, filter.from));
134
- }
135
- if (!filter?.from ||
136
- (filter?.from && !isHexEqual(filter.from, requester))) {
137
- list = list.filter((entry) => isHexEqual(entry.delegation.delegate, requester));
138
- }
139
- const filterChainId = filter?.chainId;
140
- if (filterChainId) {
141
- list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));
142
- }
143
- const tags = filter?.tags;
144
- if (tags && tags.length > 0) {
145
- // Filter entries that contain all of the filter tags
146
- list = list.filter((entry) => tags.every((tag) => entry.tags.includes(tag)));
147
- }
148
- return list;
149
- }
150
- /**
151
- * Retrieves the delegation entry for a given delegation hash.
152
- *
153
- * @param hash - The hash of the delegation to retrieve.
154
- * @returns The delegation entry, or null if not found.
155
- */
156
- retrieve(hash) {
157
- return this.state.delegations[hash] ?? null;
158
- }
159
- /**
160
- * Retrieves a delegation chain from a delegation hash.
161
- *
162
- * @param hash - The hash of the delegation to retrieve.
163
- * @returns The delegation chain, or null if not found.
164
- */
165
- chain(hash) {
166
- const chain = [];
167
- const entry = this.retrieve(hash);
168
- if (!entry) {
169
- return null;
170
- }
171
- chain.push(entry);
172
- for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY;) {
173
- const parent = this.retrieve(_hash);
174
- if (!parent) {
175
- throw new Error('Invalid delegation chain');
176
- }
177
- chain.push(parent);
178
- _hash = parent.delegation.authority;
179
- }
180
- return chain;
181
- }
182
- /**
183
- * Deletes a delegation entrie from storage, along with any other entries
184
- * that are redelegated from it.
185
- *
186
- * @param hash - The hash of the delegation to delete.
187
- * @returns The number of entries deleted.
188
- */
189
- delete(hash) {
190
- const root = this.retrieve(hash);
191
- if (!root) {
192
- return 0;
193
- }
194
- const entries = Object.entries(this.state.delegations);
195
- const nextHashes = [hash];
196
- const deletedHashes = [];
197
- while (nextHashes.length > 0) {
198
- const currentHash = nextHashes.pop();
199
- // Find all delegations that have this hash as their authority
200
- const children = entries.filter(([_, v]) => v.delegation.authority === currentHash);
201
- // Add the hashes of all child delegations to be processed next
202
- children.forEach(([k]) => {
203
- nextHashes.push(k);
204
- });
205
- deletedHashes.push(currentHash);
206
- }
207
- // Delete delegations
208
- this.update((state) => {
209
- deletedHashes.forEach((h) => {
210
- delete state.delegations[h];
211
- });
212
- });
213
- return deletedHashes.length;
214
- }
215
83
  }
216
- _DelegationController_hashDelegation = new WeakMap(), _DelegationController_getDelegationEnvironment = new WeakMap();
84
+ _DelegationController_getDelegationEnvironment = new WeakMap();
217
85
  //# 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;AAY7C,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,oBAAgB;AAE/D,MAAM,CAAC,MAAM,cAA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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;QAClC,CAAC;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 MESSENGER_EXPOSED_METHODS = [\n 'signDelegation',\n 'store',\n 'list',\n 'retrieve',\n 'chain',\n 'delete',\n] as const;\n\nconst delegationControllerMetadata = {\n delegations: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: 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 this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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.messenger.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.messenger.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
+ {"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;AAS9C,OAAO,EAAE,wBAAwB,EAAE,oBAAgB;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAErD,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAE9D,MAAM,4BAA4B,GAChC,EAAqD,CAAC;AAExD;;;;;;;GAOG;AACH,SAAS,mCAAmC;IAC1C,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAIzC;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,wBAAwB,GAKzB;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;QA3BI,iEAAkE;QA4BzE,uBAAA,IAAI,kDAA6B,wBAAwB,MAAA,CAAC;QAE1D,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,cAAc,CAAC,MAGpB;QACC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QACvC,MAAM,EAAE,iBAAiB,EAAE,GAAG,uBAAA,IAAI,sDAA0B,MAA9B,IAAI,EAA2B,OAAO,CAAC,CAAC;QAEtE,MAAM,IAAI,GAAG,wBAAwB,CAAC;YACpC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;YAC7B,IAAI,EAAE,UAAU,CAAC,SAAS;YAC1B,UAAU,EAAE;gBACV,GAAG,UAAU;gBACb,SAAS,EAAE,IAAI;aAChB;YACD,iBAAiB,EAAE,iBAAiB;SACrC,CAAC,CAAC;QAEH,qEAAqE;QACrE,mDAAmD;QACnD,MAAM,SAAS,GAAW,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACjD,oCAAoC,EACpC,IAAI,EACJ,oBAAoB,CAAC,EAAE,CACxB,CAAC;QAEF,OAAO,SAAS,CAAC;IACnB,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 type {\n DelegationControllerMessenger,\n DelegationControllerState,\n DeleGatorEnvironment,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst MESSENGER_EXPOSED_METHODS = ['signDelegation'] as const;\n\nconst delegationControllerMetadata =\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}\n\n/**\n * The {@link DelegationController} class.\n * This controller signs delegations via the keyring (typed-data signing).\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\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.getDelegationEnvironment - A function to get the delegation environment for a given chainId.\n */\n constructor({\n messenger,\n state,\n getDelegationEnvironment,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\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.#getDelegationEnvironment = getDelegationEnvironment;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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.messenger.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAiBA,mEAA8D;AAArD,4HAAA,oBAAoB,OAAA","sourcesContent":["export type {\n DelegationControllerSignDelegationAction,\n DelegationControllerStoreAction,\n DelegationControllerListAction,\n DelegationControllerRetrieveAction,\n DelegationControllerChainAction,\n DelegationControllerDeleteAction,\n} from './DelegationController-method-action-types';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n DelegationEntry,\n DelegationFilter,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,mEAA8D;AAArD,4HAAA,oBAAoB,OAAA","sourcesContent":["export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export type { DelegationControllerSignDelegationAction, DelegationControllerStoreAction, DelegationControllerListAction, DelegationControllerRetrieveAction, DelegationControllerChainAction, DelegationControllerDeleteAction, } from "./DelegationController-method-action-types.cjs";
2
- export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, DelegationEntry, DelegationFilter, } from "./types.cjs";
1
+ export type { DelegationControllerSignDelegationAction } from "./DelegationController-method-action-types.cjs";
2
+ export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, } from "./types.cjs";
3
3
  export { DelegationController } from "./DelegationController.cjs";
4
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wCAAwC,EACxC,+BAA+B,EAC/B,8BAA8B,EAC9B,kCAAkC,EAClC,+BAA+B,EAC/B,gCAAgC,GACjC,uDAAmD;AACpD,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,GACjB,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wCAAwC,EAAE,uDAAmD;AAC3G,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,GAC9B,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export type { DelegationControllerSignDelegationAction, DelegationControllerStoreAction, DelegationControllerListAction, DelegationControllerRetrieveAction, DelegationControllerChainAction, DelegationControllerDeleteAction, } from "./DelegationController-method-action-types.mjs";
2
- export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, DelegationEntry, DelegationFilter, } from "./types.mjs";
1
+ export type { DelegationControllerSignDelegationAction } from "./DelegationController-method-action-types.mjs";
2
+ export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, } from "./types.mjs";
3
3
  export { DelegationController } from "./DelegationController.mjs";
4
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wCAAwC,EACxC,+BAA+B,EAC/B,8BAA8B,EAC9B,kCAAkC,EAClC,+BAA+B,EAC/B,gCAAgC,GACjC,uDAAmD;AACpD,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,GACjB,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wCAAwC,EAAE,uDAAmD;AAC3G,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,GAC9B,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B","sourcesContent":["export type {\n DelegationControllerSignDelegationAction,\n DelegationControllerStoreAction,\n DelegationControllerListAction,\n DelegationControllerRetrieveAction,\n DelegationControllerChainAction,\n DelegationControllerDeleteAction,\n} from './DelegationController-method-action-types';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n DelegationEntry,\n DelegationFilter,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B","sourcesContent":["export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\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} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { controllerName } from './DelegationController';\nimport type { DelegationControllerMethodActions } from './DelegationController-method-action-types';\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 DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerMethodActions;\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 = Messenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents\n>;\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { controllerName } from './DelegationController';\nimport type { DelegationControllerMethodActions } from './DelegationController-method-action-types';\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\n// Empty controller state (signing-only; no persisted fields).\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type DelegationControllerState = {};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerMethodActions;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions = KeyringControllerSignTypedMessageAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = Messenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents\n>;\n"]}
package/dist/types.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AccountsControllerGetSelectedAccountAction } from "@metamask/accounts-controller";
2
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
3
2
  import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
4
3
  import type { Messenger } from "@metamask/messenger";
@@ -59,27 +58,12 @@ export type UnsignedDelegation = Omit<Delegation, 'signature'>;
59
58
  export type DelegationStruct = Omit<Delegation, 'salt'> & {
60
59
  salt: bigint;
61
60
  };
62
- export type DelegationEntry = {
63
- tags: string[];
64
- chainId: Hex;
65
- delegation: Delegation;
66
- meta?: string;
67
- };
68
- export type DelegationFilter = {
69
- chainId?: Hex;
70
- tags?: string[];
71
- from?: Address;
72
- };
73
- export type DelegationControllerState = {
74
- delegations: {
75
- [hash: Hex]: DelegationEntry;
76
- };
77
- };
61
+ export type DelegationControllerState = {};
78
62
  export type DelegationControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DelegationControllerState>;
79
63
  export type DelegationControllerActions = DelegationControllerGetStateAction | DelegationControllerMethodActions;
80
64
  export type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DelegationControllerState>;
81
65
  export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
82
- type AllowedActions = KeyringControllerSignTypedMessageAction | AccountsControllerGetSelectedAccountAction;
66
+ type AllowedActions = KeyringControllerSignTypedMessageAction;
83
67
  type AllowedEvents = never;
84
68
  export type DelegationControllerMessenger = Messenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents>;
85
69
  //# sourceMappingURL=types.d.cts.map
@@ -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,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,qCAAqC;AAC5F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,mCAA+B;AAC7D,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AAEpG,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AACzB,KAAK,OAAO,GAAG,KAAK,MAAM,EA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cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E,KAAK,cAAc,GAAG,uCAAuC,CAAC;AAE9D,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,6BAA6B,GAAG,SAAS,CACnD,OAAO,cAAc,EACrB,2BAA2B,GAAG,cAAc,EAC5C,0BAA0B,GAAG,aAAa,CAC3C,CAAC"}
package/dist/types.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AccountsControllerGetSelectedAccountAction } from "@metamask/accounts-controller";
2
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
3
2
  import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
4
3
  import type { Messenger } from "@metamask/messenger";
@@ -59,27 +58,12 @@ export type UnsignedDelegation = Omit<Delegation, 'signature'>;
59
58
  export type DelegationStruct = Omit<Delegation, 'salt'> & {
60
59
  salt: bigint;
61
60
  };
62
- export type DelegationEntry = {
63
- tags: string[];
64
- chainId: Hex;
65
- delegation: Delegation;
66
- meta?: string;
67
- };
68
- export type DelegationFilter = {
69
- chainId?: Hex;
70
- tags?: string[];
71
- from?: Address;
72
- };
73
- export type DelegationControllerState = {
74
- delegations: {
75
- [hash: Hex]: DelegationEntry;
76
- };
77
- };
61
+ export type DelegationControllerState = {};
78
62
  export type DelegationControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DelegationControllerState>;
79
63
  export type DelegationControllerActions = DelegationControllerGetStateAction | DelegationControllerMethodActions;
80
64
  export type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DelegationControllerState>;
81
65
  export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
82
- type AllowedActions = KeyringControllerSignTypedMessageAction | AccountsControllerGetSelectedAccountAction;
66
+ type AllowedActions = KeyringControllerSignTypedMessageAction;
83
67
  type AllowedEvents = never;
84
68
  export type DelegationControllerMessenger = Messenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents>;
85
69
  //# sourceMappingURL=types.d.mts.map
@@ -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,EAC3B,kCAAkC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,qCAAqC;AAC5F,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,mCAA+B;AAC7D,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AAEpG,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AACzB,KAAK,OAAO,GAAG,KAAK,MAAM,EAAE,CAAC;AAE7B,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,iBAAiB,EAAE,GAAG,CAAC;IACvB,UAAU,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,GAAG,CAAC;IACnB,eAAe,EAAE;QACf,CAAC,cAAc,EAAE,MAAM,GAAG,GAAG,CAAC;KAC/B,CAAC;IACF,eAAe,EAAE;QACf,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;KACzB,CAAC;CACH,CAAC;AAEF;;;;;GAKG;AACH,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;IAC/F,SAAS,EAAE,GAAG,CAAC;IAC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C1D,IAAI,EAAE,GAAG,CAAC;IACV,uCAAuC;IACvC,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AAE/D,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;IACxD,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAIF,MAAM,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE3C,MAAM,MAAM,kCAAkC,GAAG,wBAAwB,CACvE,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,kCAAkC,GAClC,iCAAiC,CAAC;AAEtC,MAAM,MAAM,oCAAoC,GAAG,0BAA0B,CAC3E,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E,KAAK,cAAc,GAAG,uCAAuC,CAAC;AAE9D,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,6BAA6B,GAAG,SAAS,CACnD,OAAO,cAAc,EACrB,2BAA2B,GAAG,cAAc,EAC5C,0BAA0B,GAAG,aAAa,CAC3C,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} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { controllerName } from './DelegationController';\nimport type { DelegationControllerMethodActions } from './DelegationController-method-action-types';\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 DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerMethodActions;\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 = Messenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents\n>;\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { controllerName } from './DelegationController';\nimport type { DelegationControllerMethodActions } from './DelegationController-method-action-types';\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\n// Empty controller state (signing-only; no persisted fields).\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type DelegationControllerState = {};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerMethodActions;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions = KeyringControllerSignTypedMessageAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = Messenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents\n>;\n"]}
package/dist/utils.cjs CHANGED
@@ -1,19 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTypedMessageParams = exports.toDelegationStruct = exports.isHexEqual = void 0;
3
+ exports.createTypedMessageParams = exports.toDelegationStruct = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const constants_1 = require("./constants.cjs");
6
- /**
7
- * Checks if two hex strings are equal.
8
- *
9
- * @param a - The first hex string.
10
- * @param b - The second hex string.
11
- * @returns True if the hex strings are equal, false otherwise.
12
- */
13
- function isHexEqual(a, b) {
14
- return a.toLowerCase() === b.toLowerCase();
15
- }
16
- exports.isHexEqual = isHexEqual;
17
6
  /**
18
7
  * Converts a Delegation to a DelegationStruct.
19
8
  * The DelegationStruct is the format used in the Delegation Framework.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AAErD,+CAA6D;AAG7D;;;;;;GAMG;AACH,SAAgB,UA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O,EAAE,IAAA,0BAAkB,EAAC,UAAU,CAAC;SACxC;QACD,IAAI;KACL,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AArBD,4DAqBC","sourcesContent":["import type { TypedMessageParams } from '@metamask/keyring-controller';\nimport { getChecksumAddress } from '@metamask/utils';\n\nimport { SIGNABLE_DELEGATION_TYPED_DATA } from './constants';\nimport type { Address, Delegation, DelegationStruct, Hex } from './types';\n\n/**\n * Checks if two hex strings are equal.\n *\n * @param a - The first hex string.\n * @param b - The second hex string.\n * @returns True if the hex strings are equal, false otherwise.\n */\nexport function isHexEqual(a: Hex, b: Hex) {\n return a.toLowerCase() === b.toLowerCase();\n}\n\ntype CreateTypedMessageParamsOptions = {\n chainId: number;\n from: Address;\n delegation: Delegation;\n verifyingContract: Address;\n};\n\n/**\n * Converts a Delegation to a DelegationStruct.\n * The DelegationStruct is the format used in the Delegation Framework.\n *\n * @param delegation the delegation to format\n * @returns the formatted delegation\n */\nexport const toDelegationStruct = (\n delegation: Delegation,\n): DelegationStruct => {\n const caveats = delegation.caveats.map((caveat) => ({\n enforcer: getChecksumAddress(caveat.enforcer),\n terms: caveat.terms,\n args: caveat.args,\n }));\n\n const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);\n\n return {\n delegate: getChecksumAddress(delegation.delegate),\n delegator: getChecksumAddress(delegation.delegator),\n authority: delegation.authority,\n caveats,\n salt,\n signature: delegation.signature,\n };\n};\n\n/**\n *\n * @param opts - The options for creating typed message params.\n * @returns The typed message params.\n */\nexport function createTypedMessageParams(\n opts: CreateTypedMessageParamsOptions,\n): TypedMessageParams {\n const { chainId, from, delegation, verifyingContract } = opts;\n\n const data: TypedMessageParams = {\n data: {\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n domain: {\n chainId,\n name: 'DelegationManager',\n version: '1',\n verifyingContract,\n },\n message: toDelegationStruct(delegation),\n },\n from,\n };\n\n return data;\n}\n"]}
1
+ {"version":3,"file":"utils.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ACD,IAAI;KACL,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AArBD,4DAqBC","sourcesContent":["import type { TypedMessageParams } from '@metamask/keyring-controller';\nimport { getChecksumAddress } from '@metamask/utils';\n\nimport { SIGNABLE_DELEGATION_TYPED_DATA } from './constants';\nimport type { Address, Delegation, DelegationStruct } from './types';\n\ntype CreateTypedMessageParamsOptions = {\n chainId: number;\n from: Address;\n delegation: Delegation;\n verifyingContract: Address;\n};\n\n/**\n * Converts a Delegation to a DelegationStruct.\n * The DelegationStruct is the format used in the Delegation Framework.\n *\n * @param delegation the delegation to format\n * @returns the formatted delegation\n */\nexport const toDelegationStruct = (\n delegation: Delegation,\n): DelegationStruct => {\n const caveats = delegation.caveats.map((caveat) => ({\n enforcer: getChecksumAddress(caveat.enforcer),\n terms: caveat.terms,\n args: caveat.args,\n }));\n\n const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);\n\n return {\n delegate: getChecksumAddress(delegation.delegate),\n delegator: getChecksumAddress(delegation.delegator),\n authority: delegation.authority,\n caveats,\n salt,\n signature: delegation.signature,\n };\n};\n\n/**\n *\n * @param opts - The options for creating typed message params.\n * @returns The typed message params.\n */\nexport function createTypedMessageParams(\n opts: CreateTypedMessageParamsOptions,\n): TypedMessageParams {\n const { chainId, from, delegation, verifyingContract } = opts;\n\n const data: TypedMessageParams = {\n data: {\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n domain: {\n chainId,\n name: 'DelegationManager',\n version: '1',\n verifyingContract,\n },\n message: toDelegationStruct(delegation),\n },\n from,\n };\n\n return data;\n}\n"]}
package/dist/utils.d.cts CHANGED
@@ -1,13 +1,5 @@
1
1
  import type { TypedMessageParams } from "@metamask/keyring-controller";
2
- import type { Address, Delegation, DelegationStruct, Hex } from "./types.cjs";
3
- /**
4
- * Checks if two hex strings are equal.
5
- *
6
- * @param a - The first hex string.
7
- * @param b - The second hex string.
8
- * @returns True if the hex strings are equal, false otherwise.
9
- */
10
- export declare function isHexEqual(a: Hex, b: Hex): boolean;
2
+ import type { Address, Delegation, DelegationStruct } from "./types.cjs";
11
3
  type CreateTypedMessageParamsOptions = {
12
4
  chainId: number;
13
5
  from: Address;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qCAAqC;AAIvE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,EAAE,oBAAgB;AAE1E;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,WAExC;AAED,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,eACjB,UAAU,KACrB,gBAiBF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,+BAA+B,GACpC,kBAAkB,CAmBpB"}
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qCAAqC;AAIvE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,oBAAgB;AAErE,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,eACjB,UAAU,KACrB,gBAiBF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,+BAA+B,GACpC,kBAAkB,CAmBpB"}
package/dist/utils.d.mts CHANGED
@@ -1,13 +1,5 @@
1
1
  import type { TypedMessageParams } from "@metamask/keyring-controller";
2
- import type { Address, Delegation, DelegationStruct, Hex } from "./types.mjs";
3
- /**
4
- * Checks if two hex strings are equal.
5
- *
6
- * @param a - The first hex string.
7
- * @param b - The second hex string.
8
- * @returns True if the hex strings are equal, false otherwise.
9
- */
10
- export declare function isHexEqual(a: Hex, b: Hex): boolean;
2
+ import type { Address, Delegation, DelegationStruct } from "./types.mjs";
11
3
  type CreateTypedMessageParamsOptions = {
12
4
  chainId: number;
13
5
  from: Address;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qCAAqC;AAIvE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,EAAE,oBAAgB;AAE1E;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,WAExC;AAED,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,eACjB,UAAU,KACrB,gBAiBF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,+BAA+B,GACpC,kBAAkB,CAmBpB"}
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,qCAAqC;AAIvE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,oBAAgB;AAErE,KAAK,+BAA+B,GAAG;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,eACjB,UAAU,KACrB,gBAiBF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,+BAA+B,GACpC,kBAAkB,CAmBpB"}
package/dist/utils.mjs CHANGED
@@ -1,15 +1,5 @@
1
1
  import { getChecksumAddress } from "@metamask/utils";
2
2
  import { SIGNABLE_DELEGATION_TYPED_DATA } from "./constants.mjs";
3
- /**
4
- * Checks if two hex strings are equal.
5
- *
6
- * @param a - The first hex string.
7
- * @param b - The second hex string.
8
- * @returns True if the hex strings are equal, false otherwise.
9
- */
10
- export function isHexEqual(a, b) {
11
- return a.toLowerCase() === b.toLowerCase();
12
- }
13
3
  /**
14
4
  * Converts a Delegation to a DelegationStruct.
15
5
  * The DelegationStruct is the format used in the Delegation Framework.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,8BAA8B,EAAE,wBAAoB;AAG7D;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,CAAM,EAAE,CAAM;IACvC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7C,CAAC;AASD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,UAAsB,EACJ,EAAE;IACpB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClD,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC7C,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,CAAC,CAAC;IAEJ,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAErE,OAAO;QACL,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC,SAAS,CAAC;QACnD,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAqC;IAErC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAE9D,MAAM,IAAI,GAAuB;QAC/B,IAAI,EAAE;YACJ,KAAK,EAAE,8BAA8B;YACrC,WAAW,EAAE,YAAY;YACzB,MAAM,EAAE;gBACN,OAAO;gBACP,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,GAAG;gBACZ,iBAAiB;aAClB;YACD,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC;SACxC;QACD,IAAI;KACL,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { TypedMessageParams } from '@metamask/keyring-controller';\nimport { getChecksumAddress } from '@metamask/utils';\n\nimport { SIGNABLE_DELEGATION_TYPED_DATA } from './constants';\nimport type { Address, Delegation, DelegationStruct, Hex } from './types';\n\n/**\n * Checks if two hex strings are equal.\n *\n * @param a - The first hex string.\n * @param b - The second hex string.\n * @returns True if the hex strings are equal, false otherwise.\n */\nexport function isHexEqual(a: Hex, b: Hex) {\n return a.toLowerCase() === b.toLowerCase();\n}\n\ntype CreateTypedMessageParamsOptions = {\n chainId: number;\n from: Address;\n delegation: Delegation;\n verifyingContract: Address;\n};\n\n/**\n * Converts a Delegation to a DelegationStruct.\n * The DelegationStruct is the format used in the Delegation Framework.\n *\n * @param delegation the delegation to format\n * @returns the formatted delegation\n */\nexport const toDelegationStruct = (\n delegation: Delegation,\n): DelegationStruct => {\n const caveats = delegation.caveats.map((caveat) => ({\n enforcer: getChecksumAddress(caveat.enforcer),\n terms: caveat.terms,\n args: caveat.args,\n }));\n\n const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);\n\n return {\n delegate: getChecksumAddress(delegation.delegate),\n delegator: getChecksumAddress(delegation.delegator),\n authority: delegation.authority,\n caveats,\n salt,\n signature: delegation.signature,\n };\n};\n\n/**\n *\n * @param opts - The options for creating typed message params.\n * @returns The typed message params.\n */\nexport function createTypedMessageParams(\n opts: CreateTypedMessageParamsOptions,\n): TypedMessageParams {\n const { chainId, from, delegation, verifyingContract } = opts;\n\n const data: TypedMessageParams = {\n data: {\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n domain: {\n chainId,\n name: 'DelegationManager',\n version: '1',\n verifyingContract,\n },\n message: toDelegationStruct(delegation),\n },\n from,\n };\n\n return data;\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,8BAA8B,EAAE,wBAAoB;AAU7D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,UAAsB,EACJ,EAAE;IACpB,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAClD,QAAQ,EAAE,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC7C,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,CAAC,CAAC;IAEJ,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAErE,OAAO;QACL,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC,SAAS,CAAC;QACnD,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,OAAO;QACP,IAAI;QACJ,SAAS,EAAE,UAAU,CAAC,SAAS;KAChC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAqC;IAErC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;IAE9D,MAAM,IAAI,GAAuB;QAC/B,IAAI,EAAE;YACJ,KAAK,EAAE,8BAA8B;YACrC,WAAW,EAAE,YAAY;YACzB,MAAM,EAAE;gBACN,OAAO;gBACP,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,GAAG;gBACZ,iBAAiB;aAClB;YACD,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC;SACxC;QACD,IAAI;KACL,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { TypedMessageParams } from '@metamask/keyring-controller';\nimport { getChecksumAddress } from '@metamask/utils';\n\nimport { SIGNABLE_DELEGATION_TYPED_DATA } from './constants';\nimport type { Address, Delegation, DelegationStruct } from './types';\n\ntype CreateTypedMessageParamsOptions = {\n chainId: number;\n from: Address;\n delegation: Delegation;\n verifyingContract: Address;\n};\n\n/**\n * Converts a Delegation to a DelegationStruct.\n * The DelegationStruct is the format used in the Delegation Framework.\n *\n * @param delegation the delegation to format\n * @returns the formatted delegation\n */\nexport const toDelegationStruct = (\n delegation: Delegation,\n): DelegationStruct => {\n const caveats = delegation.caveats.map((caveat) => ({\n enforcer: getChecksumAddress(caveat.enforcer),\n terms: caveat.terms,\n args: caveat.args,\n }));\n\n const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);\n\n return {\n delegate: getChecksumAddress(delegation.delegate),\n delegator: getChecksumAddress(delegation.delegator),\n authority: delegation.authority,\n caveats,\n salt,\n signature: delegation.signature,\n };\n};\n\n/**\n *\n * @param opts - The options for creating typed message params.\n * @returns The typed message params.\n */\nexport function createTypedMessageParams(\n opts: CreateTypedMessageParamsOptions,\n): TypedMessageParams {\n const { chainId, from, delegation, verifyingContract } = opts;\n\n const data: TypedMessageParams = {\n data: {\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n domain: {\n chainId,\n name: 'DelegationManager',\n version: '1',\n verifyingContract,\n },\n message: toDelegationStruct(delegation),\n },\n from,\n };\n\n return data;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/delegation-controller",
3
- "version": "2.1.0-preview-dff83af4c",
3
+ "version": "2.1.0-preview-6b4f746",
4
4
  "description": "Manages delegations for MetaMask",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -49,7 +49,6 @@
49
49
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
50
50
  },
51
51
  "dependencies": {
52
- "@metamask/accounts-controller": "^37.2.0",
53
52
  "@metamask/base-controller": "^9.0.1",
54
53
  "@metamask/keyring-controller": "^25.2.0",
55
54
  "@metamask/messenger": "^1.1.1",