Skip to content

Commit

Permalink
Merge pull request #1 from metalurgical/refactor_part_1
Browse files Browse the repository at this point in the history
refactor: cleanup and common signing code
  • Loading branch information
grvgoel81 authored Sep 11, 2023
2 parents fd65486 + 54e0af2 commit ef4d030
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 271 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea
.DS_Store
/build
/captures
Expand Down
2 changes: 2 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.web3auth.tss_client_android.client.TSSClientError;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.math.BigInteger;
import java.util.concurrent.ExecutionException;

@RunWith(AndroidJUnit4.class)
public class MpcProviderTests {
Expand Down Expand Up @@ -42,7 +46,7 @@ public class MpcProviderTests {
BigInteger[] nodeIndexs = {new BigInteger("1"), new BigInteger("2"), new BigInteger("3")};

@Test
public void testSigningMessage() {
public void testSigningMessage() throws TSSClientError, CustomSigningError {
EthTssAccountParams params = new EthTssAccountParams(
fullAddress, factorKey, tssNonce, tssShare, tssIndex, selected_tag, verifier, verifierId,
nodeIndexs, tssEndpoints, sigs);
Expand All @@ -55,19 +59,13 @@ public void testSigningMessage() {
}

@Test
public void testSigningTransaction() {
public void testSigningTransaction() throws TSSClientError, CustomSigningError, IOException, ExecutionException, InterruptedException {
EthTssAccountParams params = new EthTssAccountParams(
fullAddress, factorKey, tssNonce, tssShare, tssIndex, selected_tag, verifier, verifierId,
nodeIndexs, tssEndpoints, sigs);

EthereumTssAccount account = new EthereumTssAccount(params);

String fromAddress = Utils.generateAddressFromPubKey(params.getPublicKey());
System.out.println("fromAddress: " + fromAddress);
String toAddress = "0x048975d4997D7578A3419851639c10318db430b6"; //Utils.generateAddressFromPubKey(params.getPublicKey());
String transactionHash = account.signAndSendTransaction("https://rpc.ankr.com/eth_goerli", 0.001,
fromAddress, toAddress);
System.out.println("Transaction Hash: " + transactionHash);
String toAddress = "0x048975d4997D7578A3419851639c10318db430b6";
String transactionHash = account.signAndSendTransaction("https://rpc.ankr.com/eth_goerli", 0.001, toAddress);
assertNotNull(transactionHash);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import java.math.BigInteger;

public final class EthTssAccountParams {
private String publicKey;
private String factorKey;
private int tssNonce;
private String tssShare;
private String tssIndex;
private String selectedTag;
private String verifier;
private String verifierID;
private BigInteger[] nodeIndexes;
private String[] tssEndpoints;
private String[] authSigs;
final String publicKey;
final String factorKey;
final int tssNonce;
final String tssShare;
final String tssIndex;
final String selectedTag;
final String verifier;
final String verifierID;
final BigInteger[] nodeIndexes;
final String[] tssEndpoints;
final String[] authSigs;

public EthTssAccountParams(String publicKey, String factorKey, int tssNonce, String tssShare, String tssIndex, String selectedTag, String verifier, String verifierID, BigInteger[] nodeIndexes, String[] tssEndpoints, String[] authSigs) {
this.publicKey = publicKey;
Expand All @@ -28,49 +28,5 @@ public EthTssAccountParams(String publicKey, String factorKey, int tssNonce, Str
this.tssEndpoints = tssEndpoints;
this.authSigs = authSigs;
}

public String getPublicKey() {
return publicKey;
}

public String getFactorKey() {
return factorKey;
}

public int getTssNonce() {
return tssNonce;
}

public String getTssShare() {
return tssShare;
}

public String getTssIndex() {
return tssIndex;
}

public String getSelectedTag() {
return selectedTag;
}

public String getVerifier() {
return verifier;
}

public String getVerifierID() {
return verifierID;
}

public BigInteger[] getNodeIndexes() {
return nodeIndexes;
}

public String[] getTssEndpoints() {
return tssEndpoints;
}

public String[] getAuthSigs() {
return authSigs;
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.web3auth.web3_android_mpc_provider;

public class EthereumSignerError extends Error {
private ErrorType errorType;
private final ErrorType errorType;

public EthereumSignerError(ErrorType errorType) {
this.errorType = errorType;
Expand All @@ -11,7 +11,7 @@ public String getErrorDescription() {
switch (errorType) {
case EMPTY_RAW_TRANSACTION:
return "emptyRawTransaction";
case INSUFFICIENT_Funds:
case INSUFFICIENT_FUNDS:
return "insufficientFunds";
case UNKNOWN_ERROR:
return "unknownError";
Expand All @@ -22,7 +22,7 @@ public String getErrorDescription() {

public enum ErrorType {
EMPTY_RAW_TRANSACTION,
INSUFFICIENT_Funds,
INSUFFICIENT_FUNDS,
UNKNOWN_ERROR
}
}
Expand Down
Loading

0 comments on commit ef4d030

Please sign in to comment.