File size: 1,383 Bytes
518343a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
 * @szl-holdings/a11oy-qec-integrity
 *
 * QEC-derived receipt integrity primitives for the a11oy governance fabric.
 *
 * v17 grafts (see Lutar/QEC/ in szl-holdings/lutar-lean):
 *   • Hamming distance / weight over byte-arrays (Hamming 1950).
 *   • Shor [[9,1,3]] 9-fold receipt replication (Shor 1995).
 *   • CSS classical-to-stabilizer bridge (Calderbank-Shor-Steane 1996).
 *   • Kitaev surface-code vertex parity (Kitaev 1997 / 2003).
 *
 * Doctrine v6 clean.
 */

export {
  hammingDist,
  hammingWeight,
  hammingDistByte,
  minDistance,
  shorEncode,
  shorMajorityPayload,
  classicalToCSS,
  cssConsistent,
  vertexParity,
  singleSiteError,
  allErrors,
  noErrors,
} from './qec_lineage';

export type {
  PhysicalReceipt,
  StabilizerPair,
  Site,
  VertexCheck,
} from './qec_lineage';

/**
 * Helper specific to a11oy: compute receipt-integrity Hamming weight for
 * detection of doctrine corruption.  Returns the number of differing
 * bytes between a candidate receipt and the canonical one, byte-by-byte.
 */
export function receiptHammingWeight(
  candidate: Uint8Array,
  canonical: Uint8Array,
): number {
  if (candidate.length !== canonical.length) {
    throw new Error('receiptHammingWeight: length mismatch');
  }
  let w = 0;
  for (let i = 0; i < candidate.length; i += 1) {
    if (candidate[i] !== canonical[i]) w += 1;
  }
  return w;
}