-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateKeys.ts
More file actions
24 lines (22 loc) · 829 Bytes
/
generateKeys.ts
File metadata and controls
24 lines (22 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { getRandomValues } from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { toString } from "uint8arrays";
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
/**
* Generate a random encryption key
* @returns The encryption key
*/
export const generateEncryptionKeyHex = () => {
/* Generate a random encryption key */
const uint8Array = getRandomValues(new Uint8Array(32));
/* Convert the encryption key to a hex string */
return toString(uint8Array, "hex");
};
export const xmtpKeys = () => {
const walletKey = generatePrivateKey();
const account = privateKeyToAccount(walletKey);
const encryptionKeyHex = generateEncryptionKeyHex();
const publicKey = account.address;
return { walletKey, encryptionKeyHex, publicKey };
};