jose/docs/classes/jws_compact_sign.CompactSign.md
2021-11-11 22:10:41 +01:00

76 lines
1.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: CompactSign
The CompactSign class is a utility for creating Compact JWS strings.
**`example`** Usage
```js
const jws = await new jose.CompactSign(
new TextEncoder().encode(
'Its a dangerous business, Frodo, going out your door.'
)
)
.setProtectedHeader({ alg: 'ES256' })
.sign(privateKey)
console.log(jws)
```
## Table of contents
### Constructors
- [constructor](jws_compact_sign.CompactSign.md#constructor)
### Methods
- [setProtectedHeader](jws_compact_sign.CompactSign.md#setprotectedheader)
- [sign](jws_compact_sign.CompactSign.md#sign)
## Constructors
### constructor
**new CompactSign**(`payload`)
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `payload` | `Uint8Array` | Binary representation of the payload to sign. |
## Methods
### setProtectedHeader
**setProtectedHeader**(`protectedHeader`): [`CompactSign`](jws_compact_sign.CompactSign.md)
Sets the JWS Protected Header on the Sign object.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `protectedHeader` | [`CompactJWSHeaderParameters`](../interfaces/types.CompactJWSHeaderParameters.md) | JWS Protected Header. |
#### Returns
[`CompactSign`](jws_compact_sign.CompactSign.md)
___
### sign
**sign**(`key`, `options?`): `Promise`<`string`\>
Signs and resolves the value of the Compact JWS string.
#### Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| `key` | [`KeyLike`](../types/types.KeyLike.md) \| `Uint8Array` | Private Key or Secret to sign the JWS with. |
| `options?` | [`SignOptions`](../interfaces/types.SignOptions.md) | JWS Sign options. |
#### Returns
`Promise`<`string`\>