Hash-related types
Dimensions of choices:
opaque type Hash <: ByteString
opaque type Hash <: Array[Byte]
opaque type Hash <: IArray[Byte]
type Hash[Size <: Int & Singleton]
type Hash[+HF, Size <: Int & Singleton]
type Hash[+HF, Size <: Int & Singleton, +Purpose]
case class Hash28(value: Array[Byte])
case class Hash28(value: IArray[Byte])
case class Hash28(value: ByteString)
- Hash type:
Hash
orHash[HF, Size]
orHash[HF, Size, Purpose]
- opaque vs type alias vs case class
- over
ByteString
vsIArray[Byte]
vsArray[Byte]
Compatibility considerations
- For Java/Kotlin, opaque types are just type aliases, so no type safety there.
- Wrapping Array[Byte] in a case class is type-safe, but adds overhead.
- Wrapping ByteString in a case class is type-safe, but adds even more overhead.
- We use
ByteString
for script evaluation and onchain data types, so it makes sense to use it as the base type forHash
. This allows us to use the same type for both offchain and onchain data, which is convenient.
So, looks like the compromise is to use ByteString
as the base type for Hash
, and use opaque types for type safety.