Skip to content
Merged
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
21 changes: 10 additions & 11 deletions src/caip-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Infer } from '@metamask/superstruct';
import { is } from '@metamask/superstruct';

import { definePattern } from './superstruct';

Expand Down Expand Up @@ -164,7 +163,7 @@ export type KnownCaipNamespacedChainId<
* @returns Whether the value is a {@link CaipChainId}.
*/
export function isCaipChainId(value: unknown): value is CaipChainId {
return is(value, CaipChainIdStruct);
return typeof value === 'string' && CAIP_CHAIN_ID_REGEX.test(value);
}

/**
Expand All @@ -174,7 +173,7 @@ export function isCaipChainId(value: unknown): value is CaipChainId {
* @returns Whether the value is a {@link CaipNamespace}.
*/
export function isCaipNamespace(value: unknown): value is CaipNamespace {
return is(value, CaipNamespaceStruct);
return typeof value === 'string' && CAIP_NAMESPACE_REGEX.test(value);
}

/**
Expand All @@ -184,7 +183,7 @@ export function isCaipNamespace(value: unknown): value is CaipNamespace {
* @returns Whether the value is a {@link CaipReference}.
*/
export function isCaipReference(value: unknown): value is CaipReference {
return is(value, CaipReferenceStruct);
return typeof value === 'string' && CAIP_REFERENCE_REGEX.test(value);
}

/**
Expand All @@ -194,7 +193,7 @@ export function isCaipReference(value: unknown): value is CaipReference {
* @returns Whether the value is a {@link CaipAccountId}.
*/
export function isCaipAccountId(value: unknown): value is CaipAccountId {
return is(value, CaipAccountIdStruct);
return typeof value === 'string' && CAIP_ACCOUNT_ID_REGEX.test(value);
}

/**
Expand All @@ -206,7 +205,7 @@ export function isCaipAccountId(value: unknown): value is CaipAccountId {
export function isCaipAccountAddress(
value: unknown,
): value is CaipAccountAddress {
return is(value, CaipAccountAddressStruct);
return typeof value === 'string' && CAIP_ACCOUNT_ADDRESS_REGEX.test(value);
}

/**
Expand All @@ -218,7 +217,7 @@ export function isCaipAccountAddress(
export function isCaipAssetNamespace(
value: unknown,
): value is CaipAssetNamespace {
return is(value, CaipAssetNamespaceStruct);
return typeof value === 'string' && CAIP_ASSET_NAMESPACE_REGEX.test(value);
}

/**
Expand All @@ -230,7 +229,7 @@ export function isCaipAssetNamespace(
export function isCaipAssetReference(
value: unknown,
): value is CaipAssetReference {
return is(value, CaipAssetReferenceStruct);
return typeof value === 'string' && CAIP_ASSET_REFERENCE_REGEX.test(value);
}

/**
Expand All @@ -240,7 +239,7 @@ export function isCaipAssetReference(
* @returns Whether the value is a {@link CaipTokenId}.
*/
export function isCaipTokenId(value: unknown): value is CaipTokenId {
return is(value, CaipTokenIdStruct);
return typeof value === 'string' && CAIP_TOKEN_ID_REGEX.test(value);
}

/**
Expand All @@ -250,7 +249,7 @@ export function isCaipTokenId(value: unknown): value is CaipTokenId {
* @returns Whether the value is a {@link CaipAssetType}.
*/
export function isCaipAssetType(value: unknown): value is CaipAssetType {
return is(value, CaipAssetTypeStruct);
return typeof value === 'string' && CAIP_ASSET_TYPE_REGEX.test(value);
}

/**
Expand All @@ -260,7 +259,7 @@ export function isCaipAssetType(value: unknown): value is CaipAssetType {
* @returns Whether the value is a {@link CaipAssetId}.
*/
export function isCaipAssetId(value: unknown): value is CaipAssetId {
return is(value, CaipAssetIdStruct);
return typeof value === 'string' && CAIP_ASSET_ID_REGEX.test(value);
}

/**
Expand Down
Loading