@sd-jwt/core 0.9.2-next.0 → 0.9.2-next.2
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/index.js +29 -0
- package/dist/index.mjs +29 -0
- package/package.json +7 -7
- package/src/index.ts +37 -0
- package/test/app-e2e.spec.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -597,10 +597,34 @@ var GeneralJSON = class _GeneralJSON {
|
|
|
597
597
|
};
|
|
598
598
|
|
|
599
599
|
// src/index.ts
|
|
600
|
+
var IANA_HASH_ALGORITHMS = [
|
|
601
|
+
"sha-256",
|
|
602
|
+
"sha-256-128",
|
|
603
|
+
"sha-256-120",
|
|
604
|
+
"sha-256-96",
|
|
605
|
+
"sha-256-64",
|
|
606
|
+
"sha-256-32",
|
|
607
|
+
"sha-384",
|
|
608
|
+
"sha-512",
|
|
609
|
+
"sha3-224",
|
|
610
|
+
"sha3-256",
|
|
611
|
+
"sha3-384",
|
|
612
|
+
"sha3-512",
|
|
613
|
+
"blake2s-256",
|
|
614
|
+
"blake2b-256",
|
|
615
|
+
"blake2b-512",
|
|
616
|
+
"k12-256",
|
|
617
|
+
"k12-512"
|
|
618
|
+
];
|
|
600
619
|
var _SDJwtInstance = class _SDJwtInstance {
|
|
601
620
|
constructor(userConfig) {
|
|
602
621
|
this.userConfig = {};
|
|
603
622
|
if (userConfig) {
|
|
623
|
+
if (userConfig.hashAlg && !IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)) {
|
|
624
|
+
throw new import_utils7.SDJWTException(
|
|
625
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`
|
|
626
|
+
);
|
|
627
|
+
}
|
|
604
628
|
this.userConfig = userConfig;
|
|
605
629
|
}
|
|
606
630
|
}
|
|
@@ -852,6 +876,11 @@ var SDJwtGeneralJSONInstance = class {
|
|
|
852
876
|
constructor(userConfig) {
|
|
853
877
|
this.userConfig = {};
|
|
854
878
|
if (userConfig) {
|
|
879
|
+
if (userConfig.hashAlg && !IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)) {
|
|
880
|
+
throw new import_utils7.SDJWTException(
|
|
881
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`
|
|
882
|
+
);
|
|
883
|
+
}
|
|
855
884
|
this.userConfig = userConfig;
|
|
856
885
|
}
|
|
857
886
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -581,10 +581,34 @@ var GeneralJSON = class _GeneralJSON {
|
|
|
581
581
|
};
|
|
582
582
|
|
|
583
583
|
// src/index.ts
|
|
584
|
+
var IANA_HASH_ALGORITHMS = [
|
|
585
|
+
"sha-256",
|
|
586
|
+
"sha-256-128",
|
|
587
|
+
"sha-256-120",
|
|
588
|
+
"sha-256-96",
|
|
589
|
+
"sha-256-64",
|
|
590
|
+
"sha-256-32",
|
|
591
|
+
"sha-384",
|
|
592
|
+
"sha-512",
|
|
593
|
+
"sha3-224",
|
|
594
|
+
"sha3-256",
|
|
595
|
+
"sha3-384",
|
|
596
|
+
"sha3-512",
|
|
597
|
+
"blake2s-256",
|
|
598
|
+
"blake2b-256",
|
|
599
|
+
"blake2b-512",
|
|
600
|
+
"k12-256",
|
|
601
|
+
"k12-512"
|
|
602
|
+
];
|
|
584
603
|
var _SDJwtInstance = class _SDJwtInstance {
|
|
585
604
|
constructor(userConfig) {
|
|
586
605
|
this.userConfig = {};
|
|
587
606
|
if (userConfig) {
|
|
607
|
+
if (userConfig.hashAlg && !IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)) {
|
|
608
|
+
throw new SDJWTException6(
|
|
609
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`
|
|
610
|
+
);
|
|
611
|
+
}
|
|
588
612
|
this.userConfig = userConfig;
|
|
589
613
|
}
|
|
590
614
|
}
|
|
@@ -836,6 +860,11 @@ var SDJwtGeneralJSONInstance = class {
|
|
|
836
860
|
constructor(userConfig) {
|
|
837
861
|
this.userConfig = {};
|
|
838
862
|
if (userConfig) {
|
|
863
|
+
if (userConfig.hashAlg && !IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)) {
|
|
864
|
+
throw new SDJWTException6(
|
|
865
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`
|
|
866
|
+
);
|
|
867
|
+
}
|
|
839
868
|
this.userConfig = userConfig;
|
|
840
869
|
}
|
|
841
870
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/core",
|
|
3
|
-
"version": "0.9.2-next.
|
|
3
|
+
"version": "0.9.2-next.2+3c85e8e",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@sd-jwt/crypto-nodejs": "0.9.2-next.
|
|
41
|
+
"@sd-jwt/crypto-nodejs": "0.9.2-next.2+3c85e8e"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@sd-jwt/decode": "0.9.2-next.
|
|
45
|
-
"@sd-jwt/present": "0.9.2-next.
|
|
46
|
-
"@sd-jwt/types": "0.9.2-next.
|
|
47
|
-
"@sd-jwt/utils": "0.9.2-next.
|
|
44
|
+
"@sd-jwt/decode": "0.9.2-next.2+3c85e8e",
|
|
45
|
+
"@sd-jwt/present": "0.9.2-next.2+3c85e8e",
|
|
46
|
+
"@sd-jwt/types": "0.9.2-next.2+3c85e8e",
|
|
47
|
+
"@sd-jwt/utils": "0.9.2-next.2+3c85e8e"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"esm"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "3c85e8e283fa53e871a14c321b3a04fc4380b875"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type SDJWTConfig,
|
|
18
18
|
type JwtPayload,
|
|
19
19
|
type Signer,
|
|
20
|
+
type HashAlgorithm,
|
|
20
21
|
} from '@sd-jwt/types';
|
|
21
22
|
import { getSDAlgAndPayload } from '@sd-jwt/decode';
|
|
22
23
|
import { FlattenJSON } from './flattenJSON';
|
|
@@ -31,6 +32,26 @@ export * from './generalJSON';
|
|
|
31
32
|
|
|
32
33
|
export type SdJwtPayload = Record<string, unknown>;
|
|
33
34
|
|
|
35
|
+
const IANA_HASH_ALGORITHMS: HashAlgorithm[] = [
|
|
36
|
+
'sha-256',
|
|
37
|
+
'sha-256-128',
|
|
38
|
+
'sha-256-120',
|
|
39
|
+
'sha-256-96',
|
|
40
|
+
'sha-256-64',
|
|
41
|
+
'sha-256-32',
|
|
42
|
+
'sha-384',
|
|
43
|
+
'sha-512',
|
|
44
|
+
'sha3-224',
|
|
45
|
+
'sha3-256',
|
|
46
|
+
'sha3-384',
|
|
47
|
+
'sha3-512',
|
|
48
|
+
'blake2s-256',
|
|
49
|
+
'blake2b-256',
|
|
50
|
+
'blake2b-512',
|
|
51
|
+
'k12-256',
|
|
52
|
+
'k12-512',
|
|
53
|
+
];
|
|
54
|
+
|
|
34
55
|
export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
35
56
|
//header type
|
|
36
57
|
protected type?: string;
|
|
@@ -41,6 +62,14 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
|
41
62
|
|
|
42
63
|
constructor(userConfig?: SDJWTConfig) {
|
|
43
64
|
if (userConfig) {
|
|
65
|
+
if (
|
|
66
|
+
userConfig.hashAlg &&
|
|
67
|
+
!IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)
|
|
68
|
+
) {
|
|
69
|
+
throw new SDJWTException(
|
|
70
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
44
73
|
this.userConfig = userConfig;
|
|
45
74
|
}
|
|
46
75
|
}
|
|
@@ -340,6 +369,14 @@ export class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
|
|
|
340
369
|
|
|
341
370
|
constructor(userConfig?: SDJWTConfig) {
|
|
342
371
|
if (userConfig) {
|
|
372
|
+
if (
|
|
373
|
+
userConfig.hashAlg &&
|
|
374
|
+
!IANA_HASH_ALGORITHMS.includes(userConfig.hashAlg)
|
|
375
|
+
) {
|
|
376
|
+
throw new SDJWTException(
|
|
377
|
+
`Invalid hash algorithm: ${userConfig.hashAlg}`,
|
|
378
|
+
);
|
|
379
|
+
}
|
|
343
380
|
this.userConfig = userConfig;
|
|
344
381
|
}
|
|
345
382
|
}
|
package/test/app-e2e.spec.ts
CHANGED
|
@@ -36,7 +36,7 @@ describe('App', () => {
|
|
|
36
36
|
signAlg: 'EdDSA',
|
|
37
37
|
verifier,
|
|
38
38
|
hasher: digest,
|
|
39
|
-
hashAlg: '
|
|
39
|
+
hashAlg: 'sha-256',
|
|
40
40
|
saltGenerator: generateSalt,
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -208,7 +208,7 @@ async function JSONtest(filename: string) {
|
|
|
208
208
|
signAlg: 'EdDSA',
|
|
209
209
|
verifier,
|
|
210
210
|
hasher: digest,
|
|
211
|
-
hashAlg: '
|
|
211
|
+
hashAlg: 'sha-256',
|
|
212
212
|
saltGenerator: generateSalt,
|
|
213
213
|
});
|
|
214
214
|
|