@totemsdk/omnia-factory 0.1.9 → 0.2.1
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/durable-factory-store.d.ts +42 -0
- package/dist/durable-factory-store.js +59 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +11 -10
- package/rust/pkg/omnia_factory_wasm_bg.wasm +0 -0
- package/rust/pkg/package.json +1 -1
- package/rust/pkg-node/omnia_factory_wasm_bg.wasm +0 -0
- package/rust/pkg-node/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Durable factory signing-state store (RFC-007 G9).
|
|
3
|
+
*
|
|
4
|
+
* `createFactory`/`acceptFactory`/`reallocate` are pure functions that return
|
|
5
|
+
* updated `ChannelFactory` records; this store makes the actionable part of that
|
|
6
|
+
* state — `pendingCommitment`, `pendingSignatures` (partial-signature counts),
|
|
7
|
+
* and `stateLog` — durable, so it survives a host restart with no partial-funding
|
|
8
|
+
* loss. A factory that was mid-signing-round (N of N signatures collected) reopens
|
|
9
|
+
* with every already-collected signature intact and can resume exactly where it
|
|
10
|
+
* left off.
|
|
11
|
+
*
|
|
12
|
+
* Backed by the shared revision-CAS snapshot store: single-key, whole-record
|
|
13
|
+
* update, corruption surfaced (never treated as absence), no silent downgrade.
|
|
14
|
+
*/
|
|
15
|
+
import type { StorageAdapterWithCapabilities, CasStore, WriteAckMode } from '@totemsdk/storage/types';
|
|
16
|
+
import type { ChannelFactory } from './types.js';
|
|
17
|
+
export interface FactoryRegistryState {
|
|
18
|
+
factories: Record<string, ChannelFactory>;
|
|
19
|
+
}
|
|
20
|
+
export interface DurableFactoryStoreOptions {
|
|
21
|
+
/** Key namespace prefix; default `totem_omnia_factory:v1:`. */
|
|
22
|
+
readonly namespace?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Required write acknowledgment; default `durably-acknowledged`. Pass
|
|
25
|
+
* `volatile` only for tests/scratch adapters (e.g. `MemoryStore`).
|
|
26
|
+
*/
|
|
27
|
+
readonly requireAckMode?: WriteAckMode;
|
|
28
|
+
}
|
|
29
|
+
export interface DurableFactoryStore {
|
|
30
|
+
/** Persist a factory (create/accept/reallocate state transition). */
|
|
31
|
+
saveFactory(factory: ChannelFactory): Promise<void>;
|
|
32
|
+
getFactory(factoryId: string): Promise<ChannelFactory | undefined>;
|
|
33
|
+
/** All factories known to the registry. */
|
|
34
|
+
listFactories(): Promise<ChannelFactory[]>;
|
|
35
|
+
/** Current registry transition counter (0 before the first write). */
|
|
36
|
+
getRevision(): Promise<number>;
|
|
37
|
+
/** True once any factory record has been persisted. */
|
|
38
|
+
hasState(): Promise<boolean>;
|
|
39
|
+
/** Current persisted registry state. */
|
|
40
|
+
getSnapshot(): Promise<FactoryRegistryState>;
|
|
41
|
+
}
|
|
42
|
+
export declare function createDurableFactoryStore(adapter: StorageAdapterWithCapabilities & CasStore, options?: DurableFactoryStoreOptions): DurableFactoryStore;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Durable factory signing-state store (RFC-007 G9).
|
|
4
|
+
*
|
|
5
|
+
* `createFactory`/`acceptFactory`/`reallocate` are pure functions that return
|
|
6
|
+
* updated `ChannelFactory` records; this store makes the actionable part of that
|
|
7
|
+
* state — `pendingCommitment`, `pendingSignatures` (partial-signature counts),
|
|
8
|
+
* and `stateLog` — durable, so it survives a host restart with no partial-funding
|
|
9
|
+
* loss. A factory that was mid-signing-round (N of N signatures collected) reopens
|
|
10
|
+
* with every already-collected signature intact and can resume exactly where it
|
|
11
|
+
* left off.
|
|
12
|
+
*
|
|
13
|
+
* Backed by the shared revision-CAS snapshot store: single-key, whole-record
|
|
14
|
+
* update, corruption surfaced (never treated as absence), no silent downgrade.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createDurableFactoryStore = createDurableFactoryStore;
|
|
18
|
+
const snapshot_1 = require("@totemsdk/storage/snapshot");
|
|
19
|
+
const errors_1 = require("@totemsdk/storage/errors");
|
|
20
|
+
const DEFAULT_NAMESPACE = 'totem_omnia_factory:v1:';
|
|
21
|
+
function assertRegistryState(state) {
|
|
22
|
+
if (typeof state !== 'object' || state === null || Array.isArray(state)) {
|
|
23
|
+
throw new errors_1.StorageError('omnia-factory registry state is not an object', 'corrupt');
|
|
24
|
+
}
|
|
25
|
+
const value = state.factories;
|
|
26
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
27
|
+
throw new errors_1.StorageError('omnia-factory registry state is missing section "factories"', 'corrupt');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createDurableFactoryStore(adapter, options = {}) {
|
|
31
|
+
const snapshots = (0, snapshot_1.createRevisionedSnapshotStore)(adapter, {
|
|
32
|
+
namespace: options.namespace ?? DEFAULT_NAMESPACE,
|
|
33
|
+
requireAckMode: options.requireAckMode,
|
|
34
|
+
empty: () => ({ factories: {} }),
|
|
35
|
+
validate: assertRegistryState,
|
|
36
|
+
});
|
|
37
|
+
async function mutate(fn) {
|
|
38
|
+
await snapshots.mutate(fn);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
async saveFactory(factory) {
|
|
42
|
+
await mutate((state) => {
|
|
43
|
+
const factories = { ...state.factories, [factory.factoryId]: factory };
|
|
44
|
+
return { ...state, factories };
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async getFactory(factoryId) {
|
|
48
|
+
return (await snapshots.load()).factories[factoryId];
|
|
49
|
+
},
|
|
50
|
+
async listFactories() {
|
|
51
|
+
return Object.values((await snapshots.load()).factories);
|
|
52
|
+
},
|
|
53
|
+
getRevision: () => snapshots.getRevision(),
|
|
54
|
+
hasState: () => snapshots.hasState(),
|
|
55
|
+
async getSnapshot() {
|
|
56
|
+
return snapshots.load();
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { computeFactoryStateCommitment } from './commitment.js';
|
|
|
4
4
|
export { createFactory, acceptFactory, reallocate, enforceConservation, } from './factory.js';
|
|
5
5
|
export { openVirtualChannel, closeVirtualChannel, } from './virtual.js';
|
|
6
6
|
export { closeFactory, buildDisputePayload, } from './settlement.js';
|
|
7
|
+
export { createDurableFactoryStore, } from './durable-factory-store.js';
|
|
8
|
+
export type { FactoryRegistryState, DurableFactoryStore, DurableFactoryStoreOptions, } from './durable-factory-store.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.createDurableFactoryStore = 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
4
|
var script_js_1 = require("./script.js");
|
|
5
5
|
Object.defineProperty(exports, "buildFactoryScript", { enumerable: true, get: function () { return script_js_1.buildFactoryScript; } });
|
|
6
6
|
Object.defineProperty(exports, "buildAndHashFactoryScript", { enumerable: true, get: function () { return script_js_1.buildAndHashFactoryScript; } });
|
|
@@ -19,3 +19,5 @@ Object.defineProperty(exports, "closeVirtualChannel", { enumerable: true, get: f
|
|
|
19
19
|
var settlement_js_1 = require("./settlement.js");
|
|
20
20
|
Object.defineProperty(exports, "closeFactory", { enumerable: true, get: function () { return settlement_js_1.closeFactory; } });
|
|
21
21
|
Object.defineProperty(exports, "buildDisputePayload", { enumerable: true, get: function () { return settlement_js_1.buildDisputePayload; } });
|
|
22
|
+
var durable_factory_store_js_1 = require("./durable-factory-store.js");
|
|
23
|
+
Object.defineProperty(exports, "createDurableFactoryStore", { enumerable: true, get: function () { return durable_factory_store_js_1.createDurableFactoryStore; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totemsdk/omnia-factory",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Channel factory layer for Omnia — N-of-N MULTISIG funding, virtual channel management, and factory settlement",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@totemsdk/core": "^1.2.
|
|
23
|
-
"@totemsdk/
|
|
24
|
-
"@totemsdk/
|
|
25
|
-
"@totemsdk/
|
|
26
|
-
"@totemsdk/txpow": "^0.
|
|
27
|
-
"@totemsdk/chain-provider": "^0.1
|
|
22
|
+
"@totemsdk/core": "^1.2.11",
|
|
23
|
+
"@totemsdk/omnia": "^1.0.2",
|
|
24
|
+
"@totemsdk/tx-builder": "^0.2.1",
|
|
25
|
+
"@totemsdk/wots-lease": "^1.0.1",
|
|
26
|
+
"@totemsdk/txpow": "^1.0.2",
|
|
27
|
+
"@totemsdk/chain-provider": "^0.2.1",
|
|
28
|
+
"@totemsdk/storage": "^0.1.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/jest": "^30.0.0",
|
|
@@ -41,13 +42,13 @@
|
|
|
41
42
|
},
|
|
42
43
|
"license": "MIT",
|
|
43
44
|
"author": "Totem SDK",
|
|
44
|
-
"homepage": "https://totem.ing",
|
|
45
|
+
"homepage": "https://docs.totem.ing",
|
|
45
46
|
"bugs": {
|
|
46
|
-
"url": "https://github.com/
|
|
47
|
+
"url": "https://github.com/Totem-Edge/totem-sdk/issues"
|
|
47
48
|
},
|
|
48
49
|
"repository": {
|
|
49
50
|
"type": "git",
|
|
50
|
-
"url": "git+https://github.com/
|
|
51
|
+
"url": "git+https://github.com/Totem-Edge/totem-sdk.git",
|
|
51
52
|
"directory": "packages/omnia-factory"
|
|
52
53
|
},
|
|
53
54
|
"keywords": [
|
|
Binary file
|
package/rust/pkg/package.json
CHANGED
|
Binary file
|