@libp2p/noise 1.0.0-049bfa0fa
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/README.md +95 -0
- package/dist/index.min.js +23 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/constants.d.ts +5 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +5 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/crypto/index.browser.d.ts +2 -0
- package/dist/src/crypto/index.browser.d.ts.map +1 -0
- package/dist/src/crypto/index.browser.js +3 -0
- package/dist/src/crypto/index.browser.js.map +1 -0
- package/dist/src/crypto/index.d.ts +3 -0
- package/dist/src/crypto/index.d.ts.map +1 -0
- package/dist/src/crypto/index.js +188 -0
- package/dist/src/crypto/index.js.map +1 -0
- package/dist/src/crypto/js.d.ts +3 -0
- package/dist/src/crypto/js.d.ts.map +1 -0
- package/dist/src/crypto/js.js +43 -0
- package/dist/src/crypto/js.js.map +1 -0
- package/dist/src/crypto.d.ts +14 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +11 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/encoder.d.ts +10 -0
- package/dist/src/encoder.d.ts.map +1 -0
- package/dist/src/encoder.js +22 -0
- package/dist/src/encoder.js.map +1 -0
- package/dist/src/errors.d.ts +6 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/index.d.ts +52 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +43 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logger.d.ts +10 -0
- package/dist/src/logger.d.ts.map +1 -0
- package/dist/src/logger.js +56 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/metrics.d.ts +4 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +20 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/noise.d.ts +58 -0
- package/dist/src/noise.d.ts.map +1 -0
- package/dist/src/noise.js +174 -0
- package/dist/src/noise.js.map +1 -0
- package/dist/src/nonce.d.ts +17 -0
- package/dist/src/nonce.d.ts.map +1 -0
- package/dist/src/nonce.js +42 -0
- package/dist/src/nonce.js.map +1 -0
- package/dist/src/performHandshake.d.ts +5 -0
- package/dist/src/performHandshake.d.ts.map +1 -0
- package/dist/src/performHandshake.js +69 -0
- package/dist/src/performHandshake.js.map +1 -0
- package/dist/src/proto/payload.d.ts +22 -0
- package/dist/src/proto/payload.d.ts.map +1 -0
- package/dist/src/proto/payload.js +133 -0
- package/dist/src/proto/payload.js.map +1 -0
- package/dist/src/protocol.d.ts +71 -0
- package/dist/src/protocol.d.ts.map +1 -0
- package/dist/src/protocol.js +257 -0
- package/dist/src/protocol.js.map +1 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +11 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +176 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +94 -0
- package/src/constants.ts +5 -0
- package/src/crypto/index.browser.ts +3 -0
- package/src/crypto/index.ts +219 -0
- package/src/crypto/js.ts +56 -0
- package/src/crypto.ts +27 -0
- package/src/encoder.ts +24 -0
- package/src/errors.ts +10 -0
- package/src/index.ts +58 -0
- package/src/logger.ts +65 -0
- package/src/metrics.ts +32 -0
- package/src/noise.ts +237 -0
- package/src/nonce.ts +49 -0
- package/src/performHandshake.ts +91 -0
- package/src/proto/payload.proto +12 -0
- package/src/proto/payload.ts +170 -0
- package/src/protocol.ts +313 -0
- package/src/types.ts +105 -0
- package/src/utils.ts +221 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
|
+
import type { ICryptoInterface } from './crypto.js';
|
|
3
|
+
import type { NoiseComponents } from './index.js';
|
|
4
|
+
import type { ICrypto, INoiseConnection, INoiseExtensions } from './types.js';
|
|
5
|
+
import type { SecuredConnection, SecureConnectionOptions, MessageStream } from '@libp2p/interface';
|
|
6
|
+
export interface NoiseExtensions {
|
|
7
|
+
webtransportCerthashes: Uint8Array[];
|
|
8
|
+
}
|
|
9
|
+
export interface NoiseInit {
|
|
10
|
+
/**
|
|
11
|
+
* x25519 private key, reuse for faster handshakes
|
|
12
|
+
*/
|
|
13
|
+
staticNoiseKey?: Uint8Array;
|
|
14
|
+
extensions?: Partial<NoiseExtensions>;
|
|
15
|
+
crypto?: ICryptoInterface;
|
|
16
|
+
prologueBytes?: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export declare class Noise implements INoiseConnection {
|
|
19
|
+
protocol: string;
|
|
20
|
+
crypto: ICrypto;
|
|
21
|
+
private readonly prologue;
|
|
22
|
+
private readonly staticKey;
|
|
23
|
+
private readonly extensions?;
|
|
24
|
+
private readonly metrics?;
|
|
25
|
+
private readonly components;
|
|
26
|
+
private readonly log;
|
|
27
|
+
constructor(components: NoiseComponents, init?: NoiseInit);
|
|
28
|
+
readonly [Symbol.toStringTag] = "@libp2p/noise";
|
|
29
|
+
readonly [serviceCapabilities]: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Encrypt outgoing data to the remote party (handshake as initiator)
|
|
32
|
+
*
|
|
33
|
+
* @param connection - streaming iterable duplex that will be encrypted
|
|
34
|
+
* @param options
|
|
35
|
+
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
|
|
36
|
+
* @param options.signal - Used to abort the operation
|
|
37
|
+
*/
|
|
38
|
+
secureOutbound(connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<INoiseExtensions>>;
|
|
39
|
+
private getStreamMuxer;
|
|
40
|
+
/**
|
|
41
|
+
* Decrypt incoming data (handshake as responder).
|
|
42
|
+
*
|
|
43
|
+
* @param connection - streaming iterable duplex that will be encrypted
|
|
44
|
+
* @param options
|
|
45
|
+
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
|
|
46
|
+
* @param options.signal - Used to abort the operation
|
|
47
|
+
*/
|
|
48
|
+
secureInbound(connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<INoiseExtensions>>;
|
|
49
|
+
/**
|
|
50
|
+
* Perform XX handshake as initiator.
|
|
51
|
+
*/
|
|
52
|
+
private performHandshakeInitiator;
|
|
53
|
+
/**
|
|
54
|
+
* Perform XX handshake as responder.
|
|
55
|
+
*/
|
|
56
|
+
private performHandshakeResponder;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=noise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise.d.ts","sourceRoot":"","sources":["../../src/noise.ts"],"names":[],"mappings":"AACA,OAAO,EAA8B,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAWnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAmB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAW,MAAM,YAAY,CAAA;AACvG,OAAO,KAAK,EAAE,iBAAiB,EAA6C,uBAAuB,EAAU,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGrJ,MAAM,WAAW,eAAe;IAC9B,sBAAsB,EAAE,UAAU,EAAE,CAAA;CACrC;AAED,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,cAAc,CAAC,EAAE,UAAU,CAAA;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IACrC,MAAM,CAAC,EAAE,gBAAgB,CAAA;IACzB,aAAa,CAAC,EAAE,UAAU,CAAA;CAC3B;AAED,qBAAa,KAAM,YAAW,gBAAgB;IACrC,QAAQ,SAAW;IACnB,MAAM,EAAE,OAAO,CAAA;IAEtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAY;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAiB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,eAAe,EAAE,IAAI,GAAE,SAAc;IAuB9D,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,mBAAkB;IAE/C,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAGvC;IAED;;;;;;;OAOG;IACG,cAAc,CAAE,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAyBjI,OAAO,CAAC,cAAc;IAsBtB;;;;;;;OAOG;IACG,aAAa,CAAE,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAyBhI;;OAEG;YACW,yBAAyB;IAmCvC;;OAEG;YACW,yBAAyB;CAiCxC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys';
|
|
2
|
+
import { InvalidCryptoExchangeError, serviceCapabilities } from '@libp2p/interface';
|
|
3
|
+
import { peerIdFromPublicKey } from '@libp2p/peer-id';
|
|
4
|
+
import { lpStream } from '@libp2p/utils';
|
|
5
|
+
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
|
|
6
|
+
import { NOISE_MSG_MAX_LENGTH_BYTES } from './constants.js';
|
|
7
|
+
import { defaultCrypto } from './crypto/index.js';
|
|
8
|
+
import { wrapCrypto } from './crypto.js';
|
|
9
|
+
import { uint16BEDecode, uint16BEEncode } from './encoder.js';
|
|
10
|
+
import { registerMetrics } from './metrics.js';
|
|
11
|
+
import { performHandshakeInitiator, performHandshakeResponder } from './performHandshake.js';
|
|
12
|
+
import { toMessageStream } from "./utils.js";
|
|
13
|
+
export class Noise {
|
|
14
|
+
protocol = '/noise';
|
|
15
|
+
crypto;
|
|
16
|
+
prologue;
|
|
17
|
+
staticKey;
|
|
18
|
+
extensions;
|
|
19
|
+
metrics;
|
|
20
|
+
components;
|
|
21
|
+
log;
|
|
22
|
+
constructor(components, init = {}) {
|
|
23
|
+
const { staticNoiseKey, extensions, crypto, prologueBytes } = init;
|
|
24
|
+
const { metrics } = components;
|
|
25
|
+
this.components = components;
|
|
26
|
+
this.log = components.logger.forComponent('libp2p:noise');
|
|
27
|
+
const _crypto = crypto ?? defaultCrypto;
|
|
28
|
+
this.crypto = wrapCrypto(_crypto);
|
|
29
|
+
this.extensions = {
|
|
30
|
+
webtransportCerthashes: [],
|
|
31
|
+
...extensions
|
|
32
|
+
};
|
|
33
|
+
this.metrics = metrics ? registerMetrics(metrics) : undefined;
|
|
34
|
+
if (staticNoiseKey) {
|
|
35
|
+
// accepts x25519 private key of length 32
|
|
36
|
+
this.staticKey = _crypto.generateX25519KeyPairFromSeed(staticNoiseKey);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.staticKey = _crypto.generateX25519KeyPair();
|
|
40
|
+
}
|
|
41
|
+
this.prologue = prologueBytes ?? uint8ArrayAlloc(0);
|
|
42
|
+
}
|
|
43
|
+
[Symbol.toStringTag] = '@libp2p/noise';
|
|
44
|
+
[serviceCapabilities] = [
|
|
45
|
+
'@libp2p/connection-encryption',
|
|
46
|
+
'@libp2p/noise'
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Encrypt outgoing data to the remote party (handshake as initiator)
|
|
50
|
+
*
|
|
51
|
+
* @param connection - streaming iterable duplex that will be encrypted
|
|
52
|
+
* @param options
|
|
53
|
+
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
|
|
54
|
+
* @param options.signal - Used to abort the operation
|
|
55
|
+
*/
|
|
56
|
+
async secureOutbound(connection, options) {
|
|
57
|
+
const log = connection.log?.newScope('noise') ?? this.log;
|
|
58
|
+
const wrappedConnection = lpStream(connection, {
|
|
59
|
+
lengthEncoder: uint16BEEncode,
|
|
60
|
+
lengthDecoder: uint16BEDecode,
|
|
61
|
+
maxDataLength: NOISE_MSG_MAX_LENGTH_BYTES
|
|
62
|
+
});
|
|
63
|
+
const handshake = await this.performHandshakeInitiator(wrappedConnection, this.components.privateKey, log, options?.remotePeer?.publicKey, options);
|
|
64
|
+
const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey);
|
|
65
|
+
return {
|
|
66
|
+
connection: toMessageStream(wrappedConnection.unwrap(), handshake, this.metrics),
|
|
67
|
+
remoteExtensions: handshake.payload.extensions,
|
|
68
|
+
remotePeer: peerIdFromPublicKey(publicKey),
|
|
69
|
+
streamMuxer: options?.skipStreamMuxerNegotiation === true ? undefined : this.getStreamMuxer(handshake.payload.extensions?.streamMuxers)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
getStreamMuxer(protocols) {
|
|
73
|
+
if (protocols == null || protocols.length === 0) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const streamMuxers = this.components.upgrader.getStreamMuxers();
|
|
77
|
+
if (streamMuxers != null) {
|
|
78
|
+
for (const protocol of protocols) {
|
|
79
|
+
const streamMuxer = streamMuxers.get(protocol);
|
|
80
|
+
if (streamMuxer != null) {
|
|
81
|
+
return streamMuxer;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (protocols.length) {
|
|
86
|
+
throw new InvalidCryptoExchangeError('Early muxer negotiation was requested but the initiator and responder had no common muxers');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decrypt incoming data (handshake as responder).
|
|
91
|
+
*
|
|
92
|
+
* @param connection - streaming iterable duplex that will be encrypted
|
|
93
|
+
* @param options
|
|
94
|
+
* @param options.remotePeer - PeerId of the remote peer. Used to validate the integrity of the remote peer
|
|
95
|
+
* @param options.signal - Used to abort the operation
|
|
96
|
+
*/
|
|
97
|
+
async secureInbound(connection, options) {
|
|
98
|
+
const log = connection.log?.newScope('noise') ?? this.log;
|
|
99
|
+
const wrappedConnection = lpStream(connection, {
|
|
100
|
+
lengthEncoder: uint16BEEncode,
|
|
101
|
+
lengthDecoder: uint16BEDecode,
|
|
102
|
+
maxDataLength: NOISE_MSG_MAX_LENGTH_BYTES
|
|
103
|
+
});
|
|
104
|
+
const handshake = await this.performHandshakeResponder(wrappedConnection, this.components.privateKey, log, options?.remotePeer?.publicKey, options);
|
|
105
|
+
const publicKey = publicKeyFromProtobuf(handshake.payload.identityKey);
|
|
106
|
+
return {
|
|
107
|
+
connection: toMessageStream(wrappedConnection.unwrap(), handshake, this.metrics),
|
|
108
|
+
remoteExtensions: handshake.payload.extensions,
|
|
109
|
+
remotePeer: peerIdFromPublicKey(publicKey),
|
|
110
|
+
streamMuxer: options?.skipStreamMuxerNegotiation === true ? undefined : this.getStreamMuxer(handshake.payload.extensions?.streamMuxers)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Perform XX handshake as initiator.
|
|
115
|
+
*/
|
|
116
|
+
async performHandshakeInitiator(connection,
|
|
117
|
+
// TODO: pass private key in noise constructor via Components
|
|
118
|
+
privateKey, log, remoteIdentityKey, options) {
|
|
119
|
+
let result;
|
|
120
|
+
const streamMuxers = options?.skipStreamMuxerNegotiation === true ? [] : [...this.components.upgrader.getStreamMuxers().keys()];
|
|
121
|
+
try {
|
|
122
|
+
result = await performHandshakeInitiator({
|
|
123
|
+
connection,
|
|
124
|
+
privateKey,
|
|
125
|
+
remoteIdentityKey,
|
|
126
|
+
log: log.newScope('xxhandshake'),
|
|
127
|
+
crypto: this.crypto,
|
|
128
|
+
prologue: this.prologue,
|
|
129
|
+
s: this.staticKey,
|
|
130
|
+
extensions: {
|
|
131
|
+
streamMuxers,
|
|
132
|
+
webtransportCerthashes: [],
|
|
133
|
+
...this.extensions
|
|
134
|
+
}
|
|
135
|
+
}, options);
|
|
136
|
+
this.metrics?.xxHandshakeSuccesses.increment();
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
this.metrics?.xxHandshakeErrors.increment();
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Perform XX handshake as responder.
|
|
146
|
+
*/
|
|
147
|
+
async performHandshakeResponder(connection, privateKey, log, remoteIdentityKey, options) {
|
|
148
|
+
let result;
|
|
149
|
+
const streamMuxers = options?.skipStreamMuxerNegotiation === true ? [] : [...this.components.upgrader.getStreamMuxers().keys()];
|
|
150
|
+
try {
|
|
151
|
+
result = await performHandshakeResponder({
|
|
152
|
+
connection,
|
|
153
|
+
privateKey,
|
|
154
|
+
remoteIdentityKey,
|
|
155
|
+
log: log.newScope('xxhandshake'),
|
|
156
|
+
crypto: this.crypto,
|
|
157
|
+
prologue: this.prologue,
|
|
158
|
+
s: this.staticKey,
|
|
159
|
+
extensions: {
|
|
160
|
+
streamMuxers,
|
|
161
|
+
webtransportCerthashes: [],
|
|
162
|
+
...this.extensions
|
|
163
|
+
}
|
|
164
|
+
}, options);
|
|
165
|
+
this.metrics?.xxHandshakeSuccesses.increment();
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
this.metrics?.xxHandshakeErrors.increment();
|
|
169
|
+
throw e;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=noise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise.js","sourceRoot":"","sources":["../../src/noise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CA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YACpB,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,SAAS,EAAE,CAAA;YAC3C,MAAM,CAAC,CAAA;QACT,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const MIN_NONCE = 0;
|
|
2
|
+
export declare const MAX_NONCE = 4294967295;
|
|
3
|
+
/**
|
|
4
|
+
* The nonce is an uint that's increased over time.
|
|
5
|
+
* Maintaining different representations help improve performance.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Nonce {
|
|
8
|
+
private n;
|
|
9
|
+
private readonly bytes;
|
|
10
|
+
private readonly view;
|
|
11
|
+
constructor(n?: number);
|
|
12
|
+
increment(): void;
|
|
13
|
+
getBytes(): Uint8Array;
|
|
14
|
+
getUint64(): number;
|
|
15
|
+
assertValue(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=nonce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.d.ts","sourceRoot":"","sources":["../../src/nonce.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,IAAI,CAAA;AAO1B,eAAO,MAAM,SAAS,aAAa,CAAA;AAInC;;;GAGG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,CAAC,CAAQ;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;gBAElB,CAAC,SAAY;IAO1B,SAAS,IAAK,IAAI;IAMlB,QAAQ,IAAK,UAAU;IAIvB,SAAS,IAAK,MAAM;IAIpB,WAAW,IAAK,IAAI;CAKrB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
|
|
2
|
+
export const MIN_NONCE = 0;
|
|
3
|
+
// For performance reasons, the nonce is represented as a JS `number`
|
|
4
|
+
// Although JS `number` can safely represent integers up to 2 ** 53 - 1, we choose to only use
|
|
5
|
+
// 4 bytes to store the data for performance reason.
|
|
6
|
+
// This is a slight deviation from the noise spec, which describes the max nonce as 2 ** 64 - 2
|
|
7
|
+
// The effect is that this implementation will need a new handshake to be performed after fewer messages are exchanged than other implementations with full uint64 nonces.
|
|
8
|
+
// this MAX_NONCE is still a large number of messages, so the practical effect of this is negligible.
|
|
9
|
+
export const MAX_NONCE = 0xffffffff;
|
|
10
|
+
const ERR_MAX_NONCE = 'Cipher state has reached maximum n, a new handshake must be performed';
|
|
11
|
+
/**
|
|
12
|
+
* The nonce is an uint that's increased over time.
|
|
13
|
+
* Maintaining different representations help improve performance.
|
|
14
|
+
*/
|
|
15
|
+
export class Nonce {
|
|
16
|
+
n;
|
|
17
|
+
bytes;
|
|
18
|
+
view;
|
|
19
|
+
constructor(n = MIN_NONCE) {
|
|
20
|
+
this.n = n;
|
|
21
|
+
this.bytes = uint8ArrayAlloc(12);
|
|
22
|
+
this.view = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength);
|
|
23
|
+
this.view.setUint32(4, n, true);
|
|
24
|
+
}
|
|
25
|
+
increment() {
|
|
26
|
+
this.n++;
|
|
27
|
+
// Even though we're treating the nonce as 8 bytes, RFC7539 specifies 12 bytes for a nonce.
|
|
28
|
+
this.view.setUint32(4, this.n, true);
|
|
29
|
+
}
|
|
30
|
+
getBytes() {
|
|
31
|
+
return this.bytes;
|
|
32
|
+
}
|
|
33
|
+
getUint64() {
|
|
34
|
+
return this.n;
|
|
35
|
+
}
|
|
36
|
+
assertValue() {
|
|
37
|
+
if (this.n > MAX_NONCE) {
|
|
38
|
+
throw new Error(ERR_MAX_NONCE);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=nonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.js","sourceRoot":"","sources":["../../src/nonce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,K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, HandshakeParams } from './types.js';
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
3
|
+
export declare function performHandshakeInitiator(init: HandshakeParams, options?: AbortOptions): Promise<HandshakeResult>;
|
|
4
|
+
export declare function performHandshakeResponder(init: HandshakeParams, options?: AbortOptions): Promise<HandshakeResult>;
|
|
5
|
+
//# sourceMappingURL=performHandshake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performHandshake.d.ts","sourceRoot":"","sources":["../../src/performHandshake.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,wBAAsB,yBAAyB,CAAE,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAwCxH;AAED,wBAAsB,yBAAyB,CAAE,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAoCxH"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { logLocalStaticKeys, logLocalEphemeralKeys, logRemoteEphemeralKey, logRemoteStaticKey, logCipherState } from './logger.js';
|
|
2
|
+
import { ZEROLEN, XXHandshakeState } from './protocol.js';
|
|
3
|
+
import { createHandshakePayload, decodeHandshakePayload } from './utils.js';
|
|
4
|
+
export async function performHandshakeInitiator(init, options) {
|
|
5
|
+
const { log, connection, crypto, privateKey, prologue, s, remoteIdentityKey, extensions } = init;
|
|
6
|
+
const payload = await createHandshakePayload(privateKey, s.publicKey, extensions);
|
|
7
|
+
const xx = new XXHandshakeState({
|
|
8
|
+
crypto,
|
|
9
|
+
protocolName: 'Noise_XX_25519_ChaChaPoly_SHA256',
|
|
10
|
+
initiator: true,
|
|
11
|
+
prologue,
|
|
12
|
+
s
|
|
13
|
+
});
|
|
14
|
+
logLocalStaticKeys(xx.s, log);
|
|
15
|
+
log.trace('Stage 0 - Initiator starting to send first message.');
|
|
16
|
+
await connection.write(xx.writeMessageA(ZEROLEN), options);
|
|
17
|
+
log.trace('Stage 0 - Initiator finished sending first message.');
|
|
18
|
+
logLocalEphemeralKeys(xx.e, log);
|
|
19
|
+
log.trace('Stage 1 - Initiator waiting to receive first message from responder...');
|
|
20
|
+
const plaintext = xx.readMessageB(await connection.read(options));
|
|
21
|
+
log.trace('Stage 1 - Initiator received the message.');
|
|
22
|
+
logRemoteEphemeralKey(xx.re, log);
|
|
23
|
+
logRemoteStaticKey(xx.rs, log);
|
|
24
|
+
log.trace("Initiator going to check remote's signature...");
|
|
25
|
+
const receivedPayload = await decodeHandshakePayload(plaintext, xx.rs, remoteIdentityKey);
|
|
26
|
+
log.trace('All good with the signature!');
|
|
27
|
+
log.trace('Stage 2 - Initiator sending third handshake message.');
|
|
28
|
+
await connection.write(xx.writeMessageC(payload), options);
|
|
29
|
+
log.trace('Stage 2 - Initiator sent message with signed payload.');
|
|
30
|
+
const [cs1, cs2] = xx.ss.split();
|
|
31
|
+
logCipherState(cs1, cs2, log);
|
|
32
|
+
return {
|
|
33
|
+
payload: receivedPayload,
|
|
34
|
+
encrypt: (plaintext) => cs1.encryptWithAd(ZEROLEN, plaintext),
|
|
35
|
+
decrypt: (ciphertext, dst) => cs2.decryptWithAd(ZEROLEN, ciphertext, dst)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export async function performHandshakeResponder(init, options) {
|
|
39
|
+
const { log, connection, crypto, privateKey, prologue, s, remoteIdentityKey, extensions } = init;
|
|
40
|
+
const payload = await createHandshakePayload(privateKey, s.publicKey, extensions);
|
|
41
|
+
const xx = new XXHandshakeState({
|
|
42
|
+
crypto,
|
|
43
|
+
protocolName: 'Noise_XX_25519_ChaChaPoly_SHA256',
|
|
44
|
+
initiator: false,
|
|
45
|
+
prologue,
|
|
46
|
+
s
|
|
47
|
+
});
|
|
48
|
+
logLocalStaticKeys(xx.s, log);
|
|
49
|
+
log.trace('Stage 0 - Responder waiting to receive first message.');
|
|
50
|
+
xx.readMessageA(await connection.read(options));
|
|
51
|
+
log.trace('Stage 0 - Responder received first message.');
|
|
52
|
+
logRemoteEphemeralKey(xx.re, log);
|
|
53
|
+
log.trace('Stage 1 - Responder sending out first message with signed payload and static key.');
|
|
54
|
+
await connection.write(xx.writeMessageB(payload), options);
|
|
55
|
+
log.trace('Stage 1 - Responder sent the second handshake message with signed payload.');
|
|
56
|
+
logLocalEphemeralKeys(xx.e, log);
|
|
57
|
+
log.trace('Stage 2 - Responder waiting for third handshake message...');
|
|
58
|
+
const plaintext = xx.readMessageC(await connection.read(options));
|
|
59
|
+
log.trace('Stage 2 - Responder received the message, finished handshake.');
|
|
60
|
+
const receivedPayload = await decodeHandshakePayload(plaintext, xx.rs, remoteIdentityKey);
|
|
61
|
+
const [cs1, cs2] = xx.ss.split();
|
|
62
|
+
logCipherState(cs1, cs2, log);
|
|
63
|
+
return {
|
|
64
|
+
payload: receivedPayload,
|
|
65
|
+
encrypt: (plaintext) => cs2.encryptWithAd(ZEROLEN, plaintext),
|
|
66
|
+
decrypt: (ciphertext, dst) => cs1.decryptWithAd(ZEROLEN, ciphertext, dst)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=performHandshake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performHandshake.js","sourceRoot":"","sources":["../../src/performHandshake.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAI3E,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAE,IAAqB,EAA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Options } from 'protons-runtime';
|
|
2
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
+
export interface NoiseExtensions {
|
|
4
|
+
webtransportCerthashes: Uint8Array[];
|
|
5
|
+
streamMuxers: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare namespace NoiseExtensions {
|
|
8
|
+
const codec: () => Codec<NoiseExtensions>;
|
|
9
|
+
const encode: (obj: Partial<NoiseExtensions>) => Uint8Array;
|
|
10
|
+
const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<NoiseExtensions>) => NoiseExtensions;
|
|
11
|
+
}
|
|
12
|
+
export interface NoiseHandshakePayload {
|
|
13
|
+
identityKey: Uint8Array;
|
|
14
|
+
identitySig: Uint8Array;
|
|
15
|
+
extensions?: NoiseExtensions;
|
|
16
|
+
}
|
|
17
|
+
export declare namespace NoiseHandshakePayload {
|
|
18
|
+
const codec: () => Codec<NoiseHandshakePayload>;
|
|
19
|
+
const encode: (obj: Partial<NoiseHandshakePayload>) => Uint8Array;
|
|
20
|
+
const decode: (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<NoiseHandshakePayload>) => NoiseHandshakePayload;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../../src/proto/payload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,eAAe;IAC9B,sBAAsB,EAAE,UAAU,EAAE,CAAA;IACpC,YAAY,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,yBAAiB,eAAe,CAAC;IAGxB,MAAM,KAAK,QAAO,KAAK,CAAC,eAAe,CAgE7C,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,OAAO,CAAC,eAAe,CAAC,KAAG,UAEtD,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,UAAU,GAAG,cAAc,EAAE,OAAO,aAAa,CAAC,eAAe,CAAC,KAAG,eAEhG,CAAA;CACF;AAED,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,UAAU,CAAA;IACvB,WAAW,EAAE,UAAU,CAAA;IACvB,UAAU,CAAC,EAAE,eAAe,CAAA;CAC7B;AAED,yBAAiB,qBAAqB,CAAC;IAG9B,MAAM,KAAK,QAAO,KAAK,CAAC,qBAAqB,CA+DnD,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,OAAO,CAAC,qBAAqB,CAAC,KAAG,UAE5D,CAAA;IAEM,MAAM,MAAM,GAAI,KAAK,UAAU,GAAG,cAAc,EAAE,OAAO,aAAa,CAAC,qBAAqB,CAAC,KAAG,qBAEtG,CAAA;CACF"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { decodeMessage, encodeMessage, MaxLengthError, message } from 'protons-runtime';
|
|
2
|
+
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
|
|
3
|
+
export var NoiseExtensions;
|
|
4
|
+
(function (NoiseExtensions) {
|
|
5
|
+
let _codec;
|
|
6
|
+
NoiseExtensions.codec = () => {
|
|
7
|
+
if (_codec == null) {
|
|
8
|
+
_codec = message((obj, w, opts = {}) => {
|
|
9
|
+
if (opts.lengthDelimited !== false) {
|
|
10
|
+
w.fork();
|
|
11
|
+
}
|
|
12
|
+
if (obj.webtransportCerthashes != null) {
|
|
13
|
+
for (const value of obj.webtransportCerthashes) {
|
|
14
|
+
w.uint32(10);
|
|
15
|
+
w.bytes(value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (obj.streamMuxers != null) {
|
|
19
|
+
for (const value of obj.streamMuxers) {
|
|
20
|
+
w.uint32(18);
|
|
21
|
+
w.string(value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (opts.lengthDelimited !== false) {
|
|
25
|
+
w.ldelim();
|
|
26
|
+
}
|
|
27
|
+
}, (reader, length, opts = {}) => {
|
|
28
|
+
const obj = {
|
|
29
|
+
webtransportCerthashes: [],
|
|
30
|
+
streamMuxers: []
|
|
31
|
+
};
|
|
32
|
+
const end = length == null ? reader.len : reader.pos + length;
|
|
33
|
+
while (reader.pos < end) {
|
|
34
|
+
const tag = reader.uint32();
|
|
35
|
+
switch (tag >>> 3) {
|
|
36
|
+
case 1: {
|
|
37
|
+
if (opts.limits?.webtransportCerthashes != null && obj.webtransportCerthashes.length === opts.limits.webtransportCerthashes) {
|
|
38
|
+
throw new MaxLengthError('Decode error - map field "webtransportCerthashes" had too many elements');
|
|
39
|
+
}
|
|
40
|
+
obj.webtransportCerthashes.push(reader.bytes());
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 2: {
|
|
44
|
+
if (opts.limits?.streamMuxers != null && obj.streamMuxers.length === opts.limits.streamMuxers) {
|
|
45
|
+
throw new MaxLengthError('Decode error - map field "streamMuxers" had too many elements');
|
|
46
|
+
}
|
|
47
|
+
obj.streamMuxers.push(reader.string());
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
default: {
|
|
51
|
+
reader.skipType(tag & 7);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return obj;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return _codec;
|
|
60
|
+
};
|
|
61
|
+
NoiseExtensions.encode = (obj) => {
|
|
62
|
+
return encodeMessage(obj, NoiseExtensions.codec());
|
|
63
|
+
};
|
|
64
|
+
NoiseExtensions.decode = (buf, opts) => {
|
|
65
|
+
return decodeMessage(buf, NoiseExtensions.codec(), opts);
|
|
66
|
+
};
|
|
67
|
+
})(NoiseExtensions || (NoiseExtensions = {}));
|
|
68
|
+
export var NoiseHandshakePayload;
|
|
69
|
+
(function (NoiseHandshakePayload) {
|
|
70
|
+
let _codec;
|
|
71
|
+
NoiseHandshakePayload.codec = () => {
|
|
72
|
+
if (_codec == null) {
|
|
73
|
+
_codec = message((obj, w, opts = {}) => {
|
|
74
|
+
if (opts.lengthDelimited !== false) {
|
|
75
|
+
w.fork();
|
|
76
|
+
}
|
|
77
|
+
if ((obj.identityKey != null && obj.identityKey.byteLength > 0)) {
|
|
78
|
+
w.uint32(10);
|
|
79
|
+
w.bytes(obj.identityKey);
|
|
80
|
+
}
|
|
81
|
+
if ((obj.identitySig != null && obj.identitySig.byteLength > 0)) {
|
|
82
|
+
w.uint32(18);
|
|
83
|
+
w.bytes(obj.identitySig);
|
|
84
|
+
}
|
|
85
|
+
if (obj.extensions != null) {
|
|
86
|
+
w.uint32(34);
|
|
87
|
+
NoiseExtensions.codec().encode(obj.extensions, w);
|
|
88
|
+
}
|
|
89
|
+
if (opts.lengthDelimited !== false) {
|
|
90
|
+
w.ldelim();
|
|
91
|
+
}
|
|
92
|
+
}, (reader, length, opts = {}) => {
|
|
93
|
+
const obj = {
|
|
94
|
+
identityKey: uint8ArrayAlloc(0),
|
|
95
|
+
identitySig: uint8ArrayAlloc(0)
|
|
96
|
+
};
|
|
97
|
+
const end = length == null ? reader.len : reader.pos + length;
|
|
98
|
+
while (reader.pos < end) {
|
|
99
|
+
const tag = reader.uint32();
|
|
100
|
+
switch (tag >>> 3) {
|
|
101
|
+
case 1: {
|
|
102
|
+
obj.identityKey = reader.bytes();
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 2: {
|
|
106
|
+
obj.identitySig = reader.bytes();
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 4: {
|
|
110
|
+
obj.extensions = NoiseExtensions.codec().decode(reader, reader.uint32(), {
|
|
111
|
+
limits: opts.limits?.extensions
|
|
112
|
+
});
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
reader.skipType(tag & 7);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return obj;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return _codec;
|
|
125
|
+
};
|
|
126
|
+
NoiseHandshakePayload.encode = (obj) => {
|
|
127
|
+
return encodeMessage(obj, NoiseHandshakePayload.codec());
|
|
128
|
+
};
|
|
129
|
+
NoiseHandshakePayload.decode = (buf, opts) => {
|
|
130
|
+
return decodeMessage(buf, NoiseHandshakePayload.codec(), opts);
|
|
131
|
+
};
|
|
132
|
+
})(NoiseHandshakePayload || (NoiseHandshakePayload = {}));
|
|
133
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../src/proto/payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACvF,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAS5D,MAAM,KAAW,eAAe,CA4E/B;AA5ED,WAAiB,eAAe;IAC9B,IAAI,MAA8B,CAAA;IAErB,qBAAK,GAAG,GAA2B,EAAE;QAChD,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,GAAG,OAAO,CAAkB,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBACtD,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,IAAI,EAAE,CAAA;gBACV,CAAC;gBAED,IAAI,GAAG,CAAC,sBAAsB,IAAI,IAAI,EAAE,CAAC;oBACvC,KAAK,MAAM,KAAK,IAAI,GAAG,CAAC,sBAAsB,EAAE,CAAC;wBAC/C,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;wBACZ,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;oBAChB,CAAC;gBACH,CAAC;gBAED,IAA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State, ISymmetricState, IHandshakeState, KeyPair, ICrypto } from './types.js';
|
|
4
|
+
export declare const ZEROLEN: Uint8Array<ArrayBufferLike>;
|
|
5
|
+
interface ICipherStateWithKey extends ICipherState {
|
|
6
|
+
k: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export declare class CipherState implements ICipherState {
|
|
9
|
+
k?: Uint8Array;
|
|
10
|
+
n: Nonce;
|
|
11
|
+
private readonly crypto;
|
|
12
|
+
constructor(crypto: ICrypto, k?: Uint8Array | undefined, n?: number);
|
|
13
|
+
hasKey(): this is ICipherStateWithKey;
|
|
14
|
+
encryptWithAd(ad: Uint8Array, plaintext: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
15
|
+
decryptWithAd(ad: Uint8Array, ciphertext: Uint8Array | Uint8ArrayList, dst?: Uint8Array): Uint8Array | Uint8ArrayList;
|
|
16
|
+
}
|
|
17
|
+
export declare class SymmetricState implements ISymmetricState {
|
|
18
|
+
cs: CipherState;
|
|
19
|
+
ck: Uint8Array;
|
|
20
|
+
h: Uint8Array;
|
|
21
|
+
private readonly crypto;
|
|
22
|
+
constructor(crypto: ICrypto, protocolName: string);
|
|
23
|
+
mixKey(ikm: Uint8Array): void;
|
|
24
|
+
mixHash(data: Uint8Array | Uint8ArrayList): void;
|
|
25
|
+
encryptAndHash(plaintext: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
26
|
+
decryptAndHash(ciphertext: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
27
|
+
split(): [CipherState, CipherState];
|
|
28
|
+
}
|
|
29
|
+
export interface HandshakeStateInit {
|
|
30
|
+
crypto: ICrypto;
|
|
31
|
+
protocolName: string;
|
|
32
|
+
initiator: boolean;
|
|
33
|
+
prologue: Uint8Array;
|
|
34
|
+
s?: KeyPair;
|
|
35
|
+
e?: KeyPair;
|
|
36
|
+
rs?: Uint8Array | Uint8ArrayList;
|
|
37
|
+
re?: Uint8Array | Uint8ArrayList;
|
|
38
|
+
}
|
|
39
|
+
export declare abstract class AbstractHandshakeState implements IHandshakeState {
|
|
40
|
+
ss: SymmetricState;
|
|
41
|
+
s?: KeyPair;
|
|
42
|
+
e?: KeyPair;
|
|
43
|
+
rs?: Uint8Array | Uint8ArrayList;
|
|
44
|
+
re?: Uint8Array | Uint8ArrayList;
|
|
45
|
+
initiator: boolean;
|
|
46
|
+
protected readonly crypto: ICrypto;
|
|
47
|
+
constructor(init: HandshakeStateInit);
|
|
48
|
+
protected writeE(): Uint8Array;
|
|
49
|
+
protected writeS(): Uint8Array | Uint8ArrayList;
|
|
50
|
+
protected writeEE(): void;
|
|
51
|
+
protected writeES(): void;
|
|
52
|
+
protected writeSE(): void;
|
|
53
|
+
protected readE(message: Uint8ArrayList, offset?: number): void;
|
|
54
|
+
protected readS(message: Uint8ArrayList, offset?: number): number;
|
|
55
|
+
protected readEE(): void;
|
|
56
|
+
protected readES(): void;
|
|
57
|
+
protected readSE(): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A IHandshakeState that's optimized for the XX pattern
|
|
61
|
+
*/
|
|
62
|
+
export declare class XXHandshakeState extends AbstractHandshakeState {
|
|
63
|
+
writeMessageA(payload: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
64
|
+
writeMessageB(payload: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
65
|
+
writeMessageC(payload: Uint8Array | Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
66
|
+
readMessageA(message: Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
67
|
+
readMessageB(message: Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
68
|
+
readMessageC(message: Uint8ArrayList): Uint8Array | Uint8ArrayList;
|
|
69
|
+
}
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=protocol.d.ts.map
|