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

UPC-A

UPC-A (ISO/IEC 15420) of text: 11 digits, to which the check digit is added, or 12 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 12 digits. modules: 95, no quiet zones and no add-on, exactly the EAN-13 of 0 followed by the 12 digits: start guard 101; digits 1–6 in set A; centre guard 01010; digits 7–12 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-upca --lang rust
cd barcode-upca && 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-upca.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-upca.cases.json
[
  {
    "args": {
      "text": "03600029145"
    }
  },
  {
    "args": {
      "text": "036000291452"
    }
  },
  {
    "args": {
      "text": "07084700000"
    }
  },
  {
    "args": {
      "text": "885909950805"
    }
  },
  {
    "args": {
      "text": "01234567890"
    }
  },
  {
    "args": {
      "text": "036000291453"
    }
  },
  {
    "args": {
      "text": "12345678901"
    }
  },
  {
    "args": {
      "text": "00000000000"
    }
  },
  {
    "args": {
      "text": "000000000000"
    }
  },
  {
    "args": {
      "text": "99999999999"
    }
  },
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "1234567890a"
    }
  },
  {
    "args": {
      "text": "1234567890123"
    }
  }
]
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%.