npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

walrus-sdk

v1.0.1

Published

## What is Walrus-SDK?

Downloads

151

Readme

Walrus-SDK

What is Walrus-SDK?

Walrus-SDK is a TypeScript-based Software Development Kit (SDK) designed to simplify interaction with the Walrus decentralized storage network. It provides developers with an easy-to-use interface for uploading, retrieving, and managing files within decentralized environments.

By abstracting complex API calls, Walrus-SDK accelerates development, enhances consistency, and promotes the adoption of Walrus decentralized storage solution.


What is Walrus?

Walrus is a decentralized storage and data availability protocol designed for large binary files, or blobs. It offers a robust solution for storing unstructured content across decentralized nodes, ensuring high availability and reliability even in the presence of faults. By integrating with the Sui blockchain, Walrus leverages its composability, expressivity, and security to provide a seamless storage experience.

For more information, visit the Walrus website and consult the Walrus documentation.


Install the SDK

Install using npm:

npm i walrus-sdk

Import the SDK

const StorageSDK = require("walrus-sdk");

Initialize the SDK

const sdk = new StorageSDK({
  publisherUrl: "https://your-custom-publisher-url",
  aggregatorUrl: "https://your-custom-aggregator-url",
});

Both publisherUrl and aggregatorUrl are optional and default to the Walrus testnet URLs.

## Available Functions

storeFile(file: File, epochs: number = 5): Promise<any>

Uploads a file to the Walrus network.

Parameters:

  • file (File): The file to be uploaded.
  • epochs (number): The number of epochs to store the file for. Default is 5.

Returns:

  • A Promise resolving to the upload response.

Example:

const file = new File(["Hello, Walrus!"], "test.txt", { type: "text/plain" });
const response = await sdk.storeFile(file, 10);
console.log(response);

storeFileWithEncryption(file: File, epochs: number = 5, password: string): Promise<any>

Encrypts and uploads a file to the Walrus network.

Parameters:

  • file (File): The file to be encrypted and uploaded.
  • epochs (number): The number of epochs to store the file for. Default is 5.
  • password (string): The password used for encryption.

Returns:

  • A Promise resolving to the upload response.

Example:

const password = "secure-password";
const response = await sdk.storeFileWithEncryption(file, 10, password);
console.log(response);

readFile(blobId: string): Promise<ReadableStream<Uint8Array>>

Retrieves a file from the Walrus network.

Parameters:

  • blobId (string): The ID of the file to retrieve.

Returns:

  • A Promise resolving to a ReadableStream of the file content.

Example:

const blobId = "your-blob-id";
const fileStream = await sdk.readFile(blobId);
console.log(fileStream);

readFileWithDecryption(blobId: string, password: string): Promise<Blob>

Retrieves and decrypts a file from the Walrus network.

Parameters:

  • blobId (string): The ID of the file to retrieve.
  • password (string): The password used for decryption.

Returns:

  • A Promise resolving to a Blob of the decrypted file content.

Example:

const password = "secure-password";
const decryptedBlob = await sdk.readFileWithDecryption(blobId, password);

// Optional: Convert Blob content to string
const text = await decryptedBlob.text();
console.log(text);

Error Handling

All methods throw errors if the operation fails, including:

  • HTTP Errors: Issues with network or server response.
  • Encryption/Decryption Errors: Invalid passwords or corrupted data.

Wrap calls in try...catch to handle errors gracefully:

try {
  const response = await sdk.readFileWithDecryption(blobId, password);
  console.log(response);
} catch (error) {
  console.error("Error:", error.message);
}