@erebos/api-bzz-base
Advanced tools
Comparing version 0.4.2 to 0.5.0
117
cjs/index.js
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
var _exportNames = { | ||
BZZ_MODE_PROTOCOLS: true, | ||
getModeProtocol: true, | ||
HTTPError: true, | ||
resOrError: true, | ||
resJSON: true, | ||
resText: true | ||
}; | ||
exports.default = exports.resText = exports.resJSON = exports.resOrError = exports.HTTPError = exports.getModeProtocol = exports.BZZ_MODE_PROTOCOLS = void 0; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); | ||
@@ -16,4 +28,22 @@ | ||
var _hex = _interopRequireWildcard(require("@erebos/hex")); | ||
var _feed = require("./feed"); | ||
Object.keys(_feed).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _feed[key]; | ||
}); | ||
var _types = require("./types"); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _types[key]; | ||
}); | ||
var BZZ_MODE_PROTOCOLS = { | ||
default: 'bzz:/', | ||
feed: 'bzz-feed:/', | ||
immutable: 'bzz-immutable:/', | ||
@@ -124,2 +154,33 @@ raw: 'bzz-raw:/' | ||
_proto.getFeedURL = function getFeedURL(userOrHash, options, flag) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var url = this._url + BZZ_MODE_PROTOCOLS.feed; | ||
var params = []; | ||
if ((0, _hex.isHexValue)(userOrHash)) { | ||
// user | ||
params = Object.keys(options).reduce(function (acc, key) { | ||
var value = options[key]; | ||
if (value != null) { | ||
acc.push(key + "=" + value); | ||
} | ||
return acc; | ||
}, ["user=" + userOrHash]); | ||
} else { | ||
// hash | ||
url += userOrHash; | ||
} | ||
if (flag != null) { | ||
params.push(flag + "=1"); | ||
} | ||
return url + "?" + params.join('&'); | ||
}; | ||
_proto.hash = function hash(domain, headers) { | ||
@@ -243,2 +304,58 @@ if (headers === void 0) { | ||
_proto.createFeedManifest = function createFeedManifest(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var manifest = { | ||
entries: [{ | ||
contentType: 'application/bzz-feed', | ||
mod_time: '0001-01-01T00:00:00Z', | ||
feed: { | ||
topic: (0, _feed.getFeedTopic)(options), | ||
user: user | ||
} | ||
}] | ||
}; | ||
return this.uploadFile(JSON.stringify(manifest)).then(_hex.hexValueType); | ||
}; | ||
_proto.getFeedMetadata = function getFeedMetadata(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return this._fetch(this.getFeedURL(user, options, 'meta')).then(resJSON); | ||
}; | ||
_proto.getFeedValue = function getFeedValue(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return this._fetch(this.getFeedURL(user, options)).then(resOrError); | ||
}; | ||
_proto.postFeedValue = function postFeedValue(keyPair, data, options) { | ||
var _this2 = this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var user = (0, _feed.pubKeyToAddress)(keyPair.getPublic()); | ||
return this.getFeedMetadata(user, options).then(function (meta) { | ||
var body = (0, _hex.default)(data).toBuffer(); | ||
var url = _this2.getFeedURL(user, (0, _extends2.default)({}, meta.feed, meta.epoch, { | ||
signature: (0, _feed.signFeedUpdate)(meta, body, keyPair.getPrivate()) | ||
})); | ||
return _this2._fetch(url, { | ||
method: 'POST', | ||
body: body | ||
}); | ||
}).then(resOrError); | ||
}; | ||
return BaseBzz; | ||
@@ -245,0 +362,0 @@ }(); |
@@ -0,1 +1,2 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; | ||
@@ -5,4 +6,9 @@ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized"; | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import createHex, { hexValueType, isHexValue } from '@erebos/hex'; | ||
import { getFeedTopic, pubKeyToAddress, signFeedUpdate } from './feed'; | ||
export * from './feed'; | ||
export * from './types'; | ||
export var BZZ_MODE_PROTOCOLS = { | ||
default: 'bzz:/', | ||
feed: 'bzz-feed:/', | ||
immutable: 'bzz-immutable:/', | ||
@@ -101,2 +107,33 @@ raw: 'bzz-raw:/' | ||
_proto.getFeedURL = function getFeedURL(userOrHash, options, flag) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var url = this._url + BZZ_MODE_PROTOCOLS.feed; | ||
var params = []; | ||
if (isHexValue(userOrHash)) { | ||
// user | ||
params = Object.keys(options).reduce(function (acc, key) { | ||
var value = options[key]; | ||
if (value != null) { | ||
acc.push(key + "=" + value); | ||
} | ||
return acc; | ||
}, ["user=" + userOrHash]); | ||
} else { | ||
// hash | ||
url += userOrHash; | ||
} | ||
if (flag != null) { | ||
params.push(flag + "=1"); | ||
} | ||
return url + "?" + params.join('&'); | ||
}; | ||
_proto.hash = function hash(domain, headers) { | ||
@@ -220,2 +257,58 @@ if (headers === void 0) { | ||
_proto.createFeedManifest = function createFeedManifest(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var manifest = { | ||
entries: [{ | ||
contentType: 'application/bzz-feed', | ||
mod_time: '0001-01-01T00:00:00Z', | ||
feed: { | ||
topic: getFeedTopic(options), | ||
user: user | ||
} | ||
}] | ||
}; | ||
return this.uploadFile(JSON.stringify(manifest)).then(hexValueType); | ||
}; | ||
_proto.getFeedMetadata = function getFeedMetadata(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return this._fetch(this.getFeedURL(user, options, 'meta')).then(resJSON); | ||
}; | ||
_proto.getFeedValue = function getFeedValue(user, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
return this._fetch(this.getFeedURL(user, options)).then(resOrError); | ||
}; | ||
_proto.postFeedValue = function postFeedValue(keyPair, data, options) { | ||
var _this2 = this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var user = pubKeyToAddress(keyPair.getPublic()); | ||
return this.getFeedMetadata(user, options).then(function (meta) { | ||
var body = createHex(data).toBuffer(); | ||
var url = _this2.getFeedURL(user, _extends({}, meta.feed, meta.epoch, { | ||
signature: signFeedUpdate(meta, body, keyPair.getPrivate()) | ||
})); | ||
return _this2._fetch(url, { | ||
method: 'POST', | ||
body: body | ||
}); | ||
}).then(resOrError); | ||
}; | ||
return BaseBzz; | ||
@@ -222,0 +315,0 @@ }(); |
{ | ||
"name": "@erebos/api-bzz-base", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Base Bzz API", | ||
@@ -24,4 +24,10 @@ "repository": "git@github.com:MainframeHQ/erebos.git", | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0" | ||
"@babel/runtime": "^7.0.0", | ||
"@erebos/hex": "^0.5.0", | ||
"elliptic": "MainframeHQ/elliptic#circular-dependencies-fix", | ||
"js-sha3": "^0.8.0" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.86.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44333
14
653
4
1
1
1
+ Added@erebos/hex@^0.5.0
+ Addedelliptic@MainframeHQ/elliptic#circular-dependencies-fix
+ Addedjs-sha3@^0.8.0
+ Added@erebos/hex@0.5.4(transitive)
+ Addedjs-sha3@0.8.0(transitive)