@partylayer/sdk 0.15.0 → 0.17.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 +48 -6
- package/dist/index.d.ts +48 -6
- package/dist/index.js +204 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +204 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _partylayer_core from '@partylayer/core';
|
|
2
|
-
import { WalletAdapter, NetworkId, OfficialProviderAdapter, OfficialAdapterFactory, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult, NetworkHosts } from '@partylayer/core';
|
|
2
|
+
import { WalletAdapter, NetworkId, OfficialProviderAdapter, OfficialAdapterFactory, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult, NetworkHosts, PersistedSession } from '@partylayer/core';
|
|
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, TimeoutError, TransactionStatus, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter } 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';
|
|
@@ -76,8 +76,9 @@ type AdapterClass = new () => WalletAdapter;
|
|
|
76
76
|
*/
|
|
77
77
|
interface PartyLayerConfig {
|
|
78
78
|
/**
|
|
79
|
-
* Registry URL (optional)
|
|
80
|
-
*
|
|
79
|
+
* Registry base URL (optional). The client appends `/v1/{channel}/registry.json`,
|
|
80
|
+
* so the default fetch is `https://registry.partylayer.xyz/v1/stable/registry.json`.
|
|
81
|
+
* @default 'https://registry.partylayer.xyz'
|
|
81
82
|
*/
|
|
82
83
|
registryUrl?: string;
|
|
83
84
|
/** Registry channel */
|
|
@@ -178,6 +179,13 @@ interface PartyLayerConfig {
|
|
|
178
179
|
telemetry?: TelemetryAdapter | TelemetryConfig;
|
|
179
180
|
/** Logger adapter (optional) */
|
|
180
181
|
logger?: LoggerAdapter;
|
|
182
|
+
/**
|
|
183
|
+
* Log verbosity. Filtering happens centrally in the client before the adapter is
|
|
184
|
+
* called, so adapters never filter themselves. `silent` suppresses everything.
|
|
185
|
+
* Defaults to `info` when a logger is supplied; with no logger the client is
|
|
186
|
+
* silent regardless.
|
|
187
|
+
*/
|
|
188
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
181
189
|
/** Application metadata */
|
|
182
190
|
app: {
|
|
183
191
|
/** Application name */
|
|
@@ -349,6 +357,8 @@ declare class PartyLayerClient {
|
|
|
349
357
|
private activeSessionNeedsProbe;
|
|
350
358
|
readonly registryClient: RegistryClient;
|
|
351
359
|
private logger;
|
|
360
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
361
|
+
private readonly logLevel;
|
|
352
362
|
private crypto;
|
|
353
363
|
private storage;
|
|
354
364
|
private telemetry?;
|
|
@@ -583,6 +593,14 @@ declare class PartyLayerClient {
|
|
|
583
593
|
/**
|
|
584
594
|
* Emit event to handlers
|
|
585
595
|
*/
|
|
596
|
+
/**
|
|
597
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
598
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
599
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
600
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
601
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
602
|
+
*/
|
|
603
|
+
private log;
|
|
586
604
|
private emit;
|
|
587
605
|
}
|
|
588
606
|
/**
|
|
@@ -759,10 +777,15 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
|
|
|
759
777
|
* (e.g. `new WalleyAdapter({ host: 'https://dev.walley.cc' })`), so the bridge
|
|
760
778
|
* never sees or sets them.
|
|
761
779
|
*
|
|
780
|
+
* Session restore forwards to the official adapter's own `restore` (see {@link
|
|
781
|
+
* GenericDiscoveryAdapter.restore}): on reload the wallet reinstates its session, typically
|
|
782
|
+
* from its own storage, and the bridge adopts the returned live provider, so the first
|
|
783
|
+
* request after reload works. If the official adapter has no `restore`, the SDK revives the
|
|
784
|
+
* persisted record as-is.
|
|
785
|
+
*
|
|
762
786
|
* Eventless note: the official provider exposes `on`/`emit`/`removeListener`
|
|
763
|
-
* but popup/remote wallets typically never emit
|
|
764
|
-
* `
|
|
765
|
-
* tolerated; `getCapabilities()` therefore NEVER returns `'events'`.
|
|
787
|
+
* but popup/remote wallets typically never emit, so `getCapabilities()` NEVER
|
|
788
|
+
* returns `'events'`.
|
|
766
789
|
*/
|
|
767
790
|
|
|
768
791
|
interface GenericDiscoveryAdapterArgs {
|
|
@@ -846,6 +869,25 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
|
|
|
846
869
|
/** Install/availability probe — delegated to the official adapter (popup-free). */
|
|
847
870
|
detectInstalled(): Promise<AdapterDetectResult>;
|
|
848
871
|
connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
|
|
872
|
+
/**
|
|
873
|
+
* Restore a persisted session by delegating to the official adapter's own `restore`.
|
|
874
|
+
*
|
|
875
|
+
* The official `ProviderAdapter` shape carries an optional `restore()` that reinstates a
|
|
876
|
+
* session (for example from the wallet's own storage) and returns a LIVE provider.
|
|
877
|
+
* Without this method the SDK revived the persisted record as-is and then built a fresh,
|
|
878
|
+
* SESSION-LESS provider from `provider()`, so a wallet that restores in `restore` looked
|
|
879
|
+
* connected after a reload but its first real request threw. This forwards to the
|
|
880
|
+
* official `restore` and, when it yields a provider, adopts it as the cached provider so
|
|
881
|
+
* the very next request uses the restored session.
|
|
882
|
+
*
|
|
883
|
+
* Popup-safe: this runs on the SDK's init/restore path, never inside a user gesture, so a
|
|
884
|
+
* popup could not open here even if an adapter tried (the browser would block it). Per
|
|
885
|
+
* the official contract `restore` is storage-based and gesture-free. If the official
|
|
886
|
+
* adapter has no `restore`, it returns null, or host resolution is not ready, this falls
|
|
887
|
+
* through to the previous behavior: the persisted session is returned and the provider is
|
|
888
|
+
* built lazily on first use, exactly as before.
|
|
889
|
+
*/
|
|
890
|
+
restore(ctx: AdapterContext, persisted: PersistedSession): Promise<Session | null>;
|
|
849
891
|
disconnect(): Promise<void>;
|
|
850
892
|
signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
|
|
851
893
|
submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _partylayer_core from '@partylayer/core';
|
|
2
|
-
import { WalletAdapter, NetworkId, OfficialProviderAdapter, OfficialAdapterFactory, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult, NetworkHosts } from '@partylayer/core';
|
|
2
|
+
import { WalletAdapter, NetworkId, OfficialProviderAdapter, OfficialAdapterFactory, StorageAdapter, CryptoAdapter, TelemetryAdapter, LoggerAdapter, WalletId, Session, SessionId, TransactionHash, TransactionStatus, WalletInfo, SignMessageParams, SignedMessage, SignTransactionParams, SignedTransaction, SubmitTransactionParams, TxReceipt, LedgerApiParams, LedgerApiResult, CIP0103Provider, CapabilityKey, AdapterDetectResult, AdapterContext, AdapterConnectResult, NetworkHosts, PersistedSession } from '@partylayer/core';
|
|
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, TimeoutError, TransactionStatus, TransportError, TxReceipt, UserRejectedError, WalletAdapter, WalletId, WalletInfo, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter } 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';
|
|
@@ -76,8 +76,9 @@ type AdapterClass = new () => WalletAdapter;
|
|
|
76
76
|
*/
|
|
77
77
|
interface PartyLayerConfig {
|
|
78
78
|
/**
|
|
79
|
-
* Registry URL (optional)
|
|
80
|
-
*
|
|
79
|
+
* Registry base URL (optional). The client appends `/v1/{channel}/registry.json`,
|
|
80
|
+
* so the default fetch is `https://registry.partylayer.xyz/v1/stable/registry.json`.
|
|
81
|
+
* @default 'https://registry.partylayer.xyz'
|
|
81
82
|
*/
|
|
82
83
|
registryUrl?: string;
|
|
83
84
|
/** Registry channel */
|
|
@@ -178,6 +179,13 @@ interface PartyLayerConfig {
|
|
|
178
179
|
telemetry?: TelemetryAdapter | TelemetryConfig;
|
|
179
180
|
/** Logger adapter (optional) */
|
|
180
181
|
logger?: LoggerAdapter;
|
|
182
|
+
/**
|
|
183
|
+
* Log verbosity. Filtering happens centrally in the client before the adapter is
|
|
184
|
+
* called, so adapters never filter themselves. `silent` suppresses everything.
|
|
185
|
+
* Defaults to `info` when a logger is supplied; with no logger the client is
|
|
186
|
+
* silent regardless.
|
|
187
|
+
*/
|
|
188
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
181
189
|
/** Application metadata */
|
|
182
190
|
app: {
|
|
183
191
|
/** Application name */
|
|
@@ -349,6 +357,8 @@ declare class PartyLayerClient {
|
|
|
349
357
|
private activeSessionNeedsProbe;
|
|
350
358
|
readonly registryClient: RegistryClient;
|
|
351
359
|
private logger;
|
|
360
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
361
|
+
private readonly logLevel;
|
|
352
362
|
private crypto;
|
|
353
363
|
private storage;
|
|
354
364
|
private telemetry?;
|
|
@@ -583,6 +593,14 @@ declare class PartyLayerClient {
|
|
|
583
593
|
/**
|
|
584
594
|
* Emit event to handlers
|
|
585
595
|
*/
|
|
596
|
+
/**
|
|
597
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
598
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
599
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
600
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
601
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
602
|
+
*/
|
|
603
|
+
private log;
|
|
586
604
|
private emit;
|
|
587
605
|
}
|
|
588
606
|
/**
|
|
@@ -759,10 +777,15 @@ declare class GenericAnnounceAdapter implements WalletAdapter {
|
|
|
759
777
|
* (e.g. `new WalleyAdapter({ host: 'https://dev.walley.cc' })`), so the bridge
|
|
760
778
|
* never sees or sets them.
|
|
761
779
|
*
|
|
780
|
+
* Session restore forwards to the official adapter's own `restore` (see {@link
|
|
781
|
+
* GenericDiscoveryAdapter.restore}): on reload the wallet reinstates its session, typically
|
|
782
|
+
* from its own storage, and the bridge adopts the returned live provider, so the first
|
|
783
|
+
* request after reload works. If the official adapter has no `restore`, the SDK revives the
|
|
784
|
+
* persisted record as-is.
|
|
785
|
+
*
|
|
762
786
|
* Eventless note: the official provider exposes `on`/`emit`/`removeListener`
|
|
763
|
-
* but popup/remote wallets typically never emit
|
|
764
|
-
* `
|
|
765
|
-
* tolerated; `getCapabilities()` therefore NEVER returns `'events'`.
|
|
787
|
+
* but popup/remote wallets typically never emit, so `getCapabilities()` NEVER
|
|
788
|
+
* returns `'events'`.
|
|
766
789
|
*/
|
|
767
790
|
|
|
768
791
|
interface GenericDiscoveryAdapterArgs {
|
|
@@ -846,6 +869,25 @@ declare class GenericDiscoveryAdapter implements WalletAdapter {
|
|
|
846
869
|
/** Install/availability probe — delegated to the official adapter (popup-free). */
|
|
847
870
|
detectInstalled(): Promise<AdapterDetectResult>;
|
|
848
871
|
connect(ctx: AdapterContext): Promise<AdapterConnectResult>;
|
|
872
|
+
/**
|
|
873
|
+
* Restore a persisted session by delegating to the official adapter's own `restore`.
|
|
874
|
+
*
|
|
875
|
+
* The official `ProviderAdapter` shape carries an optional `restore()` that reinstates a
|
|
876
|
+
* session (for example from the wallet's own storage) and returns a LIVE provider.
|
|
877
|
+
* Without this method the SDK revived the persisted record as-is and then built a fresh,
|
|
878
|
+
* SESSION-LESS provider from `provider()`, so a wallet that restores in `restore` looked
|
|
879
|
+
* connected after a reload but its first real request threw. This forwards to the
|
|
880
|
+
* official `restore` and, when it yields a provider, adopts it as the cached provider so
|
|
881
|
+
* the very next request uses the restored session.
|
|
882
|
+
*
|
|
883
|
+
* Popup-safe: this runs on the SDK's init/restore path, never inside a user gesture, so a
|
|
884
|
+
* popup could not open here even if an adapter tried (the browser would block it). Per
|
|
885
|
+
* the official contract `restore` is storage-based and gesture-free. If the official
|
|
886
|
+
* adapter has no `restore`, it returns null, or host resolution is not ready, this falls
|
|
887
|
+
* through to the previous behavior: the persisted session is returned and the provider is
|
|
888
|
+
* built lazily on first use, exactly as before.
|
|
889
|
+
*/
|
|
890
|
+
restore(ctx: AdapterContext, persisted: PersistedSession): Promise<Session | null>;
|
|
849
891
|
disconnect(): Promise<void>;
|
|
850
892
|
signMessage(_ctx: AdapterContext, _session: Session, params: SignMessageParams): Promise<SignedMessage>;
|
|
851
893
|
submitTransaction(_ctx: AdapterContext, _session: Session, params: SubmitTransactionParams): Promise<TxReceipt>;
|
package/dist/index.js
CHANGED
|
@@ -360,6 +360,46 @@ var GenericDiscoveryAdapter = class {
|
|
|
360
360
|
};
|
|
361
361
|
return { partyId, session, capabilities: this.getCapabilities() };
|
|
362
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Restore a persisted session by delegating to the official adapter's own `restore`.
|
|
365
|
+
*
|
|
366
|
+
* The official `ProviderAdapter` shape carries an optional `restore()` that reinstates a
|
|
367
|
+
* session (for example from the wallet's own storage) and returns a LIVE provider.
|
|
368
|
+
* Without this method the SDK revived the persisted record as-is and then built a fresh,
|
|
369
|
+
* SESSION-LESS provider from `provider()`, so a wallet that restores in `restore` looked
|
|
370
|
+
* connected after a reload but its first real request threw. This forwards to the
|
|
371
|
+
* official `restore` and, when it yields a provider, adopts it as the cached provider so
|
|
372
|
+
* the very next request uses the restored session.
|
|
373
|
+
*
|
|
374
|
+
* Popup-safe: this runs on the SDK's init/restore path, never inside a user gesture, so a
|
|
375
|
+
* popup could not open here even if an adapter tried (the browser would block it). Per
|
|
376
|
+
* the official contract `restore` is storage-based and gesture-free. If the official
|
|
377
|
+
* adapter has no `restore`, it returns null, or host resolution is not ready, this falls
|
|
378
|
+
* through to the previous behavior: the persisted session is returned and the provider is
|
|
379
|
+
* built lazily on first use, exactly as before.
|
|
380
|
+
*/
|
|
381
|
+
async restore(ctx, persisted) {
|
|
382
|
+
const asIs = { ...persisted, walletId: this.walletId };
|
|
383
|
+
try {
|
|
384
|
+
this.resolveOfficial(ctx.network);
|
|
385
|
+
} catch {
|
|
386
|
+
return asIs;
|
|
387
|
+
}
|
|
388
|
+
const restore = this.official?.restore;
|
|
389
|
+
if (this.official && restore) {
|
|
390
|
+
let restored = null;
|
|
391
|
+
try {
|
|
392
|
+
restored = await restore.call(this.official);
|
|
393
|
+
} catch {
|
|
394
|
+
restored = null;
|
|
395
|
+
}
|
|
396
|
+
if (restored) {
|
|
397
|
+
this.providerInstance = restored;
|
|
398
|
+
return asIs;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return asIs;
|
|
402
|
+
}
|
|
363
403
|
async disconnect() {
|
|
364
404
|
try {
|
|
365
405
|
await this.provider.request({ method: "disconnect" });
|
|
@@ -385,25 +425,13 @@ var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
|
385
425
|
|
|
386
426
|
// src/adapters.ts
|
|
387
427
|
var DefaultLogger = class {
|
|
388
|
-
debug(
|
|
389
|
-
if (typeof console !== "undefined" && console.debug) {
|
|
390
|
-
console.debug(`[PartyLayer] ${message}`, ...args);
|
|
391
|
-
}
|
|
428
|
+
debug(_message, ..._args) {
|
|
392
429
|
}
|
|
393
|
-
info(
|
|
394
|
-
if (typeof console !== "undefined" && console.info) {
|
|
395
|
-
console.info(`[PartyLayer] ${message}`, ...args);
|
|
396
|
-
}
|
|
430
|
+
info(_message, ..._args) {
|
|
397
431
|
}
|
|
398
|
-
warn(
|
|
399
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
400
|
-
console.warn(`[PartyLayer] ${message}`, ...args);
|
|
401
|
-
}
|
|
432
|
+
warn(_message, ..._args) {
|
|
402
433
|
}
|
|
403
|
-
error(
|
|
404
|
-
if (typeof console !== "undefined" && console.error) {
|
|
405
|
-
console.error(`[PartyLayer] ${message}`, error, ...args);
|
|
406
|
-
}
|
|
434
|
+
error(_message, _error, ..._args) {
|
|
407
435
|
}
|
|
408
436
|
};
|
|
409
437
|
var DefaultCrypto = class {
|
|
@@ -731,6 +759,85 @@ function createTelemetryAdapter(config) {
|
|
|
731
759
|
}
|
|
732
760
|
return config;
|
|
733
761
|
}
|
|
762
|
+
|
|
763
|
+
// src/event-telemetry.ts
|
|
764
|
+
function errorProperties(error) {
|
|
765
|
+
const code = error.code;
|
|
766
|
+
return code ? { code } : {};
|
|
767
|
+
}
|
|
768
|
+
function eventTelemetryProperties(event) {
|
|
769
|
+
switch (event.type) {
|
|
770
|
+
case "registry:updated":
|
|
771
|
+
return { channel: event.channel, version: event.version };
|
|
772
|
+
case "registry:status":
|
|
773
|
+
return {
|
|
774
|
+
source: event.status.source,
|
|
775
|
+
channel: event.status.channel,
|
|
776
|
+
verified: event.status.verified,
|
|
777
|
+
stale: event.status.stale,
|
|
778
|
+
sequence: event.status.sequence
|
|
779
|
+
};
|
|
780
|
+
case "session:connected":
|
|
781
|
+
return { walletId: event.session.walletId, network: event.session.network };
|
|
782
|
+
case "session:disconnected":
|
|
783
|
+
return {};
|
|
784
|
+
case "session:expired":
|
|
785
|
+
return {};
|
|
786
|
+
case "session:networkMismatch":
|
|
787
|
+
return { expected: event.expected, actual: event.actual, enforced: event.enforced };
|
|
788
|
+
case "tx:status":
|
|
789
|
+
return { status: event.status };
|
|
790
|
+
case "error":
|
|
791
|
+
return errorProperties(event.error);
|
|
792
|
+
case "wallets:changed":
|
|
793
|
+
return { reason: event.reason };
|
|
794
|
+
default:
|
|
795
|
+
return {};
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/logging.ts
|
|
800
|
+
var LEVEL_PRIORITY = {
|
|
801
|
+
debug: 10,
|
|
802
|
+
info: 20,
|
|
803
|
+
warn: 30,
|
|
804
|
+
error: 40,
|
|
805
|
+
silent: 100
|
|
806
|
+
};
|
|
807
|
+
function shouldLog(level, threshold) {
|
|
808
|
+
if (threshold === "silent") return false;
|
|
809
|
+
return LEVEL_PRIORITY[level] >= LEVEL_PRIORITY[threshold];
|
|
810
|
+
}
|
|
811
|
+
function newCorrelationId() {
|
|
812
|
+
const scope = typeof globalThis !== "undefined" ? globalThis : {};
|
|
813
|
+
if (scope.crypto && typeof scope.crypto.getRandomValues === "function") {
|
|
814
|
+
const bytes = new Uint8Array(6);
|
|
815
|
+
scope.crypto.getRandomValues(bytes);
|
|
816
|
+
let hex = "";
|
|
817
|
+
for (const byte of bytes) hex += byte.toString(16).padStart(2, "0");
|
|
818
|
+
return hex;
|
|
819
|
+
}
|
|
820
|
+
return Math.random().toString(16).slice(2, 14).padStart(12, "0");
|
|
821
|
+
}
|
|
822
|
+
function eventLogLevel(type) {
|
|
823
|
+
switch (type) {
|
|
824
|
+
case "error":
|
|
825
|
+
return "error";
|
|
826
|
+
case "session:networkMismatch":
|
|
827
|
+
return "warn";
|
|
828
|
+
case "session:connected":
|
|
829
|
+
case "session:disconnected":
|
|
830
|
+
return "info";
|
|
831
|
+
case "registry:status":
|
|
832
|
+
case "registry:updated":
|
|
833
|
+
case "session:expired":
|
|
834
|
+
case "tx:status":
|
|
835
|
+
case "wallets:changed":
|
|
836
|
+
return "debug";
|
|
837
|
+
default:
|
|
838
|
+
return "info";
|
|
839
|
+
}
|
|
840
|
+
}
|
|
734
841
|
var SESSION_STORAGE_KEY = "active_session";
|
|
735
842
|
var WALLETS_CHANGED_DEBOUNCE_MS = 50;
|
|
736
843
|
function deriveAnnounceConfig(entry) {
|
|
@@ -774,6 +881,8 @@ var PartyLayerClient = class {
|
|
|
774
881
|
registryClient;
|
|
775
882
|
// Expose for React hooks
|
|
776
883
|
logger;
|
|
884
|
+
/** Configured log verbosity; filtering happens centrally in {@link log}. */
|
|
885
|
+
logLevel;
|
|
777
886
|
crypto;
|
|
778
887
|
storage;
|
|
779
888
|
telemetry;
|
|
@@ -798,6 +907,7 @@ var PartyLayerClient = class {
|
|
|
798
907
|
this.origin = "unknown";
|
|
799
908
|
}
|
|
800
909
|
this.logger = config.logger || new DefaultLogger();
|
|
910
|
+
this.logLevel = config.logLevel ?? "info";
|
|
801
911
|
this.crypto = config.crypto || new DefaultCrypto();
|
|
802
912
|
this.storage = config.storage || new DefaultStorage();
|
|
803
913
|
const telemetryAdapter = createTelemetryAdapter(config.telemetry);
|
|
@@ -815,7 +925,7 @@ var PartyLayerClient = class {
|
|
|
815
925
|
adapter = adapterOrClass;
|
|
816
926
|
}
|
|
817
927
|
this.adapters.set(adapter.walletId, adapter);
|
|
818
|
-
this.
|
|
928
|
+
this.log("debug", "adapter:registered", "Registered wallet adapter", {
|
|
819
929
|
walletId: adapter.walletId,
|
|
820
930
|
name: adapter.name,
|
|
821
931
|
capabilities: adapter.getCapabilities()
|
|
@@ -881,7 +991,7 @@ var PartyLayerClient = class {
|
|
|
881
991
|
this.updateRegistryStatus();
|
|
882
992
|
} catch (err) {
|
|
883
993
|
this.updateRegistryStatus();
|
|
884
|
-
this.
|
|
994
|
+
this.log("warn", "registry:fetch_failed", "Registry fetch failed, using registered adapters only", {
|
|
885
995
|
error: err instanceof Error ? err.message : String(err)
|
|
886
996
|
});
|
|
887
997
|
registryWallets = [];
|
|
@@ -1069,7 +1179,9 @@ var PartyLayerClient = class {
|
|
|
1069
1179
|
this.emit("session:expired", { type: "session:expired", sessionId: active.sessionId });
|
|
1070
1180
|
}
|
|
1071
1181
|
} catch (err) {
|
|
1072
|
-
this.
|
|
1182
|
+
this.log("warn", "session:reprobe_failed", "Restore re-probe failed; leaving session as-is", {
|
|
1183
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1184
|
+
});
|
|
1073
1185
|
}
|
|
1074
1186
|
}
|
|
1075
1187
|
}
|
|
@@ -1136,11 +1248,13 @@ var PartyLayerClient = class {
|
|
|
1136
1248
|
*/
|
|
1137
1249
|
async connect(options) {
|
|
1138
1250
|
this.telemetry?.increment?.(core.METRICS.WALLET_CONNECT_ATTEMPTS);
|
|
1251
|
+
const correlationId = newCorrelationId();
|
|
1252
|
+
this.log("debug", "connect:start", "connect", {}, correlationId);
|
|
1139
1253
|
try {
|
|
1140
|
-
const fast = this.tryFastConnect(options);
|
|
1254
|
+
const fast = this.tryFastConnect(options, correlationId);
|
|
1141
1255
|
if (fast) return await fast;
|
|
1142
1256
|
const plan = await this.resolveConnectPlan(options);
|
|
1143
|
-
return await this.completeConnect(plan, options);
|
|
1257
|
+
return await this.completeConnect(plan, options, correlationId);
|
|
1144
1258
|
} catch (err) {
|
|
1145
1259
|
const timeoutMs = options?.timeoutMs || 3e4;
|
|
1146
1260
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
@@ -1148,7 +1262,7 @@ var PartyLayerClient = class {
|
|
|
1148
1262
|
walletId: options?.walletId ? String(options.walletId) : void 0,
|
|
1149
1263
|
timeoutMs
|
|
1150
1264
|
});
|
|
1151
|
-
this.emit("error", { type: "error", error });
|
|
1265
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1152
1266
|
throw error;
|
|
1153
1267
|
}
|
|
1154
1268
|
}
|
|
@@ -1252,7 +1366,7 @@ var PartyLayerClient = class {
|
|
|
1252
1366
|
* build / persist / emit the session. Separated from plan resolution so the
|
|
1253
1367
|
* popup-safe fast-path can call it gesture-synchronously.
|
|
1254
1368
|
*/
|
|
1255
|
-
async completeConnect(plan, options) {
|
|
1369
|
+
async completeConnect(plan, options, correlationId = newCorrelationId()) {
|
|
1256
1370
|
const { selectedWallet, adapter, ctx } = plan;
|
|
1257
1371
|
const timeoutMs = options?.timeoutMs || 12e4;
|
|
1258
1372
|
const connectPromise = adapter.connect(ctx, {
|
|
@@ -1295,7 +1409,7 @@ var PartyLayerClient = class {
|
|
|
1295
1409
|
expected: mismatch.expected,
|
|
1296
1410
|
actual: mismatch.actual,
|
|
1297
1411
|
enforced: this.enforcement !== "off"
|
|
1298
|
-
});
|
|
1412
|
+
}, correlationId);
|
|
1299
1413
|
if (this.enforcement === "strict") {
|
|
1300
1414
|
throw new core.NetworkMismatchError(mismatch.expected, mismatch.actual);
|
|
1301
1415
|
}
|
|
@@ -1309,7 +1423,7 @@ var PartyLayerClient = class {
|
|
|
1309
1423
|
this.emit("session:connected", {
|
|
1310
1424
|
type: "session:connected",
|
|
1311
1425
|
session
|
|
1312
|
-
});
|
|
1426
|
+
}, correlationId);
|
|
1313
1427
|
return session;
|
|
1314
1428
|
}
|
|
1315
1429
|
/**
|
|
@@ -1349,14 +1463,14 @@ var PartyLayerClient = class {
|
|
|
1349
1463
|
* Returns the in-flight Session promise, or null to fall back to the normal
|
|
1350
1464
|
* path (e.g. cold cache, or a non-discovery wallet).
|
|
1351
1465
|
*/
|
|
1352
|
-
tryFastConnect(options) {
|
|
1466
|
+
tryFastConnect(options, correlationId) {
|
|
1353
1467
|
const walletId = options?.walletId;
|
|
1354
1468
|
if (!walletId) return null;
|
|
1355
1469
|
if (options?.requiredCapabilities || options?.allowWallets) return null;
|
|
1356
1470
|
const plan = this.warmPlans.get(walletId);
|
|
1357
1471
|
if (!plan) return null;
|
|
1358
1472
|
this.warmPlans.delete(walletId);
|
|
1359
|
-
return this.completeConnect(plan, options);
|
|
1473
|
+
return this.completeConnect(plan, options, correlationId);
|
|
1360
1474
|
}
|
|
1361
1475
|
/**
|
|
1362
1476
|
* Disconnect from wallet
|
|
@@ -1448,6 +1562,8 @@ var PartyLayerClient = class {
|
|
|
1448
1562
|
"signTransaction"
|
|
1449
1563
|
);
|
|
1450
1564
|
}
|
|
1565
|
+
const correlationId = newCorrelationId();
|
|
1566
|
+
this.log("debug", "signTransaction:start", "signTransaction", {}, correlationId);
|
|
1451
1567
|
try {
|
|
1452
1568
|
this.assertNetworkOk(session);
|
|
1453
1569
|
const ctx = this.createAdapterContext();
|
|
@@ -1458,14 +1574,14 @@ var PartyLayerClient = class {
|
|
|
1458
1574
|
txId: result.transactionHash,
|
|
1459
1575
|
status: "pending",
|
|
1460
1576
|
raw: result.signedTx
|
|
1461
|
-
});
|
|
1577
|
+
}, correlationId);
|
|
1462
1578
|
return result;
|
|
1463
1579
|
} catch (err) {
|
|
1464
1580
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1465
1581
|
phase: "signTransaction",
|
|
1466
1582
|
walletId: String(session.walletId)
|
|
1467
1583
|
});
|
|
1468
|
-
this.emit("error", { type: "error", error });
|
|
1584
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1469
1585
|
throw error;
|
|
1470
1586
|
}
|
|
1471
1587
|
}
|
|
@@ -1484,6 +1600,8 @@ var PartyLayerClient = class {
|
|
|
1484
1600
|
"submitTransaction"
|
|
1485
1601
|
);
|
|
1486
1602
|
}
|
|
1603
|
+
const correlationId = newCorrelationId();
|
|
1604
|
+
this.log("debug", "submitTransaction:start", "submitTransaction", {}, correlationId);
|
|
1487
1605
|
try {
|
|
1488
1606
|
this.assertNetworkOk(session);
|
|
1489
1607
|
const ctx = this.createAdapterContext();
|
|
@@ -1494,14 +1612,14 @@ var PartyLayerClient = class {
|
|
|
1494
1612
|
txId: result.transactionHash,
|
|
1495
1613
|
status: "submitted",
|
|
1496
1614
|
raw: result
|
|
1497
|
-
});
|
|
1615
|
+
}, correlationId);
|
|
1498
1616
|
return result;
|
|
1499
1617
|
} catch (err) {
|
|
1500
1618
|
const error = core.mapUnknownErrorToPartyLayerError(err, {
|
|
1501
1619
|
phase: "submitTransaction",
|
|
1502
1620
|
walletId: String(session.walletId)
|
|
1503
1621
|
});
|
|
1504
|
-
this.emit("error", { type: "error", error });
|
|
1622
|
+
this.emit("error", { type: "error", error }, correlationId);
|
|
1505
1623
|
throw error;
|
|
1506
1624
|
}
|
|
1507
1625
|
}
|
|
@@ -1626,7 +1744,9 @@ var PartyLayerClient = class {
|
|
|
1626
1744
|
const encrypted = await this.crypto.encrypt(data, this.origin);
|
|
1627
1745
|
await this.storage.set(SESSION_STORAGE_KEY, encrypted);
|
|
1628
1746
|
} catch (err) {
|
|
1629
|
-
this.
|
|
1747
|
+
this.log("warn", "session:persist_failed", "Failed to persist session", {
|
|
1748
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1749
|
+
});
|
|
1630
1750
|
}
|
|
1631
1751
|
}
|
|
1632
1752
|
/**
|
|
@@ -1639,7 +1759,9 @@ var PartyLayerClient = class {
|
|
|
1639
1759
|
try {
|
|
1640
1760
|
await this.storage.remove(SESSION_STORAGE_KEY);
|
|
1641
1761
|
} catch (err) {
|
|
1642
|
-
this.
|
|
1762
|
+
this.log("warn", "session:remove_failed", "Failed to remove session", {
|
|
1763
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1764
|
+
});
|
|
1643
1765
|
}
|
|
1644
1766
|
}
|
|
1645
1767
|
/**
|
|
@@ -1647,6 +1769,8 @@ var PartyLayerClient = class {
|
|
|
1647
1769
|
*/
|
|
1648
1770
|
async restoreSession() {
|
|
1649
1771
|
this.telemetry?.increment?.(core.METRICS.RESTORE_ATTEMPTS);
|
|
1772
|
+
const correlationId = newCorrelationId();
|
|
1773
|
+
this.log("debug", "session:restore_start", "restoreSession", {}, correlationId);
|
|
1650
1774
|
try {
|
|
1651
1775
|
const encrypted = await this.storage.get(SESSION_STORAGE_KEY);
|
|
1652
1776
|
if (!encrypted) {
|
|
@@ -1669,17 +1793,17 @@ var PartyLayerClient = class {
|
|
|
1669
1793
|
expected: mismatch.expected,
|
|
1670
1794
|
actual: mismatch.actual,
|
|
1671
1795
|
enforced: this.enforcement !== "off"
|
|
1672
|
-
});
|
|
1796
|
+
}, correlationId);
|
|
1673
1797
|
if (this.enforcement !== "off") {
|
|
1674
|
-
this.
|
|
1798
|
+
this.log("warn", "session:restore_network_mismatch", "Refused session restore: network mismatch", {
|
|
1675
1799
|
expected: mismatch.expected,
|
|
1676
1800
|
actual: mismatch.actual
|
|
1677
|
-
});
|
|
1801
|
+
}, correlationId);
|
|
1678
1802
|
await this.removeSession(session.sessionId);
|
|
1679
1803
|
this.emit("session:expired", {
|
|
1680
1804
|
type: "session:expired",
|
|
1681
1805
|
sessionId: session.sessionId
|
|
1682
|
-
});
|
|
1806
|
+
}, correlationId);
|
|
1683
1807
|
return null;
|
|
1684
1808
|
}
|
|
1685
1809
|
session.networkMismatch = mismatch;
|
|
@@ -1700,14 +1824,14 @@ var PartyLayerClient = class {
|
|
|
1700
1824
|
this.emit("session:connected", {
|
|
1701
1825
|
type: "session:connected",
|
|
1702
1826
|
session: restored
|
|
1703
|
-
});
|
|
1827
|
+
}, correlationId);
|
|
1704
1828
|
return restored;
|
|
1705
1829
|
} else {
|
|
1706
1830
|
await this.removeSession(session.sessionId);
|
|
1707
1831
|
this.emit("session:expired", {
|
|
1708
1832
|
type: "session:expired",
|
|
1709
1833
|
sessionId: session.sessionId
|
|
1710
|
-
});
|
|
1834
|
+
}, correlationId);
|
|
1711
1835
|
return null;
|
|
1712
1836
|
}
|
|
1713
1837
|
}
|
|
@@ -1715,7 +1839,9 @@ var PartyLayerClient = class {
|
|
|
1715
1839
|
this.activeSessionNeedsProbe = true;
|
|
1716
1840
|
return session;
|
|
1717
1841
|
} catch (err) {
|
|
1718
|
-
this.
|
|
1842
|
+
this.log("warn", "session:restore_failed", "Failed to restore session", {
|
|
1843
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1844
|
+
}, correlationId);
|
|
1719
1845
|
return null;
|
|
1720
1846
|
}
|
|
1721
1847
|
}
|
|
@@ -1757,20 +1883,56 @@ var PartyLayerClient = class {
|
|
|
1757
1883
|
/**
|
|
1758
1884
|
* Emit event to handlers
|
|
1759
1885
|
*/
|
|
1760
|
-
|
|
1886
|
+
/**
|
|
1887
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
1888
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
1889
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
1890
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
1891
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
1892
|
+
*/
|
|
1893
|
+
log(level, event, message, fields, correlationId) {
|
|
1894
|
+
if (this.logger instanceof DefaultLogger) return;
|
|
1895
|
+
if (!shouldLog(level, this.logLevel)) return;
|
|
1896
|
+
const payload = {
|
|
1897
|
+
event,
|
|
1898
|
+
...correlationId ? { correlationId } : {},
|
|
1899
|
+
...fields ?? {}
|
|
1900
|
+
};
|
|
1901
|
+
switch (level) {
|
|
1902
|
+
case "debug":
|
|
1903
|
+
this.logger.debug(message, payload);
|
|
1904
|
+
break;
|
|
1905
|
+
case "info":
|
|
1906
|
+
this.logger.info(message, payload);
|
|
1907
|
+
break;
|
|
1908
|
+
case "warn":
|
|
1909
|
+
this.logger.warn(message, payload);
|
|
1910
|
+
break;
|
|
1911
|
+
case "error":
|
|
1912
|
+
this.logger.error(message, payload);
|
|
1913
|
+
break;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
emit(event, payload, correlationId) {
|
|
1761
1917
|
if (event === "error" && "error" in payload) {
|
|
1762
1918
|
const error = payload.error;
|
|
1763
1919
|
if (error.code) {
|
|
1764
1920
|
this.telemetry?.increment?.(core.errorMetricName(error.code));
|
|
1765
1921
|
}
|
|
1766
1922
|
}
|
|
1923
|
+
if (this.telemetry && !(this.telemetry instanceof DefaultTelemetry)) {
|
|
1924
|
+
this.telemetry.track(event, eventTelemetryProperties(payload));
|
|
1925
|
+
}
|
|
1926
|
+
this.log(eventLogLevel(event), event, event, eventTelemetryProperties(payload), correlationId);
|
|
1767
1927
|
const handlers = this.eventHandlers.get(event);
|
|
1768
1928
|
if (handlers) {
|
|
1769
1929
|
for (const handler of handlers) {
|
|
1770
1930
|
try {
|
|
1771
1931
|
handler(payload);
|
|
1772
1932
|
} catch (err) {
|
|
1773
|
-
this.
|
|
1933
|
+
this.log("error", "event:handler_error", "Error in event handler", {
|
|
1934
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1935
|
+
});
|
|
1774
1936
|
}
|
|
1775
1937
|
}
|
|
1776
1938
|
}
|