Skip to content

Commit

Permalink
Multisig: Generalized for any multisig
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStahlfelge committed Mar 21, 2023
1 parent 41f9b20 commit 6e2fb0b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,55 @@
/**
* EIP-41/EIP-11 compliant multi sig transaction
*/
public class MultisigTransaction {
public abstract class MultisigTransaction {

/**
* @return transaction that is going to be signed
*/
public Transaction getTransaction() {
throw new UnsupportedOperationException();
}

/**
* @return multisig address this transaction was created for
*/
public MultisigAddress getMultisigAddress() {
throw new UnsupportedOperationException();
}
abstract public ReducedTransaction getTransaction();

/**
* adds a new commitment to this multisig transaction
* adds a new hint to this multisig transaction
* @param prover to add commitment for
*/
public void addCommitment(ErgoProver prover) {
throw new UnsupportedOperationException();
}
abstract public void addHint(ErgoProver prover);

/**
* adds the commitments not present on this instance from another multisig transaction instance
* adds the hints not present on this instance from another multisig transaction instance
* for the same transaction.
*/
public void addCommitments(MultisigTransaction other) {
throw new UnsupportedOperationException();
}
abstract public void mergeHints(MultisigTransaction other);

/**
* @return list of participants that added a commitment for the transaction
* adds the hints not present on this instance from the EIP-11 json
*/
public List<Address> getCommitingParticipants() {
throw new UnsupportedOperationException();
}

public boolean hasEnoughCommitments() {
throw new UnsupportedOperationException();
}
abstract public void mergeHints(String json);

/**
* @return the signed transaction if enough commitments are available
* @throws IllegalStateException if {@link #hasEnoughCommitments()} is false
* @return list of participants that added a hint for the transaction
*/
public SignedTransaction toSignedTransaction() {
throw new UnsupportedOperationException();
}
abstract public List<Address> getCommitingParticipants();
/**
* @return true if SignedTransaction can be built
*/
abstract public boolean isHintBagComplete();

/**
* @return EIP-11 compliant json string to transfer the partially signed transaction to the
* next particpant
* @return the signed transaction if enough commitments are available
* @throws IllegalStateException if {@link #isHintBagComplete()} is false
*/
public String toJson() {
throw new UnsupportedOperationException();
}
abstract public SignedTransaction toSignedTransaction();

/**
* constructs a multi sig transaction from an unsigned transaction. The first multi sig address
* in input boxes is used.
* @return EIP-11 compliant json string to transfer the partially signed transaction to the
* next participant
*/
public static MultisigTransaction fromTransaction(UnsignedTransaction transaction) {
throw new UnsupportedOperationException();
}
abstract public String hintsToJson();

/**
* constructs a multi sig transaction from a reduced transaction
*/
public static MultisigTransaction fromTransaction(ReducedTransaction transaction, MultisigAddress address) {
public static MultisigTransaction fromTransaction(ReducedTransaction transaction) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public interface ReducedTransaction extends Transaction {
* Returns the serialized bytes of this transaction.
*/
byte[] toBytes();

/**
* @return tree of participants required or able to sign for the transaction
*/
SigningParticipants getSignersRequired();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.ergoplatform.appkit;

import java.util.List;

/**
* Participants able to sign for a {@link ReducedTransaction}
*/
abstract public class SigningParticipants {

/**
* @return true if multiple signers are needed
*/
abstract public boolean isMultisig();

/**
* Multisig requirement, k-out-of-n
*/
public static class MultisigRequirement extends SigningParticipants {
public final int hintsNeeded;
public final List<SigningParticipants> hintbag;

public MultisigRequirement(int hintsNeeded, List<SigningParticipants> hintbag) {
this.hintsNeeded = hintsNeeded;
this.hintbag = hintbag;
}

@Override
public boolean isMultisig() {
return hintsNeeded > 1;
}
}

public static class SingleSigner extends SigningParticipants {
public final Address address;

public SingleSigner(Address address) {
this.address = address;
}

@Override
public boolean isMultisig() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public byte[] toBytes() {
return w.toBytes();
}

@Override
public SigningParticipants getSignersRequired() {
throw new UnsupportedOperationException();
}

@Override
public int hashCode() {
return _tx.hashCode();
Expand Down

0 comments on commit 6e2fb0b

Please sign in to comment.