Skip to content

Commit

Permalink
fix: changed contract
Browse files Browse the repository at this point in the history
  • Loading branch information
gagdiez authored May 20, 2024
2 parents ff2625c + 780ef49 commit e345d67
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EthereumView } from "./components/Ethereum";
import { BitcoinView } from "./components/Bitcoin";

// CONSTANTS
const MPC_CONTRACT = 'multichain-testnet-2.testnet';
const MPC_CONTRACT = 'v2.multichain-mpc.testnet';

// NEAR WALLET
const wallet = new Wallet({ network: 'testnet', createAccessKeyFor: MPC_CONTRACT });
Expand Down
4 changes: 2 additions & 2 deletions src/components/Bitcoin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function BitcoinView({ props: { setStatus, MPC_CONTRACT } }) {
const payload = await BTC.createPayload(senderAddress, receiver, amount);

setStatus('🕒 Asking MPC to sign the transaction, this might take a while...');
try{
try {
const signedTransaction = await BTC.requestSignatureToMPC(wallet, MPC_CONTRACT, derivationPath, payload, senderPK);
setStatus('✅ Signed payload ready to be relayed to the Bitcoin network');
setSignedTransaction(signedTransaction);
Expand All @@ -66,7 +66,7 @@ export function BitcoinView({ props: { setStatus, MPC_CONTRACT } }) {
const txHash = await BTC.relayTransaction(signedTransaction);
setStatus(
<>
<a href={`https://blockstream.info/testnet/tx/${txHash}`}> ✅ Successful </a>
<a href={`https://blockstream.info/testnet/tx/${txHash}`} target="_blank"> ✅ Successful </a>
</>
);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Ethereum.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function EthereumView({ props: { setStatus, MPC_CONTRACT } }) {
try {
const txHash = await Eth.relayTransaction(signedTransaction);
setStatus(<>
<a href={`https://sepolia.etherscan.io/tx/${txHash}`}> ✅ Successful </a>
<a href={`https://sepolia.etherscan.io/tx/${txHash}`} target="_blank"> ✅ Successful </a>
</>
);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext } from 'react';

/**
* @typedef NearContext
* @property {import('./wallets/near').Wallet} wallet Current wallet
* @property {import('./services/near-wallet').Wallet} wallet Current wallet
* @property {string} signedAccountId The AccountId of the signed user
*/

Expand Down
4 changes: 1 addition & 3 deletions src/services/bitcoin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ export class Bitcoin {
return { psbt, utxos };
}


async requestSignatureToMPC(wallet, contractId, path, btcPayload, publicKey) {
const { psbt, utxos } = btcPayload;

// Bitcoin needs to sign multiple utxos, so we need to pass a signer function
const sign = async (tx) => {
const payload = Array.from(ethers.getBytes(tx)).reverse();
const signature = await wallet.callMethod({ contractId, method: 'sign', args: { payload, path, key_version: 0 }, gas: '250000000000000' });
const [big_r, big_s] = await wallet.getTransactionResult(signature.transaction.hash);
const [big_r, big_s] = await wallet.callMethod({ contractId, method: 'sign', args: { payload, path, key_version: 0 }, gas: '250000000000000' });
return this.reconstructSignature(big_r, big_s);
}

Expand Down
5 changes: 2 additions & 3 deletions src/services/ethereum.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Ethereum {
// Get the nonce & gas price
const nonce = await this.web3.eth.getTransactionCount(sender);
const { maxFeePerGas, maxPriorityFeePerGas } = await this.queryGasPrice();

// Construct transaction
const transactionData = {
nonce,
Expand All @@ -56,8 +56,7 @@ export class Ethereum {
async requestSignatureToMPC(wallet, contractId, path, ethPayload, transaction, sender) {
// Ask the MPC to sign the payload
const payload = Array.from(ethPayload.reverse());
const request = await wallet.callMethod({ contractId, method: 'sign', args: { payload, path, key_version: 0 }, gas: '250000000000000' });
const [big_r, big_s] = await wallet.getTransactionResult(request.transaction.hash);
const [big_r, big_s] = await wallet.callMethod({ contractId, method: 'sign', args: { payload, path, key_version: 0 }, gas: '250000000000000' });

// reconstruct the signature
const r = Buffer.from(big_r.substring(2), 'hex');
Expand Down
2 changes: 1 addition & 1 deletion src/services/kdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import keccak from 'keccak';
import hash from 'hash.js';
import bs58check from 'bs58check';

const rootPublicKey = 'secp256k1:4HFcTSodRLVCGNVcGc4Mf2fwBBBxv9jxkGdiW2S2CA1y6UpVVRWKj6RX7d7TDt65k2Bj3w9FU4BGtt43ZvuhCnNt';
const rootPublicKey = 'secp256k1:4NfTiv3UsGahebgTaHyD9vF8KYKMBnfd6kh94mK6xv8fGBiJB8TBtFMP5WWXz6B89Ac1fbpzPwAvoyQebemHFwx3';

export function najPublicKeyStrToUncompressedHexPoint() {
const res = '04' + Buffer.from(base_decode(rootPublicKey.split(':')[1])).toString('hex');
Expand Down

0 comments on commit e345d67

Please sign in to comment.