@libp2p/crypto 2.0.8-4a474d54d → 2.0.8-68db79f6b

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.
Files changed (42) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/src/aes/cipher-mode.js.map +1 -1
  3. package/dist/src/aes/index.d.ts +1 -1
  4. package/dist/src/aes/index.d.ts.map +1 -1
  5. package/dist/src/aes/index.js +1 -1
  6. package/dist/src/aes/index.js.map +1 -1
  7. package/dist/src/ciphers/aes-gcm.browser.js.map +1 -1
  8. package/dist/src/ciphers/aes-gcm.js +3 -3
  9. package/dist/src/ciphers/aes-gcm.js.map +1 -1
  10. package/dist/src/keys/ecdh-browser.js +1 -1
  11. package/dist/src/keys/ecdh-browser.js.map +1 -1
  12. package/dist/src/keys/ecdh.js.map +1 -1
  13. package/dist/src/keys/ed25519-browser.d.ts +4 -4
  14. package/dist/src/keys/ed25519-browser.d.ts.map +1 -1
  15. package/dist/src/keys/ed25519-browser.js +4 -4
  16. package/dist/src/keys/ed25519-browser.js.map +1 -1
  17. package/dist/src/keys/ed25519-class.js +2 -2
  18. package/dist/src/keys/ed25519-class.js.map +1 -1
  19. package/dist/src/keys/ed25519.d.ts +4 -4
  20. package/dist/src/keys/ed25519.d.ts.map +1 -1
  21. package/dist/src/keys/ed25519.js +6 -7
  22. package/dist/src/keys/ed25519.js.map +1 -1
  23. package/dist/src/keys/index.js.map +1 -1
  24. package/dist/src/keys/key-stretcher.js.map +1 -1
  25. package/dist/src/keys/keys.js.map +1 -1
  26. package/dist/src/keys/rsa-browser.js.map +1 -1
  27. package/dist/src/keys/rsa-class.js.map +1 -1
  28. package/dist/src/keys/rsa-utils.js.map +1 -1
  29. package/dist/src/keys/rsa.js.map +1 -1
  30. package/dist/src/keys/secp256k1-browser.js.map +1 -1
  31. package/dist/src/keys/secp256k1-class.js.map +1 -1
  32. package/dist/src/keys/secp256k1.js.map +1 -1
  33. package/dist/src/pbkdf2.js.map +1 -1
  34. package/dist/src/random-bytes.js.map +1 -1
  35. package/dist/src/util.js.map +1 -1
  36. package/dist/src/webcrypto.js.map +1 -1
  37. package/package.json +6 -2
  38. package/src/aes/index.ts +1 -1
  39. package/src/ciphers/aes-gcm.ts +3 -3
  40. package/src/keys/ed25519-browser.ts +4 -4
  41. package/src/keys/ed25519-class.ts +2 -2
  42. package/src/keys/ed25519.ts +6 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/crypto",
3
- "version": "2.0.8-4a474d54d",
3
+ "version": "2.0.8-68db79f6b",
4
4
  "description": "Crypto primitives for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/crypto#readme",
@@ -11,6 +11,10 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/libp2p/js-libp2p/issues"
13
13
  },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "provenance": true
17
+ },
14
18
  "keywords": [
15
19
  "IPFS",
16
20
  "crypto",
@@ -86,7 +90,7 @@
86
90
  "generate": "protons ./src/keys/keys.proto"
87
91
  },
88
92
  "dependencies": {
89
- "@libp2p/interface": "0.1.6-4a474d54d",
93
+ "@libp2p/interface": "0.1.6-68db79f6b",
90
94
  "@noble/curves": "^1.1.0",
91
95
  "@noble/hashes": "^1.3.1",
92
96
  "multiformats": "^12.1.3",
package/src/aes/index.ts CHANGED
@@ -51,7 +51,7 @@ export interface AESCipher {
51
51
  * @param key - The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used
52
52
  * @param iv - Must have length `16`
53
53
  */
54
- export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> {
54
+ export function create (key: Uint8Array, iv: Uint8Array): AESCipher {
55
55
  const mode = cipherMode(key)
56
56
  const cipher = ciphers.createCipheriv(mode, key, iv)
57
57
  const decipher = ciphers.createDecipheriv(mode, key, iv)
@@ -14,7 +14,7 @@ export function create (opts?: CreateOptions): AESCipher {
14
14
  const iterations = opts?.iterations ?? 32767
15
15
  const algorithmTagLength = opts?.algorithmTagLength ?? 16
16
16
 
17
- async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
17
+ function encryptWithKey (data: Uint8Array, key: Uint8Array): Uint8Array {
18
18
  const nonce = crypto.randomBytes(nonceLength)
19
19
 
20
20
  // Create the cipher instance.
@@ -43,7 +43,7 @@ export function create (opts?: CreateOptions): AESCipher {
43
43
  const key = crypto.pbkdf2Sync(password, salt, iterations, keyLength, digest)
44
44
 
45
45
  // Encrypt and prepend salt.
46
- return uint8ArrayConcat([salt, await encryptWithKey(Uint8Array.from(data), key)])
46
+ return uint8ArrayConcat([salt, encryptWithKey(Uint8Array.from(data), key)])
47
47
  }
48
48
 
49
49
  /**
@@ -53,7 +53,7 @@ export function create (opts?: CreateOptions): AESCipher {
53
53
  * this decryption cipher must be the same as those used to create
54
54
  * the encryption cipher.
55
55
  */
56
- async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
56
+ function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {
57
57
  // Create Uint8Arrays of nonce, ciphertext and tag.
58
58
  const nonce = ciphertextAndNonce.subarray(0, nonceLength)
59
59
  const ciphertext = ciphertextAndNonce.subarray(nonceLength, ciphertextAndNonce.length - algorithmTagLength)
@@ -9,7 +9,7 @@ const KEYS_BYTE_LENGTH = 32
9
9
  export { PUBLIC_KEY_BYTE_LENGTH as publicKeyLength }
10
10
  export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength }
11
11
 
12
- export async function generateKey (): Promise<Uint8ArrayKeyPair> {
12
+ export function generateKey (): Uint8ArrayKeyPair {
13
13
  // the actual private key (32 bytes)
14
14
  const privateKeyRaw = ed.utils.randomPrivateKey()
15
15
  const publicKey = ed.getPublicKey(privateKeyRaw)
@@ -26,7 +26,7 @@ export async function generateKey (): Promise<Uint8ArrayKeyPair> {
26
26
  /**
27
27
  * Generate keypair from a 32 byte uint8array
28
28
  */
29
- export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
29
+ export function generateKeyFromSeed (seed: Uint8Array): Uint8ArrayKeyPair {
30
30
  if (seed.length !== KEYS_BYTE_LENGTH) {
31
31
  throw new TypeError('"seed" must be 32 bytes in length.')
32
32
  } else if (!(seed instanceof Uint8Array)) {
@@ -45,13 +45,13 @@ export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8Array
45
45
  }
46
46
  }
47
47
 
48
- export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<Uint8Array> {
48
+ export function hashAndSign (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array {
49
49
  const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH)
50
50
 
51
51
  return ed.sign(msg instanceof Uint8Array ? msg : msg.subarray(), privateKeyRaw)
52
52
  }
53
53
 
54
- export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<boolean> {
54
+ export function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean {
55
55
  return ed.verify(sig, msg instanceof Uint8Array ? msg : msg.subarray(), publicKey)
56
56
  }
57
57
 
@@ -129,12 +129,12 @@ export function unmarshalEd25519PublicKey (bytes: Uint8Array): Ed25519PublicKey
129
129
  }
130
130
 
131
131
  export async function generateKeyPair (): Promise<Ed25519PrivateKey> {
132
- const { privateKey, publicKey } = await crypto.generateKey()
132
+ const { privateKey, publicKey } = crypto.generateKey()
133
133
  return new Ed25519PrivateKey(privateKey, publicKey)
134
134
  }
135
135
 
136
136
  export async function generateKeyPairFromSeed (seed: Uint8Array): Promise<Ed25519PrivateKey> {
137
- const { privateKey, publicKey } = await crypto.generateKeyFromSeed(seed)
137
+ const { privateKey, publicKey } = crypto.generateKeyFromSeed(seed)
138
138
  return new Ed25519PrivateKey(privateKey, publicKey)
139
139
  }
140
140
 
@@ -1,12 +1,11 @@
1
1
  import crypto from 'crypto'
2
- import { promisify } from 'util'
3
2
  import { concat as uint8arrayConcat } from 'uint8arrays/concat'
4
3
  import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
5
4
  import { toString as uint8arrayToString } from 'uint8arrays/to-string'
6
5
  import type { Uint8ArrayKeyPair } from './interface.js'
7
6
  import type { Uint8ArrayList } from 'uint8arraylist'
8
7
 
9
- const keypair = promisify(crypto.generateKeyPair)
8
+ const keypair = crypto.generateKeyPairSync
10
9
 
11
10
  const PUBLIC_KEY_BYTE_LENGTH = 32
12
11
  const PRIVATE_KEY_BYTE_LENGTH = 64 // private key is actually 32 bytes but for historical reasons we concat private and public keys
@@ -37,8 +36,8 @@ function derivePublicKey (privateKey: Uint8Array): Uint8Array {
37
36
  return uint8arrayFromString(jwk.x, 'base64url')
38
37
  }
39
38
 
40
- export async function generateKey (): Promise<Uint8ArrayKeyPair> {
41
- const key = await keypair('ed25519', {
39
+ export function generateKey (): Uint8ArrayKeyPair {
40
+ const key = keypair('ed25519', {
42
41
  publicKeyEncoding: { type: 'spki', format: 'jwk' },
43
42
  privateKeyEncoding: { type: 'pkcs8', format: 'jwk' }
44
43
  })
@@ -57,7 +56,7 @@ export async function generateKey (): Promise<Uint8ArrayKeyPair> {
57
56
  /**
58
57
  * Generate keypair from a 32 byte uint8array
59
58
  */
60
- export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
59
+ export function generateKeyFromSeed (seed: Uint8Array): Uint8ArrayKeyPair {
61
60
  if (seed.length !== KEYS_BYTE_LENGTH) {
62
61
  throw new TypeError('"seed" must be 32 bytes in length.')
63
62
  } else if (!(seed instanceof Uint8Array)) {
@@ -73,7 +72,7 @@ export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8Array
73
72
  }
74
73
  }
75
74
 
76
- export async function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<Buffer> {
75
+ export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Buffer {
77
76
  if (!(key instanceof Uint8Array)) {
78
77
  throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.')
79
78
  }
@@ -104,7 +103,7 @@ export async function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8Array
104
103
  return crypto.sign(null, msg instanceof Uint8Array ? msg : msg.subarray(), obj)
105
104
  }
106
105
 
107
- export async function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<boolean> {
106
+ export function hashAndVerify (key: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): boolean {
108
107
  if (key.byteLength !== PUBLIC_KEY_BYTE_LENGTH) {
109
108
  throw new TypeError('"key" must be 32 bytes in length.')
110
109
  } else if (!(key instanceof Uint8Array)) {