diff --git a/README.md b/README.md index 4a89b8f..e876628 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Copy the `skills/` directory contents to your assistant's skills location. ``` skills/ ├── smart-contracts/ # Stellar smart contracts — SKILL.md router + development/testing/security files -├── dapp/ # Frontend — SKILL.md router + react / data-fetching / smart-accounts files +├── dapp/ # Frontend — SKILL.md router + react / data-fetching / smart-accounts / walletconnect files ├── assets/SKILL.md # Stellar Assets, trustlines, SAC bridge ├── data/ # Stellar RPC (preferred) — SKILL.md router + horizon (legacy) file ├── agentic-payments/ # AI/machine payments — SKILL.md router + x402 / mpp files diff --git a/evals/scenarios/dapp/05-walletconnect-module.json b/evals/scenarios/dapp/05-walletconnect-module.json new file mode 100644 index 0000000..d513f01 --- /dev/null +++ b/evals/scenarios/dapp/05-walletconnect-module.json @@ -0,0 +1,15 @@ +{ + "skills": [ + "dapp" + ], + "query": "My testnet dapp uses Stellar Wallets Kit. Users want to connect their mobile wallets with WalletConnect. How do I add that?", + "expected_behavior": [ + "Reads dapp/walletconnect.md rather than answering from memory", + "Imports WalletConnectModule from @creit-tech/stellar-wallets-kit/modules/wallet-connect and adds it next to defaultModules() in StellarWalletsKit.init, since defaultModules() does not include it", + "Passes a projectId from the Reown Dashboard and app metadata (name, description, url, icons)", + "Sets allowedChains to WalletConnectTargetChain.TESTNET to match the kit's testnet network, because the module defaults to stellar:pubnet only" + ], + "machine_checkable": [ + "Generated TypeScript passes tsc --noEmit" + ] +} diff --git a/evals/scenarios/dapp/06-walletconnect-pay-wallet.json b/evals/scenarios/dapp/06-walletconnect-pay-wallet.json new file mode 100644 index 0000000..df47cfa --- /dev/null +++ b/evals/scenarios/dapp/06-walletconnect-pay-wallet.json @@ -0,0 +1,13 @@ +{ + "skills": [ + "dapp" + ], + "query": "We run a Stellar wallet and want to accept WalletConnect Pay. How should we handle the Stellar payment request?", + "expected_behavior": [ + "Signs the gateway's envelope with stellar_signXDR and returns it as a base64 string, and does not submit it or use stellar_signAndSubmitXDR", + "Says WalletConnect Pay wraps the signed transaction in a fee bump and pays the XLM fee, so the buyer needs only USDC", + "Limits the flow to stellar:pubnet and Circle USDC, and advertises only stellar:pubnet:G... accounts, never muxed M... accounts", + "Does not change the fee, sequence number, time bounds, memo or operations before signing", + "Notes the gateway offers Stellar only when the account exists and holds a USDC trustline with enough USDC" + ] +} diff --git a/skills/dapp/SKILL.md b/skills/dapp/SKILL.md index 159a8cb..7647597 100644 --- a/skills/dapp/SKILL.md +++ b/skills/dapp/SKILL.md @@ -1,6 +1,6 @@ --- name: dapp -description: Stellar dApp / frontend development. Covers the JavaScript stellar-sdk (browser + Node.js), Varial wallet, Stellar Wallets Kit (multi-wallet), Wallet Standard, smart accounts with passkeys, transaction building / signing / submission, smart contract invocation from the client, simulation, and error handling. Use when building a React/Next.js/Node.js app that talks to Stellar — classic operations or smart contracts. Blux is also an option. +description: Stellar dApp / frontend development. Covers the JavaScript stellar-sdk (browser + Node.js), Varial wallet, Stellar Wallets Kit (multi-wallet), WalletConnect and WalletConnect Pay, Wallet Standard, smart accounts with passkeys, transaction building / signing / submission, smart contract invocation from the client, simulation, and error handling. Use when building a React/Next.js/Node.js app that talks to Stellar — classic operations or smart contracts. Blux is also an option. user-invocable: true argument-hint: "[dapp task]" --- @@ -10,7 +10,7 @@ argument-hint: "[dapp task]" Client-side development with `@stellar/stellar-sdk`, wallet connection, signing, and submitting transactions. Covers both classic Stellar operations and smart contract invocation from the browser or Node.js. ## When to use this skill -- Connecting Varial or other wallets via Stellar Wallets Kit +- Connecting Varial or other wallets via Stellar Wallets Kit, including mobile wallets over WalletConnect - Building, simulating, signing, and submitting transactions - Invoking Stellar smart contracts from a frontend - Implementing smart accounts with passkeys @@ -44,6 +44,7 @@ This file covers SDK setup, wallet connection, and transaction build/sign/submit | Connect-wallet button, payment form, Next.js App Router wiring | [react.md](react.md) | | Account balances, contract reads (`queryContract`), raw ledger entries | [data-fetching.md](data-fetching.md) | | Passkey smart wallets (Smart Account Kit), gasless tx via OpenZeppelin Relayer | [smart-accounts.md](smart-accounts.md) | +| WalletConnect: Wallets Kit module setup, the `stellar_*` wallet methods, WalletConnect Pay | [walletconnect.md](walletconnect.md) | | Production UX checklist | [Transaction UX Checklist](#transaction-ux-checklist) (below) | ## Recommended Dependencies @@ -214,6 +215,7 @@ import { defaultModules } from "@creit-tech/stellar-wallets-kit/modules/utils"; // there is no instance to construct or pass around. // defaultModules() loads every wallet that needs no extra setup; modules with // prerequisites (WalletConnect, Ledger, Trezor) must be imported and added explicitly. +// WalletConnect needs a project ID and app metadata, plus allowedChains on testnet: see walletconnect.md. StellarWalletsKit.init({ modules: defaultModules(), network: Networks.TESTNET, diff --git a/skills/dapp/walletconnect.md b/skills/dapp/walletconnect.md new file mode 100644 index 0000000..51495be --- /dev/null +++ b/skills/dapp/walletconnect.md @@ -0,0 +1,80 @@ +# WalletConnect on Stellar + +Connect mobile wallets to a dapp over WalletConnect, implement the `stellar` namespace in a wallet, and accept WalletConnect Pay. Companion to [SKILL.md](SKILL.md). + +> **Sourcing** (checked November 2026): the [WalletConnect Stellar RPC reference](https://docs.walletconnect.com/wallets/chains/stellar), the [WalletConnect Pay Stellar guide](https://docs.walletconnect.com/payments/wallets/token-chain-support/stellar-support), and Stellar Wallets Kit 2.8.0 on JSR (`sdk/modules/wallet-connect.module.ts`). WalletConnect marks the Stellar RPC standard as a proposal under review, so method shapes can change. Check the live page before you ship. + +## Dapp: add the WalletConnect module to Stellar Wallets Kit + +`defaultModules()` does not include WalletConnect, because the module needs a project ID and app metadata. Create a project ID in the [Reown Dashboard](https://dashboard.reown.com). The ID is public, so a `NEXT_PUBLIC_` variable is fine. + +```typescript +// lib/wallets-kit.ts +import { StellarWalletsKit, Networks } from "@creit-tech/stellar-wallets-kit"; +import { defaultModules } from "@creit-tech/stellar-wallets-kit/modules/utils"; +import { + WalletConnectModule, + WalletConnectTargetChain, +} from "@creit-tech/stellar-wallets-kit/modules/wallet-connect"; + +const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID; +if (!projectId) throw new Error("Missing NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID"); + +StellarWalletsKit.init({ + modules: [ + ...defaultModules(), + new WalletConnectModule({ + projectId, + metadata: { + name: "My Stellar dApp", + description: "Payments on Stellar", + url: "https://example.com", // your app's origin + icons: ["https://example.com/icon.png"], + }, + // The module defaults to stellar:pubnet only. Match the kit's network, + // or every request on testnet targets a chain the session never approved. + allowedChains: [WalletConnectTargetChain.TESTNET], + }), + ], + network: Networks.TESTNET, +}); +``` + +What to know about the module (Wallets Kit 2.8.0): +- `authModal()`, `signTransaction()` and `signAuthEntry()` work as with any other module. The kit sends `stellar:pubnet` when the network passphrase is Mainnet and `stellar:testnet` otherwise. +- The module supports only `Networks.PUBLIC` and `Networks.TESTNET`. Other networks throw on connect. +- The session requires `stellar_signXDR`. It asks for `stellar_signAndSubmitXDR`, `stellar_signAuthEntry` and `stellar_signMessage` as optional methods, so a wallet can approve the session without them. +- The module does not listen for `accountsChanged` or `chainChanged`. Read the address again after the user switches accounts in the wallet. + +## Wallet: implement the `stellar` namespace + +| Item | Value | +|------|-------| +| Chains (CAIP-2) | `stellar:pubnet`, `stellar:testnet` | +| Accounts (CAIP-10) | `stellar:pubnet:G...` | +| Methods | `stellar_signXDR`, `stellar_signAndSubmitXDR`, `stellar_signMessage`, `stellar_signAuthEntry` | +| Events | `accountsChanged`, `chainChanged` | + +Rules from the reference: +- Return only `G...` account IDs. Muxed (`M...`), pre-auth (`T...`) and hash (`X...`) forms are not valid accounts. +- Derive the network passphrase from the CAIP-2 chain. Never trust a network value from the request. +- `stellar_signXDR` signs a base64 `TransactionEnvelope` and returns it without submitting. `stellar_signAndSubmitXDR` signs and submits from the wallet. +- `stellar_signMessage` signs `sha256("Stellar Signed Message:\n" || message)`, the [SEP-53](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0053.md) format. Never sign raw bytes. +- `stellar_signAuthEntry` signs a `SorobanAuthorizationEntry` with address credentials. Reject the request when the entry's address is not the requested account. + +Two known gaps between the spec page and real clients: +- **Auth-entry signature shape.** The WalletConnect page says to put a bare `SCMap` (`public_key`, `signature`) in the entry. The Soroban host decodes a `G...` account's signature as a `Vec` of those maps and rejects anything else. Sign with `authorizeEntry` from `@stellar/stellar-sdk`, which writes the `Vec` form. +- **Parameter names.** Wallets Kit 2.8.0 sends `{ xdr }` for `stellar_signXDR` and `{ entryXdr }` for `stellar_signAuthEntry`, with no `chain` or `account`. It reads `{ status }` from `stellar_signAndSubmitXDR`. The spec page lists `authEntry`, `chain` and `account` as parameters and returns `tx_hash` and `signedXDR`. Test against the dapps your wallet must support. + +## Wallet: accept WalletConnect Pay + +WalletConnect Pay supports Stellar since 29 October 2026. LOBSTR was the first live wallet. The gateway builds the payment, the wallet signs it, and WalletConnect Pay pays the fee and broadcasts. + +- **Network and asset**: `stellar:pubnet` only. USDC from Circle, CAIP-19 `stellar:pubnet/asset:USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN`. +- **Accounts**: advertise `stellar:pubnet:G...` in `getPaymentOptions`. Muxed (`M...`) accounts are not valid. +- **Eligibility**: the gateway offers Stellar only when the account exists, holds a USDC trustline and has enough USDC. A missing Stellar option is expected, not an error. +- **Sign only**: sign with `stellar_signXDR` and return the signed envelope as a base64 string. Never use `stellar_signAndSubmitXDR`: the buyer then pays the fee and uses the sequence number the payment needs, so the payment fails. +- **Fee**: WalletConnect Pay wraps the signed transaction in a fee bump and pays the XLM fee. The buyer needs only USDC. +- **No changes**: do not change the fee, sequence number, time bounds, memo or operations. The gateway rejects a changed envelope. +- **Checks before signing**: bind the passphrase from `chainId`, confirm the transaction source equals the requested account, and show the USDC amount and destination. +- **Timing**: sign and confirm right after fetch. Another transaction from the same account in between invalidates the sequence number. diff --git a/skills/standards/ecosystem.md b/skills/standards/ecosystem.md index affa9c9..875200c 100644 --- a/skills/standards/ecosystem.md +++ b/skills/standards/ecosystem.md @@ -202,6 +202,27 @@ SDK for integrating multiple Stellar wallets. - **GitHub**: https://github.com/Creit-Tech/Stellar-Wallets-Kit - **Supports**: Varial, LOBSTR, xBull, Albedo, Rabet, Hana, Ledger, Trezor, WalletConnect +#### WalletConnect +Open protocol that connects mobile wallets to dapps. It defines a `stellar` namespace. +- **Docs**: https://docs.walletconnect.com/wallets/chains/stellar +- **Chains (CAIP-2)**: `stellar:pubnet`, `stellar:testnet`. Accounts are CAIP-10, for example `stellar:pubnet:G...` +- **Methods**: `stellar_signXDR`, `stellar_signAndSubmitXDR`, `stellar_signMessage`, `stellar_signAuthEntry` +- **Events**: `accountsChanged`, `chainChanged` +- **Status**: the Stellar RPC standard is a proposal under review, so shapes can change +- **Dapp integration**: the Stellar Wallets Kit WalletConnect module needs a project ID and app metadata. See [dapp/walletconnect.md](../dapp/walletconnect.md) + +#### WalletConnect Pay +Payment network where WalletConnect Pay builds the payment and the wallet only signs. Supports Stellar since 29 October 2026; LOBSTR was the first live wallet. +- **Docs**: https://docs.walletconnect.com/payments/wallets/token-chain-support/stellar-support +- **Network and asset**: `stellar:pubnet` only, Circle USDC (`stellar:pubnet/asset:USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN`) +- **Fees**: WalletConnect Pay wraps the signed transaction in a fee bump and pays the XLM fee. The buyer needs only USDC +- **Wallet rules**: + - Sign with `stellar_signXDR` and return the envelope. Never use `stellar_signAndSubmitXDR`: the buyer then pays the fee and uses the payment's sequence number + - Advertise only `G...` accounts. Muxed (`M...`) accounts are not valid + - The account must exist and hold a USDC trustline with enough USDC, or the gateway does not offer Stellar + - Do not change the fee, sequence number, time bounds, memo or operations. The gateway rejects a changed envelope +- **Implementation guide**: [dapp/walletconnect.md](../dapp/walletconnect.md#wallet-accept-walletconnect-pay) + ## Developer Tools ### Smart Account & Authentication