OpaqueBytes - corda

corda / net.corda.core.utilities / OpaqueBytes

# OpaqueBytes

`open class OpaqueBytes : ByteSequence`

A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it won't arrive for a few years yet!

### Constructors

#### <init> | A simple class that wraps a byte array and makes the equals/hashCode/toString methods work as you actually expect. In an ideal JVM this would be a value type and be completely overhead free. Project Valhalla is adding such functionality to Java, but it won't arrive for a few years yet! `OpaqueBytes(bytes: ByteArray)`

### Properties

#### bytes | The bytes are always cloned so that this object becomes immutable. This has been done to prevent tampering with entities such as net.corda.core.crypto.SecureHash and net.corda.core.contracts.PrivacySalt, as well as preserve the integrity of our hash constants net.corda.core.crypto.SecureHash.zeroHash and net.corda.core.crypto.SecureHash.allOnesHash. `val bytes: ByteArray`

### Companion Object Functions

#### of | Create OpaqueBytes from a sequence of Byte values. `fun of(vararg b: Byte): OpaqueBytes`

### Extension Properties

#### isZero | `val OpaqueBytes.isZero: Boolean`

### Extension Functions

#### deserialize | Convenience extension method for deserializing a ByteSequence, utilising the defaults. `fun <T : Any> ByteSequence.deserialize(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): T`
#### deserializeWithCompatibleContext | Additionally returns SerializationContext which was used for encoding. It might be helpful to know SerializationContext to use the same encoding in the reply. `fun <T : Any> ByteSequence.deserializeWithCompatibleContext(serializationFactory: SerializationFactory = SerializationFactory.defaultFactory, context: SerializationContext = serializationFactory.defaultContext): ObjectWithCompatibleContext<T>`
#### hashAs | Compute the algorithm hash for the contents of the OpaqueBytes. `fun OpaqueBytes.hashAs(algorithm: String): SecureHash`
#### sha256 | Compute the SHA-256 hash for the contents of the OpaqueBytes. `fun OpaqueBytes.sha256(): SHA256`

### Inheritors

#### DigitalSignature | A wrapper around a digital signature. `open class DigitalSignature : OpaqueBytes`
#### PrivacySalt | A privacy salt is required to compute nonces per transaction component in order to ensure that an adversary cannot use brute force techniques and reveal the content of a Merkle-leaf hashed value. Because this salt serves the role of the seed to compute nonces, its size and entropy should be equal to the underlying hash function used for Merkle tree generation, currently SecureHash.SHA256, which has an output of 32 bytes. There are two constructors, one that generates a new 32-bytes random salt, and another that takes a ByteArray input. The latter is required in cases where the salt value needs to be pre-generated (agreed between transacting parties), but it is highlighted that one should always ensure it has sufficient entropy. `class PrivacySalt : OpaqueBytes`
#### SecureHash | Container for a cryptographically secure hash value. Provides utilities for generating a cryptographic hash using different algorithms (currently only SHA-256 supported). `sealed class SecureHash : OpaqueBytes`
#### SerializedBytes | A type safe wrapper around a byte array that contains a serialised object. You can call SerializedBytes.deserialize to get the original object back. `class SerializedBytes<T : Any> : OpaqueBytes`