{"version":3,"file":"ics23-verify.cjs","names":["compareBytes","leftKey: Uint8Array | null","rightKey: Uint8Array | null","applyLeaf","applyInner","doHashOrNoop","getPadding","hasPadding","getPosition"],"sources":["../../src/proof/ics23-verify.ts"],"sourcesContent":["/**\n * ICS23 Proof Verification\n * Implements verification logic for ICS23 existence and non-existence proofs\n * Based on Go ics23 v0.10.0 proof.go and ics23.go\n */\n\nimport type {\n  CommitmentProof,\n  ExistenceProof,\n  InnerOp,\n  InnerSpec,\n  NonExistenceProof,\n  ProofSpec,\n} from \"../generated/cosmos/ics23/v1/proofs.js\";\nimport {\n  compareBytes,\n} from \"../utils/bytes.js\";\nimport {\n  applyInner,\n  applyLeaf,\n  checkInnerOp,\n  checkLeafOp,\n  getPadding,\n  hasPadding,\n} from \"./ics23-ops.js\";\n\n/** Commitment root is the merkle root hash */\nexport type CommitmentRoot = Uint8Array;\n\n/**\n * Verify membership proof\n * Returns true iff proof contains valid ExistenceProof for key/value that hashes to root\n * Based on Go ics23 VerifyMembership (ics23.go lines 33-45)\n */\nexport function verifyMembership(\n  spec: ProofSpec,\n  root: CommitmentRoot,\n  proof: CommitmentProof,\n  key: Uint8Array,\n  value: Uint8Array,\n): boolean {\n  // Get existence proof for key\n  const ep = getExistProofForKey(proof, key);\n  if (!ep) {\n    return false;\n  }\n\n  // Verify the existence proof\n  try {\n    verifyExistenceProof(ep, spec, root, key, value);\n    return true;\n  }\n  catch {\n    return false;\n  }\n}\n\n/**\n * Verify non-membership proof\n * Returns true iff proof contains valid NonExistenceProof that key is not in tree\n * Based on Go ics23 VerifyNonMembership (ics23.go lines 47-61)\n */\nexport function verifyNonMembership(\n  spec: ProofSpec,\n  root: CommitmentRoot,\n  proof: CommitmentProof,\n  key: Uint8Array,\n): boolean {\n  // Get non-existence proof for key\n  const np = getNonExistProofForKey(spec, proof, key);\n  if (!np) {\n    return false;\n  }\n\n  // Verify the non-existence proof\n  try {\n    verifyNonExistenceProof(np, spec, root, key);\n    return true;\n  }\n  catch {\n    return false;\n  }\n}\n\n/**\n * Verify ExistenceProof\n * Checks proof structure, key/value match, and root calculation\n * Based on Go ics23 ExistenceProof.Verify (proof.go lines 110-131)\n */\nexport function verifyExistenceProof(\n  proof: ExistenceProof,\n  spec: ProofSpec,\n  root: CommitmentRoot,\n  key: Uint8Array,\n  value: Uint8Array,\n): void {\n  // Check proof against spec\n  checkExistenceProof(proof, spec);\n\n  // Verify key matches\n  if (compareBytes(key, proof.key) !== 0) {\n    throw new Error(\"provided key doesn't match proof\");\n  }\n\n  // Verify value matches\n  if (compareBytes(value, proof.value) !== 0) {\n    throw new Error(\"provided value doesn't match proof\");\n  }\n\n  // Calculate root from proof\n  const calc = calculateExistenceRoot(proof);\n\n  // Verify calculated root matches provided root\n  if (compareBytes(root, calc) !== 0) {\n    throw new Error(\"calculated root doesn't match provided root\");\n  }\n}\n\n/**\n * Verify NonExistenceProof\n * Checks neighbor proofs are valid and bracket the key\n * Based on Go ics23 NonExistenceProof.Verify (proof.go lines 219-271)\n */\nexport function verifyNonExistenceProof(\n  proof: NonExistenceProof,\n  spec: ProofSpec,\n  root: CommitmentRoot,\n  key: Uint8Array,\n): void {\n  let leftKey: Uint8Array | null = null;\n  let rightKey: Uint8Array | null = null;\n\n  // Verify left proof if present\n  if (proof.left) {\n    verifyExistenceProof(proof.left, spec, root, proof.left.key, proof.left.value);\n    leftKey = proof.left.key;\n  }\n\n  // Verify right proof if present\n  if (proof.right) {\n    verifyExistenceProof(\n      proof.right,\n      spec,\n      root,\n      proof.right.key,\n      proof.right.value,\n    );\n    rightKey = proof.right.key;\n  }\n\n  // At least one proof must be present\n  if (!leftKey && !rightKey) {\n    throw new Error(\"both left and right proofs missing\");\n  }\n\n  // Verify key is in valid range\n  if (rightKey) {\n    const keyComp = keyForComparison(spec, key);\n    const rightKeyComp = keyForComparison(spec, rightKey);\n    if (compareBytes(keyComp, rightKeyComp) >= 0) {\n      throw new Error(\"key is not left of right proof\");\n    }\n  }\n\n  if (leftKey) {\n    const keyComp = keyForComparison(spec, key);\n    const leftKeyComp = keyForComparison(spec, leftKey);\n    if (compareBytes(keyComp, leftKeyComp) <= 0) {\n      throw new Error(\"key is not right of left proof\");\n    }\n  }\n\n  // Verify neighbor relationship\n  if (!leftKey) {\n    // Left proof missing, right must be leftmost\n    if (proof.right && !isLeftMost(spec.innerSpec!, proof.right.path)) {\n      throw new Error(\"left proof missing, right proof must be left-most\");\n    }\n  }\n  else if (!rightKey) {\n    // Right proof missing, left must be rightmost\n    if (proof.left && !isRightMost(spec.innerSpec!, proof.left.path)) {\n      throw new Error(\"right proof missing, left proof must be right-most\");\n    }\n  }\n  else {\n    // Both present, must be neighbors\n    if (proof.left\n      && proof.right\n      && !isLeftNeighbor(spec.innerSpec!, proof.left.path, proof.right.path)) {\n      throw new Error(\"left and right proofs are not neighbors\");\n    }\n  }\n}\n\n/**\n * Check ExistenceProof structure against spec\n * Based on Go ics23 ExistenceProof.CheckAgainstSpec (proof.go lines 182-206)\n */\nexport function checkExistenceProof(\n  proof: ExistenceProof,\n  spec: ProofSpec,\n): void {\n  if (!proof.leaf) {\n    throw new Error(\"existence Proof needs defined LeafOp\");\n  }\n\n  // Check leaf op\n  checkLeafOp(proof.leaf, spec);\n\n  // Check depth constraints\n  if (spec.minDepth > 0 && proof.path.length < spec.minDepth) {\n    throw new Error(`innerOps depth too short: ${proof.path.length}`);\n  }\n  if (spec.maxDepth > 0 && proof.path.length > spec.maxDepth) {\n    throw new Error(`innerOps depth too long: ${proof.path.length}`);\n  }\n\n  // Check each inner op\n  let layerNum = 1;\n  for (const inner of proof.path) {\n    checkInnerOp(inner, spec, layerNum);\n    layerNum += 1;\n  }\n}\n\n/**\n * Calculate root hash from ExistenceProof\n * Based on Go ics23 ExistenceProof.calculate (proof.go lines 140-164)\n */\nexport function calculateExistenceRoot(\n  proof: ExistenceProof,\n): CommitmentRoot {\n  if (!proof.leaf) {\n    throw new Error(\"existence Proof needs defined LeafOp\");\n  }\n\n  // Apply leaf op to get leaf hash\n  let res = applyLeaf(proof.leaf, proof.key, proof.value);\n\n  // Apply each inner op in sequence\n  for (const step of proof.path) {\n    res = applyInner(step, res);\n  }\n\n  return res;\n}\n\n/**\n * Get key for comparison (prehash if spec requires it)\n * Based on Go ics23 keyForComparison (proof.go lines 208-217)\n */\nfunction keyForComparison(spec: ProofSpec, key: Uint8Array): Uint8Array {\n  if (!spec.prehashKeyBeforeComparison) {\n    return key;\n  }\n\n  const prehashKey = spec.leafSpec?.prehashKey ?? 0;\n  if (prehashKey === 0) {\n    // NO_HASH\n    return key;\n  }\n\n  // Hash the key\n  return doHashOrNoop(prehashKey, key);\n}\n\n// Import doHashOrNoop from ops\nimport {\n  doHashOrNoop,\n} from \"./ics23-ops.js\";\n\n/**\n * Check if path is leftmost (all steps go left)\n * Based on Go ics23 IsLeftMost (proof.go lines 273-284)\n */\nfunction isLeftMost(spec: InnerSpec, path: InnerOp[]): boolean {\n  const {\n    minPrefix, maxPrefix, suffix,\n  } = getPadding(spec, 0);\n\n  // Every step must have expected padding for leftmost\n  for (const step of path) {\n    if (!hasPadding(step, minPrefix, maxPrefix, suffix)\n      && !leftBranchesAreEmpty(spec, step)) {\n      return false;\n    }\n  }\n  return true;\n}\n\n/**\n * Check if path is rightmost (all steps go right)\n * Based on Go ics23 IsRightMost (proof.go lines 286-298)\n */\nfunction isRightMost(spec: InnerSpec, path: InnerOp[]): boolean {\n  const last = spec.childOrder.length - 1;\n  const {\n    minPrefix, maxPrefix, suffix,\n  } = getPadding(spec, last);\n\n  // Every step must have expected padding for rightmost\n  for (const step of path) {\n    if (!hasPadding(step, minPrefix, maxPrefix, suffix)\n      && !rightBranchesAreEmpty(spec, step)) {\n      return false;\n    }\n  }\n  return true;\n}\n\n/**\n * Check if left and right are adjacent paths\n * Based on Go ics23 IsLeftNeighbor (proof.go lines 300-330)\n */\nfunction isLeftNeighbor(\n  spec: InnerSpec,\n  left: InnerOp[],\n  right: InnerOp[],\n): boolean {\n  // Find common suffix (from end, near root)\n  const leftPath = [...left];\n  const rightPath = [...right];\n\n  if (leftPath.length === 0 || rightPath.length === 0) {\n    return false;\n  }\n\n  // Remove common tail\n  while (leftPath.length > 0 && rightPath.length > 0) {\n    const leftTop = leftPath[leftPath.length - 1];\n    const rightTop = rightPath[rightPath.length - 1];\n\n    if (!bytesEqual(leftTop.prefix, rightTop.prefix)\n      || !bytesEqual(leftTop.suffix, rightTop.suffix)) {\n      break;\n    }\n\n    leftPath.pop();\n    rightPath.pop();\n  }\n\n  if (leftPath.length === 0 || rightPath.length === 0) {\n    return false;\n  }\n\n  // Get first divergent nodes\n  const topLeft = leftPath[leftPath.length - 1];\n  const topRight = rightPath[rightPath.length - 1];\n\n  // Check they are left and right of each other\n  if (!isLeftStep(spec, topLeft, topRight)) {\n    return false;\n  }\n\n  // Remove the divergent nodes\n  leftPath.pop();\n  rightPath.pop();\n\n  // Check left child is rightmost path below split\n  if (!isRightMost(spec, leftPath)) {\n    return false;\n  }\n\n  // Check right child is leftmost path below split\n  if (!isLeftMost(spec, rightPath)) {\n    return false;\n  }\n\n  return true;\n}\n\n/**\n * Check if left is exactly one slot to the left of right\n * Based on Go ics23 isLeftStep (proof.go lines 332-346)\n */\nfunction isLeftStep(spec: InnerSpec, left: InnerOp, right: InnerOp): boolean {\n  const leftIdx = orderFromPadding(spec, left);\n  const rightIdx = orderFromPadding(spec, right);\n\n  return rightIdx === leftIdx + 1;\n}\n\n/**\n * Determine branch order from padding\n * Based on Go ics23 orderFromPadding (proof.go lines 442-451)\n */\nfunction orderFromPadding(spec: InnerSpec, inner: InnerOp): number {\n  const maxBranch = spec.childOrder.length;\n  for (let branch = 0; branch < maxBranch; branch++) {\n    const {\n      minPrefix, maxPrefix, suffix,\n    } = getPadding(spec, branch);\n    if (hasPadding(inner, minPrefix, maxPrefix, suffix)) {\n      return branch;\n    }\n  }\n  throw new Error(\"cannot determine order from padding\");\n}\n\n/**\n * Check if left branches are all empty (placeholder nodes)\n * Based on Go ics23 leftBranchesAreEmpty (proof.go lines 373-398)\n */\nfunction leftBranchesAreEmpty(spec: InnerSpec, op: InnerOp): boolean {\n  const idx = orderFromPadding(spec, op);\n  const leftBranches = idx;\n\n  if (leftBranches === 0) {\n    return false;\n  }\n\n  // Calculate actual prefix length (excluding child hashes)\n  const actualPrefix = op.prefix.length - leftBranches * spec.childSize;\n  if (actualPrefix < 0) {\n    return false;\n  }\n\n  // Check each left branch is empty child\n  if (!spec.emptyChild || spec.emptyChild.length === 0) {\n    return false; // No empty child defined\n  }\n\n  for (let i = 0; i < leftBranches; i++) {\n    const position = getPosition(spec.childOrder, i);\n    const from = actualPrefix + position * spec.childSize;\n    const childSlice = op.prefix.slice(from, from + spec.childSize);\n\n    if (!bytesEqual(spec.emptyChild, childSlice)) {\n      return false;\n    }\n  }\n\n  return true;\n}\n\n/**\n * Check if right branches are all empty (placeholder nodes)\n * Based on Go ics23 rightBranchesAreEmpty (proof.go lines 400-424)\n */\nfunction rightBranchesAreEmpty(spec: InnerSpec, op: InnerOp): boolean {\n  const idx = orderFromPadding(spec, op);\n  const rightBranches = spec.childOrder.length - 1 - idx;\n\n  if (rightBranches === 0) {\n    return false;\n  }\n\n  // Sanity check suffix length\n  if (op.suffix.length !== rightBranches * spec.childSize) {\n    return false;\n  }\n\n  // Check each right branch is empty child\n  if (!spec.emptyChild || spec.emptyChild.length === 0) {\n    return false; // No empty child defined\n  }\n\n  for (let i = 0; i < rightBranches; i++) {\n    const position = getPosition(spec.childOrder, i);\n    const from = position * spec.childSize;\n    const childSlice = op.suffix.slice(from, from + spec.childSize);\n\n    if (!bytesEqual(spec.emptyChild, childSlice)) {\n      return false;\n    }\n  }\n\n  return true;\n}\n\n// Re-export getPosition from ops\nimport {\n  getPosition,\n} from \"./ics23-ops.js\";\n\n/**\n * Extract ExistenceProof for specific key from CommitmentProof\n * Based on Go ics23 getExistProofForKey (ics23.go lines 134-149)\n */\nfunction getExistProofForKey(\n  proof: CommitmentProof,\n  key: Uint8Array,\n): ExistenceProof | null {\n  // Check exist field\n  if (proof.exist) {\n    if (bytesEqual(proof.exist.key, key)) {\n      return proof.exist;\n    }\n  }\n\n  // Check batch entries\n  if (proof.batch) {\n    for (const entry of proof.batch.entries) {\n      if (entry.exist && bytesEqual(entry.exist.key, key)) {\n        return entry.exist;\n      }\n    }\n  }\n\n  return null;\n}\n\n/**\n * Extract NonExistenceProof for specific key from CommitmentProof\n * Based on Go ics23 getNonExistProofForKey (ics23.go lines 151-166)\n */\nfunction getNonExistProofForKey(\n  spec: ProofSpec,\n  proof: CommitmentProof,\n  key: Uint8Array,\n): NonExistenceProof | null {\n  // Check nonexist field\n  if (proof.nonexist) {\n    const np = proof.nonexist;\n    if (isLeft(spec, np.left, key) && isRight(spec, np.right, key)) {\n      return np;\n    }\n  }\n\n  // Check batch entries\n  if (proof.batch) {\n    for (const entry of proof.batch.entries) {\n      const np = entry.nonexist;\n      if (np && isLeft(spec, np.left, key) && isRight(spec, np.right, key)) {\n        return np;\n      }\n    }\n  }\n\n  return null;\n}\n\n/**\n * Check if left proof is to the left of key\n * Based on Go ics23 isLeft (ics23.go lines 168-170)\n */\nfunction isLeft(\n  spec: ProofSpec,\n  left: ExistenceProof | undefined,\n  key: Uint8Array,\n): boolean {\n  if (!left) {\n    return true; // No left proof is valid\n  }\n  const leftKeyComp = keyForComparison(spec, left.key);\n  const keyComp = keyForComparison(spec, key);\n  return compareBytes(leftKeyComp, keyComp) < 0;\n}\n\n/**\n * Check if right proof is to the right of key\n * Based on Go ics23 isRight (ics23.go lines 172-174)\n */\nfunction isRight(\n  spec: ProofSpec,\n  right: ExistenceProof | undefined,\n  key: Uint8Array,\n): boolean {\n  if (!right) {\n    return true; // No right proof is valid\n  }\n  const rightKeyComp = keyForComparison(spec, right.key);\n  const keyComp = keyForComparison(spec, key);\n  return compareBytes(rightKeyComp, keyComp) > 0;\n}\n\n/**\n * Helper: Compare two byte arrays for equality\n */\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n  if (a.length !== b.length) {\n    return false;\n  }\n  for (let i = 0; i < a.length; i++) {\n    if (a[i] !== b[i]) {\n      return false;\n    }\n  }\n  return true;\n}\n"],"mappings":";;;;;;;;;AAkCA,SAAgB,iBACd,MACA,MACA,OACA,KACA,OACS;CAET,MAAM,KAAK,oBAAoB,OAAO,IAAI;AAC1C,KAAI,CAAC,GACH,QAAO;AAIT,KAAI;AACF,uBAAqB,IAAI,MAAM,MAAM,KAAK,MAAM;AAChD,SAAO;SAEH;AACJ,SAAO;;;;;;;;AASX,SAAgB,oBACd,MACA,MACA,OACA,KACS;CAET,MAAM,KAAK,uBAAuB,MAAM,OAAO,IAAI;AACnD,KAAI,CAAC,GACH,QAAO;AAIT,KAAI;AACF,0BAAwB,IAAI,MAAM,MAAM,IAAI;AAC5C,SAAO;SAEH;AACJ,SAAO;;;;;;;;AASX,SAAgB,qBACd,OACA,MACA,MACA,KACA,OACM;AAEN,qBAAoB,OAAO,KAAK;AAGhC,KAAIA,2BAAa,KAAK,MAAM,IAAI,KAAK,EACnC,OAAM,IAAI,MAAM,mCAAmC;AAIrD,KAAIA,2BAAa,OAAO,MAAM,MAAM,KAAK,EACvC,OAAM,IAAI,MAAM,qCAAqC;AAOvD,KAAIA,2BAAa,MAHJ,uBAAuB,MAAM,CAGd,KAAK,EAC/B,OAAM,IAAI,MAAM,8CAA8C;;;;;;;AASlE,SAAgB,wBACd,OACA,MACA,MACA,KACM;CACN,IAAIC,UAA6B;CACjC,IAAIC,WAA8B;AAGlC,KAAI,MAAM,MAAM;AACd,uBAAqB,MAAM,MAAM,MAAM,MAAM,MAAM,KAAK,KAAK,MAAM,KAAK,MAAM;AAC9E,YAAU,MAAM,KAAK;;AAIvB,KAAI,MAAM,OAAO;AACf,uBACE,MAAM,OACN,MACA,MACA,MAAM,MAAM,KACZ,MAAM,MAAM,MACb;AACD,aAAW,MAAM,MAAM;;AAIzB,KAAI,CAAC,WAAW,CAAC,SACf,OAAM,IAAI,MAAM,qCAAqC;AAIvD,KAAI,UAGF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