Skip to content

Commit

Permalink
Merge pull request #138 from TimoGlastra/chore/update-sd-jwt
Browse files Browse the repository at this point in the history
chore: update sd-jwt
  • Loading branch information
nklomp authored Jan 19, 2024
2 parents 4452b5e + 60f2704 commit d5750a7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 49 deletions.
20 changes: 12 additions & 8 deletions lib/utils/sdJwt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Disclosure } from '@sd-jwt/core';
import { getDisclosuresForPresentationFrame } from '@sd-jwt/core/build/sdJwt';
import { swapClaims } from '@sd-jwt/core/build/sdJwt/swapClaim';
import { PresentationFrame } from '@sd-jwt/core/build/types/present';
import { decodeDisclosuresInPayload } from '@sd-jwt/decode';
import { getDisclosuresForPresentationFrame, PresentationFrame } from '@sd-jwt/present';
import { Base64url } from '@sd-jwt/utils';
import {
Hasher,
Expand All @@ -21,7 +19,7 @@ export function calculateSdHash(compactSdJwtVc: string, alg: string, hasher: Has
* `decodedPayload`, `compactSdJwt` and `disclosures` properties.
*
* Both the input and output interfaces of this method are defined in `@sphereon/ssi-types`, so
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/core)
* this method hides the actual implementation of SD-JWT (which is currently based on @sd-jwt/*)
*/
export function applySdJwtLimitDisclosure(
sdJwtDecodedVerifiableCredential: SdJwtDecodedVerifiableCredential,
Expand All @@ -32,12 +30,18 @@ export function applySdJwtLimitDisclosure(
presentationFrame as PresentationFrame<Record<string, unknown>>,
sdJwtDecodedVerifiableCredential.decodedPayload,
// Map to sd-jwt disclosure format
sdJwtDecodedVerifiableCredential.disclosures.map((d) => Disclosure.fromString(d.encoded).withDigest(d.digest)),
sdJwtDecodedVerifiableCredential.disclosures.map((d) => ({
digest: d.digest,
encoded: d.encoded,
salt: d.decoded[0],
value: d.decoded.length === 3 ? d.decoded[2] : d.decoded[1],
key: d.decoded.length === 3 ? d.decoded[1] : undefined,
})),
);

sdJwtDecodedVerifiableCredential.disclosures = requiredDisclosures.map((d) => ({
encoded: d.encoded,
decoded: d.decoded as SdJwtDecodedDisclosure,
decoded: (d.key ? [d.salt, d.key, d.value] : [d.salt, d.value]) as SdJwtDecodedDisclosure,
digest: d.digest,
}));

Expand All @@ -50,7 +54,7 @@ export function applySdJwtLimitDisclosure(
.join('~');

// Update the decoded / 'pretty' payload
sdJwtDecodedVerifiableCredential.decodedPayload = swapClaims(
sdJwtDecodedVerifiableCredential.decodedPayload = decodeDisclosuresInPayload(
sdJwtDecodedVerifiableCredential.signedPayload,
requiredDisclosures,
) as SdJwtDecodedVerifiableCredentialPayload;
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
},
"dependencies": {
"@astronautlabs/jsonpath": "^1.1.2",
"@sd-jwt/core": "^0.1.2-alpha.2",
"@sd-jwt/present": "^0.2.0",
"@sd-jwt/decode": "^0.2.0",
"@sd-jwt/utils": "^0.2.0",
"@sphereon/pex-models": "^2.1.5",
"@sphereon/ssi-types": "0.18.0",
"@sphereon/ssi-types": "0.18.1",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"jwt-decode": "^3.1.2",
Expand Down Expand Up @@ -72,11 +74,6 @@
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"resolutions": {
"@sd-jwt/utils": "0.1.2-alpha.2",
"@sd-jwt/decode": "0.1.2-alpha.1",
"@sd-jwt/types": "0.1.2-alpha.3"
},
"files": [
"index.ts",
"lib/validation/validatePDv1.js",
Expand Down
60 changes: 26 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -696,41 +696,33 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@sd-jwt/core@0.1.2-alpha.0":
version "0.1.2-alpha.0"
resolved "https://registry.yarnpkg.com/@sd-jwt/core/-/core-0.1.2-alpha.0.tgz#a1b6ed2c7efc6d71d8fcd063b6624cf77c1eb21f"
integrity sha512-x4MVXar6WmPauZDRJ3aHwaY8o/bHzN77Ts7o43JKuuqIBFjPgAcSlRtd/Xk1rWhazFai4MCIwJDSQ1OQRJtNug==
dependencies:
buffer "*"

"@sd-jwt/core@^0.1.2-alpha.2":
version "0.1.2-alpha.2"
resolved "https://registry.yarnpkg.com/@sd-jwt/core/-/core-0.1.2-alpha.2.tgz#572680c388f8c9d0922b849ac87b43c5c88e2672"
integrity sha512-MNBzv3TtBRwnlYoCrzS0tMcQIdesiN4H3XbCYbZr7Ku0lLbBJtWR2hp6xEyC3VQPlphC6XCUNOvNoRhDsVgVmg==
"@sd-jwt/decode@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@sd-jwt/decode/-/decode-0.2.0.tgz#44211418fd0884a160f8223feedfe04ae52398c4"
integrity sha512-nmiZN3SQ4ApapEu+rS1h/YAkDIq3exgN7swSCsEkrxSEwnBSbXtISIY/sv+EmwnehF1rcKbivHfHNxOWYtlxvg==
dependencies:
"@sd-jwt/decode" "workspace:*"
"@sd-jwt/types" "workspace:*"
"@sd-jwt/utils" "workspace:*"
"@sd-jwt/types" "0.2.0"
"@sd-jwt/utils" "0.2.0"

"@sd-jwt/decode@0.1.2-alpha.1", "@sd-jwt/decode@workspace:*":
version "0.1.2-alpha.1"
resolved "https://registry.yarnpkg.com/@sd-jwt/decode/-/decode-0.1.2-alpha.1.tgz#163c6bf4f0702c6d310ccc3f3f3c726863d8c30e"
integrity sha512-gm6iQeNVZFErk2yvhsK1Q48koGbJPGh6yFDEd9ACdprOkzHI/TAz9ytJbxmHk4wTmpy1MBxnKuljzaSGOcQXEw==
"@sd-jwt/present@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@sd-jwt/present/-/present-0.2.0.tgz#01ecbd09dd21287be892b36d754a79c8629387f2"
integrity sha512-6xDBiB+UqCwW8k7O7OUJ7BgC/8zcO+AD5ZX1k4I6yjDM9vscgPulSVxT/yUH+Aov3cZ/BKvfKC0qDEZkHmP/kg==
dependencies:
"@sd-jwt/types" "workspace:*"
"@sd-jwt/utils" "workspace:*"
"@sd-jwt/types" "0.2.0"
"@sd-jwt/utils" "0.2.0"

"@sd-jwt/types@0.1.2-alpha.3", "@sd-jwt/types@workspace:*":
version "0.1.2-alpha.3"
resolved "https://registry.yarnpkg.com/@sd-jwt/types/-/types-0.1.2-alpha.3.tgz#5e42ceb18a6b6e3cb9cdc9607a2c3d27d7ab12df"
integrity sha512-xeP2Z+Ub8nsdbuT2JqQDYs93C1TTNm9efZI8+rAxlyeUuCl2sbJnWiUR39kU6jlYKYs1U7c31wMf8aP4yMMUdg==
"@sd-jwt/types@0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@sd-jwt/types/-/types-0.2.0.tgz#3cb50392e1b76ce69453f403c71c937a6e202352"
integrity sha512-16WFRcL/maG0/JxN9UCSx07/vJ2SDbGscv9gDLmFLgJzhJcGPer41XfI6aDfVARYP430wHFixChfY/n7qC1L/Q==

"@sd-jwt/utils@0.1.2-alpha.2", "@sd-jwt/utils@workspace:*":
version "0.1.2-alpha.2"
resolved "https://registry.yarnpkg.com/@sd-jwt/utils/-/utils-0.1.2-alpha.2.tgz#df94cc675bb0a43df44f327ec5142260ccf49add"
integrity sha512-jl6Tk7agFdi9Ebeg3S3HdI7wl0uvelknSKM/X5DGx6a5EomJyx40dOc+KKeNf22me+8l8QJ7a0JyNkD/RP3KQQ==
"@sd-jwt/utils@0.2.0", "@sd-jwt/utils@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@sd-jwt/utils/-/utils-0.2.0.tgz#ef52b744116e874f72ec01978f0631ad5a131eb7"
integrity sha512-oHCfRYVHCb5RNwdq3eHAt7P9d7TsEaSM1TTux+xl1I9PeQGLtZETnto9Gchtzn8FlTrMdVsLlcuAcK6Viwj1Qw==
dependencies:
"@sd-jwt/types" "workspace:*"
"@sd-jwt/types" "0.2.0"
buffer "*"

"@sinclair/typebox@^0.27.8":
Expand All @@ -757,12 +749,12 @@
resolved "https://registry.yarnpkg.com/@sphereon/pex-models/-/pex-models-2.1.5.tgz#ba4474a3783081392b72403c4c8ee6da3d2e5585"
integrity sha512-7THexvdYUK/Dh8olBB46ErT9q/RnecnMdb5r2iwZ6be0Dt4vQLAUN7QU80H0HZBok4jRTb8ydt12x0raBSTHOg==

"@sphereon/ssi-types@0.18.0":
version "0.18.0"
resolved "https://registry.yarnpkg.com/@sphereon/ssi-types/-/ssi-types-0.18.0.tgz#b4f3a4a9e4e5b28719ce729b679d71d9d220cc26"
integrity sha512-D2n42NAhHCwpL4K7BqQXO9dYQ8n3st/1eJQrLqokJ18B9r2gury3km4cp+ZdiIxfefUaP9RBCeuWaiRUvjZ94w==
"@sphereon/ssi-types@0.18.1":
version "0.18.1"
resolved "https://registry.yarnpkg.com/@sphereon/ssi-types/-/ssi-types-0.18.1.tgz#c00e4939149f4e441fae56af860735886a4c33a5"
integrity sha512-uM0gb1woyc0R+p+qh8tVDi15ZWmpzo9BP0iBp/yRkJar7gAfgwox/yvtEToaH9jROKnDCwL3DDQCDeNucpMkwg==
dependencies:
"@sd-jwt/core" "0.1.2-alpha.0"
"@sd-jwt/decode" "^0.2.0"
jwt-decode "^3.1.2"

"@tokenizer/token@^0.3.0":
Expand Down

0 comments on commit d5750a7

Please sign in to comment.