# ECDSA

In this tutorial, we will learn how to use ECDSA with asymmetric public and private key pairs. Note, this is a low-level tutorial and should only be used if the SDK's higher-level [Message Signing Capabilities](/guides/sdks/ts/examples/example_message_signing.md) do not meet your needs.

## Getting Started

First, you'll need to import the `PrivateKey` function. We'll also import `utils` so we can represent our messages in human-readable formats.

```ts
import { PrivateKey, Utils } from '@bsv/sdk'
```

Now, let's generate a random private key and sign a message with it.

```ts
const privateKey = PrivateKey.fromRandom()
const message = Utils.toArray('Message to sign!')

// The .sign() method creates an ECDSA digital signature for the message from the private key.
const signature = privateKey.sign(message)

// Anyone with the corresponding public key can now verify the message.
const publicKey = privateKey.toPublicKey()

// The .verify() method is used for message verification
const valid = publicKey.verify(message, signature)
// console.log(valid) --> true
```

Anyone who knows the public key can verify the message, even if they don't have the private key. You can sign Bitcoin transactions, documents, or any other type of information with ECDSA. Changing the message will invalidate the signature.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bsvblockchain.org/guides/sdks/ts/low-level/using_ecdsa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
