TS JOSE
Wrap functions of JOSE in steady interface.
[!Note]
This package's version will FOLLOW the version of JOSE
JWT
verify
JOSE ref
Additional options
name | Description |
---|
kid | Using specific key in JWKS |
jti | Verify payload jti |
await JWT.verify(token, key, options);
await JWT.verify(token, undefined, options);
sign
Using JOSE options
name | Referrer |
---|
issuer | setIssuer |
audience | setAudience |
subject | setSubject |
exp | setExpirationTime |
jti | setJti |
notBefore | setNotBefore |
iat | setIssuedAt |
typ | Header |
kid | Header |
alg | Header |
Additional options
name | type | default | description |
---|
jwk | boolean | false | Whether embedded key to header |
await JWT.sign(payload, key, options);
decrypt
JOSE ref
Additional options
name | Description |
---|
kid | Using specific key in JWKS |
enc | Encrypt algorithm |
alg | Key management algorithm |
await JWT.decrypt(cypher, key, options);
encrypt
JOSE ref
Using JOSE options
name | Referrer |
---|
issuer | setIssuer |
audience | setAudience |
subject | setSubject |
exp | setExpirationTime |
jti | setJti |
notBefore | setNotBefore |
iat | setIssuedAt |
typ | Header |
kid | Header |
enc | Header |
alg | Header |
await JWT.encrypt(payload, key, options);
JWS
You can sign pure string.
verify
JOSE ref
await JWS.verify(data, key, options);
sign
JOSE ref
Only using below JWT.sign's options:
await JWS.sign('some-data', key, options);
JWE
You can encrypt pure string.
decrypt
JOSE ref
Additional options
Same as JWT.decrypt
await JWE.decrypt(cypher, key, options);
encrypt
JOSE ref
Only using below JWT.encrypt's options:
await JWE.encrypt('some-data', key, options);
JWK
JOSE ref
const key: JWK = await JWK.generate('ES256', {
kid: 'some-id',
use: 'sig',
});
const key: JWK = await JWK.fromObject({
kid: 'some-id',
alg: 'ES256',
kty: 'EC',
crv: 'P-256',
x: '123',
y: '456',
d: '789',
});
const keyObject: JWKObject = key.toObject(false);
const newKey: JWK = await key.toPublic();
key.isPrivate;
try {
key.getKey({ kid: 'some-id', use: 'sig', alg: 'ES256' });
} catch (err) {
}
JWKS
const keys = await JWKS.fromObject({
keys: [
{
alg: 'ES256',
kty: 'EC',
x: '123',
y: '456',
},
],
});
try {
const key: JWK = keys.getKey({ kid: 'some-id', use: 'sig', alg: 'ES256' });
} catch (err) {
}
const key: JWK = keys.getKeyByKid('some-id');
const key: JWK = keys.getKeyByUse('sig');
const key: JWK = keys.getKeyByAlg('ES256');
const publicKeys = await keys.toPublic();