New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rsksmart/ipfs-cpinner-provider

Package Overview
Dependencies
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rsksmart/ipfs-cpinner-provider

RIF Identity - IPFS Centralized Pinner Provider

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

logo

@rsksmart/ipfs-cpinner-provider

RIF Identity - IPFS Centralized Pinner Provider

docs npm

npm i @rsksmart/ipfs-cpinner-provider

A Centralized Data Vault provider compatible with RIF Data Vault standard interface. It stores content in an IPFS node associated to a given DID and key.

It is strongly recommend to encrypt the content saved in IPFS using this package.

Features

  • Stores, retrieve, deletes and swaps content from/in an IPFS node
  • Associates did -> key -> cid in a SQLite local DB so it is not needed to remember the added cid
  • Pins and unpins cids in the given IPFS node

Usage

The IPFS Centralized pinner provider was designed to use in Centralized pinner service but can be used as standalone

Set up IPFS

First of all you need to have access to an IPFS node API. To run it locally:

  1. Install IPFS CLI. Find your option: https://docs.ipfs.io/how-to/command-line-quick-start/.

  2. Init IPFS (once)

ipfs init
  1. Start IPFS Daemon
ipfs daemon

This will expose the IPFS API in http://localhost:5001

Basic instance

Plug and play configuration

import { ipfsPinnerProviderFactory } from '@rsksmart/ipfs-cpinner-provider'

const ipfsApi = 'http://localhost:5001'
const database = 'my-ipfs-pinner-provider.sqlite'

const ipfsPinnerProvider = await ipfsPinnerProviderFactory(ipfsApi, database)
// NOTE: ipfsApi and database are optional params. Defaults are: 'http://localhost:5001' and 'ipfsPinnerProvider.sqlite'

Advanced instance

This allows to configure the ipfs-http-client and set the DB connection with the desired configuration

import { createConnection } from 'typeorm'
import IpfsHttpClient from 'ipfs-http-client'
import IpfsPinnerProvider, { IpfsClient, IpfsPinner, MetadataManager, Entities, IpfsMetadata, IpfsPinnedCid } from '@rsksmart/ipfs-cpinner-provider'

// ipfs config
const ipfsConfig = { ...yourConfig, url: 'http://localhost:5001' } // refer to https://www.npmjs.com/package/ipfs-http-client
const ipfsHttpClient = IpfsHttpClient(ipfsConfig) 

// db config
const database = 'my-ipfs-pinner-database.sqlite'
const dbConnection = await createConnection({
  type: 'sqlite',
  database,
  entities: Entities,
  logging: false,
  dropSchema: true,
  synchronize: true
})

const pinnedCidsRepository = dbConnection.getRepository(IpfsPinnedCid)
const metadataRepository = dbConnection.getRepository(IpfsMetadata)

// set dependencies to inject
const ipfsClient = new IpfsClient(ipfsHttpClient)
const ipfsPinner = new IpfsPinner(ipfsHttpClient, pinnedCidsRepository)
const metadataManager = new MetadataManager(metadataRepository)

const IpfsPinnerProvider = new IpfsPinnerProvider(ipfsClient, metadataManager, ipfsPinner)

Usage

const did = 'did:ethr:rsk:12345678'
const key = 'the key'
const content = 'the content'

const cid: string = await ipfsPinnerProvider.put(did, key, content)

const cids: string[] = await ipfsPinnerProvider.get(did, key)

const newCid: string = await ipfsPinnerProvider.swap(did, key, 'the new content')

const anotherCid: string = await ipfsPinnerProvider.swap(did, key, 'the new content', newCid) // cid can be specified if there is more than one content associated to the given did and key

const deleted: boolean = await ipfsPinnerProvider.delete(did, key)

const deleted: boolean = await ipfsPinnerProvider.delete(did, key, cid) // cid can be specified if there is more than one content associated to the given did and key

Test

From base repo directory run npm test or any of the described test script variants.

Keywords

FAQs

Package last updated on 30 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc