@unicitylabs/sphere-sdk 0.5.3 → 0.5.5
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/README.md +2 -0
- package/dist/connect/index.cjs +145 -23
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.d.cts +15 -2
- package/dist/connect/index.d.ts +15 -2
- package/dist/connect/index.js +145 -23
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +670 -473
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +123 -2
- package/dist/core/index.d.ts +123 -2
- package/dist/core/index.js +667 -473
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +119 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.d.cts +53 -1
- package/dist/impl/browser/connect/index.d.ts +53 -1
- package/dist/impl/browser/connect/index.js +119 -1
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +306 -193
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +306 -193
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +134 -19
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +134 -19
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/connect/index.cjs +101 -6
- package/dist/impl/nodejs/connect/index.cjs.map +1 -1
- package/dist/impl/nodejs/connect/index.d.cts +2 -0
- package/dist/impl/nodejs/connect/index.d.ts +2 -0
- package/dist/impl/nodejs/connect/index.js +101 -6
- package/dist/impl/nodejs/connect/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +267 -152
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +2 -1
- package/dist/impl/nodejs/index.d.ts +2 -1
- package/dist/impl/nodejs/index.js +267 -152
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +682 -493
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -8
- package/dist/index.d.ts +124 -8
- package/dist/index.js +680 -493
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs +139 -32
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.js +139 -32
- package/dist/l1/index.js.map +1 -1
- package/package.json +1 -16
package/dist/core/index.d.cts
CHANGED
|
@@ -68,6 +68,42 @@ interface CreateGroupOptions {
|
|
|
68
68
|
visibility?: GroupVisibility;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* SDK Error Types
|
|
73
|
+
*
|
|
74
|
+
* Structured error codes for programmatic error handling in UI.
|
|
75
|
+
* UI can switch on error.code to show appropriate user-facing messages.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { SphereError } from '@unicitylabs/sphere-sdk';
|
|
80
|
+
*
|
|
81
|
+
* try {
|
|
82
|
+
* await sphere.payments.send({ ... });
|
|
83
|
+
* } catch (err) {
|
|
84
|
+
* if (err instanceof SphereError) {
|
|
85
|
+
* switch (err.code) {
|
|
86
|
+
* case 'INSUFFICIENT_BALANCE': showToast('Not enough funds'); break;
|
|
87
|
+
* case 'INVALID_RECIPIENT': showToast('Recipient not found'); break;
|
|
88
|
+
* case 'TRANSPORT_ERROR': showToast('Network connection issue'); break;
|
|
89
|
+
* case 'TIMEOUT': showToast('Request timed out, try again'); break;
|
|
90
|
+
* default: showToast(err.message);
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE';
|
|
97
|
+
declare class SphereError extends Error {
|
|
98
|
+
readonly code: SphereErrorCode;
|
|
99
|
+
readonly cause?: unknown;
|
|
100
|
+
constructor(message: string, code: SphereErrorCode, cause?: unknown);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Type guard to check if an error is a SphereError
|
|
104
|
+
*/
|
|
105
|
+
declare function isSphereError(err: unknown): err is SphereError;
|
|
106
|
+
|
|
71
107
|
/**
|
|
72
108
|
* Cryptographic utilities for SDK2
|
|
73
109
|
*
|
|
@@ -1957,7 +1993,6 @@ declare class PaymentsModule {
|
|
|
1957
1993
|
getConfig(): Omit<Required<PaymentsModuleConfig>, 'l1'>;
|
|
1958
1994
|
/** Price provider (optional) */
|
|
1959
1995
|
private priceProvider;
|
|
1960
|
-
private log;
|
|
1961
1996
|
/**
|
|
1962
1997
|
* Initialize module with dependencies
|
|
1963
1998
|
*/
|
|
@@ -3346,6 +3381,8 @@ interface SphereCreateOptions {
|
|
|
3346
3381
|
* - false/undefined: no auto-discovery (default)
|
|
3347
3382
|
*/
|
|
3348
3383
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3384
|
+
/** Enable debug logging (default: false) */
|
|
3385
|
+
debug?: boolean;
|
|
3349
3386
|
/** Optional callback to report initialization progress steps */
|
|
3350
3387
|
onProgress?: InitProgressCallback;
|
|
3351
3388
|
}
|
|
@@ -3382,6 +3419,8 @@ interface SphereLoadOptions {
|
|
|
3382
3419
|
* - false/undefined: no auto-discovery (default)
|
|
3383
3420
|
*/
|
|
3384
3421
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3422
|
+
/** Enable debug logging (default: false) */
|
|
3423
|
+
debug?: boolean;
|
|
3385
3424
|
/** Optional callback to report initialization progress steps */
|
|
3386
3425
|
onProgress?: InitProgressCallback;
|
|
3387
3426
|
}
|
|
@@ -3426,6 +3465,8 @@ interface SphereImportOptions {
|
|
|
3426
3465
|
* - false/undefined: no auto-discovery (default)
|
|
3427
3466
|
*/
|
|
3428
3467
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3468
|
+
/** Enable debug logging (default: false) */
|
|
3469
|
+
debug?: boolean;
|
|
3429
3470
|
/** Optional callback to report initialization progress steps */
|
|
3430
3471
|
onProgress?: InitProgressCallback;
|
|
3431
3472
|
}
|
|
@@ -3485,6 +3526,8 @@ interface SphereInitOptions {
|
|
|
3485
3526
|
* - false/undefined: no auto-discovery (default)
|
|
3486
3527
|
*/
|
|
3487
3528
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3529
|
+
/** Enable debug logging (default: false) */
|
|
3530
|
+
debug?: boolean;
|
|
3488
3531
|
/** Optional callback to report initialization progress steps */
|
|
3489
3532
|
onProgress?: InitProgressCallback;
|
|
3490
3533
|
}
|
|
@@ -4469,6 +4512,84 @@ declare function randomHex(byteLength: number): string;
|
|
|
4469
4512
|
*/
|
|
4470
4513
|
declare function randomUUID(): string;
|
|
4471
4514
|
|
|
4515
|
+
/**
|
|
4516
|
+
* Centralized SDK Logger
|
|
4517
|
+
*
|
|
4518
|
+
* A lightweight singleton logger that works across all tsup bundles
|
|
4519
|
+
* by storing state on globalThis. Supports three log levels:
|
|
4520
|
+
* - debug: detailed messages (only shown when debug=true)
|
|
4521
|
+
* - warn: important warnings (ALWAYS shown regardless of debug flag)
|
|
4522
|
+
* - error: critical errors (ALWAYS shown regardless of debug flag)
|
|
4523
|
+
*
|
|
4524
|
+
* Global debug flag enables all logging. Per-tag overrides allow
|
|
4525
|
+
* granular control (e.g., only transport debug).
|
|
4526
|
+
*
|
|
4527
|
+
* @example
|
|
4528
|
+
* ```ts
|
|
4529
|
+
* import { logger } from '@unicitylabs/sphere-sdk';
|
|
4530
|
+
*
|
|
4531
|
+
* // Enable all debug logging
|
|
4532
|
+
* logger.configure({ debug: true });
|
|
4533
|
+
*
|
|
4534
|
+
* // Enable only specific tags
|
|
4535
|
+
* logger.setTagDebug('Nostr', true);
|
|
4536
|
+
*
|
|
4537
|
+
* // Usage in SDK classes
|
|
4538
|
+
* logger.debug('Payments', 'Transfer started', { amount, recipient });
|
|
4539
|
+
* logger.warn('Nostr', 'queryEvents timed out after 5s');
|
|
4540
|
+
* logger.error('Sphere', 'Critical failure', error);
|
|
4541
|
+
* ```
|
|
4542
|
+
*/
|
|
4543
|
+
type LogLevel = 'debug' | 'warn' | 'error';
|
|
4544
|
+
type LogHandler = (level: LogLevel, tag: string, message: string, ...args: unknown[]) => void;
|
|
4545
|
+
interface LoggerConfig {
|
|
4546
|
+
/** Enable debug logging globally (default: false). When false, only warn and error messages are shown. */
|
|
4547
|
+
debug?: boolean;
|
|
4548
|
+
/** Custom log handler. If provided, replaces console output. Useful for tests or custom log sinks. */
|
|
4549
|
+
handler?: LogHandler | null;
|
|
4550
|
+
}
|
|
4551
|
+
declare const logger: {
|
|
4552
|
+
/**
|
|
4553
|
+
* Configure the logger. Can be called multiple times (last write wins).
|
|
4554
|
+
* Typically called by createBrowserProviders(), createNodeProviders(), or Sphere.init().
|
|
4555
|
+
*/
|
|
4556
|
+
configure(config: LoggerConfig): void;
|
|
4557
|
+
/**
|
|
4558
|
+
* Enable/disable debug logging for a specific tag.
|
|
4559
|
+
* Per-tag setting overrides the global debug flag.
|
|
4560
|
+
*
|
|
4561
|
+
* @example
|
|
4562
|
+
* ```ts
|
|
4563
|
+
* logger.setTagDebug('Nostr', true); // enable only Nostr logs
|
|
4564
|
+
* logger.setTagDebug('Nostr', false); // disable Nostr logs even if global debug=true
|
|
4565
|
+
* ```
|
|
4566
|
+
*/
|
|
4567
|
+
setTagDebug(tag: string, enabled: boolean): void;
|
|
4568
|
+
/**
|
|
4569
|
+
* Clear per-tag override, falling back to global debug flag.
|
|
4570
|
+
*/
|
|
4571
|
+
clearTagDebug(tag: string): void;
|
|
4572
|
+
/** Returns true if debug mode is enabled for the given tag (or globally). */
|
|
4573
|
+
isDebugEnabled(tag?: string): boolean;
|
|
4574
|
+
/**
|
|
4575
|
+
* Debug-level log. Only shown when debug is enabled (globally or for this tag).
|
|
4576
|
+
* Use for detailed operational information.
|
|
4577
|
+
*/
|
|
4578
|
+
debug(tag: string, message: string, ...args: unknown[]): void;
|
|
4579
|
+
/**
|
|
4580
|
+
* Warning-level log. ALWAYS shown regardless of debug flag.
|
|
4581
|
+
* Use for important but non-critical issues (timeouts, retries, degraded state).
|
|
4582
|
+
*/
|
|
4583
|
+
warn(tag: string, message: string, ...args: unknown[]): void;
|
|
4584
|
+
/**
|
|
4585
|
+
* Error-level log. ALWAYS shown regardless of debug flag.
|
|
4586
|
+
* Use for critical failures that should never be silenced.
|
|
4587
|
+
*/
|
|
4588
|
+
error(tag: string, message: string, ...args: unknown[]): void;
|
|
4589
|
+
/** Reset all logger state (debug flag, tags, handler). Primarily for tests. */
|
|
4590
|
+
reset(): void;
|
|
4591
|
+
};
|
|
4592
|
+
|
|
4472
4593
|
/**
|
|
4473
4594
|
* Network Health Check
|
|
4474
4595
|
*
|
|
@@ -4566,4 +4687,4 @@ interface CheckNetworkHealthOptions {
|
|
|
4566
4687
|
*/
|
|
4567
4688
|
declare function checkNetworkHealth(network?: NetworkType, options?: CheckNetworkHealthOptions): Promise<NetworkHealthResult>;
|
|
4568
4689
|
|
|
4569
|
-
export { type AddressInfo, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|
|
4690
|
+
export { type AddressInfo, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type LogHandler, type LogLevel, type LoggerConfig, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isSphereError, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, logger, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -68,6 +68,42 @@ interface CreateGroupOptions {
|
|
|
68
68
|
visibility?: GroupVisibility;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
/**
|
|
72
|
+
* SDK Error Types
|
|
73
|
+
*
|
|
74
|
+
* Structured error codes for programmatic error handling in UI.
|
|
75
|
+
* UI can switch on error.code to show appropriate user-facing messages.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { SphereError } from '@unicitylabs/sphere-sdk';
|
|
80
|
+
*
|
|
81
|
+
* try {
|
|
82
|
+
* await sphere.payments.send({ ... });
|
|
83
|
+
* } catch (err) {
|
|
84
|
+
* if (err instanceof SphereError) {
|
|
85
|
+
* switch (err.code) {
|
|
86
|
+
* case 'INSUFFICIENT_BALANCE': showToast('Not enough funds'); break;
|
|
87
|
+
* case 'INVALID_RECIPIENT': showToast('Recipient not found'); break;
|
|
88
|
+
* case 'TRANSPORT_ERROR': showToast('Network connection issue'); break;
|
|
89
|
+
* case 'TIMEOUT': showToast('Request timed out, try again'); break;
|
|
90
|
+
* default: showToast(err.message);
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
type SphereErrorCode = 'NOT_INITIALIZED' | 'ALREADY_INITIALIZED' | 'INVALID_CONFIG' | 'INVALID_IDENTITY' | 'INSUFFICIENT_BALANCE' | 'INVALID_RECIPIENT' | 'TRANSFER_FAILED' | 'STORAGE_ERROR' | 'TRANSPORT_ERROR' | 'AGGREGATOR_ERROR' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'DECRYPTION_ERROR' | 'MODULE_NOT_AVAILABLE';
|
|
97
|
+
declare class SphereError extends Error {
|
|
98
|
+
readonly code: SphereErrorCode;
|
|
99
|
+
readonly cause?: unknown;
|
|
100
|
+
constructor(message: string, code: SphereErrorCode, cause?: unknown);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Type guard to check if an error is a SphereError
|
|
104
|
+
*/
|
|
105
|
+
declare function isSphereError(err: unknown): err is SphereError;
|
|
106
|
+
|
|
71
107
|
/**
|
|
72
108
|
* Cryptographic utilities for SDK2
|
|
73
109
|
*
|
|
@@ -1957,7 +1993,6 @@ declare class PaymentsModule {
|
|
|
1957
1993
|
getConfig(): Omit<Required<PaymentsModuleConfig>, 'l1'>;
|
|
1958
1994
|
/** Price provider (optional) */
|
|
1959
1995
|
private priceProvider;
|
|
1960
|
-
private log;
|
|
1961
1996
|
/**
|
|
1962
1997
|
* Initialize module with dependencies
|
|
1963
1998
|
*/
|
|
@@ -3346,6 +3381,8 @@ interface SphereCreateOptions {
|
|
|
3346
3381
|
* - false/undefined: no auto-discovery (default)
|
|
3347
3382
|
*/
|
|
3348
3383
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3384
|
+
/** Enable debug logging (default: false) */
|
|
3385
|
+
debug?: boolean;
|
|
3349
3386
|
/** Optional callback to report initialization progress steps */
|
|
3350
3387
|
onProgress?: InitProgressCallback;
|
|
3351
3388
|
}
|
|
@@ -3382,6 +3419,8 @@ interface SphereLoadOptions {
|
|
|
3382
3419
|
* - false/undefined: no auto-discovery (default)
|
|
3383
3420
|
*/
|
|
3384
3421
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3422
|
+
/** Enable debug logging (default: false) */
|
|
3423
|
+
debug?: boolean;
|
|
3385
3424
|
/** Optional callback to report initialization progress steps */
|
|
3386
3425
|
onProgress?: InitProgressCallback;
|
|
3387
3426
|
}
|
|
@@ -3426,6 +3465,8 @@ interface SphereImportOptions {
|
|
|
3426
3465
|
* - false/undefined: no auto-discovery (default)
|
|
3427
3466
|
*/
|
|
3428
3467
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3468
|
+
/** Enable debug logging (default: false) */
|
|
3469
|
+
debug?: boolean;
|
|
3429
3470
|
/** Optional callback to report initialization progress steps */
|
|
3430
3471
|
onProgress?: InitProgressCallback;
|
|
3431
3472
|
}
|
|
@@ -3485,6 +3526,8 @@ interface SphereInitOptions {
|
|
|
3485
3526
|
* - false/undefined: no auto-discovery (default)
|
|
3486
3527
|
*/
|
|
3487
3528
|
discoverAddresses?: boolean | DiscoverAddressesOptions;
|
|
3529
|
+
/** Enable debug logging (default: false) */
|
|
3530
|
+
debug?: boolean;
|
|
3488
3531
|
/** Optional callback to report initialization progress steps */
|
|
3489
3532
|
onProgress?: InitProgressCallback;
|
|
3490
3533
|
}
|
|
@@ -4469,6 +4512,84 @@ declare function randomHex(byteLength: number): string;
|
|
|
4469
4512
|
*/
|
|
4470
4513
|
declare function randomUUID(): string;
|
|
4471
4514
|
|
|
4515
|
+
/**
|
|
4516
|
+
* Centralized SDK Logger
|
|
4517
|
+
*
|
|
4518
|
+
* A lightweight singleton logger that works across all tsup bundles
|
|
4519
|
+
* by storing state on globalThis. Supports three log levels:
|
|
4520
|
+
* - debug: detailed messages (only shown when debug=true)
|
|
4521
|
+
* - warn: important warnings (ALWAYS shown regardless of debug flag)
|
|
4522
|
+
* - error: critical errors (ALWAYS shown regardless of debug flag)
|
|
4523
|
+
*
|
|
4524
|
+
* Global debug flag enables all logging. Per-tag overrides allow
|
|
4525
|
+
* granular control (e.g., only transport debug).
|
|
4526
|
+
*
|
|
4527
|
+
* @example
|
|
4528
|
+
* ```ts
|
|
4529
|
+
* import { logger } from '@unicitylabs/sphere-sdk';
|
|
4530
|
+
*
|
|
4531
|
+
* // Enable all debug logging
|
|
4532
|
+
* logger.configure({ debug: true });
|
|
4533
|
+
*
|
|
4534
|
+
* // Enable only specific tags
|
|
4535
|
+
* logger.setTagDebug('Nostr', true);
|
|
4536
|
+
*
|
|
4537
|
+
* // Usage in SDK classes
|
|
4538
|
+
* logger.debug('Payments', 'Transfer started', { amount, recipient });
|
|
4539
|
+
* logger.warn('Nostr', 'queryEvents timed out after 5s');
|
|
4540
|
+
* logger.error('Sphere', 'Critical failure', error);
|
|
4541
|
+
* ```
|
|
4542
|
+
*/
|
|
4543
|
+
type LogLevel = 'debug' | 'warn' | 'error';
|
|
4544
|
+
type LogHandler = (level: LogLevel, tag: string, message: string, ...args: unknown[]) => void;
|
|
4545
|
+
interface LoggerConfig {
|
|
4546
|
+
/** Enable debug logging globally (default: false). When false, only warn and error messages are shown. */
|
|
4547
|
+
debug?: boolean;
|
|
4548
|
+
/** Custom log handler. If provided, replaces console output. Useful for tests or custom log sinks. */
|
|
4549
|
+
handler?: LogHandler | null;
|
|
4550
|
+
}
|
|
4551
|
+
declare const logger: {
|
|
4552
|
+
/**
|
|
4553
|
+
* Configure the logger. Can be called multiple times (last write wins).
|
|
4554
|
+
* Typically called by createBrowserProviders(), createNodeProviders(), or Sphere.init().
|
|
4555
|
+
*/
|
|
4556
|
+
configure(config: LoggerConfig): void;
|
|
4557
|
+
/**
|
|
4558
|
+
* Enable/disable debug logging for a specific tag.
|
|
4559
|
+
* Per-tag setting overrides the global debug flag.
|
|
4560
|
+
*
|
|
4561
|
+
* @example
|
|
4562
|
+
* ```ts
|
|
4563
|
+
* logger.setTagDebug('Nostr', true); // enable only Nostr logs
|
|
4564
|
+
* logger.setTagDebug('Nostr', false); // disable Nostr logs even if global debug=true
|
|
4565
|
+
* ```
|
|
4566
|
+
*/
|
|
4567
|
+
setTagDebug(tag: string, enabled: boolean): void;
|
|
4568
|
+
/**
|
|
4569
|
+
* Clear per-tag override, falling back to global debug flag.
|
|
4570
|
+
*/
|
|
4571
|
+
clearTagDebug(tag: string): void;
|
|
4572
|
+
/** Returns true if debug mode is enabled for the given tag (or globally). */
|
|
4573
|
+
isDebugEnabled(tag?: string): boolean;
|
|
4574
|
+
/**
|
|
4575
|
+
* Debug-level log. Only shown when debug is enabled (globally or for this tag).
|
|
4576
|
+
* Use for detailed operational information.
|
|
4577
|
+
*/
|
|
4578
|
+
debug(tag: string, message: string, ...args: unknown[]): void;
|
|
4579
|
+
/**
|
|
4580
|
+
* Warning-level log. ALWAYS shown regardless of debug flag.
|
|
4581
|
+
* Use for important but non-critical issues (timeouts, retries, degraded state).
|
|
4582
|
+
*/
|
|
4583
|
+
warn(tag: string, message: string, ...args: unknown[]): void;
|
|
4584
|
+
/**
|
|
4585
|
+
* Error-level log. ALWAYS shown regardless of debug flag.
|
|
4586
|
+
* Use for critical failures that should never be silenced.
|
|
4587
|
+
*/
|
|
4588
|
+
error(tag: string, message: string, ...args: unknown[]): void;
|
|
4589
|
+
/** Reset all logger state (debug flag, tags, handler). Primarily for tests. */
|
|
4590
|
+
reset(): void;
|
|
4591
|
+
};
|
|
4592
|
+
|
|
4472
4593
|
/**
|
|
4473
4594
|
* Network Health Check
|
|
4474
4595
|
*
|
|
@@ -4566,4 +4687,4 @@ interface CheckNetworkHealthOptions {
|
|
|
4566
4687
|
*/
|
|
4567
4688
|
declare function checkNetworkHealth(network?: NetworkType, options?: CheckNetworkHealthOptions): Promise<NetworkHealthResult>;
|
|
4568
4689
|
|
|
4569
|
-
export { type AddressInfo, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|
|
4690
|
+
export { type AddressInfo, CHARSET, type CheckNetworkHealthOptions, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type DiscoverAddressProgress, type DiscoverAddressesOptions, type DiscoverAddressesResult, type DiscoveredAddress, type EncryptedData, type EncryptionOptions, type InitProgress, type InitProgressCallback, type InitProgressStep, type KeyPair, type L1Config, type LogHandler, type LogLevel, type LoggerConfig, type MasterKey, type ScanAddressProgress, type ScanAddressesOptions, type ScanAddressesResult, type ScannedAddressResult, Sphere, type SphereCreateOptions, SphereError, type SphereErrorCode, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, checkNetworkHealth, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, discoverAddressesImpl, doubleSha256, ec, encodeBech32, encrypt, encryptMnemonic, encryptSimple, entropyToMnemonic, extractFromText, findPattern, formatAmount, generateAddressInfo, generateMasterKey, generateMnemonic, generateRandomKey, getAddressHrp, getPublicKey, getSphere, hash160, hash160ToBytes, hexToBytes, identityFromMnemonic, identityFromMnemonicSync, importSphere, initSphere, isEncryptedData, isSphereError, isValidBech32, isValidNametag, isValidPrivateKey, loadSphere, logger, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
|