@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/mjs/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Bee } from "./bee.js";
2
2
  import { BeeDev } from "./bee-dev.js";
3
+ import { Stamper } from "./stamper/stamper.js";
3
4
  export { MerkleTree } from 'cafe-utility';
4
5
  export { MantarayNode } from "./manifest/manifest.js";
5
6
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from "./modules/debug/status.js";
@@ -11,4 +12,4 @@ export * from "./utils/error.js";
11
12
  export * as Utils from "./utils/expose.js";
12
13
  export * from "./utils/tokens.js";
13
14
  export * from "./utils/typed-bytes.js";
14
- export { Bee, BeeDev };
15
+ export { Bee, BeeDev, Stamper };
@@ -0,0 +1,39 @@
1
+ import { Binary } from 'cafe-utility';
2
+ import { BatchId, PrivateKey } from "../utils/typed-bytes.js";
3
+ export class Stamper {
4
+ constructor(signer, batchId, buckets, depth) {
5
+ this.signer = new PrivateKey(signer);
6
+ this.batchId = new BatchId(batchId);
7
+ this.buckets = buckets;
8
+ this.depth = depth;
9
+ this.maxSlot = 2 ** (this.depth - 16);
10
+ }
11
+ static fromBlank(signer, batchId, depth) {
12
+ return new Stamper(signer, batchId, new Uint32Array(65536), depth);
13
+ }
14
+ static fromState(signer, batchId, buckets, depth) {
15
+ return new Stamper(signer, batchId, buckets, depth);
16
+ }
17
+ stamp(chunk) {
18
+ const address = chunk.hash();
19
+ const bucket = Binary.uint16ToNumber(address, 'BE');
20
+ const height = this.buckets[bucket];
21
+ if (height >= this.maxSlot) {
22
+ throw Error('Bucket is full');
23
+ }
24
+ this.buckets[bucket]++;
25
+ const index = Binary.concatBytes(Binary.numberToUint32(bucket, 'BE'), Binary.numberToUint32(height, 'BE'));
26
+ const timestamp = Binary.numberToUint64(BigInt(Date.now()), 'BE');
27
+ const signature = this.signer.sign(Binary.concatBytes(address, this.batchId.toUint8Array(), index, timestamp));
28
+ return {
29
+ batchId: this.batchId,
30
+ index,
31
+ issuer: this.signer.publicKey().address().toUint8Array(),
32
+ signature: signature.toUint8Array(),
33
+ timestamp
34
+ };
35
+ }
36
+ getState() {
37
+ return this.buckets;
38
+ }
39
+ }
@@ -1,5 +1,6 @@
1
1
  import { Bee } from './bee';
2
2
  import { BeeDev } from './bee-dev';
3
+ import { Stamper } from './stamper/stamper';
3
4
  export { MerkleTree } from 'cafe-utility';
4
5
  export { MantarayNode } from './manifest/manifest';
5
6
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from './modules/debug/status';
@@ -11,12 +12,13 @@ export * from './utils/error';
11
12
  export * as Utils from './utils/expose';
12
13
  export * from './utils/tokens';
13
14
  export * from './utils/typed-bytes';
14
- export { Bee, BeeDev };
15
+ export { Bee, BeeDev, Stamper };
15
16
  declare global {
16
17
  interface Window {
17
18
  BeeJs: {
18
19
  Bee: typeof import('./bee').Bee;
19
20
  BeeDev: typeof import('./bee-dev').BeeDev;
21
+ Stamper: typeof import('./stamper/stamper').Stamper;
20
22
  Utils: typeof import('./utils/expose');
21
23
  Duration: typeof import('./utils/duration').Duration;
22
24
  BeeError: typeof import('./utils/error').BeeError;
@@ -0,0 +1,15 @@
1
+ import { Chunk } from 'cafe-utility';
2
+ import { EnvelopeWithBatchId } from '../types';
3
+ import { BatchId, PrivateKey } from '../utils/typed-bytes';
4
+ export declare class Stamper {
5
+ signer: PrivateKey;
6
+ batchId: BatchId;
7
+ buckets: Uint32Array;
8
+ depth: number;
9
+ maxSlot: number;
10
+ private constructor();
11
+ static fromBlank(signer: PrivateKey | Uint8Array | string, batchId: BatchId | Uint8Array | string, depth: number): Stamper;
12
+ static fromState(signer: PrivateKey | Uint8Array | string, batchId: BatchId | Uint8Array | string, buckets: Uint32Array, depth: number): Stamper;
13
+ stamp(chunk: Chunk): EnvelopeWithBatchId;
14
+ getState(): Uint32Array;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upcoming/bee-js",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",