@metamask-previews/accounts-controller 27.0.0-preview-5ea27f10 → 27.0.0-preview-20e2defb

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.
@@ -4,7 +4,7 @@ import { KeyringTypes } from "@metamask/keyring-controller";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  export declare const ETH_EOA_METHODS: readonly [EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4];
6
6
  export declare const ETH_ERC_4337_METHODS: readonly [EthMethod.PatchUserOperation, EthMethod.PrepareUserOperation, EthMethod.SignUserOperation];
7
- export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, methods, scopes, importTime, lastSelected, }?: {
7
+ export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, methods, scopes, importTime, lastSelected, options, }?: {
8
8
  id?: string | undefined;
9
9
  address?: string | undefined;
10
10
  type?: KeyringAccountType | undefined;
@@ -19,6 +19,7 @@ export declare const createMockInternalAccount: ({ id, address, type, name, keyr
19
19
  } | undefined;
20
20
  importTime?: number | undefined;
21
21
  lastSelected?: number | undefined;
22
+ options?: Record<string, unknown> | undefined;
22
23
  }) => InternalAccount;
23
24
  export declare const createExpectedInternalAccount: (args: Parameters<typeof createMockInternalAccount>[0]) => {
24
25
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh" | "solana:data-account";
@@ -42,4 +43,5 @@ export declare const createExpectedInternalAccount: (args: Parameters<typeof cre
42
43
  scopes: `${string}:${string}`[];
43
44
  methods: string[];
44
45
  };
46
+ export declare const createMockInternalAccountOptions: (keyringIndex: number, keyringType: KeyringTypes, groupIndex: number) => Record<string, string>;
45
47
  //# sourceMappingURL=mocks.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,8BAA8B;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,eAAO,MAAM,eAAe,+JAOlB,CAAC;AAEX,eAAO,MAAM,oBAAoB,sGAIvB,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;;;;;YAoB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;MAIP,eAyCR,CAAC;AAEF,eAAO,MAAM,6BAA6B,SAClC,WAAW,gCAAgC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;CAOtD,CAAC"}
1
+ {"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,8BAA8B;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,eAAO,MAAM,eAAe,+JAOlB,CAAC;AAEX,eAAO,MAAM,oBAAoB,sGAIvB,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;;;;;YAqB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;;MAKP,eAyCR,CAAC;AAEF,eAAO,MAAM,6BAA6B,SAClC,WAAW,gCAAgC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;CAOtD,CAAC;AAEF,eAAO,MAAM,gCAAgC,iBAC7B,MAAM,eACP,YAAY,cACb,MAAM,KACjB,OAAO,MAAM,EAAE,MAAM,CASvB,CAAC"}
@@ -4,7 +4,7 @@ import { KeyringTypes } from "@metamask/keyring-controller";
4
4
  import type { InternalAccount } from "@metamask/keyring-internal-api";
5
5
  export declare const ETH_EOA_METHODS: readonly [EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4];
6
6
  export declare const ETH_ERC_4337_METHODS: readonly [EthMethod.PatchUserOperation, EthMethod.PrepareUserOperation, EthMethod.SignUserOperation];
7
- export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, methods, scopes, importTime, lastSelected, }?: {
7
+ export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, methods, scopes, importTime, lastSelected, options, }?: {
8
8
  id?: string | undefined;
9
9
  address?: string | undefined;
10
10
  type?: KeyringAccountType | undefined;
@@ -19,6 +19,7 @@ export declare const createMockInternalAccount: ({ id, address, type, name, keyr
19
19
  } | undefined;
20
20
  importTime?: number | undefined;
21
21
  lastSelected?: number | undefined;
22
+ options?: Record<string, unknown> | undefined;
22
23
  }) => InternalAccount;
23
24
  export declare const createExpectedInternalAccount: (args: Parameters<typeof createMockInternalAccount>[0]) => {
24
25
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh" | "solana:data-account";
@@ -42,4 +43,5 @@ export declare const createExpectedInternalAccount: (args: Parameters<typeof cre
42
43
  scopes: `${string}:${string}`[];
43
44
  methods: string[];
44
45
  };
46
+ export declare const createMockInternalAccountOptions: (keyringIndex: number, keyringType: KeyringTypes, groupIndex: number) => Record<string, string>;
45
47
  //# sourceMappingURL=mocks.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,8BAA8B;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,eAAO,MAAM,eAAe,+JAOlB,CAAC;AAEX,eAAO,MAAM,oBAAoB,sGAIvB,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;;;;;YAoB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;MAIP,eAyCR,CAAC;AAEF,eAAO,MAAM,6BAA6B,SAClC,WAAW,gCAAgC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;CAOtD,CAAC"}
1
+ {"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,SAAS,EAGV,8BAA8B;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,8BAA8B;AAC7E,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,eAAO,MAAM,eAAe,+JAOlB,CAAC;AAEX,eAAO,MAAM,oBAAoB,sGAIvB,CAAC;AAEX,eAAO,MAAM,yBAAyB;;;;;;;;;YAqB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;;MAKP,eAyCR,CAAC;AAEF,eAAO,MAAM,6BAA6B,SAClC,WAAW,gCAAgC,CAAC,CAAC,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;CAOtD,CAAC;AAEF,eAAO,MAAM,gCAAgC,iBAC7B,MAAM,eACP,YAAY,cACb,MAAM,KACjB,OAAO,MAAM,EAAE,MAAM,CASvB,CAAC"}
@@ -14,7 +14,7 @@ export const ETH_ERC_4337_METHODS = [
14
14
  EthMethod.PrepareUserOperation,
15
15
  EthMethod.SignUserOperation,
16
16
  ];
17
- export const createMockInternalAccount = ({ id = v4(), address = '0x2990079bcdee240329a520d2444386fc119da21a', type = EthAccountType.Eoa, name = 'Account 1', keyringType = KeyringTypes.hd, snap, methods, scopes, importTime = Date.now(), lastSelected = Date.now(), } = {}) => {
17
+ export const createMockInternalAccount = ({ id = v4(), address = '0x2990079bcdee240329a520d2444386fc119da21a', type = EthAccountType.Eoa, name = 'Account 1', keyringType = KeyringTypes.hd, snap, methods, scopes, importTime = Date.now(), lastSelected = Date.now(), options, } = {}) => {
18
18
  const getInternalAccountDefaults = () => {
19
19
  switch (type) {
20
20
  case `${EthAccountType.Eoa}`:
@@ -40,7 +40,7 @@ export const createMockInternalAccount = ({ id = v4(), address = '0x2990079bcdee
40
40
  return {
41
41
  id,
42
42
  address,
43
- options: {},
43
+ options: options ?? {},
44
44
  methods: methods ?? defaults.methods,
45
45
  scopes: scopes ?? defaults.scopes,
46
46
  type,
@@ -61,4 +61,13 @@ export const createExpectedInternalAccount = (args) => {
61
61
  lastSelected: expect.any(Number),
62
62
  });
63
63
  };
64
+ export const createMockInternalAccountOptions = (keyringIndex, keyringType, groupIndex) => {
65
+ if (keyringType === KeyringTypes.hd) {
66
+ return {
67
+ entropySource: `mock-keyring-id-${keyringIndex}`,
68
+ derivationPath: `m/44'/60'/0'/0/${groupIndex}`,
69
+ };
70
+ }
71
+ return {};
72
+ };
64
73
  //# sourceMappingURL=mocks.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,EAAE,EAAE,aAAa;AAE1B,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,IAAI;IACd,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,eAAe;CACjB,CAAC;AAEX,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS,CAAC,kBAAkB;IAC5B,SAAS,CAAC,oBAAoB;IAC9B,SAAS,CAAC,iBAA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OAAO,IAAI,QAAQ,CAAC,OAAO;QACpC,MAAM,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM;QACjC,IAAI;QACJ,QAAQ,EAAE;YACR,IAAI;YACJ,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC9B,UAAU;YACV,YAAY;YACZ,2EAA2E;YAC3E,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1B;KACiB,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,IAAqD,EACrD,EAAE;IACF,OAAO,yBAAyB,CAAC;QAC/B,GAAG,IAAI;QACP,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;KACjC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import {\n BtcAccountType,\n EthAccountType,\n BtcMethod,\n EthMethod,\n EthScope,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { CaipChainId, KeyringAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { v4 } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nexport const ETH_ERC_4337_METHODS = [\n EthMethod.PatchUserOperation,\n EthMethod.PrepareUserOperation,\n EthMethod.SignUserOperation,\n] as const;\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 methods,\n scopes,\n importTime = Date.now(),\n lastSelected = Date.now(),\n}: {\n id?: string;\n address?: string;\n type?: KeyringAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n scopes?: CaipChainId[];\n methods?: (EthMethod | BtcMethod)[];\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n} = {}): InternalAccount => {\n const getInternalAccountDefaults = () => {\n switch (type) {\n case `${EthAccountType.Eoa}`:\n return {\n methods: [...Object.values(ETH_EOA_METHODS)],\n scopes: [EthScope.Eoa],\n };\n case `${EthAccountType.Erc4337}`:\n return {\n methods: [...Object.values(ETH_ERC_4337_METHODS)],\n scopes: [EthScope.Mainnet], // Assuming we are using mainnet for those Smart Accounts.\n };\n case `${BtcAccountType.P2wpkh}`:\n return {\n methods: [...Object.values(BtcMethod)],\n scopes: [BtcScope.Mainnet],\n };\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n };\n\n const defaults = getInternalAccountDefaults();\n\n return {\n id,\n address,\n options: {},\n methods: methods ?? defaults.methods,\n scopes: scopes ?? defaults.scopes,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n // Use spread operator, to avoid having a `snap: undefined` if not defined.\n ...(snap ? { snap } : {}),\n },\n } as InternalAccount;\n};\n\nexport const createExpectedInternalAccount = (\n args: Parameters<typeof createMockInternalAccount>[0],\n) => {\n return createMockInternalAccount({\n ...args,\n importTime: expect.any(Number),\n lastSelected: expect.any(Number),\n });\n};\n"]}
1
+ {"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACT,8BAA8B;AAE/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAE5D,OAAO,EAAE,EAAE,EAAE,aAAa;AAE1B,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,IAAI;IACd,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C;iBAC3B,CAAC;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAc,EAAE,CAAC,CAAC;SAC9D;IACH,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,0BAA0B,EAAE,CAAC;IAE9C,OAAO;QACL,EAAE;QACF,OAAO;QACP,OAAO,EAAE,OAAO,IAAI,EAAE;QACtB,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC,OAAO;QACpC,MAAM,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM;QACjC,IAAI;QACJ,QAAQ,EAAE;YACR,IAAI;YACJ,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC9B,UAAU;YACV,YAAY;YACZ,2EAA2E;YAC3E,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1B;KACiB,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,IAAqD,EACrD,EAAE;IACF,OAAO,yBAAyB,CAAC;QAC/B,GAAG,IAAI;QACP,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;KACjC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,YAAoB,EACpB,WAAyB,EACzB,UAAkB,EACM,EAAE;IAC1B,IAAI,WAAW,KAAK,YAAY,CAAC,EAAE,EAAE;QACnC,OAAO;YACL,aAAa,EAAE,mBAAmB,YAAY,EAAE;YAChD,cAAc,EAAE,kBAAkB,UAAU,EAAE;SAC/C,CAAC;KACH;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import {\n BtcAccountType,\n EthAccountType,\n BtcMethod,\n EthMethod,\n EthScope,\n BtcScope,\n} from '@metamask/keyring-api';\nimport type { CaipChainId, KeyringAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { v4 } from 'uuid';\n\nexport const ETH_EOA_METHODS = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n] as const;\n\nexport const ETH_ERC_4337_METHODS = [\n EthMethod.PatchUserOperation,\n EthMethod.PrepareUserOperation,\n EthMethod.SignUserOperation,\n] as const;\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 methods,\n scopes,\n importTime = Date.now(),\n lastSelected = Date.now(),\n options,\n}: {\n id?: string;\n address?: string;\n type?: KeyringAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n scopes?: CaipChainId[];\n methods?: (EthMethod | BtcMethod)[];\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n options?: Record<string, unknown>;\n} = {}): InternalAccount => {\n const getInternalAccountDefaults = () => {\n switch (type) {\n case `${EthAccountType.Eoa}`:\n return {\n methods: [...Object.values(ETH_EOA_METHODS)],\n scopes: [EthScope.Eoa],\n };\n case `${EthAccountType.Erc4337}`:\n return {\n methods: [...Object.values(ETH_ERC_4337_METHODS)],\n scopes: [EthScope.Mainnet], // Assuming we are using mainnet for those Smart Accounts.\n };\n case `${BtcAccountType.P2wpkh}`:\n return {\n methods: [...Object.values(BtcMethod)],\n scopes: [BtcScope.Mainnet],\n };\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n };\n\n const defaults = getInternalAccountDefaults();\n\n return {\n id,\n address,\n options: options ?? {},\n methods: methods ?? defaults.methods,\n scopes: scopes ?? defaults.scopes,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n // Use spread operator, to avoid having a `snap: undefined` if not defined.\n ...(snap ? { snap } : {}),\n },\n } as InternalAccount;\n};\n\nexport const createExpectedInternalAccount = (\n args: Parameters<typeof createMockInternalAccount>[0],\n) => {\n return createMockInternalAccount({\n ...args,\n importTime: expect.any(Number),\n lastSelected: expect.any(Number),\n });\n};\n\nexport const createMockInternalAccountOptions = (\n keyringIndex: number,\n keyringType: KeyringTypes,\n groupIndex: number,\n): Record<string, string> => {\n if (keyringType === KeyringTypes.hd) {\n return {\n entropySource: `mock-keyring-id-${keyringIndex}`,\n derivationPath: `m/44'/60'/0'/0/${groupIndex}`,\n };\n }\n\n return {};\n};\n"]}
package/dist/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNormalKeyringType = exports.getUUIDFromAddressOfNormalAccount = exports.getUUIDOptionsFromAddressOfNormalAccount = exports.keyringTypeToName = void 0;
3
+ exports.getDerivationPathForIndex = exports.isHdKeyringType = exports.isNormalKeyringType = exports.getUUIDFromAddressOfNormalAccount = exports.getUUIDOptionsFromAddressOfNormalAccount = exports.keyringTypeToName = void 0;
4
4
  const keyring_controller_1 = require("@metamask/keyring-controller");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  const sha256_1 = require("ethereum-cryptography/sha256");
@@ -12,11 +12,6 @@ const uuid_1 = require("uuid");
12
12
  * @returns The name of the keyring type.
13
13
  */
14
14
  function keyringTypeToName(keyringType) {
15
- // Custody keyrings are a special case, as they are not a single type
16
- // they just start with the prefix `Custody`
17
- if ((0, keyring_controller_1.isCustodyKeyring)(keyringType)) {
18
- return 'Custody';
19
- }
20
15
  switch (keyringType) {
21
16
  case keyring_controller_1.KeyringTypes.simple: {
22
17
  return 'Account';
@@ -83,4 +78,24 @@ function isNormalKeyringType(keyringType) {
83
78
  return keyringType !== keyring_controller_1.KeyringTypes.snap;
84
79
  }
85
80
  exports.isNormalKeyringType = isNormalKeyringType;
81
+ /**
82
+ * Check if a keyring is a HD keyring.
83
+ *
84
+ * @param keyringType - The account's keyring type.
85
+ * @returns True if the keyring is a HD keyring, false otherwise.
86
+ */
87
+ function isHdKeyringType(keyringType) {
88
+ return keyringType === keyring_controller_1.KeyringTypes.hd;
89
+ }
90
+ exports.isHdKeyringType = isHdKeyringType;
91
+ /**
92
+ * Get the derivation path for the index of an account within a HD keyring.
93
+ *
94
+ * @param index - The account index.
95
+ * @returns The derivation path.
96
+ */
97
+ function getDerivationPathForIndex(index) {
98
+ return `m/44'/60'/0'/0/${index}`;
99
+ }
100
+ exports.getDerivationPathForIndex = getDerivationPathForIndex;
86
101
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qEAA8E;AAC9E,2CAA6C;AAC7C,yDAAsD;AAEtD,+BAAkC;AAElC;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,WAAmB;IACnD,qEAAqE;IACrE,4CAA4C;IAC5C,IAAI,IAAA,qCAAgB,EAAC,WAAW,CAAC,EAAE;QACjC,OAAO,SAAS,CAAC;KAClB;IAED,QAAQ,WAAW,EAAE;QACnB,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,iCAAY,CAAC,EAAE,CAAC,CAAC;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAAQ,CAAC;SACjB;QACD,KAAK,iCAAY,CAAC,OAAO,CAAC,CAAC;YACzB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,iCAAY,CAAC,EAAE,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;SACb;QACD,KAAK,iCAAY,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;AApCD,8CAoCC;AAED;;;;;GAKG;AACH,SAAgB,wCAAwC,CACtD,OAAe;IAEf,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,IAAA,eAAM,EAAC,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACjD,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AARD,4FAQC;AAED;;;;;GAKG;AACH,SAAgB,iCAAiC,CAAC,OAAe;IAC/D,OAAO,IAAA,SAAI,EAAC,wCAAwC,CAAC,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AAFD,8EAEC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,WAAyB;IAC3D,gFAAgF;IAChF,oDAAoD;IACpD,OAAO,WAAW,KAAK,iCAAY,CAAC,IAAI,CAAC;AAC3C,CAAC;AAJD,kDAIC","sourcesContent":["import { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { hexToBytes } from '@metamask/utils';\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.oneKey: {\n return 'OneKey';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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"]}
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAC5D,2CAA6C;AAC7C,yDAAsD;AAEtD,+BAAkC;AAElC;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,WAAmB;IACnD,QAAQ,WAAW,EAAE;QACnB,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,iCAAY,CAAC,EAAE,CAAC,CAAC;YACpB,OAAO,SAAS,CAAC;SAClB;QACD,KAAK,iCAAY,CAAC,MAAM,CAAC,CAAC;YACxB,OAAO,QAA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kB,KAAK,EAAE,CAAC;AACnC,CAAC;AAFD,8DAEC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport { hexToBytes } from '@metamask/utils';\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 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.oneKey: {\n return 'OneKey';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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 * Check if a keyring is a HD keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring is a HD keyring, false otherwise.\n */\nexport function isHdKeyringType(keyringType: KeyringTypes): boolean {\n return keyringType === KeyringTypes.hd;\n}\n\n/**\n * Get the derivation path for the index of an account within a HD keyring.\n *\n * @param index - The account index.\n * @returns The derivation path.\n */\nexport function getDerivationPathForIndex(index: number): string {\n return `m/44'/60'/0'/0/${index}`;\n}\n"]}
package/dist/utils.d.cts CHANGED
@@ -28,4 +28,18 @@ export declare function getUUIDFromAddressOfNormalAccount(address: string): stri
28
28
  * @returns True if the keyring type is considered a "normal" keyring, false otherwise.
29
29
  */
30
30
  export declare function isNormalKeyringType(keyringType: KeyringTypes): boolean;
31
+ /**
32
+ * Check if a keyring is a HD keyring.
33
+ *
34
+ * @param keyringType - The account's keyring type.
35
+ * @returns True if the keyring is a HD keyring, false otherwise.
36
+ */
37
+ export declare function isHdKeyringType(keyringType: KeyringTypes): boolean;
38
+ /**
39
+ * Get the derivation path for the index of an account within a HD keyring.
40
+ *
41
+ * @param index - The account index.
42
+ * @returns The derivation path.
43
+ */
44
+ export declare function getDerivationPathForIndex(index: number): string;
31
45
  //# sourceMappingURL=utils.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,qCAAqC;AAG9E,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa;AAGtC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAoC7D;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,MAAM,GACd,SAAS,CAMX;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAItE"}
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa;AAGtC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA8B7D;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,MAAM,GACd,SAAS,CAMX;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAItE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D"}
package/dist/utils.d.mts CHANGED
@@ -28,4 +28,18 @@ export declare function getUUIDFromAddressOfNormalAccount(address: string): stri
28
28
  * @returns True if the keyring type is considered a "normal" keyring, false otherwise.
29
29
  */
30
30
  export declare function isNormalKeyringType(keyringType: KeyringTypes): boolean;
31
+ /**
32
+ * Check if a keyring is a HD keyring.
33
+ *
34
+ * @param keyringType - The account's keyring type.
35
+ * @returns True if the keyring is a HD keyring, false otherwise.
36
+ */
37
+ export declare function isHdKeyringType(keyringType: KeyringTypes): boolean;
38
+ /**
39
+ * Get the derivation path for the index of an account within a HD keyring.
40
+ *
41
+ * @param index - The account index.
42
+ * @returns The derivation path.
43
+ */
44
+ export declare function getDerivationPathForIndex(index: number): string;
31
45
  //# sourceMappingURL=utils.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,qCAAqC;AAG9E,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa;AAGtC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAoC7D;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,MAAM,GACd,SAAS,CAMX;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAItE"}
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa;AAGtC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA8B7D;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,EAAE,MAAM,GACd,SAAS,CAMX;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAItE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,YAAY,GAAG,OAAO,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D"}
package/dist/utils.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { isCustodyKeyring, KeyringTypes } from "@metamask/keyring-controller";
1
+ import { KeyringTypes } from "@metamask/keyring-controller";
2
2
  import { hexToBytes } from "@metamask/utils";
3
3
  import { sha256 } from "ethereum-cryptography/sha256";
4
4
  import { v4 as uuid } from "uuid";
@@ -9,11 +9,6 @@ import { v4 as uuid } from "uuid";
9
9
  * @returns The name of the keyring type.
10
10
  */
11
11
  export function keyringTypeToName(keyringType) {
12
- // Custody keyrings are a special case, as they are not a single type
13
- // they just start with the prefix `Custody`
14
- if (isCustodyKeyring(keyringType)) {
15
- return 'Custody';
16
- }
17
12
  switch (keyringType) {
18
13
  case KeyringTypes.simple: {
19
14
  return 'Account';
@@ -76,4 +71,22 @@ export function isNormalKeyringType(keyringType) {
76
71
  // adapted later on if we have new kind of keyrings!
77
72
  return keyringType !== KeyringTypes.snap;
78
73
  }
74
+ /**
75
+ * Check if a keyring is a HD keyring.
76
+ *
77
+ * @param keyringType - The account's keyring type.
78
+ * @returns True if the keyring is a HD keyring, false otherwise.
79
+ */
80
+ export function isHdKeyringType(keyringType) {
81
+ return keyringType === KeyringTypes.hd;
82
+ }
83
+ /**
84
+ * Get the derivation path for the index of an account within a HD keyring.
85
+ *
86
+ * @param index - The account index.
87
+ * @returns The derivation path.
88
+ */
89
+ export function getDerivationPathForIndex(index) {
90
+ return `m/44'/60'/0'/0/${index}`;
91
+ }
79
92
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,qCAAqC;AAC9E,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAC7C,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,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;;;;;GAKG;AACH,MAAM,UAAU,wCAAwC,CACtD,OAAe;IAEf,MAAM,SAAS,GAAG;QAChB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACjD,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAAC,OAAe;IAC/D,OAAO,IAAI,CAAC,wCAAwC,CAAC,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAyB;IAC3D,gFAAgF;IAChF,oDAAoD;IACpD,OAAO,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC;AAC3C,CAAC","sourcesContent":["import { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { hexToBytes } from '@metamask/utils';\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.oneKey: {\n return 'OneKey';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D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AAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAyB;IAC3D,gFAAgF;IAChF,oDAAoD;IACpD,OAAO,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,WAAyB;IACvD,OAAO,WAAW,KAAK,YAAY,CAAC,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAa;IACrD,OAAO,kBAAkB,KAAK,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport { hexToBytes } from '@metamask/utils';\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 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.oneKey: {\n return 'OneKey';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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 * Check if a keyring is a HD keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring is a HD keyring, false otherwise.\n */\nexport function isHdKeyringType(keyringType: KeyringTypes): boolean {\n return keyringType === KeyringTypes.hd;\n}\n\n/**\n * Get the derivation path for the index of an account within a HD keyring.\n *\n * @param index - The account index.\n * @returns The derivation path.\n */\nexport function getDerivationPathForIndex(index: number): string {\n return `m/44'/60'/0'/0/${index}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/accounts-controller",
3
- "version": "27.0.0-preview-5ea27f10",
3
+ "version": "27.0.0-preview-20e2defb",
4
4
  "description": "Manages internal accounts",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -63,8 +63,8 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@metamask/auto-changelog": "^3.4.4",
66
- "@metamask/keyring-controller": "^21.0.4",
67
- "@metamask/network-controller": "^23.2.0",
66
+ "@metamask/keyring-controller": "^21.0.5",
67
+ "@metamask/network-controller": "^23.3.0",
68
68
  "@metamask/providers": "^21.0.0",
69
69
  "@metamask/snaps-controllers": "^11.2.1",
70
70
  "@types/jest": "^27.4.1",