# `Tezex.Forge`
[🔗](https://github.com/objkt-com/tezex/blob/v5.0.1/lib/forge.ex#L1)

Convert Tezos Micheline data from/to binary form for injection into the Tezos blockchain (aka forging/unforging Micheline).

Mostly ported from pytezos@9352c4579e436b92f8070343964af20747255197
> pytezos / MIT License / (c) 2020 Baking Bad / (c) 2018 Arthur Breitman

# `base58_encoding`

```elixir
@type base58_encoding() :: %{
  e_prefix: String.t(),
  e_len: non_neg_integer(),
  d_prefix: binary(),
  d_len: non_neg_integer()
}
```

Represents a base58 encoding configuration.

# `io_encoding`

```elixir
@type io_encoding() :: :bytes | :hex
```

Represents the encoding type for input/output operations.
Can be either `:bytes` for raw binary data or `:hex` for hexadecimal string representation.

# `forge_address`

```elixir
@spec forge_address(binary(), io_encoding(), boolean()) :: nonempty_binary()
```

Encode address or key hash into bytes.

- `value` is a base58 encoded address or key_hash
- `tz_only` indicates that it's a key_hash (will be encoded in a more compact form)

# `forge_array`

```elixir
@spec forge_array(binary(), io_encoding(), non_neg_integer()) :: binary()
```

# `forge_base58`

```elixir
@spec forge_base58(binary(), io_encoding()) :: binary()
```

# `forge_bool`

```elixir
@spec forge_bool(boolean(), io_encoding()) :: nonempty_binary()
```

# `forge_contract`

```elixir
@spec forge_contract(binary(), io_encoding()) :: binary()
```

# `forge_int16`

```elixir
@spec forge_int16(integer(), io_encoding()) :: nonempty_binary()
```

# `forge_int32`

```elixir
@spec forge_int32(integer(), io_encoding()) :: nonempty_binary()
```

# `forge_int`

```elixir
@spec forge_int(integer(), io_encoding()) :: nonempty_binary()
```

Encodes a signed unbounded integer into byte form.

## Parameters

  * `value` - The integer to be encoded.
  * `output_encoding` - The encoding type for the output. Defaults to `:bytes`.

## Returns

  A binary string representing the encoded integer.

## Examples

    iex> forge_int(123)
    <<123>>

    iex> forge_int(123, :hex)
    "7B"

# `forge_micheline`

```elixir
@spec forge_micheline(list() | map(), io_encoding()) :: binary()
```

Encode a Micheline expression into byte form.

# `forge_nat`

```elixir
@spec forge_nat(non_neg_integer(), io_encoding()) :: nonempty_binary()
```

Encode a non-negative integer using LEB128 encoding.

# `forge_public_key`

```elixir
@spec forge_public_key(binary(), io_encoding()) :: nonempty_binary()
```

# `forge_script`

```elixir
@spec forge_script(map(), io_encoding()) :: binary()
```

# `forge_script_expr`

```elixir
@spec forge_script_expr(binary(), io_encoding()) :: nonempty_binary()
```

# `optimize_timestamp`

```elixir
@spec optimize_timestamp(binary()) :: integer()
```

# `unforge_address`

```elixir
@spec unforge_address(binary(), io_encoding()) :: nonempty_binary()
```

# `unforge_array`

```elixir
@spec unforge_array(binary(), io_encoding(), non_neg_integer()) ::
  {binary(), non_neg_integer()}
```

# `unforge_chain_id`

```elixir
@spec unforge_chain_id(binary(), io_encoding()) :: nonempty_binary()
```

# `unforge_contract`

```elixir
@spec unforge_contract(binary(), io_encoding()) :: nonempty_binary()
```

Decode a contract (address + optional entrypoint) from bytes, returning a string with the base58 encoded address and, if present, the entrypoint separated by `%`.

# `unforge_int`

```elixir
@spec unforge_int(binary(), io_encoding()) :: {integer(), non_neg_integer()}
```

Decode a signed unbounded integer from bytes.

# `unforge_micheline`

```elixir
@spec unforge_micheline(binary(), io_encoding()) :: list() | map()
```

Parse Micheline map from bytes.

# `unforge_public_key`

```elixir
@spec unforge_public_key(binary(), io_encoding()) :: nonempty_binary()
```

# `unforge_signature`

```elixir
@spec unforge_signature(binary(), io_encoding()) :: nonempty_binary()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
