Back to Jose

Class: GeneralSign

docs/jws/general/sign/classes/GeneralSign.md

6.2.122.1 KB
Original Source

Class: GeneralSign

πŸ’— 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.

Builds and signs 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

Creates a General JWS signer.

Parameters

ParameterTypeDescription
payloadUint8ArrayBinary representation of the payload to sign.

Returns

GeneralSign

Methods

addSignature()

β–Έ addSignature(key, options?): Signature

Adds a signature and returns its configuration.

Parameters

ParameterTypeDescription
keyKeyInputPrivate key or shared secret. See Algorithm Key Requirements.
options?SignOptionsJWS Sign options.

Returns

Signature


sign()

β–Έ sign(): Promise<GeneralJWS>

Signs the payload as a General JWS.

Returns

Promise<GeneralJWS>