@rahulxsh/secure-core
v1.1.0
Published
Shared types and pure utility helpers for secure hybrid encryption
Downloads
343
Maintainers
Readme
@rahulxsh/secure-core
Shared types and pure utility helpers for secure hybrid encryption. Used by @rahulxsh/secure-client and @rahulxsh/secure-server. Zero runtime dependencies.
Install
npm install @rahulxsh/secure-coreUsage
import {
toBase64Url,
fromBase64Url,
randomBytes,
randomNonce,
stringToBytes,
bytesToString,
assertValidPayload,
} from "@rahulxsh/secure-core";
// Encode / decode base64url (used in payloads)
const encoded = toBase64Url(new Uint8Array([1, 2, 3]));
const decoded = fromBase64Url(encoded);
// Random bytes and nonces
const bytes = randomBytes(32);
const nonce = randomNonce();
// String ↔ bytes
const bytes = stringToBytes("hello");
const str = bytesToString(bytes);
// Validate encrypted payload shape (throws if invalid)
assertValidPayload(payload);API
- Types:
EncryptedPayload,KeyPair,EncryptOptions,SupportedAlgorithm - Base64url:
toBase64Url,fromBase64Url - Random:
randomBytes,randomNonce - Buffer:
stringToBytes,bytesToString,arrayBufferToBytes,concatBytes - Time:
nowSeconds,isFresh - Validation:
assertValidPayload,PayloadValidationError
License
MIT
