@cantonconnect/core 0.2.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.
@@ -0,0 +1,885 @@
1
+ /**
2
+ * Core types for CantonConnect SDK
3
+ *
4
+ * References:
5
+ * - Wallet Integration Guide: https://docs.digitalasset.com/integrate/devnet/index.html
6
+ * - Signing transactions from dApps: https://docs.digitalasset.com/integrate/devnet/signing-transactions-from-dapps/index.html
7
+ * - OpenRPC dApp API spec: https://github.com/hyperledger-labs/splice-wallet-kernel/blob/main/api-specs/openrpc-dapp-api.json
8
+ */
9
+ /**
10
+ * Branded string types for type safety
11
+ */
12
+ type WalletId = string & {
13
+ readonly __brand: 'WalletId';
14
+ };
15
+ type PartyId = string & {
16
+ readonly __brand: 'PartyId';
17
+ };
18
+ type SessionId = string & {
19
+ readonly __brand: 'SessionId';
20
+ };
21
+ type TransactionHash = string & {
22
+ readonly __brand: 'TransactionHash';
23
+ };
24
+ type Signature = string & {
25
+ readonly __brand: 'Signature';
26
+ };
27
+ /**
28
+ * Network identifier
29
+ * Standard networks: "devnet" | "testnet" | "mainnet"
30
+ * Custom networks allowed as string
31
+ */
32
+ type NetworkId = 'devnet' | 'testnet' | 'mainnet' | string;
33
+ /**
34
+ * Capability keys that wallets can support
35
+ * Based on OpenRPC dApp API capabilities
36
+ */
37
+ type CapabilityKey = 'connect' | 'disconnect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction' | 'events' | 'deeplink' | 'popup' | 'injected' | 'remoteSigner';
38
+ /**
39
+ * Wallet installation hints for detection
40
+ */
41
+ interface InstallHints {
42
+ /** Window property name (e.g., "consoleWallet") */
43
+ injectedKey?: string;
44
+ /** Browser extension ID */
45
+ extensionId?: string;
46
+ /** Deep link scheme (e.g., "loop://") */
47
+ deepLinkScheme?: string;
48
+ /** Script tag identifier */
49
+ scriptTag?: string;
50
+ }
51
+ /**
52
+ * Wallet adapter metadata
53
+ */
54
+ interface AdapterMetadata {
55
+ /** NPM package name */
56
+ packageName: string;
57
+ /** Version range (semver) */
58
+ versionRange: string;
59
+ }
60
+ /**
61
+ * Wallet information from registry
62
+ */
63
+ interface WalletInfo {
64
+ /** Wallet identifier */
65
+ walletId: WalletId;
66
+ /** Display name */
67
+ name: string;
68
+ /** Website URL */
69
+ website: string;
70
+ /** Icon URLs (different sizes) */
71
+ icons: {
72
+ sm?: string;
73
+ md?: string;
74
+ lg?: string;
75
+ };
76
+ /** Category (e.g., "browser", "mobile", "hardware") */
77
+ category?: string;
78
+ /** Supported capabilities */
79
+ capabilities: CapabilityKey[];
80
+ /** Installation detection hints */
81
+ installHints?: InstallHints;
82
+ /** Adapter package information */
83
+ adapter: AdapterMetadata;
84
+ /** Documentation URLs */
85
+ docs: string[];
86
+ /** Minimum SDK version required */
87
+ minSdkVersion?: string;
88
+ /** Supported networks */
89
+ networks: NetworkId[];
90
+ /** Registry channel */
91
+ channel: 'stable' | 'beta';
92
+ /** Additional metadata (e.g., originAllowlist) */
93
+ metadata?: Record<string, string>;
94
+ }
95
+ /**
96
+ * Session information
97
+ * Sessions are origin-bound and encrypted in storage
98
+ */
99
+ interface Session {
100
+ /** Unique session ID */
101
+ sessionId: SessionId;
102
+ /** Wallet identifier */
103
+ walletId: WalletId;
104
+ /** Connected party ID */
105
+ partyId: PartyId;
106
+ /** Current network */
107
+ network: NetworkId;
108
+ /** Session creation timestamp */
109
+ createdAt: number;
110
+ /** Session expiration timestamp (if applicable) */
111
+ expiresAt?: number;
112
+ /** Origin of the dApp that created the session */
113
+ origin: string;
114
+ /** Capabilities available in this session */
115
+ capabilitiesSnapshot: CapabilityKey[];
116
+ /** Additional metadata (encrypted in storage) */
117
+ metadata?: Record<string, string>;
118
+ }
119
+ /**
120
+ * Persisted session (for restoration)
121
+ */
122
+ interface PersistedSession extends Session {
123
+ /** Encrypted session data */
124
+ encrypted: string;
125
+ }
126
+ /**
127
+ * Signed message result
128
+ */
129
+ interface SignedMessage {
130
+ /** Signature */
131
+ signature: Signature;
132
+ /** Party ID that signed */
133
+ partyId: PartyId;
134
+ /** Original message */
135
+ message: string;
136
+ /** Nonce used (if provided) */
137
+ nonce?: string;
138
+ /** Domain used (if provided) */
139
+ domain?: string;
140
+ }
141
+ /**
142
+ * Signed transaction result
143
+ */
144
+ interface SignedTransaction {
145
+ /** Signed transaction data */
146
+ signedTx: unknown;
147
+ /** Transaction hash */
148
+ transactionHash: TransactionHash;
149
+ /** Party ID that signed */
150
+ partyId: PartyId;
151
+ }
152
+ /**
153
+ * Transaction receipt
154
+ */
155
+ interface TxReceipt {
156
+ /** Transaction hash */
157
+ transactionHash: TransactionHash;
158
+ /** Submission timestamp */
159
+ submittedAt: number;
160
+ /** Command ID (if available) */
161
+ commandId?: string;
162
+ /** Update ID (if available) */
163
+ updateId?: string;
164
+ }
165
+ /**
166
+ * Transaction status
167
+ */
168
+ type TransactionStatus = 'pending' | 'submitted' | 'committed' | 'rejected' | 'failed';
169
+ /**
170
+ * Transaction status update
171
+ */
172
+ interface TxStatusUpdate {
173
+ /** Session ID */
174
+ sessionId: SessionId;
175
+ /** Transaction ID */
176
+ txId: TransactionHash;
177
+ /** Current status */
178
+ status: TransactionStatus;
179
+ /** Raw transaction data (if available) */
180
+ raw?: unknown;
181
+ /** Timestamp */
182
+ timestamp: number;
183
+ }
184
+ /**
185
+ * Helper to create branded WalletId
186
+ */
187
+ declare function toWalletId(id: string): WalletId;
188
+ /**
189
+ * Helper to create branded PartyId
190
+ */
191
+ declare function toPartyId(id: string): PartyId;
192
+ /**
193
+ * Helper to create branded SessionId
194
+ */
195
+ declare function toSessionId(id: string): SessionId;
196
+ /**
197
+ * Helper to create branded TransactionHash
198
+ */
199
+ declare function toTransactionHash(hash: string): TransactionHash;
200
+ /**
201
+ * Helper to create branded Signature
202
+ */
203
+ declare function toSignature(sig: string): Signature;
204
+
205
+ /**
206
+ * Error taxonomy for CantonConnect SDK
207
+ *
208
+ * All errors extend CantonConnectError with stable error codes.
209
+ * Error codes are string literals for telemetry and UI message mapping.
210
+ *
211
+ * References:
212
+ * - Wallet Integration Guide: https://docs.digitalasset.com/integrate/devnet/index.html
213
+ */
214
+ /**
215
+ * Error code union - stable string literals for telemetry and UI
216
+ */
217
+ 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';
218
+ /**
219
+ * Error mapping context
220
+ */
221
+ interface ErrorMappingContext {
222
+ /** Wallet ID (if applicable) */
223
+ walletId?: string;
224
+ /** Operation phase */
225
+ phase: 'connect' | 'restore' | 'signMessage' | 'signTransaction' | 'submitTransaction';
226
+ /** Transport type */
227
+ transport?: 'injected' | 'popup' | 'deeplink' | 'remote';
228
+ /** Timeout in milliseconds (for timeout errors) */
229
+ timeoutMs?: number;
230
+ /** Additional context */
231
+ details?: Record<string, unknown>;
232
+ }
233
+ /**
234
+ * Base error class for all CantonConnect errors
235
+ */
236
+ declare class CantonConnectError extends Error {
237
+ readonly code: ErrorCode;
238
+ readonly cause?: unknown;
239
+ readonly details?: Record<string, unknown>;
240
+ readonly isOperational: boolean;
241
+ constructor(message: string, code: ErrorCode, options?: {
242
+ cause?: unknown;
243
+ details?: Record<string, unknown>;
244
+ isOperational?: boolean;
245
+ });
246
+ /**
247
+ * Serialize error to JSON for telemetry/logging
248
+ */
249
+ toJSON(): Record<string, unknown>;
250
+ }
251
+ /**
252
+ * Wallet not found error
253
+ */
254
+ declare class WalletNotFoundError extends CantonConnectError {
255
+ constructor(walletId: string);
256
+ }
257
+ /**
258
+ * Wallet not installed error
259
+ */
260
+ declare class WalletNotInstalledError extends CantonConnectError {
261
+ constructor(walletId: string, reason?: string);
262
+ }
263
+ /**
264
+ * User rejected error
265
+ */
266
+ declare class UserRejectedError extends CantonConnectError {
267
+ constructor(operation: string, details?: Record<string, unknown>);
268
+ }
269
+ /**
270
+ * Origin not allowed error
271
+ */
272
+ declare class OriginNotAllowedError extends CantonConnectError {
273
+ constructor(origin: string, allowedOrigins?: string[]);
274
+ }
275
+ /**
276
+ * Session expired error
277
+ */
278
+ declare class SessionExpiredError extends CantonConnectError {
279
+ constructor(sessionId: string);
280
+ }
281
+ /**
282
+ * Capability not supported error
283
+ */
284
+ declare class CapabilityNotSupportedError extends CantonConnectError {
285
+ constructor(walletId: string, capability: string);
286
+ }
287
+ /**
288
+ * Transport error
289
+ */
290
+ declare class TransportError extends CantonConnectError {
291
+ constructor(message: string, cause?: unknown, details?: Record<string, unknown>);
292
+ }
293
+ /**
294
+ * Registry fetch failed error
295
+ */
296
+ declare class RegistryFetchFailedError extends CantonConnectError {
297
+ constructor(url: string, cause?: unknown);
298
+ }
299
+ /**
300
+ * Registry verification failed error
301
+ */
302
+ declare class RegistryVerificationFailedError extends CantonConnectError {
303
+ constructor(reason: string, details?: Record<string, unknown>);
304
+ }
305
+ /**
306
+ * Registry schema invalid error
307
+ */
308
+ declare class RegistrySchemaInvalidError extends CantonConnectError {
309
+ constructor(reason: string, details?: Record<string, unknown>);
310
+ }
311
+ /**
312
+ * Internal error (non-operational)
313
+ */
314
+ declare class InternalError extends CantonConnectError {
315
+ constructor(message: string, cause?: unknown, details?: Record<string, unknown>);
316
+ }
317
+ /**
318
+ * Timeout error
319
+ */
320
+ declare class TimeoutError extends CantonConnectError {
321
+ constructor(operation: string, timeoutMs: number);
322
+ }
323
+ /**
324
+ * Map unknown errors to CantonConnectError
325
+ *
326
+ * This is the single error mapping strategy used by all adapters.
327
+ * It normalizes errors from various sources (wallet SDKs, network, etc.)
328
+ * into typed CantonConnectError instances.
329
+ */
330
+ declare function mapUnknownErrorToCantonConnectError(err: unknown, context: ErrorMappingContext): CantonConnectError;
331
+
332
+ /**
333
+ * Wallet adapter interface contract
334
+ *
335
+ * All wallet adapters must implement this interface.
336
+ * Adapters are responsible for:
337
+ * - Detecting wallet installation
338
+ * - Establishing connections
339
+ * - Signing messages/transactions
340
+ * - Emitting events
341
+ *
342
+ * References:
343
+ * - OpenRPC dApp API spec: https://github.com/hyperledger-labs/splice-wallet-kernel/blob/main/api-specs/openrpc-dapp-api.json
344
+ * - Wallet Integration Guide: https://docs.digitalasset.com/integrate/devnet/index.html
345
+ */
346
+
347
+ /**
348
+ * Adapter detection result
349
+ */
350
+ interface AdapterDetectResult {
351
+ /** Whether wallet is installed */
352
+ installed: boolean;
353
+ /** Reason if not installed */
354
+ reason?: string;
355
+ }
356
+ /**
357
+ * Adapter connection result
358
+ */
359
+ interface AdapterConnectResult {
360
+ /** Connected party ID */
361
+ partyId: PartyId;
362
+ /** Partial session data (SDK will complete it) */
363
+ session: Partial<Session>;
364
+ /** Capabilities available in this session */
365
+ capabilities: CapabilityKey[];
366
+ }
367
+ /**
368
+ * Sign message parameters
369
+ */
370
+ interface SignMessageParams {
371
+ /** Message to sign */
372
+ message: string;
373
+ /** Optional nonce */
374
+ nonce?: string;
375
+ /** Optional domain */
376
+ domain?: string;
377
+ }
378
+ /**
379
+ * Sign transaction parameters
380
+ */
381
+ interface SignTransactionParams {
382
+ /** Transaction to sign (type kept as unknown for wallet-specific formats) */
383
+ tx: unknown;
384
+ }
385
+ /**
386
+ * Submit transaction parameters
387
+ */
388
+ interface SubmitTransactionParams {
389
+ /** Signed transaction */
390
+ signedTx: unknown;
391
+ }
392
+ /**
393
+ * Logger interface
394
+ */
395
+ interface LoggerAdapter {
396
+ debug(message: string, ...args: unknown[]): void;
397
+ info(message: string, ...args: unknown[]): void;
398
+ warn(message: string, ...args: unknown[]): void;
399
+ error(message: string, error?: unknown, ...args: unknown[]): void;
400
+ }
401
+ /**
402
+ * Telemetry interface
403
+ */
404
+ interface TelemetryAdapter {
405
+ track(event: string, properties?: Record<string, unknown>): void;
406
+ error(error: Error, properties?: Record<string, unknown>): void;
407
+ }
408
+ /**
409
+ * Crypto interface
410
+ */
411
+ interface CryptoAdapter {
412
+ encrypt(data: string, key: string): Promise<string>;
413
+ decrypt(encrypted: string, key: string): Promise<string>;
414
+ generateKey(): Promise<string>;
415
+ }
416
+ /**
417
+ * Storage interface
418
+ */
419
+ interface StorageAdapter {
420
+ get(key: string): Promise<string | null>;
421
+ set(key: string, value: string): Promise<void>;
422
+ remove(key: string): Promise<void>;
423
+ clear(): Promise<void>;
424
+ }
425
+ /**
426
+ * Registry client interface (for adapters to query wallet info)
427
+ */
428
+ interface RegistryClientAdapter {
429
+ getWallet(walletId: WalletId): Promise<unknown>;
430
+ }
431
+ /**
432
+ * Adapter context provided to all adapter methods
433
+ */
434
+ interface AdapterContext {
435
+ /** Application name */
436
+ appName: string;
437
+ /** Origin (for origin binding) */
438
+ origin: string;
439
+ /** Network */
440
+ network: NetworkId;
441
+ /** Logger */
442
+ logger: LoggerAdapter;
443
+ /** Telemetry (optional) */
444
+ telemetry?: TelemetryAdapter;
445
+ /** Registry client */
446
+ registry: RegistryClientAdapter;
447
+ /** Crypto adapter */
448
+ crypto: CryptoAdapter;
449
+ /** Storage adapter */
450
+ storage: StorageAdapter;
451
+ /** Timeout helper */
452
+ timeout: (ms: number) => Promise<never>;
453
+ /** Abort signal (for cancellation) */
454
+ abortSignal?: AbortSignal;
455
+ }
456
+ /**
457
+ * Adapter event names
458
+ */
459
+ type AdapterEventName = 'connect' | 'disconnect' | 'sessionExpired' | 'txStatus' | 'error';
460
+ /**
461
+ * Wallet adapter interface
462
+ *
463
+ * All wallet adapters must implement this interface.
464
+ * Optional methods (marked with ?) should only be implemented
465
+ * if the wallet supports that capability.
466
+ */
467
+ interface WalletAdapter {
468
+ /** Wallet identifier */
469
+ readonly walletId: WalletId;
470
+ /** Wallet display name */
471
+ readonly name: string;
472
+ /**
473
+ * Get supported capabilities
474
+ */
475
+ getCapabilities(): CapabilityKey[];
476
+ /**
477
+ * Detect if wallet is installed
478
+ */
479
+ detectInstalled(): Promise<AdapterDetectResult>;
480
+ /**
481
+ * Connect to wallet
482
+ * @param ctx Adapter context
483
+ * @param opts Connection options (optional)
484
+ */
485
+ connect(ctx: AdapterContext, opts?: {
486
+ timeoutMs?: number;
487
+ partyId?: PartyId;
488
+ }): Promise<AdapterConnectResult>;
489
+ /**
490
+ * Disconnect from wallet
491
+ * @param ctx Adapter context
492
+ * @param session Session to disconnect
493
+ */
494
+ disconnect(ctx: AdapterContext, session: Session): Promise<void>;
495
+ /**
496
+ * Restore session (optional - only if wallet supports it)
497
+ * @param ctx Adapter context
498
+ * @param persisted Persisted session data
499
+ */
500
+ restore?(ctx: AdapterContext, persisted: PersistedSession): Promise<Session | null>;
501
+ /**
502
+ * Sign message (optional - only if wallet supports it)
503
+ * @param ctx Adapter context
504
+ * @param session Active session
505
+ * @param params Sign message parameters
506
+ */
507
+ signMessage?(ctx: AdapterContext, session: Session, params: SignMessageParams): Promise<SignedMessage>;
508
+ /**
509
+ * Sign transaction (optional - only if wallet supports it)
510
+ * @param ctx Adapter context
511
+ * @param session Active session
512
+ * @param params Sign transaction parameters
513
+ */
514
+ signTransaction?(ctx: AdapterContext, session: Session, params: SignTransactionParams): Promise<SignedTransaction>;
515
+ /**
516
+ * Submit transaction (optional - only if wallet supports it)
517
+ * @param ctx Adapter context
518
+ * @param session Active session
519
+ * @param params Submit transaction parameters
520
+ */
521
+ submitTransaction?(ctx: AdapterContext, session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
522
+ /**
523
+ * Subscribe to adapter events (optional)
524
+ * @param event Event name
525
+ * @param handler Event handler
526
+ * @returns Unsubscribe function
527
+ */
528
+ on?(event: AdapterEventName, handler: (payload: unknown) => void): () => void;
529
+ }
530
+ /**
531
+ * Check if adapter supports required capabilities
532
+ * Throws CapabilityNotSupportedError if not supported
533
+ */
534
+ declare function capabilityGuard(adapter: WalletAdapter, requiredCapabilities: CapabilityKey[]): void;
535
+ /**
536
+ * Check if wallet is installed
537
+ * Throws WalletNotInstalledError if not installed
538
+ */
539
+ declare function installGuard(adapter: WalletAdapter): Promise<void>;
540
+
541
+ /**
542
+ * Session management utilities
543
+ */
544
+
545
+ /**
546
+ * Generate a unique session ID
547
+ */
548
+ declare function generateSessionId(): SessionId;
549
+ /**
550
+ * Validate session structure
551
+ */
552
+ declare function validateSession(session: unknown): session is Session;
553
+ /**
554
+ * Check if session is expired
555
+ */
556
+ declare function isSessionExpired(session: Session): boolean;
557
+ /**
558
+ * Create a session with default values
559
+ */
560
+ declare function createSession(walletId: string, partyId: string, network: string, origin: string, capabilities?: string[], expiresInMs?: number): Session;
561
+
562
+ /**
563
+ * Transport layer types for wallet communication
564
+ *
565
+ * Supports deep link, popup, and postMessage transports for mobile and web wallets.
566
+ */
567
+
568
+ /**
569
+ * Transport type
570
+ */
571
+ type TransportType = 'deeplink' | 'popup' | 'postmessage' | 'injected';
572
+ /**
573
+ * Transport options
574
+ */
575
+ interface TransportOptions {
576
+ /** Timeout in milliseconds */
577
+ timeoutMs?: number;
578
+ /** Allowed callback origins */
579
+ allowedOrigins?: string[];
580
+ /** Current origin for validation */
581
+ origin: string;
582
+ }
583
+ /**
584
+ * Connect request payload
585
+ */
586
+ interface ConnectRequest {
587
+ appName: string;
588
+ origin: string;
589
+ network: string;
590
+ requestedCapabilities?: string[];
591
+ state: string;
592
+ redirectUri?: string;
593
+ }
594
+ /**
595
+ * Connect response payload
596
+ */
597
+ interface ConnectResponse {
598
+ state: string;
599
+ partyId?: PartyId;
600
+ sessionToken?: string;
601
+ expiresAt?: number;
602
+ capabilities?: string[];
603
+ error?: {
604
+ code: string;
605
+ message: string;
606
+ };
607
+ }
608
+ /**
609
+ * Sign request payload
610
+ */
611
+ interface SignRequest {
612
+ message?: string;
613
+ transaction?: unknown;
614
+ state: string;
615
+ redirectUri?: string;
616
+ }
617
+ /**
618
+ * Sign response payload
619
+ */
620
+ interface SignResponse {
621
+ state: string;
622
+ signature?: string;
623
+ transactionHash?: string;
624
+ jobId?: string;
625
+ error?: {
626
+ code: string;
627
+ message: string;
628
+ };
629
+ }
630
+ /**
631
+ * Job status (for async approval flows)
632
+ */
633
+ interface JobStatus {
634
+ jobId: string;
635
+ status: 'pending' | 'approved' | 'denied' | 'expired';
636
+ result?: {
637
+ signature?: string;
638
+ transactionHash?: string;
639
+ };
640
+ error?: {
641
+ code: string;
642
+ message: string;
643
+ };
644
+ }
645
+ /**
646
+ * Transport interface
647
+ */
648
+ interface Transport$1 {
649
+ /**
650
+ * Open a connection request
651
+ */
652
+ openConnectRequest(url: string, request: ConnectRequest, options: TransportOptions): Promise<ConnectResponse>;
653
+ /**
654
+ * Open a sign request
655
+ */
656
+ openSignRequest(url: string, request: SignRequest, options: TransportOptions): Promise<SignResponse>;
657
+ /**
658
+ * Poll job status (if supported)
659
+ */
660
+ pollJobStatus?(jobId: string, statusUrl: string, options: TransportOptions): Promise<JobStatus>;
661
+ }
662
+
663
+ /**
664
+ * Deep Link Transport
665
+ *
666
+ * Opens a deep link URL (mobile) and awaits callback via redirect or postMessage.
667
+ *
668
+ * Security:
669
+ * - State parameter (nonce) for CSRF protection
670
+ * - Origin validation
671
+ * - Timeout enforcement
672
+ * - Callback origin allowlist
673
+ */
674
+
675
+ /**
676
+ * Deep link transport implementation
677
+ */
678
+ declare class DeepLinkTransport implements Transport$1 {
679
+ /**
680
+ * Generate a random state nonce
681
+ */
682
+ private generateState;
683
+ /**
684
+ * Build deep link URL with query parameters
685
+ */
686
+ private buildDeepLinkUrl;
687
+ /**
688
+ * Validate callback origin
689
+ */
690
+ private validateOrigin;
691
+ /**
692
+ * Wait for callback via postMessage or redirect
693
+ */
694
+ private waitForCallback;
695
+ /**
696
+ * Open a connection request
697
+ */
698
+ openConnectRequest(url: string, request: ConnectRequest, options: TransportOptions): Promise<ConnectResponse>;
699
+ /**
700
+ * Open a sign request
701
+ */
702
+ openSignRequest(url: string, request: SignRequest, options: TransportOptions): Promise<SignResponse>;
703
+ }
704
+
705
+ /**
706
+ * Popup Transport
707
+ *
708
+ * Opens a centered popup window and establishes a postMessage channel.
709
+ *
710
+ * Security:
711
+ * - Origin validation
712
+ * - State parameter validation
713
+ * - Popup window management
714
+ */
715
+
716
+ /**
717
+ * Popup transport implementation
718
+ */
719
+ declare class PopupTransport implements Transport$1 {
720
+ /**
721
+ * Generate a random state nonce
722
+ */
723
+ private generateState;
724
+ /**
725
+ * Build URL with query parameters
726
+ */
727
+ private buildUrl;
728
+ /**
729
+ * Validate message origin
730
+ */
731
+ private validateOrigin;
732
+ /**
733
+ * Open popup window
734
+ */
735
+ private openPopup;
736
+ /**
737
+ * Wait for postMessage callback
738
+ */
739
+ private waitForCallback;
740
+ /**
741
+ * Open a connection request
742
+ */
743
+ openConnectRequest(url: string, request: ConnectRequest, options: TransportOptions): Promise<ConnectResponse>;
744
+ /**
745
+ * Open a sign request
746
+ */
747
+ openSignRequest(url: string, request: SignRequest, options: TransportOptions): Promise<SignResponse>;
748
+ }
749
+
750
+ /**
751
+ * PostMessage Transport
752
+ *
753
+ * Establishes a postMessage channel with an existing window/iframe.
754
+ *
755
+ * Security:
756
+ * - Origin validation
757
+ * - State parameter validation
758
+ */
759
+
760
+ /**
761
+ * PostMessage transport implementation
762
+ */
763
+ declare class PostMessageTransport implements Transport$1 {
764
+ /**
765
+ * Generate a random state nonce
766
+ */
767
+ private generateState;
768
+ /**
769
+ * Validate message origin
770
+ */
771
+ private validateOrigin;
772
+ /**
773
+ * Send message and wait for response
774
+ */
775
+ private sendAndWait;
776
+ /**
777
+ * Open a connection request
778
+ */
779
+ openConnectRequest(url: string, request: ConnectRequest, options: TransportOptions): Promise<ConnectResponse>;
780
+ /**
781
+ * Open a sign request
782
+ */
783
+ openSignRequest(url: string, request: SignRequest, options: TransportOptions): Promise<SignResponse>;
784
+ }
785
+
786
+ /**
787
+ * Mock Transport
788
+ *
789
+ * For testing and development. Simulates transport behavior without real network calls.
790
+ */
791
+
792
+ /**
793
+ * Mock transport implementation
794
+ */
795
+ declare class MockTransport implements Transport$1 {
796
+ private mockResponses;
797
+ private mockJobs;
798
+ /**
799
+ * Set mock response for a state
800
+ */
801
+ setMockResponse(state: string, response: ConnectResponse | SignResponse): void;
802
+ /**
803
+ * Set mock job status
804
+ */
805
+ setMockJob(jobId: string, status: JobStatus): void;
806
+ /**
807
+ * Clear all mocks
808
+ */
809
+ clearMocks(): void;
810
+ /**
811
+ * Open a connection request (mock)
812
+ */
813
+ openConnectRequest(_url: string, request: ConnectRequest, _options: TransportOptions): Promise<ConnectResponse>;
814
+ /**
815
+ * Open a sign request (mock)
816
+ */
817
+ openSignRequest(_url: string, request: SignRequest, _options: TransportOptions): Promise<SignResponse>;
818
+ /**
819
+ * Poll job status (mock)
820
+ */
821
+ pollJobStatus(jobId: string, _statusUrl: string, _options: TransportOptions): Promise<JobStatus>;
822
+ }
823
+
824
+ /**
825
+ * Transport abstractions for wallet communication
826
+ */
827
+ /**
828
+ * Transport message
829
+ */
830
+ interface TransportMessage<T = unknown> {
831
+ /** Message ID */
832
+ id: string;
833
+ /** Message type */
834
+ type: string;
835
+ /** Message payload */
836
+ payload: T;
837
+ /** Timestamp */
838
+ timestamp: number;
839
+ /** Origin */
840
+ origin?: string;
841
+ }
842
+ /**
843
+ * Transport response
844
+ */
845
+ interface TransportResponse<T = unknown> {
846
+ /** Response ID (matches request ID) */
847
+ id: string;
848
+ /** Success flag */
849
+ success: boolean;
850
+ /** Response data (if success) */
851
+ data?: T;
852
+ /** Error (if not success) */
853
+ error?: {
854
+ code: string;
855
+ message: string;
856
+ };
857
+ }
858
+ /**
859
+ * Transport interface for wallet communication
860
+ * Different wallets may use different transports (postMessage, WebSocket, HTTP, etc.)
861
+ */
862
+ interface Transport {
863
+ /**
864
+ * Send a message and wait for response
865
+ */
866
+ send<TRequest = unknown, TResponse = unknown>(message: TransportMessage<TRequest>): Promise<TransportResponse<TResponse>>;
867
+ /**
868
+ * Subscribe to incoming messages
869
+ */
870
+ onMessage(handler: (message: TransportMessage) => void): () => void;
871
+ /**
872
+ * Check if transport is connected
873
+ */
874
+ isConnected(): boolean;
875
+ /**
876
+ * Connect the transport
877
+ */
878
+ connect(): Promise<void>;
879
+ /**
880
+ * Disconnect the transport
881
+ */
882
+ disconnect(): Promise<void>;
883
+ }
884
+
885
+ export { type AdapterConnectResult, type AdapterContext, type AdapterDetectResult, type AdapterEventName, type AdapterMetadata, CantonConnectError, type CapabilityKey, CapabilityNotSupportedError, type ConnectRequest, type ConnectResponse, type CryptoAdapter, DeepLinkTransport, type ErrorCode, type ErrorMappingContext, type InstallHints, InternalError, type JobStatus, type LoggerAdapter, MockTransport, type NetworkId, OriginNotAllowedError, type PartyId, type PersistedSession, PopupTransport, PostMessageTransport, 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, createSession, generateSessionId, installGuard, isSessionExpired, mapUnknownErrorToCantonConnectError, toPartyId, toSessionId, toSignature, toTransactionHash, toWalletId, validateSession };