shield-bridge-sdk
Version:
594 lines • 31 kB
TypeScript
import { BlockResponse } from '@tezos-x/octez.js-rpc';
import type { ContractArchitecture, ShieldParams, UnshieldParams, TransferParams, SaplingTokenInfo, TransactionProgressCallbacks, ShieldBridgeSDKConfig, OrderedTransactionList, SaplingDeposits, SaplingTransactions, ShieldedAssetInfo } from './types.js';
export type { ContractArchitecture, AmountInput, ShieldParams, UnshieldParams, TransferParams, SaplingTokenInfo, TransactionProgressCallbacks, ShieldBridgeSDKConfig, FactoryStorage, ShieldedAssetInfo, TokenMetadata, TzKTTokenBalance, } from './types.js';
export { shieldBridgeContract, saplingFactoryContract, saplingMapContract, saplingStateMapContract, tzktApiMap, } from './constants.js';
export { SaplingWorkerPool, DEFAULT_POOL_SIZE, DEFAULT_IDLE_TIMEOUT_MS, } from './workerPool.js';
export type { PoolEntry } from './workerPool.js';
export type { SaplingWorkerCore } from './saplingCore.js';
export { MemoryDiffStore, IndexedDbDiffStore, createDefaultDiffStore, makeCachingReadProvider, } from './saplingDiffCache.js';
export type { SaplingDiffStore, CachedSaplingDiff, SaplingDiffResponse, } from './saplingDiffCache.js';
/**
* Realign an `estimate.batch()` result with the ops we asked it to estimate, for an UNREVEALED
* source account.
*
* octez.js auto-prepends a reveal operation when the source's public key isn't yet on-chain, and
* `estimate.batch()` returns that reveal's Estimate as element [0] — but, unlike its single-op
* estimators (`contractCall`/`transfer`/…, which call `estimateProperties.shift()`), it deliberately
* does NOT drop it (see RPCEstimateProvider.batch). We pin gasLimit/storageLimit/fee POSITIONALLY per
* op, so a stray leading reveal estimate mis-gasses everything: op0 gets the reveal's ~1000-gas
* limits, every op is shifted by one, and the last op's estimate is silently dropped — the node then
* rejects the broadcast with gas_exhausted / fees_too_low. (This is why a fresh wallet "fails on
* simulate" until revealed out-of-band.)
*
* Drop the leading reveal estimate so the array maps 1:1 onto our ops; the wallet re-adds and funds
* the actual reveal at injection time. No-op for an already-revealed source (length === opCount).
*/
export declare function realignEstimatesForReveal<T>(estimates: T[], expectedOpCount: number): T[];
/**
* ShieldBridgeSDK provides an abstraction to interact with the Shield Bridge smart contract
* to shield, unshield, and transfer sapling tokens.
*
* The SDK supports two modes of operation:
*
* 1. **Full Access Mode** (with spending key or mnemonic):
* - Can perform all operations: shield, unshield, transfer
* - Can query balances and transactions
* - Can export viewing keys for read-only access
*
* 2. **View-Only Mode** (with viewing key):
* - Can only query balances and transactions
* - Cannot perform transaction operations
* - Useful for auditing, monitoring, and compliance
*
* @class
* @param {ShieldBridgeSDKConfig} config The configuration object for the Shield Bridge SDK
* @param {TezosToolkit} config.client The TezosToolkit instance
* @param {'mainnet' | 'shadownet'} [config.tzktApi='mainnet'] The tzkt API to use
* @param {number} [config.minConfirmations=1] The minimum number of confirmations for the transaction
* @param {string} [config.saplingStateMapContract='KT1RYEs6rfXgHqeb2XzfHKRii5NsNyKbS6WM'] The sapling state map contract address
* @param {boolean} [config.useBaseUnits=false] Whether to use base unit for the token amounts (mutez or token units with decimals)
* @param {boolean} [config.parallelThreads=true] Whether to spawn parallel threads for the sapling worker
* @param {boolean} [config.saplingDiffCache=true] Cache the sapling-diff delta (finalized prefix + fresh tail) instead of refetching the full pool diff each read — far less RPC. Browser auto-uses IndexedDB; Node/Lambda supplies `saplingDiffStore`.
* @param {boolean} [config.saplingBalanceCache=false] Opt-in "v2" decrypt cache: also caches decrypted notes and decrypts only new commitments (O(new)). Self-checked against the stock balance; decrypted notes are encrypted at rest under the viewing key.
* @param {SaplingDiffStore} [config.saplingDiffStore] Persistent store backing the diff cache in Node/Lambda (direct mode only); the browser auto-uses IndexedDB.
* @param {string} [config.saplingSecret] The sapling secret key (for full access mode)
* @param {string} [config.saplingMnemonic] The sapling mnemonic (for full access mode)
* @param {string} [config.saplingViewingKey] The sapling viewing key (for view-only mode)
* @returns {ShieldBridgeSDK} The Shield Bridge SDK instance
*
* @example
* // Full access mode with secret key
* const tezos = new TezosToolkit('https://mainnet.api.tez.ie');
* const signerProvider = await InMemorySigner.fromSecretKey('edsk...');
* tezos.setSignerProvider(signerProvider);
* const shieldBridge = new ShieldBridgeSDK({
* client: tezos,
* saplingSecret: 'sask...'
* });
* await shieldBridge.shield([
* {
* amount: 1,
* contract: 'KT1...',
* tokenId: 0,
* memo: 'abcdefgh'
* }
* ]);
*
* @example
* // Export viewing key for read-only access
* const viewingKey = await shieldBridge.getViewingKey();
*
* @example
* // View-only mode with viewing key
* const viewOnlySdk = new ShieldBridgeSDK({
* client: tezos,
* saplingViewingKey: 'abc123...'
* });
* const balance = await viewOnlySdk.getShieldedBalance({});
* console.log('View-only mode:', viewOnlySdk.isViewOnlyMode); // true
*/
export declare class ShieldBridgeSDK {
#private;
private tezosClient;
private saplingWorker;
/** Worker pool for parallel operations (null when parallelThreads is false) */
private workerPool;
/**
* The contract address used for operations.
* - V2: Factory contract address
* - V1: Map contract address
* @deprecated Use shieldBridgeContractAddress instead.
*/
get saplingStateMapContract(): string;
/**
* The Shield Bridge contract address used for operations.
* - V2: Factory contract address
* - V1: Map contract address
*/
shieldBridgeContractAddress: string;
/**
* Contract architecture version
* - '2': Factory contract with individual set contracts
* - '1': Legacy map contract with inline sapling states
* Can be changed at runtime via switchArchitecture()
*/
contractArchitecture: ContractArchitecture;
minConfirmations: number;
useBaseUnits: boolean;
parallelThreads: boolean;
/** Maximum pool size when parallelThreads is enabled */
private maxPoolSize;
/** TzKT API base URL for this SDK instance */
private tzktBaseUrl;
/** Counter for in-flight operations to prevent architecture switches during active work */
private operationsInFlight;
ready: Promise<boolean>;
/**
* Indicates whether the SDK is in view-only mode (using a viewing key)
* When true, only read operations (balance, transactions, address) are available
* Transaction operations (shield, unshield, transfer) will throw errors
*/
readonly isViewOnlyMode: boolean;
/**
* Await op.confirmation() with a visibility-change recovery for mobile browsers.
*
* When the user switches to a wallet app to sign, the browser tab is backgrounded
* and timers are throttled/frozen. op.confirmation() uses RxJS polling (setInterval)
* that stalls on backgrounded tabs. The polling resumes on return but needs to walk
* through every missed block sequentially, which can take a very long time.
*
* This helper races op.confirmation() against visibility/focus listeners that
* query TzKT for the operation status when the tab regains focus, bypassing the
* stalled block-by-block walk entirely.
*
* Uses both `visibilitychange` and `focus` because iOS Safari sometimes fails
* to fire `visibilitychange` when switching between native apps.
*/
private awaitConfirmation;
private setAddressCache;
private saplingIdCache;
private tokenDecimalsCache;
private tokenMetadataCache;
private walletContractCache;
private estimatorContractCache;
/**
* Memoized factory storage snapshot (V2). The factory abstraction and its
* top-level storage are immutable for a given contract address, and big-map
* `.get()` lookups always issue a fresh head RPC, so a single snapshot serves
* every per-token set-address lookup without re-fetching the storage.
* Reset on architecture switch, destroy, and on fetch error.
*/
private factoryStoragePromise;
/**
* Memoized deterministic outputs of the loaded sapling key. The shielded
* payment address and the viewing key are pure functions of the key — which
* is fixed for the SDK's lifetime and only cleared in destroy — and do not
* depend on the contract architecture, so they are derived once and reused.
* Reset to undefined on failure so a transient worker/WASM error stays
* retryable; cleared in destroy.
*/
private shieldedAddressPromise?;
private viewingKeyPromise?;
/** Custom base URL for sapling params (overrides default relative resolution) */
private saplingParamsUrl?;
/** Whether the incremental sapling-diff (fetch) cache is enabled (default true). */
private saplingDiffCache;
/** Whether the incremental balance (decrypt) cache is enabled (opt-in, default false). */
private saplingBalanceCache;
/** Optional injected diff-cache store (Node/Lambda/tests; direct-execution mode). */
private saplingDiffStore?;
/** Network identifier for default contract address resolution */
private network;
constructor(config: ShieldBridgeSDKConfig);
/**
* @description Helper to create a worker instance compatible with both Browser and Node.js
*/
private createWorker;
initializeSaplingWorker: () => Promise<boolean>;
/**
* @description Get the sapling key type and value
* @returns The key type ('secretKey' | 'mnemonic' | 'viewingKey') and the key value
*/
private getSaplingKeyInfo;
/**
* @description Format token info for error messages
*/
private static formatTokenInfo;
/**
* @description Get cached contract or fetch and cache it
* @param contractAddress The contract address
*/
private getContract;
/**
* @description Get cached estimator contract or fetch and cache it
* @param contractAddress The contract address
*/
private getEstimatorContract;
/**
* @description Get the memoized factory storage snapshot (V2), reusing the
* cached factory contract abstraction. Big-map `.get()` lookups off the
* snapshot stay live (each issues a fresh head RPC), so this only collapses
* the repeated `contract.at()` + `storage()` round-trips, not per-token
* freshness. Used by getSetAddress, which holds its own per-key result cache.
*/
private getFactoryStorage;
/**
* @description Helper method to initialize a sapling worker with the sapling secret and state
* @param contract The token contract address (optional)
* @param tokenId The token id (optional)
* @param providedSetAddress The set contract address if already known (V2 only, optional)
* @param providedSaplingId The sapling ID if already known (V1 only, optional)
* @returns The initialized sapling worker, set address/map contract, and token decimals
*/
private initializeSaplingWorkerWithState;
/**
* @description Execute an operation with a properly managed sapling worker.
* Ensures the parallel worker is always released after the operation completes
* or throws, preventing memory leaks from orphaned Web Workers.
*
* @param fn Callback receiving the initialized worker, token decimals, and set address
* @param contract Optional token contract address
* @param tokenId Optional token ID
* @param providedSetAddress Optional pre-resolved set address (V2)
* @param providedSaplingId Optional pre-resolved sapling ID (V1)
* @returns The result of the callback
*/
private withWorker;
/**
* @description Get the sapling set contract address for the token contract and token id if provided
* @param {string} [contract] The token contract address
* @param {number} [tokenId] The token id
* @returns The sapling set contract address for the token contract and token id if provided
* @note This method is for V2 (Factory) architecture. For V1, use getSaplingId instead.
*/
getSetAddress: (contract?: string, tokenId?: number) => Promise<string | undefined>;
/**
* @deprecated V1 architecture is deprecated. Use V2 (Factory) with getSetAddress instead.
* @description Get the sapling ID for the token contract and token id (V1 Map architecture)
* @param {string} [contract] The token contract address
* @param {number} [tokenId] The token id
* @returns The sapling ID for the token in the map contract storage
*/
getSaplingId: (contract?: string, tokenId?: number) => Promise<number | undefined>;
/**
* @description Get the metadata for the token contract and token id if provided
* @param {string} contract The token contract address
* @param {number} [tokenId] The token id
* @returns The metadata for the token contract and token id if provided
*
* @note Uses TzKT API which automatically decodes token metadata from bytes.
* Taquito RPC returns raw big map structures that require manual decoding.
*/
getTokenMetadata: (contract: string, tokenId?: number) => Promise<any>;
/**
* @description Get the number of decimals for the token contract and token id if provided
* @param {string} contract The token contract address
* @param {number} [tokenId] The token id
* @returns The number of decimals for the token contract and token id if provided
*/
getTokenDecimals: (contract: string, tokenId?: number) => Promise<number>;
/**
* @description Get the total shielded pool balances across all set contracts
* @returns The aggregated balances from all individual set contracts
*
* @note In the factory architecture, the factory contract itself holds no balances.
* Each token type has its own set contract that holds the actual assets.
* This method aggregates balances from all individual set contracts.
*/
getTotalShieldedSetBalances: () => Promise<never[]>;
/**
* @description Estimate the gas and storage limits for the transaction list of shielding transactions
* @param {OrderedTransactionList} transactionList The constructed transaction list
* @returns The estimated gas and storage limits for the transaction list
*/
estimateShieldTransactionLimits: (transactionList: OrderedTransactionList) => Promise<import("@tezos-x/octez.js").Estimate[]>;
/**
* @description Submit sapling deposits/shielding transactions
* @param {SaplingDeposits} saplingDeposits Sapling deposits/shielding transactions to be submitted
* @param {number} saplingDeposits.amount The amount to be shielded
* @param {string[]} saplingDeposits.saplingTransactions The sapling transactions to be submitted
* @param {string} [saplingDeposits.contract] The token contract address
* @param {number} [saplingDeposits.tokenId] The token id
* @param {string} [saplingDeposits.owner] The shielded address to apply the shielded tokens
* @returns The confirmation of the submitted sapling deposits/shielding transactions
*/
submitSaplingShieldTransaction: (saplingDeposits: SaplingDeposits[], callbacks?: TransactionProgressCallbacks) => Promise<{
opHash: string;
}>;
/**
* @description V2: Submit sapling shield transactions by calling Set contracts directly.
* Bypasses the Factory contract for maximum gas efficiency:
* - FA1.2: approve(Set) → Set.default(txns)
* - FA2: add_operator(Set) → Set.default(txns) → remove_operator(Set)
* - Tez: TezSet.default(txns) with XTZ amount
*/
private submitSaplingShieldTransactionV2;
/**
* @description Submit sapling transactions (shared implementation for unshield and transfer)
* @param {SaplingTransactions} saplingTransactions Sapling transactions to be submitted
* @param {string[]} saplingTransactions.saplingTransactions The sapling transactions to be submitted
* @param {string} [saplingTransactions.contract] The token contract address
* @param {number} [saplingTransactions.tokenId] The token id
* @returns The confirmation of the submitted sapling transactions
*/
submitSaplingTransaction: (saplingTransactions: SaplingTransactions[], callbacks?: TransactionProgressCallbacks) => Promise<{
block?: BlockResponse;
opHash: string;
}>;
/**
* @description V2: Submit sapling transactions (unshield/transfer) by calling Set contracts directly.
* No token approvals needed — unshield sends from pool, transfer is state-only.
*/
private submitSaplingTransactionV2;
/**
* @description Submit sapling withdrawals/unshielding transactions
* @param {SaplingTransactions} saplingWithdrawals Sapling withdrawals/unshielding transactions to be submitted
* @param {string[]} saplingWithdrawals.saplingTransactions The sapling transactions to be submitted
* @param {string} [saplingWithdrawals.contract] The token contract address
* @param {number} [saplingWithdrawals.tokenId] The token id
* @returns The confirmation of the submitted sapling withdrawals/unshielding transactions
*/
submitSaplingUnshieldTransaction: (saplingWithdrawals: SaplingTransactions[], callbacks?: TransactionProgressCallbacks) => Promise<{
block?: BlockResponse;
opHash: string;
}>;
/**
* @description Submit sapling transfers transactions
* @param {SaplingTransactions} saplingTransfers Sapling transfers to be submitted
* @param {string[]} saplingTransfers.saplingTransactions The sapling transactions to be submitted
* @param {string} [saplingTransfers.contract] The token contract address
* @param {number} [saplingTransfers.tokenId] The token id
* @returns The confirmation of the submitted sapling transfers
*/
submitSaplingTransferTransaction: (saplingTransfers: SaplingTransactions[], callbacks?: TransactionProgressCallbacks) => Promise<{
block?: BlockResponse;
opHash: string;
}>;
/**
* @description Construct the sapling parameters for the shielded transaction
* @param shieldParam The sapling shielding parameters
* @param {number} shieldParam.amount The amount to be shielded
* @param {string} [shieldParam.shieldedAddress] The shielded address to apply the shielded tokens
* @param {string} [shieldParam.contract] The token contract address
* @param {number} [shieldParam.tokenId] The token id
* @param {string} [shieldParam.memo] The memo to be included in the sapling transaction
* @returns The sapling parameters for the shielded transaction
*/
constructShieldTokenParams: (shieldParam: ShieldParams) => Promise<{
saplingTransactions: string[];
owner: string;
amount: string;
contract: string | undefined;
tokenId: number | undefined;
}>;
/**
* @description Shield the specified amount of unshielded tokens to the sapling address
* @param {ShieldParams} shieldParams Sapling shielding parameters to be constructed into sapling transactions
* @param {number} shieldParams.amount The amount to be shielded
* @param {string} [shieldParams.shieldedAddress] The shielded address to apply the shielded tokens
* @param {string} [shieldParams.contract] The token contract address
* @param {number} [shieldParams.tokenId] The token id
* @param {string} [shieldParams.memo] The memo to be included in the sapling transaction
* @param {TransactionProgressCallbacks} [callbacks] Optional callbacks for operation progress updates
* @returns The confirmation of the submitted sapling shielding transactions
* @throws {Error} If called in view-only mode (with a viewing key)
*/
shield: (shieldParams: ShieldParams[], callbacks?: TransactionProgressCallbacks) => Promise<{
opHash: string;
}>;
/**
* @description Construct the sapling parameters for the unshielded transaction
* @param unshieldParam The sapling unshielding parameters
* @param {number} unshieldParam.amount The amount to be unshielded
* @param {string} [unshieldParam.unshieldedAddress] The unshielded address to apply the unshielded tokens
* @param {string} [unshieldParam.contract] The token contract address
* @param {number} [unshieldParam.tokenId] The token id
* @returns The sapling parameters for the unshielded transaction
*/
constructUnshieldTokenParams: (unshieldParam: UnshieldParams) => Promise<{
saplingTransactions: string[];
contract: string | undefined;
tokenId: number | undefined;
}>;
/**
* @description Unshield the specified amount of shielded tokens from the sapling address
* @param {UnshieldParams} unshieldParams Sapling unshielding parameters to be constructed into sapling transactions
* @param {number} unshieldParams.amount The amount to be unshielded
* @param {string} [unshieldParams.unshieldedAddress] The unshielded address to apply the unshielded tokens
* @param {string} [unshieldParams.contract] The token contract address
* @param {number} [unshieldParams.tokenId] The token id
* @param {TransactionProgressCallbacks} [callbacks] Optional callbacks for operation progress updates
* @returns The confirmation of the submitted sapling unshielding transactions
* @throws {Error} If called in view-only mode (with a viewing key)
*/
unshield: (unshieldParams: UnshieldParams[], callbacks?: TransactionProgressCallbacks) => Promise<{
block?: BlockResponse;
opHash: string;
}>;
/**
* @description Construct the sapling parameters for the transfer transaction
* @param transferParam The sapling transfer parameters
* @param {string} [transferParam.contract] The token contract address
* @param {number} [transferParam.tokenId] The token id
* @param {object} transferParam.transfers The transfers to be made
* @returns The sapling parameters for the transfer transaction
*/
constructTransferTokenParams: (transferParam: TransferParams) => Promise<{
saplingTransactions: string[];
contract: string | undefined;
tokenId: number | undefined;
}>;
/**
* @description Transfer the specified amount of shielded tokens to the specified shielded address
* @param {TransferParams[]} transferParams Sapling transfer parameters to be constructed into sapling transactions
* @param {string} [transferParams.contract] The token contract address
* @param {number} [transferParams.tokenId] The token id
* @param {object} transferParams.transfers The transfers to be made
* @param {TransactionProgressCallbacks} [callbacks] Optional callbacks for operation progress updates
* @returns The confirmation of the submitted sapling transfer transactions
* @throws {Error} If called in view-only mode (with a viewing key)
*/
transfer: (transferParams: TransferParams[], callbacks?: TransactionProgressCallbacks) => Promise<{
block?: BlockResponse;
opHash: string;
}>;
/**
* @description Get the shielded sapling token balance for the currently loaded shielded address
* @param {SaplingTokenInfo} saplingTokenInfo The sapling token information
* @param {string} [saplingTokenInfo.contract] The token contract address
* @param {number} [saplingTokenInfo.tokenId] The token id
* @param {string} [saplingTokenInfo.setAddress] The set contract address
* @returns The shielded sapling token balance for the currently loaded shielded address
*/
getShieldedBalance: ({ contract, tokenId, setAddress, decimals, }: SaplingTokenInfo) => Promise<number>;
/**
* @description Evict this account's incremental balance cache (the v2 decrypt cache, which
* holds decrypted notes). Call this when forgetting/locking an account so no decrypted data is
* left at rest. No-op when the balance cache is disabled or unavailable.
*/
clearShieldedBalanceCache: () => Promise<void>;
/**
* @description Get the Tez set contract address from the factory
* @returns The address of the Tez sapling set contract
* @throws If the factory contract doesn't have a Tez set or if not using V2 architecture
*/
getTezSetAddress: () => Promise<string>;
/**
* @description Get the FA1.2 set contract address for a given token from the factory
* @param tokenContract The FA1.2 token contract address
* @returns The address of the FA1.2 sapling set contract, or undefined if not registered
* @throws If not using V2 architecture
*/
getFA12SetAddress: (tokenContract: string) => Promise<string | undefined>;
/**
* @description Get the FA2 set contract address for a given token and token ID from the factory
* @param tokenContract The FA2 token contract address
* @param tokenId The FA2 token ID
* @returns The address of the FA2 sapling set contract, or undefined if not registered
* @throws If not using V2 architecture
*/
getFA2SetAddress: (tokenContract: string, tokenId: number) => Promise<string | undefined>;
/**
* @description Check if a set contract address was deployed by this factory
* @param setAddress The set contract address to verify
* @returns true if the address is a registered set contract deployed by this factory
* @throws If not using V2 architecture
*/
isRegisteredSet: (setAddress: string) => Promise<boolean>;
/**
* @description Get all the shielded sapling tokens
* @param includeMetadata Include the metadata for the shielded sapling tokens
* @returns The shielded sapling tokens with their set contract addresses
*
* @note This method uses TzKT API to enumerate big maps in the factory storage.
* For individual token lookups, use getSetAddress() which uses RPC directly.
* Big maps cannot be enumerated via RPC without knowing the keys.
*/
getAllShieldedAssets: (includeMetadata?: boolean) => Promise<ShieldedAssetInfo[]>;
/**
* @description Get the shielded sapling token balances for all the sapling tokens
* @returns The shielded sapling token balances for all the sapling tokens
*/
getAllShieldedBalances: () => Promise<{
setAddress: string;
contract?: string;
tokenId?: number;
balance: number;
}[]>;
/**
* @description Get the shielded incoming and outgoing transactions for the specified sapling contract and token id
* @param {string} [contract] Sapling contract address
* @param {number} [tokenId] Token id
* @returns The shielded incoming and outgoing transactions for the specified sapling contract and token id
*/
getShieldedTransactions: (contract?: string, tokenId?: number) => Promise<{
incoming: {
value: number;
memo: string;
paymentAddress: string;
isSpent: boolean;
isChange: boolean;
}[];
outgoing: {
value: number;
memo: string;
paymentAddress: string;
isChange: boolean;
}[];
}>;
/**
* @description Get the sapling payment address of the currently loaded sapling key
* @returns The sapling payment address
*/
getShieldedAddress: () => Promise<string>;
/**
* Switch contract architecture without re-initializing sapling keys.
*
* This allows seamless migration between V1 (Map) and V2 (Factory) contracts
* while preserving the user's sapling account. The shielded address remains
* the same since it's derived from the mnemonic, not the contract.
*
* @param architecture - '1' for Map (legacy), '2' for Factory (recommended)
* @param contractAddress - Optional custom contract address override
*
* @example
* ```typescript
* // Switch to V1 to access legacy funds
* sdk.switchArchitecture('1');
* await sdk.getShieldedBalance('V1_CONTRACT_ADDRESS');
*
* // Switch back to V2 for new transactions
* sdk.switchArchitecture('2');
* ```
*/
switchArchitecture: (architecture: ContractArchitecture, contractAddress?: string) => void;
/**
* Get the current contract architecture version.
*
* @returns '1' for Map (legacy) or '2' for Factory (recommended)
*/
getArchitecture: () => ContractArchitecture;
/**
* @description Export the viewing key for the currently loaded sapling key
*
* The viewing key can be used to initialize the SDK in view-only mode, allowing
* read-only operations (balance queries, transaction history) without exposing
* the spending key. This is useful for:
* - Auditing and compliance purposes
* - Sharing balance visibility without spending ability
* - Creating monitoring applications
*
* @returns The viewing key as a hex string
* @throws {Error} If no spending key or viewing key is loaded
*
* @example
* // Export viewing key from spending key
* const viewingKey = await sdk.getViewingKey();
*
* // Use it to create a view-only SDK instance
* const viewOnlySdk = new ShieldBridgeSDK({
* client: tezos,
* saplingViewingKey: viewingKey
* });
*
* // Now you can query balances without spending ability
* const balance = await viewOnlySdk.getShieldedBalance({});
*/
getViewingKey: () => Promise<string>;
/**
* @description Clean up all workers and clear caches.
* Call this when the SDK instance is no longer needed to prevent memory leaks,
* especially in single-page applications where components may mount/unmount.
*/
destroy: () => Promise<void>;
/**
* @description Initialize the sapling set for the specified token contract and token id
* @param {string} contract The token contract address
* @param {number} [tokenId] The token id
* @returns The confirmation of the initialized sapling set
*/
initTokenSaplingSet: (contract: string, tokenId?: number) => Promise<{
opHash: string;
}>;
}
//# sourceMappingURL=index.d.ts.map