@metamask-previews/accounts-controller 24.0.1-preview-95a6811 → 24.0.1-preview-5dad659d
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.
- package/CHANGELOG.md +5 -0
- package/dist/AccountsController.cjs +37 -89
- package/dist/AccountsController.cjs.map +1 -1
- package/dist/AccountsController.d.cts +5 -13
- package/dist/AccountsController.d.cts.map +1 -1
- package/dist/AccountsController.d.mts +5 -13
- package/dist/AccountsController.d.mts.map +1 -1
- package/dist/AccountsController.mjs +38 -90
- package/dist/AccountsController.mjs.map +1 -1
- package/dist/tests/mocks.cjs +49 -29
- package/dist/tests/mocks.cjs.map +1 -1
- package/dist/tests/mocks.d.cts +29 -2
- package/dist/tests/mocks.d.cts.map +1 -1
- package/dist/tests/mocks.d.mts +29 -2
- package/dist/tests/mocks.d.mts.map +1 -1
- package/dist/tests/mocks.mjs +48 -29
- package/dist/tests/mocks.mjs.map +1 -1
- package/package.json +2 -1
package/dist/tests/mocks.d.cts
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
import
|
1
|
+
import { BtcMethod, EthMethod } from "@metamask/keyring-api";
|
2
|
+
import type { CaipChainId, KeyringAccountType } from "@metamask/keyring-api";
|
2
3
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
3
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
4
|
-
export declare const
|
5
|
+
export declare const ETH_EOA_METHODS: readonly [EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4];
|
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, }?: {
|
5
8
|
id?: string | undefined;
|
6
9
|
address?: string | undefined;
|
7
10
|
type?: KeyringAccountType | undefined;
|
8
11
|
name?: string | undefined;
|
9
12
|
keyringType?: KeyringTypes | undefined;
|
13
|
+
scopes?: `${string}:${string}`[] | undefined;
|
14
|
+
methods?: (EthMethod | BtcMethod)[] | undefined;
|
10
15
|
snap?: {
|
11
16
|
id: string;
|
12
17
|
enabled: boolean;
|
@@ -15,4 +20,26 @@ export declare const createMockInternalAccount: ({ id, address, type, name, keyr
|
|
15
20
|
importTime?: number | undefined;
|
16
21
|
lastSelected?: number | undefined;
|
17
22
|
}) => InternalAccount;
|
23
|
+
export declare const createExpectedInternalAccount: (args: Parameters<typeof createMockInternalAccount>[0]) => {
|
24
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh" | "solana:data-account";
|
25
|
+
id: string;
|
26
|
+
options: Record<string, import("@metamask/utils").Json>;
|
27
|
+
metadata: {
|
28
|
+
name: string;
|
29
|
+
importTime: number;
|
30
|
+
keyring: {
|
31
|
+
type: string;
|
32
|
+
};
|
33
|
+
nameLastUpdatedAt?: number | undefined;
|
34
|
+
snap?: {
|
35
|
+
name: string;
|
36
|
+
id: string;
|
37
|
+
enabled: boolean;
|
38
|
+
} | undefined;
|
39
|
+
lastSelected?: number | undefined;
|
40
|
+
};
|
41
|
+
address: string;
|
42
|
+
scopes: `${string}:${string}`[];
|
43
|
+
methods: string[];
|
44
|
+
};
|
18
45
|
//# sourceMappingURL=mocks.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
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"}
|
package/dist/tests/mocks.d.mts
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
import
|
1
|
+
import { BtcMethod, EthMethod } from "@metamask/keyring-api";
|
2
|
+
import type { CaipChainId, KeyringAccountType } from "@metamask/keyring-api";
|
2
3
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
3
4
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
4
|
-
export declare const
|
5
|
+
export declare const ETH_EOA_METHODS: readonly [EthMethod.PersonalSign, EthMethod.Sign, EthMethod.SignTransaction, EthMethod.SignTypedDataV1, EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4];
|
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, }?: {
|
5
8
|
id?: string | undefined;
|
6
9
|
address?: string | undefined;
|
7
10
|
type?: KeyringAccountType | undefined;
|
8
11
|
name?: string | undefined;
|
9
12
|
keyringType?: KeyringTypes | undefined;
|
13
|
+
scopes?: `${string}:${string}`[] | undefined;
|
14
|
+
methods?: (EthMethod | BtcMethod)[] | undefined;
|
10
15
|
snap?: {
|
11
16
|
id: string;
|
12
17
|
enabled: boolean;
|
@@ -15,4 +20,26 @@ export declare const createMockInternalAccount: ({ id, address, type, name, keyr
|
|
15
20
|
importTime?: number | undefined;
|
16
21
|
lastSelected?: number | undefined;
|
17
22
|
}) => InternalAccount;
|
23
|
+
export declare const createExpectedInternalAccount: (args: Parameters<typeof createMockInternalAccount>[0]) => {
|
24
|
+
type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh" | "solana:data-account";
|
25
|
+
id: string;
|
26
|
+
options: Record<string, import("@metamask/utils").Json>;
|
27
|
+
metadata: {
|
28
|
+
name: string;
|
29
|
+
importTime: number;
|
30
|
+
keyring: {
|
31
|
+
type: string;
|
32
|
+
};
|
33
|
+
nameLastUpdatedAt?: number | undefined;
|
34
|
+
snap?: {
|
35
|
+
name: string;
|
36
|
+
id: string;
|
37
|
+
enabled: boolean;
|
38
|
+
} | undefined;
|
39
|
+
lastSelected?: number | undefined;
|
40
|
+
};
|
41
|
+
address: string;
|
42
|
+
scopes: `${string}:${string}`[];
|
43
|
+
methods: string[];
|
44
|
+
};
|
18
45
|
//# sourceMappingURL=mocks.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
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"}
|
package/dist/tests/mocks.mjs
CHANGED
@@ -1,45 +1,64 @@
|
|
1
|
-
import { BtcAccountType, EthAccountType, BtcMethod, EthMethod } from "@metamask/keyring-api";
|
1
|
+
import { BtcAccountType, EthAccountType, BtcMethod, EthMethod, EthScope, BtcScope } from "@metamask/keyring-api";
|
2
2
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
3
3
|
import { v4 } from "uuid";
|
4
|
-
export const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
4
|
+
export const ETH_EOA_METHODS = [
|
5
|
+
EthMethod.PersonalSign,
|
6
|
+
EthMethod.Sign,
|
7
|
+
EthMethod.SignTransaction,
|
8
|
+
EthMethod.SignTypedDataV1,
|
9
|
+
EthMethod.SignTypedDataV3,
|
10
|
+
EthMethod.SignTypedDataV4,
|
11
|
+
];
|
12
|
+
export const ETH_ERC_4337_METHODS = [
|
13
|
+
EthMethod.PatchUserOperation,
|
14
|
+
EthMethod.PrepareUserOperation,
|
15
|
+
EthMethod.SignUserOperation,
|
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(), } = {}) => {
|
18
|
+
const getInternalAccountDefaults = () => {
|
19
|
+
switch (type) {
|
20
|
+
case `${EthAccountType.Eoa}`:
|
21
|
+
return {
|
22
|
+
methods: [...Object.values(ETH_EOA_METHODS)],
|
23
|
+
scopes: [EthScope.Eoa],
|
24
|
+
};
|
25
|
+
case `${EthAccountType.Erc4337}`:
|
26
|
+
return {
|
27
|
+
methods: [...Object.values(ETH_ERC_4337_METHODS)],
|
28
|
+
scopes: [EthScope.Mainnet], // Assuming we are using mainnet for those Smart Accounts.
|
29
|
+
};
|
30
|
+
case `${BtcAccountType.P2wpkh}`:
|
31
|
+
return {
|
32
|
+
methods: [...Object.values(BtcMethod)],
|
33
|
+
scopes: [BtcScope.Mainnet],
|
34
|
+
};
|
35
|
+
default:
|
36
|
+
throw new Error(`Unknown account type: ${type}`);
|
37
|
+
}
|
38
|
+
};
|
39
|
+
const defaults = getInternalAccountDefaults();
|
30
40
|
return {
|
31
41
|
id,
|
32
42
|
address,
|
33
43
|
options: {},
|
34
|
-
methods,
|
44
|
+
methods: methods ?? defaults.methods,
|
45
|
+
scopes: scopes ?? defaults.scopes,
|
35
46
|
type,
|
36
47
|
metadata: {
|
37
48
|
name,
|
38
49
|
keyring: { type: keyringType },
|
39
50
|
importTime,
|
40
51
|
lastSelected,
|
41
|
-
snap
|
52
|
+
// Use spread operator, to avoid having a `snap: undefined` if not defined.
|
53
|
+
...(snap ? { snap } : {}),
|
42
54
|
},
|
43
55
|
};
|
44
56
|
};
|
57
|
+
export const createExpectedInternalAccount = (args) => {
|
58
|
+
return createMockInternalAccount({
|
59
|
+
...args,
|
60
|
+
importTime: expect.any(Number),
|
61
|
+
lastSelected: expect.any(Number),
|
62
|
+
});
|
63
|
+
};
|
45
64
|
//# sourceMappingURL=mocks.mjs.map
|
package/dist/tests/mocks.mjs.map
CHANGED
@@ -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,
|
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/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CAAC,MAAM,EAAE;gBAC7B,OAAO;oBACL,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACtC,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;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,EAAE;QACX,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","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"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask-previews/accounts-controller",
|
3
|
-
"version": "24.0.1-preview-
|
3
|
+
"version": "24.0.1-preview-5dad659d",
|
4
4
|
"description": "Manages internal accounts",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -52,6 +52,7 @@
|
|
52
52
|
"@metamask/eth-snap-keyring": "^11.1.0",
|
53
53
|
"@metamask/keyring-api": "^17.2.0",
|
54
54
|
"@metamask/keyring-internal-api": "^4.0.3",
|
55
|
+
"@metamask/keyring-utils": "^2.3.1",
|
55
56
|
"@metamask/network-controller": "^22.2.1",
|
56
57
|
"@metamask/snaps-sdk": "^6.17.1",
|
57
58
|
"@metamask/snaps-utils": "^8.10.0",
|