@ethersphere/bee-js 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +50 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +132 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +206 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +16 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +137 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.js +28326 -0
- package/dist/index.js.map +1 -0
- package/dist/mjs/bee-debug.js +509 -0
- package/dist/mjs/bee.js +845 -0
- package/dist/mjs/chunk/bmt.js +46 -0
- package/dist/mjs/chunk/cac.js +50 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +112 -0
- package/dist/mjs/chunk/soc.js +127 -0
- package/dist/mjs/chunk/span.js +25 -0
- package/dist/mjs/feed/index.js +136 -0
- package/dist/mjs/feed/json.js +23 -0
- package/dist/mjs/feed/topic.js +20 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +56 -0
- package/dist/mjs/modules/bzz.js +119 -0
- package/dist/mjs/modules/chunk.js +43 -0
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +131 -0
- package/dist/mjs/modules/debug/chunk.js +33 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stamps.js +59 -0
- package/dist/mjs/modules/debug/states.js +29 -0
- package/dist/mjs/modules/debug/status.js +114 -0
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +57 -0
- package/dist/mjs/modules/feed.js +61 -0
- package/dist/mjs/modules/pinning.js +60 -0
- package/dist/mjs/modules/pss.js +36 -0
- package/dist/mjs/modules/soc.js +28 -0
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +69 -0
- package/dist/mjs/package.json +7 -0
- package/dist/mjs/types/debug.js +6 -0
- package/dist/mjs/types/index.js +33 -0
- package/dist/mjs/utils/bytes.js +95 -0
- package/dist/mjs/utils/collection.browser.js +18 -0
- package/dist/mjs/utils/collection.js +52 -0
- package/dist/mjs/utils/collection.node.js +63 -0
- package/dist/mjs/utils/data.browser.js +57 -0
- package/dist/mjs/utils/data.js +39 -0
- package/dist/mjs/utils/error.js +48 -0
- package/dist/mjs/utils/eth.js +184 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +33 -0
- package/dist/mjs/utils/hash.js +12 -0
- package/dist/mjs/utils/headers.js +54 -0
- package/dist/mjs/utils/hex.js +139 -0
- package/dist/mjs/utils/http.js +136 -0
- package/dist/mjs/utils/merge.js +30 -0
- package/dist/mjs/utils/pss.js +14 -0
- package/dist/mjs/utils/stamps.js +13 -0
- package/dist/mjs/utils/stream.js +131 -0
- package/dist/mjs/utils/tar.js +18 -0
- package/dist/mjs/utils/type.js +296 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +50 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +8 -0
- package/dist/{src → types}/types/index.d.ts +1 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +0 -0
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +39 -23
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -59
- package/dist/index.browser.min.js.map +0 -1
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -24
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setJsonData = exports.getJsonData = void 0;
|
|
13
|
+
const type_1 = require("../utils/type");
|
|
14
|
+
function serializeJson(data) {
|
|
15
|
+
try {
|
|
16
|
+
const jsonString = JSON.stringify(data);
|
|
17
|
+
return new TextEncoder().encode(jsonString);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
if ((0, type_1.isError)(e)) {
|
|
21
|
+
e.message = `JsonFeed: ${e.message}`;
|
|
22
|
+
}
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function getJsonData(bee, reader) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const feedUpdate = yield reader.download();
|
|
29
|
+
const retrievedData = yield bee.downloadData(feedUpdate.reference);
|
|
30
|
+
return retrievedData.json();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.getJsonData = getJsonData;
|
|
34
|
+
function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const serializedData = serializeJson(data);
|
|
37
|
+
const { reference } = yield bee.uploadData(postageBatchId, serializedData, options);
|
|
38
|
+
return writer.upload(postageBatchId, reference);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.setJsonData = setJsonData;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTopicFromString = exports.makeTopic = void 0;
|
|
4
|
+
const hash_1 = require("../utils/hash");
|
|
5
|
+
const bytes_1 = require("../utils/bytes");
|
|
6
|
+
const hex_1 = require("../utils/hex");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
function makeTopic(topic) {
|
|
9
|
+
if (typeof topic === 'string') {
|
|
10
|
+
return (0, hex_1.makeHexString)(topic, types_1.TOPIC_HEX_LENGTH);
|
|
11
|
+
}
|
|
12
|
+
else if (topic instanceof Uint8Array) {
|
|
13
|
+
(0, bytes_1.assertBytes)(topic, types_1.TOPIC_BYTES_LENGTH);
|
|
14
|
+
return (0, hex_1.bytesToHex)(topic, types_1.TOPIC_HEX_LENGTH);
|
|
15
|
+
}
|
|
16
|
+
throw new TypeError('invalid topic');
|
|
17
|
+
}
|
|
18
|
+
exports.makeTopic = makeTopic;
|
|
19
|
+
function makeTopicFromString(s) {
|
|
20
|
+
if (typeof s !== 'string') {
|
|
21
|
+
throw new TypeError('topic has to be string!');
|
|
22
|
+
}
|
|
23
|
+
return (0, hex_1.bytesToHex)((0, hash_1.keccak256Hash)(s), types_1.TOPIC_HEX_LENGTH);
|
|
24
|
+
}
|
|
25
|
+
exports.makeTopicFromString = makeTopicFromString;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertFeedType = exports.isFeedType = exports.DEFAULT_FEED_TYPE = void 0;
|
|
4
|
+
const feedTypes = ['sequence', 'epoch'];
|
|
5
|
+
exports.DEFAULT_FEED_TYPE = 'sequence';
|
|
6
|
+
function isFeedType(type) {
|
|
7
|
+
return typeof type === 'string' && feedTypes.includes(type);
|
|
8
|
+
}
|
|
9
|
+
exports.isFeedType = isFeedType;
|
|
10
|
+
function assertFeedType(type) {
|
|
11
|
+
if (!isFeedType(type)) {
|
|
12
|
+
throw new TypeError('invalid feed type');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.assertFeedType = assertFeedType;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.BeeDebug = exports.Bee = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.Utils = void 0;
|
|
26
|
+
const bee_1 = require("./bee");
|
|
27
|
+
Object.defineProperty(exports, "Bee", { enumerable: true, get: function () { return bee_1.Bee; } });
|
|
28
|
+
const bee_debug_1 = require("./bee-debug");
|
|
29
|
+
Object.defineProperty(exports, "BeeDebug", { enumerable: true, get: function () { return bee_debug_1.BeeDebug; } });
|
|
30
|
+
exports.Utils = __importStar(require("./utils/expose"));
|
|
31
|
+
__exportStar(require("./types"), exports);
|
|
32
|
+
__exportStar(require("./utils/error"), exports);
|
|
33
|
+
var status_1 = require("./modules/debug/status");
|
|
34
|
+
Object.defineProperty(exports, "SUPPORTED_BEE_VERSION", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION; } });
|
|
35
|
+
Object.defineProperty(exports, "SUPPORTED_BEE_VERSION_EXACT", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION_EXACT; } });
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.downloadReadable = exports.download = exports.upload = void 0;
|
|
13
|
+
const data_1 = require("../utils/data");
|
|
14
|
+
const headers_1 = require("../utils/headers");
|
|
15
|
+
const http_1 = require("../utils/http");
|
|
16
|
+
const bytes_1 = require("../utils/bytes");
|
|
17
|
+
const type_1 = require("../utils/type");
|
|
18
|
+
const endpoint = 'bytes';
|
|
19
|
+
/**
|
|
20
|
+
* Upload data to a Bee node
|
|
21
|
+
*
|
|
22
|
+
* @param ky Ky instance
|
|
23
|
+
* @param data Data to be uploaded
|
|
24
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
25
|
+
* @param options Additional options like tag, encryption, pinning
|
|
26
|
+
*/
|
|
27
|
+
function upload(ky, data, postageBatchId, options) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const response = yield (0, http_1.http)(ky, {
|
|
30
|
+
path: endpoint,
|
|
31
|
+
method: 'post',
|
|
32
|
+
responseType: 'json',
|
|
33
|
+
body: yield (0, data_1.prepareData)(data),
|
|
34
|
+
headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
reference: response.data.reference,
|
|
38
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.upload = upload;
|
|
43
|
+
/**
|
|
44
|
+
* Download data as a byte array
|
|
45
|
+
*
|
|
46
|
+
* @param ky
|
|
47
|
+
* @param hash Bee content reference
|
|
48
|
+
*/
|
|
49
|
+
function download(ky, hash) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const response = yield (0, http_1.http)(ky, {
|
|
52
|
+
responseType: 'arraybuffer',
|
|
53
|
+
path: `${endpoint}/${hash}`,
|
|
54
|
+
});
|
|
55
|
+
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.download = download;
|
|
59
|
+
/**
|
|
60
|
+
* Download data as a readable stream
|
|
61
|
+
*
|
|
62
|
+
* @param ky
|
|
63
|
+
* @param hash Bee content reference
|
|
64
|
+
*/
|
|
65
|
+
function downloadReadable(ky, hash) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const response = yield (0, http_1.http)(ky, {
|
|
68
|
+
responseType: 'stream',
|
|
69
|
+
path: `${endpoint}/${hash}`,
|
|
70
|
+
});
|
|
71
|
+
return response.data;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
exports.downloadReadable = downloadReadable;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
|
|
13
|
+
const headers_1 = require("../utils/headers");
|
|
14
|
+
const http_1 = require("../utils/http");
|
|
15
|
+
const data_1 = require("../utils/data");
|
|
16
|
+
const tar_1 = require("../utils/tar");
|
|
17
|
+
const collection_1 = require("../utils/collection");
|
|
18
|
+
const bytes_1 = require("../utils/bytes");
|
|
19
|
+
const stream_1 = require("../utils/stream");
|
|
20
|
+
const type_1 = require("../utils/type");
|
|
21
|
+
const bzzEndpoint = 'bzz';
|
|
22
|
+
function extractFileUploadHeaders(postageBatchId, options) {
|
|
23
|
+
const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
|
|
24
|
+
if (options === null || options === void 0 ? void 0 : options.size)
|
|
25
|
+
headers['content-length'] = String(options.size);
|
|
26
|
+
if (options === null || options === void 0 ? void 0 : options.contentType)
|
|
27
|
+
headers['content-type'] = options.contentType;
|
|
28
|
+
return headers;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Upload single file
|
|
32
|
+
*
|
|
33
|
+
* @param ky
|
|
34
|
+
* @param data Files data
|
|
35
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
36
|
+
* @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
|
|
37
|
+
* @param options
|
|
38
|
+
*/
|
|
39
|
+
function uploadFile(ky, data, postageBatchId, name, options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if ((0, stream_1.isReadable)(data) && !(options === null || options === void 0 ? void 0 : options.contentType)) {
|
|
42
|
+
if (!options)
|
|
43
|
+
options = {};
|
|
44
|
+
options.contentType = 'application/octet-stream';
|
|
45
|
+
}
|
|
46
|
+
const response = yield (0, http_1.http)(ky, {
|
|
47
|
+
method: 'post',
|
|
48
|
+
path: bzzEndpoint,
|
|
49
|
+
body: yield (0, data_1.prepareData)(data),
|
|
50
|
+
headers: Object.assign({}, extractFileUploadHeaders(postageBatchId, options)),
|
|
51
|
+
searchParams: { name },
|
|
52
|
+
responseType: 'json',
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
reference: response.data.reference,
|
|
56
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.uploadFile = uploadFile;
|
|
61
|
+
/**
|
|
62
|
+
* Download single file as a buffer
|
|
63
|
+
*
|
|
64
|
+
* @param ky Ky instance for given Bee class instance
|
|
65
|
+
* @param hash Bee file or collection hash
|
|
66
|
+
* @param path If hash is collection then this defines path to a single file in the collection
|
|
67
|
+
*/
|
|
68
|
+
function downloadFile(ky, hash, path = '') {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const response = yield (0, http_1.http)(ky, {
|
|
71
|
+
method: 'GET',
|
|
72
|
+
responseType: 'arraybuffer',
|
|
73
|
+
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
74
|
+
});
|
|
75
|
+
const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data)) });
|
|
76
|
+
return file;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.downloadFile = downloadFile;
|
|
80
|
+
/**
|
|
81
|
+
* Download single file as a readable stream
|
|
82
|
+
*
|
|
83
|
+
* @param ky Ky instance for given Bee class instance
|
|
84
|
+
* @param hash Bee file or collection hash
|
|
85
|
+
* @param path If hash is collection then this defines path to a single file in the collection
|
|
86
|
+
*/
|
|
87
|
+
function downloadFileReadable(ky, hash, path = '') {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const response = yield (0, http_1.http)(ky, {
|
|
90
|
+
method: 'GET',
|
|
91
|
+
responseType: 'stream',
|
|
92
|
+
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
93
|
+
});
|
|
94
|
+
const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: response.data });
|
|
95
|
+
return file;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.downloadFileReadable = downloadFileReadable;
|
|
99
|
+
function extractCollectionUploadHeaders(postageBatchId, options) {
|
|
100
|
+
const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
|
|
101
|
+
if (options === null || options === void 0 ? void 0 : options.indexDocument)
|
|
102
|
+
headers['swarm-index-document'] = options.indexDocument;
|
|
103
|
+
if (options === null || options === void 0 ? void 0 : options.errorDocument)
|
|
104
|
+
headers['swarm-error-document'] = options.errorDocument;
|
|
105
|
+
return headers;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Upload collection
|
|
109
|
+
* @param ky Ky instance for given Bee class instance
|
|
110
|
+
* @param collection Collection of Uint8Array buffers to upload
|
|
111
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
112
|
+
* @param options
|
|
113
|
+
*/
|
|
114
|
+
function uploadCollection(ky, collection, postageBatchId, options) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
(0, collection_1.assertCollection)(collection);
|
|
117
|
+
const tarData = (0, tar_1.makeTar)(collection);
|
|
118
|
+
const response = yield (0, http_1.http)(ky, {
|
|
119
|
+
method: 'post',
|
|
120
|
+
path: bzzEndpoint,
|
|
121
|
+
body: tarData,
|
|
122
|
+
responseType: 'json',
|
|
123
|
+
headers: Object.assign({ 'content-type': 'application/x-tar', 'swarm-collection': 'true' }, extractCollectionUploadHeaders(postageBatchId, options)),
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
reference: response.data.reference,
|
|
127
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
exports.uploadCollection = uploadCollection;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.download = exports.upload = void 0;
|
|
13
|
+
const headers_1 = require("../utils/headers");
|
|
14
|
+
const http_1 = require("../utils/http");
|
|
15
|
+
const bytes_1 = require("../utils/bytes");
|
|
16
|
+
const endpoint = 'chunks';
|
|
17
|
+
/**
|
|
18
|
+
* Upload chunk to a Bee node
|
|
19
|
+
*
|
|
20
|
+
* The chunk data consists of 8 byte span and up to 4096 bytes of payload data.
|
|
21
|
+
* The span stores the length of the payload in uint64 little endian encoding.
|
|
22
|
+
* Upload expects the chuck data to be set accordingly.
|
|
23
|
+
*
|
|
24
|
+
* @param ky Ky instance
|
|
25
|
+
* @param data Chunk data to be uploaded
|
|
26
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
27
|
+
* @param options Additional options like tag, encryption, pinning
|
|
28
|
+
*/
|
|
29
|
+
function upload(ky, data, postageBatchId, options) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const response = yield (0, http_1.http)(ky, {
|
|
32
|
+
method: 'post',
|
|
33
|
+
path: `${endpoint}`,
|
|
34
|
+
body: data,
|
|
35
|
+
headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
|
|
36
|
+
responseType: 'json',
|
|
37
|
+
});
|
|
38
|
+
return response.data.reference;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.upload = upload;
|
|
42
|
+
/**
|
|
43
|
+
* Download chunk data as a byte array
|
|
44
|
+
*
|
|
45
|
+
* @param ky Ky instance for given Bee class instance
|
|
46
|
+
* @param hash Bee content reference
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
function download(ky, hash) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const response = yield (0, http_1.http)(ky, {
|
|
52
|
+
responseType: 'arraybuffer',
|
|
53
|
+
path: `${endpoint}/${hash}`,
|
|
54
|
+
});
|
|
55
|
+
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.download = download;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getPastDueConsumptionPeerBalance = exports.getPastDueConsumptionBalances = exports.getPeerBalance = exports.getAllBalances = void 0;
|
|
13
|
+
const http_1 = require("../../utils/http");
|
|
14
|
+
const balancesEndpoint = 'balances';
|
|
15
|
+
const consumedEndpoint = 'consumed';
|
|
16
|
+
/**
|
|
17
|
+
* Get the balances with all known peers including prepaid services
|
|
18
|
+
*
|
|
19
|
+
* @param ky Ky debug instance
|
|
20
|
+
*/
|
|
21
|
+
function getAllBalances(ky) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const response = yield (0, http_1.http)(ky, {
|
|
24
|
+
path: balancesEndpoint,
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.getAllBalances = getAllBalances;
|
|
31
|
+
/**
|
|
32
|
+
* Get the balances with a specific peer including prepaid services
|
|
33
|
+
*
|
|
34
|
+
* @param ky Ky debug instance
|
|
35
|
+
* @param address Swarm address of peer
|
|
36
|
+
*/
|
|
37
|
+
function getPeerBalance(ky, address) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const response = yield (0, http_1.http)(ky, {
|
|
40
|
+
path: `${balancesEndpoint}/${address}`,
|
|
41
|
+
responseType: 'json',
|
|
42
|
+
});
|
|
43
|
+
return response.data;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.getPeerBalance = getPeerBalance;
|
|
47
|
+
/**
|
|
48
|
+
* Get the past due consumption balances with all known peers
|
|
49
|
+
*
|
|
50
|
+
* @param ky Ky debug instance
|
|
51
|
+
*/
|
|
52
|
+
function getPastDueConsumptionBalances(ky) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const response = yield (0, http_1.http)(ky, {
|
|
55
|
+
path: consumedEndpoint,
|
|
56
|
+
responseType: 'json',
|
|
57
|
+
});
|
|
58
|
+
return response.data;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
|
|
62
|
+
/**
|
|
63
|
+
* Get the past due consumption balance with a specific peer
|
|
64
|
+
*
|
|
65
|
+
* @param ky Ky debug instance
|
|
66
|
+
* @param address Swarm address of peer
|
|
67
|
+
*/
|
|
68
|
+
function getPastDueConsumptionPeerBalance(ky, address) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const response = yield (0, http_1.http)(ky, {
|
|
71
|
+
path: `${consumedEndpoint}/${address}`,
|
|
72
|
+
responseType: 'json',
|
|
73
|
+
});
|
|
74
|
+
return response.data;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.withdrawTokens = exports.depositTokens = exports.getLastCheques = exports.getLastChequesForPeer = exports.cashoutLastCheque = exports.getLastCashoutAction = exports.getChequebookBalance = exports.getChequebookAddress = void 0;
|
|
13
|
+
const http_1 = require("../../utils/http");
|
|
14
|
+
const chequebookEndpoint = 'chequebook';
|
|
15
|
+
/**
|
|
16
|
+
* Get the address of the chequebook contract used
|
|
17
|
+
*
|
|
18
|
+
* @param ky Ky debug instance
|
|
19
|
+
*/
|
|
20
|
+
function getChequebookAddress(ky) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const response = yield (0, http_1.http)(ky, {
|
|
23
|
+
path: chequebookEndpoint + '/address',
|
|
24
|
+
responseType: 'json',
|
|
25
|
+
});
|
|
26
|
+
return response.data;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.getChequebookAddress = getChequebookAddress;
|
|
30
|
+
/**
|
|
31
|
+
* Get the balance of the chequebook
|
|
32
|
+
*
|
|
33
|
+
* @param ky Ky debug instance
|
|
34
|
+
*/
|
|
35
|
+
function getChequebookBalance(ky) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const response = yield (0, http_1.http)(ky, {
|
|
38
|
+
path: chequebookEndpoint + '/balance',
|
|
39
|
+
responseType: 'json',
|
|
40
|
+
});
|
|
41
|
+
return response.data;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.getChequebookBalance = getChequebookBalance;
|
|
45
|
+
/**
|
|
46
|
+
* Get last cashout action for the peer
|
|
47
|
+
*
|
|
48
|
+
* @param ky Ky debug instance
|
|
49
|
+
* @param peer Swarm address of peer
|
|
50
|
+
*/
|
|
51
|
+
function getLastCashoutAction(ky, peer) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const response = yield (0, http_1.http)(ky, {
|
|
54
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
55
|
+
responseType: 'json',
|
|
56
|
+
});
|
|
57
|
+
return response.data;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.getLastCashoutAction = getLastCashoutAction;
|
|
61
|
+
/**
|
|
62
|
+
* Cashout the last cheque for the peer
|
|
63
|
+
*
|
|
64
|
+
* @param ky Ky debug instance
|
|
65
|
+
* @param peer Swarm address of peer
|
|
66
|
+
* @param options
|
|
67
|
+
*/
|
|
68
|
+
function cashoutLastCheque(ky, peer, options) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const headers = {};
|
|
71
|
+
if (options === null || options === void 0 ? void 0 : options.gasPrice) {
|
|
72
|
+
headers['gas-price'] = options.gasPrice.toString();
|
|
73
|
+
}
|
|
74
|
+
if (options === null || options === void 0 ? void 0 : options.gasLimit) {
|
|
75
|
+
headers['gas-limit'] = options.gasLimit.toString();
|
|
76
|
+
}
|
|
77
|
+
const response = yield (0, http_1.http)(ky, {
|
|
78
|
+
method: 'post',
|
|
79
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
80
|
+
responseType: 'json',
|
|
81
|
+
headers,
|
|
82
|
+
});
|
|
83
|
+
return response.data.transactionHash;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.cashoutLastCheque = cashoutLastCheque;
|
|
87
|
+
/**
|
|
88
|
+
* Get last cheques for the peer
|
|
89
|
+
*
|
|
90
|
+
* @param ky Ky debug instance
|
|
91
|
+
* @param peer Swarm address of peer
|
|
92
|
+
*/
|
|
93
|
+
function getLastChequesForPeer(ky, peer) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const response = yield (0, http_1.http)(ky, {
|
|
96
|
+
path: chequebookEndpoint + `/cheque/${peer}`,
|
|
97
|
+
responseType: 'json',
|
|
98
|
+
});
|
|
99
|
+
return response.data;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
exports.getLastChequesForPeer = getLastChequesForPeer;
|
|
103
|
+
/**
|
|
104
|
+
* Get last cheques for all peers
|
|
105
|
+
*
|
|
106
|
+
* @param ky Ky debug instance
|
|
107
|
+
*/
|
|
108
|
+
function getLastCheques(ky) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const response = yield (0, http_1.http)(ky, {
|
|
111
|
+
path: chequebookEndpoint + '/cheque',
|
|
112
|
+
responseType: 'json',
|
|
113
|
+
});
|
|
114
|
+
return response.data;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
exports.getLastCheques = getLastCheques;
|
|
118
|
+
/**
|
|
119
|
+
* Deposit tokens from overlay address into chequebook
|
|
120
|
+
*
|
|
121
|
+
* @param ky Ky debug instance
|
|
122
|
+
* @param amount Amount of tokens to deposit
|
|
123
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
124
|
+
* @return string Hash of the transaction
|
|
125
|
+
*/
|
|
126
|
+
function depositTokens(ky, amount, gasPrice) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const headers = {};
|
|
129
|
+
if (gasPrice) {
|
|
130
|
+
headers['gas-price'] = gasPrice.toString();
|
|
131
|
+
}
|
|
132
|
+
const response = yield (0, http_1.http)(ky, {
|
|
133
|
+
method: 'post',
|
|
134
|
+
path: chequebookEndpoint + '/deposit',
|
|
135
|
+
responseType: 'json',
|
|
136
|
+
searchParams: { amount: amount.toString(10) },
|
|
137
|
+
headers,
|
|
138
|
+
});
|
|
139
|
+
return response.data.transactionHash;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
exports.depositTokens = depositTokens;
|
|
143
|
+
/**
|
|
144
|
+
* Withdraw tokens from the chequebook to the overlay address
|
|
145
|
+
*
|
|
146
|
+
* @param ky Ky debug instance
|
|
147
|
+
* @param amount Amount of tokens to withdraw
|
|
148
|
+
* @param gasPrice Gas Price in WEI for the transaction call
|
|
149
|
+
* @return string Hash of the transaction
|
|
150
|
+
*/
|
|
151
|
+
function withdrawTokens(ky, amount, gasPrice) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const headers = {};
|
|
154
|
+
if (gasPrice) {
|
|
155
|
+
headers['gas-price'] = gasPrice.toString();
|
|
156
|
+
}
|
|
157
|
+
const response = yield (0, http_1.http)(ky, {
|
|
158
|
+
method: 'post',
|
|
159
|
+
path: chequebookEndpoint + '/withdraw',
|
|
160
|
+
responseType: 'json',
|
|
161
|
+
searchParams: { amount: amount.toString(10) },
|
|
162
|
+
headers,
|
|
163
|
+
});
|
|
164
|
+
return response.data.transactionHash;
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
exports.withdrawTokens = withdrawTokens;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.deleteChunkFromLocalStorage = exports.checkIfChunkExistsLocally = void 0;
|
|
13
|
+
const http_1 = require("../../utils/http");
|
|
14
|
+
const endpoint = 'chunks';
|
|
15
|
+
/**
|
|
16
|
+
* Check if chunk at address exists locally
|
|
17
|
+
*
|
|
18
|
+
* @param ky Ky debug instance
|
|
19
|
+
* @param address Swarm address of chunk
|
|
20
|
+
*
|
|
21
|
+
* @returns BeeGenericResponse if chunk is found or throws an exception
|
|
22
|
+
*/
|
|
23
|
+
function checkIfChunkExistsLocally(ky, address) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const response = yield (0, http_1.http)(ky, {
|
|
26
|
+
path: endpoint + `/${address}`,
|
|
27
|
+
responseType: 'json',
|
|
28
|
+
});
|
|
29
|
+
return response.data;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.checkIfChunkExistsLocally = checkIfChunkExistsLocally;
|
|
33
|
+
/**
|
|
34
|
+
* Delete a chunk from local storage
|
|
35
|
+
*
|
|
36
|
+
* @param ky Ky debug instance
|
|
37
|
+
* @param address Swarm address of chunk
|
|
38
|
+
*
|
|
39
|
+
* @returns BeeGenericResponse if chunk was deleted or throws an exception
|
|
40
|
+
*/
|
|
41
|
+
function deleteChunkFromLocalStorage(ky, address) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const response = yield (0, http_1.http)(ky, {
|
|
44
|
+
method: 'delete',
|
|
45
|
+
path: endpoint + `/${address}`,
|
|
46
|
+
responseType: 'json',
|
|
47
|
+
});
|
|
48
|
+
return response.data;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
exports.deleteChunkFromLocalStorage = deleteChunkFromLocalStorage;
|