@glacislabs/stablegenie-zerodelta 2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Glacis Labs
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.
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # @glacislabs/stablegenie-zerodelta
2
+
3
+ A lightweight, embeddable **ZeroDelta payment + swap widget**. Two variants share one
4
+ dependency-free engine:
5
+
6
+ - **`<StableGeniePay>`** — *exact-receive*. A merchant/dApp needs exactly `X` USDC on chain `Y` at
7
+ address `Z`; the user pays in any supported asset/chain and ZeroDelta routes to the exact receive.
8
+ - **`<StableGenieSwap>`** — *exact-in* swap between supported assets/chains (li.fi-style).
9
+
10
+ The user's own wallet always owns the final signature — the widget never holds keys and never
11
+ submits silently. Every ZeroDelta quote is re-validated (`assertQuoteMatchesSelection`), every
12
+ planned transaction is re-decoded before signing (`validatePlannedTransaction`), and the settling
13
+ transaction is confirmed on-chain in a trusted realm (`verifySubmittedTx`).
14
+
15
+ Supported chains: Ethereum, Optimism, Arbitrum, Base, Ink, Unichain, Plasma, Sonic.
16
+ Supported assets: USDC, USDT, USDE, XAUT. (Card/fiat rails are roadmap, not shipped.)
17
+
18
+ ## Install (React host)
19
+
20
+ ```sh
21
+ npm i @glacislabs/stablegenie-zerodelta
22
+ ```
23
+
24
+ No registry configuration and no auth token are needed — the package is published publicly to
25
+ npmjs.com with [npm provenance](https://docs.npmjs.com/generating-provenance-statements), so you can
26
+ verify on the package page that a given tarball was built by this repo's release workflow.
27
+
28
+ `react` and `react-dom` are **required peerDependencies** for the main entry (they are kept external
29
+ in the ESM/CJS builds, so the host's React is reused — no double bundle). CSS is auto-injected; there
30
+ is no stylesheet to import.
31
+
32
+ ### Entry points
33
+
34
+ | Import | Contains | React required |
35
+ |---|---|---|
36
+ | `@glacislabs/stablegenie-zerodelta` | the React components (`StableGeniePay`, `StableGenieSwap`, `StableGenieExchange`, `StableGenieProvider`) | **yes** |
37
+ | `…/core` | the framework-agnostic engine — quoting, routing, encoding, the pre-sign validator and the on-chain verifier | **no** |
38
+ | `…/mount` | imperative `mountPay` / `mountSwap` for non-React hosts | yes (bundled by the host build) |
39
+ | `…/standalone` | the prebuilt IIFE with React bundled in, for plain `<script>` embeds | no |
40
+
41
+ Use `…/core` if you want the routing/validation engine without pulling in React — it is verifiably
42
+ React-free (zero references in the emitted ESM, CJS and `.d.ts`).
43
+
44
+ ```tsx
45
+ import { StableGeniePay } from "@glacislabs/stablegenie-zerodelta";
46
+
47
+ <StableGeniePay
48
+ recipient="0x…" // merchant deposit address
49
+ toChainId={42161} // Arbitrum
50
+ toAsset="USDC"
51
+ amount="250.00" // recipient receives exactly this
52
+ apiBase="/api/widget/v1" // same-origin keyless proxy (default)
53
+ provider={eip1193} // optional: inject the host wallet (e.g. wagmi connector)
54
+ onSuccess={({ hash }) => console.log("paid", hash)}
55
+ />
56
+ ```
57
+
58
+ ```tsx
59
+ import { StableGenieSwap } from "@glacislabs/stablegenie-zerodelta";
60
+
61
+ <StableGenieSwap defaultFromAsset="USDT" defaultFromChainId={42161} defaultToAsset="USDC" defaultToChainId={8453} />
62
+ ```
63
+
64
+ ## Embed (plain `<script>`, no React on the host)
65
+
66
+ ```html
67
+ <div id="sg"></div>
68
+ <script src="/vendor/standalone.global.js"></script>
69
+ <script>
70
+ StableGenieWidget.mountPay(document.getElementById("sg"), {
71
+ recipient: "0x…", toChainId: 42161, toAsset: "USDC", amount: "250.00",
72
+ });
73
+ </script>
74
+ ```
75
+
76
+ The `standalone.global.js` build bundles React; the ESM/CJS builds keep it external.
77
+
78
+ **Getting the file.** It ships in the package at `dist/standalone.global.js`, reachable as the
79
+ `./standalone` export. Copy it into your own static assets as part of your build, e.g.
80
+
81
+ ```jsonc
82
+ // package.json
83
+ "scripts": {
84
+ "vendor:widget": "cp node_modules/@glacislabs/stablegenie-zerodelta/dist/standalone.global.js public/vendor/"
85
+ }
86
+ ```
87
+
88
+ **Or load it from a CDN.** The `unpkg` and `jsdelivr` fields point at the standalone build:
89
+
90
+ ```html
91
+ <script src="https://unpkg.com/@glacislabs/stablegenie-zerodelta"></script>
92
+ <!-- or -->
93
+ <script src="https://cdn.jsdelivr.net/npm/@glacislabs/stablegenie-zerodelta"></script>
94
+ ```
95
+
96
+ ★ For production, pin an exact version (`…/stablegenie-zerodelta@1.1.0`) rather than tracking
97
+ `latest`, and prefer self-hosting if your CSP disallows third-party script origins — this widget
98
+ sits in a payment path.
99
+
100
+ ## Configuration
101
+
102
+ | Prop | Default | Notes |
103
+ |---|---|---|
104
+ | `apiBase` | `/api/widget/v1` | Same-origin keyless proxy (server injects the ZeroDelta key). |
105
+ | `apiKey` | — | Not needed against the keyless proxy. Attached **only** to a same-origin (relative) `apiBase`, or to an absolute one matching `trustedApiOrigin`. |
106
+ | `trustedApiOrigin` | — | The single absolute origin permitted to receive `apiKey`, e.g. `https://pay.example.com`. Omit and no absolute origin is trusted — same-origin only. |
107
+ | `provider` | EIP-6963 / `window.ethereum` | Inject the host's EIP-1193 provider to reuse an existing connection. |
108
+ | `theme` | light/dark | `{ accent, bg, surface, text, border, radius, font, mode }` — mirrors the ZeroDelta palette. |
109
+ | `rpcOverrides` | registry / bundled | Per-chain RPC for on-chain settlement verification. |
110
+
111
+ `StableGenieProvider` can supply these once for multiple widgets.
112
+
113
+ > **On `trustedApiOrigin`.** The widget deliberately ships **no** default trusted origin. The
114
+ > ZeroDelta API is reached through a server-side proxy that injects the key, so the browser normally
115
+ > holds no credential at all — and the proxy origin differs per integrator deployment, so there is no
116
+ > single correct value to bake in. Set this only to an origin you control: it is the one destination
117
+ > permitted to receive your key.
118
+
119
+ ## Security model
120
+
121
+ The wallet always owns the final signature. In addition:
122
+
123
+ - **The escrow address is pinned offline** per chain (`CANONICAL_ESCROW`) and cross-checked against
124
+ the quote and the chain registry. Because both of those come from the same API, the offline pin is
125
+ what makes the check meaningful — the widget fails closed on a mismatch.
126
+ - **Every quote is re-validated** against your selection (`assertQuoteMatchesSelection`): owner,
127
+ receiver, both tokens, both chains, both amounts, and a bounded deadline. Min-received is enforced
128
+ on the encoded calldata, not trusted from the response.
129
+ - **Every planned transaction is re-decoded before signing** (`validatePlannedTransaction`) and its
130
+ `value` bound to the plan. Approvals are exact-amount — never unbounded.
131
+ - **Settlement is confirmed by receipt.** `verifySubmittedTx` requires an
132
+ `eth_getTransactionReceipt` with status `0x1` over a bundled public RPC before reporting success.
133
+ A broadcast-but-unmined or reverted transaction surfaces as `pending`/`reverted`, and **`onSuccess`
134
+ does not fire** for either — treat that callback as "the money moved", because that is what it means.
135
+ - **No telemetry.** The only network calls are to your `apiBase` and to the RPC used for verification.
136
+
137
+ ## Develop
138
+
139
+ ```sh
140
+ npm i
141
+ npm run lint # biome — also runs in CI ahead of typecheck
142
+ npm run typecheck # tsc --noEmit
143
+ npm test # vitest — engine (node) + DOM behaviour (happy-dom)
144
+ npm run build # tsup → dist/ (ESM + CJS + d.ts + standalone.global.js)
145
+ npm run dev # tsup --watch
146
+ ```
147
+
148
+ Requires Node ≥ 20 (`engines`); CI verifies on 22.x.
149
+
150
+ The vitest suite encodes the engine's security invariants (encoders, exact-out/in solvers,
151
+ `assertQuoteMatchesSelection`, `buildRoute` native-value bounds, `validatePlannedTransaction`,
152
+ `verifySubmittedTx`, and the API-key destination gate). Treat it as the release gate: a change that
153
+ relaxes one of those checks should fail here first.
154
+
155
+ Tests run in **node** by default. Files under `test/dom/` opt into a DOM with
156
+ `// @vitest-environment happy-dom`; that is where the React behaviour lives, notably the
157
+ verdict→UI mapping that decides whether a payment is reported as settled.