gridstamp 1.0.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/.cursorrules +74 -0
- package/CLAUDE.md +61 -0
- package/LICENSE +190 -0
- package/README.md +107 -0
- package/dist/index.js +194 -0
- package/package.json +84 -0
- package/src/antispoofing/detector.ts +509 -0
- package/src/antispoofing/index.ts +7 -0
- package/src/gamification/badges.ts +429 -0
- package/src/gamification/fleet-leaderboard.ts +293 -0
- package/src/gamification/index.ts +44 -0
- package/src/gamification/streaks.ts +243 -0
- package/src/gamification/trust-tiers.ts +393 -0
- package/src/gamification/zone-mastery.ts +256 -0
- package/src/index.ts +341 -0
- package/src/memory/index.ts +9 -0
- package/src/memory/place-cells.ts +279 -0
- package/src/memory/spatial-memory.ts +375 -0
- package/src/navigation/index.ts +1 -0
- package/src/navigation/pathfinding.ts +403 -0
- package/src/perception/camera.ts +249 -0
- package/src/perception/index.ts +2 -0
- package/src/types/index.ts +416 -0
- package/src/utils/crypto.ts +94 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/math.ts +204 -0
- package/src/verification/index.ts +9 -0
- package/src/verification/spatial-proof.ts +442 -0
- package/tests/antispoofing/detector.test.ts +196 -0
- package/tests/gamification/badges.test.ts +163 -0
- package/tests/gamification/fleet-leaderboard.test.ts +181 -0
- package/tests/gamification/streaks.test.ts +158 -0
- package/tests/gamification/trust-tiers.test.ts +165 -0
- package/tests/gamification/zone-mastery.test.ts +143 -0
- package/tests/memory/place-cells.test.ts +128 -0
- package/tests/stress/load.test.ts +499 -0
- package/tests/stress/security.test.ts +378 -0
- package/tests/stress/simulation.test.ts +361 -0
- package/tests/utils/crypto.test.ts +115 -0
- package/tests/utils/math.test.ts +195 -0
- package/tests/verification/spatial-proof.test.ts +299 -0
- package/tsconfig.json +26 -0
package/.cursorrules
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
You are an expert in TypeScript, Node.js, robotics perception, and spatial computing.
|
|
2
|
+
|
|
3
|
+
Project: GridStamp — Spatial proof-of-presence for autonomous robots.
|
|
4
|
+
|
|
5
|
+
Architecture: 6-layer system
|
|
6
|
+
1. Perception (src/perception/) — HMAC-signed camera frames, stereo depth, dual-camera fusion
|
|
7
|
+
2. Memory (src/memory/) — Short/mid/long-term spatial memory, place cells, grid cells, Merkle integrity
|
|
8
|
+
3. Navigation (src/navigation/) — A* and RRT* pathfinding on 3D occupancy grids
|
|
9
|
+
4. Verification (src/verification/) — SSIM + LPIPS + depth MAE spatial proofs for payment authorization
|
|
10
|
+
5. Anti-spoofing (src/antispoofing/) — Replay detection, adversarial patches, depth injection, canary honeypots
|
|
11
|
+
6. Gamification (src/gamification/) — Trust tiers, badges, streaks, zone mastery, fleet leaderboard
|
|
12
|
+
|
|
13
|
+
Core Rules:
|
|
14
|
+
- Every camera frame MUST be HMAC-SHA256 signed at capture time
|
|
15
|
+
- All secrets must be >= 32 characters
|
|
16
|
+
- Use deriveKey() for subsystem key isolation — NEVER reuse the master secret directly
|
|
17
|
+
- Fail closed: if any integrity check fails, reject the frame/proof
|
|
18
|
+
- No floating-point equality checks — use tolerance-based comparison
|
|
19
|
+
- All spatial coordinates use Vec3 { x, y, z } — right-handed coordinate system
|
|
20
|
+
- Quaternions are { w, x, y, z } — Hamilton convention, w-first
|
|
21
|
+
- Depth maps are Float32Array, RGB is Uint8Array (packed R,G,B per pixel)
|
|
22
|
+
|
|
23
|
+
Type System (src/types/index.ts):
|
|
24
|
+
- Pose = { position: Vec3, orientation: Quaternion, timestamp: number }
|
|
25
|
+
- CameraFrame = RGB + depth + pose + HMAC + sequenceNumber
|
|
26
|
+
- GaussianSplat = 59 parameters (position, covariance, SH coefficients, opacity)
|
|
27
|
+
- SpatialProof = metrics + signature + nonce + Merkle root
|
|
28
|
+
- ThreatDetection = { type, severity, confidence, details, mitigationApplied }
|
|
29
|
+
|
|
30
|
+
Testing:
|
|
31
|
+
- Framework: vitest
|
|
32
|
+
- Run all: npx vitest run
|
|
33
|
+
- Run specific: npx vitest run tests/memory/place-cells.test.ts
|
|
34
|
+
- 221 tests across 13 test files
|
|
35
|
+
- Test images use deterministic pseudo-random data (seed-based)
|
|
36
|
+
|
|
37
|
+
Key Patterns:
|
|
38
|
+
- Place cells: Gaussian activation centered at a 3D position
|
|
39
|
+
- Grid cells: Hexagonal pattern via 3 cosine waves at 60° offsets
|
|
40
|
+
- SSIM: 8x8 sliding window, constants C1=6.5025 C2=58.5225
|
|
41
|
+
- Spatial proof composite: SSIM * 0.4 + (1-LPIPS) * 0.3 + depthScore * 0.3
|
|
42
|
+
- Settlement: atomic verify-then-pay, proof must pass integrity check first
|
|
43
|
+
|
|
44
|
+
Gamification Layer (maps WeMeetWeMet's activity-based system to robot fleet management):
|
|
45
|
+
- Trust Tiers: 6 levels (Untrusted→Autonomous), fee multipliers, tx limits, HMAC-signed tier changes
|
|
46
|
+
- Badges: 20+ capability badges across 5 categories, HMAC-signed awards
|
|
47
|
+
- Streaks: Daily consecutive operation streaks, multiplier curve (1.0x→2.0x), freeze system
|
|
48
|
+
- Zone Mastery: Geographic expertise = coverage × success_rate × time_factor
|
|
49
|
+
- Fleet Leaderboard: Multi-fleet rankings by trust/deliveries/zones/safety, HMAC-signed entries
|
|
50
|
+
- All tier changes, badges, and leaderboard entries are HMAC-signed to prevent forgery
|
|
51
|
+
|
|
52
|
+
File Layout:
|
|
53
|
+
src/
|
|
54
|
+
types/index.ts — All type definitions
|
|
55
|
+
utils/crypto.ts — HMAC, SHA-256, nonces, key derivation
|
|
56
|
+
utils/math.ts — Vec3, quaternion, coordinate transforms
|
|
57
|
+
perception/camera.ts — Frame capture, dual cameras, depth fusion
|
|
58
|
+
memory/spatial-memory.ts — STM/MTM/LTM with Merkle trees
|
|
59
|
+
memory/place-cells.ts — Place cells, grid cells, spatial coding
|
|
60
|
+
navigation/pathfinding.ts — A*, RRT*, occupancy grid
|
|
61
|
+
verification/spatial-proof.ts — SSIM, LPIPS, spatial proofs, settlements
|
|
62
|
+
antispoofing/detector.ts — Replay, patches, depth, canaries
|
|
63
|
+
gamification/trust-tiers.ts — 6-tier trust system with promotion/demotion
|
|
64
|
+
gamification/badges.ts — 20+ capability badges, criteria engine
|
|
65
|
+
gamification/streaks.ts — Daily streak multipliers, freeze system
|
|
66
|
+
gamification/zone-mastery.ts — Geographic zone expertise scoring
|
|
67
|
+
gamification/fleet-leaderboard.ts — Fleet-wide robot rankings
|
|
68
|
+
index.ts — createAgent() factory, public API
|
|
69
|
+
|
|
70
|
+
Dependencies:
|
|
71
|
+
- merkletreejs + crypto-js — Merkle tree for memory integrity
|
|
72
|
+
- sharp — Image processing (future: resize for multi-scale LPIPS)
|
|
73
|
+
- ssim.js — Reference SSIM (we also have custom implementation)
|
|
74
|
+
- typescript, vitest, eslint — Dev tooling
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# GridStamp
|
|
2
|
+
|
|
3
|
+
Spatial proof-of-presence for autonomous robots.
|
|
4
|
+
|
|
5
|
+
**IMPORTANT:** This is a SEPARATE project from MnemoPay. Do not mix codebases.
|
|
6
|
+
|
|
7
|
+
## Quick Commands
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm test # Run all 221 tests
|
|
11
|
+
npx vitest run # Same, explicit
|
|
12
|
+
npx tsc --noEmit # Type check only
|
|
13
|
+
npm run build # Compile to dist/
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
6 layers, each isolated with derived keys:
|
|
19
|
+
|
|
20
|
+
| Layer | Path | Purpose |
|
|
21
|
+
|-------|------|---------|
|
|
22
|
+
| Perception | src/perception/ | HMAC-signed frames, stereo depth |
|
|
23
|
+
| Memory | src/memory/ | Place cells, grid cells, Merkle-signed LTM |
|
|
24
|
+
| Navigation | src/navigation/ | A* + RRT* on 3D voxel grids |
|
|
25
|
+
| Verification | src/verification/ | SSIM/LPIPS spatial proofs → payments |
|
|
26
|
+
| Anti-spoofing | src/antispoofing/ | Replay, patches, depth injection, canaries |
|
|
27
|
+
| Gamification | src/gamification/ | Trust tiers, badges, streaks, zone mastery, fleet leaderboard |
|
|
28
|
+
|
|
29
|
+
## Security Model
|
|
30
|
+
|
|
31
|
+
- Every frame is HMAC-SHA256 signed at capture (timestamp + sequence in payload)
|
|
32
|
+
- Keys derived per subsystem: `deriveKey(masterSecret, 'frame-signing')` etc.
|
|
33
|
+
- Fail closed on any integrity violation
|
|
34
|
+
- Monotonic sequence numbers detect replay attacks
|
|
35
|
+
- Canary landmarks detect memory poisoning
|
|
36
|
+
- Constant-time HMAC comparison (timingSafeEqual)
|
|
37
|
+
|
|
38
|
+
## Key Types
|
|
39
|
+
|
|
40
|
+
- `CameraFrame` — RGB + depth + pose + HMAC + sequence
|
|
41
|
+
- `SpatialProof` — Rendered vs captured comparison with cryptographic signature
|
|
42
|
+
- `SpatialSettlement` — Payment contingent on spatial verification passing
|
|
43
|
+
- `GridStampAgent` — Main API: see/remember/navigate/verifySpatial/settle
|
|
44
|
+
|
|
45
|
+
## Module Map
|
|
46
|
+
|
|
47
|
+
- `src/types/index.ts` — All interfaces and enums
|
|
48
|
+
- `src/utils/crypto.ts` — HMAC, SHA-256, nonces, key derivation
|
|
49
|
+
- `src/utils/math.ts` — Vec3, quaternions, coordinate transforms, Gaussian functions
|
|
50
|
+
- `src/perception/camera.ts` — FrameCapture, DualCameraSystem, depth fusion
|
|
51
|
+
- `src/memory/spatial-memory.ts` — ShortTermMemory (LRU+TTL), MidTermMemory, LongTermMemory (Merkle)
|
|
52
|
+
- `src/memory/place-cells.ts` — PlaceCell, GridCell, PlaceCellPopulation, GridCellSystem
|
|
53
|
+
- `src/navigation/pathfinding.ts` — OccupancyGrid, aStarPath, rrtStarPath
|
|
54
|
+
- `src/verification/spatial-proof.ts` — computeSSIM, approximateLPIPS, generateSpatialProof, createSettlement
|
|
55
|
+
- `src/antispoofing/detector.ts` — ReplayDetector, AdversarialPatchDetector, CanarySystem, FrameIntegrityChecker
|
|
56
|
+
- `src/gamification/trust-tiers.ts` — TrustTierSystem (6 tiers, HMAC-signed promotion/demotion)
|
|
57
|
+
- `src/gamification/badges.ts` — BadgeSystem (20+ badges, 5 categories, HMAC-signed awards)
|
|
58
|
+
- `src/gamification/streaks.ts` — StreakSystem (daily streaks, multiplier curve, freeze system)
|
|
59
|
+
- `src/gamification/zone-mastery.ts` — ZoneMasterySystem (coverage × success × time scoring)
|
|
60
|
+
- `src/gamification/fleet-leaderboard.ts` — FleetLeaderboard (multi-fleet rankings, HMAC-signed entries)
|
|
61
|
+
- `src/index.ts` — createAgent() factory, re-exports everything
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Jerry Omiagbo
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# GridStamp
|
|
2
|
+
|
|
3
|
+
Spatial proof-of-presence for autonomous robots.
|
|
4
|
+
|
|
5
|
+
GridStamp gives robots the ability to prove where they are, remember where they've been, and get paid for verified operations. Built on 3D Gaussian Splatting, bio-inspired navigation (place cells + grid cells), and cryptographic spatial proofs.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Robots need to prove they actually did the job. A delivery robot needs to verify it reached the destination. A warehouse AMR needs spatial proof for billing. An inspection drone needs tamper-proof evidence it surveyed the site.
|
|
10
|
+
|
|
11
|
+
No existing SDK combines spatial memory, payment verification, and anti-spoofing in one package.
|
|
12
|
+
|
|
13
|
+
## Architecture
|
|
14
|
+
|
|
15
|
+
Six layers, each cryptographically isolated:
|
|
16
|
+
|
|
17
|
+
| Layer | What it does |
|
|
18
|
+
|-------|-------------|
|
|
19
|
+
| **Perception** | HMAC-signed camera frames, stereo depth fusion, dual-camera support |
|
|
20
|
+
| **Memory** | 3-tier spatial memory (short/mid/long-term) with Merkle tree integrity |
|
|
21
|
+
| **Navigation** | A* and RRT* pathfinding on 3D occupancy grids, place cells + grid cells |
|
|
22
|
+
| **Verification** | SSIM + LPIPS + depth comparison for spatial proof-of-location |
|
|
23
|
+
| **Anti-Spoofing** | Replay detection, adversarial patch detection, depth injection, canary honeypots |
|
|
24
|
+
| **Gamification** | Trust tiers, capability badges, streak multipliers, zone mastery, fleet leaderboard |
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install gridstamp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { createAgent } from 'gridstamp';
|
|
36
|
+
|
|
37
|
+
const agent = createAgent({
|
|
38
|
+
robotId: 'DLV-001',
|
|
39
|
+
cameras: [{ type: 'oak-d-pro', role: 'foveal', /* ... */ }],
|
|
40
|
+
hmacSecret: process.env.GRIDSTAMP_SECRET, // min 32 chars
|
|
41
|
+
}, cameraDriver);
|
|
42
|
+
|
|
43
|
+
// Capture and verify
|
|
44
|
+
const frame = await agent.see();
|
|
45
|
+
const proof = await agent.verifySpatial();
|
|
46
|
+
|
|
47
|
+
// Settle payment only if spatial proof passes
|
|
48
|
+
const settlement = await agent.settle({
|
|
49
|
+
amount: 15.00,
|
|
50
|
+
currency: 'USD',
|
|
51
|
+
payeeId: 'merchant-001',
|
|
52
|
+
spatialProof: true,
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Trust Tiers
|
|
57
|
+
|
|
58
|
+
Robots earn trust through verified operations, similar to a credit score:
|
|
59
|
+
|
|
60
|
+
| Tier | Points | Fee | Max Tx | Verification |
|
|
61
|
+
|------|--------|-----|--------|-------------|
|
|
62
|
+
| Untrusted | 0 | 2.5x | $10 | Every operation |
|
|
63
|
+
| Probation | 100 | 2.0x | $50 | Every operation |
|
|
64
|
+
| Verified | 500 | 1.5x | $200 | Every 3rd |
|
|
65
|
+
| Trusted | 2,000 | 1.2x | $1,000 | Every 5th |
|
|
66
|
+
| Elite | 5,000 | 1.0x | $5,000 | Every 10th |
|
|
67
|
+
| Autonomous | 10,000 | 0.8x | $25,000 | Spot checks |
|
|
68
|
+
|
|
69
|
+
All tier changes are HMAC-signed. Spoofing attempts result in immediate two-tier demotion.
|
|
70
|
+
|
|
71
|
+
## Security Model
|
|
72
|
+
|
|
73
|
+
- Every camera frame is HMAC-SHA256 signed at capture time
|
|
74
|
+
- Cryptographic key derivation isolates subsystems (`deriveKey(master, 'frame-signing')`)
|
|
75
|
+
- Monotonic sequence numbers prevent replay attacks
|
|
76
|
+
- Canary landmarks detect memory poisoning
|
|
77
|
+
- Constant-time HMAC comparison prevents timing attacks
|
|
78
|
+
- Fail-closed: any integrity violation blocks payment
|
|
79
|
+
|
|
80
|
+
## Modules
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
gridstamp # Full SDK
|
|
84
|
+
gridstamp/perception # Camera + depth
|
|
85
|
+
gridstamp/memory # Spatial memory + place/grid cells
|
|
86
|
+
gridstamp/navigation # Pathfinding
|
|
87
|
+
gridstamp/verification # Spatial proofs + settlements
|
|
88
|
+
gridstamp/antispoofing # Threat detection
|
|
89
|
+
gridstamp/gamification # Trust tiers + badges + leaderboard
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Use Cases
|
|
93
|
+
|
|
94
|
+
- **Last-mile delivery** — Robot proves it reached the doorstep before payment settles
|
|
95
|
+
- **Warehouse operations** — AMRs earn trust tiers based on verified pick accuracy
|
|
96
|
+
- **Drone inspection** — Tamper-proof spatial evidence of site surveys
|
|
97
|
+
- **Autonomous trucking** — Spatial proof-of-delivery for freight settlements
|
|
98
|
+
- **Roofing/HVAC/Plumbing** — AI agents verify on-site work completion
|
|
99
|
+
|
|
100
|
+
## Requirements
|
|
101
|
+
|
|
102
|
+
- Node.js 20+
|
|
103
|
+
- TypeScript 5.6+
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
Apache 2.0 — see [LICENSE](LICENSE)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GridStamp — Spatial Proof-of-Presence for Autonomous Robots
|
|
3
|
+
*
|
|
4
|
+
* Nobody else unifies spatial memory + payment verification + anti-spoofing.
|
|
5
|
+
* - Niantic has maps but no payments
|
|
6
|
+
* - NVIDIA has rendering but no memory persistence
|
|
7
|
+
* - OpenMind has robot payments but no spatial proof
|
|
8
|
+
* - FOAM/Auki has proof-of-location but no payments
|
|
9
|
+
*
|
|
10
|
+
* GridStamp sits at the intersection.
|
|
11
|
+
*
|
|
12
|
+
* API:
|
|
13
|
+
* agent.see() — Capture + process current view
|
|
14
|
+
* agent.remember() — Store spatial context to memory
|
|
15
|
+
* agent.navigate() — Plan path to target
|
|
16
|
+
* agent.verifySpatial() — Prove robot is at claimed location
|
|
17
|
+
* agent.settle() — Payment with spatial proof requirement
|
|
18
|
+
*/
|
|
19
|
+
export { CameraType, MemoryTier, PathAlgorithm, ReferenceFrame, SettlementStatus, ThreatType, ThreatSeverity, } from './types/index.js';
|
|
20
|
+
// Re-export modules
|
|
21
|
+
export * from './perception/index.js';
|
|
22
|
+
export * from './memory/index.js';
|
|
23
|
+
export * from './navigation/index.js';
|
|
24
|
+
export * from './verification/index.js';
|
|
25
|
+
export * from './antispoofing/index.js';
|
|
26
|
+
export * from './gamification/index.js';
|
|
27
|
+
// Re-export key utilities
|
|
28
|
+
export { hmacSign, hmacVerify, signFrame, verifyFrame, generateNonce, sha256, deriveKey, } from './utils/crypto.js';
|
|
29
|
+
export { vec3Distance, vec3Add, vec3Sub, vec3Scale, vec3Normalize, egoToAllo, alloToEgo, stereoDepth, gaussian3D, meanAbsoluteError, poseToMat4, quatRotateVec3, quatSlerp, } from './utils/math.js';
|
|
30
|
+
import { FrameCapture } from './perception/index.js';
|
|
31
|
+
import { ShortTermMemory, MidTermMemory, LongTermMemory as LongTermMemoryStore, MemoryConsolidator, } from './memory/index.js';
|
|
32
|
+
import { PlaceCellPopulation, GridCellSystem, computeSpatialCode } from './memory/index.js';
|
|
33
|
+
import { OccupancyGrid, planPath } from './navigation/index.js';
|
|
34
|
+
import { generateSpatialProof, createSettlement, } from './verification/index.js';
|
|
35
|
+
import { FrameIntegrityChecker, CanarySystem } from './antispoofing/index.js';
|
|
36
|
+
import { deriveKey } from './utils/crypto.js';
|
|
37
|
+
/**
|
|
38
|
+
* Create a GridStamp agent
|
|
39
|
+
*
|
|
40
|
+
* This is the main entry point. Pass a config + camera driver,
|
|
41
|
+
* get back an agent with see/remember/navigate/verify/settle methods.
|
|
42
|
+
*/
|
|
43
|
+
export function createAgent(config, primaryDriver) {
|
|
44
|
+
// Validate config
|
|
45
|
+
if (!config.robotId)
|
|
46
|
+
throw new Error('robotId is required');
|
|
47
|
+
if (!config.hmacSecret || config.hmacSecret.length < 32) {
|
|
48
|
+
throw new Error('hmacSecret must be at least 32 characters');
|
|
49
|
+
}
|
|
50
|
+
// Derive separate keys for each subsystem (key separation)
|
|
51
|
+
const frameKey = deriveKey(config.hmacSecret, 'frame-signing');
|
|
52
|
+
const memoryKey = deriveKey(config.hmacSecret, 'memory-signing');
|
|
53
|
+
const proofKey = config.hmacSecret; // proof uses master key
|
|
54
|
+
// Initialize subsystems
|
|
55
|
+
const frameCapture = new FrameCapture(primaryDriver, config.cameras[0], frameKey);
|
|
56
|
+
const shortTerm = new ShortTermMemory(900, config.memoryConfig?.shortTermTTL ?? 30_000);
|
|
57
|
+
const midTerm = new MidTermMemory(config.memoryConfig?.midTermMaxEntries ?? 1000);
|
|
58
|
+
const longTermStore = new LongTermMemoryStore(memoryKey);
|
|
59
|
+
const consolidator = new MemoryConsolidator(shortTerm, midTerm, longTermStore);
|
|
60
|
+
const placeCells = new PlaceCellPopulation();
|
|
61
|
+
const gridCells = new GridCellSystem();
|
|
62
|
+
const integrityChecker = new FrameIntegrityChecker(frameKey);
|
|
63
|
+
const canaries = new CanarySystem(memoryKey);
|
|
64
|
+
let lastFrame;
|
|
65
|
+
let initialized = false;
|
|
66
|
+
const agent = {
|
|
67
|
+
async see() {
|
|
68
|
+
if (!initialized) {
|
|
69
|
+
await frameCapture.initialize();
|
|
70
|
+
initialized = true;
|
|
71
|
+
}
|
|
72
|
+
const frame = await frameCapture.capture();
|
|
73
|
+
// Run integrity check on every frame (fail-closed)
|
|
74
|
+
const integrity = integrityChecker.check(frame);
|
|
75
|
+
if (!integrityChecker.isSafe(integrity)) {
|
|
76
|
+
const criticalThreats = integrity.threats
|
|
77
|
+
.filter(t => t.severity === 'critical')
|
|
78
|
+
.map(t => t.details)
|
|
79
|
+
.join('; ');
|
|
80
|
+
throw new Error(`Frame rejected by anti-spoofing: ${criticalThreats}`);
|
|
81
|
+
}
|
|
82
|
+
// Store in short-term memory (empty splats for now — 3DGS integration point)
|
|
83
|
+
shortTerm.add(frame, []);
|
|
84
|
+
// Auto-generate place cell at frame position if we have pose
|
|
85
|
+
if (frame.pose) {
|
|
86
|
+
const cell = (await import('./memory/place-cells.js')).createPlaceCell(frame.pose.position);
|
|
87
|
+
placeCells.add(cell);
|
|
88
|
+
}
|
|
89
|
+
lastFrame = frame;
|
|
90
|
+
return frame;
|
|
91
|
+
},
|
|
92
|
+
async remember(tags) {
|
|
93
|
+
const consolidated = consolidator.consolidateToMidTerm(tags ?? []);
|
|
94
|
+
if (!consolidated) {
|
|
95
|
+
// Even if not enough for full consolidation, store what we have
|
|
96
|
+
const entries = shortTerm.getAll();
|
|
97
|
+
if (entries.length === 0) {
|
|
98
|
+
throw new Error('No frames in short-term memory to remember');
|
|
99
|
+
}
|
|
100
|
+
// Force store
|
|
101
|
+
const allSplats = entries.flatMap(e => e.splats);
|
|
102
|
+
const scene = {
|
|
103
|
+
id: (await import('./utils/crypto.js')).generateNonce(16),
|
|
104
|
+
splats: allSplats,
|
|
105
|
+
count: allSplats.length,
|
|
106
|
+
boundingBox: {
|
|
107
|
+
min: { x: 0, y: 0, z: 0 },
|
|
108
|
+
max: { x: 0, y: 0, z: 0 },
|
|
109
|
+
},
|
|
110
|
+
createdAt: Date.now(),
|
|
111
|
+
};
|
|
112
|
+
const location = lastFrame?.pose?.position ?? { x: 0, y: 0, z: 0 };
|
|
113
|
+
return midTerm.store(scene, location, tags ?? []);
|
|
114
|
+
}
|
|
115
|
+
// Get the most recent mid-term memory
|
|
116
|
+
const memories = midTerm.findNear(lastFrame?.pose?.position ?? { x: 0, y: 0, z: 0 }, 100);
|
|
117
|
+
return memories[0];
|
|
118
|
+
},
|
|
119
|
+
async navigate(target, options) {
|
|
120
|
+
const start = lastFrame?.pose?.position ?? { x: 0, y: 0, z: 0 };
|
|
121
|
+
const bounds = {
|
|
122
|
+
min: {
|
|
123
|
+
x: Math.min(start.x, target.x) - 10,
|
|
124
|
+
y: Math.min(start.y, target.y) - 10,
|
|
125
|
+
z: Math.min(start.z, target.z) - 2,
|
|
126
|
+
},
|
|
127
|
+
max: {
|
|
128
|
+
x: Math.max(start.x, target.x) + 10,
|
|
129
|
+
y: Math.max(start.y, target.y) + 10,
|
|
130
|
+
z: Math.max(start.z, target.z) + 2,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const grid = new OccupancyGrid(bounds);
|
|
134
|
+
const algorithm = options?.algorithm ?? config.navigationConfig?.defaultAlgorithm ?? 'a-star';
|
|
135
|
+
const path = planPath(start, target, grid, bounds, algorithm);
|
|
136
|
+
if (!path)
|
|
137
|
+
throw new Error('No path found to target');
|
|
138
|
+
return path;
|
|
139
|
+
},
|
|
140
|
+
async verifySpatial(claimedPose) {
|
|
141
|
+
if (!lastFrame)
|
|
142
|
+
throw new Error('No frame captured. Call see() first.');
|
|
143
|
+
const pose = claimedPose ?? lastFrame.pose;
|
|
144
|
+
if (!pose)
|
|
145
|
+
throw new Error('No pose available. Provide claimedPose or ensure camera provides pose.');
|
|
146
|
+
// In production, this would render from long-term memory 3DGS
|
|
147
|
+
// For now, use the last frame as "expected" (self-verification)
|
|
148
|
+
const expectedRender = {
|
|
149
|
+
rgb: lastFrame.rgb,
|
|
150
|
+
depth: lastFrame.depth ?? new Float32Array(0),
|
|
151
|
+
width: lastFrame.width,
|
|
152
|
+
height: lastFrame.height,
|
|
153
|
+
pose,
|
|
154
|
+
renderTimeMs: 0,
|
|
155
|
+
};
|
|
156
|
+
return generateSpatialProof(config.robotId, pose, lastFrame, expectedRender, 'pending-merkle-root', // would come from long-term memory
|
|
157
|
+
[], proofKey, config.verificationThresholds);
|
|
158
|
+
},
|
|
159
|
+
async settle(params) {
|
|
160
|
+
if (!params.spatialProof) {
|
|
161
|
+
throw new Error('GridStamp requires spatialProof=true. Use MnemoPay directly for non-spatial payments.');
|
|
162
|
+
}
|
|
163
|
+
const proof = await agent.verifySpatial();
|
|
164
|
+
return createSettlement(proof, params.amount, params.currency, params.payeeId, proofKey);
|
|
165
|
+
},
|
|
166
|
+
getSpatialCode() {
|
|
167
|
+
const position = lastFrame?.pose?.position ?? { x: 0, y: 0, z: 0 };
|
|
168
|
+
return computeSpatialCode(position, placeCells, gridCells);
|
|
169
|
+
},
|
|
170
|
+
getMemoryStats() {
|
|
171
|
+
const shortEntries = shortTerm.getAll();
|
|
172
|
+
return {
|
|
173
|
+
shortTerm: {
|
|
174
|
+
count: shortTerm.count,
|
|
175
|
+
oldestMs: shortEntries.length > 0 ? Date.now() - shortEntries[0].timestamp : 0,
|
|
176
|
+
},
|
|
177
|
+
midTerm: {
|
|
178
|
+
count: midTerm.count,
|
|
179
|
+
totalSplats: midTerm.getTotalSplatCount(),
|
|
180
|
+
},
|
|
181
|
+
longTerm: {
|
|
182
|
+
count: longTermStore.totalEntries,
|
|
183
|
+
rooms: longTermStore.roomCount,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
async shutdown() {
|
|
188
|
+
await frameCapture.shutdown();
|
|
189
|
+
integrityChecker.reset();
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
return agent;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=index.js.map
|