@metamask/accounts-controller 18.2.0 → 18.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/AccountsController.cjs +608 -0
  3. package/dist/AccountsController.cjs.map +1 -0
  4. package/dist/{types/AccountsController.d.ts → AccountsController.d.cts} +8 -8
  5. package/dist/AccountsController.d.cts.map +1 -0
  6. package/dist/AccountsController.d.mts +215 -0
  7. package/dist/AccountsController.d.mts.map +1 -0
  8. package/dist/AccountsController.mjs +604 -9
  9. package/dist/AccountsController.mjs.map +1 -1
  10. package/dist/index.cjs +9 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/{types/index.d.ts → index.d.cts} +4 -4
  13. package/dist/index.d.cts.map +1 -0
  14. package/dist/index.d.mts +4 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +2 -13
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/tests/mocks.cjs +49 -0
  19. package/dist/tests/mocks.cjs.map +1 -0
  20. package/dist/{types/tests/mocks.d.ts → tests/mocks.d.cts} +3 -3
  21. package/dist/tests/mocks.d.cts.map +1 -0
  22. package/dist/tests/mocks.d.mts +17 -0
  23. package/dist/tests/mocks.d.mts.map +1 -0
  24. package/dist/tests/mocks.mjs +41 -60
  25. package/dist/tests/mocks.mjs.map +1 -1
  26. package/dist/utils.cjs +80 -0
  27. package/dist/utils.cjs.map +1 -0
  28. package/dist/{types/utils.d.ts → utils.d.cts} +3 -3
  29. package/dist/utils.d.cts.map +1 -0
  30. package/dist/utils.d.mts +28 -0
  31. package/dist/utils.d.mts.map +1 -0
  32. package/dist/utils.mjs +73 -13
  33. package/dist/utils.mjs.map +1 -1
  34. package/package.json +19 -14
  35. package/dist/AccountsController.js +0 -11
  36. package/dist/AccountsController.js.map +0 -1
  37. package/dist/chunk-2DVFC4VN.js +0 -763
  38. package/dist/chunk-2DVFC4VN.js.map +0 -1
  39. package/dist/chunk-BYPP7G2N.js +0 -56
  40. package/dist/chunk-BYPP7G2N.js.map +0 -1
  41. package/dist/chunk-RIZO66PK.mjs +0 -763
  42. package/dist/chunk-RIZO66PK.mjs.map +0 -1
  43. package/dist/chunk-UJIPPGP6.js +0 -19
  44. package/dist/chunk-UJIPPGP6.js.map +0 -1
  45. package/dist/chunk-Y2QVUNIA.mjs +0 -56
  46. package/dist/chunk-Y2QVUNIA.mjs.map +0 -1
  47. package/dist/chunk-ZNSHBDHA.mjs +0 -19
  48. package/dist/chunk-ZNSHBDHA.mjs.map +0 -1
  49. package/dist/index.js +0 -14
  50. package/dist/index.js.map +0 -1
  51. package/dist/tests/mocks.js +0 -65
  52. package/dist/tests/mocks.js.map +0 -1
  53. package/dist/tsconfig.build.tsbuildinfo +0 -1
  54. package/dist/types/AccountsController.d.ts.map +0 -1
  55. package/dist/types/index.d.ts.map +0 -1
  56. package/dist/types/tests/mocks.d.ts.map +0 -1
  57. package/dist/types/utils.d.ts.map +0 -1
  58. package/dist/utils.js +0 -14
  59. package/dist/utils.js.map +0 -1
package/dist/utils.mjs CHANGED
@@ -1,14 +1,74 @@
1
- import {
2
- getUUIDFromAddressOfNormalAccount,
3
- getUUIDOptionsFromAddressOfNormalAccount,
4
- isNormalKeyringType,
5
- keyringTypeToName
6
- } from "./chunk-Y2QVUNIA.mjs";
7
- import "./chunk-ZNSHBDHA.mjs";
8
- export {
9
- getUUIDFromAddressOfNormalAccount,
10
- getUUIDOptionsFromAddressOfNormalAccount,
11
- isNormalKeyringType,
12
- keyringTypeToName
13
- };
1
+ import $ethereumjsutil from "@ethereumjs/util";
2
+ const { toBuffer } = $ethereumjsutil;
3
+ import { isCustodyKeyring, KeyringTypes } from "@metamask/keyring-controller";
4
+ import { sha256 } from "ethereum-cryptography/sha256";
5
+ import { v4 as uuid } from "uuid";
6
+ /**
7
+ * Returns the name of the keyring type.
8
+ *
9
+ * @param keyringType - The type of the keyring.
10
+ * @returns The name of the keyring type.
11
+ */
12
+ export function keyringTypeToName(keyringType) {
13
+ // Custody keyrings are a special case, as they are not a single type
14
+ // they just start with the prefix `Custody`
15
+ if (isCustodyKeyring(keyringType)) {
16
+ return 'Custody';
17
+ }
18
+ switch (keyringType) {
19
+ case KeyringTypes.simple: {
20
+ return 'Account';
21
+ }
22
+ case KeyringTypes.hd: {
23
+ return 'Account';
24
+ }
25
+ case KeyringTypes.trezor: {
26
+ return 'Trezor';
27
+ }
28
+ case KeyringTypes.ledger: {
29
+ return 'Ledger';
30
+ }
31
+ case KeyringTypes.lattice: {
32
+ return 'Lattice';
33
+ }
34
+ case KeyringTypes.qr: {
35
+ return 'QR';
36
+ }
37
+ case KeyringTypes.snap: {
38
+ return 'Snap Account';
39
+ }
40
+ default: {
41
+ throw new Error(`Unknown keyring ${keyringType}`);
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Generates a UUID v4 options from a given Ethereum address.
47
+ * @param address - The Ethereum address to generate the UUID from.
48
+ * @returns The UUID v4 options.
49
+ */
50
+ export function getUUIDOptionsFromAddressOfNormalAccount(address) {
51
+ const v4options = {
52
+ random: sha256(toBuffer(address)).slice(0, 16),
53
+ };
54
+ return v4options;
55
+ }
56
+ /**
57
+ * Generates a UUID from a given Ethereum address.
58
+ * @param address - The Ethereum address to generate the UUID from.
59
+ * @returns The generated UUID.
60
+ */
61
+ export function getUUIDFromAddressOfNormalAccount(address) {
62
+ return uuid(getUUIDOptionsFromAddressOfNormalAccount(address));
63
+ }
64
+ /**
65
+ * Check if a keyring type is considered a "normal" keyring.
66
+ * @param keyringType - The account's keyring type.
67
+ * @returns True if the keyring type is considered a "normal" keyring, false otherwise.
68
+ */
69
+ export function isNormalKeyringType(keyringType) {
70
+ // Right now, we only have to "exclude" Snap accounts, but this might need to be
71
+ // adapted later on if we have new kind of keyrings!
72
+ return keyringType !== KeyringTypes.snap;
73
+ }
14
74
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"utils.mjs","sour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AAiC,CAAC,OAAe;IAC/D,OAAO,IAAI,CAAC,wCAAwC,CAAC,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAyB;IAC3D,gFAAgF;IAChF,oDAAoD;IACpD,OAAO,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC;AAC3C,CAAC","sourcesContent":["import { toBuffer } from '@ethereumjs/util';\nimport { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport type { V4Options } from 'uuid';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * Returns the name of the keyring type.\n *\n * @param keyringType - The type of the keyring.\n * @returns The name of the keyring type.\n */\nexport function keyringTypeToName(keyringType: string): string {\n // Custody keyrings are a special case, as they are not a single type\n // they just start with the prefix `Custody`\n if (isCustodyKeyring(keyringType)) {\n return 'Custody';\n }\n\n switch (keyringType) {\n case KeyringTypes.simple: {\n return 'Account';\n }\n case KeyringTypes.hd: {\n return 'Account';\n }\n case KeyringTypes.trezor: {\n return 'Trezor';\n }\n case KeyringTypes.ledger: {\n return 'Ledger';\n }\n case KeyringTypes.lattice: {\n return 'Lattice';\n }\n case KeyringTypes.qr: {\n return 'QR';\n }\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n default: {\n throw new Error(`Unknown keyring ${keyringType}`);\n }\n }\n}\n\n/**\n * Generates a UUID v4 options from a given Ethereum address.\n * @param address - The Ethereum address to generate the UUID from.\n * @returns The UUID v4 options.\n */\nexport function getUUIDOptionsFromAddressOfNormalAccount(\n address: string,\n): V4Options {\n const v4options = {\n random: sha256(toBuffer(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n * @param address - The Ethereum address to generate the UUID from.\n * @returns The generated UUID.\n */\nexport function getUUIDFromAddressOfNormalAccount(address: string): string {\n return uuid(getUUIDOptionsFromAddressOfNormalAccount(address));\n}\n\n/**\n * Check if a keyring type is considered a \"normal\" keyring.\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a \"normal\" keyring, false otherwise.\n */\nexport function isNormalKeyringType(keyringType: KeyringTypes): boolean {\n // Right now, we only have to \"exclude\" Snap accounts, but this might need to be\n // adapted later on if we have new kind of keyrings!\n return keyringType !== KeyringTypes.snap;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/accounts-controller",
3
- "version": "18.2.0",
3
+ "version": "18.2.1",
4
4
  "description": "Manages internal accounts",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -18,19 +18,24 @@
18
18
  "sideEffects": false,
19
19
  "exports": {
20
20
  ".": {
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.js",
23
- "types": "./dist/types/index.d.ts"
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
+ }
24
29
  },
25
30
  "./package.json": "./package.json"
26
31
  },
27
- "main": "./dist/index.js",
28
- "types": "./dist/types/index.d.ts",
32
+ "main": "./dist/index.cjs",
33
+ "types": "./dist/index.d.cts",
29
34
  "files": [
30
35
  "dist/"
31
36
  ],
32
37
  "scripts": {
33
- "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
38
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
34
39
  "build:docs": "typedoc",
35
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/accounts-controller",
36
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/accounts-controller",
@@ -43,11 +48,11 @@
43
48
  },
44
49
  "dependencies": {
45
50
  "@ethereumjs/util": "^8.1.0",
46
- "@metamask/base-controller": "^7.0.0",
47
- "@metamask/eth-snap-keyring": "^4.3.1",
51
+ "@metamask/base-controller": "^7.0.1",
52
+ "@metamask/eth-snap-keyring": "^4.3.3",
48
53
  "@metamask/keyring-api": "^8.1.0",
49
- "@metamask/snaps-sdk": "^6.1.1",
50
- "@metamask/snaps-utils": "^7.8.1",
54
+ "@metamask/snaps-sdk": "^6.5.0",
55
+ "@metamask/snaps-utils": "^8.1.1",
51
56
  "@metamask/utils": "^9.1.0",
52
57
  "deepmerge": "^4.2.2",
53
58
  "ethereum-cryptography": "^2.1.2",
@@ -56,8 +61,8 @@
56
61
  },
57
62
  "devDependencies": {
58
63
  "@metamask/auto-changelog": "^3.4.4",
59
- "@metamask/keyring-controller": "^17.2.0",
60
- "@metamask/snaps-controllers": "^9.3.1",
64
+ "@metamask/keyring-controller": "^17.2.1",
65
+ "@metamask/snaps-controllers": "^9.7.0",
61
66
  "@types/jest": "^27.4.1",
62
67
  "@types/readable-stream": "^2.3.0",
63
68
  "jest": "^27.5.1",
@@ -68,7 +73,7 @@
68
73
  },
69
74
  "peerDependencies": {
70
75
  "@metamask/keyring-controller": "^17.0.0",
71
- "@metamask/snaps-controllers": "^9.3.0"
76
+ "@metamask/snaps-controllers": "^9.7.0"
72
77
  },
73
78
  "engines": {
74
79
  "node": "^18.18 || >=20"
@@ -1,11 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunk2DVFC4VNjs = require('./chunk-2DVFC4VN.js');
5
- require('./chunk-BYPP7G2N.js');
6
- require('./chunk-UJIPPGP6.js');
7
-
8
-
9
-
10
- exports.AccountsController = _chunk2DVFC4VNjs.AccountsController; exports.EMPTY_ACCOUNT = _chunk2DVFC4VNjs.EMPTY_ACCOUNT;
11
- //# sourceMappingURL=AccountsController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}