openepcis / openepcis-event-hash-generator

Project to generate event hash for EPCIS document/event in XML/JSON-LD format.
https://openepcis.io
Apache License 2.0
6 stars 2 forks source link

Potential issues on the implementation of the algorithm #7

Closed clementh59 closed 1 year ago

clementh59 commented 1 year ago

Hi,

First of all, thanks a lot for you open source implementation. It is super useful. I tested your algorithm, and compared it to ours (https://github.com/evrythng/epcis2.js#generating-a-hashed-id-for-an-event)

I compared with this EPCIS document:

{
  "@context": "https://ref.gs1.org/standards/epcis/2.0.0/epcis-context.jsonld",

  "id": "_:document1",
  "type": "EPCISDocument",
  "schemaVersion": "2.0",
  "creationDate": "2005-07-11T11:30:47.0Z",
  "epcisBody": {
    "eventList": [
      {
        "type": "ObjectEvent",
        "action": "OBSERVE",
        "bizStep": "shipping",
        "disposition": "in_transit",
        "epcList": ["urn:epc:id:sgtin:0614141.107346.2017", "urn:epc:id:sgtin:0614141.107346.2018"],
        "eventTime": "2005-04-03T20:33:31.116000-06:00",
        "eventTimeZoneOffset": "-06:00",
        "readPoint": { "id": "urn:epc:id:sgln:0614141.07346.1234" },
        "bizTransactionList": [
          {
            "type": "po",
            "bizTransaction": "http://transaction.acme.com/po/12345678"
          }
        ]
      }
    ]
  }
}

The pre-hash string I got from your algorithm is:

eventType=ObjectEvent
eventTime=2005-04-04T02:33:31.116Z
eventTimeZoneOffset=-06:00
epcList
epc=https://id.gs1.org/01/10614141073464/21/2017
epc=https://id.gs1.org/01/10614141073464/21/2018
action=OBSERVE
bizStep=https://ref.gs1.org/voc/Bizstep-shipping
disposition=https://ref.gs1.org/voc/Disp-in_transit
readPoint
id=https://id.gs1.org/414/0614141073467/254/1234
bizTransactionList
bizTransaction=http://transaction.acme.com/po/12345678
type=https://ref.gs1.org/voc/BTT-po

Whereas I got this from ours:

eventType=ObjectEvent
eventTime=2005-04-04T02:33:31.116Ze
ventTimeZoneOffset=-06:00
epcList
epc=https://id.gs1.org/01/10614141073464/21/2017
epc=https://id.gs1.org/01/10614141073464/21/2018
action=OBSERVE
bizStep=https://ref.gs1.org/cbv/BizStep-shipping
disposition=https://ref.gs1.org/cbv/Disp-in_transit
readPoint
id=https://id.gs1.org/414/0614141073467/254/1234
bizTransactionList
type=https://ref.gs1.org/cbv/BTT-po
bizTransaction=http://transaction.acme.com/po/12345678

There are two differences:

  1. For the CBV URL, you use https://ref.gs1.org/voc/ whereas we use https://ref.gs1.org/cbv/. I think the second option is the correct path. Here is how it is defined in the CBV standard:

    If an EPCIS event is represented in JSON/JSON-LD, standard vocabulary elements are not expressed as URIs, but in bare string notation (i.e. 'in_transit' instead of 'https://ref.gs1.org/cbv/Disp-in_transit'). All standard vocabulary elements expressed in bare string notation SHALL be expanded to their corresponding GS1 Web URI (starting with 'https://ref.gs1.org/cbv').

  2. For bizTransactionLists, you put the bizTransaction first and then the type. However, here is what I got from the canonical order, defined in the standard:
    1. bizTransactionList – bizTransaction (business transaction type, business transaction ID) For most of the fields that has a type field, the latter should be first in the associated prehash string.

I hope this helps! :)

Regards,

Clément

Aravinda93 commented 1 year ago

@clementh59

Thanks a lot for trying our open-source tool and bringing the issue to our notice.

We just analysed the code and compared it with standard documentation and this is a bug in our code. This issue occurs because we were referencing the incorrect/outdated documentation during the development.

We are currently working on the fix and will update you as soon as it has been merged with the main branch.

clementh59 commented 1 year ago

Great, thanks a lot! I'll compare the implementations again once it is merged :)

Aravinda93 commented 1 year ago

@clementh59

The issue has been fixed now and the changes are available in main branch. Along with bizTransaction we have also changed the ordering for source and destination as per the standard..

Please validate the changes and let us know if you are still seeing any issues.

clementh59 commented 1 year ago

@Aravinda93 Thanks a lot,

The web tools (https://tools.openepcis.io/q/swagger-ui/#/Event%20Hash%20Generator/1 and https://tools.openepcis.io/openepcis-ui/EventHash/) don't seem to be updated. Which tool should I use to have the latest version?

sboeckelmann commented 1 year ago

The web tools (https://tools.openepcis.io/q/swagger-ui/#/Event%20Hash%20Generator/1 and https://tools.openepcis.io/openepcis-ui/EventHash/) don't seem to be updated. Which tool should I use to have the latest version?

the fix has only been integrated into this project's release build and can be tested with the command line client: https://github.com/openepcis/openepcis-event-hash-generator/tree/main/cli

@clementh59 @Aravinda93 I am currently rebuilding the service and ui wrapper that we are running on tools.openepcis.io and let you know once it has been deployed.

sboeckelmann commented 1 year ago

@clementh59 https://tools.openepcis.io was updated with the latest fixes.

You might also be interested in https://tools.openepcis.io/q/swagger-ui

clementh59 commented 1 year ago

Thanks!