@@ -119,7 +119,9 @@ BlobObj.prototype.init = function(fn) {
119
119
120
120
self . revision = resp . body . revision ;
121
121
self . encrypted_secret = resp . body . encrypted_secret ;
122
+ self . identity_id = resp . body . identity_id ;
122
123
self . missing_fields = resp . body . missing_fields ;
124
+ //self.attestations = resp.body.attestation_summary;
123
125
124
126
if ( ! self . decrypt ( resp . body . blob ) ) {
125
127
return fn ( new Error ( 'Error while decrypting blob' ) ) ;
@@ -561,7 +563,6 @@ BlobObj.prototype.get2FA = function (fn) {
561
563
* @params {boolean} options.enabled
562
564
* @params {string} options.phone
563
565
* @params {string} options.country_code
564
- * @params {string} options.via //sms, etc
565
566
*/
566
567
567
568
BlobObj . prototype . set2FA = function ( options , fn ) {
@@ -572,8 +573,7 @@ BlobObj.prototype.set2FA = function(options, fn) {
572
573
data : {
573
574
enabled : options . enabled ,
574
575
phone : options . phone ,
575
- country_code : options . country_code ,
576
- via : options . via
576
+ country_code : options . country_code
577
577
}
578
578
} ;
579
579
@@ -1115,48 +1115,6 @@ BlobClient.recoverBlob = function (opts, fn) {
1115
1115
} ;
1116
1116
} ;
1117
1117
1118
- /**
1119
- * updateProfile
1120
- * update information stored outside the blob - HMAC signed
1121
- * @param {object }
1122
- * @param {string } opts.url
1123
- * @param {string } opts.username
1124
- * @param {string } opts.auth_secret
1125
- * @param {srring } opts.blob_id
1126
- * @param {object } opts.profile
1127
- * @param {string } opts.profile.phone - optional
1128
- * @param {string } opts.profile.country - optional
1129
- * @param {string } opts.profile.region - optional
1130
- * @param {string } opts.profile.city - optional
1131
- */
1132
-
1133
- BlobClient . updateProfile = function ( opts , fn ) {
1134
- var config = {
1135
- method : 'POST' ,
1136
- url : opts . url + '/v1/user/' + opts . username + '/profile' ,
1137
- dataType : 'json' ,
1138
- data : opts . profile
1139
- } ;
1140
-
1141
- var signedRequest = new SignedRequest ( config ) ;
1142
- var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1143
-
1144
- request . post ( signed . url )
1145
- . send ( signed . data )
1146
- . end ( function ( err , resp ) {
1147
- if ( err ) {
1148
- log . error ( 'updateProfile:' , err ) ;
1149
- fn ( new Error ( 'Failed to update profile - XHR error' ) ) ;
1150
- } else if ( resp . body && resp . body . result === 'success' ) {
1151
- fn ( null , resp . body ) ;
1152
- } else if ( resp . body ) {
1153
- log . error ( 'updateProfile:' , resp . body ) ;
1154
- } else {
1155
- fn ( new Error ( 'Failed to update profile' ) ) ;
1156
- }
1157
- } ) ;
1158
-
1159
- } ;
1160
1118
1161
1119
/**
1162
1120
* updateKeys
@@ -1320,6 +1278,7 @@ BlobClient.create = function(options, fn) {
1320
1278
if ( err ) {
1321
1279
fn ( err ) ;
1322
1280
} else if ( resp . body && resp . body . result === 'success' ) {
1281
+ blob . identity_id = resp . body . identity_id ;
1323
1282
fn ( null , blob , resp . body ) ;
1324
1283
} else if ( resp . body && resp . body . result === 'error' ) {
1325
1284
fn ( new Error ( resp . body . message ) ) ;
@@ -1363,4 +1322,263 @@ BlobClient.deleteBlob = function(options, fn) {
1363
1322
} ) ;
1364
1323
} ;
1365
1324
1325
+ /*** identity related functions ***/
1326
+
1327
+ /**
1328
+ * updateProfile
1329
+ * update information stored outside the blob - HMAC signed
1330
+ * @param {object }
1331
+ * @param {string } opts.url
1332
+ * @param {string } opts.auth_secret
1333
+ * @param {srring } opts.blob_id
1334
+ * @param {object } opts.profile
1335
+ * @param {array } opts.profile.attributes (optional, array of attribute objects)
1336
+ * @param {array } opts.profile.addresses (optional, array of address objects)
1337
+ *
1338
+ * @param {string } attribute.id ... id of existing attribute
1339
+ * @param {string } attribute.name ... attribute name i.e. ripple_address
1340
+ * @param {string } attribute.type ... optional, sub-type of attribute
1341
+ * @param {string } attribute.value ... value of attribute
1342
+ * @param {string } attribute.domain ... corresponding domain
1343
+ * @param {string } attribute.status ... “current”, “removed”, etc.
1344
+ * @param {string } attribute.visibitlity ... “public”, ”private”
1345
+ */
1346
+
1347
+ BlobClient . updateProfile = function ( opts , fn ) {
1348
+ var config = {
1349
+ method : 'POST' ,
1350
+ url : opts . url + '/v1/profile/' ,
1351
+ dataType : 'json' ,
1352
+ data : opts . profile
1353
+ } ;
1354
+
1355
+ var signedRequest = new SignedRequest ( config ) ;
1356
+ var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1357
+
1358
+ request . post ( signed . url )
1359
+ . send ( signed . data )
1360
+ . end ( function ( err , resp ) {
1361
+
1362
+ if ( err ) {
1363
+ log . error ( 'updateProfile:' , err ) ;
1364
+ fn ( new Error ( 'Failed to update profile - XHR error' ) ) ;
1365
+ } else if ( resp . body && resp . body . result === 'success' ) {
1366
+ fn ( null , resp . body ) ;
1367
+ } else if ( resp . body ) {
1368
+ log . error ( 'updateProfile:' , resp . body ) ;
1369
+ fn ( new Error ( 'Failed to update profile' ) ) ;
1370
+ } else {
1371
+ fn ( new Error ( 'Failed to update profile' ) ) ;
1372
+ }
1373
+ } ) ;
1374
+ } ;
1375
+
1376
+ /**
1377
+ * getProfile
1378
+ * @param {Object } opts
1379
+ * @param {string } opts.url
1380
+ * @param {string } opts.auth_secret
1381
+ * @param {srring } opts.blob_id
1382
+ */
1383
+
1384
+ BlobClient . getProfile = function ( opts , fn ) {
1385
+ var config = {
1386
+ method : 'GET' ,
1387
+ url : opts . url + '/v1/profile/'
1388
+ } ;
1389
+
1390
+ var signedRequest = new SignedRequest ( config ) ;
1391
+ var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1392
+
1393
+ request . get ( signed . url )
1394
+ . send ( signed . data )
1395
+ . end ( function ( err , resp ) {
1396
+
1397
+ if ( err ) {
1398
+ log . error ( 'getProfile:' , err ) ;
1399
+ fn ( new Error ( 'Failed to get profile - XHR error' ) ) ;
1400
+ } else if ( resp . body && resp . body . result === 'success' ) {
1401
+ fn ( null , resp . body ) ;
1402
+ } else if ( resp . body ) {
1403
+ log . error ( 'getProfile:' , resp . body ) ;
1404
+ fn ( new Error ( 'Failed to get profile' ) ) ;
1405
+ } else {
1406
+ fn ( new Error ( 'Failed to get profile' ) ) ;
1407
+ }
1408
+ } ) ;
1409
+ } ;
1410
+
1411
+ /**
1412
+ * getAttestation
1413
+ * @param {Object } opts
1414
+ * @param {string } opts.url
1415
+ * @param {string } opts.auth_secret
1416
+ * @param {string } opts.blob_id
1417
+ * @param {string } opts.type (email,phone,basic_identity)
1418
+ * @param {object } opts.phone (required for type 'phone')
1419
+ * @param {string } opts.email (required for type 'email')
1420
+ */
1421
+
1422
+ BlobClient . getAttestation = function ( opts , fn ) {
1423
+ var params = { } ;
1424
+
1425
+ if ( opts . phone ) params . phone = opts . phone ;
1426
+ if ( opts . email ) params . email = opts . email ;
1427
+
1428
+ var config = {
1429
+ method : 'POST' ,
1430
+ url : opts . url + '/v1/attestation/' + opts . type ,
1431
+ dataType : 'json' ,
1432
+ data : params
1433
+ } ;
1434
+
1435
+ var signedRequest = new SignedRequest ( config ) ;
1436
+ var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1437
+
1438
+ request . post ( signed . url )
1439
+ . send ( signed . data )
1440
+ . end ( function ( err , resp ) {
1441
+
1442
+ if ( err ) {
1443
+ log . error ( 'attest:' , err ) ;
1444
+ fn ( new Error ( 'attestation error - XHR error' ) ) ;
1445
+ } else if ( resp . body && resp . body . result === 'success' ) {
1446
+ if ( resp . body . attestation ) {
1447
+ resp . body . decoded = BlobClient . parseAttestation ( resp . body . attestation ) ;
1448
+ }
1449
+
1450
+ fn ( null , resp . body ) ;
1451
+ } else if ( resp . body ) {
1452
+ log . error ( 'attestation:' , resp . body ) ;
1453
+ fn ( new Error ( 'attestation error: ' + resp . body . message || "" ) ) ;
1454
+ } else {
1455
+ fn ( new Error ( 'attestation error' ) ) ;
1456
+ }
1457
+ } ) ;
1458
+ } ;
1459
+
1460
+ /**
1461
+ * getAttestationSummary
1462
+ * @param {Object } opts
1463
+ * @param {string } opts.url
1464
+ * @param {string } opts.auth_secret
1465
+ * @param {string } opts.blob_id
1466
+ */
1467
+
1468
+ BlobClient . getAttestationSummary = function ( opts , fn ) {
1469
+
1470
+
1471
+ var config = {
1472
+ method : 'GET' ,
1473
+ url : opts . url + '/v1/attestation/summary' ,
1474
+ dataType : 'json'
1475
+ } ;
1476
+
1477
+ if ( opts . full ) config . url += '?full=true' ;
1478
+
1479
+ var signedRequest = new SignedRequest ( config ) ;
1480
+ var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1481
+
1482
+ request . get ( signed . url )
1483
+ . send ( signed . data )
1484
+ . end ( function ( err , resp ) {
1485
+
1486
+ if ( err ) {
1487
+ log . error ( 'attest:' , err ) ;
1488
+ fn ( new Error ( 'attestation error - XHR error' ) ) ;
1489
+ } else if ( resp . body && resp . body . result === 'success' ) {
1490
+ if ( resp . body . attestation ) {
1491
+ resp . body . decoded = BlobClient . parseAttestation ( resp . body . attestation ) ;
1492
+ }
1493
+
1494
+ fn ( null , resp . body ) ;
1495
+ } else if ( resp . body ) {
1496
+ log . error ( 'attestation:' , resp . body ) ;
1497
+ fn ( new Error ( 'attestation error: ' + resp . body . message || "" ) ) ;
1498
+ } else {
1499
+ fn ( new Error ( 'attestation error' ) ) ;
1500
+ }
1501
+ } ) ;
1502
+ } ;
1503
+
1504
+ /**
1505
+ * updateAttestation
1506
+ * @param {Object } opts
1507
+ * @param {string } opts.url
1508
+ * @param {string } opts.auth_secret
1509
+ * @param {string } opts.blob_id
1510
+ * @param {string } opts.type (email,phone,profile,identity)
1511
+ * @param {object } opts.phone (required for type 'phone')
1512
+ * @param {object } opts.profile (required for type 'profile')
1513
+ * @param {string } opts.email (required for type 'email')
1514
+ * @param {string } opts.answers (required for type 'identity')
1515
+ * @param {string } opts.token (required for completing email or phone attestations)
1516
+ */
1517
+
1518
+ BlobClient . updateAttestation = function ( opts , fn ) {
1519
+
1520
+ var params = { } ;
1521
+
1522
+ if ( opts . phone ) params . phone = opts . phone ;
1523
+ if ( opts . profile ) params . profile = opts . profile ;
1524
+ if ( opts . email ) params . email = opts . email ;
1525
+ if ( opts . token ) params . token = opts . token ;
1526
+ if ( opts . answers ) params . answers = opts . answers ;
1527
+
1528
+ var config = {
1529
+ method : 'POST' ,
1530
+ url : opts . url + '/v1/attestation/' + opts . type + '/update' ,
1531
+ dataType : 'json' ,
1532
+ data : params
1533
+ } ;
1534
+
1535
+ var signedRequest = new SignedRequest ( config ) ;
1536
+ var signed = signedRequest . signHmac ( opts . auth_secret , opts . blob_id ) ;
1537
+
1538
+ request . post ( signed . url )
1539
+ . send ( signed . data )
1540
+ . end ( function ( err , resp ) {
1541
+
1542
+ if ( err ) {
1543
+ log . error ( 'attest:' , err ) ;
1544
+ fn ( new Error ( 'attestation error - XHR error' ) ) ;
1545
+ } else if ( resp . body && resp . body . result === 'success' ) {
1546
+ if ( resp . body . attestation ) {
1547
+ resp . body . decoded = BlobClient . parseAttestation ( resp . body . attestation ) ;
1548
+ }
1549
+
1550
+ fn ( null , resp . body ) ;
1551
+ } else if ( resp . body ) {
1552
+ log . error ( 'attestation:' , resp . body ) ;
1553
+ fn ( new Error ( 'attestation error: ' + resp . body . message || "" ) ) ;
1554
+ } else {
1555
+ fn ( new Error ( 'attestation error' ) ) ;
1556
+ }
1557
+ } ) ;
1558
+ } ;
1559
+
1560
+ /**
1561
+ * parseAttestation
1562
+ * @param {Object } attestation
1563
+ */
1564
+
1565
+ BlobClient . parseAttestation = function ( attestation ) {
1566
+ var segments = attestation . split ( '.' ) ;
1567
+ var decoded ;
1568
+
1569
+ // base64 decode and parse JSON
1570
+ try {
1571
+ decoded = {
1572
+ header : JSON . parse ( crypt . decodeBase64 ( segments [ 0 ] ) ) ,
1573
+ payload : JSON . parse ( crypt . decodeBase64 ( segments [ 1 ] ) ) ,
1574
+ signature : segments [ 2 ]
1575
+ } ;
1576
+
1577
+ } catch ( e ) {
1578
+ console . log ( "invalid attestation:" , e ) ;
1579
+ }
1580
+
1581
+ return decoded ;
1582
+ } ;
1583
+
1366
1584
exports . BlobClient = BlobClient ;
0 commit comments