@libp2p/tls 2.1.1 → 2.1.2-b9e32cc37
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.
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +55 -43
- package/dist/src/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/utils.ts +63 -47
- package/dist/typedoc-urls.json +0 -8
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AAepD,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AAepD,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEjG,OAAO,KAAK,EAAE,MAAM,EAAU,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAapD,wBAAsB,qBAAqB,CAAE,cAAc,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4D/H;AAED,wBAAsB,mBAAmB,CAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAiDzG;AAeD;;GAEG;AACH,wBAAgB,mBAAmB,CAAE,aAAa,EAAE,WAAW,GAAG,UAAU,CAQ3E;AAmBD,wBAAgB,UAAU,CAAE,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,GAAG,YAAY,CAoCnG;AA0DD,wBAAgB,UAAU,CAAE,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC,CAErG"}
|
package/dist/src/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as asn1X509 from '@peculiar/asn1-x509';
|
|
|
7
7
|
import { Crypto } from '@peculiar/webcrypto';
|
|
8
8
|
import * as x509 from '@peculiar/x509';
|
|
9
9
|
import * as asn1js from 'asn1js';
|
|
10
|
-
import {
|
|
10
|
+
import { queuelessPushable } from 'it-queueless-pushable';
|
|
11
11
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
12
12
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
13
13
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
@@ -147,14 +147,18 @@ function formatAsPem(str) {
|
|
|
147
147
|
return finalString;
|
|
148
148
|
}
|
|
149
149
|
export function itToStream(conn) {
|
|
150
|
-
const output =
|
|
150
|
+
const output = queuelessPushable();
|
|
151
151
|
const iterator = conn.source[Symbol.asyncIterator]();
|
|
152
152
|
const stream = new DuplexStream({
|
|
153
153
|
autoDestroy: false,
|
|
154
154
|
allowHalfOpen: true,
|
|
155
155
|
write(chunk, encoding, callback) {
|
|
156
|
-
output.push(chunk)
|
|
157
|
-
|
|
156
|
+
void output.push(chunk)
|
|
157
|
+
.then(() => {
|
|
158
|
+
callback();
|
|
159
|
+
}, err => {
|
|
160
|
+
callback(err);
|
|
161
|
+
});
|
|
158
162
|
},
|
|
159
163
|
read() {
|
|
160
164
|
iterator.next()
|
|
@@ -177,50 +181,58 @@ export function itToStream(conn) {
|
|
|
177
181
|
});
|
|
178
182
|
return stream;
|
|
179
183
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
184
|
+
class DuplexIterable {
|
|
185
|
+
source;
|
|
186
|
+
stream;
|
|
187
|
+
constructor(stream) {
|
|
188
|
+
this.stream = stream;
|
|
189
|
+
this.source = queuelessPushable();
|
|
190
|
+
stream.addListener('data', (buf) => {
|
|
191
|
+
stream.pause();
|
|
192
|
+
this.source.push(buf.subarray())
|
|
193
|
+
.then(() => {
|
|
194
|
+
stream.resume();
|
|
195
|
+
}, (err) => {
|
|
196
|
+
stream.emit('error', err);
|
|
193
197
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
198
|
+
});
|
|
199
|
+
// both ends closed
|
|
200
|
+
stream.addListener('close', () => {
|
|
201
|
+
this.source.end()
|
|
202
|
+
.catch(err => {
|
|
203
|
+
stream.emit('error', err);
|
|
197
204
|
});
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
});
|
|
206
|
+
stream.addListener('error', (err) => {
|
|
207
|
+
this.source.end(err)
|
|
208
|
+
.catch(() => { });
|
|
209
|
+
});
|
|
210
|
+
// just writable end closed
|
|
211
|
+
stream.addListener('finish', () => {
|
|
212
|
+
this.source.end()
|
|
213
|
+
.catch(() => { });
|
|
214
|
+
});
|
|
215
|
+
this.sink = this.sink.bind(this);
|
|
216
|
+
}
|
|
217
|
+
async sink(source) {
|
|
218
|
+
try {
|
|
219
|
+
for await (const buf of source) {
|
|
220
|
+
const sendMore = this.stream.write(buf.subarray());
|
|
221
|
+
if (!sendMore) {
|
|
222
|
+
await waitForBackpressure(this.stream);
|
|
213
223
|
}
|
|
214
|
-
// close writable end
|
|
215
|
-
stream.end();
|
|
216
|
-
}
|
|
217
|
-
catch (err) {
|
|
218
|
-
stream.destroy(err);
|
|
219
|
-
throw err;
|
|
220
224
|
}
|
|
225
|
+
// close writable end
|
|
226
|
+
this.stream.end();
|
|
221
227
|
}
|
|
222
|
-
|
|
223
|
-
|
|
228
|
+
catch (err) {
|
|
229
|
+
this.stream.destroy(err);
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
export function streamToIt(stream) {
|
|
235
|
+
return new DuplexIterable(stream);
|
|
224
236
|
}
|
|
225
237
|
async function waitForBackpressure(stream) {
|
|
226
238
|
await new Promise((resolve, reject) => {
|
package/dist/src/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAChC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OA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AG,CAAC,GAAW,EAAQ,EAAE;YACzC,OAAO,EAAE,CAAA;YACT,MAAM,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAA;QAED,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;YAChD,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;YAC1C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;QAC9C,CAAC,CAAA;QAED,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;QAC7C,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;QACvC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IAC3C,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/tls",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2-b9e32cc37",
|
|
4
4
|
"description": "A connection encrypter that uses TLS 1.3",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-tls#readme",
|
|
@@ -48,22 +48,22 @@
|
|
|
48
48
|
"doc-check": "aegir doc-check"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@libp2p/crypto": "
|
|
52
|
-
"@libp2p/interface": "
|
|
53
|
-
"@libp2p/peer-id": "
|
|
51
|
+
"@libp2p/crypto": "5.1.0-b9e32cc37",
|
|
52
|
+
"@libp2p/interface": "2.8.0-b9e32cc37",
|
|
53
|
+
"@libp2p/peer-id": "5.1.1-b9e32cc37",
|
|
54
54
|
"@peculiar/asn1-schema": "^2.3.13",
|
|
55
55
|
"@peculiar/asn1-x509": "^2.3.13",
|
|
56
56
|
"@peculiar/webcrypto": "^1.5.0",
|
|
57
57
|
"@peculiar/x509": "^1.12.3",
|
|
58
58
|
"asn1js": "^3.0.5",
|
|
59
|
-
"it-pushable": "^
|
|
59
|
+
"it-queueless-pushable": "^1.0.2",
|
|
60
60
|
"it-stream-types": "^2.0.2",
|
|
61
61
|
"protons-runtime": "^5.5.0",
|
|
62
62
|
"uint8arraylist": "^2.4.8",
|
|
63
63
|
"uint8arrays": "^5.1.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@libp2p/logger": "
|
|
66
|
+
"@libp2p/logger": "5.1.14-b9e32cc37",
|
|
67
67
|
"aegir": "^45.1.1",
|
|
68
68
|
"it-pair": "^2.0.6",
|
|
69
69
|
"protons": "^7.6.0",
|
package/src/utils.ts
CHANGED
|
@@ -7,14 +7,15 @@ import * as asn1X509 from '@peculiar/asn1-x509'
|
|
|
7
7
|
import { Crypto } from '@peculiar/webcrypto'
|
|
8
8
|
import * as x509 from '@peculiar/x509'
|
|
9
9
|
import * as asn1js from 'asn1js'
|
|
10
|
-
import {
|
|
10
|
+
import { queuelessPushable } from 'it-queueless-pushable'
|
|
11
11
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
12
12
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
13
13
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
14
14
|
import { InvalidCertificateError } from './errors.js'
|
|
15
15
|
import { KeyType, PublicKey } from './pb/index.js'
|
|
16
16
|
import type { PeerId, PublicKey as Libp2pPublicKey, Logger, PrivateKey } from '@libp2p/interface'
|
|
17
|
-
import type {
|
|
17
|
+
import type { Pushable } from 'it-queueless-pushable'
|
|
18
|
+
import type { Duplex, Source } from 'it-stream-types'
|
|
18
19
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
19
20
|
|
|
20
21
|
const crypto = new Crypto()
|
|
@@ -185,15 +186,19 @@ function formatAsPem (str: string): string {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
export function itToStream (conn: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>>): DuplexStream {
|
|
188
|
-
const output =
|
|
189
|
+
const output = queuelessPushable<Uint8Array>()
|
|
189
190
|
const iterator = conn.source[Symbol.asyncIterator]() as AsyncGenerator<Uint8Array>
|
|
190
191
|
|
|
191
192
|
const stream = new DuplexStream({
|
|
192
193
|
autoDestroy: false,
|
|
193
194
|
allowHalfOpen: true,
|
|
194
195
|
write (chunk, encoding, callback) {
|
|
195
|
-
output.push(chunk)
|
|
196
|
-
|
|
196
|
+
void output.push(chunk)
|
|
197
|
+
.then(() => {
|
|
198
|
+
callback()
|
|
199
|
+
}, err => {
|
|
200
|
+
callback(err)
|
|
201
|
+
})
|
|
197
202
|
},
|
|
198
203
|
read () {
|
|
199
204
|
iterator.next()
|
|
@@ -218,53 +223,64 @@ export function itToStream (conn: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayL
|
|
|
218
223
|
return stream
|
|
219
224
|
}
|
|
220
225
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
229
|
-
// both ends closed
|
|
230
|
-
stream.addListener('close', () => {
|
|
231
|
-
output.end()
|
|
232
|
-
})
|
|
233
|
-
stream.addListener('error', (err) => {
|
|
234
|
-
output.end(err)
|
|
235
|
-
})
|
|
236
|
-
// just writable end closed
|
|
237
|
-
stream.addListener('finish', () => {
|
|
238
|
-
output.end()
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
try {
|
|
242
|
-
yield * output
|
|
243
|
-
} catch (err: any) {
|
|
244
|
-
stream.destroy(err)
|
|
245
|
-
throw err
|
|
246
|
-
}
|
|
247
|
-
})(),
|
|
248
|
-
sink: async (source) => {
|
|
249
|
-
try {
|
|
250
|
-
for await (const buf of source) {
|
|
251
|
-
const sendMore = stream.write(buf.subarray())
|
|
252
|
-
|
|
253
|
-
if (!sendMore) {
|
|
254
|
-
await waitForBackpressure(stream)
|
|
255
|
-
}
|
|
256
|
-
}
|
|
226
|
+
class DuplexIterable implements Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
227
|
+
source: Pushable<Uint8Array>
|
|
228
|
+
private readonly stream: DuplexStream
|
|
229
|
+
|
|
230
|
+
constructor (stream: DuplexStream) {
|
|
231
|
+
this.stream = stream
|
|
232
|
+
this.source = queuelessPushable<Uint8Array>()
|
|
257
233
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
234
|
+
stream.addListener('data', (buf) => {
|
|
235
|
+
stream.pause()
|
|
236
|
+
this.source.push(buf.subarray())
|
|
237
|
+
.then(() => {
|
|
238
|
+
stream.resume()
|
|
239
|
+
}, (err) => {
|
|
240
|
+
stream.emit('error', err)
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
// both ends closed
|
|
244
|
+
stream.addListener('close', () => {
|
|
245
|
+
this.source.end()
|
|
246
|
+
.catch(err => {
|
|
247
|
+
stream.emit('error', err)
|
|
248
|
+
})
|
|
249
|
+
})
|
|
250
|
+
stream.addListener('error', (err) => {
|
|
251
|
+
this.source.end(err)
|
|
252
|
+
.catch(() => {})
|
|
253
|
+
})
|
|
254
|
+
// just writable end closed
|
|
255
|
+
stream.addListener('finish', () => {
|
|
256
|
+
this.source.end()
|
|
257
|
+
.catch(() => {})
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
this.sink = this.sink.bind(this)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async sink (source: Source<Uint8Array | Uint8ArrayList>): Promise<void> {
|
|
264
|
+
try {
|
|
265
|
+
for await (const buf of source) {
|
|
266
|
+
const sendMore = this.stream.write(buf.subarray())
|
|
267
|
+
|
|
268
|
+
if (!sendMore) {
|
|
269
|
+
await waitForBackpressure(this.stream)
|
|
270
|
+
}
|
|
263
271
|
}
|
|
272
|
+
|
|
273
|
+
// close writable end
|
|
274
|
+
this.stream.end()
|
|
275
|
+
} catch (err: any) {
|
|
276
|
+
this.stream.destroy(err)
|
|
277
|
+
throw err
|
|
264
278
|
}
|
|
265
279
|
}
|
|
280
|
+
}
|
|
266
281
|
|
|
267
|
-
|
|
282
|
+
export function streamToIt (stream: DuplexStream): Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
|
|
283
|
+
return new DuplexIterable(stream)
|
|
268
284
|
}
|
|
269
285
|
|
|
270
286
|
async function waitForBackpressure (stream: DuplexStream): Promise<void> {
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"TLSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tls.TLSComponents.html",
|
|
3
|
-
".:TLSComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_tls.TLSComponents.html",
|
|
4
|
-
"PROTOCOL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_tls.PROTOCOL.html",
|
|
5
|
-
".:PROTOCOL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_tls.PROTOCOL.html",
|
|
6
|
-
"tls": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tls.tls.html",
|
|
7
|
-
".:tls": "https://libp2p.github.io/js-libp2p/functions/_libp2p_tls.tls.html"
|
|
8
|
-
}
|