Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@identity.com/credential-commons

Package Overview
Dependencies
Maintainers
11
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@identity.com/credential-commons - npm Package Compare versions

Comparing version 2.0.0-beta.9 to 2.0.0-beta.10

2

dist/browser/schemas/jsonSchema/loaders/cvc.js

@@ -1,1 +0,1 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),fs=require("fs"),_require=require("../../../lib/stringUtils"),parseIdentifier=_require.parseIdentifier,_require2=require("../../../services"),services=_require2.services,rootUri="http://identity.com/schemas/",DEFAULT_SCHEMA_PATH="http://test-schemas.civic.com.s3-website-us-east-1.amazonaws.com",FSSchemaCache=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"./.tmp/schemas";(0,_classCallCheck2.default)(this,a),this.cachePath=b,fs.mkdirSync(b,{recursive:!0})}return(0,_createClass2.default)(a,[{key:"get",value:function(a){var b="".concat(this.cachePath,"/").concat(a,".schema.json");return fs.existsSync(b)?fs.readFileSync(b):null}},{key:"set",value:function(a,b){var c="".concat(this.cachePath,"/").concat(a,".schema.json");fs.writeFileSync(c,b)}}]),a}(),getIdentifierPath=function(a){var b;if(/^cvc:.*$/.test(a))b="uca/1/".concat(a);else{var c=parseIdentifier(a);c&&(b="".concat(c[1],"/").concat(c[4],"/").concat(c[2]))}return b},CVCLoader=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:services.container.Http,c=1<arguments.length?arguments[1]:void 0;(0,_classCallCheck2.default)(this,a),this.http=b,this.cache=void 0===c?new FSSchemaCache:null}return(0,_createClass2.default)(a,[{key:"schemaId",value:function(a){return rootUri+a}},{key:"valid",value:function(a){return /^(claim|credential|type)-(cvc|alt):.*$/.test(a)||/^cvc:.*$/.test(a)}},{key:"loadSchema",value:function(){var a=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function a(b){var c;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=null,this.cache&&(c=this.cache.get(b)),c){a.next=7;break}return a.next=5,this.remote(b);case 5:c=a.sent,this.cache&&c&&this.cache.set(b,c);case 7:return a.abrupt("return",c?JSON.parse(c):null);case 8:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}()},{key:"remote",value:function(){var a=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function a(b){var c,d,e;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=getIdentifierPath(b),c){a.next=3;break}return a.abrupt("return",null);case 3:return d="".concat(DEFAULT_SCHEMA_PATH,"/").concat(c,".schema.json"),e=null,a.prev=5,a.next=8,this.http.request(d);case 8:e=a.sent,a.next=21;break;case 11:if(a.prev=11,a.t0=a["catch"](5),!(!a.t0.statusCode||500<=a.t0.statusCode&&599>=a.t0.statusCode)){a.next=19;break}return a.next=16,services.container.Http.request(d);case 16:e=a.sent,a.next=21;break;case 19:if(!(400>a.t0.statusCode||500<=a.t0.statusCode)){a.next=21;break}throw a.t0;case 21:return a.abrupt("return",e);case 22:case"end":return a.stop();}},a,this,[[5,11]])}));return function(){return a.apply(this,arguments)}}()}]),a}();module.exports=CVCLoader;
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),fs=require("fs"),_require=require("../../../lib/stringUtils"),parseIdentifier=_require.parseIdentifier,_require2=require("../../../services"),services=_require2.services,rootUri="http://identity.com/schemas/",DEFAULT_SCHEMA_PATH="http://schemas.civic.com.s3-website-us-east-1.amazonaws.com/dev",FSSchemaCache=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"./.tmp/schemas";(0,_classCallCheck2.default)(this,a),this.cachePath=b,fs.mkdirSync(b,{recursive:!0})}return(0,_createClass2.default)(a,[{key:"get",value:function(a){var b="".concat(this.cachePath,"/").concat(a,".schema.json");return fs.existsSync(b)?fs.readFileSync(b):null}},{key:"set",value:function(a,b){var c="".concat(this.cachePath,"/").concat(a,".schema.json");fs.writeFileSync(c,b)}}]),a}(),getIdentifierPath=function(a){var b;if(/^cvc:.*$/.test(a))b="uca/1/".concat(a);else{var c=parseIdentifier(a);c&&(b="".concat(c[1],"/").concat(c[4],"/").concat(c[2]))}return b},CVCLoader=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:services.container.Http,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:new FSSchemaCache,d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:DEFAULT_SCHEMA_PATH;(0,_classCallCheck2.default)(this,a),this.http=b,this.cache=c,this.schemaPath=d}return(0,_createClass2.default)(a,[{key:"schemaId",value:function(a){return rootUri+a}},{key:"valid",value:function(a){return /^(claim|credential|type)-(cvc|alt):.*$/.test(a)||/^cvc:.*$/.test(a)}},{key:"loadSchema",value:function(){var a=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function a(b){var c;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=null,this.cache&&(c=this.cache.get(b)),c){a.next=7;break}return a.next=5,this.remote(b);case 5:c=a.sent,this.cache&&c&&this.cache.set(b,c);case 7:return a.abrupt("return",c?JSON.parse(c):null);case 8:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}()},{key:"remote",value:function(){var a=(0,_asyncToGenerator2.default)(_regenerator.default.mark(function a(b){var c,d,e;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c=getIdentifierPath(b),c){a.next=3;break}return a.abrupt("return",null);case 3:return d="".concat(this.schemaPath,"/").concat(c,".schema.json"),e=null,a.prev=5,a.next=8,this.http.request(d);case 8:e=a.sent,a.next=21;break;case 11:if(a.prev=11,a.t0=a["catch"](5),!(!a.t0.statusCode||500<=a.t0.statusCode&&599>=a.t0.statusCode)){a.next=19;break}return a.next=16,services.container.Http.request(d);case 16:e=a.sent,a.next=21;break;case 19:if(!(400>a.t0.statusCode||500<=a.t0.statusCode)){a.next=21;break}throw a.t0;case 21:return a.abrupt("return",e);case 22:case"end":return a.stop();}},a,this,[[5,11]])}));return function(){return a.apply(this,arguments)}}()}]),a}();module.exports=CVCLoader;

@@ -18,3 +18,3 @@ "use strict";

const rootUri = 'http://identity.com/schemas/';
const DEFAULT_SCHEMA_PATH = 'http://test-schemas.civic.com.s3-website-us-east-1.amazonaws.com';
const DEFAULT_SCHEMA_PATH = 'http://schemas.civic.com.s3-website-us-east-1.amazonaws.com/dev';

@@ -67,5 +67,6 @@ class FSSchemaCache {

class CVCLoader {
constructor(http = services.container.Http, cache) {
constructor(http = services.container.Http, cache = new FSSchemaCache(), schemaPath = DEFAULT_SCHEMA_PATH) {
this.http = http;
this.cache = cache === undefined ? new FSSchemaCache() : null;
this.cache = cache;
this.schemaPath = schemaPath;
}

@@ -134,3 +135,3 @@ /**

const uri = `${DEFAULT_SCHEMA_PATH}/${identifierPath}.schema.json`;
const uri = `${_this2.schemaPath}/${identifierPath}.schema.json`;
let response = null;

@@ -137,0 +138,0 @@

@@ -12,3 +12,3 @@ const fs = require('fs');

const rootUri = 'http://identity.com/schemas/';
const DEFAULT_SCHEMA_PATH = 'http://test-schemas.civic.com.s3-website-us-east-1.amazonaws.com';
const DEFAULT_SCHEMA_PATH = 'http://schemas.civic.com.s3-website-us-east-1.amazonaws.com/dev';

@@ -61,5 +61,6 @@ class FSSchemaCache {

class CVCLoader {
constructor(http = services.container.Http, cache) {
constructor(http = services.container.Http, cache = new FSSchemaCache(), schemaPath = DEFAULT_SCHEMA_PATH) {
this.http = http;
this.cache = cache === undefined ? new FSSchemaCache() : null;
this.cache = cache;
this.schemaPath = schemaPath;
}

@@ -121,3 +122,3 @@ /**

const uri = `${DEFAULT_SCHEMA_PATH}/${identifierPath}.schema.json`;
const uri = `${this.schemaPath}/${identifierPath}.schema.json`;
let response = null;

@@ -124,0 +125,0 @@

{
"name": "@identity.com/credential-commons",
"version": "2.0.0-beta.9",
"version": "2.0.0-beta.10",
"author": "Identity.com Community",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -75,5 +75,3 @@ # Identity.com Verifiable Credential Library

- `npm run test:watch` - run all tests in watch mode
- `npm run generate-schema` - run the CLI command and generate all schemas
## Configuration

@@ -125,23 +123,11 @@

#### Defining new Claim
Just add a new definition entry with the [format](http://) on the definitions [file](http://)
#### Exporting Claim to the Claim Registry Services
Claim definitions are packed inside this library but also are available for public consumption at the [Claim Registry](http://) to export new defined Claims just run:
```
npm run export-definitions
```
#### Using a Claim in javascript (with this library)
##### creating Claim instances with the constructor
##### creating Claim instances with the async `create` function
`Claim(identifier, value, version)`
`Claim.create(identifier, value)`
Example
```
const name = new Claim('claim-cvc:Identity.address-v1', {
const name = await Claim.create('claim-cvc:Identity.address-v1', {
street: 'Alameda dos Anjos',

@@ -154,14 +140,2 @@ unit: '102',

country: 'Brazil',
}, '1');
```
Or use the shorthand
```
const name = new Claim.IdentityAddress({
street: 'Alameda dos Anjos',
unit: '102',
city: 'Belo Horizonte',
zipCode: '94103345',
state: 'Minas Gerais',
county: 'Sao Bento',
country: 'Brazil',
});

@@ -343,10 +317,2 @@ ```

#### Exporting Claim to the Claim Registry Services
Credentials definitions are packed inside this library but also are available for public consumption at the [Credential Registry](http://) to export new defined Credentials
```
npm run export-definitions
```
#### Using a VerifiableCredential in javascript (with this library)

@@ -358,5 +324,5 @@

```
const name = new Claim.IdentityName({ first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = new Claim.IdentityDateOfBirth({ day: 20, month: 3, year: 1978 });
const cred = new VC('cvc:cred:Test', 'jest:test', null, [name, dob]);
const name = await Claim.create('claim-cvc:Identity.name-v1', { first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('cvc:cred:Test', 'jest:test', null, [name, dob]);
```

@@ -370,4 +336,4 @@

```
const name = new Claim.IdentityName({ first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = new Claim.IdentityDateOfBirth({ day: 20, month: 3, year: 1978 });
const name = await Claim.create('claim-cvc:Identity.name-v1', { first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const evidence = {

@@ -382,3 +348,3 @@ id: 'https://idv.civic.com/evidence/f2aeec97-fc0d-42bf-8ca7-0548192dxyzab',

const cred = new VC('cvc:cred:Test', 'jest:test', null, [name, dob], '1', evidence);
const cred = await VC.create('cvc:cred:Test', 'jest:test', null, [name, dob], '1', evidence);
```

@@ -389,5 +355,5 @@

```
const name = new Claim.IdentityName({ first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = new Claim.IdentityDateOfBirth({ day: 20, month: 3, year: 1978 });
const cred = new VC('cvc:cred:Test', 'jest:test', [name, dob]);
const name = await Claim.create('claim-cvc:Identity.name-v1', { first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('cvc:cred:Test', 'jest:test', [name, dob]);
cred.requestAnchor().then(() => {

@@ -401,5 +367,5 @@ //The original instance is updated

```
const name = new Claim.IdentityName({ first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = new Claim.IdentityDateOfBirth({ day: 20, month: 3, year: 1978 });
const cred = new VC('cvc:cred:Test', 'jest:test', [name, dob]);
const name = await Claim.create('claim-cvc:Identity.name-v1', { first: 'Joao', middle: 'Barbosa', last: 'Santos' });
const dob = await Claim.create('claim-cvc:Identity.dateOfBirth-v1', { day: 20, month: 3, year: 1978 });
const cred = await VC.create('cvc:cred:Test', 'jest:test', [name, dob]);
cred.updateAnchor().then(() => {

@@ -418,3 +384,3 @@ //The original instance is updated

##### Grating
##### Granting
```js

@@ -588,3 +554,3 @@ cred.grantUsageFor(requestorId, requestId)

const credJSon = require('./ACred.json');
const cred = VC.fromJSON(credJSon);
const cred = await VC.fromJSON(credJSon);
```

@@ -600,3 +566,3 @@ Now you can access any method of a `cred` instance, like `.updateAnchor()` or `.verify()`

const credJSon = require('./ACred.json');
const cred = VC.fromJSON(credJSon);
const cred = await VC.fromJSON(credJSon);
const verifiedLevel = cred.verify();

@@ -617,64 +583,28 @@ ```

## Schema Generator
## Loading schemas
The json schema generator will get a previous definition and build a sample JSON (with random values).
Schema's can be loaded by providing a schema loader as follows:
On top of the sample data and combining the identifier properties it will infer an JSON Schema for validating the data.
A identifier like this:
Example
```javascript
const name = new Claim('claim-cvc:Identity.name-v1', {
first: 'Joao',
middle: 'Barbosa',
last: 'Santos'
})
const { schemaLoader } = require('@identity/credential-commons');
schemaLoader.addLoader(new SchemaLoader())
```
Will generate a JSON like this:
```
{
first: 'Joao',
middle: 'Barbosa',
last: 'Santos'
The provided SchemaLoader needs to confirm to the following interface:
```javascript
interface SchemaLoader {
// Returns a boolean if the schema loader can load the supplied identitifier (in the case of multiple loaders)
valid(identifier);
// Returns the schema id for the provided identifier (e.g. http://identity.com/schemas/claim-cvc:Identity.address-v1)
schemaId(identifier);
// Load the schema based on the provided identifier and returns the schema as an object
async loadSchema(identifier)
}
```
The schema generator will generate an json schema like this:
A default schema loaded is provided [here](/src/schemas/jsonSchema/loaders/cvc.js)
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "claim-cvc:Identity.name-v1.first",
"type": "object",
"properties": {
"first": {
"type": "string"
}
},
"required": [
"first"
],
"additionalProperties": false
}
```
## Publishing schemas
The Verifiable Credential Library has a script, avaiable in the *package.json*, to publish the generate schemas to a bucket in AWS. The following command will publish the schemas:
```bash
S3_BUCKET_SCHEMA_URL=<s3://your-bucket-url> npm run publish-schemas
```
There is also a script to check the published schemas:
```bash
S3_PUBLIC_SCHEMA_URL=<http://your-schem-url> npm run check-schemas
```
To publish and check the schemas it is required to have the environment variables for AWS credentials defined (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).
## Conventions:

@@ -681,0 +611,0 @@

@@ -6,3 +6,3 @@ const fs = require('fs');

const rootUri = 'http://identity.com/schemas/';
const DEFAULT_SCHEMA_PATH = 'http://test-schemas.civic.com.s3-website-us-east-1.amazonaws.com';
const DEFAULT_SCHEMA_PATH = 'http://schemas.civic.com.s3-website-us-east-1.amazonaws.com/dev';

@@ -51,5 +51,6 @@ class FSSchemaCache {

class CVCLoader {
constructor(http = services.container.Http, cache) {
constructor(http = services.container.Http, cache = new FSSchemaCache(), schemaPath = DEFAULT_SCHEMA_PATH) {
this.http = http;
this.cache = cache === undefined ? new FSSchemaCache() : null;
this.cache = cache;
this.schemaPath = schemaPath;
}

@@ -106,3 +107,3 @@

const uri = `${DEFAULT_SCHEMA_PATH}/${identifierPath}.schema.json`;
const uri = `${this.schemaPath}/${identifierPath}.schema.json`;

@@ -109,0 +110,0 @@ let response = null;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc