mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
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]>
75 lines
2.2 KiB
Markdown
75 lines
2.2 KiB
Markdown
# Class: GeneralSign
|
||
|
||
## [💗 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 GeneralSign class is used to build and sign General 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/general/sign'`.
|
||
|
||
## Example
|
||
|
||
```js
|
||
const jws = await new jose.GeneralSign(
|
||
new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
|
||
)
|
||
.addSignature(ecPrivateKey)
|
||
.setProtectedHeader({ alg: 'ES256' })
|
||
.addSignature(rsaPrivateKey)
|
||
.setProtectedHeader({ alg: 'PS256' })
|
||
.sign()
|
||
|
||
console.log(jws)
|
||
```
|
||
|
||
## Constructors
|
||
|
||
### Constructor
|
||
|
||
â–¸ **new GeneralSign**(`payload`): `GeneralSign`
|
||
|
||
GeneralSign 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
|
||
|
||
`GeneralSign`
|
||
|
||
## Methods
|
||
|
||
### addSignature()
|
||
|
||
â–¸ **addSignature**(`key`, `options?`): [`Signature`](../interfaces/Signature.md)
|
||
|
||
Adds an additional signature for the General JWS object.
|
||
|
||
#### Parameters
|
||
|
||
| Parameter | Type | Description |
|
||
| ------ | ------ | ------ |
|
||
| `key` | [`KeyInput`](../../../../types/type-aliases/KeyInput.md) | Private Key or Secret to sign the individual JWS signature with. See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210#jws-alg). |
|
||
| `options?` | [`SignOptions`](../../../../types/interfaces/SignOptions.md) | JWS Sign options. |
|
||
|
||
#### Returns
|
||
|
||
[`Signature`](../interfaces/Signature.md)
|
||
|
||
***
|
||
|
||
### sign()
|
||
|
||
â–¸ **sign**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`GeneralJWS`](../../../../types/interfaces/GeneralJWS.md)\>
|
||
|
||
Signs and resolves the value of the General JWS object.
|
||
|
||
#### Returns
|
||
|
||
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`GeneralJWS`](../../../../types/interfaces/GeneralJWS.md)\>
|