1 | import { fromJose, hexToBytes } from '../util.js'
|
2 | import type { Signer } from '../JWT.js'
|
3 | import { 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 | */
|
18 | function 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 |
|
26 | export default SimpleSigner
|