jws/compact/sign.CompactSign
The CompactSign class is a utility for creating Compact JWS strings.
example
ESM import
import { CompactSign } from 'jose/jws/compact/sign'
example
CJS import
const { CompactSign } = require('jose/jws/compact/sign')
example
Usage
const encoder = new TextEncoder()
const jws = await new CompactSign(encoder.encode('It’s a dangerous business, Frodo, going out your door.'))
.setProtectedHeader({ alg: 'ES256' })
.sign(privateKey)
console.log(jws)
• new CompactSign(payload
)
Name | Type | Description |
---|---|---|
payload |
Uint8Array |
Binary representation of the payload to sign. |
▸ setProtectedHeader(protectedHeader
): CompactSign
Sets the JWS Protected Header on the Sign object.
Name | Type | Description |
---|---|---|
protectedHeader |
JWSHeaderParameters |
JWS Protected Header. |
▸ sign(key
, options?
): Promise
<string
>
Signs and resolves the value of the Compact JWS string.
Name | Type | Description |
---|---|---|
key |
KeyLike |
Private Key or Secret to sign the JWS with. |
options? |
SignOptions |
JWS Sign options. |
Promise
<string
>