TS JOSE
Wrap functions of JOSE in steady interface.
JWT
verify
ref
const options = {
algorithms: ['a1', 'a2'],
audience: 'hi',
clockTolerance: '3s',
complete: true,
crit: { 'some-key': true },
currentDate: new Date(),
issuer: 'some-issuer',
jti: 'some-token-id',
maxTokenAge: '5m',
subject: 'some-user-id',
typ: 'ac+jwt',
};
await JWT.verify(token, key, options);
await JWT.verify(token, undefined, options);
sign
ref
const options = {
alg: 'ES256',
audience: 'hi',
exp: '3h',
iat: 123,
issuer: 'some-issuer',
jti: 'some-token-id',
jwk: true,
kid: 'some-key-id',
notBefore: '1s',
subject: 'some-user-id',
typ: 'ac+jwt',
};
await JWT.sign(payload, key, options);
decrypt
ref
const options = {
audience: 'hi',
clockTolerance: '3s',
complete: true,
enc: ['A128GCM'],
crit: { 'some-key': true },
currentDate: new Date(),
issuer: 'some-issuer',
jti: 'some-token-id',
alg: ['ECDH-ES+A128KW'],
kid: 'some-key-id',
maxTokenAge: '5m',
typ: 'ac+jwt',
};
await JWT.decrypt(cypher, key, options);
encrypt
ref
const options = {
alg: 'A128GCMKW',
audience: 'hi',
crit: { 'some-key': true },
enc: 'A128CBC-HS256',
exp: '3h',
iat: 123,
issuer: 'some-issuer',
jti: 'some-token-id',
kid: 'some-key-id',
notBefore: '1s',
};
await JWT.encrypt(payload, key, options);
JWS
You can sign pure string.
verify
ref
const options = {
algorithms: ['ES256', 'ES192'],
crit: { key: true },
typ: 'some-type',
};
await JWS.verify(data, key, options);
sign
ref
const options = {
alg: 'ES256',
kid: 'some-key-id',
jwk: true,
typ: 'some-type',
};
await JWS.sign('some-data', key, options);
JWE
You can encrypt pure string.
decrypt
ref
const options = {
alg: 'ECDH-ES+A128KW',
enc: ['A128GCM'],
kid: 'some-key-id',
};
await JWE.decrypt(cypher, key, options);
encrypt
ref
const options = {
alg: 'ECDH-ES+A128KW',
enc: 'A128GCM',
crit: { 'some-key': true },
kid: 'some-key-id',
};
await JWE.encrypt(cypher, key, options);
JWK
ref
await JWK.generate('ES256', {
kid: 'some-id',
use: 'sig',
});
await JWK.fromObject({
kid: 'some-id',
alg: 'ES256',
kty: 'EC',
crv: 'P-256',
x: '123',
y: '456',
d: '789',
});
key.toObject(false);
await key.toPublic();
key.isisPrivate;
try {
key.getKey({
kid: 'some-id',
use: 'sig',
alg: 'ES256',
});
} catch (err) {
}
JWKS
const keys = await JWKS.fromObject('ES256', {
keys: [
{
alg: 'ES256',
kty: 'EC',
x: '123',
y: '456',
},
],
});
keys.getKey({ kid: 'some-id', use: 'sig', alg: 'ES256' });
keys.getKeyByKid('some-id');
keys.getKeyByUse('sig');
keys.getKeyByAlg('ES256');