Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InterfaceContextStruct,
UserInputEventStruct,
} from '@metamask/snaps-sdk';
import { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';
import { HandlerType } from '@metamask/snaps-utils';
import type { Infer, Struct } from '@metamask/superstruct';
import {
any,
Expand Down Expand Up @@ -127,7 +127,7 @@ export type RequestArguments =
export const OnTransactionRequestArgumentsStruct = object({
// TODO: Improve `transaction` type.
transaction: record(string(), JsonStruct),
chainId: ChainIdStruct,
chainId: CaipChainIdStruct,
transactionOrigin: nullable(string()),
});

Expand Down Expand Up @@ -182,7 +182,7 @@ export function assertIsOnSignatureRequestArguments(
);
}

const baseNameLookupArgs = { chainId: ChainIdStruct };
const baseNameLookupArgs = { chainId: CaipChainIdStruct };
const domainRequestStruct = object({
...baseNameLookupArgs,
address: string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe('nameLookupCaveatSpecifications', () => {
value: ['eip155'],
}),
).toThrow(
'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".',
'Assertion failed: At path: 0 -- Expected a value of type `CaipChainId`, but received: `"eip155"`.',
);

expect(() =>
Expand Down
15 changes: 0 additions & 15 deletions packages/snaps-sdk/src/types/caip.test.ts

This file was deleted.

15 changes: 13 additions & 2 deletions packages/snaps-sdk/src/types/caip.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import type { CaipAccountId, CaipChainId } from '@metamask/utils';

export type {
CaipAccountId,
CaipAssetType,
CaipChainId,
CaipNamespace,
} from '@metamask/utils';

/**
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
*
* @see https://chainagnostic.org/CAIPs/caip-2
* @deprecated Use {@link CaipChainId} instead.
*/
export type ChainId = `${string}:${string}`;
export type ChainId = CaipChainId;

/**
* A CAIP-10 account ID, i.e., a chain ID and an account address.
*
* @see https://chainagnostic.org/CAIPs/caip-10
* @deprecated Use {@link CaipAccountId} instead.
*/
export type AccountId = `${ChainId}:${string}`;
export type AccountId = CaipAccountId;
8 changes: 3 additions & 5 deletions packages/snaps-sdk/src/types/handlers/name-lookup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { NonEmptyArray } from '@metamask/utils';

import type { ChainId } from '../caip';
import type { CaipChainId, NonEmptyArray } from '@metamask/utils';

type BaseOnNameLookupArgs = {
chainId: ChainId;
chainId: CaipChainId;
};

/**
Expand Down Expand Up @@ -76,7 +74,7 @@ export type AddressLookupResult = {
* Note that using this handler requires the `endowment:name-lookup` permission.
*
* @param args - The request arguments.
* @param args.chainId - The CAIP-2 {@link ChainId} of the network the
* @param args.chainId - The CAIP-2 {@link CaipChainId} of the network the
* transaction is being submitted to.
* @param args.domain - The human-readable address that is to be resolved. This
* is mutually exclusive with `args.address`.
Expand Down
7 changes: 4 additions & 3 deletions packages/snaps-sdk/src/types/handlers/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CaipChainId } from '@metamask/utils';

import type { ComponentOrElement } from '..';
import type { EnumToUnion } from '../../internals';
import type { ChainId } from '../caip';

/**
* The severity level of content being returned from a transaction insight.
Expand Down Expand Up @@ -87,7 +88,7 @@ export type Transaction = EIP1559Transaction | LegacyTransaction;
* @param args - The request arguments.
* @param args.transaction - The transaction object, containing the address,
* value, data, and other properties of the transaction.
* @param args.chainId - The CAIP-2 {@link ChainId} of the network the
* @param args.chainId - The CAIP-2 {@link CaipChainId} of the network the
* transaction is being submitted to.
* @param args.transactionOrigin - The origin of the transaction. This is the
* URL of the website that submitted the transaction. This is only available if
Expand All @@ -99,7 +100,7 @@ export type Transaction = EIP1559Transaction | LegacyTransaction;
*/
export type OnTransactionHandler = (args: {
transaction: Transaction;
chainId: ChainId;
chainId: CaipChainId;
transactionOrigin?: string;
}) => Promise<OnTransactionResponse | null>;

Expand Down
6 changes: 2 additions & 4 deletions packages/snaps-sdk/src/types/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { SupportedCurve } from '@metamask/key-tree';
import type { JsonRpcRequest } from '@metamask/utils';

import type { ChainId } from './caip';
import type { CaipChainId, JsonRpcRequest } from '@metamask/utils';

export type EmptyObject = Record<string, never>;

Expand Down Expand Up @@ -49,7 +47,7 @@ export type InitialPermissions = Partial<{
maxRequestTime?: number;
};
'endowment:name-lookup': {
chains?: ChainId[];
chains?: CaipChainId[];
matchers?: NameLookupMatchers;
maxRequestTime?: number;
};
Expand Down
6 changes: 3 additions & 3 deletions packages/snaps-utils/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 99.74,
"functions": 98.95,
"lines": 99.47,
"statements": 96.27
"functions": 98.92,
"lines": 99.61,
"statements": 96.91
}
1 change: 0 additions & 1 deletion packages/snaps-utils/src/index.executionenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export * from './handlers';
export * from './handler-types';
export * from './iframe';
export * from './logging';
export * from './namespace';
export * from './types';
1 change: 0 additions & 1 deletion packages/snaps-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export * from './json-rpc';
export * from './localization';
export * from './logging';
export * from './manifest';
export * from './namespace';
export * from './path';
export * from './platform-version';
export * from './snaps';
Expand Down
3 changes: 1 addition & 2 deletions packages/snaps-utils/src/manifest/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { isEqual } from '../array';
import { CronjobSpecificationArrayStruct } from '../cronjob';
import { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';
import { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';
import { ChainIdStruct } from '../namespace';
import { SnapIdStruct } from '../snaps';
import { mergeStructs, type InferMatching } from '../structs';
import { NameStruct, NpmSnapFileNames, uri } from '../types';
Expand Down Expand Up @@ -151,7 +150,7 @@ export const SnapIdsStruct = refine(

export type SnapIds = Infer<typeof SnapIdsStruct>;

export const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);
export const ChainIdsStruct = size(array(CaipChainIdStruct), 1, Infinity);

export const LookupMatchersStruct = union([
object({
Expand Down
Loading
Loading