
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@ratio1/cstore-auth-ts
Advanced tools
Plug-and-play authentication layer for Ratio1 CStore hashes. This TypeScript library wraps the official [@ratio1/ratio1-sdk-ts](https://github.com/Ratio1/ratio1-sdk-ts) SDK, providing a minimal API to bootstrap an admin account and manage simple username/
Plug-and-play authentication layer for Ratio1 CStore hashes. This TypeScript library wraps the official @ratio1/ratio1-sdk-ts SDK, providing a minimal API to bootstrap an admin account and manage simple username/password credentials.
pnpm add @ratio1/cstore-auth-ts
# or
npm install @ratio1/cstore-auth-ts
| Variable | Description |
|---|---|
R1EN_CSTORE_AUTH_HKEY | Hash key that stores all user records (e.g. auth:default). |
R1EN_CSTORE_AUTH_SECRET | Long-lived server-side pepper mixed into password hashes. |
R1EN_CSTORE_AUTH_BOOTSTRAP_ADMIN_PWD | One-time bootstrap password for the initial admin user. Required until the admin account exists. |
Note: Legacy environment variable names (
EE_CSTORE_AUTH_HKEY,EE_CSTORE_AUTH_SECRET,EE_CSTORE_AUTH_BOOTSTRAP_ADMIN_PW) are still supported for backwards compatibility but are deprecated.
import { CStoreAuth } from '@ratio1/cstore-auth-ts';
const auth = new CStoreAuth();
await auth.simple.init();
await auth.simple.createUser('alice', 'S3curePassw0rd', {
metadata: { email: 'alice@example.com' }
});
const user = await auth.simple.authenticate('alice', 'S3curePassw0rd');
console.log(user);
// → { username: 'alice', role: 'user', metadata: { email: 'alice@example.com' }, createdAt: '...', updatedAt: '...', type: 'simple' }
// Retrieve all users
const allUsers = await auth.simple.getAllUsers();
console.log(`Total users: ${allUsers.length}`);
allUsers.forEach((u) => console.log(`- ${u.username} (${u.role})`));
// Update user metadata or role
// IMPORTANT: Implement authorization checks in your application layer!
// Example: Only allow users to edit themselves or admins to edit anyone
await auth.simple.updateUser('alice', {
metadata: { email: 'newemail@example.com', verified: true }
});
// Change password (requires current password)
await auth.simple.changePassword('alice', 'S3curePassw0rd', 'NewP@ssw0rd!');
interface CStoreAuthOptions {
hkey?: string;
secret?: string;
client?: CStoreLikeClient;
hasher?: PasswordHasher;
now?: () => Date;
logger?: Pick<Console, 'debug' | 'info' | 'warn' | 'error'>;
}
class CStoreAuth {
constructor(opts?: CStoreAuthOptions);
simple: {
init(): Promise<void>;
createUser<TMeta = Record<string, unknown>>(
username: string,
password: string,
opts?: CreateUserOptions<TMeta>
): Promise<PublicUser<TMeta>>;
authenticate<TMeta = Record<string, unknown>>(
username: string,
password: string
): Promise<PublicUser<TMeta>>;
getUser<TMeta = Record<string, unknown>>(username: string): Promise<PublicUser<TMeta> | null>;
getAllUsers<TMeta = Record<string, unknown>>(): Promise<PublicUser<TMeta>[]>;
updateUser<TMeta = Record<string, unknown>>(
username: string,
opts: UpdateUserOptions<TMeta>
): Promise<PublicUser<TMeta>>;
changePassword(username: string, currentPassword: string, newPassword: string): Promise<void>;
};
}
Errors are surfaced as descriptive subclasses (EnvVarMissingError, AuthInitError, InvalidUsernameError, InvalidCredentialsError, UserExistsError, UserNotFoundError, etc.).
⚠️ IMPORTANT: updateUser does not enforce authorization. You must implement authorization checks in your application layer.
// Example: Users can edit themselves, admins can edit anyone
async function updateUserWithAuth(
currentUser: PublicUser,
targetUsername: string,
updates: UpdateUserOptions
) {
// Check if user is editing themselves OR is an admin
const isEditingSelf = currentUser.username === targetUsername;
const isAdmin = currentUser.role === 'admin';
if (!isEditingSelf && !isAdmin) {
throw new Error('Unauthorized: You can only edit your own profile');
}
// Only admins can change roles
if (updates.role && !isAdmin) {
throw new Error('Unauthorized: Only admins can change roles');
}
return await auth.simple.updateUser(targetUsername, updates);
}
// Example: Express.js middleware
app.put('/api/users/:username', async (req, res) => {
const currentUser = req.session.user; // From authenticated session
const { username } = req.params;
const updates = req.body;
try {
// Authorization check
if (currentUser.username !== username && currentUser.role !== 'admin') {
return res.status(403).json({ error: 'Forbidden' });
}
// Only admins can change roles
if (updates.role && currentUser.role !== 'admin') {
return res.status(403).json({ error: 'Only admins can change roles' });
}
const updated = await auth.simple.updateUser(username, updates);
res.json(updated);
} catch (error) {
res.status(400).json({ error: error.message });
}
});
@node-rs/argon2) is used when available. The module automatically downgrades to Node's built-in crypto.scrypt with strong defaults when Argon2 cannot load.R1EN_CSTORE_AUTH_SECRET).changePassword always requires current password verification.updateUser does NOT enforce authorization - implement checks in your application layerverified: true on themselves)[a-z0-9._-]{3,64}.pnpm install
pnpm run lint
pnpm test # Run unit tests
pnpm run test:integration # Run integration tests
pnpm run test:all # Run all tests
pnpm run build
pnpm run docs
The project includes two test suites:
test/**/*.spec.ts): Fast, isolated tests with mocked dependenciestest/integration/**/*.integration.spec.ts): Complete workflow tests with realistic cleanup patternsIntegration tests follow best practices including:
See test/integration/README.md for detailed integration testing documentation.
Typedoc emits HTML documentation to docs/. GitHub Actions (see .github/workflows/ci.yml) runs linting, type-checking, tests, build, and docs generation on Node.js 18 and 20.
simple methodFAQs
Plug-and-play authentication layer for Ratio1 CStore hashes. This TypeScript library wraps the official [@ratio1/ratio1-sdk-ts](https://github.com/Ratio1/ratio1-sdk-ts) SDK, providing a minimal API to bootstrap an admin account and manage simple username/
We found that @ratio1/cstore-auth-ts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.