@metamask-previews/delegation-controller 0.0.0-preview-31a5eea2
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 +14 -0
- package/LICENSE +20 -0
- package/README.md +15 -0
- package/dist/DelegationController.cjs +210 -0
- package/dist/DelegationController.cjs.map +1 -0
- package/dist/DelegationController.d.cts +76 -0
- package/dist/DelegationController.d.cts.map +1 -0
- package/dist/DelegationController.d.mts +76 -0
- package/dist/DelegationController.d.mts.map +1 -0
- package/dist/DelegationController.mjs +206 -0
- 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.mjs +25 -0
- 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 +3 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +3 -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.cts +107 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +107 -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 +65 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +32 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +32 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +59 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +77 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"DelegationController.mjs","sourceRoot":"","sources":["../src/DelegationController.ts"],"names":[],"mappings":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gBACvB,UAAU,CAAC,IAAI,CAAC,CAAQ,CAAC,CAAC;YAC5B,CAAC,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SACjC;QAED,qBAAqB;QACrB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC1B,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC,MAAM,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport { hexToNumber } from '@metamask/utils';\n\nimport { ROOT_AUTHORITY } from './constants';\nimport type {\n Address,\n Delegation,\n DelegationControllerMessenger,\n DelegationControllerState,\n DelegationEntry,\n DelegationFilter,\n DeleGatorEnvironment,\n Hex,\n UnsignedDelegation,\n} from './types';\nimport { createTypedMessageParams, isHexEqual } from './utils';\n\nexport const controllerName = 'DelegationController';\n\nconst delegationControllerMetadata = {\n delegations: {\n persist: true,\n anonymous: false,\n },\n} satisfies StateMetadata<DelegationControllerState>;\n\n/**\n * Constructs the default {@link DelegationController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link DelegationController} state.\n */\nfunction getDefaultDelegationControllerState(): DelegationControllerState {\n return {\n delegations: {},\n };\n}\n\n/**\n * The {@link DelegationController} class.\n * This controller is meant to be a centralized place to store and sign delegations.\n */\nexport class DelegationController extends BaseController<\n typeof controllerName,\n DelegationControllerState,\n DelegationControllerMessenger\n> {\n readonly #hashDelegation: (delegation: Delegation) => Hex;\n\n readonly #getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n\n /**\n * Constructs a new {@link DelegationController} instance.\n *\n * @param params - The parameters for constructing the controller.\n * @param params.messenger - The messenger instance to use for the controller.\n * @param params.state - The initial state for the controller.\n * @param params.hashDelegation - A function to hash delegations.\n * @param params.getDelegationEnvironment - A function to get the delegation environment for a given chainId.\n */\n constructor({\n messenger,\n state,\n hashDelegation,\n getDelegationEnvironment,\n }: {\n messenger: DelegationControllerMessenger;\n state?: Partial<DelegationControllerState>;\n hashDelegation: (delegation: Delegation) => Hex;\n getDelegationEnvironment: (chainId: Hex) => DeleGatorEnvironment;\n }) {\n super({\n messenger,\n metadata: delegationControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultDelegationControllerState(),\n ...state,\n },\n });\n this.#hashDelegation = hashDelegation;\n this.#getDelegationEnvironment = getDelegationEnvironment;\n }\n\n /**\n * Signs a delegation.\n *\n * @param params - The parameters for signing the delegation.\n * @param params.delegation - The delegation to sign.\n * @param params.chainId - The chainId of the chain to sign the delegation for.\n * @returns The signature of the delegation.\n */\n async signDelegation(params: {\n delegation: UnsignedDelegation;\n chainId: Hex;\n }) {\n const { delegation, chainId } = params;\n const { DelegationManager } = this.#getDelegationEnvironment(chainId);\n\n const data = createTypedMessageParams({\n chainId: hexToNumber(chainId),\n from: delegation.delegator,\n delegation: {\n ...delegation,\n signature: '0x',\n },\n verifyingContract: DelegationManager,\n });\n\n // TODO:: Replace with `SignatureController:newUnsignedTypedMessage`.\n // Waiting on confirmations team to implement this.\n const signature: string = await this.messagingSystem.call(\n 'KeyringController:signTypedMessage',\n data,\n SignTypedDataVersion.V4,\n );\n\n return signature;\n }\n\n /**\n * Stores a delegation in storage.\n *\n * @param params - The parameters for storing the delegation.\n * @param params.entry - The delegation entry to store.\n */\n store(params: { entry: DelegationEntry }) {\n const { entry } = params;\n const hash = this.#hashDelegation(entry.delegation);\n\n // If the authority is not the root authority, validate that the\n // parent entry does exist.\n if (\n !isHexEqual(entry.delegation.authority, ROOT_AUTHORITY) &&\n !this.state.delegations[entry.delegation.authority]\n ) {\n throw new Error('Invalid authority');\n }\n this.update((state) => {\n state.delegations[hash] = entry;\n });\n }\n\n /**\n * Lists delegation entries.\n *\n * @param filter - The filter to use to list the delegation entries.\n * @returns A list of delegation entries that match the filter.\n */\n list(filter?: DelegationFilter) {\n const account = this.messagingSystem.call(\n 'AccountsController:getSelectedAccount',\n );\n const requester = account.address as Address;\n\n let list: DelegationEntry[] = Object.values(this.state.delegations);\n\n if (filter?.from) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegator, filter.from as Address),\n );\n }\n\n if (\n !filter?.from ||\n (filter?.from && !isHexEqual(filter.from, requester))\n ) {\n list = list.filter((entry) =>\n isHexEqual(entry.delegation.delegate, requester),\n );\n }\n\n const filterChainId = filter?.chainId;\n if (filterChainId) {\n list = list.filter((entry) => isHexEqual(entry.chainId, filterChainId));\n }\n\n const tags = filter?.tags;\n if (tags && tags.length > 0) {\n // Filter entries that contain all of the filter tags\n list = list.filter((entry) =>\n tags.every((tag) => entry.tags.includes(tag)),\n );\n }\n\n return list;\n }\n\n /**\n * Retrieves the delegation entry for a given delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation entry, or null if not found.\n */\n retrieve(hash: Hex) {\n return this.state.delegations[hash] ?? null;\n }\n\n /**\n * Retrieves a delegation chain from a delegation hash.\n *\n * @param hash - The hash of the delegation to retrieve.\n * @returns The delegation chain, or null if not found.\n */\n chain(hash: Hex) {\n const chain: DelegationEntry[] = [];\n\n const entry = this.retrieve(hash);\n if (!entry) {\n return null;\n }\n chain.push(entry);\n\n for (let _hash = entry.delegation.authority; _hash !== ROOT_AUTHORITY; ) {\n const parent = this.retrieve(_hash);\n if (!parent) {\n throw new Error('Invalid delegation chain');\n }\n chain.push(parent);\n _hash = parent.delegation.authority;\n }\n\n return chain;\n }\n\n /**\n * Deletes a delegation entrie from storage, along with any other entries\n * that are redelegated from it.\n *\n * @param hash - The hash of the delegation to delete.\n * @returns The number of entries deleted.\n */\n delete(hash: Hex): number {\n const root = this.retrieve(hash);\n if (!root) {\n return 0;\n }\n\n const entries = Object.entries(this.state.delegations);\n const nextHashes: Hex[] = [hash];\n const deletedHashes: Hex[] = [];\n\n while (nextHashes.length > 0) {\n const currentHash = nextHashes.pop() as Hex;\n\n // Find all delegations that have this hash as their authority\n const children = entries.filter(\n ([_, v]) => v.delegation.authority === currentHash,\n );\n\n // Add the hashes of all child delegations to be processed next\n children.forEach(([k]) => {\n nextHashes.push(k as Hex);\n });\n\n deletedHashes.push(currentHash);\n }\n\n // Delete delegations\n this.update((state) => {\n deletedHashes.forEach((h) => {\n delete state.delegations[h];\n });\n });\n\n return deletedHashes.length;\n }\n}\n"]}
|
@@ -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';\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,25 @@
|
|
1
|
+
export const ROOT_AUTHORITY = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
|
2
|
+
const EIP712Domain = [
|
3
|
+
{ name: 'name', type: 'string' },
|
4
|
+
{ name: 'version', type: 'string' },
|
5
|
+
{ name: 'chainId', type: 'uint256' },
|
6
|
+
{ name: 'verifyingContract', type: 'address' },
|
7
|
+
];
|
8
|
+
const SDK_SIGNABLE_DELEGATION_TYPED_DATA = {
|
9
|
+
Caveat: [
|
10
|
+
{ name: 'enforcer', type: 'address' },
|
11
|
+
{ name: 'terms', type: 'bytes' },
|
12
|
+
],
|
13
|
+
Delegation: [
|
14
|
+
{ name: 'delegate', type: 'address' },
|
15
|
+
{ name: 'delegator', type: 'address' },
|
16
|
+
{ name: 'authority', type: 'bytes32' },
|
17
|
+
{ name: 'caveats', type: 'Caveat[]' },
|
18
|
+
{ name: 'salt', type: 'uint256' },
|
19
|
+
],
|
20
|
+
};
|
21
|
+
export const SIGNABLE_DELEGATION_TYPED_DATA = {
|
22
|
+
EIP712Domain,
|
23
|
+
...SDK_SIGNABLE_DELEGATION_TYPED_DATA,
|
24
|
+
};
|
25
|
+
//# sourceMappingURL=constants.mjs.map
|
@@ -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';\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_1 = require("./DelegationController.cjs");
|
5
|
+
Object.defineProperty(exports, "DelegationController", { enumerable: true, get: function () { return DelegationController_1.DelegationController; } });
|
6
|
+
//# sourceMappingURL=index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAcA,mEAA8D;AAArD,4HAAA,oBAAoB,OAAA","sourcesContent":["export type {\n DelegationControllerSignDelegationAction,\n DelegationControllerStoreAction,\n DelegationControllerListAction,\n DelegationControllerRetrieveAction,\n DelegationControllerChainAction,\n DelegationControllerDeleteAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n DelegationEntry,\n DelegationFilter,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\n"]}
|
package/dist/index.d.cts
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
export type { DelegationControllerSignDelegationAction, DelegationControllerStoreAction, DelegationControllerListAction, DelegationControllerRetrieveAction, DelegationControllerChainAction, DelegationControllerDeleteAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, DelegationEntry, DelegationFilter, } from "./types.cjs";
|
2
|
+
export { DelegationController } from "./DelegationController.cjs";
|
3
|
+
//# sourceMappingURL=index.d.cts.map
|
@@ -0,0 +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,EAChC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,GACjB,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
export type { DelegationControllerSignDelegationAction, DelegationControllerStoreAction, DelegationControllerListAction, DelegationControllerRetrieveAction, DelegationControllerChainAction, DelegationControllerDeleteAction, DelegationControllerActions, DelegationControllerEvents, DelegationControllerMessenger, DelegationEntry, DelegationFilter, } from "./types.mjs";
|
2
|
+
export { DelegationController } from "./DelegationController.mjs";
|
3
|
+
//# sourceMappingURL=index.d.mts.map
|
@@ -0,0 +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,EAChC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,GACjB,oBAAgB;AAEjB,OAAO,EAAE,oBAAoB,EAAE,mCAA+B"}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,mCAA+B","sourcesContent":["export type {\n DelegationControllerSignDelegationAction,\n DelegationControllerStoreAction,\n DelegationControllerListAction,\n DelegationControllerRetrieveAction,\n DelegationControllerChainAction,\n DelegationControllerDeleteAction,\n DelegationControllerActions,\n DelegationControllerEvents,\n DelegationControllerMessenger,\n DelegationEntry,\n DelegationFilter,\n} from './types';\n\nexport { DelegationController } from './DelegationController';\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 { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\n/**\n * A version agnostic blob of contract addresses required for the DeleGator system to function.\n */\nexport type DeleGatorEnvironment = {\n DelegationManager: Hex;\n EntryPoint: Hex;\n SimpleFactory: Hex;\n implementations: {\n [implementation: string]: Hex;\n };\n caveatEnforcers: {\n [enforcer: string]: Hex;\n };\n};\n\n/**\n * A delegation caveat is a condition that must be met in order for a delegation\n * to be valid. The caveat is defined by an enforcer, terms, and arguments.\n *\n * @see https://docs.gator.metamask.io/concepts/caveat-enforcers\n */\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/types.d.cts
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
import type { AccountsControllerGetSelectedAccountAction } from "@metamask/accounts-controller";
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
|
3
|
+
import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
|
4
|
+
import type { controllerName, DelegationController } from "./DelegationController.cjs";
|
5
|
+
type Hex = `0x${string}`;
|
6
|
+
type Address = `0x${string}`;
|
7
|
+
export type { Address, Hex };
|
8
|
+
/**
|
9
|
+
* A version agnostic blob of contract addresses required for the DeleGator system to function.
|
10
|
+
*/
|
11
|
+
export type DeleGatorEnvironment = {
|
12
|
+
DelegationManager: Hex;
|
13
|
+
EntryPoint: Hex;
|
14
|
+
SimpleFactory: Hex;
|
15
|
+
implementations: {
|
16
|
+
[implementation: string]: Hex;
|
17
|
+
};
|
18
|
+
caveatEnforcers: {
|
19
|
+
[enforcer: string]: Hex;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* A delegation caveat is a condition that must be met in order for a delegation
|
24
|
+
* to be valid. The caveat is defined by an enforcer, terms, and arguments.
|
25
|
+
*
|
26
|
+
* @see https://docs.gator.metamask.io/concepts/caveat-enforcers
|
27
|
+
*/
|
28
|
+
export type Caveat = {
|
29
|
+
enforcer: Hex;
|
30
|
+
terms: Hex;
|
31
|
+
args: Hex;
|
32
|
+
};
|
33
|
+
/**
|
34
|
+
* A delegation is a signed statement that gives a delegate permission to
|
35
|
+
* act on behalf of a delegator. The permissions are defined by a set of caveats.
|
36
|
+
* The caveats are a set of conditions that must be met in order for the delegation
|
37
|
+
* to be valid.
|
38
|
+
*
|
39
|
+
* @see https://docs.gator.metamask.io/concepts/delegation
|
40
|
+
*/
|
41
|
+
export type Delegation = {
|
42
|
+
/** The address of the delegate. */
|
43
|
+
delegate: Hex;
|
44
|
+
/** The address of the delegator. */
|
45
|
+
delegator: Hex;
|
46
|
+
/** The hash of the parent delegation, or the root authority if this is the root delegation. */
|
47
|
+
authority: Hex;
|
48
|
+
/** The terms of the delegation. */
|
49
|
+
caveats: Caveat[];
|
50
|
+
/** The salt used to generate the delegation signature. */
|
51
|
+
salt: Hex;
|
52
|
+
/** The signature of the delegation. */
|
53
|
+
signature: Hex;
|
54
|
+
};
|
55
|
+
/** An unsigned delegation is a delegation without a signature. */
|
56
|
+
export type UnsignedDelegation = Omit<Delegation, 'signature'>;
|
57
|
+
export type DelegationStruct = Omit<Delegation, 'salt'> & {
|
58
|
+
salt: bigint;
|
59
|
+
};
|
60
|
+
export type DelegationEntry = {
|
61
|
+
tags: string[];
|
62
|
+
chainId: Hex;
|
63
|
+
delegation: Delegation;
|
64
|
+
meta?: string;
|
65
|
+
};
|
66
|
+
export type DelegationFilter = {
|
67
|
+
chainId?: Hex;
|
68
|
+
tags?: string[];
|
69
|
+
from?: Address;
|
70
|
+
};
|
71
|
+
export type DelegationControllerState = {
|
72
|
+
delegations: {
|
73
|
+
[hash: Hex]: DelegationEntry;
|
74
|
+
};
|
75
|
+
};
|
76
|
+
export type DelegationControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DelegationControllerState>;
|
77
|
+
export type DelegationControllerSignDelegationAction = {
|
78
|
+
type: `${typeof controllerName}:signDelegation`;
|
79
|
+
handler: DelegationController['signDelegation'];
|
80
|
+
};
|
81
|
+
export type DelegationControllerStoreAction = {
|
82
|
+
type: `${typeof controllerName}:store`;
|
83
|
+
handler: DelegationController['store'];
|
84
|
+
};
|
85
|
+
export type DelegationControllerListAction = {
|
86
|
+
type: `${typeof controllerName}:list`;
|
87
|
+
handler: DelegationController['list'];
|
88
|
+
};
|
89
|
+
export type DelegationControllerRetrieveAction = {
|
90
|
+
type: `${typeof controllerName}:retrieve`;
|
91
|
+
handler: DelegationController['retrieve'];
|
92
|
+
};
|
93
|
+
export type DelegationControllerChainAction = {
|
94
|
+
type: `${typeof controllerName}:chain`;
|
95
|
+
handler: DelegationController['chain'];
|
96
|
+
};
|
97
|
+
export type DelegationControllerDeleteAction = {
|
98
|
+
type: `${typeof controllerName}:delete`;
|
99
|
+
handler: DelegationController['delete'];
|
100
|
+
};
|
101
|
+
export type DelegationControllerActions = DelegationControllerGetStateAction | DelegationControllerSignDelegationAction | DelegationControllerStoreAction | DelegationControllerListAction | DelegationControllerRetrieveAction | DelegationControllerChainAction | DelegationControllerDeleteAction;
|
102
|
+
export type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DelegationControllerState>;
|
103
|
+
export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
|
104
|
+
type AllowedActions = KeyringControllerSignTypedMessageAction | AccountsControllerGetSelectedAccountAction;
|
105
|
+
type AllowedEvents = never;
|
106
|
+
export type DelegationControllerMessenger = RestrictedMessenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
107
|
+
//# sourceMappingURL=types.d.cts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,GAAG,OAAO,cAAc,QAAQ,CAAC;IACvC,OAAO,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,GAAG,OAAO,cAAc,SAAS,CAAC;IACxC,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GACnC,kCAAkC,GAClC,wCAAwC,GACxC,+BAA+B,GAC/B,8BAA8B,GAC9B,kCAAkC,GAClC,+BAA+B,GAC/B,gCAAgC,CAAC;AAErC,MAAM,MAAM,oCAAoC,GAAG,0BAA0B,CAC3E,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E,KAAK,cAAc,GACf,uCAAuC,GACvC,0CAA0C,CAAC;AAE/C,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,6BAA6B,GAAG,mBAAmB,CAC7D,OAAO,cAAc,EACrB,2BAA2B,GAAG,cAAc,EAC5C,0BAA0B,GAAG,aAAa,EAC1C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
|
package/dist/types.d.mts
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
import type { AccountsControllerGetSelectedAccountAction } from "@metamask/accounts-controller";
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
|
3
|
+
import type { KeyringControllerSignTypedMessageAction } from "@metamask/keyring-controller";
|
4
|
+
import type { controllerName, DelegationController } from "./DelegationController.mjs";
|
5
|
+
type Hex = `0x${string}`;
|
6
|
+
type Address = `0x${string}`;
|
7
|
+
export type { Address, Hex };
|
8
|
+
/**
|
9
|
+
* A version agnostic blob of contract addresses required for the DeleGator system to function.
|
10
|
+
*/
|
11
|
+
export type DeleGatorEnvironment = {
|
12
|
+
DelegationManager: Hex;
|
13
|
+
EntryPoint: Hex;
|
14
|
+
SimpleFactory: Hex;
|
15
|
+
implementations: {
|
16
|
+
[implementation: string]: Hex;
|
17
|
+
};
|
18
|
+
caveatEnforcers: {
|
19
|
+
[enforcer: string]: Hex;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* A delegation caveat is a condition that must be met in order for a delegation
|
24
|
+
* to be valid. The caveat is defined by an enforcer, terms, and arguments.
|
25
|
+
*
|
26
|
+
* @see https://docs.gator.metamask.io/concepts/caveat-enforcers
|
27
|
+
*/
|
28
|
+
export type Caveat = {
|
29
|
+
enforcer: Hex;
|
30
|
+
terms: Hex;
|
31
|
+
args: Hex;
|
32
|
+
};
|
33
|
+
/**
|
34
|
+
* A delegation is a signed statement that gives a delegate permission to
|
35
|
+
* act on behalf of a delegator. The permissions are defined by a set of caveats.
|
36
|
+
* The caveats are a set of conditions that must be met in order for the delegation
|
37
|
+
* to be valid.
|
38
|
+
*
|
39
|
+
* @see https://docs.gator.metamask.io/concepts/delegation
|
40
|
+
*/
|
41
|
+
export type Delegation = {
|
42
|
+
/** The address of the delegate. */
|
43
|
+
delegate: Hex;
|
44
|
+
/** The address of the delegator. */
|
45
|
+
delegator: Hex;
|
46
|
+
/** The hash of the parent delegation, or the root authority if this is the root delegation. */
|
47
|
+
authority: Hex;
|
48
|
+
/** The terms of the delegation. */
|
49
|
+
caveats: Caveat[];
|
50
|
+
/** The salt used to generate the delegation signature. */
|
51
|
+
salt: Hex;
|
52
|
+
/** The signature of the delegation. */
|
53
|
+
signature: Hex;
|
54
|
+
};
|
55
|
+
/** An unsigned delegation is a delegation without a signature. */
|
56
|
+
export type UnsignedDelegation = Omit<Delegation, 'signature'>;
|
57
|
+
export type DelegationStruct = Omit<Delegation, 'salt'> & {
|
58
|
+
salt: bigint;
|
59
|
+
};
|
60
|
+
export type DelegationEntry = {
|
61
|
+
tags: string[];
|
62
|
+
chainId: Hex;
|
63
|
+
delegation: Delegation;
|
64
|
+
meta?: string;
|
65
|
+
};
|
66
|
+
export type DelegationFilter = {
|
67
|
+
chainId?: Hex;
|
68
|
+
tags?: string[];
|
69
|
+
from?: Address;
|
70
|
+
};
|
71
|
+
export type DelegationControllerState = {
|
72
|
+
delegations: {
|
73
|
+
[hash: Hex]: DelegationEntry;
|
74
|
+
};
|
75
|
+
};
|
76
|
+
export type DelegationControllerGetStateAction = ControllerGetStateAction<typeof controllerName, DelegationControllerState>;
|
77
|
+
export type DelegationControllerSignDelegationAction = {
|
78
|
+
type: `${typeof controllerName}:signDelegation`;
|
79
|
+
handler: DelegationController['signDelegation'];
|
80
|
+
};
|
81
|
+
export type DelegationControllerStoreAction = {
|
82
|
+
type: `${typeof controllerName}:store`;
|
83
|
+
handler: DelegationController['store'];
|
84
|
+
};
|
85
|
+
export type DelegationControllerListAction = {
|
86
|
+
type: `${typeof controllerName}:list`;
|
87
|
+
handler: DelegationController['list'];
|
88
|
+
};
|
89
|
+
export type DelegationControllerRetrieveAction = {
|
90
|
+
type: `${typeof controllerName}:retrieve`;
|
91
|
+
handler: DelegationController['retrieve'];
|
92
|
+
};
|
93
|
+
export type DelegationControllerChainAction = {
|
94
|
+
type: `${typeof controllerName}:chain`;
|
95
|
+
handler: DelegationController['chain'];
|
96
|
+
};
|
97
|
+
export type DelegationControllerDeleteAction = {
|
98
|
+
type: `${typeof controllerName}:delete`;
|
99
|
+
handler: DelegationController['delete'];
|
100
|
+
};
|
101
|
+
export type DelegationControllerActions = DelegationControllerGetStateAction | DelegationControllerSignDelegationAction | DelegationControllerStoreAction | DelegationControllerListAction | DelegationControllerRetrieveAction | DelegationControllerChainAction | DelegationControllerDeleteAction;
|
102
|
+
export type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, DelegationControllerState>;
|
103
|
+
export type DelegationControllerEvents = DelegationControllerStateChangeEvent;
|
104
|
+
type AllowedActions = KeyringControllerSignTypedMessageAction | AccountsControllerGetSelectedAccountAction;
|
105
|
+
type AllowedEvents = never;
|
106
|
+
export type DelegationControllerMessenger = RestrictedMessenger<typeof controllerName, DelegationControllerActions | AllowedActions, DelegationControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
107
|
+
//# 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,EAAE,0CAA0C,EAAE,sCAAsC;AAChG,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,KAAK,EAAE,uCAAuC,EAAE,qCAAqC;AAE5F,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,mCAA+B;AAEhC,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AACzB,KAAK,OAAO,GAAG,KAAK,MAAM,EAAE,CAAC;AAE7B,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAE7B;;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,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|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountsControllerGetSelectedAccountAction } from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { KeyringControllerSignTypedMessageAction } from '@metamask/keyring-controller';\n\nimport type {\n controllerName,\n DelegationController,\n} from './DelegationController';\n\ntype Hex = `0x${string}`;\ntype Address = `0x${string}`;\n\nexport type { Address, Hex };\n\n/**\n * A version agnostic blob of contract addresses required for the DeleGator system to function.\n */\nexport type DeleGatorEnvironment = {\n DelegationManager: Hex;\n EntryPoint: Hex;\n SimpleFactory: Hex;\n implementations: {\n [implementation: string]: Hex;\n };\n caveatEnforcers: {\n [enforcer: string]: Hex;\n };\n};\n\n/**\n * A delegation caveat is a condition that must be met in order for a delegation\n * to be valid. The caveat is defined by an enforcer, terms, and arguments.\n *\n * @see https://docs.gator.metamask.io/concepts/caveat-enforcers\n */\nexport type Caveat = {\n enforcer: Hex;\n terms: Hex;\n args: Hex;\n};\n\n/**\n * A delegation is a signed statement that gives a delegate permission to\n * act on behalf of a delegator. The permissions are defined by a set of caveats.\n * The caveats are a set of conditions that must be met in order for the delegation\n * to be valid.\n *\n * @see https://docs.gator.metamask.io/concepts/delegation\n */\nexport type Delegation = {\n /** The address of the delegate. */\n delegate: Hex;\n /** The address of the delegator. */\n delegator: Hex;\n /** The hash of the parent delegation, or the root authority if this is the root delegation. */\n authority: Hex;\n /** The terms of the delegation. */\n caveats: Caveat[];\n /** The salt used to generate the delegation signature. */\n salt: Hex;\n /** The signature of the delegation. */\n signature: Hex;\n};\n\n/** An unsigned delegation is a delegation without a signature. */\nexport type UnsignedDelegation = Omit<Delegation, 'signature'>;\n\nexport type DelegationStruct = Omit<Delegation, 'salt'> & {\n salt: bigint;\n};\n\nexport type DelegationEntry = {\n tags: string[];\n chainId: Hex;\n delegation: Delegation;\n meta?: string;\n};\n\nexport type DelegationFilter = {\n chainId?: Hex;\n tags?: string[];\n from?: Address;\n};\n\nexport type DelegationControllerState = {\n delegations: {\n [hash: Hex]: DelegationEntry;\n };\n};\n\nexport type DelegationControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerSignDelegationAction = {\n type: `${typeof controllerName}:signDelegation`;\n handler: DelegationController['signDelegation'];\n};\n\nexport type DelegationControllerStoreAction = {\n type: `${typeof controllerName}:store`;\n handler: DelegationController['store'];\n};\n\nexport type DelegationControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: DelegationController['list'];\n};\n\nexport type DelegationControllerRetrieveAction = {\n type: `${typeof controllerName}:retrieve`;\n handler: DelegationController['retrieve'];\n};\n\nexport type DelegationControllerChainAction = {\n type: `${typeof controllerName}:chain`;\n handler: DelegationController['chain'];\n};\n\nexport type DelegationControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: DelegationController['delete'];\n};\n\nexport type DelegationControllerActions =\n | DelegationControllerGetStateAction\n | DelegationControllerSignDelegationAction\n | DelegationControllerStoreAction\n | DelegationControllerListAction\n | DelegationControllerRetrieveAction\n | DelegationControllerChainAction\n | DelegationControllerDeleteAction;\n\nexport type DelegationControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n DelegationControllerState\n>;\n\nexport type DelegationControllerEvents = DelegationControllerStateChangeEvent;\n\ntype AllowedActions =\n | KeyringControllerSignTypedMessageAction\n | AccountsControllerGetSelectedAccountAction;\n\ntype AllowedEvents = never;\n\nexport type DelegationControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n DelegationControllerActions | AllowedActions,\n DelegationControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
|
package/dist/utils.cjs
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createTypedMessageParams = exports.toDelegationStruct = exports.isHexEqual = void 0;
|
4
|
+
const utils_1 = require("@metamask/utils");
|
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
|
+
/**
|
18
|
+
* Converts a Delegation to a DelegationStruct.
|
19
|
+
* The DelegationStruct is the format used in the Delegation Framework.
|
20
|
+
*
|
21
|
+
* @param delegation the delegation to format
|
22
|
+
* @returns the formatted delegation
|
23
|
+
*/
|
24
|
+
const toDelegationStruct = (delegation) => {
|
25
|
+
const caveats = delegation.caveats.map((caveat) => ({
|
26
|
+
enforcer: (0, utils_1.getChecksumAddress)(caveat.enforcer),
|
27
|
+
terms: caveat.terms,
|
28
|
+
args: caveat.args,
|
29
|
+
}));
|
30
|
+
const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);
|
31
|
+
return {
|
32
|
+
delegate: (0, utils_1.getChecksumAddress)(delegation.delegate),
|
33
|
+
delegator: (0, utils_1.getChecksumAddress)(delegation.delegator),
|
34
|
+
authority: delegation.authority,
|
35
|
+
caveats,
|
36
|
+
salt,
|
37
|
+
signature: delegation.signature,
|
38
|
+
};
|
39
|
+
};
|
40
|
+
exports.toDelegationStruct = toDelegationStruct;
|
41
|
+
/**
|
42
|
+
*
|
43
|
+
* @param opts - The options for creating typed message params.
|
44
|
+
* @returns The typed message params.
|
45
|
+
*/
|
46
|
+
function createTypedMessageParams(opts) {
|
47
|
+
const { chainId, from, delegation, verifyingContract } = opts;
|
48
|
+
const data = {
|
49
|
+
data: {
|
50
|
+
types: constants_1.SIGNABLE_DELEGATION_TYPED_DATA,
|
51
|
+
primaryType: 'Delegation',
|
52
|
+
domain: {
|
53
|
+
chainId,
|
54
|
+
name: 'DelegationManager',
|
55
|
+
version: '1',
|
56
|
+
verifyingContract,
|
57
|
+
},
|
58
|
+
message: (0, exports.toDelegationStruct)(delegation),
|
59
|
+
},
|
60
|
+
from,
|
61
|
+
};
|
62
|
+
return data;
|
63
|
+
}
|
64
|
+
exports.createTypedMessageParams = createTypedMessageParams;
|
65
|
+
//# sourceMappingURL=utils.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AAErD,+CAA6D;AAG7D;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,CAAM,EAAE,CAAM;IACvC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7C,CAAC;AAFD,gCAEC;AASD;;;;;;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,0CAA8B;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';\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"]}
|
package/dist/utils.d.cts
ADDED
@@ -0,0 +1,32 @@
|
|
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;
|
11
|
+
type CreateTypedMessageParamsOptions = {
|
12
|
+
chainId: number;
|
13
|
+
from: Address;
|
14
|
+
delegation: Delegation;
|
15
|
+
verifyingContract: Address;
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* Converts a Delegation to a DelegationStruct.
|
19
|
+
* The DelegationStruct is the format used in the Delegation Framework.
|
20
|
+
*
|
21
|
+
* @param delegation the delegation to format
|
22
|
+
* @returns the formatted delegation
|
23
|
+
*/
|
24
|
+
export declare const toDelegationStruct: (delegation: Delegation) => DelegationStruct;
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @param opts - The options for creating typed message params.
|
28
|
+
* @returns The typed message params.
|
29
|
+
*/
|
30
|
+
export declare function createTypedMessageParams(opts: CreateTypedMessageParamsOptions): TypedMessageParams;
|
31
|
+
export {};
|
32
|
+
//# 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,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"}
|
package/dist/utils.d.mts
ADDED
@@ -0,0 +1,32 @@
|
|
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;
|
11
|
+
type CreateTypedMessageParamsOptions = {
|
12
|
+
chainId: number;
|
13
|
+
from: Address;
|
14
|
+
delegation: Delegation;
|
15
|
+
verifyingContract: Address;
|
16
|
+
};
|
17
|
+
/**
|
18
|
+
* Converts a Delegation to a DelegationStruct.
|
19
|
+
* The DelegationStruct is the format used in the Delegation Framework.
|
20
|
+
*
|
21
|
+
* @param delegation the delegation to format
|
22
|
+
* @returns the formatted delegation
|
23
|
+
*/
|
24
|
+
export declare const toDelegationStruct: (delegation: Delegation) => DelegationStruct;
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @param opts - The options for creating typed message params.
|
28
|
+
* @returns The typed message params.
|
29
|
+
*/
|
30
|
+
export declare function createTypedMessageParams(opts: CreateTypedMessageParamsOptions): TypedMessageParams;
|
31
|
+
export {};
|
32
|
+
//# 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,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"}
|