@metamask-previews/eth-snap-keyring 8.1.1-7ba2de1 → 9.0.0-0aca2ee

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 CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [9.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add `account{AssetList,Balances,Transactions}Updated` keyring events and re-publish them through the new `Messenger` ([#154](https://github.com/MetaMask/accounts/pull/154))
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Use `Messenger` instead of `SnapsController` ([#152](https://github.com/MetaMask/accounts/pull/152))
19
+ - This allows to break the runtime dependency we had with some `snaps-*` pacakges.
20
+ - **BREAKING:** Make `scopes` more strict ([#159](https://github.com/MetaMask/accounts/pull/159))
21
+ - We now use specific `*AccountStucts` when checking created/updated accounts to make the `scopes` sent by the Snap are valid regarding their account type definition.
22
+
10
23
  ## [8.1.1]
11
24
 
12
25
  ### Changed
@@ -416,7 +429,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
416
429
 
417
430
  - Initial release.
418
431
 
419
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.1...HEAD
432
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@9.0.0...HEAD
433
+ [9.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.1...@metamask/eth-snap-keyring@9.0.0
420
434
  [8.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.1.0...@metamask/eth-snap-keyring@8.1.1
421
435
  [8.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@8.0.0...@metamask/eth-snap-keyring@8.1.0
422
436
  [8.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-snap-keyring@7.1.0...@metamask/eth-snap-keyring@8.0.0
@@ -30,31 +30,31 @@ function getScopesForAccountV1(accountV1) {
30
30
  case keyring_api_1.EthAccountType.Eoa: {
31
31
  // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
32
32
  // namespaces when the scope relates to ALL chains (from that namespace).
33
- return [keyring_api_1.EthScopes.Namespace];
33
+ return [keyring_api_1.EthScope.Namespace];
34
34
  }
35
35
  case keyring_api_1.EthAccountType.Erc4337: {
36
36
  // EVM Erc4337 account
37
37
  // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default
38
- // to mainnet since we cannot really "guess" it from here.
39
- // Also, there's no official Snap as of today that uses this account type. So
40
- // this case should never happen.
41
- return [keyring_api_1.EthScopes.Mainnet];
38
+ // to testnet since we cannot really "guess" it from here.
39
+ // Also, there's no official Snap as of today that uses this account type. So this case should never happen
40
+ // in production.
41
+ return [keyring_api_1.EthScope.Testnet];
42
42
  }
43
43
  case keyring_api_1.BtcAccountType.P2wpkh: {
44
44
  // Bitcoin uses different accounts for testnet and mainnet
45
45
  return [
46
46
  (0, keyring_utils_1.isBtcMainnetAddress)(accountV1.address)
47
- ? keyring_api_1.BtcScopes.Mainnet
48
- : keyring_api_1.BtcScopes.Testnet,
47
+ ? keyring_api_1.BtcScope.Mainnet
48
+ : keyring_api_1.BtcScope.Testnet,
49
49
  ];
50
50
  }
51
51
  case keyring_api_1.SolAccountType.DataAccount: {
52
52
  // Solana account supports multiple chains.
53
- return [keyring_api_1.SolScopes.Mainnet, keyring_api_1.SolScopes.Testnet, keyring_api_1.SolScopes.Devnet];
53
+ return [keyring_api_1.SolScope.Mainnet, keyring_api_1.SolScope.Testnet, keyring_api_1.SolScope.Devnet];
54
54
  }
55
55
  default:
56
56
  // We re-use EOA scopes if we don't know what to do for now.
57
- return [keyring_api_1.EthScopes.Namespace];
57
+ return [keyring_api_1.EthScope.Namespace];
58
58
  }
59
59
  }
60
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"v1.cjs","sour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;;;;;;;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 mainnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So\n // this case should never happen.\n return [EthScopes.Mainnet];\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"]}
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,sBAAQ,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;QACD,KAAK,4BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,sBAAsB;YACtB,wGAAwG;YACxG,0DAA0D;YAC1D,2GAA2G;YAC3G,iBAAiB;YACjB,OAAO,CAAC,sBAAQ,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;QACD,KAAK,4BAAc,CAAC,MAAM,CAAC,CAAC,CAAC;YAC3B,0DAA0D;YAC1D,OAAO;gBACL,IAAA,mCAAmB,EAAC,SAAS,CAAC,OAAO,CAAC;oBACpC,CAAC,CAAC,sBAAQ,CAAC,OAAO;oBAClB,CAAC,CAAC,sBAAQ,CAAC,OAAO;aACrB,CAAC;QACJ,CAAC;QACD,KAAK,4BAAc,CAAC,WAAW,CAAC,CAAC,CAAC;YAChC,2CAA2C;YAC3C,OAAO,CAAC,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,OAAO,EAAE,sBAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;QACD;YACE,4DAA4D;YAC5D,OAAO,CAAC,sBAAQ,CAAC,SAAS,CAAC,CAAC;IAChC,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 BtcScope,\n EthAccountType,\n EthScope,\n SolAccountType,\n SolScope,\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 [EthScope.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 [EthScope.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScope.Mainnet\n : BtcScope.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScope.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"]}
@@ -1,4 +1,4 @@
1
- import { BtcAccountType, BtcScopes, EthAccountType, EthScopes, SolAccountType, SolScopes } from "@metamask/keyring-api";
1
+ import { BtcAccountType, BtcScope, EthAccountType, EthScope, SolAccountType, SolScope } 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";
@@ -24,31 +24,31 @@ export function getScopesForAccountV1(accountV1) {
24
24
  case EthAccountType.Eoa: {
25
25
  // EVM EOA account are compatible with any EVM networks, and we use CAIP-2
26
26
  // namespaces when the scope relates to ALL chains (from that namespace).
27
- return [EthScopes.Namespace];
27
+ return [EthScope.Namespace];
28
28
  }
29
29
  case EthAccountType.Erc4337: {
30
30
  // EVM Erc4337 account
31
31
  // NOTE: A Smart Contract account might not be compatible with every chain, in this case we just default
32
- // to mainnet since we cannot really "guess" it from here.
33
- // Also, there's no official Snap as of today that uses this account type. So
34
- // this case should never happen.
35
- return [EthScopes.Mainnet];
32
+ // to testnet since we cannot really "guess" it from here.
33
+ // Also, there's no official Snap as of today that uses this account type. So this case should never happen
34
+ // in production.
35
+ return [EthScope.Testnet];
36
36
  }
37
37
  case BtcAccountType.P2wpkh: {
38
38
  // Bitcoin uses different accounts for testnet and mainnet
39
39
  return [
40
40
  isBtcMainnetAddress(accountV1.address)
41
- ? BtcScopes.Mainnet
42
- : BtcScopes.Testnet,
41
+ ? BtcScope.Mainnet
42
+ : BtcScope.Testnet,
43
43
  ];
44
44
  }
45
45
  case SolAccountType.DataAccount: {
46
46
  // Solana account supports multiple chains.
47
- return [SolScopes.Mainnet, SolScopes.Testnet, SolScopes.Devnet];
47
+ return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];
48
48
  }
49
49
  default:
50
50
  // We re-use EOA scopes if we don't know what to do for now.
51
- return [EthScopes.Namespace];
51
+ return [EthScope.Namespace];
52
52
  }
53
53
  }
54
54
  /**
@@ -1 +1 @@
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,6EAA6E;YAC7E,iCAAiC;YACjC,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 mainnet since we cannot really \"guess\" it from here.\n // Also, there's no official Snap as of today that uses this account type. So\n // this case should never happen.\n return [EthScopes.Mainnet];\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"]}
1
+ {"version":3,"file":"v1.mjs","sourceRoot":"","sources":["../../src/migrations/v1.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,cAAc,EACd,QAAQ,EAET,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,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;QACD,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5B,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AAE,qBAAqB,CAAC,SAAS,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BtcAccountType,\n BtcScope,\n EthAccountType,\n EthScope,\n SolAccountType,\n SolScope,\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 [EthScope.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 [EthScope.Testnet];\n }\n case BtcAccountType.P2wpkh: {\n // Bitcoin uses different accounts for testnet and mainnet\n return [\n isBtcMainnetAddress(accountV1.address)\n ? BtcScope.Mainnet\n : BtcScope.Testnet,\n ];\n }\n case SolAccountType.DataAccount: {\n // Solana account supports multiple chains.\n return [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];\n }\n default:\n // We re-use EOA scopes if we don't know what to do for now.\n return [EthScope.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/eth-snap-keyring",
3
- "version": "8.1.1-7ba2de1",
3
+ "version": "9.0.0-0aca2ee",
4
4
  "description": "Snaps keyring bridge.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,10 +40,10 @@
40
40
  "@ethereumjs/tx": "^4.2.0",
41
41
  "@metamask/base-controller": "^7.1.1",
42
42
  "@metamask/eth-sig-util": "^8.1.2",
43
- "@metamask/keyring-api": "14.0.0",
44
- "@metamask/keyring-internal-api": "2.0.1",
45
- "@metamask/keyring-internal-snap-client": "3.0.0",
46
- "@metamask/keyring-utils": "1.2.0",
43
+ "@metamask/keyring-api": "15.0.0",
44
+ "@metamask/keyring-internal-api": "3.0.0",
45
+ "@metamask/keyring-internal-snap-client": "3.0.1",
46
+ "@metamask/keyring-utils": "1.3.0",
47
47
  "@metamask/superstruct": "^3.1.0",
48
48
  "@metamask/utils": "^11.0.1",
49
49
  "@types/uuid": "^9.0.8",