# 3id-blockchain-utils

> Blockchain utils for 3ID

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

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install 3id-blockchain-utils
pnpm add 3id-blockchain-utils
yarn add 3id-blockchain-utils
bun add 3id-blockchain-utils
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2020-12-16 |
| First published | 2019-11-11 |
| Weekly downloads | 0 |
| License | (Apache-2.0 OR MIT) |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 109.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | oed |
| Maintainers | oed, zachferland, simonovic86, paul_lecam |

## Links

- npm: https://www.npmjs.com/package/3id-blockchain-utils
- npm.io page: https://npm.io/package/3id-blockchain-utils

## Dependencies (9)

- [caip](https://npm.io/package/caip.md) ^0.9.2
- [js-sha256](https://npm.io/package/js-sha256.md) ^0.9.0
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^1.1.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.9.2
- [@ethersproject/wallet](https://npm.io/package/@ethersproject/wallet.md) ^5.0.1
- [@polkadot/util-crypto](https://npm.io/package/@polkadot/util-crypto.md) ^3.6.1
- [@ethersproject/contracts](https://npm.io/package/@ethersproject/contracts.md) ^5.0.1
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.0.4
- [@smontero/eosio-signing-tools](https://npm.io/package/@smontero/eosio-signing-tools.md) 0.0.6

## Recent versions

- 1.3.1 (latest) — 2020-12-16
- 0.2.0-beta.3 (next) — 2019-11-12
- 1.3.0 — 2020-12-16
- 1.2.0 — 2020-12-09
- 1.1.1 — 2020-11-24
- 1.1.0 — 2020-11-18
- 1.0.0 — 2020-08-11
- 0.4.1 — 2020-08-06
- 0.4.0 — 2020-05-30
- 0.3.4 — 2020-05-18
- 0.3.3 — 2020-03-17
- 0.3.2 — 2019-11-26
- 0.3.1 — 2019-11-26
- 0.3.0 — 2019-11-13
- 0.2.1 — 2019-11-12
- … 4 more at https://npm.io/package/3id-blockchain-utils/versions

## README

# 3id-blockchain-utils
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![CircleCI](https://img.shields.io/circleci/project/github/ceramicnetwork/js-3id-blockchain-utils.svg?style=for-the-badge)](https://circleci.com/gh/ceramicnetwork/js-3id-blockchain-utils)
[![npm](https://img.shields.io/npm/dt/3id-blockchain-utils.svg?style=for-the-badge)](https://www.npmjs.com/package/3id-blockchain-utils)
[![npm](https://img.shields.io/npm/v/3id-blockchain-utils.svg?style=for-the-badge)](https://www.npmjs.com/package/3id-blockchain-utils)
[![Codecov](https://img.shields.io/codecov/c/github/ceramicnetwork/js-3id-blockchain-utils.svg?style=for-the-badge)](https://codecov.io/gh/ceramicnetwork/js-3id-blockchain-utils)

This package contains a bunch of utilities that is used by 3ID and 3Box in order to create and verify links from blockchain addresses.

## Tabel of Contents
- [Install](#install)
- [Usage](#usage)
- [Supported blockchains](#supported-blockchains)
- [Contributing](#contributing)
  - [Test](#Test)
- [License](#license)

## Install
```
$ npm install --save 3id-blockchain-utils
```

## Usage
Import the package into your project
```js
import { createLink, validateLink, authenticate } from '3id-blockchain-utils'
```

Use the library to create and verify links:
```js
const did = 'did:3:bafypwg9834gf...'
const proof = await createLink(did, '0x123abc...', ethereumProvider)
console.log(proof)

const verified = await validateLink(proof)
if (verified) {
  console.log('Proof is valid', proof)
} else {
  console.log('Proof is invalid')
}
```

Use the library for 3ID authenticate:

```js
await authenticate(message, '0x123abc...', ethereumProvider)
```

## Supported blockchains

Below you can see a table which lists supported blockchains and their provider objects.

| Blockchain | CAIP-2 namespace | Supported providers             |
|------------|-----------|---------------------------------|
| Ethereum   | [eip155](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-3.md)    | metamask-like ethereum provider |
| Filecoin   | fil       | [Filecoin Wallet Provider](https://github.com/openworklabs/filecoin-wallet-provider) |

## Maintainers
[@oed](https://github.com/oed)

## Adding support for a blockchain
If you want to add support for a new blockchain to 3ID this is the place to do so. This library uses [CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md) to represent accounts in a blockchain agnostic way. If the blockchain you want to add isn't already part of the [CAIP](https://github.com/ChainAgnostic/CAIPs) standards you shold make sure to add it there.

To begin adding support for a given blockchain add a file with the path: `src/blockchains/<blockchain-name>.js`. This module needs to export three functions:

* `createLink` - creates a LinkProof object which associates the specified AccountID with the DID
* `validateLink` - validates the given LinkProof
* `authenticate` - signs a message and returns some entropy based on the signature. Needs to be deterministic

It also needs to export a constant called `namespace`. This constant is a string which contains the [CAIP-2](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md) chainId namespace.

Please see `src/blockchains/ethereum.js` for an example of how this is implemented for the `eip155` (ethereum) CAIP-2 namespace.


Finally add support for your blockchain in `src/index.js`. Simply add it to the `handlers` array.

### Test
Test the code by running:
```
$ npm test
```

## Licence
Apache-2.0 OR MIT

---
_Source: https://npm.io/package/3id-blockchain-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
