@totemsdk/omnia-factory 0.1.4 → 0.1.5

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
@@ -64,7 +64,7 @@ await provider.broadcastTxPoW(settlementHex);
64
64
 
65
65
  ## See also
66
66
 
67
- - [`@totemsdk/omnia`](../omnia) — core channel state machine used by virtual channels
68
- - [`@totemsdk/omnia-router`](../omnia-router) — route payments across factory and direct channels
69
- - [`@totemsdk/wots-lease`](../wots-lease) — WOTS key safety for factory signing
70
- - [`@totemsdk/tx-builder`](../tx-builder) — builds the N-of-N funding transaction
67
+ - [`@totemsdk/omnia`](https://www.npmjs.com/package/@totemsdk/omnia) — core channel state machine used by virtual channels
68
+ - [`@totemsdk/omnia-router`](https://www.npmjs.com/package/@totemsdk/omnia-router) — route payments across factory and direct channels
69
+ - [`@totemsdk/wots-lease`](https://www.npmjs.com/package/@totemsdk/wots-lease) — WOTS key safety for factory signing
70
+ - [`@totemsdk/tx-builder`](https://www.npmjs.com/package/@totemsdk/tx-builder) — builds the N-of-N funding transaction
@@ -1,4 +1,7 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeFactoryStateCommitment = computeFactoryStateCommitment;
4
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
2
5
  /**
3
6
  * Compute the canonical 32-byte state commitment for N-of-N factory signing.
4
7
  *
@@ -14,7 +17,7 @@ import { sha3_256 } from '@noble/hashes/sha3';
14
17
  * This commitment is what every party signs via `FactorySignerOps.sign`, and
15
18
  * what `FactorySignerOps.verify` checks against each stored signature.
16
19
  */
17
- export function computeFactoryStateCommitment(factoryId, sequence, pendingAllocations, virtualChannelIds) {
20
+ function computeFactoryStateCommitment(factoryId, sequence, pendingAllocations, virtualChannelIds) {
18
21
  const canonical = {
19
22
  factoryId,
20
23
  sequence,
@@ -23,5 +26,5 @@ export function computeFactoryStateCommitment(factoryId, sequence, pendingAlloca
23
26
  .map(([k, v]) => [k, v.toString()])),
24
27
  virtualChannelIds: [...virtualChannelIds].sort(),
25
28
  };
26
- return sha3_256(new TextEncoder().encode(JSON.stringify(canonical)));
29
+ return (0, sha3_js_1.sha3_256)(new TextEncoder().encode(JSON.stringify(canonical)));
27
30
  }
package/dist/factory.js CHANGED
@@ -1,9 +1,15 @@
1
- import { sha3_256 } from '@noble/hashes/sha3';
2
- import { concatBytes, wotsVerifyDigest, fromHex } from '@totemsdk/core';
3
- import { buildFundingTx, omniaDraftToMinimaBytes, computeTxDraftDigest, } from '@totemsdk/omnia';
4
- import { mineTxPoW, TX_POW_MIN_DIFFICULTY, serializeTxBody } from '@totemsdk/txpow';
5
- import { buildAndHashFactoryScript } from './script.js';
6
- import { computeFactoryStateCommitment } from './commitment.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enforceConservation = enforceConservation;
4
+ exports.createFactory = createFactory;
5
+ exports.acceptFactory = acceptFactory;
6
+ exports.reallocate = reallocate;
7
+ const sha3_js_1 = require("@noble/hashes/sha3.js");
8
+ const core_1 = require("@totemsdk/core");
9
+ const omnia_1 = require("@totemsdk/omnia");
10
+ const txpow_1 = require("@totemsdk/txpow");
11
+ const script_js_1 = require("./script.js");
12
+ const commitment_js_1 = require("./commitment.js");
7
13
  // ─── Balance conservation ────────────────────────────────────────────────────
8
14
  /**
9
15
  * Enforce the factory's balance conservation invariant:
@@ -11,7 +17,7 @@ import { computeFactoryStateCommitment } from './commitment.js';
11
17
  *
12
18
  * Throws on violation. Called after every committed state transition.
13
19
  */
14
- export function enforceConservation(factory) {
20
+ function enforceConservation(factory) {
15
21
  const allocSum = Object.values(factory.allocations).reduce((a, b) => a + b, 0n);
16
22
  const vcSum = factory.virtualChannels.reduce((acc, vc) => acc + vc.totalValue, 0n);
17
23
  if (allocSum + vcSum !== factory.totalValue) {
@@ -44,7 +50,7 @@ async function leaseSign(factoryId, commitment, purpose, participant, bundle) {
44
50
  // Verify the signature against the REGISTERED participant public key digest —
45
51
  // not self-reported from the signer, ensuring the signer matches the factory record.
46
52
  const verifyFn = bundle.verify
47
- ?? ((s, c, pkd) => wotsVerifyDigest(s, c, fromHex(pkd)));
53
+ ?? ((s, c, pkd) => (0, core_1.wotsVerifyDigest)(s, c, (0, core_1.fromHex)(pkd)));
48
54
  if (!verifyFn(sig, commitment, participant.publicKeyDigest)) {
49
55
  await bundle.leaseProvider.burnReservation(reservation.reservationId, 'verification-failed').catch(() => { });
50
56
  throw new Error(`Signature verification failed for party '${participant.partyId}' — refusing to commit`);
@@ -75,7 +81,7 @@ function generateFactoryId(participants, tokenId) {
75
81
  tokenId,
76
82
  nonce,
77
83
  });
78
- return Buffer.from(sha3_256(new TextEncoder().encode(input))).toString('hex');
84
+ return Buffer.from((0, sha3_js_1.sha3_256)(new TextEncoder().encode(input))).toString('hex');
79
85
  }
80
86
  // ─── createFactory ────────────────────────────────────────────────────────────
81
87
  /**
@@ -106,7 +112,7 @@ function generateFactoryId(participants, tokenId) {
106
112
  * one of the registered participants).
107
113
  * @param chainProvider - Optional: build + mine + broadcast the factory funding TX.
108
114
  */
109
- export async function createFactory(participants, tokenId, bundle, chainProvider) {
115
+ async function createFactory(participants, tokenId, bundle, chainProvider) {
110
116
  if (participants.length < 2) {
111
117
  throw new Error(`Factory requires at least 2 participants, got ${participants.length}`);
112
118
  }
@@ -120,7 +126,7 @@ export async function createFactory(participants, tokenId, bundle, chainProvider
120
126
  for (const p of participants) {
121
127
  allocations[p.partyId] = p.contributionAmount;
122
128
  }
123
- const { script, address } = buildAndHashFactoryScript(participants);
129
+ const { script, address } = (0, script_js_1.buildAndHashFactoryScript)(participants);
124
130
  const factoryId = generateFactoryId(participants, tokenId);
125
131
  // ── Build + mine + broadcast funding TX (when participants provide UTXOs) ──
126
132
  let fundingTxId;
@@ -128,20 +134,20 @@ export async function createFactory(participants, tokenId, bundle, chainProvider
128
134
  let pendingCommitment;
129
135
  const allHaveCoinId = participants.every(p => p.fundingCoinId);
130
136
  if (allHaveCoinId && chainProvider) {
131
- const fundingDraft = buildFundingTx(script, address, totalValue, tokenId, 0, participants.map(p => p.fundingCoinId), participants.map(p => p.contributionAmount), participants.map(p => p.settlementAddress ?? p.publicKeyDigest));
137
+ const fundingDraft = (0, omnia_1.buildFundingTx)(script, address, totalValue, tokenId, 0, participants.map(p => p.fundingCoinId), participants.map(p => p.contributionAmount), participants.map(p => p.settlementAddress ?? p.publicKeyDigest));
132
138
  // All parties co-sign the TX digest — the exact on-chain TX structure.
133
- pendingCommitment = computeTxDraftDigest(fundingDraft);
134
- const draftBytes = omniaDraftToMinimaBytes(fundingDraft);
135
- const txBody = serializeTxBody(draftBytes, new Uint8Array(0));
136
- const mined = await mineTxPoW(txBody, TX_POW_MIN_DIFFICULTY);
137
- const fullTxPoW = concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01]), txBody);
139
+ pendingCommitment = (0, omnia_1.computeTxDraftDigest)(fundingDraft);
140
+ const draftBytes = (0, omnia_1.omniaDraftToMinimaBytes)(fundingDraft);
141
+ const txBody = (0, txpow_1.serializeTxBody)(draftBytes, new Uint8Array(0));
142
+ const mined = await (0, txpow_1.mineTxPoW)(txBody, txpow_1.TX_POW_MIN_DIFFICULTY);
143
+ const fullTxPoW = (0, core_1.concatBytes)(mined.minedHeaderBytes, new Uint8Array([0x01]), txBody);
138
144
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
139
145
  fundingTxId = Buffer.from(mined.txpowId).toString('hex');
140
146
  fundingCoinId = `${fundingTxId}-0`;
141
147
  }
142
148
  else {
143
149
  // In-memory / test path: sign the factory state commitment instead.
144
- pendingCommitment = computeFactoryStateCommitment(factoryId, 1, allocations, []);
150
+ pendingCommitment = (0, commitment_js_1.computeFactoryStateCommitment)(factoryId, 1, allocations, []);
145
151
  }
146
152
  // Sign with the proposer's lease (full bundle preserved so verify override is available).
147
153
  const proposerSig = await leaseSign(factoryId, pendingCommitment, 'factory-open', proposer, bundle);
@@ -190,7 +196,7 @@ export async function createFactory(participants, tokenId, bundle, chainProvider
190
196
  * @param signer - This counterparty's channel signer (`signer.publicKeyDigest`
191
197
  * must match a registered participant not yet signed).
192
198
  */
193
- export async function acceptFactory(factory, bundle) {
199
+ async function acceptFactory(factory, bundle) {
194
200
  if (factory.status !== 'opening') {
195
201
  throw new Error(`acceptFactory requires factory status 'opening', got '${factory.status}'`);
196
202
  }
@@ -248,7 +254,7 @@ function commitOpening(factory) {
248
254
  * @param amount - Amount to transfer (must be positive and within `fromPartyId`'s balance).
249
255
  * @param leaseProviders - WOTS lease bundles for ALL N factory participants.
250
256
  */
251
- export async function reallocate(factory, fromPartyId, toPartyId, amount, leaseProviders) {
257
+ async function reallocate(factory, fromPartyId, toPartyId, amount, leaseProviders) {
252
258
  if (factory.status !== 'active') {
253
259
  throw new Error(`reallocate requires factory status 'active', got '${factory.status}'`);
254
260
  }
@@ -269,7 +275,7 @@ export async function reallocate(factory, fromPartyId, toPartyId, amount, leaseP
269
275
  };
270
276
  const newSequence = factory.currentSequence + 1;
271
277
  const vcIds = factory.virtualChannels.map(vc => vc.channelId);
272
- const commitment = computeFactoryStateCommitment(factory.factoryId, newSequence, newAllocations, vcIds);
278
+ const commitment = (0, commitment_js_1.computeFactoryStateCommitment)(factory.factoryId, newSequence, newAllocations, vcIds);
273
279
  await collectNofN(factory.factoryId, commitment, 'factory-reallocate', factory.participants, leaseProviders);
274
280
  const logEntry = {
275
281
  sequence: newSequence,
package/dist/index.js CHANGED
@@ -1,5 +1,21 @@
1
- export { buildFactoryScript, buildAndHashFactoryScript, scriptAddress, normalizeScript, } from './script.js';
2
- export { computeFactoryStateCommitment } from './commitment.js';
3
- export { createFactory, acceptFactory, reallocate, enforceConservation, } from './factory.js';
4
- export { openVirtualChannel, closeVirtualChannel, } from './virtual.js';
5
- export { closeFactory, buildDisputePayload, } from './settlement.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildDisputePayload = exports.closeFactory = exports.closeVirtualChannel = exports.openVirtualChannel = exports.enforceConservation = exports.reallocate = exports.acceptFactory = exports.createFactory = exports.computeFactoryStateCommitment = exports.normalizeScript = exports.scriptAddress = exports.buildAndHashFactoryScript = exports.buildFactoryScript = void 0;
4
+ var script_js_1 = require("./script.js");
5
+ Object.defineProperty(exports, "buildFactoryScript", { enumerable: true, get: function () { return script_js_1.buildFactoryScript; } });
6
+ Object.defineProperty(exports, "buildAndHashFactoryScript", { enumerable: true, get: function () { return script_js_1.buildAndHashFactoryScript; } });
7
+ Object.defineProperty(exports, "scriptAddress", { enumerable: true, get: function () { return script_js_1.scriptAddress; } });
8
+ Object.defineProperty(exports, "normalizeScript", { enumerable: true, get: function () { return script_js_1.normalizeScript; } });
9
+ var commitment_js_1 = require("./commitment.js");
10
+ Object.defineProperty(exports, "computeFactoryStateCommitment", { enumerable: true, get: function () { return commitment_js_1.computeFactoryStateCommitment; } });
11
+ var factory_js_1 = require("./factory.js");
12
+ Object.defineProperty(exports, "createFactory", { enumerable: true, get: function () { return factory_js_1.createFactory; } });
13
+ Object.defineProperty(exports, "acceptFactory", { enumerable: true, get: function () { return factory_js_1.acceptFactory; } });
14
+ Object.defineProperty(exports, "reallocate", { enumerable: true, get: function () { return factory_js_1.reallocate; } });
15
+ Object.defineProperty(exports, "enforceConservation", { enumerable: true, get: function () { return factory_js_1.enforceConservation; } });
16
+ var virtual_js_1 = require("./virtual.js");
17
+ Object.defineProperty(exports, "openVirtualChannel", { enumerable: true, get: function () { return virtual_js_1.openVirtualChannel; } });
18
+ Object.defineProperty(exports, "closeVirtualChannel", { enumerable: true, get: function () { return virtual_js_1.closeVirtualChannel; } });
19
+ var settlement_js_1 = require("./settlement.js");
20
+ Object.defineProperty(exports, "closeFactory", { enumerable: true, get: function () { return settlement_js_1.closeFactory; } });
21
+ Object.defineProperty(exports, "buildDisputePayload", { enumerable: true, get: function () { return settlement_js_1.buildDisputePayload; } });
package/dist/script.js CHANGED
@@ -1,4 +1,10 @@
1
- import { computeScriptAddress } from '@totemsdk/core';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFactoryScript = buildFactoryScript;
4
+ exports.normalizeScript = normalizeScript;
5
+ exports.scriptAddress = scriptAddress;
6
+ exports.buildAndHashFactoryScript = buildAndHashFactoryScript;
7
+ const core_1 = require("@totemsdk/core");
2
8
  /**
3
9
  * Normalize a hex public key digest to the KISSVM-compatible format:
4
10
  * strip leading 0x/0X and render as upper-case hex with leading '0X'.
@@ -23,7 +29,7 @@ function kissHex(hex) {
23
29
  *
24
30
  * Minimum 2 participants required.
25
31
  */
26
- export function buildFactoryScript(participants) {
32
+ function buildFactoryScript(participants) {
27
33
  if (participants.length < 2) {
28
34
  throw new Error(`Factory requires at least 2 participants, got ${participants.length}`);
29
35
  }
@@ -39,18 +45,18 @@ export function buildFactoryScript(participants) {
39
45
  'ENDIF',
40
46
  ].join('\n');
41
47
  }
42
- export function normalizeScript(script) {
48
+ function normalizeScript(script) {
43
49
  return script.trim().toUpperCase();
44
50
  }
45
51
  /** Compute the SHA3-256 script-hash address for a factory script. */
46
- export function scriptAddress(script) {
47
- return computeScriptAddress(script);
52
+ function scriptAddress(script) {
53
+ return (0, core_1.computeScriptAddress)(script);
48
54
  }
49
55
  /**
50
56
  * Build the factory script and compute its canonical address in one step.
51
57
  * The address is used as the output address of the factory funding TX.
52
58
  */
53
- export function buildAndHashFactoryScript(participants) {
59
+ function buildAndHashFactoryScript(participants) {
54
60
  const script = buildFactoryScript(participants);
55
61
  const address = scriptAddress(script);
56
62
  return { script, address };
@@ -1,6 +1,10 @@
1
- import { concatBytes, wotsVerifyDigest, fromHex } from '@totemsdk/core';
2
- import { serializeTxDraft, omniaDraftToMinimaBytes, computeTxDraftDigest, } from '@totemsdk/omnia';
3
- import { mineTxPoW, TX_POW_MIN_DIFFICULTY, serializeTxBody } from '@totemsdk/txpow';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closeFactory = closeFactory;
4
+ exports.buildDisputePayload = buildDisputePayload;
5
+ const core_1 = require("@totemsdk/core");
6
+ const omnia_1 = require("@totemsdk/omnia");
7
+ const txpow_1 = require("@totemsdk/txpow");
4
8
  // ─── closeFactory ─────────────────────────────────────────────────────────────
5
9
  /**
6
10
  * Cooperative N-of-N factory close.
@@ -21,7 +25,7 @@ import { mineTxPoW, TX_POW_MIN_DIFFICULTY, serializeTxBody } from '@totemsdk/txp
21
25
  * @param leaseProviders - WOTS lease bundles for ALL N factory participants.
22
26
  * @param chainProvider - Optional: mine + broadcast the settlement TX.
23
27
  */
24
- export async function closeFactory(factory, leaseProviders, chainProvider) {
28
+ async function closeFactory(factory, leaseProviders, chainProvider) {
25
29
  if (factory.status !== 'active') {
26
30
  throw new Error(`closeFactory requires factory status 'active', got '${factory.status}'`);
27
31
  }
@@ -66,10 +70,10 @@ export async function closeFactory(factory, leaseProviders, chainProvider) {
66
70
  storeState: true,
67
71
  stateVariables: [{ port: 100, value: true, type: 'bool' }],
68
72
  };
69
- const settlementTxHex = serializeTxDraft(settlementDraft);
73
+ const settlementTxHex = (0, omnia_1.serializeTxDraft)(settlementDraft);
70
74
  // ── Step 3: Collect N-of-N settlement signatures ──────────────────────────
71
75
  // All parties sign the TX draft digest — the canonical on-chain commitment.
72
- const txDigest = computeTxDraftDigest(settlementDraft);
76
+ const txDigest = (0, omnia_1.computeTxDraftDigest)(settlementDraft);
73
77
  const witnessParts = [];
74
78
  for (const p of factory.participants) {
75
79
  const bundle = leaseProviders[p.partyId];
@@ -87,7 +91,7 @@ export async function closeFactory(factory, leaseProviders, chainProvider) {
87
91
  throw err;
88
92
  }
89
93
  const verifyFn = bundle.verify
90
- ?? ((s, c, pkd) => wotsVerifyDigest(s, c, fromHex(pkd)));
94
+ ?? ((s, c, pkd) => (0, core_1.wotsVerifyDigest)(s, c, (0, core_1.fromHex)(pkd)));
91
95
  if (!verifyFn(sig, txDigest, p.publicKeyDigest)) {
92
96
  await bundle.leaseProvider.burnReservation(reservation.reservationId, 'verification-failed').catch(() => { });
93
97
  throw new Error(`Settlement signature verification failed for party '${p.partyId}'`);
@@ -96,7 +100,7 @@ export async function closeFactory(factory, leaseProviders, chainProvider) {
96
100
  witnessParts.push(sig);
97
101
  }
98
102
  // Concatenated WOTS signatures form the N-of-N MULTISIG witness.
99
- const witnessBytes = concatBytes(...witnessParts);
103
+ const witnessBytes = (0, core_1.concatBytes)(...witnessParts);
100
104
  const payload = {
101
105
  factoryId: factory.factoryId,
102
106
  sequence: factory.currentSequence,
@@ -105,10 +109,10 @@ export async function closeFactory(factory, leaseProviders, chainProvider) {
105
109
  };
106
110
  // ── Step 4: Mine + broadcast ──────────────────────────────────────────────
107
111
  if (chainProvider) {
108
- const draftBytes = omniaDraftToMinimaBytes(settlementDraft);
109
- const txBody = serializeTxBody(draftBytes, witnessBytes);
110
- const mined = await mineTxPoW(txBody, TX_POW_MIN_DIFFICULTY);
111
- const fullTxPoW = concatBytes(mined.minedHeaderBytes, new Uint8Array([0x01]), txBody);
112
+ const draftBytes = (0, omnia_1.omniaDraftToMinimaBytes)(settlementDraft);
113
+ const txBody = (0, txpow_1.serializeTxBody)(draftBytes, witnessBytes);
114
+ const mined = await (0, txpow_1.mineTxPoW)(txBody, txpow_1.TX_POW_MIN_DIFFICULTY);
115
+ const fullTxPoW = (0, core_1.concatBytes)(mined.minedHeaderBytes, new Uint8Array([0x01]), txBody);
112
116
  await chainProvider.broadcastTxPoW(Buffer.from(fullTxPoW).toString('hex'));
113
117
  payload.txpowId = Buffer.from(mined.txpowId).toString('hex');
114
118
  }
@@ -123,7 +127,7 @@ export async function closeFactory(factory, leaseProviders, chainProvider) {
123
127
  * dispute time are included by ID so the dispute resolver can adjudicate their
124
128
  * balances independently.
125
129
  */
126
- export function buildDisputePayload(factory, evidence) {
130
+ function buildDisputePayload(factory, evidence) {
127
131
  const logEntry = {
128
132
  sequence: factory.currentSequence,
129
133
  timestamp: Date.now(),
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/virtual.js CHANGED
@@ -1,6 +1,10 @@
1
- import { wotsVerifyDigest, fromHex } from '@totemsdk/core';
2
- import { enforceConservation } from './factory.js';
3
- import { computeFactoryStateCommitment } from './commitment.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openVirtualChannel = openVirtualChannel;
4
+ exports.closeVirtualChannel = closeVirtualChannel;
5
+ const core_1 = require("@totemsdk/core");
6
+ const factory_js_1 = require("./factory.js");
7
+ const commitment_js_1 = require("./commitment.js");
4
8
  // ─── Internal helpers ─────────────────────────────────────────────────────────
5
9
  function generateChannelId(factoryId, partyAId, partyBId) {
6
10
  const nonce = Array.from(globalThis.crypto?.getRandomValues?.(new Uint8Array(8)) ?? new Uint8Array(8)).map(b => b.toString(16).padStart(2, '0')).join('');
@@ -22,7 +26,7 @@ async function leaseSign(factoryId, commitment, purpose, partyId, publicKeyDiges
22
26
  throw err;
23
27
  }
24
28
  const verifyFn = bundle.verify
25
- ?? ((s, c, pkd) => wotsVerifyDigest(s, c, fromHex(pkd)));
29
+ ?? ((s, c, pkd) => (0, core_1.wotsVerifyDigest)(s, c, (0, core_1.fromHex)(pkd)));
26
30
  if (!verifyFn(sig, commitment, publicKeyDigest)) {
27
31
  await bundle.leaseProvider.burnReservation(reservation.reservationId, 'verification-failed').catch(() => { });
28
32
  throw new Error(`Signature verification failed for party '${partyId}' — aborting virtual channel operation`);
@@ -65,7 +69,7 @@ async function collectNofN(factoryId, commitment, purpose, participants, leasePr
65
69
  * @param leaseProviders - WOTS lease bundles for ALL N factory participants.
66
70
  * @param channelId - Optional explicit channel ID; auto-generated if omitted.
67
71
  */
68
- export async function openVirtualChannel(factory, parties, amounts, leaseProviders, channelId) {
72
+ async function openVirtualChannel(factory, parties, amounts, leaseProviders, channelId) {
69
73
  if (factory.status !== 'active') {
70
74
  throw new Error(`openVirtualChannel requires factory status 'active', got '${factory.status}'`);
71
75
  }
@@ -100,7 +104,7 @@ export async function openVirtualChannel(factory, parties, amounts, leaseProvide
100
104
  [partyBId]: allocB - amountB,
101
105
  };
102
106
  const newVcIds = [...factory.virtualChannels.map(vc => vc.channelId), vcId];
103
- const commitment = computeFactoryStateCommitment(factory.factoryId, newSequence, newAllocations, newVcIds);
107
+ const commitment = (0, commitment_js_1.computeFactoryStateCommitment)(factory.factoryId, newSequence, newAllocations, newVcIds);
104
108
  await collectNofN(factory.factoryId, commitment, 'factory-vc-open', factory.participants, leaseProviders);
105
109
  const now = Date.now();
106
110
  const partyA = {
@@ -152,7 +156,7 @@ export async function openVirtualChannel(factory, parties, amounts, leaseProvide
152
156
  currentSequence: newSequence,
153
157
  stateLog: [...factory.stateLog, logEntry],
154
158
  };
155
- enforceConservation(updated);
159
+ (0, factory_js_1.enforceConservation)(updated);
156
160
  return { factory: updated, channel };
157
161
  }
158
162
  // ─── closeVirtualChannel ─────────────────────────────────────────────────────
@@ -172,7 +176,7 @@ export async function openVirtualChannel(factory, parties, amounts, leaseProvide
172
176
  * @param channel - The virtual `OmniaChannel` to close (with `latestState` set if updated).
173
177
  * @param leaseProviders - WOTS lease bundles for ALL N factory participants.
174
178
  */
175
- export async function closeVirtualChannel(factory, channel, leaseProviders) {
179
+ async function closeVirtualChannel(factory, channel, leaseProviders) {
176
180
  const existing = factory.virtualChannels.find(c => c.channelId === channel.channelId);
177
181
  if (!existing)
178
182
  throw new Error(`Virtual channel '${channel.channelId}' not found in factory`);
@@ -190,7 +194,7 @@ export async function closeVirtualChannel(factory, channel, leaseProviders) {
190
194
  const remainingVcIds = factory.virtualChannels
191
195
  .filter(c => c.channelId !== channel.channelId)
192
196
  .map(c => c.channelId);
193
- const commitment = computeFactoryStateCommitment(factory.factoryId, newSequence, newAllocations, remainingVcIds);
197
+ const commitment = (0, commitment_js_1.computeFactoryStateCommitment)(factory.factoryId, newSequence, newAllocations, remainingVcIds);
194
198
  await collectNofN(factory.factoryId, commitment, 'factory-vc-close', factory.participants, leaseProviders);
195
199
  const logEntry = {
196
200
  sequence: newSequence,
@@ -206,6 +210,6 @@ export async function closeVirtualChannel(factory, channel, leaseProviders) {
206
210
  currentSequence: newSequence,
207
211
  stateLog: [...factory.stateLog, logEntry],
208
212
  };
209
- enforceConservation(updated);
213
+ (0, factory_js_1.enforceConservation)(updated);
210
214
  return updated;
211
215
  }
package/package.json CHANGED
@@ -1,30 +1,31 @@
1
1
  {
2
2
  "name": "@totemsdk/omnia-factory",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Channel factory layer for Omnia — N-of-N MULTISIG funding, virtual channel management, and factory settlement",
5
- "type": "module",
6
5
  "main": "dist/index.js",
7
6
  "types": "dist/index.d.ts",
8
7
  "exports": {
9
8
  ".": {
10
9
  "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
11
  "import": "./dist/index.js"
12
12
  }
13
13
  },
14
14
  "files": [
15
15
  "dist",
16
- "src"
16
+ "README.md",
17
+ "LICENSE"
17
18
  ],
18
19
  "dependencies": {
19
20
  "@totemsdk/core": "1.0.9",
20
- "@totemsdk/omnia": "0.1.3",
21
+ "@totemsdk/omnia": "0.1.4",
21
22
  "@totemsdk/wots-lease": "0.1.2",
22
- "@totemsdk/txpow": "0.1.3",
23
23
  "@totemsdk/tx-builder": "0.1.4",
24
- "@totemsdk/chain-provider": "0.1.2"
24
+ "@totemsdk/txpow": "0.1.4",
25
+ "@totemsdk/chain-provider": "0.1.3"
25
26
  },
26
27
  "peerDependencies": {
27
- "@noble/hashes": ">=1.3.0 <2.0.0"
28
+ "@noble/hashes": ">=1.3.0"
28
29
  },
29
30
  "peerDependenciesMeta": {
30
31
  "@noble/hashes": {
@@ -32,7 +33,7 @@
32
33
  }
33
34
  },
34
35
  "devDependencies": {
35
- "@noble/hashes": "^1.3.0",
36
+ "@noble/hashes": "^2.2.0",
36
37
  "@types/jest": "^29.0.0",
37
38
  "@types/node": "^20.0.0",
38
39
  "jest": "^29.0.0",
@@ -46,6 +47,33 @@
46
47
  "access": "public"
47
48
  },
48
49
  "license": "MIT",
50
+ "author": "Totem SDK",
51
+ "homepage": "https://totemsdk.com",
52
+ "bugs": {
53
+ "url": "https://github.com/MrGheek/axia-totem/issues"
54
+ },
55
+ "repository": {
56
+ "type": "git",
57
+ "url": "git+https://github.com/MrGheek/axia-totem.git",
58
+ "directory": "packages/totem-sdk/packages/omnia-factory"
59
+ },
60
+ "keywords": [
61
+ "totem",
62
+ "totemsdk",
63
+ "minima",
64
+ "blockchain",
65
+ "quantum-resistant",
66
+ "wots",
67
+ "kissvm",
68
+ "utxo",
69
+ "omnia",
70
+ "payment-channel",
71
+ "eltoo",
72
+ "layer2",
73
+ "channel-factory",
74
+ "virtual-channel",
75
+ "multisig"
76
+ ],
49
77
  "scripts": {
50
78
  "build": "tsc",
51
79
  "clean": "rm -rf dist",