|
| 1 | +Multisignature |
| 2 | +============== |
| 3 | + |
| 4 | +Multisignature transactions are transactions which require multiple signatures before execution. In simplest example it means that, if there is token wallet which require 5 signatures from different parties, all 5 parties must sign spent transaction, before it will be processed. |
| 5 | + |
| 6 | +It is standard functionality in blockchain systems and it is also implemented in IOTA |
| 7 | + |
| 8 | +.. note:: |
| 9 | + |
| 10 | + You can read more about IOTA multisignature on the `wiki`_. |
| 11 | + |
| 12 | +Generating multisignature address |
| 13 | +--------------------------------- |
| 14 | + |
| 15 | +In order to use multisignature functionality, a special multisignature address must be created. It is done by adding each key digest in agreed order into digests list. At the end, last participant is converting digests list (Curl state trits) into multisignature address. |
| 16 | + |
| 17 | +Here is the example where digest is created: |
| 18 | + |
| 19 | +.. code-block:: python |
| 20 | +
|
| 21 | + # Create digest 3 of 3. |
| 22 | + api_3 =\ |
| 23 | + MultisigIota( |
| 24 | + adapter = 'http://localhost:14265', |
| 25 | +
|
| 26 | + seed = |
| 27 | + Seed( |
| 28 | + b'TESTVALUE9DONTUSEINPRODUCTION99999JYFRTI' |
| 29 | + b'WMKVVBAIEIYZDWLUVOYTZBKPKLLUMPDF9PPFLO9KT', |
| 30 | + ), |
| 31 | + ) |
| 32 | +
|
| 33 | + gd_result = api_3.get_digests(index=8, count=1, security_level=2) |
| 34 | +
|
| 35 | + digest_3 = gd_result['digests'][0] # type: Digest |
| 36 | +
|
| 37 | +And here is example where digests are converted into multisignature address: |
| 38 | + |
| 39 | +.. code-block:: python |
| 40 | +
|
| 41 | + cma_result =\ |
| 42 | + api_1.create_multisig_address(digests=[digest_1, |
| 43 | + digest_2, |
| 44 | + digest_3]) |
| 45 | +
|
| 46 | + # For consistency, every API command returns a dict, even if it only |
| 47 | + # has a single value. |
| 48 | + multisig_address = cma_result['address'] # type: MultisigAddress |
| 49 | +
|
| 50 | +
|
| 51 | +
|
| 52 | +Prepare transfer |
| 53 | +------------------ |
| 54 | + |
| 55 | +.. note:: |
| 56 | + |
| 57 | + Since spending tokens from the same address more than once is insecure, remainder should be transferred to other address. So, this address should be created before as next to be used multisignature address. |
| 58 | + |
| 59 | +First signer for multisignature wallet is defining address where tokens should be transferred and next wallet address for reminder: |
| 60 | + |
| 61 | +.. code-block:: python |
| 62 | +
|
| 63 | + pmt_result =\ |
| 64 | + api_1.prepare_multisig_transfer( |
| 65 | + # These are the transactions that will spend the IOTAs. |
| 66 | + # You can divide up the IOTAs to send to multiple addresses if you |
| 67 | + # want, but to keep this example focused, we will only include a |
| 68 | + # single spend transaction. |
| 69 | + transfers = [ |
| 70 | + ProposedTransaction( |
| 71 | + address = |
| 72 | + Address( |
| 73 | + b'TESTVALUE9DONTUSEINPRODUCTION99999NDGYBC' |
| 74 | + b'QZJFGGWZ9GBQFKDOLWMVILARZRHJMSYFZETZTHTZR', |
| 75 | + ), |
| 76 | +
|
| 77 | + value = 42, |
| 78 | +
|
| 79 | + # If you'd like, you may include an optional tag and/or |
| 80 | + # message. |
| 81 | + tag = Tag(b'KITTEHS'), |
| 82 | + message = TryteString.from_string('thanx fur cheezburgers'), |
| 83 | + ), |
| 84 | + ], |
| 85 | +
|
| 86 | + # Specify our multisig address as the input for the spend |
| 87 | + # transaction(s). |
| 88 | + # Note that PyOTA currently only allows one multisig input per |
| 89 | + # bundle (although the protocol does not impose a limit). |
| 90 | + multisig_input = multisig_address, |
| 91 | +
|
| 92 | + # If there will be change from this transaction, you MUST specify |
| 93 | + # the change address! Unlike regular transfers, multisig transfers |
| 94 | + # will NOT automatically generate a change address; that wouldn't |
| 95 | + # be fair to the other participants! |
| 96 | + change_address = None, |
| 97 | + ) |
| 98 | +
|
| 99 | + prepared_trytes = pmt_result['trytes'] # type: List[TransactionTrytes] |
| 100 | +
|
| 101 | +
|
| 102 | +Sign the inputs |
| 103 | +--------------- |
| 104 | + |
| 105 | +.. note:: |
| 106 | + |
| 107 | + Validate the signatures. |
| 108 | + |
| 109 | +Broadcast the bundle |
| 110 | +-------------------- |
| 111 | + |
| 112 | +Remarks |
| 113 | +------- |
| 114 | + |
| 115 | +Full code `example`_. |
| 116 | + |
| 117 | +.. note:: |
| 118 | + |
| 119 | + How M-of-N works |
| 120 | + |
| 121 | +.. _example: https://github.com/iotaledger/iota.lib.py/blob/develop/examples/multisig.py |
| 122 | +.. _wiki: https://github.com/iotaledger/wiki/blob/master/multisigs.md |
0 commit comments