Class: ClientKey

ClientKey(alg, privateKey, publicJwk, thumbprint)

The client instance's key (RFC 9635 section 7.1). In GNAP the key IS the client: it is presented by value in the first request, and every request after is signed with it, so each token the AS issues is bound to it. This library proves it with HTTP message signatures (httpsig, RFC 9421).

The private key is generated NON-EXTRACTABLE: script running in the page (including injected script) can ask it to sign while the page is open, but can never read it out, so a stolen access token or continuation token is useless anywhere else. IndexedDBKeyStore keeps that non-extractable key across page loads. WebStorageKeyStore keeps an extractable copy in sessionStorage for this tab, which is what Web Storage can hold.

The JWK's kid is its RFC 7638 thumbprint, and is the keyid of every signature.

Constructor

new ClientKey(alg, privateKey, publicJwk, thumbprint)

Use ClientKey.create() or ClientKey.loadOrCreate() rather than this.

Parameters:
Name Type Description
alg string
privateKey CryptoKey
publicJwk Record.<string, any>
thumbprint string
Source:

Classes

ClientKey

Members

alg :string

Type:
  • string
Source:

keyPair :CryptoKeyPair|undefined

Type:
  • CryptoKeyPair | undefined
Source:

publicJwk

The public JWK, with alg and kid. @type {Record<string, any>}

Source:

thumbprint

RFC 7638 SHA-256 thumbprint of the public key; also its kid. @type {string}

Source:

Methods

keyObject() → {Object}

The key object a grant request carries by value (RFC 9635 section 7.1): the proof method and the public JWK. Register exactly this on the AS (iya-sts: the application's gnapKey).

Source:
Returns:
Type
Object

(async) sign(data) → {Promise.<Uint8Array>}

Signs bytes with the private key, as RFC 9421 section 3.3.7 does for a JWS algorithm: ECDSA signatures are the raw r || s concatenation, which is what WebCrypto produces.

Parameters:
Name Type Description
data Uint8Array
Source:
Returns:
Type
Promise.<Uint8Array>

(async, static) create(optsopt) → {Promise.<ClientKey>}

Builds a key from a CryptoKeyPair, generating a new pair if none is given. Generated keys are non-extractable unless extractable is set, which sessionStorage requires.

Parameters:
Name Type Attributes Description
opts Object <optional>

(TypeScript: { alg?: string, keyPair?: CryptoKeyPair, extractable?: boolean })

Source:
Returns:
Type
Promise.<ClientKey>

(async, static) loadOrCreate(store, optsopt) → {Promise.<ClientKey>}

Loads the key held in store, or creates one and stores it.

Parameters:
Name Type Attributes Description
store KeyStore
opts Object <optional>

(TypeScript: { alg?: string })

Source:
Returns:
Type
Promise.<ClientKey>