🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@cere-ddc-sdk/content-addressable-storage

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cere-ddc-sdk/content-addressable-storage

Content-addressable storage client

latest
Source
npmnpm
Version
1.9.6
Version published
Weekly downloads
103
10200%
Maintainers
1
Weekly downloads
 
Created
Source

@cere-ddc-sdk/content-addressable-storage

Basic package for working with data in DDC.

Support commands:

  • store - store data in DDC
  • storeEncrypted - store encrypted data in DDC
  • read - download piece with data from DDC
  • readDecrypted - download and decrypt piece with data from DDC
  • search - search pieces by tags and download from DDC

Example

Setup

Initialize client by cluster id and secret phrase.

import {ContentAddressableStorage} from '@cere-ddc-sdk/content-addressable-storage';

const signatureAlgorithm = 'ed25519';
const secretPhrase = '0x9gh7...';
const cdnClusterId = 2n;

const storage = await ContentAddressableStorage.build(
    {
        clusterAddress: cdnClusterId,
        scheme: signatureAlgorithm,
    },
    secretPhrase,
);

Store

Store piece with data in DDC.

import {Piece, PieceUri, Tag} from '@cere-ddc-sdk/content-addressable-storage';

const data = new Uint8Array([1, 2, 3, 4]); // data for storing
const bucketId = 1n;
const tags = [new Tag('key', 'test')]; // tag for search
const piece = new Piece(data, tags);

const pieceUri: PieceUri = await storage.store(bucketId, piece);

Store Encrypted

Store encrypted data in DDC.

import {Piece} from '@cere-ddc-sdk/content-addressable-storage';

const data = new Uint8Array([1, 2, 3, 4]); // data for storing
const bucketId = 1n;
const tags = [new Tag('key', 'test')]; // tag for search
const piece = new Piece(data, tags);

const encryptionOptions = {dekPath: '/data/secret', dek: dekBytes};

const pieceUri = await storage.storeEncrypted(bucketId, piece, encryptionOptions);

Read

Download piece from DDC.

import {Piece} from '@cere-ddc-sdk/content-addressable-storage';

const bucketId = 1n;
const cid = 'b89mndf...'; // CID can get from pieceUri (pieceUri.cid)

const piece: Piece = await storage.read(bucketId, cid);

Read Decrypted

Read and decrypt piece from DDC.

import {Piece} from '@cere-ddc-sdk/content-addressable-storage';

const bucketId = 1n;
const cid = 'b89mndf...'; // CID can get from pieceUri (pieceUri.cid)

const piece: Piece = await storage.readDecrypted(bucketId, cid, dekBytes);

Search data

Search by tags pieces and download.

import {Piece, Query, SearchResult, Tag} from '@cere-ddc-sdk/content-addressable-storage';

const bucketId = 1n;
const tags = [new Tag('key', 'test')];
const skipData = false; // download pieces with data or metadata only
const query = new Query(bucketId, tags, skipData);

const searchResult: SearchResult = await storage.search(query);
const pieces: Array<Piece> = searchResult.pieces;

FAQs

Package last updated on 14 Nov 2023

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