UNPKG

shield-bridge-sdk

Version:
102 lines 4.11 kB
/** * Core sapling worker functions — no Comlink, no threading. * * This module contains all the sapling operations (key management, proof * generation, balance/transaction queries) without any Comlink or Web Worker * dependency. It is the single source of truth that both: * * - `worker.ts` wraps with Comlink.expose() for browser Web Workers / Node.js * worker_threads, and * - `index.ts` can import directly for thread-free ("direct execution") mode * (e.g. AWS Lambda, CLI tools). * * The module maintains singleton state (spending key, toolkit, etc.) which is * safe because each execution context (Web Worker, worker_thread, or the main * thread in direct mode) loads its own copy. */ import type { SaplingContractDetails } from '@tezos-x/octez.js-sapling/dist/types/types'; import type { ParametersSaplingTransaction, ParametersUnshieldedTransaction } from './types.js'; import { type SaplingDiffStore } from './saplingDiffCache.js'; export type { SaplingContractDetails }; /** A raw note as returned by SaplingTransactionViewer.getIncomingAndOutgoingTransactionsRaw(). */ export interface RawSaplingNote { value: Uint8Array; memo: Uint8Array; paymentAddress: Uint8Array; randomCommitmentTrapdoor: Uint8Array; isSpent?: boolean; } /** * Format raw incoming/outgoing notes and tag the "self-sent" set. A note you created to YOURSELF * (change, or a shield to your own address) is decryptable as BOTH receiver and sender, so it shows * up in the incoming AND outgoing lists with the SAME commitment trapdoor (rcm). Matching by rcm * flags that set EXACTLY — no address/value/memo guessing — so the app can separate real * receives/sends from internal change no matter which diversified address the change went to. * Pure + exported for unit testing. */ export declare function notesToHistory(raw: { incoming: RawSaplingNote[]; outgoing: RawSaplingNote[]; }): { incoming: { value: number; memo: string; paymentAddress: string; isSpent: boolean; isChange: boolean; }[]; outgoing: { value: number; memo: string; paymentAddress: string; isChange: boolean; }[]; }; export declare const saplingWorkerCore: { createExtendedSpendingKey: (mnemonic: string) => Promise<string>; loadSaplingSecret: ({ sk, saplingDetails, rpcUrl, skType, }: { sk: string; saplingDetails: SaplingContractDetails; rpcUrl: string; skType: "secretKey" | "mnemonic" | "viewingKey"; }) => Promise<void>; getPaymentAddress: () => Promise<{ address: string; addressIndex: number; }>; getViewingKey: () => Promise<string>; prepareShieldedTransaction: (shieldTransactions: ParametersSaplingTransaction[]) => Promise<string>; prepareUnshieldedTransaction: (unshieldTransaction: ParametersUnshieldedTransaction) => Promise<string>; prepareSaplingTransaction: (saplingTransactions?: ParametersSaplingTransaction[]) => Promise<string>; getSaplingBalance: () => Promise<number>; getSaplingTransactions: () => Promise<{ incoming: { value: number; memo: string; paymentAddress: string; isSpent: boolean; isChange: boolean; }[]; outgoing: { value: number; memo: string; paymentAddress: string; isChange: boolean; }[]; }>; reInitializeSapling: () => void; initSaplingParams: () => Promise<void>; areSaplingParamsLoaded: () => boolean; preloadSaplingParams: () => void; setSaplingParamsUrl: (baseUrl: string) => void; setSaplingParamsUrls: (urls: { spend: string; output: string; }) => void; setDiffCacheEnabled: (enabled: boolean) => void; setBalanceCacheEnabled: (enabled: boolean) => void; setDiffCacheStore: (store: SaplingDiffStore | null) => void; clearShieldedBalanceCache: () => Promise<void>; }; export type SaplingWorkerCore = typeof saplingWorkerCore; //# sourceMappingURL=saplingCore.d.ts.map