> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canton.network/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> If you are building a Canton Network application, start from https://docs.canton.network/appdev/quickstart.md. To run only a local network for your own Daml code, without building the QuickStart demo, see https://docs.canton.network/sdks-tools/development-tools/localnet.md.

# DA.Crypto.Text

> Reference documentation for Daml module DA.Crypto.Text.

Daml module

# DA.Crypto.Text

Functions for working with Crypto builtins.

Daml

[Updated 3.5.1](#history-updated-3-5-1)

Module
DA.Crypto.Text

Latest release
3.7.5

## Data Types

### `type BytesHex`

\= [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952)

### `type PublicKeyHex`

\= [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952)

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

### `type SignatureHex`

\= [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952)

A DER formatted SECP256K1 signature

## Typeclasses

### `class HasToHex a`

Methods:

* `toHex` : `a` -> [`BytesHex`](#type-da-crypto-text-byteshex-47880)
  Converts a typed data value into a hex encoded string.

Instances:

* instance [`HasToHex`](#class-da-crypto-text-hastohex-92431) [`Party`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-party-57932)
* instance [`HasToHex`](#class-da-crypto-text-hastohex-92431) [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261)
* instance [`HasToHex`](#class-da-crypto-text-hastohex-92431) [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952)

### `class HasFromHex a`

Methods:

* `fromHex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> `a`
  Converts a hex encoded string into a typed data value.

Instances:

* instance [`HasFromHex`](#class-da-crypto-text-hasfromhex-84972) ([`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) [`Party`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-lf-party-57932))
* instance [`HasFromHex`](#class-da-crypto-text-hasfromhex-84972) ([`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261))
* instance [`HasFromHex`](#class-da-crypto-text-hasfromhex-84972) ([`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952))

## Functions

### `isHex`

`isHex` : [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

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

### `sha256`

`sha256` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`BytesHex`](#type-da-crypto-text-byteshex-47880)

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`

`keccak256` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`BytesHex`](#type-da-crypto-text-byteshex-47880)

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`

`secp256k1WithValidation` : [`SignatureHex`](#type-da-crypto-text-signaturehex-12945) -> [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`PublicKeyHex`](#type-da-crypto-text-publickeyhex-51359) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

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`

`secp256k1WithEcdsaOnly` : [`SignatureHex`](#type-da-crypto-text-signaturehex-12945) -> [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`PublicKeyHex`](#type-da-crypto-text-publickeyhex-51359) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

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

### `secp256k1`

`secp256k1` : [`SignatureHex`](#type-da-crypto-text-signaturehex-12945) -> [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`PublicKeyHex`](#type-da-crypto-text-publickeyhex-51359) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

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

### `numericViaStringToHex`

`numericViaStringToHex` : [`NumericScale`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-numericscale-83720) `n` => [`Numeric`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-numeric-891) `n` -> [`BytesHex`](#type-da-crypto-text-byteshex-47880)

### `numericViaStringFromHex`

`numericViaStringFromHex` : [`NumericScale`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#class-ghc-classes-numericscale-83720) `n` => [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) ([`Numeric`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-numeric-891) `n`)

### `byteCount`

`byteCount` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261)

Number of bytes present in a byte encoded string.

### `minBytes32Hex`

`minBytes32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Minimum Bytes32 hex value

### `maxBytes32Hex`

`maxBytes32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Maximum Bytes32 hex value

### `isBytes32Hex`

`isBytes32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Validate that the byte encoded string is Bytes32Hex

### `minUInt32Hex`

`minUInt32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Minimum UInt32 hex value

### `maxUInt32Hex`

`maxUInt32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Maximum UInt32 hex value

### `isUInt32Hex`

`isUInt32Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Validate that the byte encoded string is UInt32Hex

### `minUInt64Hex`

`minUInt64Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Minimum UInt64 hex value

### `maxUInt64Hex`

`maxUInt64Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Maximum UInt64 hex value

### `isUInt64Hex`

`isUInt64Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Validate that the byte encoded string is UInt64Hex

### `minUInt256Hex`

`minUInt256Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Minimum UInt256 hex value

### `maxUInt256Hex`

`maxUInt256Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880)

Maximum UInt256 hex value

### `isUInt256Hex`

`isUInt256Hex` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Bool`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-bool-66265)

Validate that the byte encoded string is UInt256Hex

### `packHexBytes`

`packHexBytes` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261) -> [`Optional`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-internal-prelude-optional-37153) [`BytesHex`](#type-da-crypto-text-byteshex-47880)

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`

`sliceHexBytes` : [`BytesHex`](#type-da-crypto-text-byteshex-47880) -> [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261) -> [`Int`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-int-37261) -> [`Either`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-da-types-either-56020) [`Text`](https://docs.canton.network/appdev/reference/daml-standard-library/prelude#type-ghc-types-text-51952) [`BytesHex`](#type-da-crypto-text-byteshex-47880)

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

## History

Updated
`3.5.1`

Module declarations or documentation updated.
