@windingtree/org.id-auth
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -97,11 +97,15 @@ "use strict"; | ||
} | ||
return generate_key_pair_1.generateKeyPair(algConfig.alg, Object.assign(Object.assign(Object.assign({}, options), (algConfig.crv | ||
? { | ||
crv: algConfig.crv | ||
} | ||
: {})), (algConfig.modulusLength | ||
? { | ||
modulusLength: algConfig.modulusLength | ||
} | ||
: {}))); | ||
return generate_key_pair_1.generateKeyPair(algConfig.alg, { | ||
...options, | ||
...(algConfig.crv | ||
? { | ||
crv: algConfig.crv | ||
} | ||
: {}), | ||
...(algConfig.modulusLength | ||
? { | ||
modulusLength: algConfig.modulusLength | ||
} | ||
: {}) | ||
}); | ||
}; | ||
@@ -113,7 +117,11 @@ exports.generateKeyPair = generateKeyPair; | ||
// Import a private key | ||
const importKeyPrivatePem = (key, passphrase) => crypto_1.createPrivateKey(Object.assign({ key, format: 'pem' }, (passphrase | ||
? { | ||
passphrase | ||
} | ||
: {}))); | ||
const importKeyPrivatePem = (key, passphrase) => crypto_1.createPrivateKey({ | ||
key, | ||
format: 'pem', | ||
...(passphrase | ||
? { | ||
passphrase | ||
} | ||
: {}) | ||
}); | ||
exports.importKeyPrivatePem = importKeyPrivatePem; | ||
@@ -120,0 +128,0 @@ // Import a public key |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,3 +10,3 @@ exports.verifyAuthJWT = exports.createAuthJWT = void 0; | ||
// Create an authentication JWT | ||
const createAuthJWT = (privateKey, issuer, audience, scope, expiration) => __awaiter(void 0, void 0, void 0, function* () { | ||
const createAuthJWT = async (privateKey, issuer, audience, scope, expiration) => { | ||
if (!org_id_utils_1.regexp.did.exec(issuer)) { | ||
@@ -47,3 +38,3 @@ throw new Error(`Wrong Issuer DID format: ${issuer}`); | ||
alg = keys_1.getAlgFromJWK(privateKey); | ||
privateKey = yield parse_1.parseJwk(privateKey); | ||
privateKey = await parse_1.parseJwk(privateKey); | ||
} | ||
@@ -55,3 +46,3 @@ else { | ||
} | ||
const privateKeyJWK = yield keys_1.createJWK(privateKey); | ||
const privateKeyJWK = await keys_1.createJWK(privateKey); | ||
alg = keys_1.getAlgFromJWK(privateKeyJWK, true); | ||
@@ -70,6 +61,6 @@ } | ||
return token.sign(privateKey); | ||
}); | ||
}; | ||
exports.createAuthJWT = createAuthJWT; | ||
// Verify authentication token | ||
const verifyAuthJWT = (jwt, publicKey, issuer, audience, scope) => __awaiter(void 0, void 0, void 0, function* () { | ||
const verifyAuthJWT = async (jwt, publicKey, issuer, audience, scope) => { | ||
if (!org_id_utils_1.regexp.did.exec(issuer)) { | ||
@@ -83,3 +74,3 @@ throw new Error(`Wrong Issuer DID format: ${issuer}`); | ||
// JWK provided so converting key to KeyLike format | ||
publicKey = yield parse_1.parseJwk(publicKey); | ||
publicKey = await parse_1.parseJwk(publicKey); | ||
} | ||
@@ -89,3 +80,3 @@ if (publicKey.type !== 'public') { | ||
} | ||
const { payload, protectedHeader } = yield verify_1.jwtVerify(jwt, publicKey, { | ||
const { payload, protectedHeader } = await verify_1.jwtVerify(jwt, publicKey, { | ||
issuer, | ||
@@ -99,3 +90,3 @@ audience | ||
} | ||
catch (_a) { | ||
catch { | ||
throw new Error(`Unable to parse scope: ${scope}`); | ||
@@ -110,3 +101,3 @@ } | ||
} | ||
catch (_b) { | ||
catch { | ||
throw new Error(`Unable to parse scope: ${scope}`); | ||
@@ -124,4 +115,4 @@ } | ||
}; | ||
}); | ||
}; | ||
exports.verifyAuthJWT = verifyAuthJWT; | ||
//# sourceMappingURL=tokens.js.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -150,23 +141,34 @@ exports.isValidFromUntil = exports.isExpired = exports.verifyVC = exports.createVC = exports.buildProofUtil = exports.checkDateUtil = exports.buildHolderUtil = void 0; | ||
// Sign VC with private token | ||
sign: (privateKey) => __awaiter(void 0, void 0, void 0, function* () { | ||
sign: async (privateKey) => { | ||
// Creation of unsigned VC object | ||
const unsignedVS = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ '@context': [ | ||
const unsignedVS = { | ||
'@context': [ | ||
'https://www.w3.org/2018/credentials/v1' | ||
], id: org_id_utils_1.uid.uuid4(), type: vcType, issuer: did }, (vcHolder | ||
? { | ||
holder: vcHolder | ||
} | ||
: {})), { issuanceDate: vcIssuanceDate.toISO() }), (vcValidFrom | ||
? { | ||
validFrom: vcValidFrom.toISO() | ||
} | ||
: {})), (vcValidUntil | ||
? { | ||
validUntil: vcValidUntil.toISO() | ||
} | ||
: {})), (vcExpirationDate | ||
? { | ||
expirationDate: vcExpirationDate.toISO() | ||
} | ||
: {})), { credentialSubject: vcSubject }); | ||
], | ||
id: org_id_utils_1.uid.uuid4(), | ||
type: vcType, | ||
issuer: did, | ||
...(vcHolder | ||
? { | ||
holder: vcHolder | ||
} | ||
: {}), | ||
issuanceDate: vcIssuanceDate.toISO(), | ||
...(vcValidFrom | ||
? { | ||
validFrom: vcValidFrom.toISO() | ||
} | ||
: {}), | ||
...(vcValidUntil | ||
? { | ||
validUntil: vcValidUntil.toISO() | ||
} | ||
: {}), | ||
...(vcExpirationDate | ||
? { | ||
expirationDate: vcExpirationDate.toISO() | ||
} | ||
: {}), | ||
credentialSubject: vcSubject | ||
}; | ||
// @todo Add validation of the VC object with existed JSON schema | ||
@@ -179,3 +181,3 @@ let alg; | ||
keySuiteType = keys_1.keyTypeFromJWK(privateKey); | ||
privateKey = yield parse_1.parseJwk(privateKey); | ||
privateKey = await parse_1.parseJwk(privateKey); | ||
} | ||
@@ -187,3 +189,3 @@ else { | ||
} | ||
const privateKeyJWK = yield keys_1.createJWK(privateKey); | ||
const privateKeyJWK = await keys_1.createJWK(privateKey); | ||
keySuiteType = keys_1.keyTypeFromJWK(privateKeyJWK); | ||
@@ -193,3 +195,3 @@ alg = keys_1.getAlgFromJWK(privateKeyJWK, true); | ||
const encoder = new TextEncoder(); | ||
const jws = yield new sign_1.CompactSign(encoder.encode(JSON.stringify(unsignedVS))) | ||
const jws = await new sign_1.CompactSign(encoder.encode(JSON.stringify(unsignedVS))) | ||
.setProtectedHeader({ | ||
@@ -200,4 +202,7 @@ alg | ||
const vcProof = exports.buildProofUtil(jws, keySuiteType, issuer); | ||
return Object.assign(Object.assign({}, unsignedVS), { proof: vcProof }); | ||
}) | ||
return { | ||
...unsignedVS, | ||
proof: vcProof | ||
}; | ||
} | ||
}; | ||
@@ -208,3 +213,3 @@ return chain; | ||
// VC verification | ||
const verifyVC = (vc, publicKey) => __awaiter(void 0, void 0, void 0, function* () { | ||
const verifyVC = async (vc, publicKey) => { | ||
const jws = org_id_utils_1.object.getDeepValue(vc, 'proof.jws'); | ||
@@ -216,3 +221,3 @@ if (typeof jws !== 'string') { | ||
// JWK provided so converting key to KeyLike format | ||
publicKey = yield parse_1.parseJwk(publicKey); | ||
publicKey = await parse_1.parseJwk(publicKey); | ||
} | ||
@@ -223,3 +228,3 @@ if (publicKey.type !== 'public') { | ||
const decoder = new TextDecoder(); | ||
const { payload } = yield verify_1.compactVerify(jws, publicKey); | ||
const { payload } = await verify_1.compactVerify(jws, publicKey); | ||
let decodedPayload; | ||
@@ -234,3 +239,3 @@ try { | ||
return decodedPayload; | ||
}); | ||
}; | ||
exports.verifyVC = verifyVC; | ||
@@ -237,0 +242,0 @@ // Check if VC expired |
{ | ||
"name": "@windingtree/org.id-auth", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "ORGiD authentication library", | ||
@@ -42,4 +42,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"jose": "3.12.2", | ||
"@windingtree/org.id-utils": "0.2.10", | ||
"jose": "3.12.3", | ||
"@windingtree/org.id-utils": "0.2.11", | ||
"@windingtree/org.json-schema": "0.5.5-beta", | ||
@@ -51,11 +51,11 @@ "luxon": "1.27.0" | ||
"@types/luxon": "1.26.5", | ||
"@typescript-eslint/eslint-plugin": "4.25.0", | ||
"@typescript-eslint/parser": "4.25.0", | ||
"@typescript-eslint/eslint-plugin": "4.26.0", | ||
"@typescript-eslint/parser": "4.26.0", | ||
"eslint": "7.27.0", | ||
"jest": "27.0.1", | ||
"ts-jest": "27.0.1", | ||
"jest": "27.0.3", | ||
"ts-jest": "27.0.2", | ||
"typedoc": "0.20.36", | ||
"typedoc-plugin-markdown": "3.8.2", | ||
"typedoc-plugin-markdown": "3.9.0", | ||
"typescript": "4.2.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
599
0
39125
+ Added@windingtree/org.id-utils@0.2.11(transitive)
+ Addedjose@3.12.3(transitive)
- Removed@windingtree/org.id-utils@0.2.10(transitive)
- Removedjose@3.12.2(transitive)
Updatedjose@3.12.3