Skip to content

Commit

Permalink
Merge pull request #498 from xpepermint/master
Browse files Browse the repository at this point in the history
Fix cert calculation bug
  • Loading branch information
xpepermint authored May 10, 2019
2 parents 0bd9977 + 1b8e669 commit 0ced126
Show file tree
Hide file tree
Showing 92 changed files with 827 additions and 359 deletions.
2 changes: 1 addition & 1 deletion INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ import { Cert } from '@0xcert/cert';

const cert = new Cert({ schema });
const imprints = await cert.notarize(data);
const imprints = await cert.disclose(exampleData, [ ...paths... ]);
const imprints = await cert.disclose(defaultData, [ ...paths... ]);
const imprint = await cert.calculate(data, imprints);
const imprint = await cert.imprint(data);
```
Expand Down
46 changes: 23 additions & 23 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"policyName": "patchAll",
"definitionName": "lockStepVersion",
"version": "1.5.0",
"version": "1.5.2",
"nextBump": "patch"
}
]
2 changes: 1 addition & 1 deletion dist/0xcert-cert.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/0xcert-ethereum.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/0xcert-wanchain.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/0xcert-cert/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"name": "@0xcert/cert",
"entries": [
{
"version": "1.5.2",
"tag": "@0xcert/cert_v1.5.2",
"date": "Fri, 10 May 2019 16:39:10 GMT",
"comments": {}
},
{
"version": "1.5.1",
"tag": "@0xcert/cert_v1.5.1",
"date": "Mon, 06 May 2019 16:02:11 GMT",
"comments": {}
},
{
"version": "1.5.0",
"tag": "@0xcert/cert_v1.5.0",
Expand Down
12 changes: 11 additions & 1 deletion packages/0xcert-cert/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Change Log - @0xcert/cert

This log was last generated on Fri, 03 May 2019 12:52:02 GMT and should not be manually modified.
This log was last generated on Fri, 10 May 2019 16:39:10 GMT and should not be manually modified.

## 1.5.2
Fri, 10 May 2019 16:39:10 GMT

*Version update only*

## 1.5.1
Mon, 06 May 2019 16:02:11 GMT

*Version update only*

## 1.5.0
Fri, 03 May 2019 12:52:02 GMT
Expand Down
8 changes: 4 additions & 4 deletions packages/0xcert-cert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xcert/cert",
"version": "1.5.0",
"version": "1.5.2",
"description": "Asset certification module for 0xcert Framework.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -72,8 +72,8 @@
"typescript": "^3.1.1"
},
"dependencies": {
"@0xcert/utils": "1.5.0",
"@0xcert/merkle": "1.5.0",
"@0xcert/conventions": "1.5.0"
"@0xcert/utils": "1.5.2",
"@0xcert/merkle": "1.5.2",
"@0xcert/conventions": "1.5.2"
}
}
7 changes: 5 additions & 2 deletions packages/0xcert-cert/src/core/cert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ export class Cert {
*/
protected buildSchemaProps(data: any, schema = this.schema, prepend = []): any {
if (schema.type === 'array') {
return (data || [])
const items = (data || [])
.map((v, i) => {
return this.buildSchemaProps(v, schema.items, [...prepend, i]);
})
.reduce((a, b) => a.concat(b), []);
return items.length > 0
? items
: [this.buildSchemaProps(undefined, {}, [...prepend])]; // add empty object to preserve keys sequence
} else if (schema.type === 'object') {
return Object.keys(schema.properties)
.sort()
Expand Down Expand Up @@ -260,7 +263,7 @@ export class Cert {
const dataIndex = this.getPathIndexes(prop.path).pop();
const recipeValue = recipe.values.find((v: any) => v.index === dataIndex);

if (typeof recipeValue === undefined) {
if (typeof recipeValue === 'undefined') {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Spec } from '@hayspec/spec';
import { Cert } from '../../../core/cert';
import { exampleData, exampleSchema } from '../helpers/schema';
import { defaultData, defaultSchema } from '../helpers/schemas';

const spec = new Spec();

spec.test('imprints complete data object', async (ctx) => {
const cert = new Cert({
schema: exampleSchema,
schema: defaultSchema,
});
const recipes = await cert.notarize(exampleData);
const imprint = await cert.calculate(exampleData, recipes);
const recipes = await cert.notarize(defaultData);
const imprint = await cert.calculate(defaultData, recipes);
ctx.is(imprint, '048c8f3384d5600792a4c8279d2c933fa43c26b81f2cab63462b72dd7488baad');
});

spec.test('validates selected paths', async (ctx) => {
const cert = new Cert({
schema: exampleSchema,
schema: defaultSchema,
});
const recipes = await cert.disclose(exampleData, [
const recipes = await cert.disclose(defaultData, [
['name'],
]);
const data = { name: 'B' };
Expand All @@ -27,9 +27,9 @@ spec.test('validates selected paths', async (ctx) => {

spec.test('validates selected nested paths', async (ctx) => {
const cert = new Cert({
schema: exampleSchema,
schema: defaultSchema,
});
const recipes = await cert.disclose(exampleData, [
const recipes = await cert.disclose(defaultData, [
['name'],
['books', 1, 'title'],
]);
Expand All @@ -43,9 +43,9 @@ spec.test('validates selected nested paths', async (ctx) => {

spec.test('fails when data includes more data then exposed', async (ctx) => {
const cert = new Cert({
schema: exampleSchema,
schema: defaultSchema,
});
const recipes = await cert.disclose(exampleData, [
const recipes = await cert.disclose(defaultData, [
['name'],
['books', 1, 'title'],
]);
Expand All @@ -59,9 +59,9 @@ spec.test('fails when data includes more data then exposed', async (ctx) => {

spec.test('pass on custom properties not defined by schema', async (ctx) => {
const cert = new Cert({
schema: exampleSchema,
schema: defaultSchema,
});
const recipes = await cert.disclose(exampleData, [
const recipes = await cert.disclose(defaultData, [
['name'],
]);
const data = {
Expand All @@ -72,4 +72,17 @@ spec.test('pass on custom properties not defined by schema', async (ctx) => {
ctx.is(imprint, '048c8f3384d5600792a4c8279d2c933fa43c26b81f2cab63462b72dd7488baad');
});

spec.test('pass on preliminary array and following object empty fields', async (ctx) => {
// Ref: https://github.com/0xcert/framework/issues/499
const cert = new Cert({
schema: defaultSchema,
});
const data = {
email: 'foo',
};
const recipes = await cert.notarize(data);
const imprint = await cert.calculate(data, recipes);
ctx.is(imprint, 'f5414c1036e8764d0ded2f3b33dd85bc511f080752a1d27eec17d647bdf7b62f');
});

export default spec;
Loading

0 comments on commit 0ced126

Please sign in to comment.