Skip to content

Commit

Permalink
single account auth only with new auth repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Funkatronics committed Nov 13, 2023
1 parent 6ffd522 commit daeb2df
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class MobileWalletAdapterViewModel(application: Application) : AndroidViewModel(
val keypair = getApplication<FakeWalletApplication>().keyRepository.generateKeypair()
val publicKey = keypair.public as Ed25519PublicKeyParameters
Log.d(TAG, "Generated a new keypair (pub=${publicKey.encoded.contentToString()}) for authorize request")
val accounts = arrayOf(buildAccount(publicKey.encoded, "fakewallet"))
request.request.completeWithAuthorize(accounts, null,
val account = buildAccount(publicKey.encoded, "fakewallet")
request.request.completeWithAuthorize(account, null,
request.sourceVerificationState.authorizationScope.encodeToByteArray(), null)
} else {
request.request.completeWithDecline()
Expand Down Expand Up @@ -174,8 +174,8 @@ class MobileWalletAdapterViewModel(application: Application) : AndroidViewModel(
val signInResult = SignInResult(publicKey.encoded,
siwsMessage.encodeToByteArray(), signResult.signature, "ed25519")

val accounts = arrayOf(buildAccount(publicKey.encoded, "fakewallet"))
request.request.completeWithAuthorize(accounts, null,
val account = buildAccount(publicKey.encoded, "fakewallet")
request.request.completeWithAuthorize(account, null,
request.sourceVerificationState.authorizationScope.encodeToByteArray(), signInResult)
} else {
request.request.completeWithDecline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,21 @@ private void onAuthorizationComplete(@NonNull NotifyOnCompleteFuture<Authorizati
final JSONObject o = new JSONObject();
try {
o.put(ProtocolContract.RESULT_AUTH_TOKEN, result.authToken);
final JSONArray accounts = new JSONArray();
for (AuthorizedAccount aa : result.accounts) {
final String publicKeyBase64 = Base64.encodeToString(aa.publicKey, Base64.NO_WRAP);
final JSONObject account = new JSONObject();
account.put(ProtocolContract.RESULT_ACCOUNTS_ADDRESS, publicKeyBase64);
if (aa.displayAddress != null && aa.displayAddressFormat != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_DISPLAY_ADDRESS, aa.displayAddress);
account.put(ProtocolContract.RESULT_ACCOUNTS_DISPLAY_ADDRESS_FORMAT, aa.displayAddressFormat);
}
if (aa.accountLabel != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_LABEL, aa.accountLabel);
}
if (aa.icon != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_ICON, aa.icon);
}
accounts.put(account);
final AuthorizedAccount aa = result.account;
final String publicKeyBase64 = Base64.encodeToString(aa.publicKey, Base64.NO_WRAP);
final JSONObject account = new JSONObject();
account.put(ProtocolContract.RESULT_ACCOUNTS_ADDRESS, publicKeyBase64);
if (aa.displayAddress != null && aa.displayAddressFormat != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_DISPLAY_ADDRESS, aa.displayAddress);
account.put(ProtocolContract.RESULT_ACCOUNTS_DISPLAY_ADDRESS_FORMAT, aa.displayAddressFormat);
}
if (aa.accountLabel != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_LABEL, aa.accountLabel);
}
if (aa.icon != null) {
account.put(ProtocolContract.RESULT_ACCOUNTS_ICON, aa.icon);
}
final JSONArray accounts = new JSONArray().put(account); // TODO(#44): support multiple accounts
o.put(ProtocolContract.RESULT_ACCOUNTS, accounts);
o.put(ProtocolContract.RESULT_WALLET_URI_BASE, result.walletUriBase); // OK if null
if (result.signInResult != null) {
Expand Down Expand Up @@ -348,8 +346,10 @@ public static class AuthorizationResult {
@Nullable
public final Uri walletUriBase;

@NonNull @Size(min = 1)
public final AuthorizedAccount[] accounts;
// @NonNull @Size(min = 1)
// public final AuthorizedAccount[] accounts;
@NonNull
public final AuthorizedAccount account;

@Nullable
public final SignInResult signInResult;
Expand All @@ -364,20 +364,22 @@ public AuthorizationResult(@NonNull String authToken,
this.accountLabel = accountLabel;
this.walletUriBase = walletUriBase;
this.signInResult = null;
this.accounts = new AuthorizedAccount[] {
new AuthorizedAccount(publicKey, accountLabel, null, null, null) };
// this.accounts = new AuthorizedAccount[] {
// new AuthorizedAccount(publicKey, accountLabel, null, null, null) };
this.account = new AuthorizedAccount(publicKey, accountLabel, null, null, null);
}

public AuthorizationResult(@NonNull String authToken,
@NonNull @Size(min = 1) AuthorizedAccount[] accounts,
@NonNull @Size(min = 1) AuthorizedAccount account,
@Nullable Uri walletUriBase,
@Nullable SignInResult signInResult) {
this.authToken = authToken;
this.walletUriBase = walletUriBase;
this.accounts = accounts;
// this.accounts = accounts;
this.account = account;
this.signInResult = signInResult;
this.publicKey = accounts[0].publicKey;
this.accountLabel = accounts[0].accountLabel;
this.publicKey = account.publicKey;
this.accountLabel = account.accountLabel;
}

@NonNull
Expand All @@ -386,7 +388,8 @@ public String toString() {
return "AuthorizeResult{" +
"authToken=<REDACTED>" +
", walletUriBase=" + walletUriBase +
", accounts=" + Arrays.toString(accounts) +
// ", accounts=" + Arrays.toString(accounts) +
", account=" + account +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ public void completeWithAuthorize(@NonNull byte[] publicKey,
mRequest.complete(new Result(accounts, walletUriBase, scope, null));
}

public void completeWithAuthorize(@NonNull AuthorizedAccount[] accounts,
public void completeWithAuthorize(@NonNull AuthorizedAccount account, // TODO(#44): support multiple addresses
@Nullable Uri walletUriBase,
@Nullable byte[] scope,
@Nullable SignInResult signInResult) {
mRequest.complete(new Result(accounts, walletUriBase, scope, signInResult));
mRequest.complete(new Result(new AuthorizedAccount[] { account }, walletUriBase, scope, signInResult));
}

public void completeWithDecline() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,17 @@ public void authorize(@NonNull MobileWalletAdapterServer.AuthorizeRequest reques
final String name = request.identityName != null ? request.identityName : "";
final Uri uri = request.identityUri != null ? request.identityUri : Uri.EMPTY;
final Uri relativeIconUri = request.iconUri != null ? request.iconUri : Uri.EMPTY;
final AuthorizedAccount account = authorize.accounts[0]; // TODO(#44): support multiple addresses
final AuthRecord authRecord = mAuthRepository.issue(
name, uri, relativeIconUri, account.publicKey,
account.accountLabel, chain, authorize.walletUriBase,
authorize.scope);
final AuthRecord authRecord = mAuthRepository.issue(name, uri,
relativeIconUri, authorize.accounts[0], // TODO(#44): support multiple addresses
chain, authorize.walletUriBase, authorize.scope);
Log.d(TAG, "Authorize request completed successfully; issued auth: " + authRecord);
synchronized (mLock) {
mActiveAuthorization = authRecord;
}

final String authToken = mAuthRepository.toAuthToken(authRecord);
request.complete(new MobileWalletAdapterServer.AuthorizationResult(
authToken, authorize.accounts,
authToken, authorize.accounts[0], // TODO(#44): support multiple addresses
authorize.walletUriBase, authorize.signInResult));
} else {
request.completeExceptionally(new MobileWalletAdapterServer.RequestDeclinedException(
Expand Down

0 comments on commit daeb2df

Please sign in to comment.