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