# @spidexjs/metamask-sign-recover-pubkey

> recover public key by metamask signature.

Latest version **0.1.6** (published 2022-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @spidexjs/metamask-sign-recover-pubkey
pnpm add @spidexjs/metamask-sign-recover-pubkey
yarn add @spidexjs/metamask-sign-recover-pubkey
bun add @spidexjs/metamask-sign-recover-pubkey
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2022-10-26 |
| First published | 2022-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 133.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | bitsteven, spidex |

## Links

- npm: https://www.npmjs.com/package/@spidexjs/metamask-sign-recover-pubkey
- Homepage: https://github.com/pngfi/spidexjs
- npm.io page: https://npm.io/package/@spidexjs/metamask-sign-recover-pubkey

## Dependencies (4)

- [@types/node](https://npm.io/package/@types/node.md) ^18.11.5
- [crypto-addr-codec](https://npm.io/package/crypto-addr-codec.md) ^0.1.7
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.6.8
- [@hanchon/signature-to-pubkey](https://npm.io/package/@hanchon/signature-to-pubkey.md) ^1.0.1

## Recent versions

- 0.1.6 (latest) — 2022-10-26
- 0.1.5 — 2022-10-25
- 0.1.4 — 2022-10-25
- 0.1.3 — 2022-10-25

## README

# metamask-sign-recover-pubkey

#### How to recover pubkey by metamask signature, 

### Metamask eth_getEncryptionPublicKey function cannot use 

```ts
ethereum
  .request({
    method: 'eth_getEncryptionPublicKey',
    params: [accounts[0]], // you must have access to the specified account
  })

 ```

### So we need get pubkey from signature

![img_1.png](img_1.png)img_1.png

## example
```ts
import {getPubkey} from "@spidexjs/metamask-sign-recover-pubkey";

const pubkey = await getPubkey(account.address);
console.log(pubkey);
// AiJbGH7xjbW7PoDClLDb3On9YgiWXQMq2cHIA1v4lfPj

```

```ts
  const {ethereum}: any = window;
 
  // message hex
  let message = arrayify(hashMessage('generate_pubkey'));
  let 0xhex = "0x" + ua2hex(message)
  const sign = await ethereum.request({method: "eth_sign", params: [address, 0xhex]});
  const pk = signatureToPubkey(
    sign,
    Buffer.from(message)
  )

  console.log('pubkey:', pk)
  
  //pubkey : AiJbGH7xjbW7PoDClLDb3On9YgiWXQMq2cHIA1v4lfPj
  return pk;

---
_Source: https://npm.io/package/@spidexjs/metamask-sign-recover-pubkey · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
