Skip to content

Commit 71cd456

Browse files
fixup! fix(trezor): fix output format mapping on trezor HW devices
1 parent d187f4a commit 71cd456

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

packages/hardware-trezor/src/TrezorKeyAgent.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -237,37 +237,6 @@ export class TrezorKeyAgent extends KeyAgentBase {
237237
return Trezor.PROTO.CardanoTxSigningMode.ORDINARY_TRANSACTION;
238238
}
239239

240-
/**
241-
* There are currently two types of outputs supported by the ledger:
242-
*
243-
* legacy_transaction_output =
244-
* [ address
245-
* , amount : value
246-
* , ? datum_hash : $hash32
247-
* ]
248-
*
249-
* and
250-
*
251-
* post_alonzo_transaction_output =
252-
* { 0 : address
253-
* , 1 : value
254-
* , ? 2 : datum_option ; New; datum option
255-
* , ? 3 : script_ref ; New; script reference
256-
* }
257-
*
258-
* Legacy outputs are definite length arrays of three elements, however the new babbage outputs are definite length maps
259-
* of four elements.
260-
*
261-
* @param outputs The outputs to be verified.
262-
*/
263-
hasBabbageOutput(outputs: Array<Serialization.TransactionOutput>): boolean {
264-
if (outputs.length === 0) return false;
265-
266-
const reader = new Serialization.CborReader(outputs[0].toCbor());
267-
268-
return reader.peekState() === Serialization.CborReaderState.StartMap;
269-
}
270-
271240
async signTransaction(
272241
txBody: Serialization.TransactionBody,
273242
{ knownAddresses, txInKeyPathMap, scripts }: SignTransactionContext
@@ -283,7 +252,7 @@ export class TrezorKeyAgent extends KeyAgentBase {
283252
knownAddresses,
284253
tagCborSets: txBody.hasTaggedSets(),
285254
txInKeyPathMap,
286-
useBabbageOutputs: this.hasBabbageOutput(txBody.outputs())
255+
useBabbageOutputs: txBody.hasBabbageOutput()
287256
});
288257

289258
const signingMode = TrezorKeyAgent.matchSigningMode(trezorTxData);

packages/hardware-trezor/test/transformers/tx.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ describe('tx', () => {
204204
...contextWithKnownAddresses,
205205
txInKeyPathMap: {
206206
[TxInId(babbageTxBodyWithScripts.inputs[0])]: knownAddressPaymentKeyPath
207-
}
207+
},
208+
useBabbageOutputs: true
208209
})
209210
).toEqual({
210211
additionalWitnessRequests: [
@@ -327,7 +328,8 @@ describe('tx', () => {
327328
txInKeyPathMap: {
328329
[TxInId(plutusTxWithBabbage.inputs[0])]: knownAddressPaymentKeyPath,
329330
[TxInId(plutusTxWithBabbage.collaterals[0])]: knownAddressPaymentKeyPath
330-
}
331+
},
332+
useBabbageOutputs: true
331333
})
332334
).toEqual({
333335
additionalWitnessRequests: [
@@ -361,7 +363,7 @@ describe('tx', () => {
361363
address:
362364
'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp',
363365
amount: '10',
364-
format: Trezor.PROTO.CardanoTxOutputSerializationFormat.ARRAY_LEGACY
366+
format: Trezor.PROTO.CardanoTxOutputSerializationFormat.MAP_BABBAGE
365367
},
366368
fee: '10',
367369
inputs: [

0 commit comments

Comments
 (0)