@sphereon/ssi-sdk-ext.jwt-service 0.28.1-feature.esm.cjs.8 → 0.28.1-feature.oyd.cmsm.improv.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/JwtService.d.ts +17 -0
- package/dist/agent/JwtService.d.ts.map +1 -0
- package/dist/agent/JwtService.js +137 -0
- package/dist/agent/JwtService.js.map +1 -0
- package/dist/functions/JWE.d.ts +75 -0
- package/dist/functions/JWE.d.ts.map +1 -0
- package/dist/functions/JWE.js +280 -0
- package/dist/functions/JWE.js.map +1 -0
- package/dist/functions/index.d.ts +35 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +385 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/index.d.ts +8 -273
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -14772
- package/dist/index.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/IJwtService.d.ts +222 -0
- package/dist/types/IJwtService.d.ts.map +1 -0
- package/dist/types/IJwtService.js +75 -0
- package/dist/types/IJwtService.js.map +1 -0
- package/package.json +22 -34
- package/plugin.schema.json +4315 -12439
- package/src/agent/JwtService.ts +3 -6
- package/src/functions/JWE.ts +4 -10
- package/src/functions/index.ts +3 -5
- package/dist/index.cjs +0 -14802
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -278
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IAgentPlugin } from '@veramo/core';
|
|
2
|
+
import { IJwtService } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class JwtService implements IAgentPlugin {
|
|
7
|
+
readonly schema: any;
|
|
8
|
+
readonly methods: IJwtService;
|
|
9
|
+
private jwtPrepareJws;
|
|
10
|
+
private jwtCreateJwsJsonGeneralSignature;
|
|
11
|
+
private jwtCreateJwsJsonFlattenedSignature;
|
|
12
|
+
private jwtCreateJwsCompactSignature;
|
|
13
|
+
private jwtVerifyJwsSignature;
|
|
14
|
+
private jwtEncryptJweCompactJwt;
|
|
15
|
+
private jwtDecryptJweCompactJwt;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=JwtService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JwtService.d.ts","sourceRoot":"","sources":["../../src/agent/JwtService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAK3C,OAAO,EAUL,WAAW,EAaZ,MAAM,IAAI,CAAA;AAGX;;GAEG;AACH,qBAAa,UAAW,YAAW,YAAY;IAC7C,QAAQ,CAAC,MAAM,MAAqB;IACpC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAQ5B;YAEa,aAAa;YAIb,gCAAgC;YAIhC,kCAAkC;YAIlC,4BAA4B;YAK5B,qBAAqB;YAIrB,uBAAuB;YA8CvB,uBAAuB;CAGtC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.JwtService = void 0;
|
|
39
|
+
const debug_1 = __importDefault(require("debug"));
|
|
40
|
+
const jose_1 = require("jose");
|
|
41
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
42
|
+
const __1 = require("..");
|
|
43
|
+
const JWE_1 = require("../functions/JWE");
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
class JwtService {
|
|
48
|
+
constructor() {
|
|
49
|
+
this.schema = __1.schema.IJwtService;
|
|
50
|
+
this.methods = {
|
|
51
|
+
jwtPrepareJws: this.jwtPrepareJws.bind(this),
|
|
52
|
+
jwtCreateJwsJsonGeneralSignature: this.jwtCreateJwsJsonGeneralSignature.bind(this),
|
|
53
|
+
jwtCreateJwsJsonFlattenedSignature: this.jwtCreateJwsJsonFlattenedSignature.bind(this),
|
|
54
|
+
jwtCreateJwsCompactSignature: this.jwtCreateJwsCompactSignature.bind(this),
|
|
55
|
+
jwtVerifyJwsSignature: this.jwtVerifyJwsSignature.bind(this),
|
|
56
|
+
jwtEncryptJweCompactJwt: this.jwtEncryptJweCompactJwt.bind(this),
|
|
57
|
+
jwtDecryptJweCompactJwt: this.jwtDecryptJweCompactJwt.bind(this),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
jwtPrepareJws(args, context) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return yield (0, __1.prepareJwsObject)(args, context);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
jwtCreateJwsJsonGeneralSignature(args, context) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return yield (0, __1.createJwsJsonGeneral)(args, context);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
jwtCreateJwsJsonFlattenedSignature(args, context) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return yield (0, __1.createJwsJsonFlattened)(args, context);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
jwtCreateJwsCompactSignature(args, context) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
// We wrap it in a json object for remote REST calls
|
|
78
|
+
return { jwt: yield (0, __1.createJwsCompact)(args, context) };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
jwtVerifyJwsSignature(args, context) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return yield (0, __1.verifyJws)(args, context);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
jwtEncryptJweCompactJwt(args, context) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
89
|
+
const { payload, protectedHeader = { alg: args.alg, enc: args.enc }, recipientKey, issuer, expirationTime, audience } = args;
|
|
90
|
+
try {
|
|
91
|
+
(0, debug_1.default)(`JWE Encrypt: ${JSON.stringify(args, null, 2)}`);
|
|
92
|
+
const alg = (_b = (_a = (0, __1.jweAlg)(args.alg)) !== null && _a !== void 0 ? _a : (0, __1.jweAlg)(protectedHeader.alg)) !== null && _b !== void 0 ? _b : 'ECDH-ES';
|
|
93
|
+
const enc = (_d = (_c = (0, __1.jweEnc)(args.enc)) !== null && _c !== void 0 ? _c : (0, __1.jweEnc)(protectedHeader.enc)) !== null && _d !== void 0 ? _d : 'A256GCM';
|
|
94
|
+
const encJwks = recipientKey.jwks.length === 1
|
|
95
|
+
? [recipientKey.jwks[0]]
|
|
96
|
+
: recipientKey.jwks.filter((jwk) => (jwk.kid && (jwk.kid === jwk.jwk.kid || jwk.kid === jwk.jwkThumbprint)) || jwk.jwk.use === 'enc');
|
|
97
|
+
if (encJwks.length === 0) {
|
|
98
|
+
return Promise.reject(Error(`No public JWK found that can be used to encrypt against`));
|
|
99
|
+
}
|
|
100
|
+
const jwkInfo = encJwks[0];
|
|
101
|
+
if (encJwks.length > 0) {
|
|
102
|
+
__1.JwtLogger.warning(`More than one JWK with 'enc' usage found. Selected the first one as no 'kid' was provided`, encJwks);
|
|
103
|
+
}
|
|
104
|
+
if (((_e = jwkInfo.jwk.kty) === null || _e === void 0 ? void 0 : _e.startsWith('EC')) !== true || !alg.startsWith('ECDH')) {
|
|
105
|
+
return Promise.reject(Error(`Currently only ECDH-ES is supported for encryption. JWK alg ${jwkInfo.jwk.kty}, header alg ${alg}`)); // TODO: Probably we support way more already
|
|
106
|
+
}
|
|
107
|
+
const apuVal = (_f = protectedHeader.apu) !== null && _f !== void 0 ? _f : args.apu;
|
|
108
|
+
const apu = apuVal ? u8a.fromString(apuVal, 'base64url') : undefined;
|
|
109
|
+
const apvVal = (_g = protectedHeader.apv) !== null && _g !== void 0 ? _g : args.apv;
|
|
110
|
+
const apv = apvVal ? u8a.fromString(apvVal, 'base64url') : undefined;
|
|
111
|
+
const pubKey = yield (0, jose_1.importJWK)(jwkInfo.jwk);
|
|
112
|
+
const encrypter = new JWE_1.CompactJwtEncrypter({
|
|
113
|
+
enc,
|
|
114
|
+
alg,
|
|
115
|
+
keyManagementParams: { apu, apv },
|
|
116
|
+
key: pubKey,
|
|
117
|
+
issuer,
|
|
118
|
+
expirationTime,
|
|
119
|
+
audience,
|
|
120
|
+
});
|
|
121
|
+
const jwe = yield encrypter.encryptCompactJWT(payload, {});
|
|
122
|
+
return { jwt: jwe };
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error(`Error encrypting JWE: ${error.message}`, error);
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
jwtDecryptJweCompactJwt(args, context) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
return { jwt: 'FIXME' };
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.JwtService = JwtService;
|
|
137
|
+
//# sourceMappingURL=JwtService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JwtService.js","sourceRoot":"","sources":["../../src/agent/JwtService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAAyB;AACzB,+BAAgC;AAEhC,iDAAkC;AAClC,0BAuBW;AACX,0CAAsD;AAEtD;;GAEG;AACH,MAAa,UAAU;IAAvB;QACW,WAAM,GAAG,UAAM,CAAC,WAAW,CAAA;QAC3B,YAAO,GAAgB;YAC9B,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5C,gCAAgC,EAAE,IAAI,CAAC,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC;YAClF,kCAAkC,EAAE,IAAI,CAAC,kCAAkC,CA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C,OAAO,EAAE,EAAE,KAAK,CAAC,CAAA;gBAC9D,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;KAAA;IAEa,uBAAuB,CAAC,IAA8B,EAAE,OAAyB;;YAC7F,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;QACzB,CAAC;KAAA;CACF;AAlFD,gCAkFC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RandomSource } from '@stablelib/random';
|
|
2
|
+
import * as jose from 'jose';
|
|
3
|
+
import { JWEKeyManagementHeaderParameters, JWTDecryptOptions } from 'jose';
|
|
4
|
+
import type { KeyLike } from 'jose/dist/types/types';
|
|
5
|
+
import { JweAlg, JweEnc, JweHeader, JweJsonGeneral, JweProtectedHeader, JweRecipient, JweRecipientUnprotectedHeader, JwsPayload } from '../types/IJwtService';
|
|
6
|
+
export interface EncryptionResult {
|
|
7
|
+
ciphertext: Uint8Array;
|
|
8
|
+
tag: Uint8Array;
|
|
9
|
+
iv: Uint8Array;
|
|
10
|
+
protectedHeader?: string;
|
|
11
|
+
recipients?: JweRecipient[];
|
|
12
|
+
cek?: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
export declare const generateContentEncryptionKey: ({ alg, randomSource, }: {
|
|
15
|
+
alg: JweEnc;
|
|
16
|
+
randomSource?: RandomSource;
|
|
17
|
+
}) => Promise<Uint8Array>;
|
|
18
|
+
export interface JwtEncrypter {
|
|
19
|
+
alg: string;
|
|
20
|
+
enc: string;
|
|
21
|
+
encrypt: (payload: JwsPayload, protectedHeader: JweProtectedHeader, aad?: Uint8Array) => Promise<EncryptionResult>;
|
|
22
|
+
encryptCek?: (cek: Uint8Array) => Promise<JweRecipient>;
|
|
23
|
+
}
|
|
24
|
+
export interface JweEncrypter {
|
|
25
|
+
alg: string;
|
|
26
|
+
enc: string;
|
|
27
|
+
encrypt: (payload: Uint8Array, protectedHeader: JweProtectedHeader, aad?: Uint8Array) => Promise<EncryptionResult>;
|
|
28
|
+
encryptCek?: (cek: Uint8Array) => Promise<JweRecipient>;
|
|
29
|
+
}
|
|
30
|
+
export interface JweDecrypter {
|
|
31
|
+
alg: string;
|
|
32
|
+
enc: string;
|
|
33
|
+
decrypt: (sealed: Uint8Array, iv: Uint8Array, aad?: Uint8Array, recipient?: JweRecipient) => Promise<Uint8Array | null>;
|
|
34
|
+
}
|
|
35
|
+
export declare class CompactJwtEncrypter implements JweEncrypter {
|
|
36
|
+
private _alg;
|
|
37
|
+
private _enc;
|
|
38
|
+
private _keyManagementParams;
|
|
39
|
+
private recipientKey;
|
|
40
|
+
private expirationTime;
|
|
41
|
+
private issuer;
|
|
42
|
+
private audience;
|
|
43
|
+
constructor(args: {
|
|
44
|
+
key: Uint8Array | jose.KeyLike;
|
|
45
|
+
alg?: JweAlg;
|
|
46
|
+
enc?: JweEnc;
|
|
47
|
+
keyManagementParams?: JWEKeyManagementHeaderParameters;
|
|
48
|
+
expirationTime?: number | string | Date;
|
|
49
|
+
issuer?: string;
|
|
50
|
+
audience?: string | string[];
|
|
51
|
+
});
|
|
52
|
+
get enc(): string;
|
|
53
|
+
set enc(value: JweEnc | string);
|
|
54
|
+
get alg(): string;
|
|
55
|
+
set alg(value: JweAlg | string);
|
|
56
|
+
encryptCompactJWT(payload: JwsPayload, jweProtectedHeader: JweProtectedHeader, aad?: Uint8Array | undefined): Promise<string>;
|
|
57
|
+
static decryptCompactJWT(jwt: string, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<jose.JWTDecryptResult<jose.JWTPayload>>;
|
|
58
|
+
encrypt(payload: Uint8Array, jweProtectedHeader: JweProtectedHeader, aad?: Uint8Array | undefined): Promise<EncryptionResult>;
|
|
59
|
+
}
|
|
60
|
+
export declare function createJwe(cleartext: Uint8Array, encrypters: JweEncrypter[], protectedHeader: JweProtectedHeader, aad?: Uint8Array): Promise<JweJsonGeneral>;
|
|
61
|
+
/**
|
|
62
|
+
* Merges all headers, so we get a unified header.
|
|
63
|
+
*
|
|
64
|
+
* @param protectedHeader
|
|
65
|
+
* @param unprotectedHeader
|
|
66
|
+
* @param recipientUnprotectedHeader
|
|
67
|
+
*/
|
|
68
|
+
export declare function jweMergeHeaders({ protectedHeader, unprotectedHeader, recipientUnprotectedHeader, }: {
|
|
69
|
+
protectedHeader?: JweProtectedHeader;
|
|
70
|
+
unprotectedHeader?: JweHeader;
|
|
71
|
+
recipientUnprotectedHeader?: JweRecipientUnprotectedHeader;
|
|
72
|
+
}): JweHeader;
|
|
73
|
+
export declare function decryptJwe(jwe: JweJsonGeneral, decrypter: JweDecrypter): Promise<Uint8Array>;
|
|
74
|
+
export declare function toWebCryptoCiphertext(ciphertext: string, tag: string): Uint8Array;
|
|
75
|
+
//# sourceMappingURL=JWE.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JWE.d.ts","sourceRoot":"","sources":["../../src/functions/JWE.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElF,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAC1E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,EACL,MAAM,EAEN,MAAM,EAEN,SAAS,EACT,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,6BAA6B,EAC7B,UAAU,EACX,MAAM,sBAAsB,CAAA;AAE7B,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,UAAU,CAAA;IACf,EAAE,EAAE,UAAU,CAAA;IACd,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,YAAY,EAAE,CAAA;IAC3B,GAAG,CAAC,EAAE,UAAU,CAAA;CACjB;AAED,eAAO,MAAM,4BAA4B,2BAGtC;IACD,GAAG,EAAE,MAAM,CAAA;IACX,YAAY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B,CAAC,EAAE,SAAS,CAAA;IAC7B,0BAA0B,CAAC,EAAE,6BAA6B,CAAA;CAC3D,GAAG,SAAS,CAQZ;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CA0BlG;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAEjF"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.CompactJwtEncrypter = exports.generateContentEncryptionKey = void 0;
|
|
36
|
+
exports.createJwe = createJwe;
|
|
37
|
+
exports.jweMergeHeaders = jweMergeHeaders;
|
|
38
|
+
exports.decryptJwe = decryptJwe;
|
|
39
|
+
exports.toWebCryptoCiphertext = toWebCryptoCiphertext;
|
|
40
|
+
const random_1 = require("@stablelib/random");
|
|
41
|
+
const utils_1 = require("@veramo/utils");
|
|
42
|
+
const jose = __importStar(require("jose"));
|
|
43
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
44
|
+
const IJwtService_1 = require("../types/IJwtService");
|
|
45
|
+
const generateContentEncryptionKey = (_a) => __awaiter(void 0, [_a], void 0, function* ({ alg, randomSource = random_1.defaultRandomSource, }) {
|
|
46
|
+
let length;
|
|
47
|
+
switch (alg) {
|
|
48
|
+
case 'A128GCM':
|
|
49
|
+
length = 16;
|
|
50
|
+
break;
|
|
51
|
+
case 'A192GCM':
|
|
52
|
+
length = 24;
|
|
53
|
+
break;
|
|
54
|
+
case 'A128CBC-HS256':
|
|
55
|
+
case 'A256GCM':
|
|
56
|
+
length = 32;
|
|
57
|
+
break;
|
|
58
|
+
case 'A192CBC-HS384':
|
|
59
|
+
length = 48;
|
|
60
|
+
break;
|
|
61
|
+
case 'A256CBC-HS512':
|
|
62
|
+
length = 64;
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
length = 32;
|
|
66
|
+
}
|
|
67
|
+
return (0, random_1.randomBytes)(length, randomSource);
|
|
68
|
+
});
|
|
69
|
+
exports.generateContentEncryptionKey = generateContentEncryptionKey;
|
|
70
|
+
function jweAssertValid(jwe) {
|
|
71
|
+
if (!(jwe.protected && jwe.iv && jwe.ciphertext && jwe.tag)) {
|
|
72
|
+
throw Error('JWE is missing properties: protected, iv, ciphertext and/or tag');
|
|
73
|
+
}
|
|
74
|
+
if (jwe.recipients) {
|
|
75
|
+
jwe.recipients.map((recipient) => {
|
|
76
|
+
if (!(recipient.header && recipient.encrypted_key)) {
|
|
77
|
+
throw Error('Malformed JWE recipients; no header and encrypted key present');
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function jweEncode({ ciphertext, tag, iv, protectedHeader, recipients, aad, unprotected, }) {
|
|
83
|
+
if (!recipients || recipients.length === 0) {
|
|
84
|
+
throw Error(`No recipient found`);
|
|
85
|
+
}
|
|
86
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (unprotected && { unprotected })), { protected: protectedHeader, iv: (0, utils_1.bytesToBase64url)(iv), ciphertext: (0, utils_1.bytesToBase64url)(ciphertext) }), (tag && { tag: (0, utils_1.bytesToBase64url)(tag) })), (aad && { aad: (0, utils_1.bytesToBase64url)(aad) })), { recipients });
|
|
87
|
+
}
|
|
88
|
+
class CompactJwtEncrypter {
|
|
89
|
+
constructor(args) {
|
|
90
|
+
if (args === null || args === void 0 ? void 0 : args.alg) {
|
|
91
|
+
this._alg = args.alg;
|
|
92
|
+
}
|
|
93
|
+
if (args === null || args === void 0 ? void 0 : args.enc) {
|
|
94
|
+
this._enc = args.enc;
|
|
95
|
+
}
|
|
96
|
+
this._keyManagementParams = args.keyManagementParams;
|
|
97
|
+
this.recipientKey = args.key;
|
|
98
|
+
this.expirationTime = args.expirationTime;
|
|
99
|
+
this.issuer = args.issuer;
|
|
100
|
+
this.audience = args.audience;
|
|
101
|
+
}
|
|
102
|
+
get enc() {
|
|
103
|
+
if (!this._enc) {
|
|
104
|
+
throw Error(`enc not set`);
|
|
105
|
+
}
|
|
106
|
+
return this._enc;
|
|
107
|
+
}
|
|
108
|
+
set enc(value) {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
if (!IJwtService_1.JweEncs.includes(value)) {
|
|
111
|
+
throw Error(`invalid JWE enc value ${value}`);
|
|
112
|
+
}
|
|
113
|
+
this._enc = value;
|
|
114
|
+
}
|
|
115
|
+
get alg() {
|
|
116
|
+
if (!this._alg) {
|
|
117
|
+
throw Error(`alg not set`);
|
|
118
|
+
}
|
|
119
|
+
return this._alg;
|
|
120
|
+
}
|
|
121
|
+
set alg(value) {
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
if (!IJwtService_1.JweAlgs.includes(value)) {
|
|
124
|
+
throw Error(`invalid JWE alg value ${value}`);
|
|
125
|
+
}
|
|
126
|
+
this._alg = value;
|
|
127
|
+
}
|
|
128
|
+
encryptCompactJWT(payload, jweProtectedHeader, aad) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
var _a, _b;
|
|
131
|
+
const protectedHeader = Object.assign(Object.assign({}, jweProtectedHeader), { alg: (_a = jweProtectedHeader.alg) !== null && _a !== void 0 ? _a : this._alg, enc: (_b = jweProtectedHeader.enc) !== null && _b !== void 0 ? _b : this._enc });
|
|
132
|
+
if (!protectedHeader.alg || !protectedHeader.enc) {
|
|
133
|
+
return Promise.reject(Error(`no 'alg' or 'enc' value set for the protected JWE header!`));
|
|
134
|
+
}
|
|
135
|
+
this.enc = protectedHeader.enc;
|
|
136
|
+
this.alg = protectedHeader.alg;
|
|
137
|
+
if (payload.exp) {
|
|
138
|
+
this.expirationTime = payload.exp;
|
|
139
|
+
}
|
|
140
|
+
if (payload.iss) {
|
|
141
|
+
this.issuer = payload.iss;
|
|
142
|
+
}
|
|
143
|
+
if (payload.aud) {
|
|
144
|
+
this.audience = payload.aud;
|
|
145
|
+
}
|
|
146
|
+
const encrypt = new jose.EncryptJWT(payload).setProtectedHeader(Object.assign(Object.assign({}, protectedHeader), { alg: this.alg, enc: this.enc }));
|
|
147
|
+
if (this._alg.startsWith('ECDH')) {
|
|
148
|
+
if (!this._keyManagementParams) {
|
|
149
|
+
return Promise.reject(Error(`ECDH requires key management params`));
|
|
150
|
+
}
|
|
151
|
+
encrypt.setKeyManagementParameters(this._keyManagementParams);
|
|
152
|
+
}
|
|
153
|
+
if (this.expirationTime !== undefined) {
|
|
154
|
+
encrypt.setExpirationTime(this.expirationTime);
|
|
155
|
+
}
|
|
156
|
+
if (this.issuer) {
|
|
157
|
+
encrypt.setIssuer(this.issuer);
|
|
158
|
+
}
|
|
159
|
+
if (this.audience) {
|
|
160
|
+
encrypt.setAudience(this.audience);
|
|
161
|
+
}
|
|
162
|
+
return yield encrypt.encrypt(this.recipientKey);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
static decryptCompactJWT(jwt, key, options) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
return yield jose.jwtDecrypt(jwt, key, options);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
encrypt(payload, jweProtectedHeader, aad) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const jwt = yield this.encryptCompactJWT(JSON.parse(u8a.toString(payload)), jweProtectedHeader, aad);
|
|
173
|
+
const [protectedHeader, encryptedKey, ivB64, payloadB64, tagB64] = jwt.split('.');
|
|
174
|
+
//[jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
|
|
175
|
+
console.log(`FIXME: TO EncryptionResult`);
|
|
176
|
+
return {
|
|
177
|
+
protectedHeader,
|
|
178
|
+
tag: (0, utils_1.base64ToBytes)(tagB64),
|
|
179
|
+
ciphertext: (0, utils_1.base64ToBytes)(payloadB64),
|
|
180
|
+
iv: (0, utils_1.base64ToBytes)(ivB64),
|
|
181
|
+
recipients: [
|
|
182
|
+
Object.assign({}, (encryptedKey && { encrypted_key: encryptedKey })),
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.CompactJwtEncrypter = CompactJwtEncrypter;
|
|
189
|
+
function createJwe(cleartext, encrypters, protectedHeader, aad) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
var _a, _b;
|
|
192
|
+
if (encrypters.length === 0) {
|
|
193
|
+
throw Error('JWE needs at least 1 encryptor');
|
|
194
|
+
}
|
|
195
|
+
if (encrypters.find((enc) => enc.alg === 'dir' || enc.alg === 'ECDH-ES')) {
|
|
196
|
+
if (encrypters.length !== 1) {
|
|
197
|
+
throw Error(`JWE can only do "dir" or "ECDH-ES" encryption with one key. ${encrypters.length} supplied`);
|
|
198
|
+
}
|
|
199
|
+
const encryptionResult = yield encrypters[0].encrypt(cleartext, protectedHeader, aad);
|
|
200
|
+
return jweEncode(Object.assign(Object.assign({}, encryptionResult), { aad }));
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const tmpEnc = encrypters[0].enc;
|
|
204
|
+
if (!encrypters.reduce((acc, encrypter) => acc && encrypter.enc === tmpEnc, true)) {
|
|
205
|
+
throw new Error('invalid_argument: Incompatible encrypters passed');
|
|
206
|
+
}
|
|
207
|
+
let cek = undefined;
|
|
208
|
+
let jwe = undefined;
|
|
209
|
+
for (const encrypter of encrypters) {
|
|
210
|
+
if (!cek) {
|
|
211
|
+
const encryptionResult = yield encrypter.encrypt(cleartext, protectedHeader, aad);
|
|
212
|
+
cek = encryptionResult.cek;
|
|
213
|
+
jwe = jweEncode(Object.assign(Object.assign({}, encryptionResult), { aad }));
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const recipient = yield ((_a = encrypter.encryptCek) === null || _a === void 0 ? void 0 : _a.call(encrypter, cek));
|
|
217
|
+
if (recipient) {
|
|
218
|
+
(_b = jwe === null || jwe === void 0 ? void 0 : jwe.recipients) === null || _b === void 0 ? void 0 : _b.push(recipient);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!jwe) {
|
|
223
|
+
throw Error(`No JWE constructed`);
|
|
224
|
+
}
|
|
225
|
+
return jwe;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Merges all headers, so we get a unified header.
|
|
231
|
+
*
|
|
232
|
+
* @param protectedHeader
|
|
233
|
+
* @param unprotectedHeader
|
|
234
|
+
* @param recipientUnprotectedHeader
|
|
235
|
+
*/
|
|
236
|
+
function jweMergeHeaders({ protectedHeader, unprotectedHeader, recipientUnprotectedHeader, }) {
|
|
237
|
+
// TODO: Check that all headers/params are disjoint!
|
|
238
|
+
const header = Object.assign(Object.assign(Object.assign({}, protectedHeader), unprotectedHeader), recipientUnprotectedHeader);
|
|
239
|
+
if (!header.alg || !header.enc) {
|
|
240
|
+
throw Error(`Either 'alg' or 'enc' are missing from the headers`);
|
|
241
|
+
}
|
|
242
|
+
return header;
|
|
243
|
+
}
|
|
244
|
+
function decryptJwe(jwe, decrypter) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
jweAssertValid(jwe);
|
|
247
|
+
const protectedHeader = JSON.parse((0, utils_1.decodeBase64url)(jwe.protected));
|
|
248
|
+
if ((protectedHeader === null || protectedHeader === void 0 ? void 0 : protectedHeader.enc) !== decrypter.enc) {
|
|
249
|
+
return Promise.reject(Error(`Decrypter enc '${decrypter.enc}' does not support header enc '${protectedHeader.enc}'`));
|
|
250
|
+
}
|
|
251
|
+
else if (!jwe.tag) {
|
|
252
|
+
return Promise.reject(Error(`Decrypter enc '${decrypter.enc}' does not support header enc '${protectedHeader.enc}'`));
|
|
253
|
+
}
|
|
254
|
+
const sealed = toWebCryptoCiphertext(jwe.ciphertext, jwe.tag);
|
|
255
|
+
const aad = u8a.fromString(jwe.aad ? `${jwe.protected}.${jwe.aad}` : jwe.protected);
|
|
256
|
+
let cleartext = null;
|
|
257
|
+
if (protectedHeader.alg === 'dir' && decrypter.alg === 'dir') {
|
|
258
|
+
cleartext = yield decrypter.decrypt(sealed, (0, utils_1.base64ToBytes)(jwe.iv), aad);
|
|
259
|
+
}
|
|
260
|
+
else if (!jwe.recipients || jwe.recipients.length === 0) {
|
|
261
|
+
throw Error('missing recipients for JWE');
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
for (let i = 0; !cleartext && i < jwe.recipients.length; i++) {
|
|
265
|
+
const recipient = jwe.recipients[i];
|
|
266
|
+
recipient.header = Object.assign(Object.assign({}, recipient.header), protectedHeader);
|
|
267
|
+
if (recipient.header.alg === decrypter.alg) {
|
|
268
|
+
cleartext = yield decrypter.decrypt(sealed, (0, utils_1.base64ToBytes)(jwe.iv), aad, recipient);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (cleartext === null)
|
|
273
|
+
throw new Error('failure: Failed to decrypt');
|
|
274
|
+
return cleartext;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function toWebCryptoCiphertext(ciphertext, tag) {
|
|
278
|
+
return u8a.concat([(0, utils_1.base64ToBytes)(ciphertext), (0, utils_1.base64ToBytes)(tag)]);
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=JWE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JWE.js","sourceRoot":"","sources":["../../src/functions/JWE.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsQA,8BAuCC;AASD,0CAgBC;AAED,gCA0BC;AAED,sDAEC;AAtWD,8CAAkF;AAClF,yCAAgF;AAChF,2CAA4B;AAG5B,iDAAkC;AAClC,sDAW6B;AAWtB,MAAM,4BAA4B,GAAG,KAMpB,EAAE,4CANyB,EACjD,GAAG,EACH,YAAY,GAAG,4BAAmB,GAInC;IACC,IAAI,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IACnE,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,IAAA,qBAAa,EAAC,UAAU,CAAC,EAAE,IAAA,qBAAa,EAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACpE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ExternalIdentifierDidOpts, ExternalIdentifierX5cOpts, IIdentifierResolution, ManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
2
|
+
import { JWK } from '@sphereon/ssi-types';
|
|
3
|
+
import { IAgentContext } from '@veramo/core';
|
|
4
|
+
import { CreateJwsCompactArgs, CreateJwsFlattenedArgs, CreateJwsJsonArgs, IJwsValidationResult, IRequiredContext, Jws, JwsCompact, JwsHeader, JwsIdentifierMode, JwsJsonFlattened, JwsJsonGeneral, JwsJsonGeneralWithIdentifiers, PreparedJwsObject, VerifyJwsArgs } from '../types/IJwtService';
|
|
5
|
+
export declare const prepareJwsObject: (args: CreateJwsJsonArgs, context: IRequiredContext) => Promise<PreparedJwsObject>;
|
|
6
|
+
export declare const createJwsCompact: (args: CreateJwsCompactArgs, context: IRequiredContext) => Promise<JwsCompact>;
|
|
7
|
+
export declare const createJwsJsonFlattened: (args: CreateJwsFlattenedArgs, context: IRequiredContext) => Promise<JwsJsonFlattened>;
|
|
8
|
+
export declare const createJwsJsonGeneral: (args: CreateJwsJsonArgs, context: IRequiredContext) => Promise<JwsJsonGeneral>;
|
|
9
|
+
/**
|
|
10
|
+
* Updates the JWT header to include x5c, kid, jwk objects using the supplied issuer identifier that will be used to sign. If not present will automatically make the header objects available
|
|
11
|
+
* @param mode The type of header to check or include
|
|
12
|
+
* @param identifier The identifier of the signer. This identifier will be used later to sign
|
|
13
|
+
* @param header The JWT header
|
|
14
|
+
* @param noIdentifierInHeader
|
|
15
|
+
* @param context
|
|
16
|
+
*/
|
|
17
|
+
export declare const checkAndUpdateJwsHeader: ({ mode, identifier, header, noIdentifierInHeader, }: {
|
|
18
|
+
mode?: JwsIdentifierMode;
|
|
19
|
+
identifier: ManagedIdentifierResult;
|
|
20
|
+
noIdentifierInHeader?: boolean;
|
|
21
|
+
header: JwsHeader;
|
|
22
|
+
}, context: IRequiredContext) => Promise<undefined>;
|
|
23
|
+
export declare const verifyJws: (args: VerifyJwsArgs, context: IAgentContext<IIdentifierResolution>) => Promise<IJwsValidationResult>;
|
|
24
|
+
export declare const toJwsJsonGeneral: ({ jws }: {
|
|
25
|
+
jws: Jws;
|
|
26
|
+
}, context: IAgentContext<any>) => Promise<JwsJsonGeneral>;
|
|
27
|
+
export declare const toJwsJsonGeneralWithIdentifiers: (args: {
|
|
28
|
+
jws: Jws;
|
|
29
|
+
jwk?: JWK;
|
|
30
|
+
opts?: {
|
|
31
|
+
x5c?: Omit<ExternalIdentifierX5cOpts, "identifier">;
|
|
32
|
+
did?: Omit<ExternalIdentifierDidOpts, "identifier">;
|
|
33
|
+
};
|
|
34
|
+
}, context: IAgentContext<IIdentifierResolution>) => Promise<JwsJsonGeneralWithIdentifiers>;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EAIrB,uBAAuB,EAExB,MAAM,6CAA6C,CAAA;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5C,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAKhB,GAAG,EACH,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,6BAA6B,EAI7B,iBAAiB,EACjB,aAAa,EACd,MAAM,sBAAsB,CAAA;AAQ7B,eAAO,MAAM,gBAAgB,SAAgB,iBAA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