0.1.13 • Published 1 year ago

@smontero/hashed-private-client-api v0.1.13

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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 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 and Group objects can be accessed.

Document services

  • store: 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: 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: View a stored payload by specifying the cid, returns the deciphered payload(object or File)
const document = await hp.document().viewByCID({cid})
const document = await hp.document().updateMetadata({
    cid,
    name,
    description
  })
  • delete: Delete a document by specifying the cid
await hp.document().delete(cid)

Group services

  • getById: Get the group details by id
let group = await hp.group().getById(groupId)
let groupId = await hp.group().createGroup({name})
  • upsertMember: Insert a group member or update the role for an existing member
await hp.group().upsertMember({
  userAddress,
  groupId,
  roleId
})
await hp.group().deleteMember({
  userAddress,
  groupId
})
0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.0.8

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago