# @vessel-kit/identity

> Identity layer for VesselKit

Latest version **1.1.0** (published 2020-12-10) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install @vessel-kit/identity
pnpm add @vessel-kit/identity
yarn add @vessel-kit/identity
bun add @vessel-kit/identity
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-12-10 |
| First published | 2020-09-30 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 23 |
| Unpacked size | 287.5 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Sergey Ukustov |
| Maintainers | ukstv |

## Links

- npm: https://www.npmjs.com/package/@vessel-kit/identity
- Repository: https://github.com/vessel-kit/vessel-kit
- Homepage: https://github.com/vessel-kit/vessel-kit/tree/master/libs/identity
- Issues: https://github.com/vessel-kit/vessel-kit/issues
- npm.io page: https://npm.io/package/@vessel-kit/identity

## Dependencies (23)

- [cids](https://npm.io/package/cids.md) ^1.0.1
- [dids](https://npm.io/package/dids.md) ^1.1.0
- [bn.js](https://npm.io/package/bn.js.md) ^4.4.0
- [fp-ts](https://npm.io/package/fp-ts.md) ^2.8.2
- [io-ts](https://npm.io/package/io-ts.md) ^2.2.10
- [tslib](https://npm.io/package/tslib.md) ^2.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [dag-jose](https://npm.io/package/dag-jose.md) ^0.3.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.3
- [multicodec](https://npm.io/package/multicodec.md) ^2.0.1
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^1.1.0
- [did-resolver](https://npm.io/package/did-resolver.md) ^2.1.1
- [multiformats](https://npm.io/package/multiformats.md) ^4.4.0
- [query-string](https://npm.io/package/query-string.md) ^6.13.2
- [identity-wallet](https://npm.io/package/identity-wallet.md) ^2.0.0-alpha.20
- [3id-did-provider](https://npm.io/package/3id-did-provider.md) ^0.1.2
- [@stablelib/bytes](https://npm.io/package/@stablelib/bytes.md) ^1.0.0
- [@stablelib/sha256](https://npm.io/package/@stablelib/sha256.md) ^1.0.0
- [@vessel-kit/codec](https://npm.io/package/@vessel-kit/codec.md) 1.0.0
- [@stablelib/ed25519](https://npm.io/package/@stablelib/ed25519.md) ^1.0.1
- [fast-json-stable-stringify](https://npm.io/package/fast-json-stable-stringify.md) ^2.1.0
- [@ceramicnetwork/http-client](https://npm.io/package/@ceramicnetwork/http-client.md) ^0.8.7
- [@ceramicnetwork/3id-did-resolver](https://npm.io/package/@ceramicnetwork/3id-did-resolver.md) ^0.5.4

## Recent versions

- 1.1.0 (latest) — 2020-12-10
- 1.0.5 — 2020-11-20
- 1.0.4 — 2020-11-20
- 1.0.3 — 2020-11-16
- 1.0.2 — 2020-11-16
- 1.0.1 — 2020-10-02
- 1.0.0 — 2020-09-30

## README

# VesselKit / Identity

Identity layer for VesselKit.

[DID](https://w3c.github.io/did-core/) provides (amongst others) a way to link private
keys to a self-sovereign identifier. The package provides an opinionated programming model to abstract
over various DID methods to create and verify signatures,
starting with [did:key](https://w3c-ccg.github.io/did-method-key/) method as the most straightforward one.

## Background

VesselKit requires records to be signed. Instead of relying on private keys directly, we employ notion of DID
that abstracts over private keys in a meaningful and interoperable way. This package provides a programming model
for DID-related cryptography functions such as signing. [did:key](https://w3c-ccg.github.io/did-method-key/) is
the most minimal version of these functions.

For _did:key_ a subject is assumed to own a private key. The private key is deterministically
mapped to a DID Document, DID identifier, and has a proper DID URL to identify the public key as key id.
Then, it is possible to put the key id in a JWS, creating a minimal DID signature verification process.

## Install

Using [pnpm](https://pnpm.js.org):

```
pnpm add @vessel-kit/identity
```

Using [yarn](https://yarnpkg.com):

```
yarn add @vessel-kit/identity
```

Using [yarn](https://yarnpkg.com):

```
npm add @vessel-kit/identity
```

## Usage

Mainly the package is concerned with signatures in [JWS](https://tools.ietf.org/html/rfc7515) format.
The full lifecycle is (1) create a signature that is sign a payload, (2) verify the signature against public key.
To sign a payload one would have to own a private key. For managed private key see `IPrivateKey` and `PrivateKeyFactory`.

We assume the private key is a part of DID. JWS contains its key identifier as `kid` header.
This `kid` is a DID URL.

Signature verification happens against _DID_, not individual public key. DID Resolver resolves public key by DID URL in `kid`.

```ts
import { PrivateKeyFactory, AlgorithmKind, KeyMethod, jws } from '@vessel-kit/identity';
import { Resolver } from 'did-resolver';

// Get private key somehow. Here it is a managed instance.
const privateKeyFactory = new PrivateKeyFactory();
const privateKey = privateKeyFactory.fromSeed(AlgorithmKind.ES256K, 'seed');
// SignerIdentified can communicate `kid` according to did:key method.
const signer = await KeyMethod.SignerIdentified.fromPrivateKey(privateKey);
// Create signature as JWS compact serialization
const signature = await jws.create(signer, { hello: 'world' });
// Prepare resolver to discover public key identified by `kid`
const resolver = new Resolver({
  ...KeyMethod.getResolver(),
});
// Verify
const isVerified = await jws.verify(signature, resolver); // Expect true.
```

## License

[MIT](https://opensource.org/licenses/MIT) or [Apache-2.0](https://opensource.org/licenses/Apache-2.0).

---
_Source: https://npm.io/package/@vessel-kit/identity · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
