Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decred support #28

Closed
wants to merge 8 commits into from
Closed
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
38 changes: 38 additions & 0 deletions coins.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,42 @@
},
"dust_limit": 546,
"blocktime_minutes": 2.5
}, {
"coin_name": "Decred",
"coin_shortcut": "DCR",
"address_type": 1855,
"maxfee_kb": 100000000,
"address_type_p2sh": 1818,
"address_type_p2wpkh": null,
"address_type_p2wsh": null,
"signed_message_header": "Decred Signed Message:\n",
"hash_genesis_block": "298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980",
"xpub_magic": "02fda926",
"xprv_magic": "02fda4e8",
"bip44": 20,
"segwit": false,
"default_fee_b": {
"Normal": 10
},
"dust_limit": 546,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

"blocktime_minutes": 10
}, {
"coin_name": "DecredTestnet",
"coin_shortcut": "DCRT",
"address_type": 3873,
"maxfee_kb": 100000000,
"address_type_p2sh": 3836,
"address_type_p2wpkh": null,
"address_type_p2wsh": null,
"signed_message_header": "Decred Signed Message:\n",
"hash_genesis_block": "298e5cc3d985bfe7f81dc135f360abe089edd4396b86d2de66b0cef42b21d980",
"xpub_magic": "043587d1",
"xprv_magic": "04358397",
"bip44": 11,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testnet should use 1. 11 is registered to another coin.

"segwit": false,
"default_fee_b": {
"Normal": 10
},
"dust_limit": 546,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation, again.

"blocktime_minutes": 10
}]
112 changes: 111 additions & 1 deletion protob/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ enum MessageType {
MessageType_DebugLinkMemoryRead = 110 [(wire_debug_in) = true];
MessageType_DebugLinkMemory = 111 [(wire_debug_out) = true];
MessageType_DebugLinkMemoryWrite = 112 [(wire_debug_in) = true];
MessageType_DebugLinkFlashErase = 113 [(wire_debug_in) = true];
MessageType_DebugLinkFlashErase = 113 [(wire_debug_in) = true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here?

MessageType_DecredLoadDevice = 114 [(wire_in) = true];
MessageType_DecredGetAddress = 115 [(wire_in) = true];
MessageType_DecredAddress = 116 [(wire_out) = true];
MessageType_DecredEntropyAck = 117 [(wire_in) = true];
MessageType_DecredSignMessage = 118 [(wire_in) = true];
MessageType_DecredVerifyMessage = 119 [(wire_in) = true];
MessageType_DecredSignTx = 120 [(wire_in) = true];
MessageType_DecredTxAck = 121 [(wire_in) = true];
MessageType_DecredTxRequest = 122 [(wire_out) = true];
}

////////////////////
Expand Down Expand Up @@ -348,6 +357,107 @@ message LoadDevice {
optional uint32 u2f_counter = 8; // U2F counter
}

/**
* Request: Load Decred seed PGP word list from the computer
* @next ButtonRequest
* @next Success
* @next Failure
*/
message DecredLoadDevice {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you need a new message or could you have added it as an enum in the existing message?

optional string mnemonic = 1; // seed encoded as BIP-39 mnemonic (12, 18 or 24 words)
optional HDNodeType node = 2; // BIP-32 node
optional string pin = 3; // set PIN protection
optional bool passphrase_protection = 4; // enable master node encryption using passphrase
optional string language = 5 [default='english']; // device language
optional string label = 6; // device label
optional uint32 u2f_counter = 7; // U2F counter
}

/**
* Request: Ask device for Decred address corresponding to address_n path
* @next PassphraseRequest
* @next DecredAddress
* @next Failure
*/
message DecredGetAddress {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
optional bool show_display = 2; // optionally show on display before sending the result
}

/**
* Response: Contains an Decred address derived from device private seed
* @prev DecredGetAddress
*/
message DecredAddress {
required string address = 1; // Base58 encoded address string
}

/**
* Request: Provide additional entropy for seed generation function (Decred variant)
* @prev EntropyRequest
* @next ButtonRequest
*/
message DecredEntropyAck {
optional bytes entropy = 1; // 256 bits (32 bytes) of random data
}

/**
* Request: Ask device to sign message (Decred variant)
* @next MessageSignature
* @next Failure
*/
message DecredSignMessage {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required bytes message = 2; // message to be signed
}

/**
* Request: Ask device to verify message (Decred variant)
* @next Success
* @next Failure
*/
message DecredVerifyMessage {
optional string address = 1; // address to verify
optional bytes signature = 2; // signature to verify
optional bytes message = 3; // message to verify
}

/**
* Request: Ask device to sign transaction (Decred variant)
* @next PassphraseRequest
* @next PinMatrixRequest
* @next DecredTxRequest
* @next Failure
*/
message DecredSignTx {
required uint32 outputs_count = 1; // number of transaction outputs
required uint32 inputs_count = 2; // number of transaction inputs
optional uint32 version = 4 [default=1]; // transaction version
optional uint32 lock_time = 5 [default=0]; // transaction lock_time
}

/**
* Response: Device asks for information for signing Decred transaction or returns the last result
* If request_index is set, device awaits TxAck message (with fields filled in according to request_type)
* If signature_index is set, 'signature' contains signed input of signature_index's input
* @prev DecredSignTx
* @prev DecredTxAck
*/
message DecredTxRequest {
optional RequestType request_type = 1; // what should be filled in TxAck message?
optional TxRequestDetailsType details = 2; // request for tx details
optional TxRequestSerializedType serialized = 3; // serialized data and request for next
}

/**
* Request: Decred Reported transaction data
* @prev DecredTxRequest
* @next DecredTxRequest
*/
message DecredTxAck {
optional DecredTransactionType tx = 1;
}

/**
* Request: Ask device to do initialization involving user interaction
* @next EntropyRequest
Expand Down
75 changes: 75 additions & 0 deletions protob/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,78 @@ message IdentityType {
optional string path = 5; // path part of URI
optional uint32 index = 6 [default=0]; // identity index
}


/**
* Structure representing a decred data type that is used to track previous
* transaction outputs.
* @used_in DecredTxInType
*/
message DecredOutPointType {
required bytes hash = 1;
required uint64 index = 2;
optional bytes tree = 3;
}

/**
* Structure representing decred transaction input
* @used_in SimpleSignTx
* @used_in DecredTransactionType
*/
message DecredTxInType {
// Non-witness
required DecredOutPointType previous_out_point = 1;
required uint32 sequence = 2 [default=0xffffffff];

// Witness
required int64 value_in = 3;
required uint32 block_height = 4;
required uint32 block_index = 5;
required bytes signature_script = 6; // FIXME ATM this has a fixed size set in - should be dynamic length/pointer

required bytes prev_hash = 7; // XXX remove me, I may not be needed
optional InputScriptType script_type = 8 [default=SPENDADDRESS]; // defines template of input script
optional MultisigRedeemScriptType multisig = 9; // Filled if input is going to spend multisig tx
optional uint64 amount = 10; // amount of previous transaction output (for segwit only)
repeated uint32 address_n = 11; // BIP-32 path to derive the key from master node
required uint32 prev_index = 12; // index of previous output to spend
optional bytes script_sig = 13; // script signature, unset for tx to sign
}

/**
* Structure representing decred transaction output
* @used_in SimpleSignTx
* @used_in DecredTransactionType
*/
message DecredTxOutType {
required int64 value = 1;
required uint32 version = 2;
required bytes pk_script = 3; // FIXME ATM this has a fixed size set in - should be dynamic length/pointer

// XXX remove the below members
optional string address = 4; // target coin address in Base58 encoding
repeated uint32 address_n = 5; // BIP-32 path to derive the key from master node; has higher priority than "address"
required uint64 amount = 6; // amount to spend in satoshis
required OutputScriptType script_type = 7; // output script type
optional MultisigRedeemScriptType multisig = 8; // defines multisig address; script_type must be PAYTOMULTISIG
optional bytes op_return_data = 9; // defines op_return data; script_type must be PAYTOOPRETURN, amount must be 0

}

/**
* Structure representing decred transaction
* @used_in DecredTxAck
*/
message DecredTransactionType {
optional int32 version = 1;
repeated DecredTxInType inputs = 2;
repeated TxOutputBinType bin_outputs = 3;
optional uint32 lock_time = 4;
repeated DecredTxOutType outputs = 5;
optional uint32 inputs_cnt = 6;
optional uint32 outputs_cnt = 7;
optional bytes extra_data = 8;
optional uint32 extra_data_len = 9;
required bytes cached_hash = 10;
optional uint32 expiry = 11;
}