@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/DelegationController.cjs +210 -0
  5. package/dist/DelegationController.cjs.map +1 -0
  6. package/dist/DelegationController.d.cts +76 -0
  7. package/dist/DelegationController.d.cts.map +1 -0
  8. package/dist/DelegationController.d.mts +76 -0
  9. package/dist/DelegationController.d.mts.map +1 -0
  10. package/dist/DelegationController.mjs +206 -0
  11. package/dist/DelegationController.mjs.map +1 -0
  12. package/dist/constants.cjs +28 -0
  13. package/dist/constants.cjs.map +1 -0
  14. package/dist/constants.d.cts +31 -0
  15. package/dist/constants.d.cts.map +1 -0
  16. package/dist/constants.d.mts +31 -0
  17. package/dist/constants.d.mts.map +1 -0
  18. package/dist/constants.mjs +25 -0
  19. package/dist/constants.mjs.map +1 -0
  20. package/dist/index.cjs +6 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +3 -0
  23. package/dist/index.d.cts.map +1 -0
  24. package/dist/index.d.mts +3 -0
  25. package/dist/index.d.mts.map +1 -0
  26. package/dist/index.mjs +2 -0
  27. package/dist/index.mjs.map +1 -0
  28. package/dist/types.cjs +3 -0
  29. package/dist/types.cjs.map +1 -0
  30. package/dist/types.d.cts +107 -0
  31. package/dist/types.d.cts.map +1 -0
  32. package/dist/types.d.mts +107 -0
  33. package/dist/types.d.mts.map +1 -0
  34. package/dist/types.mjs +2 -0
  35. package/dist/types.mjs.map +1 -0
  36. package/dist/utils.cjs +65 -0
  37. package/dist/utils.cjs.map +1 -0
  38. package/dist/utils.d.cts +32 -0
  39. package/dist/utils.d.cts.map +1 -0
  40. package/dist/utils.d.mts +32 -0
  41. package/dist/utils.d.mts.map +1 -0
  42. package/dist/utils.mjs +59 -0
  43. package/dist/utils.mjs.map +1 -0
  44. package/package.json +77 -0
package/dist/utils.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import { getChecksumAddress } from "@metamask/utils";
2
+ import { SIGNABLE_DELEGATION_TYPED_DATA } from "./constants.mjs";
3
+ /**
4
+ * Checks if two hex strings are equal.
5
+ *
6
+ * @param a - The first hex string.
7
+ * @param b - The second hex string.
8
+ * @returns True if the hex strings are equal, false otherwise.
9
+ */
10
+ export function isHexEqual(a, b) {
11
+ return a.toLowerCase() === b.toLowerCase();
12
+ }
13
+ /**
14
+ * Converts a Delegation to a DelegationStruct.
15
+ * The DelegationStruct is the format used in the Delegation Framework.
16
+ *
17
+ * @param delegation the delegation to format
18
+ * @returns the formatted delegation
19
+ */
20
+ export const toDelegationStruct = (delegation) => {
21
+ const caveats = delegation.caveats.map((caveat) => ({
22
+ enforcer: getChecksumAddress(caveat.enforcer),
23
+ terms: caveat.terms,
24
+ args: caveat.args,
25
+ }));
26
+ const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);
27
+ return {
28
+ delegate: getChecksumAddress(delegation.delegate),
29
+ delegator: getChecksumAddress(delegation.delegator),
30
+ authority: delegation.authority,
31
+ caveats,
32
+ salt,
33
+ signature: delegation.signature,
34
+ };
35
+ };
36
+ /**
37
+ *
38
+ * @param opts - The options for creating typed message params.
39
+ * @returns The typed message params.
40
+ */
41
+ export function createTypedMessageParams(opts) {
42
+ const { chainId, from, delegation, verifyingContract } = opts;
43
+ const data = {
44
+ data: {
45
+ types: SIGNABLE_DELEGATION_TYPED_DATA,
46
+ primaryType: 'Delegation',
47
+ domain: {
48
+ chainId,
49
+ name: 'DelegationManager',
50
+ version: '1',
51
+ verifyingContract,
52
+ },
53
+ message: toDelegationStruct(delegation),
54
+ },
55
+ from,
56
+ };
57
+ return data;
58
+ }
59
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,E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AAmB;gBACzB,OAAO,EAAE,GAAG;gBACZ,iBAAiB;aAClB;YACD,OAAO,EAAE,kBAAkB,CAAC,UAAU,CAAC;SACxC;QACD,IAAI;KACL,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { TypedMessageParams } from '@metamask/keyring-controller';\nimport { getChecksumAddress } from '@metamask/utils';\n\nimport { SIGNABLE_DELEGATION_TYPED_DATA } from './constants';\nimport type { Address, Delegation, DelegationStruct, Hex } from './types';\n\n/**\n * Checks if two hex strings are equal.\n *\n * @param a - The first hex string.\n * @param b - The second hex string.\n * @returns True if the hex strings are equal, false otherwise.\n */\nexport function isHexEqual(a: Hex, b: Hex) {\n return a.toLowerCase() === b.toLowerCase();\n}\n\ntype CreateTypedMessageParamsOptions = {\n chainId: number;\n from: Address;\n delegation: Delegation;\n verifyingContract: Address;\n};\n\n/**\n * Converts a Delegation to a DelegationStruct.\n * The DelegationStruct is the format used in the Delegation Framework.\n *\n * @param delegation the delegation to format\n * @returns the formatted delegation\n */\nexport const toDelegationStruct = (\n delegation: Delegation,\n): DelegationStruct => {\n const caveats = delegation.caveats.map((caveat) => ({\n enforcer: getChecksumAddress(caveat.enforcer),\n terms: caveat.terms,\n args: caveat.args,\n }));\n\n const salt = delegation.salt === '0x' ? 0n : BigInt(delegation.salt);\n\n return {\n delegate: getChecksumAddress(delegation.delegate),\n delegator: getChecksumAddress(delegation.delegator),\n authority: delegation.authority,\n caveats,\n salt,\n signature: delegation.signature,\n };\n};\n\n/**\n *\n * @param opts - The options for creating typed message params.\n * @returns The typed message params.\n */\nexport function createTypedMessageParams(\n opts: CreateTypedMessageParamsOptions,\n): TypedMessageParams {\n const { chainId, from, delegation, verifyingContract } = opts;\n\n const data: TypedMessageParams = {\n data: {\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n domain: {\n chainId,\n name: 'DelegationManager',\n version: '1',\n verifyingContract,\n },\n message: toDelegationStruct(delegation),\n },\n from,\n };\n\n return data;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@metamask-previews/delegation-controller",
3
+ "version": "0.0.0-preview-31a5eea2",
4
+ "description": "Manages delegations for MetaMask",
5
+ "keywords": [
6
+ "MetaMask",
7
+ "Ethereum"
8
+ ],
9
+ "homepage": "https://github.com/MetaMask/core/tree/main/packages/delegation-controller#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/MetaMask/core/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/MetaMask/core.git"
16
+ },
17
+ "license": "MIT",
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "import": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "main": "./dist/index.cjs",
33
+ "types": "./dist/index.d.cts",
34
+ "files": [
35
+ "dist/"
36
+ ],
37
+ "scripts": {
38
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39
+ "build:docs": "typedoc",
40
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/delegation-controller",
41
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/delegation-controller",
42
+ "publish:preview": "yarn npm publish --tag preview",
43
+ "since-latest-release": "../../scripts/since-latest-release.sh",
44
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
45
+ "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
46
+ "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
47
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48
+ },
49
+ "dependencies": {
50
+ "@metamask/base-controller": "^8.0.0",
51
+ "@metamask/utils": "^11.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@metamask/accounts-controller": "^27.0.0",
55
+ "@metamask/auto-changelog": "^3.4.4",
56
+ "@metamask/keyring-controller": "^21.0.2",
57
+ "@ts-bridge/cli": "^0.6.1",
58
+ "@types/jest": "^27.4.1",
59
+ "deepmerge": "^4.2.2",
60
+ "jest": "^27.5.1",
61
+ "ts-jest": "^27.1.4",
62
+ "typedoc": "^0.24.8",
63
+ "typedoc-plugin-missing-exports": "^2.0.0",
64
+ "typescript": "~5.2.2"
65
+ },
66
+ "peerDependencies": {
67
+ "@metamask/accounts-controller": "^27.0.0",
68
+ "@metamask/keyring-controller": "^21.0.2"
69
+ },
70
+ "engines": {
71
+ "node": "^18.18 || >=20"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public",
75
+ "registry": "https://registry.npmjs.org/"
76
+ }
77
+ }