@fluxpointstudios/orynq-sdk-midnight-prover 0.1.0
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/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/linking/cardano-anchor-link.d.ts +250 -0
- package/dist/linking/cardano-anchor-link.d.ts.map +1 -0
- package/dist/linking/cardano-anchor-link.js +447 -0
- package/dist/linking/cardano-anchor-link.js.map +1 -0
- package/dist/linking/index.d.ts +33 -0
- package/dist/linking/index.d.ts.map +1 -0
- package/dist/linking/index.js +31 -0
- package/dist/linking/index.js.map +1 -0
- package/dist/linking/proof-publication.d.ts +217 -0
- package/dist/linking/proof-publication.d.ts.map +1 -0
- package/dist/linking/proof-publication.js +385 -0
- package/dist/linking/proof-publication.js.map +1 -0
- package/dist/midnight/index.d.ts +30 -0
- package/dist/midnight/index.d.ts.map +1 -0
- package/dist/midnight/index.js +27 -0
- package/dist/midnight/index.js.map +1 -0
- package/dist/midnight/proof-server-client.d.ts +236 -0
- package/dist/midnight/proof-server-client.d.ts.map +1 -0
- package/dist/midnight/proof-server-client.js +422 -0
- package/dist/midnight/proof-server-client.js.map +1 -0
- package/dist/midnight/public-inputs.d.ts +134 -0
- package/dist/midnight/public-inputs.d.ts.map +1 -0
- package/dist/midnight/public-inputs.js +338 -0
- package/dist/midnight/public-inputs.js.map +1 -0
- package/dist/midnight/witness-builder.d.ts +119 -0
- package/dist/midnight/witness-builder.d.ts.map +1 -0
- package/dist/midnight/witness-builder.js +238 -0
- package/dist/midnight/witness-builder.js.map +1 -0
- package/dist/proofs/hash-chain-proof.d.ts +171 -0
- package/dist/proofs/hash-chain-proof.d.ts.map +1 -0
- package/dist/proofs/hash-chain-proof.js +437 -0
- package/dist/proofs/hash-chain-proof.js.map +1 -0
- package/dist/proofs/index.d.ts +35 -0
- package/dist/proofs/index.d.ts.map +1 -0
- package/dist/proofs/index.js +34 -0
- package/dist/proofs/index.js.map +1 -0
- package/dist/proofs/policy-compliance-proof.d.ts +165 -0
- package/dist/proofs/policy-compliance-proof.d.ts.map +1 -0
- package/dist/proofs/policy-compliance-proof.js +514 -0
- package/dist/proofs/policy-compliance-proof.js.map +1 -0
- package/dist/proofs/selective-disclosure.d.ts +213 -0
- package/dist/proofs/selective-disclosure.d.ts.map +1 -0
- package/dist/proofs/selective-disclosure.js +629 -0
- package/dist/proofs/selective-disclosure.js.map +1 -0
- package/dist/prover-interface.d.ts +288 -0
- package/dist/prover-interface.d.ts.map +1 -0
- package/dist/prover-interface.js +114 -0
- package/dist/prover-interface.js.map +1 -0
- package/dist/prover.d.ts +163 -0
- package/dist/prover.d.ts.map +1 -0
- package/dist/prover.js +417 -0
- package/dist/prover.js.map +1 -0
- package/dist/types.d.ts +410 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +128 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
- package/src/__tests__/hash-chain-proof.test.ts +709 -0
- package/src/__tests__/midnight-prover.test.ts +716 -0
- package/src/__tests__/policy-compliance.test.ts +567 -0
- package/src/__tests__/proof-publication.test.ts +644 -0
- package/src/__tests__/selective-disclosure.test.ts +921 -0
- package/src/index.ts +260 -0
- package/src/linking/cardano-anchor-link.ts +682 -0
- package/src/linking/index.ts +58 -0
- package/src/linking/proof-publication.ts +557 -0
- package/src/midnight/index.ts +73 -0
- package/src/midnight/proof-server-client.ts +595 -0
- package/src/midnight/public-inputs.ts +590 -0
- package/src/midnight/witness-builder.ts +341 -0
- package/src/proofs/hash-chain-proof.ts +610 -0
- package/src/proofs/index.ts +77 -0
- package/src/proofs/policy-compliance-proof.ts +717 -0
- package/src/proofs/selective-disclosure.ts +839 -0
- package/src/prover-interface.ts +410 -0
- package/src/prover.ts +537 -0
- package/src/types.ts +551 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Flux Point Studios
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PoI Midnight Prover Package
|
|
3
|
+
*
|
|
4
|
+
* ZK proof generation for PoI using the Midnight network.
|
|
5
|
+
* Enables privacy-preserving verification of trace properties.
|
|
6
|
+
*
|
|
7
|
+
* Location: packages/midnight-prover/src/index.ts
|
|
8
|
+
*
|
|
9
|
+
* Summary:
|
|
10
|
+
* This is the main entry point for the poi-midnight-prover package. It re-exports
|
|
11
|
+
* all public types, interfaces, and utilities for ZK proof generation.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* The package integrates with:
|
|
15
|
+
* - poi-process-trace: Provides TraceEvent and TraceBundle data for proofs
|
|
16
|
+
* - poi-attestor: Provides AttestationBundle for attestation proofs
|
|
17
|
+
* - poi-anchors-cardano: Provides Cardano anchor transaction binding
|
|
18
|
+
*
|
|
19
|
+
* All proofs are bound to a Cardano anchor transaction, creating a cross-chain
|
|
20
|
+
* link between the PoI trace on Cardano L1 and the ZK proof on Midnight.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import {
|
|
25
|
+
* MidnightProver,
|
|
26
|
+
* proverRegistry,
|
|
27
|
+
* HashChainInput,
|
|
28
|
+
* MidnightProverException,
|
|
29
|
+
* } from '@fluxpointstudios/orynq-sdk-midnight-prover';
|
|
30
|
+
*
|
|
31
|
+
* // Get the default prover
|
|
32
|
+
* const prover = proverRegistry.getDefault();
|
|
33
|
+
*
|
|
34
|
+
* // Connect to proof server
|
|
35
|
+
* await prover.connect({
|
|
36
|
+
* proofServerUrl: 'https://proof.midnight.network',
|
|
37
|
+
* apiKey: process.env.MIDNIGHT_API_KEY,
|
|
38
|
+
* timeout: 300000,
|
|
39
|
+
* retries: 3,
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* try {
|
|
43
|
+
* // Generate a hash chain proof
|
|
44
|
+
* const proof = await prover.proveHashChain({
|
|
45
|
+
* events: bundle.privateRun.events,
|
|
46
|
+
* genesisHash: '0x' + '0'.repeat(64),
|
|
47
|
+
* expectedRootHash: bundle.rootHash,
|
|
48
|
+
* cardanoAnchorTxHash: anchorTxHash,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Publish to Midnight
|
|
52
|
+
* const result = await prover.publish(proof);
|
|
53
|
+
* console.log('Proof published:', result.midnightTxHash);
|
|
54
|
+
* } catch (e) {
|
|
55
|
+
* if (e instanceof MidnightProverException) {
|
|
56
|
+
* console.error('Prover error:', e.code, e.message);
|
|
57
|
+
* }
|
|
58
|
+
* throw e;
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @packageDocumentation
|
|
63
|
+
*/
|
|
64
|
+
export type { ProofType, Proof, HashChainInput, HashChainProof, HashChainPublicInputs, PolicyInput, PolicyProof, PolicyPublicInputs, ContentPolicy, PolicyRule, AttestationInput, AttestationProof, AttestationPublicInputs, DisclosureInput, DisclosureProof, DisclosurePublicInputs, InferenceInput, InferenceProof, InferencePublicInputs, InferenceParams, InferenceProofMetrics, ProofServerConfig, PublicationResult, ProofVerificationResult, AnyProof, AnyProofInput, AnyPublicInputs, } from "./types.js";
|
|
65
|
+
export { MidnightProverError, MidnightProverException, DEFAULT_PROOF_SERVER_CONFIG, } from "./types.js";
|
|
66
|
+
export { isHashChainProof, isPolicyProof, isAttestationProof, isDisclosureProof, isInferenceProof, } from "./types.js";
|
|
67
|
+
export type { MidnightProver, MidnightProverFactory, CreateMidnightProverOptions, MidnightProverRegistry, } from "./prover-interface.js";
|
|
68
|
+
export { AbstractMidnightProver, DefaultMidnightProverRegistry, proverRegistry, } from "./prover-interface.js";
|
|
69
|
+
export type { HashChainProverOptions, PolicyComplianceProverOptions, RuleEvaluationResult, PolicyEvaluationResult, RuleEvaluator, SelectiveDisclosureProverOptions, MerkleInclusionResult, } from "./proofs/index.js";
|
|
70
|
+
export { HashChainProver, createHashChainProver, PolicyComplianceProver, createPolicyComplianceProver, SelectiveDisclosureProver, createSelectiveDisclosureProver, computeSpanHash, computeLeafHash, computeNodeHash, computeMerkleRoot, generateMerkleInclusionProof, verifyMerkleProof, verifySpanInclusion, } from "./proofs/index.js";
|
|
71
|
+
export type { EventWitness, HashChainWitness, HashChainPublicInputData, PolicyPublicInputData, AttestationPublicInputData, DisclosurePublicInputData, InferencePublicInputData, AnyPublicInputData, } from "./midnight/index.js";
|
|
72
|
+
export { buildHashChainWitness, serializeWitness, computeWitnessSize, validateWitness, buildPublicInputs, serializePublicInputs, hashPublicInputs, } from "./midnight/index.js";
|
|
73
|
+
export type { ProofResult, CircuitInfo, ProofServerClientOptions, } from "./midnight/index.js";
|
|
74
|
+
export { ProofServerClient, createProofServerClient, } from "./midnight/index.js";
|
|
75
|
+
export type { ProofStatus, ProofStatusInfo, ProofPublisherOptions, CrossChainLink, LinkVerificationResult, CardanoAnchorLinkerOptions, } from "./linking/index.js";
|
|
76
|
+
export { ProofPublisher, createProofPublisher, CardanoAnchorLinker, createCardanoAnchorLinker, } from "./linking/index.js";
|
|
77
|
+
export { DefaultMidnightProver, createMidnightProver, } from "./prover.js";
|
|
78
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAMH,YAAY,EAEV,SAAS,EAGT,KAAK,EAGL,cAAc,EACd,cAAc,EACd,qBAAqB,EAGrB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,UAAU,EAGV,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EAGvB,eAAe,EACf,eAAe,EACf,sBAAsB,EAGtB,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EAGrB,iBAAiB,EAGjB,iBAAiB,EAGjB,uBAAuB,EAGvB,QAAQ,EACR,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,YAAY,CAAC;AAMpB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAMpB,YAAY,EACV,cAAc,EACd,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/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
+
*
|
|
4
|
+
* ZK proof generation for PoI using the Midnight network.
|
|
5
|
+
* Enables privacy-preserving verification of trace properties.
|
|
6
|
+
*
|
|
7
|
+
* Location: packages/midnight-prover/src/index.ts
|
|
8
|
+
*
|
|
9
|
+
* Summary:
|
|
10
|
+
* This is the main entry point for the poi-midnight-prover package. It re-exports
|
|
11
|
+
* all public types, interfaces, and utilities for ZK proof generation.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* The package integrates with:
|
|
15
|
+
* - poi-process-trace: Provides TraceEvent and TraceBundle data for proofs
|
|
16
|
+
* - poi-attestor: Provides AttestationBundle for attestation proofs
|
|
17
|
+
* - poi-anchors-cardano: Provides Cardano anchor transaction binding
|
|
18
|
+
*
|
|
19
|
+
* All proofs are bound to a Cardano anchor transaction, creating a cross-chain
|
|
20
|
+
* link between the PoI trace on Cardano L1 and the ZK proof on Midnight.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import {
|
|
25
|
+
* MidnightProver,
|
|
26
|
+
* proverRegistry,
|
|
27
|
+
* HashChainInput,
|
|
28
|
+
* MidnightProverException,
|
|
29
|
+
* } from '@fluxpointstudios/orynq-sdk-midnight-prover';
|
|
30
|
+
*
|
|
31
|
+
* // Get the default prover
|
|
32
|
+
* const prover = proverRegistry.getDefault();
|
|
33
|
+
*
|
|
34
|
+
* // Connect to proof server
|
|
35
|
+
* await prover.connect({
|
|
36
|
+
* proofServerUrl: 'https://proof.midnight.network',
|
|
37
|
+
* apiKey: process.env.MIDNIGHT_API_KEY,
|
|
38
|
+
* timeout: 300000,
|
|
39
|
+
* retries: 3,
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* try {
|
|
43
|
+
* // Generate a hash chain proof
|
|
44
|
+
* const proof = await prover.proveHashChain({
|
|
45
|
+
* events: bundle.privateRun.events,
|
|
46
|
+
* genesisHash: '0x' + '0'.repeat(64),
|
|
47
|
+
* expectedRootHash: bundle.rootHash,
|
|
48
|
+
* cardanoAnchorTxHash: anchorTxHash,
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Publish to Midnight
|
|
52
|
+
* const result = await prover.publish(proof);
|
|
53
|
+
* console.log('Proof published:', result.midnightTxHash);
|
|
54
|
+
* } catch (e) {
|
|
55
|
+
* if (e instanceof MidnightProverException) {
|
|
56
|
+
* console.error('Prover error:', e.code, e.message);
|
|
57
|
+
* }
|
|
58
|
+
* throw e;
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @packageDocumentation
|
|
63
|
+
*/
|
|
64
|
+
// =============================================================================
|
|
65
|
+
// ERROR HANDLING
|
|
66
|
+
// =============================================================================
|
|
67
|
+
export { MidnightProverError, MidnightProverException, DEFAULT_PROOF_SERVER_CONFIG, } from "./types.js";
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// TYPE GUARDS
|
|
70
|
+
// =============================================================================
|
|
71
|
+
export { isHashChainProof, isPolicyProof, isAttestationProof, isDisclosureProof, isInferenceProof, } from "./types.js";
|
|
72
|
+
export { AbstractMidnightProver, DefaultMidnightProverRegistry, proverRegistry, } from "./prover-interface.js";
|
|
73
|
+
export {
|
|
74
|
+
// Hash chain prover
|
|
75
|
+
HashChainProver, createHashChainProver,
|
|
76
|
+
// Policy compliance prover
|
|
77
|
+
PolicyComplianceProver, createPolicyComplianceProver,
|
|
78
|
+
// Selective disclosure prover
|
|
79
|
+
SelectiveDisclosureProver, createSelectiveDisclosureProver,
|
|
80
|
+
// Merkle utilities
|
|
81
|
+
computeSpanHash, computeLeafHash, computeNodeHash, computeMerkleRoot, generateMerkleInclusionProof, verifyMerkleProof, verifySpanInclusion, } from "./proofs/index.js";
|
|
82
|
+
export { buildHashChainWitness, serializeWitness, computeWitnessSize, validateWitness, buildPublicInputs, serializePublicInputs, hashPublicInputs, } from "./midnight/index.js";
|
|
83
|
+
export { ProofServerClient, createProofServerClient, } from "./midnight/index.js";
|
|
84
|
+
export { ProofPublisher, createProofPublisher, CardanoAnchorLinker, createCardanoAnchorLinker, } from "./linking/index.js";
|
|
85
|
+
// =============================================================================
|
|
86
|
+
// DEFAULT PROVER IMPLEMENTATION
|
|
87
|
+
// =============================================================================
|
|
88
|
+
export { DefaultMidnightProver, createMidnightProver, } from "./prover.js";
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAyDH,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AAapB,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,cAAc,GACf,MAAM,uBAAuB,CAAC;AAgB/B,OAAO;AACL,oBAAoB;AACpB,eAAe,EACf,qBAAqB;AACrB,2BAA2B;AAC3B,sBAAsB,EACtB,4BAA4B;AAC5B,8BAA8B;AAC9B,yBAAyB,EACzB,+BAA+B;AAC/B,mBAAmB;AACnB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAe7B,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,gFAAgF;AAChF,gCAAgC;AAChC,gFAAgF;AAEhF,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Cross-chain linking between Midnight proofs and Cardano anchors.
|
|
3
|
+
*
|
|
4
|
+
* Location: packages/midnight-prover/src/linking/cardano-anchor-link.ts
|
|
5
|
+
*
|
|
6
|
+
* Summary:
|
|
7
|
+
* This module implements the CardanoAnchorLinker class which creates and verifies
|
|
8
|
+
* bidirectional links between ZK proofs on Midnight and anchor transactions on Cardano.
|
|
9
|
+
* These links enable cross-chain verification of PoI traces.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* - Used after proof publication to establish cross-chain references
|
|
13
|
+
* - Integrates with poi-anchors-cardano for anchor verification
|
|
14
|
+
* - Enables verification that a Midnight proof corresponds to a specific Cardano anchor
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { CardanoAnchorLinker } from './cardano-anchor-link.js';
|
|
19
|
+
*
|
|
20
|
+
* const linker = new CardanoAnchorLinker();
|
|
21
|
+
*
|
|
22
|
+
* const link = linker.linkToAnchor(proof, cardanoTxHash);
|
|
23
|
+
* console.log('Cross-chain link created:', link.linkId);
|
|
24
|
+
*
|
|
25
|
+
* const isValid = await linker.verifyLink(link);
|
|
26
|
+
* console.log('Link valid:', isValid);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
import type { AnyProof } from "../types.js";
|
|
30
|
+
/**
|
|
31
|
+
* Bidirectional cross-chain link between a Midnight proof and a Cardano anchor.
|
|
32
|
+
*
|
|
33
|
+
* This link establishes a verifiable relationship between:
|
|
34
|
+
* - A ZK proof published on Midnight
|
|
35
|
+
* - An anchor transaction recorded on Cardano L1
|
|
36
|
+
*
|
|
37
|
+
* The link is cryptographically bound through hash commitments.
|
|
38
|
+
*/
|
|
39
|
+
export interface CrossChainLink {
|
|
40
|
+
/**
|
|
41
|
+
* Unique identifier for this link.
|
|
42
|
+
*/
|
|
43
|
+
linkId: string;
|
|
44
|
+
/**
|
|
45
|
+
* Version of the link format.
|
|
46
|
+
*/
|
|
47
|
+
version: "1.0.0";
|
|
48
|
+
/**
|
|
49
|
+
* Proof ID on the Midnight network.
|
|
50
|
+
*/
|
|
51
|
+
midnightProofId: string;
|
|
52
|
+
/**
|
|
53
|
+
* Transaction hash on the Midnight network (if published).
|
|
54
|
+
*/
|
|
55
|
+
midnightTxHash: string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Type of the proof.
|
|
58
|
+
*/
|
|
59
|
+
proofType: string;
|
|
60
|
+
/**
|
|
61
|
+
* Hash of the proof's public inputs.
|
|
62
|
+
*/
|
|
63
|
+
publicInputsHash: string;
|
|
64
|
+
/**
|
|
65
|
+
* Anchor transaction hash on Cardano L1.
|
|
66
|
+
*/
|
|
67
|
+
cardanoAnchorTxHash: string;
|
|
68
|
+
/**
|
|
69
|
+
* Root hash that was anchored (e.g., trace merkle root or rolling hash).
|
|
70
|
+
*/
|
|
71
|
+
anchoredRootHash: string;
|
|
72
|
+
/**
|
|
73
|
+
* ISO 8601 timestamp when the link was created.
|
|
74
|
+
*/
|
|
75
|
+
createdAt: string;
|
|
76
|
+
/**
|
|
77
|
+
* Hash commitment binding both chain references.
|
|
78
|
+
*/
|
|
79
|
+
linkCommitment: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Result of link verification.
|
|
83
|
+
*/
|
|
84
|
+
export interface LinkVerificationResult {
|
|
85
|
+
valid: boolean;
|
|
86
|
+
linkId: string;
|
|
87
|
+
errors: string[];
|
|
88
|
+
warnings: string[];
|
|
89
|
+
verifiedAt: string;
|
|
90
|
+
midnightVerified: boolean;
|
|
91
|
+
cardanoVerified: boolean;
|
|
92
|
+
commitmentVerified: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Options for the CardanoAnchorLinker.
|
|
96
|
+
*/
|
|
97
|
+
export interface CardanoAnchorLinkerOptions {
|
|
98
|
+
/**
|
|
99
|
+
* Enable debug logging.
|
|
100
|
+
*/
|
|
101
|
+
debug?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Custom verification function for Cardano anchors.
|
|
104
|
+
* If not provided, uses mock verification.
|
|
105
|
+
*/
|
|
106
|
+
cardanoVerifier?: (txHash: string) => Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Custom verification function for Midnight proofs.
|
|
109
|
+
* If not provided, uses mock verification.
|
|
110
|
+
*/
|
|
111
|
+
midnightVerifier?: (proofId: string, txHash: string | undefined) => Promise<boolean>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* CardanoAnchorLinker creates and verifies cross-chain links.
|
|
115
|
+
*
|
|
116
|
+
* This class provides:
|
|
117
|
+
* - Creation of bidirectional links between Midnight proofs and Cardano anchors
|
|
118
|
+
* - Cryptographic commitment generation for link verification
|
|
119
|
+
* - Link verification against both chains
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const linker = new CardanoAnchorLinker({ debug: true });
|
|
124
|
+
*
|
|
125
|
+
* // Create a link after proof publication
|
|
126
|
+
* const link = linker.linkToAnchor(proof, cardanoTxHash);
|
|
127
|
+
*
|
|
128
|
+
* // Verify the link
|
|
129
|
+
* const result = await linker.verifyLink(link);
|
|
130
|
+
* if (result.valid) {
|
|
131
|
+
* console.log('Cross-chain link verified');
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare class CardanoAnchorLinker {
|
|
136
|
+
private readonly options;
|
|
137
|
+
private readonly linkCache;
|
|
138
|
+
/**
|
|
139
|
+
* Create a new CardanoAnchorLinker instance.
|
|
140
|
+
*
|
|
141
|
+
* @param options - Configuration options
|
|
142
|
+
*/
|
|
143
|
+
constructor(options?: CardanoAnchorLinkerOptions);
|
|
144
|
+
/**
|
|
145
|
+
* Create a cross-chain link between a proof and a Cardano anchor.
|
|
146
|
+
*
|
|
147
|
+
* This method:
|
|
148
|
+
* 1. Extracts relevant data from the proof
|
|
149
|
+
* 2. Generates a unique link ID
|
|
150
|
+
* 3. Creates a cryptographic commitment binding both chains
|
|
151
|
+
* 4. Returns the complete cross-chain link
|
|
152
|
+
*
|
|
153
|
+
* @param proof - The Midnight proof to link
|
|
154
|
+
* @param cardanoTxHash - The Cardano anchor transaction hash
|
|
155
|
+
* @param midnightTxHash - Optional Midnight transaction hash (if already published)
|
|
156
|
+
* @returns The cross-chain link
|
|
157
|
+
*/
|
|
158
|
+
linkToAnchor(proof: AnyProof, cardanoTxHash: string, midnightTxHash?: string): CrossChainLink;
|
|
159
|
+
/**
|
|
160
|
+
* Verify a cross-chain link.
|
|
161
|
+
*
|
|
162
|
+
* This method verifies:
|
|
163
|
+
* 1. Link structure and format
|
|
164
|
+
* 2. Link commitment integrity
|
|
165
|
+
* 3. Midnight proof existence (if verifier provided)
|
|
166
|
+
* 4. Cardano anchor existence (if verifier provided)
|
|
167
|
+
*
|
|
168
|
+
* @param link - The cross-chain link to verify
|
|
169
|
+
* @returns Promise resolving to the verification result
|
|
170
|
+
*/
|
|
171
|
+
verifyLink(link: CrossChainLink): Promise<LinkVerificationResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Get a cached link by ID.
|
|
174
|
+
*
|
|
175
|
+
* @param linkId - The link identifier
|
|
176
|
+
* @returns The cached link or undefined
|
|
177
|
+
*/
|
|
178
|
+
getCachedLink(linkId: string): CrossChainLink | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Get a link by proof ID.
|
|
181
|
+
*
|
|
182
|
+
* @param proofId - The proof identifier
|
|
183
|
+
* @returns The cached link or undefined
|
|
184
|
+
*/
|
|
185
|
+
getLinkByProofId(proofId: string): CrossChainLink | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Get all links for a Cardano anchor.
|
|
188
|
+
*
|
|
189
|
+
* @param cardanoTxHash - The Cardano transaction hash
|
|
190
|
+
* @returns Array of links for this anchor
|
|
191
|
+
*/
|
|
192
|
+
getLinksByCardanoAnchor(cardanoTxHash: string): CrossChainLink[];
|
|
193
|
+
/**
|
|
194
|
+
* Validate a proof for linking.
|
|
195
|
+
*/
|
|
196
|
+
private validateProof;
|
|
197
|
+
/**
|
|
198
|
+
* Validate a transaction hash.
|
|
199
|
+
*/
|
|
200
|
+
private validateTxHash;
|
|
201
|
+
/**
|
|
202
|
+
* Validate link structure.
|
|
203
|
+
*/
|
|
204
|
+
private validateLinkStructure;
|
|
205
|
+
/**
|
|
206
|
+
* Extract data from proof for linking.
|
|
207
|
+
*/
|
|
208
|
+
private extractProofData;
|
|
209
|
+
/**
|
|
210
|
+
* Extract Cardano anchor transaction hash from proof.
|
|
211
|
+
*/
|
|
212
|
+
private extractCardanoAnchorTxHash;
|
|
213
|
+
/**
|
|
214
|
+
* Generate a unique link ID.
|
|
215
|
+
*/
|
|
216
|
+
private generateLinkId;
|
|
217
|
+
/**
|
|
218
|
+
* Generate link commitment synchronously.
|
|
219
|
+
*/
|
|
220
|
+
private generateLinkCommitmentSync;
|
|
221
|
+
/**
|
|
222
|
+
* Hash public inputs synchronously.
|
|
223
|
+
*/
|
|
224
|
+
private hashPublicInputsSync;
|
|
225
|
+
/**
|
|
226
|
+
* Simple synchronous hash function (for use in sync contexts).
|
|
227
|
+
* Uses a deterministic algorithm suitable for identifiers.
|
|
228
|
+
*/
|
|
229
|
+
private simpleHash;
|
|
230
|
+
/**
|
|
231
|
+
* Mock Cardano verifier (always returns true for valid hashes).
|
|
232
|
+
*/
|
|
233
|
+
private mockCardanoVerifier;
|
|
234
|
+
/**
|
|
235
|
+
* Mock Midnight verifier (always returns true for non-empty proof IDs).
|
|
236
|
+
*/
|
|
237
|
+
private mockMidnightVerifier;
|
|
238
|
+
/**
|
|
239
|
+
* Debug logging helper.
|
|
240
|
+
*/
|
|
241
|
+
private debug;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a new CardanoAnchorLinker instance.
|
|
245
|
+
*
|
|
246
|
+
* @param options - Configuration options
|
|
247
|
+
* @returns New CardanoAnchorLinker instance
|
|
248
|
+
*/
|
|
249
|
+
export declare function createCardanoAnchorLinker(options?: CardanoAnchorLinkerOptions): CardanoAnchorLinker;
|
|
250
|
+
//# sourceMappingURL=cardano-anchor-link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cardano-anchor-link.d.ts","sourceRoot":"","sources":["../../src/linking/cardano-anchor-link.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAEV,QAAQ,EAMT,MAAM,aAAa,CAAC;AAkBrB;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAGjB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAGzB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAGzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAA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