Skip to content

Commit cc334d6

Browse files
committed
comments
1 parent ca9b32b commit cc334d6

File tree

10 files changed

+154
-85
lines changed

10 files changed

+154
-85
lines changed

examples/wallet-auth/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ It contains two separate implementations:
99

1010
**Auth Proxy Highlights**
1111

12-
- **Simplified setup:** No need to host or maintain your own authentication backend. The Auth Proxy is a managed, multi-tenant service that handles signing and forwarding authentication requests.
13-
- **Built-in security:** Proxy keys are HPKE-encrypted inside Turnkey’s enclave and decrypted only in memory per request. Includes strict origin validation and CORS enforcement.
14-
- **Centralized configuration:** Manage allowed origins, session lifetimes, email/SMS templates, and OAuth settings directly from the Turnkey Dashboard.
15-
- **Faster development:** The frontend calls Auth Proxy endpoints directly — no backend endpoints needed for OTP, OAuth, or signup flows.
12+
- No need to host or maintain your own authentication backend. The Auth Proxy is a managed, multi-tenant service that handles signing and forwarding authentication requests.
13+
- Proxy keys are HPKE-encrypted inside Turnkey’s enclave and decrypted only in memory per request. Includes strict origin validation and CORS enforcement.
14+
- Manage allowed origins, session lifetimes, email/SMS templates, and OAuth settings directly from the Turnkey Dashboard.
15+
- The frontend calls Auth Proxy endpoints directly — no backend endpoints needed for OTP, OAuth, or signup flows.
1616

1717
**Custom Backend Highlights**
1818

1919
You could:
2020

21-
- **User data:** Store and retrieve user data associated with Turnkey sub-organizations.
22-
- **Metrics and monitoring:** Add custom validations, rate limiting, and logging.
23-
- **Co-signing capabilities:** Enable 2/2 signing patterns where your application is a co-signer.
21+
- Store and retrieve user data associated with Turnkey sub-organizations.
22+
- Add custom validations, rate limiting, and logging.
23+
- Enable 2/2 signing patterns where your application is a co-signer.

examples/wallet-auth/with-backend/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ A high-level summary of the user experience and what appears on screen:
1313

1414
Once logged in, access a dashboard with two panels:
1515

16-
**Left:** sign messages and simple demo transactions for both Ethereum and Solana using the **selected** embedded **or** connected wallet. The signing and broadcasting behavior differs slightly depending on wallet type:
16+
**Left:** sign messages and simple demo testnet transactions for both Ethereum (Sepolia testnet) and Solana (Devnet) using the **selected** embedded **or** connected wallet. The signing and broadcasting behavior differs slightly depending on wallet type:
1717

1818
- **Connected wallets**
19-
- Ethereum: delegates to the wallet’s native `signAndSendTransaction` method. Does not require an rpcUrl (the wallet handles broadcasting).
19+
- Ethereum: delegates to the wallet’s native `signAndSendTransaction` method. Does not require an rpcUrl (the external wallet provider handles broadcasting).
2020
- Solana: signs locally with the connected wallet but requires an rpcUrl for broadcasting.
2121

2222
- **Embedded wallets**
@@ -27,15 +27,16 @@ Once logged in, access a dashboard with two panels:
2727
Notes:
2828

2929
> In this demo, you can configure these URLs using `NEXT_PUBLIC_RPC_ETH` and `NEXT_PUBLIC_RPC_SOL`.
30-
> Both Ethereum and Solana demo transactions are send-to-self transfers with zero value, purely for demonstration purposes.
30+
> Both Ethereum and Solana demo testnet transactions are send-to-self transfers with zero value, purely for demonstration purposes.
3131
3232
**Right:** view all the sub-organization embedded and connected wallets.
3333

3434
## How it works
3535

3636
1. Build and sign a wallet login request **without submitting it to Turnkey** using [buildWalletLoginRequest()](https://github.com/tkhq/sdk/blob/fa54063a394bfef7ead9f64b72a093c5e696a401/packages/core/src/__clients__/core.ts#L797). This function performs the following:
3737

38-
- Initializes the wallet stamper, ensures a valid session public key (generating one if needed), and signs the login intent with the connected wallet.
38+
- Generates a new key pair to serve as the session key and has the connected wallet sign a login intent containing the public key. This resulting stamped request can then be sent to Turnkey to register that key pair as a session key pair.
39+
3940
- For **Ethereum wallets**, the public key cannot be derived from the wallet address alone — it’s extracted from the signature included in the stamped login request.
4041
- For **Solana wallets**, the wallet address itself is the public key, so it’s retrieved directly from the connected wallet.
4142
- Returns both:

examples/wallet-auth/with-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@tailwindcss/postcss": "4.1.13",
1616
"@turnkey/react-wallet-kit": "workspace:*",
1717
"@turnkey/sdk-server": "workspace:*",
18+
"@turnkey/encoding": "workspace:*",
1819
"@types/node": "20.3.1",
1920
"@types/react": "18.2.14",
2021
"@types/react-dom": "18.2.6",

examples/wallet-auth/with-backend/src/app/dashboard/page.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
VersionedTransaction,
2626
clusterApiUrl,
2727
} from "@solana/web3.js";
28+
import { uint8ArrayToHexString } from "@turnkey/encoding";
2829

2930
// ---------- Utils ----------
3031
function safeStringify(x: unknown) {
@@ -35,13 +36,6 @@ function safeStringify(x: unknown) {
3536
);
3637
}
3738

38-
// Uint8Array -> hex
39-
function toHex(u8: Uint8Array) {
40-
return Array.from(u8)
41-
.map((b) => b.toString(16).padStart(2, "0"))
42-
.join("");
43-
}
44-
4539
// Build a Solana v0 unsigned transaction and return HEX
4640
async function buildUnsignedSolanaTxHex(fromAddress: string, rpcUrl?: string) {
4741
const connection = new Connection(
@@ -69,7 +63,7 @@ async function buildUnsignedSolanaTxHex(fromAddress: string, rpcUrl?: string) {
6963

7064
// Serialize without requiring signatures; then hex-encode
7165
const bytes = unsignedTx.serialize();
72-
return toHex(bytes);
66+
return uint8ArrayToHexString(bytes);
7367
}
7468

7569
// Build an EVM demo tx (send-to-self, 0 value) with a fresh nonce
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
NEXT_PUBLIC_ORGANIZATION_ID="<Turnkey organization ID>"
22
NEXT_PUBLIC_BASE_URL="https://api.turnkey.com"
3+
NEXT_PUBLIC_AUTH_PROXY_BASE_URL="https://authproxy.turnkey.com"
34
NEXT_PUBLIC_AUTH_PROXY_CONFIG_ID="<Auth Proxy Config ID>"
45
NEXT_PUBLIC_RPC_SOL="<Solana Devnet RPC URL>"
56
NEXT_PUBLIC_RPC_ETH="<Ethereum Sepolia RPC URL>"

examples/wallet-auth/without-backend/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ A high-level summary of the user experience and what appears on screen:
1313

1414
Once logged in, access a dashboard with two panels:
1515

16-
**Left:** sign messages and simple demo transactions for both Ethereum and Solana using the **selected** embedded **or** connected wallet. The signing and broadcasting behavior differs slightly depending on wallet type:
16+
**Left:** sign messages and simple testnet demo transactions for both Ethereum (Sepolia testnet) and Solana (Devnet) using the **selected** embedded **or** connected wallet. The signing and broadcasting behavior differs slightly depending on wallet type:
1717

1818
- **Connected wallets**
19-
- Ethereum: delegates to the wallet’s native `signAndSendTransaction` method. Does not require an rpcUrl (the wallet handles broadcasting).
19+
- Ethereum: delegates to the wallet’s native `signAndSendTransaction` method. Does not require an rpcUrl (the external wallet provider handles broadcasting).
2020
- Solana: signs locally with the connected wallet but requires an rpcUrl for broadcasting.
2121

2222
- **Embedded wallets**
@@ -76,6 +76,7 @@ Now open `.env.local` and add the missing environment variables:
7676
- `NEXT_PUBLIC_BASE_URL`
7777
- `NEXT_PUBLIC_ORGANIZATION_ID`
7878
- `NEXT_PUBLIC_AUTH_PROXY_CONFIG_ID`
79+
- `NEXT_PUBLIC_AUTH_PROXY_BASE_URL`
7980
- `NEXT_PUBLIC_RPC_SOL`
8081
- `NEXT_PUBLIC_RPC_ETH`
8182

examples/wallet-auth/without-backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@tailwindcss/postcss": "4.1.13",
1616
"@turnkey/react-wallet-kit": "workspace:*",
1717
"@turnkey/sdk-server": "workspace:*",
18+
"@turnkey/encoding": "workspace:*",
1819
"@types/node": "20.3.1",
1920
"@types/react": "18.2.14",
2021
"@types/react-dom": "18.2.6",

examples/wallet-auth/without-backend/src/app/dashboard/page.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
VersionedTransaction,
2626
clusterApiUrl,
2727
} from "@solana/web3.js";
28+
import { uint8ArrayToHexString } from "@turnkey/encoding";
2829

2930
// ---------- Utils ----------
3031
function safeStringify(x: unknown) {
@@ -35,13 +36,6 @@ function safeStringify(x: unknown) {
3536
);
3637
}
3738

38-
// Uint8Array -> hex
39-
function toHex(u8: Uint8Array) {
40-
return Array.from(u8)
41-
.map((b) => b.toString(16).padStart(2, "0"))
42-
.join("");
43-
}
44-
4539
// Build a Solana v0 unsigned transaction and return HEX
4640
async function buildUnsignedSolanaTxHex(fromAddress: string, rpcUrl?: string) {
4741
const connection = new Connection(
@@ -69,7 +63,7 @@ async function buildUnsignedSolanaTxHex(fromAddress: string, rpcUrl?: string) {
6963

7064
// Serialize without requiring signatures; then hex-encode
7165
const bytes = unsignedTx.serialize();
72-
return toHex(bytes);
66+
return uint8ArrayToHexString(bytes);
7367
}
7468

7569
// Build an EVM demo tx (send-to-self, 0 value) with a fresh nonce

examples/wallet-auth/without-backend/src/app/providers.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export function Providers({ children }: { children: React.ReactNode }) {
3939
const turnkeyConfig: TurnkeyProviderConfig = {
4040
organizationId: process.env.NEXT_PUBLIC_ORGANIZATION_ID!,
4141
authProxyConfigId: process.env.NEXT_PUBLIC_AUTH_PROXY_CONFIG_ID!,
42+
authProxyUrl:
43+
process.env.NEXT_PUBLIC_AUTH_PROXY_BASE_URL ||
44+
"https://authproxy.turnkey.com",
4245
auth: {
4346
methods: {
4447
emailOtpAuthEnabled: false,

0 commit comments

Comments
 (0)