Skip to content

Commit 796859a

Browse files
committed
compatible with standard ts
1 parent 325b967 commit 796859a

File tree

20 files changed

+403
-186
lines changed

20 files changed

+403
-186
lines changed

.eslintrc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4-
"plugins": [
5-
"@typescript-eslint",
6-
"prettier"
7-
],
4+
"plugins": ["@typescript-eslint", "prettier"],
85
"extends": [
96
"eslint:recommended",
107
"plugin:@typescript-eslint/eslint-recommended",
@@ -15,4 +12,4 @@
1512
// "no-console": 1, // Means warning
1613
"prettier/prettier": 2 // Means error
1714
}
18-
}
15+
}

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"trailingComma": "none",
44
"singleQuote": true,
55
"printWidth": 80
6-
}
6+
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# MinAuth
2-
Rapid development of POC of MinAuth - MinAuth is a library and a set of tools for providing JWT-based authentication protocol that uses SnarkyJS zero-knowledge proofs as the basis of the authentication. It uses plugins to prove statements about external data such as on-chain data or 3rd-party data.
32

3+
Rapid development of POC of MinAuth - MinAuth is a library and a set of tools for providing JWT-based authentication protocol that uses SnarkyJS zero-knowledge proofs as the basis of the authentication. It uses plugins to prove statements about external data such as on-chain data or 3rd-party data.
44

55
### Current status
66

77
The current code implements minimal authentication flow that recreates the usual passport authentication, but using snarkyjs ZKPs.
88

9-
109
### Repository Structure
1110

1211
Currently the source code of the repository is structure like this:

nodemon.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
2-
"watch": [
3-
"src"
4-
],
5-
"ext": ".ts,.js",
6-
"ignore": [],
7-
"execMap": {
8-
"ts": "ts-node"
9-
},
10-
"env": {
11-
"TS_NODE_PROJECT": "tsconfig.json"
12-
}
2+
"watch": ["src"],
3+
"ext": ".ts,.js",
4+
"ignore": [],
5+
"execMap": {
6+
"ts": "ts-node"
7+
},
8+
"env": {
9+
"TS_NODE_PROJECT": "tsconfig.json"
10+
}
1311
}

package-lock.json

Lines changed: 103 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"nodemon": "^3.0.1",
5151
"prettier": "^3.0.3",
5252
"ts-node": "^10.9.1",
53+
"tsconfig-paths": "^4.2.0",
5354
"typescript": "^5.2.2"
5455
},
5556
"peerDependencies": {

src/library/plugin/pluginLoader.ts renamed to src/library/plugin/fp/pluginLoader.ts

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as path from 'path';
2-
import { IMinAuthPlugin, IMinAuthPluginFactory } from './pluginType';
2+
import {
3+
FpInterfaceType,
4+
IMinAuthPlugin,
5+
IMinAuthPluginFactory,
6+
TsInterfaceType,
7+
fpInterfaceTag,
8+
tsInterfaceTag
9+
} from './pluginType';
310
import * as R from 'fp-ts/Record';
411
import { pipe } from 'fp-ts/function';
512
import { TaskEither } from 'fp-ts/TaskEither';
@@ -12,10 +19,7 @@ import { z } from 'zod';
1219
import env from 'env-var';
1320
import { existsSync } from 'fs';
1421
import fs from 'fs/promises';
15-
import {
16-
fromFailablePromise,
17-
liftZodParseResult
18-
} from '../../utils/TaskEither';
22+
import { fromFailablePromise, liftZodParseResult } from '@utils/fp/TaskEither';
1923

2024
export const configurationSchema = z.object({
2125
pluginDir: z.string().optional(),
@@ -62,17 +66,29 @@ export const readConfiguration = _readConfiguration(
6266

6367
//
6468

65-
export type UntypedPlugin = IMinAuthPlugin<unknown, unknown>;
66-
67-
export type UntypedPluginFactory = IMinAuthPluginFactory<
68-
UntypedPlugin,
69-
unknown,
70-
unknown,
71-
unknown
72-
>;
69+
export interface UntypedPluginInstance
70+
extends IMinAuthPlugin<FpInterfaceType, unknown, unknown> {}
71+
72+
export type UntypedPluginFactory =
73+
| IMinAuthPluginFactory<
74+
IMinAuthPlugin<FpInterfaceType, unknown, unknown>,
75+
FpInterfaceType,
76+
unknown,
77+
unknown,
78+
unknown
79+
>
80+
| IMinAuthPluginFactory<
81+
IMinAuthPlugin<TsInterfaceType, unknown, unknown>,
82+
TsInterfaceType,
83+
unknown,
84+
unknown,
85+
unknown
86+
>;
7387

7488
export type UntypedPluginModule = { default: UntypedPluginFactory };
7589

90+
export type ActivePlugins = Record<string, UntypedPluginInstance>;
91+
7692
const importPluginModule = (
7793
pluginModulePath: string
7894
): TaskEither<string, UntypedPluginModule> =>
@@ -87,22 +103,45 @@ const validatePluginCfg = (
87103
const initializePlugin = (
88104
pluginModulePath: string,
89105
pluginCfg: unknown
90-
): TaskEither<string, UntypedPlugin> =>
106+
): TaskEither<string, UntypedPluginInstance> =>
91107
pipe(
92108
TE.Do,
93109
TE.bind('pluginModule', () => importPluginModule(pluginModulePath)),
94110
TE.let('pluginFactory', ({ pluginModule }) => pluginModule.default),
95111
TE.bind('typedPluginCfg', ({ pluginFactory }) =>
96112
validatePluginCfg(pluginCfg, pluginFactory)
97113
),
98-
TE.chain(({ pluginFactory, typedPluginCfg }) =>
99-
pluginFactory.initialize(typedPluginCfg)
114+
TE.chain(
115+
({
116+
pluginFactory,
117+
typedPluginCfg
118+
}): TaskEither<string, UntypedPluginInstance> =>
119+
pluginFactory.__interface_tag === fpInterfaceTag
120+
? pluginFactory.initialize(typedPluginCfg)
121+
: pluginFactory.__interface_tag === tsInterfaceTag
122+
? pipe(
123+
fromFailablePromise(() =>
124+
pluginFactory.initialize(typedPluginCfg)
125+
),
126+
TE.map(
127+
(obj): UntypedPluginInstance => ({
128+
__interface_tag: fpInterfaceTag,
129+
verifyAndGetOutput: (pia, sp) =>
130+
fromFailablePromise(() => obj.verifyAndGetOutput(pia, sp)),
131+
publicInputArgsSchema: obj.publicInputArgsSchema,
132+
customRoutes: obj.customRoutes,
133+
verificationKey: obj.verificationKey
134+
})
135+
)
136+
)
137+
: // TODO This check should be moved to `importPluginModule`
138+
TE.throwError('invalid plugin module')
100139
)
101140
);
102141

103142
export const initializePlugins = (
104143
cfg: Configuration
105-
): TaskEither<string, Record<string, UntypedPlugin>> => {
144+
): TaskEither<string, ActivePlugins> => {
106145
const resolvePluginModulePath =
107146
(name: string, optionalPath?: string) => () => {
108147
const dir =
@@ -121,7 +160,7 @@ export const initializePlugins = (
121160
path?: string | undefined;
122161
config?: unknown;
123162
}
124-
): TaskEither<string, UntypedPlugin> =>
163+
): TaskEither<string, UntypedPluginInstance> =>
125164
pipe(
126165
TE.fromIO(resolvePluginModulePath(pluginName, pluginCfg.path)),
127166
TE.chain((modulePath: string) =>

0 commit comments

Comments
 (0)