UNPKG

800 BPlain TextView Raw
1import { fromJose, hexToBytes } from '../util.js'
2import type { Signer } from '../JWT.js'
3import { ES256KSigner } from './ES256KSigner.js'
4
5/**
6 * @deprecated Please use ES256KSigner
7 * The SimpleSigner returns a configured function for signing data.
8 *
9 * @example
10 * const signer = SimpleSigner(process.env.PRIVATE_KEY)
11 * signer(data, (err, signature) => {
12 * ...
13 * })
14 *
15 * @param {String} hexPrivateKey a hex encoded private key
16 * @return {Function} a configured signer function
17 */
18function SimpleSigner(hexPrivateKey: string): Signer {
19 const signer = ES256KSigner(hexToBytes(hexPrivateKey), true)
20 return async (data) => {
21 const signature = (await signer(data)) as string
22 return fromJose(signature)
23 }
24}
25
26export default SimpleSigner