@partylayer/core 0.2.6 → 0.3.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
@@ -57,6 +57,62 @@ interface AdapterMetadata {
57
57
  /** Version range (semver) */
58
58
  versionRange: string;
59
59
  }
60
+ /**
61
+ * Provider matcher: a single rule used by `ProviderDetection.matchers`.
62
+ *
63
+ * Three match modes are defined; OR-combined inside a `ProviderDetection`.
64
+ * Exact and prefix work on string fields directly; domain interprets the
65
+ * field as a URL and tests its hostname against the registrable domain
66
+ * (with subdomain support).
67
+ */
68
+ type ProviderMatcher = {
69
+ field: 'kernel.url' | 'kernel.userUrl';
70
+ match: 'domain';
71
+ /** Hostname or registrable domain. Subdomains are accepted. */
72
+ value: string;
73
+ } | {
74
+ field: 'kernel.id' | 'kernel.url' | 'kernel.userUrl' | 'kernel.clientType';
75
+ match: 'exact';
76
+ /** One or more exact values; ANY match returns true. */
77
+ values: string[];
78
+ } | {
79
+ field: 'kernel.id' | 'kernel.url' | 'kernel.userUrl';
80
+ match: 'prefix';
81
+ value: string;
82
+ };
83
+ /**
84
+ * Standards-first runtime detection of a CIP-0103 wallet.
85
+ *
86
+ * The registry stores these rules so that any current or future wallet
87
+ * implementing `window.canton` can be identified without code changes —
88
+ * a registry JSON update is enough.
89
+ */
90
+ interface ProviderDetection {
91
+ /** Transport mechanism. Currently only 'window.canton' is supported. */
92
+ transport: 'window.canton';
93
+ /** OR-list of matchers. Provider matches if ANY matcher returns true. */
94
+ matchers: ProviderMatcher[];
95
+ }
96
+ /**
97
+ * Canonical CIP-0103 support marker.
98
+ *
99
+ * When `native: true`, the wallet is treated as a first-class CIP-0103
100
+ * provider in the picker — it always appears in the "CIP-0103 NATIVE"
101
+ * section regardless of install state, with a per-wallet readiness
102
+ * indicator that reflects whether the wallet's `providerDetection` rules
103
+ * matched the currently-injected `window.canton` provider.
104
+ *
105
+ * The field is optional; wallets that don't claim CIP-0103 support omit
106
+ * it and continue to appear in the "AVAILABLE" section as before.
107
+ */
108
+ interface Cip0103Support {
109
+ /** True if this wallet has confirmed CIP-0103 dApp API support. */
110
+ native: boolean;
111
+ /** Public evidence link (npm package, blog post, official statement). */
112
+ evidence?: string;
113
+ /** ISO date when CIP-0103 support was confirmed (informational). */
114
+ since?: string;
115
+ }
60
116
  /**
61
117
  * Wallet information from registry
62
118
  */
@@ -91,7 +147,29 @@ interface WalletInfo {
91
147
  channel: 'stable' | 'beta';
92
148
  /** Additional metadata (e.g., originAllowlist) */
93
149
  metadata?: Record<string, string>;
150
+ /**
151
+ * Optional CIP-0103 runtime detection rules. When present, the picker can
152
+ * decide whether this wallet is the currently-injected `window.canton`
153
+ * provider and route it into the "CIP-0103 Native" section without any
154
+ * hardcoded wallet IDs. Wallets that aren't CIP-0103-injected (e.g. Bron,
155
+ * Cantor8 deeplink) leave this unset.
156
+ */
157
+ providerDetection?: ProviderDetection;
158
+ /**
159
+ * Canonical CIP-0103 support marker. When set with `native: true`, the
160
+ * picker always lists the wallet in the "CIP-0103 NATIVE" section
161
+ * regardless of install state.
162
+ */
163
+ cip0103?: Cip0103Support;
94
164
  }
165
+ /**
166
+ * Returns true if the wallet has been canonically marked as CIP-0103
167
+ * native via its registry entry. The check is structural so it works on
168
+ * both raw `RegistryWalletEntry` shapes and converted `WalletInfo`.
169
+ */
170
+ declare function isCip0103Native(entry: {
171
+ cip0103?: Cip0103Support;
172
+ }): boolean;
95
173
  /**
96
174
  * Session information
97
175
  * Sessions are origin-bound and encrypted in storage
@@ -395,7 +473,7 @@ interface SubmitTransactionParams {
395
473
  interface LedgerApiParams {
396
474
  /** HTTP method for the JSON Ledger API */
397
475
  requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
398
- /** Resource path (e.g., "/v1/state/acs") */
476
+ /** Resource path (e.g., "/v2/state/acs") */
399
477
  resource: string;
400
478
  /** Optional JSON body */
401
479
  body?: string;
@@ -533,6 +611,8 @@ interface WalletAdapter {
533
611
  connect(ctx: AdapterContext, opts?: {
534
612
  timeoutMs?: number;
535
613
  partyId?: PartyId;
614
+ /** When false, prefer remote/mobile transport over installed extension */
615
+ preferInstalled?: boolean;
536
616
  }): Promise<AdapterConnectResult>;
537
617
  /**
538
618
  * Disconnect from wallet
@@ -614,6 +694,62 @@ declare function isSessionExpired(session: Session): boolean;
614
694
  */
615
695
  declare function createSession(walletId: string, partyId: string, network: string, origin: string, capabilities?: string[], expiresInMs?: number): Session;
616
696
 
697
+ /**
698
+ * Standards-first CIP-0103 wallet detection.
699
+ *
700
+ * The registry stores `providerDetection` rules per wallet entry. At
701
+ * runtime the picker calls `window.canton.request({method:'status'})`,
702
+ * receives the wallet's self-reported identity (kernel.id / kernel.url /
703
+ * kernel.userUrl / kernel.clientType), and asks `findMatchingWallet`
704
+ * which registry entry — if any — claims this provider.
705
+ *
706
+ * The architecture deliberately avoids hardcoding wallet IDs anywhere
707
+ * outside the registry. Adding a new CIP-0103 wallet to the ecosystem
708
+ * is a registry JSON update; no SDK release is required.
709
+ */
710
+
711
+ /**
712
+ * The shape of a CIP-0103 status response that detection cares about.
713
+ *
714
+ * Mirrors what `window.canton.request({ method: 'status' })` returns —
715
+ * declared structurally so adapter packages can reuse this without
716
+ * reaching into the wallet-specific types.
717
+ */
718
+ interface Cip0103StatusForDetection {
719
+ kernel?: {
720
+ id?: string;
721
+ url?: string;
722
+ userUrl?: string;
723
+ clientType?: string;
724
+ };
725
+ }
726
+ /** Returns true if the runtime status matches any of the detection's matchers. */
727
+ declare function matchesProviderDetection(status: Cip0103StatusForDetection | null | undefined, detection: ProviderDetection | undefined): boolean;
728
+ /**
729
+ * Find the first registry entry whose `providerDetection` matches the
730
+ * runtime status. Entries without `providerDetection` are skipped.
731
+ *
732
+ * Accepts either the raw `RegistryWalletEntry[]` shape (registry-client's
733
+ * native input) or the converted `WalletInfo[]` shape that flows through
734
+ * the SDK / React layer — the only field read is `providerDetection`,
735
+ * which both shapes carry post-conversion.
736
+ */
737
+ declare function findMatchingWallet<T extends {
738
+ providerDetection?: ProviderDetection;
739
+ }>(status: Cip0103StatusForDetection | null | undefined, registry: readonly T[]): T | undefined;
740
+ /**
741
+ * Type-guard convenience for the WalletInfo shape, since the SDK exposes
742
+ * `WalletInfo[]` to React consumers.
743
+ */
744
+ declare function findMatchingWalletInfo(status: Cip0103StatusForDetection | null | undefined, wallets: readonly WalletInfo[]): WalletInfo | undefined;
745
+ /**
746
+ * Best-effort display name for an unrecognised CIP-0103 provider. Reads
747
+ * the wallet's self-declared `kernel.userUrl` (the human-facing URL
748
+ * surfaced by Sigilry-style wallets) and falls back to `kernel.id` or
749
+ * a generic label.
750
+ */
751
+ declare function deriveGenericWalletName(status: Cip0103StatusForDetection | null | undefined): string;
752
+
617
753
  /**
618
754
  * Transport layer types for wallet communication
619
755
  *
@@ -1218,4 +1354,4 @@ interface Transport {
1218
1354
  disconnect(): Promise<void>;
1219
1355
  }
1220
1356
 
1221
- 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 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, 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, errorMetricName, generateSessionId, hashForPrivacy, installGuard, isSessionExpired, mapUnknownErrorToPartyLayerError, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
1357
+ 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 };
package/dist/index.d.ts CHANGED
@@ -57,6 +57,62 @@ interface AdapterMetadata {
57
57
  /** Version range (semver) */
58
58
  versionRange: string;
59
59
  }
60
+ /**
61
+ * Provider matcher: a single rule used by `ProviderDetection.matchers`.
62
+ *
63
+ * Three match modes are defined; OR-combined inside a `ProviderDetection`.
64
+ * Exact and prefix work on string fields directly; domain interprets the
65
+ * field as a URL and tests its hostname against the registrable domain
66
+ * (with subdomain support).
67
+ */
68
+ type ProviderMatcher = {
69
+ field: 'kernel.url' | 'kernel.userUrl';
70
+ match: 'domain';
71
+ /** Hostname or registrable domain. Subdomains are accepted. */
72
+ value: string;
73
+ } | {
74
+ field: 'kernel.id' | 'kernel.url' | 'kernel.userUrl' | 'kernel.clientType';
75
+ match: 'exact';
76
+ /** One or more exact values; ANY match returns true. */
77
+ values: string[];
78
+ } | {
79
+ field: 'kernel.id' | 'kernel.url' | 'kernel.userUrl';
80
+ match: 'prefix';
81
+ value: string;
82
+ };
83
+ /**
84
+ * Standards-first runtime detection of a CIP-0103 wallet.
85
+ *
86
+ * The registry stores these rules so that any current or future wallet
87
+ * implementing `window.canton` can be identified without code changes —
88
+ * a registry JSON update is enough.
89
+ */
90
+ interface ProviderDetection {
91
+ /** Transport mechanism. Currently only 'window.canton' is supported. */
92
+ transport: 'window.canton';
93
+ /** OR-list of matchers. Provider matches if ANY matcher returns true. */
94
+ matchers: ProviderMatcher[];
95
+ }
96
+ /**
97
+ * Canonical CIP-0103 support marker.
98
+ *
99
+ * When `native: true`, the wallet is treated as a first-class CIP-0103
100
+ * provider in the picker — it always appears in the "CIP-0103 NATIVE"
101
+ * section regardless of install state, with a per-wallet readiness
102
+ * indicator that reflects whether the wallet's `providerDetection` rules
103
+ * matched the currently-injected `window.canton` provider.
104
+ *
105
+ * The field is optional; wallets that don't claim CIP-0103 support omit
106
+ * it and continue to appear in the "AVAILABLE" section as before.
107
+ */
108
+ interface Cip0103Support {
109
+ /** True if this wallet has confirmed CIP-0103 dApp API support. */
110
+ native: boolean;
111
+ /** Public evidence link (npm package, blog post, official statement). */
112
+ evidence?: string;
113
+ /** ISO date when CIP-0103 support was confirmed (informational). */
114
+ since?: string;
115
+ }
60
116
  /**
61
117
  * Wallet information from registry
62
118
  */
@@ -91,7 +147,29 @@ interface WalletInfo {
91
147
  channel: 'stable' | 'beta';
92
148
  /** Additional metadata (e.g., originAllowlist) */
93
149
  metadata?: Record<string, string>;
150
+ /**
151
+ * Optional CIP-0103 runtime detection rules. When present, the picker can
152
+ * decide whether this wallet is the currently-injected `window.canton`
153
+ * provider and route it into the "CIP-0103 Native" section without any
154
+ * hardcoded wallet IDs. Wallets that aren't CIP-0103-injected (e.g. Bron,
155
+ * Cantor8 deeplink) leave this unset.
156
+ */
157
+ providerDetection?: ProviderDetection;
158
+ /**
159
+ * Canonical CIP-0103 support marker. When set with `native: true`, the
160
+ * picker always lists the wallet in the "CIP-0103 NATIVE" section
161
+ * regardless of install state.
162
+ */
163
+ cip0103?: Cip0103Support;
94
164
  }
165
+ /**
166
+ * Returns true if the wallet has been canonically marked as CIP-0103
167
+ * native via its registry entry. The check is structural so it works on
168
+ * both raw `RegistryWalletEntry` shapes and converted `WalletInfo`.
169
+ */
170
+ declare function isCip0103Native(entry: {
171
+ cip0103?: Cip0103Support;
172
+ }): boolean;
95
173
  /**
96
174
  * Session information
97
175
  * Sessions are origin-bound and encrypted in storage
@@ -395,7 +473,7 @@ interface SubmitTransactionParams {
395
473
  interface LedgerApiParams {
396
474
  /** HTTP method for the JSON Ledger API */
397
475
  requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';
398
- /** Resource path (e.g., "/v1/state/acs") */
476
+ /** Resource path (e.g., "/v2/state/acs") */
399
477
  resource: string;
400
478
  /** Optional JSON body */
401
479
  body?: string;
@@ -533,6 +611,8 @@ interface WalletAdapter {
533
611
  connect(ctx: AdapterContext, opts?: {
534
612
  timeoutMs?: number;
535
613
  partyId?: PartyId;
614
+ /** When false, prefer remote/mobile transport over installed extension */
615
+ preferInstalled?: boolean;
536
616
  }): Promise<AdapterConnectResult>;
537
617
  /**
538
618
  * Disconnect from wallet
@@ -614,6 +694,62 @@ declare function isSessionExpired(session: Session): boolean;
614
694
  */
615
695
  declare function createSession(walletId: string, partyId: string, network: string, origin: string, capabilities?: string[], expiresInMs?: number): Session;
616
696
 
697
+ /**
698
+ * Standards-first CIP-0103 wallet detection.
699
+ *
700
+ * The registry stores `providerDetection` rules per wallet entry. At
701
+ * runtime the picker calls `window.canton.request({method:'status'})`,
702
+ * receives the wallet's self-reported identity (kernel.id / kernel.url /
703
+ * kernel.userUrl / kernel.clientType), and asks `findMatchingWallet`
704
+ * which registry entry — if any — claims this provider.
705
+ *
706
+ * The architecture deliberately avoids hardcoding wallet IDs anywhere
707
+ * outside the registry. Adding a new CIP-0103 wallet to the ecosystem
708
+ * is a registry JSON update; no SDK release is required.
709
+ */
710
+
711
+ /**
712
+ * The shape of a CIP-0103 status response that detection cares about.
713
+ *
714
+ * Mirrors what `window.canton.request({ method: 'status' })` returns —
715
+ * declared structurally so adapter packages can reuse this without
716
+ * reaching into the wallet-specific types.
717
+ */
718
+ interface Cip0103StatusForDetection {
719
+ kernel?: {
720
+ id?: string;
721
+ url?: string;
722
+ userUrl?: string;
723
+ clientType?: string;
724
+ };
725
+ }
726
+ /** Returns true if the runtime status matches any of the detection's matchers. */
727
+ declare function matchesProviderDetection(status: Cip0103StatusForDetection | null | undefined, detection: ProviderDetection | undefined): boolean;
728
+ /**
729
+ * Find the first registry entry whose `providerDetection` matches the
730
+ * runtime status. Entries without `providerDetection` are skipped.
731
+ *
732
+ * Accepts either the raw `RegistryWalletEntry[]` shape (registry-client's
733
+ * native input) or the converted `WalletInfo[]` shape that flows through
734
+ * the SDK / React layer — the only field read is `providerDetection`,
735
+ * which both shapes carry post-conversion.
736
+ */
737
+ declare function findMatchingWallet<T extends {
738
+ providerDetection?: ProviderDetection;
739
+ }>(status: Cip0103StatusForDetection | null | undefined, registry: readonly T[]): T | undefined;
740
+ /**
741
+ * Type-guard convenience for the WalletInfo shape, since the SDK exposes
742
+ * `WalletInfo[]` to React consumers.
743
+ */
744
+ declare function findMatchingWalletInfo(status: Cip0103StatusForDetection | null | undefined, wallets: readonly WalletInfo[]): WalletInfo | undefined;
745
+ /**
746
+ * Best-effort display name for an unrecognised CIP-0103 provider. Reads
747
+ * the wallet's self-declared `kernel.userUrl` (the human-facing URL
748
+ * surfaced by Sigilry-style wallets) and falls back to `kernel.id` or
749
+ * a generic label.
750
+ */
751
+ declare function deriveGenericWalletName(status: Cip0103StatusForDetection | null | undefined): string;
752
+
617
753
  /**
618
754
  * Transport layer types for wallet communication
619
755
  *
@@ -1218,4 +1354,4 @@ interface Transport {
1218
1354
  disconnect(): Promise<void>;
1219
1355
  }
1220
1356
 
1221
- 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 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, 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, errorMetricName, generateSessionId, hashForPrivacy, installGuard, isSessionExpired, mapUnknownErrorToPartyLayerError, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validatePayload, validateSession };
1357
+ 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 };
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  // src/types.ts
4
+ function isCip0103Native(entry) {
5
+ return entry?.cip0103?.native === true;
6
+ }
4
7
  function toWalletId(id) {
5
8
  return id;
6
9
  }
@@ -275,6 +278,71 @@ function createSession(walletId, partyId, network, origin, capabilities = [], ex
275
278
  };
276
279
  }
277
280
 
281
+ // src/detection.ts
282
+ function matchesProviderDetection(status, detection) {
283
+ if (!status || !detection || !detection.matchers || detection.matchers.length === 0) {
284
+ return false;
285
+ }
286
+ return detection.matchers.some((m) => matchesSingle(status, m));
287
+ }
288
+ function matchesSingle(status, matcher) {
289
+ const fieldValue = readField(status, matcher.field);
290
+ if (typeof fieldValue !== "string" || fieldValue.length === 0) return false;
291
+ switch (matcher.match) {
292
+ case "exact":
293
+ return matcher.values.includes(fieldValue);
294
+ case "prefix":
295
+ return fieldValue.startsWith(matcher.value);
296
+ case "domain":
297
+ return matchesDomain(fieldValue, matcher.value);
298
+ default:
299
+ return false;
300
+ }
301
+ }
302
+ function readField(status, field) {
303
+ const dot = field.indexOf(".");
304
+ if (dot < 0) return void 0;
305
+ const root = field.slice(0, dot);
306
+ const key = field.slice(dot + 1);
307
+ if (root !== "kernel" || !status.kernel) return void 0;
308
+ return status.kernel[key];
309
+ }
310
+ function matchesDomain(url, domain) {
311
+ try {
312
+ const hostname = new URL(url).hostname.toLowerCase();
313
+ const target = domain.toLowerCase();
314
+ return hostname === target || hostname.endsWith("." + target);
315
+ } catch {
316
+ return false;
317
+ }
318
+ }
319
+ function findMatchingWallet(status, registry) {
320
+ if (!status) return void 0;
321
+ for (const entry of registry) {
322
+ if (matchesProviderDetection(status, entry.providerDetection)) {
323
+ return entry;
324
+ }
325
+ }
326
+ return void 0;
327
+ }
328
+ function findMatchingWalletInfo(status, wallets) {
329
+ return findMatchingWallet(status, wallets);
330
+ }
331
+ function deriveGenericWalletName(status) {
332
+ const userUrl = status?.kernel?.userUrl;
333
+ if (typeof userUrl === "string" && userUrl.length > 0) {
334
+ try {
335
+ return new URL(userUrl).hostname.replace(/^www\./, "");
336
+ } catch {
337
+ }
338
+ }
339
+ const id = status?.kernel?.id;
340
+ if (typeof id === "string" && id.length > 0) {
341
+ return `CIP-0103 wallet (${id.slice(0, 8)}\u2026)`;
342
+ }
343
+ return "CIP-0103 wallet";
344
+ }
345
+
278
346
  // src/metrics.ts
279
347
  var ENABLEMENT_METRICS = {
280
348
  /** Total wallet connect() calls made */
@@ -927,12 +995,17 @@ exports.WalletNotInstalledError = WalletNotInstalledError;
927
995
  exports.capabilityGuard = capabilityGuard;
928
996
  exports.createMetricsPayload = createMetricsPayload;
929
997
  exports.createSession = createSession;
998
+ exports.deriveGenericWalletName = deriveGenericWalletName;
930
999
  exports.errorMetricName = errorMetricName;
1000
+ exports.findMatchingWallet = findMatchingWallet;
1001
+ exports.findMatchingWalletInfo = findMatchingWalletInfo;
931
1002
  exports.generateSessionId = generateSessionId;
932
1003
  exports.hashForPrivacy = hashForPrivacy;
933
1004
  exports.installGuard = installGuard;
1005
+ exports.isCip0103Native = isCip0103Native;
934
1006
  exports.isSessionExpired = isSessionExpired;
935
1007
  exports.mapUnknownErrorToPartyLayerError = mapUnknownErrorToPartyLayerError;
1008
+ exports.matchesProviderDetection = matchesProviderDetection;
936
1009
  exports.toPartyId = toPartyId;
937
1010
  exports.toSessionId = toSessionId;
938
1011
  exports.toSignature = toSignature;