@metamask-previews/delegation-controller 3.0.2-preview-3866c0ff1 → 3.0.2-preview-acb2929f3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/DelegationController-method-action-types.cjs +7 -0
- package/dist/DelegationController-method-action-types.cjs.map +1 -0
- package/dist/{DelegationController-method-action-types.d.ts → DelegationController-method-action-types.d.cts} +2 -2
- package/dist/DelegationController-method-action-types.d.cts.map +1 -0
- package/dist/DelegationController-method-action-types.d.mts +22 -0
- package/dist/DelegationController-method-action-types.d.mts.map +1 -0
- package/dist/{DelegationController-method-action-types.js → DelegationController-method-action-types.mjs} +1 -1
- package/dist/DelegationController-method-action-types.mjs.map +1 -0
- package/dist/DelegationController.cjs +89 -0
- package/dist/DelegationController.cjs.map +1 -0
- package/dist/{DelegationController.d.ts → DelegationController.d.cts} +3 -3
- package/dist/DelegationController.d.cts.map +1 -0
- package/dist/DelegationController.d.mts +36 -0
- package/dist/DelegationController.d.mts.map +1 -0
- package/dist/{DelegationController.js → DelegationController.mjs} +21 -8
- package/dist/DelegationController.mjs.map +1 -0
- package/dist/constants.cjs +28 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +31 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +31 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/constants.mjs.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +6 -6
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +69 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +54 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +24 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/{utils.js → utils.mjs} +3 -3
- package/dist/utils.mjs.map +1 -0
- package/package.json +16 -12
- package/dist/DelegationController-method-action-types.d.ts.map +0 -1
- package/dist/DelegationController-method-action-types.js.map +0 -1
- package/dist/DelegationController.d.ts.map +0 -1
- package/dist/DelegationController.js.map +0 -1
- package/dist/constants.d.ts +0 -32
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
-
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
12
|
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
|
14
13
|
- Bump `@metamask/keyring-controller` from `^27.0.0` to `^27.1.1` ([#9129](https://github.com/MetaMask/core/pull/9129), [#9791](https://github.com/MetaMask/core/pull/9791))
|
|
15
14
|
- Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
|
|
@@ -0,0 +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.js';\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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { DelegationController } from
|
|
5
|
+
import type { DelegationController } from "./DelegationController.cjs";
|
|
6
6
|
/**
|
|
7
7
|
* Signs a delegation.
|
|
8
8
|
*
|
|
@@ -19,4 +19,4 @@ export type DelegationControllerSignDelegationAction = {
|
|
|
19
19
|
* Union of all DelegationController action types.
|
|
20
20
|
*/
|
|
21
21
|
export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction;
|
|
22
|
-
//# sourceMappingURL=DelegationController-method-action-types.d.
|
|
22
|
+
//# sourceMappingURL=DelegationController-method-action-types.d.cts.map
|
|
@@ -0,0 +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,mCAAkC;AAEtE;;;;;;;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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { DelegationController } from "./DelegationController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Signs a delegation.
|
|
8
|
+
*
|
|
9
|
+
* @param params - The parameters for signing the delegation.
|
|
10
|
+
* @param params.delegation - The delegation to sign.
|
|
11
|
+
* @param params.chainId - The chainId of the chain to sign the delegation for.
|
|
12
|
+
* @returns The signature of the delegation.
|
|
13
|
+
*/
|
|
14
|
+
export type DelegationControllerSignDelegationAction = {
|
|
15
|
+
type: `DelegationController:signDelegation`;
|
|
16
|
+
handler: DelegationController['signDelegation'];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Union of all DelegationController action types.
|
|
20
|
+
*/
|
|
21
|
+
export type DelegationControllerMethodActions = DelegationControllerSignDelegationAction;
|
|
22
|
+
//# sourceMappingURL=DelegationController-method-action-types.d.mts.map
|
|
@@ -0,0 +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,mCAAkC;AAEtE;;;;;;;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"}
|
|
@@ -0,0 +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.js';\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"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _DelegationController_getDelegationEnvironment;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DelegationController = exports.controllerName = void 0;
|
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
18
|
+
const utils_1 = require("@metamask/utils");
|
|
19
|
+
const utils_js_1 = require("./utils.cjs");
|
|
20
|
+
exports.controllerName = 'DelegationController';
|
|
21
|
+
const MESSENGER_EXPOSED_METHODS = ['signDelegation'];
|
|
22
|
+
const delegationControllerMetadata = {};
|
|
23
|
+
/**
|
|
24
|
+
* Constructs the default {@link DelegationController} state. This allows
|
|
25
|
+
* consumers to provide a partial state object when initializing the controller
|
|
26
|
+
* and also helps in constructing complete state objects for this controller in
|
|
27
|
+
* tests.
|
|
28
|
+
*
|
|
29
|
+
* @returns The default {@link DelegationController} state.
|
|
30
|
+
*/
|
|
31
|
+
function getDefaultDelegationControllerState() {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The {@link DelegationController} class.
|
|
36
|
+
* This controller signs delegations via the keyring (typed-data signing).
|
|
37
|
+
*/
|
|
38
|
+
class DelegationController extends base_controller_1.BaseController {
|
|
39
|
+
/**
|
|
40
|
+
* Constructs a new {@link DelegationController} instance.
|
|
41
|
+
*
|
|
42
|
+
* @param params - The parameters for constructing the controller.
|
|
43
|
+
* @param params.messenger - The messenger instance to use for the controller.
|
|
44
|
+
* @param params.state - The initial state for the controller.
|
|
45
|
+
* @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
|
|
46
|
+
*/
|
|
47
|
+
constructor({ messenger, state, getDelegationEnvironment, }) {
|
|
48
|
+
super({
|
|
49
|
+
messenger,
|
|
50
|
+
metadata: delegationControllerMetadata,
|
|
51
|
+
name: exports.controllerName,
|
|
52
|
+
state: {
|
|
53
|
+
...getDefaultDelegationControllerState(),
|
|
54
|
+
...state,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
_DelegationController_getDelegationEnvironment.set(this, void 0);
|
|
58
|
+
__classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
|
|
59
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Signs a delegation.
|
|
63
|
+
*
|
|
64
|
+
* @param params - The parameters for signing the delegation.
|
|
65
|
+
* @param params.delegation - The delegation to sign.
|
|
66
|
+
* @param params.chainId - The chainId of the chain to sign the delegation for.
|
|
67
|
+
* @returns The signature of the delegation.
|
|
68
|
+
*/
|
|
69
|
+
async signDelegation(params) {
|
|
70
|
+
const { delegation, chainId } = params;
|
|
71
|
+
const { DelegationManager } = __classPrivateFieldGet(this, _DelegationController_getDelegationEnvironment, "f").call(this, chainId);
|
|
72
|
+
const data = (0, utils_js_1.createTypedMessageParams)({
|
|
73
|
+
chainId: (0, utils_1.hexToNumber)(chainId),
|
|
74
|
+
from: delegation.delegator,
|
|
75
|
+
delegation: {
|
|
76
|
+
...delegation,
|
|
77
|
+
signature: '0x',
|
|
78
|
+
},
|
|
79
|
+
verifyingContract: DelegationManager,
|
|
80
|
+
});
|
|
81
|
+
// TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.
|
|
82
|
+
// Waiting on confirmations team to implement this.
|
|
83
|
+
const signature = await this.messenger.call('KeyringController:signTypedMessage', data, keyring_controller_1.SignTypedDataVersion.V4);
|
|
84
|
+
return signature;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.DelegationController = DelegationController;
|
|
88
|
+
_DelegationController_getDelegationEnvironment = new WeakMap();
|
|
89
|
+
//# sourceMappingURL=DelegationController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DelegationController.cjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+DAA2D;AAC3D,qEAAoE;AACpE,2CAA8C;AAS9C,0CAAsD;AAEzC,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,mCAAwB,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.js';\nimport { createTypedMessageParams } from './utils.js';\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,5 +1,5 @@
|
|
|
1
|
-
import { BaseController } from
|
|
2
|
-
import type { DelegationControllerMessenger, DelegationControllerState, DeleGatorEnvironment, Hex, UnsignedDelegation } from
|
|
1
|
+
import { BaseController } from "@metamask/base-controller";
|
|
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.
|
|
@@ -33,4 +33,4 @@ export declare class DelegationController extends BaseController<typeof controll
|
|
|
33
33
|
chainId: Hex;
|
|
34
34
|
}): Promise<string>;
|
|
35
35
|
}
|
|
36
|
-
//# sourceMappingURL=DelegationController.d.
|
|
36
|
+
//# sourceMappingURL=DelegationController.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,oBAAmB;AAGpB,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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseController } from "@metamask/base-controller";
|
|
2
|
+
import type { DelegationControllerMessenger, DelegationControllerState, DeleGatorEnvironment, Hex, UnsignedDelegation } from "./types.mjs";
|
|
3
|
+
export declare const controllerName = "DelegationController";
|
|
4
|
+
/**
|
|
5
|
+
* The {@link DelegationController} class.
|
|
6
|
+
* This controller signs delegations via the keyring (typed-data signing).
|
|
7
|
+
*/
|
|
8
|
+
export declare class DelegationController extends BaseController<typeof controllerName, DelegationControllerState, DelegationControllerMessenger> {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new {@link DelegationController} instance.
|
|
12
|
+
*
|
|
13
|
+
* @param params - The parameters for constructing the controller.
|
|
14
|
+
* @param params.messenger - The messenger instance to use for the controller.
|
|
15
|
+
* @param params.state - The initial state for the controller.
|
|
16
|
+
* @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.
|
|
17
|
+
*/
|
|
18
|
+
constructor({ messenger, state, getDelegationEnvironment, }: {
|
|
19
|
+
messenger: DelegationControllerMessenger;
|
|
20
|
+
state?: Partial<DelegationControllerState>;
|
|
21
|
+
getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Signs a delegation.
|
|
25
|
+
*
|
|
26
|
+
* @param params - The parameters for signing the delegation.
|
|
27
|
+
* @param params.delegation - The delegation to sign.
|
|
28
|
+
* @param params.chainId - The chainId of the chain to sign the delegation for.
|
|
29
|
+
* @returns The signature of the delegation.
|
|
30
|
+
*/
|
|
31
|
+
signDelegation(params: {
|
|
32
|
+
delegation: UnsignedDelegation;
|
|
33
|
+
chainId: Hex;
|
|
34
|
+
}): Promise<string>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=DelegationController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,oBAAmB;AAGpB,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,7 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _DelegationController_getDelegationEnvironment;
|
|
13
|
+
import { BaseController } from "@metamask/base-controller";
|
|
14
|
+
import { SignTypedDataVersion } from "@metamask/keyring-controller";
|
|
15
|
+
import { hexToNumber } from "@metamask/utils";
|
|
16
|
+
import { createTypedMessageParams } from "./utils.mjs";
|
|
5
17
|
export const controllerName = 'DelegationController';
|
|
6
18
|
const MESSENGER_EXPOSED_METHODS = ['signDelegation'];
|
|
7
19
|
const delegationControllerMetadata = {};
|
|
@@ -21,7 +33,6 @@ function getDefaultDelegationControllerState() {
|
|
|
21
33
|
* This controller signs delegations via the keyring (typed-data signing).
|
|
22
34
|
*/
|
|
23
35
|
export class DelegationController extends BaseController {
|
|
24
|
-
#getDelegationEnvironment;
|
|
25
36
|
/**
|
|
26
37
|
* Constructs a new {@link DelegationController} instance.
|
|
27
38
|
*
|
|
@@ -40,7 +51,8 @@ export class DelegationController extends BaseController {
|
|
|
40
51
|
...state,
|
|
41
52
|
},
|
|
42
53
|
});
|
|
43
|
-
this
|
|
54
|
+
_DelegationController_getDelegationEnvironment.set(this, void 0);
|
|
55
|
+
__classPrivateFieldSet(this, _DelegationController_getDelegationEnvironment, getDelegationEnvironment, "f");
|
|
44
56
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
45
57
|
}
|
|
46
58
|
/**
|
|
@@ -53,7 +65,7 @@ export class DelegationController extends BaseController {
|
|
|
53
65
|
*/
|
|
54
66
|
async signDelegation(params) {
|
|
55
67
|
const { delegation, chainId } = params;
|
|
56
|
-
const { DelegationManager } = this
|
|
68
|
+
const { DelegationManager } = __classPrivateFieldGet(this, _DelegationController_getDelegationEnvironment, "f").call(this, chainId);
|
|
57
69
|
const data = createTypedMessageParams({
|
|
58
70
|
chainId: hexToNumber(chainId),
|
|
59
71
|
from: delegation.delegator,
|
|
@@ -69,4 +81,5 @@ export class DelegationController extends BaseController {
|
|
|
69
81
|
return signature;
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
|
-
|
|
84
|
+
_DelegationController_getDelegationEnvironment = new WeakMap();
|
|
85
|
+
//# sourceMappingURL=DelegationController.mjs.map
|
|
@@ -0,0 +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;AAS9C,OAAO,EAAE,wBAAwB,EAAE,oBAAmB;AAEtD,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.js';\nimport { createTypedMessageParams } from './utils.js';\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"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SIGNABLE_DELEGATION_TYPED_DATA = exports.ROOT_AUTHORITY = void 0;
|
|
4
|
+
exports.ROOT_AUTHORITY = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
|
|
5
|
+
const EIP712Domain = [
|
|
6
|
+
{ name: 'name', type: 'string' },
|
|
7
|
+
{ name: 'version', type: 'string' },
|
|
8
|
+
{ name: 'chainId', type: 'uint256' },
|
|
9
|
+
{ name: 'verifyingContract', type: 'address' },
|
|
10
|
+
];
|
|
11
|
+
const SDK_SIGNABLE_DELEGATION_TYPED_DATA = {
|
|
12
|
+
Caveat: [
|
|
13
|
+
{ name: 'enforcer', type: 'address' },
|
|
14
|
+
{ name: 'terms', type: 'bytes' },
|
|
15
|
+
],
|
|
16
|
+
Delegation: [
|
|
17
|
+
{ name: 'delegate', type: 'address' },
|
|
18
|
+
{ name: 'delegator', type: 'address' },
|
|
19
|
+
{ name: 'authority', type: 'bytes32' },
|
|
20
|
+
{ name: 'caveats', type: 'Caveat[]' },
|
|
21
|
+
{ name: 'salt', type: 'uint256' },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
exports.SIGNABLE_DELEGATION_TYPED_DATA = {
|
|
25
|
+
EIP712Domain,
|
|
26
|
+
...SDK_SIGNABLE_DELEGATION_TYPED_DATA,
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GACzB,oEAA2E,CAAC;AAE9E,MAAM,YAAY,GAAG;IACnB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;CAC/C,CAAC;AAEF,MAAM,kCAAkC,GAAG;IACzC,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;KACjC;IACD,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;QACrC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;KAClC;CACO,CAAC;AAEE,QAAA,8BAA8B,GAAG;IAC5C,YAAY;IACZ,GAAG,kCAAkC;CACtC,CAAC","sourcesContent":["import type { Hex } from './types.js';\n\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as Hex;\n\nconst EIP712Domain = [\n { name: 'name', type: 'string' },\n { name: 'version', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n { name: 'verifyingContract', type: 'address' },\n];\n\nconst SDK_SIGNABLE_DELEGATION_TYPED_DATA = {\n Caveat: [\n { name: 'enforcer', type: 'address' },\n { name: 'terms', type: 'bytes' },\n ],\n Delegation: [\n { name: 'delegate', type: 'address' },\n { name: 'delegator', type: 'address' },\n { name: 'authority', type: 'bytes32' },\n { name: 'caveats', type: 'Caveat[]' },\n { name: 'salt', type: 'uint256' },\n ],\n} as const;\n\nexport const SIGNABLE_DELEGATION_TYPED_DATA = {\n EIP712Domain,\n ...SDK_SIGNABLE_DELEGATION_TYPED_DATA,\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const ROOT_AUTHORITY: `0x${string}`;
|
|
2
|
+
export declare const SIGNABLE_DELEGATION_TYPED_DATA: {
|
|
3
|
+
Caveat: readonly [{
|
|
4
|
+
readonly name: "enforcer";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly name: "terms";
|
|
8
|
+
readonly type: "bytes";
|
|
9
|
+
}];
|
|
10
|
+
Delegation: readonly [{
|
|
11
|
+
readonly name: "delegate";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "delegator";
|
|
15
|
+
readonly type: "address";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "authority";
|
|
18
|
+
readonly type: "bytes32";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "caveats";
|
|
21
|
+
readonly type: "Caveat[]";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "salt";
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
}];
|
|
26
|
+
EIP712Domain: {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=constants.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,eACkD,CAAC;AAuB9E,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const ROOT_AUTHORITY: `0x${string}`;
|
|
2
|
+
export declare const SIGNABLE_DELEGATION_TYPED_DATA: {
|
|
3
|
+
Caveat: readonly [{
|
|
4
|
+
readonly name: "enforcer";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
}, {
|
|
7
|
+
readonly name: "terms";
|
|
8
|
+
readonly type: "bytes";
|
|
9
|
+
}];
|
|
10
|
+
Delegation: readonly [{
|
|
11
|
+
readonly name: "delegate";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly name: "delegator";
|
|
15
|
+
readonly type: "address";
|
|
16
|
+
}, {
|
|
17
|
+
readonly name: "authority";
|
|
18
|
+
readonly type: "bytes32";
|
|
19
|
+
}, {
|
|
20
|
+
readonly name: "caveats";
|
|
21
|
+
readonly type: "Caveat[]";
|
|
22
|
+
}, {
|
|
23
|
+
readonly name: "salt";
|
|
24
|
+
readonly type: "uint256";
|
|
25
|
+
}];
|
|
26
|
+
EIP712Domain: {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,eACkD,CAAC;AAuB9E,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GACzB,oEAA2E,CAAC;AAE9E,MAAM,YAAY,GAAG;IACnB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;CAC/C,CAAC;AAEF,MAAM,kCAAkC,GAAG;IACzC,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;KACjC;IACD,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;QACrC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;KAClC;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,YAAY;IACZ,GAAG,kCAAkC;CACtC,CAAC","sourcesContent":["import type { Hex } from './types.js';\n\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as Hex;\n\nconst EIP712Domain = [\n { name: 'name', type: 'string' },\n { name: 'version', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n { name: 'verifyingContract', type: 'address' },\n];\n\nconst SDK_SIGNABLE_DELEGATION_TYPED_DATA = {\n Caveat: [\n { name: 'enforcer', type: 'address' },\n { name: 'terms', type: 'bytes' },\n ],\n Delegation: [\n { name: 'delegate', type: 'address' },\n { name: 'delegator', type: 'address' },\n { name: 'authority', type: 'bytes32' },\n { name: 'caveats', type: 'Caveat[]' },\n { name: 'salt', type: 'uint256' },\n ],\n} as const;\n\nexport const SIGNABLE_DELEGATION_TYPED_DATA = {\n EIP712Domain,\n ...SDK_SIGNABLE_DELEGATION_TYPED_DATA,\n};\n"]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegationController = void 0;
|
|
4
|
+
var DelegationController_js_1 = require("./DelegationController.cjs");
|
|
5
|
+
Object.defineProperty(exports, "DelegationController", { enumerable: true, get: function () { return DelegationController_js_1.DelegationController; } });
|
|
6
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,sEAAiE;AAAxD,+HAAA,oBAAoB,OAAA","sourcesContent":["export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types.js';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n} from './types.js';\n\nexport { DelegationController } from './DelegationController.js';\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { DelegationControllerSignDelegationAction } from "./DelegationController-method-action-types.cjs";
|
|
2
|
+
export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, } from "./types.cjs";
|
|
3
|
+
export { DelegationController } from "./DelegationController.cjs";
|
|
4
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wCAAwC,EAAE,uDAAsD;AAC9G,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,GAC9B,oBAAmB;AAEpB,OAAO,EAAE,oBAAoB,EAAE,mCAAkC"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { DelegationControllerSignDelegationAction } from "./DelegationController-method-action-types.mjs";
|
|
2
|
+
export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, } from "./types.mjs";
|
|
3
|
+
export { DelegationController } from "./DelegationController.mjs";
|
|
4
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wCAAwC,EAAE,uDAAsD;AAC9G,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,GAC9B,oBAAmB;AAEpB,OAAO,EAAE,oBAAoB,EAAE,mCAAkC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,mCAAkC","sourcesContent":["export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types.js';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n} from './types.js';\n\nexport { DelegationController } from './DelegationController.js';\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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 { DelegationControllerMethodActions } from './DelegationController-method-action-types.js';\nimport type { controllerName } from './DelegationController.js';\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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import type { KeyringControllerSignTypedMessageAction } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import type { DelegationControllerMethodActions } from
|
|
5
|
-
import type { controllerName } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
|
+
import type { DelegationControllerMethodActions } from "./DelegationController-method-action-types.cjs";
|
|
5
|
+
import type { controllerName } from "./DelegationController.cjs";
|
|
6
6
|
type Hex = `0x${string}`;
|
|
7
7
|
type Address = `0x${string}`;
|
|
8
8
|
export type { Address, Hex };
|
|
@@ -66,4 +66,4 @@ export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
|
|
|
66
66
|
type AllowedActions = KeyringControllerSignTypedMessageAction;
|
|
67
67
|
type AllowedEvents = never;
|
|
68
68
|
export type DelegationControllerMessenger = Messenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents>;
|
|
69
|
-
//# sourceMappingURL=types.d.
|
|
69
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,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,iCAAiC,EAAE,uDAAsD;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAkC;AAEhE,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;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0DAA0D;IAC1D,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"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
+
import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
|
|
3
|
+
import type { Messenger } from "@metamask/messenger";
|
|
4
|
+
import type { DelegationControllerMethodActions } from "./DelegationController-method-action-types.mjs";
|
|
5
|
+
import type { controllerName } from "./DelegationController.mjs";
|
|
6
|
+
type Hex = `0x${string}`;
|
|
7
|
+
type Address = `0x${string}`;
|
|
8
|
+
export type { Address, Hex };
|
|
9
|
+
/**
|
|
10
|
+
* A version agnostic blob of contract addresses required for the DeleGator system to function.
|
|
11
|
+
*/
|
|
12
|
+
export type DeleGatorEnvironment = {
|
|
13
|
+
DelegationManager: Hex;
|
|
14
|
+
EntryPoint: Hex;
|
|
15
|
+
SimpleFactory: Hex;
|
|
16
|
+
implementations: {
|
|
17
|
+
[implementation: string]: Hex;
|
|
18
|
+
};
|
|
19
|
+
caveatEnforcers: {
|
|
20
|
+
[enforcer: string]: Hex;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A delegation caveat is a condition that must be met in order for a delegation
|
|
25
|
+
* to be valid. The caveat is defined by an enforcer, terms, and arguments.
|
|
26
|
+
*
|
|
27
|
+
* @see https://docs.gator.metamask.io/concepts/caveat-enforcers
|
|
28
|
+
*/
|
|
29
|
+
export type Caveat = {
|
|
30
|
+
enforcer: Hex;
|
|
31
|
+
terms: Hex;
|
|
32
|
+
args: Hex;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A delegation is a signed statement that gives a delegate permission to
|
|
36
|
+
* act on behalf of a delegator. The permissions are defined by a set of caveats.
|
|
37
|
+
* The caveats are a set of conditions that must be met in order for the delegation
|
|
38
|
+
* to be valid.
|
|
39
|
+
*
|
|
40
|
+
* @see https://docs.gator.metamask.io/concepts/delegation
|
|
41
|
+
*/
|
|
42
|
+
export type Delegation = {
|
|
43
|
+
/** The address of the delegate. */
|
|
44
|
+
delegate: Hex;
|
|
45
|
+
/** The address of the delegator. */
|
|
46
|
+
delegator: Hex;
|
|
47
|
+
/** The hash of the parent delegation, or the root authority if this is the root delegation. */
|
|
48
|
+
authority: Hex;
|
|
49
|
+
/** The terms of the delegation. */
|
|
50
|
+
caveats: Caveat[];
|
|
51
|
+
/** The salt used to generate the delegation signature. */
|
|
52
|
+
salt: Hex;
|
|
53
|
+
/** The signature of the delegation. */
|
|
54
|
+
signature: Hex;
|
|
55
|
+
};
|
|
56
|
+
/** An unsigned delegation is a delegation without a signature. */
|
|
57
|
+
export type UnsignedDelegation = Omit<Delegation, 'signature'>;
|
|
58
|
+
export type DelegationStruct = Omit<Delegation, 'salt'> & {
|
|
59
|
+
salt: bigint;
|
|
60
|
+
};
|
|
61
|
+
export type DelegationControllerState = {};
|
|
62
|
+
export type DelegationControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DelegationControllerState>;
|
|
63
|
+
export type DelegationControllerActions = DelegationControllerGetStateAction | DelegationControllerMethodActions;
|
|
64
|
+
export type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DelegationControllerState>;
|
|
65
|
+
export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
|
|
66
|
+
type AllowedActions = KeyringControllerSignTypedMessageAction;
|
|
67
|
+
type AllowedEvents = never;
|
|
68
|
+
export type DelegationControllerMessenger = Messenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents>;
|
|
69
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,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,iCAAiC,EAAE,uDAAsD;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,mCAAkC;AAEhE,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;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0DAA0D;IAC1D,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"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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 { DelegationControllerMethodActions } from './DelegationController-method-action-types.js';\nimport type { controllerName } from './DelegationController.js';\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
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTypedMessageParams = exports.toDelegationStruct = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const constants_js_1 = require("./constants.cjs");
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Delegation to a DelegationStruct.
|
|
8
|
+
* The DelegationStruct is the format used in the Delegation Framework.
|
|
9
|
+
*
|
|
10
|
+
* @param delegation the delegation to format
|
|
11
|
+
* @returns the formatted delegation
|
|
12
|
+
*/
|
|
13
|
+
const toDelegationStruct = (delegation) => {
|
|
14
|
+
const caveats = delegation.caveats.map((caveat) => ({
|
|
15
|
+
enforcer: (0, utils_1.getChecksumAddress)(caveat.enforcer),
|
|
16
|
+
terms: caveat.terms,
|
|
17
|
+
args: caveat.args,
|
|
18
|
+
}));
|
|
19
|
+
const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);
|
|
20
|
+
return {
|
|
21
|
+
delegate: (0, utils_1.getChecksumAddress)(delegation.delegate),
|
|
22
|
+
delegator: (0, utils_1.getChecksumAddress)(delegation.delegator),
|
|
23
|
+
authority: delegation.authority,
|
|
24
|
+
caveats,
|
|
25
|
+
salt,
|
|
26
|
+
signature: delegation.signature,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.toDelegationStruct = toDelegationStruct;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param opts - The options for creating typed message params.
|
|
33
|
+
* @returns The typed message params.
|
|
34
|
+
*/
|
|
35
|
+
function createTypedMessageParams(opts) {
|
|
36
|
+
const { chainId, from, delegation, verifyingContract } = opts;
|
|
37
|
+
const data = {
|
|
38
|
+
data: {
|
|
39
|
+
types: constants_js_1.SIGNABLE_DELEGATION_TYPED_DATA,
|
|
40
|
+
primaryType: 'Delegation',
|
|
41
|
+
domain: {
|
|
42
|
+
chainId,
|
|
43
|
+
name: 'DelegationManager',
|
|
44
|
+
version: '1',
|
|
45
|
+
verifyingContract,
|
|
46
|
+
},
|
|
47
|
+
message: (0, exports.toDelegationStruct)(delegation),
|
|
48
|
+
},
|
|
49
|
+
from,
|
|
50
|
+
};
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
exports.createTypedMessageParams = createTypedMessageParams;
|
|
54
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AAErD,kDAAgE;AAUhE;;;;;;GAMG;AACI,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,IAAA,0BAAkB,EAAC,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,IAAA,0BAAkB,EAAC,UAAU,CAAC,QAAQ,CAAC;QACjD,SAAS,EAAE,IAAA,0BAAkB,EAAC,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;AAnBW,QAAA,kBAAkB,sBAmB7B;AAEF;;;;GAIG;AACH,SAAgB,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,6CAA8B;YACrC,WAAW,EAAE,YAAY;YACzB,MAAM,EAAE;gBACN,OAAO;gBACP,IAAI,EAAE,mBAAmB;gBACzB,OAAO,EAAE,GAAG;gBACZ,iBAAiB;aAClB;YACD,OAAO,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.js';\nimport type { Address, Delegation, DelegationStruct } from './types.js';\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,5 +1,5 @@
|
|
|
1
|
-
import type { TypedMessageParams } from
|
|
2
|
-
import type { Address, Delegation, DelegationStruct } from
|
|
1
|
+
import type { TypedMessageParams } from "@metamask/keyring-controller";
|
|
2
|
+
import type { Address, Delegation, DelegationStruct } from "./types.cjs";
|
|
3
3
|
type CreateTypedMessageParamsOptions = {
|
|
4
4
|
chainId: number;
|
|
5
5
|
from: Address;
|
|
@@ -21,4 +21,4 @@ export declare const toDelegationStruct: (delegation: Delegation) => DelegationS
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function createTypedMessageParams(opts: CreateTypedMessageParamsOptions): TypedMessageParams;
|
|
23
23
|
export {};
|
|
24
|
-
//# sourceMappingURL=utils.d.
|
|
24
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +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,oBAAmB;AAExE,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
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TypedMessageParams } from "@metamask/keyring-controller";
|
|
2
|
+
import type { Address, Delegation, DelegationStruct } from "./types.mjs";
|
|
3
|
+
type CreateTypedMessageParamsOptions = {
|
|
4
|
+
chainId: number;
|
|
5
|
+
from: Address;
|
|
6
|
+
delegation: Delegation;
|
|
7
|
+
verifyingContract: Address;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Converts a Delegation to a DelegationStruct.
|
|
11
|
+
* The DelegationStruct is the format used in the Delegation Framework.
|
|
12
|
+
*
|
|
13
|
+
* @param delegation the delegation to format
|
|
14
|
+
* @returns the formatted delegation
|
|
15
|
+
*/
|
|
16
|
+
export declare const toDelegationStruct: (delegation: Delegation) => DelegationStruct;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param opts - The options for creating typed message params.
|
|
20
|
+
* @returns The typed message params.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTypedMessageParams(opts: CreateTypedMessageParamsOptions): TypedMessageParams;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +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,oBAAmB;AAExE,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,5 +1,5 @@
|
|
|
1
|
-
import { getChecksumAddress } from
|
|
2
|
-
import { SIGNABLE_DELEGATION_TYPED_DATA } from
|
|
1
|
+
import { getChecksumAddress } from "@metamask/utils";
|
|
2
|
+
import { SIGNABLE_DELEGATION_TYPED_DATA } from "./constants.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Converts a Delegation to a DelegationStruct.
|
|
5
5
|
* The DelegationStruct is the format used in the Delegation Framework.
|
|
@@ -46,4 +46,4 @@ export function createTypedMessageParams(opts) {
|
|
|
46
46
|
};
|
|
47
47
|
return data;
|
|
48
48
|
}
|
|
49
|
-
//# sourceMappingURL=utils.
|
|
49
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +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,wBAAuB;AAUhE;;;;;;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.js';\nimport type { Address, Delegation, DelegationStruct } from './types.js';\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": "3.0.2-preview-
|
|
3
|
+
"version": "3.0.2-preview-acb2929f3",
|
|
4
4
|
"description": "Manages delegations for MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,12 +18,19 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
-
"type": "module",
|
|
22
21
|
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
|
-
"
|
|
26
|
-
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
33
|
+
}
|
|
27
34
|
},
|
|
28
35
|
"./package.json": "./package.json"
|
|
29
36
|
},
|
|
@@ -32,11 +39,9 @@
|
|
|
32
39
|
"registry": "https://registry.npmjs.org/"
|
|
33
40
|
},
|
|
34
41
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
-
"build:all": "
|
|
37
|
-
"build:clean": "yarn build:only-clean && yarn build",
|
|
42
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
43
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
38
44
|
"build:docs": "typedoc",
|
|
39
|
-
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
40
45
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/delegation-controller",
|
|
41
46
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/delegation-controller",
|
|
42
47
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -57,18 +62,17 @@
|
|
|
57
62
|
},
|
|
58
63
|
"devDependencies": {
|
|
59
64
|
"@metamask/auto-changelog": "^6.1.0",
|
|
65
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
60
66
|
"@types/jest": "^30.0.0",
|
|
61
|
-
"@typescript/native": "npm:typescript@^7.0.2",
|
|
62
67
|
"deepmerge": "^4.2.2",
|
|
63
68
|
"jest": "^30.4.2",
|
|
64
|
-
"rimraf": "^5.0.5",
|
|
65
69
|
"ts-jest": "^29.4.11",
|
|
66
70
|
"tsx": "^4.20.5",
|
|
67
71
|
"typedoc": "^0.25.13",
|
|
68
72
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
69
|
-
"typescript": "
|
|
73
|
+
"typescript": "~5.3.3"
|
|
70
74
|
},
|
|
71
75
|
"engines": {
|
|
72
|
-
"node": "^
|
|
76
|
+
"node": "^18.18 || >=20"
|
|
73
77
|
}
|
|
74
78
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DelegationController-method-action-types.d.ts","sourceRoot":"","sources":["../src/DelegationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;;;;;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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DelegationController-method-action-types.js","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.js';\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DelegationController.d.ts","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI3D,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,oBAAoB,EACpB,GAAG,EACH,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAmBrD;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;;IAGC;;;;;;;OAOG;IACH,YAAY,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,EAgBA;IAED;;;;;;;OAOG;IACG,cAAc,CAAC,MAAM,EAAE;QAC3B,UAAU,EAAE,kBAAkB,CAAC;QAC/B,OAAO,EAAE,GAAG,CAAC;KACd,mBAuBA;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DelegationController.js","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAS9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,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;IACU,yBAAyB,CAAyC;IAE3E;;;;;;;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;QACH,IAAI,CAAC,yBAAyB,GAAG,wBAAwB,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,IAAI,CAAC,yBAAyB,CAAC,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.js';\nimport { createTypedMessageParams } from './utils.js';\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"]}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Hex } from './types.js';
|
|
2
|
-
export declare const ROOT_AUTHORITY: Hex;
|
|
3
|
-
export declare const SIGNABLE_DELEGATION_TYPED_DATA: {
|
|
4
|
-
Caveat: readonly [{
|
|
5
|
-
readonly name: 'enforcer';
|
|
6
|
-
readonly type: 'address';
|
|
7
|
-
}, {
|
|
8
|
-
readonly name: 'terms';
|
|
9
|
-
readonly type: 'bytes';
|
|
10
|
-
}];
|
|
11
|
-
Delegation: readonly [{
|
|
12
|
-
readonly name: 'delegate';
|
|
13
|
-
readonly type: 'address';
|
|
14
|
-
}, {
|
|
15
|
-
readonly name: 'delegator';
|
|
16
|
-
readonly type: 'address';
|
|
17
|
-
}, {
|
|
18
|
-
readonly name: 'authority';
|
|
19
|
-
readonly type: 'bytes32';
|
|
20
|
-
}, {
|
|
21
|
-
readonly name: 'caveats';
|
|
22
|
-
readonly type: 'Caveat[]';
|
|
23
|
-
}, {
|
|
24
|
-
readonly name: 'salt';
|
|
25
|
-
readonly type: 'uint256';
|
|
26
|
-
}];
|
|
27
|
-
EIP712Domain: {
|
|
28
|
-
name: string;
|
|
29
|
-
type: string;
|
|
30
|
-
}[];
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,cAAc,EAC+C,GAAG,CAAC;AAuB9E,eAAO,MAAM,8BAA8B;;iBAZrC,IAAI,EAAE,UAAU;iBAAE,IAAI,EAAE,SAAS;;iBACjC,IAAI,EAAE,OAAO;iBAAE,IAAI,EAAE,OAAO;;;iBAG5B,IAAI,EAAE,UAAU;iBAAE,IAAI,EAAE,SAAS;;iBACjC,IAAI,EAAE,WAAW;iBAAE,IAAI,EAAE,SAAS;;iBAClC,IAAI,EAAE,WAAW;iBAAE,IAAI,EAAE,SAAS;;iBAClC,IAAI,EAAE,SAAS;iBAAE,IAAI,EAAE,UAAU;;iBACjC,IAAI,EAAE,MAAM;iBAAE,IAAI,EAAE,SAAS;;;;;;CAOlC,CAAC"}
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GACzB,oEAA2E,CAAC;AAE9E,MAAM,YAAY,GAAG;IACnB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;CAC/C,CAAC;AAEF,MAAM,kCAAkC,GAAG;IACzC,MAAM,EAAE;QACN,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;KACjC;IACD,UAAU,EAAE;QACV,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE;QACrC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE;QACrC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;KAClC;CACO,CAAC;AAEX,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,YAAY;IACZ,GAAG,kCAAkC;CACtC,CAAC","sourcesContent":["import type { Hex } from './types.js';\n\nexport const ROOT_AUTHORITY =\n '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' as Hex;\n\nconst EIP712Domain = [\n { name: 'name', type: 'string' },\n { name: 'version', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n { name: 'verifyingContract', type: 'address' },\n];\n\nconst SDK_SIGNABLE_DELEGATION_TYPED_DATA = {\n Caveat: [\n { name: 'enforcer', type: 'address' },\n { name: 'terms', type: 'bytes' },\n ],\n Delegation: [\n { name: 'delegate', type: 'address' },\n { name: 'delegator', type: 'address' },\n { name: 'authority', type: 'bytes32' },\n { name: 'caveats', type: 'Caveat[]' },\n { name: 'salt', type: 'uint256' },\n ],\n} as const;\n\nexport const SIGNABLE_DELEGATION_TYPED_DATA = {\n EIP712Domain,\n ...SDK_SIGNABLE_DELEGATION_TYPED_DATA,\n};\n"]}
|
package/dist/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types.js';
|
|
2
|
-
export type { DelegationControllerGetStateAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, } from './types.js';
|
|
3
|
-
export { DelegationController } from './DelegationController.js';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAC;AAC9G,YAAY,EACV,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC","sourcesContent":["export type { DelegationControllerSignDelegationAction } from './DelegationController-method-action-types.js';\nexport type {\n DelegationControllerGetStateAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n} from './types.js';\n\nexport { DelegationController } from './DelegationController.js';\n"]}
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,MAAM,8BAA8B,CAAC;AAC5F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,+CAA+C,CAAC;AACvG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,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;IACf,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0DAA0D;IAC1D,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"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","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 { DelegationControllerMethodActions } from './DelegationController-method-action-types.js';\nimport type { controllerName } from './DelegationController.js';\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.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAIvE,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAExE,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.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAUhE;;;;;;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.js';\nimport type { Address, Delegation, DelegationStruct } from './types.js';\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"]}
|