@upcoming/bee-js 0.10.1 → 0.11.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/index.js +3 -1
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -26,11 +26,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.BeeDev = exports.Bee = exports.Utils = exports.Duration = exports.Bytes = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.MerkleTree = void 0;
|
|
29
|
+
exports.Stamper = exports.BeeDev = exports.Bee = exports.Utils = exports.Duration = exports.Bytes = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.MerkleTree = void 0;
|
|
30
30
|
const bee_1 = require("./bee");
|
|
31
31
|
Object.defineProperty(exports, "Bee", { enumerable: true, get: function () { return bee_1.Bee; } });
|
|
32
32
|
const bee_dev_1 = require("./bee-dev");
|
|
33
33
|
Object.defineProperty(exports, "BeeDev", { enumerable: true, get: function () { return bee_dev_1.BeeDev; } });
|
|
34
|
+
const stamper_1 = require("./stamper/stamper");
|
|
35
|
+
Object.defineProperty(exports, "Stamper", { enumerable: true, get: function () { return stamper_1.Stamper; } });
|
|
34
36
|
var cafe_utility_1 = require("cafe-utility");
|
|
35
37
|
Object.defineProperty(exports, "MerkleTree", { enumerable: true, get: function () { return cafe_utility_1.MerkleTree; } });
|
|
36
38
|
var manifest_1 = require("./manifest/manifest");
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Stamper = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
6
|
+
class Stamper {
|
|
7
|
+
constructor(signer, batchId, buckets, depth) {
|
|
8
|
+
this.signer = new typed_bytes_1.PrivateKey(signer);
|
|
9
|
+
this.batchId = new typed_bytes_1.BatchId(batchId);
|
|
10
|
+
this.buckets = buckets;
|
|
11
|
+
this.depth = depth;
|
|
12
|
+
this.maxSlot = 2 ** (this.depth - 16);
|
|
13
|
+
}
|
|
14
|
+
static fromBlank(signer, batchId, depth) {
|
|
15
|
+
return new Stamper(signer, batchId, new Uint32Array(65536), depth);
|
|
16
|
+
}
|
|
17
|
+
static fromState(signer, batchId, buckets, depth) {
|
|
18
|
+
return new Stamper(signer, batchId, buckets, depth);
|
|
19
|
+
}
|
|
20
|
+
stamp(chunk) {
|
|
21
|
+
const address = chunk.hash();
|
|
22
|
+
const bucket = cafe_utility_1.Binary.uint16ToNumber(address, 'BE');
|
|
23
|
+
const height = this.buckets[bucket];
|
|
24
|
+
if (height >= this.maxSlot) {
|
|
25
|
+
throw Error('Bucket is full');
|
|
26
|
+
}
|
|
27
|
+
this.buckets[bucket]++;
|
|
28
|
+
const index = cafe_utility_1.Binary.concatBytes(cafe_utility_1.Binary.numberToUint32(bucket, 'BE'), cafe_utility_1.Binary.numberToUint32(height, 'BE'));
|
|
29
|
+
const timestamp = cafe_utility_1.Binary.numberToUint64(BigInt(Date.now()), 'BE');
|
|
30
|
+
const signature = this.signer.sign(cafe_utility_1.Binary.concatBytes(address, this.batchId.toUint8Array(), index, timestamp));
|
|
31
|
+
return {
|
|
32
|
+
batchId: this.batchId,
|
|
33
|
+
index,
|
|
34
|
+
issuer: this.signer.publicKey().address().toUint8Array(),
|
|
35
|
+
signature: signature.toUint8Array(),
|
|
36
|
+
timestamp,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
getState() {
|
|
40
|
+
return this.buckets;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Stamper = Stamper;
|