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 4, 2021
1 parent c0f977c commit 5c03297
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
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 5c03297

Please sign in to comment.