octopus-ts-sdk
npm install @zhoujun_aptos/octopus-ts-sdkThis TypeScript SDK provides cryptographic operations for the Aptos crypto oracle, including ElGamal encryption over BLS12-381 curves with AES-256-GCM for symmetric encryption.
- 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
``bash`
npm install
`bash`
npm run build
The project includes comprehensive test coverage for all cryptographic operations:
`bashRun tests in watch mode
npm test
$3
The test suite covers:
1. Key Generation
- Valid key pair generation
- Uniqueness of generated keys
- BLS12-381 curve point validation
2. Encryption & Decryption
- Basic encryption/decryption functionality
- Empty and large plaintext handling
- Binary data support
- Unicode text support
- Wrong key rejection
3. Serialization
- Byte array serialization/deserialization
- Hex encoding/decoding
- Key integrity preservation
4. Error Handling
- Corrupted ciphertext handling
- Truncated data handling
- Invalid input validation
5. Cryptographic Properties
- Semantic security verification
- Key privacy validation
- Multiple encryption support
6. Performance & Edge Cases
- Multiple key generation efficiency
- Large data handling
- Boundary condition testing
Usage
`typescript
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 function
- crypto`: Node.js built-in cryptographic functionsThis 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