* Use @noble/curves (secp256k1 only for now) * Re-add canonical signatures (now lowS) * Swap tweetnacl usage for ed25519 * Adjust previously failing tests * Adjust test for ethereum encoding * hasBigInt for ed25519 operations * CHANGELOG * Publich beta to npm for size check
30 lines
791 B
TypeScript
30 lines
791 B
TypeScript
// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Keypair } from '../../types.js';
|
|
|
|
/**
|
|
* @name ed25519PairFromSecret
|
|
* @summary Creates a new public/secret keypair from a secret.
|
|
* @description
|
|
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied secret.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { ed25519PairFromSecret } from '@polkadot/util-crypto';
|
|
*
|
|
* ed25519PairFromSecret(...); // => { secretKey: [...], publicKey: [...] }
|
|
* ```
|
|
*/
|
|
export function ed25519PairFromSecret (secretKey: Uint8Array): Keypair {
|
|
if (secretKey.length !== 64) {
|
|
throw new Error('Invalid secretKey provided');
|
|
}
|
|
|
|
return {
|
|
publicKey: secretKey.slice(32),
|
|
secretKey
|
|
};
|
|
}
|