@@ -512,7 +512,6 @@ In this example, you will learn how to:
512
512
513
513
- **Convert Python data structures to JSON format. **
514
514
- **Encrypt data and include it in a zero-value transaction. **
515
- - **Generate an address with a PyOTA specific utility tool. **
516
515
- **Store the zero-value transaction with encrypted data on the Tangle. **
517
516
518
517
.. warning ::
@@ -530,37 +529,37 @@ Code
530
529
Discussion
531
530
~~~~~~~~~~
532
531
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
533
- :lines: 1-15
532
+ :lines: 1-18
534
533
:lineno-start: 1
535
534
536
- The first odd thing we notice among the imports is
537
- :py:class: `~iota.crypto.addresses.AddressGenerator `. It is a PyOTA specific
538
- utility that generates addresses given your seed.
539
-
540
- We will use the ``encrypt `` method to enchiper the data, and ``b64encode `` for
535
+ We will use the ``encrypt `` method to encipher the data, and ``b64encode `` for
541
536
representing it as ASCII characters. ``getpass `` will prompt the user for a
542
537
password, and the ``json `` library is used for JSON formatting.
543
538
539
+ We will need an address to upload the data, therefore we need to supply the
540
+ seed to the ``Iota `` API instance. The address will be generated from this
541
+ seed.
542
+
544
543
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
545
- :lines: 17-23
546
- :lineno-start: 17
544
+ :lines: 20-26
545
+ :lineno-start: 20
547
546
548
547
The data to be stored is considered confidential information, therefore we
549
548
can't just put it on the Tangle as plaintext so everyone can read it. Think of
550
549
what would happen if the world's most famous secret agent's identity was leaked
551
550
on the Tangle...
552
551
553
552
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
554
- :lines: 25-26
555
- :lineno-start: 25
553
+ :lines: 28-29
554
+ :lineno-start: 28
556
555
557
556
Notice, that ``data `` is a Python ``dict `` object. As a common way of exchanging
558
557
data on the web, we would like to convert it to JSON format. The ``json.dumps() ``
559
558
method does exactly that, and the result is a JSON formatted plaintext.
560
559
561
560
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
562
- :lines: 28-37
563
- :lineno-start: 28
561
+ :lines: 31-40
562
+ :lineno-start: 31
564
563
565
564
Next, we will encrypt this data with a secret password we obtain from the user.
566
565
@@ -577,20 +576,18 @@ Therefore, we first encode our binary data into ASCII characters with `Base64`_
577
576
encoding.
578
577
579
578
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
580
- :lines: 39-57
581
- :lineno-start: 39
579
+ :lines: 42-58
580
+ :lineno-start: 42
582
581
583
582
Now, we are ready to construct the transfer. We convert the encrypted `Base64 `_
584
583
encoded data to trytes and assign it to the :py:class: `ProposedTransaction `
585
- object's message argument.
584
+ object's `` message `` argument.
586
585
587
586
An address is also needed, so we generate one with the help of
588
- :py:class: `~iota.crypto.addresses.AddressGenerator ` and its
589
- :py:meth: `~iota.crypto.addresses.AddressGenerator.get_addresses ` method. Feel
590
- free to chose the index of the generated address, and don't forget, that the
591
- method returns a list of addresses, even if it contains only one. Put your seed
592
- (from `4.a Generate Address `_) onto line 44 to generate an address that belongs
593
- to you. For more detailed explanation on how addresses are generated in PyOTA,
587
+ :py:meth: `~Iota.get_new_addresses ` extended API method. Feel free to choose the
588
+ index of the generated address, and don't forget, that the method returns a
589
+ ``dict `` with a list of addresses, even if it contains only one.
590
+ For more detailed explanation on how addresses are generated in PyOTA,
594
591
refer to the :ref: `Generating Addresses ` page.
595
592
596
593
We also attach a custom :py:class: `Tag ` to our :py:class: `ProposedTransaction `.
@@ -599,8 +596,8 @@ of a transaction, the library would split it accross more transactions that
599
596
together form the transfer bundle.
600
597
601
598
.. literalinclude :: ../examples/tutorials/06_store_encrypted.py
602
- :lines: 59-65
603
- :lineno-start: 59
599
+ :lines: 60-66
600
+ :lineno-start: 60
604
601
605
602
Finally, we use :py:meth: `Iota.send_transfer ` to prepare the transfer and
606
603
send it to the network.
@@ -611,8 +608,8 @@ The tail transaction (a tail transaction is the one with index 0 in the bundle)
611
608
hash is printed on the console, because you will need it in the next tutorial,
612
609
and anyway, it is a good practice to keep a reference to your transfers.
613
610
614
- In the next example, we will try to decode the confidential information from the
615
- Tangle.
611
+ In the next example, we will try to decode the confidential information from
612
+ the Tangle.
616
613
617
614
7. Fetch Encrypted Data
618
615
-----------------------
@@ -658,7 +655,7 @@ To fetch transactions or bundles from the Tangle, a reference is required to
658
655
retreive them from the network. Transactions are identified by their
659
656
transaction hash, while a group of transaction (a bundle) by bundle hash.
660
657
Hashes ensure the integrity of the Tangle, since they contain verifiable
661
- information on the content of the transfer objects.
658
+ information about the content of the transfer objects.
662
659
663
660
``input() `` asks the user to give the tail transaction hash of the bundle
664
661
that holds the encrypted messages. The tail transaction is the first in the
@@ -680,7 +677,7 @@ To simplify the code, several operations are happening on line 21:
680
677
681
678
- Calling :py:meth: `~Iota.get_bundles ` that returns a ``dict ``,
682
679
- accessing the ``'bundles' `` key in the ``dict ``,
683
- - and taking the first element of the the list if bundles in the value
680
+ - and taking the first element of the the list of bundles in the value
684
681
associated with the key.
685
682
686
683
.. literalinclude :: ../examples/tutorials/07_fetch_encrypted.py
@@ -694,13 +691,14 @@ the ``signature_message_fragment`` fields of the transactions, decoded from
694
691
trytes into unicode characters.
695
692
696
693
We then combine these message chunks into one stream of characters by using
697
- ``sting .join() ``.
694
+ ``string .join() ``.
698
695
699
696
We know that at this stage that we can't make sense of our message, because it
700
697
is encrypted and encoded into `Base64 `_. Let's peel that onion layer by layer:
701
698
702
699
- On line 28, we decode the message into bytes with ``b64decode ``.
703
- - On line 31, we ask the user for a decryption password.
700
+ - On line 31, we ask the user for thr decryption password (from the previous
701
+ tutorial).
704
702
- On line 36, we decrypt the bytes cipher with the password and decode the
705
703
result into a unicode string.
706
704
- Since we used JSON formatting in the previous tutorial, there is one
0 commit comments