mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-28 12:07:58 +00:00
32 lines
985 B
JavaScript
32 lines
985 B
JavaScript
import { ed25519 } from '@noble/curves/ed25519';
|
|
import { hasBigInt, u8aConcatStrict } from '@pezkuwi/util';
|
|
import { ed25519KeypairFromSeed, isReady } from '@pezkuwi/wasm-crypto';
|
|
/**
|
|
* @name ed25519PairFromSeed
|
|
* @summary Creates a new public/secret keypair from a seed.
|
|
* @description
|
|
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { ed25519PairFromSeed } from '@pezkuwi/util-crypto';
|
|
*
|
|
* ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
|
|
* ```
|
|
*/
|
|
export function ed25519PairFromSeed(seed, onlyJs) {
|
|
if (!hasBigInt || (!onlyJs && isReady())) {
|
|
const full = ed25519KeypairFromSeed(seed);
|
|
return {
|
|
publicKey: full.slice(32),
|
|
secretKey: full.slice(0, 64)
|
|
};
|
|
}
|
|
const publicKey = ed25519.getPublicKey(seed);
|
|
return {
|
|
publicKey,
|
|
secretKey: u8aConcatStrict([seed, publicKey])
|
|
};
|
|
}
|