@weave_protocol/domere 1.0.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/PLANNING.md +231 -0
- package/README.md +50 -0
- package/dist/anchoring/ethereum.d.ts +135 -0
- package/dist/anchoring/ethereum.d.ts.map +1 -0
- package/dist/anchoring/ethereum.js +474 -0
- package/dist/anchoring/ethereum.js.map +1 -0
- package/dist/anchoring/index.d.ts +93 -0
- package/dist/anchoring/index.d.ts.map +1 -0
- package/dist/anchoring/index.js +184 -0
- package/dist/anchoring/index.js.map +1 -0
- package/dist/anchoring/merkle.d.ts +91 -0
- package/dist/anchoring/merkle.d.ts.map +1 -0
- package/dist/anchoring/merkle.js +203 -0
- package/dist/anchoring/merkle.js.map +1 -0
- package/dist/anchoring/solana.d.ts +85 -0
- package/dist/anchoring/solana.d.ts.map +1 -0
- package/dist/anchoring/solana.js +301 -0
- package/dist/anchoring/solana.js.map +1 -0
- package/dist/constants.d.ts +130 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +536 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/language/code-analyzer.d.ts +80 -0
- package/dist/language/code-analyzer.d.ts.map +1 -0
- package/dist/language/code-analyzer.js +489 -0
- package/dist/language/code-analyzer.js.map +1 -0
- package/dist/language/detector.d.ts +53 -0
- package/dist/language/detector.d.ts.map +1 -0
- package/dist/language/detector.js +248 -0
- package/dist/language/detector.js.map +1 -0
- package/dist/language/index.d.ts +61 -0
- package/dist/language/index.d.ts.map +1 -0
- package/dist/language/index.js +109 -0
- package/dist/language/index.js.map +1 -0
- package/dist/language/nl-analyzer.d.ts +59 -0
- package/dist/language/nl-analyzer.d.ts.map +1 -0
- package/dist/language/nl-analyzer.js +350 -0
- package/dist/language/nl-analyzer.js.map +1 -0
- package/dist/language/semantic.d.ts +48 -0
- package/dist/language/semantic.d.ts.map +1 -0
- package/dist/language/semantic.js +329 -0
- package/dist/language/semantic.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +6 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/memory.d.ts +48 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +211 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/thread/drift.d.ts +43 -0
- package/dist/thread/drift.d.ts.map +1 -0
- package/dist/thread/drift.js +248 -0
- package/dist/thread/drift.js.map +1 -0
- package/dist/thread/index.d.ts +9 -0
- package/dist/thread/index.d.ts.map +1 -0
- package/dist/thread/index.js +9 -0
- package/dist/thread/index.js.map +1 -0
- package/dist/thread/intent.d.ts +68 -0
- package/dist/thread/intent.d.ts.map +1 -0
- package/dist/thread/intent.js +333 -0
- package/dist/thread/intent.js.map +1 -0
- package/dist/thread/manager.d.ts +85 -0
- package/dist/thread/manager.d.ts.map +1 -0
- package/dist/thread/manager.js +305 -0
- package/dist/thread/manager.js.map +1 -0
- package/dist/thread/weave.d.ts +61 -0
- package/dist/thread/weave.d.ts.map +1 -0
- package/dist/thread/weave.js +158 -0
- package/dist/thread/weave.js.map +1 -0
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +102 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +466 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +48 -0
- package/dist/types.js.map +1 -0
- package/package.json +24 -0
- package/src/anchoring/ethereum.ts +568 -0
- package/src/anchoring/index.ts +236 -0
- package/src/anchoring/merkle.ts +256 -0
- package/src/anchoring/solana.ts +370 -0
- package/src/constants.ts +566 -0
- package/src/index.ts +43 -0
- package/src/language/code-analyzer.ts +564 -0
- package/src/language/detector.ts +297 -0
- package/src/language/index.ts +129 -0
- package/src/language/nl-analyzer.ts +411 -0
- package/src/language/semantic.ts +385 -0
- package/src/storage/index.ts +6 -0
- package/src/storage/memory.ts +271 -0
- package/src/thread/drift.ts +319 -0
- package/src/thread/index.ts +9 -0
- package/src/thread/intent.ts +409 -0
- package/src/thread/manager.ts +414 -0
- package/src/thread/weave.ts +205 -0
- package/src/tools/index.ts +107 -0
- package/src/types.ts +736 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - The Judge Protocol
|
|
3
|
+
* Anchoring Module
|
|
4
|
+
*/
|
|
5
|
+
export { MerkleTree, BatchAnchor } from './merkle.js';
|
|
6
|
+
export { SolanaAnchorClient, SOLANA_PROGRAM_IDL } from './solana.js';
|
|
7
|
+
export { EthereumAnchorClient, ETHEREUM_CONTRACT_ABI, ETHEREUM_CONTRACT_SOURCE } from './ethereum.js';
|
|
8
|
+
import { AnchoringError } from '../types.js';
|
|
9
|
+
import { SolanaAnchorClient } from './solana.js';
|
|
10
|
+
import { EthereumAnchorClient } from './ethereum.js';
|
|
11
|
+
import { MerkleTree, BatchAnchor } from './merkle.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Unified Anchoring Service
|
|
14
|
+
// ============================================================================
|
|
15
|
+
export class AnchoringService {
|
|
16
|
+
solana;
|
|
17
|
+
ethereum;
|
|
18
|
+
pendingBatch = null;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.solana = new SolanaAnchorClient(config?.solana);
|
|
21
|
+
this.ethereum = new EthereumAnchorClient(config?.ethereum);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Prepare thread for anchoring
|
|
25
|
+
*/
|
|
26
|
+
prepareThreadAnchor(thread) {
|
|
27
|
+
// Build Merkle tree from hop signatures
|
|
28
|
+
const hopSignatures = thread.hops.map(hop => hop.hop_signature);
|
|
29
|
+
const tree = new MerkleTree(hopSignatures.length > 0 ? hopSignatures : ['empty']);
|
|
30
|
+
return {
|
|
31
|
+
thread_id: thread.id,
|
|
32
|
+
merkle_root: tree.getRootHex(),
|
|
33
|
+
hop_count: thread.hops.length,
|
|
34
|
+
intent_hash: thread.intent.hash,
|
|
35
|
+
compliant: thread.status !== 'violated',
|
|
36
|
+
network: 'solana', // Default to Solana
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Estimate anchoring cost
|
|
41
|
+
*/
|
|
42
|
+
async estimateCost(network) {
|
|
43
|
+
if (network === 'solana' || network === 'solana-devnet') {
|
|
44
|
+
const cost = await this.solana.estimateCost();
|
|
45
|
+
return {
|
|
46
|
+
network,
|
|
47
|
+
network_fee: cost.network_fee_sol,
|
|
48
|
+
protocol_fee: cost.protocol_fee_sol,
|
|
49
|
+
total: cost.total_sol,
|
|
50
|
+
currency: 'SOL',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const cost = await this.ethereum.estimateGas();
|
|
55
|
+
return {
|
|
56
|
+
network,
|
|
57
|
+
network_fee: cost.estimated_eth,
|
|
58
|
+
protocol_fee: cost.protocol_fee_eth,
|
|
59
|
+
total: cost.total_eth,
|
|
60
|
+
currency: 'ETH',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create anchor transaction (unsigned)
|
|
66
|
+
*/
|
|
67
|
+
async createAnchorTransaction(request) {
|
|
68
|
+
if (request.network === 'solana' || request.network === 'solana-devnet') {
|
|
69
|
+
const tx = await this.solana.createAnchorTransaction(request);
|
|
70
|
+
return {
|
|
71
|
+
network: request.network,
|
|
72
|
+
transaction_data: tx.unsigned_transaction,
|
|
73
|
+
estimated_cost: tx.estimated_cost,
|
|
74
|
+
instructions: `Sign this transaction with your Solana wallet to anchor thread ${request.thread_id}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const tx = await this.ethereum.createAnchorTransaction(request);
|
|
79
|
+
return {
|
|
80
|
+
network: request.network,
|
|
81
|
+
transaction_data: tx,
|
|
82
|
+
estimated_cost: tx.estimated_cost,
|
|
83
|
+
instructions: `Sign this transaction with your Ethereum wallet to anchor thread ${request.thread_id}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Submit signed transaction
|
|
89
|
+
*/
|
|
90
|
+
async submitSignedTransaction(network, signedTransaction) {
|
|
91
|
+
if (network === 'solana' || network === 'solana-devnet') {
|
|
92
|
+
return this.solana.submitSignedTransaction(signedTransaction);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return this.ethereum.submitSignedTransaction(signedTransaction);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Verify anchor on-chain
|
|
100
|
+
*/
|
|
101
|
+
async verifyAnchor(network, threadId, expectedMerkleRoot) {
|
|
102
|
+
if (network === 'solana' || network === 'solana-devnet') {
|
|
103
|
+
return this.solana.verifyAnchor(threadId, expectedMerkleRoot);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return this.ethereum.verifyAnchor(threadId, expectedMerkleRoot);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Start a batch for efficient anchoring
|
|
111
|
+
*/
|
|
112
|
+
startBatch() {
|
|
113
|
+
if (this.pendingBatch) {
|
|
114
|
+
throw new AnchoringError('Batch already in progress');
|
|
115
|
+
}
|
|
116
|
+
this.pendingBatch = new BatchAnchor();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Add thread to batch
|
|
120
|
+
*/
|
|
121
|
+
addToBatch(thread) {
|
|
122
|
+
if (!this.pendingBatch) {
|
|
123
|
+
throw new AnchoringError('No batch in progress');
|
|
124
|
+
}
|
|
125
|
+
const hopSignatures = thread.hops.map(hop => hop.hop_signature);
|
|
126
|
+
const tree = new MerkleTree(hopSignatures.length > 0 ? hopSignatures : ['empty']);
|
|
127
|
+
this.pendingBatch.add(thread.id, JSON.stringify({
|
|
128
|
+
thread_id: thread.id,
|
|
129
|
+
merkle_root: tree.getRootHex(),
|
|
130
|
+
intent_hash: thread.intent.hash,
|
|
131
|
+
compliant: thread.status !== 'violated',
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Finalize batch and get root
|
|
136
|
+
*/
|
|
137
|
+
finalizeBatch() {
|
|
138
|
+
if (!this.pendingBatch) {
|
|
139
|
+
throw new AnchoringError('No batch in progress');
|
|
140
|
+
}
|
|
141
|
+
const root = this.pendingBatch.finalize();
|
|
142
|
+
const threadIds = this.pendingBatch.getItemIds();
|
|
143
|
+
const count = this.pendingBatch.getCount();
|
|
144
|
+
return { root, count, thread_ids: threadIds };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get proof for specific thread in batch
|
|
148
|
+
*/
|
|
149
|
+
getBatchProof(threadId) {
|
|
150
|
+
if (!this.pendingBatch) {
|
|
151
|
+
throw new AnchoringError('No batch in progress');
|
|
152
|
+
}
|
|
153
|
+
return this.pendingBatch.getProof(threadId);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Clear batch
|
|
157
|
+
*/
|
|
158
|
+
clearBatch() {
|
|
159
|
+
this.pendingBatch = null;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get explorer URL for transaction
|
|
163
|
+
*/
|
|
164
|
+
getExplorerUrl(network, txHash) {
|
|
165
|
+
if (network === 'solana' || network === 'solana-devnet') {
|
|
166
|
+
return this.solana.getExplorerUrl(txHash);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return this.ethereum.getExplorerUrl(txHash);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get client for direct access
|
|
174
|
+
*/
|
|
175
|
+
getClient(network) {
|
|
176
|
+
if (network === 'solana' || network === 'solana-devnet') {
|
|
177
|
+
return this.solana;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
return this.ethereum;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/anchoring/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAStG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEtD,+EAA+E;AAC/E,4BAA4B;AAC5B,+EAA+E;AAE/E,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAqB;IAC3B,QAAQ,CAAuB;IAC/B,YAAY,GAAuB,IAAI,CAAC;IAEhD,YAAY,MAGX;QACC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,IAAI,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,MAAc;QAChC,wCAAwC;QACxC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAChE,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CA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E,UAAU,EAAE,SAAS,EAAE,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,QAAgB;QAK5B,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,sBAAsB,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,cAAc,CAAC,OAA0B,EAAE,MAAc;QACvD,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;YACxD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,OAA0B;QAClC,IAAI,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;YACxD,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - The Judge Protocol
|
|
3
|
+
* Merkle Tree Utilities
|
|
4
|
+
*/
|
|
5
|
+
export declare class MerkleTree {
|
|
6
|
+
private leaves;
|
|
7
|
+
private layers;
|
|
8
|
+
private root;
|
|
9
|
+
constructor(leaves: (string | Buffer)[]);
|
|
10
|
+
/**
|
|
11
|
+
* Build the Merkle tree
|
|
12
|
+
*/
|
|
13
|
+
private buildTree;
|
|
14
|
+
/**
|
|
15
|
+
* Get the Merkle root
|
|
16
|
+
*/
|
|
17
|
+
getRoot(): Buffer;
|
|
18
|
+
/**
|
|
19
|
+
* Get root as hex string
|
|
20
|
+
*/
|
|
21
|
+
getRootHex(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get root as 32-byte array (for blockchain)
|
|
24
|
+
*/
|
|
25
|
+
getRootBytes32(): number[];
|
|
26
|
+
/**
|
|
27
|
+
* Get proof for a leaf at given index
|
|
28
|
+
*/
|
|
29
|
+
getProof(index: number): {
|
|
30
|
+
proof: Buffer[];
|
|
31
|
+
proofHex: string[];
|
|
32
|
+
positions: number[];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Verify a proof
|
|
36
|
+
*/
|
|
37
|
+
static verify(leaf: string | Buffer, proof: Buffer[], positions: number[], root: Buffer): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get all layers (for debugging)
|
|
40
|
+
*/
|
|
41
|
+
getLayers(): Buffer[][];
|
|
42
|
+
/**
|
|
43
|
+
* Get leaf count
|
|
44
|
+
*/
|
|
45
|
+
getLeafCount(): number;
|
|
46
|
+
/**
|
|
47
|
+
* Hash a leaf
|
|
48
|
+
*/
|
|
49
|
+
private hashLeaf;
|
|
50
|
+
/**
|
|
51
|
+
* Hash a pair of nodes
|
|
52
|
+
*/
|
|
53
|
+
private hashPair;
|
|
54
|
+
/**
|
|
55
|
+
* Sort pair for consistent ordering
|
|
56
|
+
*/
|
|
57
|
+
private sortPair;
|
|
58
|
+
}
|
|
59
|
+
export declare class BatchAnchor {
|
|
60
|
+
private items;
|
|
61
|
+
private tree;
|
|
62
|
+
/**
|
|
63
|
+
* Add item to batch
|
|
64
|
+
*/
|
|
65
|
+
add(id: string, data: string): void;
|
|
66
|
+
/**
|
|
67
|
+
* Finalize batch and build tree
|
|
68
|
+
*/
|
|
69
|
+
finalize(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Get proof for specific item
|
|
72
|
+
*/
|
|
73
|
+
getProof(id: string): {
|
|
74
|
+
proof: string[];
|
|
75
|
+
positions: number[];
|
|
76
|
+
root: string;
|
|
77
|
+
} | null;
|
|
78
|
+
/**
|
|
79
|
+
* Get root
|
|
80
|
+
*/
|
|
81
|
+
getRoot(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Get item count
|
|
84
|
+
*/
|
|
85
|
+
getCount(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Get all item IDs
|
|
88
|
+
*/
|
|
89
|
+
getItemIds(): string[];
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../src/anchoring/merkle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,IAAI,CAAuB;gBAEvB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE;IAQvC;;OAEG;IACH,OAAO,CAAC,SAAS;IAwBjB;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,UAAU,IAAI,MAAM;IAIpB;;OAEG;IACH,cAAc,IAAI,MAAM,EAAE;IAI1B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG;QACvB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB;IA6BD;;OAEG;IACH,MAAM,CAAC,MAAM,CACX,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,EAAE,MAAM,GACX,OAAO;IAkBV;;OAEG;IACH,SAAS,IAAI,MAAM,EAAE,EAAE;IAIvB;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAIhB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAMhB;;OAEG;IACH,OAAO,CAAC,QAAQ;CAGjB;AAMD,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAA2D;IACxE,OAAO,CAAC,IAAI,CAA2B;IAEvC;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAOnC;;OAEG;IACH,QAAQ,IAAI,MAAM;IAalB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG;QACpB,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,IAAI;IAmBR;;OAEG;IACH,OAAO,IAAI,MAAM;IAOjB;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;CAGvB"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - The Judge Protocol
|
|
3
|
+
* Merkle Tree Utilities
|
|
4
|
+
*/
|
|
5
|
+
import * as crypto from 'crypto';
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Merkle Tree
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export class MerkleTree {
|
|
10
|
+
leaves;
|
|
11
|
+
layers;
|
|
12
|
+
root = null;
|
|
13
|
+
constructor(leaves) {
|
|
14
|
+
this.leaves = leaves.map(leaf => typeof leaf === 'string' ? this.hashLeaf(leaf) : leaf);
|
|
15
|
+
this.layers = [this.leaves];
|
|
16
|
+
this.buildTree();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build the Merkle tree
|
|
20
|
+
*/
|
|
21
|
+
buildTree() {
|
|
22
|
+
let currentLayer = this.leaves;
|
|
23
|
+
while (currentLayer.length > 1) {
|
|
24
|
+
const newLayer = [];
|
|
25
|
+
for (let i = 0; i < currentLayer.length; i += 2) {
|
|
26
|
+
if (i + 1 < currentLayer.length) {
|
|
27
|
+
// Sort pair for consistent ordering
|
|
28
|
+
const [left, right] = this.sortPair(currentLayer[i], currentLayer[i + 1]);
|
|
29
|
+
newLayer.push(this.hashPair(left, right));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Promote odd node
|
|
33
|
+
newLayer.push(currentLayer[i]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
this.layers.push(newLayer);
|
|
37
|
+
currentLayer = newLayer;
|
|
38
|
+
}
|
|
39
|
+
this.root = currentLayer.length > 0 ? currentLayer[0] : this.hashLeaf('empty');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the Merkle root
|
|
43
|
+
*/
|
|
44
|
+
getRoot() {
|
|
45
|
+
return this.root;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get root as hex string
|
|
49
|
+
*/
|
|
50
|
+
getRootHex() {
|
|
51
|
+
return this.root.toString('hex');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get root as 32-byte array (for blockchain)
|
|
55
|
+
*/
|
|
56
|
+
getRootBytes32() {
|
|
57
|
+
return Array.from(this.root);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get proof for a leaf at given index
|
|
61
|
+
*/
|
|
62
|
+
getProof(index) {
|
|
63
|
+
if (index < 0 || index >= this.leaves.length) {
|
|
64
|
+
throw new Error('Index out of bounds');
|
|
65
|
+
}
|
|
66
|
+
const proof = [];
|
|
67
|
+
const positions = [];
|
|
68
|
+
let currentIndex = index;
|
|
69
|
+
for (let i = 0; i < this.layers.length - 1; i++) {
|
|
70
|
+
const layer = this.layers[i];
|
|
71
|
+
const isRight = currentIndex % 2 === 1;
|
|
72
|
+
const siblingIndex = isRight ? currentIndex - 1 : currentIndex + 1;
|
|
73
|
+
if (siblingIndex < layer.length) {
|
|
74
|
+
proof.push(layer[siblingIndex]);
|
|
75
|
+
positions.push(isRight ? 0 : 1); // Sibling position
|
|
76
|
+
}
|
|
77
|
+
currentIndex = Math.floor(currentIndex / 2);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
proof,
|
|
81
|
+
proofHex: proof.map(p => p.toString('hex')),
|
|
82
|
+
positions,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Verify a proof
|
|
87
|
+
*/
|
|
88
|
+
static verify(leaf, proof, positions, root) {
|
|
89
|
+
let current = typeof leaf === 'string'
|
|
90
|
+
? crypto.createHash('sha256').update(leaf).digest()
|
|
91
|
+
: leaf;
|
|
92
|
+
for (let i = 0; i < proof.length; i++) {
|
|
93
|
+
const [left, right] = positions[i] === 0
|
|
94
|
+
? [proof[i], current]
|
|
95
|
+
: [current, proof[i]];
|
|
96
|
+
current = crypto.createHash('sha256')
|
|
97
|
+
.update(Buffer.concat([left, right]))
|
|
98
|
+
.digest();
|
|
99
|
+
}
|
|
100
|
+
return current.equals(root);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get all layers (for debugging)
|
|
104
|
+
*/
|
|
105
|
+
getLayers() {
|
|
106
|
+
return this.layers;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get leaf count
|
|
110
|
+
*/
|
|
111
|
+
getLeafCount() {
|
|
112
|
+
return this.leaves.length;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Hash a leaf
|
|
116
|
+
*/
|
|
117
|
+
hashLeaf(data) {
|
|
118
|
+
return crypto.createHash('sha256').update(data).digest();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Hash a pair of nodes
|
|
122
|
+
*/
|
|
123
|
+
hashPair(left, right) {
|
|
124
|
+
return crypto.createHash('sha256')
|
|
125
|
+
.update(Buffer.concat([left, right]))
|
|
126
|
+
.digest();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Sort pair for consistent ordering
|
|
130
|
+
*/
|
|
131
|
+
sortPair(a, b) {
|
|
132
|
+
return Buffer.compare(a, b) <= 0 ? [a, b] : [b, a];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// ============================================================================
|
|
136
|
+
// Batch Anchoring
|
|
137
|
+
// ============================================================================
|
|
138
|
+
export class BatchAnchor {
|
|
139
|
+
items = new Map();
|
|
140
|
+
tree = null;
|
|
141
|
+
/**
|
|
142
|
+
* Add item to batch
|
|
143
|
+
*/
|
|
144
|
+
add(id, data) {
|
|
145
|
+
if (this.tree) {
|
|
146
|
+
throw new Error('Batch already finalized');
|
|
147
|
+
}
|
|
148
|
+
this.items.set(id, { data, index: this.items.size });
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Finalize batch and build tree
|
|
152
|
+
*/
|
|
153
|
+
finalize() {
|
|
154
|
+
if (this.items.size === 0) {
|
|
155
|
+
throw new Error('Cannot finalize empty batch');
|
|
156
|
+
}
|
|
157
|
+
const leaves = Array.from(this.items.values())
|
|
158
|
+
.sort((a, b) => a.index - b.index)
|
|
159
|
+
.map(item => item.data);
|
|
160
|
+
this.tree = new MerkleTree(leaves);
|
|
161
|
+
return this.tree.getRootHex();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get proof for specific item
|
|
165
|
+
*/
|
|
166
|
+
getProof(id) {
|
|
167
|
+
if (!this.tree) {
|
|
168
|
+
throw new Error('Batch not finalized');
|
|
169
|
+
}
|
|
170
|
+
const item = this.items.get(id);
|
|
171
|
+
if (!item) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const { proofHex, positions } = this.tree.getProof(item.index);
|
|
175
|
+
return {
|
|
176
|
+
proof: proofHex,
|
|
177
|
+
positions,
|
|
178
|
+
root: this.tree.getRootHex(),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get root
|
|
183
|
+
*/
|
|
184
|
+
getRoot() {
|
|
185
|
+
if (!this.tree) {
|
|
186
|
+
throw new Error('Batch not finalized');
|
|
187
|
+
}
|
|
188
|
+
return this.tree.getRootHex();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get item count
|
|
192
|
+
*/
|
|
193
|
+
getCount() {
|
|
194
|
+
return this.items.size;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get all item IDs
|
|
198
|
+
*/
|
|
199
|
+
getItemIds() {
|
|
200
|
+
return Array.from(this.items.keys());
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=merkle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../src/anchoring/merkle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,OAAO,UAAU;IACb,MAAM,CAAW;IACjB,MAAM,CAAa;IACnB,IAAI,GAAkB,IAAI,CAAC;IAEnC,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAC9B,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CACtD,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,SAAS;QACf,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;QAE/B,OAAO,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,QAAQ,GAAa,EAAE,CAAC;YAE9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,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qB,CAAC,CAAC;QACzC,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE/D,OAAO;YACL,KAAK,EAAE,QAAQ;YACf,SAAS;YACT,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;SAC7B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - The Judge Protocol
|
|
3
|
+
* Solana Anchoring Client
|
|
4
|
+
*
|
|
5
|
+
* Note: This is the client interface. The actual Solana program
|
|
6
|
+
* should be deployed separately using Anchor framework.
|
|
7
|
+
*/
|
|
8
|
+
import type { AnchorRequest, AnchorResult, AnchorVerification } from '../types.js';
|
|
9
|
+
export interface SolanaConfig {
|
|
10
|
+
rpc_url: string;
|
|
11
|
+
program_id: string;
|
|
12
|
+
treasury?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SolanaAnchorData {
|
|
15
|
+
thread_id: number[];
|
|
16
|
+
merkle_root: number[];
|
|
17
|
+
hop_count: number;
|
|
18
|
+
intent_hash: number[];
|
|
19
|
+
compliant: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class SolanaAnchorClient {
|
|
22
|
+
private config;
|
|
23
|
+
private isDevnet;
|
|
24
|
+
constructor(config?: Partial<SolanaConfig>);
|
|
25
|
+
/**
|
|
26
|
+
* Prepare anchor data for Solana
|
|
27
|
+
*/
|
|
28
|
+
prepareAnchorData(request: AnchorRequest): SolanaAnchorData;
|
|
29
|
+
/**
|
|
30
|
+
* Estimate transaction cost
|
|
31
|
+
*/
|
|
32
|
+
estimateCost(): Promise<{
|
|
33
|
+
network_fee_lamports: number;
|
|
34
|
+
network_fee_sol: string;
|
|
35
|
+
protocol_fee_lamports: number;
|
|
36
|
+
protocol_fee_sol: string;
|
|
37
|
+
total_lamports: number;
|
|
38
|
+
total_sol: string;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Anchor thread to Solana
|
|
42
|
+
*
|
|
43
|
+
* Note: This returns the transaction data needed for signing.
|
|
44
|
+
* Actual signing must be done client-side with the user's wallet.
|
|
45
|
+
*/
|
|
46
|
+
createAnchorTransaction(request: AnchorRequest): Promise<{
|
|
47
|
+
unsigned_transaction: string;
|
|
48
|
+
message: string;
|
|
49
|
+
instructions: unknown[];
|
|
50
|
+
estimated_cost: any;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* Submit signed transaction
|
|
54
|
+
*
|
|
55
|
+
* Note: In production, this would use @solana/web3.js to submit
|
|
56
|
+
* the signed transaction to the network.
|
|
57
|
+
*/
|
|
58
|
+
submitSignedTransaction(signedTransaction: string): Promise<AnchorResult>;
|
|
59
|
+
/**
|
|
60
|
+
* Verify an anchor on-chain
|
|
61
|
+
*/
|
|
62
|
+
verifyAnchor(threadId: string, expectedMerkleRoot: string): Promise<AnchorVerification>;
|
|
63
|
+
/**
|
|
64
|
+
* Get explorer URL for transaction
|
|
65
|
+
*/
|
|
66
|
+
getExplorerUrl(signature: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Get program address
|
|
69
|
+
*/
|
|
70
|
+
getProgramId(): string;
|
|
71
|
+
/**
|
|
72
|
+
* Derive PDA for thread anchor
|
|
73
|
+
*/
|
|
74
|
+
deriveThreadAnchorPda(threadId: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Convert string to 32-byte array
|
|
77
|
+
*/
|
|
78
|
+
private stringToBytes32;
|
|
79
|
+
/**
|
|
80
|
+
* Convert hex string to 32-byte array
|
|
81
|
+
*/
|
|
82
|
+
private hexToBytes32;
|
|
83
|
+
}
|
|
84
|
+
export declare const SOLANA_PROGRAM_IDL = "\n// Anchor program for D\u014Dmere anchoring\n// Deploy using: anchor build && anchor deploy\n\nuse anchor_lang::prelude::*;\n\ndeclare_id!(\"WeaveXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\");\n\n#[program]\npub mod domere_anchor {\n use super::*;\n \n pub const PROTOCOL_FEE: u64 = 100_000; // 0.0001 SOL\n \n pub fn anchor_thread(\n ctx: Context<AnchorThread>,\n thread_id: [u8; 32],\n merkle_root: [u8; 32],\n hop_count: u64,\n intent_hash: [u8; 32],\n compliant: bool,\n ) -> Result<()> {\n let anchor = &mut ctx.accounts.thread_anchor;\n \n anchor.thread_id = thread_id;\n anchor.merkle_root = merkle_root;\n anchor.hop_count = hop_count;\n anchor.intent_hash = intent_hash;\n anchor.compliant = compliant;\n anchor.timestamp = Clock::get()?.unix_timestamp;\n anchor.anchorer = ctx.accounts.payer.key();\n \n // Transfer protocol fee to treasury\n let cpi_context = CpiContext::new(\n ctx.accounts.system_program.to_account_info(),\n anchor_lang::system_program::Transfer {\n from: ctx.accounts.payer.to_account_info(),\n to: ctx.accounts.treasury.to_account_info(),\n },\n );\n anchor_lang::system_program::transfer(cpi_context, PROTOCOL_FEE)?;\n \n emit!(ThreadAnchored {\n thread_id,\n merkle_root,\n anchorer: ctx.accounts.payer.key(),\n timestamp: anchor.timestamp,\n });\n \n Ok(())\n }\n \n pub fn verify_anchor(\n ctx: Context<VerifyAnchor>,\n thread_id: [u8; 32],\n expected_merkle_root: [u8; 32],\n ) -> Result<bool> {\n let anchor = &ctx.accounts.thread_anchor;\n \n Ok(anchor.thread_id == thread_id && \n anchor.merkle_root == expected_merkle_root)\n }\n}\n\n#[derive(Accounts)]\n#[instruction(thread_id: [u8; 32])]\npub struct AnchorThread<'info> {\n #[account(mut)]\n pub payer: Signer<'info>,\n \n #[account(\n init_if_needed,\n payer = payer,\n space = 8 + ThreadAnchor::INIT_SPACE,\n seeds = [b\"thread_anchor\", thread_id.as_ref()],\n bump\n )]\n pub thread_anchor: Account<'info, ThreadAnchor>,\n \n /// CHECK: Treasury account for protocol fees\n #[account(mut)]\n pub treasury: AccountInfo<'info>,\n \n pub system_program: Program<'info, System>,\n}\n\n#[derive(Accounts)]\n#[instruction(thread_id: [u8; 32])]\npub struct VerifyAnchor<'info> {\n #[account(\n seeds = [b\"thread_anchor\", thread_id.as_ref()],\n bump\n )]\n pub thread_anchor: Account<'info, ThreadAnchor>,\n}\n\n#[account]\n#[derive(InitSpace)]\npub struct ThreadAnchor {\n pub thread_id: [u8; 32],\n pub merkle_root: [u8; 32],\n pub hop_count: u64,\n pub intent_hash: [u8; 32],\n pub compliant: bool,\n pub timestamp: i64,\n pub anchorer: Pubkey,\n}\n\n#[event]\npub struct ThreadAnchored {\n pub thread_id: [u8; 32],\n pub merkle_root: [u8; 32],\n pub anchorer: Pubkey,\n pub timestamp: i64,\n}\n";
|
|
85
|
+
//# sourceMappingURL=solana.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/anchoring/solana.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,kBAAkB,EAEnB,MAAM,aAAa,CAAC;AAQrB,MAAM,WAAW,YAAY;IAC3B,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