Skip to content

Commit 78b008c

Browse files
authored
chore: remove require-await comments in libp2p/crypto (#1958)
These eslint-disable-line comments are no longer needed. They were added ~3 years ago and do not affect current linting rules. provenance: 7273739 related: #1949
1 parent 18567b7 commit 78b008c

File tree

10 files changed

+24
-24
lines changed

10 files changed

+24
-24
lines changed

packages/crypto/src/aes/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ export interface AESCipher {
66
decrypt: (data: Uint8Array) => Promise<Uint8Array>
77
}
88

9-
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> { // eslint-disable-line require-await
9+
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> {
1010
const mode = cipherMode(key)
1111
const cipher = ciphers.createCipheriv(mode, key, iv)
1212
const decipher = ciphers.createDecipheriv(mode, key, iv)
1313

1414
const res: AESCipher = {
15-
async encrypt (data) { // eslint-disable-line require-await
15+
async encrypt (data) {
1616
return cipher.update(data)
1717
},
1818

19-
async decrypt (data) { // eslint-disable-line require-await
19+
async decrypt (data) {
2020
return decipher.update(data)
2121
}
2222
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function create (opts?: CreateOptions): AESCipher {
3232
* Uses the provided password to derive a pbkdf2 key. The key
3333
* will then be used to encrypt the data.
3434
*/
35-
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
35+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
3636
const salt = crypto.getRandomValues(new Uint8Array(saltLength))
3737
const nonce = crypto.getRandomValues(new Uint8Array(nonceLength))
3838
const aesGcm = { name: algorithm, iv: nonce }

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

Lines changed: 4 additions & 4 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> { // eslint-disable-line require-await
17+
async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
1818
const nonce = crypto.randomBytes(nonceLength)
1919

2020
// Create the cipher instance.
@@ -31,7 +31,7 @@ export function create (opts?: CreateOptions): AESCipher {
3131
* Uses the provided password to derive a pbkdf2 key. The key
3232
* will then be used to encrypt the data.
3333
*/
34-
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
34+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
3535
// Generate a 128-bit salt using a CSPRNG.
3636
const salt = crypto.randomBytes(saltLength)
3737

@@ -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> { // eslint-disable-line require-await
56+
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<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)
@@ -77,7 +77,7 @@ export function create (opts?: CreateOptions): AESCipher {
7777
* @param {Uint8Array} data - The data to decrypt
7878
* @param {string|Uint8Array} password - A plain password
7979
*/
80-
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
80+
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
8181
// Create Uint8Arrays of salt and ciphertextAndNonce.
8282
const salt = data.subarray(0, saltLength)
8383
const ciphertextAndNonce = data.subarray(saltLength)

packages/crypto/src/hmac/index-browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Ui
2727
)
2828

2929
return {
30-
async digest (data: Uint8Array) { // eslint-disable-line require-await
30+
async digest (data: Uint8Array) {
3131
return sign(key, data)
3232
},
3333
length: lengths[hashType]

packages/crypto/src/hmac/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface HMAC {
88

99
export async function create (hash: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise<HMAC> {
1010
const res = {
11-
async digest (data: Uint8Array) { // eslint-disable-line require-await
11+
async digest (data: Uint8Array) {
1212
const hmac = crypto.createHmac(hash.toLowerCase(), secret)
1313
hmac.update(data)
1414
return hmac.digest()

packages/crypto/src/keys/ecdh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const curves = {
1111
const curveTypes = Object.keys(curves)
1212
const names = curveTypes.join(' / ')
1313

14-
export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> { // eslint-disable-line require-await
14+
export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> {
1515
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {
1616
throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')
1717
}
@@ -22,7 +22,7 @@ export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey>
2222
return {
2323
key: ecdh.getPublicKey() as Uint8Array,
2424

25-
async genSharedKey (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> { // eslint-disable-line require-await
25+
async genSharedKey (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> {
2626
if (forcePrivate != null) {
2727
ecdh.setPrivateKey(forcePrivate.private)
2828
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Ed25519PublicKey {
1515
this._key = ensureKey(key, crypto.publicKeyLength)
1616
}
1717

18-
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
18+
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
1919
return crypto.hashAndVerify(this._key, sig, data)
2020
}
2121

@@ -52,7 +52,7 @@ export class Ed25519PrivateKey {
5252
this._publicKey = ensureKey(publicKey, crypto.publicKeyLength)
5353
}
5454

55-
async sign (message: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
55+
async sign (message: Uint8Array): Promise<Uint8Array> {
5656
return crypto.hashAndSign(this._key, message)
5757
}
5858

packages/crypto/src/keys/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ function typeToKey (type: string): typeof RSA | typeof Ed25519 | typeof Secp256k
4141
}
4242

4343
// Generates a keypair of the given type and bitsize
44-
export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
44+
export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> {
4545
return typeToKey(type).generateKeyPair(bits ?? 2048)
4646
}
4747

4848
// Generates a keypair of the given type and bitsize
4949
// seed is a 32 byte uint8array
50-
export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
50+
export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise<PrivateKey> {
5151
if (type.toLowerCase() !== 'ed25519') {
5252
throw new CodeError('Seed key derivation is unimplemented for RSA or secp256k1', 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE')
5353
}
@@ -82,7 +82,7 @@ export function marshalPublicKey (key: { bytes: Uint8Array }, type?: string): Ui
8282

8383
// Converts a protobuf serialized private key into its
8484
// representative object
85-
export async function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey> { // eslint-disable-line require-await
85+
export async function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey> {
8686
const decoded = keysPBM.PrivateKey.decode(buf)
8787
const data = decoded.Data ?? new Uint8Array()
8888

@@ -110,7 +110,7 @@ export function marshalPrivateKey (key: { bytes: Uint8Array }, type?: string): U
110110
* @param {string} encryptedKey
111111
* @param {string} password
112112
*/
113-
export async function importKey (encryptedKey: string, password: string): Promise<PrivateKey> { // eslint-disable-line require-await
113+
export async function importKey (encryptedKey: string, password: string): Promise<PrivateKey> {
114114
try {
115115
const key = await importer(encryptedKey, password)
116116
return await unmarshalPrivateKey(key)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class RsaPublicKey {
1919
this._key = key
2020
}
2121

22-
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
22+
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
2323
return crypto.hashAndVerify(this._key, sig, data)
2424
}
2525

@@ -62,7 +62,7 @@ export class RsaPrivateKey {
6262
return crypto.getRandomValues(16)
6363
}
6464

65-
async sign (message: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
65+
async sign (message: Uint8Array): Promise<Uint8Array> {
6666
return crypto.hashAndSign(this._key, message)
6767
}
6868

@@ -114,7 +114,7 @@ export class RsaPrivateKey {
114114
/**
115115
* Exports the key into a password protected PEM format
116116
*/
117-
async export (password: string, format = 'pkcs-8'): Promise<Multibase<'m'>> { // eslint-disable-line require-await
117+
async export (password: string, format = 'pkcs-8'): Promise<Multibase<'m'>> {
118118
if (format === 'pkcs-8') {
119119
const buffer = new forge.util.ByteBuffer(this.marshal())
120120
const asn1 = forge.asn1.fromDer(buffer)

packages/crypto/src/keys/rsa.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const keypair = promisify(crypto.generateKeyPair)
99

1010
export { utils }
1111

12-
export async function generateKey (bits: number): Promise<JWKKeyPair> { // eslint-disable-line require-await
12+
export async function generateKey (bits: number): Promise<JWKKeyPair> {
1313
// @ts-expect-error node types are missing jwk as a format
1414
const key = await keypair('rsa', {
1515
modulusLength: bits,
@@ -26,7 +26,7 @@ export async function generateKey (bits: number): Promise<JWKKeyPair> { // eslin
2626
}
2727

2828
// Takes a jwk key
29-
export async function unmarshalPrivateKey (key: JsonWebKey): Promise<JWKKeyPair> { // eslint-disable-line require-await
29+
export async function unmarshalPrivateKey (key: JsonWebKey): Promise<JWKKeyPair> {
3030
if (key == null) {
3131
throw new CodeError('Missing key parameter', 'ERR_MISSING_KEY')
3232
}
@@ -49,7 +49,7 @@ export async function hashAndSign (key: JsonWebKey, msg: Uint8Array): Promise<Ui
4949
.sign({ format: 'jwk', key })
5050
}
5151

52-
export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
52+
export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
5353
return crypto.createVerify('RSA-SHA256')
5454
.update(msg)
5555
// @ts-expect-error node types are missing jwk as a format

0 commit comments

Comments
 (0)