Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .changeset/sour-lands-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@evolution-sdk/evolution": patch
---

Add `Data.hashData()` function for computing blake2b-256 hash of PlutusData.

This moves the hashing functionality from `utils/Hash.hashPlutusData()` to the Data module for better organization and discoverability. The function computes the datum hash used for inline datums and datum witnesses.

**Example:**

```typescript
import * as Data from "@evolution-sdk/evolution/Data"

// Hash a simple integer
const intHash = Data.hashData(42n)

// Hash a constructor (e.g., for a custom datum type)
const constr = new Data.Constr({ index: 0n, fields: [1n, 2n] })
const constrHash = Data.hashData(constr)

// Hash a bytearray
const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef])
const bytesHash = Data.hashData(bytes)

// Hash a map
const map = new Map<Data.Data, Data.Data>([[1n, 2n]])
const mapHash = Data.hashData(map)
```

**Breaking Change:** `hashPlutusData` has been removed from `utils/Hash`. Use `Data.hashData()` instead.
28 changes: 14 additions & 14 deletions docs/content/docs/modules/Address.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent: Modules

## Address overview

Added in v1.0.0
Added in v2.0.0

---

Expand Down Expand Up @@ -57,7 +57,7 @@ FastCheck arbitrary generator for testing
export declare const arbitrary: FastCheck.Arbitrary<Address>
```

Added in v1.0.0
Added in v2.0.0

# Functions

Expand All @@ -71,7 +71,7 @@ Sync functions using Schema utilities
export declare const fromBech32: (i: string, overrideOptions?: ParseOptions) => Address
```

Added in v1.0.0
Added in v2.0.0

# Model

Expand All @@ -94,7 +94,7 @@ export interface AddressDetails {
}
```

Added in v1.0.0
Added in v2.0.0

# Schema

Expand All @@ -106,7 +106,7 @@ Added in v1.0.0
export declare class Address
```

Added in v1.0.0
Added in v2.0.0

### toJSON (method)

Expand Down Expand Up @@ -164,7 +164,7 @@ export declare const FromBech32: Schema.transformOrFail<
>
```

Added in v1.0.0
Added in v2.0.0

## FromBytes

Expand All @@ -181,7 +181,7 @@ export declare const FromBytes: Schema.transformOrFail<
>
```

Added in v1.0.0
Added in v2.0.0

## FromHex

Expand All @@ -202,7 +202,7 @@ export declare const FromHex: Schema.transform<
>
```

Added in v1.0.0
Added in v2.0.0

# Utils

Expand Down Expand Up @@ -236,7 +236,7 @@ if (details) {
}
```

Added in v1.0.0
Added in v2.0.0

## getNetworkId

Expand All @@ -248,7 +248,7 @@ Get network ID from AddressStructure
export declare const getNetworkId: (address: Address) => NetworkId.NetworkId
```

Added in v1.0.0
Added in v2.0.0

## getPaymentCredential

Expand All @@ -261,7 +261,7 @@ Returns undefined if the address cannot be parsed
export declare const getPaymentCredential: (address: string) => Credential.Credential | undefined
```

Added in v1.0.0
Added in v2.0.0

## getStakingCredential

Expand All @@ -274,7 +274,7 @@ Returns undefined if the address has no staking credential or cannot be parsed
export declare const getStakingCredential: (address: string) => Credential.Credential | undefined
```

Added in v1.0.0
Added in v2.0.0

## hasStakingCredential

Expand All @@ -286,7 +286,7 @@ Check if AddressStructure has staking credential (BaseAddress-like)
export declare const hasStakingCredential: (address: Address) => boolean
```

Added in v1.0.0
Added in v2.0.0

## isEnterprise

Expand All @@ -298,7 +298,7 @@ Check if AddressStructure is enterprise-like (no staking credential)
export declare const isEnterprise: (address: Address) => boolean
```

Added in v1.0.0
Added in v2.0.0

# utils

Expand Down
35 changes: 35 additions & 0 deletions docs/content/docs/modules/Data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ parent: Modules
- [arbitraryPlutusData](#arbitraryplutusdata)
- [arbitraryPlutusList](#arbitraryplutuslist)
- [arbitraryPlutusMap](#arbitraryplutusmap)
- [hashing](#hashing)
- [hashData](#hashdata)
- [model](#model)
- [Data (type alias)](#data-type-alias)
- [DataEncoded (type alias)](#dataencoded-type-alias)
Expand Down Expand Up @@ -307,6 +309,39 @@ export declare const arbitraryPlutusMap: (depth: number) => FastCheck.Arbitrary<

Added in v2.0.0

# hashing

## hashData

Compute the hash of PlutusData using blake2b-256 over its CBOR encoding.
Defaults to CML_DATA_DEFAULT_OPTIONS (indefinite-length arrays/maps).

**Signature**

```ts
export declare const hashData: (data: Data, options?: CBOR.CodecOptions) => DatumHash.DatumHash
```

**Example**

```typescript
import * as Data from "@evolution-sdk/evolution/Data"

// Hash a simple integer
const intData = 42n
const intHash = Data.hashData(intData)

// Hash a constructor
const constr = new Data.Constr({ index: 0n, fields: [1n, 2n] })
const constrHash = Data.hashData(constr)

// Hash a bytearray
const bytes = new Uint8Array([0xde, 0xad, 0xbe, 0xef])
const bytesHash = Data.hashData(bytes)
```

Added in v2.0.0

# model

## Data (type alias)
Expand Down
14 changes: 0 additions & 14 deletions docs/content/docs/modules/utils/Hash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ parent: Modules
- [RedeemersFormat (type alias)](#redeemersformat-type-alias)
- [computeTotalExUnits](#computetotalexunits)
- [hashAuxiliaryData](#hashauxiliarydata)
- [hashPlutusData](#hashplutusdata)
- [hashScriptData](#hashscriptdata)
- [hashTransaction](#hashtransaction)

Expand Down Expand Up @@ -55,19 +54,6 @@ Compute hash of auxiliary data (tag 259) per ledger rules.
export declare const hashAuxiliaryData: (aux: AuxiliaryData.AuxiliaryData) => AuxiliaryDataHash.AuxiliaryDataHash
```

## hashPlutusData

Compute hash of plutus data using specified CBOR encoding options.
Defaults to CML_DATA_DEFAULT_OPTIONS (indefinite-length arrays/maps).

TODO: Consider moving this to the Data module as Data.hash() for better organization

**Signature**

```ts
export declare const hashPlutusData: (pd: Data.Data, options?: CBOR.CodecOptions) => DatumHash.DatumHash
```

## hashScriptData

Compute script_data_hash using standard module encoders.
Expand Down
28 changes: 14 additions & 14 deletions packages/evolution/docs/modules/Address.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent: Modules

## Address overview

Added in v1.0.0
Added in v2.0.0
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Address documentation version changes from v1.0.0 to v2.0.0 appear to be unrelated to the hashPlutusData refactoring described in the PR. While these changes may be correct (as the Address.ts source code uses @SInCE 2.0.0), they are not mentioned in the PR description. Consider whether these changes should be in a separate PR or if the PR description should be updated to mention them.

Copilot uses AI. Check for mistakes.

---

Expand Down Expand Up @@ -57,7 +57,7 @@ FastCheck arbitrary generator for testing
export declare const arbitrary: FastCheck.Arbitrary<Address>
```

Added in v1.0.0
Added in v2.0.0

# Functions

Expand All @@ -71,7 +71,7 @@ Sync functions using Schema utilities
export declare const fromBech32: (i: string, overrideOptions?: ParseOptions) => Address
```

Added in v1.0.0
Added in v2.0.0

# Model

Expand All @@ -94,7 +94,7 @@ export interface AddressDetails {
}
```

Added in v1.0.0
Added in v2.0.0

# Schema

Expand All @@ -106,7 +106,7 @@ Added in v1.0.0
export declare class Address
```

Added in v1.0.0
Added in v2.0.0

### toJSON (method)

Expand Down Expand Up @@ -164,7 +164,7 @@ export declare const FromBech32: Schema.transformOrFail<
>
```

Added in v1.0.0
Added in v2.0.0

## FromBytes

Expand All @@ -181,7 +181,7 @@ export declare const FromBytes: Schema.transformOrFail<
>
```

Added in v1.0.0
Added in v2.0.0

## FromHex

Expand All @@ -202,7 +202,7 @@ export declare const FromHex: Schema.transform<
>
```

Added in v1.0.0
Added in v2.0.0

# Utils

Expand Down Expand Up @@ -236,7 +236,7 @@ if (details) {
}
```

Added in v1.0.0
Added in v2.0.0

## getNetworkId

Expand All @@ -248,7 +248,7 @@ Get network ID from AddressStructure
export declare const getNetworkId: (address: Address) => NetworkId.NetworkId
```

Added in v1.0.0
Added in v2.0.0

## getPaymentCredential

Expand All @@ -261,7 +261,7 @@ Returns undefined if the address cannot be parsed
export declare const getPaymentCredential: (address: string) => Credential.Credential | undefined
```

Added in v1.0.0
Added in v2.0.0

## getStakingCredential

Expand All @@ -274,7 +274,7 @@ Returns undefined if the address has no staking credential or cannot be parsed
export declare const getStakingCredential: (address: string) => Credential.Credential | undefined
```

Added in v1.0.0
Added in v2.0.0

## hasStakingCredential

Expand All @@ -286,7 +286,7 @@ Check if AddressStructure has staking credential (BaseAddress-like)
export declare const hasStakingCredential: (address: Address) => boolean
```

Added in v1.0.0
Added in v2.0.0

## isEnterprise

Expand All @@ -298,7 +298,7 @@ Check if AddressStructure is enterprise-like (no staking credential)
export declare const isEnterprise: (address: Address) => boolean
```

Added in v1.0.0
Added in v2.0.0

# utils

Expand Down
Loading