> For the complete documentation index, see [llms.txt](https://hub.bsvblockchain.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hub.bsvblockchain.org/bsv-skills-center/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](https://hub.bsvblockchain.org/bsv-skills-center/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hub.bsvblockchain.org/bsv-skills-center/guides/sdks/ts/low-level/using_ecdsa.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
