@partylayer/sdk 0.10.2 → 0.12.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
@@ -299,10 +299,25 @@ interface ErrorEvent {
299
299
  type: 'error';
300
300
  error: Error;
301
301
  }
302
+ /**
303
+ * Wallet-list changed event — the set of listable wallets changed since the last
304
+ * `listWallets()` (e.g. a wallet announced late via `canton:announceProvider`,
305
+ * after the picker already loaded). SIGNAL-ONLY: it carries no wallet payload
306
+ * because `listWallets()` does registry-merge + discovery-gating + identity-
307
+ * bridging + filtering that a raw announce doesn't reflect — the authoritative
308
+ * read is to re-call `listWallets()` (mirrors EIP-6963/mipd: store emits, UI
309
+ * re-reads). Emitted debounced (coalesces a burst into one). Never emitted when
310
+ * nothing announces (byte-identical idle).
311
+ */
312
+ interface WalletsChangedEvent {
313
+ type: 'wallets:changed';
314
+ /** Why the list changed. Currently only late/inject-time announce discovery. */
315
+ reason: 'announced';
316
+ }
302
317
  /**
303
318
  * All event types
304
319
  */
305
- type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
320
+ type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | WalletsChangedEvent | ErrorEvent;
306
321
  /**
307
322
  * Event handler type
308
323
  */
@@ -334,6 +349,8 @@ declare class PartyLayerClient {
334
349
  private announceEntriesCache;
335
350
  private readonly announceRegistry;
336
351
  private announceUnsubscribe;
352
+ /** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
353
+ private walletsChangedTimer;
337
354
  private origin;
338
355
  constructor(config: PartyLayerConfig);
339
356
  /**
@@ -390,6 +407,22 @@ declare class PartyLayerClient {
390
407
  * `canton:requestProvider` handshake (e.g. after a wallet is installed).
391
408
  */
392
409
  refreshDiscovery(): void;
410
+ /**
411
+ * Persistent-accumulator callback (mounted at construction). On each newly
412
+ * announced provider:
413
+ * 1. record it in the live `announceRegistry` (unchanged);
414
+ * 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
415
+ * as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
416
+ * and surfaces the wallet. This does NOT touch `warmPlans` (those hold
417
+ * only GenericDiscoveryAdapter popup plans — a disjoint set);
418
+ * 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
419
+ * the React provider) re-lists. The debounce coalesces a burst — and the
420
+ * construction-time reply storm — into one emit (no re-discovery storm).
421
+ *
422
+ * Byte-identical idle: with zero announces this never fires — no invalidation,
423
+ * no emit, no re-list.
424
+ */
425
+ private onAnnounceAccumulated;
393
426
  /**
394
427
  * Aggregate `canton:announceProvider` wallets into the picker list (A2).
395
428
  *
@@ -581,12 +614,43 @@ declare function createPartyLayer(config: PartyLayerConfig): PartyLayerClient;
581
614
  *
582
615
  * KNOWN wallets (Console, Send, …) never use this class — the SDK's identity
583
616
  * bridge maps their announce id to their existing adapter via `providerDetection`.
617
+ *
618
+ * OPTIONAL CAPABILITIES (additive; wagmi's optional-method model): a registry
619
+ * announce entry (`adapter.transport: 'announce'`) can opt a wallet into the
620
+ * optional CIP-0103 surface via {@link AnnounceAdapterConfig}. Each optional
621
+ * method is assigned in the constructor ONLY when configured, so it stays
622
+ * `undefined` otherwise (feature-detection honest) and `getCapabilities()`
623
+ * derives from what is actually present. With NO config the behavior is exactly
624
+ * the baseline: 3 capabilities + a minimal session.
584
625
  */
585
626
 
586
627
  /** Canonical providerId prefix for an announced extension (provider.md: `browser:ext:<id>`). */
587
628
  declare const ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
588
629
  /** Build the canonical SDK walletId for an announced extension id. */
589
630
  declare function announcedWalletId(announceId: string): WalletId;
631
+ /**
632
+ * Opt-in configuration for an announced wallet's OPTIONAL capabilities. Sourced
633
+ * from its registry entry (`adapter.transport: 'announce'`): `events` from
634
+ * `capabilities.events`, the rest from `adapter.config`. Every field is opt-in;
635
+ * an absent config is byte-identical to the baseline 3-capability adapter.
636
+ */
637
+ interface AnnounceAdapterConfig {
638
+ /** Enable `on()` — bridge the provider's CIP-0103 `txChanged` → adapter `txStatus`. */
639
+ events?: boolean;
640
+ /** Enable `restore()` — silent `status()`/`getPrimaryAccount()` probe + party-match. */
641
+ restore?: boolean;
642
+ /** Enable `ledgerApi()` — proxy the standard CIP-0103 `ledgerApi` call. */
643
+ ledgerApi?: boolean;
644
+ /** Populate the richer `session.metadata` on connect when the provider returns it. */
645
+ metadata?: boolean;
646
+ /**
647
+ * Optional error-translation hook. Given first crack at a thrown error: return
648
+ * an `Error` to surface it, or `undefined` to fall through to the SDK's
649
+ * built-in standard EIP-1193/-1474 mapping. A generic mechanism — not
650
+ * wallet-specific code.
651
+ */
652
+ mapError?: (err: unknown) => Error | undefined;
653
+ }
590
654
  interface GenericAnnounceAdapterArgs {
591
655
  /** The announced extension id (== announce `detail.id`). */
592
656
  announceId: string;
@@ -596,6 +660,14 @@ interface GenericAnnounceAdapterArgs {
596
660
  icon?: string;
597
661
  /** Target-scoped CIP-0103 provider built from the announce (the discovery result). */
598
662
  provider: CIP0103Provider;
663
+ /**
664
+ * Override the adapter's walletId. Defaults to `browser:ext:<announceId>` (the
665
+ * UNKNOWN-wallet case). For a KNOWN registry announce wallet, pass its registry
666
+ * walletId so the adapter registers under the id its picker entry resolves by.
667
+ */
668
+ walletId?: WalletId;
669
+ /** Optional opt-in capabilities (registry-driven). Absent ⇒ baseline behavior. */
670
+ config?: AnnounceAdapterConfig;
599
671
  }
600
672
  declare class GenericAnnounceAdapter implements WalletAdapter {
601
673
  readonly walletId: WalletId;
@@ -603,8 +675,16 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
603
675
  /** Icon surfaced to the picker (announce detail). */
604
676
  readonly icon?: string;
605
677
  private readonly provider;
678
+ private readonly metadataEnabled;
679
+ private readonly mapError?;
680
+ restore?: WalletAdapter['restore'];
681
+ on?: WalletAdapter['on'];
682
+ ledgerApi?: WalletAdapter['ledgerApi'];
606
683
  constructor(args: GenericAnnounceAdapterArgs);
607
- /** Baseline CIP-0103 capabilities every announced wallet must implement. */
684
+ /**
685
+ * Capabilities: the baseline three plus whatever optional methods were
686
+ * configured (derived from actual presence, never advertised when absent).
687
+ */
608
688
  getCapabilities(): CapabilityKey[];
609
689
  /**
610
690
  * The adapter is only ever constructed for a wallet that just announced, so
@@ -615,6 +695,19 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
615
695
  disconnect(): Promise<void>;
616
696
  signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
617
697
  submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
698
+ /** events: bridge the provider's CIP-0103 `txChanged` push event → `txStatus`. */
699
+ private makeOn;
700
+ /** restore: silent status()/getPrimaryAccount() probe + expiry + party-match. */
701
+ private makeRestore;
702
+ /** ledgerApi: proxy the standard CIP-0103 ledgerApi call; shape to {response:string}. */
703
+ private makeLedgerApi;
704
+ /**
705
+ * Run an operation, giving the optional `mapError` hook first crack at any
706
+ * thrown error. With NO hook configured this is a direct pass-through (no
707
+ * try/catch) — byte-identical to the baseline, and the SDK's built-in standard
708
+ * error mapping still applies downstream.
709
+ */
710
+ private guarded;
618
711
  }
619
712
 
620
713
  /**
@@ -850,4 +943,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
850
943
  */
851
944
  declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
852
945
 
853
- export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
946
+ export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, type WalletsChangedEvent, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
package/dist/index.d.ts CHANGED
@@ -299,10 +299,25 @@ interface ErrorEvent {
299
299
  type: 'error';
300
300
  error: Error;
301
301
  }
302
+ /**
303
+ * Wallet-list changed event — the set of listable wallets changed since the last
304
+ * `listWallets()` (e.g. a wallet announced late via `canton:announceProvider`,
305
+ * after the picker already loaded). SIGNAL-ONLY: it carries no wallet payload
306
+ * because `listWallets()` does registry-merge + discovery-gating + identity-
307
+ * bridging + filtering that a raw announce doesn't reflect — the authoritative
308
+ * read is to re-call `listWallets()` (mirrors EIP-6963/mipd: store emits, UI
309
+ * re-reads). Emitted debounced (coalesces a burst into one). Never emitted when
310
+ * nothing announces (byte-identical idle).
311
+ */
312
+ interface WalletsChangedEvent {
313
+ type: 'wallets:changed';
314
+ /** Why the list changed. Currently only late/inject-time announce discovery. */
315
+ reason: 'announced';
316
+ }
302
317
  /**
303
318
  * All event types
304
319
  */
305
- type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
320
+ type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | WalletsChangedEvent | ErrorEvent;
306
321
  /**
307
322
  * Event handler type
308
323
  */
@@ -334,6 +349,8 @@ declare class PartyLayerClient {
334
349
  private announceEntriesCache;
335
350
  private readonly announceRegistry;
336
351
  private announceUnsubscribe;
352
+ /** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
353
+ private walletsChangedTimer;
337
354
  private origin;
338
355
  constructor(config: PartyLayerConfig);
339
356
  /**
@@ -390,6 +407,22 @@ declare class PartyLayerClient {
390
407
  * `canton:requestProvider` handshake (e.g. after a wallet is installed).
391
408
  */
392
409
  refreshDiscovery(): void;
410
+ /**
411
+ * Persistent-accumulator callback (mounted at construction). On each newly
412
+ * announced provider:
413
+ * 1. record it in the live `announceRegistry` (unchanged);
414
+ * 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
415
+ * as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
416
+ * and surfaces the wallet. This does NOT touch `warmPlans` (those hold
417
+ * only GenericDiscoveryAdapter popup plans — a disjoint set);
418
+ * 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
419
+ * the React provider) re-lists. The debounce coalesces a burst — and the
420
+ * construction-time reply storm — into one emit (no re-discovery storm).
421
+ *
422
+ * Byte-identical idle: with zero announces this never fires — no invalidation,
423
+ * no emit, no re-list.
424
+ */
425
+ private onAnnounceAccumulated;
393
426
  /**
394
427
  * Aggregate `canton:announceProvider` wallets into the picker list (A2).
395
428
  *
@@ -581,12 +614,43 @@ declare function createPartyLayer(config: PartyLayerConfig): PartyLayerClient;
581
614
  *
582
615
  * KNOWN wallets (Console, Send, …) never use this class — the SDK's identity
583
616
  * bridge maps their announce id to their existing adapter via `providerDetection`.
617
+ *
618
+ * OPTIONAL CAPABILITIES (additive; wagmi's optional-method model): a registry
619
+ * announce entry (`adapter.transport: 'announce'`) can opt a wallet into the
620
+ * optional CIP-0103 surface via {@link AnnounceAdapterConfig}. Each optional
621
+ * method is assigned in the constructor ONLY when configured, so it stays
622
+ * `undefined` otherwise (feature-detection honest) and `getCapabilities()`
623
+ * derives from what is actually present. With NO config the behavior is exactly
624
+ * the baseline: 3 capabilities + a minimal session.
584
625
  */
585
626
 
586
627
  /** Canonical providerId prefix for an announced extension (provider.md: `browser:ext:<id>`). */
587
628
  declare const ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
588
629
  /** Build the canonical SDK walletId for an announced extension id. */
589
630
  declare function announcedWalletId(announceId: string): WalletId;
631
+ /**
632
+ * Opt-in configuration for an announced wallet's OPTIONAL capabilities. Sourced
633
+ * from its registry entry (`adapter.transport: 'announce'`): `events` from
634
+ * `capabilities.events`, the rest from `adapter.config`. Every field is opt-in;
635
+ * an absent config is byte-identical to the baseline 3-capability adapter.
636
+ */
637
+ interface AnnounceAdapterConfig {
638
+ /** Enable `on()` — bridge the provider's CIP-0103 `txChanged` → adapter `txStatus`. */
639
+ events?: boolean;
640
+ /** Enable `restore()` — silent `status()`/`getPrimaryAccount()` probe + party-match. */
641
+ restore?: boolean;
642
+ /** Enable `ledgerApi()` — proxy the standard CIP-0103 `ledgerApi` call. */
643
+ ledgerApi?: boolean;
644
+ /** Populate the richer `session.metadata` on connect when the provider returns it. */
645
+ metadata?: boolean;
646
+ /**
647
+ * Optional error-translation hook. Given first crack at a thrown error: return
648
+ * an `Error` to surface it, or `undefined` to fall through to the SDK's
649
+ * built-in standard EIP-1193/-1474 mapping. A generic mechanism — not
650
+ * wallet-specific code.
651
+ */
652
+ mapError?: (err: unknown) => Error | undefined;
653
+ }
590
654
  interface GenericAnnounceAdapterArgs {
591
655
  /** The announced extension id (== announce `detail.id`). */
592
656
  announceId: string;
@@ -596,6 +660,14 @@ interface GenericAnnounceAdapterArgs {
596
660
  icon?: string;
597
661
  /** Target-scoped CIP-0103 provider built from the announce (the discovery result). */
598
662
  provider: CIP0103Provider;
663
+ /**
664
+ * Override the adapter's walletId. Defaults to `browser:ext:<announceId>` (the
665
+ * UNKNOWN-wallet case). For a KNOWN registry announce wallet, pass its registry
666
+ * walletId so the adapter registers under the id its picker entry resolves by.
667
+ */
668
+ walletId?: WalletId;
669
+ /** Optional opt-in capabilities (registry-driven). Absent ⇒ baseline behavior. */
670
+ config?: AnnounceAdapterConfig;
599
671
  }
600
672
  declare class GenericAnnounceAdapter implements WalletAdapter {
601
673
  readonly walletId: WalletId;
@@ -603,8 +675,16 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
603
675
  /** Icon surfaced to the picker (announce detail). */
604
676
  readonly icon?: string;
605
677
  private readonly provider;
678
+ private readonly metadataEnabled;
679
+ private readonly mapError?;
680
+ restore?: WalletAdapter['restore'];
681
+ on?: WalletAdapter['on'];
682
+ ledgerApi?: WalletAdapter['ledgerApi'];
606
683
  constructor(args: GenericAnnounceAdapterArgs);
607
- /** Baseline CIP-0103 capabilities every announced wallet must implement. */
684
+ /**
685
+ * Capabilities: the baseline three plus whatever optional methods were
686
+ * configured (derived from actual presence, never advertised when absent).
687
+ */
608
688
  getCapabilities(): CapabilityKey[];
609
689
  /**
610
690
  * The adapter is only ever constructed for a wallet that just announced, so
@@ -615,6 +695,19 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
615
695
  disconnect(): Promise<void>;
616
696
  signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
617
697
  submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
698
+ /** events: bridge the provider's CIP-0103 `txChanged` push event → `txStatus`. */
699
+ private makeOn;
700
+ /** restore: silent status()/getPrimaryAccount() probe + expiry + party-match. */
701
+ private makeRestore;
702
+ /** ledgerApi: proxy the standard CIP-0103 ledgerApi call; shape to {response:string}. */
703
+ private makeLedgerApi;
704
+ /**
705
+ * Run an operation, giving the optional `mapError` hook first crack at any
706
+ * thrown error. With NO hook configured this is a direct pass-through (no
707
+ * try/catch) — byte-identical to the baseline, and the SDK's built-in standard
708
+ * error mapping still applies downstream.
709
+ */
710
+ private guarded;
618
711
  }
619
712
 
620
713
  /**
@@ -850,4 +943,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
850
943
  */
851
944
  declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
852
945
 
853
- export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
946
+ export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, type WalletsChangedEvent, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
package/dist/index.js CHANGED
@@ -15,21 +15,54 @@ var ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
15
15
  function announcedWalletId(announceId) {
16
16
  return core.toWalletId(`${ANNOUNCED_WALLET_ID_PREFIX}${announceId}`);
17
17
  }
18
+ function mapTxStatus(status) {
19
+ switch (status) {
20
+ case "pending":
21
+ return "pending";
22
+ case "signed":
23
+ return "submitted";
24
+ case "executed":
25
+ return "committed";
26
+ case "failed":
27
+ default:
28
+ return "failed";
29
+ }
30
+ }
18
31
  var GenericAnnounceAdapter = class {
19
32
  walletId;
20
33
  name;
21
34
  /** Icon surfaced to the picker (announce detail). */
22
35
  icon;
23
36
  provider;
37
+ metadataEnabled;
38
+ mapError;
39
+ // Optional WalletAdapter surface — assigned in the ctor ONLY when configured,
40
+ // so `getCapabilities()` and `'x' in adapter` feature-detection stay honest.
41
+ restore;
42
+ on;
43
+ ledgerApi;
24
44
  constructor(args) {
25
- this.walletId = announcedWalletId(args.announceId);
45
+ this.walletId = args.walletId ?? announcedWalletId(args.announceId);
26
46
  this.name = args.name && args.name.length > 0 ? args.name : `Canton Wallet (${args.announceId.slice(0, 6)}\u2026)`;
27
47
  this.icon = args.icon;
28
48
  this.provider = args.provider;
49
+ const config = args.config;
50
+ this.metadataEnabled = config?.metadata === true;
51
+ this.mapError = config?.mapError;
52
+ if (config?.events) this.on = this.makeOn();
53
+ if (config?.restore) this.restore = this.makeRestore();
54
+ if (config?.ledgerApi) this.ledgerApi = this.makeLedgerApi();
29
55
  }
30
- /** Baseline CIP-0103 capabilities every announced wallet must implement. */
56
+ /**
57
+ * Capabilities: the baseline three plus whatever optional methods were
58
+ * configured (derived from actual presence, never advertised when absent).
59
+ */
31
60
  getCapabilities() {
32
- return ["connect", "signMessage", "submitTransaction"];
61
+ const caps = ["connect", "signMessage", "submitTransaction"];
62
+ if (this.restore) caps.push("restore");
63
+ if (this.ledgerApi) caps.push("ledgerApi");
64
+ if (this.on) caps.push("events");
65
+ return caps;
33
66
  }
34
67
  /**
35
68
  * The adapter is only ever constructed for a wallet that just announced, so
@@ -39,25 +72,28 @@ var GenericAnnounceAdapter = class {
39
72
  return { installed: true, reason: "Announced via canton:announceProvider" };
40
73
  }
41
74
  async connect(ctx) {
42
- await this.provider.request({ method: "connect" });
43
- const account = await this.provider.request({
44
- method: "getPrimaryAccount"
45
- });
46
- let reportedNetwork;
47
- try {
48
- const status = await this.provider.request({
49
- method: "status"
75
+ return this.guarded(async () => {
76
+ await this.provider.request({ method: "connect" });
77
+ const account = await this.provider.request({
78
+ method: "getPrimaryAccount"
50
79
  });
51
- reportedNetwork = status?.network?.networkId;
52
- } catch {
53
- }
54
- const partyId = core.toPartyId(account.partyId);
55
- const session = {
56
- walletId: this.walletId,
57
- partyId,
58
- network: reportedNetwork ?? account.networkId ?? ctx.network
59
- };
60
- return { partyId, session, capabilities: this.getCapabilities() };
80
+ let status;
81
+ try {
82
+ status = await this.provider.request({ method: "status" });
83
+ } catch {
84
+ }
85
+ const reportedNetwork = status?.network?.networkId;
86
+ const partyId = core.toPartyId(account.partyId);
87
+ const session = {
88
+ walletId: this.walletId,
89
+ partyId,
90
+ network: reportedNetwork ?? account.networkId ?? ctx.network
91
+ };
92
+ if (this.metadataEnabled) {
93
+ session.metadata = buildMetadata(status, account);
94
+ }
95
+ return { partyId, session, capabilities: this.getCapabilities() };
96
+ });
61
97
  }
62
98
  async disconnect() {
63
99
  try {
@@ -66,18 +102,108 @@ var GenericAnnounceAdapter = class {
66
102
  }
67
103
  }
68
104
  async signMessage(_ctx, _session, params) {
69
- return this.provider.request({
70
- method: "signMessage",
71
- params: { message: params.message }
72
- });
105
+ return this.guarded(
106
+ () => this.provider.request({
107
+ method: "signMessage",
108
+ params: { message: params.message }
109
+ })
110
+ );
73
111
  }
74
112
  async submitTransaction(_ctx, _session, params) {
75
- return this.provider.request({
76
- method: "prepareExecute",
77
- params
113
+ return this.guarded(
114
+ () => this.provider.request({
115
+ method: "prepareExecute",
116
+ params
117
+ })
118
+ );
119
+ }
120
+ // ── Optional-method factories (assigned only when configured) ──────────────
121
+ /** events: bridge the provider's CIP-0103 `txChanged` push event → `txStatus`. */
122
+ makeOn() {
123
+ return (event, handler) => {
124
+ if (event !== "txStatus") return () => {
125
+ };
126
+ const listener = (...args) => {
127
+ const tx = args[0];
128
+ if (!tx) return;
129
+ handler({ status: mapTxStatus(tx.status), commandId: tx.commandId, raw: tx });
130
+ };
131
+ try {
132
+ this.provider.on("txChanged", listener);
133
+ } catch {
134
+ return () => {
135
+ };
136
+ }
137
+ return () => this.provider.removeListener("txChanged", listener);
138
+ };
139
+ }
140
+ /** restore: silent status()/getPrimaryAccount() probe + expiry + party-match. */
141
+ makeRestore() {
142
+ return (_ctx, persisted) => this.guarded(async () => {
143
+ if (persisted.expiresAt && Date.now() >= persisted.expiresAt) return null;
144
+ let status;
145
+ try {
146
+ status = await this.provider.request({ method: "status" });
147
+ } catch {
148
+ }
149
+ const connected = status?.isConnected ?? status?.connection?.isConnected;
150
+ if (connected === false) return null;
151
+ const account = await this.provider.request({
152
+ method: "getPrimaryAccount"
153
+ });
154
+ if (account.partyId !== persisted.partyId) return null;
155
+ return {
156
+ ...persisted,
157
+ walletId: this.walletId,
158
+ metadata: { ...persisted.metadata ?? {}, ...buildMetadata(status, account) }
159
+ };
160
+ });
161
+ }
162
+ /** ledgerApi: proxy the standard CIP-0103 ledgerApi call; shape to {response:string}. */
163
+ makeLedgerApi() {
164
+ return (_ctx, _session, params) => this.guarded(async () => {
165
+ const result = await this.provider.request({
166
+ method: "ledgerApi",
167
+ params: {
168
+ requestMethod: params.requestMethod,
169
+ resource: params.resource,
170
+ body: params.body
171
+ }
172
+ });
173
+ if (result && typeof result.response === "string") return { response: result.response };
174
+ return { response: JSON.stringify(result ?? null) };
78
175
  });
79
176
  }
177
+ /**
178
+ * Run an operation, giving the optional `mapError` hook first crack at any
179
+ * thrown error. With NO hook configured this is a direct pass-through (no
180
+ * try/catch) — byte-identical to the baseline, and the SDK's built-in standard
181
+ * error mapping still applies downstream.
182
+ */
183
+ async guarded(op) {
184
+ if (!this.mapError) return op();
185
+ try {
186
+ return await op();
187
+ } catch (err) {
188
+ const mapped = this.mapError(err);
189
+ throw mapped ?? err;
190
+ }
191
+ }
80
192
  };
193
+ function buildMetadata(status, account) {
194
+ const meta = {};
195
+ const put = (k, v) => {
196
+ if (typeof v === "string" && v.length > 0) meta[k] = v;
197
+ };
198
+ put("publicKey", account.publicKey);
199
+ put("namespace", account.namespace);
200
+ put("networkId", account.networkId);
201
+ put("signingProviderId", account.signingProviderId);
202
+ put("hint", account.hint);
203
+ put("ledgerApiBaseUrl", status?.network?.ledgerApi?.baseUrl);
204
+ put("userId", status?.session?.userId);
205
+ return meta;
206
+ }
81
207
  var GenericDiscoveryAdapter = class {
82
208
  walletId;
83
209
  name;
@@ -579,6 +705,16 @@ function createTelemetryAdapter(config) {
579
705
  return config;
580
706
  }
581
707
  var SESSION_STORAGE_KEY = "active_session";
708
+ var WALLETS_CHANGED_DEBOUNCE_MS = 50;
709
+ function deriveAnnounceConfig(entry) {
710
+ const cfg = entry.adapter?.config ?? {};
711
+ return {
712
+ events: entry.capabilities?.events === true,
713
+ restore: cfg.restore === true,
714
+ ledgerApi: cfg.ledgerApi === true,
715
+ metadata: cfg.metadata === true
716
+ };
717
+ }
582
718
  var PartyLayerClient = class {
583
719
  config;
584
720
  adapters = /* @__PURE__ */ new Map();
@@ -605,6 +741,8 @@ var PartyLayerClient = class {
605
741
  // torn down in destroy(). Empty → listWallets() output is byte-identical.
606
742
  announceRegistry = /* @__PURE__ */ new Map();
607
743
  announceUnsubscribe = null;
744
+ /** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
745
+ walletsChangedTimer = null;
608
746
  origin;
609
747
  constructor(config) {
610
748
  this.config = config;
@@ -648,7 +786,7 @@ var PartyLayerClient = class {
648
786
  this.updateRegistryStatus();
649
787
  if (this.announceEnabled) {
650
788
  this.announceUnsubscribe = provider.subscribeAnnouncedProviders(
651
- (p) => this.announceRegistry.set(p.id, p),
789
+ (p) => this.onAnnounceAccumulated(p),
652
790
  { createProvider: (a) => provider.createExtensionChannelProvider({ target: a.target ?? a.id }) }
653
791
  );
654
792
  }
@@ -795,6 +933,30 @@ var PartyLayerClient = class {
795
933
  refreshDiscovery() {
796
934
  this.announceEntriesCache = null;
797
935
  }
936
+ /**
937
+ * Persistent-accumulator callback (mounted at construction). On each newly
938
+ * announced provider:
939
+ * 1. record it in the live `announceRegistry` (unchanged);
940
+ * 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
941
+ * as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
942
+ * and surfaces the wallet. This does NOT touch `warmPlans` (those hold
943
+ * only GenericDiscoveryAdapter popup plans — a disjoint set);
944
+ * 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
945
+ * the React provider) re-lists. The debounce coalesces a burst — and the
946
+ * construction-time reply storm — into one emit (no re-discovery storm).
947
+ *
948
+ * Byte-identical idle: with zero announces this never fires — no invalidation,
949
+ * no emit, no re-list.
950
+ */
951
+ onAnnounceAccumulated(p) {
952
+ this.announceRegistry.set(p.id, p);
953
+ this.announceEntriesCache = null;
954
+ if (this.walletsChangedTimer !== null) return;
955
+ this.walletsChangedTimer = setTimeout(() => {
956
+ this.walletsChangedTimer = null;
957
+ this.emit("wallets:changed", { type: "wallets:changed", reason: "announced" });
958
+ }, WALLETS_CHANGED_DEBOUNCE_MS);
959
+ }
798
960
  /**
799
961
  * Aggregate `canton:announceProvider` wallets into the picker list (A2).
800
962
  *
@@ -830,7 +992,25 @@ var PartyLayerClient = class {
830
992
  { provider: { id: d.id } },
831
993
  base
832
994
  );
833
- if (known) continue;
995
+ if (known) {
996
+ if (this.adapters.has(known.walletId)) continue;
997
+ try {
998
+ const entry = await this.registryClient.getWalletEntry(String(known.walletId));
999
+ if (entry?.adapter?.transport === "announce") {
1000
+ const configured = new GenericAnnounceAdapter({
1001
+ announceId: d.id,
1002
+ walletId: known.walletId,
1003
+ name: d.name ?? known.name,
1004
+ icon: d.icon,
1005
+ provider: d.provider,
1006
+ config: deriveAnnounceConfig(entry)
1007
+ });
1008
+ this.adapters.set(configured.walletId, configured);
1009
+ }
1010
+ } catch {
1011
+ }
1012
+ continue;
1013
+ }
834
1014
  const adapter = new GenericAnnounceAdapter({
835
1015
  announceId: d.id,
836
1016
  name: d.name,
@@ -1335,6 +1515,10 @@ var PartyLayerClient = class {
1335
1515
  this.announceUnsubscribe?.();
1336
1516
  this.announceUnsubscribe = null;
1337
1517
  this.announceRegistry.clear();
1518
+ if (this.walletsChangedTimer !== null) {
1519
+ clearTimeout(this.walletsChangedTimer);
1520
+ this.walletsChangedTimer = null;
1521
+ }
1338
1522
  this.eventHandlers.clear();
1339
1523
  this.activeSession = null;
1340
1524
  }