UNPKG

896 BPlain TextView Raw
1import { EdDSASigner as EdDSASigner } from './EdDSASigner.js'
2import type { Signer } from '../JWT.js'
3import { base64ToBytes } from '../util.js'
4
5/**
6 * @deprecated Please use EdDSASigner
7 *
8 * The NaclSigner returns a configured function for signing data using the Ed25519 algorithm.
9 *
10 * The signing function itself takes the data as a `string` or `Uint8Array` parameter and returns a
11 * `base64Url`-encoded signature.
12 *
13 * @example
14 * const signer = NaclSigner(process.env.PRIVATE_KEY)
15 * const data: string = '...'
16 * signer(data).then( (signature: string) => {
17 * ...
18 * })
19 *
20 * @param {String} base64PrivateKey a 64 byte base64 encoded private key
21 * @return {Function} a configured signer function
22 */
23
24function NaclSigner(base64PrivateKey: string): Signer {
25 return EdDSASigner(base64ToBytes(base64PrivateKey))
26}
27
28export default NaclSigner