Skip to content

Commit 7238baa

Browse files
authored
Merge branch 'main' into feat/config-validation
2 parents 3fff6fd + 68db79f commit 7238baa

File tree

38 files changed

+146
-21
lines changed

38 files changed

+146
-21
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ jobs:
218218
transport-interop
219219
]
220220
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
221+
# https://docs.npmjs.com/generating-provenance-statements
222+
permissions:
223+
id-token: write
221224
steps:
222225
- uses: GoogleCloudPlatform/release-please-action@v2
223226
id: release

packages/crypto/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"bugs": {
1212
"url": "https://github.com/libp2p/js-libp2p/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"IPFS",
1620
"crypto",

packages/crypto/src/aes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface AESCipher {
5151
* @param key - The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used
5252
* @param iv - Must have length `16`
5353
*/
54-
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> {
54+
export function create (key: Uint8Array, iv: Uint8Array): AESCipher {
5555
const mode = cipherMode(key)
5656
const cipher = ciphers.createCipheriv(mode, key, iv)
5757
const decipher = ciphers.createDecipheriv(mode, key, iv)

packages/crypto/src/ciphers/aes-gcm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function create (opts?: CreateOptions): AESCipher {
1414
const iterations = opts?.iterations ?? 32767
1515
const algorithmTagLength = opts?.algorithmTagLength ?? 16
1616

17-
async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
17+
function encryptWithKey (data: Uint8Array, key: Uint8Array): Uint8Array {
1818
const nonce = crypto.randomBytes(nonceLength)
1919

2020
// Create the cipher instance.
@@ -43,7 +43,7 @@ export function create (opts?: CreateOptions): AESCipher {
4343
const key = crypto.pbkdf2Sync(password, salt, iterations, keyLength, digest)
4444

4545
// Encrypt and prepend salt.
46-
return uint8ArrayConcat([salt, await encryptWithKey(Uint8Array.from(data), key)])
46+
return uint8ArrayConcat([salt, encryptWithKey(Uint8Array.from(data), key)])
4747
}
4848

4949
/**
@@ -53,7 +53,7 @@ export function create (opts?: CreateOptions): AESCipher {
5353
* this decryption cipher must be the same as those used to create
5454
* the encryption cipher.
5555
*/
56-
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
56+
function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {
5757
// Create Uint8Arrays of nonce, ciphertext and tag.
5858
const nonce = ciphertextAndNonce.subarray(0, nonceLength)
5959
const ciphertext = ciphertextAndNonce.subarray(nonceLength, ciphertextAndNonce.length - algorithmTagLength)

packages/crypto/src/keys/ed25519-browser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const KEYS_BYTE_LENGTH = 32
99
export { PUBLIC_KEY_BYTE_LENGTH as publicKeyLength }
1010
export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength }
1111

12-
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
12+
export function generateKey (): Uint8ArrayKeyPair {
1313
// the actual private key (32 bytes)
1414
const privateKeyRaw = ed.utils.randomPrivateKey()
1515
const publicKey = ed.getPublicKey(privateKeyRaw)
@@ -26,7 +26,7 @@ export async function generateKey (): Promise<Uint8ArrayKeyPair> {
2626
/**
2727
* Generate keypair from a 32 byte uint8array
2828
*/
29-
export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
29+
export function generateKeyFromSeed (seed: Uint8Array): Uint8ArrayKeyPair {
3030
if (seed.length !== KEYS_BYTE_LENGTH) {
3131
throw new TypeError('"seed" must be 32 bytes in length.')
3232
} else if (!(seed instanceof Uint8Array)) {
@@ -45,13 +45,13 @@ export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8Array
4545
}
4646
}
4747

48-
export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<Uint8Array> {
48+
export function hashAndSign (privateKey: Uint8Array, msg: Uint8Array | Uint8ArrayList): Uint8Array {
4949
const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH)
5050

5151
return ed.sign(msg instanceof Uint8Array ? msg : msg.subarray(), privateKeyRaw)
5252
}
5353

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 {
5555
return ed.verify(sig, msg instanceof Uint8Array ? msg : msg.subarray(), publicKey)
5656
}
5757

packages/crypto/src/keys/ed25519-class.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ export function unmarshalEd25519PublicKey (bytes: Uint8Array): Ed25519PublicKey
129129
}
130130

131131
export async function generateKeyPair (): Promise<Ed25519PrivateKey> {
132-
const { privateKey, publicKey } = await crypto.generateKey()
132+
const { privateKey, publicKey } = crypto.generateKey()
133133
return new Ed25519PrivateKey(privateKey, publicKey)
134134
}
135135

136136
export async function generateKeyPairFromSeed (seed: Uint8Array): Promise<Ed25519PrivateKey> {
137-
const { privateKey, publicKey } = await crypto.generateKeyFromSeed(seed)
137+
const { privateKey, publicKey } = crypto.generateKeyFromSeed(seed)
138138
return new Ed25519PrivateKey(privateKey, publicKey)
139139
}
140140

packages/crypto/src/keys/ed25519.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import crypto from 'crypto'
2-
import { promisify } from 'util'
32
import { concat as uint8arrayConcat } from 'uint8arrays/concat'
43
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
54
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
65
import type { Uint8ArrayKeyPair } from './interface.js'
76
import type { Uint8ArrayList } from 'uint8arraylist'
87

9-
const keypair = promisify(crypto.generateKeyPair)
8+
const keypair = crypto.generateKeyPairSync
109

1110
const PUBLIC_KEY_BYTE_LENGTH = 32
1211
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 {
3736
return uint8arrayFromString(jwk.x, 'base64url')
3837
}
3938

40-
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
41-
const key = await keypair('ed25519', {
39+
export function generateKey (): Uint8ArrayKeyPair {
40+
const key = keypair('ed25519', {
4241
publicKeyEncoding: { type: 'spki', format: 'jwk' },
4342
privateKeyEncoding: { type: 'pkcs8', format: 'jwk' }
4443
})
@@ -57,7 +56,7 @@ export async function generateKey (): Promise<Uint8ArrayKeyPair> {
5756
/**
5857
* Generate keypair from a 32 byte uint8array
5958
*/
60-
export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
59+
export function generateKeyFromSeed (seed: Uint8Array): Uint8ArrayKeyPair {
6160
if (seed.length !== KEYS_BYTE_LENGTH) {
6261
throw new TypeError('"seed" must be 32 bytes in length.')
6362
} else if (!(seed instanceof Uint8Array)) {
@@ -73,7 +72,7 @@ export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8Array
7372
}
7473
}
7574

76-
export async function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<Buffer> {
75+
export function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8ArrayList): Buffer {
7776
if (!(key instanceof Uint8Array)) {
7877
throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.')
7978
}
@@ -104,7 +103,7 @@ export async function hashAndSign (key: Uint8Array, msg: Uint8Array | Uint8Array
104103
return crypto.sign(null, msg instanceof Uint8Array ? msg : msg.subarray(), obj)
105104
}
106105

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 {
108107
if (key.byteLength !== PUBLIC_KEY_BYTE_LENGTH) {
109108
throw new TypeError('"key" must be 32 bytes in length.')
110109
} else if (!(key instanceof Uint8Array)) {

packages/crypto/test/aes/aes.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('AES-CTR', () => {
2424
const iv = new Uint8Array(16)
2525
iv.fill(1)
2626

27-
const cipher = await crypto.aes.create(key, iv)
27+
const cipher = crypto.aes.create(key, iv)
2828

2929
await encryptAndDecrypt(cipher)
3030
await encryptAndDecrypt(cipher)
@@ -42,7 +42,7 @@ describe('AES-CTR', () => {
4242
const iv = new Uint8Array(16)
4343
iv.fill(1)
4444

45-
const cipher = await crypto.aes.create(key, iv)
45+
const cipher = crypto.aes.create(key, iv)
4646
// @ts-expect-error cannot index fixtures like this
4747
const fixture = fixtures[length]
4848

@@ -71,7 +71,7 @@ describe('AES-CTR', () => {
7171
const iv = new Uint8Array(16)
7272
iv.fill(1)
7373

74-
const cipher = await crypto.aes.create(key, iv)
74+
const cipher = crypto.aes.create(key, iv)
7575
// @ts-expect-error cannot index fixtures like this
7676
const fixture = goFixtures[length]
7777

@@ -90,7 +90,7 @@ describe('AES-CTR', () => {
9090
it('checks key length', () => {
9191
const key = new Uint8Array(5)
9292
const iv = new Uint8Array(16)
93-
return expect(crypto.aes.create(key, iv)).to.eventually.be.rejected.with.property('code', 'ERR_INVALID_KEY_LENGTH')
93+
return expect(() => crypto.aes.create(key, iv)).to.throw().with.property('code', 'ERR_INVALID_KEY_LENGTH')
9494
})
9595
})
9696

packages/interface-internal/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"bugs": {
1212
"url": "https://github.com/libp2p/js-libp2p/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"interface",
1620
"libp2p"

packages/kad-dht/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"bugs": {
1212
"url": "https://github.com/libp2p/js-libp2p/issues"
1313
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
1418
"keywords": [
1519
"IPFS"
1620
],

0 commit comments

Comments
 (0)