<p><a href="https://github.com/ChrisCho-H/bitcoin-sdk-js" rel="nofollow noreferrer"><code>bitcoin-sdk-js</code></a> supports signing &amp; verification for p2pkh, p2wpkh and p2tr with an <code>address</code> parameter.</p>
<pre class="lang-javascript prettyprint-override"><code>import * as bitcoin from 'bitcoin-sdk-js'

assert.strictEqual(
  await bitcoin.crypto.verifyMessage(message, signature, address),
  true,
);
</code></pre>
<p>Note that segwit address(p2wpkh, p2tr) should follow <a href="https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki" rel="nofollow noreferrer">BIP322</a> signing schema. However, it's not widely adopted yet, so I'm not sure if the signature generated from UniSat does follow BIP322.</p>
<p>Disclaimer: I'm the owner of the library.</p>

CC BY-SA 4.0
2024-08-06T00:49:45.623Z
2024-08-06T14:28:13.530Z
2024-08-06T14:28:13.530Z
Hyunhum Cho
<p>The example in the documentation of <code>signMessage</code> has a line that shows a <code>verifyMessage</code> function.</p>
<p><a href="https://i.sstatic.net/A2GnfDU8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/A2GnfDU8.png" alt="Example for signMessage that shows a verifyMessage function." /></a></p>
<p>According to the example the parameters appear to be:</p>
<p><code>verifyMessage(pubkey, message, signature)</code></p>
<p>Unfortunately, the function does not appear to be documented in the same GitBook. You could attempt using the function as it is used in the example, and/or try to contact UniSat to request that they document the function.</p>

CC BY-SA 4.0
2024-08-05T13:38:07.290Z
2024-08-05T13:38:07.290Z
Murch
<p>At the frontend, user signs an arbitrary message (e.g., &quot;Sign this message to prove that you own this wallet&quot;). We can do this via, for example, UniSat's <code>signMessage</code> function (see <a href="https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#signmessage" rel="nofollow noreferrer">here</a>).</p>
<p>I want to verify this message at the backend. I want something like this:</p>
<pre class="lang-typescript prettyprint-override"><code>function verifySignature(message: string, address: string, signature: string): boolean
</code></pre>
<p>How to achieve this? Note that it's <code>address</code> instead of <code>publicKey</code> that is in the function parameter list.</p>
<p>I know Bitcoin wallet Apps or browser extensions use ECDSA to sign a message (or more precisely, the SHA256 digest of the message), but the signing processes differ among various types of Bitcoin address (P2PKH, P2SH, P2WPKH, P2WSH, P2TR). So I want some JavaScript/TypeScript packages that can do this robustly instead of implementing on my own.</p>

<signature><ecdsa><javascript><message-signing>
After signing a message, how to verify the signature with JavaScript/TypeScript?
Yan
# After signing a message, how to verify the signature with JavaScript/TypeScript?

(Asked by: username_0 on 2024-08-05)

At the frontend, user signs an arbitrary message (e.g., "Sign this message to prove that you own this wallet"). We can do this via, for example, UniSat's `signMessage` function (see [here](https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet#signmessage)).

I want to verify this message at the backend. I want something like this:

```typescript
function verifySignature(message: string, address: string, signature: string): boolean

```

How to achieve this? Note that it's `address` instead of `publicKey` that is in the function parameter list.

I know Bitcoin wallet Apps or browser extensions use ECDSA to sign a message (or more precisely, the SHA256 digest of the message), but the signing processes differ among various types of Bitcoin address (P2PKH, P2SH, P2WPKH, P2WSH, P2TR). So I want some JavaScript/TypeScript packages that can do this robustly instead of implementing on my own.

**Tags:** signature, ecdsa, javascript, message-signing


---

## 2 answers

### Answer by username_1 on 2024-08-06. Score: 1

[`bitcoin-sdk-js`](https://github.com/ChrisCho-H/bitcoin-sdk-js) supports signing & verification for p2pkh, p2wpkh and p2tr with an `address` parameter.

```javascript
import * as bitcoin from 'bitcoin-sdk-js'

assert.strictEqual(
  await bitcoin.crypto.verifyMessage(message, signature, address),
  true,
);

```

Note that segwit address(p2wpkh, p2tr) should follow [BIP322](https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki) signing schema. However, it's not widely adopted yet, so I'm not sure if the signature generated from UniSat does follow BIP322.

Disclaimer: I'm the owner of the library.


---

### Answer by username_2 on 2024-08-05. Score: 0

The example in the documentation of `signMessage` has a line that shows a `verifyMessage` function.

[![Example for signMessage that shows a verifyMessage function.](https://i.sstatic.net/A2GnfDU8.png)](https://i.sstatic.net/A2GnfDU8.png)

According to the example the parameters appear to be:

`verifyMessage(pubkey, message, signature)`

Unfortunately, the function does not appear to be documented in the same GitBook. You could attempt using the function as it is used in the example, and/or try to contact UniSat to request that they document the function.


---

