@effectstream/sm 0.100.21 → 0.100.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectstream/sm",
3
- "version": "0.100.21",
3
+ "version": "0.100.23",
4
4
  "license": "MIT",
5
5
  "homepage": "https://effectstream.github.io/docs/",
6
6
  "repository": {
@@ -17,14 +17,14 @@
17
17
  "./grammar": "./primitives/src/grammar.ts"
18
18
  },
19
19
  "dependencies": {
20
- "@effectstream/concise": "0.100.21",
21
- "@effectstream/config": "0.100.21",
22
- "@effectstream/coroutine": "0.100.21",
23
- "@effectstream/crypto": "0.100.21",
24
- "@effectstream/db": "0.100.21",
25
- "@effectstream/event-client": "0.100.21",
26
- "@effectstream/log": "0.100.21",
27
- "@effectstream/utils": "0.100.21",
20
+ "@effectstream/concise": "0.100.23",
21
+ "@effectstream/config": "0.100.23",
22
+ "@effectstream/coroutine": "0.100.23",
23
+ "@effectstream/crypto": "0.100.23",
24
+ "@effectstream/db": "0.100.23",
25
+ "@effectstream/event-client": "0.100.23",
26
+ "@effectstream/log": "0.100.23",
27
+ "@effectstream/utils": "0.100.23",
28
28
  "pg": "8.21.0",
29
29
  "pg-tx": "^1.0.1",
30
30
  "@sinclair/typebox": "0.34.41",
@@ -3,6 +3,9 @@
3
3
  export const PrimitiveTypeMidnightGeneric = "Midnight:Generic" as const;
4
4
  export const PrimitiveTypeMidnightNullifier = "Midnight:Nullifier" as const;
5
5
  export const PrimitiveTypeMidnightUnshieldedSpend = "Midnight:UnshieldedSpend" as const;
6
+ export const PrimitiveTypeMidnightUnshieldedCreate = "Midnight:UnshieldedCreate" as const;
7
+ export const PrimitiveTypeMidnightZswapRoot = "Midnight:ZswapRoot" as const;
8
+ export const PrimitiveTypeMidnightTokenMint = "Midnight:TokenMint" as const;
6
9
 
7
10
  export const PrimitiveTypeUtxorpcGeneric = "Utxorpc:Generic" as const;
8
11
  export const PrimitiveTypeCardanoMintBurn = "Cardano:MintBurn" as const;
@@ -34,6 +37,9 @@ type BuiltInPrimitives =
34
37
  typeof PrimitiveTypeMidnightGeneric |
35
38
  typeof PrimitiveTypeMidnightNullifier |
36
39
  typeof PrimitiveTypeMidnightUnshieldedSpend |
40
+ typeof PrimitiveTypeMidnightUnshieldedCreate |
41
+ typeof PrimitiveTypeMidnightZswapRoot |
42
+ typeof PrimitiveTypeMidnightTokenMint |
37
43
  typeof PrimitiveTypeEVMEffectstreamL2 |
38
44
  typeof PrimitiveTypeEVMERC721 |
39
45
  typeof PrimitiveTypeEVMERC20 |
@@ -0,0 +1,8 @@
1
+ import { Type } from "@sinclair/typebox";
2
+
3
+ export const midnightTokenMintGrammar = [
4
+ [
5
+ "payload",
6
+ Type.Any(),
7
+ ],
8
+ ] as const;
@@ -0,0 +1,126 @@
1
+ import { Primitive } from "@effectstream/sm";
2
+ import {
3
+ type AddressAndType,
4
+ AddressType,
5
+ type EffectstreamBlockNumber,
6
+ } from "@effectstream/utils";
7
+ import type { StaticDecode } from "@sinclair/typebox";
8
+ import {
9
+ type CommandTuple,
10
+ generateRawStmInput,
11
+ type ParamToData,
12
+ } from "@effectstream/concise";
13
+ import type {
14
+ ConfigSyncProtocolType,
15
+ FlattenSyncProtocolIOFor,
16
+ ProtocolPrimitiveMap,
17
+ } from "@effectstream/config";
18
+ import type { SyncStateUpdateStream } from "@effectstream/coroutine";
19
+ import { PrimitiveTypeMidnightTokenMint } from "../builtin.ts";
20
+ import { midnightTokenMintGrammar } from "./midnight-token-mint-grammar.ts";
21
+
22
+ /**
23
+ * MidnightTokenMintPrimitive
24
+ *
25
+ * Watches custom token *mints* on the Midnight ledger. A contract call's
26
+ * effects record minted tokens as `domain_sep → amount` maps (shielded and
27
+ * unshielded), and the resulting token type ("color") is derived as
28
+ * `rawTokenType(domain_sep, contract_address)` — so this primitive is the
29
+ * only way for a consumer to map a wallet-visible token id back to the
30
+ * contract that minted it. The fetcher deserializes each regular
31
+ * transaction's raw bytes with ledger-v8, walks the contract calls, and
32
+ * emits one state-machine input per `(tx, call, domainSep, kind)` — only
33
+ * for effects that actually applied on chain (failed segments roll back).
34
+ *
35
+ * The mint nonce is NOT part of token identity (it only randomizes coin
36
+ * commitments) and is never public for shielded mints, so it is not part
37
+ * of the payload.
38
+ *
39
+ * Usage:
40
+ * stm.addStateTransition("myPrefix", function* (data) {
41
+ * const { payload } = data.parsedInput;
42
+ * // payload = { txHash, contractAddress, domainSep, rawTokenType,
43
+ * // kind: "shielded" | "unshielded", amount, entryPoint }
44
+ * // amount is a decimal string (u64 mints can exceed MAX_SAFE_INTEGER)
45
+ * });
46
+ */
47
+ export class MidnightTokenMintPrimitive extends Primitive<
48
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL,
49
+ typeof midnightTokenMintGrammar
50
+ > {
51
+ readonly internalTypeName = PrimitiveTypeMidnightTokenMint;
52
+ override readonly grammar = midnightTokenMintGrammar;
53
+
54
+ override dynamicTables = undefined;
55
+ override getIntermediatePrefix(): string[] {
56
+ return [];
57
+ }
58
+ override getViewPrefix(): string[] {
59
+ return [];
60
+ }
61
+
62
+ constructor(config: {
63
+ instanceName: string;
64
+ startBlockHeight: number;
65
+ stateMachinePrefix: string;
66
+ }) {
67
+ super(config);
68
+ }
69
+
70
+ override *getPayload(
71
+ _: EffectstreamBlockNumber,
72
+ primitiveTransactionData: FlattenSyncProtocolIOFor<
73
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
74
+ >,
75
+ ): SyncStateUpdateStream<{
76
+ isBatched: boolean;
77
+ data: {
78
+ fromAddressAndType: AddressAndType;
79
+ stateMachinePayload:
80
+ | StaticDecode<CommandTuple<string, typeof midnightTokenMintGrammar>>
81
+ | null;
82
+ accountingPayload: ParamToData<typeof midnightTokenMintGrammar>;
83
+ }[];
84
+ }> {
85
+ const payload = primitiveTransactionData.output.payload;
86
+
87
+ const accountingPayload: ParamToData<typeof this.grammar> = {
88
+ payload,
89
+ };
90
+
91
+ const stateMachinePayload:
92
+ | StaticDecode<CommandTuple<string, typeof this.grammar>>
93
+ | null = this.stateMachinePrefix
94
+ ? generateRawStmInput(
95
+ this.grammar,
96
+ this.stateMachinePrefix,
97
+ accountingPayload,
98
+ )
99
+ : null;
100
+
101
+ return {
102
+ isBatched: false,
103
+ data: [
104
+ {
105
+ fromAddressAndType: {
106
+ type: AddressType.NONE,
107
+ address: "0x0",
108
+ },
109
+ accountingPayload,
110
+ stateMachinePayload,
111
+ },
112
+ ],
113
+ };
114
+ }
115
+
116
+ override getConfig(): ProtocolPrimitiveMap[
117
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
118
+ ] {
119
+ return {
120
+ name: this.instanceName,
121
+ type: this.internalTypeName,
122
+ startBlockHeight: this.startBlockHeight,
123
+ scheduledPrefix: this.stateMachinePrefix ?? "",
124
+ } as const;
125
+ }
126
+ }
@@ -0,0 +1,8 @@
1
+ import { Type } from "@sinclair/typebox";
2
+
3
+ export const midnightUnshieldedCreateGrammar = [
4
+ [
5
+ "payload",
6
+ Type.Any(),
7
+ ],
8
+ ] as const;
@@ -0,0 +1,121 @@
1
+ import { Primitive } from "@effectstream/sm";
2
+ import {
3
+ type AddressAndType,
4
+ AddressType,
5
+ type EffectstreamBlockNumber,
6
+ } from "@effectstream/utils";
7
+ import type { StaticDecode } from "@sinclair/typebox";
8
+ import {
9
+ type CommandTuple,
10
+ generateRawStmInput,
11
+ type ParamToData,
12
+ } from "@effectstream/concise";
13
+ import type {
14
+ ConfigSyncProtocolType,
15
+ FlattenSyncProtocolIOFor,
16
+ ProtocolPrimitiveMap,
17
+ } from "@effectstream/config";
18
+ import type { SyncStateUpdateStream } from "@effectstream/coroutine";
19
+ import { PrimitiveTypeMidnightUnshieldedCreate } from "../builtin.ts";
20
+ import { midnightUnshieldedCreateGrammar } from "./midnight-unshielded-create-grammar.ts";
21
+
22
+ /**
23
+ * MidnightUnshieldedCreatePrimitive
24
+ *
25
+ * Watches all unshielded UTXO *creation* events on the Midnight ledger — the
26
+ * mirror of MidnightUnshieldedSpendPrimitive. The indexer's GraphQL
27
+ * `transactions.unshieldedCreatedOutputs` field reports the
28
+ * `(owner, intentHash, outputIndex)` triple for each unshielded UTXO created
29
+ * in a block (by regular AND system transactions — rewards/bridge mint
30
+ * unshielded UTXOs). One state-machine input is emitted per created output.
31
+ *
32
+ * Lets a node maintain a persistent set of UTXOs that have actually been
33
+ * created on chain, so an offer referencing a never-created unshielded UTXO
34
+ * can be rejected (existence check).
35
+ *
36
+ * Usage:
37
+ * stm.addStateTransition("myPrefix", function* (data) {
38
+ * const { payload } = data.parsedInput;
39
+ * // payload = { owner, intentHash, outputIndex, txHash }
40
+ * });
41
+ */
42
+ export class MidnightUnshieldedCreatePrimitive extends Primitive<
43
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL,
44
+ typeof midnightUnshieldedCreateGrammar
45
+ > {
46
+ readonly internalTypeName = PrimitiveTypeMidnightUnshieldedCreate;
47
+ override readonly grammar = midnightUnshieldedCreateGrammar;
48
+
49
+ override dynamicTables = undefined;
50
+ override getIntermediatePrefix(): string[] {
51
+ return [];
52
+ }
53
+ override getViewPrefix(): string[] {
54
+ return [];
55
+ }
56
+
57
+ constructor(config: {
58
+ instanceName: string;
59
+ startBlockHeight: number;
60
+ stateMachinePrefix: string;
61
+ }) {
62
+ super(config);
63
+ }
64
+
65
+ override *getPayload(
66
+ _: EffectstreamBlockNumber,
67
+ primitiveTransactionData: FlattenSyncProtocolIOFor<
68
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
69
+ >,
70
+ ): SyncStateUpdateStream<{
71
+ isBatched: boolean;
72
+ data: {
73
+ fromAddressAndType: AddressAndType;
74
+ stateMachinePayload:
75
+ | StaticDecode<CommandTuple<string, typeof midnightUnshieldedCreateGrammar>>
76
+ | null;
77
+ accountingPayload: ParamToData<typeof midnightUnshieldedCreateGrammar>;
78
+ }[];
79
+ }> {
80
+ const payload = primitiveTransactionData.output.payload;
81
+
82
+ const accountingPayload: ParamToData<typeof this.grammar> = {
83
+ payload,
84
+ };
85
+
86
+ const stateMachinePayload:
87
+ | StaticDecode<CommandTuple<string, typeof this.grammar>>
88
+ | null = this.stateMachinePrefix
89
+ ? generateRawStmInput(
90
+ this.grammar,
91
+ this.stateMachinePrefix,
92
+ accountingPayload,
93
+ )
94
+ : null;
95
+
96
+ return {
97
+ isBatched: false,
98
+ data: [
99
+ {
100
+ fromAddressAndType: {
101
+ type: AddressType.NONE,
102
+ address: "0x0",
103
+ },
104
+ accountingPayload,
105
+ stateMachinePayload,
106
+ },
107
+ ],
108
+ };
109
+ }
110
+
111
+ override getConfig(): ProtocolPrimitiveMap[
112
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
113
+ ] {
114
+ return {
115
+ name: this.instanceName,
116
+ type: this.internalTypeName,
117
+ startBlockHeight: this.startBlockHeight,
118
+ scheduledPrefix: this.stateMachinePrefix ?? "",
119
+ } as const;
120
+ }
121
+ }
@@ -0,0 +1,8 @@
1
+ import { Type } from "@sinclair/typebox";
2
+
3
+ export const midnightZswapRootGrammar = [
4
+ [
5
+ "payload",
6
+ Type.Any(),
7
+ ],
8
+ ] as const;
@@ -0,0 +1,121 @@
1
+ import { Primitive } from "@effectstream/sm";
2
+ import {
3
+ type AddressAndType,
4
+ AddressType,
5
+ type EffectstreamBlockNumber,
6
+ } from "@effectstream/utils";
7
+ import type { StaticDecode } from "@sinclair/typebox";
8
+ import {
9
+ type CommandTuple,
10
+ generateRawStmInput,
11
+ type ParamToData,
12
+ } from "@effectstream/concise";
13
+ import type {
14
+ ConfigSyncProtocolType,
15
+ FlattenSyncProtocolIOFor,
16
+ ProtocolPrimitiveMap,
17
+ } from "@effectstream/config";
18
+ import type { SyncStateUpdateStream } from "@effectstream/coroutine";
19
+ import { PrimitiveTypeMidnightZswapRoot } from "../builtin.ts";
20
+ import { midnightZswapRootGrammar } from "./midnight-zswap-root-grammar.ts";
21
+
22
+ /**
23
+ * MidnightZswapRootPrimitive
24
+ *
25
+ * Emits the zswap coin-commitment Merkle tree root as it advances on chain.
26
+ * The indexer's `RegularTransaction.zswapMerkleTreeRoot` is the tree root
27
+ * *after* that transaction; this primitive surfaces the latest such root per
28
+ * block (the last regular transaction's root), with the block timestamp.
29
+ *
30
+ * A node can accumulate these into a windowed "known roots" set (mirroring the
31
+ * ledger's `past_roots`, retained for the on-chain root window) and reject an
32
+ * offer that proves against a root the chain never held or that has aged out —
33
+ * the root-known liveness check. Blocks with no regular transactions emit
34
+ * nothing (the root is unchanged).
35
+ *
36
+ * Usage:
37
+ * stm.addStateTransition("myPrefix", function* (data) {
38
+ * const { payload } = data.parsedInput;
39
+ * // payload = { root, txHash } ; data.blockTimestamp is the window key
40
+ * });
41
+ */
42
+ export class MidnightZswapRootPrimitive extends Primitive<
43
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL,
44
+ typeof midnightZswapRootGrammar
45
+ > {
46
+ readonly internalTypeName = PrimitiveTypeMidnightZswapRoot;
47
+ override readonly grammar = midnightZswapRootGrammar;
48
+
49
+ override dynamicTables = undefined;
50
+ override getIntermediatePrefix(): string[] {
51
+ return [];
52
+ }
53
+ override getViewPrefix(): string[] {
54
+ return [];
55
+ }
56
+
57
+ constructor(config: {
58
+ instanceName: string;
59
+ startBlockHeight: number;
60
+ stateMachinePrefix: string;
61
+ }) {
62
+ super(config);
63
+ }
64
+
65
+ override *getPayload(
66
+ _: EffectstreamBlockNumber,
67
+ primitiveTransactionData: FlattenSyncProtocolIOFor<
68
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
69
+ >,
70
+ ): SyncStateUpdateStream<{
71
+ isBatched: boolean;
72
+ data: {
73
+ fromAddressAndType: AddressAndType;
74
+ stateMachinePayload:
75
+ | StaticDecode<CommandTuple<string, typeof midnightZswapRootGrammar>>
76
+ | null;
77
+ accountingPayload: ParamToData<typeof midnightZswapRootGrammar>;
78
+ }[];
79
+ }> {
80
+ const payload = primitiveTransactionData.output.payload;
81
+
82
+ const accountingPayload: ParamToData<typeof this.grammar> = {
83
+ payload,
84
+ };
85
+
86
+ const stateMachinePayload:
87
+ | StaticDecode<CommandTuple<string, typeof this.grammar>>
88
+ | null = this.stateMachinePrefix
89
+ ? generateRawStmInput(
90
+ this.grammar,
91
+ this.stateMachinePrefix,
92
+ accountingPayload,
93
+ )
94
+ : null;
95
+
96
+ return {
97
+ isBatched: false,
98
+ data: [
99
+ {
100
+ fromAddressAndType: {
101
+ type: AddressType.NONE,
102
+ address: "0x0",
103
+ },
104
+ accountingPayload,
105
+ stateMachinePayload,
106
+ },
107
+ ],
108
+ };
109
+ }
110
+
111
+ override getConfig(): ProtocolPrimitiveMap[
112
+ ConfigSyncProtocolType.MIDNIGHT_PARALLEL
113
+ ] {
114
+ return {
115
+ name: this.instanceName,
116
+ type: this.internalTypeName,
117
+ startBlockHeight: this.startBlockHeight,
118
+ scheduledPrefix: this.stateMachinePrefix ?? "",
119
+ } as const;
120
+ }
121
+ }
@@ -2,6 +2,9 @@ import {
2
2
  PrimitiveTypeMidnightGeneric,
3
3
  PrimitiveTypeMidnightNullifier,
4
4
  PrimitiveTypeMidnightUnshieldedSpend,
5
+ PrimitiveTypeMidnightUnshieldedCreate,
6
+ PrimitiveTypeMidnightZswapRoot,
7
+ PrimitiveTypeMidnightTokenMint,
5
8
  PrimitiveTypeEVMEffectstreamL2,
6
9
  PrimitiveTypeEVMERC721,
7
10
  PrimitiveTypeEVMERC20,
@@ -27,6 +30,9 @@ import {
27
30
  import { MidnightGenericPrimitive } from "./midnight-generic/midnight-genetic.ts";
28
31
  import { MidnightNullifierPrimitive } from "./midnight-nullifier/midnight-nullifier.ts";
29
32
  import { MidnightUnshieldedSpendPrimitive } from "./midnight-unshielded-spend/midnight-unshielded-spend.ts";
33
+ import { MidnightUnshieldedCreatePrimitive } from "./midnight-unshielded-create/midnight-unshielded-create.ts";
34
+ import { MidnightZswapRootPrimitive } from "./midnight-zswap-root/midnight-zswap-root.ts";
35
+ import { MidnightTokenMintPrimitive } from "./midnight-token-mint/midnight-token-mint.ts";
30
36
  import { EffectstreamL2Primitive } from "./evm-effectstream-l2/effectstream-l2-primitive.ts";
31
37
  import { Erc721Primitive } from "./evm-erc721/erc721-primitive.ts";
32
38
  import { Erc20Primitive } from "./evm-erc20/erc20-primitive.ts";
@@ -52,6 +58,9 @@ const builtInPrimitivesMap = {
52
58
  [PrimitiveTypeMidnightGeneric]: MidnightGenericPrimitive,
53
59
  [PrimitiveTypeMidnightNullifier]: MidnightNullifierPrimitive,
54
60
  [PrimitiveTypeMidnightUnshieldedSpend]: MidnightUnshieldedSpendPrimitive,
61
+ [PrimitiveTypeMidnightUnshieldedCreate]: MidnightUnshieldedCreatePrimitive,
62
+ [PrimitiveTypeMidnightZswapRoot]: MidnightZswapRootPrimitive,
63
+ [PrimitiveTypeMidnightTokenMint]: MidnightTokenMintPrimitive,
55
64
  [PrimitiveTypeEVMEffectstreamL2]: EffectstreamL2Primitive,
56
65
  [PrimitiveTypeEVMERC721]: Erc721Primitive,
57
66
  [PrimitiveTypeEVMERC20]: Erc20Primitive,
@@ -82,6 +91,9 @@ export {
82
91
  MidnightGenericPrimitive,
83
92
  MidnightNullifierPrimitive,
84
93
  MidnightUnshieldedSpendPrimitive,
94
+ MidnightUnshieldedCreatePrimitive,
95
+ MidnightZswapRootPrimitive,
96
+ MidnightTokenMintPrimitive,
85
97
  EffectstreamL2Primitive,
86
98
  Erc721Primitive,
87
99
  Erc20Primitive,