Files
Filip Skokan acb2913e8e refactor(types): improve key and result inference
Thread resolver return types through verify and decrypt results. Add
overloads so wrappers can forward either keys or resolvers.

Infer importJWK and generateSecret results from their inputs. Keep JWT
payload generics unconstrained while rejecting known non-object shapes.

Signed-off-by: Filip Skokan <[email protected]>
2026-07-29 18:50:54 +02:00

96 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Class: FlattenedSign
## [💗 Help the project](https://github.com/sponsors/panva)
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](https://github.com/sponsors/panva).
The FlattenedSign class is used to build and sign Flattened JWS objects.
This class is exported (as a named export) from the main `'jose'` module entry point as well as
from its subpath export `'jose/jws/flattened/sign'`.
## Example
```js
const jws = await new jose.FlattenedSign(
new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
)
.setProtectedHeader({ alg: 'ES256' })
.sign(privateKey)
console.log(jws)
```
## Constructors
### Constructor
â–¸ **new FlattenedSign**(`payload`): `FlattenedSign`
FlattenedSign constructor
#### Parameters
| Parameter | Type | Description |
| ------ | ------ | ------ |
| `payload` | [`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | Binary representation of the payload to sign. |
#### Returns
`FlattenedSign`
## Methods
### setProtectedHeader()
â–¸ **setProtectedHeader**(`protectedHeader`): `this`
Sets the JWS Protected Header on the FlattenedSign object.
#### Parameters
| Parameter | Type | Description |
| ------ | ------ | ------ |
| `protectedHeader` | [`JWSHeaderParameters`](../../../../types/interfaces/JWSHeaderParameters.md) | JWS Protected Header. |
#### Returns
`this`
***
### setUnprotectedHeader()
â–¸ **setUnprotectedHeader**(`unprotectedHeader`): `this`
Sets the JWS Unprotected Header on the FlattenedSign object.
#### Parameters
| Parameter | Type | Description |
| ------ | ------ | ------ |
| `unprotectedHeader` | [`JWSHeaderParameters`](../../../../types/interfaces/JWSHeaderParameters.md) | JWS Unprotected Header. |
#### Returns
`this`
***
### sign()
â–¸ **sign**(`key`, `options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`FlattenedJWS`](../../../../types/interfaces/FlattenedJWS.md)\>
Signs and resolves the value of the Flattened JWS object.
#### Parameters
| Parameter | Type | Description |
| ------ | ------ | ------ |
| `key` | [`KeyInput`](../../../../types/type-aliases/KeyInput.md) | Private Key or Secret to sign the JWS with. See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210#jws-alg). |
| `options?` | [`SignOptions`](../../../../types/interfaces/SignOptions.md) | JWS Sign options. |
#### Returns
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`FlattenedJWS`](../../../../types/interfaces/FlattenedJWS.md)\>