Skip to content

Commit

Permalink
fix(vite-app): eslint config and errors and implements iam flow
Browse files Browse the repository at this point in the history
  • Loading branch information
gdixon authored and shavinac committed Apr 7, 2022
1 parent 3190e3e commit d034f23
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 138 deletions.
12 changes: 5 additions & 7 deletions identity/src/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { generateMerkle } from './merkle';
// ---- Types
import { ChallengeRecord, MerkleRecord } from '@dpopp/types';

// Utility to add a number of days to a date
// Utility to add a number of seconds to a date
const addSeconds = (date: Date, seconds: number) => {
const result = new Date(date);
result.setSeconds(result.getSeconds() + seconds);
Expand Down Expand Up @@ -51,7 +51,7 @@ const _issueCredential = async (
export const issueChallengeCredential = async (DIDKit: { [k: string]: any }, key: string, record: ChallengeRecord) => {
// attempt to create a VC for the given payload
try {
// generate a verifiableCredential
// generate a verifiableCredential (60s ttl)
const credential = await _issueCredential(DIDKit, key, 60, {
credentialSubject: {
'@context': [
Expand Down Expand Up @@ -95,14 +95,14 @@ export const issueMerkleCredential = async (DIDKit: { [k: string]: any }, key: s
id: `did:ethr:${record.address}#${record.type}`,
// custom fields to verify a merkleTree of content that the user might voluntarily share with 3rd parties
// *loosely defined atm - How do we enforce only valid content can enter the tree?
root: root?.toString('base64')
root: root?.toString('base64'),
},
});

// didkit-wasm-node returns credential as a string - parse for JSON
return {
credential,
record
record,
};
} catch (e: any) {
return {
Expand All @@ -126,8 +126,6 @@ export const verifyCredential = async (DIDKit: { [k: string]: any }, credential:
return verify.errors.length === 0;
} else {
// past expiry :(
return {
errors: ['expired'],
};
return false;
}
};
5 changes: 4 additions & 1 deletion identity/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// export everything...
// export merkle and credential tooling
export * from './merkle';
export * from './credentials';

// export typings from libs
export type { Proof } from 'merkle-tools';
2 changes: 1 addition & 1 deletion identity/src/merkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const generateMerkle = (record: MerkleRecord) => {
for (prop in record) {
if (record.hasOwnProperty(prop)) {
// add leaf to merkle
merkleTools.addLeaf(record[prop] || "", true);
merkleTools.addLeaf(record[prop] || '', true);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"schemas",
"iam",
"identity",
"types",
"utils"
"types"
],
"npmClient": "yarn",
"version": "independent",
Expand Down
5 changes: 5 additions & 0 deletions vite-app/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*.js
/*.ts
/test/**/*.js
/dist/*
/__mocks__/**/*.js
5 changes: 3 additions & 2 deletions vite-app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
'plugin:react/recommended',
'prettier',
],
ignorePatterns: ['.eslintrc.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
Expand All @@ -25,11 +26,11 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'prettier', 'jest', 'react'],
rules: {
quotes: ['error', 'double'],
quotes: ['error', 'single'],
'no-console': 'warn',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
'@typescript-eslint/explicit-function-return-type': 'warn', // Consider using explicit annotations for object literals and function return types even when they can be inferred.
// '@typescript-eslint/explicit-function-return-type': 'warn', // Consider using explicit annotations for object literals and function return types even when they can be inferred.
'no-empty': 'warn',
'@typescript-eslint/no-misused-promises': 1,
'@typescript-eslint/no-floating-promises': 1,
Expand Down
4 changes: 2 additions & 2 deletions vite-app/__mocks__/@dpopp/identity/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ const identity = {};
// pass a false proof
identity.generateMerkle = jest.fn(() => ({
proofs: ['proof'],
root: "merkleRoot",
root: 'merkleRoot',
}));
// always verifies
identity.verifyCredential = jest.fn(() => true);
identity.verifyMerkleProof = jest.fn(() => true);

// mock nested directory
identity.dist = {
'didkit-browser.js': {}
'didkit-browser.js': {},
};

// return full mock
Expand Down
4 changes: 2 additions & 2 deletions vite-app/__mocks__/@web3-onboard/react.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const react = {};

const mockConnectFn = jest.fn();
const mockDisconnectFn = jest.fn();
const mockConnectFn = jest.fn(() => new Promise((resolve) => resolve()));
const mockDisconnectFn = jest.fn(() => new Promise((resolve) => resolve()));
const mockUseConnectWallet = () => [{ wallet: {} }, mockConnectFn, mockDisconnectFn];

react.useConnectWallet = mockUseConnectWallet;
Expand Down
7 changes: 3 additions & 4 deletions vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "tslint -c tslint.json -p tsconfig.json --fix",
"lint": "tsc --noEmit && eslint --ext .ts,.js,.tsx .",
"test": "jest",
"prettier": "prettier --write ."
},
"dependencies": {
"@dpopp/types": "^0.0.1",
"@dpopp/identity": "^0.0.1",
"@dpopp/types": "^0.0.1",
"@ethersproject/providers": "^5.6.2",
"@walletconnect/web3-provider": "^1.7.7",
"@web3-onboard/core": "^2.1.0",
"@web3-onboard/injected-wallets": "^2.0.2",
Expand All @@ -31,7 +32,6 @@
"devDependencies": {
"@babel/preset-typescript": "^7.16.7",
"@emotion/react": "^11.8.2",
"@rollup/plugin-inject": "^4.0.4",
"@testing-library/jest-dom": "5.14.1",
"@testing-library/react": "12.0.0",
"@testing-library/user-event": "13.2.1",
Expand All @@ -52,7 +52,6 @@
"jest": "^27.5.1",
"postcss": "^8.4.12",
"prettier": "^2.6.1",
"rollup-plugin-polyfill-node": "^0.9.0",
"stream-browserify": "^3.0.0",
"tailwindcss": "^3.0.23",
"ts-jest": "^27.1.4",
Expand Down
Loading

0 comments on commit d034f23

Please sign in to comment.