Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rstp-god committed Nov 8, 2022
2 parents 6203e60 + 63026d3 commit 0caa8cb
Show file tree
Hide file tree
Showing 41 changed files with 523 additions and 346 deletions.
56 changes: 13 additions & 43 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
{
"overrides": [
{
"files": "*.js",
"extends": [
"eslint:recommended",
"prettier"
],
"plugins": [
"prettier"
],
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true
},
"rules": {
"prettier/prettier": "error"
}
},
{
"files": "*.ts",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint"
],
"plugins": [
"@typescript-eslint",
"prettier"
],
"parser": "@typescript-eslint/parser",
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/triple-slash-reference": "off",
"prettier/prettier": "error"
}
}
]
"plugins": [
"eslint-plugin-prettier",
"eslint-plugin-no-cyrillic-string"
],
"rules": {
"prettier/prettier": "error",
"no-cyrillic-string/no-cyrillic-string": "error"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
}
}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ node_js:
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
before_install:
- yarn cache clean
install:
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"packages/*"
],
"useWorkspaces": true,
"version": "2.4.5"
"version": "6.0.0"
}
25 changes: 15 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@
"docs": "node scripts/generate-docs.js"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"ejs": "^3.0.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-no-cyrillic-string": "^1.0.5",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^8.0.0",
"husky": "^4.2.1",
"lerna": "^3.20.2",
"lerna": "^6.0.0",
"lerna-update-wizard": "^1.1.2",
"lint-staged": "^10.0.2",
"prettier": "1.18.2",
"typedoc": "^0.16.9",
"typescript": "^3.7.5"
"prettier": "2.7.1",
"typedoc": "^0.23.16",
"typescript": "^4.8.4"
},
"workspaces": {
"packages": [
"examples/*",
"packages/*"
],
"examples": [
"examples/*"
],
"nohoist": [
"**/react-native",
"**/react-native/**",
Expand Down
13 changes: 0 additions & 13 deletions packages/e3kit-base/.mocharc.json

This file was deleted.

53 changes: 27 additions & 26 deletions packages/e3kit-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,39 @@
"build": "rollup -c",
"clean": "rimraf .rpt2_cache dist",
"prepare": "npm run clean && npm run build",
"test": "mocha"
"ts-mocha": "ts-mocha -p tsconfig.spec.json src/__tests__/*.spec.ts"
},
"dependencies": {
"@types/abstract-leveldown": "^5.0.1",
"@types/levelup": "^4.3.0",
"@virgilsecurity/crypto-types": "^1.0.0",
"@virgilsecurity/keyknox": "^1.0.3",
"@virgilsecurity/sdk-crypto": "^1.0.0",
"abstract-leveldown": "^6.2.2",
"levelup": "^4.3.2",
"subleveldown": "^4.1.4",
"virgil-pythia": "^1.0.2",
"virgil-sdk": "^6.1.2"
"@types/abstract-leveldown": "7.2.0",
"@types/expect": "24.3.0",
"@types/levelup": "5.1.2",
"@virgilsecurity/crypto-types": "1.1.1",
"@virgilsecurity/keyknox": "1.0.3",
"@virgilsecurity/sdk-crypto": "1.1.1",
"abstract-leveldown": "7.2.0",
"levelup": "5.1.1",
"subleveldown": "6.0.1",
"virgil-pythia": "1.0.2",
"virgil-sdk": "6.1.2"
},
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/chai-as-promised": "^7.1.2",
"@types/chai": "4.3.3",
"@types/chai-as-promised": "7.1.5",
"@types/memdown": "^3.0.0",
"@types/mocha": "^5.2.7",
"@types/sinon": "7.5.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"@types/mocha": "10.0.0",
"@types/sinon": "10.0.13",
"chai": "4.3.6",
"chai-as-promised": "7.1.1",
"memdown": "^5.1.0",
"mocha": "^7.0.1",
"rimraf": "^3.0.0",
"rollup": "^1.29.1",
"rollup-plugin-license": "^2.3.0",
"rollup-plugin-typescript2": "^0.25.3",
"sinon": "8.1.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5",
"virgil-crypto": "^4.1.2"
"rimraf": "3.0.2",
"rollup": "3.1.0",
"rollup-plugin-license": "2.8.1",
"rollup-plugin-typescript2": "0.34.1",
"sinon": "14.0.1",
"ts-mocha": "10.0.0",
"ts-node": "10.9.1",
"typescript": "4.8.4",
"virgil-crypto": "4.2.2"
},
"publishConfig": {
"access": "public"
Expand Down
12 changes: 6 additions & 6 deletions packages/e3kit-base/src/AbstractEThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export abstract class AbstractEThree {
}
this.inProcess = true;
try {
const [cards, privateKey] = await Promise.all<ICard[], IPrivateKey | null>([
const [cards, privateKey]: [ICard[], IPrivateKey | null] = await Promise.all([
this.cardManager.searchCards(this.identity),
this.keyLoader.loadLocalPrivateKey(),
]);
Expand All @@ -134,7 +134,7 @@ export abstract class AbstractEThree {
}
this.inProcess = true;
try {
const [cards, privateKey] = await Promise.all<ICard[], IPrivateKey | null>([
const [cards, privateKey]: [ICard[], IPrivateKey | null] = await Promise.all([
this.cardManager.searchCards(this.identity),
this.keyLoader.loadLocalPrivateKey(),
]);
Expand Down Expand Up @@ -472,7 +472,7 @@ export abstract class AbstractEThree {
}

const identitiesFound = new Set(Object.keys(result));
const identitiesNotFound = new Set([...identitySet].filter(i => !identitiesFound.has(i)));
const identitiesNotFound = new Set([...identitySet].filter((i) => !identitiesFound.has(i)));
if (identitiesNotFound.size > 0) {
throw new UsersNotFoundError([...identitiesNotFound]);
}
Expand Down Expand Up @@ -533,7 +533,7 @@ export abstract class AbstractEThree {
const resultWithErrors: { [identity: string]: Error } = {};

for (const identity of argument) {
const filteredCards = cards.filter(card => card.identity === identity);
const filteredCards = cards.filter((card) => card.identity === identity);
if (filteredCards.length === 0) {
resultWithErrors[identity] = new LookupNotFoundError(identity);
} else if (filteredCards.length > 1) {
Expand Down Expand Up @@ -689,10 +689,10 @@ export abstract class AbstractEThree {
private isOwnPublicKeyIncluded(ownPublicKey: IPublicKey, publicKeys: IPublicKey[]) {
const selfPublicKey = this.virgilCrypto.exportPublicKey(ownPublicKey).toString('base64');

const stringKeys = publicKeys.map(key =>
const stringKeys = publicKeys.map((key) =>
this.virgilCrypto.exportPublicKey(key).toString('base64'),
);
return stringKeys.some(key => key === selfPublicKey);
return stringKeys.some((key) => key === selfPublicKey);
}

private throwIllegalInvocationError(method: string) {
Expand Down
30 changes: 16 additions & 14 deletions packages/e3kit-base/src/GroupLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference path="../declarations.d.ts" />
import levelup, { LevelUp } from 'levelup';
import levelup from 'levelup';
import { LevelUp } from 'levelup';
import sub from 'subleveldown';
import { AbstractLevelDOWN, AbstractBatch } from 'abstract-leveldown';
import { Ticket, RawGroup, GroupInfo, IKeyPair, ICrypto } from './types';
Expand All @@ -18,7 +19,7 @@ export interface GroupLocalStorageConstructorParams {

export class GroupLocalStorage {
private _db: LevelUp;
private _encryptionLevel: VirgilEncryptDown<string>;
private readonly _encryptionLevel: VirgilEncryptDown<string>;

constructor({ identity, virgilCrypto, leveldown }: GroupLocalStorageConstructorParams) {
this._encryptionLevel = new VirgilEncryptDown(leveldown, { virgilCrypto });
Expand All @@ -39,11 +40,13 @@ export class GroupLocalStorage {
key: sessionId,
value: rawGroup.info,
};
const insertTickets: AbstractBatch<string, Ticket>[] = rawGroup.tickets.map(ticket => ({
type: 'put',
key: this.getTicketKey(sessionId, ticket.groupSessionMessage.epochNumber),
value: ticket,
}));
const insertTickets: AbstractBatch<string, Ticket>[] = rawGroup.tickets.map(
(ticket: Ticket) => ({
type: 'put',
key: this.getTicketKey(sessionId, ticket.groupSessionMessage.epochNumber),
value: ticket,
}),
);

await this._db.batch([insertInfo, ...insertTickets]);
}
Expand All @@ -56,12 +59,11 @@ export class GroupLocalStorage {
throw new Error('Either "ticketCount" or "epochNumber" option must be provided');
}

const [info, tickets] = await Promise.all<GroupInfo | null, Ticket[]>([
const [info, tickets]: [GroupInfo | null, Ticket[]] = await Promise.all([
this.retrieveGroupInfo(sessionId),
options.ticketCount
? this.retrieveNLastTickets(sessionId, options.ticketCount)
: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.retrieveTicketByEpochNumber(sessionId, options.epochNumber!),
: this.retrieveTicketByEpochNumber(sessionId, options.epochNumber!),
]);

if (!info || tickets.length === 0) return null;
Expand Down Expand Up @@ -100,7 +102,7 @@ export class GroupLocalStorage {
private async retrieveGroupInfo(sessionId: string): Promise<GroupInfo | null> {
try {
return await this._db.get(sessionId);
} catch (err) {
} catch (err: any) {
if (err.notFound) {
return null;
}
Expand All @@ -121,8 +123,8 @@ export class GroupLocalStorage {
reverse: true,
limit: ticketCount,
})
.on('data', data => tickets.unshift(data.value))
.on('error', err => (error = err))
.on('data', (data) => tickets.unshift(data.value))
.on('error', (err) => (error = err))
.on('end', () => (error ? reject(error) : resolve(tickets)));
});
}
Expand All @@ -135,7 +137,7 @@ export class GroupLocalStorage {
try {
const ticket = await this._db.get(key);
return [ticket];
} catch (err) {
} catch (err: any) {
if (err.notFound) {
return [];
}
Expand Down
15 changes: 7 additions & 8 deletions packages/e3kit-base/src/GroupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class GroupManager {
initiatorCard.identity,
initiatorCard.publicKey,
);
} catch (err) {
} catch (err: any) {
if (
err.name === 'GroupTicketDoesntExistError' ||
err.name === 'GroupTicketNoAccessError'
Expand All @@ -92,7 +92,7 @@ export class GroupManager {
}

const initiator = initiatorCard.identity;
const tickets = cloudTickets.map(ct => ({
const tickets = cloudTickets.map((ct) => ({
groupSessionMessage: ct.groupSessionMessageInfo,
participants: ct.identities,
}));
Expand Down Expand Up @@ -124,7 +124,7 @@ export class GroupManager {
cardManager: this._cardManager,
groupManager: this,
});
} catch (error) {
} catch (error: any) {
if (error.name === 'GroupTicketNoAccessError') {
throw new GroupError(
GroupErrorCode.NoAccess,
Expand All @@ -142,9 +142,9 @@ export class GroupManager {
await cloudTicketStorage.addRecipients(sessionId, allowedCards);
await localGroupStorage.addParticipants(
sessionId,
allowedCards.map(card => card.identity),
allowedCards.map((card) => card.identity),
);
} catch (error) {
} catch (error: any) {
if (error.name === 'GroupTicketNoAccessError') {
throw new GroupError(
GroupErrorCode.NoAccess,
Expand All @@ -158,7 +158,7 @@ export class GroupManager {
async removeAccess(sessionId: string, forbiddenIdentities: string[]) {
const cloudTicketStorage = await this.getCloudTicketStorage();
await Promise.all(
forbiddenIdentities.map(identity =>
forbiddenIdentities.map((identity) =>
cloudTicketStorage.removeRecipient(sessionId, identity),
),
);
Expand All @@ -175,7 +175,7 @@ export class GroupManager {
const cloudTicketStorage = await this.getCloudTicketStorage();
try {
await cloudTicketStorage.reAddRecipient(sessionId, allowedCard);
} catch (error) {
} catch (error: any) {
if (error.name === 'GroupTicketNoAccessError') {
throw new GroupError(
GroupErrorCode.NoAccess,
Expand Down Expand Up @@ -217,7 +217,6 @@ export class GroupManager {
accessTokenProvider,
apiUrl,
undefined,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
new VirgilAgent(
process.env.__VIRGIL_PRODUCT_NAME__!,
process.env.__VIRGIL_PRODUCT_VERSION__!,
Expand Down
Loading

0 comments on commit 0caa8cb

Please sign in to comment.