@metamask/accounts-controller 18.1.1 → 18.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +40 -1
- package/dist/AccountsController.cjs +608 -0
- package/dist/AccountsController.cjs.map +1 -0
- package/dist/{types/AccountsController.d.ts → AccountsController.d.cts} +13 -10
- package/dist/AccountsController.d.cts.map +1 -0
- package/dist/AccountsController.d.mts +215 -0
- package/dist/AccountsController.d.mts.map +1 -0
- package/dist/AccountsController.mjs +604 -9
- package/dist/AccountsController.mjs.map +1 -1
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/index.d.ts → index.d.cts} +4 -4
- 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 -13
- package/dist/index.mjs.map +1 -1
- package/dist/tests/mocks.cjs +49 -0
- package/dist/tests/mocks.cjs.map +1 -0
- package/dist/{types/tests/mocks.d.ts → tests/mocks.d.cts} +3 -3
- package/dist/tests/mocks.d.cts.map +1 -0
- package/dist/tests/mocks.d.mts +17 -0
- package/dist/tests/mocks.d.mts.map +1 -0
- package/dist/tests/mocks.mjs +41 -60
- package/dist/tests/mocks.mjs.map +1 -1
- package/dist/utils.cjs +80 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{types/utils.d.ts → utils.d.cts} +3 -3
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +28 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +73 -13
- package/dist/utils.mjs.map +1 -1
- package/package.json +19 -14
- package/dist/AccountsController.js +0 -11
- package/dist/AccountsController.js.map +0 -1
- package/dist/chunk-5MTWAWAS.js +0 -753
- package/dist/chunk-5MTWAWAS.js.map +0 -1
- package/dist/chunk-BYPP7G2N.js +0 -56
- package/dist/chunk-BYPP7G2N.js.map +0 -1
- package/dist/chunk-UJIPPGP6.js +0 -19
- package/dist/chunk-UJIPPGP6.js.map +0 -1
- package/dist/chunk-Y2QVUNIA.mjs +0 -56
- package/dist/chunk-Y2QVUNIA.mjs.map +0 -1
- package/dist/chunk-ZNSHBDHA.mjs +0 -19
- package/dist/chunk-ZNSHBDHA.mjs.map +0 -1
- package/dist/chunk-ZPUB3DMH.mjs +0 -753
- package/dist/chunk-ZPUB3DMH.mjs.map +0 -1
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/tests/mocks.js +0 -65
- package/dist/tests/mocks.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/AccountsController.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/tests/mocks.d.ts.map +0 -1
- package/dist/types/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -14
- package/dist/utils.js.map +0 -1
package/dist/utils.mjs
CHANGED
@@ -1,14 +1,74 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
package/dist/utils.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":[],"
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,qCAAqC;AAC9E,OAAO,EAAE,MAAM,EAAE,qCAAqC;AAEtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAElC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,qEAAqE;IACrE,4CAA4C;IAC5C,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE;QACjC,OAAO,SAAS,CAAC;KAClB;IAED,QAAQ,WAAW,EAAE;QACnB,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;SACb;QACD,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;YACtB,OAAO,cAAc,CAAC;SACvB;QACD,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,mBAAmB,WAAW,EAAE,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CACtD,OAAe;IAEf,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KAC/C,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,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.
|
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":
|
22
|
-
|
23
|
-
|
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.
|
28
|
-
"types": "./dist/
|
32
|
+
"main": "./dist/index.cjs",
|
33
|
+
"types": "./dist/index.d.cts",
|
29
34
|
"files": [
|
30
35
|
"dist/"
|
31
36
|
],
|
32
37
|
"scripts": {
|
33
|
-
"build": "
|
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.
|
47
|
-
"@metamask/eth-snap-keyring": "^4.3.
|
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.
|
50
|
-
"@metamask/snaps-utils": "^
|
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.
|
60
|
-
"@metamask/snaps-controllers": "^9.
|
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.
|
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 _chunk5MTWAWASjs = require('./chunk-5MTWAWAS.js');
|
5
|
-
require('./chunk-BYPP7G2N.js');
|
6
|
-
require('./chunk-UJIPPGP6.js');
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
exports.AccountsController = _chunk5MTWAWASjs.AccountsController; exports.EMPTY_ACCOUNT = _chunk5MTWAWASjs.EMPTY_ACCOUNT;
|
11
|
-
//# sourceMappingURL=AccountsController.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|