Client library for Passky Server. It talks to the server, derives keys from the master password and encrypts every entry before it leaves the device.
bun add @rabbit-company/passky-apiPassky talks to the REST API of Passky Server 10. It derives the keys from the master password, encrypts every entry before it is sent and checks every answer from the server.
import { Passky, PasskyApiError, emptyEntry } from "@rabbit-company/passky-api";
const passky = new Passky("https://eu.passky.org");
await passky.register({ username: "ana.novak", email: "ana@example.com", password: "4d7f2a9c1e8b" });
const knownKdf = localStorage.getItem("kdf");
const login = await passky.signIn("ana.novak", "4d7f2a9c1e8b", { knownKdf });
const session = login.session ?? (await login.secondFactor.submit({ otp: "123456" }));
if (session.kdf) localStorage.setItem("kdf", session.kdf);
const { entries } = await session.passwords();
const saved = await session.addPassword(emptyEntry({ website: "passky.org", username: "ana.novak", password: "9f3b7c21d6e4" }));
await session.movePasswords([saved.id], "Work");Methods return plain values and throw PasskyApiError when something fails. Its code comes from the server or the client and never changes, so apps can react to it. Its message can be shown to people, and details.field names an invalid field.
try {
await session.deleteAccount("master password");
} catch (error) {
if (error instanceof PasskyApiError && error.code === "INVALID_PASSWORD") showWrongPassword();
}Deleting the account or every password, changing the master password and removing a second factor ask for the master password again.
When the account uses two factor authentication, signIn returns secondFactor instead of session. secondFactor.methods lists what the account can use: totp, yubikey, security-key and backup-code.
await login.secondFactor.submit({ otp });
await login.secondFactor.submit({ backupCode });
await login.secondFactor.useSecurityKey(authenticate);Security keys are used through a function the app passes in. In browsers it is authenticate from @rabbit-company/webauthn/browser, and native apps can pass their own. Registering works the same way:
import { register } from "@rabbit-company/webauthn/browser";
const { backupCodes } = await session.addSecurityKey("Blue key", register);Store session.kdf after signing in and pass it as knownKdf next time. Sign in then fails with KDF_DOWNGRADE when a server offers weaker settings than the account uses.
PasskyServer speaks the legacy ?action= API that every Passky Server supports. Use it only for servers older than version 10.
import { ErrorCode, PasskyServer, decryptEntries, deriveKeys, emptyEntry, encryptEntry } from "@rabbit-company/passky-api";
const server = new PasskyServer("https://eu.passky.org");
const { kdf } = await server.getKdf("username");
const keys = await deriveKeys("username", "master password", kdf);
const login = await server.getToken("username", keys.authenticationHash);
if (login.error === ErrorCode.SUCCESS) {
const session = { username: "username", token: login.token };
const vault = await decryptEntries(login.passwords, keys.vaultKey);
const entry = emptyEntry({ website: "passky.org", username: "me", password: "secret", folder: "Work" });
await server.savePassword(session, await encryptEntry(entry, keys.vaultKey));
}Every legacy call returns an object with error and info. When error is ErrorCode.SUCCESS the remaining fields are present. Invalid input is rejected before anything is sent.
Every entry has nine fields, and all of them are encrypted on the device:
| Field | Holds |
|---|---|
website |
The website of a login, or the title of any other item |
username |
Login username |
password |
Login password, or the passphrase of a key |
message |
Note |
folder |
Folder name |
favorite |
Favorite flag |
otp |
Two factor secret or otpauth:// URI |
kind |
login, ssh-key, pgp-key, passkey, note or card |
data |
Content that depends on kind, such as a key pair or card, up to 32768 characters |
emptyEntry creates a login with every field empty and validateEntry checks the fields before they are encrypted. Servers older than 10 only store the website, username, password and note, and getKdf reports entryFields: false for them so clients can hide the rest.
Accounts created by Passky clients before version 9 use the legacy derivation and the original XChaCha20 entry format. kdf is null for them.
New and upgraded accounts store Argon2id parameters on the server. One Argon2id run produces a master key. Keyed Blake2b turns it into the authentication hash sent to the server and a separate 256 bit encryption key that never leaves the device. Entries are encrypted with XChaCha20-Poly1305, so any change to stored data is detected. Each field is bound to its name and to the encrypted password of its entry, so a server can not move a field into another entry, and fields are padded so the server only learns rough sizes.
Clients should remember the parameters of upgraded accounts and check every login with isKdfDowngrade, so a server can not push an account back to weaker settings.
await session.upgradeSecurity("master password");
await session.changeMasterPassword("master password", "new master password");Both re-encrypt every entry on the device, verify the result and replace everything on the server in one transaction. Other sessions are signed out. With the legacy API the same is done by hand:
import { createKdf, deriveKeys, reencryptEntries } from "@rabbit-company/passky-api";
const kdf = createKdf();
const next = await deriveKeys("username", "new master password", kdf);
const passwords = await reencryptEntries(login.passwords, keys.vaultKey, next.vaultKey);
await server.changeMasterPassword("username", keys.authenticationHash, otp, next.authenticationHash, kdf, passwords);The server replaces every entry and the login in one transaction and signs out all sessions. It refuses the change with ErrorCode.VAULT_CHANGED when another device added or removed an entry in the meantime.
Sharing is end-to-end encrypted and needs an upgraded account. Each person sets it up once and shows their contact code, which others compare in person, on a call or through a channel they trust:
const sharing = await session.setUpSharing("master password");
console.log(sharing.contactCode); // "05843 19274 66310 08452 91736 25048"Verify a contact with their code, or with the text of their QR code, before sharing with them:
import { emptyEntry } from "@rabbit-company/passky-api";
if (!(await sharing.verifyContact("bob.kovac", "05843 19274 66310 08452 91736 25048"))) throw new Error("The contact code does not match.");
const folderId = await sharing.create("Family", [{ username: "bob.kovac", role: "editor" }]);
await sharing.addItem(folderId, emptyEntry({ website: "bank.example", username: "ana.novak", password: "9f3b7c21d6e4" }));On the next device or after signing in again, open sharing with session.sharing(). The other person accepts with sharing.accept(folderId) and reads the folder with sharing.open(folderId). Everything the server returns is checked: a changed key, a member list the owner did not sign, an older version or an item from someone who may not edit throws a SharingError.
bun testThe integration tests run against a real Passky Server and look for a clone next to this repository:
git clone https://github.com/Rabbit-Company/Passky-Server.git ../Passky-Server
cd ../Passky-Server && bun installWithout it those tests are skipped and the rest still run. To use a checkout somewhere else, set PASSKY_SERVER_DIR, for example in a .env file, which Bun loads on its own.