Comparing version 0.3.1 to 0.3.2
@@ -17,2 +17,6 @@ 'use strict'; | ||
var _nets = require('nets'); | ||
var _nets2 = _interopRequireDefault(_nets); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -77,6 +81,39 @@ | ||
profile = _ref.profile; | ||
return _extends({}, profile, payload.own || {}, { address: payload.iss }); | ||
return _extends({}, profile, payload.own || {}, payload.capabilities && payload.capabilities.length === 1 ? { pushToken: payload.capabilities[0] } : {}, { address: payload.iss }); | ||
}); | ||
} | ||
}, { | ||
key: 'push', | ||
value: function push(token, _ref2) { | ||
var url = _ref2.url; | ||
return new Promise(function (resolve, reject) { | ||
if (!token) { | ||
return reject(new Error('Missing push notification token')); | ||
} | ||
if (!url) { | ||
return reject(new Error('Missing payload url for sending to users device')); | ||
} | ||
(0, _nets2.default)({ | ||
uri: 'https://chasqui.uport.me/api/v1/sns', | ||
json: { url: url }, | ||
method: 'POST', | ||
withCredentials: false, | ||
headers: { | ||
Authorization: 'Bearer ' + token | ||
} | ||
}, function (error, res, body) { | ||
if (error) return reject(error); | ||
if (res.statusCode === 200) { | ||
resolve(body); | ||
} | ||
if (res.statusCode === 403) { | ||
return reject(new Error('Error sending push notification to user: Invalid Token')); | ||
} | ||
reject(new Error('Error sending push notification to user: ' + res.statusCode + ' ' + body.toString())); | ||
}); | ||
}); | ||
} | ||
// Create attestation | ||
@@ -86,6 +123,6 @@ | ||
key: 'attest', | ||
value: function attest(_ref2) { | ||
var sub = _ref2.sub, | ||
claim = _ref2.claim, | ||
exp = _ref2.exp; | ||
value: function attest(_ref3) { | ||
var sub = _ref3.sub, | ||
claim = _ref3.claim, | ||
exp = _ref3.exp; | ||
@@ -92,0 +129,0 @@ return (0, _JWT.createJWT)(this.settings, { sub: sub, claim: claim, exp: exp }); |
{ | ||
"name": "uport", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Library for interacting with uport profiles and attestations", | ||
@@ -22,7 +22,11 @@ "main": "lib/index.js", | ||
"jsontokens": "^0.6.5", | ||
"uport-lite": "^0.2.2" | ||
"nets": "^3.2.0", | ||
"uport-lite": "^0.2.4" | ||
}, | ||
"jest": { | ||
"coverageDirectory": "./coverage/", | ||
"collectCoverage": true | ||
"collectCoverage": true, | ||
"unmockedModulePathPatterns": [ | ||
"<rootDir>/node_modules/nock" | ||
] | ||
}, | ||
@@ -43,4 +47,5 @@ "devDependencies": { | ||
"mockdate": "^2.0.1", | ||
"nock": "^9.0.6", | ||
"webpack": "^1.14.0" | ||
} | ||
} |
@@ -144,3 +144,3 @@ # uport-js | ||
// Coming soon, not yet implemented | ||
credentials.pushTo(pushToken, attestation).then(response => { | ||
credentials.push(pushToken, `me.uport:add?attestation=${attestationjwt}`, message).then(response => { | ||
@@ -147,0 +147,0 @@ }) |
import { createJWT, verifyJWT } from './JWT' | ||
import UportLite from 'uport-lite' | ||
import nets from 'nets' | ||
@@ -36,6 +37,37 @@ export default class Credentials { | ||
return verifyJWT(this.settings, token, callbackUrl).then(({payload, profile}) => ( | ||
{...profile, ...(payload.own || {}), address: payload.iss} | ||
{...profile, ...(payload.own || {}), ...(payload.capabilities && payload.capabilities.length === 1 ? {pushToken: payload.capabilities[0]} : {}), address: payload.iss} | ||
)) | ||
} | ||
push (token, {url}) { | ||
return new Promise((resolve, reject) => { | ||
if (!token) { | ||
return reject(new Error('Missing push notification token')) | ||
} | ||
if (!url) { | ||
return reject(new Error('Missing payload url for sending to users device')) | ||
} | ||
nets({ | ||
uri: 'https://chasqui.uport.me/api/v1/sns', | ||
json: {url}, | ||
method: 'POST', | ||
withCredentials: false, | ||
headers: { | ||
Authorization: `Bearer ${token}` | ||
} | ||
}, | ||
(error, res, body) => { | ||
if (error) return reject(error) | ||
if (res.statusCode === 200) { | ||
resolve(body) | ||
} | ||
if (res.statusCode === 403) { | ||
return reject(new Error('Error sending push notification to user: Invalid Token')) | ||
} | ||
reject(new Error(`Error sending push notification to user: ${res.statusCode} ${body.toString()}`)) | ||
}) | ||
}) | ||
} | ||
// Create attestation | ||
@@ -42,0 +74,0 @@ attest ({sub, claim, exp}) { |
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
571961
16764
4
15
2
+ Addednets@^3.2.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddom-walk@0.1.2(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-function@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addednets@3.2.0(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedparse-headers@2.0.5(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxhr@2.6.0(transitive)
+ Addedxtend@4.0.2(transitive)
Updateduport-lite@^0.2.4