19 lines
721 B
TypeScript
19 lines
721 B
TypeScript
|
|
import { ed25519 } from '@noble/curves/ed25519.js';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Deterministically derive an Ed25519 public key from a 32-byte seed.
|
||
|
|
*
|
||
|
|
* In the @noble/curves convention the "private key" *is* the seed —
|
||
|
|
* `sign(seed, msg)` works directly, and `getPublicKey(seed)` recovers
|
||
|
|
* the matching public key. V4.9's encrypted-blob primitive uses this
|
||
|
|
* to mint a per-slot signing keypair from an HKDF output rooted at the
|
||
|
|
* user's master key, so the same credentials always reproduce the same
|
||
|
|
* keypair.
|
||
|
|
*/
|
||
|
|
export function ed25519PublicKeyFromSeed(seed: Uint8Array): Uint8Array {
|
||
|
|
if (seed.length !== 32) {
|
||
|
|
throw new Error(`Ed25519 seed must be 32 bytes, got ${seed.length}`);
|
||
|
|
}
|
||
|
|
return ed25519.getPublicKey(seed);
|
||
|
|
}
|