> For the complete documentation index, see [llms.txt](https://docs.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bsvblockchain.org/guides/sdks/ts/low-level/using_ecdsa.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
