Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
barcode / barcode-ean8OpenRuns on Liberas

EAN-8

EAN-8 (ISO/IEC 15420) of text: 7 digits, to which the check digit is added, or 8 digits whose last is the right check digit. Anything else (another character, another length, a wrong check digit) is an error. Check digit: weights 3, 1, 3, … from the rightmost data digit leftward, then (10 − sum mod 10) mod 10. text: the 8 digits. modules: 67, no quiet zones and no add-on: start guard 101; digits 1–4 in set A; centre guard 01010; digits 5–8 in set C; end guard 101. Set A codes 0–9: 0001101 0011001 0010011 0111101 0100011 0110001 0101111 0111011 0110111 0001011; set C is set A with every module inverted; set B is set C reversed.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init barcode-ean8 --lang rust
cd barcode-ean8 && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)21 lines›
barcode-ean8.wit
package root:component;

world root {
  import liberas:barcode/types@0.1.0;

  export liberas:barcode/linear-encode@0.1.0;
}
package liberas:barcode@0.1.0 {
  interface types {
    record linear {
      text: string,
      modules: string,
    }
  }
  interface linear-encode {
    use types.{linear};

    encode: func(text: string) -> result<linear, string>;
  }
}
Test vectors13›
barcode-ean8.cases.json
[
  {
    "args": {
      "text": "9638507"
    }
  },
  {
    "args": {
      "text": "96385074"
    }
  },
  {
    "args": {
      "text": "4002301"
    }
  },
  {
    "args": {
      "text": "1234567"
    }
  },
  {
    "args": {
      "text": "73513537"
    }
  },
  {
    "args": {
      "text": "96385075"
    }
  },
  {
    "args": {
      "text": "5512345"
    }
  },
  {
    "args": {
      "text": "0000000"
    }
  },
  {
    "args": {
      "text": "9999999"
    }
  },
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "123456"
    }
  },
  {
    "args": {
      "text": "x234567"
    }
  },
  {
    "args": {
      "text": "123456789"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 13 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.