@streamr/dht 100.0.0-testnet-two.4 → 100.0.0-testnet-three.0
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 +8 -8
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +3 -3
- package/dist/src/connection/ConnectionLockHandler.js +8 -10
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.js +5 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -4
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +8 -8
- package/dist/src/connection/ConnectionManager.js +54 -55
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +7 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.js +3 -1
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +23 -15
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +5 -2
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js +32 -20
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +24 -15
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +6 -3
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -19
- package/dist/src/dht/DhtNode.js +56 -65
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +5 -5
- package/dist/src/dht/PeerManager.js +31 -24
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.js +3 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.js +9 -5
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.js +1 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
- package/dist/src/dht/contact/RpcRemote.js +4 -0
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +3 -2
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.js +8 -8
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +26 -20
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +1 -1
- package/dist/src/dht/routing/Router.js +20 -15
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
- package/dist/src/dht/routing/RoutingSession.js +27 -9
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.js +5 -4
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +8 -8
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.js +1 -0
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +3 -3
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -4
- package/dist/src/exports.js +4 -7
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.js +2 -1
- package/dist/src/helpers/MapWithTtl.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +56 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/identifiers.d.ts +3 -0
- package/dist/src/identifiers.js +9 -1
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +8 -5
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +10 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/transport/ITransport.d.ts +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +8 -8
- package/protos/DhtRpc.proto +7 -4
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +3 -3
- package/src/connection/ConnectionLockRpcLocal.ts +1 -5
- package/src/connection/ConnectionLockRpcRemote.ts +1 -1
- package/src/connection/ConnectionManager.ts +24 -38
- package/src/connection/ConnectorFacade.ts +3 -2
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +3 -3
- package/src/connection/connectivityRequestHandler.ts +7 -3
- package/src/connection/simulator/Simulator.ts +1 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/simulator/SimulatorConnector.ts +1 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
- package/src/connection/webrtc/WebrtcConnector.ts +9 -17
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +7 -7
- package/src/connection/websocket/ClientWebsocket.ts +3 -2
- package/src/connection/websocket/ServerWebsocket.ts +17 -1
- package/src/connection/websocket/WebsocketConnector.ts +10 -9
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
- package/src/connection/websocket/WebsocketServer.ts +2 -2
- package/src/dht/DhtNode.ts +63 -86
- package/src/dht/DhtNodeRpcLocal.ts +5 -5
- package/src/dht/DhtNodeRpcRemote.ts +3 -3
- package/src/dht/ExternalApiRpcLocal.ts +3 -4
- package/src/dht/PeerManager.ts +14 -20
- package/src/dht/contact/Contact.ts +1 -2
- package/src/dht/contact/RpcRemote.ts +2 -1
- package/src/dht/discovery/DiscoverySession.ts +2 -3
- package/src/dht/discovery/PeerDiscovery.ts +16 -9
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +12 -11
- package/src/dht/routing/RouterRpcLocal.ts +1 -2
- package/src/dht/routing/RouterRpcRemote.ts +5 -5
- package/src/dht/routing/RoutingSession.ts +22 -2
- package/src/dht/store/StoreManager.ts +1 -2
- package/src/dht/store/StoreRpcRemote.ts +1 -1
- package/src/exports.ts +9 -4
- package/src/helpers/createPeerDescriptor.ts +56 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/identifiers.ts +10 -1
- package/src/proto/google/protobuf/any.ts +12 -9
- package/src/proto/google/protobuf/empty.ts +2 -5
- package/src/proto/google/protobuf/timestamp.ts +14 -5
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +0 -1
- package/src/transport/ITransport.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +1 -1
- package/test/benchmark/Find.test.ts +6 -8
- package/test/benchmark/KademliaCorrectness.test.ts +2 -3
- package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
- package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
- package/test/end-to-end/Layer0.test.ts +4 -4
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +12 -12
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
- package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
- package/test/end-to-end/memory-leak.test.ts +2 -2
- package/test/integration/ConnectionLocking.test.ts +60 -47
- package/test/integration/ConnectionManager.test.ts +8 -7
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
- package/test/integration/DhtRpc.test.ts +4 -3
- package/test/integration/Find.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +7 -7
- package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +52 -161
- package/test/integration/RouteMessage.test.ts +24 -47
- package/test/integration/RouterRpcRemote.test.ts +7 -4
- package/test/integration/ScaleDownDht.test.ts +2 -3
- package/test/integration/SimultaneousConnections.test.ts +9 -8
- package/test/integration/Store.test.ts +1 -2
- package/test/integration/StoreAndDelete.test.ts +5 -0
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
- package/test/integration/StoreRpcRemote.test.ts +4 -4
- package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
- package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
- package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
- package/test/unit/DuplicateDetector.test.ts +2 -2
- package/test/unit/LocalDataStore.test.ts +1 -4
- package/test/unit/RandomContactList.test.ts +2 -4
- package/test/unit/RecursiveOperationManager.test.ts +5 -6
- package/test/unit/RecursiveOperationSession.test.ts +5 -4
- package/test/unit/Router.test.ts +25 -8
- package/test/unit/RoutingSession.test.ts +3 -3
- package/test/unit/SortedContactList.test.ts +2 -4
- package/test/unit/connectivityRequestHandler.test.ts +5 -3
- package/test/unit/createPeerDescriptor.test.ts +63 -0
- package/test/utils/FakeTransport.ts +7 -4
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +6 -6
- package/dist/src/helpers/PeerID.d.ts +0 -27
- package/dist/src/helpers/PeerID.js +0 -87
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/helpers/PeerID.ts +0 -97
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BrandedString } from '@streamr/utils';
|
|
2
|
-
import { DhtAddress } from '../identifiers';
|
|
3
|
-
export type PeerIDKey = BrandedString<'PeerIDKey'>;
|
|
4
|
-
export declare const createPeerIDKey: (nodeId: Uint8Array) => PeerIDKey;
|
|
5
|
-
export declare class PeerID {
|
|
6
|
-
private static readonly textEncoder;
|
|
7
|
-
private static readonly textDecoder;
|
|
8
|
-
private readonly data;
|
|
9
|
-
private readonly key;
|
|
10
|
-
protected constructor({ ip, value, stringValue }?: {
|
|
11
|
-
ip?: string;
|
|
12
|
-
value?: Uint8Array;
|
|
13
|
-
stringValue?: string;
|
|
14
|
-
});
|
|
15
|
-
static fromIp(ip: string): PeerID;
|
|
16
|
-
static fromValue(value: Uint8Array): PeerID;
|
|
17
|
-
static fromKey(value: PeerIDKey): PeerID;
|
|
18
|
-
static fromString(stringValue: string): PeerID;
|
|
19
|
-
private ip2Int;
|
|
20
|
-
equals(other: PeerID): boolean;
|
|
21
|
-
toString(): string;
|
|
22
|
-
toKey(): PeerIDKey;
|
|
23
|
-
toNodeId(): DhtAddress;
|
|
24
|
-
get value(): Uint8Array;
|
|
25
|
-
hasSmallerHashThan(other: PeerID): boolean;
|
|
26
|
-
private static offeringHash;
|
|
27
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PeerID = exports.createPeerIDKey = void 0;
|
|
7
|
-
const utils_1 = require("@streamr/utils");
|
|
8
|
-
const UUID_1 = require("./UUID");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
-
const identifiers_1 = require("../identifiers");
|
|
12
|
-
const createPeerIDKey = (nodeId) => {
|
|
13
|
-
return (0, utils_1.binaryToHex)(nodeId);
|
|
14
|
-
};
|
|
15
|
-
exports.createPeerIDKey = createPeerIDKey;
|
|
16
|
-
class PeerID {
|
|
17
|
-
constructor({ ip, value, stringValue } = {}) {
|
|
18
|
-
if (ip !== undefined) {
|
|
19
|
-
this.data = new Uint8Array(20);
|
|
20
|
-
const ipNum = this.ip2Int(ip);
|
|
21
|
-
const view = new DataView(this.data.buffer);
|
|
22
|
-
view.setInt32(0, ipNum);
|
|
23
|
-
this.data.set((new UUID_1.UUID()).value, 4);
|
|
24
|
-
}
|
|
25
|
-
else if (value) {
|
|
26
|
-
this.data = new Uint8Array(value.slice(0));
|
|
27
|
-
}
|
|
28
|
-
else if (stringValue !== undefined) {
|
|
29
|
-
const ab = PeerID.textEncoder.encode(stringValue); //toUTF8Array(stringValue)
|
|
30
|
-
this.data = ab;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new errors_1.IllegalArguments('Constructor of PeerID must be given either ip, value or stringValue');
|
|
34
|
-
}
|
|
35
|
-
this.key = (0, exports.createPeerIDKey)(this.data);
|
|
36
|
-
}
|
|
37
|
-
static fromIp(ip) {
|
|
38
|
-
return new PeerID({ ip });
|
|
39
|
-
}
|
|
40
|
-
static fromValue(value) {
|
|
41
|
-
return new PeerID({ value });
|
|
42
|
-
}
|
|
43
|
-
static fromKey(value) {
|
|
44
|
-
return new PeerID({ value: Buffer.from(value, 'hex') });
|
|
45
|
-
}
|
|
46
|
-
static fromString(stringValue) {
|
|
47
|
-
return new PeerID({ stringValue });
|
|
48
|
-
}
|
|
49
|
-
// TODO convert to static method?
|
|
50
|
-
// eslint-disable-next-line class-methods-use-this
|
|
51
|
-
ip2Int(ip) {
|
|
52
|
-
return ip.split('.').map((octet, index, array) => {
|
|
53
|
-
return parseInt(octet) * Math.pow(256, (array.length - index - 1));
|
|
54
|
-
}).reduce((prev, curr) => {
|
|
55
|
-
return prev + curr;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
equals(other) {
|
|
59
|
-
return (Buffer.compare(this.data, other.value) === 0);
|
|
60
|
-
}
|
|
61
|
-
toString() {
|
|
62
|
-
return PeerID.textDecoder.decode(this.data);
|
|
63
|
-
}
|
|
64
|
-
toKey() {
|
|
65
|
-
return this.key;
|
|
66
|
-
}
|
|
67
|
-
toNodeId() {
|
|
68
|
-
return (0, identifiers_1.getDhtAddressFromRaw)(this.data);
|
|
69
|
-
}
|
|
70
|
-
get value() {
|
|
71
|
-
return this.data;
|
|
72
|
-
}
|
|
73
|
-
hasSmallerHashThan(other) {
|
|
74
|
-
const myId = this.toKey();
|
|
75
|
-
const theirId = other.toKey();
|
|
76
|
-
return PeerID.offeringHash(myId + ',' + theirId) < PeerID.offeringHash(theirId + ',' + myId);
|
|
77
|
-
}
|
|
78
|
-
static offeringHash(idPair) {
|
|
79
|
-
const buffer = crypto_1.default.createHash('md5').update(idPair).digest();
|
|
80
|
-
return buffer.readInt32LE(0);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.PeerID = PeerID;
|
|
84
|
-
// avoid creating a new instance for every operation
|
|
85
|
-
PeerID.textEncoder = new TextEncoder();
|
|
86
|
-
PeerID.textDecoder = new TextDecoder();
|
|
87
|
-
//# sourceMappingURL=PeerID.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PeerID.js","sourceRoot":"","sources":["../../../src/helpers/PeerID.ts"],"names":[],"mappings":"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"}
|
package/dist/src/helpers/UUID.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UUID = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const utils_1 = require("@streamr/utils");
|
|
6
|
-
class UUID {
|
|
7
|
-
constructor(other) {
|
|
8
|
-
if (other === undefined) {
|
|
9
|
-
this.buf = new Uint8Array(16);
|
|
10
|
-
(0, uuid_1.v4)(null, this.buf);
|
|
11
|
-
}
|
|
12
|
-
else if (other.constructor === UUID) {
|
|
13
|
-
this.buf = other.buf;
|
|
14
|
-
}
|
|
15
|
-
else if (typeof other === 'string') {
|
|
16
|
-
this.buf = new Uint8Array((0, uuid_1.parse)(other));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.buf = other;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
toString() {
|
|
23
|
-
return (0, uuid_1.stringify)(this.buf);
|
|
24
|
-
}
|
|
25
|
-
toHex() {
|
|
26
|
-
return (0, utils_1.binaryToHex)(this.buf);
|
|
27
|
-
}
|
|
28
|
-
equals(other) {
|
|
29
|
-
return (Buffer.compare(this.buf, other.value) === 0);
|
|
30
|
-
}
|
|
31
|
-
get value() {
|
|
32
|
-
return this.buf;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.UUID = UUID;
|
|
36
|
-
//# sourceMappingURL=UUID.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UUID.js","sourceRoot":"","sources":["../../../src/helpers/UUID.ts"],"names":[],"mappings":";;;AAAA,+BAA2C;AAC3C,0CAA4C;AAE5C,MAAa,IAAI;IAGb,YAAY,KAAoC;QAC5C,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,IAAI,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;YAC7B,IAAA,SAAE,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;SACrB;aAAM,IAAI,KAAK,CAAC,WAAW,KAAK,IAAI,EAAE;YACnC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;SACvB;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAClC,IAAI,CAAC,GAAG,GAAG,IAAI,UAAU,CAAC,IAAA,YAAK,EAAC,KAAK,CAAC,CAAC,CAAA;SAC1C;aAAM;YACH,IAAI,CAAC,GAAG,GAAG,KAAmB,CAAA;SACjC;IACL,CAAC;IAED,QAAQ;QACJ,OAAO,IAAA,gBAAS,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK;QACD,OAAO,IAAA,mBAAW,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,MAAM,CAAC,KAAW;QACd,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,GAAG,CAAA;IACnB,CAAC;CACJ;AA/BD,oBA+BC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { PeerID, PeerIDKey } from './PeerID';
|
|
3
|
-
import { DhtAddress } from '../identifiers';
|
|
4
|
-
export declare const peerIdFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => PeerID;
|
|
5
|
-
export declare const getNodeIdFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => DhtAddress;
|
|
6
|
-
export declare const keyFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => PeerIDKey;
|
|
7
|
-
export declare const areEqualPeerDescriptors: (peerDescriptor1: PeerDescriptor, peerDescriptor2: PeerDescriptor) => boolean;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.areEqualPeerDescriptors = exports.keyFromPeerDescriptor = exports.getNodeIdFromPeerDescriptor = exports.peerIdFromPeerDescriptor = void 0;
|
|
4
|
-
const utils_1 = require("@streamr/utils");
|
|
5
|
-
const PeerID_1 = require("./PeerID");
|
|
6
|
-
const identifiers_1 = require("../identifiers");
|
|
7
|
-
const peerIdFromPeerDescriptor = (peerDescriptor) => {
|
|
8
|
-
return PeerID_1.PeerID.fromValue(peerDescriptor.nodeId);
|
|
9
|
-
};
|
|
10
|
-
exports.peerIdFromPeerDescriptor = peerIdFromPeerDescriptor;
|
|
11
|
-
const getNodeIdFromPeerDescriptor = (peerDescriptor) => {
|
|
12
|
-
return (0, identifiers_1.getDhtAddressFromRaw)(peerDescriptor.nodeId);
|
|
13
|
-
};
|
|
14
|
-
exports.getNodeIdFromPeerDescriptor = getNodeIdFromPeerDescriptor;
|
|
15
|
-
const keyFromPeerDescriptor = (peerDescriptor) => {
|
|
16
|
-
return (0, PeerID_1.createPeerIDKey)(peerDescriptor.nodeId);
|
|
17
|
-
};
|
|
18
|
-
exports.keyFromPeerDescriptor = keyFromPeerDescriptor;
|
|
19
|
-
const areEqualPeerDescriptors = (peerDescriptor1, peerDescriptor2) => {
|
|
20
|
-
return (0, utils_1.areEqualBinaries)(peerDescriptor1.nodeId, peerDescriptor2.nodeId);
|
|
21
|
-
};
|
|
22
|
-
exports.areEqualPeerDescriptors = areEqualPeerDescriptors;
|
|
23
|
-
//# sourceMappingURL=peerIdFromPeerDescriptor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peerIdFromPeerDescriptor.js","sourceRoot":"","sources":["../../../src/helpers/peerIdFromPeerDescriptor.ts"],"names":[],"mappings":";;;AAAA,0CAAiD;AAEjD,qCAA6D;AAC7D,gDAAiE;AAE1D,MAAM,wBAAwB,GAAG,CAAC,cAA8B,EAAU,EAAE;IAC/E,OAAO,eAAM,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AAClD,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC;AAEM,MAAM,2BAA2B,GAAG,CAAC,cAA8B,EAAc,EAAE;IACtF,OAAO,IAAA,kCAAoB,EAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AACtD,CAAC,CAAA;AAFY,QAAA,2BAA2B,+BAEvC;AAEM,MAAM,qBAAqB,GAAG,CAAC,cAA8B,EAAa,EAAE;IAC/E,OAAO,IAAA,wBAAe,EAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AACjD,CAAC,CAAA;AAFY,QAAA,qBAAqB,yBAEjC;AAEM,MAAM,uBAAuB,GAAG,CAAC,eAA+B,EAAE,eAA+B,EAAW,EAAE;IACjH,OAAO,IAAA,wBAAgB,EAAC,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;AAC3E,CAAC,CAAA;AAFY,QAAA,uBAAuB,2BAEnC"}
|
package/src/helpers/PeerID.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { BrandedString, binaryToHex } from '@streamr/utils'
|
|
2
|
-
import { UUID } from './UUID'
|
|
3
|
-
import { IllegalArguments } from './errors'
|
|
4
|
-
import crypto from 'crypto'
|
|
5
|
-
import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
|
|
6
|
-
|
|
7
|
-
export type PeerIDKey = BrandedString<'PeerIDKey'>
|
|
8
|
-
|
|
9
|
-
export const createPeerIDKey = (nodeId: Uint8Array): PeerIDKey => {
|
|
10
|
-
return binaryToHex(nodeId) as PeerIDKey
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class PeerID {
|
|
14
|
-
// avoid creating a new instance for every operation
|
|
15
|
-
private static readonly textEncoder = new TextEncoder()
|
|
16
|
-
private static readonly textDecoder = new TextDecoder()
|
|
17
|
-
|
|
18
|
-
private readonly data!: Uint8Array
|
|
19
|
-
private readonly key: PeerIDKey // precompute often-used form of data
|
|
20
|
-
|
|
21
|
-
protected constructor({ ip, value, stringValue }: { ip?: string, value?: Uint8Array, stringValue?: string } = {}) {
|
|
22
|
-
if (ip !== undefined) {
|
|
23
|
-
this.data = new Uint8Array(20)
|
|
24
|
-
const ipNum = this.ip2Int(ip)
|
|
25
|
-
const view = new DataView(this.data.buffer)
|
|
26
|
-
view.setInt32(0, ipNum)
|
|
27
|
-
|
|
28
|
-
this.data.set((new UUID()).value, 4)
|
|
29
|
-
} else if (value) {
|
|
30
|
-
this.data = new Uint8Array(value.slice(0))
|
|
31
|
-
} else if (stringValue !== undefined) {
|
|
32
|
-
const ab = PeerID.textEncoder.encode(stringValue) //toUTF8Array(stringValue)
|
|
33
|
-
this.data = ab
|
|
34
|
-
} else {
|
|
35
|
-
throw new IllegalArguments('Constructor of PeerID must be given either ip, value or stringValue')
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.key = createPeerIDKey(this.data)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static fromIp(ip: string): PeerID {
|
|
42
|
-
return new PeerID({ ip })
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static fromValue(value: Uint8Array): PeerID {
|
|
46
|
-
return new PeerID({ value })
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static fromKey(value: PeerIDKey): PeerID {
|
|
50
|
-
return new PeerID({ value: Buffer.from(value, 'hex') })
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
static fromString(stringValue: string): PeerID {
|
|
54
|
-
return new PeerID({ stringValue })
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// TODO convert to static method?
|
|
58
|
-
// eslint-disable-next-line class-methods-use-this
|
|
59
|
-
private ip2Int(ip: string): number {
|
|
60
|
-
return ip.split('.').map((octet, index, array) => {
|
|
61
|
-
return parseInt(octet) * Math.pow(256, (array.length - index - 1))
|
|
62
|
-
}).reduce((prev, curr) => {
|
|
63
|
-
return prev + curr
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
equals(other: PeerID): boolean {
|
|
68
|
-
return (Buffer.compare(this.data, other.value) === 0)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
toString(): string {
|
|
72
|
-
return PeerID.textDecoder.decode(this.data)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
toKey(): PeerIDKey {
|
|
76
|
-
return this.key
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
toNodeId(): DhtAddress {
|
|
80
|
-
return getDhtAddressFromRaw(this.data)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get value(): Uint8Array {
|
|
84
|
-
return this.data
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
hasSmallerHashThan(other: PeerID): boolean {
|
|
88
|
-
const myId = this.toKey()
|
|
89
|
-
const theirId = other.toKey()
|
|
90
|
-
return PeerID.offeringHash(myId + ',' + theirId) < PeerID.offeringHash(theirId + ',' + myId)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private static offeringHash(idPair: string): number {
|
|
94
|
-
const buffer = crypto.createHash('md5').update(idPair).digest()
|
|
95
|
-
return buffer.readInt32LE(0)
|
|
96
|
-
}
|
|
97
|
-
}
|
package/src/helpers/UUID.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { v4, parse, stringify } from 'uuid'
|
|
2
|
-
import { binaryToHex } from '@streamr/utils'
|
|
3
|
-
|
|
4
|
-
export class UUID {
|
|
5
|
-
private buf: Uint8Array
|
|
6
|
-
|
|
7
|
-
constructor(other?: (UUID | Uint8Array | string)) {
|
|
8
|
-
if (other === undefined) {
|
|
9
|
-
this.buf = new Uint8Array(16)
|
|
10
|
-
v4(null, this.buf)
|
|
11
|
-
} else if (other.constructor === UUID) {
|
|
12
|
-
this.buf = other.buf
|
|
13
|
-
} else if (typeof other === 'string') {
|
|
14
|
-
this.buf = new Uint8Array(parse(other))
|
|
15
|
-
} else {
|
|
16
|
-
this.buf = other as Uint8Array
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
toString(): string {
|
|
21
|
-
return stringify(this.buf)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
toHex(): string {
|
|
25
|
-
return binaryToHex(this.buf)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
equals(other: UUID): boolean {
|
|
29
|
-
return (Buffer.compare(this.buf, other.value) === 0)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get value(): Uint8Array {
|
|
33
|
-
return this.buf
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { areEqualBinaries } from '@streamr/utils'
|
|
2
|
-
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { PeerID, PeerIDKey, createPeerIDKey } from './PeerID'
|
|
4
|
-
import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
|
|
5
|
-
|
|
6
|
-
export const peerIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerID => {
|
|
7
|
-
return PeerID.fromValue(peerDescriptor.nodeId)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): DhtAddress => {
|
|
11
|
-
return getDhtAddressFromRaw(peerDescriptor.nodeId)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const keyFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerIDKey => {
|
|
15
|
-
return createPeerIDKey(peerDescriptor.nodeId)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const areEqualPeerDescriptors = (peerDescriptor1: PeerDescriptor, peerDescriptor2: PeerDescriptor): boolean => {
|
|
19
|
-
return areEqualBinaries(peerDescriptor1.nodeId, peerDescriptor2.nodeId)
|
|
20
|
-
}
|
package/test/unit/PeerID.test.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
2
|
-
|
|
3
|
-
describe('PeerID', () => {
|
|
4
|
-
|
|
5
|
-
it('Conversions between input formats work', async () => {
|
|
6
|
-
const stringId = '123'
|
|
7
|
-
const id1 = PeerID.fromString(stringId)
|
|
8
|
-
const id2 = PeerID.fromValue(id1.value)
|
|
9
|
-
|
|
10
|
-
expect(id1.equals(id2)).toBeTruthy()
|
|
11
|
-
expect(id1.toString()).toEqual(id2.toString())
|
|
12
|
-
expect(stringId).toEqual(id2.toString())
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('peerKey', () => {
|
|
16
|
-
const peerIdFromString = PeerID.fromString('peerId')
|
|
17
|
-
const peerKey = peerIdFromString.toKey()
|
|
18
|
-
const peerIdFromKey = PeerID.fromKey(peerKey)
|
|
19
|
-
expect(peerIdFromString.equals(peerIdFromKey)).toEqual(true)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
})
|
package/test/unit/UUID.test.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { UUID } from '../../src/helpers/UUID'
|
|
2
|
-
import { v4 } from 'uuid'
|
|
3
|
-
|
|
4
|
-
describe('UUID', () => {
|
|
5
|
-
|
|
6
|
-
it('generates unique IDs without constructor parameters', () => {
|
|
7
|
-
const ids: UUID[] = []
|
|
8
|
-
for (let i = 0; i < 100; i++) {
|
|
9
|
-
ids.push(new UUID())
|
|
10
|
-
}
|
|
11
|
-
for (let x = 0; x < ids.length; x++) {
|
|
12
|
-
const compare1 = ids[x]
|
|
13
|
-
for (let y = 0; y < ids.length; y++) {
|
|
14
|
-
if (x !== y) {
|
|
15
|
-
const compare2 = ids[y]
|
|
16
|
-
expect(compare1.toString() === compare2.toString()).toEqual(false)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('Uses passed string uuid parameter as id', () => {
|
|
23
|
-
const stringId = v4()
|
|
24
|
-
const uuid = new UUID(stringId)
|
|
25
|
-
expect(uuid.toString() === stringId).toEqual(true)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('toHex', () => {
|
|
29
|
-
const stringId = v4()
|
|
30
|
-
const uuid = new UUID(stringId)
|
|
31
|
-
expect(uuid.toHex() === stringId.replaceAll('-', '')).toEqual(true)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('Throws if incorrect string is given as uuid string parameter', () => {
|
|
35
|
-
expect(() => {new UUID('äå%')}).toThrow(TypeError)
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('Uses passed UUID as id', () => {
|
|
39
|
-
const uuid1 = new UUID()
|
|
40
|
-
const uuid2 = new UUID(uuid1)
|
|
41
|
-
expect(uuid1.toString() === uuid2.toString()).toEqual(true)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('Uses passed UintArray uuid as id', () => {
|
|
45
|
-
const uuid1 = new UUID()
|
|
46
|
-
const uuid2 = new UUID(uuid1.value)
|
|
47
|
-
expect(uuid1.toString() === uuid2.toString()).toEqual(true)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('Get value returns correct value', () => {
|
|
51
|
-
const uuid1 = new UUID()
|
|
52
|
-
const uuid2 = new UUID(uuid1.value)
|
|
53
|
-
expect(Buffer.compare(uuid1.value, uuid2.value) === 0)
|
|
54
|
-
})
|
|
55
|
-
})
|