@libp2p/crypto 1.0.15 → 1.0.16
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.min.js +7 -7
- package/dist/src/ciphers/aes-gcm.browser.d.ts +0 -1
- package/dist/src/ciphers/aes-gcm.browser.d.ts.map +1 -1
- package/dist/src/ciphers/aes-gcm.browser.js +18 -6
- package/dist/src/ciphers/aes-gcm.browser.js.map +1 -1
- package/package.json +1 -1
- package/src/ciphers/aes-gcm.browser.ts +16 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.browser.d.ts","sourceRoot":"","sources":["../../../src/ciphers/aes-gcm.browser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"aes-gcm.browser.d.ts","sourceRoot":"","sources":["../../../src/ciphers/aes-gcm.browser.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAY9D,eAAO,MAAM,uBAAuB;;;;;;CAA0G,CAAA;AAI9I,wBAAgB,MAAM,CAAE,IAAI,CAAC,EAAE,aAAa,GAAG,SAAS,CAyFvD"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { concat } from 'uint8arrays/concat';
|
|
2
2
|
import { fromString } from 'uint8arrays/from-string';
|
|
3
3
|
import webcrypto from '../webcrypto.js';
|
|
4
|
-
export function isWebkitLinux() {
|
|
5
|
-
return typeof navigator !== 'undefined' && navigator.userAgent.includes('Safari') && navigator.userAgent.includes('Linux') && !navigator.userAgent.includes('Chrome');
|
|
6
|
-
}
|
|
7
4
|
// WebKit on Linux does not support deriving a key from an empty PBKDF2 key.
|
|
8
5
|
// So, as a workaround, we provide the generated key as a constant. We test that
|
|
9
6
|
// this generated key is accurate in test/workaround.spec.ts
|
|
@@ -37,8 +34,16 @@ export function create(opts) {
|
|
|
37
34
|
password = fromString(password);
|
|
38
35
|
}
|
|
39
36
|
let cryptoKey;
|
|
40
|
-
if (password.length === 0
|
|
37
|
+
if (password.length === 0) {
|
|
41
38
|
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt']);
|
|
39
|
+
try {
|
|
40
|
+
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
|
|
41
|
+
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey']);
|
|
42
|
+
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['encrypt']);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt']);
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
else {
|
|
44
49
|
// Derive a key using PBKDF2.
|
|
@@ -65,8 +70,15 @@ export function create(opts) {
|
|
|
65
70
|
password = fromString(password);
|
|
66
71
|
}
|
|
67
72
|
let cryptoKey;
|
|
68
|
-
if (password.length === 0
|
|
69
|
-
|
|
73
|
+
if (password.length === 0) {
|
|
74
|
+
try {
|
|
75
|
+
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
|
|
76
|
+
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey']);
|
|
77
|
+
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['decrypt']);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['decrypt']);
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
else {
|
|
72
84
|
// Derive the key using PBKDF2.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.browser.js","sourceRoot":"","sources":["../../../src/ciphers/aes-gcm.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AAGvC,
|
|
1
|
+
{"version":3,"file":"aes-gcm.browser.js","sourceRoot":"","sources":["../../../src/ciphers/aes-gcm.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,SAAS,MAAM,iBAAiB,CAAA;AAGvC,4EAA4E;AAC5E,gFAAgF;AAChF,4DAA4D;AAC5D,iBAAiB;AACjB,uCAAuC;AACvC,mCAAmC;AACnC,kGAAkG;AAClG,yGAAyG;AACzG,sEAAsE;AACtE,IAAI;AACJ,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,wBAAwB,EAAE,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAA;AAE9I,yFAAyF;AAEzF,MAAM,UAAU,MAAM,CAAE,IAAoB;IAC1C,MAAM,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,SAAS,CAAA;IAC9C,IAAI,SAAS,GAAG,IAAI,EAAE,SAAS,IAAI,EAAE,CAAA;IACrC,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,IAAI,EAAE,CAAA;IAC3C,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,SAAS,CAAA;IACxC,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI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EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;YACjF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;YACvG,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;SAC3H;QAED,sBAAsB;QACtB,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QAC5E,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAA;IAClC,CAAC;IAED,MAAM,MAAM,GAAc;QACxB,OAAO;QACP,OAAO;KACR,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,10 +3,6 @@ import { fromString } from 'uint8arrays/from-string'
|
|
|
3
3
|
import webcrypto from '../webcrypto.js'
|
|
4
4
|
import type { CreateOptions, AESCipher } from './interface.js'
|
|
5
5
|
|
|
6
|
-
export function isWebkitLinux (): boolean {
|
|
7
|
-
return typeof navigator !== 'undefined' && navigator.userAgent.includes('Safari') && navigator.userAgent.includes('Linux') && !navigator.userAgent.includes('Chrome')
|
|
8
|
-
}
|
|
9
|
-
|
|
10
6
|
// WebKit on Linux does not support deriving a key from an empty PBKDF2 key.
|
|
11
7
|
// So, as a workaround, we provide the generated key as a constant. We test that
|
|
12
8
|
// this generated key is accurate in test/workaround.spec.ts
|
|
@@ -46,8 +42,15 @@ export function create (opts?: CreateOptions): AESCipher {
|
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
let cryptoKey: CryptoKey
|
|
49
|
-
if (password.length === 0
|
|
45
|
+
if (password.length === 0) {
|
|
50
46
|
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt'])
|
|
47
|
+
try {
|
|
48
|
+
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
|
|
49
|
+
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
|
|
50
|
+
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['encrypt'])
|
|
51
|
+
} catch {
|
|
52
|
+
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt'])
|
|
53
|
+
}
|
|
51
54
|
} else {
|
|
52
55
|
// Derive a key using PBKDF2.
|
|
53
56
|
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
|
|
@@ -77,8 +80,14 @@ export function create (opts?: CreateOptions): AESCipher {
|
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
let cryptoKey: CryptoKey
|
|
80
|
-
if (password.length === 0
|
|
81
|
-
|
|
83
|
+
if (password.length === 0) {
|
|
84
|
+
try {
|
|
85
|
+
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
|
|
86
|
+
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
|
|
87
|
+
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['decrypt'])
|
|
88
|
+
} catch {
|
|
89
|
+
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['decrypt'])
|
|
90
|
+
}
|
|
82
91
|
} else {
|
|
83
92
|
// Derive the key using PBKDF2.
|
|
84
93
|
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
|