Skip to content

Commit

Permalink
feat(suite): support 258 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskp committed Dec 13, 2023
1 parent bfb4acb commit c6074b9
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
88 changes: 88 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,
use258Tag: false,
},
result: {
hash: 'e200b2c91f3493a1f3b9cfc8b6c141f70181741025e53941e9d57d22b1470c5c',
Expand All @@ -720,6 +721,43 @@ 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,
use258Tag: true,
},
result: {
// SHOULD FAIL
hash: 'e200b2c91f3493a1f3b9cfc8b6c141f70181741025e53941e9d57d22b1470c5c',
witnesses: [
{
type: 1,
pubKey: '5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1',
signature:
'79a357517a08c7256b0fab1e93a92a477386f4c2d72cea7bc68527c0133c32472305f010350665d72e8017bb6c2080b5742680ce7700bbddda561c917f294a07',
chainCode: null,
},
{
type: 1,
pubKey: 'bc65be1b0b9d7531778a1317c2aa6de936963c3f9ac7d5ee9e9eda25e0c97c5e',
signature:
'dca542910d0362fc22744e7a24732343db4e013495a7d9b47562886f09af8eb56ecaa105e20a9df3e4248fdab61dd91b6fb2a3bfc15d0d9a0442671c07e1ba02',
chainCode: null,
},
],
auxiliaryDataSupplement: undefined,
},
legacyResults: [legacyResults.beforeConway],
},

{
description: 'signStakeRegistrationNoOutputs',
params: {
Expand Down Expand Up @@ -2533,6 +2571,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],
use258Tag: 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
16 changes: 16 additions & 0 deletions packages/connect/src/api/cardano/api/cardanoSignTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const CardanoSignTransactionFeatures = Object.freeze({
Babbage: ['0', '2.5.2'],
CIP36Registration: ['0', '2.5.3'],
CIP36RegistrationExternalPaymentAddress: ['0', '2.5.4'],
Conway: ['0', '2.6.4'],
});

export type CardanoSignTransactionParams = {
Expand All @@ -73,6 +74,7 @@ export type CardanoSignTransactionParams = {
additionalWitnessRequests: Path[];
derivationType: PROTO.CardanoDerivationType;
includeNetworkId?: boolean;
use258Tag?: boolean;
unsignedTx?: { body: string; hash: string };
testnet?: boolean;
};
Expand Down Expand Up @@ -150,6 +152,7 @@ export default class CardanoSignTransaction extends AbstractMethod<
{ name: 'additionalWitnessRequests', type: 'array', allowEmpty: true },
{ name: 'derivationType', type: 'number' },
{ name: 'includeNetworkId', type: 'boolean' },
{ name: 'use258Tag', type: 'boolean' },
{ name: 'unsignedTx', type: 'object' },
{ name: 'testnet', type: 'boolean' },
]);
Expand Down Expand Up @@ -258,6 +261,7 @@ export default class CardanoSignTransaction extends AbstractMethod<
? payload.derivationType
: PROTO.CardanoDerivationType.ICARUS_TREZOR,
includeNetworkId: payload.includeNetworkId,
use258Tag: payload.use258Tag,
unsignedTx: 'unsignedTx' in payload ? payload.unsignedTx : undefined,
testnet: 'testnet' in payload ? payload.testnet : undefined,
};
Expand Down Expand Up @@ -290,6 +294,13 @@ export default class CardanoSignTransaction extends AbstractMethod<
if (certificate.key_hash) {
this._ensureFeatureIsSupported('KeyHashStakeCredential');
}
if (
certificate.type === PROTO.CardanoCertificateType.STAKE_REGISTRATION_CONWAY ||
certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY ||
certificate.type === PROTO.CardanoCertificateType.VOTE_DELEGATION
) {
this._ensureFeatureIsSupported('Conway');
}
});

params.outputsWithData.forEach(({ output }) => {
Expand Down Expand Up @@ -319,6 +330,10 @@ export default class CardanoSignTransaction extends AbstractMethod<
this._ensureFeatureIsSupported('NetworkIdInTxBody');
}

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

if (params.scriptDataHash) {
this._ensureFeatureIsSupported('ScriptDataHash');
}
Expand Down Expand Up @@ -397,6 +412,7 @@ export default class CardanoSignTransaction extends AbstractMethod<
reference_inputs_count: this.params.referenceInputs.length,
derivation_type: this.params.derivationType,
include_network_id: this.params.includeNetworkId,
use_258_tag: this.params.use258Tag,
};

// 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,
use258Tag: 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 @@ -224,6 +224,7 @@ export interface CardanoSignTransaction {
signingMode: PROTO.CardanoTxSigningMode;
derivationType?: PROTO.CardanoDerivationType;
includeNetworkId?: boolean;
use258Tag?: boolean;
}

export interface CardanoSignedTxWitness {
Expand Down

0 comments on commit c6074b9

Please sign in to comment.