Skip to content

Commit

Permalink
docs: add docs for ScriptSigner
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Sep 2, 2023
1 parent 9e8a3ad commit 53105b3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
21 changes: 21 additions & 0 deletions core/src/main/java/org/nervos/ckb/sign/ScriptSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

import org.nervos.ckb.type.Transaction;

/**
* ScriptSigner implements the signing logic for various scripts.
*
* These signers should be registered in {@link TransactionSigner}.
*/
public interface ScriptSigner {
/**
* Sign the transaction for the script.
*
* This function is called by {@link TransactionSigner}
* for each context and each matched script group.
*
* @param transaction The transaction to be signed.
* @param scriptGroup TransactionSigner selects the corresponding ScriptSigner for each script group.
* This selection is based on the registered ScriptSigner's provided script type and hash.
* @param context This is passed from {@code TransactionSigner.signTransaction}
* @return {@code true} when the script handler has modified the transaction.
*
* @see TransactionSigner#signTransaction(TransactionWithScriptGroups, Context...)
* @see TransactionSigner#signTransaction(TransactionWithScriptGroups, Set<Context>)
* @see TransactionSigner#signTransaction(TransactionWithScriptGroups, String...)
*/
boolean signTransaction(Transaction transaction, ScriptGroup scriptGroup, Context context);
}
22 changes: 21 additions & 1 deletion core/src/main/java/org/nervos/ckb/sign/TransactionSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,25 @@ public TransactionSigner registerLockScriptSigner(String codeHash, ScriptSigner
return registerLockScriptSigner(Numeric.hexStringToByteArray(codeHash), scriptSigner);
}


/**
* signTransaction signs the transaction using registered ScriptSigners.
*
* @param transaction Transaction to be signed.
* @param contexts Contexts for {@link org.nervos.ckb.sign.ScriptSigner}.
* @return signed groups indices.
*/
public Set<Integer> signTransaction(
TransactionWithScriptGroups transaction, Context... contexts) {
return signTransaction(transaction, new HashSet<>(Arrays.asList(contexts)));
}

/**
* signTransaction signs the transaction using registered ScriptSigners.
*
* @param transaction Transaction to be signed.
* @param contexts Contexts for {@link org.nervos.ckb.sign.ScriptSigner}.
* @return signed groups indices.
*/
public Set<Integer> signTransaction(
TransactionWithScriptGroups transaction, Set<Context> contexts) {
Set<Integer> signedGroupsIndices = new HashSet<>();
Expand Down Expand Up @@ -122,6 +135,13 @@ public Set<Integer> signTransaction(
return signedGroupsIndices;
}

/**
* signTransaction signs the transaction using registered ScriptSigners.
*
* @param transaction Transaction to be signed.
* @param privateKeys Each private key is wrapped in one {@link Context}. These contexts will be passed to ScriptSigners.
* @return signed groups indices.
*/
public Set<Integer> signTransaction(
TransactionWithScriptGroups transaction, String... privateKeys) {
Contexts contexts = new Contexts();
Expand Down

0 comments on commit 53105b3

Please sign in to comment.