Skip to content

Commit 82dd8fd

Browse files
committed
Add FlowChain local wallet envelopes
1 parent 69329be commit 82dd8fd

27 files changed

Lines changed: 2534 additions & 25 deletions

crypto/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules/
22
coverage/
33
.nyc_output/
4+
.wallet/
5+
*.vault.local.json
6+
*.wallet.local.json

crypto/FLOWCHAIN_LOCAL_ALPHA_OBJECTS.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pre-hashed before entering the typed object.
6161
| MemoryCell | `memoryCellId` | `memoryCellV0` | `memoryCellId` | `memoryCellId` |
6262
| Challenge | `challengeId` | `challengeV0` | `challengeId` | `challengeId` |
6363
| FinalityReceipt | `finalityReceiptId` | `finalityReceiptV0` | `finalityReceiptId` | `finalityReceiptId` |
64+
| BridgeDeposit | `depositId` | `bridgeDepositV0` | `bridgeDepositId` | `bridgeDepositId` |
65+
| BridgeCredit | `creditId` | `bridgeCreditV0` | `bridgeCreditId` | `bridgeCreditId` |
66+
| BridgeWithdrawal | `withdrawalId` | `bridgeWithdrawalV0` | `bridgeWithdrawalId` | `bridgeWithdrawalId` |
67+
| LocalAccountBalance | `balanceId` | `localAccountBalanceV0` | `localAccountBalanceId` | `localAccountBalanceId` |
6468
| HardwareSignalEnvelope | `hardwareSignalEnvelopeId` | `hardwareSignalEnvelopeV0` | `hardwareSignalEnvelopeId` | `hardwareSignalEnvelopeId` |
6569
| Control-plane provenance response | `provenanceResponseId` | `controlPlaneProvenanceResponseV0` | `controlPlaneProvenanceResponseId` | `controlPlaneProvenanceResponseId` |
6670

@@ -77,6 +81,20 @@ domain separator, signer ID, signer key ID, signer role, sequence, validity
7781
window, and nonce. The signing digest is the local EIP-712 style digest over
7882
that struct hash and the object domain separator.
7983

84+
`LocalTransactionEnvelope` uses `localTransactionEnvelopeV0` and
85+
`localTransactionEnvelopeHash`. It signs the chain id, nonce, signer ID, signer
86+
key ID, signer role, canonical payload hash, validity window, and transaction
87+
domain separator. The JSON payload preserves `payload.tx` so the existing
88+
devnet transaction model can unwrap and submit the same transaction object after
89+
envelope validation.
90+
91+
`BridgeDeposit` intentionally keeps the existing
92+
`flowmemory.bridge_deposit.v0` schema used by the bridge observer. The crypto
93+
ID is a typed hash over the Base source chain id, source contract, tx hash,
94+
log index, token, amount, sender, FlowChain recipient, nonce, and metadata
95+
hash. `BridgeCredit` and `BridgeWithdrawal` are local FlowChain objects that
96+
record no-production bridge accounting for private/local testing only.
97+
8098
Runnable definitions live in `crypto/src/objects.js`.
8199

82100
Canonical object fixtures live in:
@@ -103,8 +121,14 @@ schemas/flowmemory/verifier-module.schema.json
103121
schemas/flowmemory/verifier-report.schema.json
104122
schemas/flowmemory/challenge.schema.json
105123
schemas/flowmemory/finality-receipt.schema.json
124+
schemas/flowmemory/bridge-deposit.schema.json
125+
schemas/flowmemory/bridge-credit.schema.json
126+
schemas/flowmemory/bridge-withdrawal.schema.json
127+
schemas/flowmemory/local-account-balance.schema.json
106128
schemas/flowmemory/hardware-signal-envelope.schema.json
107129
schemas/flowmemory/local-signature-envelope.schema.json
130+
schemas/flowmemory/local-transaction-envelope.schema.json
131+
schemas/flowmemory/local-wallet-public-metadata.schema.json
108132
schemas/flowmemory/control-plane-provenance-response.schema.json
109133
```
110134

@@ -136,6 +160,41 @@ signer, bad signature, zero hash, malformed ID, malformed dependency, bad
136160
parent/root, and wrong object type. Every Local Alpha object envelope also has a
137161
valid fixture and a bad-signature invalid fixture.
138162

163+
Local transaction envelope validation additionally requires:
164+
165+
- `domain` and `domainSeparator` match `flowchain.local.v0.transaction-envelope`.
166+
- the context-supplied chain id matches the envelope chain id.
167+
- `payloadHash` recomputes from canonical JSON.
168+
- `signerId` and `signerKeyId` derive from the public key and signer role.
169+
- the caller supplies replay context and rejects repeated signer/domain/nonce tuples.
170+
- object documents embedded under `payload.object` pass the same object ID and root checks.
171+
- the secp256k1 signature verifies against the transaction signing digest.
172+
173+
The transaction vectors cover wrong chain id, wrong domain, wrong signer,
174+
replayed nonce, malformed roots, malformed bridge deposit, and changed object
175+
type.
176+
177+
## Local Wallet Boundary
178+
179+
`crypto/src/wallet.js` provides an encrypted local vault for no-value test keys.
180+
It supports create, unlock, list public accounts, sign transaction, verify
181+
transaction, public metadata import/export, and rotate/create additional
182+
accounts. The vault uses scrypt plus AES-256-GCM and stores private keys only in
183+
the encrypted blob. The export shape is
184+
`flowchain.local_wallet_public_metadata.v0`, which contains public account IDs,
185+
signer IDs, key IDs, roles, public keys, labels, and nonces only.
186+
187+
The CLI entry point is `crypto/src/wallet-cli.js` and is exposed through:
188+
189+
```powershell
190+
npm run wallet:create --prefix crypto
191+
npm run wallet:sign --prefix crypto
192+
npm run wallet:verify --prefix crypto
193+
```
194+
195+
Set `FLOWCHAIN_WALLET_PASSWORD` for non-interactive use. The default vault path
196+
is `crypto/.wallet/flowchain-wallet.local.json`, which is ignored by git.
197+
139198
## Consumer Rules
140199

141200
Chain/devnet:
@@ -178,6 +237,7 @@ V0 also proves:
178237
- domain/type-string separation for each object class;
179238
- malformed hex rejection for bytes32/address fields;
180239
- canonical JSON stability for pre-hashed control-plane response bodies;
240+
- local wallet-signed transaction envelope verification without exposing private keys;
181241
- duplicate ID detection in fixture validation;
182242
- explicit finality and challenge state labels for local/test consumers.
183243

crypto/FLOWMEMORY_CRYPTO_SPEC.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ artifactAvailabilityProofId
110110
verifierModuleId
111111
challengeId
112112
finalityReceiptId
113+
bridgeDepositId
114+
bridgeCreditId
115+
bridgeWithdrawalId
116+
localAccountBalanceId
117+
localSignerId
118+
localSignerKeyId
113119
hardwareSignalEnvelopeId
114120
controlPlaneProvenanceResponseId
115121
localSignatureEnvelope
122+
localTransactionEnvelope
116123
```
117124

118125
## Versioning Strategy
@@ -138,8 +145,10 @@ The current package implements:
138145
- deterministic verifier reports
139146
- verifier signature envelopes
140147
- reorg-aware status handling
141-
- FlowChain Local Alpha object identity for agent accounts, model passports, work receipts, artifact availability proofs, verifier modules, verifier reports, memory cells, challenges, finality receipts, hardware signal envelopes, and control-plane provenance responses
148+
- FlowChain Local Alpha object identity for agent accounts, model passports, work receipts, artifact availability proofs, verifier modules, verifier reports, memory cells, challenges, finality receipts, bridge deposits, bridge credits, bridge withdrawals, local account balances, hardware signal envelopes, and control-plane provenance responses
142149
- Local Alpha operator, agent, verifier, and hardware signature envelope payloads and validators for replay, wrong domain, missing signer, zero hash, malformed id, malformed dependency, bad parent/root, and wrong object type checks
150+
- local transaction envelopes that bind domain, chain id, nonce, signer, payload hash, validity window, and signature while preserving `payload.tx` for devnet consumers
151+
- encrypted local wallet/vault helpers for no-value test keys with public metadata import/export and rotation
143152
- test vectors and cross-language conformance tests
144153

145154
The runnable package in `crypto/src/` currently implements the v0 hash utilities and tests them against fixtures in `crypto/fixtures/`.
@@ -151,7 +160,7 @@ MVP should remain verifier-attested for:
151160
- storage provider claims
152161
- model or worker behavior
153162
- final status labels before proof systems exist
154-
- local operator-vault policy; current fixture keys are deterministic no-value test keys and do not represent wallet custody, production account control, or transferable value
163+
- local operator-vault policy; current fixture keys and local wallet keys are deterministic or generated no-value test keys and do not represent production wallet custody, production account control, or transferable value
155164

156165
## Future Split
157166

crypto/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ canonical JSON Schemas:
4040
npm run validate:local-alpha
4141
```
4242

43+
Create and use a local encrypted no-value wallet vault:
44+
45+
```powershell
46+
$env:FLOWCHAIN_WALLET_PASSWORD = "replace-with-local-test-password"
47+
npm run wallet:create
48+
npm run wallet:sign
49+
npm run wallet:verify
50+
```
51+
52+
The default vault and generated envelopes live under `crypto/.wallet/`, which is
53+
ignored by git. Use `wallet:list`, `wallet:unlock`, `wallet:rotate`,
54+
`wallet:export-public`, and `wallet:import-public` for public account metadata
55+
and additional local accounts.
56+
4357
## Read Order
4458

4559
1. `FLOWMEMORY_CRYPTO_SPEC.md`
@@ -50,7 +64,7 @@ npm run validate:local-alpha
5064
6. `FLOWCHAIN_LOCAL_ALPHA_OBJECTS.md`
5165
7. `TEST_VECTORS.md`
5266

53-
Runnable fixtures live in `fixtures/`. `fixtures/vectors.json` contains the current 33 package-level vectors. `fixtures/local-alpha-objects.json` contains positive and negative Local Alpha object and signed-envelope fixtures. Supporting cross-language vectors live in `test-vectors/`.
67+
Runnable fixtures live in `fixtures/`. `fixtures/vectors.json` contains the current 41 package-level vectors. `fixtures/local-alpha-objects.json` contains positive and negative Local Alpha object and signed-envelope fixtures. `fixtures/local-transaction-vectors.json` contains wallet-signed local transaction envelopes and negative transaction vectors. Supporting cross-language vectors live in `test-vectors/`.
5468

5569
Validate the current vector set with:
5670

@@ -68,12 +82,14 @@ The Python validator is a cross-check for the FlowPulse aggregate vector. The pr
6882
- `artifactRoot`: commitment to off-chain artifact bytes and metadata.
6983
- `reportId`: deterministic identifier for a verifier report.
7084
- `attestation`: signed worker or verifier envelope over a receipt, report, artifact, or root.
71-
- Local Alpha object IDs: canonical IDs for `AgentAccount`, `ModelPassport`, `WorkReceipt`, `ArtifactAvailabilityProof`, `VerifierModule`, `VerifierReport`, `MemoryCell`, `Challenge`, `FinalityReceipt`, hardware signal envelopes, and control-plane provenance responses.
85+
- Local Alpha object IDs: canonical IDs for `AgentAccount`, `ModelPassport`, `WorkReceipt`, `ArtifactAvailabilityProof`, `VerifierModule`, `VerifierReport`, `MemoryCell`, `Challenge`, `FinalityReceipt`, `BridgeDeposit`, `BridgeCredit`, `BridgeWithdrawal`, local account balances, hardware signal envelopes, and control-plane provenance responses.
7286
- Local Alpha signature envelopes: local operator, agent, verifier, and hardware secp256k1 test signatures over typed object IDs. These are no-value local/test keys and are not wallet custody or production key-management claims.
87+
- Local transaction envelopes: wallet-signed wrappers that bind domain separation, chain id, nonce, signer, payload hash, validity window, and signature while preserving `payload.tx` for devnet/control-plane consumers.
88+
- Local wallet vault: AES-256-GCM encrypted local test-key storage with public metadata export. It is not a production wallet or custody system.
7389

7490
## Implemented Helpers
7591

76-
The package exports Keccak helpers, canonical JSON hashing, typed hash utilities, FlowPulse observation ids, cursor ids, report digests, receipt hashes, artifact/root commitments, work receipt ids, Local Alpha object ids, hardware signal envelope ids, Local Alpha signature envelope payloads, envelope validators, Merkle roots, worker/verifier signature payloads, verifier attestation envelope hashes, and local secp256k1 sign/verify helpers for tests.
92+
The package exports Keccak helpers, canonical JSON hashing, typed hash utilities, FlowPulse observation ids, cursor ids, report digests, receipt hashes, artifact/root commitments, work receipt ids, Local Alpha object ids, bridge/account-balance ids, hardware signal envelope ids, Local Alpha signature envelope payloads, local transaction envelope payloads, wallet vault helpers, envelope validators, Merkle roots, worker/verifier signature payloads, verifier attestation envelope hashes, and local secp256k1 sign/verify helpers for tests.
7793

7894
The implementation is ESM JavaScript with `src/index.d.ts` declarations for TypeScript consumers.
7995

@@ -99,6 +115,8 @@ Nearby Noesis/FlowChain RD crates under `E:\FlowMemory\github-research-sources\n
99115
## Downstream Consumption
100116

101117
- Chain/devnet agents should use the object ID helpers as transaction/object keys and reject zero roots, malformed IDs, wrong object types, replayed signer sequences, and bad parent/root relationships before state updates.
118+
- Chain/devnet agents can consume wallet-signed transaction envelopes by validating the envelope and then reading the existing devnet transaction object at `payload.tx`.
102119
- Services and verifiers should use `validateLocalAlphaEnvelope` before accepting object documents from local transactions, API calls, hardware packets, or fixture imports.
120+
- Control-plane agents should display only `flowchain.local_wallet_public_metadata.v0` account metadata and never vault ciphertext or private keys.
103121
- Dashboard/workbench agents should display IDs, domains, signer roles, status labels, and validation errors from these fixtures without implying production proof security.
104122
- Hardware agents should treat hardware signal envelopes as low-bandwidth authenticated control messages only; payloads remain off-chain and signal roots are commitments, not radio bandwidth or field-deployment claims.

crypto/TEST_VECTORS.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
Status: draft v0.
44

5-
The test vectors are synthetic and contain no production secrets or signatures.
5+
The test vectors are synthetic and contain no production secrets. Signatures are
6+
no-value local/test signatures with public keys only; private keys are not
7+
committed in fixtures or public exports.
68

79
## Vector Files
810

911
- `fixtures/sample-flowpulse.json`: FlowPulse event args and expected `pulseId` / `eventArgsHash`.
1012
- `fixtures/sample-observation.json`: observation metadata, artifact/storage inputs, and expected `observationId` / `receiptHash`.
1113
- `fixtures/sample-report.json`: verifier report, worker signature payload, verifier signature payload, and attestation envelope expectations.
1214
- `fixtures/local-alpha-objects.json`: positive and negative fixtures for FlowChain Local Alpha object identity, signed-envelope validation, and schema validation.
13-
- `fixtures/vectors.json`: 33 package-level vectors for domains, canonical JSON, observation ids, receipts, artifacts, Merkle roots, reports, attestations, cursors, identities, root commitments, work receipts, devnet block hashes, Local Alpha object ids, hardware signal envelopes, and local signature envelopes.
15+
- `fixtures/local-transaction-vectors.json`: wallet-signed local transaction envelopes, public wallet metadata, and negative vectors for chain id, domain, signer, nonce replay, malformed roots, malformed bridge deposits, and changed object type.
16+
- `fixtures/vectors.json`: 41 package-level vectors for domains, canonical JSON, observation ids, receipts, artifacts, Merkle roots, reports, attestations, cursors, identities, root commitments, work receipts, devnet block hashes, Local Alpha object ids, bridge/account objects, signer IDs, local transaction payloads, hardware signal envelopes, and local signature envelopes.
1417
- `test-vectors/flowpulse-observation-v0.json`: FlowPulse-specific observation, receipt, artifact, report, worker signature digest, and verifier signature digest.
1518

1619
## FlowPulse Observation Vector Highlights
@@ -50,8 +53,9 @@ An implementation should reproduce:
5053
- Merkle root and artifact root
5154
- deterministic verifier report id
5255
- EIP-712 signing digests without requiring test private keys
53-
- Local Alpha object IDs for AgentAccount, ModelPassport, WorkReceipt, ArtifactAvailabilityProof, VerifierModule, VerifierReport, MemoryCell, Challenge, FinalityReceipt, hardware signal envelopes, and control-plane provenance responses
56+
- Local Alpha object IDs for AgentAccount, ModelPassport, WorkReceipt, ArtifactAvailabilityProof, VerifierModule, VerifierReport, MemoryCell, Challenge, FinalityReceipt, BridgeDeposit, BridgeCredit, BridgeWithdrawal, local account balance, hardware signal envelopes, and control-plane provenance responses
5457
- Local Alpha signature envelope IDs and signing digests for local operator, agent, verifier, and hardware no-value test keys
58+
- Local transaction envelope IDs, payload hashes, signing digests, and public signer metadata
5559

5660
Run the package test suite:
5761

@@ -69,7 +73,7 @@ npm run validate:vectors
6973
Expected output:
7074

7175
```text
72-
FLOWMEMORY_CRYPTO_VECTORS_OK 33
76+
FLOWMEMORY_CRYPTO_VECTORS_OK vectors=41 localTransactionPositive=2 localTransactionNegative=7
7377
```
7478

7579
Validate the Local Alpha object documents and signature envelopes against the
@@ -82,7 +86,7 @@ npm run validate:local-alpha
8286
Expected output:
8387

8488
```text
85-
FLOWCHAIN_LOCAL_ALPHA_FIXTURES_OK documents=11 envelopes=11 schemas=12
89+
FLOWCHAIN_LOCAL_ALPHA_FIXTURES_OK documents=15 envelopes=11 schemas=16
8690
```
8791

8892
Print the sample vector summary:
@@ -116,11 +120,14 @@ FLOWPULSE_VECTOR_RECOMPUTE_OK
116120
- duplicate Local Alpha object IDs should be rejected by fixture validation
117121
- canonical JSON key order should not change the control-plane provenance response body hash
118122
- replayed Local Alpha signer/domain/sequence tuples should be rejected
123+
- replayed local transaction signer/domain/nonce tuples should be rejected
124+
- wrong local transaction chain id, domain, and signer should be rejected
125+
- malformed bridge deposits inside local transaction payloads should be rejected
119126
- wrong signature domains should be rejected
120127
- missing local operator/agent/verifier/hardware signer fields should be rejected
121128
- each Local Alpha object envelope has a bad-signature invalid vector
122129
- zero critical hashes, malformed object IDs, malformed dependency roots, bad parent/root relationships, and wrong object types should be rejected
123130
- expired worker signature should be rejected by verifier policy
124131
- reorged observation should not mutate into a verified report
125132

126-
The package tests cover the hash, schema, malformed hex, duplicate, type-string, canonical JSON, signed-envelope, replay, wrong-domain, missing-signer, bad-signature, zero-hash, malformed-dependency, bad-parent/root, and wrong-object-type checks. Expiry and reorg-to-report policy are verifier-service responsibilities because they require policy context, not just hash recomputation.
133+
The package tests cover the hash, schema, malformed hex, duplicate, type-string, canonical JSON, signed-envelope, transaction-envelope, wallet public-metadata, replay, wrong-chain-id, wrong-domain, wrong-signer, missing-signer, bad-signature, zero-hash, malformed-dependency, malformed-root, malformed bridge-deposit, bad-parent/root, and wrong-object-type checks. Expiry and reorg-to-report policy are verifier-service responsibilities because they require policy context, not just hash recomputation.

0 commit comments

Comments
 (0)