@partylayer/sdk 0.19.0 → 0.20.1

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
@@ -3,8 +3,11 @@ import { WalletAdapter, NetworkId, OfficialProviderAdapter, OfficialAdapterFacto
3
3
  export { AdapterConnectResult, AdapterContext, AdapterDetectResult, AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityKey, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, ErrorCode, InternalError, LedgerApiParams, LedgerApiResult, METRICS, MetricName, MetricsPayload, NetworkHosts, NetworkId, OfficialAdapterFactory, OfficialProviderAdapter, OriginNotAllowedError, PartyId, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, Session, SessionExpiredError, SessionId, SignMessageParams, SignTransactionParams, SignedMessage, SignedTransaction, SubmitTransactionParams, TRANSFER_INTENT_FIELDS, TimeoutError, TokenInstrumentId, TransactionStatus, TransferIntent, TransferResult, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter, toTransferIntent } from '@partylayer/core';
4
4
  import { RegistryClient, RegistryStatus } from '@partylayer/registry-client';
5
5
  export { Cip0103StatusForDetection, Cip0103Support, ProviderDetection, ProviderMatcher, RegistryStatus, deriveGenericWalletName, findMatchingWallet, findMatchingWalletInfo, isCip0103Native, matchesProviderDetection } from '@partylayer/registry-client';
6
- export { CANTON_NETWORKS, CIP0103Account, CIP0103ConnectResult, CIP0103Event, CIP0103EventBus, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, DiscoveredProvider, JSON_RPC_ERRORS, PartyLayerProvider, PartyLayerProviderOptions, ProviderRpcError, RPC_ERRORS, createProviderBridge, discoverInjectedProviders, fromCAIP2Network, isCIP0103Provider, isValidCAIP2, toCAIP2Network, waitForProvider } from '@partylayer/provider';
6
+ import { BronAdapterConfig } from '@partylayer/adapter-bron';
7
7
  export { BronAdapter, BronAdapterConfig, BronApiConfig, BronAuthConfig } from '@partylayer/adapter-bron';
8
+ import { WalletConnectAdapterConfig } from '@partylayer/adapter-walletconnect';
9
+ export { WalletConnectAdapterConfig } from '@partylayer/adapter-walletconnect';
10
+ export { CANTON_NETWORKS, CIP0103Account, CIP0103ConnectResult, CIP0103Event, CIP0103EventBus, CIP0103Method, CIP0103Network, CIP0103Provider, CIP0103StatusEvent, CIP0103TxChangedEvent, CIP0103TxStatus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, DiscoveredProvider, JSON_RPC_ERRORS, PartyLayerProvider, PartyLayerProviderOptions, ProviderRpcError, RPC_ERRORS, createProviderBridge, discoverInjectedProviders, fromCAIP2Network, isCIP0103Provider, isValidCAIP2, toCAIP2Network, waitForProvider } from '@partylayer/provider';
8
11
  export { Cantor8Adapter } from '@partylayer/adapter-cantor8';
9
12
  export { ConsoleAdapter } from '@partylayer/adapter-console';
10
13
  export { LoopAdapter } from '@partylayer/adapter-loop';
@@ -75,6 +78,12 @@ type AdapterClass = new () => WalletAdapter;
75
78
  * PartyLayer configuration
76
79
  */
77
80
  interface PartyLayerConfig {
81
+ /**
82
+ * Delay browser subscriptions and automatic restoration until initialize()
83
+ * or the first explicit client action. Frameworks use this for render safety.
84
+ * @default false
85
+ */
86
+ deferInitialization?: boolean;
78
87
  /**
79
88
  * Registry base URL (optional). The client appends `/v1/{channel}/registry.json`,
80
89
  * so the default fetch is `https://registry.partylayer.xyz/v1/stable/registry.json`.
@@ -99,47 +108,17 @@ interface PartyLayerConfig {
99
108
  */
100
109
  networkEnforcement?: 'off' | 'guard' | 'strict';
101
110
  /**
102
- * Wallet adapters to register (OPTIONAL)
103
- *
104
- * By default, the built-in adapters that need no configuration are registered:
105
- * - LoopAdapter (5N Loop - QR code / popup)
106
- * - Cantor8Adapter (Cantor8 - deep link transport)
107
- * - NightlyAdapter (Nightly - injected extension)
108
- *
109
- * Console and Send are NOT in the defaults; they are CIP-0103 native and appear
110
- * through the announce path. BronAdapter (hosted OAuth) and the WalletConnect
111
- * adapter require configuration and are opt-in.
112
- *
113
- * Only provide this if you want to customize which adapters to use.
114
- *
115
- * @example
116
- * ```typescript
117
- * // Default: the no-config built-in adapters (recommended)
118
- * const client = createPartyLayer({
119
- * network: 'devnet',
120
- * app: { name: 'My dApp' },
121
- * // adapters not specified = getBuiltinAdapters() = Loop, Cantor8, Nightly
122
- * });
123
- *
124
- * // Custom: only specific adapters
125
- * import { ConsoleAdapter } from '@partylayer/sdk';
126
- * const client = createPartyLayer({
127
- * adapters: [new ConsoleAdapter()], // Only Console Wallet
128
- * // ...
129
- * });
130
- *
131
- * // With Bron (enterprise wallet with OAuth)
132
- * import { BronAdapter, getBuiltinAdapters } from '@partylayer/sdk';
133
- * const client = createPartyLayer({
134
- * adapters: [
135
- * ...getBuiltinAdapters(),
136
- * new BronAdapter({ auth: {...}, api: {...} }),
137
- * ],
138
- * // ...
139
- * });
140
- * ```
111
+ * Replace the default wallet catalog. Omit for all supported wallets on the
112
+ * configured network/channel. Official wallet SDKs are included and loaded
113
+ * lazily; no per-wallet installation or registration is required.
141
114
  */
142
115
  adapters?: (WalletAdapter | AdapterClass | OfficialProviderAdapter | OfficialAdapterFactory)[];
116
+ /** Extend the default catalog with custom adapters (for example a test wallet). */
117
+ additionalAdapters?: PartyLayerConfig['adapters'];
118
+ /** Enable WalletConnect with your application's Cloud project id. */
119
+ walletConnect?: WalletConnectAdapterConfig;
120
+ /** Enable the Bron remote signer with your application's OAuth/API configuration. */
121
+ bron?: BronAdapterConfig;
143
122
  /** Storage adapter (default: browser localStorage-based encrypted) */
144
123
  storage?: StorageAdapter;
145
124
  /** Crypto adapter (default: WebCrypto) */
@@ -340,14 +319,13 @@ type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConne
340
319
  */
341
320
  type EventHandler<T extends PartyLayerEvent = PartyLayerEvent> = (event: T) => void | Promise<void>;
342
321
 
343
- /**
344
- * PartyLayer Client
345
- *
346
- * Main client interface for dApps to interact with Canton wallets.
347
- */
348
322
  declare class PartyLayerClient {
349
323
  private config;
350
324
  private adapters;
325
+ private destroyed;
326
+ private initialized;
327
+ private readonly defaultLoads;
328
+ private readonly registryDefaultIds;
351
329
  /**
352
330
  * Pre-resolved connect plans for popup/remote (GenericDiscoveryAdapter)
353
331
  * wallets, warmed on `listWallets()` (which the modal calls on open) so a
@@ -357,6 +335,11 @@ declare class PartyLayerClient {
357
335
  private readonly warmPlans;
358
336
  private eventHandlers;
359
337
  private activeSession;
338
+ private sessionRevision;
339
+ private connectionAttempt;
340
+ private restoreTask;
341
+ private restorationBlocked;
342
+ private sessionStorageQueue;
360
343
  /**
361
344
  * True when `activeSession` was revived AS-IS (no live `status()` probe) because
362
345
  * its adapter wasn't registered yet at restore time (the lazy configured-announce
@@ -374,11 +357,17 @@ declare class PartyLayerClient {
374
357
  /** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
375
358
  private announceEntriesCache;
376
359
  private readonly announceRegistry;
360
+ private readonly announceChannels;
377
361
  private announceUnsubscribe;
378
362
  /** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
379
363
  private walletsChangedTimer;
380
364
  private origin;
365
+ private readonly nativeOwner?;
366
+ private sessionProvider?;
381
367
  constructor(config: PartyLayerConfig);
368
+ /** Start browser discovery/restoration once; safe for framework effect replay. */
369
+ initialize(): void;
370
+ private announceChannel;
382
371
  /**
383
372
  * Register a wallet adapter
384
373
  *
@@ -387,6 +376,7 @@ declare class PartyLayerClient {
387
376
  * In production, adapters would be auto-registered via registry.
388
377
  */
389
378
  registerAdapter(adapter: WalletAdapter): void;
379
+ private onNativeIdentityChanged;
390
380
  /**
391
381
  * Look up a registered adapter by wallet id.
392
382
  *
@@ -407,6 +397,8 @@ declare class PartyLayerClient {
407
397
  * List available wallets
408
398
  */
409
399
  listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
400
+ /** Resolve only reviewed default SDKs present in the active registry. */
401
+ private ensureDefaultWallets;
410
402
  /**
411
403
  * Hide registry entries whose wallet needs an app-registered adapter that is
412
404
  * NOT registered. This is the library default (RainbowKit-style): never show a
@@ -578,20 +570,16 @@ declare class PartyLayerClient {
578
570
  */
579
571
  off<T extends PartyLayerEvent>(event: T['type'], handler: EventHandler<T>): void;
580
572
  /**
581
- * Get a CIP-0103 Provider backed by this client.
582
- *
583
- * This bridge routes all request() calls through the existing
584
- * PartyLayerClient methods and maps events to CIP-0103 format.
573
+ * Get the stable provider facade for this client.
585
574
  *
586
- * The bridge implements the full CIP-0103 specification:
587
- * - All 10 mandatory methods including `ledgerApi` (when adapter supports it)
588
- * - Full transaction lifecycle: pending -> signed -> executed/failed
589
- * - All CIP-0103 events: statusChanged, accountsChanged, txChanged, connected
575
+ * Browser-native connections expose the official owner's actual accounts,
576
+ * network, execution/events and raw Ledger API response, including standard
577
+ * path/query/header request fields. Signing keeps the reviewed encoding policy.
578
+ * Existing proprietary/custom integrations retain their compatibility bridge.
579
+ * `createProviderBridge(client)` remains available explicitly for legacy callers.
580
+ * Full async server user-URL orchestration needs a verified direct provider path.
590
581
  *
591
- * **Note:** Async wallets (userUrl pattern) are not supported through the
592
- * bridge. For async wallet support, use `PartyLayerProvider` directly.
593
- *
594
- * @returns CIP-0103 compliant Provider
582
+ * @returns Stable CIP-0103 provider facade
595
583
  */
596
584
  asProvider(): _partylayer_core.CIP0103Provider;
597
585
  /**
@@ -617,6 +605,7 @@ declare class PartyLayerClient {
617
605
  * Restore session from storage
618
606
  */
619
607
  private restoreSession;
608
+ private restoreSessionOnce;
620
609
  /**
621
610
  * Update registry status and emit event
622
611
  */
@@ -760,7 +749,7 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
760
749
  readonly name: string;
761
750
  /** Icon surfaced to the picker (announce detail). */
762
751
  readonly icon?: string;
763
- private readonly provider;
752
+ private readonly rawProvider;
764
753
  private readonly metadataEnabled;
765
754
  private readonly staticMetadata?;
766
755
  private readonly mapError?;
@@ -775,6 +764,9 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
775
764
  ledgerApi?: WalletAdapter['ledgerApi'];
776
765
  signMessage?: WalletAdapter['signMessage'];
777
766
  constructor(args: GenericAnnounceAdapterArgs);
767
+ private get provider();
768
+ /** @internal Register the discovered transport with the one official owner. */
769
+ prepareNativeConnection(network: NetworkId): Promise<void>;
778
770
  /**
779
771
  * Capabilities derived from actual presence: connect and submitTransaction are
780
772
  * always present; signMessage, restore, ledgerApi, and events are each included
@@ -787,7 +779,9 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
787
779
  * its presence is established by the announce handshake itself.
788
780
  */
789
781
  detectInstalled(): Promise<AdapterDetectResult>;
790
- connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
782
+ connect(ctx: AdapterContext, options?: {
783
+ signal?: AbortSignal;
784
+ }): Promise<AdapterConnectResult>;
791
785
  disconnect(): Promise<void>;
792
786
  private signMessageImpl;
793
787
  submitTransaction(ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
@@ -832,8 +826,8 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
832
826
  * Session restore forwards to the official adapter's own `restore` (see {@link
833
827
  * GenericDiscoveryAdapter.restore}): on reload the wallet reinstates its session, typically
834
828
  * from its own storage, and the bridge adopts the returned live provider, so the first
835
- * request after reload works. If the official adapter has no `restore`, the SDK revives the
836
- * persisted record as-is.
829
+ * request after reload works. A silent primary-account probe validates the persisted party;
830
+ * an expired or unavailable provider requires reconnection.
837
831
  *
838
832
  * Eventless note: the official provider exposes `on`/`emit`/`removeListener`
839
833
  * but popup/remote wallets typically never emit, so `getCapabilities()` NEVER
@@ -847,6 +841,8 @@ interface GenericDiscoveryAdapterArgs {
847
841
  * `networkHosts` are ignored. Mutually exclusive with `factory`.
848
842
  */
849
843
  official?: OfficialProviderAdapter;
844
+ /** Declared registry capabilities; only methods implemented by this bridge are exposed. */
845
+ capabilities?: Partial<Record<CapabilityKey, boolean>>;
850
846
  /**
851
847
  * Factory form: `create(host)` constructs the official adapter with a host
852
848
  * resolved from `networkHosts[activeNetwork]` at connect time. Needed because
@@ -873,6 +869,8 @@ interface GenericDiscoveryAdapterArgs {
873
869
  /** Icon override (falls back to the official adapter's / factory's icon). */
874
870
  icon?: string;
875
871
  }
872
+ /** The generic bridge's implemented methods, constrained by registry declarations. */
873
+ declare function getDiscoveryCapabilities(declared?: Partial<Record<CapabilityKey, boolean>>): CapabilityKey[];
876
874
  declare class GenericDiscoveryAdapter implements WalletAdapter {
877
875
  readonly walletId: WalletId;
878
876
  readonly name: string;
@@ -894,6 +892,8 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
894
892
  * submit and reused, so the wallet is asked at most once.
895
893
  */
896
894
  private readonly executeVerb;
895
+ private readonly capabilities;
896
+ readonly ledgerApi?: WalletAdapter['ledgerApi'];
897
897
  constructor(args: GenericDiscoveryAdapterArgs);
898
898
  /** Whether this bridge resolves its host from `networkHosts` (factory form). */
899
899
  usesFactory(): boolean;
@@ -913,40 +913,49 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
913
913
  * no host for `network` in `networkHosts` throws, naming the network.
914
914
  */
915
915
  resolveOfficial(network: NetworkId): void;
916
+ /** @internal Prepare the official owner before a popup-opening click. */
917
+ prepareNativeConnection(network: NetworkId): Promise<void>;
916
918
  /** Lazily obtain (and cache) the official provider — deferred off the init/SSR path.
917
919
  * `official.provider()` is typed `OfficialProvider` (loose `request` so real
918
920
  * official adapters are assignable); it is call-compatible with CIP0103Provider
919
921
  * (the bridge only ever calls `request({ method, params })`). */
920
922
  private get provider();
921
- /**
922
- * Baseline CIP-0103 capabilities. NEVER includes `'events'`: popup/remote
923
- * wallets expose the event surface but do not emit (truthfulness doctrine).
924
- */
923
+ /** Implemented, registry-declared capabilities; popup event listeners are never claimed. */
925
924
  getCapabilities(): CapabilityKey[];
926
- /** Install/availability probe — delegated to the official adapter (popup-free). */
927
- detectInstalled(): Promise<AdapterDetectResult>;
928
- connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
929
925
  /**
930
- * Restore a persisted session by delegating to the official adapter's own `restore`.
926
+ * THE SINGLE PLACE THE discovery-adapter RULE IS APPLIED.
927
+ *
928
+ * **A `discovery-adapter` transport implies there is no local install.** Every
929
+ * wallet on that transport is a hosted popup or remote gateway reached with
930
+ * `window.open` — Walley, Cauri and OneSwap today. There is no extension, no
931
+ * injected global, nothing on the machine to probe. The honest answer is
932
+ * `no-local-install`, and it follows from the registry entry alone.
931
933
  *
932
- * The official `ProviderAdapter` shape carries an optional `restore()` that reinstates a
933
- * session (for example from the wallet's own storage) and returns a LIVE provider.
934
- * Without this method the SDK revived the persisted record as-is and then built a fresh,
935
- * SESSION-LESS provider from `provider()`, so a wallet that restores in `restore` looked
936
- * connected after a reload but its first real request threw. This forwards to the
937
- * official `restore` and, when it yields a provider, adopts it as the cached provider so
938
- * the very next request uses the restored session.
934
+ * SO THE VENDOR'S `detect()` IS NOT CALLED, and reinstating that call would be
935
+ * a regression however much it looks like rigour. Read from their shipped
936
+ * source, all three are constants:
939
937
  *
940
- * Popup-safe: this runs on the SDK's init/restore path, never inside a user gesture, so a
941
- * popup could not open here even if an adapter tried (the browser would block it). Per
942
- * the official contract `restore` is storage-based and gesture-free. If the official
943
- * adapter has no `restore`, it returns null, or host resolution is not ready, this falls
944
- * through to the previous behavior: the persisted session is returned and the provider is
945
- * built lazily on first use, exactly as before.
938
+ * walley: typeof window < "u" && typeof window.open == "function"
939
+ * cauri: Promise.resolve(true)
940
+ * oneswap: typeof window !== 'undefined'
941
+ *
942
+ * Each returns true in any browser. Awaiting them bought a value carrying no
943
+ * information, at the cost of an async hop on the picker's render path and a
944
+ * dependency on three third parties independently choosing to answer
945
+ * honestly. The registry already knows, it is signed, and it cannot drift.
946
+ *
947
+ * `installed: false` is deliberate and is NOT "not available": there is no
948
+ * local install, so the only truthful value for a field that asks about one
949
+ * is false. A picker must read `availability`, which says why.
946
950
  */
951
+ detectInstalled(): Promise<AdapterDetectResult>;
952
+ connect(ctx: AdapterContext, options?: {
953
+ signal?: AbortSignal;
954
+ }): Promise<AdapterConnectResult>;
955
+ /** Restore silently and validate the live party before exposing a connected session. */
947
956
  restore(ctx: AdapterContext, persisted: PersistedSession): Promise<Session | null>;
948
957
  disconnect(): Promise<void>;
949
- signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
958
+ signMessage(_ctx: AdapterContext, session: Session, params: SignMessageParams): Promise<SignedMessage>;
950
959
  submitTransaction(ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
951
960
  }
952
961
 
@@ -960,7 +969,8 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
960
969
  /**
961
970
  * Get all built-in adapters
962
971
  *
963
- * This function returns instances of all supported wallet adapters.
972
+ * This synchronous function returns the legacy, configuration-free adapters.
973
+ * The full default catalog also includes official SDKs loaded during discovery.
964
974
  * Called automatically by createPartyLayer() unless custom adapters are provided.
965
975
  *
966
976
  * Included adapters (returned by this function):
@@ -975,7 +985,7 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
975
985
  * - SendAdapter: Send Canton Wallet (passkey / WebAuthn-PRF).
976
986
  *
977
987
  * Note: BronAdapter is NOT included by default because it requires OAuth configuration.
978
- * To use Bron, install @partylayer/adapter-bron and register it manually.
988
+ * To use Bron with the full default catalog, set config.bron; no separate install is needed.
979
989
  */
980
990
  declare function getBuiltinAdapters(): WalletAdapter[];
981
991
 
@@ -1066,4 +1076,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
1066
1076
  */
1067
1077
  declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
1068
1078
 
1069
- 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 };
1079
+ 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, getDiscoveryCapabilities, isTelemetryConfig };