Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions clients/js/src/confidentialTransferArithmetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ export function extractCiphertextFromGroupedBytes(groupedCiphertext: ReadonlyUin
return ciphertext;
}

function addCiphertexts(left: ReadonlyUint8Array, right: ReadonlyUint8Array) {
const leftPoints = ciphertextToPoints(left);
const rightPoints = ciphertextToPoints(right);
return pointsToCiphertext(
leftPoints.commitment.add(rightPoints.commitment),
leftPoints.handle.add(rightPoints.handle),
);
}

function subtractCiphertexts(left: ReadonlyUint8Array, right: ReadonlyUint8Array) {
const leftPoints = ciphertextToPoints(left);
const rightPoints = ciphertextToPoints(right);
Expand All @@ -70,6 +79,20 @@ function combineLoHiCiphertexts(ciphertextLo: ReadonlyUint8Array, ciphertextHi:
);
}

/**
* Combines lo/hi ciphertext halves (hi << bitLength + lo) and adds the result
* to `left`. Used to compute the new encrypted supply ciphertext after a
* confidential mint.
*/
export function addWithLoHiCiphertexts(
left: ReadonlyUint8Array,
ciphertextLo: ReadonlyUint8Array,
ciphertextHi: ReadonlyUint8Array,
bitLength: bigint,
) {
return addCiphertexts(left, combineLoHiCiphertexts(ciphertextLo, ciphertextHi, bitLength));
}

/**
* Combines lo/hi ciphertext halves (hi << bitLength + lo) and subtracts the
* result from `left`. Used to compute the new available-balance ciphertext
Expand Down
Loading