Skip to content
Merged
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"doc-check": "aegir doc-check"
},
"devDependencies": {
"aegir": "^47.0.22"
"aegir": "^48.0.11"
},
"private": true
}
2 changes: 1 addition & 1 deletion interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@libp2p/websockets": "^10.1.13",
"@libp2p/webtransport": "^6.0.27",
"@multiformats/multiaddr": "^13.0.1",
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"libp2p": "^3.3.2",
"p-event": "^7.0.0",
"redis": "^4.7.1"
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"docs:no-publish": "aegir docs --publish false -- --exclude interop --exclude doc"
},
"devDependencies": {
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"npm-run-all": "^4.1.5"
},
"workspaces": [
Expand All @@ -48,7 +48,6 @@
"packages/*"
],
"overrides": {
"playwright-core": "1.58.0",
"@multiformats/multiaddr": "13.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"interface-datastore": "^9.0.1"
},
"devDependencies": {
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"datastore-core": "^11.0.1"
},
"sideEffects": false
Expand Down
2 changes: 1 addition & 1 deletion packages/config/test/load-private-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { keychain } from '@libp2p/keychain'
import { defaultLogger } from '@libp2p/logger'
import { expect } from 'aegir/chai'
import { MemoryDatastore } from 'datastore-core'
import { loadOrCreateSelfKey } from '../src/index.js'
import { loadOrCreateSelfKey } from '../src/index.ts'

describe('load-private-key', () => {
it('should load a private key', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/connection-encrypter-plaintext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"@libp2p/utils": "^7.2.1",
"protons-runtime": "^6.0.1",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
"uint8arrays": "^6.1.1"
},
"devDependencies": {
"@libp2p/crypto": "^5.1.18",
"@libp2p/logger": "^6.2.7",
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"protons": "^8.1.1",
"sinon": "^21.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { peerIdFromPrivateKey } from '@libp2p/peer-id'
import { streamPair } from '@libp2p/utils'
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { plaintext } from '../src/index.js'
import { plaintext } from '../src/index.ts'
import type { ConnectionEncrypter, PeerId } from '@libp2p/interface'

describe('plaintext', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/connection-encrypter-tls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
"protons-runtime": "^6.0.1",
"reflect-metadata": "^0.2.2",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
"uint8arrays": "^6.1.1"
},
"devDependencies": {
"@libp2p/logger": "^6.2.7",
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"protons": "^8.1.1",
"sinon": "^21.0.0",
"sinon-ts": "^2.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/connection-encrypter-tls/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Uint8ArrayList } from 'uint8arraylist'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import { InvalidCertificateError } from './errors.ts'
import { KeyType, PublicKey } from './pb/index.ts'
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey, AbortOptions, MessageStream, StreamCloseEvent } from '@libp2p/interface'
Expand All @@ -34,7 +35,7 @@ const CERT_VALIDITY_PERIOD_TO = 100 * 365 * 24 * 60 * 60 * 1000 // ~100 years

export async function verifyPeerCertificate (rawCertificate: Uint8Array, expectedPeerId?: PeerId, log?: Logger): Promise<PeerId> {
const now = Date.now()
const x509Cert = new x509.X509Certificate(rawCertificate)
const x509Cert = new x509.X509Certificate(withArrayBuffer(rawCertificate))

if (x509Cert.notBefore.getTime() > now) {
log?.error('the certificate was not valid yet')
Expand Down
2 changes: 1 addition & 1 deletion packages/connection-encrypter-tls/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { multiaddrConnectionPair, streamPair } from '@libp2p/utils'
import { expect } from 'aegir/chai'
import sinon from 'sinon'
import { stubInterface } from 'sinon-ts'
import { tls } from '../src/index.js'
import { tls } from '../src/index.ts'
import type { StreamMuxerFactory, ConnectionEncrypter, PeerId, Upgrader } from '@libp2p/interface'

describe('tls', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/connection-encrypter-tls/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { expect } from 'aegir/chai'
import { pEvent } from 'p-event'
import { stubInterface } from 'sinon-ts'
import { Uint8ArrayList } from 'uint8arraylist'
import { toMessageStream, toNodeDuplex, verifyPeerCertificate } from '../src/utils.js'
import { toMessageStream, toNodeDuplex, verifyPeerCertificate } from '../src/utils.ts'
import * as testVectors from './fixtures/test-vectors.ts'

const crypto = new Crypto()
Expand Down
7 changes: 3 additions & 4 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
"multiformats": "^13.4.0",
"protons-runtime": "^6.0.1",
"uint8arraylist": "^2.4.8",
"uint8arrays": "^5.1.0"
"uint8arrays": "^6.1.1"
},
"devDependencies": {
"@types/mocha": "^10.0.10",
"aegir": "^47.0.22",
"aegir": "^48.0.11",
"asn1js": "^3.0.6",
"benchmark": "^2.1.4",
"protons": "^8.1.1"
Expand All @@ -111,8 +111,7 @@
"./dist/src/keys/ecdh/index.js": "./dist/src/keys/ecdh/index.browser.js",
"./dist/src/keys/ed25519/index.js": "./dist/src/keys/ed25519/index.browser.js",
"./dist/src/keys/rsa/index.js": "./dist/src/keys/rsa/index.browser.js",
"./dist/src/keys/secp256k1/index.js": "./dist/src/keys/secp256k1/index.browser.js",
"./dist/src/webcrypto/webcrypto.js": "./dist/src/webcrypto/webcrypto.browser.js"
"./dist/src/keys/secp256k1/index.js": "./dist/src/keys/secp256k1/index.browser.js"
},
"sideEffects": false
}
15 changes: 8 additions & 7 deletions packages/crypto/src/ciphers/aes-gcm.browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { concat } from 'uint8arrays/concat'
import { fromString } from 'uint8arrays/from-string'
import webcrypto from '../webcrypto/index.js'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import webcrypto from '../webcrypto/index.ts'
import type { CreateAESCipherOptions, AESCipher } from './interface.ts'

// WebKit on Linux does not support deriving a key from an empty PBKDF2 key.
Expand Down Expand Up @@ -53,20 +54,20 @@ export function create (opts?: CreateAESCipherOptions): AESCipher {
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt'])
try {
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', withArrayBuffer(password), { name: 'PBKDF2' }, false, ['deriveKey'])
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['encrypt'])
} catch {
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['encrypt'])
}
} else {
// Derive a key using PBKDF2.
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
const rawKey = await crypto.subtle.importKey('raw', withArrayBuffer(password), { name: 'PBKDF2' }, false, ['deriveKey'])
cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['encrypt'])
}

// Encrypt the string.
const ciphertext = await crypto.subtle.encrypt(aesGcm, cryptoKey, data)
const ciphertext = await crypto.subtle.encrypt(aesGcm, cryptoKey, withArrayBuffer(data))
return concat([salt, aesGcm.iv, new Uint8Array(ciphertext)])
}

Expand All @@ -90,20 +91,20 @@ export function create (opts?: CreateAESCipherOptions): AESCipher {
if (password.length === 0) {
try {
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
const runtimeDerivedEmptyPassword = await crypto.subtle.importKey('raw', withArrayBuffer(password), { name: 'PBKDF2' }, false, ['deriveKey'])
cryptoKey = await crypto.subtle.deriveKey(deriveParams, runtimeDerivedEmptyPassword, { name: algorithm, length: keyLength }, true, ['decrypt'])
} catch {
cryptoKey = await crypto.subtle.importKey('jwk', derivedEmptyPasswordKey, { name: 'AES-GCM' }, true, ['decrypt'])
}
} else {
// Derive the key using PBKDF2.
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }
const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])
const rawKey = await crypto.subtle.importKey('raw', withArrayBuffer(password), { name: 'PBKDF2' }, false, ['deriveKey'])
cryptoKey = await crypto.subtle.deriveKey(deriveParams, rawKey, { name: algorithm, length: keyLength }, true, ['decrypt'])
}

// Decrypt the string.
const plaintext = await crypto.subtle.decrypt(aesGcm, cryptoKey, ciphertext)
const plaintext = await crypto.subtle.decrypt(aesGcm, cryptoKey, withArrayBuffer(ciphertext))
return new Uint8Array(plaintext)
}

Expand Down
7 changes: 4 additions & 3 deletions packages/crypto/src/hmac/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import webcrypto from '../webcrypto/index.js'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import webcrypto from '../webcrypto/index.ts'
import lengths from './lengths.ts'

const hashTypes = {
Expand All @@ -8,7 +9,7 @@ const hashTypes = {
}

const sign = async (key: CryptoKey, data: Uint8Array): Promise<Uint8Array> => {
const buf = await webcrypto.get().subtle.sign({ name: 'HMAC' }, key, data)
const buf = await webcrypto.get().subtle.sign({ name: 'HMAC' }, key, withArrayBuffer(data))
return new Uint8Array(buf, 0, buf.byteLength)
}

Expand All @@ -17,7 +18,7 @@ export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Ui

const key = await webcrypto.get().subtle.importKey(
'raw',
secret,
withArrayBuffer(secret),
{
name: 'HMAC',
hash: { name: hash }
Expand Down
6 changes: 3 additions & 3 deletions packages/crypto/src/keys/ecdh/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { InvalidParametersError } from '@libp2p/interface'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { base64urlToBuffer } from '../../util.js'
import webcrypto from '../../webcrypto/index.js'
import { base64urlToBuffer } from '../../util.ts'
import webcrypto from '../../webcrypto/index.ts'
import type { Curve } from './index.ts'
import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from '../interface.js'
import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from '../interface.ts'

const curveLengths = {
'P-256': 32,
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/ecdh/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'crypto'
import { InvalidParametersError } from '@libp2p/interface'
import type { ECDHKey, ECDHKeyPair } from '../interface.js'
import type { ECDHKey, ECDHKeyPair } from '../interface.ts'

export type Curve = 'P-256' | 'P-384' | 'P-521'

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { base58btc } from 'multiformats/bases/base58'
import { CID } from 'multiformats/cid'
import { identity } from 'multiformats/hashes/identity'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { publicKeyToProtobuf } from '../index.js'
import { publicKeyToProtobuf } from '../index.ts'
import { hashAndVerify, hashAndSign } from './index.ts'
import { privateKeyToPKIMessage, publicKeyToPKIMessage } from './utils.ts'
import type { ECDSAPublicKey as ECDSAPublicKeyInterface, ECDSAPrivateKey as ECDSAPrivateKeyInterface, AbortOptions } from '@libp2p/interface'
Expand Down
7 changes: 4 additions & 3 deletions packages/crypto/src/keys/ecdsa/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JWKKeyPair } from '../interface.js'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import type { JWKKeyPair } from '../interface.ts'
import type { AbortOptions } from '@libp2p/interface'
import type { Uint8ArrayList } from 'uint8arraylist'

Expand Down Expand Up @@ -32,7 +33,7 @@ export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8Array
hash: {
name: 'SHA-256'
}
}, privateKey, msg.subarray())
}, privateKey, withArrayBuffer(msg.subarray()))
options?.signal?.throwIfAborted()

return new Uint8Array(signature, 0, signature.byteLength)
Expand All @@ -50,7 +51,7 @@ export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint
hash: {
name: 'SHA-256'
}
}, publicKey, sig, msg.subarray())
}, publicKey, withArrayBuffer(sig), withArrayBuffer(msg.subarray()))
options?.signal?.throwIfAborted()

return result
Expand Down
4 changes: 2 additions & 2 deletions packages/crypto/src/keys/ecdsa/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { InvalidParametersError } from '@libp2p/interface'
import { Uint8ArrayList } from 'uint8arraylist'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { decodeDer, encodeBitString, encodeInteger, encodeOctetString, encodeSequence } from '../rsa/der.js'
import { decodeDer, encodeBitString, encodeInteger, encodeOctetString, encodeSequence } from '../rsa/der.ts'
import { ECDSAPrivateKey as ECDSAPrivateKeyClass, ECDSAPublicKey as ECDSAPublicKeyClass } from './ecdsa.ts'
import { generateECDSAKey } from './index.ts'
import type { Curve } from '../ecdh/index.js'
import type { Curve } from '../ecdh/index.ts'
import type { ECDSAPublicKey, ECDSAPrivateKey } from '@libp2p/interface'

// 1.2.840.10045.3.1.7 prime256v1 (ANSI X9.62 named elliptic curve)
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/ed25519/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CID } from 'multiformats/cid'
import { identity } from 'multiformats/hashes/identity'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { isPromise } from '../../util.ts'
import { publicKeyToProtobuf } from '../index.js'
import { publicKeyToProtobuf } from '../index.ts'
import * as crypto from './index.ts'
import { ensureEd25519Key } from './utils.ts'
import type { Ed25519PublicKey as Ed25519PublicKeyInterface, Ed25519PrivateKey as Ed25519PrivateKeyInterface, AbortOptions } from '@libp2p/interface'
Expand Down
9 changes: 5 additions & 4 deletions packages/crypto/src/keys/ed25519/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ed25519 as ed } from '@noble/curves/ed25519.js'
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
import crypto from '../../webcrypto/index.js'
import type { Uint8ArrayKeyPair } from '../interface.js'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import crypto from '../../webcrypto/index.ts'
import type { Uint8ArrayKeyPair } from '../interface.ts'
import type { Uint8ArrayList } from 'uint8arraylist'

const PUBLIC_KEY_BYTE_LENGTH = 32
Expand Down Expand Up @@ -73,7 +74,7 @@ async function hashAndSignWebCrypto (privateKey: Uint8Array, msg: Uint8Array | U
}

const key = await crypto.get().subtle.importKey('jwk', jwk, { name: 'Ed25519' }, true, ['sign'])
const sig = await crypto.get().subtle.sign({ name: 'Ed25519' }, key, msg instanceof Uint8Array ? msg : msg.subarray())
const sig = await crypto.get().subtle.sign({ name: 'Ed25519' }, key, withArrayBuffer(msg instanceof Uint8Array ? msg : msg.subarray()))

return new Uint8Array(sig, 0, sig.byteLength)
}
Expand All @@ -99,7 +100,7 @@ export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array | Uin
async function hashAndVerifyWebCrypto (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array | Uint8ArrayList): Promise<boolean> {
if (publicKey.buffer instanceof ArrayBuffer) {
const key = await crypto.get().subtle.importKey('raw', publicKey.buffer, { name: 'Ed25519' }, false, ['verify'])
const isValid = await crypto.get().subtle.verify({ name: 'Ed25519' }, key, sig, msg instanceof Uint8Array ? msg : msg.subarray())
const isValid = await crypto.get().subtle.verify({ name: 'Ed25519' }, key, withArrayBuffer(sig), withArrayBuffer(msg instanceof Uint8Array ? msg : msg.subarray()))
return isValid
}

Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/ed25519/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ed25519 as ed } from '@noble/curves/ed25519.js'
import { concat as uint8arrayConcat } from 'uint8arrays/concat'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
import type { Uint8ArrayKeyPair } from '../interface.js'
import type { Uint8ArrayKeyPair } from '../interface.ts'
import type { Uint8ArrayList } from 'uint8arraylist'

const keypair = crypto.generateKeyPairSync
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto/src/keys/key-stretcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InvalidParametersError } from '@libp2p/interface'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import * as hmac from '../hmac/index.js'
import * as hmac from '../hmac/index.ts'
import type { EnhancedKey, EnhancedKeyPair } from './interface.ts'

interface Cipher {
Expand Down
13 changes: 7 additions & 6 deletions packages/crypto/src/keys/rsa/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { InvalidParametersError } from '@libp2p/interface'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import randomBytes from '../../random-bytes.js'
import webcrypto from '../../webcrypto/index.js'
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
import randomBytes from '../../random-bytes.ts'
import webcrypto from '../../webcrypto/index.ts'
import * as utils from './utils.ts'
import type { JWKKeyPair } from '../interface.js'
import type { JWKKeyPair } from '../interface.ts'
import type { AbortOptions } from '@libp2p/interface'
import type { Uint8ArrayList } from 'uint8arraylist'

Expand Down Expand Up @@ -49,7 +50,7 @@ export async function hashAndSign (key: JsonWebKey, msg: Uint8Array | Uint8Array
const sig = await webcrypto.get().subtle.sign(
{ name: 'RSASSA-PKCS1-v1_5' },
privateKey,
msg instanceof Uint8Array ? msg : msg.subarray()
withArrayBuffer(msg instanceof Uint8Array ? msg : msg.subarray())
)
options?.signal?.throwIfAborted()

Expand All @@ -72,8 +73,8 @@ export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint
const result = await webcrypto.get().subtle.verify(
{ name: 'RSASSA-PKCS1-v1_5' },
publicKey,
sig,
msg instanceof Uint8Array ? msg : msg.subarray()
withArrayBuffer(sig),
withArrayBuffer(msg instanceof Uint8Array ? msg : msg.subarray())
)
options?.signal?.throwIfAborted()

Expand Down
Loading
Loading