# @smontero/hashed-private-client-api

> Client API for interacting with the hashed private server

Latest version **0.1.13** (published 2022-11-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install @smontero/hashed-private-client-api
pnpm add @smontero/hashed-private-client-api
yarn add @smontero/hashed-private-client-api
bun add @smontero/hashed-private-client-api
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2022-11-11 |
| First published | 2022-06-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 47.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | smontero |

## Links

- npm: https://www.npmjs.com/package/@smontero/hashed-private-client-api
- npm.io page: https://npm.io/package/@smontero/hashed-private-client-api

## Dependencies (10)

- [it-all](https://npm.io/package/it-all.md) ^1.0.6
- [sha.js](https://npm.io/package/sha.js.md) ^2.4.11
- [graphql](https://npm.io/package/graphql.md) ^16.5.0
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.35
- [await-sleep](https://npm.io/package/await-sleep.md) ^0.0.1
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [@apollo/client](https://npm.io/package/@apollo/client.md) ^3.6.8
- [ipfs-http-client](https://npm.io/package/ipfs-http-client.md) ^55.0.0
- [@smontero/hashed-crypto](https://npm.io/package/@smontero/hashed-crypto.md) ^0.0.8

## Recent versions

- 0.1.13 (latest) — 2022-11-11
- 0.1.12 — 2022-11-11
- 0.1.11 — 2022-11-04
- 0.1.10 — 2022-11-04
- 0.1.9 — 2022-11-04
- 0.1.8 — 2022-11-04
- 0.1.7 — 2022-11-04
- 0.1.6 — 2022-11-04
- 0.1.5 — 2022-11-03
- 0.1.4 — 2022-11-03
- 0.1.3 — 2022-11-02
- 0.1.2 — 2022-11-01
- 0.1.1 — 2022-10-21
- 0.0.8 — 2022-10-20
- 0.0.7 — 2022-08-11
- … 5 more at https://npm.io/package/@smontero/hashed-private-client-api/versions

## README

**Hashed Private Client API**

Enables the usage of the Hashed Private backend services by client applications.

To install the hashed private client api run the following command:

`npm i --save @smontero/hashed-private-client-api`

Access to most of the functionality is done through the HashedPrivate object which enables its configuration and provides access to the different API objects:

`import { HashedPrivate } from '@smontero/hashed-private-client-api'`



A new instance of the [HashedPrivate](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/HashedPrivate.js#L20) class has to be created passing in the 
ipfs url, hashed private server endpoint and the sigining function:

```
const hp = new HashedPrivate({
    ipfsURL: 'https://ipfs.infura.io:5001',
    privateURI: 'http://localhost:8080/v1/graphql',
    signFn: async (address, message) => {
      const { signature } = await nbvStorageApi.signMessage(message, address)
      return signature
    }
})
```

Then the user has to be logged in into the hashed private server:

`await hp.login(address)`

Once logged in the services provided by the [Document](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L83) and [Group](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Group.js#L67) objects can be accessed.  

**Document services**

* [store](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L230): Store a personal private document in the hashed private service

```
const document = await hp.document().store({
    name: 'name1',
    description: 'desc1',
    payload: {
      prop1: 1,
      prop2: 'str1'
    }
  })
```
This method receives an optional actorId parameter that can be used to store a document on behalf of a group

* [share](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L281): Share a private document with another user or group

```
const document = await hp.document().share({
    toActorAddress: '5CBLWNtpdafzuUsq7P5Hn4amrBAd66R183FmHkEC7utB28ni'
    name: 'name1',
    description: 'desc1',
    payload: {
      prop1: 1,
      prop2: 'str1'
    }
  })
```
This method receives an optional actorId parameter that can be used to store a document on behalf of a group


* [viewByCID](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L343): View a stored payload by specifying the cid, returns the deciphered payload(object or File)

```
const document = await hp.document().viewByCID({cid})
```

* [updateMetadata](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L186): Update the metadata for a document

```
const document = await hp.document().updateMetadata({
    cid,
    name,
    description
  })
```

* [delete](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Document.js#L166): Delete a document by specifying the cid

```
await hp.document().delete(cid)
```

**Group services**

* [getById](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Group.js#L143): Get the group details by id

```
let group = await hp.group().getById(groupId)
```

* [createGroup](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Group.js#L157): Create a group

```
let groupId = await hp.group().createGroup({name})
```

* [upsertMember](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Group.js#L188): Insert a group member or update the role for an existing member 

```
await hp.group().upsertMember({
  userAddress,
  groupId,
  roleId
})
```

* [deleteMember](https://github.com/hashed-io/hashed-private-client-api/blob/19bca988d6367649ef701a8107984db125af7bf4/src/model/Group.js#L225): Delete a group member 

```
await hp.group().deleteMember({
  userAddress,
  groupId
})
```

---
_Source: https://npm.io/package/@smontero/hashed-private-client-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
