@sip-protocol/sdk 0.7.2 → 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 +48874 -18336
- package/dist/browser.mjs +674 -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-YWGJ77A2.mjs +33806 -0
- 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-DXh2IGkz.d.ts +24681 -0
- package/dist/index-DeE1ZzA4.d.mts +24681 -0
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +48676 -17318
- package/dist/index.mjs +583 -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 +276 -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 +201 -0
- 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 +402 -0
- package/src/chains/solana/providers/index.ts +85 -0
- package/src/chains/solana/providers/interface.ts +221 -0
- 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 +790 -0
- package/src/chains/solana/rpc-client.ts +1150 -0
- package/src/chains/solana/scan.ts +170 -73
- 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 +77 -7
- 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 +37 -0
- package/src/compliance/range-sas.ts +956 -0
- 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 +785 -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 +336 -0
- package/src/privacy-backends/interface.ts +906 -0
- 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-types.ts +278 -0
- package/src/privacy-backends/privacycash.ts +456 -0
- package/src/privacy-backends/private-swap.ts +570 -0
- package/src/privacy-backends/rate-limiter.ts +683 -0
- package/src/privacy-backends/registry.ts +690 -0
- package/src/privacy-backends/router.ts +626 -0
- package/src/privacy-backends/shadowwire.ts +449 -0
- package/src/privacy-backends/sip-native.ts +256 -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 +111 -30
- 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/surveillance/algorithms/address-reuse.ts +143 -0
- package/src/surveillance/algorithms/cluster.ts +247 -0
- package/src/surveillance/algorithms/exchange.ts +295 -0
- package/src/surveillance/algorithms/temporal.ts +337 -0
- package/src/surveillance/analyzer.ts +442 -0
- package/src/surveillance/index.ts +64 -0
- package/src/surveillance/scoring.ts +372 -0
- package/src/surveillance/types.ts +264 -0
- 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-3INS3PR5.mjs +0 -884
- package/dist/chunk-3OVABDRH.mjs +0 -17096
- package/dist/chunk-DLDWZFYC.mjs +0 -1495
- package/dist/chunk-E6SZWREQ.mjs +0 -57
- package/dist/chunk-G33LB27A.mjs +0 -16166
- package/dist/chunk-HGU6HZRC.mjs +0 -231
- package/dist/chunk-L2K34JCU.mjs +0 -1496
- package/dist/chunk-SN4ZDTVW.mjs +0 -16166
- package/dist/constants-VOI7BSLK.mjs +0 -27
- 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-xbWjohNq.d.mts +0 -11390
- package/dist/solana-5EMCTPTS.mjs +0 -46
- package/dist/solana-Q4NAVBTS.mjs +0 -46
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof Format Converter Interface
|
|
3
|
+
*
|
|
4
|
+
* Defines the interface for converting proofs between native formats
|
|
5
|
+
* (Noir, Halo2, Kimchi) and the unified SIP proof format.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
ProofSystem,
|
|
12
|
+
SingleProof,
|
|
13
|
+
HexString,
|
|
14
|
+
} from '@sip-protocol/types'
|
|
15
|
+
|
|
16
|
+
// ─── Native Proof Formats ────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Base interface for native proof formats
|
|
20
|
+
*/
|
|
21
|
+
export interface NativeProofFormat {
|
|
22
|
+
/** The proof system this format belongs to */
|
|
23
|
+
readonly system: ProofSystem
|
|
24
|
+
/** Raw proof bytes/data */
|
|
25
|
+
proofData: Uint8Array | HexString
|
|
26
|
+
/** Public inputs in native format */
|
|
27
|
+
publicInputs: unknown[]
|
|
28
|
+
/** System-specific verification key */
|
|
29
|
+
verificationKey?: Uint8Array | HexString
|
|
30
|
+
/** Native metadata specific to the proof system */
|
|
31
|
+
nativeMetadata?: Record<string, unknown>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Noir native proof format
|
|
36
|
+
*/
|
|
37
|
+
export interface NoirNativeProof extends NativeProofFormat {
|
|
38
|
+
readonly system: 'noir'
|
|
39
|
+
/** Noir proof bytes (Barretenberg format) */
|
|
40
|
+
proofData: Uint8Array
|
|
41
|
+
/** Public inputs as field elements */
|
|
42
|
+
publicInputs: string[]
|
|
43
|
+
/** ACIR circuit artifact hash */
|
|
44
|
+
circuitHash?: string
|
|
45
|
+
/** Noir version that generated this proof */
|
|
46
|
+
noirVersion?: string
|
|
47
|
+
/** Backend version (Barretenberg) */
|
|
48
|
+
backendVersion?: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Halo2 native proof format
|
|
53
|
+
*/
|
|
54
|
+
export interface Halo2NativeProof extends NativeProofFormat {
|
|
55
|
+
readonly system: 'halo2'
|
|
56
|
+
/** Halo2 proof transcript */
|
|
57
|
+
proofData: Uint8Array
|
|
58
|
+
/** Public inputs as field elements */
|
|
59
|
+
publicInputs: string[]
|
|
60
|
+
/** Proving key commitment */
|
|
61
|
+
provingKeyCommitment?: HexString
|
|
62
|
+
/** Circuit degree (k value) */
|
|
63
|
+
k?: number
|
|
64
|
+
/** Halo2 library version */
|
|
65
|
+
halo2Version?: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Kimchi native proof format (Mina Protocol)
|
|
70
|
+
*/
|
|
71
|
+
export interface KimchiNativeProof extends NativeProofFormat {
|
|
72
|
+
readonly system: 'kimchi'
|
|
73
|
+
/** Kimchi proof data */
|
|
74
|
+
proofData: Uint8Array
|
|
75
|
+
/** Public inputs as Pasta field elements */
|
|
76
|
+
publicInputs: string[]
|
|
77
|
+
/** SRS (Structured Reference String) hash */
|
|
78
|
+
srsHash?: HexString
|
|
79
|
+
/** Kimchi/o1js version */
|
|
80
|
+
kimchiVersion?: string
|
|
81
|
+
/** Verifier index commitment */
|
|
82
|
+
verifierIndexCommitment?: HexString
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ─── Conversion Types ────────────────────────────────────────────────────────
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Options for proof conversion
|
|
89
|
+
*/
|
|
90
|
+
export interface ConversionOptions {
|
|
91
|
+
/** Preserve all native metadata in the output */
|
|
92
|
+
preserveNativeMetadata?: boolean
|
|
93
|
+
/** Validate proof structure before conversion */
|
|
94
|
+
validateBeforeConversion?: boolean
|
|
95
|
+
/** Include verification key in output */
|
|
96
|
+
includeVerificationKey?: boolean
|
|
97
|
+
/** Target chain ID for the converted proof */
|
|
98
|
+
targetChainId?: string
|
|
99
|
+
/** Custom ID generator for the output proof */
|
|
100
|
+
idGenerator?: () => string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Result of a conversion operation
|
|
105
|
+
*/
|
|
106
|
+
export interface ConversionResult<T> {
|
|
107
|
+
/** Whether conversion was successful */
|
|
108
|
+
success: boolean
|
|
109
|
+
/** The converted proof (if successful) */
|
|
110
|
+
result?: T
|
|
111
|
+
/** Error message (if failed) */
|
|
112
|
+
error?: string
|
|
113
|
+
/** Detailed error code for programmatic handling */
|
|
114
|
+
errorCode?: ConversionErrorCode
|
|
115
|
+
/** Warnings generated during conversion */
|
|
116
|
+
warnings?: string[]
|
|
117
|
+
/** Whether the conversion was lossless */
|
|
118
|
+
lossless: boolean
|
|
119
|
+
/** Metadata about the conversion process */
|
|
120
|
+
conversionMetadata: ConversionMetadata
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Metadata about the conversion process
|
|
125
|
+
*/
|
|
126
|
+
export interface ConversionMetadata {
|
|
127
|
+
/** Source format/system */
|
|
128
|
+
sourceSystem: ProofSystem
|
|
129
|
+
/** Target format/system */
|
|
130
|
+
targetSystem: ProofSystem | 'sip'
|
|
131
|
+
/** Conversion timestamp */
|
|
132
|
+
convertedAt: number
|
|
133
|
+
/** Converter version */
|
|
134
|
+
converterVersion: string
|
|
135
|
+
/** Time taken for conversion (ms) */
|
|
136
|
+
conversionTimeMs: number
|
|
137
|
+
/** Original proof size (bytes) */
|
|
138
|
+
originalSize: number
|
|
139
|
+
/** Converted proof size (bytes) */
|
|
140
|
+
convertedSize: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Error codes for conversion failures
|
|
145
|
+
*/
|
|
146
|
+
export type ConversionErrorCode =
|
|
147
|
+
| 'INVALID_INPUT'
|
|
148
|
+
| 'UNSUPPORTED_VERSION'
|
|
149
|
+
| 'MISSING_REQUIRED_FIELD'
|
|
150
|
+
| 'VALIDATION_FAILED'
|
|
151
|
+
| 'ENCODING_ERROR'
|
|
152
|
+
| 'DECODING_ERROR'
|
|
153
|
+
| 'METADATA_ERROR'
|
|
154
|
+
| 'UNKNOWN_ERROR'
|
|
155
|
+
|
|
156
|
+
// ─── Converter Interface ─────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Interface for proof format converters
|
|
160
|
+
*
|
|
161
|
+
* Converters transform proofs between native formats and the unified SIP format.
|
|
162
|
+
* All converters should:
|
|
163
|
+
* - Be pure functions (no side effects)
|
|
164
|
+
* - Preserve proof validity
|
|
165
|
+
* - Handle version differences gracefully
|
|
166
|
+
* - Provide detailed error information
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const converter = new NoirProofConverter()
|
|
171
|
+
*
|
|
172
|
+
* // Convert Noir proof to SIP format
|
|
173
|
+
* const result = converter.toSIP(noirProof, {
|
|
174
|
+
* preserveNativeMetadata: true,
|
|
175
|
+
* })
|
|
176
|
+
*
|
|
177
|
+
* if (result.success) {
|
|
178
|
+
* const sipProof = result.result!
|
|
179
|
+
* console.log('Converted proof:', sipProof.id)
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export interface ProofConverter<TNative extends NativeProofFormat> {
|
|
184
|
+
/** The proof system this converter handles */
|
|
185
|
+
readonly system: ProofSystem
|
|
186
|
+
|
|
187
|
+
/** Converter version for tracking */
|
|
188
|
+
readonly version: string
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Convert from native format to SIP unified format
|
|
192
|
+
*
|
|
193
|
+
* @param nativeProof - The native proof to convert
|
|
194
|
+
* @param options - Conversion options
|
|
195
|
+
* @returns Conversion result with SIP proof
|
|
196
|
+
*/
|
|
197
|
+
toSIP(
|
|
198
|
+
nativeProof: TNative,
|
|
199
|
+
options?: ConversionOptions,
|
|
200
|
+
): ConversionResult<SingleProof>
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Convert from SIP unified format to native format
|
|
204
|
+
*
|
|
205
|
+
* @param sipProof - The SIP proof to convert
|
|
206
|
+
* @param options - Conversion options
|
|
207
|
+
* @returns Conversion result with native proof
|
|
208
|
+
*/
|
|
209
|
+
fromSIP(
|
|
210
|
+
sipProof: SingleProof,
|
|
211
|
+
options?: ConversionOptions,
|
|
212
|
+
): ConversionResult<TNative>
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Validate a native proof structure without converting
|
|
216
|
+
*
|
|
217
|
+
* @param nativeProof - The native proof to validate
|
|
218
|
+
* @returns Validation result
|
|
219
|
+
*/
|
|
220
|
+
validateNative(nativeProof: TNative): ValidationResult
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Check if a SIP proof can be converted to this native format
|
|
224
|
+
*
|
|
225
|
+
* @param sipProof - The SIP proof to check
|
|
226
|
+
* @returns Whether conversion is possible
|
|
227
|
+
*/
|
|
228
|
+
canConvertFromSIP(sipProof: SingleProof): boolean
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get supported versions for this converter
|
|
232
|
+
*
|
|
233
|
+
* @returns List of supported system versions
|
|
234
|
+
*/
|
|
235
|
+
getSupportedVersions(): string[]
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Validation result for proof structure
|
|
240
|
+
*/
|
|
241
|
+
export interface ValidationResult {
|
|
242
|
+
/** Whether the proof is valid */
|
|
243
|
+
valid: boolean
|
|
244
|
+
/** Validation errors (if any) */
|
|
245
|
+
errors: ValidationError[]
|
|
246
|
+
/** Validation warnings */
|
|
247
|
+
warnings: string[]
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Validation error details
|
|
252
|
+
*/
|
|
253
|
+
export interface ValidationError {
|
|
254
|
+
/** Field that failed validation */
|
|
255
|
+
field: string
|
|
256
|
+
/** Error message */
|
|
257
|
+
message: string
|
|
258
|
+
/** Error code */
|
|
259
|
+
code: string
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ─── Error Classes ───────────────────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Base error class for conversion errors
|
|
266
|
+
*/
|
|
267
|
+
export class ProofConversionError extends Error {
|
|
268
|
+
readonly code: ConversionErrorCode
|
|
269
|
+
readonly sourceSystem: ProofSystem
|
|
270
|
+
readonly targetSystem: ProofSystem | 'sip'
|
|
271
|
+
readonly cause?: Error
|
|
272
|
+
|
|
273
|
+
constructor(
|
|
274
|
+
code: ConversionErrorCode,
|
|
275
|
+
message: string,
|
|
276
|
+
sourceSystem: ProofSystem,
|
|
277
|
+
targetSystem: ProofSystem | 'sip',
|
|
278
|
+
cause?: Error,
|
|
279
|
+
) {
|
|
280
|
+
super(message)
|
|
281
|
+
this.name = 'ProofConversionError'
|
|
282
|
+
this.code = code
|
|
283
|
+
this.sourceSystem = sourceSystem
|
|
284
|
+
this.targetSystem = targetSystem
|
|
285
|
+
this.cause = cause
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Error for invalid input proofs
|
|
291
|
+
*/
|
|
292
|
+
export class InvalidProofError extends ProofConversionError {
|
|
293
|
+
readonly validationErrors: ValidationError[]
|
|
294
|
+
|
|
295
|
+
constructor(
|
|
296
|
+
sourceSystem: ProofSystem,
|
|
297
|
+
targetSystem: ProofSystem | 'sip',
|
|
298
|
+
validationErrors: ValidationError[],
|
|
299
|
+
) {
|
|
300
|
+
const errorSummary = validationErrors.map(e => `${e.field}: ${e.message}`).join('; ')
|
|
301
|
+
super(
|
|
302
|
+
'INVALID_INPUT',
|
|
303
|
+
`Invalid proof structure: ${errorSummary}`,
|
|
304
|
+
sourceSystem,
|
|
305
|
+
targetSystem,
|
|
306
|
+
)
|
|
307
|
+
this.name = 'InvalidProofError'
|
|
308
|
+
this.validationErrors = validationErrors
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Error for unsupported proof system versions
|
|
314
|
+
*/
|
|
315
|
+
export class UnsupportedVersionError extends ProofConversionError {
|
|
316
|
+
readonly providedVersion: string
|
|
317
|
+
readonly supportedVersions: string[]
|
|
318
|
+
|
|
319
|
+
constructor(
|
|
320
|
+
sourceSystem: ProofSystem,
|
|
321
|
+
providedVersion: string,
|
|
322
|
+
supportedVersions: string[],
|
|
323
|
+
) {
|
|
324
|
+
super(
|
|
325
|
+
'UNSUPPORTED_VERSION',
|
|
326
|
+
`Version ${providedVersion} is not supported. Supported: ${supportedVersions.join(', ')}`,
|
|
327
|
+
sourceSystem,
|
|
328
|
+
'sip',
|
|
329
|
+
)
|
|
330
|
+
this.name = 'UnsupportedVersionError'
|
|
331
|
+
this.providedVersion = providedVersion
|
|
332
|
+
this.supportedVersions = supportedVersions
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ─── Utility Types ───────────────────────────────────────────────────────────
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Union type of all native proof formats
|
|
340
|
+
*/
|
|
341
|
+
export type AnyNativeProof = NoirNativeProof | Halo2NativeProof | KimchiNativeProof
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Map of proof systems to their native proof types
|
|
345
|
+
*/
|
|
346
|
+
export interface ProofSystemToNativeMap {
|
|
347
|
+
noir: NoirNativeProof
|
|
348
|
+
halo2: Halo2NativeProof
|
|
349
|
+
kimchi: KimchiNativeProof
|
|
350
|
+
groth16: NativeProofFormat
|
|
351
|
+
plonk: NativeProofFormat
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Default conversion options
|
|
356
|
+
*/
|
|
357
|
+
export const DEFAULT_CONVERSION_OPTIONS: Required<ConversionOptions> = {
|
|
358
|
+
preserveNativeMetadata: true,
|
|
359
|
+
validateBeforeConversion: true,
|
|
360
|
+
includeVerificationKey: true,
|
|
361
|
+
targetChainId: '',
|
|
362
|
+
idGenerator: () => `proof-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
|
|
363
|
+
}
|