# key-did-provider-secp256k1-with-lit

> secp256k1 key did provider

Latest version **0.1.2** (published 2022-11-04) · (Apache-2.0 OR MIT) license · 0 weekly downloads

## Install

```sh
npm install key-did-provider-secp256k1-with-lit
pnpm add key-did-provider-secp256k1-with-lit
yarn add key-did-provider-secp256k1-with-lit
bun add key-did-provider-secp256k1-with-lit
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2022-11-04 |
| First published | 2022-07-01 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14.14 |
| Dependencies | 11 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Anson |
| Maintainers | glitch003, websaam |

## Links

- npm: https://www.npmjs.com/package/key-did-provider-secp256k1-with-lit
- Repository: https://github.com/LIT-Protocol/key-did-provider-secp256k1
- Issues: https://github.com/LIT-Protocol/key-did-provider-secp256k1/issues
- npm.io page: https://npm.io/package/key-did-provider-secp256k1-with-lit

## Dependencies (11)

- [dids](https://npm.io/package/dids.md) ^3.0.0
- [watch](https://npm.io/package/watch.md) ^1.0.2
- [global](https://npm.io/package/global.md) ^4.4.0
- [did-jwt](https://npm.io/package/did-jwt.md) ^6.0.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.4
- [rpc-utils](https://npm.io/package/rpc-utils.md) ^0.6.2
- [lit-js-sdk](https://npm.io/package/lit-js-sdk.md) ^1.2.22
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [canonicalize](https://npm.io/package/canonicalize.md) ^1.0.8
- [@types/elliptic](https://npm.io/package/@types/elliptic.md) ^6.4.14
- [fast-json-stable-stringify](https://npm.io/package/fast-json-stable-stringify.md) ^2.1.0

## Recent versions

- 0.1.2 (latest) — 2022-11-04
- 0.1.0 — 2022-08-23
- 0.0.9 — 2022-08-16
- 0.0.8 — 2022-07-12
- 0.0.7 — 2022-07-09
- 0.0.6 — 2022-07-09
- 0.0.5 — 2022-07-09
- 0.0.4 — 2022-07-01
- 0.0.3 — 2022-07-01

## README

# secp256k1 key did provider with Lit Actions x PKP powered by Lit Protocol

This is a `DID` provider which integrated Lit Actions x PKP powered by Lit Protocol for `did:key` using `secp256k1`. It does not support encryption / JWE. It's a fork from [symfoni/key-did-provider-secp256k1](https://github.com/symfoni/key-did-provider-secp256k1) and was designed to be used with [Ceramic Network](https://ceramic.network/).

## What it does?

- Instead of manually providing a `PUBLIC_KEY` to get the `DID` (decentralised identifier), this SDK gets the `PUBLIC_KEY` from the `PKP` NFT

- The `DID` that we got is then passed into a resolver, which would allow us to run methods such as `did.authenticate()`.

- To authenticate, instead of providing a `PRIVATE_KEY` to sign a message to verify the signature from the signed message matches the corresponding `PUBLIC_KEY`, we will ask the Lit nodes, who hold the `PRIVATE_KEY` collectively of the `PKP` NFT, to execute some static Javascript code that is hosted on IPFS and use the output signature to verify.

- So now that `PKP` NFT owns the decentralised identifier `DID`, we can use this `DID` in Ceramic to read & write stream that only this `PKP` NFT owner can do.

## Installation

```
yarn add key-did-provider-secp256k1-with-lit
```

## Usage

```js
import {
  encodeDIDWithLit,
  Secp256k1ProviderWithLit,
} from "key-did-provider-secp256k1-with-lit";

import { CeramicClient } from "@ceramicnetwork/http-client";
import { TileDocument } from "@ceramicnetwork/stream-tile";
import { getResolver } from "key-did-resolver";
import { DID } from "dids";

const ceramic = new CeramicClient("https://ceramic-clay.3boxlabs.com");

const PKP_PUBLIC_KEY = "30eceb963993d467ca197f3fd9fe3073b8b224ac2c9068d9a9caafcd5e20cf983";

// -- get your encode did with your PKP public key
const encodedDID = await encodeDIDWithLit(PKP_PUBLIC_KEY);

// -- static lit action code hosted on https://ipfs.io/ipfs/QmYrfiMf6TDuU3NiTbZANiELNBCyn2f66Zok3gEuzRTYmL
const provider = new Secp256k1ProviderWithLit({
  did: encodedDID,
  ipfsId: "QmYrfiMf6TDuU3NiTbZANiELNBCyn2f66Zok3gEuzRTYmL",
});

const did = new DID({ provider, resolver: getResolver() });

// -- authenticate
await did.authenticate();
ceramic.did = did;
console.log("DID:", did);

// -- write to ceramic stream
const doc = await TileDocument.create(ceramic, "Hola hola ¿Cómo estás?");
console.log("Doc/StreamID:", doc.id.toString());

// -- read a ceramic stream
var loadDoc = await TileDocument.load(ceramic, doc.id.toString());
console.log("Specific doc:", loadDoc.content);
```

<!-- ### To upload a new Lit Action code on IPFS

```js
const code = `
    const go = async () => {
        const sigShare = await LitActions.signEcdsa({ toSign, keyId, sigName });
    };
    go();
`;

const ipfsData  = await uploadToIPFS(code);

console("ipfsData:", ipfsData);
``` -->

## License

Apache-2.0 OR MIT

---
_Source: https://npm.io/package/key-did-provider-secp256k1-with-lit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
