0.1.3 • Published 3 years ago

@rsksmart/ipfs-cpinner-client v0.1.3

Weekly downloads
46
License
MIT
Repository
github
Last release
3 years ago

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

  • CRUD operations over the RIF Data Vault

  • Stores the authentication credentials in the given storage

  • Encrypts content using the user wallet prior to save it in the service - if getEncryptionPublicKey function provided

  • If retrieving an encrypted content, it decrypts it in the user wallet prior to return it - if proper decrypt function provided

Quick Usage

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: [data, address] })
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 to check custom storage options.

Get

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

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

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

const keys = await client.getKeys()

Get storage information

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

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

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

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

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

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.

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.1-beta.13

3 years ago

0.1.1-beta.12

3 years ago

0.1.1-beta.10

3 years ago

0.1.1-beta.11

3 years ago

0.1.1-beta.9

3 years ago

0.1.1-beta.8

3 years ago

0.1.1-beta.7

3 years ago

0.1.1-beta.6

3 years ago

0.1.1-beta.5

3 years ago

0.1.1-beta.4

3 years ago

0.1.1-beta.3

3 years ago

0.1.1-beta.2

3 years ago

0.1.1-beta.1

3 years ago