spiderweave 1.0.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 playwebit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,424 @@
1
+ Metadata-Version: 2.4
2
+ Name: spiderweave
3
+ Version: 1.0.0
4
+ Summary: Cross-table hash architecture for tamper-proof blockchain data integrity
5
+ Home-page: https://github.com/playwebit/spiderweave-sdk
6
+ Author: Priyanshu Chauhan
7
+ Author-email:
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Security :: Cryptography
12
+ Classifier: Topic :: Database
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: requests
18
+ Provides-Extra: supabase
19
+ Requires-Dist: supabase>=1.0.0; extra == "supabase"
20
+ Provides-Extra: postgres
21
+ Requires-Dist: sqlalchemy>=1.4.0; extra == "postgres"
22
+ Requires-Dist: psycopg2-binary>=2.9.0; extra == "postgres"
23
+ Provides-Extra: mysql
24
+ Requires-Dist: sqlalchemy>=1.4.0; extra == "mysql"
25
+ Requires-Dist: pymysql>=1.0.0; extra == "mysql"
26
+ Provides-Extra: evm
27
+ Requires-Dist: web3>=6.0.0; extra == "evm"
28
+ Provides-Extra: all
29
+ Requires-Dist: supabase>=1.0.0; extra == "all"
30
+ Requires-Dist: sqlalchemy>=1.4.0; extra == "all"
31
+ Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
32
+ Requires-Dist: web3>=6.0.0; extra == "all"
33
+ Requires-Dist: requests; extra == "all"
34
+ Dynamic: author
35
+ Dynamic: classifier
36
+ Dynamic: description
37
+ Dynamic: description-content-type
38
+ Dynamic: home-page
39
+ Dynamic: license-file
40
+ Dynamic: provides-extra
41
+ Dynamic: requires-dist
42
+ Dynamic: requires-python
43
+ Dynamic: summary
44
+
45
+ # SpiderWeave SDK
46
+
47
+ **Cross-table hash architecture for tamper-proof blockchain data integrity.**
48
+
49
+ SpiderWeave links your database tables together with cryptographic hashes and anchors the result on any blockchain. If anyone tampers with even a single row in any table — the entire chain breaks instantly, exposing the attack.
50
+
51
+ Invented by **Priyanshu Chauhan / PlayWebit** as part of the SpiderWeave Hash Architecture research.
52
+
53
+ ---
54
+
55
+ ## The Problem It Solves
56
+
57
+ NFT metadata and transaction data are typically stored off-chain (in a database like Supabase or PostgreSQL). This creates a vulnerability: anyone with database access can silently change a record — altering ownership, price, or metadata — without the blockchain knowing.
58
+
59
+ **SpiderWeave fixes this** by creating a cryptographic fingerprint that spans multiple tables simultaneously. Change anything, anywhere — and the fingerprint breaks.
60
+
61
+ ---
62
+
63
+ ## How It Works
64
+
65
+ ```
66
+ Table: nfts → hash_1 ──┐
67
+ Table: wallets → hash_2 ──┤
68
+ Table: sessions → hash_3 ──┼──► Spider Hash ──► Blockchain
69
+ Table: marketplace→ hash_4 ──┤ ▲
70
+ Table: contracts → hash_5 ──┘ │
71
+ Previous hash
72
+ (chain link)
73
+ ```
74
+
75
+ Every event (mint, transfer, sale) produces a new Spider Hash that:
76
+ 1. Includes a hash from every registered table row
77
+ 2. Links to the previous Spider Hash (forming a chain)
78
+ 3. Gets anchored permanently on your blockchain
79
+
80
+ If someone changes `wallets.balance` after a mint — the Spider Hash from that mint no longer matches. Tamper detected.
81
+
82
+ ---
83
+
84
+ ## Installation
85
+
86
+ ```bash
87
+ pip install spiderweave
88
+ ```
89
+
90
+ Install with your database driver:
91
+
92
+ ```bash
93
+ pip install spiderweave[supabase] # Supabase
94
+ pip install spiderweave[postgres] # PostgreSQL / MySQL
95
+ pip install spiderweave[evm] # Ethereum / Polygon / EVM chains
96
+ pip install spiderweave[all] # Everything
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Quick Start
102
+
103
+ ### With Supabase + PlayWebit
104
+
105
+ ```python
106
+ from spiderweave import SpiderWeave
107
+ from spiderweave.adapters.supabase_adapter import SupabaseAdapter
108
+ from spiderweave.adapters.playwebit_adapter import PlayWebitAdapter
109
+
110
+ # Connect your database and blockchain
111
+ sc = SpiderWeave(
112
+ db_adapter=SupabaseAdapter(
113
+ url="https://your-project.supabase.co",
114
+ key="your-anon-key"
115
+ ),
116
+ blockchain_adapter=PlayWebitAdapter(
117
+ node_url="https://your-playwebit-node.hf.space"
118
+ )
119
+ )
120
+
121
+ # Tell SpiderWeave which tables to watch
122
+ sc.register_table("nfts", lookup_key="token_id")
123
+ sc.register_table("wallets", lookup_key="user_id")
124
+ sc.register_table("sessions", lookup_key="user_id")
125
+ sc.register_table("marketplace", lookup_key="token_id")
126
+
127
+ # When a user mints an NFT — create and anchor the Spider Hash
128
+ result = sc.create_and_anchor(
129
+ chain_id="token_abc123",
130
+ event_type="mint",
131
+ event_context={
132
+ "token_id": "abc123",
133
+ "user_id": "0xabc..."
134
+ }
135
+ )
136
+
137
+ print(result["spider_hash"]) # 64-char hash stored on blockchain
138
+ print(result["tx_hash"]) # blockchain transaction proof
139
+ ```
140
+
141
+ ### With PostgreSQL + Ethereum
142
+
143
+ ```python
144
+ from spiderweave import SpiderWeave
145
+ from spiderweave.adapters.postgres_adapter import PostgresAdapter
146
+ from spiderweave.adapters.evm_adapter import EVMAdapter
147
+
148
+ sc = SpiderWeave(
149
+ db_adapter=PostgresAdapter(
150
+ connection_string="postgresql://user:pass@localhost:5432/mydb"
151
+ ),
152
+ blockchain_adapter=EVMAdapter(
153
+ rpc_url="https://mainnet.infura.io/v3/YOUR_KEY",
154
+ private_key="0x..."
155
+ )
156
+ )
157
+
158
+ sc.register_table("users", lookup_key="user_id")
159
+ sc.register_table("orders", lookup_key="order_id", is_anchor=True)
160
+ sc.register_table("payments", lookup_key="order_id")
161
+
162
+ result = sc.create_and_anchor(
163
+ chain_id="order_99",
164
+ event_type="payment_confirmed",
165
+ event_context={"order_id": "99", "user_id": "42"}
166
+ )
167
+ ```
168
+
169
+ ### Hash Only (No Blockchain)
170
+
171
+ ```python
172
+ sc = SpiderWeave(db_adapter=SupabaseAdapter(url="...", key="..."))
173
+
174
+ sc.register_table("documents", lookup_key="doc_id")
175
+ sc.register_table("authors", lookup_key="user_id")
176
+
177
+ hash_result = sc.create_spider_hash(
178
+ chain_id="doc_001",
179
+ event_context={"doc_id": "001", "user_id": "author_1"}
180
+ )
181
+
182
+ print(hash_result["spider_hash"])
183
+ print(hash_result["table_hashes"]) # hash from each individual table
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Verifying Integrity
189
+
190
+ ```python
191
+ # Later — verify nothing has changed
192
+ result = sc.verify(
193
+ chain_id="token_abc123",
194
+ event_context={"token_id": "abc123", "user_id": "0xabc..."},
195
+ stored_hash="the-spider-hash-from-your-blockchain",
196
+ stored_timestamp=1716000000000
197
+ )
198
+
199
+ if result["valid"]:
200
+ print("Data integrity confirmed")
201
+ else:
202
+ print("TAMPER DETECTED")
203
+ print(result["table_hashes"]) # see which tables changed
204
+ ```
205
+
206
+ ---
207
+
208
+ ## Detecting Tampering
209
+
210
+ ```python
211
+ from spiderweave.exceptions import TamperDetectedError
212
+
213
+ try:
214
+ sc.detect_tamper(chain_id="token_abc123")
215
+ print("Chain is clean")
216
+ except TamperDetectedError as e:
217
+ print(f"Tamper detected at event {e.broken_at}")
218
+ print(f"Compromised hash: {e.broken_hash}")
219
+ ```
220
+
221
+ ---
222
+
223
+ ## View Chain History
224
+
225
+ ```python
226
+ history = sc.get_chain_history("token_abc123")
227
+
228
+ for event in history:
229
+ print(event["event_type"], event["spider_hash"][:16], event["timestamp"])
230
+
231
+ # mint a3f9c2b1... 1716000000000
232
+ # list_sale b7d4e8f2... 1716001000000
233
+ # transfer c9a1f3d5... 1716002000000
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Writing a Custom Database Adapter
239
+
240
+ If you use MongoDB, Firebase, DynamoDB, or any other database — write a custom adapter in 5 methods:
241
+
242
+ ```python
243
+ from spiderweave.adapters.base_adapter import BaseDBAdapter
244
+ import hashlib, json
245
+
246
+ class MongoDBAdapter(BaseDBAdapter):
247
+
248
+ def __init__(self, connection_string, database_name):
249
+ from pymongo import MongoClient
250
+ self.db = MongoClient(connection_string)[database_name]
251
+
252
+ def get_row_hash(self, table, row_id):
253
+ row = self.db[table].find_one({"_id": row_id})
254
+ if not row:
255
+ return "0" * 64
256
+ row.pop("_id", None)
257
+ return hashlib.sha256(
258
+ json.dumps(row, sort_keys=True, default=str).encode()
259
+ ).hexdigest()
260
+
261
+ def get_table_chain(self, table, row_id):
262
+ return list(
263
+ self.db["spider_chain_events"]
264
+ .find({"table_name": table, "row_id": row_id})
265
+ .sort("timestamp", 1)
266
+ )
267
+
268
+ def get_chain_history(self, chain_id, before_timestamp=None, limit=50):
269
+ query = {"chain_id": chain_id}
270
+ if before_timestamp:
271
+ query["timestamp"] = {"$lt": before_timestamp}
272
+ return list(
273
+ self.db["spider_chain_events"]
274
+ .find(query)
275
+ .sort("timestamp", -1)
276
+ .limit(limit)
277
+ )
278
+
279
+ def save_chain_event(self, event):
280
+ self.db["spider_chain_events"].insert_one(event)
281
+
282
+ def get_rows_for_event(self, table_config, event_context):
283
+ rows = {}
284
+ for table_def in table_config:
285
+ name = table_def["name"]
286
+ key = table_def.get("lookup_key", "_id")
287
+ val = event_context.get(key)
288
+ row = self.db[name].find_one({key: val}) or {}
289
+ row.pop("_id", None)
290
+ rows[name] = row
291
+ return rows
292
+ ```
293
+
294
+ Then use it exactly like the built-in adapters:
295
+
296
+ ```python
297
+ sc = SpiderWeave(
298
+ db_adapter=MongoDBAdapter("mongodb://localhost", "mydb"),
299
+ blockchain_adapter=EVMAdapter(rpc_url="...")
300
+ )
301
+ ```
302
+
303
+ ---
304
+
305
+ ## Writing a Custom Blockchain Adapter
306
+
307
+ For any blockchain not supported out of the box:
308
+
309
+ ```python
310
+ from spiderweave.adapters.base_blockchain_adapter import BaseBlockchainAdapter
311
+
312
+ class SolanaAdapter(BaseBlockchainAdapter):
313
+
314
+ def __init__(self, rpc_url, keypair_path):
315
+ self.rpc_url = rpc_url
316
+ self.keypair_path = keypair_path
317
+
318
+ def anchor_hash(self, spider_hash, chain_id, event_type, metadata=None):
319
+ # Write spider_hash to Solana via memo instruction
320
+ # Return the transaction signature
321
+ tx_sig = self._submit_memo(spider_hash)
322
+ return tx_sig
323
+
324
+ def verify_on_chain(self, tx_hash):
325
+ # Look up the transaction on Solana
326
+ tx = self._get_transaction(tx_hash)
327
+ return {
328
+ "verified": tx is not None,
329
+ "spider_hash": self._extract_hash(tx),
330
+ "block_number": tx.get("slot"),
331
+ "timestamp": tx.get("blockTime")
332
+ }
333
+
334
+ def get_anchored_hashes(self, chain_id, limit=50):
335
+ return []
336
+ ```
337
+
338
+ ---
339
+
340
+ ## Required Database Table
341
+
342
+ SpiderWeave needs one table in your database to store chain events:
343
+
344
+ ```sql
345
+ CREATE TABLE spider_chain_events (
346
+ id SERIAL PRIMARY KEY,
347
+ chain_id VARCHAR(255) NOT NULL,
348
+ spider_hash VARCHAR(64) NOT NULL,
349
+ event_type VARCHAR(100) NOT NULL,
350
+ timestamp BIGINT NOT NULL,
351
+ metadata JSONB,
352
+ previous_hash VARCHAR(64)
353
+ );
354
+
355
+ CREATE INDEX idx_spider_chain_chain_id ON spider_chain_events(chain_id);
356
+ CREATE INDEX idx_spider_chain_timestamp ON spider_chain_events(timestamp);
357
+ ```
358
+
359
+ For Supabase, run this SQL in your project's SQL editor.
360
+
361
+ ---
362
+
363
+ ## API Reference
364
+
365
+ ### `SpiderWeave(db_adapter, blockchain_adapter=None)`
366
+ Main SDK class. Create one instance per application.
367
+
368
+ ### `.register_table(table_name, lookup_key="id", is_anchor=False)`
369
+ Register a table to participate in Spider Hash calculation. Returns `self` for chaining.
370
+
371
+ ### `.create_and_anchor(chain_id, event_type, event_context, metadata=None)`
372
+ Calculate Spider Hash and anchor it on-chain. Returns full result dict.
373
+
374
+ ### `.create_spider_hash(chain_id, event_context, timestamp=None)`
375
+ Calculate Spider Hash without anchoring. Returns hash result dict.
376
+
377
+ ### `.anchor(spider_hash, chain_id, event_type, metadata=None)`
378
+ Anchor an existing Spider Hash on-chain.
379
+
380
+ ### `.verify(chain_id, event_context, stored_hash, stored_timestamp)`
381
+ Verify current database state matches a stored Spider Hash.
382
+
383
+ ### `.detect_tamper(chain_id)`
384
+ Walk chain history and detect broken links. Raises `TamperDetectedError` if found.
385
+
386
+ ### `.get_chain_history(chain_id, limit=50)`
387
+ Return the event history for a chain.
388
+
389
+ ---
390
+
391
+ ## Exceptions
392
+
393
+ | Exception | When raised |
394
+ |---|---|
395
+ | `TamperDetectedError` | Chain integrity check fails |
396
+ | `ChainBrokenError` | Chain sequence is broken |
397
+ | `AdapterNotConfiguredError` | Missing db or blockchain adapter |
398
+ | `InvalidHashError` | Malformed hash value |
399
+ | `TableNotRegisteredError` | Using an unregistered table |
400
+
401
+ ---
402
+
403
+ ## Research & Citation
404
+
405
+ SpiderWeave Hash Architecture is an original invention described in:
406
+
407
+ > *SpiderWeave Hash Architecture: Cross-Table Tamper Detection for Off-Chain Blockchain Data*
408
+ > Priyanshu Chauhan / PlayWebit Research, 2026
409
+
410
+ If you use SpiderWeave SDK in academic work, please cite the above paper.
411
+
412
+ ---
413
+
414
+ ## License
415
+
416
+ MIT License. See LICENSE file for details.
417
+
418
+ ---
419
+
420
+ ## Contributing
421
+
422
+ SpiderWeave is open to community adapters for new databases and blockchains.
423
+ To contribute an adapter, implement `BaseDBAdapter` or `BaseBlockchainAdapter`
424
+ and open a pull request.