Skip to content

Commit 47131ec

Browse files
committed
docs: correct argon2 example
1 parent b4b5000 commit 47131ec

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a client and server implementation of 1Password's [fantastic SRP library
88

99
SRP is a fascinating protocol. I highly recommend reading through [1Password's explainer](https://blog.1password.com/developers-how-we-use-srp-and-you-can-too/) to get familiar with its innerworkings and processes first.
1010

11-
## Step 1: Pick a group
11+
### Step 1: Pick a group
1212

1313
This library uses RFC 5054 groups between 2048 and 8192 bits. 4096 and above are highly recommended. Any lower is unlikely to be secure for the near future.
1414

@@ -20,19 +20,31 @@ import { knownGroups } from "secure-remote-password-js";
2020
const group = knownGroups[4096];
2121
```
2222

23-
## Step 2: Pick a KDF
23+
### Step 2: Pick a KDF
2424

2525
You'll need a Key Derivation Function (KDF) to convert your password into a secure format. While this library includes a simple KDF for testing, you should use a strong KDF like Argon2id, bcrypt, or scrypt in production.
2626

2727
[@phi-ag/argon2](https://github.com/phi-ag/argon2) is a great library for Argon2 in TS.
2828

2929
```typescript
30-
import { argon2id } from "@phi-ag/argon2";
31-
32-
const x = argon2id.hash(password, salt);
30+
import { Argon2Type } from "@phi-ag/argon2";
31+
import wasm from "@phi-ag/argon2/argon2.wasm?url";
32+
import initialize from "@phi-ag/argon2/fetch";
33+
34+
const argon2 = await initialize(wasm);
35+
const hash = argon2.hash(password, {
36+
salt,
37+
memoryCost: 64 * 1024,
38+
timeCost: 1,
39+
parallelism: 4,
40+
hashLength: 32,
41+
type: Argon2Type.Argon2id,
42+
});
43+
44+
return hash;
3345
```
3446

35-
## Step 3: Initialize SRP Client
47+
### Step 3: Initialize SRP Client
3648

3749
Create an SRP client instance for both server and client sides:
3850

@@ -47,7 +59,7 @@ const verifier = client.verifier(); // Generate this during registration
4759
const server = new SrpClient(knownGroups[4096], verifier, undefined, "server");
4860
```
4961

50-
## Step 4: Exchange Public Keys
62+
### Step 4: Exchange Public Keys
5163

5264
Exchange ephemeral public keys between client and server:
5365

@@ -63,7 +75,7 @@ client.setOthersPublic(serverPublicB);
6375
server.setOthersPublic(clientPublicA);
6476
```
6577

66-
## Step 5: Generate Session Key
78+
### Step 5: Generate Session Key
6779

6880
Both sides can now generate the shared session key:
6981

@@ -72,7 +84,7 @@ Both sides can now generate the shared session key:
7284
const key = client.getKey(); // or server.getKey()
7385
```
7486

75-
## Step 6: Verify Both Parties
87+
### Step 6: Verify Both Parties
7688

7789
Finally, verify that both parties derived the same key:
7890

0 commit comments

Comments
 (0)