NOVA SDK for JavaScript

A JavaScript/TypeScript SDK for interacting with the NOVA secure file-sharing on the NEAR blockchain. Provides encrypted, decentralized file storage using IPFS and NEAR smart contracts with group-based access control.

Features

  • πŸ” AES-256-CBC Encryption - Client-side encryption for data privacy

  • 🌐 IPFS Storage - Decentralized file storage via Pinata

  • ⛓️ NEAR Blockchain - Immutable transaction records and access control

  • πŸ‘₯ Group Management - Fine-grained access control with member authorization

  • πŸ”‘ Key Rotation - Automatic key rotation on member revocation

  • πŸš€ Composite Operations - Simplified high-level workflows

  • πŸ“¦ TypeScript Support - Full type definitions included

Installation

npm install nova-sdk-js

Quick Start

import { NovaSdk } from 'nova-sdk-js';

async function main() {
  // Initialize SDK
  const sdk = new NovaSdk(
    'https://rpc.testnet.near.org',
    'nova-contract.testnet',
    'your_pinata_api_key',
    'your_pinata_secret_key'
  );

  // Attach signer
  await sdk.withSigner(
    'ed25519:your_private_key',
    'your-account.testnet'
  );

  // Upload encrypted file
  const data = Buffer.from('Confidential data');
  const result = await sdk.compositeUpload(
    'project_alpha',      // group_id
    'alice.testnet',      // user_id
    data,                 // data buffer
    'report.txt'          // filename
  );

  console.log('βœ… Uploaded to IPFS:', result.cid);
  console.log('πŸ“ Transaction ID:', result.trans_id);
  console.log('πŸ”’ File Hash:', result.file_hash);

  // Retrieve and decrypt file
  const retrieved = await sdk.compositeRetrieve(
    'project_alpha',
    result.cid
  );

  const content = retrieved.data.toString('utf8');
  console.log('πŸ“„ Content:', content);
}

main().catch(console.error);

Core Concepts

Groups

Groups provide isolated access control domains. Each group has:

  • A unique identifier (group_id)

  • An owner who manages membership

  • A shared encryption key

  • A list of authorized members

Access Control

Encryption

All data is encrypted client-side using AES-256-CBC:

  • 256-bit symmetric keys

  • Random IV per encryption

  • PKCS7 padding

  • Keys stored encrypted on blockchain

Transaction Recording

Every file operation creates an immutable blockchain record:

API Overview

Initialization

Group Management

Key Management

File Operations

Utilities

Types

Environment Setup

For testing and development, set these environment variables:

Create a .env file:

Testing

Error Handling

The SDK uses a custom NovaError class:

Security Considerations

⚠️ Important Security Notes:

  1. Private Keys - Never commit private keys to version control

  2. Key Storage - Store encryption keys securely

  3. IPFS Privacy - IPFS content is public; encryption is essential

  4. Access Control - Verify user authorization before operations

  5. Key Rotation - Revoked members cannot decrypt new content

  6. Buffer Handling - Use Buffer for binary data to avoid encoding issues

NEAR Token Deposits

Some operations require NEAR token deposits:

  • registerGroup() - 0.1 NEAR

  • addGroupMember() - 0.0005 NEAR

  • revokeGroupMember() - 0.0005 NEAR

  • storeGroupKey() - 0.0005 NEAR

  • recordTransaction() - 0.002 NEAR

Ensure your account has sufficient balance before calling these methods.

Examples

Basic File Upload

Group Management

Transaction History

Building from Source

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Add tests for new functionality

  4. Ensure all tests pass (npm test)

  5. Submit a pull request

License

This project is licensed under the MIT License - see LICENSE file for details.

Resources

Support

Last updated