mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-11-08 16:31:15 +00:00
The header rule takes the current year as the end of the range, as upstream's does; 581 sources still ended at 2025, which failed lint. Lint never ran to completion here, so this went unseen. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Keypair } from '../types.js';
|
|
|
|
import { ed25519 } from '@noble/curves/ed25519';
|
|
|
|
import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
|
|
import { ed25519Sign as wasmSign, isReady } from '@pezkuwi/wasm-crypto';
|
|
|
|
/**
|
|
* @name ed25519Sign
|
|
* @summary Signs a message using the supplied secretKey
|
|
* @description
|
|
* Returns message signature of `message`, using the `secretKey`.
|
|
* @example
|
|
* <BR>
|
|
*
|
|
* ```javascript
|
|
* import { ed25519Sign } from '@pezkuwi/util-crypto';
|
|
*
|
|
* ed25519Sign([...], [...]); // => [...]
|
|
* ```
|
|
*/
|
|
export function ed25519Sign (message: string | Uint8Array, { publicKey, secretKey }: Partial<Keypair>, onlyJs?: boolean): Uint8Array {
|
|
if (!secretKey) {
|
|
throw new Error('Expected a valid secretKey');
|
|
} else if (!publicKey) {
|
|
throw new Error('Expected a valid publicKey');
|
|
}
|
|
|
|
const messageU8a = u8aToU8a(message);
|
|
const privateU8a = secretKey.subarray(0, 32);
|
|
|
|
return !hasBigInt || (!onlyJs && isReady())
|
|
? wasmSign(publicKey, privateU8a, messageU8a)
|
|
: ed25519.sign(messageU8a, privateU8a);
|
|
}
|