@sphereon/ssi-sdk-ext.jwt-service 0.28.1-feature.oyd.cmsm.improv.20 → 0.28.1-next.53

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.
@@ -1,31 +1,34 @@
1
- import { IAgentPlugin } from '@veramo/core'
2
- import debug from 'debug'
1
+ import { Loggers } from '@sphereon/ssi-types'
2
+ import type { IAgentPlugin } from '@veramo/core'
3
+ const logger = Loggers.DEFAULT.get('sphereon:jwt-service')
3
4
  import { importJWK } from 'jose'
4
5
 
6
+ // @ts-ignore
5
7
  import * as u8a from 'uint8arrays'
8
+ const { fromString } = u8a
6
9
  import {
7
10
  createJwsCompact,
8
- CreateJwsCompactArgs,
9
- CreateJwsFlattenedArgs,
10
- CreateJwsJsonArgs,
11
+ type CreateJwsCompactArgs,
12
+ type CreateJwsFlattenedArgs,
13
+ type CreateJwsJsonArgs,
11
14
  createJwsJsonFlattened,
12
15
  createJwsJsonGeneral,
13
- DecryptJweCompactJwtArgs,
14
- EncryptJweCompactJwtArgs,
15
- IJwsValidationResult,
16
- IJwtService,
17
- IRequiredContext,
16
+ type DecryptJweCompactJwtArgs,
17
+ type EncryptJweCompactJwtArgs,
18
+ type IJwsValidationResult,
19
+ type IJwtService,
20
+ type IRequiredContext,
18
21
  jweAlg,
19
22
  jweEnc,
20
- JwsJsonFlattened,
21
- JwsJsonGeneral,
22
- JwtCompactResult,
23
+ type JwsJsonFlattened,
24
+ type JwsJsonGeneral,
25
+ type JwtCompactResult,
23
26
  JwtLogger,
24
- PreparedJwsObject,
27
+ type PreparedJwsObject,
25
28
  prepareJwsObject,
26
29
  schema,
27
30
  verifyJws,
28
- VerifyJwsArgs,
31
+ type VerifyJwsArgs,
29
32
  } from '..'
30
33
  import { CompactJwtEncrypter } from '../functions/JWE'
31
34
 
@@ -69,7 +72,7 @@ export class JwtService implements IAgentPlugin {
69
72
  const { payload, protectedHeader = { alg: args.alg, enc: args.enc }, recipientKey, issuer, expirationTime, audience } = args
70
73
 
71
74
  try {
72
- debug(`JWE Encrypt: ${JSON.stringify(args, null, 2)}`)
75
+ logger.debug(`JWE Encrypt: ${JSON.stringify(args, null, 2)}`)
73
76
 
74
77
  const alg = jweAlg(args.alg) ?? jweAlg(protectedHeader.alg) ?? 'ECDH-ES'
75
78
  const enc = jweEnc(args.enc) ?? jweEnc(protectedHeader.enc) ?? 'A256GCM'
@@ -88,9 +91,9 @@ export class JwtService implements IAgentPlugin {
88
91
  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
89
92
  }
90
93
  const apuVal = protectedHeader.apu ?? args.apu
91
- const apu = apuVal ? u8a.fromString(apuVal, 'base64url') : undefined
94
+ const apu = apuVal ? fromString(apuVal, 'base64url') : undefined
92
95
  const apvVal = protectedHeader.apv ?? args.apv
93
- const apv = apvVal ? u8a.fromString(apvVal, 'base64url') : undefined
96
+ const apv = apvVal ? fromString(apvVal, 'base64url') : undefined
94
97
 
95
98
  const pubKey = await importJWK(jwkInfo.jwk)
96
99
  const encrypter = new CompactJwtEncrypter({
@@ -1,20 +1,24 @@
1
- import { defaultRandomSource, randomBytes, RandomSource } from '@stablelib/random'
1
+ import { defaultRandomSource, randomBytes, type RandomSource } from '@stablelib/random'
2
2
  import { base64ToBytes, bytesToBase64url, decodeBase64url } from '@veramo/utils'
3
3
  import * as jose from 'jose'
4
- import { JWEKeyManagementHeaderParameters, JWTDecryptOptions } from 'jose'
5
- import type { KeyLike } from 'jose/dist/types/types'
4
+ import type { JWEKeyManagementHeaderParameters, JWTDecryptOptions } from 'jose'
5
+ // // @ts-ignore
6
+ // import type { KeyLike } from 'jose/dist/types/types'
7
+ export type KeyLike = { type: string }
8
+ // @ts-ignore
6
9
  import * as u8a from 'uint8arrays'
10
+ const { fromString, toString, concat } = u8a
7
11
  import {
8
- JweAlg,
12
+ type JweAlg,
9
13
  JweAlgs,
10
- JweEnc,
14
+ type JweEnc,
11
15
  JweEncs,
12
- JweHeader,
13
- JweJsonGeneral,
14
- JweProtectedHeader,
15
- JweRecipient,
16
- JweRecipientUnprotectedHeader,
17
- JwsPayload,
16
+ type JweHeader,
17
+ type JweJsonGeneral,
18
+ type JweProtectedHeader,
19
+ type JweRecipient,
20
+ type JweRecipientUnprotectedHeader,
21
+ type JwsPayload,
18
22
  } from '../types/IJwtService'
19
23
 
20
24
  export interface EncryptionResult {
@@ -237,7 +241,7 @@ export class CompactJwtEncrypter implements JweEncrypter {
237
241
  }
238
242
 
239
243
  async encrypt(payload: Uint8Array, jweProtectedHeader: JweProtectedHeader, aad?: Uint8Array | undefined): Promise<EncryptionResult> {
240
- const jwt = await this.encryptCompactJWT(JSON.parse(u8a.toString(payload)), jweProtectedHeader, aad)
244
+ const jwt = await this.encryptCompactJWT(JSON.parse(toString(payload)), jweProtectedHeader, aad)
241
245
  const [protectedHeader, encryptedKey, ivB64, payloadB64, tagB64] = jwt.split('.')
242
246
  //[jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
243
247
  console.log(`FIXME: TO EncryptionResult`)
@@ -335,7 +339,7 @@ export async function decryptJwe(jwe: JweJsonGeneral, decrypter: JweDecrypter):
335
339
  return Promise.reject(Error(`Decrypter enc '${decrypter.enc}' does not support header enc '${protectedHeader.enc}'`))
336
340
  }
337
341
  const sealed = toWebCryptoCiphertext(jwe.ciphertext, jwe.tag)
338
- const aad = u8a.fromString(jwe.aad ? `${jwe.protected}.${jwe.aad}` : jwe.protected)
342
+ const aad = fromString(jwe.aad ? `${jwe.protected}.${jwe.aad}` : jwe.protected)
339
343
  let cleartext = null
340
344
  if (protectedHeader.alg === 'dir' && decrypter.alg === 'dir') {
341
345
  cleartext = await decrypter.decrypt(sealed, base64ToBytes(jwe.iv), aad)
@@ -355,5 +359,5 @@ export async function decryptJwe(jwe: JweJsonGeneral, decrypter: JweDecrypter):
355
359
  }
356
360
 
357
361
  export function toWebCryptoCiphertext(ciphertext: string, tag: string): Uint8Array {
358
- return u8a.concat([base64ToBytes(ciphertext), base64ToBytes(tag)])
362
+ return concat([base64ToBytes(ciphertext), base64ToBytes(tag)])
359
363
  }
@@ -1,28 +1,28 @@
1
+ import { jwkTtoPublicKeyHex } from '@sphereon/ssi-sdk-ext.did-utils'
1
2
  import {
2
3
  ensureManagedIdentifierResult,
3
- ExternalIdentifierDidOpts,
4
- ExternalIdentifierX5cOpts,
5
- IIdentifierResolution,
4
+ type ExternalIdentifierDidOpts,
5
+ type ExternalIdentifierX5cOpts,
6
+ type IIdentifierResolution,
6
7
  isManagedIdentifierDidResult,
7
8
  isManagedIdentifierX5cResult,
8
- ManagedIdentifierMethod,
9
- ManagedIdentifierResult,
9
+ type ManagedIdentifierMethod,
10
+ type ManagedIdentifierResult,
10
11
  resolveExternalJwkIdentifier,
11
12
  } from '@sphereon/ssi-sdk-ext.identifier-resolution'
12
- import { verifyRawSignature } from '@sphereon/ssi-sdk-ext.key-utils'
13
- import { JWK } from '@sphereon/ssi-types'
14
- import { IAgentContext } from '@veramo/core'
13
+ import { keyTypeFromCryptographicSuite, signatureAlgorithmFromKeyType, verifyRawSignature } from '@sphereon/ssi-sdk-ext.key-utils'
14
+ import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
15
+ import type { JoseSignatureAlgorithm, JWK } from '@sphereon/ssi-types'
16
+ import type { IAgentContext } from '@veramo/core'
15
17
  import { base64ToBytes, bytesToBase64url, decodeJoseBlob, encodeJoseBlob } from '@veramo/utils'
18
+ // @ts-ignore
16
19
  import * as u8a from 'uint8arrays'
17
- import {
20
+ import type {
18
21
  CreateJwsCompactArgs,
19
22
  CreateJwsFlattenedArgs,
20
23
  CreateJwsJsonArgs,
21
24
  IJwsValidationResult,
22
25
  IRequiredContext,
23
- isJwsCompact,
24
- isJwsJsonFlattened,
25
- isJwsJsonGeneral,
26
26
  JweHeader,
27
27
  Jws,
28
28
  JwsCompact,
@@ -37,11 +37,14 @@ import {
37
37
  PreparedJwsObject,
38
38
  VerifyJwsArgs,
39
39
  } from '../types/IJwtService'
40
+ import { isJwsCompact, isJwsJsonFlattened, isJwsJsonGeneral } from '../types/IJwtService'
41
+
42
+ const { fromString } = u8a
40
43
 
41
44
  const payloadToBytes = (payload: string | JwsPayload | Uint8Array): Uint8Array => {
42
45
  const isBytes = payload instanceof Uint8Array
43
46
  const isString = typeof payload === 'string'
44
- return isBytes ? payload : isString ? u8a.fromString(payload, 'base64url') : u8a.fromString(JSON.stringify(payload), 'utf-8')
47
+ return isBytes ? payload : isString ? fromString(payload, 'base64url') : fromString(JSON.stringify(payload), 'utf-8')
45
48
  }
46
49
 
47
50
  export const prepareJwsObject = async (args: CreateJwsJsonArgs, context: IRequiredContext): Promise<PreparedJwsObject> => {
@@ -111,11 +114,15 @@ export const createJwsJsonGeneral = async (args: CreateJwsJsonArgs, context: IRe
111
114
  },
112
115
  context
113
116
  )
117
+
118
+ const alg: string | undefined = protectedHeader.alg ?? signatureAlgorithmFromKeyType({ type: identifier.key.type })
119
+
114
120
  // const algorithm = await signatureAlgorithmFromKey({ key: identifier.key })
115
121
  const signature = await context.agent.keyManagerSign({
116
122
  keyRef: identifier.kmsKeyRef,
117
123
  data: `${b64.protectedHeader}.${b64.payload}`,
118
124
  encoding: undefined,
125
+ algorithm: alg,
119
126
  })
120
127
  const jsonSignature = {
121
128
  protected: b64.protectedHeader,
@@ -151,6 +158,8 @@ export const checkAndUpdateJwsHeader = async (
151
158
  },
152
159
  context: IRequiredContext
153
160
  ) => {
161
+ // Make sure we have an alg in the header (https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.1)
162
+ header.alg = header.alg ?? signatureAlgorithmFromKeyType({ type: identifier.key.type })
154
163
  if (isIdentifierMode(mode, identifier.method, 'did')) {
155
164
  // kid is VM of the DID
156
165
  // @see https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.4
@@ -312,25 +321,31 @@ export const verifyJws = async (args: VerifyJwsArgs, context: IAgentContext<IIde
312
321
  // If we have a specific KMS agent plugin that can do the verification prefer that over the generic verification
313
322
  index++
314
323
  let valid: boolean
315
- const data = u8a.fromString(`${sigWithId.protected}.${jws.payload}`, 'utf-8')
324
+ const data = fromString(`${sigWithId.protected}.${jws.payload}`, 'utf-8')
316
325
  const jwkInfo = sigWithId.identifier.jwks[0]
317
- /* if (sigWithId.header?.alg === 'RSA' && contextHasPlugin(context, 'keyManagerVerify')) {
326
+ let signatureAlg: JoseSignatureAlgorithm | undefined = undefined
327
+ if (sigWithId.protected.startsWith(`ey`)) {
328
+ const header = decodeJoseBlob(sigWithId.protected)
329
+ signatureAlg = header.alg as JoseSignatureAlgorithm | undefined
330
+ }
331
+
332
+ if (false && signatureAlg?.startsWith('PS') && contextHasPlugin(context, 'keyManagerVerify')) {
318
333
  const publicKeyHex = jwkTtoPublicKeyHex(jwkInfo.jwk)
319
334
  valid = await context.agent.keyManagerVerify({
320
335
  signature: sigWithId.signature,
321
336
  data,
322
337
  publicKeyHex,
323
- type: keyTypeFromCryptographicSuite({ crv: jwkInfo.jwk.crv ?? 'ES256' }),
338
+ type: keyTypeFromCryptographicSuite({ ...(jwkInfo.jwk.crv && { crv: jwkInfo.jwk.crv }), alg: signatureAlg as string }),
324
339
  // no kms arg, as the current key manager needs a bit more work
325
340
  })
326
- } else {*/
327
- const signature = base64ToBytes(sigWithId.signature)
328
- valid = await verifyRawSignature({ data, signature, key: jwkInfo.jwk })
329
- // }
341
+ } else {
342
+ const signature = base64ToBytes(sigWithId.signature)
343
+ valid = await verifyRawSignature({ data, signature, key: jwkInfo.jwk, opts: { signatureAlg: signatureAlg } })
344
+ // }
345
+ }
330
346
  if (!valid) {
331
347
  errorMessages.push(`Signature ${index} was not valid`)
332
348
  }
333
-
334
349
  return {
335
350
  sigWithId,
336
351
  valid,
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  ExternalIdentifierDidOpts,
3
3
  ExternalIdentifierResult,
4
4
  ExternalIdentifierX5cOpts,
@@ -6,9 +6,9 @@ import {
6
6
  ManagedIdentifierOptsOrResult,
7
7
  ManagedIdentifierResult,
8
8
  } from '@sphereon/ssi-sdk-ext.identifier-resolution'
9
- import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
10
- import { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types'
11
- import { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core'
9
+ import type { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
10
+ import type { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types'
11
+ import type { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core'
12
12
 
13
13
  export type IRequiredContext = IAgentContext<IIdentifierResolution & IKeyManager> // could we still interop with Veramo?
14
14
 
@@ -1,17 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,137 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,IAAI,CAAC,IAAI,CAAC;YACtF,4BAA4B,EAAE,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC;YAC1E,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5D,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;YAChE,uBAAuB,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;SACjE,CAAA;IAwEH,CAAC;IAtEe,aAAa,CAAC,IAAuB,EAAE,OAAyB;;YAC5E,OAAO,MAAM,IAAA,oBAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CA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,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBACpE,MAAM,MAAM,GAAG,MAAA,eAAe,CAAC,GAAG,mCAAI,IAAI,CAAC,GAAG,CAAA;gBAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBAEpE,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAS,EAAC,OAAO,CAAC,GAAG,CAAC,CAAA;gBAC3C,MAAM,SAAS,GAAG,IAAI,yBAAmB,CAAC;oBACxC,GAAG;oBACH,GAAG;oBACH,mBAAmB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;oBACjC,GAAG,EAAE,MAAM;oBACX,MAAM;oBACN,cAAc;oBACd,QAAQ;iBACT,CAAC,CAAA;gBAEF,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;gBAC1D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;YACrB,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,CAAC,KAAK,CAAC,yBAAyB,KAAK,CAAC,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"}
@@ -1,75 +0,0 @@
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
@@ -1 +0,0 @@
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,YAA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