@hackthedev/dsync-sign 1.0.9 → 1.0.10
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/README.md +1 -1
- package/index.mjs +21 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ dSyncSign is an additional package that comes with a few helper functions that c
|
|
|
14
14
|
You can import the package with the following line into your code and install it like below
|
|
15
15
|
|
|
16
16
|
```js
|
|
17
|
-
import { dSyncSign } from "@hackthedev/dsync";
|
|
17
|
+
import { dSyncSign } from "@hackthedev/dsync-sign";
|
|
18
18
|
|
|
19
19
|
const signer = new dSyncSign("./mykeys.json"); // optional path for private key file
|
|
20
20
|
```
|
package/index.mjs
CHANGED
|
@@ -52,15 +52,32 @@ export class dSyncSign {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
async signString(text) {
|
|
56
|
+
const priv = await this.getPrivateKey();
|
|
57
|
+
const signer = crypto.createSign("SHA256");
|
|
58
|
+
signer.update(text, "utf8");
|
|
59
|
+
signer.end();
|
|
60
|
+
return signer.sign(priv, "base64");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
verifyString(text, signatureBase64, publicKeyPem) {
|
|
65
|
+
const verifier = crypto.createVerify("SHA256");
|
|
66
|
+
verifier.update(text, "utf8");
|
|
67
|
+
verifier.end();
|
|
68
|
+
return verifier.verify(publicKeyPem, signatureBase64, "base64");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
generateGid(publicKey) {
|
|
56
73
|
if (publicKey.length >= 120) {
|
|
57
|
-
return this.
|
|
74
|
+
return this.encodeToBase64(publicKey.substring(80, 120)) // 40 chars
|
|
58
75
|
} else {
|
|
59
|
-
return this.
|
|
76
|
+
return this.encodeToBase64(publicKey.substring(0, publicKey.length))
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
79
|
|
|
63
|
-
|
|
80
|
+
encodeToBase64(str) {
|
|
64
81
|
return Buffer.from(str, "utf8").toString("base64")
|
|
65
82
|
}
|
|
66
83
|
|