Skip to content

Commit

Permalink
Add memo field to Sep10Challenge.newChallenge()
Browse files Browse the repository at this point in the history
  • Loading branch information
lijamie98 committed May 26, 2022
1 parent 80e4c90 commit 22d1617
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'com.github.ben-manes.versions' // gradle dependencyUpdates -Drevi
apply plugin: 'project-report' // gradle htmlDependencyReport

sourceCompatibility = 1.6
version = '0.31.0'
version = '0.32.0'
group = 'stellar'

jar {
Expand Down
58 changes: 45 additions & 13 deletions src/main/java/org/stellar/sdk/Sep10Challenge.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ public static Transaction newChallenge(
return newChallenge(signer, network, clientAccountId, domainName, webAuthDomain, timebounds, "", "");
}

/**
* Returns a valid <a href="https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md#response" target="_blank">SEP 10</a> challenge, for use in web authentication.
*
* @param signer The server's signing account.
* @param network The Stellar network used by the server.
* @param clientAccountId The stellar account belonging to the client.
* @param domainName The <a href="https://en.wikipedia.org/wiki/Fully_qualified_domain_name" target="_blank">fully qualified domain name</a> of the service requiring authentication.
* @param webAuthDomain The fully qualified domain name of the service issuing the challenge.
* @param timebounds The lifetime of the challenge token.
* @param clientDomain The domain of the client application requesting authentication.
* @param clientSigningKey The stellar account listed as the SIGNING_KEY on the client domain's TOML file.
*/
/**
* Returns a valid <a href="https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md#response" target="_blank">SEP 10</a> challenge, for use in web authentication.
*
* @param signer The server's signing account.
* @param network The Stellar network used by the server.
* @param clientAccountId The stellar account belonging to the client.
* @param domainName The <a href="https://en.wikipedia.org/wiki/Fully_qualified_domain_name" target="_blank">fully qualified domain name</a> of the service requiring authentication.
* @param webAuthDomain The fully qualified domain name of the service issuing the challenge.
* @param timebounds The lifetime of the challenge token.
* @param clientDomain The domain of the client application requesting authentication.
* @param clientSigningKey The stellar account listed as the SIGNING_KEY on the client domain's TOML file.
* @param memo The memo of the challenge transaction.
*/
public static Transaction newChallenge(
KeyPair signer,
Network network,
Expand All @@ -64,7 +65,8 @@ public static Transaction newChallenge(
String webAuthDomain,
TimeBounds timebounds,
String clientDomain,
String clientSigningKey
String clientSigningKey,
Memo memo
) throws InvalidSep10ChallengeException {
byte[] nonce = new byte[48];
SecureRandom random = new SecureRandom();
Expand Down Expand Up @@ -94,6 +96,10 @@ public static Transaction newChallenge(
.addOperation(domainNameOperation)
.addOperation(webAuthDomainOperation);

if (memo != null) {
builder.addMemo(memo);
}

if (!clientSigningKey.isEmpty()) {
if (StrKey.decodeVersionByte(clientSigningKey) != StrKey.VersionByte.ACCOUNT_ID) {
throw new InvalidSep10ChallengeException(clientSigningKey + " is not a valid account id");
Expand All @@ -109,6 +115,32 @@ public static Transaction newChallenge(
return transaction;
}


/**
* Returns a valid <a href="https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md#response" target="_blank">SEP 10</a> challenge, for use in web authentication.
*
* @param signer The server's signing account.
* @param network The Stellar network used by the server.
* @param clientAccountId The stellar account belonging to the client.
* @param domainName The <a href="https://en.wikipedia.org/wiki/Fully_qualified_domain_name" target="_blank">fully qualified domain name</a> of the service requiring authentication.
* @param webAuthDomain The fully qualified domain name of the service issuing the challenge.
* @param timebounds The lifetime of the challenge token.
* @param clientDomain The domain of the client application requesting authentication.
* @param clientSigningKey The stellar account listed as the SIGNING_KEY on the client domain's TOML file.
*/
public static Transaction newChallenge(
KeyPair signer,
Network network,
String clientAccountId,
String domainName,
String webAuthDomain,
TimeBounds timebounds,
String clientDomain,
String clientSigningKey
) throws InvalidSep10ChallengeException {
return newChallenge(signer, network, clientAccountId, domainName, webAuthDomain, timebounds, clientDomain, clientSigningKey, null);
}

/**
* Reads a SEP 10 challenge transaction and returns the decoded transaction envelope and client account ID contained within.
* <p>
Expand Down

0 comments on commit 22d1617

Please sign in to comment.