@trenskow/signed-stream 0.1.5 → 0.1.7
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 +2 -3
- package/lib/sign-stream.js +5 -5
- package/package.json +1 -1
- package/test/index.js +1 -1
package/README.md
CHANGED
|
@@ -18,13 +18,12 @@ const fileSignature = async (file) => {
|
|
|
18
18
|
|
|
19
19
|
const signStream = new SignStream({
|
|
20
20
|
algorithm: 'SHA256', // Default is `SHA256`,
|
|
21
|
-
privateKey: '-----BEGIN PUBLIC KEY-----\n-...'
|
|
22
|
-
encoding: 'base64', // Default is `base64`.
|
|
21
|
+
privateKey: '-----BEGIN PUBLIC KEY-----\n-...'
|
|
23
22
|
});
|
|
24
23
|
|
|
25
24
|
return await createReadStream(file)
|
|
26
25
|
.pipe(signStream)
|
|
27
|
-
.signature();
|
|
26
|
+
.signature('base64'); // Default encoding is none (returns a `Buffer`).
|
|
28
27
|
|
|
29
28
|
};
|
|
30
29
|
````
|
package/lib/sign-stream.js
CHANGED
|
@@ -12,7 +12,7 @@ import CryptoStream from './crypto-stream.js';
|
|
|
12
12
|
|
|
13
13
|
export default class SignStream extends CryptoStream {
|
|
14
14
|
|
|
15
|
-
constructor({ algorithm, privateKey
|
|
15
|
+
constructor({ algorithm, privateKey }) {
|
|
16
16
|
|
|
17
17
|
const sign = createSign(algorithm);
|
|
18
18
|
|
|
@@ -22,19 +22,19 @@ export default class SignStream extends CryptoStream {
|
|
|
22
22
|
|
|
23
23
|
this._sign = sign;
|
|
24
24
|
this._privateKey = privateKey;
|
|
25
|
-
this._encoding = encoding;
|
|
26
25
|
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
_final(callback) {
|
|
30
29
|
super._final(callback);
|
|
31
30
|
|
|
32
|
-
this._resolve(this._sign.sign(this._privateKey)
|
|
31
|
+
this._resolve(this._sign.sign(this._privateKey));
|
|
33
32
|
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
signature() {
|
|
37
|
-
return this._result
|
|
35
|
+
signature(encoding) {
|
|
36
|
+
return this._result
|
|
37
|
+
.then((signature) => (typeof encoding === 'string') ? signature.toString(encoding) : signature);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
};
|
package/package.json
CHANGED
package/test/index.js
CHANGED