Skip to content

Commit

Permalink
added commen interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed May 1, 2021
1 parent c35be5e commit d9ff198
Show file tree
Hide file tree
Showing 6 changed files with 4,551 additions and 8 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "provotum-ssi-utils",
"version": "1.0.0",
"version": "1.0.2",
"description": "SSI relevant functionality for Provotum",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -40,5 +40,8 @@
},
"files": [
"lib/**/*"
]
],
"dependencies": {
"@veramo/selective-disclosure": "^1.2.0"
}
}
23 changes: 23 additions & 0 deletions src/__tests__/Expression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// import Expression from '../index';

test('Dummy test', () => {
expect(0).toBe(0);
});

// test('Text with substring', () => {
// expect(new Expression("'${VALUE}'.includes('${ARG_1}')", 'Zurich', ['ich']).evaluate()).toBe(true);
// });

// test('String part of array', () => {
// expect(new Expression("${ARG_1}.includes('${VALUE}')", 'Zürich', ["['Zürich', 'Flims', 'Luzern']"]).evaluate()).toBe(
// true,
// );
// });

// test('Number with <= operator', () => {
// expect(new Expression('${VALUE} <= ${ARG_1}', '1', ['2']).evaluate()).toBe(true);
// });

// test('Number with multiple arguments', () => {
// expect(new Expression('${VALUE} <= ${ARG_1} && ${VALUE} <= ${ARG_2}', '1', ['2', '1']).evaluate()).toBe(true);
// });
4 changes: 0 additions & 4 deletions src/__tests__/Greeter.test.ts

This file was deleted.

115 changes: 114 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,114 @@
export const Greeter = (name: string) => `Hello ${name}`;
import { ICredentialRequestInput } from '@veramo/selective-disclosure';

/**
* Interface that captures the DAG architecture of JSON-LD documents.
*/
export interface ISchemaNode {
key: string;
name?: string;
url?: string;
children?: ISchemaNode[];
dataType?: DataType;
}

/**
* Data types that are used in the claim context.
*/
export type DataType = 'NUMBER' | 'DATE' | 'BOOLEAN' | 'TEXT';

/**
* Schemas that create a common context among different parties.
* Used to quickly bootstrap verifiable credentials, presentations and selective disclosure requests.
* TODO: add additional schemas from schema.org and others.
*/
export const schemas: [ISchemaNode] = [
{
key: 'https://schema.org',
children: [
{
key: 'Person',
url: 'https://schema.org/Person',
children: [
{
key: 'birthDate',
url: 'https://schema.org/birthDate',
dataType: 'DATE',
},
{
key: 'PostalAddress',
url: 'https://schema.org/Person',
children: [
{
key: 'postalCode',
url: 'https://schema.org/postalCode',
dataType: 'TEXT',
},
],
},
],
},
{
key: 'Ticket',
url: 'https://schema.org/Ticket',
children: [
{
key: 'dateIssued',
url: 'https://schema.org/dateIssued',
dataType: 'DATE',
},
{
key: 'ticketNumber',
url: 'https://schema.org/ticketNumber',
dataType: 'TEXT',
},
{
key: 'totalPrice',
url: 'https://schema.org/totalPrice',
dataType: 'NUMBER',
},
],
},
{
key: 'VoteAction',
url: 'https://schema.org/VoteAction',
children: [
{
key: 'name',
url: 'https://schema.org/name',
dataType: 'TEXT',
},
],
},
{
key: 'Place',
url: 'https://schema.org/Place',
children: [
{
key: 'publicAccess',
url: 'https://schema.org/publicAccess',
dataType: 'BOOLEAN',
},
],
},
],
},
];

/**
* Interface that captures a constraint configuration.
* The `js` string is a JS expression that can be evaluated with `eval()`.
*/
export interface IConstraint {
js: string;
desc: string;
}

/**
* Interface that captures a combination of a claim and a constraint.
* The claim is used to create selective disclouse requets in the authentication process. (ex. reveal your brithDate)
* The constraint is used to evaluate the value that is revealed in the authentication process. (ex. is your birthDay before some date)
*/
export interface IClaimConstraintConfig {
claim: ICredentialRequestInput;
constraint: IConstraint;
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"strict": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
"exclude": ["node_modules", "**/__tests__/*"],
"no-eval": false
}
Loading

0 comments on commit d9ff198

Please sign in to comment.