@partylayer/sdk 0.6.0 → 0.7.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 +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.js +150 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _partylayer_core from '@partylayer/core';
|
|
2
|
-
import { WalletAdapter, NetworkId, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult } from '@partylayer/core';
|
|
2
|
+
import { WalletAdapter, NetworkId, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult } from '@partylayer/core';
|
|
3
3
|
export { AdapterConnectResult, AdapterContext, AdapterDetectResult, PartyLayerError as CantonConnectError, CapabilityKey, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, ErrorCode, InternalError, LedgerApiParams, LedgerApiResult, METRICS, MetricName, MetricsPayload, NetworkId, OriginNotAllowedError, PartyId, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, Session, SessionExpiredError, SessionId, SignMessageParams, SignTransactionParams, SignedMessage, SignedTransaction, SubmitTransactionParams, TimeoutError, TransactionStatus, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError, errorMetricName } 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';
|
|
@@ -143,6 +143,28 @@ interface PartyLayerConfig {
|
|
|
143
143
|
crypto?: CryptoAdapter;
|
|
144
144
|
/** Registry public keys for signature verification (ed25519) */
|
|
145
145
|
registryPublicKeys?: string[];
|
|
146
|
+
/**
|
|
147
|
+
* EIP-6963-style announce discovery — the canonical Canton provider contract
|
|
148
|
+
* (`canton:requestProvider` → `canton:announceProvider`, see provider.md).
|
|
149
|
+
*
|
|
150
|
+
* When enabled, `listWallets()` aggregates announced CIP-0103 wallets with
|
|
151
|
+
* the `window.canton` namespace scan, the registry, and registered adapters:
|
|
152
|
+
* - an announced id matching a registered/registry wallet's
|
|
153
|
+
* `providerDetection` (provider.id) maps to that adapter — NO duplicate
|
|
154
|
+
* picker entry (e.g. Console's announce `lpnf…` → the Console adapter);
|
|
155
|
+
* - an UNKNOWN announced id surfaces as a dynamic entry routed to its own
|
|
156
|
+
* extension `target` (collision-proof; future announce-capable wallets
|
|
157
|
+
* appear with zero code changes).
|
|
158
|
+
*
|
|
159
|
+
* Default ON in the browser; ALWAYS skipped under SSR (`typeof window` guard).
|
|
160
|
+
* With zero announcers, `listWallets()` output is byte-identical to before.
|
|
161
|
+
*/
|
|
162
|
+
discovery?: {
|
|
163
|
+
/** Aggregate `canton:announceProvider` wallets. @default true (in browser) */
|
|
164
|
+
announce?: boolean;
|
|
165
|
+
/** Announce-collection window in ms. @default 300 (canonical ~300ms) */
|
|
166
|
+
announceTimeoutMs?: number;
|
|
167
|
+
};
|
|
146
168
|
/**
|
|
147
169
|
* Telemetry configuration or adapter
|
|
148
170
|
*
|
|
@@ -301,6 +323,8 @@ declare class PartyLayerClient {
|
|
|
301
323
|
private crypto;
|
|
302
324
|
private storage;
|
|
303
325
|
private telemetry?;
|
|
326
|
+
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
327
|
+
private announceEntriesCache;
|
|
304
328
|
private origin;
|
|
305
329
|
constructor(config: PartyLayerConfig);
|
|
306
330
|
/**
|
|
@@ -331,6 +355,30 @@ declare class PartyLayerClient {
|
|
|
331
355
|
* List available wallets
|
|
332
356
|
*/
|
|
333
357
|
listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Whether announce discovery is active: explicit `discovery.announce`, else
|
|
360
|
+
* ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
|
|
361
|
+
*/
|
|
362
|
+
private get announceEnabled();
|
|
363
|
+
/**
|
|
364
|
+
* Clear the cached announce round-trip so the next `listWallets()` re-runs the
|
|
365
|
+
* `canton:requestProvider` handshake (e.g. after a wallet is installed).
|
|
366
|
+
*/
|
|
367
|
+
refreshDiscovery(): void;
|
|
368
|
+
/**
|
|
369
|
+
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
370
|
+
*
|
|
371
|
+
* One-shot cached per client (refresh via {@link refreshDiscovery}); SSR-skipped.
|
|
372
|
+
* For each discovered provider (announce ∪ `window.canton` scan, deduped):
|
|
373
|
+
* - if its id matches a known wallet's `providerDetection` (provider.id) it
|
|
374
|
+
* IS that wallet — no new entry (identity bridge: Console's `lpnf…` → the
|
|
375
|
+
* `console` entry, Send's `ldmo…` → the `send` entry);
|
|
376
|
+
* - otherwise it is surfaced as a dynamic `browser:ext:<id>` entry routed to
|
|
377
|
+
* its own extension `target`, with a {@link GenericAnnounceAdapter}
|
|
378
|
+
* registered so a click connects through that target ONLY (no shared slot).
|
|
379
|
+
* With zero announcers this returns `base` unchanged.
|
|
380
|
+
*/
|
|
381
|
+
private aggregateAnnouncedWallets;
|
|
334
382
|
/** Active network-enforcement policy (default 'guard'). */
|
|
335
383
|
private get enforcement();
|
|
336
384
|
/**
|
|
@@ -453,6 +501,59 @@ declare class PartyLayerClient {
|
|
|
453
501
|
*/
|
|
454
502
|
declare function createPartyLayer(config: PartyLayerConfig): PartyLayerClient;
|
|
455
503
|
|
|
504
|
+
/**
|
|
505
|
+
* Dynamic adapter for an announced CIP-0103 wallet that has no first-party
|
|
506
|
+
* PartyLayer adapter.
|
|
507
|
+
*
|
|
508
|
+
* Canonical contract (provider.md): after `canton:requestProvider`, wallets
|
|
509
|
+
* announce `{ id, name?, icon?, target? }`; "the SDK … registers one adapter
|
|
510
|
+
* per id with providerId `browser:ext:<id>`". This adapter is that registration
|
|
511
|
+
* for the UNKNOWN case — it delegates every call to a `CIP0103Provider` bound to
|
|
512
|
+
* the wallet's own extension `target` channel (built by
|
|
513
|
+
* `createExtensionChannelProvider({ target: announced.target ?? announced.id })`).
|
|
514
|
+
* Because the channel is target-scoped, a click on this entry can ONLY ever
|
|
515
|
+
* reach the wallet that announced it — never a shared `window.canton` slot or
|
|
516
|
+
* another wallet (the A2 collision guarantee), and future announce-capable
|
|
517
|
+
* Canton wallets light up with zero code changes.
|
|
518
|
+
*
|
|
519
|
+
* KNOWN wallets (Console, Send, …) never use this class — the SDK's identity
|
|
520
|
+
* bridge maps their announce id to their existing adapter via `providerDetection`.
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
/** Canonical providerId prefix for an announced extension (provider.md: `browser:ext:<id>`). */
|
|
524
|
+
declare const ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
|
|
525
|
+
/** Build the canonical SDK walletId for an announced extension id. */
|
|
526
|
+
declare function announcedWalletId(announceId: string): WalletId;
|
|
527
|
+
interface GenericAnnounceAdapterArgs {
|
|
528
|
+
/** The announced extension id (== announce `detail.id`). */
|
|
529
|
+
announceId: string;
|
|
530
|
+
/** Display name from the announce detail (falls back to a derived label). */
|
|
531
|
+
name?: string;
|
|
532
|
+
/** Icon (data: URI or URL) from the announce detail. */
|
|
533
|
+
icon?: string;
|
|
534
|
+
/** Target-scoped CIP-0103 provider built from the announce (the discovery result). */
|
|
535
|
+
provider: CIP0103Provider;
|
|
536
|
+
}
|
|
537
|
+
declare class GenericAnnounceAdapter implements WalletAdapter {
|
|
538
|
+
readonly walletId: WalletId;
|
|
539
|
+
readonly name: string;
|
|
540
|
+
/** Icon surfaced to the picker (announce detail). */
|
|
541
|
+
readonly icon?: string;
|
|
542
|
+
private readonly provider;
|
|
543
|
+
constructor(args: GenericAnnounceAdapterArgs);
|
|
544
|
+
/** Baseline CIP-0103 capabilities every announced wallet must implement. */
|
|
545
|
+
getCapabilities(): CapabilityKey[];
|
|
546
|
+
/**
|
|
547
|
+
* The adapter is only ever constructed for a wallet that just announced, so
|
|
548
|
+
* its presence is established by the announce handshake itself.
|
|
549
|
+
*/
|
|
550
|
+
detectInstalled(): Promise<AdapterDetectResult>;
|
|
551
|
+
connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
|
|
552
|
+
disconnect(): Promise<void>;
|
|
553
|
+
signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
|
|
554
|
+
submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
|
|
555
|
+
}
|
|
556
|
+
|
|
456
557
|
/**
|
|
457
558
|
* Built-in wallet adapters
|
|
458
559
|
*
|
|
@@ -571,4 +672,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
|
|
|
571
672
|
*/
|
|
572
673
|
declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
|
|
573
674
|
|
|
574
|
-
export { type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
|
675
|
+
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, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _partylayer_core from '@partylayer/core';
|
|
2
|
-
import { WalletAdapter, NetworkId, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult } from '@partylayer/core';
|
|
2
|
+
import { WalletAdapter, NetworkId, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult } from '@partylayer/core';
|
|
3
3
|
export { AdapterConnectResult, AdapterContext, AdapterDetectResult, PartyLayerError as CantonConnectError, CapabilityKey, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, ErrorCode, InternalError, LedgerApiParams, LedgerApiResult, METRICS, MetricName, MetricsPayload, NetworkId, OriginNotAllowedError, PartyId, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, Session, SessionExpiredError, SessionId, SignMessageParams, SignTransactionParams, SignedMessage, SignedTransaction, SubmitTransactionParams, TimeoutError, TransactionStatus, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError, errorMetricName } 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';
|
|
@@ -143,6 +143,28 @@ interface PartyLayerConfig {
|
|
|
143
143
|
crypto?: CryptoAdapter;
|
|
144
144
|
/** Registry public keys for signature verification (ed25519) */
|
|
145
145
|
registryPublicKeys?: string[];
|
|
146
|
+
/**
|
|
147
|
+
* EIP-6963-style announce discovery — the canonical Canton provider contract
|
|
148
|
+
* (`canton:requestProvider` → `canton:announceProvider`, see provider.md).
|
|
149
|
+
*
|
|
150
|
+
* When enabled, `listWallets()` aggregates announced CIP-0103 wallets with
|
|
151
|
+
* the `window.canton` namespace scan, the registry, and registered adapters:
|
|
152
|
+
* - an announced id matching a registered/registry wallet's
|
|
153
|
+
* `providerDetection` (provider.id) maps to that adapter — NO duplicate
|
|
154
|
+
* picker entry (e.g. Console's announce `lpnf…` → the Console adapter);
|
|
155
|
+
* - an UNKNOWN announced id surfaces as a dynamic entry routed to its own
|
|
156
|
+
* extension `target` (collision-proof; future announce-capable wallets
|
|
157
|
+
* appear with zero code changes).
|
|
158
|
+
*
|
|
159
|
+
* Default ON in the browser; ALWAYS skipped under SSR (`typeof window` guard).
|
|
160
|
+
* With zero announcers, `listWallets()` output is byte-identical to before.
|
|
161
|
+
*/
|
|
162
|
+
discovery?: {
|
|
163
|
+
/** Aggregate `canton:announceProvider` wallets. @default true (in browser) */
|
|
164
|
+
announce?: boolean;
|
|
165
|
+
/** Announce-collection window in ms. @default 300 (canonical ~300ms) */
|
|
166
|
+
announceTimeoutMs?: number;
|
|
167
|
+
};
|
|
146
168
|
/**
|
|
147
169
|
* Telemetry configuration or adapter
|
|
148
170
|
*
|
|
@@ -301,6 +323,8 @@ declare class PartyLayerClient {
|
|
|
301
323
|
private crypto;
|
|
302
324
|
private storage;
|
|
303
325
|
private telemetry?;
|
|
326
|
+
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
327
|
+
private announceEntriesCache;
|
|
304
328
|
private origin;
|
|
305
329
|
constructor(config: PartyLayerConfig);
|
|
306
330
|
/**
|
|
@@ -331,6 +355,30 @@ declare class PartyLayerClient {
|
|
|
331
355
|
* List available wallets
|
|
332
356
|
*/
|
|
333
357
|
listWallets(filter?: WalletFilter): Promise<WalletInfo[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Whether announce discovery is active: explicit `discovery.announce`, else
|
|
360
|
+
* ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
|
|
361
|
+
*/
|
|
362
|
+
private get announceEnabled();
|
|
363
|
+
/**
|
|
364
|
+
* Clear the cached announce round-trip so the next `listWallets()` re-runs the
|
|
365
|
+
* `canton:requestProvider` handshake (e.g. after a wallet is installed).
|
|
366
|
+
*/
|
|
367
|
+
refreshDiscovery(): void;
|
|
368
|
+
/**
|
|
369
|
+
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
370
|
+
*
|
|
371
|
+
* One-shot cached per client (refresh via {@link refreshDiscovery}); SSR-skipped.
|
|
372
|
+
* For each discovered provider (announce ∪ `window.canton` scan, deduped):
|
|
373
|
+
* - if its id matches a known wallet's `providerDetection` (provider.id) it
|
|
374
|
+
* IS that wallet — no new entry (identity bridge: Console's `lpnf…` → the
|
|
375
|
+
* `console` entry, Send's `ldmo…` → the `send` entry);
|
|
376
|
+
* - otherwise it is surfaced as a dynamic `browser:ext:<id>` entry routed to
|
|
377
|
+
* its own extension `target`, with a {@link GenericAnnounceAdapter}
|
|
378
|
+
* registered so a click connects through that target ONLY (no shared slot).
|
|
379
|
+
* With zero announcers this returns `base` unchanged.
|
|
380
|
+
*/
|
|
381
|
+
private aggregateAnnouncedWallets;
|
|
334
382
|
/** Active network-enforcement policy (default 'guard'). */
|
|
335
383
|
private get enforcement();
|
|
336
384
|
/**
|
|
@@ -453,6 +501,59 @@ declare class PartyLayerClient {
|
|
|
453
501
|
*/
|
|
454
502
|
declare function createPartyLayer(config: PartyLayerConfig): PartyLayerClient;
|
|
455
503
|
|
|
504
|
+
/**
|
|
505
|
+
* Dynamic adapter for an announced CIP-0103 wallet that has no first-party
|
|
506
|
+
* PartyLayer adapter.
|
|
507
|
+
*
|
|
508
|
+
* Canonical contract (provider.md): after `canton:requestProvider`, wallets
|
|
509
|
+
* announce `{ id, name?, icon?, target? }`; "the SDK … registers one adapter
|
|
510
|
+
* per id with providerId `browser:ext:<id>`". This adapter is that registration
|
|
511
|
+
* for the UNKNOWN case — it delegates every call to a `CIP0103Provider` bound to
|
|
512
|
+
* the wallet's own extension `target` channel (built by
|
|
513
|
+
* `createExtensionChannelProvider({ target: announced.target ?? announced.id })`).
|
|
514
|
+
* Because the channel is target-scoped, a click on this entry can ONLY ever
|
|
515
|
+
* reach the wallet that announced it — never a shared `window.canton` slot or
|
|
516
|
+
* another wallet (the A2 collision guarantee), and future announce-capable
|
|
517
|
+
* Canton wallets light up with zero code changes.
|
|
518
|
+
*
|
|
519
|
+
* KNOWN wallets (Console, Send, …) never use this class — the SDK's identity
|
|
520
|
+
* bridge maps their announce id to their existing adapter via `providerDetection`.
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
/** Canonical providerId prefix for an announced extension (provider.md: `browser:ext:<id>`). */
|
|
524
|
+
declare const ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
|
|
525
|
+
/** Build the canonical SDK walletId for an announced extension id. */
|
|
526
|
+
declare function announcedWalletId(announceId: string): WalletId;
|
|
527
|
+
interface GenericAnnounceAdapterArgs {
|
|
528
|
+
/** The announced extension id (== announce `detail.id`). */
|
|
529
|
+
announceId: string;
|
|
530
|
+
/** Display name from the announce detail (falls back to a derived label). */
|
|
531
|
+
name?: string;
|
|
532
|
+
/** Icon (data: URI or URL) from the announce detail. */
|
|
533
|
+
icon?: string;
|
|
534
|
+
/** Target-scoped CIP-0103 provider built from the announce (the discovery result). */
|
|
535
|
+
provider: CIP0103Provider;
|
|
536
|
+
}
|
|
537
|
+
declare class GenericAnnounceAdapter implements WalletAdapter {
|
|
538
|
+
readonly walletId: WalletId;
|
|
539
|
+
readonly name: string;
|
|
540
|
+
/** Icon surfaced to the picker (announce detail). */
|
|
541
|
+
readonly icon?: string;
|
|
542
|
+
private readonly provider;
|
|
543
|
+
constructor(args: GenericAnnounceAdapterArgs);
|
|
544
|
+
/** Baseline CIP-0103 capabilities every announced wallet must implement. */
|
|
545
|
+
getCapabilities(): CapabilityKey[];
|
|
546
|
+
/**
|
|
547
|
+
* The adapter is only ever constructed for a wallet that just announced, so
|
|
548
|
+
* its presence is established by the announce handshake itself.
|
|
549
|
+
*/
|
|
550
|
+
detectInstalled(): Promise<AdapterDetectResult>;
|
|
551
|
+
connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
|
|
552
|
+
disconnect(): Promise<void>;
|
|
553
|
+
signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
|
|
554
|
+
submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
|
|
555
|
+
}
|
|
556
|
+
|
|
456
557
|
/**
|
|
457
558
|
* Built-in wallet adapters
|
|
458
559
|
*
|
|
@@ -571,4 +672,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
|
|
|
571
672
|
*/
|
|
572
673
|
declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
|
|
573
674
|
|
|
574
|
-
export { type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
|
675
|
+
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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,73 @@ var adapterSend = require('@partylayer/adapter-send');
|
|
|
11
11
|
var adapterBron = require('@partylayer/adapter-bron');
|
|
12
12
|
|
|
13
13
|
// src/client.ts
|
|
14
|
+
var ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
|
|
15
|
+
function announcedWalletId(announceId) {
|
|
16
|
+
return core.toWalletId(`${ANNOUNCED_WALLET_ID_PREFIX}${announceId}`);
|
|
17
|
+
}
|
|
18
|
+
var GenericAnnounceAdapter = class {
|
|
19
|
+
walletId;
|
|
20
|
+
name;
|
|
21
|
+
/** Icon surfaced to the picker (announce detail). */
|
|
22
|
+
icon;
|
|
23
|
+
provider;
|
|
24
|
+
constructor(args) {
|
|
25
|
+
this.walletId = announcedWalletId(args.announceId);
|
|
26
|
+
this.name = args.name && args.name.length > 0 ? args.name : `Canton Wallet (${args.announceId.slice(0, 6)}\u2026)`;
|
|
27
|
+
this.icon = args.icon;
|
|
28
|
+
this.provider = args.provider;
|
|
29
|
+
}
|
|
30
|
+
/** Baseline CIP-0103 capabilities every announced wallet must implement. */
|
|
31
|
+
getCapabilities() {
|
|
32
|
+
return ["connect", "signMessage", "submitTransaction"];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The adapter is only ever constructed for a wallet that just announced, so
|
|
36
|
+
* its presence is established by the announce handshake itself.
|
|
37
|
+
*/
|
|
38
|
+
async detectInstalled() {
|
|
39
|
+
return { installed: true, reason: "Announced via canton:announceProvider" };
|
|
40
|
+
}
|
|
41
|
+
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"
|
|
50
|
+
});
|
|
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() };
|
|
61
|
+
}
|
|
62
|
+
async disconnect() {
|
|
63
|
+
try {
|
|
64
|
+
await this.provider.request({ method: "disconnect" });
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async signMessage(_ctx, _session, params) {
|
|
69
|
+
return this.provider.request({
|
|
70
|
+
method: "signMessage",
|
|
71
|
+
params: { message: params.message }
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async submitTransaction(_ctx, _session, params) {
|
|
75
|
+
return this.provider.request({
|
|
76
|
+
method: "prepareExecute",
|
|
77
|
+
params
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
14
81
|
|
|
15
82
|
// src/config.ts
|
|
16
83
|
var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
@@ -373,6 +440,8 @@ var PartyLayerClient = class {
|
|
|
373
440
|
crypto;
|
|
374
441
|
storage;
|
|
375
442
|
telemetry;
|
|
443
|
+
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
444
|
+
announceEntriesCache = null;
|
|
376
445
|
origin;
|
|
377
446
|
constructor(config) {
|
|
378
447
|
this.config = config;
|
|
@@ -477,6 +546,7 @@ var PartyLayerClient = class {
|
|
|
477
546
|
channel: "stable"
|
|
478
547
|
});
|
|
479
548
|
}
|
|
549
|
+
registryWallets = await this.aggregateAnnouncedWallets(registryWallets);
|
|
480
550
|
if (filter?.requiredCapabilities) {
|
|
481
551
|
return registryWallets.filter(
|
|
482
552
|
(walletInfo) => filter.requiredCapabilities.every(
|
|
@@ -489,6 +559,83 @@ var PartyLayerClient = class {
|
|
|
489
559
|
}
|
|
490
560
|
return registryWallets;
|
|
491
561
|
}
|
|
562
|
+
/**
|
|
563
|
+
* Whether announce discovery is active: explicit `discovery.announce`, else
|
|
564
|
+
* ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
|
|
565
|
+
*/
|
|
566
|
+
get announceEnabled() {
|
|
567
|
+
if (typeof window === "undefined") return false;
|
|
568
|
+
return this.config.discovery?.announce ?? true;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Clear the cached announce round-trip so the next `listWallets()` re-runs the
|
|
572
|
+
* `canton:requestProvider` handshake (e.g. after a wallet is installed).
|
|
573
|
+
*/
|
|
574
|
+
refreshDiscovery() {
|
|
575
|
+
this.announceEntriesCache = null;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
579
|
+
*
|
|
580
|
+
* One-shot cached per client (refresh via {@link refreshDiscovery}); SSR-skipped.
|
|
581
|
+
* For each discovered provider (announce ∪ `window.canton` scan, deduped):
|
|
582
|
+
* - if its id matches a known wallet's `providerDetection` (provider.id) it
|
|
583
|
+
* IS that wallet — no new entry (identity bridge: Console's `lpnf…` → the
|
|
584
|
+
* `console` entry, Send's `ldmo…` → the `send` entry);
|
|
585
|
+
* - otherwise it is surfaced as a dynamic `browser:ext:<id>` entry routed to
|
|
586
|
+
* its own extension `target`, with a {@link GenericAnnounceAdapter}
|
|
587
|
+
* registered so a click connects through that target ONLY (no shared slot).
|
|
588
|
+
* With zero announcers this returns `base` unchanged.
|
|
589
|
+
*/
|
|
590
|
+
async aggregateAnnouncedWallets(base) {
|
|
591
|
+
if (!this.announceEnabled) return base;
|
|
592
|
+
if (this.announceEntriesCache === null) {
|
|
593
|
+
try {
|
|
594
|
+
const discovered = await provider.discoverProviders({
|
|
595
|
+
timeoutMs: this.config.discovery?.announceTimeoutMs,
|
|
596
|
+
// Working provider over the announce target channel; G4 (provider.md):
|
|
597
|
+
// target defaults to id when omitted — never a shared slot.
|
|
598
|
+
createProvider: (a) => provider.createExtensionChannelProvider({ target: a.target ?? a.id })
|
|
599
|
+
});
|
|
600
|
+
const entries = [];
|
|
601
|
+
for (const d of discovered) {
|
|
602
|
+
if (d.identityResolved === false) continue;
|
|
603
|
+
const known = core.findMatchingWalletInfo(
|
|
604
|
+
{ provider: { id: d.id } },
|
|
605
|
+
base
|
|
606
|
+
);
|
|
607
|
+
if (known) continue;
|
|
608
|
+
const adapter = new GenericAnnounceAdapter({
|
|
609
|
+
announceId: d.id,
|
|
610
|
+
name: d.name,
|
|
611
|
+
icon: d.icon,
|
|
612
|
+
provider: d.provider
|
|
613
|
+
});
|
|
614
|
+
this.adapters.set(adapter.walletId, adapter);
|
|
615
|
+
entries.push({
|
|
616
|
+
walletId: adapter.walletId,
|
|
617
|
+
name: adapter.name,
|
|
618
|
+
website: "",
|
|
619
|
+
icons: d.icon ? { sm: d.icon, md: d.icon, lg: d.icon } : {},
|
|
620
|
+
capabilities: adapter.getCapabilities(),
|
|
621
|
+
adapter: { packageName: "announced", versionRange: "*" },
|
|
622
|
+
docs: [],
|
|
623
|
+
networks: [this.config.network || "devnet"],
|
|
624
|
+
channel: "stable"
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
this.announceEntriesCache = entries;
|
|
628
|
+
} catch {
|
|
629
|
+
this.announceEntriesCache = [];
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (this.announceEntriesCache.length === 0) return base;
|
|
633
|
+
const ids = new Set(base.map((w) => String(w.walletId)));
|
|
634
|
+
return [
|
|
635
|
+
...base,
|
|
636
|
+
...this.announceEntriesCache.filter((w) => !ids.has(String(w.walletId)))
|
|
637
|
+
];
|
|
638
|
+
}
|
|
492
639
|
/** Active network-enforcement policy (default 'guard'). */
|
|
493
640
|
get enforcement() {
|
|
494
641
|
return this.config.networkEnforcement ?? "guard";
|
|
@@ -1224,10 +1371,13 @@ Object.defineProperty(exports, "BronAdapter", {
|
|
|
1224
1371
|
enumerable: true,
|
|
1225
1372
|
get: function () { return adapterBron.BronAdapter; }
|
|
1226
1373
|
});
|
|
1374
|
+
exports.ANNOUNCED_WALLET_ID_PREFIX = ANNOUNCED_WALLET_ID_PREFIX;
|
|
1227
1375
|
exports.CantonConnectClient = PartyLayerClient;
|
|
1228
1376
|
exports.DEFAULT_REGISTRY_URL = DEFAULT_REGISTRY_URL;
|
|
1377
|
+
exports.GenericAnnounceAdapter = GenericAnnounceAdapter;
|
|
1229
1378
|
exports.MetricsTelemetryAdapter = MetricsTelemetryAdapter;
|
|
1230
1379
|
exports.PartyLayerClient = PartyLayerClient;
|
|
1380
|
+
exports.announcedWalletId = announcedWalletId;
|
|
1231
1381
|
exports.createCantonConnect = createPartyLayer;
|
|
1232
1382
|
exports.createPartyLayer = createPartyLayer;
|
|
1233
1383
|
exports.createTelemetryAdapter = createTelemetryAdapter;
|