mirror of
https://github.com/alexgo-io/stacks.js.git
synced 2026-04-29 09:45:50 +08:00
43
dist/blockstack.js
vendored
43
dist/blockstack.js
vendored
@@ -3493,12 +3493,13 @@ exports.Twitter = Twitter;
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.BLOCKSTACK_GAIA_HUB_LABEL = undefined;
|
||||
exports.APP_INDEX_FILE_NAME = exports.BLOCKSTACK_GAIA_HUB_LABEL = undefined;
|
||||
exports.uploadToGaiaHub = uploadToGaiaHub;
|
||||
exports.getFullReadUrl = getFullReadUrl;
|
||||
exports.connectToGaiaHub = connectToGaiaHub;
|
||||
exports.setLocalGaiaHubConnection = setLocalGaiaHubConnection;
|
||||
exports.getOrSetLocalGaiaHubConnection = getOrSetLocalGaiaHubConnection;
|
||||
exports.generateAppIndexFilePath = generateAppIndexFilePath;
|
||||
|
||||
var _bitcoinjsLib = require('bitcoinjs-lib');
|
||||
|
||||
@@ -3515,6 +3516,7 @@ var _authConstants = require('../auth/authConstants');
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var BLOCKSTACK_GAIA_HUB_LABEL = exports.BLOCKSTACK_GAIA_HUB_LABEL = 'blockstack-gaia-hub-config';
|
||||
var APP_INDEX_FILE_NAME = exports.APP_INDEX_FILE_NAME = 'app_index.json';
|
||||
|
||||
function uploadToGaiaHub(filename, contents, hubConfig) {
|
||||
var contentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'application/octet-stream';
|
||||
@@ -3573,6 +3575,8 @@ function connectToGaiaHub(gaiaHubUrl, challengeSignerHex) {
|
||||
function setLocalGaiaHubConnection() {
|
||||
var userData = (0, _authApp.loadUserData)();
|
||||
|
||||
console.log(userData);
|
||||
|
||||
if (!userData.hubUrl) {
|
||||
userData.hubUrl = _authConstants.BLOCKSTACK_DEFAULT_GAIA_HUB_URL;
|
||||
|
||||
@@ -3597,6 +3601,25 @@ function getOrSetLocalGaiaHubConnection() {
|
||||
return setLocalGaiaHubConnection();
|
||||
}
|
||||
}
|
||||
|
||||
function generateAppIndexFilePath(gaiaHubUrl, appPrivateKey) {
|
||||
console.log('connectToGaiaHub: ' + gaiaHubUrl + '/hub_info');
|
||||
var challengeSigner = new _bitcoinjsLib2.default.ECPair(_bigi2.default.fromHex(appPrivateKey));
|
||||
return new Promise(function (resolve) {
|
||||
fetch(gaiaHubUrl + '/hub_info').then(function (response) {
|
||||
return response.text();
|
||||
}).then(function (responseText) {
|
||||
return JSON.parse(responseText);
|
||||
}).then(function (responseJSON) {
|
||||
var readURL = responseJSON.read_url_prefix;
|
||||
var address = challengeSigner.getAddress();
|
||||
var appIndexUrl = '' + readURL + address + '/' + APP_INDEX_FILE_NAME;
|
||||
console.log('generateAppIndexFilePath');
|
||||
console.log(appIndexUrl);
|
||||
resolve(appIndexUrl);
|
||||
});
|
||||
});
|
||||
}
|
||||
}).call(this,require("buffer").Buffer)
|
||||
},{"../auth/authApp":1,"../auth/authConstants":2,"bigi":40,"bitcoinjs-lib":79,"buffer":135}],36:[function(require,module,exports){
|
||||
'use strict';
|
||||
@@ -3623,8 +3646,6 @@ var _keys = require('../keys');
|
||||
|
||||
var _profiles = require('../profiles');
|
||||
|
||||
var APP_INDEX_FILE_NAME = 'app_index.json';
|
||||
|
||||
/**
|
||||
* Retrieves the specified file from the app's data store.
|
||||
* @param {String} path - the path to the file to read
|
||||
@@ -3632,8 +3653,6 @@ var APP_INDEX_FILE_NAME = 'app_index.json';
|
||||
* @returns {Promise} that resolves to the raw data in the file
|
||||
* or rejects with an error
|
||||
*/
|
||||
|
||||
|
||||
function getFile(path) {
|
||||
var decrypt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
|
||||
@@ -3673,6 +3692,8 @@ function getFile(path) {
|
||||
* @return {Promise} that resolves if the operation succeed and rejects
|
||||
* if it failed
|
||||
*/
|
||||
|
||||
|
||||
function putFile(path, content) {
|
||||
var encrypt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
||||
|
||||
@@ -3694,13 +3715,13 @@ function putFile(path, content) {
|
||||
|
||||
/**
|
||||
* Get the app index file URL
|
||||
* @param {String} gaiaHubUrl - the gaia hub url to generate index file url for
|
||||
* @param {String} appPrivateKey - the app private key used to generate the app address
|
||||
* @returns {Promise} That resolves to the URL of the app index file
|
||||
* or rejects if it fails
|
||||
*/
|
||||
function getAppIndexFileUrl() {
|
||||
return (0, _hub.getOrSetLocalGaiaHubConnection)().then(function (gaiaHubConfig) {
|
||||
return '' + gaiaHubConfig.url_prefix + gaiaHubConfig.address + '\n /' + APP_INDEX_FILE_NAME;
|
||||
});
|
||||
function getAppIndexFileUrl(gaiaHubUrl, appPrivateKey) {
|
||||
return (0, _hub.generateAppIndexFilePath)(gaiaHubUrl, appPrivateKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3709,7 +3730,7 @@ function getAppIndexFileUrl() {
|
||||
* or rejects with an error
|
||||
*/
|
||||
function getAppIndexFile() {
|
||||
return this.getFile(APP_INDEX_FILE_NAME);
|
||||
return this.getFile(_hub.APP_INDEX_FILE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3721,7 +3742,7 @@ function getAppIndexFile() {
|
||||
* if it failed
|
||||
*/
|
||||
function putAppIndexFile(content) {
|
||||
return this.putFile(APP_INDEX_FILE_NAME, content, false);
|
||||
return this.putFile(_hub.APP_INDEX_FILE_NAME, content, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
513
docs.json
513
docs.json
@@ -6078,22 +6078,22 @@
|
||||
],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 13,
|
||||
"line": 12,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 19,
|
||||
"line": 18,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 20,
|
||||
"line": 19,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 50,
|
||||
"line": 49,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
@@ -6417,22 +6417,22 @@
|
||||
],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 52,
|
||||
"line": 51,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 59,
|
||||
"line": 58,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 60,
|
||||
"line": 59,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 74,
|
||||
"line": 73,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
@@ -7603,6 +7603,325 @@
|
||||
],
|
||||
"namespace": "getUserAppIndex"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Get the app index file URL",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"title": "param",
|
||||
"description": "the gaia hub url to generate index file url for",
|
||||
"lineNumber": 2,
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "String"
|
||||
},
|
||||
"name": "gaiaHubUrl"
|
||||
},
|
||||
{
|
||||
"title": "param",
|
||||
"description": "the app private key used to generate the app address",
|
||||
"lineNumber": 3,
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "String"
|
||||
},
|
||||
"name": "appPrivateKey"
|
||||
},
|
||||
{
|
||||
"title": "returns",
|
||||
"description": "That resolves to the URL of the app index file\nor rejects if it fails",
|
||||
"lineNumber": 4,
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "Promise"
|
||||
}
|
||||
}
|
||||
],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 75,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 81,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 82,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 84,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"file": "/Users/Yukan/Desktop/work/blockstack/blockstack.js/src/storage/index.js"
|
||||
},
|
||||
"augments": [],
|
||||
"examples": [],
|
||||
"params": [
|
||||
{
|
||||
"title": "param",
|
||||
"name": "gaiaHubUrl",
|
||||
"lineNumber": 2,
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "the gaia hub url to generate index file url for",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 48,
|
||||
"offset": 47
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 48,
|
||||
"offset": 47
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 48,
|
||||
"offset": 47
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "String"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "param",
|
||||
"name": "appPrivateKey",
|
||||
"lineNumber": 3,
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "the app private key used to generate the app address",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 53,
|
||||
"offset": 52
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 53,
|
||||
"offset": 52
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 53,
|
||||
"offset": 52
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "String"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": [],
|
||||
"returns": [
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "That resolves to the URL of the app index file\nor rejects if it fails",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
},
|
||||
"indent": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
},
|
||||
"indent": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "returns",
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "Promise"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sees": [],
|
||||
"throws": [],
|
||||
"todos": [],
|
||||
"name": "getAppIndexFileUrl",
|
||||
"kind": "function",
|
||||
"members": {
|
||||
"global": [],
|
||||
"inner": [],
|
||||
"instance": [],
|
||||
"events": [],
|
||||
"static": []
|
||||
},
|
||||
"path": [
|
||||
{
|
||||
"name": "getAppIndexFileUrl",
|
||||
"kind": "function"
|
||||
}
|
||||
],
|
||||
"namespace": "getAppIndexFileUrl"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
@@ -8354,7 +8673,7 @@
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 91,
|
||||
"line": 93,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
@@ -8445,182 +8764,6 @@
|
||||
],
|
||||
"namespace": "setLocalGaiaHubConnection"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Get the app index file URL",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
},
|
||||
"indent": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27,
|
||||
"offset": 26
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"title": "returns",
|
||||
"description": "That resolves to the URL of the app index file\nor rejects if it fails",
|
||||
"lineNumber": 2,
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "Promise"
|
||||
}
|
||||
}
|
||||
],
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 76,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 80,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 81,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 84,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"file": "/Users/Yukan/Desktop/work/blockstack/blockstack.js/src/storage/index.js"
|
||||
},
|
||||
"augments": [],
|
||||
"examples": [],
|
||||
"params": [],
|
||||
"properties": [],
|
||||
"returns": [
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "That resolves to the URL of the app index file\nor rejects if it fails",
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
},
|
||||
"indent": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
},
|
||||
"indent": [
|
||||
1
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1,
|
||||
"offset": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 23,
|
||||
"offset": 69
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "returns",
|
||||
"type": {
|
||||
"type": "NameExpression",
|
||||
"name": "Promise"
|
||||
}
|
||||
}
|
||||
],
|
||||
"sees": [],
|
||||
"throws": [],
|
||||
"todos": [],
|
||||
"name": "getAppIndexFileUrl",
|
||||
"kind": "function",
|
||||
"members": {
|
||||
"global": [],
|
||||
"inner": [],
|
||||
"instance": [],
|
||||
"events": [],
|
||||
"static": []
|
||||
},
|
||||
"path": [
|
||||
{
|
||||
"name": "getAppIndexFileUrl",
|
||||
"kind": "function"
|
||||
}
|
||||
],
|
||||
"namespace": "getAppIndexFileUrl"
|
||||
},
|
||||
{
|
||||
"description": {
|
||||
"type": "root",
|
||||
|
||||
155
docs/index.html
155
docs/index.html
@@ -254,6 +254,16 @@
|
||||
</li>
|
||||
|
||||
|
||||
<li><a
|
||||
href='#getappindexfileurl'
|
||||
class="">
|
||||
getAppIndexFileUrl
|
||||
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li><a
|
||||
href='#encryptecies'
|
||||
class="">
|
||||
@@ -284,16 +294,6 @@
|
||||
</li>
|
||||
|
||||
|
||||
<li><a
|
||||
href='#getappindexfileurl'
|
||||
class="">
|
||||
getAppIndexFileUrl
|
||||
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li><a
|
||||
href='#deletefile'
|
||||
class="">
|
||||
@@ -1982,6 +1982,85 @@ or rejects with an error
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section class='p2 mb2 clearfix bg-white minishadow'>
|
||||
|
||||
|
||||
<div class='clearfix'>
|
||||
|
||||
<h3 class='fl m0' id='getappindexfileurl'>
|
||||
getAppIndexFileUrl
|
||||
</h3>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<p>Get the app index file URL</p>
|
||||
|
||||
|
||||
<div class='pre p1 fill-light mt0'>getAppIndexFileUrl(gaiaHubUrl: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>, appPrivateKey: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class='py1 quiet mt1 prose-big'>Parameters</div>
|
||||
<div class='prose'>
|
||||
|
||||
<div class='space-bottom0'>
|
||||
<div>
|
||||
<span class='code bold'>gaiaHubUrl</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code>
|
||||
the gaia hub url to generate index file url for
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='space-bottom0'>
|
||||
<div>
|
||||
<span class='code bold'>appPrivateKey</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>)</code>
|
||||
the app private key used to generate the app address
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
||||
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>:
|
||||
That resolves to the URL of the app index file
|
||||
or rejects if it fails
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
@@ -2201,62 +2280,6 @@ a hub connection, and store the hub config to localstorage</p>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
<section class='p2 mb2 clearfix bg-white minishadow'>
|
||||
|
||||
|
||||
<div class='clearfix'>
|
||||
|
||||
<h3 class='fl m0' id='getappindexfileurl'>
|
||||
getAppIndexFileUrl
|
||||
</h3>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<p>Get the app index file URL</p>
|
||||
|
||||
|
||||
<div class='pre p1 fill-light mt0'>getAppIndexFileUrl(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
||||
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>:
|
||||
That resolves to the URL of the app index file
|
||||
or rejects if it fails
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -40,4 +40,5 @@ toc:
|
||||
- putFile
|
||||
- getAppIndexFile
|
||||
- putAppIndexFile
|
||||
- getUserAppIndex
|
||||
- getUserAppIndex
|
||||
- getAppIndexFileUrl
|
||||
@@ -5,7 +5,7 @@ import { loadUserData } from '../auth/authApp'
|
||||
import { BLOCKSTACK_DEFAULT_GAIA_HUB_URL, BLOCKSTACK_STORAGE_LABEL } from '../auth/authConstants'
|
||||
|
||||
export const BLOCKSTACK_GAIA_HUB_LABEL = 'blockstack-gaia-hub-config'
|
||||
|
||||
export const APP_INDEX_FILE_NAME = 'app_index.json'
|
||||
|
||||
export type GaiaHubConfig = {
|
||||
address: string,
|
||||
@@ -74,6 +74,8 @@ export function connectToGaiaHub(gaiaHubUrl: string, challengeSignerHex: string)
|
||||
export function setLocalGaiaHubConnection(): Promise<*> {
|
||||
let userData = loadUserData()
|
||||
|
||||
console.log(userData)
|
||||
|
||||
if (!userData.hubUrl) {
|
||||
userData.hubUrl = BLOCKSTACK_DEFAULT_GAIA_HUB_URL
|
||||
|
||||
@@ -98,3 +100,21 @@ export function getOrSetLocalGaiaHubConnection(): Promise<*> {
|
||||
return setLocalGaiaHubConnection()
|
||||
}
|
||||
}
|
||||
|
||||
export function generateAppIndexFilePath(gaiaHubUrl, appPrivateKey): Promise<*> {
|
||||
console.log(`connectToGaiaHub: ${gaiaHubUrl}/hub_info`)
|
||||
const challengeSigner = new bitcoin.ECPair(bigi.fromHex(appPrivateKey))
|
||||
return new Promise((resolve) => {
|
||||
fetch(`${gaiaHubUrl}/hub_info`)
|
||||
.then((response) => response.text())
|
||||
.then((responseText) => JSON.parse(responseText))
|
||||
.then((responseJSON) => {
|
||||
const readURL = responseJSON.read_url_prefix
|
||||
const address = challengeSigner.getAddress()
|
||||
const appIndexUrl = `${readURL}${address}/${APP_INDEX_FILE_NAME}`
|
||||
console.log('generateAppIndexFilePath')
|
||||
console.log(appIndexUrl)
|
||||
resolve(appIndexUrl)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
/* @flow */
|
||||
|
||||
import { getOrSetLocalGaiaHubConnection, getFullReadUrl, GaiaHubConfig,
|
||||
connectToGaiaHub, uploadToGaiaHub, BLOCKSTACK_GAIA_HUB_LABEL } from './hub'
|
||||
connectToGaiaHub, uploadToGaiaHub, generateAppIndexFilePath,
|
||||
BLOCKSTACK_GAIA_HUB_LABEL, APP_INDEX_FILE_NAME } from './hub'
|
||||
|
||||
import { encryptECIES, decryptECIES } from '../encryption'
|
||||
import { loadUserData } from '../auth'
|
||||
import { getPublicKeyFromPrivate } from '../keys'
|
||||
import { lookupProfile } from '../profiles'
|
||||
|
||||
const APP_INDEX_FILE_NAME = 'app_index.json'
|
||||
|
||||
/**
|
||||
* Retrieves the specified file from the app's data store.
|
||||
* @param {String} path - the path to the file to read
|
||||
@@ -75,13 +74,13 @@ export function putFile(path: string, content: string | Buffer, encrypt: boolean
|
||||
|
||||
/**
|
||||
* Get the app index file URL
|
||||
* @param {String} gaiaHubUrl - the gaia hub url to generate index file url for
|
||||
* @param {String} appPrivateKey - the app private key used to generate the app address
|
||||
* @returns {Promise} That resolves to the URL of the app index file
|
||||
* or rejects if it fails
|
||||
*/
|
||||
export function getAppIndexFileUrl(): string {
|
||||
return getOrSetLocalGaiaHubConnection()
|
||||
.then((gaiaHubConfig) => `${gaiaHubConfig.url_prefix}${gaiaHubConfig.address}
|
||||
/${APP_INDEX_FILE_NAME}`)
|
||||
export function getAppIndexFileUrl(gaiaHubUrl: string, appPrivateKey: string) {
|
||||
return generateAppIndexFilePath(gaiaHubUrl, appPrivateKey)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user