Skip to main content

DA.Crypto.Text

Functions for working with Crypto builtins. For example, as used to implement CCTP functionality.

Module Snapshot

Lifecycle

Stable.

Notices

Status: active Introduced in: 3.4.9 Removed in: - Warnings: 0 Deprecations: 0 Deprecated since: -

Data Types

type BytesHex = Text

type PublicKeyHex = Text

A DER formatted public key to be used for ECDSA signature verification

type SignatureHex = Text

A DER formatted SECP256K1 signature

Typeclasses

class HasToHex a

Methods:
  • toHex : a -> BytesHex Converts a typed data value into a hex encoded string.
Instances:
  • instance HasToHex Party
  • instance HasToHex Int
  • instance HasToHex Text

class HasFromHex a

Methods:
  • fromHex : BytesHex -> a Converts a hex encoded string into a typed data value.
Instances:
  • instance HasFromHex (Optional Party)
  • instance HasFromHex (Optional Int)
  • instance HasFromHex (Optional Text)

Functions

isHex

isHex is True if t is not empty and consists only of hex or hexadecimal characters.

sha256

Computes the SHA256 hash of the decoded UTF8 bytes of the Text, and returns it in its hex-encoded form. The hex encoding uses lowercase letters.

keccak256

Computes the KECCAK256 hash of the UTF8 bytes of the Text, and returns it in its hex-encoded form. The hex encoding uses lowercase letters.

secp256k1WithValidation

Validate the SECP256K1 signature given a hex encoded message and a hex encoded DER formatted public key. Prior to signature validation, validate the public key and check it is on the SECP256K1 curve.

secp256k1WithEcdsaOnly

Validate the SECP256K1 signature given a hex encoded message and a hex encoded DER formatted public key.

secp256k1

Validate the SECP256K1 signature given a SHA256 hash of a hex encoded message and a hex encoded DER formatted public key.

numericViaStringToHex

numericViaStringFromHex

byteCount

Number of bytes present in a byte encoded string.

minBytes32Hex

Minimum Bytes32 hex value

maxBytes32Hex

Maximum Bytes32 hex value

isBytes32Hex

Validate that the byte encoded string is Bytes32Hex

minUInt32Hex

Minimum UInt32 hex value

maxUInt32Hex

Maximum UInt32 hex value

isUInt32Hex

Validate that the byte encoded string is UInt32Hex

minUInt64Hex

Minimum UInt64 hex value

maxUInt64Hex

Maximum UInt64 hex value

isUInt64Hex

Validate that the byte encoded string is UInt64Hex

minUInt256Hex

Minimum UInt256 hex value

maxUInt256Hex

Maximum UInt256 hex value

isUInt256Hex

Validate that the byte encoded string is UInt256Hex

packHexBytes

Pack a byte encoded string to a given byte count size. If the byte string is shorter than the pad size, then prefix with 00 byte strings. If the byte string is larger, then truncate the byte string.

sliceHexBytes

Extract the byte string starting at startByte up to, but excluding, endByte. Byte indexing starts at 1.