@trustvc/trustvc 1.0.0-alpha.7 → 1.0.0-alpha.9
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/config.d.mts +3 -0
- package/dist/config.d.ts +3 -0
- package/dist/config.js +5 -0
- package/dist/core/decrypt.js +4 -5
- package/dist/core/encrypt.js +2 -3
- package/dist/esm/config.js +3 -0
- package/dist/esm/core/decrypt.js +4 -5
- package/dist/esm/core/encrypt.js +2 -3
- package/package.json +1 -1
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/core/decrypt.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var config = require('../config');
|
|
3
4
|
var stringUtils = require('../utils/stringUtils');
|
|
4
5
|
var tsChacha20 = require('ts-chacha20');
|
|
5
6
|
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
function decrypt(encryptedMessage, key, nonce) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
key = stringUtils.generate32ByteKey(key ?? "");
|
|
10
|
+
key = key.length > 0 ? key : config.DEFAULT_KEY;
|
|
11
|
+
key = stringUtils.generate32ByteKey(key);
|
|
13
12
|
nonce = stringUtils.generate12ByteNonce(nonce ?? "");
|
|
14
13
|
const keyBuffer = stringUtils.stringToUint8Array(key);
|
|
15
14
|
const nonceBuffer = stringUtils.stringToUint8Array(nonce);
|
|
16
15
|
const chacha20 = new tsChacha20.Chacha20(keyBuffer, nonceBuffer);
|
|
17
|
-
const encryptedBuffer = Buffer.from(encryptedMessage, "hex");
|
|
16
|
+
const encryptedBuffer = new Uint8Array(Buffer.from(encryptedMessage, "hex"));
|
|
18
17
|
const decrypted = chacha20.decrypt(encryptedBuffer);
|
|
19
18
|
return Buffer.from(decrypted).toString("utf-8");
|
|
20
19
|
}
|
package/dist/core/encrypt.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var config = require('../config');
|
|
3
4
|
var stringUtils = require('../utils/stringUtils');
|
|
4
5
|
var tsChacha20 = require('ts-chacha20');
|
|
5
6
|
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
9
|
function encrypt(message, key, nonce) {
|
|
9
|
-
|
|
10
|
-
throw new Error("Key length must not be 0");
|
|
11
|
-
}
|
|
10
|
+
key = key.length > 0 ? key : config.DEFAULT_KEY;
|
|
12
11
|
key = stringUtils.generate32ByteKey(key);
|
|
13
12
|
nonce = stringUtils.generate12ByteNonce(nonce ?? "");
|
|
14
13
|
const keyBuffer = stringUtils.stringToUint8Array(key);
|
package/dist/esm/core/decrypt.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
import { DEFAULT_KEY } from '../config';
|
|
1
2
|
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
2
3
|
import { Chacha20 } from 'ts-chacha20';
|
|
3
4
|
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
function decrypt(encryptedMessage, key, nonce) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
key = generate32ByteKey(key ?? "");
|
|
8
|
+
key = key.length > 0 ? key : DEFAULT_KEY;
|
|
9
|
+
key = generate32ByteKey(key);
|
|
11
10
|
nonce = generate12ByteNonce(nonce ?? "");
|
|
12
11
|
const keyBuffer = stringToUint8Array(key);
|
|
13
12
|
const nonceBuffer = stringToUint8Array(nonce);
|
|
14
13
|
const chacha20 = new Chacha20(keyBuffer, nonceBuffer);
|
|
15
|
-
const encryptedBuffer = Buffer.from(encryptedMessage, "hex");
|
|
14
|
+
const encryptedBuffer = new Uint8Array(Buffer.from(encryptedMessage, "hex"));
|
|
16
15
|
const decrypted = chacha20.decrypt(encryptedBuffer);
|
|
17
16
|
return Buffer.from(decrypted).toString("utf-8");
|
|
18
17
|
}
|
package/dist/esm/core/encrypt.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_KEY } from '../config';
|
|
1
2
|
import { generate32ByteKey, generate12ByteNonce, stringToUint8Array } from '../utils/stringUtils';
|
|
2
3
|
import { Chacha20 } from 'ts-chacha20';
|
|
3
4
|
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
7
|
function encrypt(message, key, nonce) {
|
|
7
|
-
|
|
8
|
-
throw new Error("Key length must not be 0");
|
|
9
|
-
}
|
|
8
|
+
key = key.length > 0 ? key : DEFAULT_KEY;
|
|
10
9
|
key = generate32ByteKey(key);
|
|
11
10
|
nonce = generate12ByteNonce(nonce ?? "");
|
|
12
11
|
const keyBuffer = stringToUint8Array(key);
|