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

Stellar: add support for StellarManageBuyOfferOp and StellarPathPaymentStrictSendOp. #1838

Merged
merged 6 commits into from
Nov 4, 2021
Merged
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
58 changes: 45 additions & 13 deletions common/protob/messages-stellar.proto
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ message StellarSignTx {
* Response: device is ready for client to send the next operation
* @next StellarPaymentOp
* @next StellarCreateAccountOp
* @next StellarPathPaymentOp
* @next StellarManageOfferOp
* @next StellarCreatePassiveOfferOp
* @next StellarPathPaymentStrictReceiveOp
* @next StellarPathPaymentStrictSendOp
* @next StellarManageSellOfferOp
* @next StellarManageBuyOfferOp
* @next StellarCreatePassiveSellOfferOp
* @next StellarSetOptionsOp
* @next StellarChangeTrustOp
* @next StellarAllowTrustOp
Expand Down Expand Up @@ -115,22 +117,52 @@ message StellarCreateAccountOp {
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarPathPaymentOp {
optional string source_account = 1; // (optional) source address
required StellarAsset send_asset = 2;
required sint64 send_max = 3;
required string destination_account = 4;
required StellarAsset destination_asset = 5;
required sint64 destination_amount = 6;
repeated StellarAsset paths = 7;
message StellarPathPaymentStrictReceiveOp {
optional string source_account = 1; // (optional) source address
required StellarAsset send_asset = 2; // asset we pay with
required sint64 send_max = 3; // the maximum amount of sendAsset to send (excluding fees)
required string destination_account = 4; // recipient of the payment
required StellarAsset destination_asset = 5; // what they end up with
required sint64 destination_amount = 6; // amount they end up with
repeated StellarAsset paths = 7; // additional hops it must go through to get there
}

/**
* Request: ask device to confirm this operation type
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarManageOfferOp {
message StellarPathPaymentStrictSendOp {
optional string source_account = 1; // (optional) source address
required StellarAsset send_asset = 2; // asset we pay with
required sint64 send_amount = 3; // amount of sendAsset to send (excluding fees)
required string destination_account = 4; // recipient of the payment
required StellarAsset destination_asset = 5; // what they end up with
required sint64 destination_min = 6; // the minimum amount of dest asset to be received
repeated StellarAsset paths = 7; //additional hops it must go through to get there
}

/**
* Request: ask device to confirm this operation type
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarManageSellOfferOp {
optional string source_account = 1; // (optional) source account address
required StellarAsset selling_asset = 2;
required StellarAsset buying_asset = 3;
required sint64 amount = 4;
required uint32 price_n = 5; // Price numerator
required uint32 price_d = 6; // Price denominator
required uint64 offer_id = 7; // Offer ID for updating an existing offer
}

/**
* Request: ask device to confirm this operation type
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarManageBuyOfferOp {
optional string source_account = 1; // (optional) source account address
required StellarAsset selling_asset = 2;
required StellarAsset buying_asset = 3;
Expand All @@ -145,7 +177,7 @@ message StellarManageOfferOp {
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarCreatePassiveOfferOp {
message StellarCreatePassiveSellOfferOp {
optional string source_account = 1; // (optional) source account address
required StellarAsset selling_asset = 2;
required StellarAsset buying_asset = 3;
Expand Down
8 changes: 5 additions & 3 deletions common/protob/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,18 @@ enum MessageType {
MessageType_StellarAddress = 208 [(wire_out) = true];
MessageType_StellarCreateAccountOp = 210 [(wire_in) = true];
MessageType_StellarPaymentOp = 211 [(wire_in) = true];
MessageType_StellarPathPaymentOp = 212 [(wire_in) = true];
MessageType_StellarManageOfferOp = 213 [(wire_in) = true];
MessageType_StellarCreatePassiveOfferOp = 214 [(wire_in) = true];
MessageType_StellarPathPaymentStrictReceiveOp = 212 [(wire_in) = true];
MessageType_StellarManageSellOfferOp = 213 [(wire_in) = true];
MessageType_StellarCreatePassiveSellOfferOp = 214 [(wire_in) = true];
MessageType_StellarSetOptionsOp = 215 [(wire_in) = true];
MessageType_StellarChangeTrustOp = 216 [(wire_in) = true];
MessageType_StellarAllowTrustOp = 217 [(wire_in) = true];
MessageType_StellarAccountMergeOp = 218 [(wire_in) = true];
// omitted: StellarInflationOp is not a supported operation, would be 219
MessageType_StellarManageDataOp = 220 [(wire_in) = true];
MessageType_StellarBumpSequenceOp = 221 [(wire_in) = true];
MessageType_StellarManageBuyOfferOp = 222 [(wire_in) = true];
MessageType_StellarPathPaymentStrictSendOp = 223 [(wire_in) = true];
MessageType_StellarSignedTx = 230 [(wire_out) = true];

// Cardano
Expand Down
103 changes: 96 additions & 7 deletions common/tests/fixtures/stellar/sign_tx.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
}
},
{
"name": "StellarCreatePassiveOfferOp",
"name": "StellarCreatePassiveSellOfferOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAABAAAAAJBQkNERUZHSElKS0wAAAAAKYSWAsIOWDZfEjwS2HocpFUNEM0hsK4OGNROPlb9ahUAAAABWAAAAAAAAAAphJYCwg5YNl8SPBLYehykVQ0QzSGwrg4Y1E4+Vv1qFQAAAAAdzxaYAAAAAwAAAAQAAAAAAAAAAA==",
"address_n": "m/44'/148'/0'",
Expand All @@ -313,7 +313,7 @@
},
"operations": [
{
"_message_type": "StellarCreatePassiveOfferOp",
"_message_type": "StellarCreatePassiveSellOfferOp",
"selling_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
Expand All @@ -336,7 +336,46 @@
}
},
{
"name": "StellarManageOfferOp",
"name": "StellarManageBuyOfferOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAADAAAAAJBQkNERUZHSElKS0wAAAAAKYSWAsIOWDZfEjwS2HocpFUNEM0hsK4OGNROPlb9ahUAAAABWAAAAAAAAABwi6oxX35cFm2EtGS/s4/WJXj+OtJyJ+dsy7ehecRRIQAAAAAdzxaYAAAAAwAAAAQAAAAAAAAFOQAAAAAAAAAA",
"address_n": "m/44'/148'/0'",
"network_passphrase": "Test SDF Network ; September 2015",
"tx": {
"source_account": "GAXSFOOGF4ELO5HT5PTN23T5XE6D5QWL3YBHSVQ2HWOFEJNYYMRJENBV",
"fee": 100,
"sequence_number": 1000,
"timebounds_start": 461535181,
"timebounds_end": 1575234180,
"memo_type": "NONE"
},
"operations": [
{
"_message_type": "StellarManageBuyOfferOp",
"selling_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
"issuer": "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
},
"buying_asset": {
"type": "ALPHANUM4",
"code": "X",
"issuer": "GBYIXKRRL57FYFTNQS2GJP5TR7LCK6H6HLJHEJ7HNTF3PILZYRISDLNQ"
},
"amount": 500111000,
"price_n": 3,
"price_d": 4,
"offer_id": 1337
}
]
},
"result": {
"public_key": "2f22b9c62f08b774f3ebe6dd6e7db93c3ec2cbde0279561a3d9c5225b8c32292",
"signature": "sDQuKEm7j6Lsuw+QUTrotSloZiF+8LrXsuoLCBadewWpArO8+qmMgonrG3bJfaZ4dYdD8WcpfP5LNLOfU+lDBA=="
overcat marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"name": "StellarManageSellOfferOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAAAwAAAAJBQkNERUZHSElKS0wAAAAAKYSWAsIOWDZfEjwS2HocpFUNEM0hsK4OGNROPlb9ahUAAAABWAAAAAAAAAAphJYCwg5YNl8SPBLYehykVQ0QzSGwrg4Y1E4+Vv1qFQAAAAAdzxaYAAAAAwAAAAQAAAAAAAAFOQAAAAAAAAAA",
"address_n": "m/44'/148'/0'",
Expand All @@ -351,7 +390,7 @@
},
"operations": [
{
"_message_type": "StellarManageOfferOp",
"_message_type": "StellarManageSellOfferOp",
"selling_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
Expand All @@ -375,7 +414,7 @@
}
},
{
"name": "StellarPathPaymentOp",
"name": "StellarPathPaymentStrictReceiveOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAAAgAAAAFYAAAAAAAAACmElgLCDlg2XxI8Eth6HKRVDRDNIbCuDhjUTj5W/WoVAAAAAB3PFpgAAAAAXVVkJGaxhbhDFS6eIZFR28WJICfsQBAaUXvtXKAwwuAAAAACQUJDREVGR0hJSktMAAAAACmElgLCDlg2XxI8Eth6HKRVDRDNIbCuDhjUTj5W/WoVAAAAAAAB4kAAAAAAAAAAAAAAAAA=",
"address_n": "m/44'/148'/0'",
Expand All @@ -390,7 +429,7 @@
},
"operations": [
{
"_message_type": "StellarPathPaymentOp",
"_message_type": "StellarPathPaymentStrictReceiveOp",
"send_asset": {
"type": "ALPHANUM4",
"code": "X",
Expand All @@ -412,6 +451,56 @@
"signature": "A/ccrRMTEy3GXaZ7Lo5frX3ME5fy3bDMrmYaZ8oPtpPk+cnRStbcSAgdTKnRq/dPGRLfh2btvPJD9ETMe1ajDA=="
}
},
{
"name": "StellarPathPaymentStrictSendOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAADQAAAAFYAAAAAAAAAHCLqjFfflwWbYS0ZL+zj9YleP460nIn52zLt6F5xFEhAAAAAB3PFpgAAAAAXVVkJGaxhbhDFS6eIZFR28WJICfsQBAaUXvtXKAwwuAAAAACQUJDREVGR0hJSktMAAAAACmElgLCDlg2XxI8Eth6HKRVDRDNIbCuDhjUTj5W/WoVAAAAAAAB4kAAAAACAAAAAUpQWQAAAAAA/Pr8d4Jv8Bq3LDTJiXMR/LjsnkO0R2sDyP5fodnIhB4AAAACQkFOQU5BAAAAAAAAAAAAAL5FO387ZKhuvo51/hHfkV1gShE677dHpUZV6jK+Wgg7AAAAAAAAAAA=",
"address_n": "m/44'/148'/0'",
"network_passphrase": "Test SDF Network ; September 2015",
"tx": {
"source_account": "GAXSFOOGF4ELO5HT5PTN23T5XE6D5QWL3YBHSVQ2HWOFEJNYYMRJENBV",
"fee": 100,
"sequence_number": 1000,
"timebounds_start": 461535181,
"timebounds_end": 1575234180,
"memo_type": "NONE"
},
"operations": [
{
"_message_type": "StellarPathPaymentStrictSendOp",
"send_asset": {
"type": "ALPHANUM4",
"code": "X",
"issuer": "GBYIXKRRL57FYFTNQS2GJP5TR7LCK6H6HLJHEJ7HNTF3PILZYRISDLNQ"
},
"send_amount": 500111000,
"destination_account": "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V",
"destination_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
"issuer": "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
},
"destination_min": 123456,
"paths": [
{
"type": "ALPHANUM4",
"code": "JPY",
"issuer": "GD6PV7DXQJX7AGVXFQ2MTCLTCH6LR3E6IO2EO2YDZD7F7IOZZCCB5DSQ"
},
{
"type": "ALPHANUM12",
"code": "BANANA",
"issuer": "GC7EKO37HNSKQ3V6RZ274EO7SFOWASQRHLX3OR5FIZK6UMV6LIEDXHGZ"
}
]
}
]
},
"result": {
"public_key": "2f22b9c62f08b774f3ebe6dd6e7db93c3ec2cbde0279561a3d9c5225b8c32292",
"signature": "ZoJRiq9zQsbv/w5CA4IOqRPsPY46kzrQ0uMgY+Y9Ec6kKk/0ktFt2icEKNvVAKZUYmfEEigKhki/Rt9meN43CQ=="
overcat marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"name": "StellarManageDataOp",
"parameters": {
Expand Down Expand Up @@ -799,7 +888,7 @@
"starting_balance": 100000000
},
{
"_message_type": "StellarCreatePassiveOfferOp",
"_message_type": "StellarCreatePassiveSellOfferOp",
"selling_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
Expand Down
1 change: 1 addition & 0 deletions core/.changelog.d/1838.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stellar: add support for StellarManageBuyOfferOp and StellarPathPaymentStrictSendOp.
1 change: 1 addition & 0 deletions core/.changelog.d/1838.incompatible
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Stellar: rename StellarManageOfferOp to StellarManageSellOfferOp, StellarPathPaymentOp to StellarPathPaymentStrictReceiveOp and StellarCreatePassiveOfferOp to StellarCreatePassiveSellOfferOp.
8 changes: 5 additions & 3 deletions core/src/apps/stellar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ Stellar transaction is composed of one or more operations. We support all [opera
- Bump Sequence
- Change Trust
- Create Account
- Create Passive Offer
- Create Passive Sell Offer
- Manage Data
- Manage Offer
- Path Payment
- Manage Buy Offer
- Manage Sell Offer
- Path Payment Strict Receive
- Path Payment Strict Send
- Payment
- Set Options

Expand Down
34 changes: 21 additions & 13 deletions core/src/apps/stellar/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
StellarBumpSequenceOp,
StellarChangeTrustOp,
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarCreatePassiveSellOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageBuyOfferOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPathPaymentStrictSendOp,
StellarPaymentOp,
StellarSetOptionsOp,
)
Expand All @@ -26,29 +28,33 @@
StellarBumpSequenceOp,
StellarChangeTrustOp,
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarCreatePassiveSellOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageBuyOfferOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPathPaymentStrictSendOp,
StellarPaymentOp,
StellarSetOptionsOp,
]


TX_TYPE = b"\x00\x00\x00\x02"

# source: https://github.com/stellar/go/blob/3d2c1defe73dbfed00146ebe0e8d7e07ce4bb1b6/xdr/Stellar-transaction.x#L16
# source: https://github.com/stellar/go/blob/a1db2a6b1f/xdr/Stellar-transaction.x#L35
# Inflation not supported see https://github.com/trezor/trezor-core/issues/202#issuecomment-393342089
op_codes: dict[int, int] = {
MessageType.StellarAccountMergeOp: 8,
MessageType.StellarAllowTrustOp: 7,
MessageType.StellarBumpSequenceOp: 11,
MessageType.StellarChangeTrustOp: 6,
MessageType.StellarCreateAccountOp: 0,
MessageType.StellarCreatePassiveOfferOp: 4,
MessageType.StellarCreatePassiveSellOfferOp: 4,
MessageType.StellarManageDataOp: 10,
MessageType.StellarManageOfferOp: 3,
MessageType.StellarPathPaymentOp: 2,
MessageType.StellarManageBuyOfferOp: 12,
MessageType.StellarManageSellOfferOp: 3,
MessageType.StellarPathPaymentStrictReceiveOp: 2,
MessageType.StellarPathPaymentStrictSendOp: 13,
MessageType.StellarPaymentOp: 1,
MessageType.StellarSetOptionsOp: 5,
}
Expand All @@ -59,10 +65,12 @@
MessageType.StellarBumpSequenceOp,
MessageType.StellarChangeTrustOp,
MessageType.StellarCreateAccountOp,
MessageType.StellarCreatePassiveOfferOp,
MessageType.StellarCreatePassiveSellOfferOp,
MessageType.StellarManageDataOp,
MessageType.StellarManageOfferOp,
MessageType.StellarPathPaymentOp,
MessageType.StellarManageBuyOfferOp,
MessageType.StellarManageSellOfferOp,
MessageType.StellarPathPaymentStrictReceiveOp,
MessageType.StellarPathPaymentStrictSendOp,
MessageType.StellarPaymentOp,
MessageType.StellarSetOptionsOp,
]
Expand Down
24 changes: 15 additions & 9 deletions core/src/apps/stellar/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,24 @@ async def process_operation(
elif serialize.StellarCreateAccountOp.is_type_of(op):
await layout.confirm_create_account_op(ctx, op)
serialize.write_create_account_op(w, op)
elif serialize.StellarCreatePassiveOfferOp.is_type_of(op):
await layout.confirm_create_passive_offer_op(ctx, op)
serialize.write_create_passive_offer_op(w, op)
elif serialize.StellarCreatePassiveSellOfferOp.is_type_of(op):
await layout.confirm_create_passive_sell_offer_op(ctx, op)
serialize.write_create_passive_sell_offer_op(w, op)
elif serialize.StellarManageDataOp.is_type_of(op):
await layout.confirm_manage_data_op(ctx, op)
serialize.write_manage_data_op(w, op)
elif serialize.StellarManageOfferOp.is_type_of(op):
await layout.confirm_manage_offer_op(ctx, op)
serialize.write_manage_offer_op(w, op)
elif serialize.StellarPathPaymentOp.is_type_of(op):
await layout.confirm_path_payment_op(ctx, op)
serialize.write_path_payment_op(w, op)
elif serialize.StellarManageBuyOfferOp.is_type_of(op):
await layout.confirm_manage_buy_offer_op(ctx, op)
serialize.write_manage_buy_offer_op(w, op)
elif serialize.StellarManageSellOfferOp.is_type_of(op):
await layout.confirm_manage_sell_offer_op(ctx, op)
serialize.write_manage_sell_offer_op(w, op)
elif serialize.StellarPathPaymentStrictReceiveOp.is_type_of(op):
await layout.confirm_path_payment_strict_receive_op(ctx, op)
serialize.write_path_payment_strict_receive_op(w, op)
elif serialize.StellarPathPaymentStrictSendOp.is_type_of(op):
await layout.confirm_path_payment_strict_send_op(ctx, op)
serialize.write_path_payment_strict_send_op(w, op)
elif serialize.StellarPaymentOp.is_type_of(op):
await layout.confirm_payment_op(ctx, op)
serialize.write_payment_op(w, op)
Expand Down
Loading