@ottochain/sdk 2.1.0 → 2.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/cjs/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
31
31
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.OttoMetagraphClient = exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = exports.wrapError = exports.isErrorCode = exports.ErrorCode = exports.TransactionError = exports.SigningError = exports.ValidationError = exports.NetworkError = exports.OttoChainError = exports.dropNulls = exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = exports.MetagraphNetworkError = exports.HttpClient = exports.createMetagraphClient = exports.MetagraphClient = exports.verify = void 0;
|
|
34
|
+
exports.toProtoDefinition = exports.OttoMetagraphClient = exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = exports.wrapError = exports.isErrorCode = exports.ErrorCode = exports.TransactionError = exports.SigningError = exports.ValidationError = exports.NetworkError = exports.OttoChainError = exports.dropNulls = exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = exports.MetagraphNetworkError = exports.HttpClient = exports.createMetagraphClient = exports.MetagraphClient = exports.verify = void 0;
|
|
35
35
|
// ─── Core metagraph SDK ───────────────────────────────────────────────────────
|
|
36
36
|
// Consumers can also import directly from '@constellation-network/metagraph-sdk'
|
|
37
37
|
__exportStar(require("@constellation-network/metagraph-sdk"), exports);
|
|
@@ -99,3 +99,6 @@ Object.defineProperty(exports, "assert", { enumerable: true, get: function () {
|
|
|
99
99
|
// ─── OttoChain metagraph client ───────────────────────────────────────────────
|
|
100
100
|
var metagraph_client_js_1 = require("./ottochain/metagraph-client.js");
|
|
101
101
|
Object.defineProperty(exports, "OttoMetagraphClient", { enumerable: true, get: function () { return metagraph_client_js_1.MetagraphClient; } });
|
|
102
|
+
// Proto definition helper
|
|
103
|
+
var fiber_app_js_1 = require("./schema/fiber-app.js");
|
|
104
|
+
Object.defineProperty(exports, "toProtoDefinition", { enumerable: true, get: function () { return fiber_app_js_1.toProtoDefinition; } });
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* no JSON, no code generation. Import types directly.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.toJSON = exports.isFinalState = exports.getEventsFrom = exports.getTransitionsFrom = exports.defineFiberApp = void 0;
|
|
9
|
+
exports.toProtoDefinition = exports.toJSON = exports.isFinalState = exports.getEventsFrom = exports.getTransitionsFrom = exports.defineFiberApp = void 0;
|
|
10
10
|
// =============================================================================
|
|
11
11
|
// Helper: defineFiberApp
|
|
12
12
|
// =============================================================================
|
|
@@ -53,3 +53,43 @@ function toJSON(def) {
|
|
|
53
53
|
return JSON.parse(JSON.stringify(def));
|
|
54
54
|
}
|
|
55
55
|
exports.toJSON = toJSON;
|
|
56
|
+
/**
|
|
57
|
+
* Extract proto-compatible StateMachineDefinition from a FiberAppDefinition.
|
|
58
|
+
* Use this when submitting to the metagraph.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const def = getContractDefinition('agreement');
|
|
63
|
+
* const protoDef = toProtoDefinition(def);
|
|
64
|
+
* // Submit protoDef to metagraph
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function toProtoDefinition(def) {
|
|
68
|
+
// Extract only the proto-compatible fields
|
|
69
|
+
const protoDef = {
|
|
70
|
+
states: {},
|
|
71
|
+
initialState: def.initialState,
|
|
72
|
+
transitions: def.transitions.map(t => ({
|
|
73
|
+
from: t.from,
|
|
74
|
+
to: t.to,
|
|
75
|
+
eventName: t.eventName,
|
|
76
|
+
...(t.guard && { guard: t.guard }),
|
|
77
|
+
...(t.effect && { effect: t.effect }),
|
|
78
|
+
...(t.dependencies?.length && { dependencies: [...t.dependencies] }),
|
|
79
|
+
...(t.emits?.length && { emits: [...t.emits] }),
|
|
80
|
+
})),
|
|
81
|
+
};
|
|
82
|
+
// Copy states (only id and isFinal)
|
|
83
|
+
for (const [key, state] of Object.entries(def.states)) {
|
|
84
|
+
protoDef.states[key] = {
|
|
85
|
+
id: state.id,
|
|
86
|
+
isFinal: state.isFinal,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Pass metadata through unchanged - it's an optional unstructured object
|
|
90
|
+
if (def.metadata) {
|
|
91
|
+
protoDef.metadata = def.metadata;
|
|
92
|
+
}
|
|
93
|
+
return protoDef;
|
|
94
|
+
}
|
|
95
|
+
exports.toProtoDefinition = toProtoDefinition;
|
package/dist/esm/index.js
CHANGED
|
@@ -42,3 +42,5 @@ DagAddressSchema, PrivateKeySchema, PublicKeySchema, KeyPairSchema, SignaturePro
|
|
|
42
42
|
validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPair, safeParse, assert, } from './validation.js';
|
|
43
43
|
// ─── OttoChain metagraph client ───────────────────────────────────────────────
|
|
44
44
|
export { MetagraphClient as OttoMetagraphClient } from './ottochain/metagraph-client.js';
|
|
45
|
+
// Proto definition helper
|
|
46
|
+
export { toProtoDefinition } from './schema/fiber-app.js';
|
|
@@ -45,3 +45,42 @@ export function isFinalState(def, state) {
|
|
|
45
45
|
export function toJSON(def) {
|
|
46
46
|
return JSON.parse(JSON.stringify(def));
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Extract proto-compatible StateMachineDefinition from a FiberAppDefinition.
|
|
50
|
+
* Use this when submitting to the metagraph.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const def = getContractDefinition('agreement');
|
|
55
|
+
* const protoDef = toProtoDefinition(def);
|
|
56
|
+
* // Submit protoDef to metagraph
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function toProtoDefinition(def) {
|
|
60
|
+
// Extract only the proto-compatible fields
|
|
61
|
+
const protoDef = {
|
|
62
|
+
states: {},
|
|
63
|
+
initialState: def.initialState,
|
|
64
|
+
transitions: def.transitions.map(t => ({
|
|
65
|
+
from: t.from,
|
|
66
|
+
to: t.to,
|
|
67
|
+
eventName: t.eventName,
|
|
68
|
+
...(t.guard && { guard: t.guard }),
|
|
69
|
+
...(t.effect && { effect: t.effect }),
|
|
70
|
+
...(t.dependencies?.length && { dependencies: [...t.dependencies] }),
|
|
71
|
+
...(t.emits?.length && { emits: [...t.emits] }),
|
|
72
|
+
})),
|
|
73
|
+
};
|
|
74
|
+
// Copy states (only id and isFinal)
|
|
75
|
+
for (const [key, state] of Object.entries(def.states)) {
|
|
76
|
+
protoDef.states[key] = {
|
|
77
|
+
id: state.id,
|
|
78
|
+
isFinal: state.isFinal,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Pass metadata through unchanged - it's an optional unstructured object
|
|
82
|
+
if (def.metadata) {
|
|
83
|
+
protoDef.metadata = def.metadata;
|
|
84
|
+
}
|
|
85
|
+
return protoDef;
|
|
86
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -29,3 +29,4 @@ export { OttoChainError, NetworkError, ValidationError, SigningError, Transactio
|
|
|
29
29
|
export { DagAddressSchema, PrivateKeySchema, PublicKeySchema, KeyPairSchema, SignatureProofSchema, SignedSchema, TransactionReferenceSchema, CurrencyTransactionValueSchema, CurrencyTransactionSchema, TransferParamsSchema, AgentIdentityRegistrationSchema, PlatformLinkSchema, ContractTermsSchema, ProposeContractRequestSchema, AcceptContractRequestSchema, CompleteContractRequestSchema, validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPair, safeParse, assert, type ValidatedKeyPair, type ValidatedSignatureProof, type ValidatedCurrencyTransaction, type ValidatedTransferParams, type ValidatedAgentIdentityRegistration, type ValidatedPlatformLink, type ValidatedProposeContractRequest, type ValidatedAcceptContractRequest, type ValidatedCompleteContractRequest, } from './validation.js';
|
|
30
30
|
export { MetagraphClient as OttoMetagraphClient } from './ottochain/metagraph-client.js';
|
|
31
31
|
export type { MetagraphClientConfig, Checkpoint, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './ottochain/metagraph-client.js';
|
|
32
|
+
export { toProtoDefinition, type ProtoStateMachineDefinition } from './schema/fiber-app.js';
|
|
@@ -137,3 +137,36 @@ export declare function getEventsFrom<T extends FiberAppDefinition>(def: T, stat
|
|
|
137
137
|
export declare function isFinalState<T extends FiberAppDefinition>(def: T, state: StateNames<T>): boolean;
|
|
138
138
|
/** Convert definition to plain JSON (for serialization) */
|
|
139
139
|
export declare function toJSON<T extends FiberAppDefinition>(def: T): object;
|
|
140
|
+
/**
|
|
141
|
+
* Proto-compatible state machine definition for metagraph submission.
|
|
142
|
+
* Matches StateMachineDefinition from ottochain/v1/fiber.proto
|
|
143
|
+
*/
|
|
144
|
+
export interface ProtoStateMachineDefinition {
|
|
145
|
+
states: Record<string, {
|
|
146
|
+
id: string;
|
|
147
|
+
isFinal: boolean;
|
|
148
|
+
}>;
|
|
149
|
+
initialState: string;
|
|
150
|
+
transitions: Array<{
|
|
151
|
+
from: string;
|
|
152
|
+
to: string;
|
|
153
|
+
eventName: string;
|
|
154
|
+
guard?: unknown;
|
|
155
|
+
effect?: unknown;
|
|
156
|
+
dependencies?: unknown[];
|
|
157
|
+
emits?: unknown[];
|
|
158
|
+
}>;
|
|
159
|
+
metadata?: Record<string, unknown>;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Extract proto-compatible StateMachineDefinition from a FiberAppDefinition.
|
|
163
|
+
* Use this when submitting to the metagraph.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* const def = getContractDefinition('agreement');
|
|
168
|
+
* const protoDef = toProtoDefinition(def);
|
|
169
|
+
* // Submit protoDef to metagraph
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function toProtoDefinition<T extends FiberAppDefinition>(def: T): ProtoStateMachineDefinition;
|
package/package.json
CHANGED