@andamio/core 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/dist/index.mjs ADDED
@@ -0,0 +1,381 @@
1
+ import * as blake from 'blakejs';
2
+
3
+ // src/utils/hashing/slt-hash.ts
4
+ var PLUTUS_CHUNK_SIZE = 64;
5
+ function computeSltHash(slts) {
6
+ const sltBytes = slts.map((slt) => new TextEncoder().encode(slt));
7
+ const cborData = encodeAsPlutusArray(sltBytes);
8
+ return blake.blake2bHex(cborData, void 0, 32);
9
+ }
10
+ var computeSltHashDefinite = computeSltHash;
11
+ function verifySltHash(slts, expectedHash) {
12
+ const computedHash = computeSltHash(slts);
13
+ return computedHash.toLowerCase() === expectedHash.toLowerCase();
14
+ }
15
+ function isValidSltHash(hash) {
16
+ if (hash.length !== 64) {
17
+ return false;
18
+ }
19
+ return /^[0-9a-fA-F]{64}$/.test(hash);
20
+ }
21
+ function encodeAsPlutusArray(items) {
22
+ const chunks = [];
23
+ chunks.push(new Uint8Array([159]));
24
+ for (const item of items) {
25
+ chunks.push(encodePlutusBuiltinByteString(item));
26
+ }
27
+ chunks.push(new Uint8Array([255]));
28
+ return concatUint8Arrays(chunks);
29
+ }
30
+ function encodePlutusBuiltinByteString(buffer) {
31
+ if (buffer.length <= PLUTUS_CHUNK_SIZE) {
32
+ return encodeCBORByteString(buffer);
33
+ }
34
+ const chunks = [];
35
+ chunks.push(new Uint8Array([95]));
36
+ for (let i = 0; i < buffer.length; i += PLUTUS_CHUNK_SIZE) {
37
+ const chunk = buffer.subarray(i, Math.min(i + PLUTUS_CHUNK_SIZE, buffer.length));
38
+ chunks.push(encodeCBORByteString(chunk));
39
+ }
40
+ chunks.push(new Uint8Array([255]));
41
+ return concatUint8Arrays(chunks);
42
+ }
43
+ function encodeCBORByteString(buffer) {
44
+ const len = buffer.length;
45
+ if (len <= 23) {
46
+ const result = new Uint8Array(1 + len);
47
+ result[0] = 64 + len;
48
+ result.set(buffer, 1);
49
+ return result;
50
+ } else if (len <= 255) {
51
+ const result = new Uint8Array(2 + len);
52
+ result[0] = 88;
53
+ result[1] = len;
54
+ result.set(buffer, 2);
55
+ return result;
56
+ } else if (len <= 65535) {
57
+ const result = new Uint8Array(3 + len);
58
+ result[0] = 89;
59
+ result[1] = len >> 8;
60
+ result[2] = len & 255;
61
+ result.set(buffer, 3);
62
+ return result;
63
+ }
64
+ throw new Error("Byte string too long for CBOR encoding");
65
+ }
66
+ function concatUint8Arrays(arrays) {
67
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
68
+ const result = new Uint8Array(totalLength);
69
+ let offset = 0;
70
+ for (const arr of arrays) {
71
+ result.set(arr, offset);
72
+ offset += arr.length;
73
+ }
74
+ return result;
75
+ }
76
+ var PLUTUS_CHUNK_SIZE2 = 64;
77
+ function computeTaskHash(task) {
78
+ const cborData = encodeTaskAsPlutusData(task);
79
+ return blake.blake2bHex(cborData, void 0, 32);
80
+ }
81
+ function verifyTaskHash(task, expectedHash) {
82
+ const computedHash = computeTaskHash(task);
83
+ return computedHash.toLowerCase() === expectedHash.toLowerCase();
84
+ }
85
+ function isValidTaskHash(hash) {
86
+ if (hash.length !== 64) {
87
+ return false;
88
+ }
89
+ return /^[0-9a-fA-F]{64}$/.test(hash);
90
+ }
91
+ function debugTaskCBOR(task) {
92
+ const cborData = encodeTaskAsPlutusData(task);
93
+ return uint8ArrayToHex(cborData);
94
+ }
95
+ function encodeTaskAsPlutusData(task) {
96
+ const chunks = [];
97
+ chunks.push(new Uint8Array([216, 121]));
98
+ chunks.push(new Uint8Array([159]));
99
+ chunks.push(encodePlutusBuiltinByteString2(new TextEncoder().encode(task.project_content)));
100
+ chunks.push(encodePlutusInteger(task.expiration_time));
101
+ chunks.push(encodePlutusInteger(task.lovelace_amount));
102
+ chunks.push(encodeNativeAssets(task.native_assets));
103
+ chunks.push(new Uint8Array([255]));
104
+ return concatUint8Arrays2(chunks);
105
+ }
106
+ function encodeNativeAssets(assets) {
107
+ if (assets.length === 0) {
108
+ return new Uint8Array([128]);
109
+ }
110
+ const chunks = [];
111
+ chunks.push(new Uint8Array([159]));
112
+ for (const [assetClass, quantity] of assets) {
113
+ chunks.push(new Uint8Array([130]));
114
+ chunks.push(encodePlutusBuiltinByteString2(new TextEncoder().encode(assetClass)));
115
+ chunks.push(encodePlutusInteger(quantity));
116
+ }
117
+ chunks.push(new Uint8Array([255]));
118
+ return concatUint8Arrays2(chunks);
119
+ }
120
+ function encodePlutusBuiltinByteString2(buffer) {
121
+ if (buffer.length <= PLUTUS_CHUNK_SIZE2) {
122
+ return encodeCBORByteString2(buffer);
123
+ }
124
+ const chunks = [];
125
+ chunks.push(new Uint8Array([95]));
126
+ for (let i = 0; i < buffer.length; i += PLUTUS_CHUNK_SIZE2) {
127
+ const chunk = buffer.subarray(i, Math.min(i + PLUTUS_CHUNK_SIZE2, buffer.length));
128
+ chunks.push(encodeCBORByteString2(chunk));
129
+ }
130
+ chunks.push(new Uint8Array([255]));
131
+ return concatUint8Arrays2(chunks);
132
+ }
133
+ function encodePlutusInteger(n) {
134
+ if (n >= 0) {
135
+ if (n <= 23) {
136
+ return new Uint8Array([n]);
137
+ } else if (n <= 255) {
138
+ return new Uint8Array([24, n]);
139
+ } else if (n <= 65535) {
140
+ return new Uint8Array([25, n >> 8, n & 255]);
141
+ } else if (n <= 4294967295) {
142
+ return new Uint8Array([26, n >> 24 & 255, n >> 16 & 255, n >> 8 & 255, n & 255]);
143
+ } else {
144
+ const buf = new Uint8Array(9);
145
+ buf[0] = 27;
146
+ const big = BigInt(n);
147
+ const view = new DataView(buf.buffer);
148
+ view.setBigUint64(1, big, false);
149
+ return buf;
150
+ }
151
+ } else {
152
+ const absVal = -1 - n;
153
+ if (absVal <= 23) {
154
+ return new Uint8Array([32 + absVal]);
155
+ } else if (absVal <= 255) {
156
+ return new Uint8Array([56, absVal]);
157
+ } else if (absVal <= 65535) {
158
+ return new Uint8Array([57, absVal >> 8, absVal & 255]);
159
+ } else if (absVal <= 4294967295) {
160
+ return new Uint8Array([58, absVal >> 24 & 255, absVal >> 16 & 255, absVal >> 8 & 255, absVal & 255]);
161
+ } else {
162
+ const buf = new Uint8Array(9);
163
+ buf[0] = 59;
164
+ const big = BigInt(absVal);
165
+ const view = new DataView(buf.buffer);
166
+ view.setBigUint64(1, big, false);
167
+ return buf;
168
+ }
169
+ }
170
+ }
171
+ function encodeCBORByteString2(buffer) {
172
+ const len = buffer.length;
173
+ if (len <= 23) {
174
+ const result = new Uint8Array(1 + len);
175
+ result[0] = 64 + len;
176
+ result.set(buffer, 1);
177
+ return result;
178
+ } else if (len <= 255) {
179
+ const result = new Uint8Array(2 + len);
180
+ result[0] = 88;
181
+ result[1] = len;
182
+ result.set(buffer, 2);
183
+ return result;
184
+ } else if (len <= 65535) {
185
+ const result = new Uint8Array(3 + len);
186
+ result[0] = 89;
187
+ result[1] = len >> 8;
188
+ result[2] = len & 255;
189
+ result.set(buffer, 3);
190
+ return result;
191
+ }
192
+ throw new Error("Byte string too long for CBOR encoding");
193
+ }
194
+ function concatUint8Arrays2(arrays) {
195
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
196
+ const result = new Uint8Array(totalLength);
197
+ let offset = 0;
198
+ for (const arr of arrays) {
199
+ result.set(arr, offset);
200
+ offset += arr.length;
201
+ }
202
+ return result;
203
+ }
204
+ function uint8ArrayToHex(arr) {
205
+ return Array.from(arr).map((b) => b.toString(16).padStart(2, "0")).join("");
206
+ }
207
+ function normalizeForHashing(value) {
208
+ if (value === null || value === void 0) {
209
+ return null;
210
+ }
211
+ if (typeof value === "string") {
212
+ return value.trim();
213
+ }
214
+ if (typeof value === "number" || typeof value === "boolean") {
215
+ return value;
216
+ }
217
+ if (Array.isArray(value)) {
218
+ return value.map(normalizeForHashing);
219
+ }
220
+ if (typeof value === "object") {
221
+ const sorted = {};
222
+ const keys = Object.keys(value).sort();
223
+ for (const key of keys) {
224
+ const val = value[key];
225
+ if (val !== void 0) {
226
+ sorted[key] = normalizeForHashing(val);
227
+ }
228
+ }
229
+ return sorted;
230
+ }
231
+ return value;
232
+ }
233
+ function computeCommitmentHash(evidence) {
234
+ const normalized = normalizeForHashing(evidence);
235
+ const jsonString = JSON.stringify(normalized);
236
+ const bytes = new TextEncoder().encode(jsonString);
237
+ return blake.blake2bHex(bytes, void 0, 32);
238
+ }
239
+ function verifyCommitmentHash(evidence, expectedHash) {
240
+ const computedHash = computeCommitmentHash(evidence);
241
+ return computedHash.toLowerCase() === expectedHash.toLowerCase();
242
+ }
243
+ function isValidCommitmentHash(hash) {
244
+ if (typeof hash !== "string") {
245
+ return false;
246
+ }
247
+ if (hash.length !== 64) {
248
+ return false;
249
+ }
250
+ return /^[0-9a-fA-F]{64}$/.test(hash);
251
+ }
252
+ function verifyEvidenceDetailed(evidence, onChainHash) {
253
+ if (!isValidCommitmentHash(onChainHash)) {
254
+ return {
255
+ isValid: false,
256
+ computedHash: "",
257
+ expectedHash: onChainHash,
258
+ message: `Invalid on-chain hash format: expected 64 hex characters, got "${onChainHash}"`
259
+ };
260
+ }
261
+ const computedHash = computeCommitmentHash(evidence);
262
+ const isValid = computedHash.toLowerCase() === onChainHash.toLowerCase();
263
+ return {
264
+ isValid,
265
+ computedHash,
266
+ expectedHash: onChainHash.toLowerCase(),
267
+ message: isValid ? "Evidence matches on-chain commitment" : "Evidence does not match on-chain commitment - content may have been modified"
268
+ };
269
+ }
270
+ var computeAssignmentInfoHash = computeCommitmentHash;
271
+ var verifyAssignmentInfoHash = verifyCommitmentHash;
272
+ var isValidAssignmentInfoHash = isValidCommitmentHash;
273
+
274
+ // src/constants/cardano.ts
275
+ var EXPLORER_URLS = {
276
+ mainnet: "https://cardanoscan.io",
277
+ preprod: "https://preprod.cardanoscan.io",
278
+ preview: "https://preview.cardanoscan.io"
279
+ };
280
+ var CEXPLORER_URLS = {
281
+ mainnet: "https://cexplorer.io",
282
+ preprod: "https://preprod.cexplorer.io",
283
+ preview: "https://preview.cexplorer.io"
284
+ };
285
+ var NETWORK_MAGIC = {
286
+ mainnet: 764824073,
287
+ preprod: 1,
288
+ preview: 2
289
+ };
290
+ var ADDRESS_PREFIX = {
291
+ mainnet: "addr",
292
+ preprod: "addr_test",
293
+ preview: "addr_test"
294
+ };
295
+ function getTxExplorerUrl(network, txHash) {
296
+ return `${EXPLORER_URLS[network]}/transaction/${txHash}`;
297
+ }
298
+ function getAddressExplorerUrl(network, address) {
299
+ return `${EXPLORER_URLS[network]}/address/${address}`;
300
+ }
301
+ function getAssetExplorerUrl(network, policyId, assetName) {
302
+ const assetId = assetName ? `${policyId}.${assetName}` : policyId;
303
+ return `${EXPLORER_URLS[network]}/token/${assetId}`;
304
+ }
305
+ function getPolicyExplorerUrl(network, policyId) {
306
+ return `${EXPLORER_URLS[network]}/tokenPolicy/${policyId}`;
307
+ }
308
+
309
+ // src/constants/policies.ts
310
+ var POLICY_IDS = {
311
+ preprod: {
312
+ accessToken: "4758613867a8a7aa500b5d57a0e877f01a8e63c1365469589b12063c",
313
+ courseToken: "",
314
+ // Set via environment
315
+ moduleToken: "",
316
+ // Set via environment
317
+ assignmentToken: "",
318
+ // Set via environment
319
+ projectToken: "",
320
+ // Set via environment
321
+ taskToken: "",
322
+ // Set via environment
323
+ contributorToken: ""
324
+ // Set via environment
325
+ },
326
+ preview: {
327
+ accessToken: "",
328
+ courseToken: "",
329
+ moduleToken: "",
330
+ assignmentToken: "",
331
+ projectToken: "",
332
+ taskToken: "",
333
+ contributorToken: ""
334
+ },
335
+ mainnet: {
336
+ accessToken: "",
337
+ courseToken: "",
338
+ moduleToken: "",
339
+ assignmentToken: "",
340
+ projectToken: "",
341
+ taskToken: "",
342
+ contributorToken: ""
343
+ }
344
+ };
345
+ function getAccessTokenPolicyId(network) {
346
+ return POLICY_IDS[network].accessToken;
347
+ }
348
+ function isValidPolicyId(policyId) {
349
+ if (typeof policyId !== "string") {
350
+ return false;
351
+ }
352
+ if (policyId.length !== 56) {
353
+ return false;
354
+ }
355
+ return /^[0-9a-fA-F]{56}$/.test(policyId);
356
+ }
357
+ function isValidAssetName(assetName) {
358
+ if (typeof assetName !== "string") {
359
+ return false;
360
+ }
361
+ if (assetName.length > 64) {
362
+ return false;
363
+ }
364
+ if (assetName.length % 2 !== 0) {
365
+ return false;
366
+ }
367
+ return /^[0-9a-fA-F]*$/.test(assetName);
368
+ }
369
+ function stringToAssetName(str) {
370
+ return Array.from(new TextEncoder().encode(str)).map((b) => b.toString(16).padStart(2, "0")).join("");
371
+ }
372
+ function assetNameToString(hex) {
373
+ const bytes = new Uint8Array(
374
+ hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []
375
+ );
376
+ return new TextDecoder().decode(bytes);
377
+ }
378
+
379
+ export { ADDRESS_PREFIX, CEXPLORER_URLS, EXPLORER_URLS, NETWORK_MAGIC, POLICY_IDS, assetNameToString, computeAssignmentInfoHash, computeCommitmentHash, computeSltHash, computeSltHashDefinite, computeTaskHash, debugTaskCBOR, getAccessTokenPolicyId, getAddressExplorerUrl, getAssetExplorerUrl, getPolicyExplorerUrl, getTxExplorerUrl, isValidAssetName, isValidAssignmentInfoHash, isValidCommitmentHash, isValidPolicyId, isValidSltHash, isValidTaskHash, normalizeForHashing, stringToAssetName, verifyAssignmentInfoHash, verifyCommitmentHash, verifyEvidenceDetailed, verifySltHash, verifyTaskHash };
380
+ //# sourceMappingURL=index.mjs.map
381
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/hashing/slt-hash.ts","../src/utils/hashing/task-hash.ts","../src/utils/hashing/commitment-hash.ts","../src/constants/cardano.ts","../src/constants/policies.ts"],"names":["PLUTUS_CHUNK_SIZE","blake2","encodePlutusBuiltinByteString","concatUint8Arrays","encodeCBORByteString","blake3"],"mappings":";;;AAyBA,IAAM,iBAAA,GAAoB,EAAA;AA0BnB,SAAS,eAAe,IAAA,EAAwB;AACrD,EAAA,MAAM,QAAA,GAAW,IAAA,CAAK,G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AAC,CAAA,CAC1C,IAAA,CAAK,EAAE,CAAA;AACZ;AAKO,SAAS,kBAAkB,GAAA,EAAqB;AACrD,EAAA,MAAM,QAAQ,IAAI,UAAA;AAAA,IAChB,GAAA,CAAI,KAAA,CAAM,SAAS,CAAA,EAAG,GAAA,CAAI,CAAC,IAAA,KAAS,QAAA,CAAS,IAAA,EAAM,EAAE,CAAC,CAAA,IAAK;AAAC,GAC9D;AACA,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,KAAK,CAAA;AACvC","file":"index.mjs","sourcesContent":["/**\n * SLT Hash Utility\n *\n * Computes the module token name (hash) from a list of Student Learning Targets (SLTs).\n * This hash is used as the token name when minting module tokens on-chain.\n *\n * The algorithm matches the on-chain Plutus validator:\n * ```haskell\n * sltsToBbs MintModuleV2{slts} = blake2b_256 $ serialiseData $ toBuiltinData $ map stringToBuiltinByteString slts\n * ```\n *\n * Serialization format:\n * 1. Convert each SLT string to UTF-8 bytes\n * 2. Encode as CBOR indefinite-length array of byte strings\n * 3. Hash with Blake2b-256 (32 bytes / 256 bits)\n *\n * @module @andamio/core/hashing\n */\n\nimport * as blake from \"blakejs\";\n\n/**\n * Plutus chunk size for byte strings.\n * Strings longer than this are encoded as indefinite-length chunked byte strings.\n */\nconst PLUTUS_CHUNK_SIZE = 64;\n\n/**\n * Compute the module hash matching Plutus on-chain encoding.\n *\n * Plutus's `stringToBuiltinByteString` chunks byte strings at 64 bytes.\n * This function replicates that behavior:\n * - Strings <= 64 bytes: encoded as regular CBOR byte strings\n * - Strings > 64 bytes: encoded as indefinite-length chunked byte strings\n *\n * @param slts - Array of Student Learning Target strings\n * @returns 64-character hex string (256-bit Blake2b hash)\n *\n * @example\n * ```typescript\n * import { computeSltHash } from \"@andamio/core/hashing\";\n *\n * const slts = [\n * \"I can mint an access token.\",\n * \"I can complete an assignment to earn a credential.\"\n * ];\n *\n * const moduleHash = computeSltHash(slts);\n * // Returns: \"8dcbe1b925d87e6c547bbd8071c23a712db4c32751454b0948f8c846e9246b5c\"\n * ```\n */\nexport function computeSltHash(slts: string[]): string {\n const sltBytes = slts.map((slt) => new TextEncoder().encode(slt));\n const cborData = encodeAsPlutusArray(sltBytes);\n return blake.blake2bHex(cborData, undefined, 32);\n}\n\n/**\n * @deprecated Use `computeSltHash` instead. This alias is kept for backwards compatibility.\n */\nexport const computeSltHashDefinite = computeSltHash;\n\n/**\n * Verify that a given hash matches the computed hash for SLTs.\n *\n * @param slts - Array of Student Learning Target strings\n * @param expectedHash - The hash to verify (64-character hex string)\n * @returns true if the computed hash matches the expected hash\n */\nexport function verifySltHash(slts: string[], expectedHash: string): boolean {\n const computedHash = computeSltHash(slts);\n return computedHash.toLowerCase() === expectedHash.toLowerCase();\n}\n\n/**\n * Validate that a string is a valid SLT hash format.\n *\n * SLT hashes are 64-character hexadecimal strings (256-bit Blake2b hash).\n *\n * @param hash - String to validate\n * @returns true if the string is a valid SLT hash format\n */\nexport function isValidSltHash(hash: string): boolean {\n if (hash.length !== 64) {\n return false;\n }\n return /^[0-9a-fA-F]{64}$/.test(hash);\n}\n\n// =============================================================================\n// Plutus-Compatible Encoding (Internal)\n// =============================================================================\n\n/**\n * Encode an array of byte buffers matching Plutus serialization.\n *\n * Uses indefinite-length array with chunked byte strings for long values.\n *\n * @internal\n */\nfunction encodeAsPlutusArray(items: Uint8Array[]): Uint8Array {\n const chunks: Uint8Array[] = [];\n\n // Start indefinite array\n chunks.push(new Uint8Array([0x9f]));\n\n // Encode each item (with chunking for long strings)\n for (const item of items) {\n chunks.push(encodePlutusBuiltinByteString(item));\n }\n\n // End indefinite array\n chunks.push(new Uint8Array([0xff]));\n\n return concatUint8Arrays(chunks);\n}\n\n/**\n * Encode a byte buffer matching Plutus's stringToBuiltinByteString.\n *\n * - Strings <= 64 bytes: regular CBOR byte string\n * - Strings > 64 bytes: indefinite-length chunked byte string (64-byte chunks)\n *\n * @internal\n */\nfunction encodePlutusBuiltinByteString(buffer: Uint8Array): Uint8Array {\n if (buffer.length <= PLUTUS_CHUNK_SIZE) {\n // Short string: encode normally\n return encodeCBORByteString(buffer);\n }\n\n // Long string: use indefinite-length chunked encoding\n const chunks: Uint8Array[] = [];\n chunks.push(new Uint8Array([0x5f])); // Start indefinite byte string\n\n for (let i = 0; i < buffer.length; i += PLUTUS_CHUNK_SIZE) {\n const chunk = buffer.subarray(i, Math.min(i + PLUTUS_CHUNK_SIZE, buffer.length));\n chunks.push(encodeCBORByteString(chunk));\n }\n\n chunks.push(new Uint8Array([0xff])); // Break\n return concatUint8Arrays(chunks);\n}\n\n/**\n * Encode a byte buffer as a CBOR byte string (definite length).\n *\n * @internal\n */\nfunction encodeCBORByteString(buffer: Uint8Array): Uint8Array {\n const len = buffer.length;\n\n // CBOR byte string encoding (major type 2 = 0x40):\n // - 0-23 bytes: length inline (0x40 + len)\n // - 24-255 bytes: 0x58 + 1-byte length\n // - 256-65535 bytes: 0x59 + 2-byte length (big-endian)\n if (len <= 23) {\n const result = new Uint8Array(1 + len);\n result[0] = 0x40 + len;\n result.set(buffer, 1);\n return result;\n } else if (len <= 255) {\n const result = new Uint8Array(2 + len);\n result[0] = 0x58;\n result[1] = len;\n result.set(buffer, 2);\n return result;\n } else if (len <= 65535) {\n const result = new Uint8Array(3 + len);\n result[0] = 0x59;\n result[1] = len >> 8;\n result[2] = len & 0xff;\n result.set(buffer, 3);\n return result;\n }\n throw new Error(\"Byte string too long for CBOR encoding\");\n}\n\n/**\n * Concatenate multiple Uint8Arrays into one\n *\n * @internal\n */\nfunction concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n return result;\n}\n","/**\n * Task Hash Utility\n *\n * Computes the task token name (hash) from task data.\n * This hash is used as the task_hash on-chain (content-addressed identifier).\n *\n * The algorithm matches the on-chain Plutus validator serialization.\n *\n * @module @andamio/core/hashing\n */\n\nimport * as blake from \"blakejs\";\n\n/**\n * Native asset in ListValue format: [policyId.tokenName, quantity]\n */\ntype NativeAsset = [string, number];\n\n/**\n * Task data structure matching the Atlas TX API ManageTasksTxRequest\n *\n * Fields must be arranged in this specific order for hashing:\n * 1. project_content (string, max 140 chars)\n * 2. expiration_time (number, Unix timestamp in milliseconds)\n * 3. lovelace_amount (number)\n * 4. native_assets (array of [asset_class, quantity] tuples)\n */\nexport interface TaskData {\n project_content: string;\n expiration_time: number;\n lovelace_amount: number;\n native_assets: NativeAsset[];\n}\n\n/**\n * Plutus chunk size for byte strings.\n */\nconst PLUTUS_CHUNK_SIZE = 64;\n\n/**\n * Compute the task hash (token name / task_hash) from task data.\n *\n * This produces the same hash as the on-chain Plutus validator, allowing\n * clients to pre-compute or verify task hashes.\n *\n * @param task - Task data object\n * @returns 64-character hex string (256-bit Blake2b hash)\n *\n * @example\n * ```typescript\n * import { computeTaskHash } from \"@andamio/core/hashing\";\n *\n * const task = {\n * project_content: \"Open Task #1\",\n * expiration_time: 1769027280000,\n * lovelace_amount: 15000000,\n * native_assets: []\n * };\n *\n * const taskHash = computeTaskHash(task);\n * // Returns the on-chain task_hash\n * ```\n */\nexport function computeTaskHash(task: TaskData): string {\n // Serialize task data matching Plutus format\n const cborData = encodeTaskAsPlutusData(task);\n\n // Hash with Blake2b-256\n return blake.blake2bHex(cborData, undefined, 32);\n}\n\n/**\n * Verify that a given hash matches the computed hash for a task.\n *\n * @param task - Task data object\n * @param expectedHash - The hash to verify (64-character hex string)\n * @returns true if the computed hash matches the expected hash\n */\nexport function verifyTaskHash(task: TaskData, expectedHash: string): boolean {\n const computedHash = computeTaskHash(task);\n return computedHash.toLowerCase() === expectedHash.toLowerCase();\n}\n\n/**\n * Validate that a string is a valid task hash format.\n *\n * Task hashes are 64-character hexadecimal strings (256-bit Blake2b hash).\n */\nexport function isValidTaskHash(hash: string): boolean {\n if (hash.length !== 64) {\n return false;\n }\n return /^[0-9a-fA-F]{64}$/.test(hash);\n}\n\n/**\n * Debug function to show the CBOR encoding of a task.\n * Useful for comparing against on-chain data.\n *\n * @param task - Task data object\n * @returns Hex string of the CBOR-encoded data (before hashing)\n */\nexport function debugTaskCBOR(task: TaskData): string {\n const cborData = encodeTaskAsPlutusData(task);\n return uint8ArrayToHex(cborData);\n}\n\n// =============================================================================\n// Plutus Data Encoding (Internal)\n// =============================================================================\n\n/**\n * Encode task data matching Plutus serialiseData $ toBuiltinData format.\n *\n * Plutus represents this as a constructor with fields in an INDEFINITE array:\n * Constr 0 [project_content, expiration_time, lovelace_amount, native_assets]\n *\n * IMPORTANT: Plutus uses indefinite-length arrays (0x9f...0xff) not definite (0x84).\n *\n * @internal\n */\nfunction encodeTaskAsPlutusData(task: TaskData): Uint8Array {\n const chunks: Uint8Array[] = [];\n\n // Plutus Constr 0 with indefinite array\n // CBOR tag 121 (0xd879) = Constr 0 in Plutus Data\n chunks.push(new Uint8Array([0xd8, 0x79])); // Tag 121 (Constr 0)\n chunks.push(new Uint8Array([0x9f])); // Start indefinite array\n\n // Field 1: project_content as BuiltinByteString\n chunks.push(encodePlutusBuiltinByteString(new TextEncoder().encode(task.project_content)));\n\n // Field 2: expiration_time as Integer\n chunks.push(encodePlutusInteger(task.expiration_time));\n\n // Field 3: lovelace_amount as Integer\n chunks.push(encodePlutusInteger(task.lovelace_amount));\n\n // Field 4: native_assets as List of pairs\n chunks.push(encodeNativeAssets(task.native_assets));\n\n // End indefinite array\n chunks.push(new Uint8Array([0xff])); // Break\n\n return concatUint8Arrays(chunks);\n}\n\n/**\n * Encode native assets as Plutus List of (AssetClass, Integer) pairs.\n *\n * Each asset is a pair: (policyId.tokenName, quantity)\n * In Plutus, this is: List [(ByteString, Integer)]\n *\n * @internal\n */\nfunction encodeNativeAssets(assets: NativeAsset[]): Uint8Array {\n if (assets.length === 0) {\n // Empty list: definite-length array of 0 elements\n return new Uint8Array([0x80]); // Array(0)\n }\n\n const chunks: Uint8Array[] = [];\n\n // Start indefinite array\n chunks.push(new Uint8Array([0x9f]));\n\n for (const [assetClass, quantity] of assets) {\n // Each asset is a 2-element array: [bytestring, integer]\n chunks.push(new Uint8Array([0x82])); // Array of 2 elements\n chunks.push(encodePlutusBuiltinByteString(new TextEncoder().encode(assetClass)));\n chunks.push(encodePlutusInteger(quantity));\n }\n\n // End indefinite array\n chunks.push(new Uint8Array([0xff]));\n\n return concatUint8Arrays(chunks);\n}\n\n/**\n * Encode a byte buffer matching Plutus's stringToBuiltinByteString.\n *\n * - Strings <= 64 bytes: regular CBOR byte string\n * - Strings > 64 bytes: indefinite-length chunked byte string (64-byte chunks)\n *\n * @internal\n */\nfunction encodePlutusBuiltinByteString(buffer: Uint8Array): Uint8Array {\n if (buffer.length <= PLUTUS_CHUNK_SIZE) {\n return encodeCBORByteString(buffer);\n }\n\n // Long string: use indefinite-length chunked encoding\n const chunks: Uint8Array[] = [];\n chunks.push(new Uint8Array([0x5f])); // Start indefinite byte string\n\n for (let i = 0; i < buffer.length; i += PLUTUS_CHUNK_SIZE) {\n const chunk = buffer.subarray(i, Math.min(i + PLUTUS_CHUNK_SIZE, buffer.length));\n chunks.push(encodeCBORByteString(chunk));\n }\n\n chunks.push(new Uint8Array([0xff])); // Break\n return concatUint8Arrays(chunks);\n}\n\n/**\n * Encode a number as a CBOR integer (Plutus Integer).\n *\n * @internal\n */\nfunction encodePlutusInteger(n: number): Uint8Array {\n // CBOR integer encoding (major type 0 for positive, 1 for negative)\n if (n >= 0) {\n if (n <= 23) {\n return new Uint8Array([n]);\n } else if (n <= 0xff) {\n return new Uint8Array([0x18, n]);\n } else if (n <= 0xffff) {\n return new Uint8Array([0x19, n >> 8, n & 0xff]);\n } else if (n <= 0xffffffff) {\n return new Uint8Array([0x1a, (n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]);\n } else {\n // 64-bit integer - use BigInt for precision\n const buf = new Uint8Array(9);\n buf[0] = 0x1b;\n const big = BigInt(n);\n const view = new DataView(buf.buffer);\n view.setBigUint64(1, big, false); // false = big-endian\n return buf;\n }\n } else {\n // Negative integers: major type 1, encode (-1 - n)\n const absVal = -1 - n;\n if (absVal <= 23) {\n return new Uint8Array([0x20 + absVal]);\n } else if (absVal <= 0xff) {\n return new Uint8Array([0x38, absVal]);\n } else if (absVal <= 0xffff) {\n return new Uint8Array([0x39, absVal >> 8, absVal & 0xff]);\n } else if (absVal <= 0xffffffff) {\n return new Uint8Array([0x3a, (absVal >> 24) & 0xff, (absVal >> 16) & 0xff, (absVal >> 8) & 0xff, absVal & 0xff]);\n } else {\n const buf = new Uint8Array(9);\n buf[0] = 0x3b;\n const big = BigInt(absVal);\n const view = new DataView(buf.buffer);\n view.setBigUint64(1, big, false);\n return buf;\n }\n }\n}\n\n/**\n * Encode a byte buffer as a CBOR byte string (definite length).\n *\n * @internal\n */\nfunction encodeCBORByteString(buffer: Uint8Array): Uint8Array {\n const len = buffer.length;\n\n if (len <= 23) {\n const result = new Uint8Array(1 + len);\n result[0] = 0x40 + len;\n result.set(buffer, 1);\n return result;\n } else if (len <= 255) {\n const result = new Uint8Array(2 + len);\n result[0] = 0x58;\n result[1] = len;\n result.set(buffer, 2);\n return result;\n } else if (len <= 65535) {\n const result = new Uint8Array(3 + len);\n result[0] = 0x59;\n result[1] = len >> 8;\n result[2] = len & 0xff;\n result.set(buffer, 3);\n return result;\n }\n throw new Error(\"Byte string too long for CBOR encoding\");\n}\n\n/**\n * Concatenate multiple Uint8Arrays into one\n *\n * @internal\n */\nfunction concatUint8Arrays(arrays: Uint8Array[]): Uint8Array {\n const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const arr of arrays) {\n result.set(arr, offset);\n offset += arr.length;\n }\n return result;\n}\n\n/**\n * Convert Uint8Array to hex string\n *\n * @internal\n */\nfunction uint8ArrayToHex(arr: Uint8Array): string {\n return Array.from(arr)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n","/**\n * Commitment Hash Utility\n *\n * Functions for computing and verifying hashes of commitment evidence.\n * The hash is stored on-chain as `commitment_hash` in the course state datum,\n * while the full evidence (Tiptap JSON document) is stored in the database.\n *\n * This provides:\n * - Compact on-chain storage (64-char hex hash vs full JSON)\n * - Tamper-evidence (can verify DB content matches on-chain commitment)\n * - Privacy (evidence details not exposed on-chain)\n *\n * @module @andamio/core/hashing\n */\n\nimport * as blake from \"blakejs\";\n\n/**\n * Tiptap document structure (simplified)\n * The actual structure can be more complex with nested content\n */\nexport type TiptapDoc = {\n type: \"doc\";\n content?: TiptapNode[];\n [key: string]: unknown;\n};\n\nexport type TiptapNode = {\n type: string;\n content?: TiptapNode[];\n text?: string;\n marks?: TiptapMark[];\n attrs?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\nexport type TiptapMark = {\n type: string;\n attrs?: Record<string, unknown>;\n [key: string]: unknown;\n};\n\n/**\n * Normalizes a value for consistent hashing.\n *\n * Normalization rules:\n * - Objects: Sort keys alphabetically, recursively normalize values\n * - Arrays: Preserve order, recursively normalize items\n * - Strings: Trim whitespace\n * - Numbers/Booleans/null: Keep as-is\n * - undefined: Convert to null\n *\n * @param value - Any JSON-serializable value\n * @returns Normalized value\n */\nexport function normalizeForHashing(value: unknown): unknown {\n if (value === null || value === undefined) {\n return null;\n }\n\n if (typeof value === \"string\") {\n return value.trim();\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map(normalizeForHashing);\n }\n\n if (typeof value === \"object\") {\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(value as Record<string, unknown>).sort();\n for (const key of keys) {\n const val = (value as Record<string, unknown>)[key];\n if (val !== undefined) {\n sorted[key] = normalizeForHashing(val);\n }\n }\n return sorted;\n }\n\n return value;\n}\n\n/**\n * Computes the commitment hash from evidence content.\n *\n * The hash is computed as:\n * 1. Normalize the evidence (sort keys, trim strings, etc.)\n * 2. Serialize to JSON string (deterministic due to normalization)\n * 3. Apply Blake2b-256 hash\n *\n * @param evidence - The evidence content (Tiptap JSON document or any JSON-serializable data)\n * @returns 64-character lowercase hex string (Blake2b-256 hash)\n *\n * @example\n * ```typescript\n * import { computeCommitmentHash } from \"@andamio/core/hashing\";\n *\n * const evidence = {\n * type: \"doc\",\n * content: [\n * { type: \"paragraph\", content: [{ type: \"text\", text: \"My submission\" }] }\n * ]\n * };\n *\n * const hash = computeCommitmentHash(evidence);\n * // Use this hash as commitment_hash in the transaction\n * ```\n */\nexport function computeCommitmentHash(evidence: unknown): string {\n const normalized = normalizeForHashing(evidence);\n const jsonString = JSON.stringify(normalized);\n const bytes = new TextEncoder().encode(jsonString);\n return blake.blake2bHex(bytes, undefined, 32);\n}\n\n/**\n * Verifies that evidence content matches an expected hash.\n *\n * Use this to verify that database evidence matches the on-chain commitment.\n *\n * @param evidence - The evidence content to verify\n * @param expectedHash - The expected hash (from on-chain data)\n * @returns True if the evidence produces the expected hash\n */\nexport function verifyCommitmentHash(\n evidence: unknown,\n expectedHash: string\n): boolean {\n const computedHash = computeCommitmentHash(evidence);\n return computedHash.toLowerCase() === expectedHash.toLowerCase();\n}\n\n/**\n * Validates that a string is a valid commitment hash format.\n *\n * A valid hash is a 64-character hexadecimal string (Blake2b-256 output).\n *\n * @param hash - The string to validate\n * @returns True if the string is a valid hash format\n */\nexport function isValidCommitmentHash(hash: string): boolean {\n if (typeof hash !== \"string\") {\n return false;\n }\n if (hash.length !== 64) {\n return false;\n }\n return /^[0-9a-fA-F]{64}$/.test(hash);\n}\n\n/**\n * Result of comparing evidence with an on-chain hash\n */\nexport type EvidenceVerificationResult = {\n /** Whether the evidence matches the on-chain hash */\n isValid: boolean;\n /** The hash computed from the evidence */\n computedHash: string;\n /** The expected hash (from on-chain) */\n expectedHash: string;\n /** Human-readable status message */\n message: string;\n};\n\n/**\n * Performs a detailed verification of evidence against an on-chain hash.\n *\n * Returns a detailed result object with both hashes and a status message,\n * useful for debugging and user feedback.\n *\n * @param evidence - The evidence content to verify\n * @param onChainHash - The hash from on-chain data\n * @returns Detailed verification result\n */\nexport function verifyEvidenceDetailed(\n evidence: unknown,\n onChainHash: string\n): EvidenceVerificationResult {\n if (!isValidCommitmentHash(onChainHash)) {\n return {\n isValid: false,\n computedHash: \"\",\n expectedHash: onChainHash,\n message: `Invalid on-chain hash format: expected 64 hex characters, got \"${onChainHash}\"`,\n };\n }\n\n const computedHash = computeCommitmentHash(evidence);\n const isValid = computedHash.toLowerCase() === onChainHash.toLowerCase();\n\n return {\n isValid,\n computedHash,\n expectedHash: onChainHash.toLowerCase(),\n message: isValid\n ? \"Evidence matches on-chain commitment\"\n : \"Evidence does not match on-chain commitment - content may have been modified\",\n };\n}\n\n// =============================================================================\n// Backwards Compatibility Aliases (deprecated)\n// =============================================================================\n\n/**\n * @deprecated Use `computeCommitmentHash` instead.\n */\nexport const computeAssignmentInfoHash = computeCommitmentHash;\n\n/**\n * @deprecated Use `verifyCommitmentHash` instead.\n */\nexport const verifyAssignmentInfoHash = verifyCommitmentHash;\n\n/**\n * @deprecated Use `isValidCommitmentHash` instead.\n */\nexport const isValidAssignmentInfoHash = isValidCommitmentHash;\n","/**\n * Cardano Network Constants\n *\n * Network identifiers, explorer URLs, and other Cardano-specific constants.\n *\n * @module @andamio/core/constants\n */\n\n/**\n * Supported Cardano networks\n */\nexport type CardanoNetwork = \"mainnet\" | \"preprod\" | \"preview\";\n\n/**\n * Block explorer URLs by network\n */\nexport const EXPLORER_URLS: Record<CardanoNetwork, string> = {\n mainnet: \"https://cardanoscan.io\",\n preprod: \"https://preprod.cardanoscan.io\",\n preview: \"https://preview.cardanoscan.io\",\n} as const;\n\n/**\n * CExplorer URLs by network (alternative explorer)\n */\nexport const CEXPLORER_URLS: Record<CardanoNetwork, string> = {\n mainnet: \"https://cexplorer.io\",\n preprod: \"https://preprod.cexplorer.io\",\n preview: \"https://preview.cexplorer.io\",\n} as const;\n\n/**\n * Network magic numbers for Cardano networks\n */\nexport const NETWORK_MAGIC: Record<CardanoNetwork, number> = {\n mainnet: 764824073,\n preprod: 1,\n preview: 2,\n} as const;\n\n/**\n * Bech32 address prefixes by network\n */\nexport const ADDRESS_PREFIX: Record<CardanoNetwork, string> = {\n mainnet: \"addr\",\n preprod: \"addr_test\",\n preview: \"addr_test\",\n} as const;\n\n/**\n * Get explorer URL for a transaction\n */\nexport function getTxExplorerUrl(\n network: CardanoNetwork,\n txHash: string\n): string {\n return `${EXPLORER_URLS[network]}/transaction/${txHash}`;\n}\n\n/**\n * Get explorer URL for an address\n */\nexport function getAddressExplorerUrl(\n network: CardanoNetwork,\n address: string\n): string {\n return `${EXPLORER_URLS[network]}/address/${address}`;\n}\n\n/**\n * Get explorer URL for a token/asset\n */\nexport function getAssetExplorerUrl(\n network: CardanoNetwork,\n policyId: string,\n assetName?: string\n): string {\n const assetId = assetName ? `${policyId}.${assetName}` : policyId;\n return `${EXPLORER_URLS[network]}/token/${assetId}`;\n}\n\n/**\n * Get explorer URL for a policy\n */\nexport function getPolicyExplorerUrl(\n network: CardanoNetwork,\n policyId: string\n): string {\n return `${EXPLORER_URLS[network]}/tokenPolicy/${policyId}`;\n}\n","/**\n * Andamio Policy IDs\n *\n * Policy IDs for Andamio protocol tokens by network.\n * These are used to identify access tokens, course tokens, and other\n * protocol-specific assets on-chain.\n *\n * @module @andamio/core/constants\n */\n\nimport type { CardanoNetwork } from \"./cardano\";\n\n/**\n * Policy ID configuration for a network\n */\nexport interface NetworkPolicies {\n /** Access token policy ID - identifies user access tokens */\n accessToken: string;\n /** Course token policy ID - identifies course tokens */\n courseToken: string;\n /** Module token policy ID - identifies module tokens */\n moduleToken: string;\n /** Assignment token policy ID - identifies assignment tokens */\n assignmentToken: string;\n /** Project token policy ID - identifies project tokens */\n projectToken: string;\n /** Task token policy ID - identifies task tokens */\n taskToken: string;\n /** Contributor token policy ID - identifies contributor tokens */\n contributorToken: string;\n}\n\n/**\n * Policy IDs by network\n *\n * Note: These should be loaded from environment variables in production.\n * The values here are examples/defaults for the preprod network.\n */\nexport const POLICY_IDS: Record<CardanoNetwork, NetworkPolicies> = {\n preprod: {\n accessToken: \"4758613867a8a7aa500b5d57a0e877f01a8e63c1365469589b12063c\",\n courseToken: \"\", // Set via environment\n moduleToken: \"\", // Set via environment\n assignmentToken: \"\", // Set via environment\n projectToken: \"\", // Set via environment\n taskToken: \"\", // Set via environment\n contributorToken: \"\", // Set via environment\n },\n preview: {\n accessToken: \"\",\n courseToken: \"\",\n moduleToken: \"\",\n assignmentToken: \"\",\n projectToken: \"\",\n taskToken: \"\",\n contributorToken: \"\",\n },\n mainnet: {\n accessToken: \"\",\n courseToken: \"\",\n moduleToken: \"\",\n assignmentToken: \"\",\n projectToken: \"\",\n taskToken: \"\",\n contributorToken: \"\",\n },\n} as const;\n\n/**\n * Get the access token policy ID for a network\n */\nexport function getAccessTokenPolicyId(network: CardanoNetwork): string {\n return POLICY_IDS[network].accessToken;\n}\n\n/**\n * Validate a policy ID format (56 hex characters)\n */\nexport function isValidPolicyId(policyId: string): boolean {\n if (typeof policyId !== \"string\") {\n return false;\n }\n if (policyId.length !== 56) {\n return false;\n }\n return /^[0-9a-fA-F]{56}$/.test(policyId);\n}\n\n/**\n * Validate an asset name format (hex string, max 64 chars / 32 bytes)\n */\nexport function isValidAssetName(assetName: string): boolean {\n if (typeof assetName !== \"string\") {\n return false;\n }\n if (assetName.length > 64) {\n return false;\n }\n if (assetName.length % 2 !== 0) {\n return false;\n }\n return /^[0-9a-fA-F]*$/.test(assetName);\n}\n\n/**\n * Convert a UTF-8 string to hex asset name\n */\nexport function stringToAssetName(str: string): string {\n return Array.from(new TextEncoder().encode(str))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\n/**\n * Convert a hex asset name to UTF-8 string\n */\nexport function assetNameToString(hex: string): string {\n const bytes = new Uint8Array(\n hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []\n );\n return new TextDecoder().decode(bytes);\n}\n"]}