github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/sigid/data/mkdata.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 h = {} # Sigs that start with 'h' are the new-style signatures (like >= 1.0.17) 20 g = [] # Sigs that start with 'g' are the legacy-style signatures (like < 1.0.16) 21 loop 22 await gets.gets esc defer line 23 break unless line? 24 [which, hash] = line.split /\s+/ 25 if which is 'g' 26 g.push hash 27 else 28 for prefix in prefix_split(hash) 29 h[prefix] = true 30 cb null, {g, h} 31 32 output : ({h, g}) -> 33 out = [] 34 out.push "package sigid" 35 out.push '' 36 covered = {} 37 @output_shorts { out, h, g, covered } 38 @output_3bytes { out, h, g, covered } 39 @output_words { out, h, g, covered } 40 out.join "\n" 41 42 output_shorts : ({out, h, g, covered}) -> 43 out.push "var legacyHashPrefixes16 = [...]uint16{" 44 output16 = {} 45 for hash in g when not(h[(prfx = hash[0...4])]) and not(covered[hash]) 46 if not(output16[prfx]) 47 out.push "\t" + hash_to_uint16(hash) + "," 48 covered[hash] = true 49 output16[prfx] = true 50 out.push "}" 51 52 output_3bytes : ({out, h, g, covered}) -> 53 out.push "var legacyHashPrefixes24 = [...]byte{" 54 output24 = {} 55 for hash in g when not(h[(prfx = hash[0...6])]) and not(covered[hash]) 56 if not(output24[prfx]) 57 out.push "\t" + hash_to_3bytes(hash).join(", ") + "," 58 covered[hash] = true 59 output24[prfx] = true 60 out.push "}" 61 62 output_words : ({out, h, g, covered}) -> 63 out.push "var legacyHashPrefixes32 = [...]uint32{" 64 output32 = {} 65 for hash in g when not(h[(prfx = hash[0...8])]) and not(covered[hash]) 66 if not(output32[prfx]) 67 out.push "\t" + hash_to_uint32(hash) + "," 68 covered[hash] = true 69 output32[prfx] = true 70 out.push "}" 71 72 run : ({input}, cb) -> 73 esc = make_esc cb, "run" 74 await @read { input }, esc defer {g,h} 75 out = @output { g,h } 76 console.log out 77 cb null 78 79 r = new Runner 80 await r.run { input : process.stdin }, defer err 81 rc = 0 82 if err? 83 console.err err.toString() 84 rc = -2 85 process.exit rc