Skip to content

Commit 9317a91

Browse files
authored
Merge pull request #19 from omnia-network/fix/double-default-export
fix: change default export to named export
2 parents bd26362 + a0c9a49 commit 9317a91

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

src/ic-websocket.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CallRequest, Cbor } from "@dfinity/agent";
55
import { IDL } from "@dfinity/candid";
66
import { Principal } from "@dfinity/principal";
77

8-
import IcWebSocket, { COMMUNICATION_LATENCY_BOUND_MS, createWsConfig } from "./ic-websocket";
8+
import { IcWebSocket, COMMUNICATION_LATENCY_BOUND_MS, createWsConfig } from "./ic-websocket";
99
import { generateRandomIdentity } from "./identity";
1010
import {
1111
CanisterWsMessageArguments,
@@ -38,7 +38,7 @@ import {
3838
getTestCanisterActorWrongArgs,
3939
getTestCanisterActorWrongOpt,
4040
} from "./test/actor";
41-
import { GATEWAY_PRINCIPAL, LOCAL_REPLICA_ROOT_KEY } from "./test/constants";
41+
import { GATEWAY_PRINCIPAL, LOCAL_REPLICA_ROOT_KEY, MAX_CERTIFICATE_AGE_IN_MINUTES } from "./test/constants";
4242

4343
const wsGatewayAddress = "ws://127.0.0.1:8080";
4444
// the canister from which the application message was sent (needed to verify the message certificate)
@@ -51,7 +51,7 @@ const icWebsocketConfig = createWsConfig({
5151
canisterActor: testCanisterActor,
5252
networkUrl: icNetworkUrl,
5353
identity: generateRandomIdentity(),
54-
maxCertificateAgeInMinutes: 60 * 24 * 365, // 1 year. Since we're using pre-generated certificates, we need to set it really far in the future
54+
maxCertificateAgeInMinutes: MAX_CERTIFICATE_AGE_IN_MINUTES,
5555
});
5656

5757
//// Mock Servers

src/ic-websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
extractApplicationMessageIdlFromActor,
2121
isClientKeyEq,
2222
} from "./idl";
23-
import logger from "./logger";
23+
import { logger } from "./logger";
2424
import { isMessageBodyValid, randomBigInt, safeExecute } from "./utils";
2525
import {
2626
isClientIncomingMessage,
@@ -90,7 +90,7 @@ export const createWsConfig = <S extends _WS_CANISTER_SERVICE>(c: IcWebSocketCon
9090

9191
type WsParameters = ConstructorParameters<typeof WebSocket>;
9292

93-
export default class IcWebSocket<
93+
export class IcWebSocket<
9494
S extends _WS_CANISTER_SERVICE,
9595
ApplicationMessageType = GetApplicationMessageType<S>
9696
> {

src/index.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
// import default member
2-
import IcWebSocket from './ic-websocket';
3-
// re-export non-default members
4-
export * from './ic-websocket';
5-
export * from './identity';
6-
7-
// re-export default member
8-
export default IcWebSocket;
1+
export { IcWebSocket, type IcWebSocketConfig, createWsConfig } from './ic-websocket';
2+
export { generateRandomIdentity } from './identity';

src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ const logLevel = process.env.LOG_LEVEL || 'info';
55
const logger = log.getLogger('ic-websocket-js');
66
logger.setDefaultLevel(logLevel as LogLevelDesc);
77

8-
export default logger;
8+
export { logger };

src/test/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ import { Principal } from "@dfinity/principal";
44
export const GATEWAY_PRINCIPAL = Principal.fromText("sqdfl-mr4km-2hfjy-gajqo-xqvh7-hf4mf-nra4i-3it6l-neaw4-soolw-tae");
55

66
export const LOCAL_REPLICA_ROOT_KEY = fromHex("d9d9f7a66e69635f6170695f76657273696f6e66302e31382e3068726f6f745f6b65795885308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c050302010361008005229d89a17c6f9ec403a4b1a8aa103fc48055046c95f1e60ee2fbfb0bb23ab21617a93f48b99b1199ac89008cf3cf0a83e9da35f5cf27d0d51535ceff89c43ee236c31c3a7865cc6b333194ad3f7155b2931a7ffec2066777dffb20f277ca6c696d706c5f76657273696f6e65302e382e3069696d706c5f68617368784064613931633732316637386462393433346561336630303437383939383836346439313731346538626561363862333963633736326662306263383937313662757265706c6963615f6865616c74685f737461747573676865616c746879706365727469666965645f68656967687418d4");
7+
8+
const YEAR_IN_MINUTES = 365 * 24 * 60;
9+
/**
10+
* The max age of the certificate (5 years).
11+
* Since we're using pre-generated certificates, we need to set it really far in the future.
12+
*/
13+
export const MAX_CERTIFICATE_AGE_IN_MINUTES = 5 * YEAR_IN_MINUTES;

src/utils.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { HttpAgent, fromHex } from "@dfinity/agent";
22
import { Principal } from "@dfinity/principal";
33
import { isMessageBodyValid, randomBigInt, safeExecute } from "./utils";
44
import { ClientIncomingMessage } from "./types";
5-
import logger from "./logger";
5+
import { logger } from "./logger";
6+
import { MAX_CERTIFICATE_AGE_IN_MINUTES } from "./test/constants";
67

78
// the canister from which the correct data were generated
89
const canisterId = Principal.fromText("bnz7o-iuaaa-aaaaa-qaaaa-cai");
@@ -15,8 +16,6 @@ const messageToVerify: ClientIncomingMessage = {
1516
cert: new Uint8Array(fromHex("d9d9f7a2647472656583018301830183024863616e6973746572830183024a8000000000100000010183018301830183024e6365727469666965645f646174618203582087be17d7ba688bc4fb13d61f3d8d5642df92536e40da98facba7ba0450ea59e082045820f8d20e36feb79f8495eb4c632b7a04171599957c8c267f55b2156d89b5c1e424820458200d3dc76c69e69f12678a2e9a5a6859579ceb28350608e69f1902055650edaf7f820458209e5663705fa61a6ca53ee4a61daa4621e8ece0febd99b334d0ae625aad9f3f6e8204582077d28a3053cd3845a065a879ce36849add41cae9e6a56d452e328194b38e15ec82045820932e7cd3d24b95ff6c0fea6086fc624ee43b0875101777e089ba915ef7ded93d82045820fbb733f900879885afed4ace8eb90b19245f8386e7537769c072e9fded13c6ad830182045820ae29f371a7ae2a4af8bb125ef23486745500f8cb31a02c35cc7155053b67cce683024474696d6582034992da96e7ae90a2ba17697369676e61747572655830932828f169fdce98969c417666f38002e2826081deb756e94c73091a1b7c0455f6c2f3ccc509ab576c8e6f8753b7d85b")),
1617
tree: new Uint8Array(fromHex("d9d9f7830249776562736f636b657483025854737164666c2d6d72346b6d2d3268666a792d67616a716f2d78717668372d6866346d662d6e726134692d336974366c2d6e656177342d736f6f6c772d7461655f303030303030303030303030303030303030303082035820215b2aae42ccf90c6fd928fec029d0b9308e97d0c40f8772100a30097b004bb5")),
1718
};
18-
// the max age of the certificate. Since we're using pre-generated certificates, we need to set it really far in the future
19-
const maxCertificateAgeInMinutes = 5 * 60 * 24 * 365; // 5 years
2019

2120
const agent = HttpAgent.createSync();
2221
agent.rootKey = localReplicaRootKey;
@@ -30,7 +29,7 @@ describe("Utils of the IcWebSocket", () => {
3029
messageToVerify.cert,
3130
messageToVerify.tree,
3231
agent,
33-
maxCertificateAgeInMinutes,
32+
MAX_CERTIFICATE_AGE_IN_MINUTES,
3433
);
3534

3635
expect(isValid).toBe(true);
@@ -44,7 +43,7 @@ describe("Utils of the IcWebSocket", () => {
4443
messageToVerify.cert,
4544
messageToVerify.tree,
4645
agent,
47-
maxCertificateAgeInMinutes,
46+
MAX_CERTIFICATE_AGE_IN_MINUTES,
4847
)).rejects.toThrow("Could not find certified data for this canister in the certificate.");
4948
});
5049

@@ -56,7 +55,7 @@ describe("Utils of the IcWebSocket", () => {
5655
messageToVerify.cert,
5756
messageToVerify.tree,
5857
agent,
59-
maxCertificateAgeInMinutes,
58+
MAX_CERTIFICATE_AGE_IN_MINUTES,
6059
);
6160

6261
expect(isValid).toBe(false);
@@ -70,7 +69,7 @@ describe("Utils of the IcWebSocket", () => {
7069
messageToVerify.cert,
7170
messageToVerify.tree,
7271
agent,
73-
maxCertificateAgeInMinutes,
72+
MAX_CERTIFICATE_AGE_IN_MINUTES,
7473
);
7574

7675
expect(isValid).toBe(false);
@@ -84,7 +83,7 @@ describe("Utils of the IcWebSocket", () => {
8483
new Uint8Array([0, 1, 2, 3]),
8584
messageToVerify.tree,
8685
agent,
87-
maxCertificateAgeInMinutes,
86+
MAX_CERTIFICATE_AGE_IN_MINUTES,
8887
);
8988

9089
expect(isValid).toBe(false);
@@ -99,7 +98,7 @@ describe("Utils of the IcWebSocket", () => {
9998
// another tree, valid but not the same as the one used to generate the data
10099
fromHex("d9d9f7830249776562736f636b657483025854737164666c2d6d72346b6d2d3268666a792d67616a716f2d78717668372d6866346d662d6e726134692d336974366c2d6e656177342d736f6f6c772d7461655f3030303030303030303030303030303030303030820358200a621494d244cd4426e1f3c2ac6942bb21a5312f613f534e6da5182571757403"),
101100
agent,
102-
maxCertificateAgeInMinutes,
101+
MAX_CERTIFICATE_AGE_IN_MINUTES,
103102
);
104103

105104
expect(isValid).toBe(false);
@@ -114,7 +113,7 @@ describe("Utils of the IcWebSocket", () => {
114113
messageToVerify.tree,
115114
// the default agent uses the mainnet replica root key
116115
new HttpAgent(),
117-
maxCertificateAgeInMinutes,
116+
MAX_CERTIFICATE_AGE_IN_MINUTES,
118117
);
119118

120119
expect(isValid).toBe(false);

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
reconstruct,
1010
} from "@dfinity/agent";
1111
import { Principal } from "@dfinity/principal";
12-
import logger from "./logger";
12+
import { logger } from "./logger";
1313

1414
const areBuffersEqual = (buf1: ArrayBuffer, buf2: ArrayBuffer): boolean => {
1515
return compare(buf1, buf2) === 0;

0 commit comments

Comments
 (0)