@waku/enr 0.0.9 → 0.0.11

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/CHANGELOG.md CHANGED
@@ -19,6 +19,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
  * devDependencies
20
20
  * @waku/interfaces bumped from 0.0.9 to 0.0.10
21
21
 
22
+ ### Dependencies
23
+
24
+ * The following workspace dependencies were updated
25
+ * dependencies
26
+ * @waku/utils bumped from 0.0.3 to 0.0.4
27
+ * devDependencies
28
+ * @waku/interfaces bumped from 0.0.10 to 0.0.11
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @waku/utils bumped from 0.0.4 to 0.0.5
35
+ * devDependencies
36
+ * @waku/interfaces bumped from 0.0.11 to 0.0.12
37
+
22
38
  ## [0.0.9](https://github.com/waku-org/js-waku/compare/enr-v0.0.8...enr-v0.0.9) (2023-03-28)
23
39
 
24
40
 
package/bundle/index.js CHANGED
@@ -22734,6 +22734,20 @@ const bits = {
22734
22734
  const curveTypes = Object.keys(bits);
22735
22735
  curveTypes.join(' / ');
22736
22736
 
22737
+ function isWebkitLinux() {
22738
+ return typeof navigator !== 'undefined' && navigator.userAgent.includes('Safari') && navigator.userAgent.includes('Linux') && !navigator.userAgent.includes('Chrome');
22739
+ }
22740
+ // WebKit on Linux does not support deriving a key from an empty PBKDF2 key.
22741
+ // So, as a workaround, we provide the generated key as a constant. We test that
22742
+ // this generated key is accurate in test/workaround.spec.ts
22743
+ // Generated via:
22744
+ // await crypto.subtle.exportKey('jwk',
22745
+ // await crypto.subtle.deriveKey(
22746
+ // { name: 'PBKDF2', salt: new Uint8Array(16), iterations: 32767, hash: { name: 'SHA-256' } },
22747
+ // await crypto.subtle.importKey('raw', new Uint8Array(0), { name: 'PBKDF2' }, false, ['deriveKey']),
22748
+ // { name: 'AES-GCM', length: 128 }, true, ['encrypt', 'decrypt'])
22749
+ // )
22750
+ const derivedEmptyPasswordKey = { alg: 'A128GCM', ext: true, k: 'scm9jmO_4BJAgdwWGVulLg', key_ops: ['encrypt', 'decrypt'], kty: 'oct' };
22737
22751
  // Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
22738
22752
  function create(opts) {
22739
22753
  const algorithm = opts?.algorithm ?? 'AES-GCM';
@@ -22755,10 +22769,16 @@ function create(opts) {
22755
22769
  if (typeof password === 'string') {
22756
22770
  password = fromString$1(password);
22757
22771
  }
22758
- // Derive a key using PBKDF2.
22759
- const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
22760
- const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey', 'deriveBits']);
22761
- const cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['encrypt']);
22772
+ let cryptoKey;
22773
+ if (password.length === 0 && isWebkitLinux()) {
22774
+ cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt']);
22775
+ }
22776
+ else {
22777
+ // Derive a key using PBKDF2.
22778
+ const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
22779
+ const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey']);
22780
+ cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['encrypt']);
22781
+ }
22762
22782
  // Encrypt the string.
22763
22783
  const ciphertext = await crypto.subtle.encrypt(aesGcm, cryptoKey, data);
22764
22784
  return concat([salt, aesGcm.iv, new Uint8Array(ciphertext)]);
@@ -22777,10 +22797,16 @@ function create(opts) {
22777
22797
  if (typeof password === 'string') {
22778
22798
  password = fromString$1(password);
22779
22799
  }
22780
- // Derive the key using PBKDF2.
22781
- const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
22782
- const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey', 'deriveBits']);
22783
- const cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['decrypt']);
22800
+ let cryptoKey;
22801
+ if (password.length === 0 && isWebkitLinux()) {
22802
+ cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['decrypt']);
22803
+ }
22804
+ else {
22805
+ // Derive the key using PBKDF2.
22806
+ const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } };
22807
+ const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey']);
22808
+ cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['decrypt']);
22809
+ }
22784
22810
  // Decrypt the string.
22785
22811
  const plaintext = await crypto.subtle.decrypt(aesGcm, cryptoKey, ciphertext);
22786
22812
  return new Uint8Array(plaintext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waku/enr",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "ENR (EIP-778) for Waku",
5
5
  "types": "./dist/index.d.ts",
6
6
  "module": "./dist/index.js",
@@ -36,11 +36,9 @@
36
36
  "build:esm": "tsc",
37
37
  "build:bundle": "rollup --config rollup.config.js",
38
38
  "fix": "run-s fix:*",
39
- "fix:prettier": "prettier . --write",
40
39
  "fix:lint": "eslint src *.js --fix",
41
40
  "check": "run-s check:*",
42
41
  "check:lint": "eslint src --ext .ts",
43
- "check:prettier": "prettier . --list-different",
44
42
  "check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
45
43
  "check:tsc": "tsc -p tsconfig.dev.json",
46
44
  "test": "run-s test:*",
@@ -54,27 +52,27 @@
54
52
  },
55
53
  "dependencies": {
56
54
  "@ethersproject/rlp": "^5.7.0",
57
- "@libp2p/crypto": "^1.0.14",
58
- "@libp2p/peer-id": "^2.0.2",
55
+ "@libp2p/crypto": "^1.0.15",
56
+ "@libp2p/peer-id": "^2.0.3",
59
57
  "@multiformats/multiaddr": "^12.0.0",
60
58
  "@noble/secp256k1": "^1.7.1",
61
- "@waku/utils": "0.0.3",
59
+ "@waku/utils": "0.0.5",
62
60
  "debug": "^4.3.4",
63
61
  "js-sha3": "^0.8.0"
64
62
  },
65
63
  "devDependencies": {
66
64
  "@libp2p/interface-peer-id": "^2.0.1",
67
65
  "@libp2p/interface-peer-info": "^1.0.8",
68
- "@libp2p/peer-id-factory": "^2.0.1",
66
+ "@libp2p/peer-id-factory": "^2.0.3",
69
67
  "@rollup/plugin-commonjs": "^24.0.1",
70
68
  "@rollup/plugin-json": "^6.0.0",
71
- "@rollup/plugin-node-resolve": "^15.0.1",
69
+ "@rollup/plugin-node-resolve": "^15.0.2",
72
70
  "@types/chai": "^4.3.4",
73
71
  "@types/mocha": "^10.0.1",
74
72
  "@typescript-eslint/eslint-plugin": "^5.57.0",
75
73
  "@typescript-eslint/parser": "^5.51.0",
76
74
  "@waku/build-utils": "*",
77
- "@waku/interfaces": "0.0.10",
75
+ "@waku/interfaces": "0.0.12",
78
76
  "chai": "^4.3.7",
79
77
  "cspell": "^6.31.1",
80
78
  "eslint": "^8.35.0",
@@ -89,10 +87,10 @@
89
87
  "karma-webpack": "^5.0.0",
90
88
  "mocha": "^10.2.0",
91
89
  "npm-run-all": "^4.1.5",
92
- "prettier": "^2.8.4",
90
+ "prettier": "^2.8.8",
93
91
  "process": "^0.11.10",
94
92
  "puppeteer": "^19.8.2",
95
- "rollup": "^3.15.0",
93
+ "rollup": "^3.21.3",
96
94
  "ts-loader": "^9.4.2",
97
95
  "typescript": "^4.9.5",
98
96
  "uint8arrays": "^4.0.3"