@sd-jwt/decode 0.1.2-alpha.6 → 0.1.2-alpha.8

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,5 +1,5 @@
1
1
  import type { AsyncHasher, Hasher } from '@sd-jwt/types';
2
- import type { Disclosure, DisclosureWithDigest } from '@sd-jwt/types';
2
+ import type { Disclosure } from '@sd-jwt/types';
3
3
  import { HasherAlgorithm } from '@sd-jwt/utils';
4
- export type CalculateDigestReturnType<HasherImplementation extends Hasher | AsyncHasher> = ReturnType<HasherImplementation> extends Promise<any> ? Promise<DisclosureWithDigest> : DisclosureWithDigest;
4
+ export type CalculateDigestReturnType<HasherImplementation extends Hasher | AsyncHasher> = ReturnType<HasherImplementation> extends Promise<any> ? Promise<string> : string;
5
5
  export declare const disclosureCalculateDigest: <HI extends Hasher | AsyncHasher>(disclosure: Disclosure, algorithm: HasherAlgorithm, hasher: HI) => CalculateDigestReturnType<HI>;
@@ -1,18 +1,12 @@
1
- import type { AsyncHasher, Hasher } from '@sd-jwt/types';
2
- export declare const decodeSdJwtVc: <HI extends Hasher | AsyncHasher>(compact: string, hasher: HI) => {
1
+ import type { AsyncHasher, DisclosureWithDigest, Hasher } from '@sd-jwt/types';
2
+ interface DecodeSdJwtVcResult {
3
3
  compactSdJwtVc: string;
4
4
  signedPayload: Record<string, unknown>;
5
5
  header: Record<string, unknown>;
6
6
  signature: Uint8Array;
7
- keyBinding: {
8
- header: Record<string, unknown>;
9
- payload: Record<string, unknown>;
10
- signature: Uint8Array;
11
- } | undefined;
12
- disclosures: {
13
- digest: import("../disclosures/calculateDigest").CalculateDigestReturnType<HI>;
14
- decoded: import("@sd-jwt/types").Disclosure;
15
- encoded: import("@sd-jwt/types").DisclosureArray;
16
- }[];
7
+ keyBinding?: Record<string, unknown>;
8
+ disclosures: Array<DisclosureWithDigest>;
17
9
  decodedPayload: Record<string, unknown>;
18
- };
10
+ }
11
+ export declare const decodeSdJwtVc: <HI extends Hasher | AsyncHasher>(compact: string, hasher: HI) => HI extends AsyncHasher ? Promise<DecodeSdJwtVcResult> : DecodeSdJwtVcResult;
12
+ export {};
@@ -2,28 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeSdJwtVc = void 0;
4
4
  const utils_1 = require("@sd-jwt/utils");
5
- const fromCompact_1 = require("./fromCompact");
6
5
  const utils_2 = require("@sd-jwt/utils");
6
+ const fromCompact_1 = require("./fromCompact");
7
+ const utils_3 = require("@sd-jwt/utils");
7
8
  const calculateDigest_1 = require("../disclosures/calculateDigest");
8
- const toArray_1 = require("../disclosures/toArray");
9
9
  const decodeSdJwtVc = (compact, hasher) => {
10
10
  var _a, _b;
11
11
  const { header, payload, signature, keyBinding, disclosures } = (0, fromCompact_1.sdJwtVcFromCompact)(compact);
12
- const hasherAlgorithm = (_a = (0, utils_2.getValueByKeyAnyLevel)(payload, '_sd_alg')) !== null && _a !== void 0 ? _a : utils_1.HasherAlgorithm.Sha256;
13
- const disclosureWithDigests = (_b = disclosures === null || disclosures === void 0 ? void 0 : disclosures.map((d) => ({
14
- digest: (0, calculateDigest_1.disclosureCalculateDigest)(d, hasherAlgorithm, hasher),
15
- decoded: d,
16
- encoded: (0, toArray_1.disclosureToArray)(d)
17
- }))) !== null && _b !== void 0 ? _b : [];
18
- return {
12
+ const hasherAlgorithm = (_a = (0, utils_3.getValueByKeyAnyLevel)(payload, '_sd_alg')) !== null && _a !== void 0 ? _a : utils_2.HasherAlgorithm.Sha256;
13
+ const disclosuresWithDigestsResult = ((_b = disclosures === null || disclosures === void 0 ? void 0 : disclosures.map((disclosure) => {
14
+ const digestResult = (0, calculateDigest_1.disclosureCalculateDigest)(disclosure, hasherAlgorithm, hasher);
15
+ return (0, utils_1.isPromise)(digestResult)
16
+ ? digestResult.then((digest) => (Object.assign(Object.assign({}, disclosure), { digest })))
17
+ : Object.assign(Object.assign({}, disclosure), { digest: digestResult });
18
+ })) !== null && _b !== void 0 ? _b : []);
19
+ const basePayload = {
19
20
  compactSdJwtVc: compact,
20
21
  signedPayload: payload,
21
22
  header,
22
23
  signature,
23
- keyBinding,
24
- disclosures: disclosureWithDigests,
25
- decodedPayload: (0, utils_2.swapClaims)(payload, disclosureWithDigests.map((d) => (Object.assign(Object.assign({}, d.decoded), { digest: d.digest }))))
24
+ keyBinding
26
25
  };
26
+ if (isAsyncCalculateDigestReturnType(disclosuresWithDigestsResult)) {
27
+ return Promise.all(disclosuresWithDigestsResult).then((disclosureWithDigests) => (Object.assign(Object.assign({}, basePayload), { disclosures: disclosureWithDigests, decodedPayload: (0, utils_3.swapClaims)(basePayload.signedPayload, disclosureWithDigests) })));
28
+ }
29
+ else {
30
+ return Object.assign(Object.assign({}, basePayload), { disclosures: disclosuresWithDigestsResult, decodedPayload: (0, utils_3.swapClaims)(basePayload.signedPayload, disclosuresWithDigestsResult) });
31
+ }
27
32
  };
28
33
  exports.decodeSdJwtVc = decodeSdJwtVc;
34
+ function isAsyncCalculateDigestReturnType(disclosureWithDigests) {
35
+ return (0, utils_1.isPromise)(disclosureWithDigests[0]);
36
+ }
29
37
  //# sourceMappingURL=decode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/sdJwtVc/decode.ts"],"names":[],"mappings":";;;AAEA,yCAA+C;AAC/C,+CAAkD;AAClD,yCAAiE;AACjE,oEAA0E;AAC1E,oDAA0D;AAEnD,MAAM,aAAa,GAAG,CACzB,OAAe,EACf,MAAU,EACZ,EAAE;;IACA,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,GACzD,IAAA,gCAAkB,EAAC,OAAO,CAAC,CAAA;IAE/B,MAAM,eAAe,GACjB,MAAA,IAAA,6BAAqB,EAAkB,OAAO,EAAE,SAAS,CAAC,mCAC1D,uBAAe,CAAC,MAAM,CAAA;IAE1B,MAAM,qBAAqB,GACvB,MAAA,WAAW,aAAX,WAAW,u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AAe,EACf,MAAM,CACT,CAAA;QAED,OAAO,IAAA,iBAAS,EAAC,YAAY,CAAC;YAC1B,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,iCAAM,UAAU,KAAE,MAAM,IAAG,CAAC;YAC5D,CAAC,iCAAM,UAAU,KAAE,MAAM,EAAE,YAAY,GAAE,CAAA;IACjD,CAAC,CAAC,mCAAI,EAAE,CAEkC,CAAA;IAE1C,MAAM,WAAW,GAAG;QAChB,cAAc,EAAE,OAAO;QACvB,aAAa,EAAE,OAAO;QACtB,MAAM;QACN,SAAS;QACT,UAAU;KACJ,CAAA;IAEV,IAAI,gCAAgC,CAAC,4BAA4B,CAAC,EAAE,CAAC;QACjE,OAAO,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC,IAAI,CACjD,CAAC,qBAAqB,EAAE,EAAE,CAAC,iCACpB,WAAW,KACd,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,IAAA,kBAAU,EACtB,WAAW,CAAC,aAAa,EACzB,qBAAqB,CACxB,IACH,CAGmB,CAAA;IAC7B,CAAC;SAAM,CAAC;QACJ,OAAO,gCACA,WAAW,KACd,WAAW,EAAE,4BAA4B,EACzC,cAAc,EAAE,IAAA,kBAAU,EACtB,WAAW,CAAC,aAAa,EACzB,4BAA4B,CAC/B,GAGoB,CAAA;IAC7B,CAAC;AACL,CAAC,CAAA;AA5DY,QAAA,aAAa,iBA4DzB;AAED,SAAS,gCAAgC,CACrC,qBAEC;IAED,OAAO,IAAA,iBAAS,EAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/decode",
3
- "version": "0.1.2-alpha.6",
3
+ "version": "0.1.2-alpha.8",
4
4
  "description": "Decode implementation of sd-jwt Draft 06 and sd-jwt-vc Draft 01",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "author": "Berend Sliedrecht <sliedrecht@berend.io>",
@@ -37,13 +37,13 @@
37
37
  "test": "node --require ts-node/register --test ./tests/*.test.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@sd-jwt/types": "0.1.2-alpha.6",
41
- "@sd-jwt/utils": "0.1.2-alpha.6"
40
+ "@sd-jwt/types": "0.1.2-alpha.8",
41
+ "@sd-jwt/utils": "0.1.2-alpha.8"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "*",
45
45
  "ts-node": "*",
46
46
  "typescript": "*"
47
47
  },
48
- "gitHead": "b2c26012342e9dfba2220300cb5acbcde1e05ea8"
48
+ "gitHead": "e030a05d603046d98044eba671a2182263b8aced"
49
49
  }