Skip to content

Commit

Permalink
Merge pull request #189 from xidaokun/dev_v1.3
Browse files Browse the repository at this point in the history
Dev v1.3
  • Loading branch information
li.fayi authored Apr 24, 2019
2 parents 73a94eb + 639aa5c commit ed0b077
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ dependencies {
implementation 'com.tencent.bugly:nativecrashreport:latest.release'
implementation 'org.apache.shiro:shiro-crypto-hash:1.4.0'
implementation project(':walletlibrary')
implementation project(':authorizelibrary')
implementation 'com.belerweb:pinyin4j:2.5.1'
implementation project(':keypairlibrary')
implementation project(':authorizelibrary')
}

apply plugin: 'com.google.gms.google-services'
1 change: 0 additions & 1 deletion app/src/main/java/com/breadwallet/did/CallbackEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
public class CallbackEntity {
public String Data;
public String Sign;
public String PublicKey;
}
9 changes: 0 additions & 9 deletions app/src/main/java/com/breadwallet/did/DidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ private AuthorInfo cursorToInfo(Cursor cursor) {
return authorInfo;
}

public String callBackUrl(String url, CallbackEntity entity){
if(entity==null || StringUtil.isNullOrEmpty(url)) return null;
String params = new Gson().toJson(entity);
Log.i("DidDataSource", "callBackUrl: "+"url:"+url+" params:"+params);
String tmp = urlPost(url, params);
Log.i("DidDataSource", "callBackUrl: result:"+tmp);
return tmp;
}

public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
public synchronized String urlPost(String url, String json) {
int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

import com.breadwallet.R;
import com.breadwallet.did.DidDataSource;
import com.breadwallet.presenter.activities.did.DidAuthorizeActivity;
import com.breadwallet.presenter.activities.settings.BaseSettingsActivity;
import com.breadwallet.presenter.customviews.LoadingDialog;
import com.breadwallet.presenter.entities.VoteEntity;
import com.breadwallet.presenter.interfaces.BRAuthCompletion;
import com.breadwallet.tools.manager.BRSharedPrefs;
import com.breadwallet.tools.security.AuthManager;
Expand Down Expand Up @@ -119,6 +121,27 @@ private boolean verifyUri(){
return isValid;
}


private void callReturnUrl(String txId){
if(StringUtil.isNullOrEmpty(txId)) return;
String returnUrl = uriFactory.getReturnUrl();
String url;
if (returnUrl.contains("?")) {
url = returnUrl + "&txid=" + txId;
} else {
url = returnUrl + "?txid=" + txId;
}
DidDataSource.getInstance(VoteActivity.this).callReturnUrl(url);
}

private void callBackUrl(String txid){
if(StringUtil.isNullOrEmpty(txid)) return;
String backurl = uriFactory.getCallbackUrl();
VoteEntity txEntity = new VoteEntity();
txEntity.TXID = txid;
String ret = DidDataSource.getInstance(this).urlPost(backurl, new Gson().toJson(txEntity));
}

private void sendTx(){
if(null==mCandidates || mCandidates.size()<=0) return;
if(mCandidates.size()>36) {
Expand All @@ -140,14 +163,8 @@ public void run() {
String txId = transaction.getTx();
if(StringUtil.isNullOrEmpty(txId)) return;
String mRwTxid = ElaDataSource.getInstance(VoteActivity.this).sendElaRawTx(txId);
String returnUrl = uriFactory.getReturnUrl();
String url;
if (returnUrl.contains("?")) {
url = returnUrl + "&txid=" + mRwTxid;
} else {
url = returnUrl + "?txid=" + mRwTxid;
}
DidDataSource.getInstance(VoteActivity.this).callReturnUrl(url);
callBackUrl(mRwTxid);
callReturnUrl(mRwTxid);
dismissDialog();
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public class WalletActivity extends BRActivity implements InternetManager.Connec
private String mUri;

public static String mCallbackUrl;
public static String mReturnUrl;
public static String mOrderId;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -412,14 +414,15 @@ public void run() {
factory.parse(mUri);
mUri = null;
String did = factory.getDID();
String appName = factory.getAppName();
String appId = factory.getAppID();
String signed = factory.getSignature();
String PK = factory.getPublicKey();
String des = factory.getDescription();
mCallbackUrl = factory.getCallbackUrl();
Log.i(TAG, "mCallbackUrl:"+mCallbackUrl);
Log.i(TAG, "walletActivity1 did:"+did+" appId:"+appId+" signed:"+signed+" PK: "+PK);
boolean isValide = AuthorizeManager.verify(WalletActivity.this, did, PK,appId, signed);
mReturnUrl = factory.getReturnUrl();
mOrderId = factory.getOrderID();
Log.i(TAG, "walletActivity1 did:"+did+" appName:"+appName+" appId:"+appId+" PK: "+PK);
boolean isValide = AuthorizeManager.verify(WalletActivity.this, did, PK, appName, appId);
Log.i(TAG, "walletActivity1 isValide: "+isValide);
if(!isValide) return;
BaseWalletManager walletManager = WalletsMaster.getInstance(WalletActivity.this).getCurrentWallet(WalletActivity.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,17 @@ private void author() {
String appName = uriFactory.getAppName();
String PK = uriFactory.getPublicKey();
String randomNumber = uriFactory.getRandomNumber();
if(StringUtil.isNullOrEmpty(did) || StringUtil.isNullOrEmpty(appId) || StringUtil.isNullOrEmpty(appName)
|| StringUtil.isNullOrEmpty(PK) || StringUtil.isNullOrEmpty(randomNumber)) {
Toast.makeText(DidAuthorizeActivity.this, "invalid params", Toast.LENGTH_SHORT).show();
finish();
}

final String backurl = uriFactory.getCallbackUrl();
final String returnUrl = uriFactory.getReturnUrl();
boolean isValid = AuthorizeManager.verify(DidAuthorizeActivity.this, did, PK, appName, appId);
if (!isValid) {
Toast.makeText(this, "invalid params", Toast.LENGTH_SHORT);
Toast.makeText(this, "verify failed", Toast.LENGTH_SHORT);
finish();
}

Expand All @@ -280,11 +285,10 @@ private void author() {
final String myDid = Utility.getInstance(DidAuthorizeActivity.this).getDid(myPK);

CallbackData callbackData = new CallbackData();
//default
//require
callbackData.DID = myDid;
callbackData.PublicKey = myPK;
callbackData.RandomNumber = randomNumber;
callbackData.PhoneNumber = new PhoneNumber();
//request info
callbackData.Nickname = (nickNameItem!=null)?nickNameItem.getValue(this)[0] : null;
callbackData.ELAAddress = (elaAddressItem!=null)?elaAddressItem.getValue(this)[0] : null;
Expand All @@ -304,43 +308,19 @@ private void author() {
callbackData.ChineseIDCard.IDNumber = idcardItem.getValue(this)[1];
}

entity.Data = new Gson().toJson(callbackData);
entity.PublicKey = myPK;
entity.Sign = AuthorizeManager.sign(DidAuthorizeActivity.this, pk, entity.Data);
final String Data = new Gson().toJson(callbackData);
final String Sign = AuthorizeManager.sign(DidAuthorizeActivity.this, pk, Data);
entity.Data = Data;
entity.Sign = Sign;


if (!isFinishing()) mLoadingDialog.show();
BRExecutor.getInstance().forLightWeightBackgroundTasks().execute(new Runnable() {
@Override
public void run() {
try {
if(!StringUtil.isNullOrEmpty(backurl)){
String ret = DidDataSource.getInstance(DidAuthorizeActivity.this).callBackUrl(backurl, entity);
if ((StringUtil.isNullOrEmpty(ret) || StringUtil.isNullOrEmpty(ret) || ret.contains("err code:"))) {
toast("callback return error");
}
}

if (!StringUtil.isNullOrEmpty(returnUrl)) {
String url;
if (returnUrl.contains("?")) {
url = returnUrl + "&did=" + myDid + "&response=" + Uri.encode(new Gson().toJson(entity));
} else {
url = returnUrl + "?did=" + myDid + "&response=" + Uri.encode(new Gson().toJson(entity));
}

if(BRConstants.REA_PACKAGE_ID.equals(appId) || BRConstants.DPOS_VOTE_ID.equals(appId)){
UiUtils.startWebviewActivity(DidAuthorizeActivity.this, url);
} else {
UiUtils.openUrlByBrowser(DidAuthorizeActivity.this, url);
}

// if (returnUrl.contains("target=\"internal\"") || returnUrl.contains("target=internal")) {
// UiUtils.startWebviewActivity(DidAuthorizeActivity.this, url);
// } else {
// UiUtils.openUrlByBrowser(DidAuthorizeActivity.this, url);
// }
}
callBackUrl(backurl, entity);
callReturnUrl(returnUrl, Data, Sign, appId);
} catch (Exception e) {
e.printStackTrace();
} finally {
Expand All @@ -352,6 +332,38 @@ public void run() {
}
}

private void callBackUrl(String backurl, CallbackEntity entity){
if(entity==null || StringUtil.isNullOrEmpty(backurl)) return;
String params = new Gson().toJson(entity);
String ret = DidDataSource.getInstance(this).urlPost(backurl, params);
if ((StringUtil.isNullOrEmpty(ret) || StringUtil.isNullOrEmpty(ret) || ret.contains("err code:"))) {
toast("callback return error");
}
}

private void callReturnUrl(String returnUrl, String Data, String Sign, String appId){
if (!StringUtil.isNullOrEmpty(returnUrl)) {
String url;
if (returnUrl.contains("?")) {
url = returnUrl + "&Data="+Uri.encode(Data)+"&Sign="+Uri.encode(Sign);
} else {
url = returnUrl + "?Data="+Uri.encode(Data)+"&Sign="+Uri.encode(Sign);
}

if(BRConstants.REA_PACKAGE_ID.equals(appId) || BRConstants.DPOS_VOTE_ID.equals(appId)){
UiUtils.startWebviewActivity(DidAuthorizeActivity.this, url);
} else {
UiUtils.openUrlByBrowser(DidAuthorizeActivity.this, url);
}

// if (returnUrl.contains("target=\"internal\"") || returnUrl.contains("target=internal")) {
// UiUtils.startWebviewActivity(DidAuthorizeActivity.this, url);
// } else {
// UiUtils.openUrlByBrowser(DidAuthorizeActivity.this, url);
// }
}
}

private void toast(final String message) {
runOnUiThread(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.breadwallet.presenter.entities;

public class ElapayEntity {
public String TXID;
public String OrderID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.breadwallet.presenter.entities;

public class VoteEntity {
public String TXID;
}
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,11 @@ public void onPause() {
mPaste.setClickable(true);
mCurrencyCodeButton.setClickable(true);
mFromRedPackage = false;
if(!mIsSend) WalletActivity.mCallbackUrl = null;
if(!mIsSend) {
WalletActivity.mReturnUrl = null;
WalletActivity.mCallbackUrl = null;
WalletActivity.mOrderId = null;
}
}

private void handleClick(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.breadwallet.presenter.activities.ExploreWebActivity;
import com.breadwallet.presenter.activities.WalletActivity;
import com.breadwallet.presenter.entities.CurrencyEntity;
import com.breadwallet.presenter.entities.ElapayEntity;
import com.breadwallet.presenter.entities.TxUiHolder;
import com.breadwallet.tools.animation.UiUtils;
import com.breadwallet.tools.manager.BRSharedPrefs;
Expand Down Expand Up @@ -172,22 +173,35 @@ public boolean isAddressValid(String address) {
@Override
public byte[] signAndPublishTransaction(CryptoTransaction tx, byte[] seed) {
Log.i(TAG, "signAndPublishTransaction");
if(tx == null) return new byte[1];
BRElaTransaction raw = tx.getElaTx();
if(raw == null) return new byte[1];
String mRwTxid = ElaDataSource.getInstance(mContext).sendElaRawTx(raw.getTx());

if(StringUtil.isNullOrEmpty(mRwTxid)) return new byte[1];
TxManager.getInstance().updateTxList(mContext);
if(!StringUtil.isNullOrEmpty(WalletActivity.mCallbackUrl)) {
if(WalletActivity.mCallbackUrl.contains("?")){
UiUtils.startWebviewActivity(mContext, WalletActivity.mCallbackUrl+"&txid="+mRwTxid);
} else {
UiUtils.startWebviewActivity(mContext, WalletActivity.mCallbackUrl+"?txid="+mRwTxid);
try {
if(tx == null) return new byte[1];
BRElaTransaction raw = tx.getElaTx();
if(raw == null) return new byte[1];
String mRwTxid = ElaDataSource.getInstance(mContext).sendElaRawTx(raw.getTx());

if(StringUtil.isNullOrEmpty(mRwTxid)) return new byte[1];
TxManager.getInstance().updateTxList(mContext);
if(!StringUtil.isNullOrEmpty(WalletActivity.mCallbackUrl)) { //call back url
ElapayEntity elapayEntity = new ElapayEntity();
elapayEntity.OrderID = WalletActivity.mOrderId;
elapayEntity.TXID = mRwTxid;
ElaDataSource.getInstance(mContext).urlPost(WalletActivity.mCallbackUrl, new Gson().toJson(elapayEntity));
}
if(!StringUtil.isNullOrEmpty(WalletActivity.mReturnUrl)) { //call return url
if(WalletActivity.mReturnUrl.contains("?")){
UiUtils.startWebviewActivity(mContext, WalletActivity.mReturnUrl+"&txid="+mRwTxid+"&OrderID"+WalletActivity.mOrderId);
} else {
UiUtils.startWebviewActivity(mContext, WalletActivity.mReturnUrl+"?txid="+mRwTxid+"&OrderID"+WalletActivity.mOrderId);
}
}
WalletActivity.mCallbackUrl = null;
WalletActivity.mReturnUrl = null;
WalletActivity.mOrderId = null;
return mRwTxid.getBytes();
} catch (Exception e) {
e.printStackTrace();
}
WalletActivity.mCallbackUrl = null;
return mRwTxid.getBytes();
return new byte[1];
}

public void updateTxHistory() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@
<string name="Did.Detail.Author.Time">授权时间:</string>
<string name="Did.Detail.Expiration">过期时间:</string>
<string name="Did.Detail.Auth.Info">授权信息:</string>
<string name="Did.Detail.DID">- ELA DID</string>
<string name="Did.Detail.DID">- Elastos DID</string>
<string name="Did.Detail.Public.Key">- 公钥</string>
<string name="Did.Detail.Nick.Name">- 昵称</string>
<string name="Did.Detail.Ela.Address">- ELA地址</string>
Expand Down
Binary file modified authorizelibrary/authorizelibrary.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':walletlibrary', ':authorizelibrary', ':keypairlibrary'
include ':app', ':walletlibrary', ':keypairlibrary', ':authorizelibrary'

0 comments on commit ed0b077

Please sign in to comment.