Skip to content

Commit 9898fcd

Browse files
authored
BREAKING: Remove duplicate CAIP types (#3071)
This removes duplicate CAIP types that were moved to `@metamask/utils`. We were already using the `@metamask/utils` types in most places. Closes #3043. ## Breaking changes - The following functions, values, types, and structs were removed from `@metamask/snaps-utils`: - `CHAIN_ID_REGEX` - `ACCOUNT_ID_REGEX` - `ACCOUNT_ADDRESS_REGEX` - `parseChainId` - `parseAccountId` - `LimitedString` - `ChainIdStringStruct` - `ChainIdStruct` - `AccountIdStruct` - `AccountIdArrayStruct` - `AccountAddressStruct` - `AccountAddress` - `ChainStruct` - `Chain` - `NamespaceStruct` - `Namespace` - `NamespaceIdStruct` - `NamespaceId` - `isNamespaceId` - `isChainId` - `isAccountId` - `isAccountIdArray` - `isNamespace`
1 parent 3fa49bd commit 9898fcd

File tree

15 files changed

+30
-549
lines changed

15 files changed

+30
-549
lines changed

packages/snaps-execution-environments/src/common/validation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
InterfaceContextStruct,
44
UserInputEventStruct,
55
} from '@metamask/snaps-sdk';
6-
import { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';
6+
import { HandlerType } from '@metamask/snaps-utils';
77
import type { Infer, Struct } from '@metamask/superstruct';
88
import {
99
any,
@@ -127,7 +127,7 @@ export type RequestArguments =
127127
export const OnTransactionRequestArgumentsStruct = object({
128128
// TODO: Improve `transaction` type.
129129
transaction: record(string(), JsonStruct),
130-
chainId: ChainIdStruct,
130+
chainId: CaipChainIdStruct,
131131
transactionOrigin: nullable(string()),
132132
});
133133

@@ -182,7 +182,7 @@ export function assertIsOnSignatureRequestArguments(
182182
);
183183
}
184184

185-
const baseNameLookupArgs = { chainId: ChainIdStruct };
185+
const baseNameLookupArgs = { chainId: CaipChainIdStruct };
186186
const domainRequestStruct = object({
187187
...baseNameLookupArgs,
188188
address: string(),

packages/snaps-rpc-methods/src/endowments/name-lookup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe('nameLookupCaveatSpecifications', () => {
243243
value: ['eip155'],
244244
}),
245245
).toThrow(
246-
'Assertion failed: At path: 0 -- Expected a Chain ID matching `/^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/` but received "eip155".',
246+
'Assertion failed: At path: 0 -- Expected a value of type `CaipChainId`, but received: `"eip155"`.',
247247
);
248248

249249
expect(() =>

packages/snaps-sdk/src/types/caip.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
import type { CaipAccountId, CaipChainId } from '@metamask/utils';
2+
3+
export type {
4+
CaipAccountId,
5+
CaipAssetType,
6+
CaipChainId,
7+
CaipNamespace,
8+
} from '@metamask/utils';
9+
110
/**
211
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
312
*
413
* @see https://chainagnostic.org/CAIPs/caip-2
14+
* @deprecated Use {@link CaipChainId} instead.
515
*/
6-
export type ChainId = `${string}:${string}`;
16+
export type ChainId = CaipChainId;
717

818
/**
919
* A CAIP-10 account ID, i.e., a chain ID and an account address.
1020
*
1121
* @see https://chainagnostic.org/CAIPs/caip-10
22+
* @deprecated Use {@link CaipAccountId} instead.
1223
*/
13-
export type AccountId = `${ChainId}:${string}`;
24+
export type AccountId = CaipAccountId;

packages/snaps-sdk/src/types/handlers/name-lookup.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { NonEmptyArray } from '@metamask/utils';
2-
3-
import type { ChainId } from '../caip';
1+
import type { CaipChainId, NonEmptyArray } from '@metamask/utils';
42

53
type BaseOnNameLookupArgs = {
6-
chainId: ChainId;
4+
chainId: CaipChainId;
75
};
86

97
/**
@@ -76,7 +74,7 @@ export type AddressLookupResult = {
7674
* Note that using this handler requires the `endowment:name-lookup` permission.
7775
*
7876
* @param args - The request arguments.
79-
* @param args.chainId - The CAIP-2 {@link ChainId} of the network the
77+
* @param args.chainId - The CAIP-2 {@link CaipChainId} of the network the
8078
* transaction is being submitted to.
8179
* @param args.domain - The human-readable address that is to be resolved. This
8280
* is mutually exclusive with `args.address`.

packages/snaps-sdk/src/types/handlers/transaction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { CaipChainId } from '@metamask/utils';
2+
13
import type { ComponentOrElement } from '..';
24
import type { EnumToUnion } from '../../internals';
3-
import type { ChainId } from '../caip';
45

56
/**
67
* The severity level of content being returned from a transaction insight.
@@ -87,7 +88,7 @@ export type Transaction = EIP1559Transaction | LegacyTransaction;
8788
* @param args - The request arguments.
8889
* @param args.transaction - The transaction object, containing the address,
8990
* value, data, and other properties of the transaction.
90-
* @param args.chainId - The CAIP-2 {@link ChainId} of the network the
91+
* @param args.chainId - The CAIP-2 {@link CaipChainId} of the network the
9192
* transaction is being submitted to.
9293
* @param args.transactionOrigin - The origin of the transaction. This is the
9394
* URL of the website that submitted the transaction. This is only available if
@@ -99,7 +100,7 @@ export type Transaction = EIP1559Transaction | LegacyTransaction;
99100
*/
100101
export type OnTransactionHandler = (args: {
101102
transaction: Transaction;
102-
chainId: ChainId;
103+
chainId: CaipChainId;
103104
transactionOrigin?: string;
104105
}) => Promise<OnTransactionResponse | null>;
105106

packages/snaps-sdk/src/types/permissions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { SupportedCurve } from '@metamask/key-tree';
2-
import type { JsonRpcRequest } from '@metamask/utils';
3-
4-
import type { ChainId } from './caip';
2+
import type { CaipChainId, JsonRpcRequest } from '@metamask/utils';
53

64
export type EmptyObject = Record<string, never>;
75

@@ -49,7 +47,7 @@ export type InitialPermissions = Partial<{
4947
maxRequestTime?: number;
5048
};
5149
'endowment:name-lookup': {
52-
chains?: ChainId[];
50+
chains?: CaipChainId[];
5351
matchers?: NameLookupMatchers;
5452
maxRequestTime?: number;
5553
};

packages/snaps-utils/coverage.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"branches": 99.74,
3-
"functions": 98.95,
4-
"lines": 99.47,
5-
"statements": 96.27
3+
"functions": 98.92,
4+
"lines": 99.61,
5+
"statements": 96.91
66
}

packages/snaps-utils/src/index.executionenv.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ export * from './handlers';
44
export * from './handler-types';
55
export * from './iframe';
66
export * from './logging';
7-
export * from './namespace';
87
export * from './types';

packages/snaps-utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export * from './json-rpc';
2020
export * from './localization';
2121
export * from './logging';
2222
export * from './manifest';
23-
export * from './namespace';
2423
export * from './path';
2524
export * from './platform-version';
2625
export * from './snaps';

0 commit comments

Comments
 (0)