Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ns.gs1.org becomes ref.gs1.org as defined in the standard #50

Merged
merged 16 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import * as epcis from 'epcis2.js';

Or use a simple script tag to load it from the CDN:
```html
<script src="https://cdn.jsdelivr.net/npm/epcis2.js@2.6.1/dist/epcis2.browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/epcis2.js@2.7.0/dist/epcis2.browser.js"></script>
```

Then use in a browser `script` tag using the `epcis2` global variable:
Expand Down Expand Up @@ -482,7 +482,7 @@ This feature is still experimental, please submit an [issue](https://github.com/
### Generating a hashed ID for an event

You have the possibility to generate a hashed ID for each event you create. The generation algorithm is a pure
implementation of the one defined [here](https://github.com/RalphTro/epcis-event-hash-generator).
implementation of the one defined [here](https://ref.gs1.org/standards/cbv/) (section 8.9.2).

Generating a hashed ID allows developers to uniquely identify an EPCIS event or validate the integrity thereof.

Expand Down
2 changes: 1 addition & 1 deletion example/web-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<title>EPCIS2.js demo</title>
<script src="https://cdn.jsdelivr.net/npm/epcis2.js@2.6.1/dist/epcis2.browser.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/epcis2.js@2.7.0/dist/epcis2.browser.js" defer></script>
<script>
window.onload = () => {
const doc = new epcis2.EPCISDocument();
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epcis2.js",
"version": "2.6.1",
"version": "2.7.0",
"description": "Javascript SDK for the EPCIS 2.0 standard",
"main": "./dist/epcis2.node.js",
"browser": "./dist/epcis2.browser.js",
Expand Down
36 changes: 18 additions & 18 deletions src/hash_generator/EPCISEventToPreHashedString.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
for (let i = 0; i < list.length; i += 1) {
res = list[i];
// if, for example, the field is equal to 'completeness_inferred' instead of
// 'https://ns.gs1.org/cbv/Disp-completeness_inferred' for example, we need to complete it
// 'https://ref.gs1.org/cbv/Disp-completeness_inferred' for example, we need to complete it
if (Object.values(cbv.dispositions).includes(res)) {
res = `https://ns.gs1.org/cbv/Disp-${res}`;
res = `https://ref.gs1.org/cbv/Disp-${res}`;
}
strings.push(getPreHashStringOfField('set', res, throwError));
}
Expand All @@ -223,9 +223,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
for (let i = 0; i < list.length; i += 1) {
res = list[i];
// if, for example, the field is equal to 'completeness_inferred' instead of
// 'https://ns.gs1.org/cbv/Disp-completeness_inferred' for example, we need to complete it
// 'https://ref.gs1.org/cbv/Disp-completeness_inferred' for example, we need to complete it
if (Object.values(cbv.dispositions).includes(res)) {
res = `https://ns.gs1.org/cbv/Disp-${res}`;
res = `https://ref.gs1.org/cbv/Disp-${res}`;
}
strings.push(getPreHashStringOfField('unset', res, throwError));
}
Expand Down Expand Up @@ -281,9 +281,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
case 'bizTransactionList':
for (let i = 0; i < list.length; i += 1) {
// if, for example, the field is equal to 'bol' instead of
// 'https://ns.gs1.org/cbv/BTT-bol', we need to complete it
// 'https://ref.gs1.org/cbv/BTT-bol', we need to complete it
if (Object.values(cbv.businessTransactionTypes).includes(list[i].type)) {
list[i].type = `https://ns.gs1.org/cbv/BTT-${list[i].type}`;
list[i].type = `https://ref.gs1.org/cbv/BTT-${list[i].type}`;
}
res = getOrderedPreHashString(
list[i],
Expand All @@ -298,9 +298,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
case 'sourceList':
for (let i = 0; i < list.length; i += 1) {
// if, for example, the field is equal to 'location' instead of
// 'https://ns.gs1.org/cbv/SDT-location', we need to complete it
// 'https://ref.gs1.org/cbv/SDT-location', we need to complete it
if (Object.values(cbv.sourceDestinationTypes).includes(list[i].type)) {
list[i].type = `https://ns.gs1.org/cbv/SDT-${list[i].type}`;
list[i].type = `https://ref.gs1.org/cbv/SDT-${list[i].type}`;
}
res = getOrderedPreHashString(list[i], context, sourceCanonicalPropertyOrder, throwError);
strings.push(res.preHashed);
Expand All @@ -310,9 +310,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
case 'destinationList':
for (let i = 0; i < list.length; i += 1) {
// if, for example, the field is equal to 'location' instead of
// 'https://ns.gs1.org/cbv/SDT-location', we need to complete it
// 'https://ref.gs1.org/cbv/SDT-location', we need to complete it
if (Object.values(cbv.sourceDestinationTypes).includes(list[i].type)) {
list[i].type = `https://ns.gs1.org/cbv/SDT-${list[i].type}`;
list[i].type = `https://ref.gs1.org/cbv/SDT-${list[i].type}`;
}
res = getOrderedPreHashString(
list[i],
Expand Down Expand Up @@ -340,9 +340,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
string = '';
for (let i = 0; i < list.length; i += 1) {
// if, for example, the field is equal to 'Temperature' instead of
// 'https://gs1.org/voc/MeasurementType-Temperature' we need to complete it
// 'https://gs1.org/voc/Temperature' we need to complete it
if (Object.values(cbv.sensorMeasurementTypes).includes(list[i].type)) {
list[i].type = `https://gs1.org/voc/MeasurementType-${list[i].type}`;
list[i].type = `https://gs1.org/voc/${list[i].type}`;
}

// if, for example, the field is equal to 'ALARM_CONDITION' instead of
Expand All @@ -352,9 +352,9 @@ export const preHashStringTheList = (list, context, fieldName, throwError) => {
}

// if, for example, the field is equal to 'x' instead of
// 'https://ns.gs1.org/cbv/Comp-x' we need to complete it
// 'https://ref.gs1.org/cbv/Comp-x' we need to complete it
if (Object.values(cbv.components).includes(list[i].component)) {
list[i].component = `https://ns.gs1.org/cbv/Comp-${list[i].component}`;
list[i].component = `https://ref.gs1.org/cbv/Comp-${list[i].component}`;
}

res = getOrderedPreHashString(
Expand Down Expand Up @@ -481,19 +481,19 @@ export const getOrderedPreHashString = (
case 'bizStep':
res = object[orderList[i]];
// if, for example, the field is equal to 'accepting' instead of
// 'https://ns.gs1.org/cbv/BizStep-accepting' for example, we need to complete it
// 'https://ref.gs1.org/cbv/BizStep-accepting' for example, we need to complete it
if (Object.values(cbv.bizSteps).includes(res)) {
res = `https://ns.gs1.org/cbv/BizStep-${res}`;
res = `https://ref.gs1.org/cbv/BizStep-${res}`;
}

string += getPreHashStringOfField(orderList[i], res, throwError);
break;
case 'disposition':
res = object[orderList[i]];
// if, for example, the field is equal to 'active' instead of
// 'https://ns.gs1.org/cbv/Disp-active', we need to complete it
// 'https://ref.gs1.org/cbv/Disp-active', we need to complete it
if (Object.values(cbv.dispositions).includes(res)) {
res = `https://ns.gs1.org/cbv/Disp-${res}`;
res = `https://ref.gs1.org/cbv/Disp-${res}`;
}

string += getPreHashStringOfField(orderList[i], res, throwError);
Expand Down
21 changes: 6 additions & 15 deletions src/hash_generator/canonicalPropertyOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const canonicalPropertyOrder = [
'type',
'eventTime',
'eventTimeZoneOffset',
'parentID',
'certificationInfo',
'epcList',
'parentID',
'inputEPCList',
'childEPCs',
'quantityList',
Expand All @@ -36,17 +37,6 @@ export const canonicalPropertyOrder = [
'ilmd',
];

/**
* This variable sets the order of Error Declaration fields that a pre-hashed string has to follow
* in order to comply with the used algorithm
* @type {string[]}
*/
export const errorDeclarationCanonicalPropertyOrder = [
'declarationTime',
'reason',
'correctiveEventIDs',
];

/**
* This variable sets the order of Quantity Element fields that a pre-hashed string has to follow
* in order to comply with the used algorithm
Expand All @@ -73,21 +63,21 @@ export const bizLocationCanonicalPropertyOrder = ['id'];
* order to comply with the used algorithm
* @type {string[]}
*/
export const bizTransactionCanonicalPropertyOrder = ['bizTransaction', 'type'];
export const bizTransactionCanonicalPropertyOrder = ['type', 'bizTransaction'];

/**
* This variable sets the order of Source fields that a pre-hashed string has to follow in order to
* comply with the used algorithm
* @type {string[]}
*/
export const sourceCanonicalPropertyOrder = ['source', 'type'];
export const sourceCanonicalPropertyOrder = ['type', 'source'];

/**
* This variable sets the order of Destination fields that a pre-hashed string has to follow in
* order to comply with the used algorithm
* @type {string[]}
*/
export const destinationCanonicalPropertyOrder = ['destination', 'type'];
export const destinationCanonicalPropertyOrder = ['type', 'destination'];

/**
* This variable sets the order of Sensor Element fields that a pre-hashed string has to follow in
Expand Down Expand Up @@ -140,6 +130,7 @@ export const sensorReportCanonicalPropertyOrder = [
'percRank',
'percValue',
'uom',
'coordinateReferenceSystem',
];

/**
Expand Down
4 changes: 2 additions & 2 deletions src/hash_generator/hashAlgorithmUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { normalizeDigitalLinks } from './dlNormalizer';
* The list of fields that will be ignored in the pre-hashed string
* @type {string[]}
*/
export const toBeIgnored = ['recordTime', 'eventID', 'errorDeclaration'];
export const toBeIgnored = ['recordTime', 'eventID', 'errorDeclaration', '@context'];

/**
* Check if the parameter is a string
Expand Down Expand Up @@ -68,7 +68,7 @@ export const isADate = (obj) => isNaN(obj) && !isNaN(Date.parse(obj)) && obj.len

/**
* If the UTC date passed in param contains a timezone, it removes it
* It useful for the rule n°8 of the algorithm
* It is useful for the rule n°8 of the algorithm
*
* @param {string} date - a string representing an UTC date
* @return {string} - the date without the timezone
Expand Down
2 changes: 0 additions & 2 deletions test/data/hashing/epcisDocWithCustomSchemaInContext.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"epcisBody": {
"eventList": [
{
"id": "_:event1",
"type": "ObjectEvent",
"action": "OBSERVE",
"bizStep": "shipping",
Expand All @@ -29,7 +28,6 @@
"example:myField": "myValue"
},
{
"id": "_:event2",
"type": "ObjectEvent",
"action": "OBSERVE",
"bizStep": "receiving",
Expand Down
2 changes: 0 additions & 2 deletions test/data/hashing/epcisDocWithDefaultSchemaInContext.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"epcisBody": {
"eventList": [
{
"id": "_:event1",
"type": "ObjectEvent",
"action": "OBSERVE",
"bizStep": "shipping",
Expand All @@ -25,7 +24,6 @@
]
},
{
"id": "_:event2",
"type": "ObjectEvent",
"action": "OBSERVE",
"bizStep": "receiving",
Expand Down
Loading