github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/sigid/data/mktest.iced (about)

     1  {Gets} = require('iced-utils')
     2  {make_esc} = require 'iced-error'
     3  
     4  hash_to_uint32 = (h) -> "0x" + h[0...8]
     5  hash_to_3bytes = (h) -> ( "0x#{h[i...(i+2)]}" for i in [0...6] by 2)
     6  hash_to_uint16 = (h) -> "0x" + h[0...4]
     7  
     8  # "abcdef1234" => ["abcd", "abcdef", "abcdef12" ]
     9  prefix_split = (h) -> (h[0...i] for i in [4..8] by 2)
    10  
    11  class Runner
    12  
    13    constructor : () ->
    14      map = []
    15  
    16    read : ({input}, cb) ->
    17      esc = make_esc cb, "read"
    18      gets = (new Gets input).run()
    19      sig_ids = []
    20      loop
    21        await gets.gets esc defer line
    22        break unless line?
    23        [which, hash] = line.split /\s+/
    24        sig_ids.push [hash, (which is 'h')]
    25      cb null, sig_ids
    26  
    27    output : ({sig_ids}) ->
    28      out = []
    29      out.push "package sigid"
    30      out.push ''
    31      @output_test_vectors { out, sig_ids }
    32      out.join "\n"
    33  
    34    output_test_vectors : ({out, sig_ids}) ->
    35      out.push "var testVectors = []struct{"
    36      out.push "\tsigID string"
    37      out.push "\tisModern bool"
    38      out.push "}{"
    39      for [sig_id, isModern] in sig_ids
    40        out.push """\t{"#{sig_id}",#{isModern}},"""
    41      out.push "}"
    42  
    43    run : ({input}, cb) ->
    44      esc = make_esc cb, "run"
    45      await @read { input }, esc defer sig_ids
    46      out = @output { sig_ids }
    47      console.log out
    48      cb null
    49  
    50  r = new Runner
    51  await r.run { input : process.stdin }, defer err
    52  rc = 0
    53  if err?
    54    console.err err.toString()
    55    rc = -2
    56  process.exit rc