@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
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solana Noir Verifier Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for verifying Noir ZK proofs on Solana.
|
|
5
|
+
*
|
|
6
|
+
* ## Architecture
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* ┌─────────────────────────────────────────────────────────────┐
|
|
10
|
+
* │ NOIR PROOF FLOW ON SOLANA │
|
|
11
|
+
* │ │
|
|
12
|
+
* │ 1. Generate proof (BrowserNoirProvider / NoirProofProvider)│
|
|
13
|
+
* │ 2. Serialize for Solana (SolanaNoirVerifier) │
|
|
14
|
+
* │ 3. Submit to Solana program (verify instruction) │
|
|
15
|
+
* │ 4. On-chain verification (ZK Token Proof / Custom) │
|
|
16
|
+
* └─────────────────────────────────────────────────────────────┘
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @module solana/noir-verifier-types
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { SOLANA_RPC_ENDPOINTS as SOLANA_RPC_CONFIG } from '../config/endpoints'
|
|
23
|
+
|
|
24
|
+
import type { ZKProof } from '@sip-protocol/types'
|
|
25
|
+
|
|
26
|
+
// ─── Circuit Types ───────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Supported Noir circuit types for Solana verification
|
|
30
|
+
*/
|
|
31
|
+
export type NoirCircuitType = 'funding' | 'validity' | 'fulfillment'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Circuit metadata for verification key generation
|
|
35
|
+
*/
|
|
36
|
+
export interface CircuitMetadata {
|
|
37
|
+
/** Circuit type identifier */
|
|
38
|
+
type: NoirCircuitType
|
|
39
|
+
/** Number of public inputs */
|
|
40
|
+
publicInputCount: number
|
|
41
|
+
/** Approximate constraint count */
|
|
42
|
+
constraintCount: number
|
|
43
|
+
/** Circuit version hash */
|
|
44
|
+
versionHash: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Circuit metadata for all supported circuits
|
|
49
|
+
*/
|
|
50
|
+
export const CIRCUIT_METADATA: Record<NoirCircuitType, CircuitMetadata> = {
|
|
51
|
+
funding: {
|
|
52
|
+
type: 'funding',
|
|
53
|
+
publicInputCount: 3, // commitment_hash, minimum_required, asset_id
|
|
54
|
+
constraintCount: 2000,
|
|
55
|
+
versionHash: 'v1.0.0-funding',
|
|
56
|
+
},
|
|
57
|
+
validity: {
|
|
58
|
+
type: 'validity',
|
|
59
|
+
publicInputCount: 6, // intent_hash, commitment_x, commitment_y, nullifier, timestamp, expiry
|
|
60
|
+
constraintCount: 72000,
|
|
61
|
+
versionHash: 'v1.0.0-validity',
|
|
62
|
+
},
|
|
63
|
+
fulfillment: {
|
|
64
|
+
type: 'fulfillment',
|
|
65
|
+
publicInputCount: 8, // intent_hash, commitment_x, commitment_y, recipient_stealth, min_output, solver_id, fulfillment_time, expiry
|
|
66
|
+
constraintCount: 22000,
|
|
67
|
+
versionHash: 'v1.0.0-fulfillment',
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ─── Verification Key Types ──────────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Verification key for Solana on-chain verification
|
|
75
|
+
*
|
|
76
|
+
* Contains the cryptographic parameters needed to verify proofs on-chain.
|
|
77
|
+
*/
|
|
78
|
+
export interface SolanaVerificationKey {
|
|
79
|
+
/** Circuit type this key is for */
|
|
80
|
+
circuitType: NoirCircuitType
|
|
81
|
+
/** Serialized verification key bytes */
|
|
82
|
+
keyBytes: Uint8Array
|
|
83
|
+
/** Key hash for integrity check */
|
|
84
|
+
keyHash: string
|
|
85
|
+
/** Number of public inputs expected */
|
|
86
|
+
publicInputCount: number
|
|
87
|
+
/** Solana account address where key is stored (if deployed) */
|
|
88
|
+
accountAddress?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Verification key account data layout for Solana
|
|
93
|
+
*/
|
|
94
|
+
export interface VerificationKeyAccountData {
|
|
95
|
+
/** Discriminator for account type */
|
|
96
|
+
discriminator: Uint8Array
|
|
97
|
+
/** Circuit type identifier */
|
|
98
|
+
circuitType: number
|
|
99
|
+
/** Verification key data */
|
|
100
|
+
keyData: Uint8Array
|
|
101
|
+
/** Authority that can update */
|
|
102
|
+
authority: Uint8Array
|
|
103
|
+
/** Bump seed for PDA */
|
|
104
|
+
bump: number
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ─── Proof Serialization Types ───────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Solana-serialized proof ready for on-chain verification
|
|
111
|
+
*/
|
|
112
|
+
export interface SolanaSerializedProof {
|
|
113
|
+
/** Original proof type */
|
|
114
|
+
circuitType: NoirCircuitType
|
|
115
|
+
/** Proof bytes in Solana-compatible format */
|
|
116
|
+
proofBytes: Uint8Array
|
|
117
|
+
/** Public inputs as Field elements (32 bytes each) */
|
|
118
|
+
publicInputs: Uint8Array[]
|
|
119
|
+
/** Total serialized size in bytes */
|
|
120
|
+
totalSize: number
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Proof verification result from Solana
|
|
125
|
+
*/
|
|
126
|
+
export interface SolanaVerificationResult {
|
|
127
|
+
/** Whether the proof is valid */
|
|
128
|
+
valid: boolean
|
|
129
|
+
/** Transaction signature if submitted on-chain */
|
|
130
|
+
signature?: string
|
|
131
|
+
/** Slot number of verification */
|
|
132
|
+
slot?: number
|
|
133
|
+
/** Compute units used */
|
|
134
|
+
computeUnits?: number
|
|
135
|
+
/** Error message if verification failed */
|
|
136
|
+
error?: string
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ─── Instruction Types ───────────────────────────────────────────────────────
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Verify instruction data layout
|
|
143
|
+
*/
|
|
144
|
+
export interface VerifyInstructionData {
|
|
145
|
+
/** Instruction discriminator */
|
|
146
|
+
discriminator: number
|
|
147
|
+
/** Proof bytes */
|
|
148
|
+
proof: Uint8Array
|
|
149
|
+
/** Public inputs */
|
|
150
|
+
publicInputs: Uint8Array[]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Solana instruction for proof verification
|
|
155
|
+
*/
|
|
156
|
+
export interface SolanaVerifyInstruction {
|
|
157
|
+
/** Program ID to call */
|
|
158
|
+
programId: string
|
|
159
|
+
/** Instruction data */
|
|
160
|
+
data: Uint8Array
|
|
161
|
+
/** Account keys required */
|
|
162
|
+
keys: SolanaAccountMeta[]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Account metadata for Solana instruction
|
|
167
|
+
*/
|
|
168
|
+
export interface SolanaAccountMeta {
|
|
169
|
+
/** Account public key */
|
|
170
|
+
pubkey: string
|
|
171
|
+
/** Is signer */
|
|
172
|
+
isSigner: boolean
|
|
173
|
+
/** Is writable */
|
|
174
|
+
isWritable: boolean
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ─── Configuration Types ─────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Network configuration for Solana
|
|
181
|
+
*/
|
|
182
|
+
export type SolanaNetwork = 'mainnet-beta' | 'devnet' | 'testnet' | 'localnet'
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Solana Noir Verifier configuration
|
|
186
|
+
*/
|
|
187
|
+
export interface SolanaNoirVerifierConfig {
|
|
188
|
+
/**
|
|
189
|
+
* Solana network to use
|
|
190
|
+
* @default 'devnet'
|
|
191
|
+
*/
|
|
192
|
+
network?: SolanaNetwork
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Custom RPC endpoint URL
|
|
196
|
+
* If not provided, uses default for network
|
|
197
|
+
*/
|
|
198
|
+
rpcUrl?: string
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Verification program ID
|
|
202
|
+
* Uses native ZK Token Proof program by default
|
|
203
|
+
*/
|
|
204
|
+
programId?: string
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Enable verbose logging
|
|
208
|
+
* @default false
|
|
209
|
+
*/
|
|
210
|
+
verbose?: boolean
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Commitment level for transactions
|
|
214
|
+
* @default 'confirmed'
|
|
215
|
+
*/
|
|
216
|
+
commitment?: 'processed' | 'confirmed' | 'finalized'
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Maximum compute units for verification
|
|
220
|
+
* @default 400000
|
|
221
|
+
*/
|
|
222
|
+
maxComputeUnits?: number
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Default RPC URLs for each network
|
|
227
|
+
* Localnet is configurable via SOLANA_LOCALNET_RPC environment variable
|
|
228
|
+
*/
|
|
229
|
+
export const DEFAULT_RPC_URLS: Record<SolanaNetwork, string> = {
|
|
230
|
+
'mainnet-beta': SOLANA_RPC_CONFIG.mainnet,
|
|
231
|
+
devnet: SOLANA_RPC_CONFIG.devnet,
|
|
232
|
+
testnet: SOLANA_RPC_CONFIG.testnet,
|
|
233
|
+
localnet: SOLANA_RPC_CONFIG.localnet,
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Native Solana ZK proof program IDs
|
|
238
|
+
*
|
|
239
|
+
* Note: These are the native Solana programs for ZK proof verification.
|
|
240
|
+
* For custom Noir circuits, a dedicated verifier program would be needed.
|
|
241
|
+
*/
|
|
242
|
+
export const SOLANA_ZK_PROGRAM_IDS = {
|
|
243
|
+
/** ZK Token Proof Program (native) */
|
|
244
|
+
ZK_TOKEN_PROOF: 'ZkTokenProof1111111111111111111111111111111',
|
|
245
|
+
/** ZK ElGamal Proof Program (native) */
|
|
246
|
+
ZK_ELGAMAL_PROOF: 'ZkE1Gama1Proof11111111111111111111111111111',
|
|
247
|
+
/** Custom SIP Noir Verifier (TBD - to be deployed) */
|
|
248
|
+
SIP_NOIR_VERIFIER: 'SIPNoirVerifier1111111111111111111111111',
|
|
249
|
+
} as const
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Sunspot-deployed verifier program IDs for each circuit type
|
|
253
|
+
*
|
|
254
|
+
* These are Groth16 verifiers built with Sunspot and deployed to Solana.
|
|
255
|
+
* Each circuit type has its own dedicated verifier program.
|
|
256
|
+
*/
|
|
257
|
+
export const SUNSPOT_VERIFIER_PROGRAM_IDS = {
|
|
258
|
+
/** Funding proof verifier (devnet) - proves sufficient balance */
|
|
259
|
+
FUNDING_PROOF_DEVNET: '3nqQEuio4AVJo8H9pZJoERNFERWD5JNSqYan4UnsHhim',
|
|
260
|
+
/** Validity proof verifier (devnet) - proves intent authorization */
|
|
261
|
+
VALIDITY_PROOF_DEVNET: '', // TBD
|
|
262
|
+
/** Fulfillment proof verifier (devnet) - proves correct execution */
|
|
263
|
+
FULFILLMENT_PROOF_DEVNET: '', // TBD
|
|
264
|
+
/** Funding proof verifier (mainnet) */
|
|
265
|
+
FUNDING_PROOF_MAINNET: '', // TBD
|
|
266
|
+
/** Validity proof verifier (mainnet) */
|
|
267
|
+
VALIDITY_PROOF_MAINNET: '', // TBD
|
|
268
|
+
/** Fulfillment proof verifier (mainnet) */
|
|
269
|
+
FULFILLMENT_PROOF_MAINNET: '', // TBD
|
|
270
|
+
} as const
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get the verifier program ID for a circuit type and network
|
|
274
|
+
*/
|
|
275
|
+
export function getSunspotVerifierProgramId(
|
|
276
|
+
circuitType: NoirCircuitType,
|
|
277
|
+
network: SolanaNetwork
|
|
278
|
+
): string | null {
|
|
279
|
+
const isMainnet = network === 'mainnet-beta'
|
|
280
|
+
|
|
281
|
+
switch (circuitType) {
|
|
282
|
+
case 'funding':
|
|
283
|
+
return isMainnet
|
|
284
|
+
? SUNSPOT_VERIFIER_PROGRAM_IDS.FUNDING_PROOF_MAINNET || null
|
|
285
|
+
: SUNSPOT_VERIFIER_PROGRAM_IDS.FUNDING_PROOF_DEVNET || null
|
|
286
|
+
case 'validity':
|
|
287
|
+
return isMainnet
|
|
288
|
+
? SUNSPOT_VERIFIER_PROGRAM_IDS.VALIDITY_PROOF_MAINNET || null
|
|
289
|
+
: SUNSPOT_VERIFIER_PROGRAM_IDS.VALIDITY_PROOF_DEVNET || null
|
|
290
|
+
case 'fulfillment':
|
|
291
|
+
return isMainnet
|
|
292
|
+
? SUNSPOT_VERIFIER_PROGRAM_IDS.FULFILLMENT_PROOF_MAINNET || null
|
|
293
|
+
: SUNSPOT_VERIFIER_PROGRAM_IDS.FULFILLMENT_PROOF_DEVNET || null
|
|
294
|
+
default:
|
|
295
|
+
return null
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ─── Error Types ─────────────────────────────────────────────────────────────
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Error codes for Solana Noir verification
|
|
303
|
+
*/
|
|
304
|
+
export enum SolanaNoirErrorCode {
|
|
305
|
+
/** Invalid proof format */
|
|
306
|
+
INVALID_PROOF_FORMAT = 'INVALID_PROOF_FORMAT',
|
|
307
|
+
/** Invalid public inputs */
|
|
308
|
+
INVALID_PUBLIC_INPUTS = 'INVALID_PUBLIC_INPUTS',
|
|
309
|
+
/** Verification failed on-chain */
|
|
310
|
+
VERIFICATION_FAILED = 'VERIFICATION_FAILED',
|
|
311
|
+
/** Network error */
|
|
312
|
+
NETWORK_ERROR = 'NETWORK_ERROR',
|
|
313
|
+
/** Insufficient compute units */
|
|
314
|
+
INSUFFICIENT_COMPUTE = 'INSUFFICIENT_COMPUTE',
|
|
315
|
+
/** Verification key not found */
|
|
316
|
+
VKEY_NOT_FOUND = 'VKEY_NOT_FOUND',
|
|
317
|
+
/** Unsupported circuit type */
|
|
318
|
+
UNSUPPORTED_CIRCUIT = 'UNSUPPORTED_CIRCUIT',
|
|
319
|
+
/** Transaction failed */
|
|
320
|
+
TRANSACTION_FAILED = 'TRANSACTION_FAILED',
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Solana Noir verification error
|
|
325
|
+
*/
|
|
326
|
+
export class SolanaNoirError extends Error {
|
|
327
|
+
constructor(
|
|
328
|
+
message: string,
|
|
329
|
+
public readonly code: SolanaNoirErrorCode,
|
|
330
|
+
public readonly details?: Record<string, unknown>
|
|
331
|
+
) {
|
|
332
|
+
super(message)
|
|
333
|
+
this.name = 'SolanaNoirError'
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ─── Size Limits ─────────────────────────────────────────────────────────────
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Maximum proof size in bytes
|
|
341
|
+
*
|
|
342
|
+
* UltraHonk proofs are typically ~2KB, but we allow up to 4KB for safety.
|
|
343
|
+
*/
|
|
344
|
+
export const MAX_PROOF_SIZE_BYTES = 4096
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Maximum number of public inputs
|
|
348
|
+
*
|
|
349
|
+
* Based on Solana transaction size limits and our circuit designs.
|
|
350
|
+
*/
|
|
351
|
+
export const MAX_PUBLIC_INPUTS = 32
|
|
352
|
+
|
|
353
|
+
// ─── Utility Types ───────────────────────────────────────────────────────────
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Proof statistics for monitoring
|
|
357
|
+
*/
|
|
358
|
+
export interface ProofStatistics {
|
|
359
|
+
/** Circuit type */
|
|
360
|
+
circuitType: NoirCircuitType
|
|
361
|
+
/** Proof size in bytes */
|
|
362
|
+
proofSize: number
|
|
363
|
+
/** Public inputs size in bytes */
|
|
364
|
+
publicInputsSize: number
|
|
365
|
+
/** Total serialized size */
|
|
366
|
+
totalSize: number
|
|
367
|
+
/** Estimated compute units */
|
|
368
|
+
estimatedComputeUnits: number
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Batch verification request
|
|
373
|
+
*/
|
|
374
|
+
export interface BatchVerificationRequest {
|
|
375
|
+
/** Proofs to verify */
|
|
376
|
+
proofs: ZKProof[]
|
|
377
|
+
/** Whether to fail fast on first invalid proof */
|
|
378
|
+
failFast?: boolean
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Batch verification result
|
|
383
|
+
*/
|
|
384
|
+
export interface BatchVerificationResult {
|
|
385
|
+
/** Overall success */
|
|
386
|
+
success: boolean
|
|
387
|
+
/** Results for each proof */
|
|
388
|
+
results: SolanaVerificationResult[]
|
|
389
|
+
/** Total proofs verified */
|
|
390
|
+
totalVerified: number
|
|
391
|
+
/** Number of valid proofs */
|
|
392
|
+
validCount: number
|
|
393
|
+
/** Total compute units used */
|
|
394
|
+
totalComputeUnits: number
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ─── Type Guards ─────────────────────────────────────────────────────────────
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Check if a string is a valid circuit type
|
|
401
|
+
*/
|
|
402
|
+
export function isNoirCircuitType(value: string): value is NoirCircuitType {
|
|
403
|
+
return value === 'funding' || value === 'validity' || value === 'fulfillment'
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Check if a proof has the expected structure for Solana verification
|
|
408
|
+
*/
|
|
409
|
+
export function isValidSolanaProof(proof: unknown): proof is ZKProof {
|
|
410
|
+
if (!proof || typeof proof !== 'object') return false
|
|
411
|
+
const p = proof as Record<string, unknown>
|
|
412
|
+
return (
|
|
413
|
+
typeof p.type === 'string' &&
|
|
414
|
+
isNoirCircuitType(p.type) &&
|
|
415
|
+
typeof p.proof === 'string' &&
|
|
416
|
+
Array.isArray(p.publicInputs)
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Estimate compute units for verification
|
|
422
|
+
*
|
|
423
|
+
* Based on circuit complexity and proof size
|
|
424
|
+
*/
|
|
425
|
+
export function estimateComputeUnits(circuitType: NoirCircuitType): number {
|
|
426
|
+
const baseUnits = 50000
|
|
427
|
+
const constraintFactor = 0.005 // CU per constraint
|
|
428
|
+
const metadata = CIRCUIT_METADATA[circuitType]
|
|
429
|
+
return Math.ceil(baseUnits + metadata.constraintCount * constraintFactor)
|
|
430
|
+
}
|