@totemsdk/wots-lease 0.1.2 → 0.1.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Totem SDK Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -92,6 +92,6 @@ entries.forEach(e => console.log(e.flatIndex, e.allocatedAt, e.committedAt));
92
92
 
93
93
  ## See also
94
94
 
95
- - [`@totemsdk/core`](../core) — WOTS primitives this package protects
96
- - [`@totemsdk/lookup-node`](../lookup-node) — `LeaseCoordinator` for multi-client setups
97
- - [`@totemsdk/omnia`](../omnia) — integrates wots-lease to protect channel signing slots
95
+ - [`@totemsdk/core`](https://www.npmjs.com/package/@totemsdk/core) — WOTS primitives this package protects
96
+ - [`@totemsdk/lookup-node`](https://www.npmjs.com/package/@totemsdk/lookup-node) — `LeaseCoordinator` for multi-client setups
97
+ - [`@totemsdk/omnia`](https://www.npmjs.com/package/@totemsdk/omnia) — integrates wots-lease to protect channel signing slots
package/dist/axia.js CHANGED
@@ -1,23 +1,26 @@
1
+ "use strict";
1
2
  /**
2
3
  * AxiaLeaseProvider — wraps the Axia API's /v1/wots-hardened endpoints.
3
4
  *
4
5
  * Callers do NOT need to call /finalize separately — commitKeyUse() does it.
5
6
  */
6
- import { NoopLogger, LeaseStore } from '@totemsdk/core';
7
- import { prepareLease, finalizeLease } from '@totemsdk/core';
8
- import { WotsWatermarkStore, flatIndex } from './watermark.js';
9
- import { LeaseJournal } from './journal.js';
10
- import { LeaseNotFoundError } from './errors.js';
11
- export class AxiaLeaseProvider {
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.AxiaLeaseProvider = void 0;
9
+ const core_1 = require("@totemsdk/core");
10
+ const core_2 = require("@totemsdk/core");
11
+ const watermark_js_1 = require("./watermark.js");
12
+ const journal_js_1 = require("./journal.js");
13
+ const errors_js_1 = require("./errors.js");
14
+ class AxiaLeaseProvider {
12
15
  constructor(config) {
13
16
  this._initialized = false;
14
17
  this.apiUrl = config.apiUrl;
15
18
  this.apiKey = config.apiKey;
16
19
  this.rootPublicKey = config.rootPublicKey;
17
- this.logger = config.logger ?? new NoopLogger();
18
- this.watermark = new WotsWatermarkStore(config.storage, this.logger);
19
- this.leaseStore = new LeaseStore(config.storage, this.logger);
20
- this.journal = new LeaseJournal(config.storage, this.logger);
20
+ this.logger = config.logger ?? new core_1.NoopLogger();
21
+ this.watermark = new watermark_js_1.WotsWatermarkStore(config.storage, this.logger);
22
+ this.leaseStore = new core_1.LeaseStore(config.storage, this.logger);
23
+ this.journal = new journal_js_1.LeaseJournal(config.storage, this.logger);
21
24
  }
22
25
  async initialize() {
23
26
  if (this._initialized)
@@ -31,7 +34,7 @@ export class AxiaLeaseProvider {
31
34
  if (!this._initialized)
32
35
  await this.initialize();
33
36
  const txId = params.payloadHash ?? `tx-${Date.now()}`;
34
- const resp = await prepareLease(this.apiUrl, this.apiKey, {
37
+ const resp = await (0, core_2.prepareLease)(this.apiUrl, this.apiKey, {
35
38
  txId,
36
39
  rootPublicKey: this.rootPublicKey,
37
40
  to: params.treeId,
@@ -54,7 +57,7 @@ export class AxiaLeaseProvider {
54
57
  await this.journal.append({
55
58
  treeId: params.treeId,
56
59
  branchId: params.branchId ?? 'default',
57
- wotsIndex: flatIndex(indices),
60
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
58
61
  indices,
59
62
  status: 'reserved',
60
63
  payloadHash: params.payloadHash,
@@ -68,15 +71,15 @@ export class AxiaLeaseProvider {
68
71
  await this.initialize();
69
72
  const lease = this.leaseStore.get(reservationId);
70
73
  if (!lease)
71
- throw new LeaseNotFoundError(reservationId);
72
- await finalizeLease(this.apiUrl, this.apiKey, lease.leaseToken, txId);
74
+ throw new errors_js_1.LeaseNotFoundError(reservationId);
75
+ await (0, core_2.finalizeLease)(this.apiUrl, this.apiKey, lease.leaseToken, txId);
73
76
  const indices = lease.indices;
74
77
  await this.watermark.markUnavailable(lease.indices.addressIndex.toString(), indices, 'committed');
75
78
  await this.leaseStore.updateStatus(reservationId, 'finalized');
76
79
  await this.journal.append({
77
80
  treeId: reservationId,
78
81
  branchId: 'default',
79
- wotsIndex: flatIndex(indices),
82
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
80
83
  indices,
81
84
  status: 'committed',
82
85
  txId,
@@ -89,7 +92,7 @@ export class AxiaLeaseProvider {
89
92
  await this.initialize();
90
93
  const lease = this.leaseStore.get(reservationId);
91
94
  if (!lease)
92
- throw new LeaseNotFoundError(reservationId);
95
+ throw new errors_js_1.LeaseNotFoundError(reservationId);
93
96
  const indices = lease.indices;
94
97
  await this.watermark.markUnavailable(lease.indices.addressIndex.toString(), indices, 'burned');
95
98
  await this.leaseStore.updateStatus(reservationId, 'cancelled');
@@ -97,7 +100,7 @@ export class AxiaLeaseProvider {
97
100
  await this.journal.append({
98
101
  treeId: reservationId,
99
102
  branchId: 'default',
100
- wotsIndex: flatIndex(indices),
103
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
101
104
  indices,
102
105
  status: 'burned',
103
106
  timestamp: Date.now(),
@@ -121,3 +124,4 @@ export class AxiaLeaseProvider {
121
124
  return false;
122
125
  }
123
126
  }
127
+ exports.AxiaLeaseProvider = AxiaLeaseProvider;
package/dist/device.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Device keyspace partitioning — Layer 2.
3
4
  *
@@ -10,9 +11,12 @@
10
11
  * device 2 → addressIndex 16–23
11
12
  * ...
12
13
  */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.allocateDeviceRange = allocateDeviceRange;
16
+ exports.deviceSlotForAddressIndex = deviceSlotForAddressIndex;
13
17
  const ADDRESSES_PER_DEVICE = 8;
14
18
  const MAX_DEVICE_SLOTS = 8;
15
- export function allocateDeviceRange(params) {
19
+ function allocateDeviceRange(params) {
16
20
  if (params.deviceSlot < 0 || params.deviceSlot >= MAX_DEVICE_SLOTS) {
17
21
  throw new RangeError(`Device slot must be 0–${MAX_DEVICE_SLOTS - 1}, got ${params.deviceSlot}`);
18
22
  }
@@ -25,6 +29,6 @@ export function allocateDeviceRange(params) {
25
29
  addressCount: ADDRESSES_PER_DEVICE,
26
30
  };
27
31
  }
28
- export function deviceSlotForAddressIndex(addressIndex) {
32
+ function deviceSlotForAddressIndex(addressIndex) {
29
33
  return Math.floor(addressIndex / ADDRESSES_PER_DEVICE);
30
34
  }
package/dist/errors.js CHANGED
@@ -1,43 +1,52 @@
1
- export class WatermarkMonotonicityError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceRangeViolationError = exports.OnchainWatermarkNotImplementedError = exports.P2PQuorumNotImplementedError = exports.PersonalLeaseNodeNotConfiguredError = exports.LeaseNotFoundError = exports.WatermarkExhaustedError = exports.WatermarkMonotonicityError = void 0;
4
+ class WatermarkMonotonicityError extends Error {
2
5
  constructor(message) {
3
6
  super(message);
4
7
  this.name = 'WatermarkMonotonicityError';
5
8
  }
6
9
  }
7
- export class WatermarkExhaustedError extends Error {
10
+ exports.WatermarkMonotonicityError = WatermarkMonotonicityError;
11
+ class WatermarkExhaustedError extends Error {
8
12
  constructor(treeId) {
9
13
  super(`WOTS keyspace exhausted for tree: ${treeId}`);
10
14
  this.treeId = treeId;
11
15
  this.name = 'WatermarkExhaustedError';
12
16
  }
13
17
  }
14
- export class LeaseNotFoundError extends Error {
18
+ exports.WatermarkExhaustedError = WatermarkExhaustedError;
19
+ class LeaseNotFoundError extends Error {
15
20
  constructor(reservationId) {
16
21
  super(`Lease reservation not found: ${reservationId}`);
17
22
  this.reservationId = reservationId;
18
23
  this.name = 'LeaseNotFoundError';
19
24
  }
20
25
  }
21
- export class PersonalLeaseNodeNotConfiguredError extends Error {
26
+ exports.LeaseNotFoundError = LeaseNotFoundError;
27
+ class PersonalLeaseNodeNotConfiguredError extends Error {
22
28
  constructor() {
23
29
  super('PersonalLeaseNodeProvider requires a running lookup node. ' +
24
30
  'Deploy @totemsdk/lookup-node and configure { nodeUrl, nodePubkey }.');
25
31
  this.name = 'PersonalLeaseNodeNotConfiguredError';
26
32
  }
27
33
  }
28
- export class P2PQuorumNotImplementedError extends Error {
34
+ exports.PersonalLeaseNodeNotConfiguredError = PersonalLeaseNodeNotConfiguredError;
35
+ class P2PQuorumNotImplementedError extends Error {
29
36
  constructor() {
30
37
  super('P2PQuorumLeaseProvider is not yet implemented.');
31
38
  this.name = 'P2PQuorumNotImplementedError';
32
39
  }
33
40
  }
34
- export class OnchainWatermarkNotImplementedError extends Error {
41
+ exports.P2PQuorumNotImplementedError = P2PQuorumNotImplementedError;
42
+ class OnchainWatermarkNotImplementedError extends Error {
35
43
  constructor() {
36
44
  super('OnchainWatermarkProvider is not yet implemented.');
37
45
  this.name = 'OnchainWatermarkNotImplementedError';
38
46
  }
39
47
  }
40
- export class DeviceRangeViolationError extends Error {
48
+ exports.OnchainWatermarkNotImplementedError = OnchainWatermarkNotImplementedError;
49
+ class DeviceRangeViolationError extends Error {
41
50
  constructor(addressIndex, allowedStart, allowedEnd) {
42
51
  super(`Address index ${addressIndex} is outside device range [${allowedStart}, ${allowedEnd}]`);
43
52
  this.addressIndex = addressIndex;
@@ -46,3 +55,4 @@ export class DeviceRangeViolationError extends Error {
46
55
  this.name = 'DeviceRangeViolationError';
47
56
  }
48
57
  }
58
+ exports.DeviceRangeViolationError = DeviceRangeViolationError;
package/dist/hybrid.js CHANGED
@@ -1,10 +1,13 @@
1
+ "use strict";
1
2
  /**
2
3
  * HybridLeaseProvider — recommended production default.
3
4
  *
4
5
  * Always uses local first, then gates on node cert and/or quorum attestation
5
6
  * for transactions above a configurable value threshold.
6
7
  */
7
- export class HybridLeaseProvider {
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HybridLeaseProvider = void 0;
10
+ class HybridLeaseProvider {
8
11
  constructor(config) {
9
12
  this.local = config.local;
10
13
  this.node = config.node;
@@ -62,3 +65,4 @@ export class HybridLeaseProvider {
62
65
  return false;
63
66
  }
64
67
  }
68
+ exports.HybridLeaseProvider = HybridLeaseProvider;
package/dist/index.js CHANGED
@@ -1,8 +1,30 @@
1
- export { WotsWatermarkStore, flatIndex, fromFlatIndex, } from './watermark.js';
2
- export { LeaseJournal } from './journal.js';
3
- export { LocalLeaseProvider } from './local.js';
4
- export { AxiaLeaseProvider } from './axia.js';
5
- export { HybridLeaseProvider } from './hybrid.js';
6
- export { PersonalLeaseNodeProvider, P2PQuorumLeaseProvider, OnchainWatermarkProvider, } from './stubs.js';
7
- export { allocateDeviceRange, deviceSlotForAddressIndex } from './device.js';
8
- export { WatermarkMonotonicityError, WatermarkExhaustedError, LeaseNotFoundError, PersonalLeaseNodeNotConfiguredError, P2PQuorumNotImplementedError, OnchainWatermarkNotImplementedError, DeviceRangeViolationError, } from './errors.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceRangeViolationError = exports.OnchainWatermarkNotImplementedError = exports.P2PQuorumNotImplementedError = exports.PersonalLeaseNodeNotConfiguredError = exports.LeaseNotFoundError = exports.WatermarkExhaustedError = exports.WatermarkMonotonicityError = exports.deviceSlotForAddressIndex = exports.allocateDeviceRange = exports.OnchainWatermarkProvider = exports.P2PQuorumLeaseProvider = exports.PersonalLeaseNodeProvider = exports.HybridLeaseProvider = exports.AxiaLeaseProvider = exports.LocalLeaseProvider = exports.LeaseJournal = exports.fromFlatIndex = exports.flatIndex = exports.WotsWatermarkStore = void 0;
4
+ var watermark_js_1 = require("./watermark.js");
5
+ Object.defineProperty(exports, "WotsWatermarkStore", { enumerable: true, get: function () { return watermark_js_1.WotsWatermarkStore; } });
6
+ Object.defineProperty(exports, "flatIndex", { enumerable: true, get: function () { return watermark_js_1.flatIndex; } });
7
+ Object.defineProperty(exports, "fromFlatIndex", { enumerable: true, get: function () { return watermark_js_1.fromFlatIndex; } });
8
+ var journal_js_1 = require("./journal.js");
9
+ Object.defineProperty(exports, "LeaseJournal", { enumerable: true, get: function () { return journal_js_1.LeaseJournal; } });
10
+ var local_js_1 = require("./local.js");
11
+ Object.defineProperty(exports, "LocalLeaseProvider", { enumerable: true, get: function () { return local_js_1.LocalLeaseProvider; } });
12
+ var axia_js_1 = require("./axia.js");
13
+ Object.defineProperty(exports, "AxiaLeaseProvider", { enumerable: true, get: function () { return axia_js_1.AxiaLeaseProvider; } });
14
+ var hybrid_js_1 = require("./hybrid.js");
15
+ Object.defineProperty(exports, "HybridLeaseProvider", { enumerable: true, get: function () { return hybrid_js_1.HybridLeaseProvider; } });
16
+ var stubs_js_1 = require("./stubs.js");
17
+ Object.defineProperty(exports, "PersonalLeaseNodeProvider", { enumerable: true, get: function () { return stubs_js_1.PersonalLeaseNodeProvider; } });
18
+ Object.defineProperty(exports, "P2PQuorumLeaseProvider", { enumerable: true, get: function () { return stubs_js_1.P2PQuorumLeaseProvider; } });
19
+ Object.defineProperty(exports, "OnchainWatermarkProvider", { enumerable: true, get: function () { return stubs_js_1.OnchainWatermarkProvider; } });
20
+ var device_js_1 = require("./device.js");
21
+ Object.defineProperty(exports, "allocateDeviceRange", { enumerable: true, get: function () { return device_js_1.allocateDeviceRange; } });
22
+ Object.defineProperty(exports, "deviceSlotForAddressIndex", { enumerable: true, get: function () { return device_js_1.deviceSlotForAddressIndex; } });
23
+ var errors_js_1 = require("./errors.js");
24
+ Object.defineProperty(exports, "WatermarkMonotonicityError", { enumerable: true, get: function () { return errors_js_1.WatermarkMonotonicityError; } });
25
+ Object.defineProperty(exports, "WatermarkExhaustedError", { enumerable: true, get: function () { return errors_js_1.WatermarkExhaustedError; } });
26
+ Object.defineProperty(exports, "LeaseNotFoundError", { enumerable: true, get: function () { return errors_js_1.LeaseNotFoundError; } });
27
+ Object.defineProperty(exports, "PersonalLeaseNodeNotConfiguredError", { enumerable: true, get: function () { return errors_js_1.PersonalLeaseNodeNotConfiguredError; } });
28
+ Object.defineProperty(exports, "P2PQuorumNotImplementedError", { enumerable: true, get: function () { return errors_js_1.P2PQuorumNotImplementedError; } });
29
+ Object.defineProperty(exports, "OnchainWatermarkNotImplementedError", { enumerable: true, get: function () { return errors_js_1.OnchainWatermarkNotImplementedError; } });
30
+ Object.defineProperty(exports, "DeviceRangeViolationError", { enumerable: true, get: function () { return errors_js_1.DeviceRangeViolationError; } });
package/dist/journal.js CHANGED
@@ -1,11 +1,14 @@
1
+ "use strict";
1
2
  /**
2
3
  * LeaseJournal — append-only audit log for WOTS key-use events.
3
4
  * Preserves the full history: reserved → committed | burned | reserved-expired.
4
5
  */
5
- import { NoopLogger } from '@totemsdk/core';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LeaseJournal = void 0;
8
+ const core_1 = require("@totemsdk/core");
6
9
  const STORAGE_KEY = 'totem_wots_journal';
7
- export class LeaseJournal {
8
- constructor(storage, logger = new NoopLogger()) {
10
+ class LeaseJournal {
11
+ constructor(storage, logger = new core_1.NoopLogger()) {
9
12
  this.storage = storage;
10
13
  this.logger = logger;
11
14
  this.entries = [];
@@ -37,3 +40,4 @@ export class LeaseJournal {
37
40
  await this.storage.remove(STORAGE_KEY);
38
41
  }
39
42
  }
43
+ exports.LeaseJournal = LeaseJournal;
package/dist/local.js CHANGED
@@ -1,29 +1,32 @@
1
+ "use strict";
1
2
  /**
2
3
  * LocalLeaseProvider — Layer 1: local durable ledger.
3
4
  *
4
5
  * Single-device, no network coordination.
5
6
  * All WOTS safety guaranteed by the local WotsWatermarkStore + LeaseJournal.
6
7
  */
7
- import { NoopLogger } from '@totemsdk/core';
8
- import { LeaseStore } from '@totemsdk/core';
9
- import { WotsWatermarkStore, flatIndex } from './watermark.js';
10
- import { LeaseJournal } from './journal.js';
11
- import { LeaseNotFoundError, DeviceRangeViolationError } from './errors.js';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.LocalLeaseProvider = void 0;
10
+ const core_1 = require("@totemsdk/core");
11
+ const core_2 = require("@totemsdk/core");
12
+ const watermark_js_1 = require("./watermark.js");
13
+ const journal_js_1 = require("./journal.js");
14
+ const errors_js_1 = require("./errors.js");
12
15
  function randomId() {
13
16
  if (typeof crypto !== 'undefined' && crypto.randomUUID) {
14
17
  return crypto.randomUUID();
15
18
  }
16
19
  return Math.random().toString(36).slice(2) + Date.now().toString(36);
17
20
  }
18
- export class LocalLeaseProvider {
19
- constructor(storage, logger = new NoopLogger(), deviceId = 'local') {
21
+ class LocalLeaseProvider {
22
+ constructor(storage, logger = new core_1.NoopLogger(), deviceId = 'local') {
20
23
  this.logger = logger;
21
24
  this._initialized = false;
22
25
  /** In-memory map: reservationId → treeId (lost on restart; watermark survives). */
23
26
  this._treeIdByReservation = new Map();
24
- this.watermark = new WotsWatermarkStore(storage, logger);
25
- this.leaseStore = new LeaseStore(storage, logger);
26
- this.journal = new LeaseJournal(storage, logger);
27
+ this.watermark = new watermark_js_1.WotsWatermarkStore(storage, logger);
28
+ this.leaseStore = new core_2.LeaseStore(storage, logger);
29
+ this.journal = new journal_js_1.LeaseJournal(storage, logger);
27
30
  this.deviceId = deviceId;
28
31
  }
29
32
  async initialize() {
@@ -45,7 +48,7 @@ export class LocalLeaseProvider {
45
48
  await this.journal.append({
46
49
  treeId,
47
50
  branchId: 'default',
48
- wotsIndex: flatIndex(lease.indices),
51
+ wotsIndex: (0, watermark_js_1.flatIndex)(lease.indices),
49
52
  indices: lease.indices,
50
53
  status: 'reserved-expired',
51
54
  timestamp: now,
@@ -63,7 +66,7 @@ export class LocalLeaseProvider {
63
66
  if (params.deviceId) {
64
67
  const range = this.getDeviceRange(params.deviceId);
65
68
  if (range && (indices.addressIndex < range.start || indices.addressIndex > range.end)) {
66
- throw new DeviceRangeViolationError(indices.addressIndex, range.start, range.end);
69
+ throw new errors_js_1.DeviceRangeViolationError(indices.addressIndex, range.start, range.end);
67
70
  }
68
71
  }
69
72
  const reservationId = randomId();
@@ -83,7 +86,7 @@ export class LocalLeaseProvider {
83
86
  await this.journal.append({
84
87
  treeId,
85
88
  branchId: params.branchId ?? 'default',
86
- wotsIndex: flatIndex(indices),
89
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
87
90
  indices,
88
91
  status: 'reserved',
89
92
  payloadHash: params.payloadHash,
@@ -97,7 +100,7 @@ export class LocalLeaseProvider {
97
100
  await this.initialize();
98
101
  const lease = this.leaseStore.get(reservationId);
99
102
  if (!lease)
100
- throw new LeaseNotFoundError(reservationId);
103
+ throw new errors_js_1.LeaseNotFoundError(reservationId);
101
104
  const treeId = this._treeIdByReservation.get(reservationId) ?? 'default';
102
105
  const indices = lease.indices;
103
106
  await this.watermark.markUnavailable(treeId, indices, 'committed');
@@ -106,7 +109,7 @@ export class LocalLeaseProvider {
106
109
  await this.journal.append({
107
110
  treeId,
108
111
  branchId: 'default',
109
- wotsIndex: flatIndex(indices),
112
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
110
113
  indices,
111
114
  status: 'committed',
112
115
  txId,
@@ -119,7 +122,7 @@ export class LocalLeaseProvider {
119
122
  await this.initialize();
120
123
  const lease = this.leaseStore.get(reservationId);
121
124
  if (!lease)
122
- throw new LeaseNotFoundError(reservationId);
125
+ throw new errors_js_1.LeaseNotFoundError(reservationId);
123
126
  const treeId = this._treeIdByReservation.get(reservationId) ?? 'default';
124
127
  const indices = lease.indices;
125
128
  await this.watermark.markUnavailable(treeId, indices, 'burned');
@@ -129,7 +132,7 @@ export class LocalLeaseProvider {
129
132
  await this.journal.append({
130
133
  treeId,
131
134
  branchId: 'default',
132
- wotsIndex: flatIndex(indices),
135
+ wotsIndex: (0, watermark_js_1.flatIndex)(indices),
133
136
  indices,
134
137
  status: 'burned',
135
138
  timestamp: Date.now(),
@@ -161,3 +164,4 @@ export class LocalLeaseProvider {
161
164
  return { start: slot * 8, end: slot * 8 + 7 };
162
165
  }
163
166
  }
167
+ exports.LocalLeaseProvider = LocalLeaseProvider;
package/dist/stubs.js CHANGED
@@ -1,8 +1,11 @@
1
+ "use strict";
1
2
  /**
2
3
  * Stub implementations for Layers 3–5.
3
4
  * These throw descriptive errors until the full implementations land.
4
5
  */
5
- import { PersonalLeaseNodeNotConfiguredError, P2PQuorumNotImplementedError, OnchainWatermarkNotImplementedError, } from './errors.js';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.OnchainWatermarkProvider = exports.P2PQuorumLeaseProvider = exports.PersonalLeaseNodeProvider = void 0;
8
+ const errors_js_1 = require("./errors.js");
6
9
  /**
7
10
  * Layer 3 — personal p2p lease node.
8
11
  *
@@ -10,27 +13,27 @@ import { PersonalLeaseNodeNotConfiguredError, P2PQuorumNotImplementedError, Onch
10
13
  * Reserve/commit throws until the node is reachable — callers should
11
14
  * wrap with HybridLeaseProvider using a LocalLeaseProvider as the local layer.
12
15
  */
13
- export class PersonalLeaseNodeProvider {
16
+ class PersonalLeaseNodeProvider {
14
17
  constructor(config) {
15
18
  this.config = config;
16
19
  }
17
20
  reserveKeyUse(_params) {
18
- throw new PersonalLeaseNodeNotConfiguredError();
21
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
19
22
  }
20
23
  commitKeyUse(_reservationId, _txId) {
21
- throw new PersonalLeaseNodeNotConfiguredError();
24
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
22
25
  }
23
26
  burnReservation(_reservationId, _reason) {
24
- throw new PersonalLeaseNodeNotConfiguredError();
27
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
25
28
  }
26
29
  getLocalWatermark(_treeId) {
27
- throw new PersonalLeaseNodeNotConfiguredError();
30
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
28
31
  }
29
32
  publishWatermark(_treeId) {
30
- throw new PersonalLeaseNodeNotConfiguredError();
33
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
31
34
  }
32
35
  syncLeaseJournal() {
33
- throw new PersonalLeaseNodeNotConfiguredError();
36
+ throw new errors_js_1.PersonalLeaseNodeNotConfiguredError();
34
37
  }
35
38
  async verifyLeaseCertificate(cert) {
36
39
  if (!cert)
@@ -42,51 +45,54 @@ export class PersonalLeaseNodeProvider {
42
45
  return true;
43
46
  }
44
47
  }
48
+ exports.PersonalLeaseNodeProvider = PersonalLeaseNodeProvider;
45
49
  /** Layer 4 — p2p replicated lease witnesses. */
46
- export class P2PQuorumLeaseProvider {
50
+ class P2PQuorumLeaseProvider {
47
51
  reserveKeyUse(_params) {
48
- throw new P2PQuorumNotImplementedError();
52
+ throw new errors_js_1.P2PQuorumNotImplementedError();
49
53
  }
50
54
  commitKeyUse(_reservationId, _txId) {
51
- throw new P2PQuorumNotImplementedError();
55
+ throw new errors_js_1.P2PQuorumNotImplementedError();
52
56
  }
53
57
  burnReservation(_reservationId, _reason) {
54
- throw new P2PQuorumNotImplementedError();
58
+ throw new errors_js_1.P2PQuorumNotImplementedError();
55
59
  }
56
60
  getLocalWatermark(_treeId) {
57
- throw new P2PQuorumNotImplementedError();
61
+ throw new errors_js_1.P2PQuorumNotImplementedError();
58
62
  }
59
63
  publishWatermark(_treeId) {
60
- throw new P2PQuorumNotImplementedError();
64
+ throw new errors_js_1.P2PQuorumNotImplementedError();
61
65
  }
62
66
  syncLeaseJournal() {
63
- throw new P2PQuorumNotImplementedError();
67
+ throw new errors_js_1.P2PQuorumNotImplementedError();
64
68
  }
65
69
  verifyLeaseCertificate(_cert) {
66
- throw new P2PQuorumNotImplementedError();
70
+ throw new errors_js_1.P2PQuorumNotImplementedError();
67
71
  }
68
72
  }
73
+ exports.P2PQuorumLeaseProvider = P2PQuorumLeaseProvider;
69
74
  /** Layer 5 — on-chain watermark coin. */
70
- export class OnchainWatermarkProvider {
75
+ class OnchainWatermarkProvider {
71
76
  reserveKeyUse(_params) {
72
- throw new OnchainWatermarkNotImplementedError();
77
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
73
78
  }
74
79
  commitKeyUse(_reservationId, _txId) {
75
- throw new OnchainWatermarkNotImplementedError();
80
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
76
81
  }
77
82
  burnReservation(_reservationId, _reason) {
78
- throw new OnchainWatermarkNotImplementedError();
83
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
79
84
  }
80
85
  getLocalWatermark(_treeId) {
81
- throw new OnchainWatermarkNotImplementedError();
86
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
82
87
  }
83
88
  publishWatermark(_treeId) {
84
- throw new OnchainWatermarkNotImplementedError();
89
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
85
90
  }
86
91
  syncLeaseJournal() {
87
- throw new OnchainWatermarkNotImplementedError();
92
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
88
93
  }
89
94
  verifyLeaseCertificate(_cert) {
90
- throw new OnchainWatermarkNotImplementedError();
95
+ throw new errors_js_1.OnchainWatermarkNotImplementedError();
91
96
  }
92
97
  }
98
+ exports.OnchainWatermarkProvider = OnchainWatermarkProvider;
package/dist/types.js CHANGED
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /**
2
3
  * @totemsdk/wots-lease — canonical v3 watermark types and WotsLeaseProvider interface
3
4
  */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/watermark.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * WotsWatermarkStore — canonical v3 implementation
3
4
  *
@@ -6,16 +7,20 @@
6
7
  * - Enforces monotonicity: unavailable map can only grow, cursors can only advance.
7
8
  * - Storage key unchanged ('totem_wots_watermark') to avoid storage churn.
8
9
  */
9
- import { NoopLogger } from '@totemsdk/core';
10
- import { WatermarkMonotonicityError, WatermarkExhaustedError } from './errors.js';
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.WotsWatermarkStore = void 0;
12
+ exports.flatIndex = flatIndex;
13
+ exports.fromFlatIndex = fromFlatIndex;
14
+ const core_1 = require("@totemsdk/core");
15
+ const errors_js_1 = require("./errors.js");
11
16
  const STORAGE_KEY = 'totem_wots_watermark';
12
17
  const MAX_L = 64;
13
18
  const CAPACITY_PER_TREE = MAX_L * MAX_L * MAX_L;
14
19
  const DEFAULT_TREE = 'default';
15
- export function flatIndex(idx) {
20
+ function flatIndex(idx) {
16
21
  return idx.addressIndex * MAX_L * MAX_L + idx.l1 * MAX_L + idx.l2;
17
22
  }
18
- export function fromFlatIndex(flat) {
23
+ function fromFlatIndex(flat) {
19
24
  const addressIndex = Math.floor(flat / (MAX_L * MAX_L));
20
25
  const rem = flat % (MAX_L * MAX_L);
21
26
  const l1 = Math.floor(rem / MAX_L);
@@ -82,8 +87,8 @@ function migrateToV3(raw) {
82
87
  tree.l2Cursor = v1.next_l2 ?? 0;
83
88
  return { version: 3, trees: { [DEFAULT_TREE]: tree } };
84
89
  }
85
- export class WotsWatermarkStore {
86
- constructor(storage, logger = new NoopLogger()) {
90
+ class WotsWatermarkStore {
91
+ constructor(storage, logger = new core_1.NoopLogger()) {
87
92
  this.storage = storage;
88
93
  this.state = null;
89
94
  this._initialized = false;
@@ -132,7 +137,7 @@ export class WotsWatermarkStore {
132
137
  cur = nxt;
133
138
  attempts++;
134
139
  }
135
- throw new WatermarkExhaustedError(treeId);
140
+ throw new errors_js_1.WatermarkExhaustedError(treeId);
136
141
  }
137
142
  async markUnavailable(treeId, indices, reason) {
138
143
  const tree = this.getOrCreateTree(treeId);
@@ -164,12 +169,12 @@ export class WotsWatermarkStore {
164
169
  const existingFlat = flatIndex({ addressIndex: existing.addressCursor, l1: existing.l1Cursor, l2: existing.l2Cursor });
165
170
  const newFlat = flatIndex({ addressIndex: merged.addressCursor, l1: merged.l1Cursor, l2: merged.l2Cursor });
166
171
  if (newFlat < existingFlat) {
167
- throw new WatermarkMonotonicityError(`Cannot decrease watermark cursor for ${treeId}: ${existingFlat} → ${newFlat}`);
172
+ throw new errors_js_1.WatermarkMonotonicityError(`Cannot decrease watermark cursor for ${treeId}: ${existingFlat} → ${newFlat}`);
168
173
  }
169
174
  const existingUnavailCount = Object.keys(existing.unavailable).length;
170
175
  const newUnavailCount = Object.keys(merged.unavailable).length;
171
176
  if (newUnavailCount < existingUnavailCount) {
172
- throw new WatermarkMonotonicityError(`Cannot shrink unavailable map for ${treeId}: ${existingUnavailCount} → ${newUnavailCount}`);
177
+ throw new errors_js_1.WatermarkMonotonicityError(`Cannot shrink unavailable map for ${treeId}: ${existingUnavailCount} → ${newUnavailCount}`);
173
178
  }
174
179
  s.trees[treeId] = merged;
175
180
  await this.persist();
@@ -196,3 +201,4 @@ export class WotsWatermarkStore {
196
201
  await this.storage.remove(STORAGE_KEY);
197
202
  }
198
203
  }
204
+ exports.WotsWatermarkStore = WotsWatermarkStore;