# Class: CompactSign ## [💗 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 CompactSign class is used to build and sign Compact JWS strings. This class is exported (as a named export) from the main `'jose'` module entry point as well as from its subpath export `'jose/jws/compact/sign'`. ## Example ```js 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) ``` ## Constructors ### Constructor ▸ **new CompactSign**(`payload`): `CompactSign` CompactSign 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 `CompactSign` ## Methods ### setProtectedHeader() ▸ **setProtectedHeader**(`protectedHeader`): `this` Sets the JWS Protected Header on the CompactSign object. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `protectedHeader` | [`CompactJWSHeaderParameters`](../../../../types/interfaces/CompactJWSHeaderParameters.md) | JWS Protected Header. | #### Returns `this` *** ### sign() ▸ **sign**(`key`, `options?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\> Signs and resolves the value of the Compact JWS string. #### Parameters | Parameter | Type | Description | | ------ | ------ | ------ | | `key` | [`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) \| [`CryptoKey`](https://developer.mozilla.org/docs/Web/API/CryptoKey) \| [`JWK`](../../../../types/interfaces/JWK.md) \| [`KeyObject`](../../../../types/interfaces/KeyObject.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)\<`string`\>