@sd-jwt/crypto-nodejs 0.4.0 → 0.4.1-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 +10 -10
- package/package.json +2 -2
- package/src/crypto.ts +1 -1
- package/src/test/crypto.spec.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -47,18 +47,18 @@ __export(src_exports, {
|
|
|
47
47
|
module.exports = __toCommonJS(src_exports);
|
|
48
48
|
|
|
49
49
|
// src/crypto.ts
|
|
50
|
-
var
|
|
50
|
+
var import_node_crypto = require("crypto");
|
|
51
51
|
var generateSalt = (length) => {
|
|
52
52
|
if (length <= 0) {
|
|
53
53
|
return "";
|
|
54
54
|
}
|
|
55
|
-
const saltBytes = (0,
|
|
55
|
+
const saltBytes = (0, import_node_crypto.randomBytes)(length);
|
|
56
56
|
const salt = saltBytes.toString("hex");
|
|
57
57
|
return salt.substring(0, length);
|
|
58
58
|
};
|
|
59
59
|
var digest = (data, algorithm = "SHA-256") => {
|
|
60
60
|
const nodeAlg = toNodeCryptoAlg(algorithm);
|
|
61
|
-
const hash = (0,
|
|
61
|
+
const hash = (0, import_node_crypto.createHash)(nodeAlg);
|
|
62
62
|
hash.update(data);
|
|
63
63
|
const hashBuffer = hash.digest();
|
|
64
64
|
return new Uint8Array(hashBuffer);
|
|
@@ -68,7 +68,7 @@ var ES256 = {
|
|
|
68
68
|
alg: "ES256",
|
|
69
69
|
generateKeyPair() {
|
|
70
70
|
return __async(this, null, function* () {
|
|
71
|
-
const keyPair = yield
|
|
71
|
+
const keyPair = yield import_node_crypto.subtle.generateKey(
|
|
72
72
|
{
|
|
73
73
|
name: "ECDSA",
|
|
74
74
|
namedCurve: "P-256"
|
|
@@ -79,14 +79,14 @@ var ES256 = {
|
|
|
79
79
|
["sign", "verify"]
|
|
80
80
|
// can be used to sign and verify signatures
|
|
81
81
|
);
|
|
82
|
-
const publicKeyJWK = yield
|
|
83
|
-
const privateKeyJWK = yield
|
|
82
|
+
const publicKeyJWK = yield import_node_crypto.subtle.exportKey("jwk", keyPair.publicKey);
|
|
83
|
+
const privateKeyJWK = yield import_node_crypto.subtle.exportKey("jwk", keyPair.privateKey);
|
|
84
84
|
return { publicKey: publicKeyJWK, privateKey: privateKeyJWK };
|
|
85
85
|
});
|
|
86
86
|
},
|
|
87
87
|
getSigner(privateKeyJWK) {
|
|
88
88
|
return __async(this, null, function* () {
|
|
89
|
-
const privateKey = yield
|
|
89
|
+
const privateKey = yield import_node_crypto.subtle.importKey(
|
|
90
90
|
"jwk",
|
|
91
91
|
privateKeyJWK,
|
|
92
92
|
{
|
|
@@ -100,7 +100,7 @@ var ES256 = {
|
|
|
100
100
|
);
|
|
101
101
|
return (data) => __async(this, null, function* () {
|
|
102
102
|
const encoder = new TextEncoder();
|
|
103
|
-
const signature = yield
|
|
103
|
+
const signature = yield import_node_crypto.subtle.sign(
|
|
104
104
|
{
|
|
105
105
|
name: "ECDSA",
|
|
106
106
|
hash: { name: "SHA-256" }
|
|
@@ -115,7 +115,7 @@ var ES256 = {
|
|
|
115
115
|
},
|
|
116
116
|
getVerifier(publicKeyJWK) {
|
|
117
117
|
return __async(this, null, function* () {
|
|
118
|
-
const publicKey = yield
|
|
118
|
+
const publicKey = yield import_node_crypto.subtle.importKey(
|
|
119
119
|
"jwk",
|
|
120
120
|
publicKeyJWK,
|
|
121
121
|
{
|
|
@@ -133,7 +133,7 @@ var ES256 = {
|
|
|
133
133
|
atob(signatureBase64url.replace(/-/g, "+").replace(/_/g, "/")),
|
|
134
134
|
(c) => c.charCodeAt(0)
|
|
135
135
|
);
|
|
136
|
-
const isValid = yield
|
|
136
|
+
const isValid = yield import_node_crypto.subtle.verify(
|
|
137
137
|
{
|
|
138
138
|
name: "ECDSA",
|
|
139
139
|
hash: { name: "SHA-256" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/crypto-nodejs",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1-next.2+b11bedf",
|
|
4
4
|
"description": "sd-jwt draft 7 implementation in typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"esm"
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "b11bedfe62dd1827653a76226ebdca3e0da1bbe0"
|
|
56
56
|
}
|
package/src/crypto.ts
CHANGED
package/src/test/crypto.spec.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'vitest';
|
|
|
2
2
|
import { generateSalt, digest, ES256 } from '../index';
|
|
3
3
|
|
|
4
4
|
// Extract the major version as a number
|
|
5
|
-
const nodeVersionMajor = parseInt(
|
|
5
|
+
const nodeVersionMajor = Number.parseInt(
|
|
6
6
|
process.version.split('.')[0].substring(1),
|
|
7
7
|
10,
|
|
8
8
|
);
|