@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/LICENSE +190 -0
- package/README.md +83 -0
- package/dist/constants/index.d.mts +102 -0
- package/dist/constants/index.d.ts +102 -0
- package/dist/constants/index.js +123 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/index.mjs +108 -0
- package/dist/constants/index.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +432 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +381 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/hashing/index.d.mts +276 -0
- package/dist/utils/hashing/index.d.ts +276 -0
- package/dist/utils/hashing/index.js +313 -0
- package/dist/utils/hashing/index.js.map +1 -0
- package/dist/utils/hashing/index.mjs +276 -0
- package/dist/utils/hashing/index.mjs.map +1 -0
- package/package.json +58 -0
- package/src/constants/cardano.ts +90 -0
- package/src/constants/index.ts +31 -0
- package/src/constants/policies.ts +122 -0
- package/src/index.ts +14 -0
- package/src/utils/hashing/commitment-hash.ts +223 -0
- package/src/utils/hashing/index.ts +43 -0
- package/src/utils/hashing/slt-hash.ts +193 -0
- package/src/utils/hashing/task-hash.ts +308 -0
|
@@ -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"],"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,GAAA,CAAI,CAAC,GAAA,KAAQ,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,GAAG,CAAC,CAAA;AAChE,EAAA,MAAM,QAAA,G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AAC5B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,IAAA,CAAK,WAAW,EAAA,EAAI;AACtB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,mBAAA,CAAoB,KAAK,IAAI,CAAA;AACtC;AA0BO,SAAS,sBAAA,CACd,UACA,WAAA,EAC4B;AAC5B,EAAA,IAAI,CAAC,qBAAA,CAAsB,WAAW,CAAA,EAAG;AACvC,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAA;AAAA,MACT,YAAA,EAAc,EAAA;AAAA,MACd,YAAA,EAAc,WAAA;AAAA,MACd,OAAA,EAAS,kEAAkE,WAAW,CAAA,CAAA;AAAA,KACxF;AAAA,EACF;AAEA,EAAA,MAAM,YAAA,GAAe,sBAAsB,QAAQ,CAAA;AACnD,EAAA,MAAM,OAAA,GAAU,YAAA,CAAa,WAAA,EAAY,KAAM,YAAY,WAAA,EAAY;AAEvE,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA,EAAc,YAAY,WAAA,EAAY;AAAA,IACtC,OAAA,EAAS,UACL,sCAAA,GACA;AAAA,GACN;AACF;AASO,IAAM,yBAAA,GAA4B;AAKlC,IAAM,wBAAA,GAA2B;AAKjC,IAAM,yBAAA,GAA4B","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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andamio/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core utilities and constants for Andamio protocol - zero React dependencies",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./hashing": {
|
|
15
|
+
"types": "./dist/utils/hashing/index.d.ts",
|
|
16
|
+
"import": "./dist/utils/hashing/index.mjs",
|
|
17
|
+
"require": "./dist/utils/hashing/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./constants": {
|
|
20
|
+
"types": "./dist/constants/index.d.ts",
|
|
21
|
+
"import": "./dist/constants/index.mjs",
|
|
22
|
+
"require": "./dist/constants/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"src"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"clean": "rm -rf dist",
|
|
34
|
+
"prepublishOnly": "npm run build"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"blakejs": "^1.2.1"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"typescript": "^5.3.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "https://github.com/Andamio-Platform/andamio-core"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"andamio",
|
|
52
|
+
"cardano",
|
|
53
|
+
"plutus",
|
|
54
|
+
"blake2b",
|
|
55
|
+
"hashing"
|
|
56
|
+
],
|
|
57
|
+
"license": "Apache-2.0"
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cardano Network Constants
|
|
3
|
+
*
|
|
4
|
+
* Network identifiers, explorer URLs, and other Cardano-specific constants.
|
|
5
|
+
*
|
|
6
|
+
* @module @andamio/core/constants
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Supported Cardano networks
|
|
11
|
+
*/
|
|
12
|
+
export type CardanoNetwork = "mainnet" | "preprod" | "preview";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Block explorer URLs by network
|
|
16
|
+
*/
|
|
17
|
+
export const EXPLORER_URLS: Record<CardanoNetwork, string> = {
|
|
18
|
+
mainnet: "https://cardanoscan.io",
|
|
19
|
+
preprod: "https://preprod.cardanoscan.io",
|
|
20
|
+
preview: "https://preview.cardanoscan.io",
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CExplorer URLs by network (alternative explorer)
|
|
25
|
+
*/
|
|
26
|
+
export const CEXPLORER_URLS: Record<CardanoNetwork, string> = {
|
|
27
|
+
mainnet: "https://cexplorer.io",
|
|
28
|
+
preprod: "https://preprod.cexplorer.io",
|
|
29
|
+
preview: "https://preview.cexplorer.io",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Network magic numbers for Cardano networks
|
|
34
|
+
*/
|
|
35
|
+
export const NETWORK_MAGIC: Record<CardanoNetwork, number> = {
|
|
36
|
+
mainnet: 764824073,
|
|
37
|
+
preprod: 1,
|
|
38
|
+
preview: 2,
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Bech32 address prefixes by network
|
|
43
|
+
*/
|
|
44
|
+
export const ADDRESS_PREFIX: Record<CardanoNetwork, string> = {
|
|
45
|
+
mainnet: "addr",
|
|
46
|
+
preprod: "addr_test",
|
|
47
|
+
preview: "addr_test",
|
|
48
|
+
} as const;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Get explorer URL for a transaction
|
|
52
|
+
*/
|
|
53
|
+
export function getTxExplorerUrl(
|
|
54
|
+
network: CardanoNetwork,
|
|
55
|
+
txHash: string
|
|
56
|
+
): string {
|
|
57
|
+
return `${EXPLORER_URLS[network]}/transaction/${txHash}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get explorer URL for an address
|
|
62
|
+
*/
|
|
63
|
+
export function getAddressExplorerUrl(
|
|
64
|
+
network: CardanoNetwork,
|
|
65
|
+
address: string
|
|
66
|
+
): string {
|
|
67
|
+
return `${EXPLORER_URLS[network]}/address/${address}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get explorer URL for a token/asset
|
|
72
|
+
*/
|
|
73
|
+
export function getAssetExplorerUrl(
|
|
74
|
+
network: CardanoNetwork,
|
|
75
|
+
policyId: string,
|
|
76
|
+
assetName?: string
|
|
77
|
+
): string {
|
|
78
|
+
const assetId = assetName ? `${policyId}.${assetName}` : policyId;
|
|
79
|
+
return `${EXPLORER_URLS[network]}/token/${assetId}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Get explorer URL for a policy
|
|
84
|
+
*/
|
|
85
|
+
export function getPolicyExplorerUrl(
|
|
86
|
+
network: CardanoNetwork,
|
|
87
|
+
policyId: string
|
|
88
|
+
): string {
|
|
89
|
+
return `${EXPLORER_URLS[network]}/tokenPolicy/${policyId}`;
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Andamio Constants
|
|
3
|
+
*
|
|
4
|
+
* Network configuration, policy IDs, and other constants.
|
|
5
|
+
*
|
|
6
|
+
* @module @andamio/core/constants
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Cardano network constants
|
|
10
|
+
export {
|
|
11
|
+
type CardanoNetwork,
|
|
12
|
+
EXPLORER_URLS,
|
|
13
|
+
CEXPLORER_URLS,
|
|
14
|
+
NETWORK_MAGIC,
|
|
15
|
+
ADDRESS_PREFIX,
|
|
16
|
+
getTxExplorerUrl,
|
|
17
|
+
getAddressExplorerUrl,
|
|
18
|
+
getAssetExplorerUrl,
|
|
19
|
+
getPolicyExplorerUrl,
|
|
20
|
+
} from "./cardano";
|
|
21
|
+
|
|
22
|
+
// Policy ID constants
|
|
23
|
+
export {
|
|
24
|
+
type NetworkPolicies,
|
|
25
|
+
POLICY_IDS,
|
|
26
|
+
getAccessTokenPolicyId,
|
|
27
|
+
isValidPolicyId,
|
|
28
|
+
isValidAssetName,
|
|
29
|
+
stringToAssetName,
|
|
30
|
+
assetNameToString,
|
|
31
|
+
} from "./policies";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Andamio Policy IDs
|
|
3
|
+
*
|
|
4
|
+
* Policy IDs for Andamio protocol tokens by network.
|
|
5
|
+
* These are used to identify access tokens, course tokens, and other
|
|
6
|
+
* protocol-specific assets on-chain.
|
|
7
|
+
*
|
|
8
|
+
* @module @andamio/core/constants
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { CardanoNetwork } from "./cardano";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Policy ID configuration for a network
|
|
15
|
+
*/
|
|
16
|
+
export interface NetworkPolicies {
|
|
17
|
+
/** Access token policy ID - identifies user access tokens */
|
|
18
|
+
accessToken: string;
|
|
19
|
+
/** Course token policy ID - identifies course tokens */
|
|
20
|
+
courseToken: string;
|
|
21
|
+
/** Module token policy ID - identifies module tokens */
|
|
22
|
+
moduleToken: string;
|
|
23
|
+
/** Assignment token policy ID - identifies assignment tokens */
|
|
24
|
+
assignmentToken: string;
|
|
25
|
+
/** Project token policy ID - identifies project tokens */
|
|
26
|
+
projectToken: string;
|
|
27
|
+
/** Task token policy ID - identifies task tokens */
|
|
28
|
+
taskToken: string;
|
|
29
|
+
/** Contributor token policy ID - identifies contributor tokens */
|
|
30
|
+
contributorToken: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Policy IDs by network
|
|
35
|
+
*
|
|
36
|
+
* Note: These should be loaded from environment variables in production.
|
|
37
|
+
* The values here are examples/defaults for the preprod network.
|
|
38
|
+
*/
|
|
39
|
+
export const POLICY_IDS: Record<CardanoNetwork, NetworkPolicies> = {
|
|
40
|
+
preprod: {
|
|
41
|
+
accessToken: "4758613867a8a7aa500b5d57a0e877f01a8e63c1365469589b12063c",
|
|
42
|
+
courseToken: "", // Set via environment
|
|
43
|
+
moduleToken: "", // Set via environment
|
|
44
|
+
assignmentToken: "", // Set via environment
|
|
45
|
+
projectToken: "", // Set via environment
|
|
46
|
+
taskToken: "", // Set via environment
|
|
47
|
+
contributorToken: "", // Set via environment
|
|
48
|
+
},
|
|
49
|
+
preview: {
|
|
50
|
+
accessToken: "",
|
|
51
|
+
courseToken: "",
|
|
52
|
+
moduleToken: "",
|
|
53
|
+
assignmentToken: "",
|
|
54
|
+
projectToken: "",
|
|
55
|
+
taskToken: "",
|
|
56
|
+
contributorToken: "",
|
|
57
|
+
},
|
|
58
|
+
mainnet: {
|
|
59
|
+
accessToken: "",
|
|
60
|
+
courseToken: "",
|
|
61
|
+
moduleToken: "",
|
|
62
|
+
assignmentToken: "",
|
|
63
|
+
projectToken: "",
|
|
64
|
+
taskToken: "",
|
|
65
|
+
contributorToken: "",
|
|
66
|
+
},
|
|
67
|
+
} as const;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the access token policy ID for a network
|
|
71
|
+
*/
|
|
72
|
+
export function getAccessTokenPolicyId(network: CardanoNetwork): string {
|
|
73
|
+
return POLICY_IDS[network].accessToken;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Validate a policy ID format (56 hex characters)
|
|
78
|
+
*/
|
|
79
|
+
export function isValidPolicyId(policyId: string): boolean {
|
|
80
|
+
if (typeof policyId !== "string") {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (policyId.length !== 56) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return /^[0-9a-fA-F]{56}$/.test(policyId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate an asset name format (hex string, max 64 chars / 32 bytes)
|
|
91
|
+
*/
|
|
92
|
+
export function isValidAssetName(assetName: string): boolean {
|
|
93
|
+
if (typeof assetName !== "string") {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (assetName.length > 64) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (assetName.length % 2 !== 0) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return /^[0-9a-fA-F]*$/.test(assetName);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Convert a UTF-8 string to hex asset name
|
|
107
|
+
*/
|
|
108
|
+
export function stringToAssetName(str: string): string {
|
|
109
|
+
return Array.from(new TextEncoder().encode(str))
|
|
110
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
111
|
+
.join("");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Convert a hex asset name to UTF-8 string
|
|
116
|
+
*/
|
|
117
|
+
export function assetNameToString(hex: string): string {
|
|
118
|
+
const bytes = new Uint8Array(
|
|
119
|
+
hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []
|
|
120
|
+
);
|
|
121
|
+
return new TextDecoder().decode(bytes);
|
|
122
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @andamio/core
|
|
3
|
+
*
|
|
4
|
+
* Core utilities and constants for the Andamio protocol.
|
|
5
|
+
* Zero React dependencies - can be used in any JavaScript/TypeScript environment.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// Re-export all hashing utilities
|
|
11
|
+
export * from "./utils/hashing";
|
|
12
|
+
|
|
13
|
+
// Re-export all constants
|
|
14
|
+
export * from "./constants";
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commitment Hash Utility
|
|
3
|
+
*
|
|
4
|
+
* Functions for computing and verifying hashes of commitment evidence.
|
|
5
|
+
* The hash is stored on-chain as `commitment_hash` in the course state datum,
|
|
6
|
+
* while the full evidence (Tiptap JSON document) is stored in the database.
|
|
7
|
+
*
|
|
8
|
+
* This provides:
|
|
9
|
+
* - Compact on-chain storage (64-char hex hash vs full JSON)
|
|
10
|
+
* - Tamper-evidence (can verify DB content matches on-chain commitment)
|
|
11
|
+
* - Privacy (evidence details not exposed on-chain)
|
|
12
|
+
*
|
|
13
|
+
* @module @andamio/core/hashing
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import * as blake from "blakejs";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tiptap document structure (simplified)
|
|
20
|
+
* The actual structure can be more complex with nested content
|
|
21
|
+
*/
|
|
22
|
+
export type TiptapDoc = {
|
|
23
|
+
type: "doc";
|
|
24
|
+
content?: TiptapNode[];
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type TiptapNode = {
|
|
29
|
+
type: string;
|
|
30
|
+
content?: TiptapNode[];
|
|
31
|
+
text?: string;
|
|
32
|
+
marks?: TiptapMark[];
|
|
33
|
+
attrs?: Record<string, unknown>;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type TiptapMark = {
|
|
38
|
+
type: string;
|
|
39
|
+
attrs?: Record<string, unknown>;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes a value for consistent hashing.
|
|
45
|
+
*
|
|
46
|
+
* Normalization rules:
|
|
47
|
+
* - Objects: Sort keys alphabetically, recursively normalize values
|
|
48
|
+
* - Arrays: Preserve order, recursively normalize items
|
|
49
|
+
* - Strings: Trim whitespace
|
|
50
|
+
* - Numbers/Booleans/null: Keep as-is
|
|
51
|
+
* - undefined: Convert to null
|
|
52
|
+
*
|
|
53
|
+
* @param value - Any JSON-serializable value
|
|
54
|
+
* @returns Normalized value
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeForHashing(value: unknown): unknown {
|
|
57
|
+
if (value === null || value === undefined) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (typeof value === "string") {
|
|
62
|
+
return value.trim();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.map(normalizeForHashing);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof value === "object") {
|
|
74
|
+
const sorted: Record<string, unknown> = {};
|
|
75
|
+
const keys = Object.keys(value as Record<string, unknown>).sort();
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
const val = (value as Record<string, unknown>)[key];
|
|
78
|
+
if (val !== undefined) {
|
|
79
|
+
sorted[key] = normalizeForHashing(val);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return sorted;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Computes the commitment hash from evidence content.
|
|
90
|
+
*
|
|
91
|
+
* The hash is computed as:
|
|
92
|
+
* 1. Normalize the evidence (sort keys, trim strings, etc.)
|
|
93
|
+
* 2. Serialize to JSON string (deterministic due to normalization)
|
|
94
|
+
* 3. Apply Blake2b-256 hash
|
|
95
|
+
*
|
|
96
|
+
* @param evidence - The evidence content (Tiptap JSON document or any JSON-serializable data)
|
|
97
|
+
* @returns 64-character lowercase hex string (Blake2b-256 hash)
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { computeCommitmentHash } from "@andamio/core/hashing";
|
|
102
|
+
*
|
|
103
|
+
* const evidence = {
|
|
104
|
+
* type: "doc",
|
|
105
|
+
* content: [
|
|
106
|
+
* { type: "paragraph", content: [{ type: "text", text: "My submission" }] }
|
|
107
|
+
* ]
|
|
108
|
+
* };
|
|
109
|
+
*
|
|
110
|
+
* const hash = computeCommitmentHash(evidence);
|
|
111
|
+
* // Use this hash as commitment_hash in the transaction
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function computeCommitmentHash(evidence: unknown): string {
|
|
115
|
+
const normalized = normalizeForHashing(evidence);
|
|
116
|
+
const jsonString = JSON.stringify(normalized);
|
|
117
|
+
const bytes = new TextEncoder().encode(jsonString);
|
|
118
|
+
return blake.blake2bHex(bytes, undefined, 32);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Verifies that evidence content matches an expected hash.
|
|
123
|
+
*
|
|
124
|
+
* Use this to verify that database evidence matches the on-chain commitment.
|
|
125
|
+
*
|
|
126
|
+
* @param evidence - The evidence content to verify
|
|
127
|
+
* @param expectedHash - The expected hash (from on-chain data)
|
|
128
|
+
* @returns True if the evidence produces the expected hash
|
|
129
|
+
*/
|
|
130
|
+
export function verifyCommitmentHash(
|
|
131
|
+
evidence: unknown,
|
|
132
|
+
expectedHash: string
|
|
133
|
+
): boolean {
|
|
134
|
+
const computedHash = computeCommitmentHash(evidence);
|
|
135
|
+
return computedHash.toLowerCase() === expectedHash.toLowerCase();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Validates that a string is a valid commitment hash format.
|
|
140
|
+
*
|
|
141
|
+
* A valid hash is a 64-character hexadecimal string (Blake2b-256 output).
|
|
142
|
+
*
|
|
143
|
+
* @param hash - The string to validate
|
|
144
|
+
* @returns True if the string is a valid hash format
|
|
145
|
+
*/
|
|
146
|
+
export function isValidCommitmentHash(hash: string): boolean {
|
|
147
|
+
if (typeof hash !== "string") {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (hash.length !== 64) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return /^[0-9a-fA-F]{64}$/.test(hash);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Result of comparing evidence with an on-chain hash
|
|
158
|
+
*/
|
|
159
|
+
export type EvidenceVerificationResult = {
|
|
160
|
+
/** Whether the evidence matches the on-chain hash */
|
|
161
|
+
isValid: boolean;
|
|
162
|
+
/** The hash computed from the evidence */
|
|
163
|
+
computedHash: string;
|
|
164
|
+
/** The expected hash (from on-chain) */
|
|
165
|
+
expectedHash: string;
|
|
166
|
+
/** Human-readable status message */
|
|
167
|
+
message: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Performs a detailed verification of evidence against an on-chain hash.
|
|
172
|
+
*
|
|
173
|
+
* Returns a detailed result object with both hashes and a status message,
|
|
174
|
+
* useful for debugging and user feedback.
|
|
175
|
+
*
|
|
176
|
+
* @param evidence - The evidence content to verify
|
|
177
|
+
* @param onChainHash - The hash from on-chain data
|
|
178
|
+
* @returns Detailed verification result
|
|
179
|
+
*/
|
|
180
|
+
export function verifyEvidenceDetailed(
|
|
181
|
+
evidence: unknown,
|
|
182
|
+
onChainHash: string
|
|
183
|
+
): EvidenceVerificationResult {
|
|
184
|
+
if (!isValidCommitmentHash(onChainHash)) {
|
|
185
|
+
return {
|
|
186
|
+
isValid: false,
|
|
187
|
+
computedHash: "",
|
|
188
|
+
expectedHash: onChainHash,
|
|
189
|
+
message: `Invalid on-chain hash format: expected 64 hex characters, got "${onChainHash}"`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const computedHash = computeCommitmentHash(evidence);
|
|
194
|
+
const isValid = computedHash.toLowerCase() === onChainHash.toLowerCase();
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
isValid,
|
|
198
|
+
computedHash,
|
|
199
|
+
expectedHash: onChainHash.toLowerCase(),
|
|
200
|
+
message: isValid
|
|
201
|
+
? "Evidence matches on-chain commitment"
|
|
202
|
+
: "Evidence does not match on-chain commitment - content may have been modified",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// =============================================================================
|
|
207
|
+
// Backwards Compatibility Aliases (deprecated)
|
|
208
|
+
// =============================================================================
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @deprecated Use `computeCommitmentHash` instead.
|
|
212
|
+
*/
|
|
213
|
+
export const computeAssignmentInfoHash = computeCommitmentHash;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @deprecated Use `verifyCommitmentHash` instead.
|
|
217
|
+
*/
|
|
218
|
+
export const verifyAssignmentInfoHash = verifyCommitmentHash;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @deprecated Use `isValidCommitmentHash` instead.
|
|
222
|
+
*/
|
|
223
|
+
export const isValidAssignmentInfoHash = isValidCommitmentHash;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Andamio Hashing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Content-addressed hashing functions for on-chain data verification.
|
|
5
|
+
* All hashes are 64-character hex strings (Blake2b-256).
|
|
6
|
+
*
|
|
7
|
+
* @module @andamio/core/hashing
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// SLT (Student Learning Target) hashing
|
|
11
|
+
export {
|
|
12
|
+
computeSltHash,
|
|
13
|
+
computeSltHashDefinite,
|
|
14
|
+
verifySltHash,
|
|
15
|
+
isValidSltHash,
|
|
16
|
+
} from "./slt-hash";
|
|
17
|
+
|
|
18
|
+
// Task hashing
|
|
19
|
+
export {
|
|
20
|
+
computeTaskHash,
|
|
21
|
+
verifyTaskHash,
|
|
22
|
+
isValidTaskHash,
|
|
23
|
+
debugTaskCBOR,
|
|
24
|
+
type TaskData,
|
|
25
|
+
} from "./task-hash";
|
|
26
|
+
|
|
27
|
+
// Commitment (assignment evidence) hashing
|
|
28
|
+
export {
|
|
29
|
+
computeCommitmentHash,
|
|
30
|
+
verifyCommitmentHash,
|
|
31
|
+
isValidCommitmentHash,
|
|
32
|
+
verifyEvidenceDetailed,
|
|
33
|
+
normalizeForHashing,
|
|
34
|
+
// Backwards compatibility aliases
|
|
35
|
+
computeAssignmentInfoHash,
|
|
36
|
+
verifyAssignmentInfoHash,
|
|
37
|
+
isValidAssignmentInfoHash,
|
|
38
|
+
// Types
|
|
39
|
+
type TiptapDoc,
|
|
40
|
+
type TiptapNode,
|
|
41
|
+
type TiptapMark,
|
|
42
|
+
type EvidenceVerificationResult,
|
|
43
|
+
} from "./commitment-hash";
|