-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenCAP sending feature added #409
base: master
Are you sure you want to change the base?
Changes from 2 commits
0993ab1
26bb49d
741fc13
c906747
45bcde9
31aa175
7749479
cd580cd
1d9e897
b179c33
091990b
16aa33e
ea19d10
adbe7b5
6122cfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService) { | ||
angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService, ionicToast, opencapService) { | ||
var clipboardHasAddress = false; | ||
var clipboardHasContent = false; | ||
var originalList; | ||
|
@@ -61,6 +61,29 @@ angular.module('copayApp.controllers').controller('tabSendController', function( | |
}); | ||
}); | ||
|
||
$scope.sendToAlias = function(alias) { | ||
opencapService.get(alias, $scope.fromWallet.coin) | ||
.then(result => { | ||
let msg = `${$scope.fromWallet.coin} address found! Address is secure`; | ||
if(!result.dnssec){ | ||
msg = `${$scope.fromWallet.coin} address found! Address doesn\'t have maximum DNS security`; | ||
} | ||
|
||
let msgTime = 1000; | ||
$scope.$apply(function () { | ||
ionicToast.show(msg, 'bottom', false, msgTime); | ||
}); | ||
setTimeout(function(){ | ||
$scope.findContact(result.address); | ||
}, msgTime); | ||
}) | ||
.catch(status => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now :
|
||
$scope.$apply(function () { | ||
ionicToast.show(status, 'bottom', false, 1500); | ||
}); | ||
}); | ||
} | ||
|
||
$scope.findContact = function(search) { | ||
if (!search || search.length < 1) { | ||
$scope.list = originalList; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
'use strict'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect. I'll work on this, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just finished the update. I covered all of your points, let me know if there is anything else you want changed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I will review it and let you know. I don't guarantee anything, I will review technically if it is suitable to our app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I'll keep an eye if you need more changes made. |
||
|
||
angular.module('copayApp.services').service('opencapService', function () { | ||
|
||
function getAddressCall(host, alias, dnssec, coin) { | ||
var callback = function () { | ||
return fetch( | ||
`https://${host}/v1/addresses?alias=${alias}`, | ||
{ | ||
method: "GET" | ||
}, | ||
"application/json" | ||
); | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
callback() | ||
.then(parseJSON) | ||
.then(response => { | ||
if (response.ok) { | ||
if (typeof response.body === "undefined") { | ||
return reject('Error contacting opencap server, no data') | ||
} | ||
|
||
for (var i = 0; i < response.body.length; i++) { | ||
if (response.body[i].address_type === "undefined") { | ||
continue | ||
} | ||
if (response.body[i].address === "undefined") { | ||
continue | ||
} | ||
if (coin == 'bch' && | ||
(response.body[i].address_type == 200 || | ||
response.body[i].address_type == 201)) { | ||
return resolve({ address: response.body[i].address, dnssec }) | ||
} | ||
if (coin == 'btc' && | ||
(response.body[i].address_type == 100 || | ||
response.body[i].address_type == 101)) { | ||
return resolve({ address: response.body[i].address, dnssec }) | ||
} | ||
} | ||
|
||
return reject('Error contacting opencap server, no response'); | ||
} | ||
|
||
return reject('Error contacting opencap server, bad response'); | ||
}) | ||
.catch(error => | ||
reject(error.message) | ||
); | ||
}); | ||
} | ||
|
||
function getAliasData(domain, alias, coin) { | ||
var callback = function () { | ||
return fetch( | ||
`https://dns.google.com/resolve?name=_opencap._tcp.${domain}&type=SRV`, | ||
{ | ||
method: "GET" | ||
}, | ||
"application/json" | ||
); | ||
}; | ||
|
||
return callback() | ||
.then(parseJSON) | ||
.then(response => { | ||
return new Promise((resolve, reject) => { | ||
if (response.ok) { | ||
if (typeof response.body.AD === "undefined") { | ||
return reject('Error contacting google dns server, no dnnssec data') | ||
} | ||
let dnssec = response.body.AD; | ||
|
||
if (typeof response.body.Answer === "undefined") { | ||
return reject('Error contacting google dns server, no srv data') | ||
} | ||
if (response.body.Answer.length < 1) { | ||
return reject('Error contacting google dns server, not enough srv data') | ||
} | ||
|
||
let record = response.body.Answer[0].data.split(' ') | ||
if (record.length != 4) { | ||
return reject('Error contacting google dns server, improper srv data') | ||
} | ||
|
||
if (record[3].slice(-1) == '.') { | ||
record[3] = record[3].substring(0, record[3].length - 1); | ||
} | ||
|
||
return resolve({ target: record[3], alias, dnssec }) | ||
} | ||
|
||
return reject('Error contacting google dns server, bad response'); | ||
}); | ||
}) | ||
.then(args => | ||
getAddressCall(args.target, args.alias, args.dnssec, coin) | ||
) | ||
.catch(function (error) { | ||
return new Promise((resolve, reject) => { | ||
reject(error) | ||
}) | ||
}) | ||
} | ||
|
||
function parseJSON(response) { | ||
return new Promise(resolve => | ||
response.json().then(json => | ||
resolve({ | ||
status: response.status, | ||
ok: response.ok, | ||
body: json, | ||
}) | ||
) | ||
); | ||
} | ||
|
||
function validateUsername(username) { | ||
return /^[a-z0-9._-]{1,25}$/.test(username); | ||
} | ||
|
||
function validateDomain(username) { | ||
return /^[a-z0-9.\-]+\.[a-z]{2,4}$/.test(username); | ||
} | ||
|
||
function validateAlias(alias) { | ||
let splitAlias = alias.split('$'); | ||
if (splitAlias.length != 2) { | ||
return { username: '', domain: '' } | ||
} | ||
let username = splitAlias[0]; | ||
let domain = splitAlias[1]; | ||
|
||
if (!validateUsername(username)) { | ||
return { username: '', domain: '' } | ||
} | ||
if (!validateDomain(domain)) { | ||
return { username: '', domain: '' } | ||
} | ||
|
||
return { username, domain } | ||
} | ||
|
||
function get(alias, coin) { | ||
let aliasData = validateAlias(alias) | ||
if (aliasData.username === '' || aliasData.domain === '') { | ||
return new Promise((resolve, reject) => { | ||
return reject('Invalid OpenCAP alias') | ||
}) | ||
} | ||
|
||
return getAliasData(aliasData.domain, alias, coin) | ||
} | ||
|
||
return { | ||
get, | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now :
=>
: lambda expression is not supported for old javascript engine.Should be :