kalp-pkg
v1.0.11
Published
KALP blockchain SDK for cryptographic operations and blockchain interactions
Maintainers
Readme
KALP SDK
A comprehensive TypeScript SDK for interacting with the KALP blockchain network. This package provides cryptographic operations, key management, user registration, and transaction capabilities.
Features
- 🔐 Cryptographic Operations: Generate key pairs, create CSRs, and handle digital signatures
- 🌱 Seed Phrase Support: Generate and derive keys from mnemonic phrases
- 🔗 Multi-Network Support: Support for Stagenet, Testnet, and Mainnet environments
- 📝 Transaction Handling: Submit and evaluate blockchain transactions
- 👤 User Management: Register and enroll users on the KALP network
- 🔒 Encryption Utilities: Built-in text encryption and decryption
- 🌐 Cross-Platform: Works in both browser and Node.js environments
Installation
npm install kalp-sdkQuick Start
import {
getSeedPhrase,
getKeyPair,
getEnrollmentId,
createCsr,
registerAndEnrollUser,
Network
} from 'kalp-sdk';
// Generate a new seed phrase
const seedPhrase = await getSeedPhrase();
console.log('Seed Phrase:', seedPhrase);
// Generate key pair
const keyPair = await getKeyPair();
console.log('Public Key:', keyPair.pemPublicKey);
console.log('Private Key:', keyPair.pemPrivateKey);
// Get enrollment ID
const enrollmentId = await getEnrollmentId(keyPair.pemPublicKey);
console.log('Enrollment ID:', enrollmentId);
// Create CSR
const csr = createCsr(enrollmentId, keyPair.pemPrivateKey, keyPair.pemPublicKey);
// Register and enroll user
const certificate = await registerAndEnrollUser(
Network.Testnet,
null, // Use default network governance URL
null, // Use default channel name
enrollmentId,
csr
);API Reference
Key Generation
getSeedPhrase()
Generates a random mnemonic seed phrase.
const seedPhrase = await getSeedPhrase();getKeyPair()
Generates a new ECDSA key pair.
const { pemPrivateKey, pemPublicKey } = await getKeyPair();getKeyPairFromSeedPhrase(seedPhrase: string)
Derives a key pair from a seed phrase.
const keyPair = await getKeyPairFromSeedPhrase(seedPhrase);User Management
getEnrollmentId(publicKey: string)
Generates an enrollment ID from a public key.
const enrollmentId = await getEnrollmentId(publicKey);createCsr(enrollmentID: string, privateKeyPem: string, publicKeyPem: string)
Creates a Certificate Signing Request (CSR).
const csr = createCsr(enrollmentId, privateKey, publicKey);registerAndEnrollUser(...)
Registers and enrolls a user in one step.
const certificate = await registerAndEnrollUser(
network,
nglURL,
channelName,
enrollmentID,
csr
);Transactions
submitTransaction(...)
Submits a transaction to the blockchain.
const transactionId = await submitTransaction(
network,
gatewayURL,
enrollmentID,
privateKey,
certificate,
channelName,
chaincodeName,
transactionName,
transactionParams
);evaluateTransaction(...)
Evaluates a transaction without committing to the blockchain.
const result = await evaluateTransaction(
network,
gatewayURL,
enrollmentID,
privateKey,
certificate,
channelName,
chaincodeName,
transactionName,
transactionParams
);Encryption
encryptText(text: string)
Encrypts text using AES encryption.
const encrypted = encryptText('Hello World');decryptText(ciphertext: string)
Decrypts AES-encrypted text.
const decrypted = decryptText(encrypted);Networks
The SDK supports multiple network environments:
import { Network } from 'kalp-sdk';
// Available networks
Network.Stagenet // 'STAGENET'
Network.Testnet // 'TESTNET'
Network.Mainnet // 'MAINNET'
Network.IntegrationMainnet // 'INTEGRATIONMAINNET'Error Handling
All functions throw descriptive errors. Wrap calls in try-catch blocks:
try {
const keyPair = await getKeyPair();
// Use keyPair...
} catch (error) {
console.error('Key generation failed:', error.message);
}Environment Compatibility
This SDK works in both browser and Node.js environments:
- Browser: Uses native Web Crypto API
- Node.js: Uses Node.js crypto module with webcrypto polyfill
- TypeScript: Full type definitions included
Dependencies
ethers: Ethereum library for blockchain interactionselliptic: Elliptic curve cryptographyjsrsasign: JavaScript RSA signing and encryptioncrypto-js: Cryptographic functionscross-fetch: Universal fetch for HTTP requests
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and questions, please open an issue on the GitHub repository.
