.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/privacy/signatures/plot_03_cryptonote_stealth_addresses.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_privacy_signatures_plot_03_cryptonote_stealth_addresses.py: CryptoNote stealth addresses: a fresh key for every payment (2013) ================================================================== A reused address links every payment it receives. CryptoNote let a payee publish one address :math:`(A, B) = (g^a, g^b)` from which each payer derives a fresh one-time key. The payer picks :math:`r`, publishes :math:`R = g^r`, and pays to .. math:: P = g^{H(A^r)} B . The payee recognises it by computing :math:`R^a = A^r`, and spends it with :math:`x = H(R^a) + b`. The view key :math:`a` alone finds payments without being able to spend them. .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk G = bk.crypto.TEACHING_GROUP .. GENERATED FROM PYTHON SOURCE LINES 27-29 Payments to one address ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 29-46 .. code-block:: Python bob = bk.privacy.stealth_keys(view_secret=31_337, spend_secret=27_182) others = [bk.privacy.stealth_keys(1_000 + i, 2_000 + i) for i in range(4)] ledger = [] for k in range(12): payee = bob if k % 3 == 0 else others[k % 4] output = bk.privacy.stealth_payment(payee.view_public, payee.spend_public, 5_000 + k) ledger.append((payee is bob, output)) found = [o for _, o in ledger if bk.privacy.owns_output(o, bob.view_secret, bob.spend_public)] assert found == [o for mine, o in ledger if mine] print(f"bob's view key finds {len(found)} of {len(ledger)} outputs") for output in found: x = bk.privacy.one_time_secret(output, bob.view_secret, bob.spend_secret) assert G.public(x) == output.one_time_key assert len({o.one_time_key for o in found}) == len(found) .. rst-class:: sphx-glr-script-out .. code-block:: none bob's view key finds 4 of 12 outputs .. GENERATED FROM PYTHON SOURCE LINES 47-50 What the ledger shows --------------------- Bob's outputs are scattered among the rest. .. GENERATED FROM PYTHON SOURCE LINES 50-63 .. code-block:: Python fig, ax = plt.subplots(figsize=(7, 3)) for k, (mine, output) in enumerate(ledger): ax.scatter(k, output.one_time_key / G.p, color="#16a34a" if mine else "#64748b") ax.scatter([], [], color="#16a34a", label="paid to bob") ax.scatter([], [], color="#64748b", label="paid to others") ax.set(xlabel="output", ylabel="one-time key / p", ylim=(0, 1)) ax.set_title("One published address, unlinkable outputs") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/privacy/signatures/images/sphx_glr_plot_03_cryptonote_stealth_addresses_001.png :alt: One published address, unlinkable outputs :srcset: /api/gallery/privacy/signatures/images/sphx_glr_plot_03_cryptonote_stealth_addresses_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-69 Exercise -------- Bob gives his view key to an auditor. What can the auditor learn about Bob's incoming and outgoing payments, and what can it not do? A worked solution is in :doc:`/exercises/privacy`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.072 seconds) .. _sphx_glr_download_api_gallery_privacy_signatures_plot_03_cryptonote_stealth_addresses.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/privacy/signatures/plot_03_cryptonote_stealth_addresses.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_cryptonote_stealth_addresses.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_cryptonote_stealth_addresses.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_cryptonote_stealth_addresses.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_