@totemsdk/wots-lease 0.1.1 → 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 ADDED
@@ -0,0 +1,97 @@
1
+ # @totemsdk/wots-lease
2
+
3
+ **WOTS key safety — prevents catastrophic signature slot reuse.**
4
+
5
+ > ⚠️ **WOTS keys are one-time use.** Reusing a signing slot leaks the private key and permanently destroys the security of that address. This package is the guardian that prevents it from happening.
6
+
7
+ Coordinates key-use watermarks across devices and sessions so no signing slot is ever allocated twice.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @totemsdk/wots-lease
13
+ ```
14
+
15
+ ## What's inside
16
+
17
+ ### Core stores
18
+
19
+ | Class | What it does |
20
+ |-------|-------------|
21
+ | `WotsWatermarkStore` | Canonical v3 watermark tracking; `flatIndex` maps `(l1, l2)` → flat slot number |
22
+ | `LeaseJournal` | Append-only audit log of every signing slot allocation |
23
+
24
+ ### Provider tiers
25
+
26
+ | Provider | Use case |
27
+ |----------|----------|
28
+ | `LocalLeaseProvider` | Single-device, in-process coordination |
29
+ | `AxiaLeaseProvider` | Cloud-coordinated leases via Axia API |
30
+ | `HybridLeaseProvider` | Local-first with Axia sync fallback |
31
+ | `PersonalLeaseNodeProvider` | Coordinates through your personal lookup node *(ready for implementation)* |
32
+ | `P2PQuorumLeaseProvider` | Multi-device quorum consensus *(stub)* |
33
+ | `OnchainWatermarkProvider` | On-chain watermark anchoring *(stub)* |
34
+
35
+ ### Device range splitting
36
+
37
+ ```typescript
38
+ import { allocateDeviceRange } from '@totemsdk/wots-lease';
39
+
40
+ // Split 262,144 signing slots across 4 devices without overlap
41
+ const range = allocateDeviceRange({ deviceIndex: 0, totalDevices: 4 });
42
+ // { start: 0, end: 65535 }
43
+ ```
44
+
45
+ ### Error types
46
+
47
+ | Error | Meaning |
48
+ |-------|---------|
49
+ | `WatermarkMonotonicityError` | Attempted to use a slot at or before the current watermark |
50
+ | `WatermarkExhaustedError` | All 262,144 signing slots for this address have been used |
51
+ | `DeviceRangeViolationError` | Slot is outside this device's allocated range |
52
+
53
+ ## Usage
54
+
55
+ ### Local (single device)
56
+
57
+ ```typescript
58
+ import { LocalLeaseProvider, WotsWatermarkStore } from '@totemsdk/wots-lease';
59
+
60
+ const store = new WotsWatermarkStore(storageAdapter);
61
+ const provider = new LocalLeaseProvider(store);
62
+
63
+ // Allocate the next available signing slot
64
+ const slot = await provider.allocateSlot({ addressIndex: 0 });
65
+ console.log('Use flat slot:', slot.flatIndex); // e.g. 42
66
+
67
+ // After signing, commit the watermark
68
+ await provider.commitSlot(slot);
69
+ ```
70
+
71
+ ### Hybrid (local + Axia cloud backup)
72
+
73
+ ```typescript
74
+ import { HybridLeaseProvider } from '@totemsdk/wots-lease';
75
+
76
+ const provider = new HybridLeaseProvider({
77
+ local: new LocalLeaseProvider(store),
78
+ remote: new AxiaLeaseProvider({ baseUrl: 'https://api.axia.to', projectId: '...' }),
79
+ syncIntervalMs: 60_000,
80
+ });
81
+ ```
82
+
83
+ ### Audit log
84
+
85
+ ```typescript
86
+ import { LeaseJournal } from '@totemsdk/wots-lease';
87
+
88
+ const journal = new LeaseJournal(storageAdapter);
89
+ const entries = await journal.getEntries({ addressIndex: 0 });
90
+ entries.forEach(e => console.log(e.flatIndex, e.allocatedAt, e.committedAt));
91
+ ```
92
+
93
+ ## See also
94
+
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 });