Zapier Bitcoin Automation: Webhook trust boundaries
Zapier Bitcoin Automation: Webhook trust boundaries
Research question
How can a Zapier workflow request a Bitcoin balance without letting arbitrary workflow inputs determine wallet credentials, network or endpoint? This study separates orchestration from execution. The workflow proposes an operation; a trusted local process validates it and queries the engine.
Proposed workflow design
Use a trigger and a webhook action to submit an event to an authenticated intermediary. A hosted Zap cannot reach your own loopback address. Do not expose the wallet engine directly.
The following Python fragment illustrates the execution boundary, not a native Zapier connector or an importable workflow. For hosted deployments, use a separately authenticated and authorized intermediary with TLS, rate limits and minimal responses. Loopback in a cloud runner or container refers to that runner or container, not the wallet owner's machine. Do not publish the engine port to solve this routing problem.
Source implementation
1import json
2import os
3from urllib.request import Request, build_opener, ProxyHandler, HTTPRedirectHandler
4
5class NoRedirect(HTTPRedirectHandler):
6 def redirect_request(self, *args, **kwargs):
7 raise ValueError("Redirect refused")
8
9def balance():
10 req = Request("http://127.0.0.1:7070/api/v5/btc/wallet/balance",
11 data=b'{"net":"test","type":"segwit"}',
12 headers={"Content-Type":"application/json", "X-BTC-KEY":os.environ["BTC_KEY"]}, method="POST")
13 with build_opener(ProxyHandler({}), NoRedirect()).open(req, timeout=15) as response:
14 raw = response.read(1048577)
15 if len(raw) > 1048576:
16 raise ValueError("Response too large")
17 obj = json.loads(raw)
18 if obj.get("ok") is not True:
19 raise ValueError("Engine rejected request")
20 sats = obj["result"]["balance_sat"]
21 if type(sats) is not int or sats < 0:
22 raise ValueError("Invalid balance")
23 return {"net":"test", "type":"segwit", "balance_sat":sats}
24
25def run(event):
26 # Call only AFTER external authentication and rate limiting.
27 if event != {"operation":"balance"}:
28 raise ValueError("Unexpected webhook input")
29 return balance()
30
31if __name__ == "__main__":
32 print(json.dumps(run({'operation': 'balance'})))Execution contract
The example accepts only the fixed event {'operation': 'balance'}. The engine request is POST /api/v5/btc/wallet/balance with net=test and type=segwit. BTC_KEY is read locally from the environment. Redirects and environment proxies are disabled; response size and timeout are bounded. The success envelope and integer balance are checked before returning an observation. A zero balance is a valid observation, not an error. A failed request must never be represented as zero.
Deployment and privacy
Run the fragment with Python 3 and a restored Testnet wallet on a trusted host. The platform must not receive BTC_KEY in a webhook body, workflow export, execution history or model prompt. Restrict access to the execution process itself: the underlying key may authorize spending even though this fragment exposes only balance. Protect observations as private financial data. A scheduled or repeated balance query is not evidence of a new payment. Do not trigger fulfillment from a balance difference alone; use transaction-specific evidence and confirmation policy.
Failure cases and limitations
Reject unexpected events before accessing the engine. Treat malformed responses, timeouts and warming or unavailable state as failures, not as successful observations. For production, add authentication, authorization, monitoring and a bounded polling policy outside this fragment. No SEND, wallet creation, recovery or removal is exposed. No live platform or engine tests were performed. The platform design is conceptual; current node configuration and version compatibility must be checked against official documentation. The signed wallet fee law and engine remain unchanged.
References
- Platform documentation: https://help.zapier.com/
- Engine API: https://thamer.org/api
- Engine: https://thamer.org/engine
- Source repository: https://thamer.org/repo/
