The Alberti Protocol SDK is a comprehensive toolkit for cryptographic operations, including message encryption, decryption, signing, verification, and identity management. applications.
npm install @albertiprotocol/sdk
-
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);
-
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);
-
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);
-
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');
-
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']);
-
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);
const { generateKeyPair } = require('./alberti-sdk');
const { privateKey, publicKey } = generateKeyPair();
console.log(`Private Key: ${privateKey}`);
console.log(`Public Key: ${publicKey}`);
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}`);
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}`);
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
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.