Skip to content

Commit

Permalink
chore: do not explode in browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 7, 2024
1 parent 4884404 commit 4cd2517
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
3 changes: 3 additions & 0 deletions packages/connection-encrypter-tls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"protons": "^7.5.0",
"sinon": "^18.0.0"
},
"browser": {
"./dist/src/tls.js": "./dist/src/tls.browser.js"
},
"sideEffects": false
}
27 changes: 27 additions & 0 deletions packages/connection-encrypter-tls/src/tls.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { serviceCapabilities } from '@libp2p/interface'
import { PROTOCOL } from './index.js'
import type { MultiaddrConnection, ConnectionEncrypter, SecuredConnection, SecureConnectionOptions } from '@libp2p/interface'
import type { Duplex } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'

export class TLS implements ConnectionEncrypter {
public protocol: string = PROTOCOL

constructor () {
throw new Error('TLS encryption is not possible in browsers')
}

readonly [Symbol.toStringTag] = '@libp2p/tls'

readonly [serviceCapabilities]: string[] = [
'@libp2p/connection-encryption'
]

async secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
throw new Error('TLS encryption is not possible in browsers')
}

async secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
throw new Error('TLS encryption is not possible in browsers')
}
}
29 changes: 0 additions & 29 deletions packages/transport-tcp/src/tcp.browser.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
/**
* @packageDocumentation
*
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the TCP networking stack.
*
* @example
*
* ```TypeScript
* import { createLibp2p } from 'libp2p'
* import { tcp } from '@libp2p/tcp'
* import { multiaddr } from '@multiformats/multiaddr'
*
* const node = await createLibp2p({
* transports: [
* tcp()
* ]
* })
*
* const ma = multiaddr('/ip4/123.123.123.123/tcp/1234')
*
* // dial a TCP connection, timing out after 10 seconds
* const connection = await node.dial(ma, {
* signal: AbortSignal.timeout(10_000)
* })
*
* // use connection...
* ```
*/

import { serviceCapabilities, transportSymbol } from '@libp2p/interface'
import type { TCPComponents, TCPDialEvents, TCPMetrics, TCPOptions } from './index.js'
import type { Logger, Connection, Transport, Listener } from '@libp2p/interface'
Expand Down

0 comments on commit 4cd2517

Please sign in to comment.