@metamask-previews/eth-snap-keyring 9.0.0-30e933c → 9.0.0-3d5158c
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/dist/account.d.cts +1 -1
- package/dist/account.d.mts +1 -1
- package/dist/events.d.cts +6 -6
- package/dist/events.d.mts +6 -6
- package/dist/migrations/v1.cjs +8 -10
- package/dist/migrations/v1.cjs.map +1 -1
- package/dist/migrations/v1.d.cts +1 -2
- package/dist/migrations/v1.d.cts.map +1 -1
- package/dist/migrations/v1.d.mts +1 -2
- package/dist/migrations/v1.d.mts.map +1 -1
- package/dist/migrations/v1.mjs +9 -11
- package/dist/migrations/v1.mjs.map +1 -1
- package/package.json +1 -1
package/dist/account.d.cts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const KeyringAccountV1Struct: import("@metamask/superstruct").Str
|
|
|
19
19
|
"solana:data-account": "solana:data-account";
|
|
20
20
|
}>;
|
|
21
21
|
address: import("@metamask/superstruct").Struct<string, null>;
|
|
22
|
-
scopes: import("@metamask/superstruct").Struct
|
|
22
|
+
scopes: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
23
23
|
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
|
24
24
|
methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
25
25
|
}, "scopes">>;
|
package/dist/account.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const KeyringAccountV1Struct: import("@metamask/superstruct").Str
|
|
|
19
19
|
"solana:data-account": "solana:data-account";
|
|
20
20
|
}>;
|
|
21
21
|
address: import("@metamask/superstruct").Struct<string, null>;
|
|
22
|
-
scopes: import("@metamask/superstruct").Struct
|
|
22
|
+
scopes: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
23
23
|
options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
|
24
24
|
methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
25
25
|
}, "scopes">>;
|
package/dist/events.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
6
6
|
id: string;
|
|
7
7
|
options: Record<string, import("@metamask/utils").Json>;
|
|
8
8
|
address: string;
|
|
9
|
-
scopes:
|
|
9
|
+
scopes: string[];
|
|
10
10
|
methods: string[];
|
|
11
11
|
} | {
|
|
12
12
|
id: string;
|
|
@@ -26,7 +26,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
26
26
|
id: string;
|
|
27
27
|
options: Record<string, import("@metamask/utils").Json>;
|
|
28
28
|
address: string;
|
|
29
|
-
scopes:
|
|
29
|
+
scopes: string[];
|
|
30
30
|
methods: string[];
|
|
31
31
|
} | {
|
|
32
32
|
id: string;
|
|
@@ -43,7 +43,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
43
43
|
id: string;
|
|
44
44
|
options: Record<string, import("@metamask/utils").Json>;
|
|
45
45
|
address: string;
|
|
46
|
-
scopes:
|
|
46
|
+
scopes: string[];
|
|
47
47
|
methods: string[];
|
|
48
48
|
} | {
|
|
49
49
|
id: string;
|
|
@@ -64,7 +64,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
64
64
|
id: string;
|
|
65
65
|
options: Record<string, import("@metamask/utils").Json>;
|
|
66
66
|
address: string;
|
|
67
|
-
scopes:
|
|
67
|
+
scopes: string[];
|
|
68
68
|
methods: string[];
|
|
69
69
|
} | {
|
|
70
70
|
id: string;
|
|
@@ -82,7 +82,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
82
82
|
id: string;
|
|
83
83
|
options: Record<string, import("@metamask/utils").Json>;
|
|
84
84
|
address: string;
|
|
85
|
-
scopes:
|
|
85
|
+
scopes: string[];
|
|
86
86
|
methods: string[];
|
|
87
87
|
} | {
|
|
88
88
|
id: string;
|
|
@@ -97,7 +97,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
97
97
|
id: string;
|
|
98
98
|
options: Record<string, import("@metamask/utils").Json>;
|
|
99
99
|
address: string;
|
|
100
|
-
scopes:
|
|
100
|
+
scopes: string[];
|
|
101
101
|
methods: string[];
|
|
102
102
|
} | {
|
|
103
103
|
id: string;
|
package/dist/events.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
6
6
|
id: string;
|
|
7
7
|
options: Record<string, import("@metamask/utils").Json>;
|
|
8
8
|
address: string;
|
|
9
|
-
scopes:
|
|
9
|
+
scopes: string[];
|
|
10
10
|
methods: string[];
|
|
11
11
|
} | {
|
|
12
12
|
id: string;
|
|
@@ -26,7 +26,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
26
26
|
id: string;
|
|
27
27
|
options: Record<string, import("@metamask/utils").Json>;
|
|
28
28
|
address: string;
|
|
29
|
-
scopes:
|
|
29
|
+
scopes: string[];
|
|
30
30
|
methods: string[];
|
|
31
31
|
} | {
|
|
32
32
|
id: string;
|
|
@@ -43,7 +43,7 @@ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").
|
|
|
43
43
|
id: string;
|
|
44
44
|
options: Record<string, import("@metamask/utils").Json>;
|
|
45
45
|
address: string;
|
|
46
|
-
scopes:
|
|
46
|
+
scopes: string[];
|
|
47
47
|
methods: string[];
|
|
48
48
|
} | {
|
|
49
49
|
id: string;
|
|
@@ -64,7 +64,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
64
64
|
id: string;
|
|
65
65
|
options: Record<string, import("@metamask/utils").Json>;
|
|
66
66
|
address: string;
|
|
67
|
-
scopes:
|
|
67
|
+
scopes: string[];
|
|
68
68
|
methods: string[];
|
|
69
69
|
} | {
|
|
70
70
|
id: string;
|
|
@@ -82,7 +82,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
82
82
|
id: string;
|
|
83
83
|
options: Record<string, import("@metamask/utils").Json>;
|
|
84
84
|
address: string;
|
|
85
|
-
scopes:
|
|
85
|
+
scopes: string[];
|
|
86
86
|
methods: string[];
|
|
87
87
|
} | {
|
|
88
88
|
id: string;
|
|
@@ -97,7 +97,7 @@ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").
|
|
|
97
97
|
id: string;
|
|
98
98
|
options: Record<string, import("@metamask/utils").Json>;
|
|
99
99
|
address: string;
|
|
100
|
-
scopes:
|
|
100
|
+
scopes: string[];
|
|
101
101
|
methods: string[];
|
|
102
102
|
} | {
|
|
103
103
|
id: string;
|
package/dist/migrations/v1.cjs
CHANGED
|
@@ -28,11 +28,9 @@ account) {
|
|
|
28
28
|
function getScopesForAccountV1(accountV1) {
|
|
29
29
|
switch (accountV1.type) {
|
|
30
30
|
case keyring_api_1.EthAccountType.Eoa: {
|
|
31
|
-
// EVM EOA account are compatible with any EVM networks, we use
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
// See: https://namespaces.chainagnostic.org/eip155/caip10
|
|
35
|
-
return [keyring_api_1.EthScope.Eoa];
|
|
31
|
+
// EVM EOA account are compatible with any EVM networks, and we use CAIP-2
|
|
32
|
+
// namespaces when the scope relates to ALL chains (from that namespace).
|
|
33
|
+
return [keyring_api_1.EthScopes.Namespace];
|
|
36
34
|
}
|
|
37
35
|
case keyring_api_1.EthAccountType.Erc4337: {
|
|
38
36
|
// EVM Erc4337 account
|
|
@@ -40,23 +38,23 @@ function getScopesForAccountV1(accountV1) {
|
|
|
40
38
|
// to testnet since we cannot really "guess" it from here.
|
|
41
39
|
// Also, there's no official Snap as of today that uses this account type. So this case should never happen
|
|
42
40
|
// in production.
|
|
43
|
-
return [keyring_api_1.
|
|
41
|
+
return [keyring_api_1.EthScopes.Testnet];
|
|
44
42
|
}
|
|
45
43
|
case keyring_api_1.BtcAccountType.P2wpkh: {
|
|
46
44
|
// Bitcoin uses different accounts for testnet and mainnet
|
|
47
45
|
return [
|
|
48
46
|
(0, keyring_utils_1.isBtcMainnetAddress)(accountV1.address)
|
|
49
|
-
? keyring_api_1.
|
|
50
|
-
: keyring_api_1.
|
|
47
|
+
? keyring_api_1.BtcScopes.Mainnet
|
|
48
|
+
: keyring_api_1.BtcScopes.Testnet,
|
|
51
49
|
];
|
|
52
50
|
}
|
|
53
51
|
case keyring_api_1.SolAccountType.DataAccount: {
|
|
54
52
|
// Solana account supports multiple chains.
|
|
55
|
-
return [keyring_api_1.
|
|
53
|
+
return [keyring_api_1.SolScopes.Mainnet, keyring_api_1.SolScopes.Testnet, keyring_api_1.SolScopes.Devnet];
|
|
56
54
|
}
|
|
57
55
|
default:
|
|
58
56
|
// We re-use EOA scopes if we don't know what to do for now.
|
|
59
|
-
return [keyring_api_1.
|
|
57
|
+
return [keyring_api_1.EthScopes.Namespace];
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.cjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"v1.cjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":";;AAwBA,kCAKC;AAQD,sDA+BC;AAWD,gDAmBC;AAUD,4CAUC;AAtHD,uDAQ+B;AAC/B,2DAA8D;AAC9D,uDAA2C;AAE3C,4CAIoB;AAEpB;;;;;GAKG;AACH,SAAgB,WAAW;AACzB,6EAA6E;AAC7E,OAA0C;IAE1C,OAAO,IAAA,gBAAE,EAAC,OAAO,EAAE,gCAAsB,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,SAA2B;IAC/D,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,4BAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,0EAA0E;YAC1E,yEAAyE;YACzE,OAAO,CAAC,uBAAS,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;QACD,KAAK,4BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,sBAAsB;YACtB,wGAAwG;YACxG,0DAA0D;YAC1D,2GAA2G;YAC3G,iBAAiB;YACjB,OAAO,CAAC,uBAAS,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,4BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,0DAA0D;YAC1D,OAAO;gBACL,IAAA,mCAAmB,EAAC,SAAS,CAAC,OAAO,CAAC;oBACpC,CAAC,CAAC,uBAAS,CAAC,OAAO;oBACnB,CAAC,CAAC,uBAAS,CAAC,OAAO;aACtB,CAAC;QACJ,CAAC;QACD,KAAK,4BAAc,CAAC,WAAW,CAAC,CAAC,CAAC;YAChC,2CAA2C;YAC3C,OAAO,CAAC,uBAAS,CAAC,OAAO,EAAE,uBAAS,CAAC,OAAO,EAAE,uBAAS,CAAC,MAAM,CAAC,CAAC;QAClE,CAAC;QACD;YACE,4DAA4D;YAC5D,OAAO,CAAC,uBAAS,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAA2B;IAE3B,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAE3B,0EAA0E;IAC1E,yEAAyE;IACzE,wEAAwE;IACxE,0BAA0B;IAC1B,IAAI,IAAI,KAAK,4BAAc,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO;YACL,GAAG,SAAS;YACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,0DAA0D;IAC1D,OAAO,IAAA,8BAAoB,EAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScopes,\n EthAccountType,\n EthScopes,\n SolAccountType,\n SolScopes,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport {\n assertKeyringAccount,\n KeyringAccountV1Struct,\n type KeyringAccountV1,\n} from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScopes.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default\n // to testnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So this case should never happen\n // in production.\n return [EthScopes.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScopes.Mainnet\n : BtcScopes.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScopes.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n // So we can automatically inject a valid `scopes` for this, but not for\n // other kind of accounts.\n if (type === EthAccountType.Eoa) {\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and\n // each `*AccountStruct` should assert that automatically.\n return assertKeyringAccount(accountV1);\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
|
package/dist/migrations/v1.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import type { CaipChainId } from "@metamask/utils";
|
|
3
2
|
import { type KeyringAccountV1 } from "../account.cjs";
|
|
4
3
|
/**
|
|
5
4
|
* Checks if an account is an `KeyringAccount` v1.
|
|
@@ -14,7 +13,7 @@ export declare function isAccountV1(account: KeyringAccountV1 | KeyringAccount):
|
|
|
14
13
|
* @param accountV1 - A v1 account.
|
|
15
14
|
* @returns The list of scopes for that accounts.
|
|
16
15
|
*/
|
|
17
|
-
export declare function getScopesForAccountV1(accountV1: KeyringAccountV1):
|
|
16
|
+
export declare function getScopesForAccountV1(accountV1: KeyringAccountV1): string[];
|
|
18
17
|
/**
|
|
19
18
|
* Transform an account v1. This account might have optional fields that are now required by
|
|
20
19
|
* the Keyring API. This function will automatically provides the missing fields with some
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.d.cts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;
|
|
1
|
+
{"version":3,"file":"v1.d.cts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAGL,KAAK,gBAAgB,EACtB,uBAAmB;AAEpB;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA+B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAiBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
|
package/dist/migrations/v1.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type KeyringAccount } from "@metamask/keyring-api";
|
|
2
|
-
import type { CaipChainId } from "@metamask/utils";
|
|
3
2
|
import { type KeyringAccountV1 } from "../account.mjs";
|
|
4
3
|
/**
|
|
5
4
|
* Checks if an account is an `KeyringAccount` v1.
|
|
@@ -14,7 +13,7 @@ export declare function isAccountV1(account: KeyringAccountV1 | KeyringAccount):
|
|
|
14
13
|
* @param accountV1 - A v1 account.
|
|
15
14
|
* @returns The list of scopes for that accounts.
|
|
16
15
|
*/
|
|
17
|
-
export declare function getScopesForAccountV1(accountV1: KeyringAccountV1):
|
|
16
|
+
export declare function getScopesForAccountV1(accountV1: KeyringAccountV1): string[];
|
|
18
17
|
/**
|
|
19
18
|
* Transform an account v1. This account might have optional fields that are now required by
|
|
20
19
|
* the Keyring API. This function will automatically provides the missing fields with some
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.d.mts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;
|
|
1
|
+
{"version":3,"file":"v1.d.mts","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,cAAc,EACpB,8BAA8B;AAI/B,OAAO,EAGL,KAAK,gBAAgB,EACtB,uBAAmB;AAEpB;;;;;GAKG;AACH,wBAAgB,WAAW,CAEzB,OAAO,EAAE,gBAAgB,GAAG,cAAc,GACzC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,gBAAgB,GAAG,MAAM,EAAE,CA+B3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,GAC1B,cAAc,CAiBhB;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,GAAG,cAAc,CAU5E"}
|
package/dist/migrations/v1.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BtcAccountType,
|
|
1
|
+
import { BtcAccountType, BtcScopes, EthAccountType, EthScopes, SolAccountType, SolScopes } from "@metamask/keyring-api";
|
|
2
2
|
import { isBtcMainnetAddress } from "@metamask/keyring-utils";
|
|
3
3
|
import { is } from "@metamask/superstruct";
|
|
4
4
|
import { assertKeyringAccount, KeyringAccountV1Struct } from "../account.mjs";
|
|
@@ -22,11 +22,9 @@ account) {
|
|
|
22
22
|
export function getScopesForAccountV1(accountV1) {
|
|
23
23
|
switch (accountV1.type) {
|
|
24
24
|
case EthAccountType.Eoa: {
|
|
25
|
-
// EVM EOA account are compatible with any EVM networks, we use
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
// See: https://namespaces.chainagnostic.org/eip155/caip10
|
|
29
|
-
return [EthScope.Eoa];
|
|
25
|
+
// EVM EOA account are compatible with any EVM networks, and we use CAIP-2
|
|
26
|
+
// namespaces when the scope relates to ALL chains (from that namespace).
|
|
27
|
+
return [EthScopes.Namespace];
|
|
30
28
|
}
|
|
31
29
|
case EthAccountType.Erc4337: {
|
|
32
30
|
// EVM Erc4337 account
|
|
@@ -34,23 +32,23 @@ export function getScopesForAccountV1(accountV1) {
|
|
|
34
32
|
// to testnet since we cannot really "guess" it from here.
|
|
35
33
|
// Also, there's no official Snap as of today that uses this account type. So this case should never happen
|
|
36
34
|
// in production.
|
|
37
|
-
return [
|
|
35
|
+
return [EthScopes.Testnet];
|
|
38
36
|
}
|
|
39
37
|
case BtcAccountType.P2wpkh: {
|
|
40
38
|
// Bitcoin uses different accounts for testnet and mainnet
|
|
41
39
|
return [
|
|
42
40
|
isBtcMainnetAddress(accountV1.address)
|
|
43
|
-
?
|
|
44
|
-
:
|
|
41
|
+
? BtcScopes.Mainnet
|
|
42
|
+
: BtcScopes.Testnet,
|
|
45
43
|
];
|
|
46
44
|
}
|
|
47
45
|
case SolAccountType.DataAccount: {
|
|
48
46
|
// Solana account supports multiple chains.
|
|
49
|
-
return [
|
|
47
|
+
return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];
|
|
50
48
|
}
|
|
51
49
|
default:
|
|
52
50
|
// We re-use EOA scopes if we don't know what to do for now.
|
|
53
|
-
return [
|
|
51
|
+
return [EthScopes.Namespace];
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EAEV,8BAA8B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,gCAAgC;AAC9D,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EAEvB,uBAAmB;AAEpB;;;;;GAKG;AACH,MAAM,UAAU,WAAW;AACzB,6EAA6E;AAC7E,OAA0C;IAE1C,OAAO,EAAE,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAA2B;IAC/D,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;YACxB,0EAA0E;YAC1E,yEAAyE;YACzE,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC/B,CAAC;QACD,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,sBAAsB;YACtB,wGAAwG;YACxG,0DAA0D;YAC1D,2GAA2G;YAC3G,iBAAiB;YACjB,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,0DAA0D;YAC1D,OAAO;gBACL,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC;oBACpC,CAAC,CAAC,SAAS,CAAC,OAAO;oBACnB,CAAC,CAAC,SAAS,CAAC,OAAO;aACtB,CAAC;QACJ,CAAC;QACD,KAAK,cAAc,CAAC,WAAW,CAAC,CAAC,CAAC;YAChC,2CAA2C;YAC3C,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAClE,CAAC;QACD;YACE,4DAA4D;YAC5D,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAA2B;IAE3B,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAC;IAE3B,0EAA0E;IAC1E,yEAAyE;IACzE,wEAAwE;IACxE,0BAA0B;IAC1B,IAAI,IAAI,KAAK,cAAc,CAAC,GAAG,EAAE,CAAC;QAChC,OAAO;YACL,GAAG,SAAS;YACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;SACzC,CAAC;IACJ,CAAC;IAED,iFAAiF;IACjF,0DAA0D;IAC1D,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAA2B;IAC1D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,8BAA8B;QAC9B,OAAO,SAA2B,CAAC;IACrC,CAAC;IAED,OAAO;QACL,GAAG,SAAS;QACZ,MAAM,EAAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScopes,\n EthAccountType,\n EthScopes,\n SolAccountType,\n SolScopes,\n type KeyringAccount,\n} from '@metamask/keyring-api';\nimport { isBtcMainnetAddress } from '@metamask/keyring-utils';\nimport { is } from '@metamask/superstruct';\n\nimport {\n assertKeyringAccount,\n KeyringAccountV1Struct,\n type KeyringAccountV1,\n} from '../account';\n\n/**\n * Checks if an account is an `KeyringAccount` v1.\n *\n * @param account - A v1 account to check.\n * @returns True if the account is v1, false otherwise.\n */\nexport function isAccountV1(\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n account: KeyringAccountV1 | KeyringAccount,\n): boolean {\n return is(account, KeyringAccountV1Struct);\n}\n\n/**\n * Gets default scopes for a v1 account.\n *\n * @param accountV1 - A v1 account.\n * @returns The list of scopes for that accounts.\n */\nexport function getScopesForAccountV1(accountV1: KeyringAccountV1): string[] {\n switch (accountV1.type) {\n case EthAccountType.Eoa: {\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n return [EthScopes.Namespace];\n }\n case EthAccountType.Erc4337: {\n // EVM Erc4337 account\n // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default\n // to testnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So this case should never happen\n // in production.\n return [EthScopes.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScopes.Mainnet\n : BtcScopes.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScopes.Namespace];\n }\n}\n\n/**\n * Transform an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * default values.\n *\n * @param accountV1 - A v1 account to transform.\n * @throws An error if the v1 account cannot be transformed.\n * @returns A valid KeyringAccount.\n */\nexport function transformAccountV1(\n accountV1: KeyringAccountV1,\n): KeyringAccount {\n const { type } = accountV1;\n\n // EVM EOA account are compatible with any EVM networks, and we use CAIP-2\n // namespaces when the scope relates to ALL chains (from that namespace).\n // So we can automatically inject a valid `scopes` for this, but not for\n // other kind of accounts.\n if (type === EthAccountType.Eoa) {\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n }\n\n // For all other non-EVM and ERC4337 Snap accounts, the `scopes` is required, and\n // each `*AccountStruct` should assert that automatically.\n return assertKeyringAccount(accountV1);\n}\n\n/**\n * Migrate an account v1. This account might have optional fields that are now required by\n * the Keyring API. This function will automatically provides the missing fields with some\n * meaningful default values.\n *\n * @param accountV1 - The account to migrate.\n * @returns A valid KeyringAccount.\n */\nexport function migrateAccountV1(accountV1: KeyringAccountV1): KeyringAccount {\n if (!isAccountV1(accountV1)) {\n // Nothing to do in this case.\n return accountV1 as KeyringAccount;\n }\n\n return {\n ...accountV1,\n scopes: getScopesForAccountV1(accountV1),\n };\n}\n"]}
|