Skip to content

Commit f3de205

Browse files
committed
Merge branch 'main' into feat/accounts-api-rate-limiting-headers
2 parents e2b6fd1 + 4d65b43 commit f3de205

File tree

15 files changed

+161
-78
lines changed

15 files changed

+161
-78
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/core-monorepo",
3-
"version": "459.0.0",
3+
"version": "460.0.0",
44
"private": true,
55
"description": "Monorepo for packages shared between MetaMask clients",
66
"repository": {

packages/multichain-network-controller/src/MultichainNetworkController/MultichainNetworkController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '../types';
2525
import {
2626
checkIfSupportedCaipChainId,
27-
getChainIdForNonEvmAddress,
27+
getChainIdForNonEvm,
2828
convertEvmCaipToHexChainId,
2929
isEvmCaipChainId,
3030
} from '../utils';
@@ -269,7 +269,7 @@ export class MultichainNetworkController extends BaseController<
269269
* @param account - The account that was changed
270270
*/
271271
#handleOnSelectedAccountChange(account: InternalAccount) {
272-
const { type: accountType, address: accountAddress, scopes } = account;
272+
const { type: accountType, scopes } = account;
273273
const isEvmAccount = isEvmAccountType(accountType);
274274

275275
// Handle switching to EVM network
@@ -296,7 +296,7 @@ export class MultichainNetworkController extends BaseController<
296296
return;
297297
}
298298

299-
const nonEvmChainId = getChainIdForNonEvmAddress(accountAddress);
299+
const nonEvmChainId = getChainIdForNonEvm(scopes);
300300
this.update((state) => {
301301
state.selectedMultichainNetworkChainId = nonEvmChainId;
302302
state.isEvmSelected = false;

packages/multichain-network-controller/src/api/accounts-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ export const MULTICHAIN_ACCOUNTS_CLIENT_ID =
5050
*/
5151
export const MULTICHAIN_ALLOWED_ACTIVE_NETWORK_SCOPES = [
5252
String(BtcScope.Mainnet),
53+
String(BtcScope.Testnet),
54+
String(BtcScope.Testnet4),
55+
String(BtcScope.Signet),
56+
String(BtcScope.Regtest),
5357
String(SolScope.Mainnet),
5458
String(EthScope.Mainnet),
5559
String(EthScope.Testnet),

packages/multichain-network-controller/src/constants.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import type {
1111

1212
export const BTC_NATIVE_ASSET = `${BtcScope.Mainnet}/slip44:0`;
1313
export const BTC_TESTNET_NATIVE_ASSET = `${BtcScope.Testnet}/slip44:0`;
14+
export const BTC_TESTNET4_NATIVE_ASSET = `${BtcScope.Testnet4}/slip44:0`;
1415
export const BTC_SIGNET_NATIVE_ASSET = `${BtcScope.Signet}/slip44:0`;
16+
export const BTC_REGTEST_NATIVE_ASSET = `${BtcScope.Regtest}/slip44:0`;
1517
export const SOL_NATIVE_ASSET = `${SolScope.Mainnet}/slip44:501`;
1618
export const SOL_TESTNET_NATIVE_ASSET = `${SolScope.Testnet}/slip44:501`;
1719
export const SOL_DEVNET_NATIVE_ASSET = `${SolScope.Devnet}/slip44:501`;
@@ -35,12 +37,24 @@ export const AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS: Record<
3537
nativeCurrency: BTC_TESTNET_NATIVE_ASSET,
3638
isEvm: false,
3739
},
40+
[BtcScope.Testnet4]: {
41+
chainId: BtcScope.Testnet4,
42+
name: 'Bitcoin Testnet4',
43+
nativeCurrency: BTC_TESTNET4_NATIVE_ASSET,
44+
isEvm: false,
45+
},
3846
[BtcScope.Signet]: {
3947
chainId: BtcScope.Signet,
40-
name: 'Bitcoin Signet',
48+
name: 'Bitcoin Mutinynet',
4149
nativeCurrency: BTC_SIGNET_NATIVE_ASSET,
4250
isEvm: false,
4351
},
52+
[BtcScope.Regtest]: {
53+
chainId: BtcScope.Regtest,
54+
name: 'Bitcoin Regtest',
55+
nativeCurrency: BTC_REGTEST_NATIVE_ASSET,
56+
isEvm: false,
57+
},
4458
[SolScope.Mainnet]: {
4559
chainId: SolScope.Mainnet,
4660
name: 'Solana',
@@ -68,7 +82,9 @@ export const AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS: Record<
6882
*/
6983
export const NON_EVM_TESTNET_IDS: CaipChainId[] = [
7084
BtcScope.Testnet,
85+
BtcScope.Testnet4,
7186
BtcScope.Signet,
87+
BtcScope.Regtest,
7288
SolScope.Testnet,
7389
SolScope.Devnet,
7490
];
@@ -122,7 +138,9 @@ export const MULTICHAIN_NETWORK_CONTROLLER_METADATA = {
122138
export const MULTICHAIN_NETWORK_TICKER: Record<CaipChainId, string> = {
123139
[BtcScope.Mainnet]: 'BTC',
124140
[BtcScope.Testnet]: 'tBTC',
141+
[BtcScope.Testnet4]: 'tBTC',
125142
[BtcScope.Signet]: 'sBTC',
143+
[BtcScope.Regtest]: 'rBTC',
126144
[SolScope.Mainnet]: 'SOL',
127145
[SolScope.Testnet]: 'tSOL',
128146
[SolScope.Devnet]: 'dSOL',
@@ -135,7 +153,9 @@ export const MULTICHAIN_NETWORK_TICKER: Record<CaipChainId, string> = {
135153
export const MULTICHAIN_NETWORK_DECIMAL_PLACES: Record<CaipChainId, number> = {
136154
[BtcScope.Mainnet]: 8,
137155
[BtcScope.Testnet]: 8,
156+
[BtcScope.Testnet4]: 8,
138157
[BtcScope.Signet]: 8,
158+
[BtcScope.Regtest]: 8,
139159
[SolScope.Mainnet]: 5,
140160
[SolScope.Testnet]: 5,
141161
[SolScope.Devnet]: 5,

packages/multichain-network-controller/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export type MultichainNetworkMetadata = {
3535
export type SupportedCaipChainId =
3636
| BtcScope.Mainnet
3737
| BtcScope.Testnet
38+
| BtcScope.Testnet4
3839
| BtcScope.Signet
40+
| BtcScope.Regtest
3941
| SolScope.Mainnet
4042
| SolScope.Testnet
4143
| SolScope.Devnet;

packages/multichain-network-controller/src/utils.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,33 @@ import {
1111
isEvmCaipChainId,
1212
toEvmCaipChainId,
1313
convertEvmCaipToHexChainId,
14-
getChainIdForNonEvmAddress,
14+
getChainIdForNonEvm,
1515
checkIfSupportedCaipChainId,
1616
toMultichainNetworkConfiguration,
1717
toMultichainNetworkConfigurationsByChainId,
1818
isKnownCaipNamespace,
1919
} from './utils';
2020

2121
describe('utils', () => {
22-
describe('getChainIdForNonEvmAddress', () => {
23-
it('returns Solana chain ID for Solana addresses', () => {
24-
const solanaAddress = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
25-
expect(getChainIdForNonEvmAddress(solanaAddress)).toBe(SolScope.Mainnet);
22+
describe('getChainIdForNonEvm', () => {
23+
it('returns Solana chain ID for Solana scopes', () => {
24+
const scopes = [SolScope.Mainnet, SolScope.Testnet, SolScope.Devnet];
25+
expect(getChainIdForNonEvm(scopes)).toBe(SolScope.Mainnet);
2626
});
2727

28-
it('returns Bitcoin chain ID for non-Solana addresses', () => {
29-
const bitcoinAddress = 'bc1qzqc2aqlw8nwa0a05ehjkk7dgt8308ac7kzw9a6';
30-
expect(getChainIdForNonEvmAddress(bitcoinAddress)).toBe(BtcScope.Mainnet);
28+
it('returns Bitcoin chain ID for Bitcoin scopes', () => {
29+
let scopes = [BtcScope.Mainnet];
30+
expect(getChainIdForNonEvm(scopes)).toBe(BtcScope.Mainnet);
31+
32+
scopes = [BtcScope.Testnet];
33+
expect(getChainIdForNonEvm(scopes)).toBe(BtcScope.Testnet);
34+
});
35+
36+
it('throws error if network is not found', () => {
37+
const scopes = ['unknown:scope' as CaipChainId];
38+
expect(() => getChainIdForNonEvm(scopes)).toThrow(
39+
'Unsupported scope: unknown:scope.',
40+
);
3141
});
3242
});
3343

packages/multichain-network-controller/src/utils.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { BtcScope, SolScope } from '@metamask/keyring-api';
21
import type { NetworkConfiguration } from '@metamask/network-controller';
32
import {
43
type Hex,
@@ -9,7 +8,6 @@ import {
98
hexToNumber,
109
add0x,
1110
} from '@metamask/utils';
12-
import { isAddress as isSolanaAddress } from '@solana/addresses';
1311

1412
import { AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS } from './constants';
1513
import type {
@@ -29,19 +27,22 @@ export function isEvmCaipChainId(chainId: CaipChainId): boolean {
2927
}
3028

3129
/**
32-
* Returns the chain id of the non-EVM network based on the account address.
30+
* Returns the chain id of the non-EVM network based on the account scopes.
3331
*
34-
* @param address - The address to check.
32+
* @param scopes - The scopes to check.
3533
* @returns The caip chain id of the non-EVM network.
3634
*/
37-
export function getChainIdForNonEvmAddress(
38-
address: string,
35+
export function getChainIdForNonEvm(
36+
scopes: CaipChainId[],
3937
): SupportedCaipChainId {
40-
// This condition is not the most robust. Once we support more networks, we will need to update this logic.
41-
if (isSolanaAddress(address)) {
42-
return SolScope.Mainnet;
38+
const supportedScope = scopes.find((scope) =>
39+
Object.keys(AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS).includes(scope),
40+
);
41+
if (supportedScope) {
42+
return supportedScope as SupportedCaipChainId;
4343
}
44-
return BtcScope.Mainnet;
44+
45+
throw new Error(`Unsupported scope: ${scopes.join(', ')}.`);
4546
}
4647

4748
/**

packages/notification-services-controller/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [13.0.0]
11+
12+
### Changed
13+
14+
- **BREAKING:** Bump peer dependency `@metamask/profile-sync-controller` to `^20.0.0` ([#6071](https://github.com/MetaMask/core/pull/6071))
15+
1016
## [12.0.1]
1117

1218
### Changed
@@ -481,7 +487,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
481487

482488
- Initial release
483489

484-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@12.0.1...HEAD
490+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@13.0.0...HEAD
491+
[13.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@12.0.1...@metamask/notification-services-controller@13.0.0
485492
[12.0.1]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@12.0.0...@metamask/notification-services-controller@12.0.1
486493
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@11.0.0...@metamask/notification-services-controller@12.0.0
487494
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@10.0.0...@metamask/notification-services-controller@11.0.0

packages/notification-services-controller/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/notification-services-controller",
3-
"version": "12.0.1",
3+
"version": "13.0.0",
44
"description": "Manages New MetaMask decentralized Notification system",
55
"keywords": [
66
"MetaMask",
@@ -123,7 +123,7 @@
123123
"@lavamoat/preinstall-always-fail": "^2.1.0",
124124
"@metamask/auto-changelog": "^3.4.4",
125125
"@metamask/keyring-controller": "^22.1.0",
126-
"@metamask/profile-sync-controller": "^19.0.0",
126+
"@metamask/profile-sync-controller": "^20.0.0",
127127
"@types/jest": "^27.4.1",
128128
"@types/readable-stream": "^2.3.0",
129129
"contentful": "^10.15.0",
@@ -138,7 +138,7 @@
138138
},
139139
"peerDependencies": {
140140
"@metamask/keyring-controller": "^22.0.0",
141-
"@metamask/profile-sync-controller": "^19.0.0"
141+
"@metamask/profile-sync-controller": "^20.0.0"
142142
},
143143
"engines": {
144144
"node": "^18.18 || >=20"

packages/profile-sync-controller/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [20.0.0]
11+
1012
### Added
1113

12-
- Add new `AuthenticationController:getUserProfileMetaMetrics` method
13-
- This fetches data containing all MetaMetrics sessions related to the currently authenticated user, in the form of `UserProfileMetaMetrics`
14+
- Add new `AuthenticationController:getUserProfileMetaMetrics` method ([#6068](https://github.com/MetaMask/core/pull/6068))
15+
- This method fetches data using the Authentication API, returning all MetaMetrics sessions related to the currently authenticated user, in the form of `typeof UserProfileMetaMetrics`
1416

1517
### Changed
1618

@@ -649,7 +651,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
649651

650652
- Initial release
651653

652-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@19.0.0...HEAD
654+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@20.0.0...HEAD
655+
[20.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@19.0.0...@metamask/profile-sync-controller@20.0.0
653656
[19.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@18.0.0...@metamask/profile-sync-controller@19.0.0
654657
[18.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@17.1.0...@metamask/profile-sync-controller@18.0.0
655658
[17.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@17.0.0...@metamask/profile-sync-controller@17.1.0

0 commit comments

Comments
 (0)