mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 07:57:59 +00:00
ec06da0ebc
- Package namespace: @polkadot/* -> @pezkuwi/* - Repository: polkadot-js/common -> pezkuwichain/pezkuwi-common - Author: Pezkuwi Team <team@pezkuwichain.io> Core packages: - @pezkuwi/util (utilities) - @pezkuwi/util-crypto (crypto primitives) - @pezkuwi/keyring (account management) - @pezkuwi/networks (chain metadata) - @pezkuwi/hw-ledger (Ledger hardware wallet) - @pezkuwi/x-* (10 polyfill packages) Total: 14 packages Upstream: polkadot-js/common v14.0.1
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Keypair } from '../../types.js';
|
|
|
|
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: Uint8Array, onlyJs?: boolean): Keypair {
|
|
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])
|
|
};
|
|
}
|