@sip-protocol/sdk 0.7.3 → 0.7.4
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/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/{TransportWebUSB-TQ7WZ4LE.mjs → TransportWebUSB-YQMAGJAJ.mjs} +12 -9
- package/dist/browser.d.mts +10 -4
- package/dist/browser.d.ts +10 -4
- package/dist/browser.js +47556 -19603
- package/dist/browser.mjs +628 -48
- package/dist/chunk-4GRJ5MAW.mjs +152 -0
- package/dist/chunk-5D7A3L3W.mjs +717 -0
- package/dist/chunk-64AYA5F5.mjs +7834 -0
- package/dist/chunk-GMDGB22A.mjs +379 -0
- package/dist/chunk-I534WKN7.mjs +328 -0
- package/dist/chunk-IBZVA5Y7.mjs +1003 -0
- package/dist/chunk-PRRZAWJE.mjs +223 -0
- package/dist/{chunk-UJCSKKID.mjs → chunk-XGB3TDIC.mjs} +13 -1
- package/dist/{chunk-3M3HNQCW.mjs → chunk-YWGJ77A2.mjs} +28656 -13103
- package/dist/{chunk-6WGN57S2.mjs → chunk-Z3K7W5S3.mjs} +48 -0
- package/dist/constants-LHAAUC2T.mjs +51 -0
- package/dist/dist-2OGQ7FED.mjs +3957 -0
- package/dist/dist-IFHPYLDX.mjs +254 -0
- package/dist/fulfillment_proof-ANHVPKTB.mjs +21 -0
- package/dist/funding_proof-ICFZ5LHY.mjs +21 -0
- package/dist/{index-DIBZHOOQ.d.ts → index-DXh2IGkz.d.ts} +21239 -10304
- package/dist/{index-8MQz13eJ.d.mts → index-DeE1ZzA4.d.mts} +21239 -10304
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +48396 -19623
- package/dist/index.mjs +537 -19
- package/dist/interface-Bf7w1PLW.d.mts +679 -0
- package/dist/interface-Bf7w1PLW.d.ts +679 -0
- package/dist/{noir-DKfEzWy9.d.mts → noir-kzbLVTei.d.mts} +31 -21
- package/dist/{noir-DKfEzWy9.d.ts → noir-kzbLVTei.d.ts} +31 -21
- package/dist/proofs/halo2.d.mts +151 -0
- package/dist/proofs/halo2.d.ts +151 -0
- package/dist/proofs/halo2.js +350 -0
- package/dist/proofs/halo2.mjs +11 -0
- package/dist/proofs/kimchi.d.mts +160 -0
- package/dist/proofs/kimchi.d.ts +160 -0
- package/dist/proofs/kimchi.js +431 -0
- package/dist/proofs/kimchi.mjs +13 -0
- package/dist/proofs/noir.d.mts +1 -1
- package/dist/proofs/noir.d.ts +1 -1
- package/dist/proofs/noir.js +74 -18
- package/dist/proofs/noir.mjs +84 -24
- package/dist/solana-U3MEGU7W.mjs +280 -0
- package/dist/validity_proof-3POXLPNY.mjs +21 -0
- package/package.json +54 -21
- package/src/adapters/index.ts +41 -0
- package/src/adapters/jupiter.ts +571 -0
- package/src/adapters/near-intents.ts +135 -0
- package/src/advisor/advisor.ts +653 -0
- package/src/advisor/index.ts +54 -0
- package/src/advisor/tools.ts +303 -0
- package/src/advisor/types.ts +164 -0
- package/src/chains/ethereum/announcement.ts +536 -0
- package/src/chains/ethereum/bnb-optimizations.ts +474 -0
- package/src/chains/ethereum/commitment.ts +522 -0
- package/src/chains/ethereum/constants.ts +462 -0
- package/src/chains/ethereum/deployment.ts +596 -0
- package/src/chains/ethereum/gas-estimation.ts +538 -0
- package/src/chains/ethereum/index.ts +268 -0
- package/src/chains/ethereum/optimizations.ts +614 -0
- package/src/chains/ethereum/privacy-adapter.ts +855 -0
- package/src/chains/ethereum/registry.ts +584 -0
- package/src/chains/ethereum/rpc.ts +905 -0
- package/src/chains/ethereum/stealth.ts +491 -0
- package/src/chains/ethereum/token.ts +790 -0
- package/src/chains/ethereum/transfer.ts +637 -0
- package/src/chains/ethereum/types.ts +456 -0
- package/src/chains/ethereum/viewing-key.ts +455 -0
- package/src/chains/near/commitment.ts +608 -0
- package/src/chains/near/constants.ts +284 -0
- package/src/chains/near/function-call.ts +871 -0
- package/src/chains/near/history.ts +654 -0
- package/src/chains/near/implicit-account.ts +840 -0
- package/src/chains/near/index.ts +393 -0
- package/src/chains/near/native-transfer.ts +658 -0
- package/src/chains/near/nep141.ts +775 -0
- package/src/chains/near/privacy-adapter.ts +889 -0
- package/src/chains/near/resolver.ts +971 -0
- package/src/chains/near/rpc.ts +1016 -0
- package/src/chains/near/stealth.ts +419 -0
- package/src/chains/near/types.ts +317 -0
- package/src/chains/near/viewing-key.ts +876 -0
- package/src/chains/solana/anchor-transfer.ts +386 -0
- package/src/chains/solana/commitment.ts +577 -0
- package/src/chains/solana/constants.ts +126 -12
- package/src/chains/solana/ephemeral-keys.ts +543 -0
- package/src/chains/solana/index.ts +252 -1
- package/src/chains/solana/key-derivation.ts +418 -0
- package/src/chains/solana/kit-compat.ts +334 -0
- package/src/chains/solana/optimizations.ts +560 -0
- package/src/chains/solana/privacy-adapter.ts +605 -0
- package/src/chains/solana/providers/generic.ts +47 -6
- package/src/chains/solana/providers/helius-enhanced-types.ts +336 -0
- package/src/chains/solana/providers/helius-enhanced.ts +623 -0
- package/src/chains/solana/providers/helius.ts +186 -33
- package/src/chains/solana/providers/index.ts +31 -0
- package/src/chains/solana/providers/interface.ts +61 -18
- package/src/chains/solana/providers/quicknode.ts +409 -0
- package/src/chains/solana/providers/triton.ts +426 -0
- package/src/chains/solana/providers/webhook.ts +338 -67
- package/src/chains/solana/rpc-client.ts +1150 -0
- package/src/chains/solana/scan.ts +83 -66
- package/src/chains/solana/sol-transfer.ts +732 -0
- package/src/chains/solana/spl-transfer.ts +886 -0
- package/src/chains/solana/stealth-scanner.ts +703 -0
- package/src/chains/solana/sunspot-verifier.ts +453 -0
- package/src/chains/solana/transaction-builder.ts +755 -0
- package/src/chains/solana/transfer.ts +74 -5
- package/src/chains/solana/types.ts +57 -6
- package/src/chains/solana/utils.ts +110 -0
- package/src/chains/solana/viewing-key.ts +807 -0
- package/src/compliance/fireblocks.ts +921 -0
- package/src/compliance/index.ts +23 -0
- package/src/compliance/range-sas.ts +398 -33
- package/src/config/endpoints.ts +100 -0
- package/src/crypto.ts +11 -8
- package/src/errors.ts +82 -0
- package/src/evm/erc4337-relayer.ts +830 -0
- package/src/evm/index.ts +47 -0
- package/src/fees/calculator.ts +396 -0
- package/src/fees/index.ts +87 -0
- package/src/fees/near-contract.ts +429 -0
- package/src/fees/types.ts +268 -0
- package/src/index.ts +686 -1
- package/src/intent.ts +6 -3
- package/src/logger.ts +324 -0
- package/src/network/index.ts +80 -0
- package/src/network/proxy.ts +691 -0
- package/src/optimizations/index.ts +541 -0
- package/src/oracle/types.ts +1 -0
- package/src/privacy-backends/arcium-types.ts +727 -0
- package/src/privacy-backends/arcium.ts +719 -0
- package/src/privacy-backends/combined-privacy.ts +866 -0
- package/src/privacy-backends/cspl-token.ts +595 -0
- package/src/privacy-backends/cspl-types.ts +512 -0
- package/src/privacy-backends/cspl.ts +907 -0
- package/src/privacy-backends/health.ts +488 -0
- package/src/privacy-backends/inco-types.ts +323 -0
- package/src/privacy-backends/inco.ts +616 -0
- package/src/privacy-backends/index.ts +254 -4
- package/src/privacy-backends/interface.ts +649 -6
- package/src/privacy-backends/lru-cache.ts +343 -0
- package/src/privacy-backends/magicblock.ts +458 -0
- package/src/privacy-backends/mock.ts +258 -0
- package/src/privacy-backends/privacycash.ts +13 -17
- package/src/privacy-backends/private-swap.ts +570 -0
- package/src/privacy-backends/rate-limiter.ts +683 -0
- package/src/privacy-backends/registry.ts +414 -2
- package/src/privacy-backends/router.ts +283 -3
- package/src/privacy-backends/shadowwire.ts +449 -0
- package/src/privacy-backends/sip-native.ts +3 -0
- package/src/privacy-logger.ts +191 -0
- package/src/production-safety.ts +373 -0
- package/src/proofs/aggregator.ts +1029 -0
- package/src/proofs/browser-composer.ts +1150 -0
- package/src/proofs/browser.ts +113 -25
- package/src/proofs/cache/index.ts +127 -0
- package/src/proofs/cache/interface.ts +545 -0
- package/src/proofs/cache/key-generator.ts +188 -0
- package/src/proofs/cache/lru-cache.ts +481 -0
- package/src/proofs/cache/multi-tier-cache.ts +575 -0
- package/src/proofs/cache/persistent-cache.ts +788 -0
- package/src/proofs/compliance-proof.ts +872 -0
- package/src/proofs/composer/base.ts +923 -0
- package/src/proofs/composer/index.ts +25 -0
- package/src/proofs/composer/interface.ts +518 -0
- package/src/proofs/composer/types.ts +383 -0
- package/src/proofs/converters/halo2.ts +452 -0
- package/src/proofs/converters/index.ts +208 -0
- package/src/proofs/converters/interface.ts +363 -0
- package/src/proofs/converters/kimchi.ts +462 -0
- package/src/proofs/converters/noir.ts +451 -0
- package/src/proofs/fallback.ts +888 -0
- package/src/proofs/halo2.ts +42 -0
- package/src/proofs/index.ts +471 -0
- package/src/proofs/interface.ts +13 -0
- package/src/proofs/kimchi.ts +42 -0
- package/src/proofs/lazy.ts +1004 -0
- package/src/proofs/mock.ts +25 -1
- package/src/proofs/noir.ts +110 -29
- package/src/proofs/orchestrator.ts +960 -0
- package/src/proofs/parallel/concurrency.ts +297 -0
- package/src/proofs/parallel/dependency-graph.ts +602 -0
- package/src/proofs/parallel/executor.ts +420 -0
- package/src/proofs/parallel/index.ts +131 -0
- package/src/proofs/parallel/interface.ts +685 -0
- package/src/proofs/parallel/worker-pool.ts +644 -0
- package/src/proofs/providers/halo2.ts +560 -0
- package/src/proofs/providers/index.ts +34 -0
- package/src/proofs/providers/kimchi.ts +641 -0
- package/src/proofs/validator.ts +881 -0
- package/src/proofs/verifier.ts +867 -0
- package/src/quantum/index.ts +112 -0
- package/src/quantum/winternitz-vault.ts +639 -0
- package/src/quantum/wots.ts +611 -0
- package/src/settlement/backends/direct-chain.ts +1 -0
- package/src/settlement/index.ts +9 -0
- package/src/settlement/router.ts +732 -46
- package/src/solana/index.ts +72 -0
- package/src/solana/jito-relayer.ts +687 -0
- package/src/solana/noir-verifier-types.ts +430 -0
- package/src/solana/noir-verifier.ts +816 -0
- package/src/stealth/address-derivation.ts +193 -0
- package/src/stealth/ed25519.ts +431 -0
- package/src/stealth/index.ts +233 -0
- package/src/stealth/meta-address.ts +221 -0
- package/src/stealth/secp256k1.ts +368 -0
- package/src/stealth/utils.ts +194 -0
- package/src/stealth.ts +50 -1504
- package/src/sync/index.ts +106 -0
- package/src/sync/manager.ts +504 -0
- package/src/sync/mock-provider.ts +318 -0
- package/src/sync/oblivious.ts +625 -0
- package/src/tokens/index.ts +15 -0
- package/src/tokens/registry.ts +301 -0
- package/src/utils/deprecation.ts +94 -0
- package/src/utils/index.ts +9 -0
- package/src/wallet/ethereum/index.ts +68 -0
- package/src/wallet/ethereum/metamask-privacy.ts +420 -0
- package/src/wallet/ethereum/multi-wallet.ts +646 -0
- package/src/wallet/ethereum/privacy-adapter.ts +700 -0
- package/src/wallet/ethereum/types.ts +3 -1
- package/src/wallet/ethereum/walletconnect-adapter.ts +675 -0
- package/src/wallet/hardware/index.ts +10 -0
- package/src/wallet/hardware/ledger-privacy.ts +414 -0
- package/src/wallet/index.ts +71 -0
- package/src/wallet/near/adapter.ts +626 -0
- package/src/wallet/near/index.ts +86 -0
- package/src/wallet/near/meteor-wallet.ts +1153 -0
- package/src/wallet/near/my-near-wallet.ts +790 -0
- package/src/wallet/near/wallet-selector.ts +702 -0
- package/src/wallet/solana/adapter.ts +6 -4
- package/src/wallet/solana/index.ts +13 -0
- package/src/wallet/solana/privacy-adapter.ts +567 -0
- package/src/wallet/sui/types.ts +6 -4
- package/src/zcash/rpc-client.ts +13 -6
- package/dist/chunk-2XIVXWHA.mjs +0 -1930
- package/dist/chunk-3INS3PR5.mjs +0 -884
- package/dist/chunk-3OVABDRH.mjs +0 -17096
- package/dist/chunk-7RFRWDCW.mjs +0 -1504
- package/dist/chunk-DLDWZFYC.mjs +0 -1495
- package/dist/chunk-E6SZWREQ.mjs +0 -57
- package/dist/chunk-F6F73W35.mjs +0 -16166
- package/dist/chunk-G33LB27A.mjs +0 -16166
- package/dist/chunk-HGU6HZRC.mjs +0 -231
- package/dist/chunk-L2K34JCU.mjs +0 -1496
- package/dist/chunk-OFDBEIEK.mjs +0 -16166
- package/dist/chunk-SF7YSLF5.mjs +0 -1515
- package/dist/chunk-SN4ZDTVW.mjs +0 -16166
- package/dist/chunk-WWUSGOXE.mjs +0 -17129
- package/dist/constants-VOI7BSLK.mjs +0 -27
- package/dist/index-B71aXVzk.d.ts +0 -13264
- package/dist/index-BYZbDjal.d.ts +0 -11390
- package/dist/index-CHB3KuOB.d.mts +0 -11859
- package/dist/index-CzWPI6Le.d.ts +0 -11859
- package/dist/index-pOIIuwfV.d.mts +0 -13264
- package/dist/index-xbWjohNq.d.mts +0 -11390
- package/dist/solana-4O4K45VU.mjs +0 -46
- package/dist/solana-5EMCTPTS.mjs +0 -46
- package/dist/solana-NDABAZ6P.mjs +0 -56
- package/dist/solana-Q4NAVBTS.mjs +0 -46
- package/dist/solana-ZYO63LY5.mjs +0 -46
package/src/proofs/browser.ts
CHANGED
|
@@ -44,17 +44,20 @@ import type { MobileDeviceInfo, MobileWASMCompatibility } from './browser-utils'
|
|
|
44
44
|
// Import Noir JS (works in browser with WASM)
|
|
45
45
|
import { Noir } from '@noir-lang/noir_js'
|
|
46
46
|
import type { CompiledCircuit } from '@noir-lang/types'
|
|
47
|
-
import { UltraHonkBackend } from '@aztec/bb.js'
|
|
47
|
+
import { UltraHonkBackend, Barretenberg } from '@aztec/bb.js'
|
|
48
48
|
import { secp256k1 } from '@noble/curves/secp256k1'
|
|
49
49
|
|
|
50
50
|
// Import compiled circuit artifacts
|
|
51
|
-
//
|
|
51
|
+
// Circuit JSON files are typed via CompiledCircuit assertion
|
|
52
52
|
import fundingCircuitArtifact from './circuits/funding_proof.json'
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
53
|
import validityCircuitArtifact from './circuits/validity_proof.json'
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
54
|
import fulfillmentCircuitArtifact from './circuits/fulfillment_proof.json'
|
|
57
55
|
|
|
56
|
+
// Type assertion for circuit artifacts (JSON modules)
|
|
57
|
+
const fundingCircuit = fundingCircuitArtifact as unknown as CompiledCircuit
|
|
58
|
+
const validityCircuit = validityCircuitArtifact as unknown as CompiledCircuit
|
|
59
|
+
const fulfillmentCircuit = fulfillmentCircuitArtifact as unknown as CompiledCircuit
|
|
60
|
+
|
|
58
61
|
/**
|
|
59
62
|
* Public key coordinates for secp256k1
|
|
60
63
|
*/
|
|
@@ -117,6 +120,9 @@ export type ProofProgressCallback = (progress: {
|
|
|
117
120
|
message: string
|
|
118
121
|
}) => void
|
|
119
122
|
|
|
123
|
+
/** Default initialization timeout in milliseconds */
|
|
124
|
+
const DEFAULT_INIT_TIMEOUT_MS = 30000
|
|
125
|
+
|
|
120
126
|
/**
|
|
121
127
|
* Browser-compatible Noir Proof Provider
|
|
122
128
|
*
|
|
@@ -142,12 +148,17 @@ export type ProofProgressCallback = (progress: {
|
|
|
142
148
|
export class BrowserNoirProvider implements ProofProvider {
|
|
143
149
|
readonly framework: ProofFramework = 'noir'
|
|
144
150
|
private _isReady = false
|
|
151
|
+
private _initPromise: Promise<void> | null = null
|
|
152
|
+
private _initError: Error | null = null
|
|
145
153
|
private config: Required<BrowserNoirProviderConfig>
|
|
146
154
|
|
|
147
155
|
// Mobile device info (cached)
|
|
148
156
|
private deviceInfo: MobileDeviceInfo | null = null
|
|
149
157
|
private wasmCompatibility: MobileWASMCompatibility | null = null
|
|
150
158
|
|
|
159
|
+
// Barretenberg instance (shared by all backends)
|
|
160
|
+
private barretenberg: Barretenberg | null = null
|
|
161
|
+
|
|
151
162
|
// Circuit instances
|
|
152
163
|
private fundingNoir: Noir | null = null
|
|
153
164
|
private fundingBackend: UltraHonkBackend | null = null
|
|
@@ -347,10 +358,79 @@ export class BrowserNoirProvider implements ProofProvider {
|
|
|
347
358
|
* @param onProgress - Optional progress callback
|
|
348
359
|
*/
|
|
349
360
|
async initialize(onProgress?: ProofProgressCallback): Promise<void> {
|
|
361
|
+
// If already ready, return immediately
|
|
362
|
+
if (this._isReady) {
|
|
363
|
+
return
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// If initialization is in progress, wait for it
|
|
367
|
+
if (this._initPromise) {
|
|
368
|
+
return this._initPromise
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// If a previous initialization failed, rethrow the error
|
|
372
|
+
if (this._initError) {
|
|
373
|
+
throw this._initError
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Start initialization and track the promise
|
|
377
|
+
this._initPromise = this._doInitialize(onProgress)
|
|
378
|
+
|
|
379
|
+
try {
|
|
380
|
+
await this._initPromise
|
|
381
|
+
} catch (error) {
|
|
382
|
+
// Store error for future calls
|
|
383
|
+
this._initError = error instanceof Error ? error : new Error(String(error))
|
|
384
|
+
this._initPromise = null
|
|
385
|
+
throw error
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Wait for the provider to be ready, with optional timeout
|
|
391
|
+
*
|
|
392
|
+
* This method blocks until initialization is complete or the timeout is reached.
|
|
393
|
+
* If initialization is already complete, resolves immediately.
|
|
394
|
+
* If initialization hasn't started, this method will start it.
|
|
395
|
+
*
|
|
396
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 30000)
|
|
397
|
+
* @throws ProofError if timeout is reached before ready
|
|
398
|
+
* @throws ProofError if initialization fails
|
|
399
|
+
*/
|
|
400
|
+
async waitUntilReady(timeoutMs: number = DEFAULT_INIT_TIMEOUT_MS): Promise<void> {
|
|
350
401
|
if (this._isReady) {
|
|
351
402
|
return
|
|
352
403
|
}
|
|
353
404
|
|
|
405
|
+
// If there was a previous error, throw it
|
|
406
|
+
if (this._initError) {
|
|
407
|
+
throw new ProofError(
|
|
408
|
+
`BrowserNoirProvider initialization failed: ${this._initError.message}`,
|
|
409
|
+
ErrorCode.PROOF_PROVIDER_NOT_READY,
|
|
410
|
+
{ context: { error: this._initError } }
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Start initialization if not already started
|
|
415
|
+
const initPromise = this._initPromise ?? this.initialize()
|
|
416
|
+
|
|
417
|
+
// Race between initialization and timeout
|
|
418
|
+
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
419
|
+
setTimeout(() => {
|
|
420
|
+
reject(new ProofError(
|
|
421
|
+
`BrowserNoirProvider initialization timed out after ${timeoutMs}ms`,
|
|
422
|
+
ErrorCode.PROOF_PROVIDER_NOT_READY
|
|
423
|
+
))
|
|
424
|
+
}, timeoutMs)
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
await Promise.race([initPromise, timeoutPromise])
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Internal initialization logic
|
|
432
|
+
*/
|
|
433
|
+
private async _doInitialize(onProgress?: ProofProgressCallback): Promise<void> {
|
|
354
434
|
// Check mobile compatibility
|
|
355
435
|
this.wasmCompatibility = checkMobileWASMCompatibility()
|
|
356
436
|
|
|
@@ -388,21 +468,26 @@ export class BrowserNoirProvider implements ProofProvider {
|
|
|
388
468
|
console.log('[BrowserNoirProvider] Browser info:', getBrowserInfo())
|
|
389
469
|
}
|
|
390
470
|
|
|
391
|
-
// Initialize circuits in parallel for faster loading
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
471
|
+
// Initialize circuits in parallel for faster loading (using module-level typed constants)
|
|
472
|
+
onProgress?.({
|
|
473
|
+
stage: 'initializing',
|
|
474
|
+
percent: 15,
|
|
475
|
+
message: 'Initializing Barretenberg...',
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
// Initialize Barretenberg (bb.js 3.x requires shared instance)
|
|
479
|
+
this.barretenberg = await Barretenberg.new()
|
|
395
480
|
|
|
396
481
|
onProgress?.({
|
|
397
482
|
stage: 'initializing',
|
|
398
|
-
percent:
|
|
483
|
+
percent: 30,
|
|
399
484
|
message: 'Creating proof backends...',
|
|
400
485
|
})
|
|
401
486
|
|
|
402
|
-
// Create backends (
|
|
403
|
-
this.fundingBackend = new UltraHonkBackend(fundingCircuit.bytecode)
|
|
404
|
-
this.validityBackend = new UltraHonkBackend(validityCircuit.bytecode)
|
|
405
|
-
this.fulfillmentBackend = new UltraHonkBackend(fulfillmentCircuit.bytecode)
|
|
487
|
+
// Create backends (bb.js 3.x requires Barretenberg instance)
|
|
488
|
+
this.fundingBackend = new UltraHonkBackend(fundingCircuit.bytecode, this.barretenberg)
|
|
489
|
+
this.validityBackend = new UltraHonkBackend(validityCircuit.bytecode, this.barretenberg)
|
|
490
|
+
this.fulfillmentBackend = new UltraHonkBackend(fulfillmentCircuit.bytecode, this.barretenberg)
|
|
406
491
|
|
|
407
492
|
onProgress?.({
|
|
408
493
|
stage: 'initializing',
|
|
@@ -960,25 +1045,28 @@ export class BrowserNoirProvider implements ProofProvider {
|
|
|
960
1045
|
* Destroy the provider and free resources
|
|
961
1046
|
*/
|
|
962
1047
|
async destroy(): Promise<void> {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
this.validityBackend = null
|
|
970
|
-
}
|
|
971
|
-
if (this.fulfillmentBackend) {
|
|
972
|
-
await this.fulfillmentBackend.destroy()
|
|
973
|
-
this.fulfillmentBackend = null
|
|
974
|
-
}
|
|
1048
|
+
// Clear backend references (bb.js 3.x backends don't have destroy method)
|
|
1049
|
+
this.fundingBackend = null
|
|
1050
|
+
this.validityBackend = null
|
|
1051
|
+
this.fulfillmentBackend = null
|
|
1052
|
+
|
|
1053
|
+
// Terminate worker if running
|
|
975
1054
|
if (this.worker) {
|
|
976
1055
|
this.worker.terminate()
|
|
977
1056
|
this.worker = null
|
|
978
1057
|
}
|
|
1058
|
+
|
|
1059
|
+
// Clear Noir instances
|
|
979
1060
|
this.fundingNoir = null
|
|
980
1061
|
this.validityNoir = null
|
|
981
1062
|
this.fulfillmentNoir = null
|
|
1063
|
+
|
|
1064
|
+
// Destroy shared Barretenberg instance (bb.js 3.x)
|
|
1065
|
+
if (this.barretenberg) {
|
|
1066
|
+
await this.barretenberg.destroy()
|
|
1067
|
+
this.barretenberg = null
|
|
1068
|
+
}
|
|
1069
|
+
|
|
982
1070
|
this._isReady = false
|
|
983
1071
|
}
|
|
984
1072
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof Caching Layer Module
|
|
3
|
+
*
|
|
4
|
+
* @module proofs/cache
|
|
5
|
+
* @description Multi-tier caching for proofs and intermediate computation results
|
|
6
|
+
*
|
|
7
|
+
* M20-13: Implement proof caching layer (#313)
|
|
8
|
+
*
|
|
9
|
+
* ## Overview
|
|
10
|
+
*
|
|
11
|
+
* This module provides a comprehensive caching layer for ZK proofs:
|
|
12
|
+
*
|
|
13
|
+
* - **LRU Cache**: Fast in-memory caching with LRU eviction
|
|
14
|
+
* - **Persistent Cache**: IndexedDB (browser) or file-based (Node.js) storage
|
|
15
|
+
* - **Multi-Tier Cache**: Combines memory and persistent with read/write-through
|
|
16
|
+
* - **Cache Warming**: Predictive warming based on access patterns
|
|
17
|
+
*
|
|
18
|
+
* ## Usage
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import {
|
|
22
|
+
* createMultiTierCache,
|
|
23
|
+
* cacheKeyGenerator,
|
|
24
|
+
* } from '@sip-protocol/sdk/proofs/cache'
|
|
25
|
+
*
|
|
26
|
+
* // Create a multi-tier cache
|
|
27
|
+
* const cache = createMultiTierCache({
|
|
28
|
+
* memory: { maxEntries: 500, maxSizeBytes: 50 * 1024 * 1024 },
|
|
29
|
+
* writeThrough: true,
|
|
30
|
+
* readThrough: true,
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* // Generate a cache key from inputs
|
|
34
|
+
* const key = cacheKeyGenerator.generateFromInputs(
|
|
35
|
+
* 'noir',
|
|
36
|
+
* 'funding_proof',
|
|
37
|
+
* { balance: 1000n },
|
|
38
|
+
* { minRequired: 100n }
|
|
39
|
+
* )
|
|
40
|
+
*
|
|
41
|
+
* // Check cache before generating
|
|
42
|
+
* const cached = await cache.get(key)
|
|
43
|
+
* if (cached.hit) {
|
|
44
|
+
* return cached.entry!.value
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* // Generate and cache
|
|
48
|
+
* const proof = await generateProof(...)
|
|
49
|
+
* await cache.set(key, proof)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
// ─── Types and Interfaces ────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
export type {
|
|
56
|
+
// Cache Key
|
|
57
|
+
CacheKeyComponents,
|
|
58
|
+
CacheKey,
|
|
59
|
+
// Cache Entry
|
|
60
|
+
CacheEntryMetadata,
|
|
61
|
+
CacheEntry,
|
|
62
|
+
CacheLookupResult,
|
|
63
|
+
// Configuration
|
|
64
|
+
LRUCacheConfig,
|
|
65
|
+
PersistentCacheConfig,
|
|
66
|
+
MultiTierCacheConfig,
|
|
67
|
+
// Statistics
|
|
68
|
+
ProofCacheStats,
|
|
69
|
+
// Events
|
|
70
|
+
CacheEventType,
|
|
71
|
+
CacheEvent,
|
|
72
|
+
CacheEventListener,
|
|
73
|
+
// Invalidation
|
|
74
|
+
InvalidationStrategy,
|
|
75
|
+
InvalidationRule,
|
|
76
|
+
// Warming
|
|
77
|
+
CacheWarmingConfig,
|
|
78
|
+
WarmingResult,
|
|
79
|
+
// Interfaces
|
|
80
|
+
ICacheKeyGenerator,
|
|
81
|
+
IProofCache,
|
|
82
|
+
ILRUCache,
|
|
83
|
+
IPersistentCache,
|
|
84
|
+
IMultiTierCache,
|
|
85
|
+
IVerificationKeyCache,
|
|
86
|
+
ICompiledCircuitCache,
|
|
87
|
+
} from './interface'
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
DEFAULT_LRU_CONFIG,
|
|
91
|
+
DEFAULT_PERSISTENT_CONFIG,
|
|
92
|
+
DEFAULT_MULTI_TIER_CONFIG,
|
|
93
|
+
DEFAULT_WARMING_CONFIG,
|
|
94
|
+
INITIAL_PROOF_CACHE_STATS,
|
|
95
|
+
} from './interface'
|
|
96
|
+
|
|
97
|
+
// ─── Cache Key Generator ─────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
CacheKeyGenerator,
|
|
101
|
+
createCacheKeyGenerator,
|
|
102
|
+
cacheKeyGenerator,
|
|
103
|
+
} from './key-generator'
|
|
104
|
+
|
|
105
|
+
// ─── LRU Cache ───────────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
LRUCache,
|
|
109
|
+
createLRUCache,
|
|
110
|
+
} from './lru-cache'
|
|
111
|
+
|
|
112
|
+
// ─── Persistent Cache ────────────────────────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
IndexedDBCache,
|
|
116
|
+
FileCache,
|
|
117
|
+
createPersistentCache,
|
|
118
|
+
createIndexedDBCache,
|
|
119
|
+
createFileCache,
|
|
120
|
+
} from './persistent-cache'
|
|
121
|
+
|
|
122
|
+
// ─── Multi-Tier Cache ────────────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
MultiTierCache,
|
|
126
|
+
createMultiTierCache,
|
|
127
|
+
} from './multi-tier-cache'
|