Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make storage compatible to theglow #8

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "glow.ts",
"version": "0.2.0",
"version": "0.2.1",
"displayName": "Glow.ts",
"description": "Client library for interacting with Zax Cryptographic Relay Servers",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sessionTimeoutBuffer = 30 * 1000;
export const config = {
NONCE_TAG: '__nc',
SKEY_TAG: 'storage_key',
STORAGE_ROOT: '.v2.stor.vlt12',
STORAGE_ROOT: '.v1.stor.vlt12',
// Relay tokens, keys and hashes are 32 bytes
RELAY_TOKEN_LEN: 32,
// 5 min - Token expiration on the server side, matched with config.x.relay.token_timeout on Zax server
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { JsNaClDriver } from './nacl/js-nacl-driver';
import { Utils } from './utils/utils';
import { NaClDriver } from './nacl/nacl-driver.interface';
import { InMemoryStorage } from './crypto-storage/in-memory-storage';

export {
NaCl,
Expand All @@ -30,5 +31,6 @@ export {
FileStatusResponse,
NaClDriver,
JsNaClDriver,
Utils
Utils,
InMemoryStorage
};
10 changes: 5 additions & 5 deletions src/keyring/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ export class KeyRing {
}

private async loadGuestKeys() {
const guestKeys = await this.storage.get(KeyRing.guestRegistryTag);
const guestKeys = await this.storage.get(KeyRing.guestRegistryTag) as {[key:string]: any};
if (!guestKeys) {
return;
} else if (Array.isArray(guestKeys)) {
this.guestKeys = new Map(guestKeys);
} else if (typeof guestKeys === 'object') {
this.guestKeys = new Map(Object.entries(guestKeys));
} else {
throw new Error('[Keyring] Guest keys is not an array');
throw new Error('[Keyring] Guest keys is not an object');
}
}

private async saveGuests() {
await this.storage.save(KeyRing.guestRegistryTag, Array.from(this.guestKeys.entries()));
await this.storage.save(KeyRing.guestRegistryTag, Object.fromEntries(this.guestKeys.entries()));
}

private static async getCommKey(nacl: NaClDriver, storage: CryptoStorage): Promise<Keys> {
Expand Down