@sphereon/ssi-sdk-ext.jwt-service
Version:
75 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JweEncs = exports.JweAlgs = exports.COMPACT_JWE_REGEX = exports.COMPACT_JWS_REGEX = exports.jwtServiceContextMethods = void 0;
exports.isJwsCompact = isJwsCompact;
exports.isJweCompact = isJweCompact;
exports.isJwsJsonFlattened = isJwsJsonFlattened;
exports.isJwsJsonGeneral = isJwsJsonGeneral;
exports.isJweJsonFlattened = isJweJsonFlattened;
exports.isJweJsonGeneral = isJweJsonGeneral;
exports.isJwsHeader = isJwsHeader;
exports.isJweHeader = isJweHeader;
exports.jweAlg = jweAlg;
exports.jweEnc = jweEnc;
exports.jwtServiceContextMethods = [
'jwtPrepareJws',
'jwtCreateJwsJsonGeneralSignature',
'jwtCreateJwsJsonFlattenedSignature',
'jwtCreateJwsCompactSignature',
'jwtVerifyJwsSignature',
'jwtEncryptJweCompactJwt',
'jwtDecryptJweCompactJwt',
];
function isJwsCompact(jws) {
return typeof jws === 'string' && jws.split('~')[0].match(exports.COMPACT_JWS_REGEX) !== null;
}
function isJweCompact(jwe) {
return typeof jwe === 'string' && jwe.split('~')[0].match(exports.COMPACT_JWE_REGEX) !== null;
}
function isJwsJsonFlattened(jws) {
return typeof jws === 'object' && 'signature' in jws && 'protected' in jws && !('ciphertext' in jws);
}
function isJwsJsonGeneral(jws) {
return typeof jws === 'object' && 'signatures' in jws && !('ciphertext' in jws);
}
function isJweJsonFlattened(jwe) {
return typeof jwe === 'object' && 'signature' in jwe && 'ciphertext' in jwe && !('payload' in jwe);
}
function isJweJsonGeneral(jwe) {
return typeof jwe === 'object' && 'signatures' in jwe && 'ciphertext' in jwe && !('payload' in jwe);
}
function isJwsHeader(header) {
return header && !isJweHeader(header);
}
function isJweHeader(header) {
return ('enc' in header && header.enc && jweEnc(header.enc)) || (header.alg && jweAlg(header.alg));
}
exports.COMPACT_JWS_REGEX = /^([a-zA-Z0-9_=-]+).([a-zA-Z0-9_=-]+)?.([a-zA-Z0-9_=-]+)?$/;
exports.COMPACT_JWE_REGEX = /^([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)\.([a-zA-Z0-9_=-]+)?\.([a-zA-Z0-9_=-]+)?$/;
exports.JweAlgs = [
'RSA1_5',
'RSA-OAEP',
'RSA-OAEP-256',
'A128KW',
'A192KW',
'A256KW',
'dir',
'ECDH-ES' /*interop value*/,
'ECDH-ES+A128KW',
'ECDH-ES+A192KW',
'ECDH-ES+A256KW',
'A128GCMKW',
'A192GCMKW',
'A256GCMKW',
'PBES2-HS256+A128KW',
'PBES2-HS384+A192KW',
'PBES2-HS512+A256KW',
];
function jweAlg(alg) {
return exports.JweAlgs.find((supportedVal) => supportedVal === alg);
}
exports.JweEncs = ['A128CBC-HS256', 'A192CBC-HS384', 'A256CBC-HS512', 'A128GCM', 'A192GCM', 'A256GCM' /*interop value*/];
function jweEnc(alg) {
return exports.JweEncs.find((supportedVal) => supportedVal === alg);
}
//# sourceMappingURL=IJwtService.js.map