Skip to content

Commit

Permalink
Add support for all Mintlayer inputs and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Jul 16, 2024
1 parent c13d5d9 commit 967640b
Show file tree
Hide file tree
Showing 27 changed files with 9,763 additions and 515 deletions.
1 change: 1 addition & 0 deletions common/protob/messages-bitcoin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enum AmountUnit {
MILLIBITCOIN = 1; // mBTC
MICROBITCOIN = 2; // uBTC
SATOSHI = 3; // sat
ML = 4; // Mintlayer
}

/**
Expand Down
253 changes: 244 additions & 9 deletions common/protob/messages-mintlayer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ message MintlayerSignTx {
message MintlayerTxRequest {
optional MintlayerRequestType request_type = 1; // what should be filled in TxAck message?
optional MintlayerTxRequestDetailsType details = 2; // request for tx details
optional MintlayerTxRequestSerializedType serialized = 3; // serialized data and request for next
repeated MintlayerTxRequestSerializedType serialized = 3; // serialized data and request for next
/**
* Type of information required by transaction signing process
*/
Expand All @@ -121,16 +121,135 @@ message MintlayerTxRequest {
}
}

/** Data type for transaction input to be signed.
*
* @embed
*/
message MintlayerTxInput {
optional MintlayerUtxoTxInput utxo = 1; // UTXO input
optional MintlayerAccountTxInput account = 2; // account spending input
optional MintlayerAccountCommandTxInput account_command = 3; // account command input
}

/**
* Type of information required by transaction signing process
*/
enum MintlayerUtxoType {
TRANSACTION = 0;
BLOCK = 1;
}

/** Data type for transaction input to be signed.
*
* @embed
*/
message MintlayerUtxoTxInput {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required bytes prev_hash = 2; // hash of previous transaction output to spend by this input
required uint32 prev_index = 3; // index of previous output to spend
optional uint32 sequence = 4 [default=0xffffffff]; // sequence
required uint64 amount = 5; // amount of previous transaction output
required string address = 2; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
required bytes prev_hash = 3; // hash of previous transaction output to spend by this input
required uint32 prev_index = 4; // index of previous output to spend
required MintlayerUtxoType type = 5; // index of previous output to spend
optional uint32 sequence = 6 [default=0xffffffff]; // sequence
required MintlayerOutputValue value = 7; // amount of previous transaction output
}

/** Data type for transaction input to be signed.
*
* @embed
*/
message MintlayerAccountTxInput {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required string address = 2; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
optional uint32 sequence = 3 [default=0xffffffff]; // sequence
required MintlayerOutputValue value = 4; // amount of previous transaction output
required uint64 nonce = 5; // incrementing account nonce
required bytes delegation_id = 6; // the delegation id of the account
}

/** Data type for transaction input to be signed.
*
* @embed
*/
message MintlayerAccountCommandTxInput {
repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node
required string address = 2; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
optional uint32 sequence = 3 [default=0xffffffff]; // sequence
required uint64 nonce = 4; // incrementing account nonce
optional MintlayerMintTokens mint = 5; // mint tokens
optional MintlayerUnmintTokens unmint = 6; // unmint tokens
optional MintlayerLockTokenSupply lock_token_supply = 7; // lock token supply
optional MintlayerFreezeToken freeze_token = 8; // freeze supply
optional MintlayerUnfreezeToken unfreeze_token = 9; // unfreeze supply
optional MintlayerChangeTokenAuhtority change_token_authority = 10; // change token authority
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerMintTokens {
required bytes token_id = 1; // token id
required bytes amount = 2; // amoun of tokens to mint
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerUnmintTokens {
required bytes token_id = 1; // token id
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerLockTokenSupply {
required bytes token_id = 1; // token id
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerFreezeToken {
required bytes token_id = 1; // token id
required bool is_token_unfreezabe = 2; // is unfreezeable after freezing it
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerUnfreezeToken {
required bytes token_id = 1; // token id
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerChangeTokenAuhtority {
required bytes token_id = 1; // token id
required string destination = 2; // destination for the new authority
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerTxOutput {
optional MintlayerTransferTxOutput transfer = 1; // transfer output
optional MintlayerLockThenTransferTxOutput lock_then_transfer = 2; // lock then transfer output
optional MintlayerBurnTxOutput burn = 3; // burn output
optional MintlayerCreateStakePoolTxOutput create_stake_pool = 4; // create stake pool output
optional MintlayerProduceBlockFromStakeTxOutput produce_block_from_stake = 5; // create block from stake output
optional MintlayerCreateDelegationIdTxOutput create_delegation_id = 6; // create delegation Id output
optional MintlayerDelegateStakingTxOutput delegate_staking = 7; // delegate staking output
optional MintlayerIssueFungibleTokenTxOutput issue_fungible_token = 8; // issue fungible token output
optional MintlayerIssueNftTxOutput issue_nft = 9; // issue NFT output
optional MintlayerDataDepositTxOutput data_deposit = 10; // data deposit output
}

/** Data type for output value coins or token
* @embed
*/
message MintlayerOutputValue {
required bytes amount = 1; // lock until block height
optional bytes token_id = 2; // optional token id
}

/** Data type for transaction output to be signed.
Expand All @@ -139,7 +258,123 @@ message MintlayerUtxoTxInput {
message MintlayerTransferTxOutput {
optional string address = 1; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
repeated uint32 address_n = 2; // BIP-32 path to derive the destination (used for change addresses)
required uint64 amount = 3; // amount to spend in satoshis
required MintlayerOutputValue value = 3; // amount to spend in atoms for coin or token
}

/** Data type for time lock of an output
* @embed
*/
message MintlayerOutputTimeLock {
optional uint64 until_height = 1; // lock until block height
optional uint64 until_time = 2; // lock until time
optional uint64 for_block_count = 3; // lock for number of blocks
optional uint64 for_seconds = 4; // lock for number of seconds
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerLockThenTransferTxOutput {
optional string address = 1; // destination address in Base58 encoding; script_type must be PAYTOADDRESS
repeated uint32 address_n = 2; // BIP-32 path to derive the destination (used for change addresses)
required MintlayerOutputValue value = 3; // amount to spend in atoms
required MintlayerOutputTimeLock lock = 4; // output lock
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerBurnTxOutput {
required MintlayerOutputValue value = 1; // amount to burn in atoms
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerCreateStakePoolTxOutput {
required bytes pool_id = 1; // the pool id
required bytes pledge = 2; // the pledge amount
required string staker = 3; // the staker destination address
required string vrf_public_key = 4; // the VRF public key address
required string decommission_key = 5; // the decommission key
required uint32 margin_ratio_per_thousand = 6;// the margin ratio per thousand
required bytes cost_per_block = 7; // the cost per block
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerProduceBlockFromStakeTxOutput {
required string destination = 1; // the staker destination address
required bytes pool_id = 2; // the pool id
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerCreateDelegationIdTxOutput {
required string destination = 1; // the delegation owner destination address
required bytes pool_id = 2; // the pool id
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerDelegateStakingTxOutput {
required bytes amount = 1; // the amount to stake
required bytes delegation_id = 2; // the delegation id
}

/**
* Type of information required by transaction signing process
*/
enum MintlayerTokenTotalSupplyType {
FIXED = 0;
LOCKABLE = 1;
UNLIMITED = 2;
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerTokenTotalSupply {
required MintlayerTokenTotalSupplyType type = 1; // the amount to stake
optional bytes fixed_amount = 2; // the amount to stake
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerIssueFungibleTokenTxOutput {
required bytes token_ticker = 1; // the token ticker
required uint32 number_of_decimals = 2; // the number of decimals for the token
required bytes metadata_uri = 3; // the metadata uri
required MintlayerTokenTotalSupply total_supply = 4; // the total supply limit
required string authority = 5; // the token authority destination address
required bool is_freezable = 6; // if the token freezable or not
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerIssueNftTxOutput {
required bytes token_id = 1; // the token id
required string destination = 2; // the NFT authority destination address
optional string creator = 3; // the NFT creator destination address
required bytes name = 4; // the NFT name
required bytes description = 5; // the NFT description
required bytes ticker = 6; // the NFT ticker
optional bytes icon_uri = 7; // the NFT icon uri
optional bytes additional_metadata_uri = 8; // the NFT additional metadata uri
optional bytes media_uri = 9; // the NFT media uri
required bytes media_hash = 10; // the NFT media hash
}

/** Data type for transaction output to be signed.
* @embed
*/
message MintlayerDataDepositTxOutput {
required bytes data = 1; // the data to be deposited
}

/** Data type for metadata about previous transaction which contains the UTXO being spent.
Expand Down Expand Up @@ -168,7 +403,7 @@ message MintlayerPrevInput {
* @embed
*/
message MintlayerPrevTransferOutput {
required uint64 amount = 1; // amount sent to this output
required MintlayerOutputValue value = 1; // amount sent to this output
}

/**
Expand All @@ -183,7 +418,7 @@ message MintlayerTxAckUtxoInput {
required MintlayerTxAckInputWrapper tx = 1;

message MintlayerTxAckInputWrapper {
required MintlayerUtxoTxInput input = 2;
required MintlayerTxInput input = 2;
}
}

Expand All @@ -200,6 +435,6 @@ message MintlayerTxAckOutput {
required MintlayerTxAckOutputWrapper tx = 1;

message MintlayerTxAckOutputWrapper {
required MintlayerTransferTxOutput output = 5;
required MintlayerTxOutput output = 5;
}
}
30 changes: 0 additions & 30 deletions core/embed/extmod/modtrezorcrypto/modtrezorcrypto-bip32.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "embed/rust/rust_ui_common.h"


#include "bip32.h"
#include "bip39.h"
#include "curves.h"
Expand Down Expand Up @@ -545,40 +544,11 @@ STATIC mp_obj_t mod_trezorcrypto_bip32_from_seed(mp_obj_t seed,
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_from_seed_obj,
mod_trezorcrypto_bip32_from_seed);

/// def mintlayer_from_seed(seed: bytes, curve_name: str) -> bytes:
/// """
/// Construct a BIP0032 HD node from a BIP0039 seed value.
/// """
STATIC mp_obj_t mod_trezorcrypto_bip32_mintlayer_from_seed(mp_obj_t seed,
mp_obj_t curve_name) {
vstr_t pkh = {0};
// uint32_t x = mintlayer_screen_fatal_error_rust(NULL, NULL, NULL);
// ((uint8_t *)pkh.buf)[0] = (uint8_t)x;
// ((uint8_t *)pkh.buf)[1] = (uint8_t)(x+1);

unsigned char hex[32] = {0};
hex[0] = 1;
hex[1] = 2;
ByteArray arr = mintlayer_encode_utxo_input(hex, 32, 10);
vstr_init_len(&pkh, arr.len);
int i = 0;
for (; i < arr.len; i++) {
((uint8_t *)pkh.buf)[i] = (uint8_t)arr.data[i];
}

return mp_obj_new_str_from_vstr(&mp_type_bytes, &pkh);
}
// TODO: add separate new file with mintlayer functions
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorcrypto_bip32_mintlayer_from_seed_obj,
mod_trezorcrypto_bip32_mintlayer_from_seed);

STATIC const mp_rom_map_elem_t mod_trezorcrypto_bip32_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bip32)},
{MP_ROM_QSTR(MP_QSTR_HDNode), MP_ROM_PTR(&mod_trezorcrypto_HDNode_type)},
{MP_ROM_QSTR(MP_QSTR_from_seed),
MP_ROM_PTR(&mod_trezorcrypto_bip32_from_seed_obj)},
{MP_ROM_QSTR(MP_QSTR_mintlayer_from_seed),
MP_ROM_PTR(&mod_trezorcrypto_bip32_mintlayer_from_seed_obj)},
};
STATIC MP_DEFINE_CONST_DICT(mod_trezorcrypto_bip32_globals,
mod_trezorcrypto_bip32_globals_table);
Expand Down
Loading

0 comments on commit 967640b

Please sign in to comment.