@tetsuo-ai/marketplace-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/chunk-5OTKSRHM.js +128 -0
- package/dist/chunk-5OTKSRHM.js.map +1 -0
- package/dist/chunk-ABS77JB2.js +94 -0
- package/dist/chunk-ABS77JB2.js.map +1 -0
- package/dist/chunk-GN5DYVN5.js +35 -0
- package/dist/chunk-GN5DYVN5.js.map +1 -0
- package/dist/chunk-KJMR6OGC.js +1198 -0
- package/dist/chunk-KJMR6OGC.js.map +1 -0
- package/dist/chunk-YORZNYZZ.js +107 -0
- package/dist/chunk-YORZNYZZ.js.map +1 -0
- package/dist/components/agenc-components.css +570 -0
- package/dist/components/index.cjs +1335 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +5 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/hooks/index.cjs +493 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +294 -0
- package/dist/hooks/index.d.ts +294 -0
- package/dist/hooks/index.js +339 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index-BLrlBVj-.d.cts +1129 -0
- package/dist/index-CKTYsNPH.d.ts +1129 -0
- package/dist/index.cjs +1690 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +235 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -0
- package/dist/signers/index.cjs +166 -0
- package/dist/signers/index.cjs.map +1 -0
- package/dist/signers/index.d.cts +136 -0
- package/dist/signers/index.d.ts +136 -0
- package/dist/signers/index.js +4 -0
- package/dist/signers/index.js.map +1 -0
- package/dist/testing/index.cjs +62 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +71 -0
- package/dist/testing/index.d.ts +71 -0
- package/dist/testing/index.js +60 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/theme/agenc-tailwind-preset.cjs +184 -0
- package/dist/theme/agenc-tokens.css +132 -0
- package/dist/types-jvISR6bc.d.cts +135 -0
- package/dist/types-jvISR6bc.d.ts +135 -0
- package/dist/useAgentTrackRecord-BLf1nrbu.d.cts +249 -0
- package/dist/useAgentTrackRecord-BLf1nrbu.d.ts +249 -0
- package/package.json +139 -0
- package/src/components/DisputeBanner.stories.tsx +39 -0
- package/src/components/DisputeBanner.tsx +110 -0
- package/src/components/HireButton.stories.tsx +72 -0
- package/src/components/HireButton.tsx +151 -0
- package/src/components/HireCheckoutModal.stories.tsx +107 -0
- package/src/components/HireCheckoutModal.tsx +284 -0
- package/src/components/ListingCard.stories.tsx +55 -0
- package/src/components/ListingCard.tsx +148 -0
- package/src/components/ListingGrid.stories.tsx +44 -0
- package/src/components/ListingGrid.tsx +137 -0
- package/src/components/Modal.tsx +121 -0
- package/src/components/PoweredByAgenC.tsx +85 -0
- package/src/components/ProviderCard.stories.tsx +61 -0
- package/src/components/ProviderCard.tsx +154 -0
- package/src/components/ReferrerDisclosure.tsx +67 -0
- package/src/components/ReviewPanel.stories.tsx +65 -0
- package/src/components/ReviewPanel.tsx +141 -0
- package/src/components/TaskTimeline.stories.tsx +43 -0
- package/src/components/TaskTimeline.tsx +156 -0
- package/src/components/__fixtures__/index.tsx +173 -0
- package/src/components/agenc-components.css +570 -0
- package/src/components/badges.tsx +115 -0
- package/src/components/format.ts +150 -0
- package/src/components/index.ts +102 -0
- package/src/components/primitives.tsx +236 -0
- package/src/components/strings.ts +131 -0
- package/src/components/useFocusTrap.ts +122 -0
- package/src/hooks/index.ts +90 -0
- package/src/hooks/internal.ts +70 -0
- package/src/hooks/useAgentTrackRecord.ts +166 -0
- package/src/hooks/useDispute.ts +130 -0
- package/src/hooks/useHire.ts +198 -0
- package/src/hooks/useListing.ts +138 -0
- package/src/hooks/useListings.ts +133 -0
- package/src/hooks/useReferrerEarnings.ts +134 -0
- package/src/hooks/useSubmissionReview.ts +179 -0
- package/src/hooks/useTaskStatus.ts +192 -0
- package/src/hooks/useWalletSigner.ts +99 -0
- package/src/index.ts +170 -0
- package/src/provider/AgencProvider.tsx +169 -0
- package/src/provider/context.ts +35 -0
- package/src/provider/index.ts +17 -0
- package/src/provider/network.ts +68 -0
- package/src/provider/referrer.ts +97 -0
- package/src/signers/README.md +130 -0
- package/src/signers/embedded-wallet-mock.ts +158 -0
- package/src/signers/embedded-wallet.ts +64 -0
- package/src/signers/index.ts +48 -0
- package/src/signers/strings.ts +39 -0
- package/src/signers/types.ts +158 -0
- package/src/signers/wallet-account.ts +128 -0
- package/src/signers/wallet-adapter.ts +149 -0
- package/src/strings/index.ts +119 -0
- package/src/testing/index.ts +24 -0
- package/src/theme/agenc-tailwind-preset.cjs +184 -0
- package/src/theme/agenc-tokens.css +132 -0
- package/src/theme/index.ts +94 -0
- package/src/transport/index.ts +164 -0
- package/src/types.ts +224 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @tetsuo-ai/marketplace-react
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
Initial scaffold (PLAN.md P4.2 / PLAN_2.md Part A).
|
|
6
|
+
|
|
7
|
+
- `<AgencProvider>` context: indexer-first read transport with RPC/gPA fallback,
|
|
8
|
+
the write `MarketplaceClient` (with a `client` override slot), the resolved
|
|
9
|
+
referrer config and `resolveReferrerCapability()` (the P6.2 gate — not-live
|
|
10
|
+
today), and the signer. Wraps a bundled TanStack Query client.
|
|
11
|
+
- `createReadTransport()` unified read interface
|
|
12
|
+
(`listActiveListings` / `getListing` / `listingHires` / `agentTrackRecord`).
|
|
13
|
+
- Vendored AgenC brand theme (`--agenc-*` CSS custom properties) +
|
|
14
|
+
side-effect `theme.css` export and a Tailwind preset.
|
|
15
|
+
- Minimal English string catalog + `t(id, vars?)` resolver.
|
|
16
|
+
- Prebuilt themable components (PLAN_2 A3), exported from the root and the
|
|
17
|
+
tree-shakeable `./components` subpath: `ListingCard`, `ListingGrid`,
|
|
18
|
+
`HireButton` (connected over `useHire`), `HireCheckoutModal` (accessible money
|
|
19
|
+
modal: price + moderation badge + escrow note + referrer disclosure +
|
|
20
|
+
confirmation states, focus trap + ARIA), `TaskTimeline`, `ReviewPanel`,
|
|
21
|
+
`DisputeBanner`, `ProviderCard`, `PoweredByAgenC`, plus shared primitives
|
|
22
|
+
(`Modal`, `Button`, `Badge`, `Spinner`, `StateMessage`) and the
|
|
23
|
+
`ModerationBadge`/`VerifiedBadge`. Each accepts `unstyled` for white-label and
|
|
24
|
+
routes copy through a `components.*` string catalog. The referrer disclosure
|
|
25
|
+
honors the P6.2 gate (pending-support copy; never claims a charged fee).
|
|
26
|
+
- Optional component-recipe stylesheet at `./components.css` (no CSS-in-JS).
|
|
27
|
+
- Ladle stories for every component state (`.ladle/`, `npm run ladle`) and an
|
|
28
|
+
axe accessibility check in the test suite (fails on serious/critical).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tetsuo AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @tetsuo-ai/marketplace-react
|
|
2
|
+
|
|
3
|
+
Headless React hooks + themable components for the **AgenC marketplace** — built
|
|
4
|
+
on [`@tetsuo-ai/marketplace-sdk`](../sdk-ts). SSR-safe, tree-shakeable, and zero
|
|
5
|
+
required CSS imports for headless use.
|
|
6
|
+
|
|
7
|
+
> Status: **foundation layer** (PLAN.md P4.2 / PLAN_2 Part A). This package
|
|
8
|
+
> currently ships `<AgencProvider>`, the read-transport abstraction, the
|
|
9
|
+
> (P6.2-gated) referrer config, the `--agenc-*` theme contract, and the string
|
|
10
|
+
> catalog. Hooks (`useListings`, `useHire`, …) and components (`ListingCard`, …)
|
|
11
|
+
> land in the next phases and bind to the context exposed here.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @tetsuo-ai/marketplace-react @tetsuo-ai/marketplace-sdk \
|
|
17
|
+
@solana/kit @solana/program-client-core react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Peer deps: `react >=18`, `@tetsuo-ai/marketplace-sdk`, and the SDK's own peer set
|
|
21
|
+
mirrored exactly (`@solana/kit`, `@solana/program-client-core`). TanStack Query is
|
|
22
|
+
bundled as a dependency — you do not install it.
|
|
23
|
+
|
|
24
|
+
## The provider
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { AgencProvider } from "@tetsuo-ai/marketplace-react";
|
|
28
|
+
// Optional: load the default AgenC theme tokens (--agenc-* custom properties).
|
|
29
|
+
import "@tetsuo-ai/marketplace-react/theme.css";
|
|
30
|
+
|
|
31
|
+
export default function App() {
|
|
32
|
+
return (
|
|
33
|
+
<AgencProvider
|
|
34
|
+
config={{
|
|
35
|
+
network: "devnet",
|
|
36
|
+
// Indexer-first reads (the scale path). Omit to use a gPA transport.
|
|
37
|
+
indexer: { baseUrl: "https://marketplace.agenc.tech" },
|
|
38
|
+
// Write client is built from rpcUrl + signer when both are present,
|
|
39
|
+
// or pass a pre-built `client` (e.g. from startLocalMarketplace()).
|
|
40
|
+
// rpcUrl, signer,
|
|
41
|
+
// Referrer config is accepted + validated, but NOT injected until the
|
|
42
|
+
// on-chain P6.2 settlement leg is live (see "Referrer gate" below).
|
|
43
|
+
// referrer: { wallet: "<base58>", feeBps: 250 },
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<YourMarketplaceUI />
|
|
47
|
+
</AgencProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`<AgencProvider>` wraps a bundled TanStack `QueryClientProvider` and exposes one
|
|
53
|
+
context (read it with `useAgencContext()`):
|
|
54
|
+
|
|
55
|
+
| field | type | notes |
|
|
56
|
+
|---|---|---|
|
|
57
|
+
| `network` | `"localnet" \| "devnet" \| "mainnet"` | resolved target |
|
|
58
|
+
| `read` | `ReadTransport` | indexer-first, gPA fallback |
|
|
59
|
+
| `client` | `MarketplaceClient \| null` | write runtime; `null` if not configured |
|
|
60
|
+
| `signer` | `TransactionSigner \| null` | the configured signer |
|
|
61
|
+
| `referrer` | `ValidatedReferrerConfig \| null` | validated + stored |
|
|
62
|
+
| `resolveReferrerCapability()` | `ReferrerCapability` | the **P6.2 gate** |
|
|
63
|
+
|
|
64
|
+
### Override slots (test seams, public API)
|
|
65
|
+
|
|
66
|
+
- `config.client` — a pre-built `MarketplaceClient`. `startLocalMarketplace().client`
|
|
67
|
+
(from `@tetsuo-ai/marketplace-sdk/testing`) plugs straight in for hook e2e.
|
|
68
|
+
- `config.queryTransport` — a pre-built `ReadTransport` (mocks / SSR fixtures).
|
|
69
|
+
|
|
70
|
+
## Read transport
|
|
71
|
+
|
|
72
|
+
`createReadTransport({ indexer?, rpc?, queryTransport? })` returns one
|
|
73
|
+
`ReadTransport` with `listActiveListings` / `getListing` / `listingHires` /
|
|
74
|
+
`agentTrackRecord`. With an `indexer.baseUrl` it routes through the SDK indexer
|
|
75
|
+
client (the scale path); otherwise it falls back to the SDK gPA `listActiveListings`
|
|
76
|
+
over a kit RPC / `ProgramAccountsTransport` (the trustless path). The two backends
|
|
77
|
+
return parity shapes by SDK design, so callers never branch on which is live.
|
|
78
|
+
`listingHires` / `agentTrackRecord` are indexer-native; the gPA fallback rejects
|
|
79
|
+
them with a typed `ReadTransportUnsupportedError`.
|
|
80
|
+
|
|
81
|
+
## Referrer gate (P6.2)
|
|
82
|
+
|
|
83
|
+
Referral fees require an **unbuilt** on-chain change (PLAN.md P6.2 — referrer args
|
|
84
|
+
+ a 4th settlement leg). Until it ships:
|
|
85
|
+
|
|
86
|
+
- `referrer: { wallet, feeBps }` is **accepted, validated, and stored** (bad base58
|
|
87
|
+
throws; out-of-range basis points are rejected);
|
|
88
|
+
- it is **never injected** into a hire;
|
|
89
|
+
- `resolveReferrerCapability()` returns `{ live: false, reason }`;
|
|
90
|
+
- disclosure UI may still show "this site earns a referral fee (pending protocol
|
|
91
|
+
support)" — but earnings are never faked.
|
|
92
|
+
|
|
93
|
+
When P6.2 deploys, `resolveReferrerCapability()` will consult P6.5
|
|
94
|
+
`getDeployedSurface` and flip to `live: true` on supporting clusters.
|
|
95
|
+
|
|
96
|
+
## Components
|
|
97
|
+
|
|
98
|
+
Prebuilt, themable components are exported from the root (and tree-shakeable via
|
|
99
|
+
`@tetsuo-ai/marketplace-react/components`):
|
|
100
|
+
|
|
101
|
+
| Component | What it renders | Wiring |
|
|
102
|
+
|---|---|---|
|
|
103
|
+
| `ListingCard` | one decoded listing (name, price, category, provider, moderation badge) | presentational (`ListingRow`) |
|
|
104
|
+
| `ListingGrid` | a responsive grid of cards + loading/empty/error/load-more | takes `useListings()` fields |
|
|
105
|
+
| `HireButton` | price-aware CTA that opens the checkout and runs the hire | **connected** (`useHire` + `useWalletSigner`) |
|
|
106
|
+
| `HireCheckoutModal` | accessible money modal: price, moderation badge, escrow note, referrer disclosure, confirm/pending/funded/error | presentational (map `useHire()`) |
|
|
107
|
+
| `TaskTimeline` | task lifecycle (Open→In progress→Pending review→Completed) + off-path terminals | takes `useTaskStatus().status` |
|
|
108
|
+
| `ReviewPanel` | buyer accept / reject / request-changes | takes `useSubmissionReview()` |
|
|
109
|
+
| `DisputeBanner` | open-dispute alert + initiate entry point | takes `useDispute()` |
|
|
110
|
+
| `ProviderCard` | track record (provisional rates) + verified badge | takes `useAgentTrackRecord().trackRecord` |
|
|
111
|
+
| `PoweredByAgenC` | optional attribution mark linking the trust page | standalone |
|
|
112
|
+
|
|
113
|
+
Accessibility is structural: `HireCheckoutModal` ships a focus trap, full
|
|
114
|
+
keyboard navigation, ARIA dialog roles, and live-region status — it is a money
|
|
115
|
+
modal published to third parties. The `ModerationBadge` shows the attestation
|
|
116
|
+
**state only**; the unattested-listing render toggle is gated on the P6.8
|
|
117
|
+
[HUMAN] neutrality decision and is intentionally not built.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { HireButton } from "@tetsuo-ai/marketplace-react";
|
|
121
|
+
import { randomId32 } from "@tetsuo-ai/marketplace-sdk";
|
|
122
|
+
|
|
123
|
+
<HireButton
|
|
124
|
+
listing={row}
|
|
125
|
+
buildHireInput={(l) => ({
|
|
126
|
+
listing: l.address,
|
|
127
|
+
creatorAgent: myAgentPda,
|
|
128
|
+
taskId: randomId32(),
|
|
129
|
+
expectedPrice: l.account.price,
|
|
130
|
+
expectedVersion: l.account.version,
|
|
131
|
+
})}
|
|
132
|
+
onHired={(taskPda) => router.push(`/tasks/${taskPda}`)}
|
|
133
|
+
/>;
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Ladle (component workshop)
|
|
137
|
+
|
|
138
|
+
Every component's states (default / loading / error / empty) have a story.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npm run ladle # dev server at http://localhost:61000
|
|
142
|
+
npm run ladle:build # static build into ./build (CI screenshot / preview)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
An axe accessibility check runs over rendered components in the test suite
|
|
146
|
+
(`test/components/a11y.test.tsx`); it fails on any `serious`/`critical`
|
|
147
|
+
violation. Run it with `npm test`.
|
|
148
|
+
|
|
149
|
+
## Theming
|
|
150
|
+
|
|
151
|
+
Components style themselves through `--agenc-*` CSS custom properties. Load the
|
|
152
|
+
default AgenC theme for the styled look:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import "@tetsuo-ai/marketplace-react/theme.css"; // foundation tokens
|
|
156
|
+
import "@tetsuo-ai/marketplace-react/components.css"; // component recipes
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Override any token on an ancestor, or use the Tailwind preset at
|
|
160
|
+
`@tetsuo-ai/marketplace-react/tailwind-preset` (requires Tailwind in your app).
|
|
161
|
+
There is no CSS-in-JS runtime, and the CSS is entirely optional: every component
|
|
162
|
+
accepts an `unstyled` prop for full white-label (it then emits semantic markup +
|
|
163
|
+
ARIA with no `--agenc-*` classes).
|
|
164
|
+
|
|
165
|
+
## Internationalization
|
|
166
|
+
|
|
167
|
+
Every user-facing string routes through a minimal English catalog + `t(id, vars?)`
|
|
168
|
+
resolver, so a future `{ locale }` resolves translations without an API break.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { t } from './chunk-GN5DYVN5.js';
|
|
2
|
+
import { address, getTransactionEncoder, getTransactionDecoder } from '@solana/kit';
|
|
3
|
+
|
|
4
|
+
// src/signers/strings.ts
|
|
5
|
+
var EN_SIGNER_STRINGS = {
|
|
6
|
+
"signer.walletNoSignFeature": "Wallet account {address} does not expose a solana:signTransaction feature. Pass options.signTransaction explicitly, or use a Wallet Standard account that supports transaction signing.",
|
|
7
|
+
"signer.walletNoSignature": "The wallet returned no signature for account {address}. The wallet may have rejected or modified the transaction so the fee-payer signature is absent.",
|
|
8
|
+
"signer.embeddedSignatureCount": "Embedded wallet returned {got} signatures for {expected} transactions; expected one per transaction.",
|
|
9
|
+
"signer.walletAdapterDisconnected": "The wallet adapter is not connected (publicKey is null). Connect the wallet before creating a signer.",
|
|
10
|
+
"signer.walletAdapterNoSign": "The wallet adapter does not expose signTransaction. Use a wallet that supports transaction signing, or migrate to the Wallet Standard path (signerFromWalletAccount)."
|
|
11
|
+
};
|
|
12
|
+
function ts(id, vars) {
|
|
13
|
+
return t(id, vars, { catalog: EN_SIGNER_STRINGS });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/signers/wallet-account.ts
|
|
17
|
+
var SOLANA_SIGN_TRANSACTION = "solana:signTransaction";
|
|
18
|
+
function resolveSignTransaction(account, options) {
|
|
19
|
+
if (options.signTransaction) return options.signTransaction;
|
|
20
|
+
const feature = account.features?.[SOLANA_SIGN_TRANSACTION];
|
|
21
|
+
if (feature?.signTransaction) return feature.signTransaction;
|
|
22
|
+
throw new Error(ts("signer.walletNoSignFeature", { address: account.address }));
|
|
23
|
+
}
|
|
24
|
+
function resolveChain(account, options) {
|
|
25
|
+
if (options.chain) return options.chain;
|
|
26
|
+
return account.chains?.find((c) => c.startsWith("solana:"));
|
|
27
|
+
}
|
|
28
|
+
function signerFromWalletAccount(account, options = {}) {
|
|
29
|
+
const signerAddress = address(account.address);
|
|
30
|
+
const signTransaction = resolveSignTransaction(account, options);
|
|
31
|
+
const chain = resolveChain(account, options);
|
|
32
|
+
const encoder = getTransactionEncoder();
|
|
33
|
+
const decoder = getTransactionDecoder();
|
|
34
|
+
async function signOne(transaction) {
|
|
35
|
+
const wireBytes = new Uint8Array(encoder.encode(transaction));
|
|
36
|
+
const [output] = await signTransaction({
|
|
37
|
+
transaction: wireBytes,
|
|
38
|
+
...chain ? { chain } : {}
|
|
39
|
+
});
|
|
40
|
+
if (!output) {
|
|
41
|
+
throw new Error(ts("signer.walletNoSignature", { address: account.address }));
|
|
42
|
+
}
|
|
43
|
+
const signed = decoder.decode(output.signedTransaction);
|
|
44
|
+
const signature = signed.signatures[signerAddress];
|
|
45
|
+
if (!signature) {
|
|
46
|
+
throw new Error(ts("signer.walletNoSignature", { address: account.address }));
|
|
47
|
+
}
|
|
48
|
+
return signature;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
address: signerAddress,
|
|
52
|
+
async signTransactions(transactions) {
|
|
53
|
+
return Promise.all(
|
|
54
|
+
transactions.map(async (transaction) => ({
|
|
55
|
+
[signerAddress]: await signOne(transaction)
|
|
56
|
+
}))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function resolveAdapterAddress(adapter) {
|
|
62
|
+
const { publicKey } = adapter;
|
|
63
|
+
if (publicKey == null) {
|
|
64
|
+
throw new Error(ts("signer.walletAdapterDisconnected"));
|
|
65
|
+
}
|
|
66
|
+
if (typeof publicKey === "string") return publicKey;
|
|
67
|
+
if ("toBase58" in publicKey && typeof publicKey.toBase58 === "function") {
|
|
68
|
+
return publicKey.toBase58();
|
|
69
|
+
}
|
|
70
|
+
return String(publicKey);
|
|
71
|
+
}
|
|
72
|
+
function signerFromWalletAdapter(adapter, options) {
|
|
73
|
+
const signerAddress = address(resolveAdapterAddress(adapter));
|
|
74
|
+
const { signTransaction } = adapter;
|
|
75
|
+
if (typeof signTransaction !== "function") {
|
|
76
|
+
throw new Error(ts("signer.walletAdapterNoSign"));
|
|
77
|
+
}
|
|
78
|
+
const { VersionedTransaction } = options;
|
|
79
|
+
const encoder = getTransactionEncoder();
|
|
80
|
+
const decoder = getTransactionDecoder();
|
|
81
|
+
async function signOne(transaction) {
|
|
82
|
+
const wireBytes = new Uint8Array(encoder.encode(transaction));
|
|
83
|
+
const legacyTx = VersionedTransaction.deserialize(wireBytes);
|
|
84
|
+
const signed = await signTransaction(legacyTx);
|
|
85
|
+
const signedTx = decoder.decode(new Uint8Array(signed.serialize()));
|
|
86
|
+
const signature = signedTx.signatures[signerAddress];
|
|
87
|
+
if (!signature) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
ts("signer.walletNoSignature", { address: signerAddress })
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return signature;
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
address: signerAddress,
|
|
96
|
+
async signTransactions(transactions) {
|
|
97
|
+
return Promise.all(
|
|
98
|
+
transactions.map(async (transaction) => ({
|
|
99
|
+
[signerAddress]: await signOne(transaction)
|
|
100
|
+
}))
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function signerFromEmbeddedWallet(connection) {
|
|
106
|
+
const signerAddress = address(connection.address);
|
|
107
|
+
return {
|
|
108
|
+
address: signerAddress,
|
|
109
|
+
async signTransactions(transactions) {
|
|
110
|
+
const signatures = await connection.signTransactions(transactions);
|
|
111
|
+
if (signatures.length !== transactions.length) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
ts("signer.embeddedSignatureCount", {
|
|
114
|
+
expected: transactions.length,
|
|
115
|
+
got: signatures.length
|
|
116
|
+
})
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return transactions.map((_, i) => ({
|
|
120
|
+
[signerAddress]: signatures[i]
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export { EN_SIGNER_STRINGS, signerFromEmbeddedWallet, signerFromWalletAccount, signerFromWalletAdapter };
|
|
127
|
+
//# sourceMappingURL=chunk-5OTKSRHM.js.map
|
|
128
|
+
//# sourceMappingURL=chunk-5OTKSRHM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/signers/strings.ts","../src/signers/wallet-account.ts","../src/signers/wallet-adapter.ts","../src/signers/embedded-wallet.ts"],"names":["address","getTransactionEncoder","getTransactionDecoder"],"mappings":";;;;AAaO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,4BAAA,EACE,yLAAA;AAAA,EACF,0BAAA,EACE,wJAAA;AAAA,EACF,+BAAA,EACE,sGAAA;AAAA,EACF,kCAAA,EACE,uGAAA;AAAA,EACF,4BAAA,EACE;AACJ;AASO,SAAS,EAAA,CACd,IACA,IAAA,EACQ;AACR,EAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,EAAE,OAAA,EAAS,mBAAmB,CAAA;AACnD;;;ACNA,IAAM,uBAAA,GAA0B,wBAAA;AAGhC,SAAS,sBAAA,CACP,SACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,eAAA,EAAiB,OAAO,OAAA,CAAQ,eAAA;AAC5C,EAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,QAAA,GAAW,uBAAuB,CAAA;AAG1D,EAAA,IAAI,OAAA,EAAS,eAAA,EAAiB,OAAO,OAAA,CAAQ,eAAA;AAC7C,EAAA,MAAM,IAAI,MAAM,EAAA,CAAG,4BAAA,EAA8B,EAAE,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAS,CAAC,CAAA;AAChF;AAGA,SAAS,YAAA,CACP,SACA,OAAA,EACoB;AACpB,EAAA,IAAI,OAAA,CAAQ,KAAA,EAAO,OAAO,OAAA,CAAQ,KAAA;AAClC,EAAA,OAAO,OAAA,CAAQ,QAAQ,IAAA,CAAK,CAAC,MAAM,CAAA,CAAE,UAAA,CAAW,SAAS,CAAC,CAAA;AAC5D;AAkCO,SAAS,uBAAA,CACd,OAAA,EACA,OAAA,GAA0C,EAAC,EACxB;AACnB,EAAA,MAAM,aAAA,GAAyB,OAAA,CAAQ,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AA,GACF;AACF","file":"chunk-5OTKSRHM.js","sourcesContent":["/**\n * Signer-adapter string catalog (the `signer.*` namespace).\n *\n * Kept local to `src/signers/**` so the adapters route every user-facing string\n * through the package's {@link t} resolver (the PLAN_2 Part A locale contract)\n * WITHOUT cross-editing the shared `src/strings` catalog owned by another\n * surface. A future locale can extend `EN_SIGNER_STRINGS` the same way.\n *\n * @module signers/strings\n */\nimport { t, type StringCatalog } from \"../strings/index.js\";\n\n/** English `signer.*` strings used by the wallet/embedded adapters. */\nexport const EN_SIGNER_STRINGS = {\n \"signer.walletNoSignFeature\":\n \"Wallet account {address} does not expose a solana:signTransaction feature. Pass options.signTransaction explicitly, or use a Wallet Standard account that supports transaction signing.\",\n \"signer.walletNoSignature\":\n \"The wallet returned no signature for account {address}. The wallet may have rejected or modified the transaction so the fee-payer signature is absent.\",\n \"signer.embeddedSignatureCount\":\n \"Embedded wallet returned {got} signatures for {expected} transactions; expected one per transaction.\",\n \"signer.walletAdapterDisconnected\":\n \"The wallet adapter is not connected (publicKey is null). Connect the wallet before creating a signer.\",\n \"signer.walletAdapterNoSign\":\n \"The wallet adapter does not expose signTransaction. Use a wallet that supports transaction signing, or migrate to the Wallet Standard path (signerFromWalletAccount).\",\n} as const satisfies StringCatalog;\n\n/** A `signer.*` message id. */\nexport type SignerStringId = keyof typeof EN_SIGNER_STRINGS;\n\n/**\n * `t()` bound to the signer catalog: resolves `signer.*` ids while preserving\n * the shared resolver's interpolation + verbatim-fallback behavior.\n */\nexport function ts(\n id: SignerStringId,\n vars?: Record<string, string | number | bigint>,\n): string {\n return t(id, vars, { catalog: EN_SIGNER_STRINGS });\n}\n","/**\n * Wallet Standard → kit `TransactionSigner` bridge (PLAN.md P4.1 / PLAN_2 D-1).\n *\n * Turns a connected browser wallet into the {@link TransactionSigner} the SDK's\n * `createMarketplaceClient` consumes. The SDK client signs via\n * `signTransactionMessageWithSigners(...)` and submits through its OWN transport\n * — so it needs a PARTIAL signer (one that returns signatures without sending),\n * NOT a `TransactionSendingSigner` (which `signTransactionMessageWithSigners`\n * deliberately ignores). This bridge therefore produces a\n * {@link TransactionPartialSigner}: it serializes each transaction, hands it to\n * the wallet's `solana:signTransaction` feature, and diffs the returned signed\n * transaction to recover THIS account's signature.\n *\n * @see {@link signerFromWalletAccount}\n * @module signers/wallet-account\n */\nimport {\n address,\n getTransactionDecoder,\n getTransactionEncoder,\n type Address,\n type SignatureBytes,\n type Transaction,\n} from \"@solana/kit\";\nimport { ts } from \"./strings.js\";\nimport type {\n SignerFromWalletAccountOptions,\n TransactionSigner,\n WalletStandardAccountLike,\n WalletStandardSignTransaction,\n} from \"./types.js\";\n\nconst SOLANA_SIGN_TRANSACTION = \"solana:signTransaction\";\n\n/** Resolve the wallet's `solana:signTransaction` method from account/options. */\nfunction resolveSignTransaction(\n account: WalletStandardAccountLike,\n options: SignerFromWalletAccountOptions,\n): WalletStandardSignTransaction {\n if (options.signTransaction) return options.signTransaction;\n const feature = account.features?.[SOLANA_SIGN_TRANSACTION] as\n | { signTransaction?: WalletStandardSignTransaction }\n | undefined;\n if (feature?.signTransaction) return feature.signTransaction;\n throw new Error(ts(\"signer.walletNoSignFeature\", { address: account.address }));\n}\n\n/** Pick the CAIP-2 chain to forward to the wallet. */\nfunction resolveChain(\n account: WalletStandardAccountLike,\n options: SignerFromWalletAccountOptions,\n): string | undefined {\n if (options.chain) return options.chain;\n return account.chains?.find((c) => c.startsWith(\"solana:\"));\n}\n\n/**\n * Bridge a Wallet Standard account into a kit {@link TransactionSigner}.\n *\n * Accepts either a real `UiWalletAccount` (the `@solana/react` path — pass the\n * account and a `chain`, or pass the hook's feature via\n * {@link SignerFromWalletAccountOptions.signTransaction}) or any object exposing\n * the `solana:signTransaction` feature. The returned signer is a\n * {@link TransactionPartialSigner}, the exact shape the SDK client expects.\n *\n * Wallets may MODIFY a transaction before signing (priority fees, guard\n * instructions). We honor that by decoding the wallet's returned signed\n * transaction and extracting only THIS account's signature; the SDK client then\n * re-assembles and submits. (If a wallet rewrites the message such that the\n * fee-payer's own prior signing is invalidated, that is a wallet contract the\n * SDK's single-fee-payer flow already assumes won't happen for the payer.)\n *\n * SSR-safe: constructs no browser globals; the wallet round-trip only runs when\n * a transaction is actually signed.\n *\n * @param account - The connected Wallet Standard account (needs `address`).\n * @param options - Chain + an optional explicit `signTransaction` override.\n * @returns A kit {@link TransactionSigner} usable as `config.signer`.\n * @throws Error if no `solana:signTransaction` feature can be resolved.\n *\n * @example\n * ```ts\n * // With @solana/react (Wallet Standard):\n * const account = useSelectedWalletAccount(); // UiWalletAccount\n * const signer = signerFromWalletAccount(account, { chain: \"solana:devnet\" });\n * // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.\n * ```\n */\nexport function signerFromWalletAccount(\n account: WalletStandardAccountLike,\n options: SignerFromWalletAccountOptions = {},\n): TransactionSigner {\n const signerAddress: Address = address(account.address);\n const signTransaction = resolveSignTransaction(account, options);\n const chain = resolveChain(account, options);\n const encoder = getTransactionEncoder();\n const decoder = getTransactionDecoder();\n\n async function signOne(transaction: Transaction): Promise<SignatureBytes> {\n const wireBytes = new Uint8Array(encoder.encode(transaction));\n const [output] = await signTransaction({\n transaction: wireBytes,\n ...(chain ? { chain } : {}),\n });\n if (!output) {\n throw new Error(ts(\"signer.walletNoSignature\", { address: account.address }));\n }\n const signed = decoder.decode(output.signedTransaction);\n const signature = signed.signatures[signerAddress];\n if (!signature) {\n throw new Error(ts(\"signer.walletNoSignature\", { address: account.address }));\n }\n return signature as SignatureBytes;\n }\n\n return {\n address: signerAddress,\n async signTransactions(transactions) {\n // Sign in parallel — partial signers are order-independent (each returns a\n // single-entry SignatureDictionary the caller merges).\n return Promise.all(\n transactions.map(async (transaction) => ({\n [signerAddress]: await signOne(transaction),\n })),\n );\n },\n } satisfies TransactionSigner;\n}\n","/**\n * LEGACY `@solana/wallet-adapter` compatibility shim (PLAN.md P4.1).\n *\n * The supported, robust path for browser wallets is the Wallet Standard bridge\n * ({@link signerFromWalletAccount} via `@solana/react`): every modern wallet —\n * including all wallet-adapter wallets — registers as a Wallet Standard wallet,\n * so a wallet-adapter app can migrate by reading the selected account through\n * `@solana/react` and dropping it into `signerFromWalletAccount`. PREFER THAT.\n *\n * This shim exists for apps still holding a raw wallet-adapter\n * `WalletContextState` (web3.js v1 `signTransaction`). It bridges WITHOUT a hard\n * dependency on `@solana/wallet-adapter-*` OR `@solana/web3.js` (1.x): the\n * caller injects the web3.js `VersionedTransaction` class (the only piece we\n * cannot reconstruct), and we round-trip through the shared wire format — a kit\n * {@link Transaction} and a web3.js `VersionedTransaction` serialize to the SAME\n * bytes, so no semantic re-encoding is needed.\n *\n * SSR-safe: no browser globals at module scope.\n *\n * @module signers/wallet-adapter\n */\nimport {\n address,\n getTransactionDecoder,\n getTransactionEncoder,\n type SignatureBytes,\n type Transaction,\n} from \"@solana/kit\";\nimport { ts } from \"./strings.js\";\nimport type { TransactionSigner } from \"./types.js\";\n\n/**\n * The web3.js v1 `VersionedTransaction` surface this shim needs: a static\n * `deserialize(bytes)` and an instance `serialize()`. Pass the real class from\n * `@solana/web3.js` — typed structurally so this module never imports it.\n */\nexport interface VersionedTransactionLike {\n serialize(): Uint8Array;\n}\n\n/** The static side of the injected `VersionedTransaction` class. */\nexport interface VersionedTransactionCtor {\n deserialize(bytes: Uint8Array): VersionedTransactionLike;\n}\n\n/**\n * The minimal slice of a wallet-adapter `WalletContextState` this shim consumes.\n * Both `publicKey` (anything with a base58 `toString()`/`toBase58()`) and the\n * v1 `signTransaction` are required; a connected adapter exposes both.\n */\nexport interface WalletAdapterLike {\n /** The connected account's public key (base58 via `toBase58()`/`toString()`). */\n readonly publicKey:\n | { toBase58(): string }\n | { toString(): string }\n | string\n | null;\n /** web3.js v1 sign — returns the same transaction type, signed. */\n signTransaction?: <T extends VersionedTransactionLike>(\n transaction: T,\n ) => Promise<T>;\n}\n\n/** Options for {@link signerFromWalletAdapter}. */\nexport interface SignerFromWalletAdapterOptions {\n /**\n * The web3.js `VersionedTransaction` class (`import { VersionedTransaction }\n * from \"@solana/web3.js\"`). Required — it is the one piece this no-dep shim\n * cannot supply itself.\n */\n VersionedTransaction: VersionedTransactionCtor;\n}\n\nfunction resolveAdapterAddress(adapter: WalletAdapterLike): string {\n const { publicKey } = adapter;\n if (publicKey == null) {\n throw new Error(ts(\"signer.walletAdapterDisconnected\"));\n }\n if (typeof publicKey === \"string\") return publicKey;\n if (\"toBase58\" in publicKey && typeof publicKey.toBase58 === \"function\") {\n return publicKey.toBase58();\n }\n return String(publicKey);\n}\n\n/**\n * Bridge a LEGACY `@solana/wallet-adapter` `WalletContextState` into a kit\n * {@link TransactionSigner}.\n *\n * Use only when you cannot reach the wallet through `@solana/react`. The result\n * is a {@link TransactionPartialSigner} (the SDK client owns submission), built\n * by serializing the kit transaction to wire bytes, rehydrating it as a web3.js\n * `VersionedTransaction`, handing THAT to the adapter's `signTransaction`, then\n * decoding the signed wire bytes back to a kit transaction to extract this\n * account's signature.\n *\n * @param adapter - A connected wallet-adapter state (`publicKey` + `signTransaction`).\n * @param options - Must inject the web3.js `VersionedTransaction` class.\n * @returns A kit {@link TransactionSigner} usable as `config.signer`.\n * @throws Error if the adapter is disconnected or lacks `signTransaction`.\n *\n * @example\n * ```ts\n * import { VersionedTransaction } from \"@solana/web3.js\";\n * import { useWallet } from \"@solana/wallet-adapter-react\";\n *\n * const wallet = useWallet();\n * const signer = signerFromWalletAdapter(wallet, { VersionedTransaction });\n * // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.\n * ```\n */\nexport function signerFromWalletAdapter(\n adapter: WalletAdapterLike,\n options: SignerFromWalletAdapterOptions,\n): TransactionSigner {\n const signerAddress = address(resolveAdapterAddress(adapter));\n const { signTransaction } = adapter;\n if (typeof signTransaction !== \"function\") {\n throw new Error(ts(\"signer.walletAdapterNoSign\"));\n }\n const { VersionedTransaction } = options;\n const encoder = getTransactionEncoder();\n const decoder = getTransactionDecoder();\n\n async function signOne(transaction: Transaction): Promise<SignatureBytes> {\n const wireBytes = new Uint8Array(encoder.encode(transaction));\n const legacyTx = VersionedTransaction.deserialize(wireBytes);\n const signed = await signTransaction!(legacyTx);\n const signedTx = decoder.decode(new Uint8Array(signed.serialize()));\n const signature = signedTx.signatures[signerAddress];\n if (!signature) {\n throw new Error(\n ts(\"signer.walletNoSignature\", { address: signerAddress }),\n );\n }\n return signature as SignatureBytes;\n }\n\n return {\n address: signerAddress,\n async signTransactions(transactions) {\n return Promise.all(\n transactions.map(async (transaction) => ({\n [signerAddress]: await signOne(transaction),\n })),\n );\n },\n } satisfies TransactionSigner;\n}\n","/**\n * Embedded / walletless → kit `TransactionSigner` bridge (PLAN_2 D-1).\n *\n * The \"no wallet, no SOL\" buyer path. A vendor-neutral\n * {@link EmbeddedWalletProvider} (Privy / Dynamic / Web3Auth — `[HUMAN]`-gated)\n * handles email/social login + key custody; this module lifts a live\n * {@link EmbeddedWalletConnection} into the kit {@link TransactionSigner} the SDK\n * client consumes. As with the Wallet Standard bridge, the result is a PARTIAL\n * signer — the vendor signs, the SDK client's transport broadcasts.\n *\n * @see {@link signerFromEmbeddedWallet}\n * @see {@link createMockEmbeddedWallet} — the local-keypair test adapter.\n * @module signers/embedded-wallet\n */\nimport { address, type SignatureBytes, type Transaction } from \"@solana/kit\";\nimport { ts } from \"./strings.js\";\nimport type {\n EmbeddedWalletConnection,\n TransactionSigner,\n} from \"./types.js\";\n\n/**\n * Bridge a CONNECTED embedded-wallet connection into a kit\n * {@link TransactionSigner}.\n *\n * Call this AFTER `provider.connect()` resolves — it needs the live\n * {@link EmbeddedWalletConnection} (address + `signTransactions`). The hooks\n * layer (`useWalletSigner`) is expected to own the connect lifecycle and call\n * this once a connection exists.\n *\n * @param connection - A live embedded-wallet connection.\n * @returns A kit {@link TransactionSigner} usable as `config.signer`.\n *\n * @example\n * ```ts\n * const connection = await provider.connect(); // vendor login\n * const signer = signerFromEmbeddedWallet(connection);\n * // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.\n * ```\n */\nexport function signerFromEmbeddedWallet(\n connection: EmbeddedWalletConnection,\n): TransactionSigner {\n const signerAddress = address(connection.address);\n\n return {\n address: signerAddress,\n async signTransactions(transactions: readonly Transaction[]) {\n const signatures: readonly SignatureBytes[] =\n await connection.signTransactions(transactions);\n if (signatures.length !== transactions.length) {\n throw new Error(\n ts(\"signer.embeddedSignatureCount\", {\n expected: transactions.length,\n got: signatures.length,\n }),\n );\n }\n return transactions.map((_, i) => ({\n [signerAddress]: signatures[i] as SignatureBytes,\n }));\n },\n } satisfies TransactionSigner;\n}\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { t } from './chunk-GN5DYVN5.js';
|
|
2
|
+
import { isAddress, address } from '@solana/kit';
|
|
3
|
+
import { createIndexerClient, getServiceListingDecoder, listActiveListings } from '@tetsuo-ai/marketplace-sdk';
|
|
4
|
+
|
|
5
|
+
var ReadTransportUnsupportedError = class extends Error {
|
|
6
|
+
/** The unsupported operation name. */
|
|
7
|
+
operation;
|
|
8
|
+
constructor(operation) {
|
|
9
|
+
super(
|
|
10
|
+
`Read operation "${operation}" requires the indexer backend; the gPA fallback has no trustless equivalent. Configure an indexer baseUrl on <AgencProvider> to use it.`
|
|
11
|
+
);
|
|
12
|
+
this.name = "ReadTransportUnsupportedError";
|
|
13
|
+
this.operation = operation;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function toAddress(pda) {
|
|
17
|
+
if (typeof pda !== "string") return pda;
|
|
18
|
+
if (!isAddress(pda)) {
|
|
19
|
+
throw new TypeError(`Not a valid base58 Solana address: ${pda}`);
|
|
20
|
+
}
|
|
21
|
+
return address(pda);
|
|
22
|
+
}
|
|
23
|
+
function indexerReadTransport(config, indexerClientOptions) {
|
|
24
|
+
const client = createIndexerClient({
|
|
25
|
+
baseUrl: config.baseUrl,
|
|
26
|
+
apiKey: config.apiKey,
|
|
27
|
+
...indexerClientOptions ?? {}
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
kind: "indexer",
|
|
31
|
+
listActiveListings: (options) => client.listActiveListings(options),
|
|
32
|
+
async getListing(pda) {
|
|
33
|
+
const listing = await client.getListing(pda);
|
|
34
|
+
const account = getServiceListingDecoder().decode(
|
|
35
|
+
base64ToBytes(listing.accountData)
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
address: toAddress(listing.pda),
|
|
39
|
+
account,
|
|
40
|
+
indexer: listing
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
listingHires: (pda) => client.listingHires(pda),
|
|
44
|
+
agentTrackRecord: (pda) => client.agentTrackRecord(pda)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function gpaReadTransport(rpc) {
|
|
48
|
+
return {
|
|
49
|
+
kind: "gpa",
|
|
50
|
+
listActiveListings: (options) => listActiveListings(rpc, options),
|
|
51
|
+
async getListing(pda) {
|
|
52
|
+
const target = toAddress(pda);
|
|
53
|
+
const all = await listActiveListings(rpc, {});
|
|
54
|
+
const hit = all.find((entry) => entry.address === target);
|
|
55
|
+
if (hit === void 0) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Listing ${pda} not found among active listings via the gPA fallback (it may be inactive, or your RPC restricts getProgramAccounts \u2014 use an indexer baseUrl for single-listing lookups).`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return { address: hit.address, account: hit.account };
|
|
61
|
+
},
|
|
62
|
+
listingHires() {
|
|
63
|
+
return Promise.reject(new ReadTransportUnsupportedError("listingHires"));
|
|
64
|
+
},
|
|
65
|
+
agentTrackRecord() {
|
|
66
|
+
return Promise.reject(
|
|
67
|
+
new ReadTransportUnsupportedError("agentTrackRecord")
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function base64ToBytes(b64) {
|
|
73
|
+
if (typeof atob === "function") {
|
|
74
|
+
const binary = atob(b64);
|
|
75
|
+
const bytes = new Uint8Array(binary.length);
|
|
76
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
77
|
+
bytes[i] = binary.charCodeAt(i);
|
|
78
|
+
}
|
|
79
|
+
return bytes;
|
|
80
|
+
}
|
|
81
|
+
return Uint8Array.from(Buffer.from(b64, "base64"));
|
|
82
|
+
}
|
|
83
|
+
function createReadTransport(config) {
|
|
84
|
+
if (config.queryTransport) return config.queryTransport;
|
|
85
|
+
if (config.indexer?.baseUrl) {
|
|
86
|
+
return indexerReadTransport(config.indexer, config.indexerClientOptions);
|
|
87
|
+
}
|
|
88
|
+
if (config.rpc) return gpaReadTransport(config.rpc);
|
|
89
|
+
throw new Error(t("transport.noReadSource"));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { ReadTransportUnsupportedError, createReadTransport };
|
|
93
|
+
//# sourceMappingURL=chunk-ABS77JB2.js.map
|
|
94
|
+
//# sourceMappingURL=chunk-ABS77JB2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/transport/index.ts"],"names":["gpaListActiveListings"],"mappings":";;;;AAwCO,IAAM,6BAAA,GAAN,cAA4C,KAAA,CAAM;AAAA;AAAA,EAE9C,SAAA;AAAA,EACT,YAAY,SAAA,EAAmB;AAC7B,IAAA,KAAA;AAAA,MACE,mBAAmB,SAAS,CAAA,wIAAA;AAAA,KAG9B;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,+BAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AACF;AAGA,SAAS,UAAU,GAAA,EAAgC;AACjD,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,EAAU,OAAO,GAAA;AACpC,EAAA,IAAI,CAAC,SAAA,CAAU,GAAG,CAAA,EAAG;AACnB,IAAA,MAAM,IAAI,SAAA,CAAU,CAAA,mCAAA,EAAsC,GAAG,CAAA,CAAE,CAAA;AAAA,EACjE;AACA,EAAA,OAAO,QAAQ,GAAG,CAAA;AACpB;AAGA,SAAS,oBAAA,CACP,QACA,oBAAA,EACe;A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;AACA,EAAA,IAAI,MAAA,CAAO,GAAA,EAAK,OAAO,gBAAA,CAAiB,OAAO,GAAG,CAAA;AAClD,EAAA,MAAM,IAAI,KAAA,CAAM,CAAA,CAAE,wBAAwB,CAAC,CAAA;AAC7C","file":"chunk-ABS77JB2.js","sourcesContent":["/**\n * The read-transport abstraction — indexer-first with RPC/gPA fallback.\n *\n * `createReadTransport({ indexer?, rpc?, queryTransport? })` returns one\n * {@link ReadTransport}. When an indexer `baseUrl` is set it routes through the\n * SDK's `createIndexerClient` (the scale path); otherwise it falls back to the\n * SDK's gPA `listActiveListings` / account fetch (the trustless path). The two\n * backends return parity shapes BY SDK DESIGN, so callers never branch on which\n * one is live.\n *\n * `queryTransport` is a full override slot — pass a mock/pre-built transport\n * (tests, SSR fixtures) and it is used verbatim.\n *\n * SSR-safe: no `window`/`document` and no Node built-ins at module scope; the\n * SDK's indexer client is browser-safe (fetch + kit codecs only).\n *\n * @module transport\n */\nimport { address, isAddress } from \"@solana/kit\";\nimport {\n createIndexerClient,\n getServiceListingDecoder,\n listActiveListings as gpaListActiveListings,\n type IndexerClient,\n} from \"@tetsuo-ai/marketplace-sdk\";\nimport { t } from \"../strings/index.js\";\nimport type {\n Address,\n CreateReadTransportConfig,\n GpaReadSource,\n IndexerConfig,\n ReadListingResult,\n ReadTransport,\n} from \"../types.js\";\nimport type { CreateIndexerClientOptions } from \"@tetsuo-ai/marketplace-sdk\";\n\n/**\n * Thrown when a gPA-fallback transport is asked for an indexer-only capability\n * (aggregated hires / track record have no trustless gPA equivalent).\n */\nexport class ReadTransportUnsupportedError extends Error {\n /** The unsupported operation name. */\n readonly operation: string;\n constructor(operation: string) {\n super(\n `Read operation \"${operation}\" requires the indexer backend; the gPA ` +\n `fallback has no trustless equivalent. Configure an indexer baseUrl on ` +\n `<AgencProvider> to use it.`,\n );\n this.name = \"ReadTransportUnsupportedError\";\n this.operation = operation;\n }\n}\n\n/** Coerce a string|Address PDA into a kit Address (validates base58). */\nfunction toAddress(pda: Address | string): Address {\n if (typeof pda !== \"string\") return pda;\n if (!isAddress(pda)) {\n throw new TypeError(`Not a valid base58 Solana address: ${pda}`);\n }\n return address(pda);\n}\n\n/** Build the indexer-backed read transport. */\nfunction indexerReadTransport(\n config: IndexerConfig,\n indexerClientOptions?: Partial<CreateIndexerClientOptions>,\n): ReadTransport {\n const client: IndexerClient = createIndexerClient({\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n ...(indexerClientOptions ?? {}),\n });\n return {\n kind: \"indexer\",\n listActiveListings: (options) => client.listActiveListings(options),\n async getListing(pda): Promise<ReadListingResult> {\n const listing = await client.getListing(pda);\n const account = getServiceListingDecoder().decode(\n base64ToBytes(listing.accountData),\n );\n return {\n address: toAddress(listing.pda),\n account,\n indexer: listing,\n };\n },\n listingHires: (pda) => client.listingHires(pda),\n agentTrackRecord: (pda) => client.agentTrackRecord(pda),\n };\n}\n\n/** Build the gPA-fallback read transport over a kit RPC / ProgramAccountsTransport. */\nfunction gpaReadTransport(rpc: GpaReadSource): ReadTransport {\n return {\n kind: \"gpa\",\n listActiveListings: (options) => gpaListActiveListings(rpc, options),\n async getListing(pda): Promise<ReadListingResult> {\n // No single-account decode helper crosses the transport seam here, so we\n // scope the active-listings query down to the one PDA. (The indexer path\n // is the efficient one; this fallback is the trustless escape hatch.)\n const target = toAddress(pda);\n const all = await gpaListActiveListings(rpc, {});\n const hit = all.find((entry) => entry.address === target);\n if (hit === undefined) {\n throw new Error(\n `Listing ${pda} not found among active listings via the gPA ` +\n `fallback (it may be inactive, or your RPC restricts ` +\n `getProgramAccounts — use an indexer baseUrl for single-listing ` +\n `lookups).`,\n );\n }\n return { address: hit.address, account: hit.account };\n },\n listingHires() {\n return Promise.reject(new ReadTransportUnsupportedError(\"listingHires\"));\n },\n agentTrackRecord() {\n return Promise.reject(\n new ReadTransportUnsupportedError(\"agentTrackRecord\"),\n );\n },\n };\n}\n\n/** Browser-safe base64 → bytes (atob in browsers, Buffer in Node). */\nfunction base64ToBytes(b64: string): Uint8Array {\n if (typeof atob === \"function\") {\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n }\n // Node fallback — Buffer is always present there.\n return Uint8Array.from(Buffer.from(b64, \"base64\"));\n}\n\n/**\n * Create the unified read transport.\n *\n * Resolution order:\n * 1. `queryTransport` override (wins — tests/mocks/SSR fixtures);\n * 2. `indexer.baseUrl` present → indexer-first transport;\n * 3. `rpc` present → gPA fallback transport;\n * 4. nothing configured → throws a descriptive error.\n *\n * @param config - See {@link CreateReadTransportConfig}.\n * @returns A {@link ReadTransport}.\n * @throws Error when no read source is configured.\n */\nexport function createReadTransport(\n config: CreateReadTransportConfig,\n): ReadTransport {\n if (config.queryTransport) return config.queryTransport;\n if (config.indexer?.baseUrl) {\n return indexerReadTransport(config.indexer, config.indexerClientOptions);\n }\n if (config.rpc) return gpaReadTransport(config.rpc);\n throw new Error(t(\"transport.noReadSource\"));\n}\n\nexport type { ReadTransport } from \"../types.js\";\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/strings/index.ts
|
|
2
|
+
var EN_STRINGS = {
|
|
3
|
+
// Provider / context wiring errors (developer-facing, but routed for parity).
|
|
4
|
+
"provider.missingContext": "useAgencContext must be used within <AgencProvider>.",
|
|
5
|
+
"provider.missingWriteClient": "No write client is configured. Pass config.client, or config.rpcUrl + config.signer, to <AgencProvider> before using a mutating hook.",
|
|
6
|
+
"provider.missingSigner": "No signer is configured on <AgencProvider>. Connect a wallet or pass config.signer.",
|
|
7
|
+
// Referrer config validation (the P6.2 gate surface).
|
|
8
|
+
"referrer.invalidWallet": "Referrer wallet is not a valid base58 Solana address: {wallet}.",
|
|
9
|
+
"referrer.invalidFeeBps": "Referrer feeBps must be an integer between {min} and {max} (basis points); got {feeBps}.",
|
|
10
|
+
"referrer.notLive": "This site earns a referral fee (pending protocol support).",
|
|
11
|
+
"referrer.notLiveReason": "Referral settlement is not yet deployed on this cluster (PLAN.md P6.2). Referrer config is accepted and validated but not injected into hires.",
|
|
12
|
+
// Read transport.
|
|
13
|
+
"transport.noReadSource": "No read source is configured. Pass an indexer baseUrl, an rpc/queryTransport, to <AgencProvider> or createReadTransport().",
|
|
14
|
+
// Generic loading / empty / error states (components extend these).
|
|
15
|
+
"state.loading": "Loading\u2026",
|
|
16
|
+
"state.empty": "Nothing to show yet.",
|
|
17
|
+
"state.error": "Something went wrong.",
|
|
18
|
+
// Hire flow shells (components fill out the rest).
|
|
19
|
+
"hire.cta": "Hire",
|
|
20
|
+
"hire.pending": "Confirming\u2026",
|
|
21
|
+
"hire.funded": "Escrow funded."
|
|
22
|
+
};
|
|
23
|
+
function t(id, vars, options) {
|
|
24
|
+
const catalog = options?.catalog ?? EN_STRINGS;
|
|
25
|
+
const template = catalog[id] ?? id;
|
|
26
|
+
if (vars === void 0) return template;
|
|
27
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
28
|
+
const value = vars[key];
|
|
29
|
+
return value === void 0 ? match : String(value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { EN_STRINGS, t };
|
|
34
|
+
//# sourceMappingURL=chunk-GN5DYVN5.js.map
|
|
35
|
+
//# sourceMappingURL=chunk-GN5DYVN5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strings/index.ts"],"names":[],"mappings":";AAkCO,IAAM,UAAA,GAAa;AAAA;AAAA,EAExB,yBAAA,EACE,sDAAA;AAAA,EACF,6BAAA,EACE,uIAAA;AAAA,EACF,wBAAA,EACE,qFAAA;AAAA;AAAA,EAGF,wBAAA,EACE,iEAAA;AAAA,EACF,wBAAA,EACE,0FAAA;AAAA,EACF,kBAAA,EACE,4DAAA;AAAA,EACF,wBAAA,EACE,gJAAA;AAAA;AAAA,EAGF,wBAAA,EACE,4HAAA;AAAA;AAAA,EAGF,eAAA,EAAiB,eAAA;AAAA,EACjB,aAAA,EAAe,sBAAA;AAAA,EACf,aAAA,EAAe,uBAAA;AAAA;AAAA,EAGf,UAAA,EAAY,MAAA;AAAA,EACZ,cAAA,EAAgB,kBAAA;AAAA,EAChB,aAAA,EAAe;AACjB;AAwCO,SAAS,CAAA,CACd,EAAA,EACA,IAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,OAAA,GAAyB,SAAS,OAAA,IAAW,UAAA;AACnD,EAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,EAAE,CAAA,IAAK,EAAA;AAChC,EAAA,IAAI,IAAA,KAAS,QAAW,OAAO,QAAA;AAC/B,EAAA,OAAO,QAAA,CAAS,OAAA,CAAQ,YAAA,EAAc,CAAC,OAAO,GAAA,KAAgB;AAC5D,IAAA,MAAM,KAAA,GAAQ,KAAK,GAAG,CAAA;AACtB,IAAA,OAAO,KAAA,KAAU,MAAA,GAAY,KAAA,GAAQ,MAAA,CAAO,KAAK,CAAA;AAAA,EACnD,CAAC,CAAA;AACH","file":"chunk-GN5DYVN5.js","sourcesContent":["/**\n * Minimal English string catalog + a `t(id, vars?)` resolver.\n *\n * Every user-facing string in this package and its downstream hooks/components\n * routes through this module so a future `{ locale }` can resolve translations\n * **without an API break** (PLAN_2 Part A design constraint). v1 ships English\n * only; the resolver signature is already locale-shaped.\n *\n * ## Why a catalog and not inline literals\n *\n * Components published to third parties cannot assume the host's language. By\n * keying every literal here:\n * - adding a locale is a data change (a new {@link StringCatalog}), not a code\n * change to every component;\n * - the message ids are a stable contract the components agent binds to;\n * - `{var}` interpolation is centralized and SSR-safe (pure string ops, no\n * `Intl` global assumptions at module scope).\n *\n * @module strings\n */\n\n/**\n * The catalog shape: every message id maps to an English template. `{name}`\n * placeholders are filled by {@link t} from the `vars` argument.\n */\nexport interface StringCatalog {\n readonly [id: string]: string;\n}\n\n/**\n * Default English catalog. Keep ids namespaced by surface\n * (`provider.*`, `referrer.*`, `transport.*`, `hire.*`, ...) so the components\n * agent can extend it without collisions.\n */\nexport const EN_STRINGS = {\n // Provider / context wiring errors (developer-facing, but routed for parity).\n \"provider.missingContext\":\n \"useAgencContext must be used within <AgencProvider>.\",\n \"provider.missingWriteClient\":\n \"No write client is configured. Pass config.client, or config.rpcUrl + config.signer, to <AgencProvider> before using a mutating hook.\",\n \"provider.missingSigner\":\n \"No signer is configured on <AgencProvider>. Connect a wallet or pass config.signer.\",\n\n // Referrer config validation (the P6.2 gate surface).\n \"referrer.invalidWallet\":\n \"Referrer wallet is not a valid base58 Solana address: {wallet}.\",\n \"referrer.invalidFeeBps\":\n \"Referrer feeBps must be an integer between {min} and {max} (basis points); got {feeBps}.\",\n \"referrer.notLive\":\n \"This site earns a referral fee (pending protocol support).\",\n \"referrer.notLiveReason\":\n \"Referral settlement is not yet deployed on this cluster (PLAN.md P6.2). Referrer config is accepted and validated but not injected into hires.\",\n\n // Read transport.\n \"transport.noReadSource\":\n \"No read source is configured. Pass an indexer baseUrl, an rpc/queryTransport, to <AgencProvider> or createReadTransport().\",\n\n // Generic loading / empty / error states (components extend these).\n \"state.loading\": \"Loading…\",\n \"state.empty\": \"Nothing to show yet.\",\n \"state.error\": \"Something went wrong.\",\n\n // Hire flow shells (components fill out the rest).\n \"hire.cta\": \"Hire\",\n \"hire.pending\": \"Confirming…\",\n \"hire.funded\": \"Escrow funded.\",\n} as const satisfies StringCatalog;\n\n/** A message id present in the default English catalog. */\nexport type StringId = keyof typeof EN_STRINGS;\n\n/** Interpolation variables for {@link t}: `{name}` → `vars.name`. */\nexport type StringVars = Record<string, string | number | bigint>;\n\n/**\n * Options for {@link t}. `locale` is accepted today (English-only) so adding\n * real locales later does not break the call signature; `catalog` lets a host\n * inject an override/extension catalog.\n */\nexport interface TranslateOptions {\n /** BCP-47 locale tag. v1 resolves everything to English regardless. */\n locale?: string;\n /** Override catalog (e.g. a future locale, or host-supplied copy). */\n catalog?: StringCatalog;\n}\n\n/**\n * Resolve a message id to its localized string with `{var}` interpolation.\n *\n * Unknown ids and unmatched placeholders are returned verbatim (the id itself,\n * or the `{placeholder}` left intact) rather than throwing — a missing string\n * must never crash a money-handling UI.\n *\n * @param id - The message id (a {@link StringId}, or any string for host\n * catalogs).\n * @param vars - Values for `{name}` placeholders in the template.\n * @param options - Optional `locale` (forward-compatible) and `catalog`\n * override.\n * @returns The interpolated string.\n *\n * @example\n * ```ts\n * t(\"referrer.invalidFeeBps\", { min: 0, max: 10000, feeBps: 99999 });\n * // -> \"Referrer feeBps must be an integer between 0 and 10000 ...; got 99999.\"\n * ```\n */\nexport function t(\n id: StringId | (string & {}),\n vars?: StringVars,\n options?: TranslateOptions,\n): string {\n const catalog: StringCatalog = options?.catalog ?? EN_STRINGS;\n const template = catalog[id] ?? id;\n if (vars === undefined) return template;\n return template.replace(/\\{(\\w+)\\}/g, (match, key: string) => {\n const value = vars[key];\n return value === undefined ? match : String(value);\n });\n}\n"]}
|