@telika/sdk 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.
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ /**
3
+ * Telika Blockchain Client
4
+ *
5
+ * Provides a high-level API for interacting with the TelikaVerification smart contract
6
+ * on the Polygon network. Handles transaction signing, gas estimation, event monitoring,
7
+ * and read/write operations.
8
+ *
9
+ * Usage:
10
+ * // Read-only client (no private key needed)
11
+ * const reader = new TelikaBlockchainClient({
12
+ * rpcUrl: "https://polygon-amoy.g.alchemy.com/v2/KEY",
13
+ * contractAddress: "0x...",
14
+ * });
15
+ *
16
+ * // Read-write client (private key required for anchoring)
17
+ * const writer = new TelikaBlockchainClient({
18
+ * rpcUrl: "https://polygon-amoy.g.alchemy.com/v2/KEY",
19
+ * contractAddress: "0x...",
20
+ * privateKey: "0x...",
21
+ * });
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.TelikaBlockchainClient = void 0;
25
+ const ethers_1 = require("ethers");
26
+ const abi_1 = require("./abi");
27
+ // =========================================================================
28
+ // Client Class
29
+ // =========================================================================
30
+ class TelikaBlockchainClient {
31
+ provider;
32
+ contract;
33
+ signer;
34
+ config;
35
+ constructor(config) {
36
+ this.config = config;
37
+ this.provider = new ethers_1.JsonRpcProvider(config.rpcUrl);
38
+ if (config.privateKey) {
39
+ this.signer = new ethers_1.Wallet(config.privateKey, this.provider);
40
+ this.contract = new ethers_1.Contract(config.contractAddress, abi_1.TELIKA_VERIFICATION_ABI, this.signer);
41
+ }
42
+ else {
43
+ this.contract = new ethers_1.Contract(config.contractAddress, abi_1.TELIKA_VERIFICATION_ABI, this.provider);
44
+ }
45
+ }
46
+ // =========================================================================
47
+ // Write Operations (require signer)
48
+ // =========================================================================
49
+ /**
50
+ * Anchor a cryptographic proof on-chain.
51
+ *
52
+ * @param proofHash - The keccak256 hash of the verification event data (from proof-generator)
53
+ * @param eventType - The type of verification event
54
+ * @param telikaId - The unique Telika identifier
55
+ * @param metadata - Non-sensitive metadata to store alongside the proof
56
+ * @returns Transaction response with hash and wait() method
57
+ * @throws Error if no signer is configured
58
+ */
59
+ async anchorProof(proofHash, eventType, telikaId, metadata) {
60
+ this.requireSigner();
61
+ const metadataStr = typeof metadata === "string" ? metadata : JSON.stringify(metadata);
62
+ const tx = await this.contract.anchorProof(proofHash, eventType, telikaId, metadataStr);
63
+ return tx;
64
+ }
65
+ /**
66
+ * Anchor a proof and wait for transaction confirmation.
67
+ * Convenience wrapper around anchorProof() that waits for the receipt.
68
+ *
69
+ * @param proofHash - The keccak256 proof hash
70
+ * @param eventType - The event type
71
+ * @param telikaId - The Telika ID
72
+ * @param metadata - Proof metadata
73
+ * @param confirmations - Number of confirmations to wait for (default: 1)
74
+ * @returns Object with transaction hash and block number
75
+ */
76
+ async anchorProofAndWait(proofHash, eventType, telikaId, metadata, confirmations = 1) {
77
+ const tx = await this.anchorProof(proofHash, eventType, telikaId, metadata);
78
+ const receipt = await tx.wait(confirmations);
79
+ if (!receipt) {
80
+ throw new Error("Transaction receipt is null — transaction may have been dropped");
81
+ }
82
+ return {
83
+ txHash: receipt.hash,
84
+ blockNumber: receipt.blockNumber,
85
+ };
86
+ }
87
+ // =========================================================================
88
+ // Read Operations (no signer needed)
89
+ // =========================================================================
90
+ /**
91
+ * Verify whether a proof exists on-chain and retrieve its record.
92
+ *
93
+ * @param proofHash - The proof hash to verify
94
+ * @returns Verification result with existence flag and proof record
95
+ */
96
+ async verifyProof(proofHash) {
97
+ const [exists, rawRecord] = await this.contract.verifyProof(proofHash);
98
+ if (!exists) {
99
+ return { exists: false };
100
+ }
101
+ return {
102
+ exists: true,
103
+ record: this.parseProofRecord(rawRecord),
104
+ };
105
+ }
106
+ /**
107
+ * Get all proof hashes associated with a Telika ID.
108
+ *
109
+ * @param telikaId - The unique Telika identifier
110
+ * @returns Array of proof hash strings
111
+ */
112
+ async getProofsByTelikaId(telikaId) {
113
+ const hashes = await this.contract.getProofsByTelikaId(telikaId);
114
+ return Array.from(hashes);
115
+ }
116
+ /**
117
+ * Get all proof records for a Telika ID (fetches each proof's full record).
118
+ *
119
+ * @param telikaId - The unique Telika identifier
120
+ * @returns Array of full proof records
121
+ */
122
+ async getFullProofsByTelikaId(telikaId) {
123
+ const hashes = await this.getProofsByTelikaId(telikaId);
124
+ const records = await Promise.all(hashes.map(async (hash) => {
125
+ const rawRecord = await this.contract.getProof(hash);
126
+ return this.parseProofRecord(rawRecord);
127
+ }));
128
+ return records;
129
+ }
130
+ /**
131
+ * Get the count of proofs for a Telika ID.
132
+ *
133
+ * @param telikaId - The unique Telika identifier
134
+ * @returns Number of proofs anchored for this ID
135
+ */
136
+ async getProofCount(telikaId) {
137
+ const count = await this.contract.getProofCount(telikaId);
138
+ return Number(count);
139
+ }
140
+ /**
141
+ * Get the total number of proofs anchored across all Telika IDs.
142
+ */
143
+ async getTotalProofs() {
144
+ const total = await this.contract.totalProofs();
145
+ return Number(total);
146
+ }
147
+ /**
148
+ * Get paginated proof hashes for a Telika ID.
149
+ *
150
+ * @param telikaId - The Telika ID to query
151
+ * @param offset - Starting index
152
+ * @param limit - Maximum number of results
153
+ * @returns Array of proof hashes
154
+ */
155
+ async getProofsPaginated(telikaId, offset, limit) {
156
+ const hashes = await this.contract.getProofsByTelikaIdPaginated(telikaId, offset, limit);
157
+ return Array.from(hashes);
158
+ }
159
+ // =========================================================================
160
+ // Event Monitoring
161
+ // =========================================================================
162
+ /**
163
+ * Listen for new ProofAnchored events.
164
+ *
165
+ * @param callback - Function called when a new proof is anchored
166
+ * @returns Cleanup function to stop listening
167
+ */
168
+ onProofAnchored(callback) {
169
+ const listener = (proofHash, eventType, telikaId, timestamp, anchoredBy) => {
170
+ callback({
171
+ proofHash,
172
+ eventType: Number(eventType),
173
+ telikaId,
174
+ timestamp: Number(timestamp),
175
+ anchoredBy,
176
+ });
177
+ };
178
+ this.contract.on("ProofAnchored", listener);
179
+ return () => {
180
+ this.contract.off("ProofAnchored", listener);
181
+ };
182
+ }
183
+ /**
184
+ * Query historical ProofAnchored events.
185
+ *
186
+ * @param fromBlock - Starting block number (default: last 10000 blocks)
187
+ * @param toBlock - Ending block number (default: latest)
188
+ * @returns Array of proof anchored events
189
+ */
190
+ async queryProofEvents(fromBlock, toBlock) {
191
+ const currentBlock = await this.provider.getBlockNumber();
192
+ const from = fromBlock ?? Math.max(0, currentBlock - 10000);
193
+ const to = toBlock ?? currentBlock;
194
+ const filter = this.contract.filters.ProofAnchored();
195
+ const events = await this.contract.queryFilter(filter, from, to);
196
+ return events
197
+ .filter((e) => e instanceof ethers_1.EventLog)
198
+ .map((event) => ({
199
+ proofHash: event.args[0],
200
+ eventType: Number(event.args[1]),
201
+ telikaId: event.args[2],
202
+ timestamp: Number(event.args[3]),
203
+ anchoredBy: event.args[4],
204
+ blockNumber: event.blockNumber,
205
+ transactionHash: event.transactionHash,
206
+ }));
207
+ }
208
+ // =========================================================================
209
+ // Access Control
210
+ // =========================================================================
211
+ /**
212
+ * Check if an address has the ANCHOR_ROLE.
213
+ *
214
+ * @param address - The address to check
215
+ * @returns Whether the address can anchor proofs
216
+ */
217
+ async hasAnchorRole(address) {
218
+ const role = await this.contract.ANCHOR_ROLE();
219
+ return this.contract.hasRole(role, address);
220
+ }
221
+ /**
222
+ * Grant ANCHOR_ROLE to an address (requires admin role).
223
+ *
224
+ * @param address - The address to grant the role to
225
+ * @returns Transaction response
226
+ */
227
+ async grantAnchorRole(address) {
228
+ this.requireSigner();
229
+ const role = await this.contract.ANCHOR_ROLE();
230
+ return this.contract.grantRole(role, address);
231
+ }
232
+ /**
233
+ * Revoke ANCHOR_ROLE from an address (requires admin role).
234
+ *
235
+ * @param address - The address to revoke the role from
236
+ * @returns Transaction response
237
+ */
238
+ async revokeAnchorRole(address) {
239
+ this.requireSigner();
240
+ const role = await this.contract.ANCHOR_ROLE();
241
+ return this.contract.revokeRole(role, address);
242
+ }
243
+ // =========================================================================
244
+ // Utility
245
+ // =========================================================================
246
+ /**
247
+ * Get the contract address.
248
+ */
249
+ getContractAddress() {
250
+ return this.config.contractAddress;
251
+ }
252
+ /**
253
+ * Get the current signer address (if configured).
254
+ */
255
+ async getSignerAddress() {
256
+ return this.signer?.getAddress();
257
+ }
258
+ /**
259
+ * Get the current block number.
260
+ */
261
+ async getBlockNumber() {
262
+ return this.provider.getBlockNumber();
263
+ }
264
+ /**
265
+ * Get the balance of the signer (in MATIC/ETH).
266
+ */
267
+ async getSignerBalance() {
268
+ this.requireSigner();
269
+ const balance = await this.provider.getBalance(this.signer.address);
270
+ return (0, ethers_1.formatUnits)(balance, 18);
271
+ }
272
+ // =========================================================================
273
+ // Private Helpers
274
+ // =========================================================================
275
+ requireSigner() {
276
+ if (!this.signer) {
277
+ throw new Error("This operation requires a signer. Initialize TelikaBlockchainClient with a privateKey.");
278
+ }
279
+ }
280
+ parseProofRecord(raw) {
281
+ return {
282
+ proofHash: raw.proofHash ?? raw[0],
283
+ eventType: Number(raw.eventType ?? raw[1]),
284
+ telikaId: raw.telikaId ?? raw[2],
285
+ timestamp: Number(raw.timestamp ?? raw[3]),
286
+ metadata: raw.metadata ?? raw[4],
287
+ anchoredBy: raw.anchoredBy ?? raw[5],
288
+ };
289
+ }
290
+ }
291
+ exports.TelikaBlockchainClient = TelikaBlockchainClient;
292
+ //# sourceMappingURL=blockchain-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockchain-client.js","sourceRoot":"","sources":["../src/blockchain-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,mCAOgB;AAChB,+BAAgD;AAShD,4EAA4E;AAC5E,eAAe;AACf,4EAA4E;AAE5E,MAAa,sBAAsB;IACzB,QAAQ,CAAkB;IAC1B,QAAQ,CAAW;IACnB,MAAM,CAAU;IAChB,MAAM,CAAqB;IAEnC,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QA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E,kBAAkB;IAClB,4EAA4E;IAEpE,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,wFAAwF,CACzF,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,GAA4B;QACnD,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,SAAmB,IAAI,GAAG,CAAC,CAAC,CAAW;YACtD,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,CAAC,CAAc;YACvD,QAAQ,EAAE,GAAG,CAAC,QAAkB,IAAI,GAAG,CAAC,CAAC,CAAW;YACpD,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1C,QAAQ,EAAE,GAAG,CAAC,QAAkB,IAAI,GAAG,CAAC,CAAC,CAAW;YACpD,UAAU,EAAE,GAAG,CAAC,UAAoB,IAAI,GAAG,CAAC,CAAC,CAAW;SACzD,CAAC;IACJ,CAAC;CACF;AAzWD,wDAyWC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Telika SDK
3
+ *
4
+ * Public API for the Telika verification system.
5
+ * Provides proof generation and blockchain interaction capabilities.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import {
10
+ * generateProofHash,
11
+ * createIdentityProof,
12
+ * TelikaBlockchainClient,
13
+ * EventType,
14
+ * } from "@telika/sdk";
15
+ *
16
+ * // Generate a proof hash
17
+ * const proofHash = createIdentityProof({
18
+ * type: EventType.IdentityVerification,
19
+ * telikaId: "TLK-001",
20
+ * timestamp: new Date().toISOString(),
21
+ * documentType: "National ID",
22
+ * issuingCountry: "KE",
23
+ * verified: true,
24
+ * verifiedBy: "Telika Platform",
25
+ * });
26
+ *
27
+ * // Anchor it on-chain
28
+ * const client = new TelikaBlockchainClient({
29
+ * rpcUrl: "https://polygon-amoy.g.alchemy.com/v2/KEY",
30
+ * contractAddress: "0x...",
31
+ * privateKey: "0x...",
32
+ * });
33
+ *
34
+ * await client.anchorProofAndWait(
35
+ * proofHash,
36
+ * EventType.IdentityVerification,
37
+ * "TLK-001",
38
+ * { eventDescription: "Identity verified", generatedBy: "Telika", proofVersion: "1.0.0" }
39
+ * );
40
+ * ```
41
+ */
42
+ export { EventType, EventTypeLabels, type BaseEvent, type IdentityEvent, type FundingEvent, type MilestoneEvent, type ScoreUpdateEvent, type VerificationEvent, type ProofRecord, type VerificationResult, type TelikaClientConfig, type ProofMetadata, } from "./types";
43
+ export { generateProofHash, createIdentityProof, createFundingProof, createMilestoneProof, createScoreProof, generateMetadata, generateAbiEncodedHash, } from "./proof-generator";
44
+ export { TelikaBlockchainClient } from "./blockchain-client";
45
+ export { TELIKA_VERIFICATION_ABI } from "./abi";
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAGH,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,aAAa,GACnB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /**
3
+ * Telika SDK
4
+ *
5
+ * Public API for the Telika verification system.
6
+ * Provides proof generation and blockchain interaction capabilities.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import {
11
+ * generateProofHash,
12
+ * createIdentityProof,
13
+ * TelikaBlockchainClient,
14
+ * EventType,
15
+ * } from "@telika/sdk";
16
+ *
17
+ * // Generate a proof hash
18
+ * const proofHash = createIdentityProof({
19
+ * type: EventType.IdentityVerification,
20
+ * telikaId: "TLK-001",
21
+ * timestamp: new Date().toISOString(),
22
+ * documentType: "National ID",
23
+ * issuingCountry: "KE",
24
+ * verified: true,
25
+ * verifiedBy: "Telika Platform",
26
+ * });
27
+ *
28
+ * // Anchor it on-chain
29
+ * const client = new TelikaBlockchainClient({
30
+ * rpcUrl: "https://polygon-amoy.g.alchemy.com/v2/KEY",
31
+ * contractAddress: "0x...",
32
+ * privateKey: "0x...",
33
+ * });
34
+ *
35
+ * await client.anchorProofAndWait(
36
+ * proofHash,
37
+ * EventType.IdentityVerification,
38
+ * "TLK-001",
39
+ * { eventDescription: "Identity verified", generatedBy: "Telika", proofVersion: "1.0.0" }
40
+ * );
41
+ * ```
42
+ */
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.TELIKA_VERIFICATION_ABI = exports.TelikaBlockchainClient = exports.generateAbiEncodedHash = exports.generateMetadata = exports.createScoreProof = exports.createMilestoneProof = exports.createFundingProof = exports.createIdentityProof = exports.generateProofHash = exports.EventTypeLabels = exports.EventType = void 0;
45
+ // Types
46
+ var types_1 = require("./types");
47
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return types_1.EventType; } });
48
+ Object.defineProperty(exports, "EventTypeLabels", { enumerable: true, get: function () { return types_1.EventTypeLabels; } });
49
+ // Proof Generation
50
+ var proof_generator_1 = require("./proof-generator");
51
+ Object.defineProperty(exports, "generateProofHash", { enumerable: true, get: function () { return proof_generator_1.generateProofHash; } });
52
+ Object.defineProperty(exports, "createIdentityProof", { enumerable: true, get: function () { return proof_generator_1.createIdentityProof; } });
53
+ Object.defineProperty(exports, "createFundingProof", { enumerable: true, get: function () { return proof_generator_1.createFundingProof; } });
54
+ Object.defineProperty(exports, "createMilestoneProof", { enumerable: true, get: function () { return proof_generator_1.createMilestoneProof; } });
55
+ Object.defineProperty(exports, "createScoreProof", { enumerable: true, get: function () { return proof_generator_1.createScoreProof; } });
56
+ Object.defineProperty(exports, "generateMetadata", { enumerable: true, get: function () { return proof_generator_1.generateMetadata; } });
57
+ Object.defineProperty(exports, "generateAbiEncodedHash", { enumerable: true, get: function () { return proof_generator_1.generateAbiEncodedHash; } });
58
+ // Blockchain Client
59
+ var blockchain_client_1 = require("./blockchain-client");
60
+ Object.defineProperty(exports, "TelikaBlockchainClient", { enumerable: true, get: function () { return blockchain_client_1.TelikaBlockchainClient; } });
61
+ // Contract ABI
62
+ var abi_1 = require("./abi");
63
+ Object.defineProperty(exports, "TELIKA_VERIFICATION_ABI", { enumerable: true, get: function () { return abi_1.TELIKA_VERIFICATION_ABI; } });
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;;;AAEH,QAAQ;AACR,iCAaiB;AAZf,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA;AAajB,mBAAmB;AACnB,qDAQ2B;AAPzB,oHAAA,iBAAiB,OAAA;AACjB,sHAAA,mBAAmB,OAAA;AACnB,qHAAA,kBAAkB,OAAA;AAClB,uHAAA,oBAAoB,OAAA;AACpB,mHAAA,gBAAgB,OAAA;AAChB,mHAAA,gBAAgB,OAAA;AAChB,yHAAA,sBAAsB,OAAA;AAGxB,oBAAoB;AACpB,yDAA6D;AAApD,2HAAA,sBAAsB,OAAA;AAE/B,eAAe;AACf,6BAAgD;AAAvC,8GAAA,uBAAuB,OAAA"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Telika Proof Generator
3
+ *
4
+ * Generates cryptographic proof hashes (keccak256) from verification event data.
5
+ * The proof generator ensures that:
6
+ * 1. Sensitive fields are STRIPPED before hashing (e.g., bank details, personal documents)
7
+ * 2. Proof hashes are deterministic (same input always produces the same hash)
8
+ * 3. Only non-sensitive, non-identifying data is included in the proof
9
+ */
10
+ import { VerificationEvent, IdentityEvent, FundingEvent, MilestoneEvent, ScoreUpdateEvent, ProofMetadata } from "./types";
11
+ /**
12
+ * Generate a keccak256 proof hash from any verification event.
13
+ * Automatically routes to the appropriate event-specific generator
14
+ * and strips sensitive data before hashing.
15
+ *
16
+ * @param event - The verification event data
17
+ * @returns The keccak256 hash of the sanitized event data (0x-prefixed)
18
+ */
19
+ export declare function generateProofHash(event: VerificationEvent): string;
20
+ /**
21
+ * Create a proof hash specifically for an identity verification event.
22
+ *
23
+ * Included in proof: telikaId, timestamp, documentType, issuingCountry, verified, verifiedBy
24
+ * Excluded (sensitive): actual document numbers, personal details, photos
25
+ *
26
+ * @param event - Identity verification event data
27
+ * @returns The keccak256 proof hash
28
+ */
29
+ export declare function createIdentityProof(event: IdentityEvent): string;
30
+ /**
31
+ * Create a proof hash specifically for a funding disbursement event.
32
+ *
33
+ * Included in proof: telikaId, timestamp, amount, currency, funderId, funderName, fundingPurpose
34
+ * Excluded (sensitive): bank account numbers, routing numbers, transaction IDs
35
+ *
36
+ * @param event - Funding disbursement event data
37
+ * @returns The keccak256 proof hash
38
+ */
39
+ export declare function createFundingProof(event: FundingEvent): string;
40
+ /**
41
+ * Create a proof hash specifically for a milestone confirmation event.
42
+ *
43
+ * Included in proof: telikaId, timestamp, milestoneName, description, evidenceType, confirmed, confirmedBy
44
+ * Excluded (sensitive): detailed financial reports, user data
45
+ *
46
+ * @param event - Milestone confirmation event data
47
+ * @returns The keccak256 proof hash
48
+ */
49
+ export declare function createMilestoneProof(event: MilestoneEvent): string;
50
+ /**
51
+ * Create a proof hash specifically for a score update event.
52
+ *
53
+ * Included in proof: telikaId, timestamp, previousScore, newScore, reason, categoriesChanged
54
+ * Excluded (sensitive): detailed scoring breakdown, proprietary AI model outputs
55
+ *
56
+ * @param event - Score update event data
57
+ * @returns The keccak256 proof hash
58
+ */
59
+ export declare function createScoreProof(event: ScoreUpdateEvent): string;
60
+ /**
61
+ * Generate non-sensitive metadata JSON for an event.
62
+ * This metadata is stored on-chain alongside the proof hash.
63
+ *
64
+ * @param event - The verification event
65
+ * @param generatedBy - Who/what generated this proof
66
+ * @returns ProofMetadata object
67
+ */
68
+ export declare function generateMetadata(event: VerificationEvent, generatedBy?: string): ProofMetadata;
69
+ /**
70
+ * Generate a proof hash from raw ABI-encoded data.
71
+ * Useful for verifying proofs against the smart contract directly.
72
+ *
73
+ * @param types - Solidity ABI types
74
+ * @param values - Values corresponding to the types
75
+ * @returns keccak256 hash of ABI-encoded data
76
+ */
77
+ export declare function generateAbiEncodedHash(types: string[], values: unknown[]): string;
78
+ //# sourceMappingURL=proof-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-generator.d.ts","sourceRoot":"","sources":["../src/proof-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,gBAAgB,EAEhB,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAIlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAEhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAElE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAEhE;AAMD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,iBAAiB,EACxB,WAAW,GAAE,MAA0B,GACtC,aAAa,CAaf;AA8ED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAIjF"}