@ottochain/sdk 2.2.5 → 2.4.0
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/apps/contracts/index.js +15 -8
- package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +89 -46
- package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +152 -45
- package/dist/cjs/apps/contracts/state-machines/contract-universal.js +40 -8
- package/dist/cjs/apps/corporate/index.js +2 -2
- package/dist/cjs/apps/corporate/state-machines/corp-board.js +169 -59
- package/dist/cjs/apps/corporate/state-machines/corp-entity.js +245 -47
- package/dist/cjs/apps/corporate/state-machines/corp-securities.js +407 -99
- package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +151 -37
- package/dist/cjs/apps/governance/index.js +14 -14
- package/dist/cjs/apps/governance/state-machines/dao-multisig.js +85 -43
- package/dist/cjs/apps/governance/state-machines/dao-reputation.js +73 -43
- package/dist/cjs/apps/governance/state-machines/dao-single.js +55 -14
- package/dist/cjs/apps/governance/state-machines/dao-token.js +103 -45
- package/dist/cjs/apps/governance/state-machines/governance-simple.js +129 -65
- package/dist/cjs/apps/governance/state-machines/governance-universal.js +29 -5
- package/dist/cjs/apps/identity/constants.js +55 -14
- package/dist/cjs/apps/identity/index.js +27 -11
- package/dist/cjs/apps/identity/state-machines/identity-agent.js +57 -9
- package/dist/cjs/apps/identity/state-machines/identity-oracle.js +70 -27
- package/dist/cjs/apps/identity/state-machines/identity-registry.js +288 -0
- package/dist/cjs/apps/identity/state-machines/identity-universal.js +30 -6
- package/dist/cjs/apps/identity/state-machines/index.js +3 -1
- package/dist/cjs/apps/index.js +19 -8
- package/dist/cjs/apps/lending/assets.js +223 -0
- package/dist/cjs/apps/lending/credit-scoring.js +87 -0
- package/dist/cjs/apps/lending/eligibility.js +121 -0
- package/dist/cjs/apps/lending/index.js +91 -0
- package/dist/cjs/apps/lending/state-machines/index.js +9 -0
- package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +412 -0
- package/dist/cjs/apps/markets/index.js +21 -11
- package/dist/cjs/apps/markets/state-machines/market-auction.js +44 -19
- package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +54 -29
- package/dist/cjs/apps/markets/state-machines/market-group-buy.js +53 -31
- package/dist/cjs/apps/markets/state-machines/market-prediction.js +120 -61
- package/dist/cjs/apps/markets/state-machines/market-universal.js +50 -10
- package/dist/cjs/apps/oracles/index.js +2 -2
- package/dist/cjs/errors.js +3 -3
- package/dist/cjs/generated/google/protobuf/struct.js +4 -4
- package/dist/cjs/generated/index.js +11 -7
- package/dist/cjs/generated/openapi.js +6 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +50 -50
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +19 -20
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +13 -13
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +4 -4
- package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +124 -130
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +107 -107
- package/dist/cjs/generated/ottochain/v1/common.js +1722 -1
- package/dist/cjs/generated/ottochain/v1/fiber.js +355 -5
- package/dist/cjs/generated/ottochain/v1/messages.js +775 -3
- package/dist/cjs/generated/ottochain/v1/records.js +350 -3
- package/dist/cjs/index.js +45 -7
- package/dist/cjs/openapi.js +2 -0
- package/dist/cjs/ottochain/drop-nulls.js +1 -2
- package/dist/cjs/ottochain/genesis-manifest.js +193 -0
- package/dist/cjs/ottochain/index.js +27 -13
- package/dist/cjs/ottochain/metagraph-client.js +65 -8
- package/dist/cjs/ottochain/snapshot.js +11 -12
- package/dist/cjs/ottochain/transaction.js +57 -14
- package/dist/cjs/ottochain/types.js +19 -1
- package/dist/cjs/privacy/index.js +14 -0
- package/dist/cjs/privacy/sealed-bid.js +210 -0
- package/dist/cjs/privacy/shield-app.js +131 -0
- package/dist/cjs/schema/effects.js +40 -0
- package/dist/cjs/schema/fiber-app.js +19 -13
- package/dist/cjs/schema/guard-lint.js +352 -0
- package/dist/cjs/schema/guards.js +246 -0
- package/dist/cjs/signing.js +80 -0
- package/dist/cjs/types.js +2 -3
- package/dist/cjs/validation.js +8 -8
- package/dist/cjs/verify.js +9 -4
- package/dist/cjs/zk/commit.js +53 -0
- package/dist/cjs/zk/guard.js +107 -0
- package/dist/cjs/zk/index.js +48 -0
- package/dist/cjs/zk/preimage.js +37 -0
- package/dist/cjs/zk/prover.js +87 -0
- package/dist/cjs/zk/registry.js +62 -0
- package/dist/cjs/zk/types.js +28 -0
- package/dist/cjs/zk/witness.js +19 -0
- package/dist/esm/apps/contracts/index.js +7 -3
- package/dist/esm/apps/contracts/state-machines/contract-agreement.js +89 -46
- package/dist/esm/apps/contracts/state-machines/contract-escrow.js +152 -45
- package/dist/esm/apps/contracts/state-machines/contract-universal.js +40 -8
- package/dist/esm/apps/corporate/state-machines/corp-board.js +169 -59
- package/dist/esm/apps/corporate/state-machines/corp-entity.js +245 -47
- package/dist/esm/apps/corporate/state-machines/corp-securities.js +407 -99
- package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +151 -37
- package/dist/esm/apps/governance/state-machines/dao-multisig.js +85 -43
- package/dist/esm/apps/governance/state-machines/dao-reputation.js +73 -43
- package/dist/esm/apps/governance/state-machines/dao-single.js +55 -14
- package/dist/esm/apps/governance/state-machines/dao-token.js +103 -45
- package/dist/esm/apps/governance/state-machines/governance-simple.js +129 -65
- package/dist/esm/apps/governance/state-machines/governance-universal.js +29 -5
- package/dist/esm/apps/identity/constants.js +51 -12
- package/dist/esm/apps/identity/index.js +12 -7
- package/dist/esm/apps/identity/state-machines/identity-agent.js +57 -9
- package/dist/esm/apps/identity/state-machines/identity-oracle.js +70 -27
- package/dist/esm/apps/identity/state-machines/identity-registry.js +285 -0
- package/dist/esm/apps/identity/state-machines/identity-universal.js +30 -6
- package/dist/esm/apps/identity/state-machines/index.js +1 -0
- package/dist/esm/apps/index.js +1 -0
- package/dist/esm/apps/lending/assets.js +207 -0
- package/dist/esm/apps/lending/credit-scoring.js +81 -0
- package/dist/esm/apps/lending/eligibility.js +115 -0
- package/dist/esm/apps/lending/index.js +69 -0
- package/dist/esm/apps/lending/state-machines/index.js +5 -0
- package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +409 -0
- package/dist/esm/apps/markets/index.js +8 -4
- package/dist/esm/apps/markets/state-machines/market-auction.js +44 -19
- package/dist/esm/apps/markets/state-machines/market-crowdfund.js +54 -29
- package/dist/esm/apps/markets/state-machines/market-group-buy.js +53 -31
- package/dist/esm/apps/markets/state-machines/market-prediction.js +120 -61
- package/dist/esm/apps/markets/state-machines/market-universal.js +50 -10
- package/dist/esm/generated/index.js +9 -5
- package/dist/esm/generated/openapi.js +5 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +46 -46
- package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +114 -120
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +100 -100
- package/dist/esm/generated/ottochain/v1/common.js +1718 -0
- package/dist/esm/generated/ottochain/v1/fiber.js +351 -1
- package/dist/esm/generated/ottochain/v1/messages.js +774 -2
- package/dist/esm/generated/ottochain/v1/records.js +349 -2
- package/dist/esm/index.js +23 -2
- package/dist/esm/openapi.js +1 -0
- package/dist/esm/ottochain/genesis-manifest.js +189 -0
- package/dist/esm/ottochain/index.js +4 -3
- package/dist/esm/ottochain/metagraph-client.js +65 -8
- package/dist/esm/ottochain/snapshot.js +4 -4
- package/dist/esm/ottochain/transaction.js +43 -3
- package/dist/esm/ottochain/types.js +18 -0
- package/dist/esm/privacy/index.js +6 -0
- package/dist/esm/privacy/sealed-bid.js +206 -0
- package/dist/esm/privacy/shield-app.js +127 -0
- package/dist/esm/schema/effects.js +35 -0
- package/dist/esm/schema/fiber-app.js +13 -6
- package/dist/esm/schema/guard-lint.js +346 -0
- package/dist/esm/schema/guards.js +229 -0
- package/dist/esm/signing.js +74 -0
- package/dist/esm/verify.js +8 -2
- package/dist/esm/zk/commit.js +44 -0
- package/dist/esm/zk/guard.js +99 -0
- package/dist/esm/zk/index.js +19 -0
- package/dist/esm/zk/preimage.js +30 -0
- package/dist/esm/zk/prover.js +82 -0
- package/dist/esm/zk/registry.js +55 -0
- package/dist/esm/zk/types.js +25 -0
- package/dist/esm/zk/witness.js +15 -0
- package/dist/types/apps/contracts/index.d.ts +159 -227
- package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +50 -101
- package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +86 -120
- package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +20 -4
- package/dist/types/apps/corporate/index.d.ts +1040 -304
- package/dist/types/apps/corporate/state-machines/corp-board.d.ts +188 -52
- package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +267 -62
- package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +355 -131
- package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +225 -53
- package/dist/types/apps/governance/index.d.ts +396 -417
- package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -95
- package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +57 -69
- package/dist/types/apps/governance/state-machines/dao-single.d.ts +40 -50
- package/dist/types/apps/governance/state-machines/dao-token.d.ts +80 -53
- package/dist/types/apps/governance/state-machines/governance-simple.d.ts +107 -121
- package/dist/types/apps/governance/state-machines/governance-universal.d.ts +17 -5
- package/dist/types/apps/identity/constants.d.ts +32 -4
- package/dist/types/apps/identity/index.d.ts +449 -100
- package/dist/types/apps/identity/state-machines/identity-agent.d.ts +30 -0
- package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +41 -87
- package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
- package/dist/types/apps/identity/state-machines/identity-universal.d.ts +15 -0
- package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
- package/dist/types/apps/index.d.ts +1 -0
- package/dist/types/apps/lending/assets.d.ts +258 -0
- package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
- package/dist/types/apps/lending/eligibility.d.ts +83 -0
- package/dist/types/apps/lending/index.d.ts +548 -0
- package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
- package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +528 -0
- package/dist/types/apps/markets/index.d.ts +184 -204
- package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -37
- package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +26 -34
- package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +31 -43
- package/dist/types/apps/markets/state-machines/market-prediction.d.ts +67 -72
- package/dist/types/apps/markets/state-machines/market-universal.d.ts +30 -10
- package/dist/types/generated/index.d.ts +5 -5
- package/dist/types/generated/openapi.d.ts +1257 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
- package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
- package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
- package/dist/types/generated/ottochain/v1/common.d.ts +228 -0
- package/dist/types/generated/ottochain/v1/fiber.d.ts +32 -1
- package/dist/types/generated/ottochain/v1/messages.d.ts +84 -0
- package/dist/types/generated/ottochain/v1/records.d.ts +34 -0
- package/dist/types/index.d.ts +8 -2
- package/dist/types/openapi.d.ts +22 -0
- package/dist/types/ottochain/genesis-manifest.d.ts +130 -0
- package/dist/types/ottochain/index.d.ts +6 -5
- package/dist/types/ottochain/metagraph-client.d.ts +49 -7
- package/dist/types/ottochain/snapshot.d.ts +6 -6
- package/dist/types/ottochain/transaction.d.ts +33 -1
- package/dist/types/ottochain/types.d.ts +602 -11
- package/dist/types/privacy/index.d.ts +6 -0
- package/dist/types/privacy/sealed-bid.d.ts +348 -0
- package/dist/types/privacy/shield-app.d.ts +48 -0
- package/dist/types/schema/effects.d.ts +34 -0
- package/dist/types/schema/fiber-app.d.ts +41 -3
- package/dist/types/schema/guard-lint.d.ts +111 -0
- package/dist/types/schema/guards.d.ts +134 -0
- package/dist/types/signing.d.ts +45 -0
- package/dist/types/validation.d.ts +22 -217
- package/dist/types/verify.d.ts +4 -0
- package/dist/types/zk/commit.d.ts +28 -0
- package/dist/types/zk/guard.d.ts +46 -0
- package/dist/types/zk/index.d.ts +19 -0
- package/dist/types/zk/preimage.d.ts +10 -0
- package/dist/types/zk/prover.d.ts +34 -0
- package/dist/types/zk/registry.d.ts +34 -0
- package/dist/types/zk/types.d.ts +33 -0
- package/dist/types/zk/witness.d.ts +40 -0
- package/package.json +52 -35
- package/dist/cjs/ottochain/normalize.js +0 -186
- package/dist/esm/ottochain/normalize.js +0 -179
- package/dist/types/ottochain/normalize.d.ts +0 -79
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Groth16Bundle } from './types';
|
|
2
|
+
/** A request to prove that evaluating `expr` over `data` yields a result (raw JSON — canonicalized here). */
|
|
3
|
+
export interface Groth16ProveRequest {
|
|
4
|
+
/** The JLVM rule (plain JSON). Canonicalized before it reaches the prover. */
|
|
5
|
+
expr: unknown;
|
|
6
|
+
/** The (private) data context (plain JSON). Canonicalized before it reaches the prover. */
|
|
7
|
+
data: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Produces SP1-Groth16 bundles for the semi-private tier. Swap implementations in tests. */
|
|
10
|
+
export interface ZkProver {
|
|
11
|
+
proveGroth16(req: Groth16ProveRequest): Promise<Groth16Bundle>;
|
|
12
|
+
}
|
|
13
|
+
/** Configuration for {@link SubprocessProver}. Provide a binary OR a cargo manifest (binary wins). */
|
|
14
|
+
export interface SubprocessProverOptions {
|
|
15
|
+
/** Path to a prebuilt zk-jlvm host binary. Defaults to `ZK_JLVM_BIN`. */
|
|
16
|
+
binaryPath?: string;
|
|
17
|
+
/** Path to the zk-jlvm `script` crate's `Cargo.toml` (run via `cargo run --release`). Defaults to `ZK_JLVM_MANIFEST`. */
|
|
18
|
+
cargoManifestPath?: string;
|
|
19
|
+
/** Extra environment for the child (e.g. `{ SP1_PROVER: 'cuda' }`). Merged over `process.env`. */
|
|
20
|
+
env?: Record<string, string>;
|
|
21
|
+
/** Working directory for the child process. */
|
|
22
|
+
cwd?: string;
|
|
23
|
+
/** Hard timeout in ms. Default 1_800_000 (30 min) — SP1 Groth16 wrapping is slow. */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
/** Parse the host's `vkey:` / `public values:` / `proof bytes:` stdout lines into a bundle. */
|
|
27
|
+
export declare function parseGroth16Stdout(stdout: string): Groth16Bundle;
|
|
28
|
+
/** Drives the zk-jlvm host out-of-process. */
|
|
29
|
+
export declare class SubprocessProver implements ZkProver {
|
|
30
|
+
private readonly opts;
|
|
31
|
+
constructor(opts?: SubprocessProverOptions);
|
|
32
|
+
proveGroth16(req: Groth16ProveRequest): Promise<Groth16Bundle>;
|
|
33
|
+
private run;
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** A registered rule and the public `logicHash` that pins it on-chain and in proofs. */
|
|
2
|
+
export interface RegisteredRule {
|
|
3
|
+
/** The JLVM rule, as plain JSON (canonicalized when hashed and when fed to the prover). */
|
|
4
|
+
rule: unknown;
|
|
5
|
+
/** `keccak256(canonicalize(rule))` — the on-chain `logicHash` and a proof's `exprHash` word. */
|
|
6
|
+
logicHash: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
/** A client-side registry mapping rule names to their canonical `logicHash`. */
|
|
9
|
+
export declare class ExprRegistry {
|
|
10
|
+
private readonly byName;
|
|
11
|
+
/** Register (or replace) a named rule; returns the entry with its computed `logicHash`. */
|
|
12
|
+
register(name: string, rule: unknown): RegisteredRule;
|
|
13
|
+
/** Whether a rule is registered under `name`. */
|
|
14
|
+
has(name: string): boolean;
|
|
15
|
+
/** The registered rule, or throw if unknown. */
|
|
16
|
+
ruleOf(name: string): unknown;
|
|
17
|
+
/** The registered rule's `logicHash`, or throw if unknown. */
|
|
18
|
+
logicHashOf(name: string): `0x${string}`;
|
|
19
|
+
/** All registered names, in insertion order. */
|
|
20
|
+
names(): string[];
|
|
21
|
+
private require;
|
|
22
|
+
}
|
|
23
|
+
/** The comparators a bound rule can pin a private value against. */
|
|
24
|
+
export type Comparator = '>=' | '>' | '<=' | '<' | '==' | '!=';
|
|
25
|
+
/**
|
|
26
|
+
* A single-bound predicate `{[op]:[{var:varName}, bound]}` — the "pinned bound" a proof binds to.
|
|
27
|
+
* `bound` stays a JSON primitive (number/string) so the canonical bytes the prover hashes match the
|
|
28
|
+
* canonical bytes the rule registers under (bigint is not JSON-serializable — pre-encode if needed).
|
|
29
|
+
*/
|
|
30
|
+
export declare function boundRule(varName: string, op: Comparator, bound: number | string): Record<string, unknown>;
|
|
31
|
+
/** `{">=":[{"var":varName}, bound]}` — "the hidden `varName` is at least `bound`". */
|
|
32
|
+
export declare const atLeast: (varName: string, bound: number | string) => Record<string, unknown>;
|
|
33
|
+
/** `{"<=":[{"var":varName}, bound]}` — "the hidden `varName` is at most `bound`". */
|
|
34
|
+
export declare const atMost: (varName: string, bound: number | string) => Record<string, unknown>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SP1 zk-jlvm public-values types + decode.
|
|
3
|
+
*
|
|
4
|
+
* The guest commits `abi_encode(JlvmPublicValues{ bytes32 exprHash, bytes32 dataHash,
|
|
5
|
+
* bytes32 outputHash, bool ok })` — four 32-byte words, the bool right-aligned in its word.
|
|
6
|
+
* There is no on-chain `jlvm_pv_decode` opcode: the chain guard parses the same blob with the
|
|
7
|
+
* native JLVM `cat`/`substr` ops. This decode mirrors that for client-side binding/inspection.
|
|
8
|
+
*/
|
|
9
|
+
/** The decoded zk-jlvm public values: the keccak triple + the ok bit. */
|
|
10
|
+
export interface DecodedPublicValues {
|
|
11
|
+
/** keccak256(canonicalize(expr)) — pins WHICH JLVM rule ran (equals the registry logicHash). */
|
|
12
|
+
exprHash: `0x${string}`;
|
|
13
|
+
/** keccak256(canonicalize(data)) — the (private) data context's hash. */
|
|
14
|
+
dataHash: `0x${string}`;
|
|
15
|
+
/** keccak256(canonicalize(output)) — for a guarded "rule == true" proof, equals KECCAK_TRUE. */
|
|
16
|
+
outputHash: `0x${string}`;
|
|
17
|
+
/** Whether the JLVM evaluation succeeded (false ⇒ the guest aborted / errored). */
|
|
18
|
+
ok: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** A produced SP1-Groth16 bundle from the zk-jlvm prover (`--mode groth16`). */
|
|
21
|
+
export interface Groth16Bundle {
|
|
22
|
+
/** `abi_encode(JlvmPublicValues)` as a `0x` hex string. */
|
|
23
|
+
publicValues: `0x${string}`;
|
|
24
|
+
/** SP1 Groth16 proof bytes as a `0x` hex string. */
|
|
25
|
+
proof: `0x${string}`;
|
|
26
|
+
/** The program verification key (`bytes32`) as a `0x` hex string. */
|
|
27
|
+
vkey: `0x${string}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decode `abi_encode(JlvmPublicValues)`: four 32-byte words `[exprHash | dataHash | outputHash | ok]`.
|
|
31
|
+
* The bool is right-aligned in its word (final byte `0x00`/`0x01`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function decodeJlvmPublicValues(pv: `0x${string}`): DecodedPublicValues;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Witness shapers: turn a produced proof bundle (or a Merkle inclusion path) into the exact
|
|
3
|
+
* `JsonLogicValue` map a holder carries on a signed op's `witness` field. The combiner injects that
|
|
4
|
+
* map under the `witness` context key, and the policy guard reads `witness.publicValues` /
|
|
5
|
+
* `witness.proof` (groth16) or `witness.leaf` / `witness.index` / `witness.siblings` (pmt) — the
|
|
6
|
+
* shapes are fixed by metakit's guard opcodes (see ottochain ZkGatedMorphismSuite).
|
|
7
|
+
*/
|
|
8
|
+
import type { FrHex } from './commit';
|
|
9
|
+
import { type DecodedPublicValues, type Groth16Bundle } from './types';
|
|
10
|
+
/** The on-op map a `groth16_verify` guard reads. The vkey is NOT here — it is a literal in the guard. */
|
|
11
|
+
export interface Groth16WitnessMap {
|
|
12
|
+
/** `abi_encode(JlvmPublicValues)` as `0x` hex — the guard's `witness.publicValues`. */
|
|
13
|
+
publicValues: `0x${string}`;
|
|
14
|
+
/** SP1-Groth16 proof bytes as `0x` hex — the guard's `witness.proof`. */
|
|
15
|
+
proof: `0x${string}`;
|
|
16
|
+
}
|
|
17
|
+
/** A groth16 witness ready to attach to an op, plus its decoded public values for client binding. */
|
|
18
|
+
export interface Groth16Witness {
|
|
19
|
+
/** Attach this to the op's `witness` field (it is a plain `JsonLogicValue` map). */
|
|
20
|
+
witness: Groth16WitnessMap;
|
|
21
|
+
/** The decoded `{exprHash, dataHash, outputHash, ok}` — inspect/bind BEFORE submitting. */
|
|
22
|
+
decoded: DecodedPublicValues;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shape a produced {@link Groth16Bundle} into the on-op witness map (`{publicValues, proof}`) and
|
|
26
|
+
* surface its decoded public values. The vkey rides in the guard, not the witness, so it is dropped.
|
|
27
|
+
*/
|
|
28
|
+
export declare function groth16Witness(bundle: Groth16Bundle): Groth16Witness;
|
|
29
|
+
/**
|
|
30
|
+
* The on-op map a `pmt_verify` guard reads. `siblings` is the authentication path in the order the
|
|
31
|
+
* `pmt_verify` opcode folds it (ROOT-FIRST / top-down, as produced by metakit's PoseidonMerkleTree);
|
|
32
|
+
* `index` is the leaf position. Pass values straight through from the tree builder — do not reorder.
|
|
33
|
+
*/
|
|
34
|
+
export interface PmtWitnessMap {
|
|
35
|
+
leaf: FrHex;
|
|
36
|
+
index: number;
|
|
37
|
+
siblings: FrHex[];
|
|
38
|
+
}
|
|
39
|
+
/** Shape a Poseidon-Merkle inclusion path into the on-op `pmt_verify` witness map. */
|
|
40
|
+
export declare function pmtWitness(leaf: FrHex, index: number, siblings: FrHex[]): PmtWitnessMap;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ottochain/sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "TypeScript SDK for ottochain metagraph operations - signing, encoding, and network interactions",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"require": "./dist/cjs/ottochain/index.js",
|
|
22
22
|
"types": "./dist/types/ottochain/index.d.ts"
|
|
23
23
|
},
|
|
24
|
+
"./zk": {
|
|
25
|
+
"import": "./dist/esm/zk/index.js",
|
|
26
|
+
"require": "./dist/cjs/zk/index.js",
|
|
27
|
+
"types": "./dist/types/zk/index.d.ts"
|
|
28
|
+
},
|
|
24
29
|
"./apps/identity": {
|
|
25
30
|
"import": "./dist/esm/apps/identity/index.js",
|
|
26
31
|
"require": "./dist/cjs/apps/identity/index.js",
|
|
@@ -36,6 +41,11 @@
|
|
|
36
41
|
"require": "./dist/cjs/apps/markets/index.js",
|
|
37
42
|
"types": "./dist/types/apps/markets/index.d.ts"
|
|
38
43
|
},
|
|
44
|
+
"./apps/lending": {
|
|
45
|
+
"import": "./dist/esm/apps/lending/index.js",
|
|
46
|
+
"require": "./dist/cjs/apps/lending/index.js",
|
|
47
|
+
"types": "./dist/types/apps/lending/index.d.ts"
|
|
48
|
+
},
|
|
39
49
|
"./apps/oracles": {
|
|
40
50
|
"import": "./dist/esm/apps/oracles/index.js",
|
|
41
51
|
"require": "./dist/cjs/apps/oracles/index.js",
|
|
@@ -66,6 +76,25 @@
|
|
|
66
76
|
"dist",
|
|
67
77
|
"README.md"
|
|
68
78
|
],
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "npm run prebuild && npm run build:cjs && npm run build:esm && npm run build:types && npm run build:fixup",
|
|
81
|
+
"build:fixup": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
82
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
83
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
84
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
85
|
+
"test": "jest",
|
|
86
|
+
"test:coverage": "jest --coverage",
|
|
87
|
+
"lint": "eslint src tests",
|
|
88
|
+
"format": "prettier --write src tests",
|
|
89
|
+
"generate": "buf generate",
|
|
90
|
+
"gen:openapi": "openapi-typescript openapi/ottochain-openapi.json -o src/generated/openapi.ts",
|
|
91
|
+
"lint:proto": "buf lint",
|
|
92
|
+
"docs": "typedoc",
|
|
93
|
+
"docs:watch": "typedoc --watch",
|
|
94
|
+
"genesis:manifest": "npm run build && node scripts/emit-genesis-manifest.mjs genesis/std-manifest.json",
|
|
95
|
+
"prepare": "npm run build",
|
|
96
|
+
"prebuild": "node scripts/inline-json.mjs"
|
|
97
|
+
},
|
|
69
98
|
"keywords": [
|
|
70
99
|
"ottochain",
|
|
71
100
|
"constellation",
|
|
@@ -88,32 +117,35 @@
|
|
|
88
117
|
"url": "https://github.com/ottobot-ai/ottochain-sdk/issues"
|
|
89
118
|
},
|
|
90
119
|
"dependencies": {
|
|
91
|
-
"@bufbuild/protobuf": "^2.
|
|
92
|
-
"@constellation-network/metagraph-sdk": "
|
|
120
|
+
"@bufbuild/protobuf": "^2.12.0",
|
|
121
|
+
"@constellation-network/metagraph-sdk": "1.8.0-rc.5",
|
|
122
|
+
"@constellation-network/metagraph-sdk-jlvm": "1.8.0-rc.5",
|
|
123
|
+
"@noble/hashes": "^1.8.0",
|
|
93
124
|
"@stardust-collective/dag4": "^2.6.0",
|
|
94
125
|
"@stardust-collective/dag4-keystore": "^2.6.0",
|
|
95
|
-
"canonicalize": "^
|
|
126
|
+
"canonicalize": "^3.0.0",
|
|
96
127
|
"js-sha256": "^0.11.1",
|
|
97
128
|
"js-sha512": "^0.9.0",
|
|
98
|
-
"zod": "^
|
|
129
|
+
"zod": "^4.4.3"
|
|
99
130
|
},
|
|
100
131
|
"devDependencies": {
|
|
101
|
-
"@babel/preset-env": "^7.29.
|
|
102
|
-
"@commitlint/cli": "^
|
|
103
|
-
"@commitlint/config-conventional": "^
|
|
104
|
-
"@eslint/js": "^
|
|
132
|
+
"@babel/preset-env": "^7.29.7",
|
|
133
|
+
"@commitlint/cli": "^21.0.2",
|
|
134
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
135
|
+
"@eslint/js": "^10.0.1",
|
|
105
136
|
"@jest/globals": "^30.3.0",
|
|
106
137
|
"@types/jest": "^30.0.0",
|
|
107
|
-
"@types/node": "^25.
|
|
108
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
109
|
-
"@typescript-eslint/parser": "^8.
|
|
110
|
-
"eslint": "^
|
|
138
|
+
"@types/node": "^25.9.3",
|
|
139
|
+
"@typescript-eslint/eslint-plugin": "^8.61.0",
|
|
140
|
+
"@typescript-eslint/parser": "^8.61.0",
|
|
141
|
+
"eslint": "^10.5.0",
|
|
111
142
|
"jest": "^30.3.0",
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"ts-
|
|
115
|
-
"
|
|
116
|
-
"
|
|
143
|
+
"openapi-typescript": "^7.13.0",
|
|
144
|
+
"prettier": "^3.8.4",
|
|
145
|
+
"ts-jest": "29.4.9",
|
|
146
|
+
"ts-proto": "^2.11.6",
|
|
147
|
+
"typedoc": "^0.28.19",
|
|
148
|
+
"typescript": "^6.0.3"
|
|
117
149
|
},
|
|
118
150
|
"peerDependencies": {
|
|
119
151
|
"@stardust-collective/dag4": "^2.6.0"
|
|
@@ -124,20 +156,5 @@
|
|
|
124
156
|
"publishConfig": {
|
|
125
157
|
"registry": "https://registry.npmjs.org"
|
|
126
158
|
},
|
|
127
|
-
"
|
|
128
|
-
|
|
129
|
-
"build:fixup": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
130
|
-
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
131
|
-
"build:esm": "tsc -p tsconfig.esm.json",
|
|
132
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
133
|
-
"test": "jest",
|
|
134
|
-
"test:coverage": "jest --coverage",
|
|
135
|
-
"lint": "eslint src tests",
|
|
136
|
-
"format": "prettier --write src tests",
|
|
137
|
-
"generate": "buf generate",
|
|
138
|
-
"lint:proto": "buf lint",
|
|
139
|
-
"docs": "typedoc",
|
|
140
|
-
"docs:watch": "typedoc --watch",
|
|
141
|
-
"prebuild": "node scripts/inline-json.mjs"
|
|
142
|
-
}
|
|
143
|
-
}
|
|
159
|
+
"packageManager": "pnpm@10.30.0"
|
|
160
|
+
}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Normalize OttoChain Messages for Signing
|
|
4
|
-
*
|
|
5
|
-
* Converts OttoChain message objects to the wire format expected by the
|
|
6
|
-
* Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
|
|
7
|
-
* present as explicit `null` values, matching what circe's magnolia encoder
|
|
8
|
-
* produces on the Scala side.
|
|
9
|
-
*
|
|
10
|
-
* This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
|
|
11
|
-
* (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
|
|
12
|
-
* If the TypeScript client omits optional fields (undefined), the canonical
|
|
13
|
-
* JSON won't match and signature verification will fail.
|
|
14
|
-
*
|
|
15
|
-
* Schema mapping (Scala → TypeScript):
|
|
16
|
-
* - `Option[A] = None` → `null` (must be explicit, not undefined/absent)
|
|
17
|
-
* - `Option[A] = Some(v)` → `v`
|
|
18
|
-
* - `List.empty` → `[]`
|
|
19
|
-
* - `Map.empty` → `{}`
|
|
20
|
-
*/
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = void 0;
|
|
23
|
-
/**
|
|
24
|
-
* Normalize a State object for wire format
|
|
25
|
-
*/
|
|
26
|
-
function normalizeState(state) {
|
|
27
|
-
return {
|
|
28
|
-
id: state.id,
|
|
29
|
-
isFinal: state.isFinal ?? false,
|
|
30
|
-
metadata: state.metadata ?? null,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Normalize a Transition object for wire format
|
|
35
|
-
*
|
|
36
|
-
* Scala Transition schema:
|
|
37
|
-
* from: StateId (required)
|
|
38
|
-
* to: StateId (required)
|
|
39
|
-
* eventName: String (required)
|
|
40
|
-
* guard: JsonLogicExpression (required)
|
|
41
|
-
* effect: JsonLogicExpression (required)
|
|
42
|
-
* dependencies: Set[UUID] = Set.empty
|
|
43
|
-
*
|
|
44
|
-
* `dependencies` serializes as `[]` when empty (default). Both `guard`
|
|
45
|
-
* and `effect` are required non-optional fields.
|
|
46
|
-
*/
|
|
47
|
-
function normalizeTransition(t) {
|
|
48
|
-
return {
|
|
49
|
-
from: t.from,
|
|
50
|
-
to: t.to,
|
|
51
|
-
eventName: t.eventName,
|
|
52
|
-
guard: t.guard,
|
|
53
|
-
effect: t.effect,
|
|
54
|
-
dependencies: t.dependencies ?? [],
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Check if a value looks like FiberAppMetadata (has 'name' and 'app' fields).
|
|
59
|
-
* These TypeScript-only fields should be stripped before sending to metagraph.
|
|
60
|
-
*/
|
|
61
|
-
function isFiberAppMetadata(value) {
|
|
62
|
-
return (typeof value === 'object' &&
|
|
63
|
-
value !== null &&
|
|
64
|
-
'name' in value &&
|
|
65
|
-
'app' in value);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Normalize a StateMachineDefinition for wire format
|
|
69
|
-
*
|
|
70
|
-
* Strips FiberAppMetadata from the definition — the Scala schema expects
|
|
71
|
-
* `metadata: Option[Json] = None`, not the TypeScript app metadata object.
|
|
72
|
-
*/
|
|
73
|
-
function normalizeDefinition(def) {
|
|
74
|
-
const states = def.states;
|
|
75
|
-
const normalizedStates = {};
|
|
76
|
-
if (states) {
|
|
77
|
-
for (const [key, state] of Object.entries(states)) {
|
|
78
|
-
normalizedStates[key] = normalizeState(state);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const transitions = def.transitions ?? [];
|
|
82
|
-
// Strip FiberAppMetadata if present — it's TypeScript-only, not part of wire format.
|
|
83
|
-
// The Scala schema has `metadata: Option[Json] = None`, so use null for wire format.
|
|
84
|
-
const wireMetadata = isFiberAppMetadata(def.metadata) ? null : (def.metadata ?? null);
|
|
85
|
-
return {
|
|
86
|
-
states: normalizedStates,
|
|
87
|
-
initialState: def.initialState,
|
|
88
|
-
transitions: transitions.map(normalizeTransition),
|
|
89
|
-
metadata: wireMetadata,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Normalize a CreateStateMachine message for wire format
|
|
94
|
-
*
|
|
95
|
-
* Ensures all Option/default fields are explicit in wire format:
|
|
96
|
-
* - definition.metadata → null when absent
|
|
97
|
-
* - definition.states[*].metadata → null when absent
|
|
98
|
-
* - definition.transitions[*].dependencies → [] when absent
|
|
99
|
-
* - parentFiberId → null when absent
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* const message = normalizeCreateStateMachine({
|
|
104
|
-
* fiberId: '...',
|
|
105
|
-
* definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
|
|
106
|
-
* initialData: {}
|
|
107
|
-
* });
|
|
108
|
-
* // message now has parentFiberId: null, definition.metadata: null, etc.
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
function normalizeCreateStateMachine(msg) {
|
|
112
|
-
return {
|
|
113
|
-
fiberId: msg.fiberId,
|
|
114
|
-
definition: normalizeDefinition(msg.definition),
|
|
115
|
-
initialData: msg.initialData ?? {},
|
|
116
|
-
parentFiberId: msg.parentFiberId ?? null,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
exports.normalizeCreateStateMachine = normalizeCreateStateMachine;
|
|
120
|
-
/**
|
|
121
|
-
* Normalize a TransitionStateMachine message for wire format
|
|
122
|
-
*
|
|
123
|
-
* Scala TransitionStateMachine schema:
|
|
124
|
-
* fiberId: UUID (required)
|
|
125
|
-
* eventName: String (required)
|
|
126
|
-
* payload: JsonLogicValue (required)
|
|
127
|
-
* targetSequenceNumber: FiberOrdinal (required)
|
|
128
|
-
*
|
|
129
|
-
* All fields are required — no Option types, so no null normalization needed.
|
|
130
|
-
*/
|
|
131
|
-
function normalizeTransitionStateMachine(msg) {
|
|
132
|
-
return {
|
|
133
|
-
fiberId: msg.fiberId,
|
|
134
|
-
eventName: msg.eventName,
|
|
135
|
-
payload: msg.payload,
|
|
136
|
-
targetSequenceNumber: msg.targetSequenceNumber,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
exports.normalizeTransitionStateMachine = normalizeTransitionStateMachine;
|
|
140
|
-
/**
|
|
141
|
-
* Normalize an ArchiveStateMachine message for wire format
|
|
142
|
-
*
|
|
143
|
-
* Scala ArchiveStateMachine schema:
|
|
144
|
-
* fiberId: UUID (required)
|
|
145
|
-
* targetSequenceNumber: FiberOrdinal (required)
|
|
146
|
-
*
|
|
147
|
-
* All fields are required — no Option types, so no null normalization needed.
|
|
148
|
-
*/
|
|
149
|
-
function normalizeArchiveStateMachine(msg) {
|
|
150
|
-
return {
|
|
151
|
-
fiberId: msg.fiberId,
|
|
152
|
-
targetSequenceNumber: msg.targetSequenceNumber,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
exports.normalizeArchiveStateMachine = normalizeArchiveStateMachine;
|
|
156
|
-
/**
|
|
157
|
-
* Normalize any OttochainMessage wrapper for wire format.
|
|
158
|
-
*
|
|
159
|
-
* Detects the message type from the wrapper key and applies the
|
|
160
|
-
* appropriate normalization.
|
|
161
|
-
*
|
|
162
|
-
* @param message - OttochainMessage in wrapper format: `{ CreateStateMachine: {...} }`
|
|
163
|
-
* @returns Normalized message with all Option fields as explicit null
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```typescript
|
|
167
|
-
* const normalized = normalizeMessage({
|
|
168
|
-
* CreateStateMachine: { fiberId: '...', definition: {...}, initialData: {} }
|
|
169
|
-
* });
|
|
170
|
-
* const signed = await signDataUpdate(normalized, privateKey);
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
function normalizeMessage(message) {
|
|
174
|
-
if ('CreateStateMachine' in message) {
|
|
175
|
-
return { CreateStateMachine: normalizeCreateStateMachine(message.CreateStateMachine) };
|
|
176
|
-
}
|
|
177
|
-
if ('TransitionStateMachine' in message) {
|
|
178
|
-
return { TransitionStateMachine: normalizeTransitionStateMachine(message.TransitionStateMachine) };
|
|
179
|
-
}
|
|
180
|
-
if ('ArchiveStateMachine' in message) {
|
|
181
|
-
return { ArchiveStateMachine: normalizeArchiveStateMachine(message.ArchiveStateMachine) };
|
|
182
|
-
}
|
|
183
|
-
// CreateScript and InvokeScript — pass through (no optional fields)
|
|
184
|
-
return message;
|
|
185
|
-
}
|
|
186
|
-
exports.normalizeMessage = normalizeMessage;
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize OttoChain Messages for Signing
|
|
3
|
-
*
|
|
4
|
-
* Converts OttoChain message objects to the wire format expected by the
|
|
5
|
-
* Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
|
|
6
|
-
* present as explicit `null` values, matching what circe's magnolia encoder
|
|
7
|
-
* produces on the Scala side.
|
|
8
|
-
*
|
|
9
|
-
* This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
|
|
10
|
-
* (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
|
|
11
|
-
* If the TypeScript client omits optional fields (undefined), the canonical
|
|
12
|
-
* JSON won't match and signature verification will fail.
|
|
13
|
-
*
|
|
14
|
-
* Schema mapping (Scala → TypeScript):
|
|
15
|
-
* - `Option[A] = None` → `null` (must be explicit, not undefined/absent)
|
|
16
|
-
* - `Option[A] = Some(v)` → `v`
|
|
17
|
-
* - `List.empty` → `[]`
|
|
18
|
-
* - `Map.empty` → `{}`
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Normalize a State object for wire format
|
|
22
|
-
*/
|
|
23
|
-
function normalizeState(state) {
|
|
24
|
-
return {
|
|
25
|
-
id: state.id,
|
|
26
|
-
isFinal: state.isFinal ?? false,
|
|
27
|
-
metadata: state.metadata ?? null,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Normalize a Transition object for wire format
|
|
32
|
-
*
|
|
33
|
-
* Scala Transition schema:
|
|
34
|
-
* from: StateId (required)
|
|
35
|
-
* to: StateId (required)
|
|
36
|
-
* eventName: String (required)
|
|
37
|
-
* guard: JsonLogicExpression (required)
|
|
38
|
-
* effect: JsonLogicExpression (required)
|
|
39
|
-
* dependencies: Set[UUID] = Set.empty
|
|
40
|
-
*
|
|
41
|
-
* `dependencies` serializes as `[]` when empty (default). Both `guard`
|
|
42
|
-
* and `effect` are required non-optional fields.
|
|
43
|
-
*/
|
|
44
|
-
function normalizeTransition(t) {
|
|
45
|
-
return {
|
|
46
|
-
from: t.from,
|
|
47
|
-
to: t.to,
|
|
48
|
-
eventName: t.eventName,
|
|
49
|
-
guard: t.guard,
|
|
50
|
-
effect: t.effect,
|
|
51
|
-
dependencies: t.dependencies ?? [],
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Check if a value looks like FiberAppMetadata (has 'name' and 'app' fields).
|
|
56
|
-
* These TypeScript-only fields should be stripped before sending to metagraph.
|
|
57
|
-
*/
|
|
58
|
-
function isFiberAppMetadata(value) {
|
|
59
|
-
return (typeof value === 'object' &&
|
|
60
|
-
value !== null &&
|
|
61
|
-
'name' in value &&
|
|
62
|
-
'app' in value);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Normalize a StateMachineDefinition for wire format
|
|
66
|
-
*
|
|
67
|
-
* Strips FiberAppMetadata from the definition — the Scala schema expects
|
|
68
|
-
* `metadata: Option[Json] = None`, not the TypeScript app metadata object.
|
|
69
|
-
*/
|
|
70
|
-
function normalizeDefinition(def) {
|
|
71
|
-
const states = def.states;
|
|
72
|
-
const normalizedStates = {};
|
|
73
|
-
if (states) {
|
|
74
|
-
for (const [key, state] of Object.entries(states)) {
|
|
75
|
-
normalizedStates[key] = normalizeState(state);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const transitions = def.transitions ?? [];
|
|
79
|
-
// Strip FiberAppMetadata if present — it's TypeScript-only, not part of wire format.
|
|
80
|
-
// The Scala schema has `metadata: Option[Json] = None`, so use null for wire format.
|
|
81
|
-
const wireMetadata = isFiberAppMetadata(def.metadata) ? null : (def.metadata ?? null);
|
|
82
|
-
return {
|
|
83
|
-
states: normalizedStates,
|
|
84
|
-
initialState: def.initialState,
|
|
85
|
-
transitions: transitions.map(normalizeTransition),
|
|
86
|
-
metadata: wireMetadata,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Normalize a CreateStateMachine message for wire format
|
|
91
|
-
*
|
|
92
|
-
* Ensures all Option/default fields are explicit in wire format:
|
|
93
|
-
* - definition.metadata → null when absent
|
|
94
|
-
* - definition.states[*].metadata → null when absent
|
|
95
|
-
* - definition.transitions[*].dependencies → [] when absent
|
|
96
|
-
* - parentFiberId → null when absent
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* const message = normalizeCreateStateMachine({
|
|
101
|
-
* fiberId: '...',
|
|
102
|
-
* definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
|
|
103
|
-
* initialData: {}
|
|
104
|
-
* });
|
|
105
|
-
* // message now has parentFiberId: null, definition.metadata: null, etc.
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export function normalizeCreateStateMachine(msg) {
|
|
109
|
-
return {
|
|
110
|
-
fiberId: msg.fiberId,
|
|
111
|
-
definition: normalizeDefinition(msg.definition),
|
|
112
|
-
initialData: msg.initialData ?? {},
|
|
113
|
-
parentFiberId: msg.parentFiberId ?? null,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Normalize a TransitionStateMachine message for wire format
|
|
118
|
-
*
|
|
119
|
-
* Scala TransitionStateMachine schema:
|
|
120
|
-
* fiberId: UUID (required)
|
|
121
|
-
* eventName: String (required)
|
|
122
|
-
* payload: JsonLogicValue (required)
|
|
123
|
-
* targetSequenceNumber: FiberOrdinal (required)
|
|
124
|
-
*
|
|
125
|
-
* All fields are required — no Option types, so no null normalization needed.
|
|
126
|
-
*/
|
|
127
|
-
export function normalizeTransitionStateMachine(msg) {
|
|
128
|
-
return {
|
|
129
|
-
fiberId: msg.fiberId,
|
|
130
|
-
eventName: msg.eventName,
|
|
131
|
-
payload: msg.payload,
|
|
132
|
-
targetSequenceNumber: msg.targetSequenceNumber,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Normalize an ArchiveStateMachine message for wire format
|
|
137
|
-
*
|
|
138
|
-
* Scala ArchiveStateMachine schema:
|
|
139
|
-
* fiberId: UUID (required)
|
|
140
|
-
* targetSequenceNumber: FiberOrdinal (required)
|
|
141
|
-
*
|
|
142
|
-
* All fields are required — no Option types, so no null normalization needed.
|
|
143
|
-
*/
|
|
144
|
-
export function normalizeArchiveStateMachine(msg) {
|
|
145
|
-
return {
|
|
146
|
-
fiberId: msg.fiberId,
|
|
147
|
-
targetSequenceNumber: msg.targetSequenceNumber,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Normalize any OttochainMessage wrapper for wire format.
|
|
152
|
-
*
|
|
153
|
-
* Detects the message type from the wrapper key and applies the
|
|
154
|
-
* appropriate normalization.
|
|
155
|
-
*
|
|
156
|
-
* @param message - OttochainMessage in wrapper format: `{ CreateStateMachine: {...} }`
|
|
157
|
-
* @returns Normalized message with all Option fields as explicit null
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* const normalized = normalizeMessage({
|
|
162
|
-
* CreateStateMachine: { fiberId: '...', definition: {...}, initialData: {} }
|
|
163
|
-
* });
|
|
164
|
-
* const signed = await signDataUpdate(normalized, privateKey);
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
export function normalizeMessage(message) {
|
|
168
|
-
if ('CreateStateMachine' in message) {
|
|
169
|
-
return { CreateStateMachine: normalizeCreateStateMachine(message.CreateStateMachine) };
|
|
170
|
-
}
|
|
171
|
-
if ('TransitionStateMachine' in message) {
|
|
172
|
-
return { TransitionStateMachine: normalizeTransitionStateMachine(message.TransitionStateMachine) };
|
|
173
|
-
}
|
|
174
|
-
if ('ArchiveStateMachine' in message) {
|
|
175
|
-
return { ArchiveStateMachine: normalizeArchiveStateMachine(message.ArchiveStateMachine) };
|
|
176
|
-
}
|
|
177
|
-
// CreateScript and InvokeScript — pass through (no optional fields)
|
|
178
|
-
return message;
|
|
179
|
-
}
|