Skip to content

Commit

Permalink
Merge branch 'main' into personalized-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 10, 2024
2 parents 7ceaed6 + 745e05d commit 80d848d
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 105 deletions.
391 changes: 324 additions & 67 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"test:teardown": "docker compose -f .dev/compose.yml down -fsv"
},
"devDependencies": {
"@js-soft/eslint-config-ts": "^1.6.10",
"@js-soft/eslint-config-ts": "^1.6.12",
"@js-soft/license-check": "^1.0.9",
"@types/jest": "^29.5.13",
"@types/node": "^22.7.4",
"@types/node": "^22.7.5",
"enhanced-publish": "^1.1.3",
"eslint": "^8.57.1",
"jest": "^29.7.0",
Expand All @@ -41,6 +41,6 @@
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.2"
"typescript": "^5.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function validateAttributeMatchesWithIdentityAttributeQuery(
return ValidationResult.success();
}

function validateAttributeMatchesWithIQLQuery(query: IQLQuery, attribute: IdentityAttribute | RelationshipAttribute, recipient: CoreAddress): ValidationResult {
function validateAttributeMatchesWithIQLQuery(_: IQLQuery, attribute: IdentityAttribute | RelationshipAttribute, recipient: CoreAddress): ValidationResult {
if (!(attribute instanceof IdentityAttribute)) {
return ValidationResult.error(
ConsumptionCoreErrors.requests.attributeQueryMismatch(
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@nmshd/crypto": "2.0.7",
"axios": "^1.7.7",
"fast-json-patch": "^3.1.1",
"form-data": "^4.0.0",
"form-data": "^4.0.1",
"https-proxy-agent": "^7.0.5",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.21",
Expand Down
10 changes: 10 additions & 0 deletions packages/transport/src/core/CoreCrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export abstract class CoreCrypto {
*/
public static async generateSignatureKeypair(version: TransportVersion = TransportVersion.Latest): Promise<CryptoSignatureKeypair> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoSignatures.generateKeypair(CryptoSignatureAlgorithm.ECDSA_ED25519);
default:
Expand All @@ -53,6 +54,7 @@ export abstract class CoreCrypto {
*/
public static async generateExchangeKeypair(version: TransportVersion = TransportVersion.Latest): Promise<CryptoExchangeKeypair> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoExchange.generateKeypair(CryptoExchangeAlgorithm.ECDH_X25519);
default:
Expand All @@ -70,6 +72,7 @@ export abstract class CoreCrypto {
*/
public static async generateSecretKey(version: TransportVersion = TransportVersion.Latest): Promise<CryptoSecretKey> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoEncryption.generateKey(CryptoEncryptionAlgorithm.XCHACHA20_POLY1305);
default:
Expand Down Expand Up @@ -101,6 +104,7 @@ export abstract class CoreCrypto {
const masterBuffer = CoreBuffer.fromString(master, Encoding.Utf8);
const saltBuffer = CoreBuffer.fromString(salt, Encoding.Utf8);
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoDerivation.deriveKeyFromMaster(masterBuffer, 150000, keyAlgorithm, saltBuffer);
default:
Expand Down Expand Up @@ -132,6 +136,7 @@ export abstract class CoreCrypto {
version: TransportVersion = TransportVersion.Latest
): Promise<CryptoExchangeSecrets> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
const base: CryptoExchangeSecrets = await CryptoExchange.deriveTemplator(client, serverPublicKey, keyAlgorithm);
return base;
Expand All @@ -147,6 +152,7 @@ export abstract class CoreCrypto {
version: TransportVersion = TransportVersion.Latest
): Promise<CryptoExchangeSecrets> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
const base = await CryptoExchange.deriveRequestor(server, clientPublicKey, keyAlgorithm);
return base;
Expand All @@ -167,6 +173,7 @@ export abstract class CoreCrypto {
*/
public static async sign(content: CoreBuffer, privateKey: CryptoSignaturePrivateKey, version: TransportVersion = TransportVersion.Latest): Promise<CryptoSignature> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoSignatures.sign(content, privateKey, CryptoHashAlgorithm.SHA512);
default:
Expand All @@ -192,6 +199,7 @@ export abstract class CoreCrypto {
version: TransportVersion = TransportVersion.Latest
): Promise<boolean> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoSignatures.verify(content, signature, publicKey);
default:
Expand All @@ -213,6 +221,7 @@ export abstract class CoreCrypto {
*/
public static async encrypt(content: CoreBuffer, secretKey: CryptoSecretKey, version: TransportVersion = TransportVersion.Latest): Promise<CryptoCipher> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoEncryption.encrypt(content, secretKey);
default:
Expand All @@ -234,6 +243,7 @@ export abstract class CoreCrypto {
*/
public static async decrypt(cipher: CryptoCipher, secretKey: CryptoSecretKey, version: TransportVersion = TransportVersion.Latest): Promise<CoreBuffer> {
switch (version) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
case TransportVersion.V1:
return await CryptoEncryption.decrypt(cipher, secretKey);
default:
Expand Down
4 changes: 2 additions & 2 deletions packages/transport/src/core/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Reference extends Serializable implements IReference {
if (value === "") return undefined;

return parseInt(value);
} catch (e) {
} catch (_) {
throw TransportCoreErrors.general.invalidTruncatedReference("The password type must be indicated by an integer in the TruncatedReference.");
}
}
Expand All @@ -80,7 +80,7 @@ export class Reference extends Serializable implements IReference {

try {
algorithm = parseInt(alg);
} catch (e) {
} catch (_) {
throw TransportCoreErrors.general.invalidTruncatedReference("The encryption algorithm must be indicated by an integer in the TruncatedReference.");
}

Expand Down
17 changes: 2 additions & 15 deletions packages/transport/src/core/TransportCoreErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CoreError } from "@nmshd/core-types";
import stringify from "json-stringify-safe";
import { RelationshipStatus } from "../modules";

class Relationships {
Expand Down Expand Up @@ -104,20 +103,8 @@ class Challenges {
}

class Datawallet {
public unsupportedModification(type: "unsupportedCacheChangedModificationCollection", data: any) {
const errorCode = "error.transport.datawallet.unsupportedModification";
const formattedData = data ? stringify(data) : "";

switch (type) {
case "unsupportedCacheChangedModificationCollection":
return new CoreError(
errorCode,
`The following collections were received in CacheChanged datawallet modifications but are not supported by the current version of this library: '${formattedData}'.`
);

default:
throw new Error(`Given type '${type}' is not supported.`);
}
public unsupportedModification(message: string) {
return new CoreError("error.transport.datawallet.unsupportedModification", message);
}

public insufficientSupportedDatawalletVersion(supportedVersion: number, requiredVersion: number) {
Expand Down
10 changes: 5 additions & 5 deletions packages/transport/src/core/backbone/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class RESTClient {
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/naming-convention
const HttpsProxyAgent = require("https-proxy-agent").HttpsProxyAgent;
resultingRequestConfig.httpsAgent = new HttpsProxyAgent(httpsProxy, this.config.httpsAgentOptions);
} catch (e) {
} catch (_) {
// ignore
}
} else {
Expand All @@ -99,7 +99,7 @@ export class RESTClient {
const httpsAgent = require("https")?.Agent;

if (httpsAgent) resultingRequestConfig.httpsAgent = new httpsAgent(this.config.httpsAgentOptions);
} catch (e) {
} catch (_) {
// ignore
}
}
Expand All @@ -109,7 +109,7 @@ export class RESTClient {
const agent = require("http")?.Agent;

if (agent) resultingRequestConfig.httpAgent = new agent(this.config.httpAgentOptions);
} catch (e) {
} catch (_) {
// ignore
}

Expand Down Expand Up @@ -184,7 +184,7 @@ export class RESTClient {
try {
const errorText = CoreBuffer.from(response.data).toUtf8();
response.data = JSON.parse(errorText);
} catch (e) {
} catch (_) {
// Do nothing here: Error is handled below
}
}
Expand Down Expand Up @@ -503,7 +503,7 @@ export class RESTClient {
const message = `Response ${requestId}: ${method} ${path} | TraceId: '${platformParameters.traceId}' | PlatformDuration: ${platformParameters.responseDuration}`;
try {
this._logger.trace(message, JSON.stringify(response.data, undefined, 2));
} catch (e) {
} catch (_) {
this._logger.trace(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export class IdentityDeletionProcessController extends TransportController {
const getIdentityDeletionPromises = ids.map((id) => this.identityDeletionProcessClient.getIdentityDeletionProcess(id.toString()));
const backboneTokens: { id: CoreId; cache: CachedIdentityDeletionProcess }[] = [];

for await (const identityDeletionProcess of getIdentityDeletionPromises) {
const identityDeletionProcesses = await Promise.all(getIdentityDeletionPromises);

for (const identityDeletionProcess of identityDeletionProcesses) {
const { id, ...cache } = identityDeletionProcess.value;
backboneTokens.push({ id: CoreId.from(id), cache: CachedIdentityDeletionProcess.from(cache) });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export class DatawalletModificationsProcessor {
const collectionsWithUncacheableItems = uniqueCollections.filter((c) => !this.collectionsWithCacheableItems.includes(c));

if (collectionsWithUncacheableItems.length > 0) {
throw TransportCoreErrors.datawallet.unsupportedModification("unsupportedCacheChangedModificationCollection", collectionsWithUncacheableItems);
throw TransportCoreErrors.datawallet.unsupportedModification(
`The following collections were received in CacheChanged datawallet modifications but are not supported by the current version of this library: '${collectionsWithUncacheableItems.join(", ")}'.`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/transport/src/modules/tokens/TokenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class TokenController extends TransportController {
public async cleanupTokensOfDecomposedRelationship(peer: CoreAddress): Promise<void> {
const tokenDocs = await this.getTokens({ "cache.createdBy": peer.toString() });
const tokens = this.parseArray<Token>(tokenDocs, Token);
for await (const token of tokens) {
for (const token of tokens) {
await this.tokens.delete(token);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/test/core/backbone/Paginator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { FakePaginationDataSource } from "../../testHelpers/FakePaginationDataSo
import { TestUtil } from "../../testHelpers/TestUtil";

async function itereateThroughAllItemsAsynchronously<T>(paginator: Paginator<T>) {
// eslint-disable-next-line no-empty,@typescript-eslint/no-unused-vars
for await (const _ of paginator) {
// noop
}
}

Expand Down
1 change: 0 additions & 1 deletion packages/transport/test/modules/PublicAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ function testPublicFunctions(controllerName: string) {
let found = 0;
for (const functionName of publicFunctions[controllerName]) {
const item = controllers[controllerName][functionName];
// eslint-disable-next-line jest/no-conditional-in-test
if (!item || typeof item !== "function") continue;
found++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("RelationshipsController", function () {
let recipientRel: Relationship;
let tempDate: CoreDate;

function expectValidActiveFreshRelationship(relationship: Relationship, ownAccount: AccountController, peerAccount: AccountController, creationTime: CoreDate) {
function expectValidActiveFreshRelationship(relationship: Relationship, _: AccountController, peerAccount: AccountController, creationTime: CoreDate) {
expect(relationship.id).toBeInstanceOf(CoreId);
expect(relationship.status).toStrictEqual(RelationshipStatus.Active);
expect(relationship.peer).toBeInstanceOf(Identity);
Expand Down
2 changes: 1 addition & 1 deletion packages/transport/test/testHelpers/FakeSyncClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class FakeSyncClient implements ISyncClient {
throw new Error("Method not implemented.");
}

public finalizeDatawalletVersionUpgrade(id: string, request: FinalizeDatawalletVersionUpgradeRequest): Promise<ClientResult<FinalizeDatawalletVersionUpgradeResponse>> {
public finalizeDatawalletVersionUpgrade(_id: string, request: FinalizeDatawalletVersionUpgradeRequest): Promise<ClientResult<FinalizeDatawalletVersionUpgradeResponse>> {
this.finalizeDatawalletVersionUpgradeRequest = request;

return Promise.resolve(
Expand Down
2 changes: 0 additions & 2 deletions packages/transport/test/utils/Random.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe("RandomTest", function () {
const iterations = 10000;
for (let i = 1; i < iterations; i++) {
const n = await Random.intBetween(0, 1);
// eslint-disable-next-line jest/no-conditional-in-test
switch (n) {
case 0:
buckets[0]++;
Expand Down Expand Up @@ -136,7 +135,6 @@ describe("RandomTest", function () {

for (let i = 1; i < iterations; i++) {
const n = await Random.string(1, RandomCharacterRange.Alphabet);
// eslint-disable-next-line jest/no-conditional-in-test
if (buckets[n]) buckets[n]++;
else buckets[n] = 1;
}
Expand Down
2 changes: 0 additions & 2 deletions packages/transport/test/utils/Reflection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe("ReflectionTest", function () {
const reflectionKeys = Reflect.getMetadataKeys(Serializable, "types");
const notFoundClasses: string[] = [];
for (const className of cryptoClassNames) {
// eslint-disable-next-line jest/no-conditional-in-test
if (!reflectionKeys.includes(className)) {
notFoundClasses.push(className);
}
Expand All @@ -112,7 +111,6 @@ describe("ReflectionTest", function () {
const notFoundClasses: string[] = [];

for (const className of transportClassNames) {
// eslint-disable-next-line jest/no-conditional-in-test
if (!reflectionKeys.includes(className)) {
notFoundClasses.push(className);
}
Expand Down

0 comments on commit 80d848d

Please sign in to comment.