# `Tezex.Crypto.ECDSA`
[🔗](https://github.com/objkt-com/tezex/blob/v4.0.0/lib/crypto/ecdsa.ex#L1)

Elliptic Curve Digital Signature Algorithm (ECDSA) implementation to:
- decode compressed public key
- verify signatures
- sign bytes

# `decode_point`

```elixir
@spec decode_point(nonempty_binary(), Tezex.Crypto.Curve.t()) ::
  Tezex.Crypto.Point.t()
```

# `decode_public_key`

```elixir
@spec decode_public_key(
  nonempty_binary(),
  :prime256v1 | :secp256k1 | Tezex.Crypto.Curve.t()
) ::
  Tezex.Crypto.PublicKey.t()
```

Decodes a compressed public key to the EC public key it is representing on EC `curve`.

Here is a sample `curve`, P-256 with curve parameters from <https://neuromancer.sk/std/nist/>:

```elixir
%Curve{
    name: :prime256v1,
    A: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC,
    B: 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B,
    P: 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF,
    N: 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551,
    G: %Point{
      x: 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296,
      y: 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5
    }
  }
```

Parameters:
- `compressed_pubkey` [`t:binary/0`]: the public key to decode
- `curve` [`t:Tezex.Crypto.Curve.t/0`]: the curve to use (or one of `:prime256v1`, `:secp256k1` for the two known curves supported by default)

Returns:
- public_key [`t:Tezex.Crypto.PublicKey.t/0`]: a struct containing the public point and the curve;

# `sign`

```elixir
@spec sign(iodata(), Tezex.Crypto.PrivateKey.t(), [any()]) ::
  Tezex.Crypto.Signature.t()
```

# `verify?`

```elixir
@spec verify?(
  nonempty_binary(),
  Tezex.Crypto.Signature.t(),
  Tezex.Crypto.PublicKey.t(),
  list()
) ::
  boolean()
```

Verifies a message signature based on a public key

Parameters:
- `message` [`t:binary/0`]: message that was signed
- `signature` [`t:Tezex.Crypto.Signature.t/0`]: signature associated with the message
- `public_key` [`t:Tezex.Crypto.PublicKey.t/0`]: public key associated with the message signer
- `options` [`kw list`]: refines request
  - `:hashfunc` [`fun/1`]: hash function applied to the message. Default: `fn msg -> :crypto.hash(:sha256, msg) end`

Returns:
- verified [`t:boolean/0`]: true if message, public key and signature are compatible, false otherwise

---

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