Skip to content

Commit

Permalink
Don't leak libsodium types and refactor online managers a bit.
Browse files Browse the repository at this point in the history
Ref #15
  • Loading branch information
tasn committed Mar 6, 2021
1 parent c0f977c commit 408441c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@msgpack/msgpack": "^1.12.2",
"@types/urijs": "^1.15.38",
"argon2-webworker": "^0.1.1",
"isomorphic-ws": "^4.0.1",
"libsodium-wrappers": "0.7.6",
Expand All @@ -37,7 +38,6 @@
"@types/jest": "^24.0.22",
"@types/libsodium-wrappers": "^0.7.7",
"@types/node": "^13.9.1",
"@types/urijs": "^1.15.38",
"@typescript-eslint/eslint-plugin": "^2.6.1",
"@typescript-eslint/parser": "^2.6.1",
"@typescript-eslint/typescript-estree": "^2.6.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Rollsum } from "./Chunker";

import type rnsodiumType from "react-native-sodium";

export const sodium = _sodium;
const sodium = _sodium;

let rnsodium: typeof rnsodiumType;

Expand Down
2 changes: 1 addition & 1 deletion src/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as msgpack from "@msgpack/msgpack";

import _sodium from "libsodium-wrappers";

export const sodium = _sodium;
const sodium = _sodium;

export type base64 = string;

Expand Down
26 changes: 13 additions & 13 deletions src/OnlineManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ interface AccountOnlineData {
authToken: string | null;
}

class BaseNetwork {

public static urlExtend(baseUrlIn: URI, segments: string[]): URI {
const baseUrl = baseUrlIn.clone();
for (const segment of segments) {
baseUrl.segment(segment);
}
baseUrl.segment("");
return baseUrl.normalize();
function urlExtend(baseUrlIn: URI, segments: string[]): URI {
const baseUrl = baseUrlIn.clone();
for (const segment of segments) {
baseUrl.segment(segment);
}
baseUrl.segment("");
return baseUrl.normalize();
}

class BaseNetwork {
public apiBase: URI;

constructor(apiBase: string) {
this.apiBase = URI(apiBase).normalize();
}

public async newCall<T = any>(segments: string[] = [], extra: RequestInit = {}, apiBaseIn: URI = this.apiBase): Promise<T> {
const apiBase = BaseNetwork.urlExtend(apiBaseIn, segments);
const apiBase = urlExtend(apiBaseIn, segments);

extra = {
...extra,
Expand Down Expand Up @@ -205,7 +205,7 @@ class BaseNetwork {
export class Authenticator extends BaseNetwork {
constructor(apiBase: string) {
super(apiBase);
this.apiBase = BaseNetwork.urlExtend(this.apiBase, ["api", "v1", "authentication"]);
this.apiBase = urlExtend(this.apiBase, ["api", "v1", "authentication"]);
}

public async isEtebase(): Promise<boolean> {
Expand Down Expand Up @@ -318,7 +318,7 @@ class BaseManager extends BaseNetwork {
constructor(etebase: AccountOnlineData, segments: string[]) {
super(etebase.serverUrl);
this.etebase = etebase;
this.apiBase = BaseNetwork.urlExtend(this.apiBase, ["api", "v1"].concat(segments));
this.apiBase = urlExtend(this.apiBase, ["api", "v1"].concat(segments));
}

public newCall<T = any>(segments: string[] = [], extra: RequestInit = {}, apiBase: URI = this.apiBase): Promise<T> {
Expand Down Expand Up @@ -714,7 +714,7 @@ export class WebSocketManagerOnline extends BaseManager {
const urlProvider = async () => {
const options = await this.getUrlOptions();
const apiBase = this.urlFromFetchOptions(options.fetchOptions).protocol(protocol);
return BaseNetwork.urlExtend(apiBase, [options.ticket]).toString();
return urlExtend(apiBase, [options.ticket]).toString();
};

return new WebSocketHandle(urlProvider, cb);
Expand Down

0 comments on commit 408441c

Please sign in to comment.