# ipfs-cpinner-client-test

> RIF Data Vault - IPFS centralized pinner client

Latest version **0.1.1-beta.11** (published 2021-01-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install ipfs-cpinner-client-test
pnpm add ipfs-cpinner-client-test
yarn add ipfs-cpinner-client-test
bun add ipfs-cpinner-client-test
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1-beta.11 |
| Published | 2021-01-06 |
| First published | 2021-01-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 3.1 MB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | javiesses |
| Keywords | rsk, rif, storage, ipfs |

## Links

- npm: https://www.npmjs.com/package/ipfs-cpinner-client-test
- Repository: https://github.com/rsksmart/rif-data-vault
- Homepage: https://github.com/rsksmart/rif-data-vault#readme
- Issues: https://github.com/rsksmart/rif-data-vault/issues
- npm.io page: https://npm.io/package/ipfs-cpinner-client-test

## Dependencies (4)

- [axios](https://npm.io/package/axios.md) ^0.21.0
- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [did-jwt](https://npm.io/package/did-jwt.md) ^4.6.2
- [eth-sig-util](https://npm.io/package/eth-sig-util.md) ^3.0.0

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.1.1-beta.11 (latest) — 2021-01-06
- 0.1.1-beta.10 — 2021-01-06
- 0.1.1-beta.9 — 2021-01-06
- 0.1.1-beta.8 — 2021-01-06
- 0.1.1-beta.7 — 2021-01-06
- 0.1.1-beta.6 — 2021-01-06

## README

<p align="middle">
    <img src="https://www.rifos.org/assets/img/logo.svg" alt="logo" height="100" >
</p>
<h3 align="middle"><code>@rsksmart/ipfs-cpinner-client</code></h3>
<p align="middle">
    RIF Identity - IPFS Centralized Pinner Client
</p>
<p align="middle">
  <a href="https://rsksmart.github.io/rif-identity-docs/data-vault/cpinner/cpinner-client">
    <img src="https://img.shields.io/badge/-docs-brightgreen" alt="docs" />
  </a>
</p>

A Web Client to simplify the way the services provided by the IPFS Centralized Data Vault Service are consumed.

## Features

- Manage authentication according to the [DID Auth protocol](https://rsksmart.github.io/rif-identity-docs/ssi/libraries/express-did-auth)

- CRUD operations over the RIF Data Vault

- Stores the authentication credentials in the given storage 

- Encrypts/decrypts data prior to save/return using the user wallet provider

## Quick Usage

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const serviceUrl = 'http://your-ipfs-cpinner-service.com'

// the following fields are required just to perform write operations
const serviceDid = 'did:ethr:rsk:0x123456789....abc'
const address = '0xabcdef....123' // user's address
const did = `did:ethr:rsk:${address}`

// these are examples with Metamask
const personalSign = (data: string) => window.ethereum.request({ method: 'personal_sign', params: [address, data] })
const decrypt = (hexCypher: string) => window.ethereum.request({ method: 'eth_decrypt', params: [hexCypher, address] })
const getEncryptionPublicKey = () => window.ethereum.request.request({ method: 'eth_getEncryptionPublicKey', params: [address] })

const client = new DataVaultWebClient({
  serviceUrl,
  authManager: new AuthManager({ did, serviceUrl, personalSign }),
  encryptionManager: new EncryptionManager({ getEncryptionPublicKey, decrypt  })
})
```

> Note: this approach use the browser `localStorage` as the package store. Please refer to the [documentation](https://developers.rsk.co/rif/identity/data-vault/architecture/client/) to check custom storage options.

### Get

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, decrypt, did, rpcPersonalSign })

const key = 'EmailCredential'

const credentials = await client.get({ did, key })
```

### Get keys

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid })

const keys = await client.getKeys()
```

### Get storage information

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid })

const storage = await client.getStorageInformation()

console.log(`Used: ${storage.used}`)
console.log(`Available: ${storage.available}`)
```

### Get backup information

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid })

const backup = await client.getBackup()

console.log('This is the keys and cids you have stored in the DV')
console.log(backup)
```

### Create

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid, getEncryptionPublicKey })

const key = 'MyKey'
const content = 'this is my content'

const id = await client.create({ key, content })
```

### Swap

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid, getEncryptionPublicKey })

const key = 'MyKey'
const content = 'this is my content'

const id = await client.swap({ key, content })
```

### Delete

```typescript
import DataVaultWebClient from '@rsksmart/ipfs-cpinner-client'

const client = new DataVaultWebClient({ serviceUrl, did, rpcPersonalSign, serviceDid })

const key = 'MyKey'

await client.delete({ key })
```

## Advanced usage 

See our [documentation](https://developers.rsk.co/rif/identity/data-vault/architecture/client/)

## Open work

- Encrypt/decrypt content prior to save or after retrieving it from the service

## Test

From base repo directory run `npm test` or any of the described [test script variants](../../README#test).

---
_Source: https://npm.io/package/ipfs-cpinner-client-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
