|
| 1 | +--- |
| 2 | +"@evolution-sdk/evolution": patch |
| 3 | +--- |
| 4 | + |
| 5 | +## hashPlutusData encoding options |
| 6 | + |
| 7 | +Add optional CBOR encoding options parameter to `hashPlutusData` function. This allows controlling how Plutus data is encoded before hashing, which affects the resulting datum hash. |
| 8 | + |
| 9 | +**Before:** |
| 10 | + |
| 11 | +```typescript |
| 12 | +import { hashPlutusData } from "@evolution-sdk/evolution/utils/Hash" |
| 13 | + |
| 14 | +// Always uses indefinite-length encoding (CML_DATA_DEFAULT_OPTIONS) |
| 15 | +const hash = hashPlutusData(data) |
| 16 | +``` |
| 17 | + |
| 18 | +**After:** |
| 19 | + |
| 20 | +```typescript |
| 21 | +import { Core } from "@evolution-sdk/evolution" |
| 22 | +import { hashPlutusData } from "@evolution-sdk/evolution/utils/Hash" |
| 23 | + |
| 24 | +const cborHex = "d87983486c6f76656c6163655820c3e43c6b8fb46068d4ef9746a934eba534873db0aacebdaf369c78ab23cb57751a004c4b40" |
| 25 | +const decoded = Core.Data.fromCBORHex(cborHex) |
| 26 | + |
| 27 | +// Indefinite-length (SDK default for Data) |
| 28 | +const indefiniteHash = hashPlutusData(decoded, Core.CBOR.CML_DATA_DEFAULT_OPTIONS) |
| 29 | +console.log("Hash:", Core.Bytes.toHex(indefiniteHash.hash)) |
| 30 | +// b67b6e7d2497d4e87a240a080a109a905f73527a244775cc1e2a43f48202700f |
| 31 | + |
| 32 | +// Definite-length encoding |
| 33 | +const definiteHash = hashPlutusData(decoded, Core.CBOR.CML_DEFAULT_OPTIONS) |
| 34 | +console.log("Hash:", Core.Bytes.toHex(definiteHash.hash)) |
| 35 | +// bc7eea92ba15710926e99904e746e5da739d77085b6192ddd87a0e7b4298e0c0 |
| 36 | + |
| 37 | +// Aiken-compatible encoding |
| 38 | +const aikenHash = hashPlutusData(decoded, Core.CBOR.AIKEN_DEFAULT_OPTIONS) |
| 39 | +console.log("Hash:", Core.Bytes.toHex(aikenHash.hash)) |
| 40 | +// b67b6e7d2497d4e87a240a080a109a905f73527a244775cc1e2a43f48202700f |
| 41 | +``` |
0 commit comments