Skip to content

Commit

Permalink
Merge branch 'develop' into sorin/YOEXT-1610/portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
vsubhuman authored Dec 17, 2024
2 parents abb3208 + 2c75e85 commit 453c10b
Show file tree
Hide file tree
Showing 65 changed files with 928 additions and 579 deletions.
6 changes: 3 additions & 3 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ export default class AdaApi {
);

return {
txHash: Scope.WalletV4.hash_transaction(signedTx.body()).to_hex(),
txHash: Scope.WalletV4.FixedTransaction.from_hex(signedTx.to_hex()).transaction_hash().to_hex(),
encodedTx: signedTx.to_bytes(),
}
})
Expand Down Expand Up @@ -1579,13 +1579,13 @@ export default class AdaApi {
);

{
const body = unsignedTxResponse.txBuilder.build();
const tx = unsignedTxResponse.txBuilder.build_tx();
for (const withdrawal of request.withdrawals) {
if (withdrawal.privateKey != null) {
const { privateKey } = withdrawal;
neededKeys.wits.add(
RustModule.WalletV4.make_vkey_witness(
RustModule.WalletV4.hash_transaction(body),
RustModule.WalletV4.FixedTransaction.from_hex(tx.to_hex()).transaction_hash(),
privateKey
).to_hex()
);
Expand Down
8 changes: 4 additions & 4 deletions packages/yoroi-extension/app/api/ada/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ describe('app/api/ada/index', () => {
{
identifier: '',
networkId: 300,
amount: new BigNumber('8812631')
amount: new BigNumber('8812367')
},
{
amount: new BigNumber('45000000'),
Expand All @@ -508,7 +508,7 @@ describe('app/api/ada/index', () => {
]
);

expect(response.unsignedTx.get_fee_if_set()?.to_str()).toEqual('187369');
expect(response.unsignedTx.get_fee_if_set()?.to_str()).toEqual('187633');

function cmpOutputs(o1: any, o2: any): number {
if (o1.address > o2.address) {
Expand All @@ -530,7 +530,7 @@ describe('app/api/ada/index', () => {
collateral_return: null,
current_treasury_value: null,
donation: null,
fee: '187369',
fee: '187633',
inputs: [
{
index: 1,
Expand Down Expand Up @@ -610,7 +610,7 @@ describe('app/api/ada/index', () => {
{
address: 'addr_test1qp00295qtc07m8f65trccaveaycum8zaj9xrwt4jw2qqdn7r3y3kdut55a40jff00qmg74686vz44v6k363md06qkq0qn97ahn',
amount: {
coin: '2657551',
coin: '2657287',
multiasset: null
},
plutus_data: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,11 @@ export function toRemoteByronTx(
request: SignedRequestInternal,
): RemoteTransaction {
const tx = Array.isArray(request.signedTx) ? forceNonNull(last(request.signedTx)) : request.signedTx;
const signedTx = RustModule.WalletV4.Transaction.from_bytes(Buffer.from(tx, 'base64'));
const txBytes = Buffer.from(tx, 'base64');
const signedTx = RustModule.WalletV4.Transaction.from_bytes(txBytes);
const body = signedTx.body();
const hash = RustModule.WalletV4.hash_transaction(body).to_hex();
const hash = RustModule.WalletV4.FixedTransaction.from_bytes(txBytes).transaction_hash().to_hex();
const outputs = iterateLenGet(body.outputs()).map(output => ({
address: toHexOrBase58(output.address()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function buildYoroiTransferTx(payload: {|
return {
recoveredBalance: totalBalance,
fee,
id: RustModule.WalletV4.hash_transaction(signedTx.body()).to_hex(),
id: RustModule.WalletV4.FixedTransaction.from_hex(signedTx.to_hex()).transaction_hash().to_hex(),
encodedTx: signedTx.to_bytes(),
// only display unique addresses
senders: Array.from(new Set(senderUtxos.map(utxo => utxo.receiver))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ implements ISignRequest<RustModule.WalletV4.TransactionBuilder> {
}

txId(): string {
return RustModule.WalletV4.hash_transaction(this.unsignedTx.build()).to_hex();
return RustModule.WalletV4.FixedTransaction.from_hex(
this.unsignedTx.build_tx().to_hex()
).transaction_hash().to_hex();
}

size(): {| full: number, outputs: number[] |} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ import { toHexOrBase58 } from '../../lib/storage/bridge/utils';
import { Bip44DerivationLevels, } from '../../lib/storage/database/walletTypes/bip44/api/utils';
import { ChainDerivations, } from '../../../../config/numbersConfig';
import { derivePublicByAddressing } from '../../lib/cardanoCrypto/deriveByAddressing';
import { bytesToHex, fail, forceNonNull, iterateLenGet, iterateLenGetMap, maybe } from '../../../../coreUtils';
import {
bytesToHex,
fail,
forceNonNull,
hexToBytes,
iterateLenGet,
iterateLenGetMap,
maybe
} from '../../../../coreUtils';
import { mergeWitnessSets } from '../utils';

// ==================== LEDGER ==================== //
Expand All @@ -48,7 +56,18 @@ export function createLedgerSignTxPayload(request: {|
addressingMap: string => (void | $PropertyType<Addressing, 'addressing'>),
cip36: boolean,
|}): SignTransactionRequest {
const txBody = request.signRequest.unsignedTx.build();

const tx = request.signRequest.unsignedTx.build_tx();
const txBody = tx.body();

const tagsState = RustModule.WasmScope(Module =>
Module.WalletV4.has_transaction_set_tag(tx.to_bytes()));

if (tagsState === RustModule.WalletV4.TransactionSetsState.MixedSets) {
throw new Error('Transaction with mixed sets cannot be signed by Ledger');
}

const txHasSetTags = tagsState === RustModule.WalletV4.TransactionSetsState.AllSetsHaveTag;

// Inputs
const ledgerInputs = _transformToLedgerInputs(
Expand Down Expand Up @@ -166,7 +185,7 @@ export function createLedgerSignTxPayload(request: {|
},
additionalWitnessPaths: [],
options: {
tagCborSets: false,
tagCborSets: txHasSetTags,
}
};
}
Expand Down Expand Up @@ -304,17 +323,37 @@ function formatLedgerWithdrawals(
for (const [rewardAddress, withdrawalAmount] of iterateLenGetMap(withdrawals).nonNullValue()) {
const rewardAddressPayload = rewardAddress.to_address().to_hex();
const addressing = addressingMap(rewardAddressPayload);
if (addressing == null) {
throw new Error(`${nameof(formatLedgerWithdrawals)} Ledger can only withdraw from own address ${rewardAddressPayload}`);
let stakeCredential;
if (addressing != null) {
stakeCredential = {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
};
} else {
const cred = rewardAddress.payment_cred();
const maybeKeyHash = cred.to_keyhash();
const maybeScriptHash = cred.to_scripthash();
if (maybeKeyHash) {
stakeCredential = {
type: CredentialParamsType.KEY_HASH,
keyHashHex: maybeKeyHash.to_hex(),
};
} else if (maybeScriptHash) {
stakeCredential = {
type: CredentialParamsType.SCRIPT_HASH,
scriptHashHex: maybeScriptHash.to_hex(),
};
}
}
if (stakeCredential == null) {
throw new Error('Failed to resolve credential type for reward address: ' + rewardAddressPayload);
}
result.push({
amount: withdrawalAmount.to_str(),
stakeCredential: {
type: CredentialParamsType.KEY_PATH,
keyPath: addressing.path,
},
stakeCredential,
});
}
// $FlowIgnore[incompatible-return]
return result;
}

Expand Down Expand Up @@ -772,6 +811,16 @@ export function toLedgerSignRequest(
additionalRequiredSigners: Array<string> = [],
): SignTransactionRequest {

const tagsState = RustModule.WasmScope(Module => Module.WalletV4.has_transaction_set_tag(
Module.WalletV4.FixedTransaction.new_from_body_bytes(hexToBytes(txBodyHex)).to_bytes()
));

if (tagsState === RustModule.WalletV4.TransactionSetsState.MixedSets) {
throw new Error('Transaction with mixed sets cannot be signed by Ledger');
}

const txHasSetTags = tagsState === RustModule.WalletV4.TransactionSetsState.AllSetsHaveTag;

const txBody = RustModule.WalletV4.TransactionBody.from_hex(txBodyHex);

function formatInputs(inputs: RustModule.WalletV4.TransactionInputs): Array<TxInput> {
Expand Down Expand Up @@ -1076,6 +1125,9 @@ export function toLedgerSignRequest(
referenceInputs: formattedReferenceInputs,
},
additionalWitnessPaths,
options: {
tagCborSets: txHasSetTags,
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ test('Create Ledger transaction', async () => {

expect(response).toStrictEqual(({
options: {
tagCborSets: false,
tagCborSets: true,
},
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
tx: {
Expand Down
Loading

0 comments on commit 453c10b

Please sign in to comment.