Skip to content

Commit

Permalink
feat: make _digest value public in disclosure (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
Co-authored-by: Mirko Mollik <[email protected]>
  • Loading branch information
lukasjhan and cre8 committed Mar 11, 2024
1 parent 9dd530b commit 7a3fbd7
Show file tree
Hide file tree
Showing 49 changed files with 146 additions and 225 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/build-test-publish-on-push-cached.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,9 @@ jobs:
with:
node-version: 20
cache: 'pnpm'
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- name: Run Biome
run: biome ci .
# we are not using the github action for biome, but the package.json script. this makes sure we are using the same versions.
- name: Run Biome
run: pnpm run biome:ci

# Only run this job when the push is on main, next or unstable
publish:
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/basic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/custom_header.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/decoy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/kb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-example/sdjwtobject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtInstance } from '@sd-jwt/core';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/all.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/basic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/custom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/custom_header.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/decoy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/kb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/sd-jwt-vc-example/sdjwtobject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
import { DisclosureFrame } from '@sd-jwt/types';
import type { DisclosureFrame } from '@sd-jwt/types';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
"build": "lerna run build --stream",
"lint": "biome lint ./packages",
"format": "biome format . --write",
"biome:ci": "biome ci .",
"test": "vitest run --coverage.enabled=true --coverage.include=packages/*",
"test:watch": "vitest",
"clean": "lerna clean -y",
"publish:latest": "lerna publish --no-private --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest",
"publish:next": "lerna publish --no-private --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes",
"publish:unstable": "lerna publish --no-private --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes"
},
"keywords": [
"sd-jwt",
"sdjwt",
"sd-jwt-vc"
],
"keywords": ["sd-jwt", "sdjwt", "sd-jwt-vc"],
"engines": {
"node": ">=16"
},
Expand All @@ -32,7 +29,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@biomejs/biome": "^1.6.0",
"@types/node": "^20.10.2",
"@vitest/coverage-v8": "^1.2.2",
"jose": "^5.2.2",
Expand Down
15 changes: 3 additions & 12 deletions packages/browser-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
"test:browser": "vitest run ./src/test/*.spec.ts",
"test:cov": "vitest run --coverage"
},
"keywords": [
"sd-jwt",
"sdjwt",
"sd-jwt-vc"
],
"keywords": ["sd-jwt", "sdjwt", "sd-jwt-vc"],
"repository": {
"type": "git",
"url": "https://github.com/openwallet-foundation-labs/sd-jwt-js"
Expand All @@ -37,17 +33,12 @@
"access": "public"
},
"tsup": {
"entry": [
"./src/index.ts"
],
"entry": ["./src/index.ts"],
"sourceMap": true,
"splitting": false,
"clean": true,
"dts": true,
"format": [
"cjs",
"esm"
]
"format": ["cjs", "esm"]
},
"gitHead": "ded40e4551bde7ae93083181bf26bd1b38bbfcfb"
}
2 changes: 1 addition & 1 deletion packages/browser-crypto/src/test/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';
import { generateSalt, digest, getHasher, ES256 } from '../index';

// Extract the major version as a number
const nodeVersionMajor = parseInt(
const nodeVersionMajor = Number.parseInt(
process.version.split('.')[0].substring(1),
10,
);
Expand Down
15 changes: 3 additions & 12 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"test:browser": "vitest run ./src/test/*.spec.ts --environment jsdom",
"test:cov": "vitest run --coverage"
},
"keywords": [
"sd-jwt",
"sdjwt",
"sd-jwt-vc"
],
"keywords": ["sd-jwt", "sdjwt", "sd-jwt-vc"],
"engines": {
"node": ">=16"
},
Expand All @@ -50,17 +46,12 @@
"access": "public"
},
"tsup": {
"entry": [
"./src/index.ts"
],
"entry": ["./src/index.ts"],
"sourceMap": true,
"splitting": false,
"clean": true,
"dts": true,
"format": [
"cjs",
"esm"
]
"format": ["cjs", "esm"]
},
"gitHead": "ded40e4551bde7ae93083181bf26bd1b38bbfcfb"
}
2 changes: 1 addition & 1 deletion packages/core/src/decoy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HasherAndAlg, SaltGenerator } from '@sd-jwt/types';
import type { HasherAndAlg, SaltGenerator } from '@sd-jwt/types';
import { Uint8ArrayToBase64Url } from '@sd-jwt/utils';

// This function creates a decoy value that can be used to obscure SD JWT payload.
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Jwt } from './jwt';
import { KBJwt } from './kbjwt';
import { SDJwt, pack } from './sdjwt';
import {
DisclosureFrame,
Hasher,
KBOptions,
type DisclosureFrame,
type Hasher,
type KBOptions,
KB_JWT_TYP,
PresentationFrame,
SDJWTCompact,
SDJWTConfig,
type PresentationFrame,
type SDJWTCompact,
type SDJWTConfig,
} from '@sd-jwt/types';
import { getSDAlgAndPayload } from '@sd-jwt/decode';
import { JwtPayload } from '@sd-jwt/types';
import type { JwtPayload } from '@sd-jwt/types';

export * from './sdjwt';
export * from './kbjwt';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Base64urlEncode, SDJWTException } from '@sd-jwt/utils';
import { Base64urlString, Signer, Verifier } from '@sd-jwt/types';
import type { Base64urlString, Signer, Verifier } from '@sd-jwt/types';
import { decodeJwt } from '@sd-jwt/decode';

export type JwtData<
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/kbjwt.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Base64urlEncode, SDJWTException } from '@sd-jwt/utils';
import { Jwt } from './jwt';
import {
JwtPayload,
type JwtPayload,
KB_JWT_TYP,
kbHeader,
kbPayload,
KbVerifier,
type kbHeader,
type kbPayload,
type KbVerifier,
} from '@sd-jwt/types';

export class KBJwt<
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/sdjwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import { SDJWTException, Disclosure } from '@sd-jwt/utils';
import { Jwt } from './jwt';
import { KBJwt } from './kbjwt';
import {
DisclosureFrame,
Hasher,
HasherAndAlg,
PresentationFrame,
SDJWTCompact,
type DisclosureFrame,
type Hasher,
type HasherAndAlg,
type PresentationFrame,
type SDJWTCompact,
SD_DECOY,
SD_DIGEST,
SD_LIST_KEY,
SD_SEPARATOR,
SaltGenerator,
kbHeader,
kbPayload,
type SaltGenerator,
type kbHeader,
type kbPayload,
} from '@sd-jwt/types';
import { createHashMapping, getSDAlgAndPayload, unpack } from '@sd-jwt/decode';
import { transformPresentationFrame } from '@sd-jwt/present';
Expand Down Expand Up @@ -236,7 +236,7 @@ export const pack = async <T extends Record<string, unknown>>(

for (const key in disclosureFrame) {
if (key !== SD_DIGEST) {
const idx = parseInt(key);
const idx = Number.parseInt(key);
const packed = await pack(
claims[idx],
disclosureFrame[idx],
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SDJwtInstance, SdJwtPayload } from '../index';
import { Signer, Verifier, KbVerifier, JwtPayload } from '@sd-jwt/types';
import Crypto, { KeyLike } from 'node:crypto';
import { SDJwtInstance, type SdJwtPayload } from '../index';
import type { Signer, Verifier, KbVerifier, JwtPayload } from '@sd-jwt/types';
import Crypto, { type KeyLike } from 'node:crypto';
import { describe, expect, test } from 'vitest';
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
import { importJWK, exportJWK, JWK } from 'jose';
import { importJWK, exportJWK, type JWK } from 'jose';

export const createSignerVerifier = () => {
const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/jwt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SDJWTException } from '@sd-jwt/utils';
import { Jwt } from '../jwt';
import Crypto from 'node:crypto';
import { Signer, Verifier } from '@sd-jwt/types';
import type { Signer, Verifier } from '@sd-jwt/types';
import { describe, expect, test } from 'vitest';

describe('JWT', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/test/kbjwt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { SDJWTException } from '@sd-jwt/utils';
import type { SDJWTException } from '@sd-jwt/utils';
import { KBJwt } from '../kbjwt';
import {
JwtPayload,
type JwtPayload,
KB_JWT_TYP,
KbVerifier,
Signer,
type KbVerifier,
type Signer,
Verifier,
} from '@sd-jwt/types';
import Crypto, { KeyLike } from 'node:crypto';
import Crypto, { type KeyLike } from 'node:crypto';
import { describe, expect, test } from 'vitest';
import { JWK, exportJWK, importJWK } from 'jose';
import { type JWK, exportJWK, importJWK } from 'jose';

describe('KB JWT', () => {
test('create', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/test/sdjwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Jwt } from '../jwt';
import { SDJwt, listKeys, pack } from '../sdjwt';
import Crypto from 'node:crypto';
import { describe, test, expect } from 'vitest';
import { DisclosureFrame, Signer } from '@sd-jwt/types';
import type { DisclosureFrame, Signer } from '@sd-jwt/types';
import { generateSalt, digest as hasher } from '@sd-jwt/crypto-nodejs';
import { unpack, createHashMapping } from '@sd-jwt/decode';

Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/app-e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Crypto from 'node:crypto';
import { SDJwtInstance, SdJwtPayload } from '../src';
import {
import { SDJwtInstance, type SdJwtPayload } from '../src';
import type {
DisclosureFrame,
PresentationFrame,
Signer,
Verifier,
} from '@sd-jwt/types';
import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, test } from 'vitest';
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';

Expand Down
Loading

0 comments on commit 7a3fbd7

Please sign in to comment.