Skip to content

Commit

Permalink
Merge pull request #3815 from Emurgo/release/5.4.600
Browse files Browse the repository at this point in the history
Release / 5.4.600
  • Loading branch information
vsubhuman authored Jan 23, 2025
2 parents 965698c + 91d1357 commit 73b582c
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 398 deletions.
13 changes: 12 additions & 1 deletion packages/yoroi-extension/app/api/ada/lib/cardanoCrypto/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { RustModule } from './rustLoader';
import { bytesToHex, fail, forceNonNull, hexToBytes, maybe } from '../../../../coreUtils';
import { bytesToHex, fail, forceNonNull, hexToBytes, iterateLenGet, maybe } from '../../../../coreUtils';
import { base32ToHex, hexToBase32 } from '../storage/bridge/utils';

export function v4PublicToV2(
Expand Down Expand Up @@ -52,6 +52,17 @@ export function transactionHexReplaceWitnessSet(txHex: string, witnessSetHex: st
});
}

export function transactionHexAddVkeyWitnessesFromWitnessSetHex(txHex: string, witnessSetHex: string): string {
return RustModule.WasmScope(Module => {
const fixedTransaction = Module.WalletV4.FixedTransaction.from_hex(txHex);
const witnessSet = Module.WalletV4.TransactionWitnessSet.from_hex(witnessSetHex);
for (const vkeyWitness of iterateLenGet(witnessSet.vkeys())) {
fixedTransaction.add_vkey_witness(vkeyWitness);
}
return fixedTransaction.to_hex();
});
}

export function dRepToMaybeCredentialHex(s: string): ?string {
const isPotentiallyValidHex = /^(22|23)[0-9a-fA-F]{56}$/.test(s);
return RustModule.WasmScope(Module => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ test('Create Ledger transaction', async () => {
txBuilder.add_output(
RustModule.WalletV4.TransactionOutput.new(
RustModule.WalletV4.Address.from_hex(byronAddrToHex('Ae2tdPwUPEZAVDjkPPpwDhXMSAjH53CDmd2xMwuR9tZMAZWxLhFphrHKHXe')),
RustModule.WalletV4.Value.new(RustModule.WalletV4.BigNum.from_str('5326134'))
RustModule.WalletV4.Value.new(RustModule.WalletV4.BigNum.from_str('6323634'))
)
);
const certs = RustModule.WalletV4.Certificates.new();
Expand All @@ -296,7 +296,7 @@ test('Create Ledger transaction', async () => {
RustModule.WalletV4.StakeRegistration.new(stakeCredential)
));
txBuilder.set_certs(certs);
txBuilder.set_fee(RustModule.WalletV4.BigNum.from_str('1000'));
txBuilder.set_fee(RustModule.WalletV4.BigNum.from_str('2000'));
txBuilder.set_ttl(500);

const baseConfig = network.BaseConfig
Expand Down Expand Up @@ -356,7 +356,7 @@ test('Create Ledger transaction', async () => {
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
tx: {
fee: '1000',
fee: '2000',
ttl: '500',
scriptDataHashHex: null,
network: {
Expand Down Expand Up @@ -411,7 +411,7 @@ test('Create Ledger transaction', async () => {
},
type: TxOutputDestinationType.THIRD_PARTY,
},
amount: `5326134`,
amount: `6323634`,
datumHashHex: null,
tokenBundle: null,
}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ import {
import { TxBuilder, SendRequest } from '@emurgo/yoroi-eutxo-txs/dist/tx-builder'
import blake2b from 'blake2b';
import { derivePrivateByAddressing } from '../../lib/cardanoCrypto/deriveByAddressing';
import type { TxMint } from '@emurgo/yoroi-eutxo-txs/dist/tx-builder';


// <TODO:FETCH> unmagic this
const COSMODELS = 'a30098a61a000189b41901a401011903e818ad00011903e819ea350401192baf18201a000312591920a404193e801864193e801864193e801864193e801864193e801864193e80186418641864193e8018641a000170a718201a00020782182019f016041a0001194a18b2000119568718201a0001643519030104021a00014f581a00037c71187a0001011903e819a7a90402195fe419733a1826011a000db464196a8f0119ca3f19022e011999101903e819ecb2011a00022a4718201a000144ce1820193bc318201a0001291101193371041956540a197147184a01197147184a0119a9151902280119aecd19021d0119843c18201a00010a9618201a00011aaa1820191c4b1820191cdf1820192d1a18201a00014f581a00037c71187a0001011a0001614219020700011a000122c118201a00014f581a00037c71187a0001011a00014f581a00037c71187a0001011a0004213c19583c041a00163cad19fc3604194ff30104001a00022aa818201a000189b41901a401011a00013eff182019e86a1820194eae182019600c1820195108182019654d182019602f18201a032e93af1937fd0a0198af1a000189b41901a401011903e818ad00011903e819ea350401192baf18201a000312591920a404193e801864193e801864193e801864193e801864193e801864193e80186418641864193e8018641a000170a718201a00020782182019f016041a0001194a18b2000119568718201a0001643519030104021a00014f581a00037c71187a0001011903e819a7a90402195fe419733a1826011a000db464196a8f0119ca3f19022e011999101903e819ecb2011a00022a4718201a000144ce1820193bc318201a0001291101193371041956540a197147184a01197147184a0119a9151902280119aecd19021d0119843c18201a00010a9618201a00011aaa1820191c4b1820191cdf1820192d1a18201a00014f581a00037c71187a0001011a0001614219020700011a000122c118201a00014f581a00037c71187a0001011a00014f581a00037c71187a0001011a000e94721a0003414000021a0004213c19583c041a00163cad19fc3604194ff30104001a00022aa818201a000189b41901a401011a00013eff182019e86a1820194eae182019600c1820195108182019654d182019602f18201a0290f1e70a1a032e93af1937fd0a1a0298e40b1966c40a029901291a000189b41901a401011903e818ad00011903e819ea350401192baf18201a000312591920a404193e801864193e801864193e801864193e801864193e801864193e80186418641864193e8018641a000170a718201a00020782182019f016041a0001194a18b2000119568718201a0001643519030104021a00014f581a0001e143191c893903831906b419022518391a00014f580001011903e819a7a90402195fe419733a1826011a000db464196a8f0119ca3f19022e011999101903e819ecb2011a00022a4718201a000144ce1820193bc318201a0001291101193371041956540a197147184a01197147184a0119a9151902280119aecd19021d0119843c18201a00010a9618201a00011aaa1820191c4b1820191cdf1820192d1a18201a00014f581a0001e143191c893903831906b419022518391a00014f5800011a0001614219020700011a000122c118201a00014f581a0001e143191c893903831906b419022518391a00014f580001011a00014f581a0001e143191c893903831906b419022518391a00014f5800011a000e94721a0003414000021a0004213c19583c041a00163cad19fc3604194ff30104001a00022aa818201a000189b41901a401011a00013eff182019e86a1820194eae182019600c1820195108182019654d182019602f18201a0290f1e70a1a032e93af1937fd0a1a0298e40b1966c40a193e801864193e8018641a000eaf1f121a002a6e06061a0006be98011a0321aac7190eac121a00041699121a048e466e1922a4121a0327ec9a121a001e743c18241a0031410f0c1a000dbf9e011a09f2f6d31910d318241a0004578218241a096e44021967b518241a0473cee818241a13e62472011a0f23d40118481a00212c5618481a0022814619fc3b041a00032b00192076041a0013be0419702c183f00011a000f59d919aa6718fb00011a000187551902d61902cf00011a000187551902d61902cf00011a000187551902d61902cf00011a0001a5661902a800011a00017468011a00044a391949a000011a0002bfe2189f01011a00026b371922ee00011a00026e9219226d00011a0001a3e2190ce2011a00019e4919028f011a001df8bb195fc803';

/**
* based off what the cardano-wallet team found worked empirically
Expand All @@ -61,12 +66,6 @@ export type TxOutput = {|
data?: string,
|};

type TxMint = {|
policyScript: string, // HEX of the WASM policy script,
assetName: string, // HEX
amount: string,
|};

type TxAuxiliaryData = {|
metadata: ?TxMetadata,
nativeScripts: ?Array<string>,
Expand Down Expand Up @@ -679,12 +678,13 @@ export async function newAdaUnsignedTxFromUtxo(
WalletType.Shelley,
{
path: changeAdaAddr.addressing.path,
// $FlowIgnore
start: changeAdaAddr.addressing.startLevel,
}
);

if (extraWitnessDatumsPresent) {
await txBuilder.calcScriptDataHash('default');
await txBuilder.calcScriptDataHash(COSMODELS);
}

await txBuilder.addChangeAndFee(changeAddress);
Expand All @@ -701,11 +701,15 @@ export async function newAdaUnsignedTxFromUtxo(

const signRequestChangeAddr = [];
if (unsignedTx.change) {
const spendingKeyInfo = unsignedTx.change.address.spendingKeyInfo;
if (spendingKeyInfo == null) {
throw new Error('Missing spendingKeyInfo in change address');
}
signRequestChangeAddr.push({
address: unsignedTx.change.address.hex,
addressing: {
path: unsignedTx.change.address.spendingKeyInfo.path,
startLevel: unsignedTx.change.address.spendingKeyInfo.start,
path: spendingKeyInfo.path,
startLevel: spendingKeyInfo.start,
},
values: libValueToMultiToken(
unsignedTx.change.value,
Expand All @@ -716,7 +720,9 @@ export async function newAdaUnsignedTxFromUtxo(
}
const utxosMap = new Map(utxos.map(u => [u.utxo_id, u]));
return {
// $FlowIgnore
senderUtxos: unsignedTx.inputs.asArray().map(u => utxosMap.get(u.tx + u.index)),
// $FlowIgnore
txBuilder: unsignedTx.builder.wasm,
changeAddr: signRequestChangeAddr,
};
Expand Down Expand Up @@ -866,6 +872,7 @@ async function newAdaUnsignedTxFromUtxoForConnector(
setRuntime(RustModule.CrossCsl.init);

const defaultNetworkConfig = {
networkId,
linearFee: {
coefficient: protocolParams.linearFeeCoefficient,
constant: protocolParams.linearFeeConstant,
Expand All @@ -892,6 +899,7 @@ async function newAdaUnsignedTxFromUtxoForConnector(
const txBuilder = await TxBuilder.new(defaultNetworkConfig, utxoSet);

await txBuilder.addRequiredInputs(
// $FlowIgnore
await Promise.all(
mustIncludeUtxos.map(async ([utxo, witness]) => {
let taggedWitness;
Expand Down Expand Up @@ -993,6 +1001,7 @@ async function newAdaUnsignedTxFromUtxoForConnector(
WalletType.Shelley,
{
path: changeAdaAddr.addressing.path,
// $FlowIgnore
start: changeAdaAddr.addressing.startLevel,
}
);
Expand All @@ -1003,11 +1012,15 @@ async function newAdaUnsignedTxFromUtxoForConnector(

const signRequestChangeAddr = [];
if (unsignedTx.change) {
const spendingKeyInfo = unsignedTx.change.address.spendingKeyInfo;
if (spendingKeyInfo == null) {
throw new Error('Missing spendingKeyInfo in change address');
}
signRequestChangeAddr.push({
address: unsignedTx.change.address.hex,
addressing: {
path: unsignedTx.change.address.spendingKeyInfo.path,
startLevel: unsignedTx.change.address.spendingKeyInfo.start,
path: spendingKeyInfo.path,
startLevel: spendingKeyInfo.start,
},
values: libValueToMultiToken(
unsignedTx.change.value,
Expand All @@ -1024,7 +1037,9 @@ async function newAdaUnsignedTxFromUtxoForConnector(
].map(u => [u.utxo_id, u])
);
return {
// $FlowIgnore
senderUtxos: unsignedTx.inputs.asArray().map(u => utxosMap.get(u.tx + u.index)),
// $FlowIgnore
txBuilder: unsignedTx.builder.wasm,
changeAddr: signRequestChangeAddr,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ describe('Create unsigned TX from addresses', () => {

expect(unsignedTxResponse.txBuilder.get_explicit_input().coin().to_str()).toEqual('1000001');
expect(unsignedTxResponse.txBuilder.get_explicit_output().coin().to_str()).toEqual('5001');
expect(unsignedTxResponse.txBuilder.min_fee().to_str()).toEqual('1006');
expect(unsignedTxResponse.txBuilder.min_fee().to_str()).toEqual('995000');
// burns remaining amount
expect(
unsignedTxResponse.txBuilder.get_explicit_input().checked_sub(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ test('Create Trezor transaction', async () => {
txBuilder.add_output(
RustModule.WalletV4.TransactionOutput.new(
RustModule.WalletV4.Address.from_hex(byronAddrToHex('Ae2tdPwUPEZAVDjkPPpwDhXMSAjH53CDmd2xMwuR9tZMAZWxLhFphrHKHXe')),
RustModule.WalletV4.Value.new(RustModule.WalletV4.BigNum.from_str('5326134'))
RustModule.WalletV4.Value.new(RustModule.WalletV4.BigNum.from_str('6323634'))
)
);
const certs = RustModule.WalletV4.Certificates.new();
Expand All @@ -207,7 +207,7 @@ test('Create Trezor transaction', async () => {
RustModule.WalletV4.StakeRegistration.new(stakeCredential)
));
txBuilder.set_certs(certs);
txBuilder.set_fee(RustModule.WalletV4.BigNum.from_str('1000'));
txBuilder.set_fee(RustModule.WalletV4.BigNum.from_str('2000'));
txBuilder.set_ttl(500);

const baseConfig = network.BaseConfig
Expand Down Expand Up @@ -235,7 +235,7 @@ test('Create Trezor transaction', async () => {
Number.parseInt(ChainNetworkId, 10),
);
expect(response).toStrictEqual({
fee: '1000',
fee: '2000',
ttl: '500',
networkId: 1,
protocolMagic: 764824073,
Expand All @@ -260,7 +260,7 @@ test('Create Trezor transaction', async () => {
}],
outputs: [{
address: 'Ae2tdPwUPEZAVDjkPPpwDhXMSAjH53CDmd2xMwuR9tZMAZWxLhFphrHKHXe',
amount: `5326134`
amount: `6323634`
}],
certificates: [{
path: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
connectorSignCardanoTx,
connectorRecordSubmittedCardanoTransaction,
} from '../../../connector/api';
import { mergeWitnessSets } from '../../../../../app/api/ada/transactions/utils';
import {
transactionHexToHash,
transactionHexReplaceWitnessSet,
transactionHexToWitnessSet,
transactionHexAddVkeyWitnessesFromWitnessSetHex,
} from '../../../../../app/api/ada/lib/cardanoCrypto/utils';
import {
asGetSigningKey,
Expand Down Expand Up @@ -49,12 +47,7 @@ export const SignTransaction: HandlerType<
partialSign: false
},
);

const mergedWitnessSetHex = mergeWitnessSets(
transactionHexToWitnessSet(transactionHex),
signedWitnessSetHex,
);
return transactionHexReplaceWitnessSet(transactionHex, mergedWitnessSetHex);
return transactionHexAddVkeyWitnessesFromWitnessSetHex(transactionHex, signedWitnessSetHex);
} catch (error) {
return { error: error.message };
}
Expand Down
Loading

0 comments on commit 73b582c

Please sign in to comment.