Skip to content

Commit

Permalink
Fix rest
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jul 13, 2023
1 parent 22566a9 commit d9bef5b
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 90 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"rules": {
"no-console": 1, // Means warning
"prettier/prettier": 2, // Means error
"@typescript-eslint/no-floating-promises": ["error"]
"@typescript-eslint/no-floating-promises": ["error"],
"@typescript-eslint/no-non-null-assertion": "off"
},
"ignorePatterns": ["dist", "node_modules"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"doc:build": "npm run doc:extract && npm run doc:documenter",
"doc:watch:website": "ts-node ./scripts/doc-watch.ts",
"tsc:declaration:watch": "tsc --watch --module commonjs --emitDeclarationOnly",
"test": "mocha",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"strict\": false }' mocha",
"lint": "eslint --fix --ext .js,.ts src/** tests/**",
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"deps:check": "madge --circular --extensions ts ./"
Expand Down
7 changes: 3 additions & 4 deletions src/circuits/auth-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ interface AuthV2CircuitInputs {
* @class AuthV2PubSignals
*/
export class AuthV2PubSignals {
userID?: Id;
challenge?: bigint;
GISTRoot?: Hash;
//
userID!: Id;
challenge!: bigint;
GISTRoot!: Hash;

/**
* PubSignalsUnmarshal unmarshal auth.circom public inputs to AuthPubSignals
Expand Down
3 changes: 2 additions & 1 deletion src/circuits/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export const existenceToInt = (b: boolean): number => (b ? 0 : 1);
* @returns object
*/
export function getProperties(obj: object): object {
const result: any = {};
const result: { [key: string]: unknown } = {};

for (const property in obj) {
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(property) && !property.startsWith('_')) {
Expand Down
8 changes: 4 additions & 4 deletions src/circuits/state-transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ interface StateTransitionInputsInternal {
* @class StateTransitionPubSignals
*/
export class StateTransitionPubSignals {
userId?: Id;
oldUserState?: Hash;
newUserState?: Hash;
isOldStateGenesis?: boolean;
userId!: Id;
oldUserState!: Hash;
newUserState!: Hash;
isOldStateGenesis!: boolean;

/**
*
Expand Down
6 changes: 4 additions & 2 deletions src/iden3comm/handlers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export class FetchHandler implements IFetchHandler {
}
message = await resp.json();
credentials.push(message.body.credential);
} catch (e: any) {
} catch (e: unknown) {
throw new Error(
`could not fetch W3C credential, ${credentialInfo?.id}, error: ${e.message ?? e}`
`could not fetch W3C credential, ${credentialInfo?.id}, error: ${
(e as Error).message ?? e
}`
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/iden3comm/utils/did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const resolveDIDDocument = async (
const response = await fetch(`${UNIVERSAL_RESOLVER_URL}/${didUrl}`);
const data = await response.json();
return data as DIDResolutionResult;
} catch (error: any) {
throw new Error(`Can't resolve did document: ${error.message}`);
} catch (error: unknown) {
throw new Error(`Can't resolve did document: ${(error as Error).message}`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export class IdentityWallet implements IIdentityWallet {
issuerAuthBJJCredential.proof as unknown[]
)[0] as Iden3SparseMerkleTreeProof;

const sigProof: BJJSignatureProof2021 = {
const sigProof = new BJJSignatureProof2021({
type: ProofType.BJJSignature,
issuerData: new IssuerData({
id: issuerDID.string(),
Expand All @@ -634,7 +634,7 @@ export class IdentityWallet implements IIdentityWallet {
}),
coreClaim: coreClaim.hex(),
signature: Hex.encodeString(signature)
};
});
credential.proof = [sigProof];

return credential;
Expand Down
1 change: 0 additions & 1 deletion src/kms/key-providers/sec256k1-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IKeyProvider } from '../kms';
import { AbstractPrivateKeyStore, KmsKeyId, KmsKeyType } from '../store';
import Elliptic from 'elliptic';
import * as providerHelpers from '../provider-helpers';
import { PublicKey } from '@iden3/js-crypto';
import { ES256KSigner } from 'did-jwt';
import { base64ToBytes, byteEncoder, bytesToHex, hexToBytes } from '../../utils';

Expand Down
2 changes: 1 addition & 1 deletion src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ export class ProofService implements IProofService {

const [fieldName, fieldReq] = entries[0];

const fieldReqEntries = Object.entries(fieldReq as any);
const fieldReqEntries = Object.entries(fieldReq as { [key: string]: unknown });

if (fieldReqEntries.length > 1) {
throw new Error(`multiple predicates for one field not supported`);
Expand Down
1 change: 1 addition & 0 deletions src/proof/prover.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { ZKProof } from '@iden3/js-jwz';
import { CircuitId } from '../circuits';
import { ICircuitStorage } from '../storage/interfaces/circuits';
Expand Down
1 change: 1 addition & 0 deletions src/schema-processor/jsonld/parser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const jsonld = require('jsonld/lib');
const ldcontext = require('jsonld/lib/context');

Expand Down
2 changes: 1 addition & 1 deletion src/schema-processor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const createSchemaHash = (schemaId: Uint8Array): SchemaHash => {
* @param {string} fieldName - field name
* @returns Uint8Array - filled slot
*/
export const fillSlot = (data: any, fieldName: string): Uint8Array => {
export const fillSlot = (data: { [key: string]: unknown }, fieldName: string): Uint8Array => {
let slot = Uint8Array.from([]);

if (!fieldName) {
Expand Down
10 changes: 2 additions & 8 deletions src/storage/blockchain/onchain-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ export class OnChainRevocationStorage {
const p = new Proof();
p.existence = mtp.existence;
if (p.existence) {
p.nodeAux = {
key: undefined,
value: undefined
} as NodeAux;
p.nodeAux = {} as NodeAux;
} else {
if (mtp.auxExistence) {
const auxIndex = BigInt(mtp.auxIndex.toString());
Expand All @@ -83,10 +80,7 @@ export class OnChainRevocationStorage {
value: newHashFromBigInt(auxValue)
} as NodeAux;
} else {
p.nodeAux = {
key: undefined,
value: undefined
} as NodeAux;
p.nodeAux = {} as NodeAux;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/storage/blockchain/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export class EthStateStorage implements IStateStorage {
return {
root: BigInt(data.root.toString()),
existence: data.existence,
siblings: data.siblings?.map((sibling: any) => BigInt(sibling.toString())),
siblings: data.siblings?.map(
(sibling: { toString: () => string | number | bigint | boolean }) =>
BigInt(sibling.toString())
),
index: BigInt(data.index.toString()),
value: BigInt(data.value.toString()),
auxExistence: data.auxExistence,
Expand Down
4 changes: 3 additions & 1 deletion src/storage/filters/jsonQuery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { W3CCredential, ProofQuery } from '../../verifiable';

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ export interface IFilterQuery {
const truthyValues = [true, 1, 'true'];
const falsyValues = [false, 0, 'false'];

const equalsComparator = (a, b) => {
const equalsComparator = (a: number | string | boolean, b: number | string | boolean) => {
if (truthyValues.includes(a) && truthyValues.includes(b)) {
return true;
}
Expand Down Expand Up @@ -124,6 +125,7 @@ export class FilterQuery implements IFilterQuery {
*/
export const StandardJSONCredentialsQueryFilter = (query: ProofQuery): FilterQuery[] => {
return Object.keys(query).reduce((acc: FilterQuery[], queryKey) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const queryValue: any = query[queryKey as keyof typeof query];
switch (queryKey) {
case 'claimId':
Expand Down
15 changes: 12 additions & 3 deletions src/storage/indexed-db/merkletree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export class MerkleTreeIndexedDBStorage implements IMerkleTreeStorage {
throw err;
}

const resultMeta = meta.find((m: any) => m.identifier === identifier && m.type === mtType);
const resultMeta = meta.find(
(m: { identifier: string; type: MerkleTreeType }) =>
m.identifier === identifier && m.type === mtType
);
if (!resultMeta) {
throw err;
}
Expand All @@ -114,7 +117,10 @@ export class MerkleTreeIndexedDBStorage implements IMerkleTreeStorage {
if (!meta) {
throw new Error(`Merkle tree meta not found for identifier ${identifier}`);
}
const resultMeta = meta.find((m: any) => m.identifier === identifier && m.type === mtType);
const resultMeta = meta.find(
(m: { identifier: string; type: MerkleTreeType }) =>
m.identifier === identifier && m.type === mtType
);
if (!resultMeta) {
throw new Error(`Merkle tree not found for identifier ${identifier} and type ${mtType}`);
}
Expand All @@ -135,7 +141,10 @@ export class MerkleTreeIndexedDBStorage implements IMerkleTreeStorage {
throw new Error(`Merkle tree meta not found for identifier ${oldIdentifier}`);
}

const treesMeta = meta.map((m: any) => ({ ...m, identifier: newIdentifier }));
const treesMeta = meta.map((m: { identifier: string; type: MerkleTreeType }) => ({
...m,
identifier: newIdentifier
}));

await del(oldIdentifier, this._merkleTreeMetaStore);
await set(newIdentifier, treesMeta, this._merkleTreeMetaStore);
Expand Down
9 changes: 5 additions & 4 deletions src/storage/local-storage/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { StorageErrors } from '../errors';
import { IDataSource } from '../interfaces/data-source';

Expand Down Expand Up @@ -31,11 +32,11 @@ export class BrowserDataSource<Type> implements IDataSource<Type> {
async save(key: string, value: Type, keyName = 'id'): Promise<void> {
if (localStorage) {
const data = localStorage.getItem(this._localStorageKey);
let items: any;
let items: Type[] = [];
if (data) {
items = JSON.parse(data) as Type[];
}
const itemIndex = items.findIndex((i: any) => i[keyName] === key);
const itemIndex = items.findIndex((i: any): boolean => i[keyName] === key);
if (itemIndex === -1) {
items.push(value);
} else {
Expand All @@ -53,7 +54,7 @@ export class BrowserDataSource<Type> implements IDataSource<Type> {

async get(key: string, keyName = 'id'): Promise<Type | undefined> {
const data = localStorage.getItem(this._localStorageKey);
let parsedData: any;
let parsedData: Type[] = [];
if (data) {
parsedData = JSON.parse(data) as Type[];
}
Expand All @@ -74,7 +75,7 @@ export class BrowserDataSource<Type> implements IDataSource<Type> {
*/
async delete(key: string, keyName = 'id'): Promise<void> {
const dataStr = localStorage.getItem(this._localStorageKey);
let data: any;
let data: Type[] = [];
if (dataStr) {
data = JSON.parse(dataStr) as Type[];
}
Expand Down
1 change: 1 addition & 0 deletions src/storage/memory/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { StorageErrors } from '../errors';
import { IDataSource } from '../interfaces/data-source';

Expand Down
2 changes: 1 addition & 1 deletion src/storage/shared/credential-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CredentialStorage implements ICredentialStorage {
/** {@inheritdoc ICredentialStorage.listCredentials } */
async listCredentials(): Promise<W3CCredential[]> {
let creds = await this._dataSource.load();
let mappedCreds = creds.map((cred) =>
const mappedCreds = creds.map((cred) =>
cred ? Object.assign(new W3CCredential(), cred) : undefined
);
creds = mappedCreds.filter((i) => i !== undefined) as W3CCredential[];
Expand Down
2 changes: 1 addition & 1 deletion src/storage/shared/identity-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class IdentityStorage implements IIdentityStorage {
return this._identityDataSource.save(identity.identifier, identity, 'identifier');
}

async getIdentity(identifier: string): Promise<Identity> {
async getIdentity(identifier: string): Promise<Identity | undefined> {
return this._identityDataSource.get(identifier, 'identifier');
}
}
27 changes: 14 additions & 13 deletions src/verifiable/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { Merklizer, Options } from '@iden3/js-jsonld-merklization';
* @class W3CCredential
*/
export class W3CCredential {
id: string;
'@context': string[];
type: string[];
id = '';
'@context': string[] = [];
type: string[] = [];
expirationDate?: string;
issuanceDate?: string;
credentialSubject: { [key: string]: object | string | number | boolean };
credentialStatus: CredentialStatus;
issuer: string;
credentialSchema: CredentialSchema;
credentialSubject: { [key: string]: object | string | number | boolean } = {};
credentialStatus!: CredentialStatus;
issuer = '';
credentialSchema!: CredentialSchema;
proof?: object | unknown[];

/**
Expand Down Expand Up @@ -68,13 +68,13 @@ export class W3CCredential {
for (const proof of this.proof) {
const { proofType: extractedProofType } = extractProof(proof);
if (proofType === extractedProofType) {
return proof as BJJSignatureProof2021;
return new BJJSignatureProof2021(proof);
}
}
} else if (typeof this.proof === 'object') {
const { proofType: extractedProofType } = extractProof(this.proof);
if (extractedProofType == proofType) {
return this.proof as BJJSignatureProof2021;
return new BJJSignatureProof2021(this.proof);
}
}
return undefined;
Expand All @@ -91,13 +91,13 @@ export class W3CCredential {
for (const proof of this.proof) {
const { proofType: extractedProofType } = extractProof(proof);
if (proofType === extractedProofType) {
return proof as Iden3SparseMerkleTreeProof;
return new Iden3SparseMerkleTreeProof(proof);
}
}
} else if (typeof this.proof === 'object') {
const { proofType: extractedProofType } = extractProof(this.proof);
if (extractedProofType == proofType) {
return this.proof as Iden3SparseMerkleTreeProof;
return new Iden3SparseMerkleTreeProof(this.proof);
}
}
return undefined;
Expand All @@ -122,11 +122,12 @@ export function extractProof(proof: object): { claim: Claim; proofType: ProofTyp
return { claim: new Claim().fromHex(proof.coreClaim), proofType: ProofType.BJJSignature };
}
if (typeof proof === 'object') {
const defaultProofType = proof['type'];
const p = proof as { type: ProofType; coreClaim: string };
const defaultProofType: ProofType = p.type;
if (!defaultProofType) {
throw new Error('proof type is not specified');
}
const coreClaimHex = proof['coreClaim'];
const coreClaimHex = p.coreClaim;
if (!coreClaimHex) {
throw new Error(`coreClaim field is not defined in proof type ${defaultProofType}`);
}
Expand Down
Loading

0 comments on commit d9bef5b

Please sign in to comment.