def create_zeth_notes( phi: str, hsig: bytes, output0: Tuple[OwnershipPublicKey, int], output1: Tuple[OwnershipPublicKey, int]) -> Tuple[ZethNote, ZethNote]: """ Create two ordered ZethNotes. This function is used to generate new output notes. """ (recipient0, value0) = output0 (recipient1, value1) = output1 rho0 = _compute_rho_i(phi, hsig, 0) trap_r0 = trap_r_randomness() note0 = ZethNote(apk=ownership_key_as_hex(recipient0), value=int64_to_hex(value0), rho=rho0.hex(), trap_r=trap_r0) rho1 = _compute_rho_i(phi, hsig, 1) print("rho1: ", rho1.hex()) trap_r1 = trap_r_randomness() note1 = ZethNote(apk=ownership_key_as_hex(recipient1), value=int64_to_hex(value1), rho=rho1.hex(), trap_r=trap_r1) return note0, note1
def get_dummy_input_and_address( a_pk: OwnershipPublicKey) -> Tuple[int, ZethNote]: """ Create a zeth note and address, for use as circuit inputs where there is no real input. """ dummy_note = ZethNote(apk=ownership_key_as_hex(a_pk), value=ZERO_UNITS_HEX, rho=get_dummy_rho(), trap_r=trap_r_randomness()) # Note that the Merkle path is not fully checked against the root by the # circuit since the note value is 0. Hence the address used here is # arbitrary. dummy_note_address = 0 return (dummy_note_address, dummy_note)
def zeth_note_from_bytes(note_bytes: bytes) -> ZethNote: if len(note_bytes) != (constants.NOTE_LENGTH_BYTES): raise ValueError(f"note_bytes len {len(note_bytes)}, " f"(expected {constants.NOTE_LENGTH_BYTES})") apk = note_bytes[_APK_OFFSET_BYTES:_APK_OFFSET_BYTES + constants.APK_LENGTH_BYTES] value = note_bytes[_VALUE_OFFSET_BYTES:_VALUE_OFFSET_BYTES + constants.PUBLIC_VALUE_LENGTH_BYTES] rho = note_bytes[_RHO_OFFSET_BYTES:_RHO_OFFSET_BYTES + constants.RHO_LENGTH_BYTES] trap_r = note_bytes[_TRAPR_OFFSET_BYTES:] return ZethNote(apk=apk.hex(), value=value.hex(), rho=rho.hex(), trap_r=trap_r.hex())
def test_compute_commitment(self) -> None: """ Test the commitment value for a note, as computed by the circuit. """ apk = "44810c8d62784f5e9ce862925ebb889d1076a453677a5d73567387cd5717a402" value = "0000000005f5e100" rho = "0b0bb358233326ce4d346d86f9a0c3778ed8ce15efbf7640aad6e9359145659f" r = "1e3063320fd43f2d6c456d7f1ee11b7ab486308133e2a5afe916daa4ff5357f6" cm_expect = int( "fdf5279335a2fa36fb0d664509808db8d02b6f05f9e5639960952a7038363cfc", 16) cm_expect_field = cm_expect % constants.ZETH_PRIME note = ZethNote(apk=apk, value=value, rho=rho, trap_r=r) cm = int.from_bytes(compute_commitment(note), byteorder="big") self.assertEqual(cm_expect_field, cm)
def zeth_note_from_json_dict(parsed_zeth_note: Dict[str, str]) -> ZethNote: note = ZethNote(apk=parsed_zeth_note["a_pk"], value=parsed_zeth_note["value"], rho=parsed_zeth_note["rho"], trap_r=parsed_zeth_note["trap_r"]) return note