Skip to content

Commit

Permalink
feat(connect): Add tag 258 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskp committed Jan 17, 2024
1 parent 05dea3a commit 28c615e
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/packages/connect/methods/cardanoSignTransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const result = await TrezorConnect.cardanoSignTransaction(params);
- `derivationType`_optional_ `CardanoDerivationType` enum. Determines used derivation type. Default is set to ICARUS_TREZOR=2.
- `includeNetworkId`_optional_ `Boolean`. Determines whether `networkId` should be explicitly serialized into the transaction body. Default is `false`.
- `chunkify`_optional_ `boolean` determines if recipient address will be displayed in chunks of 4 characters. Default is set to `false`
- `tagCborSets` - _optional_ `boolean` determines if CBOR arrays intended to be sets will be encoded with tag 258. Default is set to `false`

### CardanoTxSigningMode

Expand Down
87 changes: 87 additions & 0 deletions packages/connect/e2e/__fixtures__/cardanoSignTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ export default {
protocolMagic: PROTOCOL_MAGICS.mainnet,
networkId: NETWORK_IDS.mainnet,
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION,
tagCborSets: false,
},
result: {
hash: 'e200b2c91f3493a1f3b9cfc8b6c141f70181741025e53941e9d57d22b1470c5c',
Expand All @@ -720,6 +721,42 @@ export default {
legacyResults: [legacyResults.beforeConway],
},

{
description: 'signStakeRegistrationConwayWith258TaggedSets',
params: {
inputs: [SAMPLE_INPUTS.shelley_input],
outputs: [SAMPLE_OUTPUTS.simple_shelley_output],
fee: FEE,
ttl: TTL,
certificates: [SAMPLE_CERTIFICATES.stake_registration_conway],
protocolMagic: PROTOCOL_MAGICS.mainnet,
networkId: NETWORK_IDS.mainnet,
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION,
tagCborSets: true,
},
result: {
hash: '5e27f8fba938603411452a8cb373462fb64305539573b7a9edc9155be5cd6473',
witnesses: [
{
type: 1,
pubKey: '5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1',
signature:
'13c136487d8048ab7bbb081a324aa6b999e0b3237f956503b5446a4c409ec1062091b82e9e5459dee7ab0ba67ed874692d788872c8bbdb5ad4a3975c465fea09',
chainCode: null,
},
{
type: 1,
pubKey: 'bc65be1b0b9d7531778a1317c2aa6de936963c3f9ac7d5ee9e9eda25e0c97c5e',
signature:
'f0674db7194d8e04d7df416af8ad9dcf1b1203ca4b78f14c1e394d47418c8f7e95fd41a8f01c43eeeb39df6264359c865a41621fc1e6b540819b25c7c4df5803',
chainCode: null,
},
],
auxiliaryDataSupplement: undefined,
},
legacyResults: [legacyResults.beforeConway],
},

{
description: 'signStakeRegistrationNoOutputs',
params: {
Expand Down Expand Up @@ -2533,6 +2570,56 @@ export default {
legacyResults: [legacyResults.beforePlutus],
},

{
description: 'plutusWithRequiredSignersAndReferenceInputAnd258TaggedSets',
params: {
inputs: [SAMPLE_INPUTS.shelley_input],
outputs: [SAMPLE_OUTPUTS.simple_shelley_output],
fee: FEE,
ttl: TTL,
protocolMagic: PROTOCOL_MAGICS.mainnet,
networkId: NETWORK_IDS.mainnet,
signingMode: CardanoTxSigningMode.PLUTUS_TRANSACTION,
scriptDataHash: SCRIPT_DATA_HASH,
collateralInputs: [SAMPLE_INPUTS.shelley_input_2],
requiredSigners: [
{ keyPath: "m/1852'/1815'/0'/0/0" },
{ keyPath: "m/1854'/1815'/0'/0/0" },
{ keyHash: '3a7f09d3df4cf66a7399c2b05bfa234d5a29560c311fc5db4c490711' },
],
referenceInput: [SAMPLE_INPUTS.plutus_input],
tagCborSets: true,
},
result: {
hash: 'eee852948723773f059bbbc9f4378473e339a62ec518ac3aeb8ecdf27abf8581',
witnesses: [
{
type: 1,
pubKey: '5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1',
signature:
'ccf25b4926d4ea953f9330196f881ec6974b3979a05fd679e846eb0fd90f5e5d64cdba51fad9354a50343a29c09dfda8177fd1717ca8d105c9d923a31071b909',
chainCode: null,
},
{
type: 1,
pubKey: '36a8ef21d5b98fdf23a27325cf643deaac35e912c835e35037f23d1061ae5b16',
signature:
'39231ff0df125987c5a7583f307d74d3bdcb9702baafc8588aa16002d19d595725da64518603bb0617bfba851fe96f0cf75c19d75b0749443e09fdc8aebb4603',
chainCode: null,
},
{
type: 1,
pubKey: 'b10be5c0d11ad8292bbe69e220ca0cfbe154610b3041a8e72f9d515c226ab3b1',
signature:
'e78e5a21c07ed5f613d01d20f9684a3b807b30ca211f69a2a0391ab3137d3b1260c51bdf08079e213e2487f3b8c36d6b42d7d15733113cf725ca3f162f030001',
chainCode: null,
},
],
auxiliaryDataSupplement: undefined,
},
legacyResults: [legacyResults.beforeConway],
},

{
description: 'plutusWithManyWitnesses',
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type CardanoSignTransactionParams = {
additionalWitnessRequests: Path[];
derivationType: PROTO.CardanoDerivationType;
includeNetworkId?: boolean;
tagCborSets?: boolean;
unsignedTx?: { body: string; hash: string };
testnet?: boolean;
chunkify?: boolean;
Expand Down Expand Up @@ -231,6 +232,7 @@ export default class CardanoSignTransaction extends AbstractMethod<
? payload.derivationType
: PROTO.CardanoDerivationType.ICARUS_TREZOR,
includeNetworkId: payload.includeNetworkId,
tagCborSets: payload.tagCborSets,
unsignedTx: 'unsignedTx' in payload ? payload.unsignedTx : undefined,
testnet: 'testnet' in payload ? payload.testnet : undefined,
chunkify: typeof payload.chunkify === 'boolean' ? payload.chunkify : false,
Expand Down Expand Up @@ -300,6 +302,10 @@ export default class CardanoSignTransaction extends AbstractMethod<
this._ensureFeatureIsSupported('NetworkIdInTxBody');
}

if (params.tagCborSets) {
this._ensureFeatureIsSupported('Conway');
}

if (params.scriptDataHash) {
this._ensureFeatureIsSupported('ScriptDataHash');
}
Expand Down Expand Up @@ -379,6 +385,7 @@ export default class CardanoSignTransaction extends AbstractMethod<
derivation_type: this.params.derivationType,
include_network_id: this.params.includeNetworkId,
chunkify: this.params.chunkify,
tag_cbor_sets: this.params.tagCborSets,
};

// init
Expand Down
1 change: 1 addition & 0 deletions packages/connect/src/types/api/__tests__/cardano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export const cardanoSignTransaction = async (api: TrezorConnect) => {
networkId: 0,
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION,
includeNetworkId: false,
tagCborSets: false,
});

if (sign.success) {
Expand Down
1 change: 1 addition & 0 deletions packages/connect/src/types/api/cardano/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const CardanoSignTransaction = Type.Object({
derivationType: Type.Optional(PROTO.EnumCardanoDerivationType),
includeNetworkId: Type.Optional(Type.Boolean()),
chunkify: Type.Optional(Type.Boolean()),
tagCborSets: Type.Optional(Type.Boolean()),
});

export type CardanoSignTransactionExtended = Static<typeof CardanoSignTransactionExtended>;
Expand Down
7 changes: 7 additions & 0 deletions packages/protobuf/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,13 @@
"chunkify": {
"type": "bool",
"id": 22
},
"tag_cbor_sets": {
"type": "bool",
"id": 23,
"options": {
"default": false
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/protobuf/src/messages-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ export const CardanoSignTxInit = Type.Object({
total_collateral: Type.Optional(Type.Uint()),
reference_inputs_count: Type.Optional(Type.Number()),
chunkify: Type.Optional(Type.Boolean()),
tag_cbor_sets: Type.Optional(Type.Boolean()),
});

export type CardanoTxInput = Static<typeof CardanoTxInput>;
Expand Down
1 change: 1 addition & 0 deletions packages/protobuf/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ export type CardanoSignTxInit = {
total_collateral?: UintType;
reference_inputs_count?: number;
chunkify?: boolean;
tag_cbor_sets?: boolean;
};

// CardanoTxInput
Expand Down

0 comments on commit 28c615e

Please sign in to comment.