@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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedded / walletless → kit `TransactionSigner` bridge (PLAN_2 D-1).
|
|
3
|
+
*
|
|
4
|
+
* The "no wallet, no SOL" buyer path. A vendor-neutral
|
|
5
|
+
* {@link EmbeddedWalletProvider} (Privy / Dynamic / Web3Auth — `[HUMAN]`-gated)
|
|
6
|
+
* handles email/social login + key custody; this module lifts a live
|
|
7
|
+
* {@link EmbeddedWalletConnection} into the kit {@link TransactionSigner} the SDK
|
|
8
|
+
* client consumes. As with the Wallet Standard bridge, the result is a PARTIAL
|
|
9
|
+
* signer — the vendor signs, the SDK client's transport broadcasts.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link signerFromEmbeddedWallet}
|
|
12
|
+
* @see {@link createMockEmbeddedWallet} — the local-keypair test adapter.
|
|
13
|
+
* @module signers/embedded-wallet
|
|
14
|
+
*/
|
|
15
|
+
import { address, type SignatureBytes, type Transaction } from "@solana/kit";
|
|
16
|
+
import { ts } from "./strings.js";
|
|
17
|
+
import type {
|
|
18
|
+
EmbeddedWalletConnection,
|
|
19
|
+
TransactionSigner,
|
|
20
|
+
} from "./types.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bridge a CONNECTED embedded-wallet connection into a kit
|
|
24
|
+
* {@link TransactionSigner}.
|
|
25
|
+
*
|
|
26
|
+
* Call this AFTER `provider.connect()` resolves — it needs the live
|
|
27
|
+
* {@link EmbeddedWalletConnection} (address + `signTransactions`). The hooks
|
|
28
|
+
* layer (`useWalletSigner`) is expected to own the connect lifecycle and call
|
|
29
|
+
* this once a connection exists.
|
|
30
|
+
*
|
|
31
|
+
* @param connection - A live embedded-wallet connection.
|
|
32
|
+
* @returns A kit {@link TransactionSigner} usable as `config.signer`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const connection = await provider.connect(); // vendor login
|
|
37
|
+
* const signer = signerFromEmbeddedWallet(connection);
|
|
38
|
+
* // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function signerFromEmbeddedWallet(
|
|
42
|
+
connection: EmbeddedWalletConnection,
|
|
43
|
+
): TransactionSigner {
|
|
44
|
+
const signerAddress = address(connection.address);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
address: signerAddress,
|
|
48
|
+
async signTransactions(transactions: readonly Transaction[]) {
|
|
49
|
+
const signatures: readonly SignatureBytes[] =
|
|
50
|
+
await connection.signTransactions(transactions);
|
|
51
|
+
if (signatures.length !== transactions.length) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
ts("signer.embeddedSignatureCount", {
|
|
54
|
+
expected: transactions.length,
|
|
55
|
+
got: signatures.length,
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return transactions.map((_, i) => ({
|
|
60
|
+
[signerAddress]: signatures[i] as SignatureBytes,
|
|
61
|
+
}));
|
|
62
|
+
},
|
|
63
|
+
} satisfies TransactionSigner;
|
|
64
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-wallet → kit `TransactionSigner` bridges (PLAN.md P4.1 / PLAN_2 D-1).
|
|
3
|
+
*
|
|
4
|
+
* Two production adapters + one test mock, all producing the
|
|
5
|
+
* {@link TransactionSigner} the SDK's `createMarketplaceClient` consumes (a
|
|
6
|
+
* PARTIAL signer — the SDK client owns submission). SSR-safe, tree-shakeable.
|
|
7
|
+
*
|
|
8
|
+
* - {@link signerFromWalletAccount} — Wallet Standard (`@solana/react`) path.
|
|
9
|
+
* - {@link signerFromEmbeddedWallet} — vendor-neutral embedded/walletless path.
|
|
10
|
+
*
|
|
11
|
+
* The local-keypair test MOCK (`createMockEmbeddedWallet`) is deliberately NOT
|
|
12
|
+
* exported here — it holds a private key in-process and lives behind the
|
|
13
|
+
* `@tetsuo-ai/marketplace-react/testing` subpath so it can't ship to production.
|
|
14
|
+
*
|
|
15
|
+
* @module signers
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Wallet Standard bridge (the supported browser-wallet path).
|
|
19
|
+
export { signerFromWalletAccount } from "./wallet-account.js";
|
|
20
|
+
|
|
21
|
+
// Legacy @solana/wallet-adapter compatibility shim (optional, no hard dep).
|
|
22
|
+
export {
|
|
23
|
+
signerFromWalletAdapter,
|
|
24
|
+
type SignerFromWalletAdapterOptions,
|
|
25
|
+
type VersionedTransactionCtor,
|
|
26
|
+
type VersionedTransactionLike,
|
|
27
|
+
type WalletAdapterLike,
|
|
28
|
+
} from "./wallet-adapter.js";
|
|
29
|
+
|
|
30
|
+
// Embedded / walletless bridge.
|
|
31
|
+
export { signerFromEmbeddedWallet } from "./embedded-wallet.js";
|
|
32
|
+
|
|
33
|
+
// NOTE: the local-keypair MOCK embedded-wallet adapter
|
|
34
|
+
// (`createMockEmbeddedWallet`) is NOT exported here — it is test-only and lives
|
|
35
|
+
// behind the "./testing" subpath (src/testing/index.ts).
|
|
36
|
+
|
|
37
|
+
// The signer-adapter contracts (the seam the hooks/components/templates bind to).
|
|
38
|
+
export type {
|
|
39
|
+
EmbeddedWalletConnection,
|
|
40
|
+
EmbeddedWalletProvider,
|
|
41
|
+
SignerFromWalletAccountOptions,
|
|
42
|
+
TransactionSigner,
|
|
43
|
+
WalletStandardAccountLike,
|
|
44
|
+
WalletStandardSignTransaction,
|
|
45
|
+
} from "./types.js";
|
|
46
|
+
|
|
47
|
+
// Signer string catalog (so a future locale can extend `signer.*`).
|
|
48
|
+
export { EN_SIGNER_STRINGS, type SignerStringId } from "./strings.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signer-adapter string catalog (the `signer.*` namespace).
|
|
3
|
+
*
|
|
4
|
+
* Kept local to `src/signers/**` so the adapters route every user-facing string
|
|
5
|
+
* through the package's {@link t} resolver (the PLAN_2 Part A locale contract)
|
|
6
|
+
* WITHOUT cross-editing the shared `src/strings` catalog owned by another
|
|
7
|
+
* surface. A future locale can extend `EN_SIGNER_STRINGS` the same way.
|
|
8
|
+
*
|
|
9
|
+
* @module signers/strings
|
|
10
|
+
*/
|
|
11
|
+
import { t, type StringCatalog } from "../strings/index.js";
|
|
12
|
+
|
|
13
|
+
/** English `signer.*` strings used by the wallet/embedded adapters. */
|
|
14
|
+
export const EN_SIGNER_STRINGS = {
|
|
15
|
+
"signer.walletNoSignFeature":
|
|
16
|
+
"Wallet account {address} does not expose a solana:signTransaction feature. Pass options.signTransaction explicitly, or use a Wallet Standard account that supports transaction signing.",
|
|
17
|
+
"signer.walletNoSignature":
|
|
18
|
+
"The wallet returned no signature for account {address}. The wallet may have rejected or modified the transaction so the fee-payer signature is absent.",
|
|
19
|
+
"signer.embeddedSignatureCount":
|
|
20
|
+
"Embedded wallet returned {got} signatures for {expected} transactions; expected one per transaction.",
|
|
21
|
+
"signer.walletAdapterDisconnected":
|
|
22
|
+
"The wallet adapter is not connected (publicKey is null). Connect the wallet before creating a signer.",
|
|
23
|
+
"signer.walletAdapterNoSign":
|
|
24
|
+
"The wallet adapter does not expose signTransaction. Use a wallet that supports transaction signing, or migrate to the Wallet Standard path (signerFromWalletAccount).",
|
|
25
|
+
} as const satisfies StringCatalog;
|
|
26
|
+
|
|
27
|
+
/** A `signer.*` message id. */
|
|
28
|
+
export type SignerStringId = keyof typeof EN_SIGNER_STRINGS;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `t()` bound to the signer catalog: resolves `signer.*` ids while preserving
|
|
32
|
+
* the shared resolver's interpolation + verbatim-fallback behavior.
|
|
33
|
+
*/
|
|
34
|
+
export function ts(
|
|
35
|
+
id: SignerStringId,
|
|
36
|
+
vars?: Record<string, string | number | bigint>,
|
|
37
|
+
): string {
|
|
38
|
+
return t(id, vars, { catalog: EN_SIGNER_STRINGS });
|
|
39
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signer-adapter contracts for `@tetsuo-ai/marketplace-react`.
|
|
3
|
+
*
|
|
4
|
+
* Two browser → kit `TransactionSigner` bridges live in this subtree:
|
|
5
|
+
*
|
|
6
|
+
* - **Wallet Standard** ({@link signerFromWalletAccount}): wraps a connected
|
|
7
|
+
* browser wallet (the `@solana/react` /
|
|
8
|
+
* `useWalletAccountTransactionSendingSigner` Wallet Standard path, or any
|
|
9
|
+
* object exposing the `solana:signTransaction` feature) into the kit
|
|
10
|
+
* {@link TransactionSigner} the SDK's `createMarketplaceClient` consumes.
|
|
11
|
+
* - **Embedded / walletless** ({@link signerFromEmbeddedWallet}): the
|
|
12
|
+
* PLAN_2 D-1 "no wallet, no SOL" path. Defines the vendor-neutral
|
|
13
|
+
* {@link EmbeddedWalletProvider} interface ONE chosen vendor (Privy / Dynamic
|
|
14
|
+
* / Web3Auth — `[HUMAN]`-gated) implements, plus a working local-keypair MOCK
|
|
15
|
+
* so the walletless Done-when is testable against localnet without a vendor.
|
|
16
|
+
*
|
|
17
|
+
* SSR-safe: nothing here touches `window`/`document` at module scope. The
|
|
18
|
+
* adapters are plain factory functions; only `provider.connect()` (a user
|
|
19
|
+
* gesture) is browser-bound, and that is the vendor's concern, not ours.
|
|
20
|
+
*
|
|
21
|
+
* @module signers/types
|
|
22
|
+
*/
|
|
23
|
+
import type {
|
|
24
|
+
Address,
|
|
25
|
+
SignatureBytes,
|
|
26
|
+
Transaction,
|
|
27
|
+
TransactionSigner,
|
|
28
|
+
} from "@solana/kit";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The kit `TransactionSigner` returned by both bridges.
|
|
32
|
+
*
|
|
33
|
+
* Re-exported so consumers (and the hooks/components agents) can type their
|
|
34
|
+
* `signer` slot against one symbol without importing `@solana/kit` directly.
|
|
35
|
+
*/
|
|
36
|
+
export type { Address, SignatureBytes, Transaction, TransactionSigner };
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A Wallet Standard `solana:signTransaction` feature method, narrowed to the
|
|
40
|
+
* single shape {@link signerFromWalletAccount} needs.
|
|
41
|
+
*
|
|
42
|
+
* This mirrors `@solana/wallet-standard-features`'s `SolanaSignTransactionMethod`
|
|
43
|
+
* structurally so callers can pass either the real feature function or a test
|
|
44
|
+
* double without a hard dependency on that package's exact version.
|
|
45
|
+
*
|
|
46
|
+
* Given one or more `{ transaction }` wire-format inputs, it returns one
|
|
47
|
+
* `{ signedTransaction }` output per input (a fully serialized, signed
|
|
48
|
+
* transaction — wallets may modify it, which is why we diff signatures rather
|
|
49
|
+
* than assume identity).
|
|
50
|
+
*/
|
|
51
|
+
export type WalletStandardSignTransaction = (
|
|
52
|
+
...inputs: ReadonlyArray<{
|
|
53
|
+
/** Serialized transaction (wire format) to sign. */
|
|
54
|
+
readonly transaction: Uint8Array;
|
|
55
|
+
/** CAIP-2 chain id (e.g. `"solana:devnet"`); forwarded to the wallet. */
|
|
56
|
+
readonly chain?: string;
|
|
57
|
+
/** Optional Wallet Standard account handle (forwarded verbatim). */
|
|
58
|
+
readonly account?: unknown;
|
|
59
|
+
}>
|
|
60
|
+
) => Promise<
|
|
61
|
+
ReadonlyArray<{
|
|
62
|
+
/** Serialized, signed transaction (wire format). */
|
|
63
|
+
readonly signedTransaction: Uint8Array;
|
|
64
|
+
}>
|
|
65
|
+
>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The minimal Wallet Standard account shape {@link signerFromWalletAccount}
|
|
69
|
+
* consumes. A real `UiWalletAccount` (from `@solana/react` /
|
|
70
|
+
* `@wallet-standard/ui`) is structurally assignable to this; a test double only
|
|
71
|
+
* needs `address` plus a `solana:signTransaction` feature.
|
|
72
|
+
*
|
|
73
|
+
* The feature may be supplied two ways:
|
|
74
|
+
* - inline under `features["solana:signTransaction"].signTransaction`
|
|
75
|
+
* (the raw Wallet Standard layout), or
|
|
76
|
+
* - via the {@link SignerFromWalletAccountOptions.signTransaction} override.
|
|
77
|
+
*/
|
|
78
|
+
export interface WalletStandardAccountLike {
|
|
79
|
+
/** Base58 account address (becomes the signer's `address`). */
|
|
80
|
+
readonly address: string;
|
|
81
|
+
/** CAIP-2 chains this account supports (used to pick a default `chain`). */
|
|
82
|
+
readonly chains?: readonly string[];
|
|
83
|
+
/** Raw Wallet Standard feature bag, when resolvable off the account. */
|
|
84
|
+
readonly features?: Readonly<
|
|
85
|
+
Record<
|
|
86
|
+
string,
|
|
87
|
+
{ readonly signTransaction?: WalletStandardSignTransaction } | unknown
|
|
88
|
+
>
|
|
89
|
+
>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Options for {@link signerFromWalletAccount}. */
|
|
93
|
+
export interface SignerFromWalletAccountOptions {
|
|
94
|
+
/**
|
|
95
|
+
* CAIP-2 chain id forwarded to the wallet on each sign (e.g.
|
|
96
|
+
* `"solana:devnet"`, `"solana:mainnet"`). Defaults to the account's first
|
|
97
|
+
* `solana:*` chain, else `"solana:mainnet"`.
|
|
98
|
+
*/
|
|
99
|
+
chain?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Explicit `solana:signTransaction` feature method. Overrides any feature
|
|
102
|
+
* resolved off `account.features`. This is the seam tests and non-Wallet-
|
|
103
|
+
* Standard wrappers use, and the recommended way to pass the result of
|
|
104
|
+
* `@solana/react`'s wallet hooks when you hold the feature directly.
|
|
105
|
+
*/
|
|
106
|
+
signTransaction?: WalletStandardSignTransaction;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Vendor-neutral embedded-wallet provider — the PLAN_2 D-1 walletless seam.
|
|
111
|
+
*
|
|
112
|
+
* ONE `[HUMAN]`-chosen vendor (Privy / Dynamic / Web3Auth) implements this
|
|
113
|
+
* behind their email/social login + key custody. The marketplace layer only
|
|
114
|
+
* ever sees this interface, so templates/widget toggle the vendor by config
|
|
115
|
+
* (the C2 `payments.embedded` boolean) without an API break.
|
|
116
|
+
*
|
|
117
|
+
* The {@link createMockEmbeddedWallet} local-keypair adapter implements it for
|
|
118
|
+
* tests so the "no wallet, no SOL" Done-when runs against localnet today.
|
|
119
|
+
*/
|
|
120
|
+
export interface EmbeddedWalletProvider {
|
|
121
|
+
/**
|
|
122
|
+
* Trigger the vendor's login/onboarding (email, social, passkey, …) and
|
|
123
|
+
* return a ready signer. Idempotent: calling it again after a connection
|
|
124
|
+
* resolves the existing wallet rather than provisioning a new one.
|
|
125
|
+
*
|
|
126
|
+
* This is the ONLY browser-bound method (it runs behind a user gesture); the
|
|
127
|
+
* factory that wraps the provider stays SSR-safe.
|
|
128
|
+
*/
|
|
129
|
+
connect(): Promise<EmbeddedWalletConnection>;
|
|
130
|
+
/** Whether a wallet is currently connected (for headless gating/SSR). */
|
|
131
|
+
isConnected(): boolean;
|
|
132
|
+
/** The connected wallet, or `null` before {@link connect}. */
|
|
133
|
+
getConnection(): EmbeddedWalletConnection | null;
|
|
134
|
+
/** Tear down the session (sign out). Optional — not all vendors expose it. */
|
|
135
|
+
disconnect?(): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A live embedded-wallet connection: the funded account address plus the
|
|
140
|
+
* primitive that produces signatures.
|
|
141
|
+
*
|
|
142
|
+
* `signTransactions` is the lowest-honest-common-denominator across vendors:
|
|
143
|
+
* given kit {@link Transaction} objects, return this account's
|
|
144
|
+
* {@link SignatureBytes} for each (a partial-signer contract — the vendor never
|
|
145
|
+
* broadcasts, the SDK client's transport does). {@link signerFromEmbeddedWallet}
|
|
146
|
+
* lifts it into a kit {@link TransactionSigner}.
|
|
147
|
+
*/
|
|
148
|
+
export interface EmbeddedWalletConnection {
|
|
149
|
+
/** The embedded wallet's base58 address. */
|
|
150
|
+
readonly address: string;
|
|
151
|
+
/**
|
|
152
|
+
* Produce this account's signature over each provided transaction WITHOUT
|
|
153
|
+
* sending it. One {@link SignatureBytes} per input, in order.
|
|
154
|
+
*/
|
|
155
|
+
signTransactions(
|
|
156
|
+
transactions: readonly Transaction[],
|
|
157
|
+
): Promise<readonly SignatureBytes[]>;
|
|
158
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wallet Standard → kit `TransactionSigner` bridge (PLAN.md P4.1 / PLAN_2 D-1).
|
|
3
|
+
*
|
|
4
|
+
* Turns a connected browser wallet into the {@link TransactionSigner} the SDK's
|
|
5
|
+
* `createMarketplaceClient` consumes. The SDK client signs via
|
|
6
|
+
* `signTransactionMessageWithSigners(...)` and submits through its OWN transport
|
|
7
|
+
* — so it needs a PARTIAL signer (one that returns signatures without sending),
|
|
8
|
+
* NOT a `TransactionSendingSigner` (which `signTransactionMessageWithSigners`
|
|
9
|
+
* deliberately ignores). This bridge therefore produces a
|
|
10
|
+
* {@link TransactionPartialSigner}: it serializes each transaction, hands it to
|
|
11
|
+
* the wallet's `solana:signTransaction` feature, and diffs the returned signed
|
|
12
|
+
* transaction to recover THIS account's signature.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link signerFromWalletAccount}
|
|
15
|
+
* @module signers/wallet-account
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
address,
|
|
19
|
+
getTransactionDecoder,
|
|
20
|
+
getTransactionEncoder,
|
|
21
|
+
type Address,
|
|
22
|
+
type SignatureBytes,
|
|
23
|
+
type Transaction,
|
|
24
|
+
} from "@solana/kit";
|
|
25
|
+
import { ts } from "./strings.js";
|
|
26
|
+
import type {
|
|
27
|
+
SignerFromWalletAccountOptions,
|
|
28
|
+
TransactionSigner,
|
|
29
|
+
WalletStandardAccountLike,
|
|
30
|
+
WalletStandardSignTransaction,
|
|
31
|
+
} from "./types.js";
|
|
32
|
+
|
|
33
|
+
const SOLANA_SIGN_TRANSACTION = "solana:signTransaction";
|
|
34
|
+
|
|
35
|
+
/** Resolve the wallet's `solana:signTransaction` method from account/options. */
|
|
36
|
+
function resolveSignTransaction(
|
|
37
|
+
account: WalletStandardAccountLike,
|
|
38
|
+
options: SignerFromWalletAccountOptions,
|
|
39
|
+
): WalletStandardSignTransaction {
|
|
40
|
+
if (options.signTransaction) return options.signTransaction;
|
|
41
|
+
const feature = account.features?.[SOLANA_SIGN_TRANSACTION] as
|
|
42
|
+
| { signTransaction?: WalletStandardSignTransaction }
|
|
43
|
+
| undefined;
|
|
44
|
+
if (feature?.signTransaction) return feature.signTransaction;
|
|
45
|
+
throw new Error(ts("signer.walletNoSignFeature", { address: account.address }));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Pick the CAIP-2 chain to forward to the wallet. */
|
|
49
|
+
function resolveChain(
|
|
50
|
+
account: WalletStandardAccountLike,
|
|
51
|
+
options: SignerFromWalletAccountOptions,
|
|
52
|
+
): string | undefined {
|
|
53
|
+
if (options.chain) return options.chain;
|
|
54
|
+
return account.chains?.find((c) => c.startsWith("solana:"));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Bridge a Wallet Standard account into a kit {@link TransactionSigner}.
|
|
59
|
+
*
|
|
60
|
+
* Accepts either a real `UiWalletAccount` (the `@solana/react` path — pass the
|
|
61
|
+
* account and a `chain`, or pass the hook's feature via
|
|
62
|
+
* {@link SignerFromWalletAccountOptions.signTransaction}) or any object exposing
|
|
63
|
+
* the `solana:signTransaction` feature. The returned signer is a
|
|
64
|
+
* {@link TransactionPartialSigner}, the exact shape the SDK client expects.
|
|
65
|
+
*
|
|
66
|
+
* Wallets may MODIFY a transaction before signing (priority fees, guard
|
|
67
|
+
* instructions). We honor that by decoding the wallet's returned signed
|
|
68
|
+
* transaction and extracting only THIS account's signature; the SDK client then
|
|
69
|
+
* re-assembles and submits. (If a wallet rewrites the message such that the
|
|
70
|
+
* fee-payer's own prior signing is invalidated, that is a wallet contract the
|
|
71
|
+
* SDK's single-fee-payer flow already assumes won't happen for the payer.)
|
|
72
|
+
*
|
|
73
|
+
* SSR-safe: constructs no browser globals; the wallet round-trip only runs when
|
|
74
|
+
* a transaction is actually signed.
|
|
75
|
+
*
|
|
76
|
+
* @param account - The connected Wallet Standard account (needs `address`).
|
|
77
|
+
* @param options - Chain + an optional explicit `signTransaction` override.
|
|
78
|
+
* @returns A kit {@link TransactionSigner} usable as `config.signer`.
|
|
79
|
+
* @throws Error if no `solana:signTransaction` feature can be resolved.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* // With @solana/react (Wallet Standard):
|
|
84
|
+
* const account = useSelectedWalletAccount(); // UiWalletAccount
|
|
85
|
+
* const signer = signerFromWalletAccount(account, { chain: "solana:devnet" });
|
|
86
|
+
* // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export function signerFromWalletAccount(
|
|
90
|
+
account: WalletStandardAccountLike,
|
|
91
|
+
options: SignerFromWalletAccountOptions = {},
|
|
92
|
+
): TransactionSigner {
|
|
93
|
+
const signerAddress: Address = address(account.address);
|
|
94
|
+
const signTransaction = resolveSignTransaction(account, options);
|
|
95
|
+
const chain = resolveChain(account, options);
|
|
96
|
+
const encoder = getTransactionEncoder();
|
|
97
|
+
const decoder = getTransactionDecoder();
|
|
98
|
+
|
|
99
|
+
async function signOne(transaction: Transaction): Promise<SignatureBytes> {
|
|
100
|
+
const wireBytes = new Uint8Array(encoder.encode(transaction));
|
|
101
|
+
const [output] = await signTransaction({
|
|
102
|
+
transaction: wireBytes,
|
|
103
|
+
...(chain ? { chain } : {}),
|
|
104
|
+
});
|
|
105
|
+
if (!output) {
|
|
106
|
+
throw new Error(ts("signer.walletNoSignature", { address: account.address }));
|
|
107
|
+
}
|
|
108
|
+
const signed = decoder.decode(output.signedTransaction);
|
|
109
|
+
const signature = signed.signatures[signerAddress];
|
|
110
|
+
if (!signature) {
|
|
111
|
+
throw new Error(ts("signer.walletNoSignature", { address: account.address }));
|
|
112
|
+
}
|
|
113
|
+
return signature as SignatureBytes;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
address: signerAddress,
|
|
118
|
+
async signTransactions(transactions) {
|
|
119
|
+
// Sign in parallel — partial signers are order-independent (each returns a
|
|
120
|
+
// single-entry SignatureDictionary the caller merges).
|
|
121
|
+
return Promise.all(
|
|
122
|
+
transactions.map(async (transaction) => ({
|
|
123
|
+
[signerAddress]: await signOne(transaction),
|
|
124
|
+
})),
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
} satisfies TransactionSigner;
|
|
128
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LEGACY `@solana/wallet-adapter` compatibility shim (PLAN.md P4.1).
|
|
3
|
+
*
|
|
4
|
+
* The supported, robust path for browser wallets is the Wallet Standard bridge
|
|
5
|
+
* ({@link signerFromWalletAccount} via `@solana/react`): every modern wallet —
|
|
6
|
+
* including all wallet-adapter wallets — registers as a Wallet Standard wallet,
|
|
7
|
+
* so a wallet-adapter app can migrate by reading the selected account through
|
|
8
|
+
* `@solana/react` and dropping it into `signerFromWalletAccount`. PREFER THAT.
|
|
9
|
+
*
|
|
10
|
+
* This shim exists for apps still holding a raw wallet-adapter
|
|
11
|
+
* `WalletContextState` (web3.js v1 `signTransaction`). It bridges WITHOUT a hard
|
|
12
|
+
* dependency on `@solana/wallet-adapter-*` OR `@solana/web3.js` (1.x): the
|
|
13
|
+
* caller injects the web3.js `VersionedTransaction` class (the only piece we
|
|
14
|
+
* cannot reconstruct), and we round-trip through the shared wire format — a kit
|
|
15
|
+
* {@link Transaction} and a web3.js `VersionedTransaction` serialize to the SAME
|
|
16
|
+
* bytes, so no semantic re-encoding is needed.
|
|
17
|
+
*
|
|
18
|
+
* SSR-safe: no browser globals at module scope.
|
|
19
|
+
*
|
|
20
|
+
* @module signers/wallet-adapter
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
address,
|
|
24
|
+
getTransactionDecoder,
|
|
25
|
+
getTransactionEncoder,
|
|
26
|
+
type SignatureBytes,
|
|
27
|
+
type Transaction,
|
|
28
|
+
} from "@solana/kit";
|
|
29
|
+
import { ts } from "./strings.js";
|
|
30
|
+
import type { TransactionSigner } from "./types.js";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The web3.js v1 `VersionedTransaction` surface this shim needs: a static
|
|
34
|
+
* `deserialize(bytes)` and an instance `serialize()`. Pass the real class from
|
|
35
|
+
* `@solana/web3.js` — typed structurally so this module never imports it.
|
|
36
|
+
*/
|
|
37
|
+
export interface VersionedTransactionLike {
|
|
38
|
+
serialize(): Uint8Array;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The static side of the injected `VersionedTransaction` class. */
|
|
42
|
+
export interface VersionedTransactionCtor {
|
|
43
|
+
deserialize(bytes: Uint8Array): VersionedTransactionLike;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The minimal slice of a wallet-adapter `WalletContextState` this shim consumes.
|
|
48
|
+
* Both `publicKey` (anything with a base58 `toString()`/`toBase58()`) and the
|
|
49
|
+
* v1 `signTransaction` are required; a connected adapter exposes both.
|
|
50
|
+
*/
|
|
51
|
+
export interface WalletAdapterLike {
|
|
52
|
+
/** The connected account's public key (base58 via `toBase58()`/`toString()`). */
|
|
53
|
+
readonly publicKey:
|
|
54
|
+
| { toBase58(): string }
|
|
55
|
+
| { toString(): string }
|
|
56
|
+
| string
|
|
57
|
+
| null;
|
|
58
|
+
/** web3.js v1 sign — returns the same transaction type, signed. */
|
|
59
|
+
signTransaction?: <T extends VersionedTransactionLike>(
|
|
60
|
+
transaction: T,
|
|
61
|
+
) => Promise<T>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Options for {@link signerFromWalletAdapter}. */
|
|
65
|
+
export interface SignerFromWalletAdapterOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The web3.js `VersionedTransaction` class (`import { VersionedTransaction }
|
|
68
|
+
* from "@solana/web3.js"`). Required — it is the one piece this no-dep shim
|
|
69
|
+
* cannot supply itself.
|
|
70
|
+
*/
|
|
71
|
+
VersionedTransaction: VersionedTransactionCtor;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveAdapterAddress(adapter: WalletAdapterLike): string {
|
|
75
|
+
const { publicKey } = adapter;
|
|
76
|
+
if (publicKey == null) {
|
|
77
|
+
throw new Error(ts("signer.walletAdapterDisconnected"));
|
|
78
|
+
}
|
|
79
|
+
if (typeof publicKey === "string") return publicKey;
|
|
80
|
+
if ("toBase58" in publicKey && typeof publicKey.toBase58 === "function") {
|
|
81
|
+
return publicKey.toBase58();
|
|
82
|
+
}
|
|
83
|
+
return String(publicKey);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Bridge a LEGACY `@solana/wallet-adapter` `WalletContextState` into a kit
|
|
88
|
+
* {@link TransactionSigner}.
|
|
89
|
+
*
|
|
90
|
+
* Use only when you cannot reach the wallet through `@solana/react`. The result
|
|
91
|
+
* is a {@link TransactionPartialSigner} (the SDK client owns submission), built
|
|
92
|
+
* by serializing the kit transaction to wire bytes, rehydrating it as a web3.js
|
|
93
|
+
* `VersionedTransaction`, handing THAT to the adapter's `signTransaction`, then
|
|
94
|
+
* decoding the signed wire bytes back to a kit transaction to extract this
|
|
95
|
+
* account's signature.
|
|
96
|
+
*
|
|
97
|
+
* @param adapter - A connected wallet-adapter state (`publicKey` + `signTransaction`).
|
|
98
|
+
* @param options - Must inject the web3.js `VersionedTransaction` class.
|
|
99
|
+
* @returns A kit {@link TransactionSigner} usable as `config.signer`.
|
|
100
|
+
* @throws Error if the adapter is disconnected or lacks `signTransaction`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { VersionedTransaction } from "@solana/web3.js";
|
|
105
|
+
* import { useWallet } from "@solana/wallet-adapter-react";
|
|
106
|
+
*
|
|
107
|
+
* const wallet = useWallet();
|
|
108
|
+
* const signer = signerFromWalletAdapter(wallet, { VersionedTransaction });
|
|
109
|
+
* // -> pass `signer` to <AgencProvider config={{ signer, rpcUrl }}>.
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function signerFromWalletAdapter(
|
|
113
|
+
adapter: WalletAdapterLike,
|
|
114
|
+
options: SignerFromWalletAdapterOptions,
|
|
115
|
+
): TransactionSigner {
|
|
116
|
+
const signerAddress = address(resolveAdapterAddress(adapter));
|
|
117
|
+
const { signTransaction } = adapter;
|
|
118
|
+
if (typeof signTransaction !== "function") {
|
|
119
|
+
throw new Error(ts("signer.walletAdapterNoSign"));
|
|
120
|
+
}
|
|
121
|
+
const { VersionedTransaction } = options;
|
|
122
|
+
const encoder = getTransactionEncoder();
|
|
123
|
+
const decoder = getTransactionDecoder();
|
|
124
|
+
|
|
125
|
+
async function signOne(transaction: Transaction): Promise<SignatureBytes> {
|
|
126
|
+
const wireBytes = new Uint8Array(encoder.encode(transaction));
|
|
127
|
+
const legacyTx = VersionedTransaction.deserialize(wireBytes);
|
|
128
|
+
const signed = await signTransaction!(legacyTx);
|
|
129
|
+
const signedTx = decoder.decode(new Uint8Array(signed.serialize()));
|
|
130
|
+
const signature = signedTx.signatures[signerAddress];
|
|
131
|
+
if (!signature) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
ts("signer.walletNoSignature", { address: signerAddress }),
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
return signature as SignatureBytes;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
address: signerAddress,
|
|
141
|
+
async signTransactions(transactions) {
|
|
142
|
+
return Promise.all(
|
|
143
|
+
transactions.map(async (transaction) => ({
|
|
144
|
+
[signerAddress]: await signOne(transaction),
|
|
145
|
+
})),
|
|
146
|
+
);
|
|
147
|
+
},
|
|
148
|
+
} satisfies TransactionSigner;
|
|
149
|
+
}
|