@sd-jwt/core 0.6.0 → 0.6.1-next.6
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 +6 -6
- package/dist/index.mjs +9 -9
- package/package.json +7 -7
- package/src/decoy.ts +2 -2
- package/src/index.ts +2 -2
- package/src/jwt.ts +5 -5
- package/src/kbjwt.ts +1 -1
- package/src/test/decoy.spec.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -115,8 +115,8 @@ var Jwt = class _Jwt {
|
|
|
115
115
|
const unsignedToken = parts.slice(0, 2).join(".");
|
|
116
116
|
return unsignedToken;
|
|
117
117
|
}
|
|
118
|
-
const header = (0, import_utils.
|
|
119
|
-
const payload = (0, import_utils.
|
|
118
|
+
const header = (0, import_utils.base64urlEncode)(JSON.stringify(this.header));
|
|
119
|
+
const payload = (0, import_utils.base64urlEncode)(JSON.stringify(this.payload));
|
|
120
120
|
return `${header}.${payload}`;
|
|
121
121
|
}
|
|
122
122
|
sign(signer) {
|
|
@@ -133,8 +133,8 @@ var Jwt = class _Jwt {
|
|
|
133
133
|
if (!this.header || !this.payload || !this.signature) {
|
|
134
134
|
throw new import_utils.SDJWTException("Serialize Error: Invalid JWT");
|
|
135
135
|
}
|
|
136
|
-
const header = (0, import_utils.
|
|
137
|
-
const payload = (0, import_utils.
|
|
136
|
+
const header = (0, import_utils.base64urlEncode)(JSON.stringify(this.header));
|
|
137
|
+
const payload = (0, import_utils.base64urlEncode)(JSON.stringify(this.payload));
|
|
138
138
|
const signature = this.signature;
|
|
139
139
|
const compact = `${header}.${payload}.${signature}`;
|
|
140
140
|
this.encoded = compact;
|
|
@@ -204,7 +204,7 @@ var createDecoy = (hash, saltGenerator) => __async(void 0, null, function* () {
|
|
|
204
204
|
const { hasher, alg } = hash;
|
|
205
205
|
const salt = yield saltGenerator(16);
|
|
206
206
|
const decoy = yield hasher(salt, alg);
|
|
207
|
-
return (0, import_utils3.
|
|
207
|
+
return (0, import_utils3.uint8ArrayToBase64Url)(decoy);
|
|
208
208
|
});
|
|
209
209
|
|
|
210
210
|
// src/sdjwt.ts
|
|
@@ -610,7 +610,7 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
610
610
|
}
|
|
611
611
|
const { _sd_alg } = (0, import_decode3.getSDAlgAndPayload)(sdjwt.jwt.payload);
|
|
612
612
|
const sdHash = yield hasher(presentSdJwtWithoutKb, _sd_alg);
|
|
613
|
-
const sdHashStr = (0, import_utils5.
|
|
613
|
+
const sdHashStr = (0, import_utils5.uint8ArrayToBase64Url)(sdHash);
|
|
614
614
|
return sdHashStr;
|
|
615
615
|
});
|
|
616
616
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -39,10 +39,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// src/index.ts
|
|
42
|
-
import { SDJWTException as SDJWTException4,
|
|
42
|
+
import { SDJWTException as SDJWTException4, uint8ArrayToBase64Url as uint8ArrayToBase64Url2 } from "@sd-jwt/utils";
|
|
43
43
|
|
|
44
44
|
// src/jwt.ts
|
|
45
|
-
import {
|
|
45
|
+
import { base64urlEncode, SDJWTException } from "@sd-jwt/utils";
|
|
46
46
|
import { decodeJwt } from "@sd-jwt/decode";
|
|
47
47
|
var Jwt = class _Jwt {
|
|
48
48
|
constructor(data) {
|
|
@@ -88,8 +88,8 @@ var Jwt = class _Jwt {
|
|
|
88
88
|
const unsignedToken = parts.slice(0, 2).join(".");
|
|
89
89
|
return unsignedToken;
|
|
90
90
|
}
|
|
91
|
-
const header =
|
|
92
|
-
const payload =
|
|
91
|
+
const header = base64urlEncode(JSON.stringify(this.header));
|
|
92
|
+
const payload = base64urlEncode(JSON.stringify(this.payload));
|
|
93
93
|
return `${header}.${payload}`;
|
|
94
94
|
}
|
|
95
95
|
sign(signer) {
|
|
@@ -106,8 +106,8 @@ var Jwt = class _Jwt {
|
|
|
106
106
|
if (!this.header || !this.payload || !this.signature) {
|
|
107
107
|
throw new SDJWTException("Serialize Error: Invalid JWT");
|
|
108
108
|
}
|
|
109
|
-
const header =
|
|
110
|
-
const payload =
|
|
109
|
+
const header = base64urlEncode(JSON.stringify(this.header));
|
|
110
|
+
const payload = base64urlEncode(JSON.stringify(this.payload));
|
|
111
111
|
const signature = this.signature;
|
|
112
112
|
const compact = `${header}.${payload}.${signature}`;
|
|
113
113
|
this.encoded = compact;
|
|
@@ -174,12 +174,12 @@ var KBJwt = class _KBJwt extends Jwt {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
// src/decoy.ts
|
|
177
|
-
import {
|
|
177
|
+
import { uint8ArrayToBase64Url } from "@sd-jwt/utils";
|
|
178
178
|
var createDecoy = (hash, saltGenerator) => __async(void 0, null, function* () {
|
|
179
179
|
const { hasher, alg } = hash;
|
|
180
180
|
const salt = yield saltGenerator(16);
|
|
181
181
|
const decoy = yield hasher(salt, alg);
|
|
182
|
-
return
|
|
182
|
+
return uint8ArrayToBase64Url(decoy);
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
// src/sdjwt.ts
|
|
@@ -592,7 +592,7 @@ var _SDJwtInstance = class _SDJwtInstance {
|
|
|
592
592
|
}
|
|
593
593
|
const { _sd_alg } = getSDAlgAndPayload2(sdjwt.jwt.payload);
|
|
594
594
|
const sdHash = yield hasher(presentSdJwtWithoutKb, _sd_alg);
|
|
595
|
-
const sdHashStr =
|
|
595
|
+
const sdHashStr = uint8ArrayToBase64Url2(sdHash);
|
|
596
596
|
return sdHashStr;
|
|
597
597
|
});
|
|
598
598
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-next.6+f8db275",
|
|
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.6.
|
|
41
|
+
"@sd-jwt/crypto-nodejs": "0.6.1-next.6+f8db275"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@sd-jwt/decode": "0.6.
|
|
45
|
-
"@sd-jwt/present": "0.6.
|
|
46
|
-
"@sd-jwt/types": "0.6.
|
|
47
|
-
"@sd-jwt/utils": "0.6.
|
|
44
|
+
"@sd-jwt/decode": "0.6.1-next.6+f8db275",
|
|
45
|
+
"@sd-jwt/present": "0.6.1-next.6+f8db275",
|
|
46
|
+
"@sd-jwt/types": "0.6.1-next.6+f8db275",
|
|
47
|
+
"@sd-jwt/utils": "0.6.1-next.6+f8db275"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"esm"
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f8db275690dab88000a039838680a3478b3b61ec"
|
|
66
66
|
}
|
package/src/decoy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HasherAndAlg, SaltGenerator } from '@sd-jwt/types';
|
|
2
|
-
import {
|
|
2
|
+
import { uint8ArrayToBase64Url } from '@sd-jwt/utils';
|
|
3
3
|
|
|
4
4
|
// This function creates a decoy value that can be used to obscure SD JWT payload.
|
|
5
5
|
// The value is basically a hash of a random salt. So the value is not predictable.
|
|
@@ -11,5 +11,5 @@ export const createDecoy = async (
|
|
|
11
11
|
const { hasher, alg } = hash;
|
|
12
12
|
const salt = await saltGenerator(16);
|
|
13
13
|
const decoy = await hasher(salt, alg);
|
|
14
|
-
return
|
|
14
|
+
return uint8ArrayToBase64Url(decoy);
|
|
15
15
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SDJWTException,
|
|
1
|
+
import { SDJWTException, uint8ArrayToBase64Url } from '@sd-jwt/utils';
|
|
2
2
|
import { Jwt } from './jwt';
|
|
3
3
|
import { KBJwt } from './kbjwt';
|
|
4
4
|
import { SDJwt, pack } from './sdjwt';
|
|
@@ -250,7 +250,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
|
|
|
250
250
|
}
|
|
251
251
|
const { _sd_alg } = getSDAlgAndPayload(sdjwt.jwt.payload);
|
|
252
252
|
const sdHash = await hasher(presentSdJwtWithoutKb, _sd_alg);
|
|
253
|
-
const sdHashStr =
|
|
253
|
+
const sdHashStr = uint8ArrayToBase64Url(sdHash);
|
|
254
254
|
return sdHashStr;
|
|
255
255
|
}
|
|
256
256
|
|
package/src/jwt.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { base64urlEncode, SDJWTException } from '@sd-jwt/utils';
|
|
2
2
|
import type { Base64urlString, Signer, Verifier } from '@sd-jwt/types';
|
|
3
3
|
import { decodeJwt } from '@sd-jwt/decode';
|
|
4
4
|
|
|
@@ -83,8 +83,8 @@ export class Jwt<
|
|
|
83
83
|
return unsignedToken;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const header =
|
|
87
|
-
const payload =
|
|
86
|
+
const header = base64urlEncode(JSON.stringify(this.header));
|
|
87
|
+
const payload = base64urlEncode(JSON.stringify(this.payload));
|
|
88
88
|
return `${header}.${payload}`;
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -104,8 +104,8 @@ export class Jwt<
|
|
|
104
104
|
throw new SDJWTException('Serialize Error: Invalid JWT');
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const header =
|
|
108
|
-
const payload =
|
|
107
|
+
const header = base64urlEncode(JSON.stringify(this.header));
|
|
108
|
+
const payload = base64urlEncode(JSON.stringify(this.payload));
|
|
109
109
|
const signature = this.signature;
|
|
110
110
|
const compact = `${header}.${payload}.${signature}`;
|
|
111
111
|
this.encoded = compact;
|
package/src/kbjwt.ts
CHANGED
package/src/test/decoy.spec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDecoy } from '../decoy';
|
|
2
2
|
import { describe, expect, test } from 'vitest';
|
|
3
|
-
import {
|
|
3
|
+
import { base64urlEncode } from '@sd-jwt/utils';
|
|
4
4
|
import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
|
|
5
5
|
|
|
6
6
|
const hash = {
|
|
@@ -21,7 +21,7 @@ describe('Decoy', () => {
|
|
|
21
21
|
// * Contents: ["6Ij7tM-a5iVPGboS5tmvVA", "email", "johndoe@example.com"]
|
|
22
22
|
test('apply hasher and saltGenerator', async () => {
|
|
23
23
|
const decoyValue = await createDecoy(hash, () =>
|
|
24
|
-
|
|
24
|
+
base64urlEncode(
|
|
25
25
|
'["6Ij7tM-a5iVPGboS5tmvVA", "email", "johndoe@example.com"]',
|
|
26
26
|
),
|
|
27
27
|
);
|