Skip to content

Commit

Permalink
Add getChallenge (#339)
Browse files Browse the repository at this point in the history
* Add getChallenge

* Fix lint
  • Loading branch information
hundredark authored Mar 11, 2024
1 parent da7445b commit b9024eb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import forge from 'node-forge';
import { validate } from 'uuid';
import type { Keystore, AppKeystore, OAuthKeystore, NetworkUserKeystore } from '../types/keystore';
import { base64RawURLEncode } from './base64';
import { sha256Hash } from './uniq';

export const getED25519KeyPair = () => {
const seed = Buffer.from(forge.random.getBytesSync(32), 'binary');
Expand All @@ -14,6 +15,13 @@ export const getED25519KeyPair = () => {
};
};

export const getChallenge = () => {
const seed = Buffer.from(forge.random.getBytesSync(32), 'binary');
const verifier = base64RawURLEncode(seed);
const challenge = base64RawURLEncode(sha256Hash(seed));
return { verifier, challenge };
};

const signToken = (payload: Object, private_key: string): string => {
const header = base64RawURLEncode(serialize({ alg: 'EdDSA', typ: 'JWT' }));
const payloadStr = base64RawURLEncode(serialize(payload));
Expand Down

0 comments on commit b9024eb

Please sign in to comment.