New:Microsoft Teams Notifications Are Now Available in Socket.Learn more
Get Started

@albertiprotocol/sdk

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@albertiprotocol/sdk

@albertiprotocol/sdk

unpublished
latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
0
Created
Source

Alberti Protocol SDK

The Alberti Protocol SDK is a comprehensive toolkit for cryptographic operations, including message encryption, decryption, signing, verification, and identity management. applications.

Installation

npm install @albertiprotocol/sdk

Function Overview

Key Management

  • generateKeyPair()

    • Generates a new key pair (private and public key).
    • Example usage:
      const { privateKey, publicKey } = generateKeyPair();
      
  • privateKeyToPublicKey(privateKey)

    • Converts a given private key to its corresponding public key.
    • Example usage:
      const publicKey = privateKeyToPublicKey(privateKey);
      

Message Signing and Verification

  • signMessage(privateKeyHex, message)

    • Signs a message using the provided private key.
    • Example usage:
      const signature = signMessage(privateKey, 'Hello, world!');
      
  • verifySignature(publicKeyHex, message, signatureHex)

    • Verifies a message against a signature using the provided public key.
    • Example usage:
      const isValid = verifySignature(publicKey, 'Hello, world!', signature);
      

Message Encryption and Decryption

  • encryptMessageWithPublicKey(message, recipientPublicKey)

    • Encrypts a message using the recipient's public key.
    • Example usage:
      const encryptedMessage = encryptMessageWithPublicKey('Hello, World!', publicKey);
      
  • decryptMessageWithPrivateKey(encryptedMessage, recipientPrivateKey)

    • Decrypts an encrypted message using the recipient's private key.
    • Example usage:
      const decryptedMessage = decryptMessageWithPrivateKey(encryptedMessage, privateKey);
      

Hashing and Difficulty Verification

  • hashMessage(message)

    • Generates a SHA-256 hash of the given message.
    • Example usage:
      const messageHash = hashMessage('Hello, world!');
      
  • difficultyverify(difficulty, hash)

    • Verifies that a given hash meets the specified difficulty criteria.
    • Example usage:
      const isValid = difficultyverify(4, '0000abcdef');
      

Template Functions

  • postTemplate(content, hashtags = [], attachments = [], parentID = null)

    • Creates a template for a post with specified content, hashtags, attachments, and optional parent ID.
    • Example usage:
      const post = postTemplate('This is a test post.', ['test', 'post'], [{ type: 'image', url: 'http://example.com/image.png' }]);
      
  • metaTemplate(name, about, image, website, followed = [], hashtags = [])

    • Creates a template for metadata with specified details such as name, about, image, website, followed users, and hashtags.
    • Example usage:
      const meta = metaTemplate('Test User', 'This is a test user.', 'http://example.com/image.png', 'http://example.com', ['user1', 'user2'], ['test', 'user']);
      

Data Commit Creation and Verification

  • createCommit(privateKey, data, type, difficulty = 3)

    • Generates a commit object by signing a data payload and ensuring it meets the specified difficulty criteria.
    • Example usage:
      const commit = createCommit(privateKey, postData, 'post', 4);
      
  • verifyCommit(commit, difficulty = 3)

    • Validates the structure, signature, and difficulty of a commit object.
    • Example usage:
      const isValid = verifyCommit(commit, 4);
      

Example Usage

Generate a Key Pair

const { generateKeyPair } = require('./alberti-sdk');
const { privateKey, publicKey } = generateKeyPair();
console.log(`Private Key: ${privateKey}`);
console.log(`Public Key: ${publicKey}`);

Encrypt and Decrypt a Message

const { encryptMessageWithPublicKey, decryptMessageWithPrivateKey } = require('./alberti-sdk');

// Encrypt message
const encryptedMessage = encryptMessageWithPublicKey('Hello, World!', publicKey);
console.log(`Encrypted Message: ${encryptedMessage.ciphertext}`);

// Decrypt message
const decryptedMessage = decryptMessageWithPrivateKey(encryptedMessage, privateKey);
console.log(`Decrypted Message: ${decryptedMessage}`);

Create and Verify a Commit

const { createCommit, verifyCommit, postTemplate } = require('./alberti-sdk');

// Define post data
const postData = postTemplate('Hello, world!', [], []);

// Create commit
const commit = createCommit(privateKey, postData, 'post', 4);

// Verify commit
const isValid = verifyCommit(commit, 4);
console.log(`Is the commit valid? ${isValid}`);

Running Tests

To ensure all functionalities are working correctly, we have a set of tests. Run these tests using the following command:

node test.js

The tests include:

  • Key generation and verification
  • Message signing and signature verification
  • Difficulty verification
  • Message hashing
  • Message encryption and decryption
  • Template creation (post and meta)
  • Commit creation and verification

Contributing

We welcome contributions from the community. If you have any suggestions, bug reports, or improvements, please feel free to submit a pull request or open an issue.

Join us in building a more secure and private internet with Alberti, redefining privacy and security in the digital age.

FAQs

Package last updated on 06 Jul 2024

Related posts