Compare commits

...

7 Commits

Author SHA1 Message Date
Guido D'Orsi
eda1588907 Merge pull request #1527 from garden-co/changeset-release/main
Version Packages
2025-02-27 09:56:16 +01:00
github-actions[bot]
b14e0bfe24 Version Packages 2025-02-26 17:58:41 +00:00
Guido D'Orsi
87aa43b46b Merge pull request #1507 from garden-co/jazz-747-passphrase-auth-restore-support-for-rerolling-the-passphrase
feat(PasskeyAuth): support random passphrase generation
2025-02-26 18:54:42 +01:00
Guido D'Orsi
b93ce9fb7e chore: rever to use property initializers 2025-02-26 18:54:32 +01:00
Guido D'Orsi
a7d83e1c10 feat(passphrase-example): inline the UI and implement the passphrase reroll flow 2025-02-26 16:29:05 +01:00
Guido D'Orsi
76a693da15 Update packages/jazz-tools/src/tests/PassphraseAuth.test.ts
Co-authored-by: Giordano Ricci <me@giordanoricci.com>
2025-02-26 16:23:02 +01:00
Guido D'Orsi
07feedd641 feat(PasskeyAuth): support random passphrase generation 2025-02-25 15:35:48 +01:00
81 changed files with 904 additions and 84 deletions

View File

@@ -1,5 +1,15 @@
# chat-rn-clerk
## 1.0.78
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react-native@0.10.13
- jazz-react-native-auth-clerk@0.10.13
- jazz-react-native-media-images@0.10.13
## 1.0.77
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "chat-rn-clerk",
"main": "index.js",
"version": "1.0.77",
"version": "1.0.78",
"scripts": {
"build": "expo export -p ios",
"start": "expo start",

View File

@@ -1,5 +1,13 @@
# chat-rn
## 1.0.74
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react-native@0.10.13
## 1.0.73
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-rn",
"version": "1.0.73",
"version": "1.0.74",
"main": "index.js",
"scripts": {
"build": "expo export -p ios",

View File

@@ -1,5 +1,14 @@
# chat-vue
## 0.0.60
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
- jazz-vue@0.10.13
## 0.0.59
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "chat-vue",
"version": "0.0.59",
"version": "0.0.60",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,14 @@
# jazz-example-chat
## 0.0.156
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser-media-images@0.10.13
- jazz-react@0.10.13
## 0.0.155
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-chat",
"private": true,
"version": "0.0.155",
"version": "0.0.156",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# minimal-auth-clerk
## 0.0.55
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
- jazz-react-auth-clerk@0.10.13
## 0.0.54
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "clerk",
"private": true,
"version": "0.0.54",
"version": "0.0.55",
"type": "module",
"scripts": {
"dev": "vite",
@@ -13,7 +13,7 @@
"dependencies": {
"@clerk/clerk-react": "^5.4.1",
"jazz-react": "workspace:*",
"jazz-react-auth-clerk": "workspace:0.10.12",
"jazz-react-auth-clerk": "workspace:0.10.13",
"jazz-tools": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1"

View File

@@ -1,5 +1,13 @@
# file-share-svelte
## 0.0.40
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-svelte@0.10.13
## 0.0.39
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "file-share-svelte",
"version": "0.0.39",
"version": "0.0.40",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,14 @@
# form
## 0.0.51
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser-media-images@0.10.13
- jazz-react@0.10.13
## 0.0.50
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "form",
"private": true,
"version": "0.0.50",
"version": "0.0.51",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# image-upload
## 0.0.53
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser-media-images@0.10.13
- jazz-react@0.10.13
## 0.0.52
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "image-upload",
"private": true,
"version": "0.0.52",
"version": "0.0.53",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# jazz-example-musicplayer
## 0.0.77
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-inspector@0.10.10
- jazz-react@0.10.13
## 0.0.76
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-music-player",
"private": true,
"version": "0.0.76",
"version": "0.0.77",
"type": "module",
"scripts": {
"dev": "vite",
@@ -22,8 +22,8 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-inspector": "workspace:*",
"jazz-react": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12",
"jazz-react": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13",
"lucide-react": "^0.274.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",

View File

@@ -1,5 +1,13 @@
# organization
## 0.0.49
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.48
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "organization",
"private": true,
"version": "0.0.48",
"version": "0.0.49",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,11 @@
# passkey-svelte
## 0.0.44
### Patch Changes
- jazz-svelte@0.10.13
## 0.0.43
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "passkey-svelte",
"version": "0.0.43",
"version": "0.0.44",
"type": "module",
"private": true,
"scripts": {

View File

@@ -1,5 +1,13 @@
# minimal-auth-passkey
## 0.0.54
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.53
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passkey",
"private": true,
"version": "0.0.53",
"version": "0.0.54",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,13 @@
# passphrase
## 0.0.51
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.50
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "passphrase",
"private": true,
"version": "0.0.50",
"version": "0.0.51",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -66,3 +66,72 @@ main {
margin: 0 auto;
text-align: center;
}
.auth-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: #f3f4f6;
}
.auth-card {
background-color: white;
padding: 2rem;
border-radius: 0.5rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px
rgba(0, 0, 0, 0.06);
width: 28rem;
}
.auth-button-primary,
.auth-button-secondary {
width: 100%;
padding: 0.5rem 1rem;
border-radius: 0.25rem;
font-weight: bold;
cursor: pointer;
margin-bottom: 1rem;
}
.auth-button-primary {
background-color: black;
color: white;
border: none;
}
.auth-button-secondary {
background-color: white;
color: black;
border: 1px solid black;
}
.auth-heading {
color: black;
font-size: 1.5rem;
font-weight: bold;
text-align: center;
margin-bottom: 1rem;
}
.auth-textarea {
width: 100%;
padding: 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.25rem;
margin-bottom: 1rem;
box-sizing: border-box;
}
.auth-description {
font-size: 0.875rem;
color: #4b5563;
text-align: center;
margin-bottom: 1rem;
}
.auth-button-group {
display: flex;
justify-content: space-between;
gap: 1rem;
}

View File

@@ -1,10 +1,142 @@
import { JazzProvider, PassphraseAuthBasicUI } from "jazz-react";
import { StrictMode } from "react";
import { JazzProvider, usePassphraseAuth } from "jazz-react";
import { StrictMode, useState } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import { wordlist } from "./wordlist.ts";
function PassphraseAuthBasicUI(props: {
appName: string;
wordlist: string[];
children?: React.ReactNode;
}) {
const auth = usePassphraseAuth({
wordlist: props.wordlist,
});
const [step, setStep] = useState<"initial" | "create" | "login">("initial");
const [loginPassphrase, setLoginPassphrase] = useState("");
const [isCopied, setIsCopied] = useState(false);
const [currentPassphrase, setCurrentPassphrase] = useState(() =>
auth.generateRandomPassphrase(),
);
if (auth.state === "signedIn") {
return props.children ?? null;
}
const handleCreateAccount = async () => {
setStep("create");
};
const handleLogin = () => {
setStep("login");
};
const handleReroll = () => {
const newPassphrase = auth.generateRandomPassphrase();
setCurrentPassphrase(newPassphrase);
setIsCopied(false);
};
const handleBack = () => {
setStep("initial");
setLoginPassphrase("");
};
const handleCopy = async () => {
await navigator.clipboard.writeText(auth.passphrase);
setIsCopied(true);
};
const handleLoginSubmit = async () => {
await auth.logIn(loginPassphrase);
setStep("initial");
setLoginPassphrase("");
};
const handleNext = async () => {
await auth.registerNewAccount(currentPassphrase, "My Account");
setStep("initial");
setLoginPassphrase("");
};
return (
<div className="auth-container">
<div className="auth-card">
{step === "initial" && (
<div>
<h1 className="auth-heading">{props.appName}</h1>
<button
onClick={handleCreateAccount}
className="auth-button-primary"
>
Create new account
</button>
<button onClick={handleLogin} className="auth-button-secondary">
Log in
</button>
</div>
)}
{step === "create" && (
<>
<h1 className="auth-heading">Your Passphrase</h1>
<p className="auth-description">
Please copy and store this passphrase somewhere safe. You'll need
it to log in.
</p>
<textarea
readOnly
value={currentPassphrase}
className="auth-textarea"
rows={5}
/>
<button onClick={handleCopy} className="auth-button-primary">
{isCopied ? "Copied!" : "Copy"}
</button>
<div className="auth-button-group">
<button onClick={handleBack} className="auth-button-secondary">
Back
</button>
<button onClick={handleReroll} className="auth-button-secondary">
Generate New Passphrase
</button>
<button onClick={handleNext} className="auth-button-primary">
Register
</button>
</div>
</>
)}
{step === "login" && (
<div>
<h1 className="auth-heading">Log In</h1>
<textarea
value={loginPassphrase}
onChange={(e) => setLoginPassphrase(e.target.value)}
placeholder="Enter your passphrase"
className="auth-textarea"
rows={5}
/>
<div className="auth-button-group">
<button onClick={handleBack} className="auth-button-secondary">
Back
</button>
<button
onClick={handleLoginSubmit}
className="auth-button-primary"
>
Log In
</button>
</div>
</div>
)}
</div>
</div>
);
}
function JazzAndAuth({ children }: { children: React.ReactNode }) {
return (
<JazzProvider

View File

@@ -1,5 +1,13 @@
# jazz-password-manager
## 0.0.75
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.74
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-password-manager",
"private": true,
"version": "0.0.74",
"version": "0.0.75",
"type": "module",
"scripts": {
"dev": "vite",
@@ -12,8 +12,8 @@
"clean-install": "rm -rf node_modules pnpm-lock.yaml && pnpm install"
},
"dependencies": {
"jazz-react": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12",
"jazz-react": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.41.5",

View File

@@ -1,5 +1,14 @@
# jazz-example-pets
## 0.0.173
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser-media-images@0.10.13
- jazz-react@0.10.13
## 0.0.172
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-pets",
"private": true,
"version": "0.0.172",
"version": "0.0.173",
"type": "module",
"scripts": {
"dev": "vite",
@@ -19,9 +19,9 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-browser-media-images": "workspace:0.10.12",
"jazz-react": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12",
"jazz-browser-media-images": "workspace:0.10.13",
"jazz-react": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",
@@ -41,7 +41,7 @@
"@vitejs/plugin-react-swc": "^3.3.2",
"autoprefixer": "^10.4.20",
"is-ci": "^3.0.1",
"jazz-run": "workspace:0.10.12",
"jazz-run": "workspace:0.10.13",
"postcss": "^8.4.27",
"tailwindcss": "^3.4.17",
"typescript": "~5.6.2",

View File

@@ -1,5 +1,14 @@
# reactions
## 0.0.53
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser-media-images@0.10.13
- jazz-react@0.10.13
## 0.0.52
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "reactions",
"private": true,
"version": "0.0.52",
"version": "0.0.53",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,14 @@
# todo-vue
## 0.0.58
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
- jazz-vue@0.10.13
## 0.0.57
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "todo-vue",
"version": "0.0.57",
"version": "0.0.58",
"private": true,
"type": "module",
"scripts": {

View File

@@ -1,5 +1,13 @@
# jazz-example-todo
## 0.0.172
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.171
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-example-todo",
"private": true,
"version": "0.0.171",
"version": "0.0.172",
"type": "module",
"scripts": {
"dev": "vite",
@@ -16,8 +16,8 @@
"@radix-ui/react-toast": "^1.1.4",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"jazz-react": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12",
"jazz-react": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13",
"lucide-react": "^0.274.0",
"qrcode": "^1.5.3",
"react": "^18.3.1",

View File

@@ -1,5 +1,13 @@
# version-history
## 0.0.50
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.49
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "version-history",
"private": true,
"version": "0.0.49",
"version": "0.0.50",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -1,5 +1,13 @@
# jazz-browser-media-images
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,14 +1,14 @@
{
"name": "jazz-auth-clerk",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",
"license": "MIT",
"dependencies": {
"cojson": "workspace:0.10.8",
"jazz-browser": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12"
"jazz-browser": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13"
},
"scripts": {
"format-and-lint": "biome check .",

View File

@@ -1,5 +1,13 @@
# jazz-browser-media-images
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-browser-media-images",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",
@@ -8,8 +8,8 @@
"dependencies": {
"@types/image-blob-reduce": "^4.1.1",
"image-blob-reduce": "^4.1.0",
"jazz-browser": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.12",
"jazz-browser": "workspace:0.10.13",
"jazz-tools": "workspace:0.10.13",
"pica": "^9.0.1",
"typescript": "~5.6.2"
},

View File

@@ -1,5 +1,12 @@
# jazz-browser
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-browser",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",

View File

@@ -1,5 +1,13 @@
# jazz-inspector
## 0.10.10
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react-core@0.10.10
## 0.10.9
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-inspector",
"version": "0.10.9",
"version": "0.10.10",
"type": "module",
"main": "./dist/app.js",
"types": "./dist/app.d.ts",

View File

@@ -1,5 +1,12 @@
# jazz-autosub
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -5,7 +5,7 @@
"types": "src/index.ts",
"type": "module",
"license": "MIT",
"version": "0.10.12",
"version": "0.10.13",
"dependencies": {
"cojson": "workspace:*",
"cojson-transport-ws": "workspace:*",

View File

@@ -1,5 +1,15 @@
# jazz-browser-media-images
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-auth-clerk@0.10.13
- jazz-browser@0.10.13
- jazz-react@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react-auth-clerk",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.tsx",

View File

@@ -1,5 +1,12 @@
# jazz-react-core
## 0.10.10
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
## 0.10.9
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react-core",
"version": "0.10.9",
"version": "0.10.10",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",

View File

@@ -29,6 +29,7 @@ export function usePassphraseAuth({
return new PassphraseAuth(
context.node.crypto,
context.authenticate,
context.register,
authSecretStorage,
wordlist,
);
@@ -50,6 +51,8 @@ export function usePassphraseAuth({
state: isAuthenticated ? "signedIn" : "anonymous",
logIn: authMethod.logIn,
signUp: authMethod.signUp,
registerNewAccount: authMethod.registerNewAccount,
generateRandomPassphrase: authMethod.generateRandomPassphrase,
passphrase,
} as const;
}

View File

@@ -1,5 +1,14 @@
# jazz-react-native-auth-clerk
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-auth-clerk@0.10.13
- jazz-react-native@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react-native-auth-clerk",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.tsx",

View File

@@ -1,5 +1,12 @@
# jazz-browser-media-images
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react-native-media-images",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",

View File

@@ -1,5 +1,13 @@
# jazz-browser
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react-core@0.10.10
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react-native",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",

View File

@@ -1,5 +1,14 @@
# jazz-react
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
- jazz-react-core@0.10.10
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-react",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",
@@ -18,9 +18,9 @@
"dependencies": {
"@scure/bip39": "^1.3.0",
"cojson": "workspace:0.10.8",
"jazz-browser": "workspace:0.10.12",
"jazz-browser": "workspace:0.10.13",
"jazz-react-core": "workspace:*",
"jazz-tools": "workspace:0.10.12"
"jazz-tools": "workspace:0.10.13"
},
"devDependencies": {
"@testing-library/dom": "^10.4.0",

View File

@@ -1,5 +1,12 @@
# jazz-run
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -3,7 +3,7 @@
"bin": "./dist/index.js",
"type": "module",
"license": "MIT",
"version": "0.10.12",
"version": "0.10.13",
"exports": {
"./startSyncServer": {
"import": "./dist/startSyncServer.js",
@@ -32,7 +32,7 @@
"cojson-storage-sqlite": "workspace:0.10.8",
"cojson-transport-ws": "workspace:0.10.8",
"effect": "^3.6.5",
"jazz-tools": "workspace:0.10.12",
"jazz-tools": "workspace:0.10.13",
"ws": "^8.14.2"
},
"devDependencies": {

View File

@@ -1,5 +1,13 @@
# jazz-svelte
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-svelte",
"version": "0.10.12",
"version": "0.10.13",
"scripts": {
"dev": "vite dev",
"build": "vite build && npm run package",

View File

@@ -14,6 +14,7 @@ export function usePassphraseAuth({
const auth = new PassphraseAuth(
context.current.node.crypto,
context.current.authenticate,
context.current.register,
authSecretStorage,
wordlist
);
@@ -35,6 +36,8 @@ export function usePassphraseAuth({
return {
logIn: auth.logIn,
signUp: auth.signUp,
registerNewAccount: auth.registerNewAccount,
generateRandomPassphrase: auth.generateRandomPassphrase,
get passphrase() {
return passphrase;
},

View File

@@ -1,5 +1,11 @@
# jazz-tools
## 0.10.13
### Patch Changes
- 07feedd: Add registerNewUser and generateRandomPassphrase methods to PasskeyAuth and accept the username param on the signUp function
## 0.10.12
### Patch Changes

View File

@@ -17,7 +17,7 @@
},
"type": "module",
"license": "MIT",
"version": "0.10.12",
"version": "0.10.13",
"dependencies": {
"@scure/bip39": "^1.3.0",
"cojson": "workspace:*"

View File

@@ -3,7 +3,10 @@ import { entropyToMnemonic } from "@scure/bip39";
import { CryptoProvider, cojsonInternals } from "cojson";
import { Account } from "../coValues/account.js";
import type { ID } from "../internal.js";
import type { AuthenticateAccountFunction } from "../types.js";
import type {
AuthenticateAccountFunction,
RegisterAccountFunction,
} from "../types.js";
import { AuthSecretStorage } from "./AuthSecretStorage.js";
/**
@@ -23,6 +26,7 @@ export class PassphraseAuth {
constructor(
private crypto: CryptoProvider,
private authenticate: AuthenticateAccountFunction,
private register: RegisterAccountFunction,
private authSecretStorage: AuthSecretStorage,
public wordlist: string[],
) {}
@@ -61,7 +65,7 @@ export class PassphraseAuth {
this.notify();
};
signUp = async () => {
signUp = async (name?: string) => {
const credentials = await this.authSecretStorage.get();
if (!credentials || !credentials.secretSeed) {
@@ -77,9 +81,32 @@ export class PassphraseAuth {
provider: "passphrase",
});
if (name?.trim()) {
const currentAccount = await Account.getMe().ensureLoaded({
profile: {},
});
currentAccount.profile.name = name;
}
return passphrase;
};
registerNewAccount = async (passphrase: string, name: string) => {
const secretSeed = bip39.mnemonicToEntropy(passphrase, this.wordlist);
const accountSecret = this.crypto.agentSecretFromSecretSeed(secretSeed);
const accountID = await this.register(accountSecret, { name });
await this.authSecretStorage.set({
accountID,
secretSeed,
accountSecret,
provider: "passphrase",
});
return accountID;
};
getCurrentAccountPassphrase = async () => {
const credentials = await this.authSecretStorage.get();
@@ -90,6 +117,10 @@ export class PassphraseAuth {
return entropyToMnemonic(credentials.secretSeed, this.wordlist);
};
generateRandomPassphrase = () => {
return entropyToMnemonic(this.crypto.newRandomSecretSeed(), this.wordlist);
};
loadCurrentAccountPassphrase = async () => {
const passphrase = await this.getCurrentAccountPassphrase();
this.passphrase = passphrase;

View File

@@ -80,6 +80,7 @@ export class JazzContextManager<
...context,
node: context.node,
authenticate: this.authenticate,
register: this.register,
logOut: this.logOut,
};
@@ -143,14 +144,59 @@ export class JazzContextManager<
this.authenticating = false;
});
if (wasAnonymous) {
await this.handleAnonymousAccountMigration(prevContext);
}
};
register = async (
accountSecret: AgentSecret,
creationProps: { name: string },
) => {
if (!this.props) {
throw new Error("Props required");
}
const prevContext = this.context;
const prevCredentials = await this.authSecretStorage.get();
const wasAnonymous =
this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
this.authenticating = true;
await this.createContext(this.props, {
newAccountProps: {
secret: accountSecret,
creationProps,
},
}).finally(() => {
this.authenticating = false;
});
if (wasAnonymous) {
await this.handleAnonymousAccountMigration(prevContext);
}
if (this.context && "me" in this.context) {
return this.context.me.id;
}
throw new Error("The registration hasn't created a new account");
};
private async handleAnonymousAccountMigration(
prevContext: PlatformSpecificContext<Acc> | undefined,
) {
if (!this.props) {
throw new Error("Props required");
}
const currentContext = this.context;
if (
prevContext &&
currentContext &&
"me" in prevContext &&
"me" in currentContext &&
wasAnonymous
"me" in currentContext
) {
// Using a direct connection to make coValue transfer almost synchronous
const [prevAccountAsPeer, currentAccountAsPeer] =
@@ -178,7 +224,7 @@ export class JazzContextManager<
}
prevContext?.done();
};
}
listeners = new Set<() => void>();
subscribe = (callback: () => void) => {

View File

@@ -338,4 +338,53 @@ describe("ContextManager", () => {
expect(me.root.transferredRoot?.value).toBe("Hello");
});
test("handles registration of new account", async () => {
const onAnonymousAccountDiscarded = vi.fn();
await manager.createContext({ onAnonymousAccountDiscarded });
const secret = Crypto.newRandomAgentSecret();
const accountId = await manager.register(secret, { name: "Test User" });
expect(accountId).toBeDefined();
const context = getCurrentValue();
expect(context.me.profile?.name).toBe("Test User");
expect(context.me.id).toBe(accountId);
});
test("calls onAnonymousAccountDiscarded when registering from anonymous user", async () => {
const onAnonymousAccountDiscarded = vi.fn();
await manager.createContext({ onAnonymousAccountDiscarded });
const anonymousAccount = getCurrentValue().me;
const secret = Crypto.newRandomAgentSecret();
await manager.register(secret, { name: "Test User" });
expect(onAnonymousAccountDiscarded).toHaveBeenCalledWith(anonymousAccount);
});
test("does not call onAnonymousAccountDiscarded when registering from authenticated user", async () => {
const onAnonymousAccountDiscarded = vi.fn();
const account = await createJazzTestAccount();
await manager.getAuthSecretStorage().set({
accountID: account.id,
accountSecret: account._raw.core.node.account.agentSecret,
provider: "test",
});
await manager.createContext({ onAnonymousAccountDiscarded });
const secret = Crypto.newRandomAgentSecret();
await manager.register(secret, { name: "New User" });
expect(onAnonymousAccountDiscarded).not.toHaveBeenCalled();
});
test("throws error when registering without props", async () => {
const secret = Crypto.newRandomAgentSecret();
await expect(
manager.register(secret, { name: "Test User" }),
).rejects.toThrow("Props required");
});
});

View File

@@ -2,6 +2,7 @@
import { mnemonicToEntropy } from "@scure/bip39";
import { AgentSecret } from "cojson";
import { PureJSCrypto } from "cojson/src/crypto/PureJSCrypto";
import {
Account,
AuthSecretStorage,
@@ -9,31 +10,41 @@ import {
InMemoryKVStore,
KvStoreContext,
} from "jazz-tools";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { assert, beforeEach, describe, expect, it, vi } from "vitest";
import { PassphraseAuth } from "../auth/PassphraseAuth";
import { createJazzTestAccount } from "../testing";
import { TestJSCrypto } from "../testing";
import {
TestJazzContextManager,
createJazzTestAccount,
setupJazzTestSync,
} from "../testing";
import { testWordlist } from "./fixtures";
// Initialize KV store for tests
KvStoreContext.getInstance().initialize(new InMemoryKVStore());
beforeEach(async () => {
await setupJazzTestSync();
});
describe("PassphraseAuth", () => {
let crypto: TestJSCrypto;
let crypto: PureJSCrypto;
let mockAuthenticate: any;
let mockRegister: any;
let authSecretStorage: AuthSecretStorage;
let passphraseAuth: PassphraseAuth;
let account: Account;
beforeEach(async () => {
// Reset storage
KvStoreContext.getInstance().getStorage().clearAll();
// Set up crypto and mocks
crypto = await TestJSCrypto.create();
crypto = await PureJSCrypto.create();
mockAuthenticate = vi.fn();
mockRegister = vi.fn();
authSecretStorage = new AuthSecretStorage();
await createJazzTestAccount({
account = await createJazzTestAccount({
isCurrentActiveAccount: true,
});
@@ -41,6 +52,7 @@ describe("PassphraseAuth", () => {
passphraseAuth = new PassphraseAuth(
crypto,
mockAuthenticate,
mockRegister,
authSecretStorage,
testWordlist,
);
@@ -121,6 +133,39 @@ describe("PassphraseAuth", () => {
"No credentials found",
);
});
it("should set account name when provided during signup", async () => {
const storageData = {
accountID: "test-account-id" as ID<Account>,
accountSecret: "test-secret" as AgentSecret,
secretSeed: new Uint8Array([
173, 58, 235, 40, 67, 188, 236, 11, 107, 237, 97, 23, 182, 49, 188,
63, 237, 52, 27, 84, 142, 66, 244, 149, 243, 114, 203, 164, 115, 239,
175, 194,
]),
provider: "anonymous",
};
await authSecretStorage.set(storageData);
const testName = "Test User";
await passphraseAuth.signUp(testName);
// Verify the account name was set
const { profile } = await account.ensureLoaded({
profile: {},
});
expect(profile.name).toBe(testName);
// Verify storage was updated correctly
const storedData = await authSecretStorage.get();
expect(storedData).toEqual({
accountID: storageData.accountID,
accountSecret: storageData.accountSecret,
secretSeed: storageData.secretSeed,
provider: "passphrase",
});
});
});
describe("getCurrentAccountPassphrase", () => {
@@ -150,3 +195,153 @@ describe("PassphraseAuth", () => {
});
});
});
// Initialize KV store for tests
KvStoreContext.getInstance().initialize(new InMemoryKVStore());
describe("PassphraseAuth with TestJazzContextManager", () => {
let crypto: PureJSCrypto;
let contextManager: TestJazzContextManager<any>;
let authSecretStorage: AuthSecretStorage;
let passphraseAuth: PassphraseAuth;
beforeEach(async () => {
// Reset storage
KvStoreContext.getInstance().getStorage().clearAll();
const account = await createJazzTestAccount({
isCurrentActiveAccount: true,
});
// Set up crypto and context manager
crypto = await PureJSCrypto.create();
contextManager = TestJazzContextManager.fromAccountOrGuest(account);
authSecretStorage = contextManager.getAuthSecretStorage();
// Create initial context
await contextManager.createContext({});
// Create PassphraseAuth instance
passphraseAuth = new PassphraseAuth(
crypto,
contextManager.authenticate,
contextManager.register,
authSecretStorage,
testWordlist,
);
});
describe("logIn", () => {
it("should successfully log in with valid passphrase", async () => {
// First sign up to create initial credentials
const passphrase = await passphraseAuth.signUp();
// Log out
await contextManager.logOut();
// Log back in with passphrase
await passphraseAuth.logIn(passphrase);
// Verify we're logged in
const context = contextManager.getCurrentValue();
assert(context && "me" in context);
// Verify storage was updated
const storedData = await authSecretStorage.get();
expect(storedData?.provider).toBe("passphrase");
});
it("should throw error with invalid passphrase", async () => {
await expect(passphraseAuth.logIn("invalid words here")).rejects.toThrow(
"Invalid passphrase",
);
});
});
describe("signUp", () => {
it("should successfully sign up new user", async () => {
expect(authSecretStorage.isAuthenticated).toBe(false);
const passphrase = await passphraseAuth.signUp();
expect(authSecretStorage.isAuthenticated).toBe(true);
// Verify passphrase format
expect(passphrase.split(" ").length).toBeGreaterThan(0);
// Verify storage was updated
const storedData = await authSecretStorage.get();
expect(storedData?.provider).toBe("passphrase");
// Verify we can log in with the passphrase
await contextManager.logOut();
await passphraseAuth.logIn(passphrase);
const context = contextManager.getCurrentValue();
assert(context && "me" in context);
expect(context.me).toBeDefined();
});
it("should throw error when no credentials found", async () => {
await authSecretStorage.clear();
await expect(passphraseAuth.signUp()).rejects.toThrow(
"No credentials found",
);
});
});
describe("registerNewAccount", () => {
it("should successfully register new account with passphrase", async () => {
expect(authSecretStorage.isAuthenticated).toBe(false);
const passphrase = passphraseAuth.generateRandomPassphrase();
const accountId = await passphraseAuth.registerNewAccount(
passphrase,
"Test User",
);
// Verify account was created
expect(accountId).toBeDefined();
// Verify we can log in with the passphrase
await contextManager.logOut();
await passphraseAuth.logIn(passphrase);
const context = contextManager.getCurrentValue();
assert(context && "me" in context);
expect(context.me.id).toBe(accountId);
expect(context.me.profile?.name).toBe("Test User");
expect(authSecretStorage.isAuthenticated).toBe(true);
const credentials = await authSecretStorage.get();
assert(credentials);
expect(credentials.accountID).toBe(accountId);
expect(credentials.provider).toBe("passphrase");
});
it("should throw error with invalid passphrase during registration", async () => {
await expect(
passphraseAuth.registerNewAccount("invalid words", "Test User"),
).rejects.toThrow();
});
});
describe("getCurrentAccountPassphrase", () => {
it("should return current user passphrase when credentials exist", async () => {
const originalPassphrase = await passphraseAuth.signUp();
const retrievedPassphrase =
await passphraseAuth.getCurrentAccountPassphrase();
expect(retrievedPassphrase).toBe(originalPassphrase);
});
it("should throw error when no credentials found", async () => {
await authSecretStorage.clear();
await expect(
passphraseAuth.getCurrentAccountPassphrase(),
).rejects.toThrow("No credentials found");
});
});
});

View File

@@ -12,6 +12,7 @@ export type AuthCredentials = {
export type AuthenticateAccountFunction = (
credentials: AuthCredentials,
) => Promise<void>;
export type RegisterAccountFunction = (
accountSecret: AgentSecret,
creationProps: { name: string },
@@ -22,6 +23,7 @@ export type JazzAuthContext<Acc extends Account> = {
me: Acc;
node: LocalNode;
authenticate: AuthenticateAccountFunction;
register: RegisterAccountFunction;
logOut: () => Promise<void>;
done: () => void;
isAuthenticated?: boolean;
@@ -31,6 +33,7 @@ export type JazzGuestContext = {
guest: AnonymousJazzAgent;
node: LocalNode;
authenticate: AuthenticateAccountFunction;
register: RegisterAccountFunction;
logOut: () => void;
done: () => void;
isAuthenticated?: boolean;

View File

@@ -1,5 +1,13 @@
# jazz-react
## 0.10.13
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-browser@0.10.13
## 0.10.12
### Patch Changes

View File

@@ -1,6 +1,6 @@
{
"name": "jazz-vue",
"version": "0.10.12",
"version": "0.10.13",
"type": "module",
"main": "dist/index.js",
"types": "src/index.ts",

View File

@@ -30,6 +30,7 @@ export function usePassphraseAuth({
return new PassphraseAuth(
context.value.node.crypto,
context.value.authenticate,
context.value.register,
authSecretStorage,
wordlist,
);
@@ -51,6 +52,8 @@ export function usePassphraseAuth({
state: isAuthenticated.value ? "signedIn" : "anonymous",
logIn: authMethod.value.logIn,
signUp: authMethod.value.signUp,
registerNewAccount: authMethod.value.registerNewAccount,
generateRandomPassphrase: authMethod.value.generateRandomPassphrase,
passphrase: passphrase.value,
}));
}

36
pnpm-lock.yaml generated
View File

@@ -444,7 +444,7 @@ importers:
specifier: workspace:*
version: link:../../packages/jazz-react
jazz-react-auth-clerk:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-react-auth-clerk
jazz-tools:
specifier: workspace:*
@@ -770,10 +770,10 @@ importers:
specifier: workspace:*
version: link:../../packages/jazz-inspector
jazz-react:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-react
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-tools
lucide-react:
specifier: ^0.274.0
@@ -1012,10 +1012,10 @@ importers:
examples/password-manager:
dependencies:
jazz-react:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-react
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-tools
react:
specifier: 18.3.1
@@ -1076,13 +1076,13 @@ importers:
specifier: ^2.0.0
version: 2.1.1
jazz-browser-media-images:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-browser-media-images
jazz-react:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-react
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-tools
lucide-react:
specifier: ^0.274.0
@@ -1137,7 +1137,7 @@ importers:
specifier: ^3.0.1
version: 3.0.1
jazz-run:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-run
postcss:
specifier: ^8.4.27
@@ -1216,10 +1216,10 @@ importers:
specifier: ^2.0.0
version: 2.1.1
jazz-react:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-react
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../../packages/jazz-tools
lucide-react:
specifier: ^0.274.0
@@ -1558,10 +1558,10 @@ importers:
specifier: workspace:0.10.8
version: link:../cojson
jazz-browser:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-browser
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-tools
devDependencies:
typescript:
@@ -1599,10 +1599,10 @@ importers:
specifier: ^4.1.0
version: 4.1.0
jazz-browser:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-browser
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-tools
pica:
specifier: ^9.0.1
@@ -1677,13 +1677,13 @@ importers:
specifier: workspace:0.10.8
version: link:../cojson
jazz-browser:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-browser
jazz-react-core:
specifier: workspace:*
version: link:../jazz-react-core
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-tools
devDependencies:
'@testing-library/dom':
@@ -1884,7 +1884,7 @@ importers:
specifier: ^3.6.5
version: 3.11.9
jazz-tools:
specifier: workspace:0.10.12
specifier: workspace:0.10.13
version: link:../jazz-tools
ws:
specifier: ^8.14.2

View File

@@ -1,5 +1,13 @@
# jazz-tailwind-demo-auth-starter
## 0.0.50
### Patch Changes
- Updated dependencies [07feedd]
- jazz-tools@0.10.13
- jazz-react@0.10.13
## 0.0.49
### Patch Changes

View File

@@ -1,7 +1,7 @@
{
"name": "jazz-tailwind-demo-auth-starter",
"private": true,
"version": "0.0.49",
"version": "0.0.50",
"type": "module",
"scripts": {
"dev": "vite",