@streamr/trackerless-network 101.0.0-beta.1 → 101.0.0-beta.3
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/package.json +5 -6
- package/dist/src/NetworkNode.d.ts +5 -7
- package/dist/src/NetworkNode.js +5 -24
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +1 -2
- package/dist/src/NetworkStack.js +1 -2
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -5
- package/dist/src/exports.js +13 -13
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/ContentDeliveryLayerNode.d.ts +5 -5
- package/dist/src/logic/ContentDeliveryLayerNode.js +3 -3
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/ContentDeliveryManager.d.ts +1 -2
- package/dist/src/logic/ContentDeliveryManager.js +2 -3
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +3 -3
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcRemote.d.ts +1 -1
- package/dist/src/logic/ContentDeliveryRpcRemote.js.map +1 -1
- package/dist/src/logic/createContentDeliveryLayerNode.d.ts +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +2 -2
- package/dist/src/logic/inspect/Inspector.js +2 -2
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +4 -4
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/Handshaker.js +4 -4
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +3 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -2
- package/dist/src/logic/proxy/ProxyClient.js +3 -3
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +3 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/test/benchmark/first-message.js +23 -12
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +4 -5
- package/dist/test/utils/utils.js +6 -7
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +5 -6
- package/src/NetworkNode.ts +7 -25
- package/src/NetworkStack.ts +1 -2
- package/src/exports.ts +14 -11
- package/src/logic/ContentDeliveryLayerNode.ts +28 -29
- package/src/logic/ContentDeliveryManager.ts +1 -2
- package/src/logic/ContentDeliveryRpcLocal.ts +3 -3
- package/src/logic/ContentDeliveryRpcRemote.ts +1 -2
- package/src/logic/createContentDeliveryLayerNode.ts +1 -1
- package/src/logic/formStreamPartDeliveryServiceId.ts +1 -1
- package/src/logic/inspect/Inspector.ts +3 -4
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +9 -10
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +1 -2
- package/src/logic/neighbor-discovery/Handshaker.ts +8 -9
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +4 -5
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +2 -2
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +1 -2
- package/src/logic/proxy/ProxyClient.ts +6 -7
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +5 -6
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +7 -7
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +2 -2
- package/test/benchmark/first-message.ts +28 -29
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +4 -5
- package/test/end-to-end/inspect.test.ts +26 -28
- package/test/end-to-end/proxy-and-full-node.test.ts +34 -32
- package/test/end-to-end/proxy-connections.test.ts +34 -31
- package/test/end-to-end/proxy-key-exchange.test.ts +41 -57
- package/test/end-to-end/webrtc-full-node-network.test.ts +1 -2
- package/test/end-to-end/websocket-full-node-network.test.ts +2 -3
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +2 -3
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +2 -3
- package/test/integration/ContentDeliveryManager.test.ts +3 -4
- package/test/integration/ContentDeliveryRpcRemote.test.ts +7 -8
- package/test/integration/HandshakeRpcRemote.test.ts +6 -6
- package/test/integration/Handshakes.test.ts +6 -6
- package/test/integration/Inspect.test.ts +1 -1
- package/test/integration/NeighborUpdateRpcRemote.test.ts +1 -1
- package/test/integration/NetworkNode.test.ts +28 -29
- package/test/integration/NetworkRpc.test.ts +7 -8
- package/test/integration/NetworkStack.test.ts +4 -4
- package/test/integration/NodeInfoRpc.test.ts +3 -4
- package/test/integration/Propagation.test.ts +2 -3
- package/test/integration/joining-streams-on-offline-peers.test.ts +3 -4
- package/test/integration/stream-without-default-entrypoints.test.ts +26 -28
- package/test/integration/streamEntryPointReplacing.test.ts +5 -6
- package/test/unit/ContentDeliveryLayerNode.test.ts +5 -6
- package/test/unit/ContentDeliveryManager.test.ts +2 -3
- package/test/unit/ContentDeliveryRpcLocal.test.ts +1 -1
- package/test/unit/HandshakeRpcLocal.test.ts +2 -2
- package/test/unit/Handshaker.test.ts +2 -2
- package/test/unit/Inspector.test.ts +1 -2
- package/test/unit/NeighborUpdateRpcLocal.test.ts +6 -6
- package/test/unit/NetworkNode.test.ts +3 -4
- package/test/unit/NodeList.test.ts +2 -2
- package/test/unit/StreamPartIDDataKey.test.ts +1 -1
- package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +1 -2
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +2 -2
- package/test/utils/mock/MockTransport.ts +1 -2
- package/test/utils/utils.ts +8 -9
- package/tsconfig.jest.json +0 -1
- package/tsconfig.node.json +0 -2
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.d.ts +0 -6
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +0 -28
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +0 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.d.ts +0 -6
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +0 -32
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +0 -1
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.d.ts +0 -6
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +0 -170
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +0 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +0 -7
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +0 -32
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +0 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +0 -28
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +0 -34
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +0 -197
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +0 -37
- package/test/unit/GroupKeyResponseTranslator.test.ts +0 -39
- package/test/unit/StreamMessageTranslator.test.ts +0 -71
- package/test/unit/oldStreamMessageBinaryUtils.test.ts +0 -39
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertBytesToGroupKeyResponse = exports.convertGroupKeyResponseToBytes = exports.convertBytesToGroupKeyRequest = exports.convertGroupKeyRequestToBytes = exports.convertBytesToStreamMessage = exports.convertStreamMessageToBytes = void 0;
|
|
4
|
-
const StreamMessageTranslator_1 = require("./StreamMessageTranslator");
|
|
5
|
-
const NetworkRpc_1 = require("../../../proto/packages/trackerless-network/protos/NetworkRpc");
|
|
6
|
-
const GroupKeyResponseTranslator_1 = require("./GroupKeyResponseTranslator");
|
|
7
|
-
const GroupKeyRequestTranslator_1 = require("./GroupKeyRequestTranslator");
|
|
8
|
-
function convertStreamMessageToBytes(oldStreamMessage) {
|
|
9
|
-
return NetworkRpc_1.StreamMessage.toBinary(StreamMessageTranslator_1.StreamMessageTranslator.toProtobuf(oldStreamMessage));
|
|
10
|
-
}
|
|
11
|
-
exports.convertStreamMessageToBytes = convertStreamMessageToBytes;
|
|
12
|
-
function convertBytesToStreamMessage(bytes) {
|
|
13
|
-
return StreamMessageTranslator_1.StreamMessageTranslator.toClientProtocol(NetworkRpc_1.StreamMessage.fromBinary(bytes));
|
|
14
|
-
}
|
|
15
|
-
exports.convertBytesToStreamMessage = convertBytesToStreamMessage;
|
|
16
|
-
const convertGroupKeyRequestToBytes = (oldGroupKeyRequest) => {
|
|
17
|
-
return NetworkRpc_1.GroupKeyRequest.toBinary(GroupKeyRequestTranslator_1.GroupKeyRequestTranslator.toProtobuf(oldGroupKeyRequest));
|
|
18
|
-
};
|
|
19
|
-
exports.convertGroupKeyRequestToBytes = convertGroupKeyRequestToBytes;
|
|
20
|
-
const convertBytesToGroupKeyRequest = (bytes) => {
|
|
21
|
-
return GroupKeyRequestTranslator_1.GroupKeyRequestTranslator.toClientProtocol(NetworkRpc_1.GroupKeyRequest.fromBinary(bytes));
|
|
22
|
-
};
|
|
23
|
-
exports.convertBytesToGroupKeyRequest = convertBytesToGroupKeyRequest;
|
|
24
|
-
const convertGroupKeyResponseToBytes = (oldGroupKeyResponse) => {
|
|
25
|
-
return NetworkRpc_1.GroupKeyResponse.toBinary(GroupKeyResponseTranslator_1.GroupKeyResponseTranslator.toProtobuf(oldGroupKeyResponse));
|
|
26
|
-
};
|
|
27
|
-
exports.convertGroupKeyResponseToBytes = convertGroupKeyResponseToBytes;
|
|
28
|
-
const convertBytesToGroupKeyResponse = (bytes) => {
|
|
29
|
-
return GroupKeyResponseTranslator_1.GroupKeyResponseTranslator.toClientProtocol(NetworkRpc_1.GroupKeyResponse.fromBinary(bytes));
|
|
30
|
-
};
|
|
31
|
-
exports.convertBytesToGroupKeyResponse = convertBytesToGroupKeyResponse;
|
|
32
|
-
//# sourceMappingURL=oldStreamMessageBinaryUtils.js.map
|
package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oldStreamMessageBinaryUtils.js","sourceRoot":"","sources":["../../../../../src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts"],"names":[],"mappings":";;;AAKA,uEAAmE;AACnE,8FAIsE;AACtE,6EAAyE;AACzE,2EAAuE;AAEvE,SAAgB,2BAA2B,CAAC,gBAAkC;IAC1E,OAAO,0BAAa,CAAC,QAAQ,CAAC,iDAAuB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAA;AACvF,CAAC;AAFD,kEAEC;AAED,SAAgB,2BAA2B,CAAC,KAAiB;IACzD,OAAO,iDAAuB,CAAC,gBAAgB,CAAC,0BAAa,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AACpF,CAAC;AAFD,kEAEC;AAEM,MAAM,6BAA6B,GAAG,CAAC,kBAAsC,EAAc,EAAE;IAChG,OAAO,4BAAe,CAAC,QAAQ,CAAC,qDAAyB,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAC7F,CAAC,CAAA;AAFY,QAAA,6BAA6B,iCAEzC;AAEM,MAAM,6BAA6B,GAAG,CAAC,KAAiB,EAAsB,EAAE;IACnF,OAAO,qDAAyB,CAAC,gBAAgB,CAAC,4BAAe,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AACxF,CAAC,CAAA;AAFY,QAAA,6BAA6B,iCAEzC;AAEM,MAAM,8BAA8B,GAAG,CAAC,mBAAwC,EAAc,EAAE;IACnG,OAAO,6BAAgB,CAAC,QAAQ,CAAC,uDAA0B,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,CAAA;AAChG,CAAC,CAAA;AAFY,QAAA,8BAA8B,kCAE1C;AAEM,MAAM,8BAA8B,GAAG,CAAC,KAAiB,EAAuB,EAAE;IACrF,OAAO,uDAA0B,CAAC,gBAAgB,CAAC,6BAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AAC1F,CAAC,CAAA;AAFY,QAAA,8BAA8B,kCAE1C"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { GroupKeyRequest as OldGroupKeyRequest } from '@streamr/protocol'
|
|
2
|
-
import { GroupKeyRequest } from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
|
-
import { toEthereumAddress, binaryToHex, binaryToUtf8, hexToBinary, utf8ToBinary } from '@streamr/utils'
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
6
|
-
export class GroupKeyRequestTranslator {
|
|
7
|
-
|
|
8
|
-
static toProtobuf(msg: OldGroupKeyRequest): GroupKeyRequest {
|
|
9
|
-
const translated: GroupKeyRequest = {
|
|
10
|
-
recipientId: hexToBinary(msg.recipient),
|
|
11
|
-
requestId: msg.requestId,
|
|
12
|
-
rsaPublicKey: utf8ToBinary(msg.rsaPublicKey),
|
|
13
|
-
groupKeyIds: [...msg.groupKeyIds]
|
|
14
|
-
}
|
|
15
|
-
return translated
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
static toClientProtocol(msg: GroupKeyRequest): OldGroupKeyRequest {
|
|
19
|
-
const translated = new OldGroupKeyRequest({
|
|
20
|
-
recipient: toEthereumAddress(binaryToHex(msg.recipientId, true)),
|
|
21
|
-
requestId: msg.requestId,
|
|
22
|
-
rsaPublicKey: binaryToUtf8(msg.rsaPublicKey),
|
|
23
|
-
groupKeyIds: msg.groupKeyIds
|
|
24
|
-
})
|
|
25
|
-
return translated
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { GroupKeyResponse as OldGroupKeyResponse, EncryptedGroupKey as OldEncryptedGroupKey } from '@streamr/protocol'
|
|
2
|
-
import { GroupKey, GroupKeyResponse } from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
|
-
import { toEthereumAddress, binaryToHex, hexToBinary } from '@streamr/utils'
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
6
|
-
export class GroupKeyResponseTranslator {
|
|
7
|
-
|
|
8
|
-
static toProtobuf(msg: OldGroupKeyResponse): GroupKeyResponse {
|
|
9
|
-
const groupKeys = msg.encryptedGroupKeys.map((groupKey) => {
|
|
10
|
-
return {
|
|
11
|
-
data: groupKey.data,
|
|
12
|
-
id: groupKey.id
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
const translated: GroupKeyResponse = {
|
|
16
|
-
recipientId: hexToBinary(msg.recipient),
|
|
17
|
-
requestId: msg.requestId,
|
|
18
|
-
groupKeys
|
|
19
|
-
}
|
|
20
|
-
return translated
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static toClientProtocol(msg: GroupKeyResponse): OldGroupKeyResponse {
|
|
24
|
-
const encryptedGroupKeys = msg.groupKeys.map((groupKey: GroupKey) => new OldEncryptedGroupKey(
|
|
25
|
-
groupKey.id,
|
|
26
|
-
groupKey.data,
|
|
27
|
-
))
|
|
28
|
-
return new OldGroupKeyResponse({
|
|
29
|
-
requestId: msg.requestId,
|
|
30
|
-
recipient: toEthereumAddress(binaryToHex(msg.recipientId, true)),
|
|
31
|
-
encryptedGroupKeys
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ContentType as OldContentType,
|
|
3
|
-
EncryptedGroupKey as OldEncryptedGroupKey,
|
|
4
|
-
EncryptionType as OldEncryptionType,
|
|
5
|
-
MessageID as OldMessageID,
|
|
6
|
-
MessageRef as OldMessageRef,
|
|
7
|
-
SignatureType as OldSignatureType,
|
|
8
|
-
StreamID,
|
|
9
|
-
StreamMessage as OldStreamMessage,
|
|
10
|
-
StreamMessageType as OldStreamMessageType
|
|
11
|
-
} from '@streamr/protocol'
|
|
12
|
-
import {
|
|
13
|
-
ContentType,
|
|
14
|
-
EncryptionType,
|
|
15
|
-
GroupKey,
|
|
16
|
-
GroupKeyRequest,
|
|
17
|
-
GroupKeyResponse,
|
|
18
|
-
MessageID,
|
|
19
|
-
MessageRef,
|
|
20
|
-
SignatureType,
|
|
21
|
-
StreamMessage
|
|
22
|
-
} from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
23
|
-
import { binaryToHex, hexToBinary, toEthereumAddress } from '@streamr/utils'
|
|
24
|
-
|
|
25
|
-
const oldToNewEncryptionType = (type: OldEncryptionType): EncryptionType => {
|
|
26
|
-
if (type === OldEncryptionType.AES) {
|
|
27
|
-
return EncryptionType.AES
|
|
28
|
-
}
|
|
29
|
-
return EncryptionType.NONE
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const newToOldEncryptionType = (type: EncryptionType): OldEncryptionType => {
|
|
33
|
-
if (type === EncryptionType.AES) {
|
|
34
|
-
return OldEncryptionType.AES
|
|
35
|
-
}
|
|
36
|
-
return OldEncryptionType.NONE
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const oldToNewContentType = (type: OldContentType): ContentType => {
|
|
40
|
-
if (type === OldContentType.JSON) {
|
|
41
|
-
return ContentType.JSON
|
|
42
|
-
}
|
|
43
|
-
return ContentType.BINARY
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const newToOldContentType = (type: ContentType): OldContentType => {
|
|
47
|
-
if (type === ContentType.JSON) {
|
|
48
|
-
return OldContentType.JSON
|
|
49
|
-
}
|
|
50
|
-
return OldContentType.BINARY
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const oldToNewSignatureType = (type: OldSignatureType): SignatureType => {
|
|
54
|
-
if (type === OldSignatureType.LEGACY_SECP256K1) {
|
|
55
|
-
return SignatureType.LEGACY_SECP256K1
|
|
56
|
-
}
|
|
57
|
-
if (type === OldSignatureType.ERC_1271) {
|
|
58
|
-
return SignatureType.ERC_1271
|
|
59
|
-
}
|
|
60
|
-
return SignatureType.SECP256K1
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const newToOldSignatureType = (type: SignatureType): OldSignatureType => {
|
|
64
|
-
if (type === SignatureType.LEGACY_SECP256K1) {
|
|
65
|
-
return OldSignatureType.LEGACY_SECP256K1
|
|
66
|
-
}
|
|
67
|
-
if (type === SignatureType.ERC_1271) {
|
|
68
|
-
return OldSignatureType.ERC_1271
|
|
69
|
-
}
|
|
70
|
-
return OldSignatureType.SECP256K1
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
75
|
-
export class StreamMessageTranslator {
|
|
76
|
-
|
|
77
|
-
static toProtobuf(msg: OldStreamMessage): StreamMessage {
|
|
78
|
-
const messageId: MessageID = {
|
|
79
|
-
timestamp: msg.getTimestamp(),
|
|
80
|
-
sequenceNumber: msg.getSequenceNumber(),
|
|
81
|
-
streamId: msg.getStreamId() as string,
|
|
82
|
-
streamPartition: msg.getStreamPartition(),
|
|
83
|
-
publisherId: hexToBinary(msg.getPublisherId()),
|
|
84
|
-
messageChainId: msg.getMsgChainId()
|
|
85
|
-
}
|
|
86
|
-
let previousMessageRef: MessageRef | undefined = undefined
|
|
87
|
-
if (msg.prevMsgRef) {
|
|
88
|
-
previousMessageRef = {
|
|
89
|
-
timestamp: msg.prevMsgRef.timestamp,
|
|
90
|
-
sequenceNumber: msg.prevMsgRef.sequenceNumber
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
let body: StreamMessage['body']
|
|
94
|
-
if (msg.messageType === OldStreamMessageType.MESSAGE) {
|
|
95
|
-
let newGroupKey: GroupKey | undefined = undefined
|
|
96
|
-
if (msg.newGroupKey) {
|
|
97
|
-
newGroupKey = {
|
|
98
|
-
id: msg.newGroupKey.id,
|
|
99
|
-
data: msg.newGroupKey.data
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
body = {
|
|
103
|
-
oneofKind: 'contentMessage',
|
|
104
|
-
contentMessage: {
|
|
105
|
-
content: msg.content,
|
|
106
|
-
contentType: oldToNewContentType(msg.contentType),
|
|
107
|
-
encryptionType: oldToNewEncryptionType(msg.encryptionType),
|
|
108
|
-
groupKeyId: msg.groupKeyId ?? undefined,
|
|
109
|
-
newGroupKey
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_REQUEST) {
|
|
113
|
-
body = {
|
|
114
|
-
oneofKind: 'groupKeyRequest',
|
|
115
|
-
groupKeyRequest: GroupKeyRequest.fromBinary(msg.content)
|
|
116
|
-
}
|
|
117
|
-
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_RESPONSE) {
|
|
118
|
-
body = {
|
|
119
|
-
oneofKind: 'groupKeyResponse',
|
|
120
|
-
groupKeyResponse: GroupKeyResponse.fromBinary(msg.content)
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
throw new Error('invalid message type')
|
|
124
|
-
}
|
|
125
|
-
const translated: StreamMessage = {
|
|
126
|
-
messageId,
|
|
127
|
-
previousMessageRef,
|
|
128
|
-
signature: msg.signature,
|
|
129
|
-
signatureType: oldToNewSignatureType(msg.signatureType),
|
|
130
|
-
body
|
|
131
|
-
}
|
|
132
|
-
return translated
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
static toClientProtocol(msg: StreamMessage): OldStreamMessage {
|
|
136
|
-
let messageType: OldStreamMessageType
|
|
137
|
-
let content: Uint8Array
|
|
138
|
-
let contentType: OldContentType = OldContentType.BINARY
|
|
139
|
-
let encryptionType: OldEncryptionType = OldEncryptionType.NONE
|
|
140
|
-
let newGroupKey: OldEncryptedGroupKey | undefined = undefined
|
|
141
|
-
let groupKeyId: string | undefined = undefined
|
|
142
|
-
if (msg.body.oneofKind === 'contentMessage') {
|
|
143
|
-
messageType = OldStreamMessageType.MESSAGE
|
|
144
|
-
content = msg.body.contentMessage.content
|
|
145
|
-
contentType = newToOldContentType(msg.body.contentMessage.contentType)
|
|
146
|
-
encryptionType = newToOldEncryptionType(msg.body.contentMessage.encryptionType)
|
|
147
|
-
if (msg.body.contentMessage.newGroupKey) {
|
|
148
|
-
newGroupKey = new OldEncryptedGroupKey(
|
|
149
|
-
msg.body.contentMessage.newGroupKey.id,
|
|
150
|
-
msg.body.contentMessage.newGroupKey.data
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
groupKeyId = msg.body.contentMessage.groupKeyId
|
|
154
|
-
} else if (msg.body.oneofKind === 'groupKeyRequest') {
|
|
155
|
-
messageType = OldStreamMessageType.GROUP_KEY_REQUEST
|
|
156
|
-
try {
|
|
157
|
-
content = GroupKeyRequest.toBinary(msg.body.groupKeyRequest)
|
|
158
|
-
} catch (err) {
|
|
159
|
-
throw new Error(`invalid group key request: ${err}`)
|
|
160
|
-
}
|
|
161
|
-
} else if (msg.body.oneofKind === 'groupKeyResponse') {
|
|
162
|
-
messageType = OldStreamMessageType.GROUP_KEY_RESPONSE
|
|
163
|
-
try {
|
|
164
|
-
content = GroupKeyResponse.toBinary(msg.body.groupKeyResponse)
|
|
165
|
-
} catch (err) {
|
|
166
|
-
throw new Error(`invalid group key response: ${err}`)
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
throw new Error('invalid message type')
|
|
170
|
-
}
|
|
171
|
-
const messageId = new OldMessageID(
|
|
172
|
-
msg.messageId!.streamId as StreamID,
|
|
173
|
-
msg.messageId!.streamPartition,
|
|
174
|
-
Number(msg.messageId!.timestamp),
|
|
175
|
-
msg.messageId!.sequenceNumber,
|
|
176
|
-
toEthereumAddress(binaryToHex(msg.messageId!.publisherId, true)),
|
|
177
|
-
msg.messageId!.messageChainId
|
|
178
|
-
)
|
|
179
|
-
let prevMsgRef: OldMessageRef | undefined = undefined
|
|
180
|
-
if (msg.previousMessageRef) {
|
|
181
|
-
prevMsgRef = new OldMessageRef(Number(msg.previousMessageRef.timestamp), msg.previousMessageRef.sequenceNumber)
|
|
182
|
-
}
|
|
183
|
-
const translated = new OldStreamMessage({
|
|
184
|
-
messageId,
|
|
185
|
-
prevMsgRef,
|
|
186
|
-
messageType,
|
|
187
|
-
content,
|
|
188
|
-
contentType,
|
|
189
|
-
signature: msg.signature,
|
|
190
|
-
signatureType: newToOldSignatureType(msg.signatureType),
|
|
191
|
-
encryptionType,
|
|
192
|
-
groupKeyId,
|
|
193
|
-
newGroupKey
|
|
194
|
-
})
|
|
195
|
-
return translated
|
|
196
|
-
}
|
|
197
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
StreamMessage as OldStreamMessage,
|
|
3
|
-
GroupKeyRequest as OldGroupKeyRequest,
|
|
4
|
-
GroupKeyResponse as OldGroupKeyResponse
|
|
5
|
-
} from '@streamr/protocol'
|
|
6
|
-
import { StreamMessageTranslator } from './StreamMessageTranslator'
|
|
7
|
-
import {
|
|
8
|
-
StreamMessage,
|
|
9
|
-
GroupKeyRequest,
|
|
10
|
-
GroupKeyResponse
|
|
11
|
-
} from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
12
|
-
import { GroupKeyResponseTranslator } from './GroupKeyResponseTranslator'
|
|
13
|
-
import { GroupKeyRequestTranslator } from './GroupKeyRequestTranslator'
|
|
14
|
-
|
|
15
|
-
export function convertStreamMessageToBytes(oldStreamMessage: OldStreamMessage): Uint8Array {
|
|
16
|
-
return StreamMessage.toBinary(StreamMessageTranslator.toProtobuf(oldStreamMessage))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function convertBytesToStreamMessage(bytes: Uint8Array): OldStreamMessage {
|
|
20
|
-
return StreamMessageTranslator.toClientProtocol(StreamMessage.fromBinary(bytes))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const convertGroupKeyRequestToBytes = (oldGroupKeyRequest: OldGroupKeyRequest): Uint8Array => {
|
|
24
|
-
return GroupKeyRequest.toBinary(GroupKeyRequestTranslator.toProtobuf(oldGroupKeyRequest))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const convertBytesToGroupKeyRequest = (bytes: Uint8Array): OldGroupKeyRequest => {
|
|
28
|
-
return GroupKeyRequestTranslator.toClientProtocol(GroupKeyRequest.fromBinary(bytes))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const convertGroupKeyResponseToBytes = (oldGroupKeyResponse: OldGroupKeyResponse): Uint8Array => {
|
|
32
|
-
return GroupKeyResponse.toBinary(GroupKeyResponseTranslator.toProtobuf(oldGroupKeyResponse))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export const convertBytesToGroupKeyResponse = (bytes: Uint8Array): OldGroupKeyResponse => {
|
|
36
|
-
return GroupKeyResponseTranslator.toClientProtocol(GroupKeyResponse.fromBinary(bytes))
|
|
37
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { GroupKeyResponseTranslator } from '../../src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator'
|
|
2
|
-
import {
|
|
3
|
-
GroupKeyResponse as OldGroupKeyResponse,
|
|
4
|
-
EncryptedGroupKey as OldEncryptedGroupKey
|
|
5
|
-
} from '@streamr/protocol'
|
|
6
|
-
import { EthereumAddress, hexToBinary } from '@streamr/utils'
|
|
7
|
-
import { GroupKey, GroupKeyResponse } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
8
|
-
|
|
9
|
-
describe('GroupKeyResponseTranslator', () => {
|
|
10
|
-
|
|
11
|
-
const oldGroupKeyResponse = new OldGroupKeyResponse({
|
|
12
|
-
requestId: 'request',
|
|
13
|
-
recipient: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as EthereumAddress,
|
|
14
|
-
encryptedGroupKeys: [ new OldEncryptedGroupKey('id', hexToBinary('0000')) ]
|
|
15
|
-
})
|
|
16
|
-
const newGroupKey: GroupKey = {
|
|
17
|
-
id: 'id',
|
|
18
|
-
data: hexToBinary('0000')
|
|
19
|
-
}
|
|
20
|
-
const newGroupKeyResponse: GroupKeyResponse = {
|
|
21
|
-
requestId: 'request',
|
|
22
|
-
recipientId: hexToBinary('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
23
|
-
groupKeys: [ newGroupKey ]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
it('translates old protocol to protobuf', () => {
|
|
27
|
-
const translated = GroupKeyResponseTranslator.toProtobuf(oldGroupKeyResponse)
|
|
28
|
-
expect(translated.groupKeys).toEqual(newGroupKeyResponse.groupKeys)
|
|
29
|
-
expect(translated.recipientId).toEqual(newGroupKeyResponse.recipientId)
|
|
30
|
-
expect(translated.requestId).toEqual(newGroupKeyResponse.requestId)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('translates protobuf to old protocol', () => {
|
|
34
|
-
const translated = GroupKeyResponseTranslator.toClientProtocol(newGroupKeyResponse)
|
|
35
|
-
expect(translated.encryptedGroupKeys).toEqual(oldGroupKeyResponse.encryptedGroupKeys)
|
|
36
|
-
expect(translated.recipient).toEqual(oldGroupKeyResponse.recipient)
|
|
37
|
-
expect(translated.requestId).toEqual(oldGroupKeyResponse.requestId)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EncryptionType,
|
|
3
|
-
MessageID,
|
|
4
|
-
StreamMessage as OldStreamMessage,
|
|
5
|
-
StreamMessageType as OldStreamMessageType,
|
|
6
|
-
StreamPartIDUtils,
|
|
7
|
-
ContentType,
|
|
8
|
-
SignatureType
|
|
9
|
-
} from '@streamr/protocol'
|
|
10
|
-
import { binaryToHex, binaryToUtf8, hexToBinary, toEthereumAddress, utf8ToBinary } from '@streamr/utils'
|
|
11
|
-
import { StreamMessageTranslator } from '../../src/logic/protocol-integration/stream-message/StreamMessageTranslator'
|
|
12
|
-
import { createStreamMessage } from '../utils/utils'
|
|
13
|
-
|
|
14
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('TEST#0')
|
|
15
|
-
|
|
16
|
-
describe('StreamMessageTranslator', () => {
|
|
17
|
-
|
|
18
|
-
const publisherId = toEthereumAddress('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
19
|
-
const signature = hexToBinary('0x1234')
|
|
20
|
-
const protobufMsg = createStreamMessage(
|
|
21
|
-
JSON.stringify({ hello: 'WORLD' }),
|
|
22
|
-
STREAM_PART_ID,
|
|
23
|
-
publisherId
|
|
24
|
-
)
|
|
25
|
-
const messageId = new MessageID(
|
|
26
|
-
StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
27
|
-
StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
28
|
-
Date.now(),
|
|
29
|
-
0,
|
|
30
|
-
publisherId,
|
|
31
|
-
'test',
|
|
32
|
-
)
|
|
33
|
-
const oldProtocolMsg = new OldStreamMessage({
|
|
34
|
-
messageId,
|
|
35
|
-
content: utf8ToBinary(JSON.stringify({ hello: 'WORLD' })),
|
|
36
|
-
contentType: ContentType.JSON,
|
|
37
|
-
messageType: OldStreamMessageType.MESSAGE,
|
|
38
|
-
encryptionType: EncryptionType.NONE,
|
|
39
|
-
signatureType: SignatureType.SECP256K1,
|
|
40
|
-
signature,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('translates old protocol to protobuf', () => {
|
|
44
|
-
const translated = StreamMessageTranslator.toProtobuf(oldProtocolMsg)
|
|
45
|
-
expect(translated.messageId!.streamId).toEqual(StreamPartIDUtils.getStreamID(STREAM_PART_ID))
|
|
46
|
-
expect(translated.messageId!.streamPartition).toEqual(StreamPartIDUtils.getStreamPartition(STREAM_PART_ID))
|
|
47
|
-
expect(translated.messageId!.timestamp).toBeGreaterThanOrEqual(0)
|
|
48
|
-
expect(translated.messageId!.sequenceNumber).toEqual(0)
|
|
49
|
-
expect(binaryToHex(translated.messageId!.publisherId, true)).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
50
|
-
expect(translated.previousMessageRef).toEqual(undefined)
|
|
51
|
-
expect(translated.body.oneofKind).toEqual('contentMessage')
|
|
52
|
-
expect((translated.body as any).contentMessage.groupKeyId).toEqual(undefined)
|
|
53
|
-
expect(translated.signature).toStrictEqual(signature)
|
|
54
|
-
expect(JSON.parse(binaryToUtf8((translated.body as any).contentMessage.content))).toEqual({ hello: 'WORLD' })
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('translates protobuf to old protocol', () => {
|
|
58
|
-
const translated = StreamMessageTranslator.toClientProtocol(protobufMsg)
|
|
59
|
-
expect(translated.messageId.streamId).toEqual(StreamPartIDUtils.getStreamID(STREAM_PART_ID))
|
|
60
|
-
expect(translated.messageId.streamPartition).toEqual(StreamPartIDUtils.getStreamPartition(STREAM_PART_ID))
|
|
61
|
-
expect(translated.messageId.timestamp).toBeGreaterThanOrEqual(0)
|
|
62
|
-
expect(translated.messageId.sequenceNumber).toEqual(0)
|
|
63
|
-
expect(translated.getPublisherId()).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
64
|
-
expect(translated.prevMsgRef).toEqual(undefined)
|
|
65
|
-
expect(translated.messageType).toEqual(OldStreamMessageType.MESSAGE)
|
|
66
|
-
expect(translated.contentType).toEqual(0)
|
|
67
|
-
expect(translated.groupKeyId).toEqual(undefined)
|
|
68
|
-
expect(translated.signature).toStrictEqual(signature)
|
|
69
|
-
expect(translated.getParsedContent()).toEqual({ hello: 'WORLD' })
|
|
70
|
-
})
|
|
71
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ContentType,
|
|
3
|
-
EncryptionType,
|
|
4
|
-
MessageID,
|
|
5
|
-
MessageRef,
|
|
6
|
-
SignatureType,
|
|
7
|
-
StreamMessage,
|
|
8
|
-
toStreamID
|
|
9
|
-
} from '@streamr/protocol'
|
|
10
|
-
import { toEthereumAddress } from '@streamr/utils'
|
|
11
|
-
import { convertBytesToStreamMessage, convertStreamMessageToBytes } from '../../src/exports'
|
|
12
|
-
|
|
13
|
-
describe('oldStreamMessageBinaryUtils', () => {
|
|
14
|
-
it('convertStreamMessageToBytes and convertBytesToStreamMessage', () => {
|
|
15
|
-
const streamMessage = new StreamMessage({
|
|
16
|
-
messageId: new MessageID(
|
|
17
|
-
toStreamID('test.ens/foobar'),
|
|
18
|
-
0,
|
|
19
|
-
10001,
|
|
20
|
-
0,
|
|
21
|
-
toEthereumAddress('0x1234567890123456789012345678901234567890'),
|
|
22
|
-
'msgChainId'
|
|
23
|
-
),
|
|
24
|
-
prevMsgRef: new MessageRef(10000, 1),
|
|
25
|
-
content: new Uint8Array([1, 2, 3]),
|
|
26
|
-
contentType: ContentType.BINARY,
|
|
27
|
-
encryptionType: EncryptionType.NONE,
|
|
28
|
-
groupKeyId: '0x1234567890123456789012345678901234567890',
|
|
29
|
-
signatureType: SignatureType.SECP256K1,
|
|
30
|
-
signature: new Uint8Array([7, 8, 9])
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const bytes = convertStreamMessageToBytes(streamMessage)
|
|
34
|
-
expect(bytes).toBeInstanceOf(Uint8Array)
|
|
35
|
-
expect(bytes.length).toBeGreaterThan(100)
|
|
36
|
-
const convertedStreamMessage = convertBytesToStreamMessage(bytes)
|
|
37
|
-
expect(convertedStreamMessage).toEqual(streamMessage)
|
|
38
|
-
})
|
|
39
|
-
})
|