@tabai/sdk 0.2.3 → 0.2.5
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/README.md +12 -9
- package/dist/_shared/abi.d.ts.map +1 -1
- package/dist/_shared/abi.js +6 -3
- package/dist/_shared/abi.js.map +1 -1
- package/dist/_shared/chains.d.ts +4 -6
- package/dist/_shared/chains.d.ts.map +1 -1
- package/dist/_shared/chains.js +1 -2
- package/dist/_shared/chains.js.map +1 -1
- package/dist/_shared/keccak256.d.ts +6 -6
- package/dist/_shared/keccak256.js +6 -6
- package/dist/_shared/keccak256.js.map +1 -1
- package/dist/_shared/result.d.ts +5 -6
- package/dist/_shared/result.d.ts.map +1 -1
- package/dist/_shared/result.js +5 -6
- package/dist/_shared/result.js.map +1 -1
- package/dist/cli/client-config.d.ts +4 -5
- package/dist/cli/client-config.d.ts.map +1 -1
- package/dist/cli/client-config.js +4 -5
- package/dist/cli/client-config.js.map +1 -1
- package/dist/cli/connect.d.ts +1 -3
- package/dist/cli/connect.d.ts.map +1 -1
- package/dist/cli/connect.js +5 -3
- package/dist/cli/connect.js.map +1 -1
- package/dist/cli/doctor.d.ts +1 -3
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +1 -3
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/main.d.ts +1 -3
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +7 -6
- package/dist/cli/main.js.map +1 -1
- package/dist/errors.d.ts +2 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -4
- package/dist/errors.js.map +1 -1
- package/dist/http/client-402.d.ts +11 -13
- package/dist/http/client-402.d.ts.map +1 -1
- package/dist/http/client-402.js +12 -14
- package/dist/http/client-402.js.map +1 -1
- package/dist/http/headers.d.ts +9 -11
- package/dist/http/headers.d.ts.map +1 -1
- package/dist/http/headers.js +9 -11
- package/dist/http/headers.js.map +1 -1
- package/dist/http/index.d.ts +0 -2
- package/dist/http/index.d.ts.map +1 -1
- package/dist/http/index.js +0 -2
- package/dist/http/index.js.map +1 -1
- package/dist/http/metering-claim.d.ts +0 -2
- package/dist/http/metering-claim.d.ts.map +1 -1
- package/dist/http/metering-claim.js +0 -2
- package/dist/http/metering-claim.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -12
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -4
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +1 -4
- package/dist/logger.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/json-schema.d.ts +1 -3
- package/dist/mcp/json-schema.d.ts.map +1 -1
- package/dist/mcp/json-schema.js +1 -3
- package/dist/mcp/json-schema.js.map +1 -1
- package/dist/mcp/json.d.ts +0 -2
- package/dist/mcp/json.d.ts.map +1 -1
- package/dist/mcp/json.js +0 -2
- package/dist/mcp/json.js.map +1 -1
- package/dist/mcp/registry-client.d.ts +0 -2
- package/dist/mcp/registry-client.d.ts.map +1 -1
- package/dist/mcp/registry-client.js +3 -4
- package/dist/mcp/registry-client.js.map +1 -1
- package/dist/mcp/schemas.d.ts +10 -8
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +5 -7
- package/dist/mcp/schemas.js.map +1 -1
- package/dist/mcp/server.d.ts +0 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +4 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/settings.d.ts +5 -1
- package/dist/mcp/settings.d.ts.map +1 -1
- package/dist/mcp/settings.js +28 -3
- package/dist/mcp/settings.js.map +1 -1
- package/dist/mcp/toolset.d.ts +2 -5
- package/dist/mcp/toolset.d.ts.map +1 -1
- package/dist/mcp/toolset.js +3 -6
- package/dist/mcp/toolset.js.map +1 -1
- package/dist/payments/config.d.ts +6 -8
- package/dist/payments/config.d.ts.map +1 -1
- package/dist/payments/config.js +5 -7
- package/dist/payments/config.js.map +1 -1
- package/dist/payments/index.d.ts +0 -2
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +0 -2
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/registry.d.ts +11 -12
- package/dist/payments/registry.d.ts.map +1 -1
- package/dist/payments/registry.js +11 -12
- package/dist/payments/registry.js.map +1 -1
- package/dist/payments/strategy.d.ts +9 -5
- package/dist/payments/strategy.d.ts.map +1 -1
- package/dist/payments/strategy.js +9 -5
- package/dist/payments/strategy.js.map +1 -1
- package/dist/proxy/hooks.d.ts +3 -5
- package/dist/proxy/hooks.d.ts.map +1 -1
- package/dist/proxy/hooks.js +2 -4
- package/dist/proxy/hooks.js.map +1 -1
- package/dist/proxy/index.d.ts +2 -2
- package/dist/proxy/index.js +2 -2
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/proxy.d.ts +3 -5
- package/dist/proxy/proxy.d.ts.map +1 -1
- package/dist/proxy/proxy.js +2 -4
- package/dist/proxy/proxy.js.map +1 -1
- package/dist/server/adapters/express.d.ts +0 -2
- package/dist/server/adapters/express.d.ts.map +1 -1
- package/dist/server/adapters/express.js +0 -2
- package/dist/server/adapters/express.js.map +1 -1
- package/dist/server/adapters/hono.d.ts +0 -2
- package/dist/server/adapters/hono.d.ts.map +1 -1
- package/dist/server/adapters/hono.js +0 -2
- package/dist/server/adapters/hono.js.map +1 -1
- package/dist/server/adapters/next.d.ts +0 -2
- package/dist/server/adapters/next.d.ts.map +1 -1
- package/dist/server/adapters/next.js +0 -2
- package/dist/server/adapters/next.js.map +1 -1
- package/dist/server/index.d.ts +5 -5
- package/dist/server/index.js +5 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/metering.d.ts +9 -11
- package/dist/server/metering.d.ts.map +1 -1
- package/dist/server/metering.js +6 -8
- package/dist/server/metering.js.map +1 -1
- package/dist/server/post-paid.d.ts +8 -10
- package/dist/server/post-paid.d.ts.map +1 -1
- package/dist/server/post-paid.js +7 -9
- package/dist/server/post-paid.js.map +1 -1
- package/dist/x402/client.d.ts +5 -6
- package/dist/x402/client.d.ts.map +1 -1
- package/dist/x402/client.js +6 -7
- package/dist/x402/client.js.map +1 -1
- package/dist/x402/server.d.ts +5 -5
- package/dist/x402/server.d.ts.map +1 -1
- package/dist/x402/server.js +2 -2
- package/dist/x402/server.js.map +1 -1
- package/dist/x402/wire.d.ts +1 -1
- package/dist/x402/wire.js +1 -1
- package/dist/x402/wire.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tabai/sdk
|
|
2
2
|
|
|
3
|
-
**Post-paid billing for autonomous agents on Monad.** Your agent calls a priced tool, gets the result
|
|
3
|
+
**Post-paid billing for autonomous agents on Monad.** Your agent calls a priced tool, gets the result in the block its charge is recorded in, and settles the bill later with its own keys. No prepayment, no held responses, no API key bought in advance.
|
|
4
4
|
|
|
5
5
|
This package is three things in one: an **MCP server** exposing four tools to any MCP client, a **CLI**, and a **TypeScript library** for building on the rail directly.
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ That is the whole setup step. It finds your MCP client's configuration file, bac
|
|
|
14
14
|
|
|
15
15
|
## What is behind it
|
|
16
16
|
|
|
17
|
-
A Service meters your agent's usage into an **Open Tab** held in `TabBook` on Monad. Your agent settles that tab in USDC on the same chain, whenever it likes, signing with keys nobody else holds.
|
|
17
|
+
A Service meters your agent's usage into an **Open Tab** held in `TabBook` on Monad. Your agent settles that tab in USDC or AUSD on the same chain, whenever it likes, signing with keys nobody else holds.
|
|
18
18
|
|
|
19
19
|
Settlement is one transaction. `TabSettlement.settle` moves the Asset to the Service's collection address and applies the Settlement to the Open Tab in the same block, atomically. There is no facilitator, no oracle, no bridge and no waiting: the transfer and the credit are the same state change, so nobody has to be trusted to say the money arrived.
|
|
20
20
|
|
|
@@ -56,7 +56,7 @@ Each tool declares a JSON Schema for its input and its output, and validates its
|
|
|
56
56
|
| `tab_discover` | Lists Services, the assets each accepts, what each tool costs, and the Bond each has staked | nothing, and needs no key |
|
|
57
57
|
| `tab_call` | Calls a metered tool. The charge lands on the Open Tab and is settled later. With an x402 signer configured, a refusal that carries an x402 offer is prepaid instead | nothing at call time, unless it prepays |
|
|
58
58
|
| `tab_status` | Credit limit, Open Tab, prepaid credit and headroom, per asset, with recent Settlements | nothing, and needs no key |
|
|
59
|
-
| `tab_settle` | Pays down an Open Tab by sending a Settlement with the agent's own key | real funds |
|
|
59
|
+
| `tab_settle` | Pays down an Open Tab by sending a Settlement with the agent's own key, or a Permit2 signature through the relay | real funds |
|
|
60
60
|
|
|
61
61
|
Start with `tab_discover`, because `tab_call` needs a `serviceId` from its list.
|
|
62
62
|
|
|
@@ -98,7 +98,7 @@ The same package is a CLI. Every command reads the chain; one of them writes to
|
|
|
98
98
|
| `mcp` | Serves the four tools over MCP. This is what a client launches | nothing |
|
|
99
99
|
| `doctor` | Checks the installation against the live deployment | nothing, and needs no key |
|
|
100
100
|
| `status` | What an agent owes, may still spend, and has settled | nothing, and needs no key |
|
|
101
|
-
| `settle` | Pays down an Open Tab | real funds, and only with `--broadcast` |
|
|
101
|
+
| `settle` | Pays down an Open Tab, with the agent's key or, with `--strategy monad-relayed`, by a Permit2 signature the gateway submits | real funds, and only with `--broadcast` |
|
|
102
102
|
|
|
103
103
|
`settle` is a dry run unless you ask otherwise. It checks the Service accepts the Asset, quotes the amount, and stops:
|
|
104
104
|
|
|
@@ -192,7 +192,8 @@ The key is read at the moment a Settlement is built, and never from this file. `
|
|
|
192
192
|
| `TAB_BOOK_ADDRESS`, `TAB_SETTLEMENT_ADDRESS`, `SERVICE_REGISTRY_ADDRESS`, `BOND_ADDRESS` | resolving credit, Services and Bond |
|
|
193
193
|
| `NEXT_PUBLIC_REGISTRY_API_URL` | the Service directory and an agent's history. Defaults to the project's hosted registry for the chosen network |
|
|
194
194
|
| `TAB_HOSTED_DEFAULTS` | `off` stops the hosted registry and demo Service from filling in what you did not configure |
|
|
195
|
-
| `
|
|
195
|
+
| `AGENT_ADDRESS` | the Agent a metered call lands on, when `tab.config` names none. Public, so `connect` copies it into the MCP stanza |
|
|
196
|
+
| `AGENT_PRIVATE_KEY` | broadcasting a Settlement, signing a Permit2 witness, paying an x402 offer, or signing a call to the hosted demo Service, and nothing else. Never written to a configuration file |
|
|
196
197
|
|
|
197
198
|
---
|
|
198
199
|
|
|
@@ -218,6 +219,7 @@ The main surfaces:
|
|
|
218
219
|
| `createX402FrontedProxy`, `createX402UpstreamPricing` | Buy now, pay later: front an x402 upstream, pay it, and meter the Agent |
|
|
219
220
|
| `fetchHubManifest` | Monad's API Hub manifest, as tools of the Service fronting a provider |
|
|
220
221
|
| `createMonadStrategy`, `createStrategyRegistry` | The Monad payment strategy, and the registry that resolves strategies |
|
|
222
|
+
| `createRelayedMonadStrategy`, `signSettlementPermit` | Gasless settlement: a Permit2 witness the Agent signs and a relay submits |
|
|
221
223
|
| `createKuruFundedStrategy`, `createKuruOnchainRouter` | Settle in any asset: swap the shortfall in through Kuru before the Monad strategy settles |
|
|
222
224
|
| `revertMappingFor` | The single table mapping a contract revert to a category, code, disposition and remedy |
|
|
223
225
|
|
|
@@ -237,7 +239,7 @@ A gateway anyone can reach requires a signature on every metered call, and the A
|
|
|
237
239
|
|
|
238
240
|
### Adding a strategy
|
|
239
241
|
|
|
240
|
-
A strategy is how an agent pays. On Monad
|
|
242
|
+
A strategy is how an agent pays. On Monad a tab is paid through `TabSettlement`, by `settle` with the Agent's key or by `settleWithPermit2` with its signature, and the shipped strategies do one each. The seam exists so that a different signer, a smart account, a session key, or a test double can stand behind the same call without the SDK caring which.
|
|
241
243
|
|
|
242
244
|
```ts
|
|
243
245
|
export interface PaymentStrategy {
|
|
@@ -317,7 +319,7 @@ The price is known only after the upstream's `402`, so `pricing` is a book the f
|
|
|
317
319
|
services: [{ serviceId, endpoint, hub: { provider: "defillama", prefix: "apihub" } }]
|
|
318
320
|
```
|
|
319
321
|
|
|
320
|
-
The
|
|
322
|
+
The metering gateway in this repository mounts both: `GATEWAY_HUB_UPSTREAMS` names the upstreams, `X402_ENABLED` and `X402_FACILITATOR_URL` govern the offer on a `402`, and `GATEWAY_COLLECTION_ADDRESS` is the `payTo` fallback when `ServiceRegistry.collectionOf` cannot be read.
|
|
321
323
|
|
|
322
324
|
**What is official and what is not.** The types, the three header codecs and the facilitator HTTP client are `@x402/core`, the reference implementation. The EIP-3009 signing is this package's own, over ethers rather than the reference client's viem, and it is checked two ways: every test recovers the signer with `verifyTypedData`, and the reference client was run over the same authorization while this was written, producing the same signature byte for byte. The request handling is this package's own because the reference server middleware gates every request on payment, which is the model Tab exists to replace.
|
|
323
325
|
|
|
@@ -388,7 +390,7 @@ Tab is deployed on both Monad networks, and `MONAD_CHAIN_ID` picks which one thi
|
|
|
388
390
|
Mainnet USDC is `0x754704Bc059F8C67012fEd69BC8A327a5aafb603` and AUSD is `0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a`.
|
|
389
391
|
Testnet USDC is `0x534b2f3A21130d7a60830c2Df862319e593943A3`, from Circle's faucet; MON for gas comes from `https://faucet.monad.xyz`.
|
|
390
392
|
|
|
391
|
-
A Settlement is final when its block is. **Nothing in an agent's request path waits for anything**: a metered call
|
|
393
|
+
A Settlement is final when its block is. **Nothing in an agent's request path waits for anything**: a metered call returns in the block its charge is recorded in, and headroom is restored in the block the Settlement lands.
|
|
392
394
|
|
|
393
395
|
---
|
|
394
396
|
|
|
@@ -401,7 +403,8 @@ Live on Monad Mainnet and Monad Testnet.
|
|
|
401
403
|
| Registry read API | `https://registry-mainnet-production.up.railway.app` | `https://registry-testnet-production.up.railway.app` |
|
|
402
404
|
| Demo Service `tab.demo` | `https://gateway-mainnet-production.up.railway.app` | `https://gateway-testnet-production-a657.up.railway.app` |
|
|
403
405
|
|
|
404
|
-
**With nothing configured, this package uses them.** `tab_discover` and `tab_status` read the hosted registry for the chosen network,
|
|
406
|
+
**With nothing configured, this package uses them.** `tab_discover` and `tab_status` read the hosted registry for the chosen network, so a fresh `npx -y @tabai/sdk connect` works before you set anything.
|
|
407
|
+
The hosted gateways meter only a signed call, so `tab_call` to the demo Service needs `AGENT_ADDRESS` and `AGENT_PRIVATE_KEY` in the environment, and then signs each call with the Agent's own key.
|
|
405
408
|
Anything you configure wins, and `TAB_HOSTED_DEFAULTS=off` switches the defaults off entirely.
|
|
406
409
|
They are exported as `TAB_HOSTED`.
|
|
407
410
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC;;;GAGG;AACH,eAAO,MAAM,gBAAgB;IAC3B,uGAAuG;;IAEvG,sGAAsG;;IAEtG,wFAAwF;;IAGxF,mFAAmF;;IAEnF,2EAA2E;;IAE3E,mGAAmG;;IAEnG;;;OAGG;;IAEH,mDAAmD;;IAEnD,mDAAmD;;IAEnD,kFAAkF;;CAE1E,CAAC;AAEX,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAE/B,CAAC;AAEhC,sCAAsC;AACtC,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,KAAG,OAA6B,CAAC;AAY5E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,EACtC,+FAAwG,CAAC;AAE3G,oGAAoG;AACpG,eAAO,MAAM,+BAA+B,EAAE,OAAqD,CAAC;AAEpG;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,qKACuE,CAAC;AAEhH,mEAAmE;AACnE,eAAO,MAAM,kCAAkC,EAC7C,sGAA+G,CAAC;AAElH,8DAA8D;AAC9D,eAAO,MAAM,kCAAkC,yQACiC,CAAC;AACjF,eAAO,MAAM,sCAAsC,EAAE,OAEpD,CAAC;AAEF,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,EAAG,SAAkB,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE;;;;EAM7E;AAED;;;;GAIG;AACH,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmBtC,CAAC;AAEX,eAAO,MAAM,0CAA0C,EAAG,2BAAoC,CAAC;AAE/F;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,0iBAO7B,CAAC;AAEX,+EAA+E;AAC/E,eAAO,MAAM,WAAW,iTAKd,CAAC;AAWX;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,qsCAiBhC,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,mvDAclC,CAAC;AAEX,8DAA8D;AAC9D,eAAO,MAAM,wBAAwB;;;;;;;CAO3B,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,wBAAwB,CAAC;AAErE,iFAAiF;AACjF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAEvC,CAAC"}
|
package/dist/_shared/abi.js
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
* indexer, and the dashboard.
|
|
4
4
|
*
|
|
5
5
|
* Only what is fixed and independently checkable lives here: canonical event
|
|
6
|
-
* signatures and the topic hashes derived from them
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* signatures and the topic hashes derived from them, the Permit2 witness types,
|
|
7
|
+
* and short human-readable fragments for the few functions callers reach
|
|
8
|
+
* directly (the Permit2 settlement path on `TabSettlement`, the slice of
|
|
9
|
+
* Permit2 a signer touches, and the ERC-8004 registries). The fragments are
|
|
10
|
+
* transcribed by hand, so each carries only the members a caller uses; the
|
|
11
|
+
* `SettlementApplied` topic is pinned by a test against the compiled `TabBook`.
|
|
9
12
|
*/
|
|
10
13
|
import { keccak256Ascii } from "./keccak256.js";
|
|
11
14
|
/**
|
package/dist/_shared/abi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,uGAAuG;IACvG,iBAAiB,EAAE,4EAA4E;IAC/F,sGAAsG;IACtG,gBAAgB,EAAE,yEAAyE;IAC3F,wFAAwF;IACxF,eAAe,EACb,mGAAmG;IACrG,mFAAmF;IACnF,aAAa,EAAE,+DAA+D;IAC9E,2EAA2E;IAC3E,qBAAqB,EAAE,gDAAgD;IACvE,mGAAmG;IACnG,OAAO,EAAE,0EAA0E;IACnF;;;OAGG;IACH,cAAc,EAAE,iCAAiC;IACjD,mDAAmD;IACnD,UAAU,EAAE,6CAA6C;IACzD,mDAAmD;IACnD,aAAa,EAAE,gDAAgD;IAC/D,kFAAkF;IAClF,QAAQ,EAAE,mCAAmC;CACrC,CAAC;AAKX;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAyC,MAAM,CAAC,WAAW,CAClF,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CACjE,CAAC;AAEhC,sCAAsC;AACtC,MAAM,CAA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D,0DAA0D;IAC1D,0DAA0D;IAC1D,iEAAiE;IACjE,gFAAgF;IAChF,gFAAgF;IAChF,oFAAoF;IACpF,6CAA6C;IAC7C,mFAAmF;IACnF,qFAAqF;IACrF,wHAAwH;IACxH,mFAAmF;CAC3E,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,gKAAgK;IAChK,gEAAgE;IAChE,iIAAiI;IACjI,wKAAwK;IACxK,gLAAgL;IAChL,gRAAgR;IAChR,qFAAqF;IACrF,+DAA+D;IAC/D,uDAAuD;IACvD,6CAA6C;IAC7C,qPAAqP;IACrP,6GAA6G;IAC7G,2KAA2K;CACnK,CAAC;AAEX,8DAA8D;AAC9D,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,UAAU,EAAE,oCAAoC;IAChD,UAAU,EAAE,oCAAoC;IAChD,WAAW,EAAE,0CAA0C;IACvD,WAAW,EAAE,6FAA6F;IAC1G,eAAe,EAAE,yCAAyC;IAC1D,gBAAgB,EAAE,iEAAiE;CAC3E,CAAC;AAIX,iFAAiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAgD,MAAM,CAAC,WAAW,CACjG,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAClE,CAAC","sourcesContent":["/**\n * Contract interface constants shared by the SDK, the gateway, the registry\n * indexer, and the dashboard.\n *\n * Only what is fixed and independently checkable lives here: canonical event\n * signatures and the topic hashes derived from them. Full ABI arrays come from\n * the Foundry artefacts in `packages/contracts/out`, never from a hand\n * transcription, so there is one source of truth for every selector.\n */\nimport { keccak256Ascii } from \"./keccak256.js\";\nimport type { Bytes32 } from \"./hex.js\";\n\n/**\n * Canonical event signatures, the exact strings the topic hash is taken over.\n * No spaces, no parameter names, canonical types.\n */\nexport const EVENT_SIGNATURES = {\n /** `TabBook.SettlementApplied`: a Settlement lowered an Open Tab. `topics[1]` is the settlement id. */\n SettlementApplied: \"SettlementApplied(bytes32,address,bytes32,address,uint256,uint256,uint128)\",\n /** `TabBook.DeliveryRecorded`: a Service metered usage into an Open Tab. `topics[1]` is the Agent. */\n DeliveryRecorded: \"DeliveryRecorded(address,bytes32,address,bytes32,uint32,uint256,uint64)\",\n /** `TabBook.HistoryExtended`: the Agent's history commitment advanced by one record. */\n HistoryExtended:\n \"HistoryExtended(address,address,bytes32,uint32,(bytes32,address,uint128,uint64,uint64,bool,bool))\",\n /** `TabBook.TabDelinquent`: a Settlement Window closed with the tab still open. */\n TabDelinquent: \"TabDelinquent(bytes32,address,bytes32,address,uint128,uint64)\",\n /** `TabBook.TabDelinquencyCleared`: the delinquent tab settled to zero. */\n TabDelinquencyCleared: \"TabDelinquencyCleared(bytes32,address,address)\",\n /** `TabSettlement.Settled`: the Asset moved from the Agent to the Service's Collection address. */\n Settled: \"Settled(bytes32,address,bytes32,address,uint128,uint128,uint128,address)\",\n /**\n * `TabSettlement.SettledGasless`: the Settlement arrived on the Agent's Permit2 signature and\n * `topics[2]` is the relayer that paid for it. Always follows a `Settled` with the same id.\n */\n SettledGasless: \"SettledGasless(bytes32,address)\",\n /** `Bond.BondFunded`: stake entered the escrow. */\n BondFunded: \"BondFunded(bytes32,address,uint128,address)\",\n /** `Bond.BondWithdrawn`: stake left the escrow. */\n BondWithdrawn: \"BondWithdrawn(bytes32,address,uint128,address)\",\n /** ERC-20 `Transfer`, for reading balances and payouts off the Asset contract. */\n Transfer: \"Transfer(address,address,uint256)\",\n} as const;\n\n/** Name of an event whose signature this module pins. */\nexport type EventName = keyof typeof EVENT_SIGNATURES;\n\n/**\n * `topics[0]` for each pinned event: the Keccak-256 hash of its canonical\n * signature. Derived rather than transcribed, so a signature edit cannot leave a\n * stale hash behind.\n */\nexport const EVENT_TOPIC0: Readonly<Record<EventName, Bytes32>> = Object.fromEntries(\n Object.entries(EVENT_SIGNATURES).map(([name, signature]) => [name, keccak256Ascii(signature)]),\n) as Record<EventName, Bytes32>;\n\n/** `topics[0]` for a pinned event. */\nexport const eventTopic0 = (name: EventName): Bytes32 => EVENT_TOPIC0[name];\n\n// ---------------------------------------------------------------------------\n// Gasless Settlement through Permit2\n//\n// `TabSettlement.settleWithPermit2` verifies an EIP-712 signature the Agent\n// made under Permit2's domain, over Permit2's `PermitWitnessTransferFrom` with\n// a Tab-specific witness. Everything a signer needs is pinned here so the SDK\n// cannot drift from the contract: the witness type, the string the contract\n// hands Permit2, and the typed-data layout for `signTypedData`.\n// ---------------------------------------------------------------------------\n\n/**\n * The witness struct, exactly as `TabSettlement.WITNESS_TYPE` declares it.\n * `surface` is the `TabSettlement` address and `chainId` the chain it lives on.\n */\nexport const TAB_SETTLEMENT_WITNESS_TYPE =\n \"TabSettlement(bytes32 serviceId,address asset,uint128 amount,address surface,uint256 chainId)\" as const;\n\n/** `keccak256(TAB_SETTLEMENT_WITNESS_TYPE)`, the same value as `TabSettlement.WITNESS_TYPEHASH`. */\nexport const TAB_SETTLEMENT_WITNESS_TYPEHASH: Bytes32 = keccak256Ascii(TAB_SETTLEMENT_WITNESS_TYPE);\n\n/**\n * What the contract passes Permit2 as `witnessTypeString`, exactly as\n * `TabSettlement.WITNESS_TYPE_STRING` declares it. Permit2 appends it to\n * `PERMIT2_WITNESS_TRANSFER_FROM_STUB`.\n */\nexport const PERMIT2_WITNESS_TYPE_STRING =\n `TabSettlement witness)${TAB_SETTLEMENT_WITNESS_TYPE}TokenPermissions(address token,uint256 amount)` as const;\n\n/** Permit2's own `_PERMIT_TRANSFER_FROM_WITNESS_TYPEHASH_STUB`. */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_STUB =\n \"PermitWitnessTransferFrom(TokenPermissions permitted,address spender,uint256 nonce,uint256 deadline,\" as const;\n\n/** The full primary type Permit2 hashes, and its typehash. */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPE =\n `${PERMIT2_WITNESS_TRANSFER_FROM_STUB}${PERMIT2_WITNESS_TYPE_STRING}` as const;\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPEHASH: Bytes32 = keccak256Ascii(\n PERMIT2_WITNESS_TRANSFER_FROM_TYPE,\n);\n\n/** Permit2's EIP-712 domain name. Its domain has no `version`. */\nexport const PERMIT2_DOMAIN_NAME = \"Permit2\" as const;\n\n/**\n * The EIP-712 domain an Agent signs a gasless Settlement under: Permit2's, on\n * the chain the Settlement happens on.\n */\nexport function permit2Domain(chainId: number | bigint, permit2: `0x${string}`) {\n return {\n name: PERMIT2_DOMAIN_NAME,\n chainId: typeof chainId === \"bigint\" ? chainId : BigInt(chainId),\n verifyingContract: permit2,\n } as const;\n}\n\n/**\n * The typed-data types for `signTypedData`, primary type\n * `PermitWitnessTransferFrom`. Field order matches Permit2's stub and the\n * witness type above; the referenced structs are what the type string names.\n */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPES = {\n PermitWitnessTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"witness\", type: \"TabSettlement\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n TabSettlement: [\n { name: \"serviceId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint128\" },\n { name: \"surface\", type: \"address\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n} as const;\n\nexport const PERMIT2_WITNESS_TRANSFER_FROM_PRIMARY_TYPE = \"PermitWitnessTransferFrom\" as const;\n\n/**\n * The gasless entry point on `TabSettlement`, as a human-readable ABI fragment.\n * `spender` in the signed message is the `TabSettlement` address and `witness`\n * is `TabSettlement.witnessHash(serviceId, asset, amount)`.\n */\nexport const TAB_SETTLEMENT_PERMIT2_ABI = [\n \"function settleWithPermit2(address agent, bytes32 serviceId, address asset, uint128 amount, uint256 nonce, uint256 deadline, bytes signature) returns (bytes32 settlementId, uint128 applied, uint128 toPrepaid)\",\n \"function witnessHash(bytes32 serviceId, address asset, uint128 amount) view returns (bytes32)\",\n \"function WITNESS_TYPE_STRING() view returns (string)\",\n \"function WITNESS_TYPEHASH() view returns (bytes32)\",\n \"function PERMIT2() view returns (address)\",\n \"event SettledGasless(bytes32 indexed settlementId, address indexed relayer)\",\n] as const;\n\n/** The slice of Permit2 a signer or relayer touches, as human-readable ABI. */\nexport const PERMIT2_ABI = [\n \"function DOMAIN_SEPARATOR() view returns (bytes32)\",\n \"function nonceBitmap(address owner, uint256 wordPosition) view returns (uint256)\",\n \"function invalidateUnorderedNonces(uint256 wordPos, uint256 mask)\",\n \"event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask)\",\n] as const;\n\n// ---------------------------------------------------------------------------\n// ERC-8004\n//\n// Human-readable fragments copied from `IdentityRegistryUpgradeable` and\n// `ReputationRegistryUpgradeable` in erc-8004/erc-8004-contracts, the\n// implementations behind the canonical proxies (`getVersion()` reports 2.0.0).\n// Only what Tab reads and writes; the ERC-721 and UUPS surface is omitted.\n// ---------------------------------------------------------------------------\n\n/**\n * The Identity Registry: an ERC-721 whose token id is the agentId, whose\n * `tokenURI` is the agent's registration file, and whose `agentWallet`\n * metadata is the account acting for the agent. `register` mints to the\n * caller and records it as the wallet; ids are sequential from zero.\n */\nexport const ERC8004_IDENTITY_REGISTRY_ABI = [\n \"function register() returns (uint256 agentId)\",\n \"function register(string agentURI) returns (uint256 agentId)\",\n \"function register(string agentURI, (string metadataKey, bytes metadataValue)[] metadata) returns (uint256 agentId)\",\n \"function setAgentURI(uint256 agentId, string newURI)\",\n \"function tokenURI(uint256 tokenId) view returns (string)\",\n \"function ownerOf(uint256 tokenId) view returns (address)\",\n \"function balanceOf(address owner) view returns (uint256)\",\n \"function getAgentWallet(uint256 agentId) view returns (address)\",\n \"function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)\",\n \"function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)\",\n \"function isAuthorizedOrOwner(address spender, uint256 agentId) view returns (bool)\",\n \"function getVersion() pure returns (string)\",\n \"event Registered(uint256 indexed agentId, string agentURI, address indexed owner)\",\n \"event URIUpdated(uint256 indexed agentId, string newURI, address indexed updatedBy)\",\n \"event MetadataSet(uint256 indexed agentId, string indexed indexedMetadataKey, string metadataKey, bytes metadataValue)\",\n \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n] as const;\n\n/**\n * The Reputation Registry: feedback about an agent, keyed by agentId and the\n * client that gave it, 1-indexed per client. An agent's owner or operator\n * cannot give feedback about it.\n */\nexport const ERC8004_REPUTATION_REGISTRY_ABI = [\n \"function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)\",\n \"function revokeFeedback(uint256 agentId, uint64 feedbackIndex)\",\n \"function appendResponse(uint256 agentId, address clientAddress, uint64 feedbackIndex, string responseURI, bytes32 responseHash)\",\n \"function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)\",\n \"function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)\",\n \"function readAllFeedback(uint256 agentId, address[] clientAddresses, string tag1, string tag2, bool includeRevoked) view returns (address[] clients, uint64[] feedbackIndexes, int128[] values, uint8[] valueDecimals, string[] tag1s, string[] tag2s, bool[] revokedStatuses)\",\n \"function getLastIndex(uint256 agentId, address clientAddress) view returns (uint64)\",\n \"function getClients(uint256 agentId) view returns (address[])\",\n \"function getIdentityRegistry() view returns (address)\",\n \"function getVersion() pure returns (string)\",\n \"event NewFeedback(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, int128 value, uint8 valueDecimals, string indexed indexedTag1, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)\",\n \"event FeedbackRevoked(uint256 indexed agentId, address indexed clientAddress, uint64 indexed feedbackIndex)\",\n \"event ResponseAppended(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, address indexed responder, string responseURI, bytes32 responseHash)\",\n] as const;\n\n/** Canonical ERC-8004 event signatures, for topic filters. */\nexport const ERC8004_EVENT_SIGNATURES = {\n Registered: \"Registered(uint256,string,address)\",\n URIUpdated: \"URIUpdated(uint256,string,address)\",\n MetadataSet: \"MetadataSet(uint256,string,string,bytes)\",\n NewFeedback: \"NewFeedback(uint256,address,uint64,int128,uint8,string,string,string,string,string,bytes32)\",\n FeedbackRevoked: \"FeedbackRevoked(uint256,address,uint64)\",\n ResponseAppended: \"ResponseAppended(uint256,address,uint64,address,string,bytes32)\",\n} as const;\n\nexport type Erc8004EventName = keyof typeof ERC8004_EVENT_SIGNATURES;\n\n/** `topics[0]` for each ERC-8004 event, derived from its canonical signature. */\nexport const ERC8004_EVENT_TOPIC0: Readonly<Record<Erc8004EventName, Bytes32>> = Object.fromEntries(\n Object.entries(ERC8004_EVENT_SIGNATURES).map(([name, signature]) => [name, keccak256Ascii(signature)]),\n) as Record<Erc8004EventName, Bytes32>;\n"]}
|
|
1
|
+
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,uGAAuG;IACvG,iBAAiB,EAAE,4EAA4E;IAC/F,sGAAsG;IACtG,gBAAgB,EAAE,yEAAyE;IAC3F,wFAAwF;IACxF,eAAe,EACb,mGAAmG;IACrG,mFAAmF;IACnF,aAAa,EAAE,+DAA+D;IAC9E,2EAA2E;IAC3E,qBAAqB,EAAE,gDAAgD;IACvE,mGAAmG;IACnG,OAAO,EAAE,0EAA0E;IACnF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,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAClE,CAAC","sourcesContent":["/**\n * Contract interface constants shared by the SDK, the gateway, the registry\n * indexer, and the dashboard.\n *\n * Only what is fixed and independently checkable lives here: canonical event\n * signatures and the topic hashes derived from them, the Permit2 witness types,\n * and short human-readable fragments for the few functions callers reach\n * directly (the Permit2 settlement path on `TabSettlement`, the slice of\n * Permit2 a signer touches, and the ERC-8004 registries). The fragments are\n * transcribed by hand, so each carries only the members a caller uses; the\n * `SettlementApplied` topic is pinned by a test against the compiled `TabBook`.\n */\nimport { keccak256Ascii } from \"./keccak256.js\";\nimport type { Bytes32 } from \"./hex.js\";\n\n/**\n * Canonical event signatures, the exact strings the topic hash is taken over.\n * No spaces, no parameter names, canonical types.\n */\nexport const EVENT_SIGNATURES = {\n /** `TabBook.SettlementApplied`: a Settlement lowered an Open Tab. `topics[1]` is the settlement id. */\n SettlementApplied: \"SettlementApplied(bytes32,address,bytes32,address,uint256,uint256,uint128)\",\n /** `TabBook.DeliveryRecorded`: a Service metered usage into an Open Tab. `topics[1]` is the Agent. */\n DeliveryRecorded: \"DeliveryRecorded(address,bytes32,address,bytes32,uint32,uint256,uint64)\",\n /** `TabBook.HistoryExtended`: the Agent's history commitment advanced by one record. */\n HistoryExtended:\n \"HistoryExtended(address,address,bytes32,uint32,(bytes32,address,uint128,uint64,uint64,bool,bool))\",\n /** `TabBook.TabDelinquent`: a Settlement Window closed with the tab still open. */\n TabDelinquent: \"TabDelinquent(bytes32,address,bytes32,address,uint128,uint64)\",\n /** `TabBook.TabDelinquencyCleared`: the delinquent tab settled to zero. */\n TabDelinquencyCleared: \"TabDelinquencyCleared(bytes32,address,address)\",\n /** `TabSettlement.Settled`: the Asset moved from the Agent to the Service's Collection address. */\n Settled: \"Settled(bytes32,address,bytes32,address,uint128,uint128,uint128,address)\",\n /**\n * `TabSettlement.SettledGasless`: the Settlement arrived on the Agent's Permit2 signature and\n * `topics[2]` is the relayer that paid for it. Always follows a `Settled` with the same id.\n */\n SettledGasless: \"SettledGasless(bytes32,address)\",\n /** `Bond.BondFunded`: stake entered the escrow. */\n BondFunded: \"BondFunded(bytes32,address,uint128,address)\",\n /** `Bond.BondWithdrawn`: stake left the escrow. */\n BondWithdrawn: \"BondWithdrawn(bytes32,address,uint128,address)\",\n /** ERC-20 `Transfer`, for reading balances and payouts off the Asset contract. */\n Transfer: \"Transfer(address,address,uint256)\",\n} as const;\n\n/** Name of an event whose signature this module pins. */\nexport type EventName = keyof typeof EVENT_SIGNATURES;\n\n/**\n * `topics[0]` for each pinned event: the Keccak-256 hash of its canonical\n * signature. Derived rather than transcribed, so a signature edit cannot leave a\n * stale hash behind.\n */\nexport const EVENT_TOPIC0: Readonly<Record<EventName, Bytes32>> = Object.fromEntries(\n Object.entries(EVENT_SIGNATURES).map(([name, signature]) => [name, keccak256Ascii(signature)]),\n) as Record<EventName, Bytes32>;\n\n/** `topics[0]` for a pinned event. */\nexport const eventTopic0 = (name: EventName): Bytes32 => EVENT_TOPIC0[name];\n\n// ---------------------------------------------------------------------------\n// Gasless Settlement through Permit2\n//\n// `TabSettlement.settleWithPermit2` verifies an EIP-712 signature the Agent\n// made under Permit2's domain, over Permit2's `PermitWitnessTransferFrom` with\n// a Tab-specific witness. Everything a signer needs is pinned here so the SDK\n// cannot drift from the contract: the witness type, the string the contract\n// hands Permit2, and the typed-data layout for `signTypedData`.\n// ---------------------------------------------------------------------------\n\n/**\n * The witness struct, exactly as `TabSettlement.WITNESS_TYPE` declares it.\n * `surface` is the `TabSettlement` address and `chainId` the chain it lives on.\n */\nexport const TAB_SETTLEMENT_WITNESS_TYPE =\n \"TabSettlement(bytes32 serviceId,address asset,uint128 amount,address surface,uint256 chainId)\" as const;\n\n/** `keccak256(TAB_SETTLEMENT_WITNESS_TYPE)`, the same value as `TabSettlement.WITNESS_TYPEHASH`. */\nexport const TAB_SETTLEMENT_WITNESS_TYPEHASH: Bytes32 = keccak256Ascii(TAB_SETTLEMENT_WITNESS_TYPE);\n\n/**\n * What the contract passes Permit2 as `witnessTypeString`, exactly as\n * `TabSettlement.WITNESS_TYPE_STRING` declares it. Permit2 appends it to\n * `PERMIT2_WITNESS_TRANSFER_FROM_STUB`.\n */\nexport const PERMIT2_WITNESS_TYPE_STRING =\n `TabSettlement witness)${TAB_SETTLEMENT_WITNESS_TYPE}TokenPermissions(address token,uint256 amount)` as const;\n\n/** Permit2's own `_PERMIT_TRANSFER_FROM_WITNESS_TYPEHASH_STUB`. */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_STUB =\n \"PermitWitnessTransferFrom(TokenPermissions permitted,address spender,uint256 nonce,uint256 deadline,\" as const;\n\n/** The full primary type Permit2 hashes, and its typehash. */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPE =\n `${PERMIT2_WITNESS_TRANSFER_FROM_STUB}${PERMIT2_WITNESS_TYPE_STRING}` as const;\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPEHASH: Bytes32 = keccak256Ascii(\n PERMIT2_WITNESS_TRANSFER_FROM_TYPE,\n);\n\n/** Permit2's EIP-712 domain name. Its domain has no `version`. */\nexport const PERMIT2_DOMAIN_NAME = \"Permit2\" as const;\n\n/**\n * The EIP-712 domain an Agent signs a gasless Settlement under: Permit2's, on\n * the chain the Settlement happens on.\n */\nexport function permit2Domain(chainId: number | bigint, permit2: `0x${string}`) {\n return {\n name: PERMIT2_DOMAIN_NAME,\n chainId: typeof chainId === \"bigint\" ? chainId : BigInt(chainId),\n verifyingContract: permit2,\n } as const;\n}\n\n/**\n * The typed-data types for `signTypedData`, primary type\n * `PermitWitnessTransferFrom`. Field order matches Permit2's stub and the\n * witness type above; the referenced structs are what the type string names.\n */\nexport const PERMIT2_WITNESS_TRANSFER_FROM_TYPES = {\n PermitWitnessTransferFrom: [\n { name: \"permitted\", type: \"TokenPermissions\" },\n { name: \"spender\", type: \"address\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint256\" },\n { name: \"witness\", type: \"TabSettlement\" },\n ],\n TokenPermissions: [\n { name: \"token\", type: \"address\" },\n { name: \"amount\", type: \"uint256\" },\n ],\n TabSettlement: [\n { name: \"serviceId\", type: \"bytes32\" },\n { name: \"asset\", type: \"address\" },\n { name: \"amount\", type: \"uint128\" },\n { name: \"surface\", type: \"address\" },\n { name: \"chainId\", type: \"uint256\" },\n ],\n} as const;\n\nexport const PERMIT2_WITNESS_TRANSFER_FROM_PRIMARY_TYPE = \"PermitWitnessTransferFrom\" as const;\n\n/**\n * The gasless entry point on `TabSettlement`, as a human-readable ABI fragment.\n * `spender` in the signed message is the `TabSettlement` address and `witness`\n * is `TabSettlement.witnessHash(serviceId, asset, amount)`.\n */\nexport const TAB_SETTLEMENT_PERMIT2_ABI = [\n \"function settleWithPermit2(address agent, bytes32 serviceId, address asset, uint128 amount, uint256 nonce, uint256 deadline, bytes signature) returns (bytes32 settlementId, uint128 applied, uint128 toPrepaid)\",\n \"function witnessHash(bytes32 serviceId, address asset, uint128 amount) view returns (bytes32)\",\n \"function WITNESS_TYPE_STRING() view returns (string)\",\n \"function WITNESS_TYPEHASH() view returns (bytes32)\",\n \"function PERMIT2() view returns (address)\",\n \"event SettledGasless(bytes32 indexed settlementId, address indexed relayer)\",\n] as const;\n\n/** The slice of Permit2 a signer or relayer touches, as human-readable ABI. */\nexport const PERMIT2_ABI = [\n \"function DOMAIN_SEPARATOR() view returns (bytes32)\",\n \"function nonceBitmap(address owner, uint256 wordPosition) view returns (uint256)\",\n \"function invalidateUnorderedNonces(uint256 wordPos, uint256 mask)\",\n \"event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask)\",\n] as const;\n\n// ---------------------------------------------------------------------------\n// ERC-8004\n//\n// Human-readable fragments copied from `IdentityRegistryUpgradeable` and\n// `ReputationRegistryUpgradeable` in erc-8004/erc-8004-contracts, the\n// implementations behind the canonical proxies (`getVersion()` reports 2.0.0).\n// Only what Tab reads and writes; the ERC-721 and UUPS surface is omitted.\n// ---------------------------------------------------------------------------\n\n/**\n * The Identity Registry: an ERC-721 whose token id is the agentId, whose\n * `tokenURI` is the agent's registration file, and whose `agentWallet`\n * metadata is the account acting for the agent. `register` mints to the\n * caller and records it as the wallet; ids are sequential from zero.\n */\nexport const ERC8004_IDENTITY_REGISTRY_ABI = [\n \"function register() returns (uint256 agentId)\",\n \"function register(string agentURI) returns (uint256 agentId)\",\n \"function register(string agentURI, (string metadataKey, bytes metadataValue)[] metadata) returns (uint256 agentId)\",\n \"function setAgentURI(uint256 agentId, string newURI)\",\n \"function tokenURI(uint256 tokenId) view returns (string)\",\n \"function ownerOf(uint256 tokenId) view returns (address)\",\n \"function balanceOf(address owner) view returns (uint256)\",\n \"function getAgentWallet(uint256 agentId) view returns (address)\",\n \"function getMetadata(uint256 agentId, string metadataKey) view returns (bytes)\",\n \"function setMetadata(uint256 agentId, string metadataKey, bytes metadataValue)\",\n \"function isAuthorizedOrOwner(address spender, uint256 agentId) view returns (bool)\",\n \"function getVersion() pure returns (string)\",\n \"event Registered(uint256 indexed agentId, string agentURI, address indexed owner)\",\n \"event URIUpdated(uint256 indexed agentId, string newURI, address indexed updatedBy)\",\n \"event MetadataSet(uint256 indexed agentId, string indexed indexedMetadataKey, string metadataKey, bytes metadataValue)\",\n \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n] as const;\n\n/**\n * The Reputation Registry: feedback about an agent, keyed by agentId and the\n * client that gave it, 1-indexed per client. An agent's owner or operator\n * cannot give feedback about it.\n */\nexport const ERC8004_REPUTATION_REGISTRY_ABI = [\n \"function giveFeedback(uint256 agentId, int128 value, uint8 valueDecimals, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)\",\n \"function revokeFeedback(uint256 agentId, uint64 feedbackIndex)\",\n \"function appendResponse(uint256 agentId, address clientAddress, uint64 feedbackIndex, string responseURI, bytes32 responseHash)\",\n \"function getSummary(uint256 agentId, address[] clientAddresses, string tag1, string tag2) view returns (uint64 count, int128 summaryValue, uint8 summaryValueDecimals)\",\n \"function readFeedback(uint256 agentId, address clientAddress, uint64 feedbackIndex) view returns (int128 value, uint8 valueDecimals, string tag1, string tag2, bool isRevoked)\",\n \"function readAllFeedback(uint256 agentId, address[] clientAddresses, string tag1, string tag2, bool includeRevoked) view returns (address[] clients, uint64[] feedbackIndexes, int128[] values, uint8[] valueDecimals, string[] tag1s, string[] tag2s, bool[] revokedStatuses)\",\n \"function getLastIndex(uint256 agentId, address clientAddress) view returns (uint64)\",\n \"function getClients(uint256 agentId) view returns (address[])\",\n \"function getIdentityRegistry() view returns (address)\",\n \"function getVersion() pure returns (string)\",\n \"event NewFeedback(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, int128 value, uint8 valueDecimals, string indexed indexedTag1, string tag1, string tag2, string endpoint, string feedbackURI, bytes32 feedbackHash)\",\n \"event FeedbackRevoked(uint256 indexed agentId, address indexed clientAddress, uint64 indexed feedbackIndex)\",\n \"event ResponseAppended(uint256 indexed agentId, address indexed clientAddress, uint64 feedbackIndex, address indexed responder, string responseURI, bytes32 responseHash)\",\n] as const;\n\n/** Canonical ERC-8004 event signatures, for topic filters. */\nexport const ERC8004_EVENT_SIGNATURES = {\n Registered: \"Registered(uint256,string,address)\",\n URIUpdated: \"URIUpdated(uint256,string,address)\",\n MetadataSet: \"MetadataSet(uint256,string,string,bytes)\",\n NewFeedback: \"NewFeedback(uint256,address,uint64,int128,uint8,string,string,string,string,string,bytes32)\",\n FeedbackRevoked: \"FeedbackRevoked(uint256,address,uint64)\",\n ResponseAppended: \"ResponseAppended(uint256,address,uint64,address,string,bytes32)\",\n} as const;\n\nexport type Erc8004EventName = keyof typeof ERC8004_EVENT_SIGNATURES;\n\n/** `topics[0]` for each ERC-8004 event, derived from its canonical signature. */\nexport const ERC8004_EVENT_TOPIC0: Readonly<Record<Erc8004EventName, Bytes32>> = Object.fromEntries(\n Object.entries(ERC8004_EVENT_SIGNATURES).map(([name, signature]) => [name, keccak256Ascii(signature)]),\n) as Record<Erc8004EventName, Bytes32>;\n"]}
|
package/dist/_shared/chains.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chain and Asset constants for Tab on Monad.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* which Assets it settles in.
|
|
4
|
+
* The Agent's payment and the ledger entry happen in the same Monad
|
|
5
|
+
* transaction. What this module carries is which Monad network a deployment
|
|
6
|
+
* targets and which Assets it settles in.
|
|
8
7
|
*
|
|
9
8
|
* Addresses of Tab's own contracts are deployment output and live in
|
|
10
9
|
* `deployments.json`, never here.
|
|
@@ -152,7 +151,6 @@ export declare const ERC8004_REGISTRIES: {
|
|
|
152
151
|
};
|
|
153
152
|
};
|
|
154
153
|
export declare function erc8004RegistriesFor(chainId: number | bigint): Erc8004Registries | undefined;
|
|
155
|
-
|
|
156
|
-
/** Formats base units of a six-decimal Asset for display, without floating point. */
|
|
154
|
+
/** Formats an amount in base units at the given decimals for display, without floating point. */
|
|
157
155
|
export declare function formatBaseUnits(amount: bigint, decimals: number): string;
|
|
158
156
|
//# sourceMappingURL=chains.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"chains.d.ts","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MA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jF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;IACpC,+FAA+F;IAC/F,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;CAkBuC,CAAC;AAE/D,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,yGAAyG;IACzG,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;CAC9B;AAED,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB;;;;;;;;;CASuC,CAAC;AAEvE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAG5F;AAED,iGAAiG;AACjG,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOxE"}
|
package/dist/_shared/chains.js
CHANGED
|
@@ -103,8 +103,7 @@ export function erc8004RegistriesFor(chainId) {
|
|
|
103
103
|
const narrowed = typeof chainId === "bigint" ? Number(chainId) : chainId;
|
|
104
104
|
return isMonadChainId(narrowed) ? ERC8004_REGISTRIES[narrowed] : undefined;
|
|
105
105
|
}
|
|
106
|
-
|
|
107
|
-
/** Formats base units of a six-decimal Asset for display, without floating point. */
|
|
106
|
+
/** Formats an amount in base units at the given decimals for display, without floating point. */
|
|
108
107
|
export function formatBaseUnits(amount, decimals) {
|
|
109
108
|
const negative = amount < 0n;
|
|
110
109
|
const abs = negative ? -amount : amount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE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QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,4CAAqD,CAAC;AAEzF,qFAAqF;AACrF,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,QAAgB;IAC9D,MAAM,QAAQ,GAAG,MAAM,GAAG,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;IAC1B,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrF,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3E,CAAC","sourcesContent":["/**\n * Chain and Asset constants for Tab on Monad.\n *\n * Tab runs on one chain. The Agent's payment and the ledger entry happen in the\n * same Monad transaction, so nothing in the system refers to any other chain.\n * What this module carries is which Monad network a deployment targets and\n * which Assets it settles in.\n *\n * Addresses of Tab's own contracts are deployment output and live in\n * `deployments.json`, never here.\n */\nimport type { Address, Bytes32 } from \"./hex.js\";\n\n/** A Monad network a Tab deployment can target. */\nexport interface ChainDescriptor {\n readonly name: string;\n readonly chainId: number;\n readonly rpcUrl: string;\n readonly explorerUrl: string;\n /** The MON faucet, testnet only. */\n readonly faucetUrl?: string;\n}\n\nexport const MONAD_MAINNET = {\n name: \"Monad Mainnet\",\n chainId: 143,\n rpcUrl: \"https://rpc.monad.xyz\",\n explorerUrl: \"https://monadvision.com\",\n} as const satisfies ChainDescriptor;\n\nexport const MONAD_TESTNET = {\n name: \"Monad Testnet\",\n chainId: 10143,\n rpcUrl: \"https://testnet-rpc.monad.xyz\",\n explorerUrl: \"https://testnet.monadvision.com\",\n faucetUrl: \"https://faucet.monad.xyz\",\n} as const satisfies ChainDescriptor;\n\nexport const CHAINS = {\n [MONAD_MAINNET.chainId]: MONAD_MAINNET,\n [MONAD_TESTNET.chainId]: MONAD_TESTNET,\n} as const;\n\nexport type MonadChainId = keyof typeof CHAINS;\n\nexport function isMonadChainId(value: unknown): value is MonadChainId {\n return value === MONAD_MAINNET.chainId || value === MONAD_TESTNET.chainId;\n}\n\nexport function chainFor(chainId: number | bigint): ChainDescriptor | undefined {\n const narrowed = typeof chainId === \"bigint\" ? Number(chainId) : chainId;\n return isMonadChainId(narrowed) ? CHAINS[narrowed] : undefined;\n}\n\n/** Link to an address or a transaction on the explorer for a chain. */\nexport function explorerLink(chain: ChainDescriptor, kind: \"address\" | \"tx\", hash: string): string {\n return `${chain.explorerUrl}/${kind}/${hash}`;\n}\n\n/** A stablecoin Tab settles in. Amounts everywhere are integer base units. */\nexport interface AssetDescriptor {\n readonly symbol: string;\n readonly decimals: number;\n readonly address: Address;\n}\n\n/** Canonical stablecoins on Monad Mainnet. */\nexport const MAINNET_ASSETS = {\n USDC: {\n symbol: \"USDC\",\n decimals: 6,\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n },\n AUSD: {\n symbol: \"AUSD\",\n decimals: 6,\n address: \"0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a\",\n },\n} as const satisfies Readonly<Record<string, AssetDescriptor>>;\n\n/**\n * Stablecoins on Monad Testnet. `USDC` is Circle's own testnet deployment\n * (`name` \"USDC\", EIP-712 version \"2\", 20 USDC per address every two hours from\n * https://faucet.circle.com). `MockUsdc`, the mintable test double the deploy\n * script ships, is a deployment output and lives in `deployments.json`.\n */\nexport const TESTNET_ASSETS = {\n USDC: {\n symbol: \"USDC\",\n decimals: 6,\n address: \"0x534b2f3A21130d7a60830c2Df862319e593943A3\",\n },\n} as const satisfies Readonly<Record<string, AssetDescriptor>>;\n\n/**\n * Uniswap's Permit2, at its canonical address on every chain it was deployed\n * to, Monad Mainnet and Testnet included. `TabSettlement.settleWithPermit2`\n * verifies an Agent's signature against it, so an Agent approves Permit2 once\n * and signs thereafter.\n */\nexport const PERMIT2_ADDRESS = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\" as const satisfies Address;\n\n/** The x402 facilitator that verifies and settles `exact` payments on Monad. */\nexport const X402_FACILITATOR_URL = \"https://x402-facilitator.molandak.org\" as const;\n\n/** A Service this project hosts, and where it is reached. */\nexport interface HostedService {\n readonly serviceId: Bytes32;\n readonly name: string;\n readonly endpoint: string;\n}\n\n/** What this project hosts on one network: the read API and the demo Service. */\nexport interface TabHosted {\n readonly registryUrl: string;\n readonly demoService: HostedService;\n /** The test token the hosted deployment prices in, where it ships one: `mUSDC`, 6 decimals. */\n readonly testAsset?: Address;\n}\n\n/**\n * The read API and the demo Service this project runs, per network.\n *\n * Defaults, never authority: the chain is the authority on every figure, and a\n * configured `registryUrl` or `services` entry always wins over these. They are\n * here so that a fresh install can discover and call something before its owner\n * has configured anything, which is the first thing anyone tries.\n */\nexport const TAB_HOSTED = {\n [MONAD_MAINNET.chainId]: {\n registryUrl: \"https://registry-mainnet-production.up.railway.app\",\n demoService: {\n serviceId: \"0x7461622e64656d6f000000000000000000000000000000000000000000000000\",\n name: \"tab.demo\",\n endpoint: \"https://gateway-mainnet-production.up.railway.app\",\n },\n },\n [MONAD_TESTNET.chainId]: {\n registryUrl: \"https://registry-testnet-production.up.railway.app\",\n demoService: {\n serviceId: \"0x7461622e64656d6f000000000000000000000000000000000000000000000000\",\n name: \"tab.demo\",\n endpoint: \"https://gateway-testnet-production-a657.up.railway.app\",\n },\n testAsset: \"0x480209747417f5c830fDA188a9b9AcFa70Bc4083\",\n },\n} as const satisfies Readonly<Record<MonadChainId, TabHosted>>;\n\n/** The two ERC-8004 registries a Tab deployment reads and writes. */\nexport interface Erc8004Registries {\n /** Agent identities: an ERC-721 whose token id is the agentId and whose URI is the registration file. */\n readonly identity: Address;\n /** Feedback about agents, keyed by agentId and client. */\n readonly reputation: Address;\n}\n\n/** The canonical ERC-8004 registries, keyed by chain id. */\nexport const ERC8004_REGISTRIES = {\n [MONAD_MAINNET.chainId]: {\n identity: \"0x8004A169FB4a3325136EB29fA0ceB6D2e539a432\",\n reputation: \"0x8004BAa17C55a88189AE136b182e5fdA19dE9b63\",\n },\n [MONAD_TESTNET.chainId]: {\n identity: \"0x8004A818BFB912233c491871b3d84c89A494BD9e\",\n reputation: \"0x8004B663056A597Dffe9eCcC1965A193B7388713\",\n },\n} as const satisfies Readonly<Record<MonadChainId, Erc8004Registries>>;\n\nexport function erc8004RegistriesFor(chainId: number | bigint): Erc8004Registries | undefined {\n const narrowed = typeof chainId === \"bigint\" ? Number(chainId) : chainId;\n return isMonadChainId(narrowed) ? ERC8004_REGISTRIES[narrowed] : undefined;\n}\n\nexport const PLACEHOLDER_ADDRESS = \"0x0000000000000000000000000000000000000000\" as const;\n\n/** Formats base units of a six-decimal Asset for display, without floating point. */\nexport function formatBaseUnits(amount: bigint, decimals: number): string {\n const negative = amount < 0n;\n const abs = negative ? -amount : amount;\n const scale = 10n ** BigInt(decimals);\n const whole = abs / scale;\n const fraction = (abs % scale).toString().padStart(decimals, \"0\").replace(/0+$/, \"\");\n return `${negative ? \"-\" : \"\"}${whole}${fraction ? `.${fraction}` : \"\"}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"chains.js","sourceRoot":"","sources":["../src/chains.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,uBAAuB;IAC/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C,CAAC,CAAC,SAAS,CAAC;AAC7E,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,QAAgB;IAC9D,MAAM,QAAQ,GAAG,MAAM,GAAG,EAAE,CAAC;IAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,GAAG,GAAG,KAAK,CAAC;IAC1B,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrF,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC3E,CAAC","sourcesContent":["/**\n * Chain and Asset constants for Tab on Monad.\n *\n * The Agent's payment and the ledger entry happen in the same Monad\n * transaction. What this module carries is which Monad network a deployment\n * targets and which Assets it settles in.\n *\n * Addresses of Tab's own contracts are deployment output and live in\n * `deployments.json`, never here.\n */\nimport type { Address, Bytes32 } from \"./hex.js\";\n\n/** A Monad network a Tab deployment can target. */\nexport interface ChainDescriptor {\n readonly name: string;\n readonly chainId: number;\n readonly rpcUrl: string;\n readonly explorerUrl: string;\n /** The MON faucet, testnet only. */\n readonly faucetUrl?: string;\n}\n\nexport const MONAD_MAINNET = {\n name: \"Monad Mainnet\",\n chainId: 143,\n rpcUrl: \"https://rpc.monad.xyz\",\n explorerUrl: \"https://monadvision.com\",\n} as const satisfies ChainDescriptor;\n\nexport const MONAD_TESTNET = {\n name: \"Monad Testnet\",\n chainId: 10143,\n rpcUrl: \"https://testnet-rpc.monad.xyz\",\n explorerUrl: \"https://testnet.monadvision.com\",\n faucetUrl: \"https://faucet.monad.xyz\",\n} as const satisfies ChainDescriptor;\n\nexport const CHAINS = {\n [MONAD_MAINNET.chainId]: MONAD_MAINNET,\n [MONAD_TESTNET.chainId]: MONAD_TESTNET,\n} as const;\n\nexport type MonadChainId = keyof typeof CHAINS;\n\nexport function isMonadChainId(value: unknown): value is MonadChainId {\n return value === MONAD_MAINNET.chainId || value === MONAD_TESTNET.chainId;\n}\n\nexport function chainFor(chainId: number | bigint): ChainDescriptor | undefined {\n const narrowed = typeof chainId === \"bigint\" ? Number(chainId) : chainId;\n return isMonadChainId(narrowed) ? CHAINS[narrowed] : undefined;\n}\n\n/** Link to an address or a transaction on the explorer for a chain. */\nexport function explorerLink(chain: ChainDescriptor, kind: \"address\" | \"tx\", hash: string): string {\n return `${chain.explorerUrl}/${kind}/${hash}`;\n}\n\n/** A stablecoin Tab settles in. Amounts everywhere are integer base units. */\nexport interface AssetDescriptor {\n readonly symbol: string;\n readonly decimals: number;\n readonly address: Address;\n}\n\n/** Canonical stablecoins on Monad Mainnet. */\nexport const MAINNET_ASSETS = {\n USDC: {\n symbol: \"USDC\",\n decimals: 6,\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n },\n AUSD: {\n symbol: \"AUSD\",\n decimals: 6,\n address: \"0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a\",\n },\n} as const satisfies Readonly<Record<string, AssetDescriptor>>;\n\n/**\n * Stablecoins on Monad Testnet. `USDC` is Circle's own testnet deployment\n * (`name` \"USDC\", EIP-712 version \"2\", 20 USDC per address every two hours from\n * https://faucet.circle.com). `MockUsdc`, the mintable test double the deploy\n * script ships, is a deployment output and lives in `deployments.json`.\n */\nexport const TESTNET_ASSETS = {\n USDC: {\n symbol: \"USDC\",\n decimals: 6,\n address: \"0x534b2f3A21130d7a60830c2Df862319e593943A3\",\n },\n} as const satisfies Readonly<Record<string, AssetDescriptor>>;\n\n/**\n * Uniswap's Permit2, at its canonical address on every chain it was deployed\n * to, Monad Mainnet and Testnet included. `TabSettlement.settleWithPermit2`\n * verifies an Agent's signature against it, so an Agent approves Permit2 once\n * and signs thereafter.\n */\nexport const PERMIT2_ADDRESS = \"0x000000000022D473030F116dDEE9F6B43aC78BA3\" as const satisfies Address;\n\n/** The x402 facilitator that verifies and settles `exact` payments on Monad. */\nexport const X402_FACILITATOR_URL = \"https://x402-facilitator.molandak.org\" as const;\n\n/** A Service this project hosts, and where it is reached. */\nexport interface HostedService {\n readonly serviceId: Bytes32;\n readonly name: string;\n readonly endpoint: string;\n}\n\n/** What this project hosts on one network: the read API and the demo Service. */\nexport interface TabHosted {\n readonly registryUrl: string;\n readonly demoService: HostedService;\n /** The test token the hosted deployment prices in, where it ships one: `mUSDC`, 6 decimals. */\n readonly testAsset?: Address;\n}\n\n/**\n * The read API and the demo Service this project runs, per network.\n *\n * Defaults, never authority: the chain is the authority on every figure, and a\n * configured `registryUrl` or `services` entry always wins over these. They are\n * here so that a fresh install can discover and call something before its owner\n * has configured anything, which is the first thing anyone tries.\n */\nexport const TAB_HOSTED = {\n [MONAD_MAINNET.chainId]: {\n registryUrl: \"https://registry-mainnet-production.up.railway.app\",\n demoService: {\n serviceId: \"0x7461622e64656d6f000000000000000000000000000000000000000000000000\",\n name: \"tab.demo\",\n endpoint: \"https://gateway-mainnet-production.up.railway.app\",\n },\n },\n [MONAD_TESTNET.chainId]: {\n registryUrl: \"https://registry-testnet-production.up.railway.app\",\n demoService: {\n serviceId: \"0x7461622e64656d6f000000000000000000000000000000000000000000000000\",\n name: \"tab.demo\",\n endpoint: \"https://gateway-testnet-production-a657.up.railway.app\",\n },\n testAsset: \"0x480209747417f5c830fDA188a9b9AcFa70Bc4083\",\n },\n} as const satisfies Readonly<Record<MonadChainId, TabHosted>>;\n\n/** The two ERC-8004 registries a Tab deployment reads and writes. */\nexport interface Erc8004Registries {\n /** Agent identities: an ERC-721 whose token id is the agentId and whose URI is the registration file. */\n readonly identity: Address;\n /** Feedback about agents, keyed by agentId and client. */\n readonly reputation: Address;\n}\n\n/** The canonical ERC-8004 registries, keyed by chain id. */\nexport const ERC8004_REGISTRIES = {\n [MONAD_MAINNET.chainId]: {\n identity: \"0x8004A169FB4a3325136EB29fA0ceB6D2e539a432\",\n reputation: \"0x8004BAa17C55a88189AE136b182e5fdA19dE9b63\",\n },\n [MONAD_TESTNET.chainId]: {\n identity: \"0x8004A818BFB912233c491871b3d84c89A494BD9e\",\n reputation: \"0x8004B663056A597Dffe9eCcC1965A193B7388713\",\n },\n} as const satisfies Readonly<Record<MonadChainId, Erc8004Registries>>;\n\nexport function erc8004RegistriesFor(chainId: number | bigint): Erc8004Registries | undefined {\n const narrowed = typeof chainId === \"bigint\" ? Number(chainId) : chainId;\n return isMonadChainId(narrowed) ? ERC8004_REGISTRIES[narrowed] : undefined;\n}\n\n/** Formats an amount in base units at the given decimals for display, without floating point. */\nexport function formatBaseUnits(amount: bigint, decimals: number): string {\n const negative = amount < 0n;\n const abs = negative ? -amount : amount;\n const scale = 10n ** BigInt(decimals);\n const whole = abs / scale;\n const fraction = (abs % scale).toString().padStart(decimals, \"0\").replace(/0+$/, \"\");\n return `${negative ? \"-\" : \"\"}${whole}${fraction ? `.${fraction}` : \"\"}`;\n}\n"]}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* Keccak-256, written against native `bigint`.
|
|
3
3
|
*
|
|
4
4
|
* `@tabai/shared` carries zero runtime dependencies, and Keccak-256 is not
|
|
5
|
-
* SHA3-256
|
|
5
|
+
* SHA3-256 (the two differ in their padding byte), so the platform hash
|
|
6
6
|
* primitives cannot stand in for it. The permutation below is therefore
|
|
7
7
|
* implemented here: 24 rounds of Keccak-f[1600] over 25 64-bit lanes, rate 136
|
|
8
8
|
* bytes, capacity 64 bytes, `0x01` domain padding.
|
|
9
9
|
*
|
|
10
10
|
* Correctness is pinned by published digests in `test/keccak256.test.mjs`: the
|
|
11
11
|
* empty-input digest, the `abc` digest, and the ERC-20 `Transfer` and `Approval`
|
|
12
|
-
* event topics any chain explorer shows
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* event topics any chain explorer shows, plus a multi-block vector whose SHA3-256
|
|
13
|
+
* sibling (same permutation and rate, different padding byte) matches the
|
|
14
|
+
* platform hash across the 136-byte block boundary. It is used only to derive a
|
|
15
|
+
* handful of event topics and typehashes at module load, so the `bigint` lane
|
|
16
|
+
* representation costs nothing that matters.
|
|
17
17
|
*/
|
|
18
18
|
import type { Bytes32 } from "./hex.js";
|
|
19
19
|
/** Hashes raw bytes and renders the digest as a 32-byte word. */
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* Keccak-256, written against native `bigint`.
|
|
3
3
|
*
|
|
4
4
|
* `@tabai/shared` carries zero runtime dependencies, and Keccak-256 is not
|
|
5
|
-
* SHA3-256
|
|
5
|
+
* SHA3-256 (the two differ in their padding byte), so the platform hash
|
|
6
6
|
* primitives cannot stand in for it. The permutation below is therefore
|
|
7
7
|
* implemented here: 24 rounds of Keccak-f[1600] over 25 64-bit lanes, rate 136
|
|
8
8
|
* bytes, capacity 64 bytes, `0x01` domain padding.
|
|
9
9
|
*
|
|
10
10
|
* Correctness is pinned by published digests in `test/keccak256.test.mjs`: the
|
|
11
11
|
* empty-input digest, the `abc` digest, and the ERC-20 `Transfer` and `Approval`
|
|
12
|
-
* event topics any chain explorer shows
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
12
|
+
* event topics any chain explorer shows, plus a multi-block vector whose SHA3-256
|
|
13
|
+
* sibling (same permutation and rate, different padding byte) matches the
|
|
14
|
+
* platform hash across the 136-byte block boundary. It is used only to derive a
|
|
15
|
+
* handful of event topics and typehashes at module load, so the `bigint` lane
|
|
16
|
+
* representation costs nothing that matters.
|
|
17
17
|
*/
|
|
18
18
|
const LANE_MASK = (1n << 64n) - 1n;
|
|
19
19
|
/** Rate in bytes for a 256-bit digest: 200 - 2 * 32. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keccak256.js","sourceRoot":"","sources":["../src/keccak256.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEnC,wDAAwD;AACxD,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,6DAA6D;AAC7D,MAAM,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC;AAElC,4BAA4B;AAC5B,MAAM,eAAe,GAAsB;IACzC,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,SAAS,GAAsB;IACnC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;CAC1F,CAAC;AAEF,2BAA2B;AAC3B,MAAM,UAAU,GAAsB;IACpC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAA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,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Keccak-256, written against native `bigint`.\n *\n * `@tabai/shared` carries zero runtime dependencies, and Keccak-256 is not\n * SHA3-256, the two differ in their padding byte, so the platform hash\n * primitives cannot stand in for it. The permutation below is therefore\n * implemented here: 24 rounds of Keccak-f[1600] over 25 64-bit lanes, rate 136\n * bytes, capacity 64 bytes, `0x01` domain padding.\n *\n * Correctness is pinned by published digests in `test/keccak256.test.mjs`: the\n * empty-input digest, the `abc` digest, and the ERC-20 `Transfer` and `Approval`\n * event topics any chain explorer shows. The permutation was additionally\n * cross-checked against the platform SHA3-256, same permutation, same rate,\n * different padding byte, at input lengths spanning the 136-byte block\n * boundary. It is used only to derive a handful of event topic hashes at module\n * load, so the `bigint` lane representation costs nothing that matters.\n */\n\nimport type { Bytes32 } from \"./hex.js\";\n\nconst LANE_MASK = (1n << 64n) - 1n;\n\n/** Rate in bytes for a 256-bit digest: 200 - 2 * 32. */\nconst RATE_BYTES = 136;\n\n/** Lanes of the state absorbed per block: RATE_BYTES / 8. */\nconst RATE_LANES = RATE_BYTES / 8;\n\n/** Iota round constants. */\nconst ROUND_CONSTANTS: readonly bigint[] = [\n 0x0000000000000001n,\n 0x0000000000008082n,\n 0x800000000000808an,\n 0x8000000080008000n,\n 0x000000000000808bn,\n 0x0000000080000001n,\n 0x8000000080008081n,\n 0x8000000000008009n,\n 0x000000000000008an,\n 0x0000000000000088n,\n 0x0000000080008009n,\n 0x000000008000000an,\n 0x000000008000808bn,\n 0x800000000000008bn,\n 0x8000000000008089n,\n 0x8000000000008003n,\n 0x8000000000008002n,\n 0x8000000000000080n,\n 0x000000000000800an,\n 0x800000008000000an,\n 0x8000000080008081n,\n 0x8000000000008080n,\n 0x0000000080000001n,\n 0x8000000080008008n,\n];\n\n/**\n * Rho rotation offsets, in lane-permutation order: `((t + 1)(t + 2) / 2) mod 64`\n * for step `t`, which is the offset of the lane the walk sits on at that step.\n */\nconst ROTATIONS: readonly number[] = [\n 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,\n];\n\n/** Pi lane permutation. */\nconst LANE_ORDER: readonly number[] = [\n 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,\n];\n\nconst rotl = (lane: bigint, bits: number): bigint => {\n const shift = BigInt(bits);\n return ((lane << shift) | (lane >> (64n - shift))) & LANE_MASK;\n};\n\n/** Applies Keccak-f[1600] to `state` in place. */\nfunction permute(state: bigint[]): void {\n const column = new Array<bigint>(5).fill(0n);\n\n for (let round = 0; round < 24; round += 1) {\n // theta\n for (let x = 0; x < 5; x += 1) {\n column[x] =\n state[x]! ^ state[x + 5]! ^ state[x + 10]! ^ state[x + 15]! ^ state[x + 20]!;\n }\n for (let x = 0; x < 5; x += 1) {\n const parity = column[(x + 4) % 5]! ^ rotl(column[(x + 1) % 5]!, 1);\n for (let y = 0; y < 25; y += 5) state[y + x] = state[y + x]! ^ parity;\n }\n\n // rho and pi\n let carried = state[1]!;\n for (let step = 0; step < 24; step += 1) {\n const target = LANE_ORDER[step]!;\n const displaced = state[target]!;\n state[target] = rotl(carried, ROTATIONS[step]!);\n carried = displaced;\n }\n\n // chi\n for (let y = 0; y < 25; y += 5) {\n for (let x = 0; x < 5; x += 1) column[x] = state[y + x]!;\n for (let x = 0; x < 5; x += 1) {\n state[y + x] = state[y + x]! ^ ((column[(x + 1) % 5]! ^ LANE_MASK) & column[(x + 2) % 5]!);\n }\n }\n\n // iota\n state[0] = state[0]! ^ ROUND_CONSTANTS[round]!;\n }\n}\n\n/** Hashes raw bytes and renders the digest as a 32-byte word. */\nexport function keccak256(data: Uint8Array): Bytes32 {\n const state = new Array<bigint>(25).fill(0n);\n\n const blocks = Math.ceil((data.length + 1) / RATE_BYTES);\n const padded = new Uint8Array(blocks * RATE_BYTES);\n padded.set(data);\n padded[data.length] = 0x01;\n const finalByte = padded.length - 1;\n padded[finalByte] = padded[finalByte]! | 0x80;\n\n for (let offset = 0; offset < padded.length; offset += RATE_BYTES) {\n for (let lane = 0; lane < RATE_LANES; lane += 1) {\n let word = 0n;\n for (let byte = 7; byte >= 0; byte -= 1) {\n word = (word << 8n) | BigInt(padded[offset + lane * 8 + byte]!);\n }\n state[lane] = state[lane]! ^ word;\n }\n permute(state);\n }\n\n let digest = \"\";\n for (let lane = 0; lane < 4; lane += 1) {\n const word = state[lane]!;\n for (let byte = 0; byte < 8; byte += 1) {\n digest += ((word >> BigInt(byte * 8)) & 0xffn).toString(16).padStart(2, \"0\");\n }\n }\n return `0x${digest}`;\n}\n\n/**\n * Hashes an ASCII string. Event and function signatures are ASCII by\n * construction, so refusing anything above `0x7f` keeps encoding out of the\n * picture entirely.\n *\n * @throws RangeError when `text` carries a non-ASCII code unit.\n */\nexport function keccak256Ascii(text: string): Bytes32 {\n const bytes = new Uint8Array(text.length);\n for (let i = 0; i < text.length; i += 1) {\n const code = text.charCodeAt(i);\n if (code > 0x7f) {\n throw new RangeError(\n `keccak256Ascii: expected ASCII only, found code unit ${code} at index ${i}`,\n );\n }\n bytes[i] = code;\n }\n return keccak256(bytes);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"keccak256.js","sourceRoot":"","sources":["../src/keccak256.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEnC,wDAAwD;AACxD,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,6DAA6D;AAC7D,MAAM,UAAU,GAAG,UAAU,GAAG,CAAC,CAAC;AAElC,4BAA4B;AAC5B,MAAM,eAAe,GAAsB;IACzC,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,mBAAm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,CAAC,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IACD,OAAO,KAAK,MAAM,EAAE,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAChC,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,UAAU,CAClB,wDAAwD,IAAI,aAAa,CAAC,EAAE,CAC7E,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["/**\n * Keccak-256, written against native `bigint`.\n *\n * `@tabai/shared` carries zero runtime dependencies, and Keccak-256 is not\n * SHA3-256 (the two differ in their padding byte), so the platform hash\n * primitives cannot stand in for it. The permutation below is therefore\n * implemented here: 24 rounds of Keccak-f[1600] over 25 64-bit lanes, rate 136\n * bytes, capacity 64 bytes, `0x01` domain padding.\n *\n * Correctness is pinned by published digests in `test/keccak256.test.mjs`: the\n * empty-input digest, the `abc` digest, and the ERC-20 `Transfer` and `Approval`\n * event topics any chain explorer shows, plus a multi-block vector whose SHA3-256\n * sibling (same permutation and rate, different padding byte) matches the\n * platform hash across the 136-byte block boundary. It is used only to derive a\n * handful of event topics and typehashes at module load, so the `bigint` lane\n * representation costs nothing that matters.\n */\n\nimport type { Bytes32 } from \"./hex.js\";\n\nconst LANE_MASK = (1n << 64n) - 1n;\n\n/** Rate in bytes for a 256-bit digest: 200 - 2 * 32. */\nconst RATE_BYTES = 136;\n\n/** Lanes of the state absorbed per block: RATE_BYTES / 8. */\nconst RATE_LANES = RATE_BYTES / 8;\n\n/** Iota round constants. */\nconst ROUND_CONSTANTS: readonly bigint[] = [\n 0x0000000000000001n,\n 0x0000000000008082n,\n 0x800000000000808an,\n 0x8000000080008000n,\n 0x000000000000808bn,\n 0x0000000080000001n,\n 0x8000000080008081n,\n 0x8000000000008009n,\n 0x000000000000008an,\n 0x0000000000000088n,\n 0x0000000080008009n,\n 0x000000008000000an,\n 0x000000008000808bn,\n 0x800000000000008bn,\n 0x8000000000008089n,\n 0x8000000000008003n,\n 0x8000000000008002n,\n 0x8000000000000080n,\n 0x000000000000800an,\n 0x800000008000000an,\n 0x8000000080008081n,\n 0x8000000000008080n,\n 0x0000000080000001n,\n 0x8000000080008008n,\n];\n\n/**\n * Rho rotation offsets, in lane-permutation order: `((t + 1)(t + 2) / 2) mod 64`\n * for step `t`, which is the offset of the lane the walk sits on at that step.\n */\nconst ROTATIONS: readonly number[] = [\n 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,\n];\n\n/** Pi lane permutation. */\nconst LANE_ORDER: readonly number[] = [\n 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,\n];\n\nconst rotl = (lane: bigint, bits: number): bigint => {\n const shift = BigInt(bits);\n return ((lane << shift) | (lane >> (64n - shift))) & LANE_MASK;\n};\n\n/** Applies Keccak-f[1600] to `state` in place. */\nfunction permute(state: bigint[]): void {\n const column = new Array<bigint>(5).fill(0n);\n\n for (let round = 0; round < 24; round += 1) {\n // theta\n for (let x = 0; x < 5; x += 1) {\n column[x] =\n state[x]! ^ state[x + 5]! ^ state[x + 10]! ^ state[x + 15]! ^ state[x + 20]!;\n }\n for (let x = 0; x < 5; x += 1) {\n const parity = column[(x + 4) % 5]! ^ rotl(column[(x + 1) % 5]!, 1);\n for (let y = 0; y < 25; y += 5) state[y + x] = state[y + x]! ^ parity;\n }\n\n // rho and pi\n let carried = state[1]!;\n for (let step = 0; step < 24; step += 1) {\n const target = LANE_ORDER[step]!;\n const displaced = state[target]!;\n state[target] = rotl(carried, ROTATIONS[step]!);\n carried = displaced;\n }\n\n // chi\n for (let y = 0; y < 25; y += 5) {\n for (let x = 0; x < 5; x += 1) column[x] = state[y + x]!;\n for (let x = 0; x < 5; x += 1) {\n state[y + x] = state[y + x]! ^ ((column[(x + 1) % 5]! ^ LANE_MASK) & column[(x + 2) % 5]!);\n }\n }\n\n // iota\n state[0] = state[0]! ^ ROUND_CONSTANTS[round]!;\n }\n}\n\n/** Hashes raw bytes and renders the digest as a 32-byte word. */\nexport function keccak256(data: Uint8Array): Bytes32 {\n const state = new Array<bigint>(25).fill(0n);\n\n const blocks = Math.ceil((data.length + 1) / RATE_BYTES);\n const padded = new Uint8Array(blocks * RATE_BYTES);\n padded.set(data);\n padded[data.length] = 0x01;\n const finalByte = padded.length - 1;\n padded[finalByte] = padded[finalByte]! | 0x80;\n\n for (let offset = 0; offset < padded.length; offset += RATE_BYTES) {\n for (let lane = 0; lane < RATE_LANES; lane += 1) {\n let word = 0n;\n for (let byte = 7; byte >= 0; byte -= 1) {\n word = (word << 8n) | BigInt(padded[offset + lane * 8 + byte]!);\n }\n state[lane] = state[lane]! ^ word;\n }\n permute(state);\n }\n\n let digest = \"\";\n for (let lane = 0; lane < 4; lane += 1) {\n const word = state[lane]!;\n for (let byte = 0; byte < 8; byte += 1) {\n digest += ((word >> BigInt(byte * 8)) & 0xffn).toString(16).padStart(2, \"0\");\n }\n }\n return `0x${digest}`;\n}\n\n/**\n * Hashes an ASCII string. Event and function signatures are ASCII by\n * construction, so refusing anything above `0x7f` keeps encoding out of the\n * picture entirely.\n *\n * @throws RangeError when `text` carries a non-ASCII code unit.\n */\nexport function keccak256Ascii(text: string): Bytes32 {\n const bytes = new Uint8Array(text.length);\n for (let i = 0; i < text.length; i += 1) {\n const code = text.charCodeAt(i);\n if (code > 0x7f) {\n throw new RangeError(\n `keccak256Ascii: expected ASCII only, found code unit ${code} at index ${i}`,\n );\n }\n bytes[i] = code;\n }\n return keccak256(bytes);\n}\n"]}
|
package/dist/_shared/result.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The zero-throw result type.
|
|
3
3
|
*
|
|
4
|
-
* No exported SDK function throws. `wrap`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* No exported SDK function throws. `wrap` and `wrapSync` are where a thrown
|
|
5
|
+
* value from a dependency becomes a `TabError`, so a caller only ever branches
|
|
6
|
+
* on `result.ok` and never writes a `try` block of its own.
|
|
7
7
|
*
|
|
8
8
|
* HTTP surfaces map `category` to a status code:
|
|
9
9
|
* `VALIDATION` 400, `AUTHORISATION` 403, `NOT_FOUND` 404, `LIMIT` 402,
|
|
10
10
|
* `CONFLICT` 409, `UPSTREAM` 502, `UNAVAILABLE` 503, and
|
|
11
11
|
* `CHAIN`/`INTERNAL` 500.
|
|
12
|
-
*
|
|
13
|
-
* Requirements: 21.5
|
|
14
12
|
*/
|
|
15
13
|
export type ErrorCategory =
|
|
16
14
|
/** caller-supplied input is malformed */
|
|
@@ -58,7 +56,8 @@ export declare const ok: <T>(value: T) => Result<T>;
|
|
|
58
56
|
export declare const err: (error: TabError) => Result<never>;
|
|
59
57
|
/**
|
|
60
58
|
* Runs `fn` and converts a thrown value into a `TabError` through `map`.
|
|
61
|
-
*
|
|
59
|
+
* Reach for it at the edge of a dependency call, so the thrown value becomes a
|
|
60
|
+
* `Result` there rather than escaping to the caller.
|
|
62
61
|
*/
|
|
63
62
|
export declare const wrap: <T>(fn: () => Promise<T>, map: (e: unknown) => TabError) => Promise<Result<T>>;
|
|
64
63
|
/** The synchronous sibling of `wrap`, for pure computations that validate their input. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,aAAa;AACvB,yCAAyC;AACvC,YAAY;AACd,2DAA2D;GACzD,eAAe;AACjB,wDAAwD;GACtD,WAAW;AACb,yCAAyC;GACvC,OAAO;AACT,6CAA6C;GAC3C,OAAO;AACT,+DAA+D;GAC7D,UAAU;AACZ,qDAAqD;GACnD,UAAU;AACZ,oCAAoC;GAClC,aAAa;AACf,6CAA6C;GAC3C,UAAU,CAAC;AAEf,2EAA2E;AAC3E,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAU3E,CAAC;AAEF,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,aAAa,CAAC;IACxB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACpD,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEhF,eAAO,MAAM,EAAE,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,CAA0B,CAAC;AAEpE,eAAO,MAAM,GAAG,GAAI,OAAO,QAAQ,KAAG,MAAM,CAAC,KAAK,CAA2B,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAU,CAAC,EAC1B,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,KAAK,CAAC,CAAC,EAAE,OAAO,KAAK,QAAQ,KAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAMnB,CAAC;AAEF,0FAA0F;AAC1F,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,OAAO,KAAK,QAAQ,KAAG,MAAM,CAAC,CAAC,CAMhF,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAKnE,CAAC;AAEF,0FAA0F;AAC1F,eAAO,MAAM,IAAI,GAAI,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC,KAAG,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAe,CAAC;AAE1F,uDAAuD;AACvD,eAAO,MAAM,YAAY,GAAI,OAAO,QAAQ,KAAG,MAAiD,CAAC"}
|
package/dist/_shared/result.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The zero-throw result type.
|
|
3
3
|
*
|
|
4
|
-
* No exported SDK function throws. `wrap`
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* No exported SDK function throws. `wrap` and `wrapSync` are where a thrown
|
|
5
|
+
* value from a dependency becomes a `TabError`, so a caller only ever branches
|
|
6
|
+
* on `result.ok` and never writes a `try` block of its own.
|
|
7
7
|
*
|
|
8
8
|
* HTTP surfaces map `category` to a status code:
|
|
9
9
|
* `VALIDATION` 400, `AUTHORISATION` 403, `NOT_FOUND` 404, `LIMIT` 402,
|
|
10
10
|
* `CONFLICT` 409, `UPSTREAM` 502, `UNAVAILABLE` 503, and
|
|
11
11
|
* `CHAIN`/`INTERNAL` 500.
|
|
12
|
-
*
|
|
13
|
-
* Requirements: 21.5
|
|
14
12
|
*/
|
|
15
13
|
/** The HTTP status every category maps to, so services cannot disagree. */
|
|
16
14
|
export const HTTP_STATUS_BY_CATEGORY = {
|
|
@@ -28,7 +26,8 @@ export const ok = (value) => ({ ok: true, value });
|
|
|
28
26
|
export const err = (error) => ({ ok: false, error });
|
|
29
27
|
/**
|
|
30
28
|
* Runs `fn` and converts a thrown value into a `TabError` through `map`.
|
|
31
|
-
*
|
|
29
|
+
* Reach for it at the edge of a dependency call, so the thrown value becomes a
|
|
30
|
+
* `Result` there rather than escaping to the caller.
|
|
32
31
|
*/
|
|
33
32
|
export const wrap = async (fn, map) => {
|
|
34
33
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAsBH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAA4C;IAC9E,UAAU,EAAE,GAAG;IACf,aAAa,EAAE,GAAG;IAClB,SAAS,EAAE,GAAG;IACd,KAAK,EAAE,GAAG;IACV,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,GAAG;IACb,WAAW,EAAE,GAAG;IAChB,QAAQ,EAAE,GAAG;CACd,CAAC;AAgBF,MAAM,CAAC,MAA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C,MAAM,CAAC,EAAE,CAAC;AAE1F,uDAAuD;AACvD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAe,EAAU,EAAE,CAAC,uBAAuB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC","sourcesContent":["/**\n * The zero-throw result type.\n *\n * No exported SDK function throws. `wrap` and `wrapSync` are where a thrown\n * value from a dependency becomes a `TabError`, so a caller only ever branches\n * on `result.ok` and never writes a `try` block of its own.\n *\n * HTTP surfaces map `category` to a status code:\n * `VALIDATION` 400, `AUTHORISATION` 403, `NOT_FOUND` 404, `LIMIT` 402,\n * `CONFLICT` 409, `UPSTREAM` 502, `UNAVAILABLE` 503, and\n * `CHAIN`/`INTERNAL` 500.\n */\n\nexport type ErrorCategory =\n /** caller-supplied input is malformed */\n | \"VALIDATION\"\n /** missing, expired, or exceeded spending authorisation */\n | \"AUTHORISATION\"\n /** unknown service, agent, asset, tab, or settlement */\n | \"NOT_FOUND\"\n /** credit limit or headroom exhausted */\n | \"LIMIT\"\n /** A Monad transaction failed or reverted */\n | \"CHAIN\"\n /** RPC endpoint, module loader, or service endpoint failure */\n | \"UPSTREAM\"\n /** duplicate registration, timelock still pending */\n | \"CONFLICT\"\n /** the write path is unavailable */\n | \"UNAVAILABLE\"\n /** invariant violated inside our own code */\n | \"INTERNAL\";\n\n/** The HTTP status every category maps to, so services cannot disagree. */\nexport const HTTP_STATUS_BY_CATEGORY: Readonly<Record<ErrorCategory, number>> = {\n VALIDATION: 400,\n AUTHORISATION: 403,\n NOT_FOUND: 404,\n LIMIT: 402,\n CHAIN: 500,\n UPSTREAM: 502,\n CONFLICT: 409,\n UNAVAILABLE: 503,\n INTERNAL: 500,\n};\n\nexport interface TabError {\n category: ErrorCategory;\n /** stable and machine-readable, for example `LIMIT_EXCEEDED` */\n code: string;\n /** human-readable, carrying no secret and no stack trace */\n message: string;\n retryable: boolean;\n retryAfterMs?: number;\n details?: Record<string, string | number | boolean>;\n cause?: { code: string; message: string };\n}\n\nexport type Result<T> = { ok: true; value: T } | { ok: false; error: TabError };\n\nexport const ok = <T>(value: T): Result<T> => ({ ok: true, value });\n\nexport const err = (error: TabError): Result<never> => ({ ok: false, error });\n\n/**\n * Runs `fn` and converts a thrown value into a `TabError` through `map`.\n * Reach for it at the edge of a dependency call, so the thrown value becomes a\n * `Result` there rather than escaping to the caller.\n */\nexport const wrap = async <T>(\n fn: () => Promise<T>,\n map: (e: unknown) => TabError,\n): Promise<Result<T>> => {\n try {\n return ok(await fn());\n } catch (e) {\n return err(map(e));\n }\n};\n\n/** The synchronous sibling of `wrap`, for pure computations that validate their input. */\nexport const wrapSync = <T>(fn: () => T, map: (e: unknown) => TabError): Result<T> => {\n try {\n return ok(fn());\n } catch (e) {\n return err(map(e));\n }\n};\n\n/** Narrows an unknown thrown value into the `cause` shape a `TabError` accepts. */\nexport const causeOf = (e: unknown): { code: string; message: string } => {\n if (e instanceof Error) {\n return { code: e.name, message: e.message };\n }\n return { code: \"UNKNOWN\", message: String(e) };\n};\n\n/** True when the result carries a value. Present so callers can filter without a cast. */\nexport const isOk = <T>(result: Result<T>): result is { ok: true; value: T } => result.ok;\n\n/** Returns the HTTP status a failed result maps to. */\nexport const httpStatusOf = (error: TabError): number => HTTP_STATUS_BY_CATEGORY[error.category];\n"]}
|
|
@@ -28,8 +28,6 @@
|
|
|
28
28
|
* file that fails to parse is not overwritten: it is reported, because a
|
|
29
29
|
* half-written config file is a client that will not start and the caller is the
|
|
30
30
|
* only one who knows what was in it.
|
|
31
|
-
*
|
|
32
|
-
* Requirements: 25.5, 25.6
|
|
33
31
|
*/
|
|
34
32
|
import type { Result } from "../_shared/index.js";
|
|
35
33
|
import { type JsonRecord } from "../mcp/json.js";
|
|
@@ -94,9 +92,10 @@ export declare function buildTabStanza(env?: StanzaEnv): TabStanza;
|
|
|
94
92
|
*
|
|
95
93
|
* Both a name check and a shape check, because either alone is defeated by the
|
|
96
94
|
* obvious mistake: a key under an innocuous name has the shape, and an empty
|
|
97
|
-
* placeholder under `PRIVATE_KEY` has the name.
|
|
98
|
-
*
|
|
99
|
-
*
|
|
95
|
+
* placeholder under `PRIVATE_KEY` has the name. `connect` runs this on the `tab`
|
|
96
|
+
* stanza it is about to write, before anything touches the disk, and
|
|
97
|
+
* `tab doctor` runs it on the stanza already in the file, which is where a
|
|
98
|
+
* secret added by hand shows up.
|
|
100
99
|
*/
|
|
101
100
|
export declare function assertNoSecret(stanza: unknown, where?: string): Result<void>;
|
|
102
101
|
export interface MergeOutcome {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../../src/cli/client-config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"client-config.d.ts","sourceRoot":"","sources":["../../src/cli/client-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE3D,qDAAqD;AACrD,MAAM,WAAW,eAAe;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,yFAAyF;IACzF,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,0FAA0F;IAC1F,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAoCD,8EAA8E;AAC9E,eAAO,MAAM,cAAc,4EAA6E,CAAC;AAUzG,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACjC,QAAQ,CAAC,GAAG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AC,YAAY,CAAC,CA4B5F;AAID,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC,CA4BxE;AAED,uFAAuF;AACvF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,IAAI,IAAI,KAAG,MACS,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,IAAI,GACP,MAAM,CAAC,YAAY,CAAC,CAiCtB;AAID;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,MAAM,CAuD9E"}
|
|
@@ -28,8 +28,6 @@
|
|
|
28
28
|
* file that fails to parse is not overwritten: it is reported, because a
|
|
29
29
|
* half-written config file is a client that will not start and the caller is the
|
|
30
30
|
* only one who knows what was in it.
|
|
31
|
-
*
|
|
32
|
-
* Requirements: 25.5, 25.6
|
|
33
31
|
*/
|
|
34
32
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
35
33
|
import { homedir, platform } from "node:os";
|
|
@@ -171,9 +169,10 @@ const SECRET_SHAPE = /^(0x)?[0-9a-fA-F]{64}$/;
|
|
|
171
169
|
*
|
|
172
170
|
* Both a name check and a shape check, because either alone is defeated by the
|
|
173
171
|
* obvious mistake: a key under an innocuous name has the shape, and an empty
|
|
174
|
-
* placeholder under `PRIVATE_KEY` has the name.
|
|
175
|
-
*
|
|
176
|
-
*
|
|
172
|
+
* placeholder under `PRIVATE_KEY` has the name. `connect` runs this on the `tab`
|
|
173
|
+
* stanza it is about to write, before anything touches the disk, and
|
|
174
|
+
* `tab doctor` runs it on the stanza already in the file, which is where a
|
|
175
|
+
* secret added by hand shows up.
|
|
177
176
|
*/
|
|
178
177
|
export function assertNoSecret(stanza, where = "the tab stanza") {
|
|
179
178
|
const problems = [];
|