mol_crypto_lib 0.1.1082 → 0.1.1083
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/node.d.ts +2 -1
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +8 -4
- package/node.js.map +1 -1
- package/node.mjs +8 -4
- package/node.test.js +26 -13
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +2 -1
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +8 -4
- package/web.js.map +1 -1
- package/web.mjs +8 -4
- package/web.test.js +18 -9
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
@@ -1760,12 +1760,16 @@ var $;
|
|
1760
1760
|
return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
|
1761
1761
|
}
|
1762
1762
|
static async from(serial) {
|
1763
|
-
if (typeof serial === 'string') {
|
1764
|
-
serial = $mol_charset_encode(serial);
|
1765
|
-
serial = await $mol_crypto_native.subtle.digest('SHA-256', serial);
|
1766
|
-
}
|
1767
1763
|
return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
|
1768
1764
|
}
|
1765
|
+
static async pass(pass, salt) {
|
1766
|
+
return new this(await $mol_crypto_native.subtle.deriveKey({
|
1767
|
+
name: "PBKDF2",
|
1768
|
+
salt,
|
1769
|
+
iterations: 10_000,
|
1770
|
+
hash: "SHA-256",
|
1771
|
+
}, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
|
1772
|
+
}
|
1769
1773
|
static async derive(private_serial, public_serial) {
|
1770
1774
|
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
1771
1775
|
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
package/node.test.js
CHANGED
@@ -1751,12 +1751,16 @@ var $;
|
|
1751
1751
|
return new this(await $mol_crypto_native.subtle.generateKey(algorithm, true, ['encrypt', 'decrypt']));
|
1752
1752
|
}
|
1753
1753
|
static async from(serial) {
|
1754
|
-
if (typeof serial === 'string') {
|
1755
|
-
serial = $mol_charset_encode(serial);
|
1756
|
-
serial = await $mol_crypto_native.subtle.digest('SHA-256', serial);
|
1757
|
-
}
|
1758
1754
|
return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
|
1759
1755
|
}
|
1756
|
+
static async pass(pass, salt) {
|
1757
|
+
return new this(await $mol_crypto_native.subtle.deriveKey({
|
1758
|
+
name: "PBKDF2",
|
1759
|
+
salt,
|
1760
|
+
iterations: 10_000,
|
1761
|
+
hash: "SHA-256",
|
1762
|
+
}, await $mol_crypto_native.subtle.importKey("raw", $mol_charset_encode(pass), "PBKDF2", false, ["deriveKey"]), algorithm, true, ['encrypt', 'decrypt']));
|
1763
|
+
}
|
1760
1764
|
static async derive(private_serial, public_serial) {
|
1761
1765
|
const ecdh = { name: "ECDH", namedCurve: "P-256" };
|
1762
1766
|
const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
|
@@ -4038,21 +4042,21 @@ var $;
|
|
4038
4042
|
(function ($) {
|
4039
4043
|
$mol_test({
|
4040
4044
|
async 'sizes'() {
|
4041
|
-
const
|
4042
|
-
const key = await
|
4045
|
+
const secret = await $mol_crypto_secret.generate();
|
4046
|
+
const key = await secret.serial();
|
4043
4047
|
$mol_assert_equal(key.byteLength, $mol_crypto_secret.size);
|
4044
4048
|
const data = new Uint8Array([1, 2, 3]);
|
4045
4049
|
const salt = $mol_crypto_salt();
|
4046
|
-
const closed = await
|
4050
|
+
const closed = await secret.encrypt(data, salt);
|
4047
4051
|
$mol_assert_equal(closed.byteLength, 16);
|
4048
4052
|
},
|
4049
4053
|
async 'decrypt self encrypted with auto generated key'() {
|
4050
|
-
const
|
4054
|
+
const secret = await $mol_crypto_secret.generate();
|
4051
4055
|
const data = new Uint8Array([1, 2, 3]);
|
4052
4056
|
const salt = $mol_crypto_salt();
|
4053
|
-
const closed = await
|
4054
|
-
const opened = await
|
4055
|
-
$
|
4057
|
+
const closed = await secret.encrypt(data, salt);
|
4058
|
+
const opened = await secret.decrypt(closed, salt);
|
4059
|
+
$mol_assert_equal(data, opened);
|
4056
4060
|
},
|
4057
4061
|
async 'decrypt encrypted with exported auto generated key'() {
|
4058
4062
|
const data = new Uint8Array([1, 2, 3]);
|
@@ -4061,14 +4065,23 @@ var $;
|
|
4061
4065
|
const closed = await Alice.encrypt(data, salt);
|
4062
4066
|
const Bob = await $mol_crypto_secret.from(await Alice.serial());
|
4063
4067
|
const opened = await Bob.decrypt(closed, salt);
|
4064
|
-
$
|
4068
|
+
$mol_assert_equal(data, opened);
|
4065
4069
|
},
|
4066
4070
|
async 'derivation from public & private keys'() {
|
4067
4071
|
const A = await $mol_crypto_key_private.generate();
|
4068
4072
|
const B = await $mol_crypto_key_private.generate();
|
4069
4073
|
const AK = await $mol_crypto_secret.derive(A.toString(), B.public().toString());
|
4070
4074
|
const BK = await $mol_crypto_secret.derive(B.toString(), A.public().toString());
|
4071
|
-
$
|
4075
|
+
$mol_assert_equal(await AK.serial(), await BK.serial());
|
4076
|
+
},
|
4077
|
+
async 'derivation from passwod'() {
|
4078
|
+
const data = new Uint8Array([1, 2, 3]);
|
4079
|
+
const salt1 = $mol_crypto_salt();
|
4080
|
+
const secret = await $mol_crypto_secret.pass('hello', salt1);
|
4081
|
+
const salt2 = $mol_crypto_salt();
|
4082
|
+
const closed = await secret.encrypt(data, salt2);
|
4083
|
+
const opened = await secret.decrypt(closed, salt2);
|
4084
|
+
$mol_assert_equal(data, opened);
|
4072
4085
|
},
|
4073
4086
|
});
|
4074
4087
|
})($ || ($ = {}));
|