paywize-merchant-sdk
v1.0.0
Published
PayWize SDK for merchant data encryption and decryption
Downloads
6
Maintainers
Readme
PayWize SDK
Official PayWize SDK for merchant data encryption and decryption using AES-256-CBC algorithm.
Installation
npm install paywize-merchant-sdkFeatures
- AES-256-CBC encryption and decryption
- TypeScript support with full type definitions
- Both class-based and functional API
- Comprehensive error handling
- Zero dependencies (uses Node.js built-in crypto module)
Usage
Class-Based API (Recommended)
Initialize the SDK once and reuse the instance:
import { PayWizeSDK } from 'paywize-merchant-sdk';
// Initialize SDK with your credentials
const sdk = new PayWizeSDK({
key: 'your-32-character-encryption-key',
iv: 'your-16-char-iv'
});
// Encrypt data
const encryptionResult = sdk.encrypt('Hello World');
if (encryptionResult.success) {
console.log('Encrypted:', encryptionResult.data);
} else {
console.error('Encryption failed:', encryptionResult.error);
}
// Decrypt data
const decryptionResult = sdk.decrypt(encryptionResult.data!);
if (decryptionResult.success) {
console.log('Decrypted:', decryptionResult.data);
} else {
console.error('Decryption failed:', decryptionResult.error);
}
// Update credentials if needed
sdk.updateCredentials({
key: 'new-32-character-encryption-key',
iv: 'new-16-char-iv'
});Functional API
For one-off encryption/decryption operations:
import { encryptData, decryptData } from 'paywize-merchant-sdk';
const key = 'your-32-character-encryption-key';
const iv = 'your-16-char-iv';
try {
// Encrypt
const encrypted = encryptData('Hello World', key, iv);
console.log('Encrypted:', encrypted);
// Decrypt
const decrypted = decryptData(encrypted, key, iv);
console.log('Decrypted:', decrypted);
} catch (error) {
console.error('Error:', error.message);
}JavaScript (CommonJS)
const { PayWizeSDK, encryptData, decryptData } = require('paywize-merchant-sdk');
// Class-based API
const sdk = new PayWizeSDK({
key: 'your-32-character-encryption-key',
iv: 'your-16-char-iv'
});
const result = sdk.encrypt('Hello World');
console.log(result);
// Functional API
const encrypted = encryptData('Hello World',
'your-32-character-encryption-key',
'your-16-char-iv'
);
console.log(encrypted);API Reference
Class: PayWizeSDK
Constructor
constructor(config: EncryptionConfig)Initialize the SDK with encryption credentials.
Parameters:
config.key(string): Encryption key (minimum 32 characters)config.iv(string): Initialization vector (minimum 16 characters)
Throws:
- Error if key or iv is missing or too short
Methods
encrypt(data: string): EncryptionResult
Encrypts the provided data.
Parameters:
data(string): Plain text data to encrypt
Returns:
{
success: boolean;
data?: string; // Base64 encoded encrypted data
error?: string; // Error message if failed
}decrypt(encryptedData: string): DecryptionResult
Decrypts the provided encrypted data.
Parameters:
encryptedData(string): Base64 encoded encrypted data
Returns:
{
success: boolean;
data?: string; // Decrypted plain text
error?: string; // Error message if failed
}updateCredentials(config: EncryptionConfig): void
Updates the encryption credentials.
Parameters:
config.key(string): New encryption keyconfig.iv(string): New initialization vector
Functions
encryptData(data: string, key: string, iv: string): string
Standalone function to encrypt data.
Parameters:
data(string): Plain text to encryptkey(string): Encryption key (minimum 32 characters)iv(string): Initialization vector (minimum 16 characters)
Returns: Base64 encoded encrypted string
Throws: Error if encryption fails
decryptData(encryptedData: string, key: string, iv: string): string
Standalone function to decrypt data.
Parameters:
encryptedData(string): Base64 encoded encrypted datakey(string): Decryption key (minimum 32 characters)iv(string): Initialization vector (minimum 16 characters)
Returns: Decrypted plain text string
Throws: Error if decryption fails
TypeScript Support
The SDK includes full TypeScript definitions. All types are exported:
import {
PayWizeSDK,
EncryptionConfig,
EncryptionResult,
DecryptionResult,
encryptData,
decryptData
} from 'paywize-merchant-sdk';Error Handling
Class-Based API
The class-based API returns result objects with error information:
const result = sdk.encrypt('data');
if (!result.success) {
console.error('Failed:', result.error);
}Functional API
The functional API throws errors:
try {
const encrypted = encryptData('data', key, iv);
} catch (error) {
console.error('Failed:', error.message);
}Requirements
- Node.js >= 14.0.0
Security Notes
- Keep your encryption keys and IVs secure
- Never commit credentials to version control
- Use environment variables for production deployments
- The key must be at least 32 characters (AES-256 requirement)
- The IV must be at least 16 characters (AES block size)
License
MIT
Support
For issues and questions, please contact PayWize support or open an issue on GitHub.
