Skip to content

Commit

Permalink
Merge pull request #2394 from Emurgo/production
Browse files Browse the repository at this point in the history
[PULL] Latest Production to Develop after 4.7.200
  • Loading branch information
vsubhuman committed Sep 15, 2021
2 parents bfd5203 + e34d2c6 commit a5fd4b4
Show file tree
Hide file tree
Showing 14 changed files with 1,212 additions and 91 deletions.
2 changes: 1 addition & 1 deletion packages/yoroi-extension/.eslintignore
@@ -1,3 +1,3 @@
node_modules
/chrome/content-scripts
flow-typed
flow-typed
Expand Up @@ -411,7 +411,9 @@ export class RemoteFetcher implements IFetcher {
}, {});
}

getCatalystRoundInfo: CatalystRoundInfoRequest => Promise<CatalystRoundInfoResponse> = async (body) => {
getCatalystRoundInfo: CatalystRoundInfoRequest =>
Promise<CatalystRoundInfoResponse> = async (body) =>
{
const { BackendService } = body.network.Backend;
if (BackendService == null) throw new Error(`${nameof(this.getCatalystRoundInfo)} missing backend url`);
return await axios(
Expand Down
121 changes: 121 additions & 0 deletions packages/yoroi-extension/app/api/ada/transactions/shelley/trezorTx.js
Expand Up @@ -13,11 +13,13 @@ import type {
CardanoAddressParameters,
CardanoAssetGroup,
CardanoToken,
CardanoSignedTxWitness,
} from 'trezor-connect/lib/types/networks/cardano';
import {
CERTIFICATE_TYPE,
ADDRESS_TYPE,
} from 'trezor-connect/lib/constants/cardano';
import { CardanoTxSigningMode } from 'trezor-connect';
import type {
Address, Value, Addressing,
} from '../../lib/storage/models/PublicDeriver/interfaces';
Expand All @@ -32,6 +34,7 @@ import {
import { RustModule } from '../../lib/cardanoCrypto/rustLoader';
import { range } from 'lodash';
import { toHexOrBase58 } from '../../lib/storage/bridge/utils';
import { derivePublicByAddressing } from '../../lib/cardanoCrypto/utils';

// ==================== TREZOR ==================== //
/** Generate a payload for Trezor SignTx */
Expand All @@ -54,6 +57,7 @@ export async function createTrezorSignTxPayload(
);

let request = {
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION,
inputs: trezorInputs,
outputs: trezorOutputs,
fee: txBody.fee().to_str(),
Expand Down Expand Up @@ -333,3 +337,120 @@ export function toTrezorAddressParameters(
}
throw new Error(`${nameof(toTrezorAddressParameters)} unknown address type`);
}

export function buildSignedTransaction(
txBody: RustModule.WalletV4.TransactionBody,
senderUtxos: Array<CardanoAddressedUtxo>,
witnesses: Array<CardanoSignedTxWitness>,
publicKey: {|
...Addressing,
key: RustModule.WalletV4.Bip32PublicKey,
|},
stakingKey: RustModule.WalletV4.Bip32PublicKey,
metadata: RustModule.WalletV4.AuxiliaryData | void
): RustModule.WalletV4.Transaction {
const findWitness = (pubKey: string) => {
for (const witness of witnesses) {
if (witness.pubKey === pubKey) {
return witness.signature;
}
}
throw new Error(`${nameof(buildSignedTransaction)} no witness for ${pubKey}`);
};

const keyLevel = publicKey.addressing.startLevel + publicKey.addressing.path.length - 1;

const witSet = RustModule.WalletV4.TransactionWitnessSet.new();
const bootstrapWitnesses: Array<RustModule.WalletV4.BootstrapWitness> = [];
const vkeys: Array<RustModule.WalletV4.Vkeywitness> = [];

const seenVKeyWit = new Set<string>();
const seenBootstrapWit = new Set<string>();

for (const utxo of senderUtxos) {
verifyFromBip44Root(utxo.addressing);

const addressKey = derivePublicByAddressing({
addressing: utxo.addressing,
startingFrom: {
level: keyLevel,
key: publicKey.key,
}
});
const pubKey = Buffer.from(addressKey.to_raw_key().as_bytes()).toString('hex');

const witness = findWitness(pubKey);

if (RustModule.WalletV4.ByronAddress.is_valid(utxo.receiver)) {

const byronAddr = RustModule.WalletV4.ByronAddress.from_base58(utxo.receiver);
const bootstrapWit = RustModule.WalletV4.BootstrapWitness.new(
RustModule.WalletV4.Vkey.new(addressKey.to_raw_key()),
RustModule.WalletV4.Ed25519Signature.from_bytes(
Buffer.from(witness, 'hex')
),
addressKey.chaincode(),
byronAddr.attributes(),
);
const asString = Buffer.from(bootstrapWit.to_bytes()).toString('hex');
if (seenBootstrapWit.has(asString)) {
continue;
}
seenBootstrapWit.add(asString);
bootstrapWitnesses.push(bootstrapWit);
continue;
}

const vkeyWit = RustModule.WalletV4.Vkeywitness.new(
RustModule.WalletV4.Vkey.new(addressKey.to_raw_key()),
RustModule.WalletV4.Ed25519Signature.from_bytes(
Buffer.from(witness, 'hex')
),
);
const asString = Buffer.from(vkeyWit.to_bytes()).toString('hex');
if (seenVKeyWit.has(asString)) {
continue;
}
seenVKeyWit.add(asString);
vkeys.push(vkeyWit);
}

// add any staking key needed
const stakingPubKey = Buffer.from(stakingKey.to_raw_key().as_bytes()).toString('hex');

for (const witness of witnesses) {
if (witness.pubKey === stakingPubKey) {
const vkeyWit = RustModule.WalletV4.Vkeywitness.new(
RustModule.WalletV4.Vkey.new(stakingKey.to_raw_key()),
RustModule.WalletV4.Ed25519Signature.from_bytes(Buffer.from(witness.signature, 'hex')),
);
const asString = Buffer.from(vkeyWit.to_bytes()).toString('hex');
if (seenVKeyWit.has(asString)) {
continue;
}
seenVKeyWit.add(asString);
vkeys.push(vkeyWit);
}
}

if (bootstrapWitnesses.length > 0) {
const bootstrapWitWasm = RustModule.WalletV4.BootstrapWitnesses.new();
for (const bootstrapWit of bootstrapWitnesses) {
bootstrapWitWasm.add(bootstrapWit);
}
witSet.set_bootstraps(bootstrapWitWasm);
}
if (vkeys.length > 0) {
const vkeyWitWasm = RustModule.WalletV4.Vkeywitnesses.new();
for (const vkey of vkeys) {
vkeyWitWasm.add(vkey);
}
witSet.set_vkeys(vkeyWitWasm);
}
// TODO: handle script witnesses
return RustModule.WalletV4.Transaction.new(
txBody,
witSet,
metadata
);
}
Expand Up @@ -278,5 +278,6 @@ test('Create Trezor transaction', async () => {
],
type: CERTIFICATE_TYPE.StakeRegistration,
}],
signingMode: 0,
});
});
18 changes: 11 additions & 7 deletions packages/yoroi-extension/app/components/topbar/NavWalletDetails.js
Expand Up @@ -62,6 +62,8 @@ export default class NavWalletDetails extends Component<Props> {
shouldHideBalance,
onUpdateHideBalance,
highlightTitle,
// <TODO:RWRD2109>
// eslint-disable-next-line no-unused-vars
rewards,
walletAmount,
infoText,
Expand Down Expand Up @@ -110,12 +112,13 @@ export default class NavWalletDetails extends Component<Props> {
</p>
{this.renderAmountDisplay({ shouldHideBalance, amount: walletAmount })}
</div>
<div>
<p className={styles.label}>
{intl.formatMessage(globalMessages.rewardsLabel)}&nbsp;
</p>
{this.renderAmountDisplay({ shouldHideBalance, amount: rewards })}
</div>
{/* <TODO:RWRD2109> */}
{/* <div> */}
{/* <p className={styles.label}> */}
{/* {intl.formatMessage(globalMessages.rewardsLabel)}&nbsp; */}
{/* </p> */}
{/* {this.renderAmountDisplay({ shouldHideBalance, amount: rewards })} */}
{/* </div> */}
</div>
}
{this.props.rewards === undefined && (
Expand Down Expand Up @@ -150,7 +153,8 @@ export default class NavWalletDetails extends Component<Props> {
if (this.props.rewards === null || this.props.walletAmount === null) {
return null;
}
return this.props.rewards.joinAddCopy(this.props.walletAmount);
// <TODO:RWRD2109>
return this.props.walletAmount; // .joinAddCopy(this.props.rewards);
}

renderAmountDisplay: {|
Expand Down
Expand Up @@ -265,7 +265,7 @@ export default class WalletSendForm extends Component<Props> {
},
selectedAmount: {
label: this.context.intl.formatMessage(messages.selectedAmountLable),
value: this.props.shouldSendAll ?
value: this.props.shouldSendAll ?
this.props.selectedToken?.TokenId ?? this.props.getTokenInfo({
identifier: this.props.defaultToken.Identifier,
networkId: this.props.defaultToken.NetworkId,
Expand Down Expand Up @@ -383,7 +383,7 @@ export default class WalletSendForm extends Component<Props> {
}));
})();


const tokenId = this.props.selectedToken?.TokenId ?? this.props.getTokenInfo({
identifier: this.props.defaultToken.Identifier,
networkId: this.props.defaultToken.NetworkId,
Expand Down Expand Up @@ -411,7 +411,7 @@ export default class WalletSendForm extends Component<Props> {
const tokenListClasses = classnames([
styles.tokenList,
{
[styles.show]: this.props.shouldSendAll &&
[styles.show]: this.props.shouldSendAll &&
this.form.$('selectedToken').value === tokenId
}
])
Expand Down Expand Up @@ -495,8 +495,8 @@ export default class WalletSendForm extends Component<Props> {
options={sendAmountOptions}
{...form.$('selectedAmount').bind()}
onChange={value => {
// Do nothing if we select the same option twice
if (this.form.$('selectedAmount').value === value) return
// Do nothing if we select the same option twice
if (this.form.$('selectedAmount').value === value) return
if (value === CUSTOM_AMOUNT) {
this.props.updateSendAllStatus(false);
} else {
Expand All @@ -506,7 +506,7 @@ export default class WalletSendForm extends Component<Props> {
this.props.updateSendAllStatus(true);
}

if (this.props.shouldSendAll) {
if (this.props.shouldSendAll) {
this.props.updateAmount(new BigNumber(
formattedAmountToNaturalUnits(
this.form.$('amount').value,
Expand Down
Expand Up @@ -145,7 +145,9 @@ export default class UserSummary extends Component<Props, State> {
<h3 className={styles.label}>
{intl.formatMessage(globalMessages.totalRewardsLabel)}:
</h3>
{this.renderAmount(this.props.totalRewards)}
{/* <TODO:RWRD2109> */}
Due to protocol update, the rewards are being recalculated.
{/* {this.renderAmount(this.props.totalRewards)} */}
</div>
<div className={styles.footer}>
{this.props.withdrawRewards != null && (
Expand All @@ -154,6 +156,7 @@ export default class UserSummary extends Component<Props, State> {
label={intl.formatMessage(globalMessages.withdrawLabel)}
onClick={this.props.withdrawRewards}
skin={ButtonSkin}
disabled // <TODO:RWRD2109>
/>
)}
<div
Expand Down
Expand Up @@ -15,6 +15,17 @@ type Props = {|

@observer
export default class TokenOptionRow extends Component<Props> {

static defaultProps: {|
id: string,
amount: string,
nameOnly: boolean,
|} = {
id: '',
amount: '',
nameOnly: false,
};

render(): Node {
const notOnlyName = !this.props.nameOnly;
return (
Expand Down
Expand Up @@ -714,6 +714,9 @@ export default class StakingDashboardPage extends Component<Props> {

const txRequests = this.generated.stores.transactions.getTxRequests(request.publicDeriver);
const balance = txRequests.requests.getBalanceRequest.result;

// <TODO:RWRD2109>
// eslint-disable-next-line no-unused-vars
const rewardBalance =
request.delegationRequests.getDelegatedBalance.result == null
? new MultiToken([], defaultToken)
Expand Down Expand Up @@ -742,7 +745,7 @@ export default class StakingDashboardPage extends Component<Props> {
totalSum={
balance == null
? undefined
: balance.joinAddCopy(rewardBalance)
: balance // .joinAddCopy(rewardBalance) // <TODO:RWRD2109>
}
totalRewards={
!showRewardAmount || request.delegationRequests.getDelegatedBalance.result == null
Expand Down
Expand Up @@ -136,7 +136,8 @@ export default class VotingPage extends Component<Props> {
);
}
// keep enabled on the testnet
const { catalystRoundInfo, loadingCatalystRoundInfo } = this.generated.stores.substores.ada.votingStore;
const { catalystRoundInfo, loadingCatalystRoundInfo } =
this.generated.stores.substores.ada.votingStore;
if (loadingCatalystRoundInfo) {
return (
<VerticallyCenteredLayout>
Expand Down

0 comments on commit a5fd4b4

Please sign in to comment.