@partylayer/core 0.4.0 → 0.5.0

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/dist/index.d.mts CHANGED
@@ -193,6 +193,15 @@ interface Session {
193
193
  capabilitiesSnapshot: CapabilityKey[];
194
194
  /** Additional metadata (encrypted in storage) */
195
195
  metadata?: Record<string, string>;
196
+ /**
197
+ * Set when the wallet's reported network differs from the dApp's configured
198
+ * network (CAIP-2 normalized). Absent when the networks match or no confident
199
+ * mismatch was detected. See `networkEnforcement` for blocking behavior.
200
+ */
201
+ networkMismatch?: {
202
+ expected: string;
203
+ actual: string;
204
+ };
196
205
  }
197
206
  /**
198
207
  * Persisted session (for restoration)
@@ -292,7 +301,7 @@ declare function toSignature(sig: string): Signature;
292
301
  /**
293
302
  * Error code union - stable string literals for telemetry and UI
294
303
  */
295
- type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_INSTALLED' | 'USER_REJECTED' | 'ORIGIN_NOT_ALLOWED' | 'SESSION_EXPIRED' | 'CAPABILITY_NOT_SUPPORTED' | 'TRANSPORT_ERROR' | 'REGISTRY_FETCH_FAILED' | 'REGISTRY_VERIFICATION_FAILED' | 'REGISTRY_SCHEMA_INVALID' | 'INTERNAL_ERROR' | 'TIMEOUT';
304
+ type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_INSTALLED' | 'USER_REJECTED' | 'ORIGIN_NOT_ALLOWED' | 'SESSION_EXPIRED' | 'CAPABILITY_NOT_SUPPORTED' | 'TRANSPORT_ERROR' | 'REGISTRY_FETCH_FAILED' | 'REGISTRY_VERIFICATION_FAILED' | 'REGISTRY_SCHEMA_INVALID' | 'INTERNAL_ERROR' | 'NETWORK_MISMATCH' | 'TIMEOUT';
296
305
  /**
297
306
  * Error mapping context
298
307
  */
@@ -356,6 +365,18 @@ declare class OriginNotAllowedError extends PartyLayerError {
356
365
  declare class SessionExpiredError extends PartyLayerError {
357
366
  constructor(sessionId: string);
358
367
  }
368
+ /**
369
+ * Network mismatch error — the connected wallet's effective network differs
370
+ * from the dApp's configured network. Thrown to block wrong-network connects
371
+ * (policy 'strict') and wrong-network transactions (policy 'guard' | 'strict').
372
+ */
373
+ declare class NetworkMismatchError extends PartyLayerError {
374
+ /** The dApp's configured (expected) network, CAIP-2 normalized. */
375
+ readonly expected: string;
376
+ /** The wallet's reported (actual) network, CAIP-2 normalized. */
377
+ readonly actual: string;
378
+ constructor(expected: string, actual: string);
379
+ }
359
380
  /**
360
381
  * Capability not supported error
361
382
  */
@@ -1139,6 +1160,49 @@ declare const CIP0103_EVENTS: {
1139
1160
  };
1140
1161
  type CIP0103Event = (typeof CIP0103_EVENTS)[keyof typeof CIP0103_EVENTS];
1141
1162
 
1163
+ /**
1164
+ * CAIP-2 Network Identity Utilities
1165
+ *
1166
+ * All CIP-0103 network identifiers use CAIP-2 format: "namespace:reference"
1167
+ * e.g. "canton:da-mainnet", "canton:da-devnet"
1168
+ *
1169
+ * Reference: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
1170
+ */
1171
+
1172
+ declare const CANTON_NETWORKS: Record<string, string>;
1173
+ /**
1174
+ * Convert a legacy PartyLayer NetworkId (e.g. "devnet") or already-CAIP-2
1175
+ * string to a CIP-0103 Network object.
1176
+ *
1177
+ * @throws {Error} if the resulting network ID is not valid CAIP-2
1178
+ */
1179
+ declare function toCAIP2Network(networkId: string): CIP0103Network;
1180
+ /**
1181
+ * Extract the short network name from a CAIP-2 ID.
1182
+ * Returns the original string if no reverse mapping exists.
1183
+ */
1184
+ declare function fromCAIP2Network(caip2: string): string;
1185
+ /**
1186
+ * Validate that a string conforms to CAIP-2 format.
1187
+ *
1188
+ * CAIP-2 format: namespace:reference
1189
+ * - namespace: [-a-z0-9]{3,8}
1190
+ * - reference: [-_a-zA-Z0-9]{1,32}
1191
+ */
1192
+ declare function isValidCAIP2(networkId: string): boolean;
1193
+ /**
1194
+ * Detect a confident, recognized, DIFFERENT-network mismatch between an
1195
+ * `expected` (dApp-configured) and `actual` (wallet-reported) network.
1196
+ *
1197
+ * Conservative by design — returns `null` (no mismatch) unless BOTH networks
1198
+ * normalize to recognized well-known Canton CAIP-2 ids AND differ. Unparseable
1199
+ * or unrecognized/custom networks → `null` (never a false positive).
1200
+ */
1201
+ declare function detectNetworkMismatch(expected: string, actual: string): {
1202
+ expected: string;
1203
+ actual: string;
1204
+ } | null;
1205
+
1142
1206
  /**
1143
1207
  * Deep Link Transport
1144
1208
  *
@@ -1361,4 +1425,4 @@ interface Transport {
1361
1425
  disconnect(): Promise<void>;
1362
1426
  }
1363
1427
 
1364
- export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, type CIP0103Account, type CIP0103AccountStatus, type CIP0103ConnectResult, type CIP0103Event, type CIP0103EventListener, type CIP0103LedgerApiRequest, type CIP0103LedgerApiResponse, type CIP0103Method, type CIP0103Network, type CIP0103Provider, type CIP0103ProviderInfo, type CIP0103ProviderRpcError, type CIP0103ProviderType, type CIP0103RequestParams, type CIP0103RequestPayload, type CIP0103SignMessageRequest, type CIP0103StatusEvent, type CIP0103TxChangedEvent, type CIP0103TxExecutedPayload, type CIP0103TxFailedPayload, type CIP0103TxPendingPayload, type CIP0103TxSignedPayload, type CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, type CapabilityKey, CapabilityNotSupportedError, type Cip0103StatusForDetection, type Cip0103Support, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, ENABLEMENT_METRICS, ERROR_METRICS, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LedgerApiParams, type LedgerApiResult, type LoggerAdapter, METRICS, type MetricName, type MetricsPayload, MockTransport, type NetworkId, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, type ProviderDetection, type ProviderMatcher, REGISTRY_METRICS, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createMetricsPayload, createSession, deriveGenericWalletName, errorMetricName, findMatchingWallet, findMatchingWalletInfo, generateSessionId, hashForPrivacy, installGuard, isCip0103Native, isSessionExpired, mapUnknownErrorToPartyLayerError, matchesProviderDetection, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
1428
+ export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, CANTON_NETWORKS, type CIP0103Account, type CIP0103AccountStatus, type CIP0103ConnectResult, type CIP0103Event, type CIP0103EventListener, type CIP0103LedgerApiRequest, type CIP0103LedgerApiResponse, type CIP0103Method, type CIP0103Network, type CIP0103Provider, type CIP0103ProviderInfo, type CIP0103ProviderRpcError, type CIP0103ProviderType, type CIP0103RequestParams, type CIP0103RequestPayload, type CIP0103SignMessageRequest, type CIP0103StatusEvent, type CIP0103TxChangedEvent, type CIP0103TxExecutedPayload, type CIP0103TxFailedPayload, type CIP0103TxPendingPayload, type CIP0103TxSignedPayload, type CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, type CapabilityKey, CapabilityNotSupportedError, type Cip0103StatusForDetection, type Cip0103Support, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, ENABLEMENT_METRICS, ERROR_METRICS, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LedgerApiParams, type LedgerApiResult, type LoggerAdapter, METRICS, type MetricName, type MetricsPayload, MockTransport, type NetworkId, NetworkMismatchError, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, type ProviderDetection, type ProviderMatcher, REGISTRY_METRICS, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createMetricsPayload, createSession, deriveGenericWalletName, detectNetworkMismatch, errorMetricName, findMatchingWallet, findMatchingWalletInfo, fromCAIP2Network, generateSessionId, hashForPrivacy, installGuard, isCip0103Native, isSessionExpired, isValidCAIP2, mapUnknownErrorToPartyLayerError, matchesProviderDetection, toCAIP2Network, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
package/dist/index.d.ts CHANGED
@@ -193,6 +193,15 @@ interface Session {
193
193
  capabilitiesSnapshot: CapabilityKey[];
194
194
  /** Additional metadata (encrypted in storage) */
195
195
  metadata?: Record<string, string>;
196
+ /**
197
+ * Set when the wallet's reported network differs from the dApp's configured
198
+ * network (CAIP-2 normalized). Absent when the networks match or no confident
199
+ * mismatch was detected. See `networkEnforcement` for blocking behavior.
200
+ */
201
+ networkMismatch?: {
202
+ expected: string;
203
+ actual: string;
204
+ };
196
205
  }
197
206
  /**
198
207
  * Persisted session (for restoration)
@@ -292,7 +301,7 @@ declare function toSignature(sig: string): Signature;
292
301
  /**
293
302
  * Error code union - stable string literals for telemetry and UI
294
303
  */
295
- type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_INSTALLED' | 'USER_REJECTED' | 'ORIGIN_NOT_ALLOWED' | 'SESSION_EXPIRED' | 'CAPABILITY_NOT_SUPPORTED' | 'TRANSPORT_ERROR' | 'REGISTRY_FETCH_FAILED' | 'REGISTRY_VERIFICATION_FAILED' | 'REGISTRY_SCHEMA_INVALID' | 'INTERNAL_ERROR' | 'TIMEOUT';
304
+ type ErrorCode = 'WALLET_NOT_FOUND' | 'WALLET_NOT_INSTALLED' | 'USER_REJECTED' | 'ORIGIN_NOT_ALLOWED' | 'SESSION_EXPIRED' | 'CAPABILITY_NOT_SUPPORTED' | 'TRANSPORT_ERROR' | 'REGISTRY_FETCH_FAILED' | 'REGISTRY_VERIFICATION_FAILED' | 'REGISTRY_SCHEMA_INVALID' | 'INTERNAL_ERROR' | 'NETWORK_MISMATCH' | 'TIMEOUT';
296
305
  /**
297
306
  * Error mapping context
298
307
  */
@@ -356,6 +365,18 @@ declare class OriginNotAllowedError extends PartyLayerError {
356
365
  declare class SessionExpiredError extends PartyLayerError {
357
366
  constructor(sessionId: string);
358
367
  }
368
+ /**
369
+ * Network mismatch error — the connected wallet's effective network differs
370
+ * from the dApp's configured network. Thrown to block wrong-network connects
371
+ * (policy 'strict') and wrong-network transactions (policy 'guard' | 'strict').
372
+ */
373
+ declare class NetworkMismatchError extends PartyLayerError {
374
+ /** The dApp's configured (expected) network, CAIP-2 normalized. */
375
+ readonly expected: string;
376
+ /** The wallet's reported (actual) network, CAIP-2 normalized. */
377
+ readonly actual: string;
378
+ constructor(expected: string, actual: string);
379
+ }
359
380
  /**
360
381
  * Capability not supported error
361
382
  */
@@ -1139,6 +1160,49 @@ declare const CIP0103_EVENTS: {
1139
1160
  };
1140
1161
  type CIP0103Event = (typeof CIP0103_EVENTS)[keyof typeof CIP0103_EVENTS];
1141
1162
 
1163
+ /**
1164
+ * CAIP-2 Network Identity Utilities
1165
+ *
1166
+ * All CIP-0103 network identifiers use CAIP-2 format: "namespace:reference"
1167
+ * e.g. "canton:da-mainnet", "canton:da-devnet"
1168
+ *
1169
+ * Reference: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
1170
+ */
1171
+
1172
+ declare const CANTON_NETWORKS: Record<string, string>;
1173
+ /**
1174
+ * Convert a legacy PartyLayer NetworkId (e.g. "devnet") or already-CAIP-2
1175
+ * string to a CIP-0103 Network object.
1176
+ *
1177
+ * @throws {Error} if the resulting network ID is not valid CAIP-2
1178
+ */
1179
+ declare function toCAIP2Network(networkId: string): CIP0103Network;
1180
+ /**
1181
+ * Extract the short network name from a CAIP-2 ID.
1182
+ * Returns the original string if no reverse mapping exists.
1183
+ */
1184
+ declare function fromCAIP2Network(caip2: string): string;
1185
+ /**
1186
+ * Validate that a string conforms to CAIP-2 format.
1187
+ *
1188
+ * CAIP-2 format: namespace:reference
1189
+ * - namespace: [-a-z0-9]{3,8}
1190
+ * - reference: [-_a-zA-Z0-9]{1,32}
1191
+ */
1192
+ declare function isValidCAIP2(networkId: string): boolean;
1193
+ /**
1194
+ * Detect a confident, recognized, DIFFERENT-network mismatch between an
1195
+ * `expected` (dApp-configured) and `actual` (wallet-reported) network.
1196
+ *
1197
+ * Conservative by design — returns `null` (no mismatch) unless BOTH networks
1198
+ * normalize to recognized well-known Canton CAIP-2 ids AND differ. Unparseable
1199
+ * or unrecognized/custom networks → `null` (never a false positive).
1200
+ */
1201
+ declare function detectNetworkMismatch(expected: string, actual: string): {
1202
+ expected: string;
1203
+ actual: string;
1204
+ } | null;
1205
+
1142
1206
  /**
1143
1207
  * Deep Link Transport
1144
1208
  *
@@ -1361,4 +1425,4 @@ interface Transport {
1361
1425
  disconnect(): Promise<void>;
1362
1426
  }
1363
1427
 
1364
- export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, type CIP0103Account, type CIP0103AccountStatus, type CIP0103ConnectResult, type CIP0103Event, type CIP0103EventListener, type CIP0103LedgerApiRequest, type CIP0103LedgerApiResponse, type CIP0103Method, type CIP0103Network, type CIP0103Provider, type CIP0103ProviderInfo, type CIP0103ProviderRpcError, type CIP0103ProviderType, type CIP0103RequestParams, type CIP0103RequestPayload, type CIP0103SignMessageRequest, type CIP0103StatusEvent, type CIP0103TxChangedEvent, type CIP0103TxExecutedPayload, type CIP0103TxFailedPayload, type CIP0103TxPendingPayload, type CIP0103TxSignedPayload, type CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, type CapabilityKey, CapabilityNotSupportedError, type Cip0103StatusForDetection, type Cip0103Support, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, ENABLEMENT_METRICS, ERROR_METRICS, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LedgerApiParams, type LedgerApiResult, type LoggerAdapter, METRICS, type MetricName, type MetricsPayload, MockTransport, type NetworkId, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, type ProviderDetection, type ProviderMatcher, REGISTRY_METRICS, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createMetricsPayload, createSession, deriveGenericWalletName, errorMetricName, findMatchingWallet, findMatchingWalletInfo, generateSessionId, hashForPrivacy, installGuard, isCip0103Native, isSessionExpired, mapUnknownErrorToPartyLayerError, matchesProviderDetection, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
1428
+ export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, CANTON_NETWORKS, type CIP0103Account, type CIP0103AccountStatus, type CIP0103ConnectResult, type CIP0103Event, type CIP0103EventListener, type CIP0103LedgerApiRequest, type CIP0103LedgerApiResponse, type CIP0103Method, type CIP0103Network, type CIP0103Provider, type CIP0103ProviderInfo, type CIP0103ProviderRpcError, type CIP0103ProviderType, type CIP0103RequestParams, type CIP0103RequestPayload, type CIP0103SignMessageRequest, type CIP0103StatusEvent, type CIP0103TxChangedEvent, type CIP0103TxExecutedPayload, type CIP0103TxFailedPayload, type CIP0103TxPendingPayload, type CIP0103TxSignedPayload, type CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, type CapabilityKey, CapabilityNotSupportedError, type Cip0103StatusForDetection, type Cip0103Support, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, ENABLEMENT_METRICS, ERROR_METRICS, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LedgerApiParams, type LedgerApiResult, type LoggerAdapter, METRICS, type MetricName, type MetricsPayload, MockTransport, type NetworkId, NetworkMismatchError, OriginNotAllowedError, type PartyId, PartyLayerError, type PersistedSession, PopupTransport, PostMessageTransport, type ProviderDetection, type ProviderMatcher, REGISTRY_METRICS, type RegistryClientAdapter, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, type Session, SessionExpiredError, type SessionId, type SignMessageParams, type SignRequest, type SignResponse, type SignTransactionParams, type Signature, type SignedMessage, type SignedTransaction, type StorageAdapter, type SubmitTransactionParams, type TelemetryAdapter, TimeoutError, type TransactionHash, type TransactionStatus, type Transport, TransportError, type TransportOptions, type TransportType, type TxReceipt, type TxStatusUpdate, UserRejectedError, type WalletAdapter, type WalletId, type WalletInfo, WalletNotFoundError, WalletNotInstalledError, capabilityGuard, createMetricsPayload, createSession, deriveGenericWalletName, detectNetworkMismatch, errorMetricName, findMatchingWallet, findMatchingWalletInfo, fromCAIP2Network, generateSessionId, hashForPrivacy, installGuard, isCip0103Native, isSessionExpired, isValidCAIP2, mapUnknownErrorToPartyLayerError, matchesProviderDetection, toCAIP2Network, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
package/dist/index.js CHANGED
@@ -103,6 +103,22 @@ var SessionExpiredError = class extends PartyLayerError {
103
103
  this.name = "SessionExpiredError";
104
104
  }
105
105
  };
106
+ var NetworkMismatchError = class extends PartyLayerError {
107
+ /** The dApp's configured (expected) network, CAIP-2 normalized. */
108
+ expected;
109
+ /** The wallet's reported (actual) network, CAIP-2 normalized. */
110
+ actual;
111
+ constructor(expected, actual) {
112
+ super(
113
+ `Wallet is on network "${actual}" but this app requires "${expected}". Switch your wallet's network, then reconnect.`,
114
+ "NETWORK_MISMATCH",
115
+ { details: { expected, actual } }
116
+ );
117
+ this.name = "NetworkMismatchError";
118
+ this.expected = expected;
119
+ this.actual = actual;
120
+ }
121
+ };
106
122
  var CapabilityNotSupportedError = class extends PartyLayerError {
107
123
  constructor(walletId, capability) {
108
124
  super(
@@ -493,6 +509,54 @@ var CIP0103_EVENTS = {
493
509
  CONNECTED: "connected"
494
510
  };
495
511
 
512
+ // src/network.ts
513
+ var CANTON_NETWORKS = {
514
+ mainnet: "canton:da-mainnet",
515
+ testnet: "canton:da-testnet",
516
+ devnet: "canton:da-devnet",
517
+ local: "canton:da-local"
518
+ };
519
+ var CAIP2_TO_SHORT = Object.fromEntries(
520
+ Object.entries(CANTON_NETWORKS).map(([short, full]) => [full, short])
521
+ );
522
+ function toCAIP2Network(networkId) {
523
+ let result;
524
+ if (networkId.includes(":")) {
525
+ result = networkId;
526
+ } else {
527
+ const caip2 = CANTON_NETWORKS[networkId];
528
+ result = caip2 ?? `canton:${networkId}`;
529
+ }
530
+ if (!isValidCAIP2(result)) {
531
+ throw new Error(
532
+ `Invalid CAIP-2 network identifier: "${result}". Expected format: "namespace:reference"`
533
+ );
534
+ }
535
+ return { networkId: result };
536
+ }
537
+ function fromCAIP2Network(caip2) {
538
+ const short = CAIP2_TO_SHORT[caip2];
539
+ if (short) return short;
540
+ const colonIndex = caip2.indexOf(":");
541
+ return colonIndex >= 0 ? caip2.slice(colonIndex + 1) : caip2;
542
+ }
543
+ function isValidCAIP2(networkId) {
544
+ return /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/.test(networkId);
545
+ }
546
+ var KNOWN_CAIP2 = new Set(Object.values(CANTON_NETWORKS));
547
+ function detectNetworkMismatch(expected, actual) {
548
+ let ne;
549
+ let na;
550
+ try {
551
+ ne = toCAIP2Network(expected).networkId;
552
+ na = toCAIP2Network(actual).networkId;
553
+ } catch {
554
+ return null;
555
+ }
556
+ if (!KNOWN_CAIP2.has(ne) || !KNOWN_CAIP2.has(na)) return null;
557
+ return ne === na ? null : { expected: ne, actual: na };
558
+ }
559
+
496
560
  // src/transport/deeplink.ts
497
561
  var DeepLinkTransport = class {
498
562
  /**
@@ -971,6 +1035,7 @@ var MockTransport = class {
971
1035
  }
972
1036
  };
973
1037
 
1038
+ exports.CANTON_NETWORKS = CANTON_NETWORKS;
974
1039
  exports.CIP0103_EVENTS = CIP0103_EVENTS;
975
1040
  exports.CIP0103_MANDATORY_METHODS = CIP0103_MANDATORY_METHODS;
976
1041
  exports.CIP0103_METHODS = CIP0103_METHODS;
@@ -981,6 +1046,7 @@ exports.ERROR_METRICS = ERROR_METRICS;
981
1046
  exports.InternalError = InternalError;
982
1047
  exports.METRICS = METRICS;
983
1048
  exports.MockTransport = MockTransport;
1049
+ exports.NetworkMismatchError = NetworkMismatchError;
984
1050
  exports.OriginNotAllowedError = OriginNotAllowedError;
985
1051
  exports.PartyLayerError = PartyLayerError;
986
1052
  exports.PopupTransport = PopupTransport;
@@ -999,16 +1065,20 @@ exports.capabilityGuard = capabilityGuard;
999
1065
  exports.createMetricsPayload = createMetricsPayload;
1000
1066
  exports.createSession = createSession;
1001
1067
  exports.deriveGenericWalletName = deriveGenericWalletName;
1068
+ exports.detectNetworkMismatch = detectNetworkMismatch;
1002
1069
  exports.errorMetricName = errorMetricName;
1003
1070
  exports.findMatchingWallet = findMatchingWallet;
1004
1071
  exports.findMatchingWalletInfo = findMatchingWalletInfo;
1072
+ exports.fromCAIP2Network = fromCAIP2Network;
1005
1073
  exports.generateSessionId = generateSessionId;
1006
1074
  exports.hashForPrivacy = hashForPrivacy;
1007
1075
  exports.installGuard = installGuard;
1008
1076
  exports.isCip0103Native = isCip0103Native;
1009
1077
  exports.isSessionExpired = isSessionExpired;
1078
+ exports.isValidCAIP2 = isValidCAIP2;
1010
1079
  exports.mapUnknownErrorToPartyLayerError = mapUnknownErrorToPartyLayerError;
1011
1080
  exports.matchesProviderDetection = matchesProviderDetection;
1081
+ exports.toCAIP2Network = toCAIP2Network;
1012
1082
  exports.toPartyId = toPartyId;
1013
1083
  exports.toSessionId = toSessionId;
1014
1084
  exports.toSignature = toSignature;