@ottochain/sdk 2.3.0 → 2.5.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/compute/index.js +33 -0
- package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
- package/dist/cjs/apps/compute/state-machines/index.js +9 -0
- package/dist/cjs/apps/contracts/index.js +16 -9
- package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +134 -161
- package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +192 -170
- package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
- package/dist/cjs/apps/corporate/index.js +2 -2
- package/dist/cjs/apps/corporate/state-machines/corp-board.js +500 -456
- package/dist/cjs/apps/corporate/state-machines/corp-entity.js +487 -361
- package/dist/cjs/apps/corporate/state-machines/corp-securities.js +769 -576
- package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +567 -557
- package/dist/cjs/apps/governance/index.js +21 -21
- package/dist/cjs/apps/governance/state-machines/dao-multisig.js +188 -209
- package/dist/cjs/apps/governance/state-machines/dao-reputation.js +181 -228
- package/dist/cjs/apps/governance/state-machines/dao-single.js +105 -88
- package/dist/cjs/apps/governance/state-machines/dao-token.js +199 -227
- package/dist/cjs/apps/governance/state-machines/governance-simple.js +231 -231
- package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
- package/dist/cjs/apps/identity/constants.js +55 -22
- package/dist/cjs/apps/identity/index.js +28 -12
- package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
- package/dist/cjs/apps/identity/state-machines/identity-oracle.js +158 -173
- package/dist/cjs/apps/identity/state-machines/identity-registry.js +262 -0
- package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
- package/dist/cjs/apps/identity/state-machines/index.js +3 -1
- package/dist/cjs/apps/index.js +22 -8
- package/dist/cjs/apps/lending/assets.js +247 -0
- package/dist/cjs/apps/lending/credit-scoring.js +87 -0
- package/dist/cjs/apps/lending/eligibility.js +105 -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 +433 -0
- package/dist/cjs/apps/markets/index.js +22 -12
- package/dist/cjs/apps/markets/state-machines/market-auction.js +116 -134
- package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +131 -141
- package/dist/cjs/apps/markets/state-machines/market-group-buy.js +163 -184
- package/dist/cjs/apps/markets/state-machines/market-prediction.js +226 -233
- package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
- package/dist/cjs/apps/oracles/index.js +3 -3
- package/dist/cjs/apps/privacy/index.js +67 -0
- package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
- package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
- package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
- package/dist/cjs/apps/staked-pool/assets.js +103 -0
- package/dist/cjs/apps/staked-pool/base.js +498 -0
- package/dist/cjs/apps/staked-pool/consumer.js +55 -0
- package/dist/cjs/apps/staked-pool/index.js +83 -0
- package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
- package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
- package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
- package/dist/cjs/errors.js +3 -3
- package/dist/cjs/generated/google/protobuf/struct.js +5 -5
- package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
- 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 +51 -51
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +20 -21
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +14 -14
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +5 -5
- package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +125 -131
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +108 -108
- package/dist/cjs/generated/ottochain/v1/common.js +5 -5
- package/dist/cjs/generated/ottochain/v1/fiber.js +44 -6
- package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
- package/dist/cjs/generated/ottochain/v1/records.js +1 -1
- package/dist/cjs/index.js +58 -7
- package/dist/cjs/openapi.js +2 -0
- package/dist/cjs/ottochain/drop-nulls.js +1 -2
- package/dist/cjs/ottochain/genesis-manifest.js +17 -11
- package/dist/cjs/ottochain/index.js +23 -13
- package/dist/cjs/ottochain/metagraph-client.js +81 -16
- package/dist/cjs/ottochain/snapshot.js +13 -16
- package/dist/cjs/ottochain/transaction.js +67 -14
- package/dist/cjs/ottochain/types.js +16 -2
- package/dist/cjs/privacy/index.js +14 -0
- package/dist/cjs/privacy/sealed-bid.js +213 -0
- package/dist/cjs/privacy/shield-app.js +131 -0
- package/dist/cjs/schema/effects.js +156 -0
- package/dist/cjs/schema/fiber-app.js +150 -15
- package/dist/cjs/schema/guard-lint.js +343 -0
- package/dist/cjs/schema/guards.js +246 -0
- package/dist/cjs/signing.js +80 -0
- package/dist/cjs/templates/asset-policy.js +190 -0
- package/dist/cjs/templates/index.js +86 -0
- package/dist/cjs/templates/machine.js +130 -0
- package/dist/cjs/templates/migration.js +39 -0
- package/dist/cjs/templates/state-shape.js +38 -0
- package/dist/cjs/types.js +2 -3
- package/dist/cjs/validation.js +9 -11
- 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/compute/index.js +29 -0
- package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
- package/dist/esm/apps/compute/state-machines/index.js +5 -0
- package/dist/esm/apps/contracts/index.js +9 -5
- package/dist/esm/apps/contracts/state-machines/contract-agreement.js +135 -162
- package/dist/esm/apps/contracts/state-machines/contract-escrow.js +193 -171
- package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
- package/dist/esm/apps/corporate/index.js +2 -2
- package/dist/esm/apps/corporate/state-machines/corp-board.js +501 -457
- package/dist/esm/apps/corporate/state-machines/corp-entity.js +488 -362
- package/dist/esm/apps/corporate/state-machines/corp-securities.js +770 -577
- package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +568 -558
- package/dist/esm/apps/governance/index.js +10 -10
- package/dist/esm/apps/governance/state-machines/dao-multisig.js +189 -210
- package/dist/esm/apps/governance/state-machines/dao-reputation.js +182 -229
- package/dist/esm/apps/governance/state-machines/dao-single.js +106 -89
- package/dist/esm/apps/governance/state-machines/dao-token.js +200 -228
- package/dist/esm/apps/governance/state-machines/governance-simple.js +232 -232
- package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
- package/dist/esm/apps/identity/constants.js +52 -21
- package/dist/esm/apps/identity/index.js +14 -9
- package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
- package/dist/esm/apps/identity/state-machines/identity-oracle.js +159 -174
- package/dist/esm/apps/identity/state-machines/identity-registry.js +259 -0
- package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
- package/dist/esm/apps/identity/state-machines/index.js +1 -0
- package/dist/esm/apps/index.js +9 -5
- package/dist/esm/apps/lending/assets.js +231 -0
- package/dist/esm/apps/lending/credit-scoring.js +81 -0
- package/dist/esm/apps/lending/eligibility.js +99 -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 +430 -0
- package/dist/esm/apps/markets/index.js +11 -7
- package/dist/esm/apps/markets/state-machines/market-auction.js +117 -135
- package/dist/esm/apps/markets/state-machines/market-crowdfund.js +132 -142
- package/dist/esm/apps/markets/state-machines/market-group-buy.js +164 -185
- package/dist/esm/apps/markets/state-machines/market-prediction.js +227 -234
- package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
- package/dist/esm/apps/oracles/index.js +3 -3
- package/dist/esm/apps/privacy/index.js +56 -0
- package/dist/esm/apps/privacy/state-machines/index.js +6 -0
- package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
- package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
- package/dist/esm/apps/staked-pool/assets.js +91 -0
- package/dist/esm/apps/staked-pool/base.js +493 -0
- package/dist/esm/apps/staked-pool/consumer.js +49 -0
- package/dist/esm/apps/staked-pool/index.js +60 -0
- package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
- package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
- package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
- package/dist/esm/generated/google/protobuf/struct.js +1 -1
- package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
- 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 +47 -47
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
- package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
- package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +115 -121
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +101 -101
- package/dist/esm/generated/ottochain/v1/common.js +1 -1
- package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
- package/dist/esm/generated/ottochain/v1/messages.js +1 -1
- package/dist/esm/generated/ottochain/v1/records.js +1 -1
- package/dist/esm/index.js +28 -3
- package/dist/esm/openapi.js +1 -0
- package/dist/esm/ottochain/genesis-manifest.js +15 -9
- package/dist/esm/ottochain/index.js +2 -3
- package/dist/esm/ottochain/metagraph-client.js +81 -16
- package/dist/esm/ottochain/snapshot.js +6 -8
- package/dist/esm/ottochain/transaction.js +51 -3
- package/dist/esm/ottochain/types.js +15 -1
- package/dist/esm/privacy/index.js +6 -0
- package/dist/esm/privacy/sealed-bid.js +209 -0
- package/dist/esm/privacy/shield-app.js +127 -0
- package/dist/esm/schema/effects.js +145 -0
- package/dist/esm/schema/fiber-app.js +139 -8
- package/dist/esm/schema/guard-lint.js +337 -0
- package/dist/esm/schema/guards.js +228 -0
- package/dist/esm/signing.js +74 -0
- package/dist/esm/templates/asset-policy.js +182 -0
- package/dist/esm/templates/index.js +41 -0
- package/dist/esm/templates/machine.js +125 -0
- package/dist/esm/templates/migration.js +34 -0
- package/dist/esm/templates/state-shape.js +34 -0
- package/dist/esm/validation.js +1 -3
- 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/compute/index.d.ts +176 -0
- package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
- package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
- package/dist/types/apps/contracts/index.d.ts +81 -221
- package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +23 -98
- package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +49 -115
- package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
- package/dist/types/apps/corporate/index.d.ts +1176 -440
- package/dist/types/apps/corporate/state-machines/corp-board.d.ts +271 -135
- package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +279 -74
- package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +373 -149
- package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +252 -80
- package/dist/types/apps/governance/index.d.ts +368 -470
- package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -107
- package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +61 -85
- package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
- package/dist/types/apps/governance/state-machines/dao-token.d.ts +79 -68
- package/dist/types/apps/governance/state-machines/governance-simple.d.ts +95 -125
- package/dist/types/apps/governance/state-machines/governance-universal.d.ts +6 -6
- package/dist/types/apps/identity/constants.d.ts +33 -5
- package/dist/types/apps/identity/index.d.ts +415 -131
- package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
- package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +27 -98
- package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
- package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
- package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
- package/dist/types/apps/index.d.ts +9 -5
- 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 +556 -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 +536 -0
- package/dist/types/apps/markets/index.d.ts +181 -276
- package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -49
- package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +35 -53
- package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +35 -61
- package/dist/types/apps/markets/state-machines/market-prediction.d.ts +65 -86
- package/dist/types/apps/markets/state-machines/market-universal.d.ts +12 -12
- package/dist/types/apps/oracles/index.d.ts +1 -1
- package/dist/types/apps/privacy/index.d.ts +328 -0
- package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
- package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
- package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
- package/dist/types/apps/staked-pool/assets.d.ts +53 -0
- package/dist/types/apps/staked-pool/base.d.ts +80 -0
- package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
- package/dist/types/apps/staked-pool/index.d.ts +51 -0
- package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
- package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
- package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
- package/dist/types/generated/index.d.ts +5 -5
- package/dist/types/generated/openapi.d.ts +1270 -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/fiber.d.ts +7 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/openapi.d.ts +24 -0
- package/dist/types/ottochain/genesis-manifest.d.ts +11 -5
- package/dist/types/ottochain/index.d.ts +5 -6
- 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 +41 -1
- package/dist/types/ottochain/types.d.ts +336 -31
- 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 +141 -0
- package/dist/types/schema/fiber-app.d.ts +282 -2
- package/dist/types/schema/guard-lint.d.ts +111 -0
- package/dist/types/schema/guards.d.ts +146 -0
- package/dist/types/signing.d.ts +45 -0
- package/dist/types/templates/asset-policy.d.ts +119 -0
- package/dist/types/templates/index.d.ts +26 -0
- package/dist/types/templates/machine.d.ts +139 -0
- package/dist/types/templates/migration.d.ts +34 -0
- package/dist/types/templates/state-shape.d.ts +30 -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 +47 -15
- 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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* package at genesis.
|
|
10
10
|
*
|
|
11
11
|
* DESIGN — content, not consensus hashes:
|
|
12
|
-
* The manifest ships CONTENT only: the `
|
|
12
|
+
* The manifest ships CONTENT only: the `machineShape` (the typed, proto-faithful
|
|
13
13
|
* projection of the app's state message) and the `definition` (the JSON-Logic
|
|
14
14
|
* `StateMachineDefinition`, verbatim — the same object the chain decodes for any
|
|
15
15
|
* fiber). The CHAIN computes the consensus values itself from this content:
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* payloads. Deriving per-event command shapes is a flagged follow-up.
|
|
38
38
|
*
|
|
39
39
|
* The JSON shape emitted here is built to deserialize against the chain's circe
|
|
40
|
-
* codecs (`
|
|
40
|
+
* codecs (`MachineShape` / `FieldShape` / `MessageShape` and
|
|
41
41
|
* `StateMachineDefinition`), whose magnolia config is camelCase with defaults.
|
|
42
42
|
*
|
|
43
43
|
* @packageDocumentation
|
|
@@ -65,8 +65,8 @@ const identityStateMessage = {
|
|
|
65
65
|
field('address', 2, 'string'),
|
|
66
66
|
field('public_key', 3, 'string'),
|
|
67
67
|
field('display_name', 4, 'string'),
|
|
68
|
-
field('identity_type', 5, 'ottochain.apps.identity.v1.
|
|
69
|
-
field('state', 6, 'ottochain.apps.identity.v1.
|
|
68
|
+
field('identity_type', 5, 'ottochain.apps.identity.v1.Type'),
|
|
69
|
+
field('state', 6, 'ottochain.apps.identity.v1.State'),
|
|
70
70
|
field('reputation', 7, 'ottochain.apps.identity.v1.Reputation'),
|
|
71
71
|
field('stake', 8, 'int64'),
|
|
72
72
|
field('domains', 9, 'string', true),
|
|
@@ -97,7 +97,7 @@ const marketStateMessage = {
|
|
|
97
97
|
typeName: 'ottochain.apps.markets.v1.Market',
|
|
98
98
|
fields: [
|
|
99
99
|
field('id', 1, 'string'),
|
|
100
|
-
field('market_type', 2, 'ottochain.apps.markets.v1.
|
|
100
|
+
field('market_type', 2, 'ottochain.apps.markets.v1.Type'),
|
|
101
101
|
field('creator', 3, 'string'),
|
|
102
102
|
field('title', 4, 'string'),
|
|
103
103
|
field('terms', 5, 'google.protobuf.Struct'),
|
|
@@ -107,7 +107,7 @@ const marketStateMessage = {
|
|
|
107
107
|
field('oracles', 9, 'string', true),
|
|
108
108
|
field('quorum', 10, 'int32'),
|
|
109
109
|
field('resolutions', 11, 'ottochain.apps.markets.v1.Resolution', true),
|
|
110
|
-
field('status', 12, 'ottochain.apps.markets.v1.
|
|
110
|
+
field('status', 12, 'ottochain.apps.markets.v1.State'),
|
|
111
111
|
field('created_at', 13, 'google.protobuf.Timestamp'),
|
|
112
112
|
field('updated_at', 14, 'google.protobuf.Timestamp'),
|
|
113
113
|
],
|
|
@@ -145,6 +145,12 @@ function toWireDefinition(def) {
|
|
|
145
145
|
})),
|
|
146
146
|
// Strip FiberAppMetadata — the chain's `metadata` is `Option[JsonLogicValue]`.
|
|
147
147
|
metadata: null,
|
|
148
|
+
// Carry the fiber constitution through verbatim from the shared projector: PRESENT for
|
|
149
|
+
// `Constrained` (a bare object of set dials) and `Immutable` (the bare string
|
|
150
|
+
// `"Immutable"`), ABSENT for `Unconstrained`. The `policy` key is only set here when
|
|
151
|
+
// `toProtoDefinition` emitted one, so an unconstrained def keeps NO `policy` key
|
|
152
|
+
// (omit-on-unconstrained wire parity).
|
|
153
|
+
...(proto.policy !== undefined ? { policy: proto.policy } : {}),
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
// ─── Builder ──────────────────────────────────────────────────────────────────
|
|
@@ -165,7 +171,7 @@ export function buildGenesisManifest() {
|
|
|
165
171
|
semver: '1.0.0',
|
|
166
172
|
strict: false,
|
|
167
173
|
metadata: {},
|
|
168
|
-
|
|
174
|
+
machineShape: { stateMessage: identityStateMessage, commands: {} },
|
|
169
175
|
definition: toWireDefinition(identityUniversalDef),
|
|
170
176
|
},
|
|
171
177
|
{
|
|
@@ -173,7 +179,7 @@ export function buildGenesisManifest() {
|
|
|
173
179
|
semver: '1.0.0',
|
|
174
180
|
strict: false,
|
|
175
181
|
metadata: {},
|
|
176
|
-
|
|
182
|
+
machineShape: { stateMessage: governanceStateMessage, commands: {} },
|
|
177
183
|
definition: toWireDefinition(govUniversalDef),
|
|
178
184
|
},
|
|
179
185
|
{
|
|
@@ -181,7 +187,7 @@ export function buildGenesisManifest() {
|
|
|
181
187
|
semver: '1.0.0',
|
|
182
188
|
strict: false,
|
|
183
189
|
metadata: {},
|
|
184
|
-
|
|
190
|
+
machineShape: { stateMessage: marketStateMessage, commands: {} },
|
|
185
191
|
definition: toWireDefinition(marketUniversalDef),
|
|
186
192
|
},
|
|
187
193
|
];
|
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
// Re-export generated protobuf types (for binary encoding)
|
|
9
9
|
export * as proto from '../generated/index.js';
|
|
10
10
|
// Runtime message type validation
|
|
11
|
-
export { OTTOCHAIN_MESSAGE_TYPES } from './types.js';
|
|
11
|
+
export { OTTOCHAIN_MESSAGE_TYPES, TOKEN_BEHAVIOR_BITS } from './types.js';
|
|
12
12
|
export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
|
|
13
13
|
export { MetagraphClient } from './metagraph-client.js';
|
|
14
14
|
// Transaction helpers (state machine payloads, signing)
|
|
15
|
-
export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
|
|
15
|
+
export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, createAuthorizeComposePayload, } from './transaction.js';
|
|
16
16
|
// Data utilities
|
|
17
|
-
export { normalizeCreateStateMachine, normalizeTransitionStateMachine, normalizeArchiveStateMachine, normalizeMessage, } from './normalize.js';
|
|
18
17
|
export { dropNulls } from './drop-nulls.js';
|
|
19
18
|
// Genesis manifest exporter (std-app pre-registration content)
|
|
20
19
|
export { buildGenesisManifest, GENESIS_MANIFEST_VERSION } from './genesis-manifest.js';
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Client for interacting with ottochain ML0 custom routes (/v1 prefix)
|
|
5
5
|
* and framework snapshot endpoints.
|
|
6
6
|
*
|
|
7
|
-
* @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/
|
|
7
|
+
* @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/ML0Routes.scala
|
|
8
8
|
* @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
@@ -28,7 +28,7 @@ import { extractOnChainState } from './snapshot.js';
|
|
|
28
28
|
* const onChain = await client.getOnChain();
|
|
29
29
|
*
|
|
30
30
|
* // Get all active state machines
|
|
31
|
-
* const machines = await client.getStateMachines('
|
|
31
|
+
* const machines = await client.getStateMachines('ACTIVE');
|
|
32
32
|
*
|
|
33
33
|
* // Get event receipts for a fiber
|
|
34
34
|
* const events = await client.getStateMachineEvents(fiberId);
|
|
@@ -87,18 +87,18 @@ export class MetagraphClient {
|
|
|
87
87
|
return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/events`);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* Get all
|
|
90
|
+
* Get all scripts, optionally filtered by status.
|
|
91
91
|
*/
|
|
92
92
|
async getScripts(status) {
|
|
93
93
|
const query = status ? `?status=${status}` : '';
|
|
94
|
-
return this.ml0.get(`/data-application/v1/
|
|
94
|
+
return this.ml0.get(`/data-application/v1/scripts${query}`);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* Get a single script
|
|
97
|
+
* Get a single script by fiber ID.
|
|
98
98
|
*/
|
|
99
99
|
async getScript(scriptId) {
|
|
100
100
|
try {
|
|
101
|
-
return await this.ml0.get(`/data-application/v1/
|
|
101
|
+
return await this.ml0.get(`/data-application/v1/scripts/${scriptId}`);
|
|
102
102
|
}
|
|
103
103
|
catch (error) {
|
|
104
104
|
if (error instanceof NetworkError && error.statusCode === 404) {
|
|
@@ -108,10 +108,67 @@ export class MetagraphClient {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Get
|
|
111
|
+
* Get script invocations from the current ordinal's logs.
|
|
112
112
|
*/
|
|
113
113
|
async getScriptInvocations(scriptId) {
|
|
114
|
-
return this.ml0.get(`/data-application/v1/
|
|
114
|
+
return this.ml0.get(`/data-application/v1/scripts/${scriptId}/invocations`);
|
|
115
|
+
}
|
|
116
|
+
// -------------------------------------------------------------------------
|
|
117
|
+
// Registry, audit, state-proofs, fee estimates (ML0 /data-application/v1/*)
|
|
118
|
+
// -------------------------------------------------------------------------
|
|
119
|
+
/** Get the metagraph version string. */
|
|
120
|
+
async getVersion() {
|
|
121
|
+
return this.ml0.get('/data-application/v1/version');
|
|
122
|
+
}
|
|
123
|
+
/** Get the full registry namespace, keyed by full registry name `labels.tld`. */
|
|
124
|
+
async getRegistry() {
|
|
125
|
+
return this.ml0.get('/data-application/v1/registry');
|
|
126
|
+
}
|
|
127
|
+
/** Resolve a single registry entry by full name (`labels.tld`), or null if unregistered. */
|
|
128
|
+
async getRegistryEntry(name) {
|
|
129
|
+
try {
|
|
130
|
+
return await this.ml0.get(`/data-application/v1/registry/${encodeURIComponent(name)}`);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error instanceof NetworkError && error.statusCode === 404)
|
|
134
|
+
return null;
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Reverse-resolve a fiber UUID to its canonical registered name (#29), or null. */
|
|
139
|
+
async getReverseName(fiberId) {
|
|
140
|
+
try {
|
|
141
|
+
return await this.ml0.get(`/data-application/v1/registry/reverse/${fiberId}`);
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
if (error instanceof NetworkError && error.statusCode === 404)
|
|
145
|
+
return null;
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** Get the rendered audit-trail lines for a state-machine fiber. */
|
|
150
|
+
async getStateMachineAudit(fiberId) {
|
|
151
|
+
return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/audit`);
|
|
152
|
+
}
|
|
153
|
+
/** Light-client state proof for a field of a state-machine fiber, against the committed root. */
|
|
154
|
+
async getStateMachineStateProof(fiberId, field) {
|
|
155
|
+
return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/state-proof?field=${encodeURIComponent(field)}`);
|
|
156
|
+
}
|
|
157
|
+
/** Light-client state proof for a field of a script fiber. */
|
|
158
|
+
async getScriptStateProof(fiberId, field) {
|
|
159
|
+
return this.ml0.get(`/data-application/v1/scripts/${fiberId}/state-proof?field=${encodeURIComponent(field)}`);
|
|
160
|
+
}
|
|
161
|
+
/** Light-client state proof for a field of an asset instance. */
|
|
162
|
+
async getAssetStateProof(assetId, field) {
|
|
163
|
+
return this.ml0.get(`/data-application/v1/assets/${assetId}/state-proof?field=${encodeURIComponent(field)}`);
|
|
164
|
+
}
|
|
165
|
+
/** Estimate the fee/gas for a transition event on a state-machine fiber. */
|
|
166
|
+
async estimateTransitionFee(fiberId, eventName) {
|
|
167
|
+
return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/estimate-fee?event=${encodeURIComponent(eventName)}`);
|
|
168
|
+
}
|
|
169
|
+
/** Estimate the fee/gas for invoking a script fiber. */
|
|
170
|
+
async estimateScriptFee(fiberId) {
|
|
171
|
+
return this.ml0.get(`/data-application/v1/scripts/${fiberId}/estimate-fee`);
|
|
115
172
|
}
|
|
116
173
|
// -------------------------------------------------------------------------
|
|
117
174
|
// Framework snapshot endpoints (ML0 /snapshots/*)
|
|
@@ -187,7 +244,9 @@ export class MetagraphClient {
|
|
|
187
244
|
try {
|
|
188
245
|
onError(cbErr instanceof Error ? cbErr : new Error(String(cbErr)));
|
|
189
246
|
}
|
|
190
|
-
catch {
|
|
247
|
+
catch {
|
|
248
|
+
/* ignore */
|
|
249
|
+
}
|
|
191
250
|
}
|
|
192
251
|
};
|
|
193
252
|
const poll = async () => {
|
|
@@ -204,7 +263,9 @@ export class MetagraphClient {
|
|
|
204
263
|
try {
|
|
205
264
|
onError(err instanceof Error ? err : new Error(String(err)));
|
|
206
265
|
}
|
|
207
|
-
catch {
|
|
266
|
+
catch {
|
|
267
|
+
/* ignore */
|
|
268
|
+
}
|
|
208
269
|
if (active)
|
|
209
270
|
setTimeout(poll, intervalMs);
|
|
210
271
|
return;
|
|
@@ -237,7 +298,9 @@ export class MetagraphClient {
|
|
|
237
298
|
// callers can unsubscribe before the first poll runs, and each
|
|
238
299
|
// jest.runOnlyPendingTimersAsync() advances exactly one poll cycle.
|
|
239
300
|
setTimeout(poll, 0);
|
|
240
|
-
return () => {
|
|
301
|
+
return () => {
|
|
302
|
+
active = false;
|
|
303
|
+
};
|
|
241
304
|
}
|
|
242
305
|
/**
|
|
243
306
|
* Wait for a fiber to reach a specific state, with an optional timeout.
|
|
@@ -335,14 +398,16 @@ export class MetagraphClient {
|
|
|
335
398
|
let settled = false;
|
|
336
399
|
let pending = this.dl1Clients.length;
|
|
337
400
|
for (const client of this.dl1Clients) {
|
|
338
|
-
client.post('/data', request).then((result) => {
|
|
339
|
-
settled
|
|
340
|
-
|
|
341
|
-
|
|
401
|
+
client.post('/data', request).then((result) => {
|
|
402
|
+
if (!settled) {
|
|
403
|
+
settled = true;
|
|
404
|
+
resolve(result);
|
|
405
|
+
}
|
|
406
|
+
}, (err) => {
|
|
342
407
|
errors.push(err instanceof Error ? err : new Error(String(err)));
|
|
343
408
|
pending--;
|
|
344
409
|
if (pending === 0 && !settled) {
|
|
345
|
-
reject(new Error('All DL1 nodes failed: ' + errors.map(e => e.message).join('; ')));
|
|
410
|
+
reject(new Error('All DL1 nodes failed: ' + errors.map((e) => e.message).join('; ')));
|
|
346
411
|
}
|
|
347
412
|
});
|
|
348
413
|
}
|
|
@@ -73,7 +73,7 @@ export function getLogsForFiber(onChain, fiberId) {
|
|
|
73
73
|
/**
|
|
74
74
|
* Get EventReceipt log entries for a specific fiber.
|
|
75
75
|
*
|
|
76
|
-
* EventReceipts are distinguished from
|
|
76
|
+
* EventReceipts are distinguished from ScriptInvocations by the presence
|
|
77
77
|
* of the `eventName` field.
|
|
78
78
|
*
|
|
79
79
|
* @param onChain - Decoded on-chain state
|
|
@@ -81,20 +81,18 @@ export function getLogsForFiber(onChain, fiberId) {
|
|
|
81
81
|
* @returns Array of EventReceipt entries
|
|
82
82
|
*/
|
|
83
83
|
export function getEventReceipts(onChain, fiberId) {
|
|
84
|
-
return getLogsForFiber(onChain, fiberId)
|
|
85
|
-
.filter((entry) => 'eventName' in entry && 'success' in entry);
|
|
84
|
+
return getLogsForFiber(onChain, fiberId).filter((entry) => 'eventName' in entry && 'success' in entry);
|
|
86
85
|
}
|
|
87
86
|
/**
|
|
88
|
-
* Get
|
|
87
|
+
* Get ScriptInvocation log entries for a specific fiber.
|
|
89
88
|
*
|
|
90
|
-
*
|
|
89
|
+
* ScriptInvocations are distinguished from EventReceipts by the presence
|
|
91
90
|
* of the `method` field.
|
|
92
91
|
*
|
|
93
92
|
* @param onChain - Decoded on-chain state
|
|
94
93
|
* @param fiberId - Fiber UUID to filter by
|
|
95
|
-
* @returns Array of
|
|
94
|
+
* @returns Array of ScriptInvocation entries
|
|
96
95
|
*/
|
|
97
96
|
export function getScriptInvocations(onChain, fiberId) {
|
|
98
|
-
return getLogsForFiber(onChain, fiberId)
|
|
99
|
-
.filter((entry) => 'method' in entry && 'result' in entry);
|
|
97
|
+
return getLogsForFiber(onChain, fiberId).filter((entry) => 'method' in entry && 'result' in entry);
|
|
100
98
|
}
|
|
@@ -4,10 +4,18 @@
|
|
|
4
4
|
* These helpers create properly formatted payloads for the bridge's
|
|
5
5
|
* self-signed mode, where clients sign their own transactions.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { getPublicKeyId } from '@constellation-network/metagraph-sdk';
|
|
8
|
+
import { signDataUpdate } from '../signing.js';
|
|
8
9
|
/**
|
|
9
10
|
* Create a new state machine fiber payload.
|
|
10
11
|
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* `params.definition` is signed VERBATIM. Pass the output of `toProtoDefinition(def)` (the
|
|
14
|
+
* allowlisted wire shape) — NOT a raw `FiberAppDefinition`: extra authoring fields
|
|
15
|
+
* (`createSchema` / `stateSchema` / `eventSchemas` / per-transition `emits`) would be signed
|
|
16
|
+
* but re-encoded away by the chain, diverging the canonical → opaque `InvalidSignature`.
|
|
17
|
+
* See `tests/ottochain/signing-parity.test.ts`.
|
|
18
|
+
*
|
|
11
19
|
* @param params - State machine creation parameters
|
|
12
20
|
* @returns A CreateStateMachine message ready for signing
|
|
13
21
|
*
|
|
@@ -94,7 +102,7 @@ export function createArchivePayload(params) {
|
|
|
94
102
|
* },
|
|
95
103
|
* },
|
|
96
104
|
* initialState: { value: 0 },
|
|
97
|
-
* accessControl: {
|
|
105
|
+
* accessControl: { Public: {} },
|
|
98
106
|
* });
|
|
99
107
|
* const signed = await signTransaction(script, privateKey);
|
|
100
108
|
* ```
|
|
@@ -105,7 +113,7 @@ export function createScriptPayload(params) {
|
|
|
105
113
|
fiberId: params.fiberId,
|
|
106
114
|
scriptProgram: params.scriptProgram,
|
|
107
115
|
initialState: params.initialState ?? null,
|
|
108
|
-
accessControl: params.accessControl ?? {
|
|
116
|
+
accessControl: params.accessControl ?? { Public: {} },
|
|
109
117
|
},
|
|
110
118
|
};
|
|
111
119
|
}
|
|
@@ -125,12 +133,49 @@ export function createInvokeScriptPayload(params) {
|
|
|
125
133
|
},
|
|
126
134
|
};
|
|
127
135
|
}
|
|
136
|
+
// ============================================================================
|
|
137
|
+
// Asset Operations (asset-model.md §7)
|
|
138
|
+
// ============================================================================
|
|
139
|
+
//
|
|
140
|
+
// Thin typed wrappers: the chain message types ({@link CreateAssetPolicy}, etc.) already model
|
|
141
|
+
// every field (required vs `Option`), so these builders just apply the `{ MessageName: ... }`
|
|
142
|
+
// envelope, for API parity with the state-machine/script `create*Payload` helpers. Sign the result
|
|
143
|
+
// with {@link signTransaction} (the canonical `JCS(dropNulls)` path drops any omitted optionals).
|
|
144
|
+
/** Wrap a {@link CreateAssetPolicy} (publish an asset-policy package version). */
|
|
145
|
+
export function createAssetPolicyPayload(params) {
|
|
146
|
+
return { CreateAssetPolicy: params };
|
|
147
|
+
}
|
|
148
|
+
/** Wrap a {@link MintAsset} (mint a new asset instance against a resolved policy version). */
|
|
149
|
+
export function createMintAssetPayload(params) {
|
|
150
|
+
return { MintAsset: params };
|
|
151
|
+
}
|
|
152
|
+
/** Wrap an {@link ApplyMorphism} (apply a typed morphism to an asset instance). */
|
|
153
|
+
export function createApplyMorphismPayload(params) {
|
|
154
|
+
return { ApplyMorphism: params };
|
|
155
|
+
}
|
|
156
|
+
/** Wrap an {@link AuthorizeCompose} (commit half of the symmetric-compose handshake). */
|
|
157
|
+
export function createAuthorizeComposePayload(params) {
|
|
158
|
+
return { AuthorizeCompose: params };
|
|
159
|
+
}
|
|
160
|
+
/** Wrap a {@link PublishMachineVersion} (create-or-append a STATE-MACHINE registry version). */
|
|
161
|
+
export function createPublishMachineVersionPayload(params) {
|
|
162
|
+
return { PublishMachineVersion: params };
|
|
163
|
+
}
|
|
164
|
+
/** Wrap an {@link UpgradeFiber} (re-pin a fiber to another registered version of the SAME package). */
|
|
165
|
+
export function createUpgradeFiberPayload(params) {
|
|
166
|
+
return { UpgradeFiber: params };
|
|
167
|
+
}
|
|
128
168
|
/**
|
|
129
169
|
* Sign a transaction payload for self-signed mode.
|
|
130
170
|
*
|
|
131
171
|
* This creates a Signed<T> object with the exact format expected by the bridge's
|
|
132
172
|
* `/agent/transition` endpoint when using self-signed mode.
|
|
133
173
|
*
|
|
174
|
+
* The signature is computed over the null-dropped canonical bytes (null
|
|
175
|
+
* object fields removed recursively, array nulls preserved, then RFC 8785),
|
|
176
|
+
* matching metakit's content-hash rule. Explicit-null and absent optional
|
|
177
|
+
* fields therefore produce identical signatures.
|
|
178
|
+
*
|
|
134
179
|
* @param message - The message to sign (e.g., from createTransitionPayload)
|
|
135
180
|
* @param privateKey - The private key in hex format (64 characters)
|
|
136
181
|
* @returns A signed object ready for submission to the bridge
|
|
@@ -199,6 +244,9 @@ export function createDataTransactionRequest(signed) {
|
|
|
199
244
|
* Use this for multi-signature scenarios where multiple parties
|
|
200
245
|
* need to sign the same transaction.
|
|
201
246
|
*
|
|
247
|
+
* The new signature is computed over the null-dropped canonical bytes,
|
|
248
|
+
* matching metakit's content-hash rule (see {@link signTransaction}).
|
|
249
|
+
*
|
|
202
250
|
* @param signed - The already-signed transaction
|
|
203
251
|
* @param privateKey - Additional signer's private key
|
|
204
252
|
* @returns Transaction with additional signature
|
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
* @see modules/models/src/main/scala/xyz/kd5ujc/schema/
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*/
|
|
10
|
+
/** Bit weights for {@link TokenBehavior} (T=16, S=8, C=4, E=2, G=1). */
|
|
11
|
+
export const TOKEN_BEHAVIOR_BITS = {
|
|
12
|
+
transferable: 16,
|
|
13
|
+
splittable: 8,
|
|
14
|
+
combinable: 4,
|
|
15
|
+
expirable: 2,
|
|
16
|
+
governable: 1,
|
|
17
|
+
};
|
|
10
18
|
/**
|
|
11
19
|
* Names of all valid OttochainMessage types.
|
|
12
20
|
* Use this for runtime validation (e.g., in API routes).
|
|
@@ -18,7 +26,13 @@ export const OTTOCHAIN_MESSAGE_TYPES = [
|
|
|
18
26
|
'UpgradeFiber',
|
|
19
27
|
'CreateScript',
|
|
20
28
|
'InvokeScript',
|
|
21
|
-
'
|
|
29
|
+
'UpgradeScript',
|
|
30
|
+
'PublishMachineVersion',
|
|
31
|
+
'PublishScriptVersion',
|
|
22
32
|
'SetVersionStatus',
|
|
23
33
|
'RegisterAlias',
|
|
34
|
+
'CreateAssetPolicy',
|
|
35
|
+
'MintAsset',
|
|
36
|
+
'ApplyMorphism',
|
|
37
|
+
'AuthorizeCompose',
|
|
24
38
|
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Privacy: shield any fiber app into a zk-jlvm-shielded private-state pool.
|
|
3
|
+
* See docs/design/zk-private-contract-state-rfc.md.
|
|
4
|
+
*/
|
|
5
|
+
export { shieldApp, SHIELDED_POOL_STATE } from './shield-app.js';
|
|
6
|
+
export { sealedBidAccountDef, shieldedSealedBidDef, vickreyAuctionDef } from './sealed-bid.js';
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sealed-bid (Vickrey) auction — the worked example for the privacy stack.
|
|
3
|
+
*
|
|
4
|
+
* Two pieces (RFC §4):
|
|
5
|
+
* 1. `sealedBidAccountDef` — the PRIVATE per-bidder bid. `shieldApp` turns it into a shielded
|
|
6
|
+
* pool (`shieldedSealedBidDef`): a bidder commits a bid note and proves it well-formed with a
|
|
7
|
+
* zk-jlvm-shielded Groth16 proof, so the amount stays sealed *until the deadline*. This is the
|
|
8
|
+
* mechanical per-instance / single-owner case.
|
|
9
|
+
* 2. `vickreyAuctionDef` — the PUBLIC settlement (reveal-then-tally). After the deadline bidders
|
|
10
|
+
* open their notes; the combine computes winner = argmax and clearingPrice = second-highest
|
|
11
|
+
* (the Vickrey price). This is the one shared-state step, kept simple for v1; a zk settlement
|
|
12
|
+
* proof that seals losers' amounts forever is the deferred upgrade (RFC §10).
|
|
13
|
+
*/
|
|
14
|
+
import { defineFiberApp } from '../schema/fiber-app.js';
|
|
15
|
+
import { shieldApp } from './shield-app.js';
|
|
16
|
+
// ── 1. The private bid (base app, shielded by shieldApp) ──────────────────────
|
|
17
|
+
/** The per-bidder PRIVATE state: a bid note `{ amount, bidder, nonce }`. */
|
|
18
|
+
export const sealedBidAccountDef = defineFiberApp({
|
|
19
|
+
metadata: {
|
|
20
|
+
name: 'SealedBidAccount',
|
|
21
|
+
app: 'markets',
|
|
22
|
+
type: 'sealed-bid-account',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
description: "A single bidder's sealed bid (private amount). Shielded via shieldApp.",
|
|
25
|
+
},
|
|
26
|
+
stateSchema: {
|
|
27
|
+
properties: {
|
|
28
|
+
amount: { type: 'number', description: 'the (private) bid amount' },
|
|
29
|
+
bidder: { type: 'address' },
|
|
30
|
+
nonce: { type: 'number', description: 'per-note randomness; keeps the commitment hiding' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
eventSchemas: {
|
|
34
|
+
place_bid: {
|
|
35
|
+
description: 'Set the sealed bid amount',
|
|
36
|
+
required: ['amount'],
|
|
37
|
+
properties: { amount: { type: 'number', minimum: 1 } },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
states: {
|
|
41
|
+
OPEN: { id: 'OPEN', isFinal: false, metadata: { label: 'Open', description: 'No bid yet', category: 'initial' } },
|
|
42
|
+
BID: { id: 'BID', isFinal: false, metadata: { label: 'Bid', description: 'Bid committed', category: 'active' } },
|
|
43
|
+
},
|
|
44
|
+
initialState: 'OPEN',
|
|
45
|
+
transitions: [
|
|
46
|
+
{
|
|
47
|
+
// This effect is what the zk-jlvm-shielded circuit runs in-zkVM; `exprHash` pins it.
|
|
48
|
+
from: 'OPEN',
|
|
49
|
+
to: 'BID',
|
|
50
|
+
eventName: 'place_bid',
|
|
51
|
+
guard: { '>': [{ var: 'event.amount' }, 0] },
|
|
52
|
+
effect: { merge: [{ var: 'state' }, { amount: { var: 'event.amount' } }] },
|
|
53
|
+
dependencies: [],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* The shielded sealed-bid pool. `vkey`/`exprHash` come from the built zk-jlvm-shielded circuit
|
|
59
|
+
* (these are placeholders until the circuit's program vkey + the keccak of the `place_bid` effect
|
|
60
|
+
* are wired in by the genesis/build step).
|
|
61
|
+
*/
|
|
62
|
+
export function shieldedSealedBidDef(opts) {
|
|
63
|
+
return shieldApp(sealedBidAccountDef, opts);
|
|
64
|
+
}
|
|
65
|
+
// ── 2. The public Vickrey settlement ──────────────────────────────────────────
|
|
66
|
+
/**
|
|
67
|
+
* Public reveal-then-tally settlement. `reveal` appends an opened bid (in a full build the opening
|
|
68
|
+
* is checked against the recorded commitment in the shielded pool); `settle` computes the winner
|
|
69
|
+
* and the Vickrey (second-price) clearing price over the revealed bids in one reduce.
|
|
70
|
+
*/
|
|
71
|
+
export const vickreyAuctionDef = defineFiberApp({
|
|
72
|
+
metadata: {
|
|
73
|
+
name: 'VickreyAuction',
|
|
74
|
+
app: 'markets',
|
|
75
|
+
type: 'vickrey-auction',
|
|
76
|
+
version: '1.0.0',
|
|
77
|
+
description: 'Sealed-bid second-price auction: public reveal-then-tally over shielded bids.',
|
|
78
|
+
crossReferences: { bidPool: 'the ShieldedSealedBidAccount pool holding the sealed bids' },
|
|
79
|
+
},
|
|
80
|
+
createSchema: {
|
|
81
|
+
required: ['seller', 'deadline'],
|
|
82
|
+
properties: {
|
|
83
|
+
seller: { type: 'address', immutable: true },
|
|
84
|
+
deadline: { type: 'timestamp', immutable: true },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
stateSchema: {
|
|
88
|
+
properties: {
|
|
89
|
+
seller: { type: 'address', immutable: true },
|
|
90
|
+
deadline: { type: 'timestamp', immutable: true },
|
|
91
|
+
status: { type: 'string', computed: true },
|
|
92
|
+
revealed: { type: 'array', computed: true, description: 'opened bids [{bidder, amount}]' },
|
|
93
|
+
winner: { type: 'address', computed: true },
|
|
94
|
+
clearingPrice: { type: 'number', computed: true, description: 'second-highest bid (Vickrey)' },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
eventSchemas: {
|
|
98
|
+
reveal: {
|
|
99
|
+
description: 'Open a sealed bid after the deadline',
|
|
100
|
+
required: ['bidder', 'amount'],
|
|
101
|
+
properties: { bidder: { type: 'address' }, amount: { type: 'number', minimum: 1 } },
|
|
102
|
+
},
|
|
103
|
+
settle: { description: 'Tally the revealed bids (winner + second price)' },
|
|
104
|
+
},
|
|
105
|
+
states: {
|
|
106
|
+
OPEN: {
|
|
107
|
+
id: 'OPEN',
|
|
108
|
+
isFinal: false,
|
|
109
|
+
metadata: { label: 'Open', description: 'Bidding (sealed)', category: 'initial' },
|
|
110
|
+
},
|
|
111
|
+
REVEAL: {
|
|
112
|
+
id: 'REVEAL',
|
|
113
|
+
isFinal: false,
|
|
114
|
+
metadata: { label: 'Reveal', description: 'Opening bids', category: 'active' },
|
|
115
|
+
},
|
|
116
|
+
SETTLED: {
|
|
117
|
+
id: 'SETTLED',
|
|
118
|
+
isFinal: true,
|
|
119
|
+
metadata: { label: 'Settled', description: 'Winner + price set', category: 'terminal' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
initialState: 'OPEN',
|
|
123
|
+
transitions: [
|
|
124
|
+
{
|
|
125
|
+
from: 'OPEN',
|
|
126
|
+
to: 'REVEAL',
|
|
127
|
+
eventName: 'reveal',
|
|
128
|
+
guard: { '>=': [{ var: '$timestamp' }, { var: 'state.deadline' }] },
|
|
129
|
+
effect: {
|
|
130
|
+
merge: [
|
|
131
|
+
{ var: 'state' },
|
|
132
|
+
{
|
|
133
|
+
status: 'REVEAL',
|
|
134
|
+
revealed: {
|
|
135
|
+
cat: [{ var: 'state.revealed' }, [{ bidder: { var: 'event.bidder' }, amount: { var: 'event.amount' } }]],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
dependencies: [],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
from: 'REVEAL',
|
|
144
|
+
to: 'REVEAL',
|
|
145
|
+
eventName: 'reveal',
|
|
146
|
+
guard: { '>=': [{ var: '$timestamp' }, { var: 'state.deadline' }] },
|
|
147
|
+
effect: {
|
|
148
|
+
merge: [
|
|
149
|
+
{ var: 'state' },
|
|
150
|
+
{
|
|
151
|
+
revealed: {
|
|
152
|
+
cat: [{ var: 'state.revealed' }, [{ bidder: { var: 'event.bidder' }, amount: { var: 'event.amount' } }]],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
dependencies: [],
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
// Vickrey tally: fold the revealed bids tracking (max, second, winner).
|
|
161
|
+
from: 'REVEAL',
|
|
162
|
+
to: 'SETTLED',
|
|
163
|
+
eventName: 'settle',
|
|
164
|
+
guard: { '>': [{ reduce: [{ var: 'state.revealed' }, { '+': [{ var: 'accumulator' }, 1] }, 0] }, 0] },
|
|
165
|
+
effect: {
|
|
166
|
+
merge: [
|
|
167
|
+
{ var: 'state' },
|
|
168
|
+
{
|
|
169
|
+
status: 'SETTLED',
|
|
170
|
+
settledAt: { var: '$timestamp' },
|
|
171
|
+
winner: {
|
|
172
|
+
var: ['tally.winner', null],
|
|
173
|
+
},
|
|
174
|
+
clearingPrice: { var: ['tally.second', 0] },
|
|
175
|
+
// compute the tally once and expose it for the two fields above
|
|
176
|
+
tally: {
|
|
177
|
+
reduce: [
|
|
178
|
+
{ var: 'state.revealed' },
|
|
179
|
+
{
|
|
180
|
+
if: [
|
|
181
|
+
{ '>': [{ var: 'current.amount' }, { var: 'accumulator.max' }] },
|
|
182
|
+
{
|
|
183
|
+
max: { var: 'current.amount' },
|
|
184
|
+
second: { var: 'accumulator.max' },
|
|
185
|
+
winner: { var: 'current.bidder' },
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
if: [
|
|
189
|
+
{ '>': [{ var: 'current.amount' }, { var: 'accumulator.second' }] },
|
|
190
|
+
{
|
|
191
|
+
max: { var: 'accumulator.max' },
|
|
192
|
+
second: { var: 'current.amount' },
|
|
193
|
+
winner: { var: 'accumulator.winner' },
|
|
194
|
+
},
|
|
195
|
+
{ var: 'accumulator' },
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
{ max: 0, second: 0, winner: null },
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
dependencies: [],
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
});
|