Skip to content

Commit ee77c84

Browse files
committedMar 13, 2025
update keys
1 parent 84cb592 commit ee77c84

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed
 

‎README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ ENCRYPTION_KEY= # encryption key for the local database
2626
You can generate random keys with the following command:
2727

2828
```bash
29-
yarn gen:keys
29+
yarn gen:keys <name>
3030
```
3131

32+
> [!TIP]
33+
> Running the `gen:keys` or `gen:keys <name>` command will write to the existing `.env` file.
34+
3235
### Fetching messages
3336

3437
There are to ways to fetch messages from a conversation, one is by starting a stream

‎scripts/generateKeys.ts

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
import { writeFile } from "node:fs/promises";
22
import { join } from "node:path";
3-
import { generatePrivateKey } from "viem/accounts";
3+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
44
import { generateEncryptionKeyHex } from "@/helpers";
55

66
console.log("Generating keys...");
77

8+
const person = process.argv[2];
89
const walletKey = generatePrivateKey();
10+
const account = privateKeyToAccount(walletKey);
911
const encryptionKeyHex = generateEncryptionKeyHex();
12+
const publicKey = account.address;
1013

1114
const filePath = join(process.cwd(), ".env");
1215

13-
await writeFile(
14-
filePath,
15-
`WALLET_KEY=${walletKey}
16+
// Format the environment variables based on whether a person name was provided
17+
let envContent;
18+
if (person) {
19+
envContent = `# ${person.toLowerCase()}
20+
WALLET_KEY_${person.toUpperCase()}=${walletKey}
21+
ENCRYPTION_KEY_${person.toUpperCase()}=${encryptionKeyHex}
22+
# public key is ${publicKey}
23+
`;
24+
} else {
25+
envContent = `# generic keys
26+
WALLET_KEY=${walletKey}
1627
ENCRYPTION_KEY=${encryptionKeyHex}
17-
`,
18-
{
19-
flag: "a",
20-
},
21-
);
28+
# public key is ${publicKey}
29+
`;
30+
}
2231

23-
console.log(`Keys written to ${filePath}`);
32+
await writeFile(filePath, envContent, { flag: "a" });
33+
34+
// Log appropriate message based on whether a person name was provided
35+
if (person) {
36+
console.log(`Keys for ${person} written to ${filePath}`);
37+
} else {
38+
console.log(`Generic keys written to ${filePath}`);
39+
}

0 commit comments

Comments
 (0)