mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
2.4 KiB
2.4 KiB
Class: CompactSign
💗 Help the project
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
The CompactSign class is used to build and sign Compact JWS strings.
Example
const jws = await new jose.CompactSign(
new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
.setProtectedHeader({ alg: 'ES256' })
.sign(privateKey)
console.log(jws)
Table of contents
Constructors
Methods
Constructors
constructor
• new CompactSign(payload)
Parameters
| Name | Type | Description |
|---|---|---|
payload |
Uint8Array |
Binary representation of the payload to sign. |
Methods
setProtectedHeader
â–¸ setProtectedHeader(protectedHeader): CompactSign
Sets the JWS Protected Header on the Sign object.
Parameters
| Name | Type | Description |
|---|---|---|
protectedHeader |
CompactJWSHeaderParameters |
JWS Protected Header. |
Returns
sign
â–¸ sign(key, options?): Promise<string>
Signs and resolves the value of the Compact JWS string.
Parameters
| Name | Type | Description |
|---|---|---|
key |
Uint8Array | KeyLike |
Private Key or Secret to sign the JWS with. See Algorithm Key Requirements. |
options? |
SignOptions |
JWS Sign options. |
Returns
Promise<string>