Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
validate / validate-imeiOpenRuns on Liberas

IMEI and IMEISV

Parses an IMEI or IMEISV (3GPP TS 23.003 section 6.2) on input as it is: ASCII digits only, no spaces, hyphens or slashes. 15 digits: an IMEI: tac (digits 1-8), serial (9-14) and check-digit (15); all 15 must pass the Luhn check (ISO/IEC 7812-1 Annex B: from the rightmost digit leftward, double every second digit starting with the second from the right, subtract 9 from doubles over 9; the sum is a multiple of 10), else checksum. 16 digits: an IMEISV, which has no check digit: tac (1-8), serial (9-14) and svn (15-16), any digits. Any other length (including a 14-digit IMEI without its check digit), any other character, and input over 65,536 bytes are format. The TAC is not checked against GSMA allocations.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init validate-imei --lang rust
cd validate-imei && 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)34 lines›
validate-imei.wit
package root:component;

world root {
  export liberas:validate/imei@0.1.0;
}
package liberas:validate@0.1.0 {
  interface imei {
    record imei-parts {
      tac: string,
      serial: string,
      check-digit: u8,
    }

    record imeisv-parts {
      tac: string,
      serial: string,
      svn: string,
    }

    enum imei-error {
      format,
      checksum,
    }

    variant imei-check {
      imei(imei-parts),
      imeisv(imeisv-parts),
      invalid(imei-error),
    }

    check: func(input: string) -> imei-check;
  }
}
Test vectors15›
validate-imei.cases.json
[
  {
    "args": {
      "input": "490154203237518"
    }
  },
  {
    "args": {
      "input": "356938035643809"
    }
  },
  {
    "args": {
      "input": "353879234252633"
    }
  },
  {
    "args": {
      "input": "000000000000000"
    }
  },
  {
    "args": {
      "input": "490154203237519"
    }
  },
  {
    "args": {
      "input": "356938035643808"
    }
  },
  {
    "args": {
      "input": "3569380356438091"
    }
  },
  {
    "args": {
      "input": "4901542032375100"
    }
  },
  {
    "args": {
      "input": "49015420323751"
    }
  },
  {
    "args": {
      "input": "49015420323751800"
    }
  },
  {
    "args": {
      "input": "35-209900-176148-1"
    }
  },
  {
    "args": {
      "input": "49015420323751X"
    }
  },
  {
    "args": {
      "input": " 490154203237518"
    }
  },
  {
    "args": {
      "input": ""
    }
  },
  {
    "args": {
      "input": "490154203237518"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 15 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%.