@metamask/accounts-controller 13.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +34 -1
- package/dist/AccountsController.js +4 -3
- package/dist/AccountsController.mjs +3 -2
- package/dist/{chunk-JNCGDLI7.mjs → chunk-3R7MA6KV.mjs} +188 -56
- package/dist/chunk-3R7MA6KV.mjs.map +1 -0
- package/dist/{chunk-HS62N4JH.js → chunk-7CWWNB3P.js} +204 -72
- package/dist/chunk-7CWWNB3P.js.map +1 -0
- package/dist/{chunk-KCST55AQ.js → chunk-EIQ5DUI6.js} +10 -17
- package/dist/chunk-EIQ5DUI6.js.map +1 -0
- package/dist/chunk-IBSI66UQ.js +65 -0
- package/dist/chunk-IBSI66UQ.js.map +1 -0
- package/dist/chunk-QAHRSXGM.mjs +65 -0
- package/dist/chunk-QAHRSXGM.mjs.map +1 -0
- package/dist/chunk-UJIPPGP6.js +19 -0
- package/dist/chunk-UJIPPGP6.js.map +1 -0
- package/dist/{chunk-E7SBT5BV.mjs → chunk-YNILZSBK.mjs} +11 -18
- package/dist/chunk-YNILZSBK.mjs.map +1 -0
- package/dist/chunk-ZNSHBDHA.mjs +19 -0
- package/dist/chunk-ZNSHBDHA.mjs.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.mjs +7 -2
- package/dist/tests/mocks.js +8 -0
- package/dist/tests/mocks.js.map +1 -0
- package/dist/tests/mocks.mjs +8 -0
- package/dist/tests/mocks.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/AccountsController.d.ts +39 -4
- package/dist/types/AccountsController.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tests/mocks.d.ts +17 -0
- package/dist/types/tests/mocks.d.ts.map +1 -0
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +7 -2
- package/dist/utils.mjs +6 -1
- package/package.json +10 -10
- package/dist/chunk-E7SBT5BV.mjs.map +0 -1
- package/dist/chunk-HS62N4JH.js.map +0 -1
- package/dist/chunk-JNCGDLI7.mjs.map +0 -1
- package/dist/chunk-KCST55AQ.js.map +0 -1
@@ -1,20 +1,7 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
2
|
-
if (!member.has(obj))
|
3
|
-
throw TypeError("Cannot " + msg);
|
4
|
-
};
|
5
|
-
var __privateAdd = (obj, member, value) => {
|
6
|
-
if (member.has(obj))
|
7
|
-
throw TypeError("Cannot add the same private member more than once");
|
8
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
9
|
-
};
|
10
|
-
var __privateMethod = (obj, member, method) => {
|
11
|
-
__accessCheck(obj, member, "access private method");
|
12
|
-
return method;
|
13
|
-
};
|
14
|
-
|
15
|
-
// src/utils.ts
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils.ts
|
16
2
|
var _util = require('@ethereumjs/util');
|
17
3
|
var _keyringcontroller = require('@metamask/keyring-controller');
|
4
|
+
var _snapsutils = require('@metamask/snaps-utils');
|
18
5
|
var _sha256 = require('ethereum-cryptography/sha256');
|
19
6
|
var _uuid = require('uuid');
|
20
7
|
function keyringTypeToName(keyringType) {
|
@@ -57,6 +44,12 @@ function getUUIDOptionsFromAddressOfNormalAccount(address) {
|
|
57
44
|
function getUUIDFromAddressOfNormalAccount(address) {
|
58
45
|
return _uuid.v4.call(void 0, getUUIDOptionsFromAddressOfNormalAccount(address));
|
59
46
|
}
|
47
|
+
function isNormalKeyringType(keyringType) {
|
48
|
+
return keyringType !== _keyringcontroller.KeyringTypes.snap;
|
49
|
+
}
|
50
|
+
function deepCloneDraft(obj) {
|
51
|
+
return _snapsutils.deepClone.call(void 0, obj);
|
52
|
+
}
|
60
53
|
|
61
54
|
|
62
55
|
|
@@ -64,5 +57,5 @@ function getUUIDFromAddressOfNormalAccount(address) {
|
|
64
57
|
|
65
58
|
|
66
59
|
|
67
|
-
exports.
|
68
|
-
//# sourceMappingURL=chunk-
|
60
|
+
exports.keyringTypeToName = keyringTypeToName; exports.getUUIDOptionsFromAddressOfNormalAccount = getUUIDOptionsFromAddressOfNormalAccount; exports.getUUIDFromAddressOfNormalAccount = getUUIDFromAddressOfNormalAccount; exports.isNormalKeyringType = isNormalKeyringType; exports.deepCloneDraft = deepCloneDraft;
|
61
|
+
//# sourceMappingURL=chunk-EIQ5DUI6.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAC/C,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAGvB,SAAS,MAAM,YAAY;AAUpB,SAAS,kBAAkB,aAA6B;AAG7D,MAAI,iBAAiB,WAAW,GAAG;AACjC,WAAO;AAAA,EACT;AAEA,UAAQ,aAAa;AAAA,IACnB,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,IAAI;AACpB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,SAAS;AACzB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,IAAI;AACpB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,MAAM;AACtB,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AACP,YAAM,IAAI,MAAM,mBAAmB,WAAW,EAAE;AAAA,IAClD;AAAA,EACF;AACF;AAOO,SAAS,yCACd,SACW;AACX,QAAM,YAAY;AAAA,IAChB,QAAQ,OAAO,SAAS,OAAO,CAAC,EAAE,MAAM,GAAG,EAAE;AAAA,EAC/C;AAEA,SAAO;AACT;AAOO,SAAS,kCAAkC,SAAyB;AACzE,SAAO,KAAK,yCAAyC,OAAO,CAAC;AAC/D;AAOO,SAAS,oBAAoB,aAAoC;AAGtE,SAAO,gBAAgB,aAAa;AACtC;AAWO,SAAS,eACd,KACyB;AAEzB,SAAO,UAAU,GAAG;AACtB","sourcesContent":["import { toBuffer } from '@ethereumjs/util';\nimport { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { deepClone } from '@metamask/snaps-utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport type { Draft } from 'immer';\nimport type { V4Options } from 'uuid';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AccountsControllerState } from './AccountsController';\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\n/**\n * WARNING: To be removed once type issue is fixed. https://github.com/MetaMask/utils/issues/168\n *\n * Creates a deep clone of the given object.\n * This is to get around error `Type instantiation is excessively deep and possibly infinite.`\n *\n * @param obj - The object to be cloned.\n * @returns The deep clone of the object.\n */\nexport function deepCloneDraft(\n obj: Draft<AccountsControllerState>,\n): AccountsControllerState {\n // We use unknown here because the type inference when using structured clone leads to the same type error.\n return deepClone(obj) as unknown as AccountsControllerState;\n}\n"]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/tests/mocks.ts
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
var _keyringapi = require('@metamask/keyring-api');
|
9
|
+
var _keyringcontroller = require('@metamask/keyring-controller');
|
10
|
+
var _uuid = require('uuid');
|
11
|
+
var createMockInternalAccount = ({
|
12
|
+
id = _uuid.v4.call(void 0, ),
|
13
|
+
address = "0x2990079bcdee240329a520d2444386fc119da21a",
|
14
|
+
type = _keyringapi.EthAccountType.Eoa,
|
15
|
+
name = "Account 1",
|
16
|
+
keyringType = _keyringcontroller.KeyringTypes.hd,
|
17
|
+
snap,
|
18
|
+
importTime = Date.now(),
|
19
|
+
lastSelected = Date.now()
|
20
|
+
} = {}) => {
|
21
|
+
let methods;
|
22
|
+
switch (type) {
|
23
|
+
case _keyringapi.EthAccountType.Eoa:
|
24
|
+
methods = [
|
25
|
+
_keyringapi.EthMethod.PersonalSign,
|
26
|
+
_keyringapi.EthMethod.Sign,
|
27
|
+
_keyringapi.EthMethod.SignTransaction,
|
28
|
+
_keyringapi.EthMethod.SignTypedDataV1,
|
29
|
+
_keyringapi.EthMethod.SignTypedDataV3,
|
30
|
+
_keyringapi.EthMethod.SignTypedDataV4
|
31
|
+
];
|
32
|
+
break;
|
33
|
+
case _keyringapi.EthAccountType.Erc4337:
|
34
|
+
methods = [
|
35
|
+
_keyringapi.EthErc4337Method.PatchUserOperation,
|
36
|
+
_keyringapi.EthErc4337Method.PrepareUserOperation,
|
37
|
+
_keyringapi.EthErc4337Method.SignUserOperation
|
38
|
+
];
|
39
|
+
break;
|
40
|
+
case _keyringapi.BtcAccountType.P2wpkh:
|
41
|
+
methods = [_keyringapi.BtcMethod.SendMany];
|
42
|
+
break;
|
43
|
+
default:
|
44
|
+
throw new Error(`Unknown account type: ${type}`);
|
45
|
+
}
|
46
|
+
return {
|
47
|
+
id,
|
48
|
+
address,
|
49
|
+
options: {},
|
50
|
+
methods,
|
51
|
+
type,
|
52
|
+
metadata: {
|
53
|
+
name,
|
54
|
+
keyring: { type: keyringType },
|
55
|
+
importTime,
|
56
|
+
lastSelected,
|
57
|
+
snap
|
58
|
+
}
|
59
|
+
};
|
60
|
+
};
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
exports.createMockInternalAccount = createMockInternalAccount;
|
65
|
+
//# sourceMappingURL=chunk-IBSI66UQ.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/tests/mocks.ts"],"names":[],"mappings":";AAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AAEZ,IAAM,4BAA4B,CAAC;AAAA,EACxC,KAAK,GAAG;AAAA,EACR,UAAU;AAAA,EACV,OAAO,eAAe;AAAA,EACtB,OAAO;AAAA,EACP,cAAc,aAAa;AAAA,EAC3B;AAAA,EACA,aAAa,KAAK,IAAI;AAAA,EACtB,eAAe,KAAK,IAAI;AAC1B,IAaI,CAAC,MAAuB;AAC1B,MAAI;AAEJ,UAAQ,MAAM;AAAA,IACZ,KAAK,eAAe;AAClB,gBAAU;AAAA,QACR,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,MACZ;AACA;AAAA,IACF,KAAK,eAAe;AAClB,gBAAU;AAAA,QACR,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,MACnB;AACA;AAAA,IACF,KAAK,eAAe;AAClB,gBAAU,CAAC,UAAU,QAAQ;AAC7B;AAAA,IACF;AACE,YAAM,IAAI,MAAM,yBAAyB,IAAc,EAAE;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,CAAC;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU;AAAA,MACR;AAAA,MACA,SAAS,EAAE,MAAM,YAAY;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import type {\n InternalAccount,\n InternalAccountType,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n EthAccountType,\n EthErc4337Method,\n EthMethod,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport { v4 } from 'uuid';\n\nexport const createMockInternalAccount = ({\n id = v4(),\n address = '0x2990079bcdee240329a520d2444386fc119da21a',\n type = EthAccountType.Eoa,\n name = 'Account 1',\n keyringType = KeyringTypes.hd,\n snap,\n importTime = Date.now(),\n lastSelected = Date.now(),\n}: {\n id?: string;\n address?: string;\n type?: InternalAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n} = {}): InternalAccount => {\n let methods;\n\n switch (type) {\n case EthAccountType.Eoa:\n methods = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ];\n break;\n case EthAccountType.Erc4337:\n methods = [\n EthErc4337Method.PatchUserOperation,\n EthErc4337Method.PrepareUserOperation,\n EthErc4337Method.SignUserOperation,\n ];\n break;\n case BtcAccountType.P2wpkh:\n methods = [BtcMethod.SendMany];\n break;\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n\n return {\n id,\n address,\n options: {},\n methods,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n snap,\n },\n } as InternalAccount;\n};\n"]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
// src/tests/mocks.ts
|
2
|
+
import {
|
3
|
+
BtcAccountType,
|
4
|
+
BtcMethod,
|
5
|
+
EthAccountType,
|
6
|
+
EthErc4337Method,
|
7
|
+
EthMethod
|
8
|
+
} from "@metamask/keyring-api";
|
9
|
+
import { KeyringTypes } from "@metamask/keyring-controller";
|
10
|
+
import { v4 } from "uuid";
|
11
|
+
var createMockInternalAccount = ({
|
12
|
+
id = v4(),
|
13
|
+
address = "0x2990079bcdee240329a520d2444386fc119da21a",
|
14
|
+
type = EthAccountType.Eoa,
|
15
|
+
name = "Account 1",
|
16
|
+
keyringType = KeyringTypes.hd,
|
17
|
+
snap,
|
18
|
+
importTime = Date.now(),
|
19
|
+
lastSelected = Date.now()
|
20
|
+
} = {}) => {
|
21
|
+
let methods;
|
22
|
+
switch (type) {
|
23
|
+
case EthAccountType.Eoa:
|
24
|
+
methods = [
|
25
|
+
EthMethod.PersonalSign,
|
26
|
+
EthMethod.Sign,
|
27
|
+
EthMethod.SignTransaction,
|
28
|
+
EthMethod.SignTypedDataV1,
|
29
|
+
EthMethod.SignTypedDataV3,
|
30
|
+
EthMethod.SignTypedDataV4
|
31
|
+
];
|
32
|
+
break;
|
33
|
+
case EthAccountType.Erc4337:
|
34
|
+
methods = [
|
35
|
+
EthErc4337Method.PatchUserOperation,
|
36
|
+
EthErc4337Method.PrepareUserOperation,
|
37
|
+
EthErc4337Method.SignUserOperation
|
38
|
+
];
|
39
|
+
break;
|
40
|
+
case BtcAccountType.P2wpkh:
|
41
|
+
methods = [BtcMethod.SendMany];
|
42
|
+
break;
|
43
|
+
default:
|
44
|
+
throw new Error(`Unknown account type: ${type}`);
|
45
|
+
}
|
46
|
+
return {
|
47
|
+
id,
|
48
|
+
address,
|
49
|
+
options: {},
|
50
|
+
methods,
|
51
|
+
type,
|
52
|
+
metadata: {
|
53
|
+
name,
|
54
|
+
keyring: { type: keyringType },
|
55
|
+
importTime,
|
56
|
+
lastSelected,
|
57
|
+
snap
|
58
|
+
}
|
59
|
+
};
|
60
|
+
};
|
61
|
+
|
62
|
+
export {
|
63
|
+
createMockInternalAccount
|
64
|
+
};
|
65
|
+
//# sourceMappingURL=chunk-QAHRSXGM.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/tests/mocks.ts"],"sourcesContent":["import type {\n InternalAccount,\n InternalAccountType,\n} from '@metamask/keyring-api';\nimport {\n BtcAccountType,\n BtcMethod,\n EthAccountType,\n EthErc4337Method,\n EthMethod,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport { v4 } from 'uuid';\n\nexport const createMockInternalAccount = ({\n id = v4(),\n address = '0x2990079bcdee240329a520d2444386fc119da21a',\n type = EthAccountType.Eoa,\n name = 'Account 1',\n keyringType = KeyringTypes.hd,\n snap,\n importTime = Date.now(),\n lastSelected = Date.now(),\n}: {\n id?: string;\n address?: string;\n type?: InternalAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n} = {}): InternalAccount => {\n let methods;\n\n switch (type) {\n case EthAccountType.Eoa:\n methods = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ];\n break;\n case EthAccountType.Erc4337:\n methods = [\n EthErc4337Method.PatchUserOperation,\n EthErc4337Method.PrepareUserOperation,\n EthErc4337Method.SignUserOperation,\n ];\n break;\n case BtcAccountType.P2wpkh:\n methods = [BtcMethod.SendMany];\n break;\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n\n return {\n id,\n address,\n options: {},\n methods,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n snap,\n },\n } as InternalAccount;\n};\n"],"mappings":";AAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AAEZ,IAAM,4BAA4B,CAAC;AAAA,EACxC,KAAK,GAAG;AAAA,EACR,UAAU;AAAA,EACV,OAAO,eAAe;AAAA,EACtB,OAAO;AAAA,EACP,cAAc,aAAa;AAAA,EAC3B;AAAA,EACA,aAAa,KAAK,IAAI;AAAA,EACtB,eAAe,KAAK,IAAI;AAC1B,IAaI,CAAC,MAAuB;AAC1B,MAAI;AAEJ,UAAQ,MAAM;AAAA,IACZ,KAAK,eAAe;AAClB,gBAAU;AAAA,QACR,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,QACV,UAAU;AAAA,MACZ;AACA;AAAA,IACF,KAAK,eAAe;AAClB,gBAAU;AAAA,QACR,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,MACnB;AACA;AAAA,IACF,KAAK,eAAe;AAClB,gBAAU,CAAC,UAAU,QAAQ;AAC7B;AAAA,IACF;AACE,YAAM,IAAI,MAAM,yBAAyB,IAAc,EAAE;AAAA,EAC7D;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,CAAC;AAAA,IACV;AAAA,IACA;AAAA,IACA,UAAU;AAAA,MACR;AAAA,MACA,SAAS,EAAE,MAAM,YAAY;AAAA,MAC7B;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __accessCheck = (obj, member, msg) => {
|
2
|
+
if (!member.has(obj))
|
3
|
+
throw TypeError("Cannot " + msg);
|
4
|
+
};
|
5
|
+
var __privateAdd = (obj, member, value) => {
|
6
|
+
if (member.has(obj))
|
7
|
+
throw TypeError("Cannot add the same private member more than once");
|
8
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
9
|
+
};
|
10
|
+
var __privateMethod = (obj, member, method) => {
|
11
|
+
__accessCheck(obj, member, "access private method");
|
12
|
+
return method;
|
13
|
+
};
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
exports.__privateAdd = __privateAdd; exports.__privateMethod = __privateMethod;
|
19
|
+
//# sourceMappingURL=chunk-UJIPPGP6.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
@@ -1,20 +1,7 @@
|
|
1
|
-
var __accessCheck = (obj, member, msg) => {
|
2
|
-
if (!member.has(obj))
|
3
|
-
throw TypeError("Cannot " + msg);
|
4
|
-
};
|
5
|
-
var __privateAdd = (obj, member, value) => {
|
6
|
-
if (member.has(obj))
|
7
|
-
throw TypeError("Cannot add the same private member more than once");
|
8
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
9
|
-
};
|
10
|
-
var __privateMethod = (obj, member, method) => {
|
11
|
-
__accessCheck(obj, member, "access private method");
|
12
|
-
return method;
|
13
|
-
};
|
14
|
-
|
15
1
|
// src/utils.ts
|
16
2
|
import { toBuffer } from "@ethereumjs/util";
|
17
3
|
import { isCustodyKeyring, KeyringTypes } from "@metamask/keyring-controller";
|
4
|
+
import { deepClone } from "@metamask/snaps-utils";
|
18
5
|
import { sha256 } from "ethereum-cryptography/sha256";
|
19
6
|
import { v4 as uuid } from "uuid";
|
20
7
|
function keyringTypeToName(keyringType) {
|
@@ -57,12 +44,18 @@ function getUUIDOptionsFromAddressOfNormalAccount(address) {
|
|
57
44
|
function getUUIDFromAddressOfNormalAccount(address) {
|
58
45
|
return uuid(getUUIDOptionsFromAddressOfNormalAccount(address));
|
59
46
|
}
|
47
|
+
function isNormalKeyringType(keyringType) {
|
48
|
+
return keyringType !== KeyringTypes.snap;
|
49
|
+
}
|
50
|
+
function deepCloneDraft(obj) {
|
51
|
+
return deepClone(obj);
|
52
|
+
}
|
60
53
|
|
61
54
|
export {
|
62
|
-
__privateAdd,
|
63
|
-
__privateMethod,
|
64
55
|
keyringTypeToName,
|
65
56
|
getUUIDOptionsFromAddressOfNormalAccount,
|
66
|
-
getUUIDFromAddressOfNormalAccount
|
57
|
+
getUUIDFromAddressOfNormalAccount,
|
58
|
+
isNormalKeyringType,
|
59
|
+
deepCloneDraft
|
67
60
|
};
|
68
|
-
//# sourceMappingURL=chunk-
|
61
|
+
//# sourceMappingURL=chunk-YNILZSBK.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import { toBuffer } from '@ethereumjs/util';\nimport { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { deepClone } from '@metamask/snaps-utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport type { Draft } from 'immer';\nimport type { V4Options } from 'uuid';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AccountsControllerState } from './AccountsController';\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\n/**\n * WARNING: To be removed once type issue is fixed. https://github.com/MetaMask/utils/issues/168\n *\n * Creates a deep clone of the given object.\n * This is to get around error `Type instantiation is excessively deep and possibly infinite.`\n *\n * @param obj - The object to be cloned.\n * @returns The deep clone of the object.\n */\nexport function deepCloneDraft(\n obj: Draft<AccountsControllerState>,\n): AccountsControllerState {\n // We use unknown here because the type inference when using structured clone leads to the same type error.\n return deepClone(obj) as unknown as AccountsControllerState;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB,oBAAoB;AAC/C,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAGvB,SAAS,MAAM,YAAY;AAUpB,SAAS,kBAAkB,aAA6B;AAG7D,MAAI,iBAAiB,WAAW,GAAG;AACjC,WAAO;AAAA,EACT;AAEA,UAAQ,aAAa;AAAA,IACnB,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,IAAI;AACpB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,QAAQ;AACxB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,SAAS;AACzB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,IAAI;AACpB,aAAO;AAAA,IACT;AAAA,IACA,KAAK,aAAa,MAAM;AACtB,aAAO;AAAA,IACT;AAAA,IACA,SAAS;AACP,YAAM,IAAI,MAAM,mBAAmB,WAAW,EAAE;AAAA,IAClD;AAAA,EACF;AACF;AAOO,SAAS,yCACd,SACW;AACX,QAAM,YAAY;AAAA,IAChB,QAAQ,OAAO,SAAS,OAAO,CAAC,EAAE,MAAM,GAAG,EAAE;AAAA,EAC/C;AAEA,SAAO;AACT;AAOO,SAAS,kCAAkC,SAAyB;AACzE,SAAO,KAAK,yCAAyC,OAAO,CAAC;AAC/D;AAOO,SAAS,oBAAoB,aAAoC;AAGtE,SAAO,gBAAgB,aAAa;AACtC;AAWO,SAAS,eACd,KACyB;AAEzB,SAAO,UAAU,GAAG;AACtB;","names":[]}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
2
|
+
if (!member.has(obj))
|
3
|
+
throw TypeError("Cannot " + msg);
|
4
|
+
};
|
5
|
+
var __privateAdd = (obj, member, value) => {
|
6
|
+
if (member.has(obj))
|
7
|
+
throw TypeError("Cannot add the same private member more than once");
|
8
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
9
|
+
};
|
10
|
+
var __privateMethod = (obj, member, method) => {
|
11
|
+
__accessCheck(obj, member, "access private method");
|
12
|
+
return method;
|
13
|
+
};
|
14
|
+
|
15
|
+
export {
|
16
|
+
__privateAdd,
|
17
|
+
__privateMethod
|
18
|
+
};
|
19
|
+
//# sourceMappingURL=chunk-ZNSHBDHA.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.js
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
2
2
|
|
3
|
-
var
|
3
|
+
var _chunk7CWWNB3Pjs = require('./chunk-7CWWNB3P.js');
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
var
|
7
|
+
var _chunkEIQ5DUI6js = require('./chunk-EIQ5DUI6.js');
|
8
8
|
|
9
9
|
|
10
|
+
var _chunkIBSI66UQjs = require('./chunk-IBSI66UQ.js');
|
11
|
+
require('./chunk-UJIPPGP6.js');
|
10
12
|
|
11
13
|
|
12
|
-
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
exports.AccountsController = _chunk7CWWNB3Pjs.AccountsController; exports.createMockInternalAccount = _chunkIBSI66UQjs.createMockInternalAccount; exports.getUUIDFromAddressOfNormalAccount = _chunkEIQ5DUI6js.getUUIDFromAddressOfNormalAccount; exports.keyringTypeToName = _chunkEIQ5DUI6js.keyringTypeToName;
|
13
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
import {
|
2
2
|
AccountsController
|
3
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-3R7MA6KV.mjs";
|
4
4
|
import {
|
5
5
|
getUUIDFromAddressOfNormalAccount,
|
6
6
|
keyringTypeToName
|
7
|
-
} from "./chunk-
|
7
|
+
} from "./chunk-YNILZSBK.mjs";
|
8
|
+
import {
|
9
|
+
createMockInternalAccount
|
10
|
+
} from "./chunk-QAHRSXGM.mjs";
|
11
|
+
import "./chunk-ZNSHBDHA.mjs";
|
8
12
|
export {
|
9
13
|
AccountsController,
|
14
|
+
createMockInternalAccount,
|
10
15
|
getUUIDFromAddressOfNormalAccount,
|
11
16
|
keyringTypeToName
|
12
17
|
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
2
|
+
|
3
|
+
var _chunkIBSI66UQjs = require('../chunk-IBSI66UQ.js');
|
4
|
+
require('../chunk-UJIPPGP6.js');
|
5
|
+
|
6
|
+
|
7
|
+
exports.createMockInternalAccount = _chunkIBSI66UQjs.createMockInternalAccount;
|
8
|
+
//# sourceMappingURL=mocks.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|