@unicitylabs/sphere-sdk 0.2.1 → 0.2.2

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.
@@ -1958,6 +1958,11 @@ declare class PaymentsModule {
1958
1958
  * Remove a token by ID
1959
1959
  */
1960
1960
  removeToken(tokenId: string, recipientNametag?: string, skipHistory?: boolean): Promise<void>;
1961
+ /**
1962
+ * Delete physical token file(s) from all storage providers.
1963
+ * Finds files by matching the SDK token ID prefix in the filename.
1964
+ */
1965
+ private deleteTokenFiles;
1961
1966
  /**
1962
1967
  * Get all tombstones
1963
1968
  */
@@ -2271,6 +2276,77 @@ declare const NETWORKS: {
2271
2276
  };
2272
2277
  type NetworkType = keyof typeof NETWORKS;
2273
2278
 
2279
+ /**
2280
+ * Address Scanning — Derive HD addresses and check L1 balances via Fulcrum.
2281
+ *
2282
+ * Used after importing BIP32/.dat wallets to discover which addresses have funds.
2283
+ */
2284
+
2285
+ /** Progress callback for address scanning */
2286
+ interface ScanAddressProgress {
2287
+ /** Number of addresses scanned so far */
2288
+ scanned: number;
2289
+ /** Total addresses to scan (maxAddresses * chains) */
2290
+ total: number;
2291
+ /** Current address being checked */
2292
+ currentAddress: string;
2293
+ /** Number of addresses found with balance */
2294
+ foundCount: number;
2295
+ /** Current gap count (consecutive empty addresses) */
2296
+ currentGap: number;
2297
+ /** Number of found addresses that have a nametag */
2298
+ nametagsFoundCount: number;
2299
+ }
2300
+ /** Single scanned address result */
2301
+ interface ScannedAddressResult {
2302
+ /** HD derivation index */
2303
+ index: number;
2304
+ /** L1 bech32 address (alpha1...) */
2305
+ address: string;
2306
+ /** Full BIP32 derivation path */
2307
+ path: string;
2308
+ /** L1 balance in ALPHA */
2309
+ balance: number;
2310
+ /** Whether this is a change address (chain 1) */
2311
+ isChange: boolean;
2312
+ /** Nametag associated with this address (resolved during scan) */
2313
+ nametag?: string;
2314
+ }
2315
+ /** Options for scanning addresses */
2316
+ interface ScanAddressesOptions {
2317
+ /** Maximum number of addresses to scan per chain (default: 50) */
2318
+ maxAddresses?: number;
2319
+ /** Stop after this many consecutive 0-balance addresses (default: 20) */
2320
+ gapLimit?: number;
2321
+ /** Also scan change addresses (chain 1) (default: true) */
2322
+ includeChange?: boolean;
2323
+ /** Progress callback */
2324
+ onProgress?: (progress: ScanAddressProgress) => void;
2325
+ /** Abort signal for cancellation */
2326
+ signal?: AbortSignal;
2327
+ /** Resolve nametag for a found address. Return nametag string or null. */
2328
+ resolveNametag?: (l1Address: string) => Promise<string | null>;
2329
+ }
2330
+ /** Result of scanning */
2331
+ interface ScanAddressesResult {
2332
+ /** All addresses found with non-zero balance */
2333
+ addresses: ScannedAddressResult[];
2334
+ /** Total balance across all found addresses (in ALPHA) */
2335
+ totalBalance: number;
2336
+ /** Number of addresses actually scanned */
2337
+ scannedCount: number;
2338
+ }
2339
+ /**
2340
+ * Scan blockchain addresses to discover used addresses with balances.
2341
+ * Derives addresses sequentially and checks L1 balance via Fulcrum.
2342
+ * Uses gap limit to stop after N consecutive empty addresses.
2343
+ *
2344
+ * @param deriveAddress - Function to derive an address at a given index
2345
+ * @param options - Scanning options
2346
+ * @returns Scan results with found addresses and total balance
2347
+ */
2348
+ declare function scanAddressesImpl(deriveAddress: (index: number, isChange: boolean) => AddressInfo, options?: ScanAddressesOptions): Promise<ScanAddressesResult>;
2349
+
2274
2350
  /**
2275
2351
  * Legacy File Serialization Types
2276
2352
  */
@@ -2848,6 +2924,35 @@ declare class Sphere {
2848
2924
  * ```
2849
2925
  */
2850
2926
  deriveAddresses(count: number, includeChange?: boolean): AddressInfo[];
2927
+ /**
2928
+ * Scan blockchain addresses to discover used addresses with balances.
2929
+ * Derives addresses sequentially and checks L1 balance via Fulcrum.
2930
+ * Uses gap limit to stop after N consecutive empty addresses.
2931
+ *
2932
+ * @param options - Scanning options
2933
+ * @returns Scan results with found addresses and total balance
2934
+ *
2935
+ * @example
2936
+ * ```ts
2937
+ * const result = await sphere.scanAddresses({
2938
+ * maxAddresses: 100,
2939
+ * gapLimit: 20,
2940
+ * onProgress: (p) => console.log(`Scanned ${p.scanned}/${p.total}, found ${p.foundCount}`),
2941
+ * });
2942
+ * console.log(`Found ${result.addresses.length} addresses, total: ${result.totalBalance} ALPHA`);
2943
+ * ```
2944
+ */
2945
+ scanAddresses(options?: ScanAddressesOptions): Promise<ScanAddressesResult>;
2946
+ /**
2947
+ * Bulk-track scanned addresses with visibility and nametag data.
2948
+ * Selected addresses get `hidden: false`, unselected get `hidden: true`.
2949
+ * Performs only 2 storage writes total (tracked addresses + nametags).
2950
+ */
2951
+ trackScannedAddresses(entries: Array<{
2952
+ index: number;
2953
+ hidden: boolean;
2954
+ nametag?: string;
2955
+ }>): Promise<void>;
2851
2956
  getStatus(): {
2852
2957
  storage: {
2853
2958
  connected: boolean;
@@ -3064,6 +3169,11 @@ declare function encryptSimple(plaintext: string, password: string): string;
3064
3169
  * @param password - Decryption password
3065
3170
  */
3066
3171
  declare function decryptSimple(ciphertext: string, password: string): string;
3172
+ /**
3173
+ * Decrypt data encrypted with PBKDF2-derived key (legacy JSON wallet format).
3174
+ * Compatible with webwallet's encryptWithPassword/decryptWithPassword.
3175
+ */
3176
+ declare function decryptWithSalt(ciphertext: string, password: string, salt: string): string | null;
3067
3177
  /**
3068
3178
  * Encrypt mnemonic phrase for storage
3069
3179
  * Uses simple AES encryption compatible with existing wallet format
@@ -3257,4 +3367,4 @@ declare function randomHex(byteLength: number): string;
3257
3367
  */
3258
3368
  declare function randomUUID(): string;
3259
3369
 
3260
- export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, type KeyPair, type L1Config, type MasterKey, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, 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, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
3370
+ export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, 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, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, 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, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
@@ -1958,6 +1958,11 @@ declare class PaymentsModule {
1958
1958
  * Remove a token by ID
1959
1959
  */
1960
1960
  removeToken(tokenId: string, recipientNametag?: string, skipHistory?: boolean): Promise<void>;
1961
+ /**
1962
+ * Delete physical token file(s) from all storage providers.
1963
+ * Finds files by matching the SDK token ID prefix in the filename.
1964
+ */
1965
+ private deleteTokenFiles;
1961
1966
  /**
1962
1967
  * Get all tombstones
1963
1968
  */
@@ -2271,6 +2276,77 @@ declare const NETWORKS: {
2271
2276
  };
2272
2277
  type NetworkType = keyof typeof NETWORKS;
2273
2278
 
2279
+ /**
2280
+ * Address Scanning — Derive HD addresses and check L1 balances via Fulcrum.
2281
+ *
2282
+ * Used after importing BIP32/.dat wallets to discover which addresses have funds.
2283
+ */
2284
+
2285
+ /** Progress callback for address scanning */
2286
+ interface ScanAddressProgress {
2287
+ /** Number of addresses scanned so far */
2288
+ scanned: number;
2289
+ /** Total addresses to scan (maxAddresses * chains) */
2290
+ total: number;
2291
+ /** Current address being checked */
2292
+ currentAddress: string;
2293
+ /** Number of addresses found with balance */
2294
+ foundCount: number;
2295
+ /** Current gap count (consecutive empty addresses) */
2296
+ currentGap: number;
2297
+ /** Number of found addresses that have a nametag */
2298
+ nametagsFoundCount: number;
2299
+ }
2300
+ /** Single scanned address result */
2301
+ interface ScannedAddressResult {
2302
+ /** HD derivation index */
2303
+ index: number;
2304
+ /** L1 bech32 address (alpha1...) */
2305
+ address: string;
2306
+ /** Full BIP32 derivation path */
2307
+ path: string;
2308
+ /** L1 balance in ALPHA */
2309
+ balance: number;
2310
+ /** Whether this is a change address (chain 1) */
2311
+ isChange: boolean;
2312
+ /** Nametag associated with this address (resolved during scan) */
2313
+ nametag?: string;
2314
+ }
2315
+ /** Options for scanning addresses */
2316
+ interface ScanAddressesOptions {
2317
+ /** Maximum number of addresses to scan per chain (default: 50) */
2318
+ maxAddresses?: number;
2319
+ /** Stop after this many consecutive 0-balance addresses (default: 20) */
2320
+ gapLimit?: number;
2321
+ /** Also scan change addresses (chain 1) (default: true) */
2322
+ includeChange?: boolean;
2323
+ /** Progress callback */
2324
+ onProgress?: (progress: ScanAddressProgress) => void;
2325
+ /** Abort signal for cancellation */
2326
+ signal?: AbortSignal;
2327
+ /** Resolve nametag for a found address. Return nametag string or null. */
2328
+ resolveNametag?: (l1Address: string) => Promise<string | null>;
2329
+ }
2330
+ /** Result of scanning */
2331
+ interface ScanAddressesResult {
2332
+ /** All addresses found with non-zero balance */
2333
+ addresses: ScannedAddressResult[];
2334
+ /** Total balance across all found addresses (in ALPHA) */
2335
+ totalBalance: number;
2336
+ /** Number of addresses actually scanned */
2337
+ scannedCount: number;
2338
+ }
2339
+ /**
2340
+ * Scan blockchain addresses to discover used addresses with balances.
2341
+ * Derives addresses sequentially and checks L1 balance via Fulcrum.
2342
+ * Uses gap limit to stop after N consecutive empty addresses.
2343
+ *
2344
+ * @param deriveAddress - Function to derive an address at a given index
2345
+ * @param options - Scanning options
2346
+ * @returns Scan results with found addresses and total balance
2347
+ */
2348
+ declare function scanAddressesImpl(deriveAddress: (index: number, isChange: boolean) => AddressInfo, options?: ScanAddressesOptions): Promise<ScanAddressesResult>;
2349
+
2274
2350
  /**
2275
2351
  * Legacy File Serialization Types
2276
2352
  */
@@ -2848,6 +2924,35 @@ declare class Sphere {
2848
2924
  * ```
2849
2925
  */
2850
2926
  deriveAddresses(count: number, includeChange?: boolean): AddressInfo[];
2927
+ /**
2928
+ * Scan blockchain addresses to discover used addresses with balances.
2929
+ * Derives addresses sequentially and checks L1 balance via Fulcrum.
2930
+ * Uses gap limit to stop after N consecutive empty addresses.
2931
+ *
2932
+ * @param options - Scanning options
2933
+ * @returns Scan results with found addresses and total balance
2934
+ *
2935
+ * @example
2936
+ * ```ts
2937
+ * const result = await sphere.scanAddresses({
2938
+ * maxAddresses: 100,
2939
+ * gapLimit: 20,
2940
+ * onProgress: (p) => console.log(`Scanned ${p.scanned}/${p.total}, found ${p.foundCount}`),
2941
+ * });
2942
+ * console.log(`Found ${result.addresses.length} addresses, total: ${result.totalBalance} ALPHA`);
2943
+ * ```
2944
+ */
2945
+ scanAddresses(options?: ScanAddressesOptions): Promise<ScanAddressesResult>;
2946
+ /**
2947
+ * Bulk-track scanned addresses with visibility and nametag data.
2948
+ * Selected addresses get `hidden: false`, unselected get `hidden: true`.
2949
+ * Performs only 2 storage writes total (tracked addresses + nametags).
2950
+ */
2951
+ trackScannedAddresses(entries: Array<{
2952
+ index: number;
2953
+ hidden: boolean;
2954
+ nametag?: string;
2955
+ }>): Promise<void>;
2851
2956
  getStatus(): {
2852
2957
  storage: {
2853
2958
  connected: boolean;
@@ -3064,6 +3169,11 @@ declare function encryptSimple(plaintext: string, password: string): string;
3064
3169
  * @param password - Decryption password
3065
3170
  */
3066
3171
  declare function decryptSimple(ciphertext: string, password: string): string;
3172
+ /**
3173
+ * Decrypt data encrypted with PBKDF2-derived key (legacy JSON wallet format).
3174
+ * Compatible with webwallet's encryptWithPassword/decryptWithPassword.
3175
+ */
3176
+ declare function decryptWithSalt(ciphertext: string, password: string, salt: string): string | null;
3067
3177
  /**
3068
3178
  * Encrypt mnemonic phrase for storage
3069
3179
  * Uses simple AES encryption compatible with existing wallet format
@@ -3257,4 +3367,4 @@ declare function randomHex(byteLength: number): string;
3257
3367
  */
3258
3368
  declare function randomUUID(): string;
3259
3369
 
3260
- export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, type KeyPair, type L1Config, type MasterKey, Sphere, type SphereCreateOptions, type SphereImportOptions, type SphereInitOptions, type SphereInitResult, type SphereLoadOptions, base58Decode, base58Encode, bytesToHex, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, 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, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };
3370
+ export { type AddressInfo, CHARSET, CurrencyUtils, DEFAULT_DERIVATION_PATH, DEFAULT_TOKEN_DECIMALS, type DerivedKey, type EncryptedData, type EncryptionOptions, 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, computeHash160, convertBits, createAddress, createBech32, createKeyPair, createSphere, decodeBech32, decrypt, decryptJson, decryptMnemonic, decryptSimple, decryptWithSalt, deriveAddressInfo, deriveChildKey, deriveKeyAtPath, deserializeEncrypted, 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, isValidPrivateKey, loadSphere, mnemonicToEntropy, mnemonicToSeed, mnemonicToSeedSync, privateKeyToAddressInfo, publicKeyToAddress, randomBytes, randomHex, randomUUID, ripemd160, scanAddressesImpl, serializeEncrypted, sha256, sleep, sphereExists, toHumanReadable, toSmallestUnit, validateMnemonic };