@zhoujun_aptos/octopus-ts-sdk
v0.3.0
Published
octopus-ts-sdk
Readme
Octopus TypeScript SDK
This TypeScript SDK provides cryptographic operations for the Aptos crypto oracle, including ElGamal encryption over BLS12-381 curves with AES-256-GCM for symmetric encryption.
Features
- ElGamal Encryption: Public-key encryption over BLS12-381 elliptic curves
- AES-256-GCM: Authenticated symmetric encryption for bulk data
- Hybrid Encryption: Combines asymmetric and symmetric encryption for efficiency
- TypeScript Support: Full TypeScript support with proper type definitions
- Serialization: Support for Aptos Move serialization format
Installation
npm installBuilding
npm run buildTesting
The project includes comprehensive test coverage for all cryptographic operations:
Running Tests
# Run tests in watch mode
npm test
# Run tests once
npm run test:run
# Run tests with coverage
npm run test:coverageTest Coverage
The test suite covers:
Key Generation
- Valid key pair generation
- Uniqueness of generated keys
- BLS12-381 curve point validation
Encryption & Decryption
- Basic encryption/decryption functionality
- Empty and large plaintext handling
- Binary data support
- Unicode text support
- Wrong key rejection
Serialization
- Byte array serialization/deserialization
- Hex encoding/decoding
- Key integrity preservation
Error Handling
- Corrupted ciphertext handling
- Truncated data handling
- Invalid input validation
Cryptographic Properties
- Semantic security verification
- Key privacy validation
- Multiple encryption support
Performance & Edge Cases
- Multiple key generation efficiency
- Large data handling
- Boundary condition testing
Usage
import { keygen, encrypt, tryDecrypt } from './src/elgamal_bls12381_aes256gcm';
// Generate key pair
const { privateKey, publicKey } = keygen();
// Encrypt data
const plaintext = new TextEncoder().encode('Hello, World!');
const ciphertext = encrypt(publicKey, plaintext);
// Decrypt data
const decrypted = tryDecrypt(privateKey, ciphertext);
console.log(new TextDecoder().decode(decrypted)); // "Hello, World!"Dependencies
@aptos-labs/ts-sdk: Aptos TypeScript SDK for serialization@noble/curves: BLS12-381 elliptic curve implementation@noble/hashes: SHA-256 hash functioncrypto: Node.js built-in cryptographic functions
Security
This implementation provides:
- Semantic Security: Same plaintext produces different ciphertexts
- Key Privacy: Ciphertexts don't reveal the public key
- Authenticated Encryption: AES-GCM provides both confidentiality and authenticity
- Post-Quantum Resistance: BLS12-381 curves provide quantum resistance
