|
| 1 | +# Profiles Reference |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The [Profiles feature](/identity/smart-wallet/concepts/features/optional/profiles) allows developers to request personal information from Smart Wallet users during a |
| 6 | +transaction. This is useful for applications that need to collect user data like email addresses, |
| 7 | +physical addresses, phone numbers, and names. |
| 8 | + |
| 9 | +This is not a guide on how to implement Profiles, but rather a reference for the API endpoints and data formats. |
| 10 | +If you are looking for a guide on how to implement Profiles, please see the [Profiles guide](/identity/smart-wallet/guides/profiles). |
| 11 | + |
| 12 | +## Supported Data Types |
| 13 | + |
| 14 | +The following data types are supported for profile requests: |
| 15 | + |
| 16 | +```typescript |
| 17 | +type DataCallbackType = |
| 18 | + | 'email' // Email address |
| 19 | + | 'phoneNumber' // Phone number with country code |
| 20 | + | 'physicalAddress' // Physical address for shipping |
| 21 | + | 'name' // User's full name |
| 22 | + | 'onchainAddress' // On-chain wallet address |
| 23 | + |
| 24 | +// Full type definitions for requests and capability |
| 25 | + |
| 26 | +type DataCallbackRequestType = { |
| 27 | + optional?: boolean; |
| 28 | + type: DataCallbackType; |
| 29 | +} |
| 30 | + |
| 31 | +type DataCallbackCapability = { |
| 32 | + requests: DataCallbackRequestType[]; |
| 33 | + callbackURL?: string; |
| 34 | +} |
| 35 | +``` |
| 36 | +
|
| 37 | +## API Reference |
| 38 | +
|
| 39 | +### Request Format |
| 40 | +
|
| 41 | +To request profile data, include the `dataCallback` capability in your [`wallet_sendCalls`](/identity/smart-wallet/technical-reference/sdk/CoinbaseWalletProvider/wallet_sendCalls) request: |
| 42 | +
|
| 43 | +```typescript |
| 44 | +const response = await provider.request({ |
| 45 | + method: "wallet_sendCalls", |
| 46 | + params: [{ |
| 47 | + version: "1.0", |
| 48 | + chainId: numberToHex(84532), // Base Sepolia |
| 49 | + calls: [ |
| 50 | + // Your transaction calls here |
| 51 | + ], |
| 52 | + capabilities: { |
| 53 | + dataCallback: { |
| 54 | + requests: [ |
| 55 | + { |
| 56 | + type: "email", |
| 57 | + optional: false, // Whether this field is optional |
| 58 | + }, |
| 59 | + { |
| 60 | + type: "physicalAddress", |
| 61 | + optional: true, |
| 62 | + }, |
| 63 | + // Add more requests as needed |
| 64 | + ], |
| 65 | + callbackURL: "https://your-api.com/validate", // Your validation endpoint |
| 66 | + }, |
| 67 | + }, |
| 68 | + }], |
| 69 | +}); |
| 70 | +``` |
| 71 | + |
| 72 | +### Callback API |
| 73 | + |
| 74 | +Your callback API will receive a POST request with the following structure: |
| 75 | + |
| 76 | +```typescript |
| 77 | +// Request body structure |
| 78 | +{ |
| 79 | + calls: { |
| 80 | + to: string; |
| 81 | + data: string; |
| 82 | + }[]; |
| 83 | + chainId: string; |
| 84 | + version: string; |
| 85 | + capabilities: { |
| 86 | + dataCallback: { |
| 87 | + requestedInfo: { |
| 88 | + email?: string; |
| 89 | + phoneNumber?: { |
| 90 | + number: string; |
| 91 | + country: string; |
| 92 | + isPrimary: boolean; |
| 93 | + }; |
| 94 | + physicalAddress?: { |
| 95 | + physicalAddress: { |
| 96 | + address1: string; |
| 97 | + address2?: string; |
| 98 | + city: string; |
| 99 | + state: string; |
| 100 | + postalCode: string; |
| 101 | + countryCode: string; |
| 102 | + name?: { |
| 103 | + firstName: string; |
| 104 | + familyName: string; |
| 105 | + }; |
| 106 | + }; |
| 107 | + isPrimary: boolean; |
| 108 | + }; |
| 109 | + name?: { |
| 110 | + firstName: string; |
| 111 | + familyName: string; |
| 112 | + }; |
| 113 | + onchainAddress?: string; |
| 114 | + }; |
| 115 | + }; |
| 116 | + }; |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### Response Format |
| 121 | + |
| 122 | +Your callback API must respond with one of two formats: |
| 123 | + |
| 124 | +1. **Success Response** - Return the calls the user will end up submitting. |
| 125 | + They can be the same calls or new ones, but they must be present. |
| 126 | + You can change all capabilities (e.g. switching Paymaster if calls happen on a different chain) except the data callback capability, which must remain present. |
| 127 | + |
| 128 | +```typescript |
| 129 | +{ |
| 130 | + calls: { |
| 131 | + to: string; |
| 132 | + data: string; |
| 133 | + }[]; |
| 134 | + chainId: string; |
| 135 | + version: string; |
| 136 | + capabilities: { |
| 137 | + dataCallback: { |
| 138 | + // Original or updated dataCallback capability |
| 139 | + }; |
| 140 | + // Other capabilities can be changed as needed |
| 141 | + }; |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +2. **Error Response** - Return validation errors to prompt the user to correct their information: |
| 146 | + |
| 147 | +```typescript |
| 148 | +{ |
| 149 | + errors: { |
| 150 | + email?: string; |
| 151 | + phoneNumber?: { |
| 152 | + number?: string; |
| 153 | + country?: string; |
| 154 | + }; |
| 155 | + physicalAddress?: { |
| 156 | + address1?: string; |
| 157 | + address2?: string; |
| 158 | + city?: string; |
| 159 | + state?: string; |
| 160 | + postalCode?: string; |
| 161 | + countryCode?: string; |
| 162 | + }; |
| 163 | + name?: { |
| 164 | + firstName?: string; |
| 165 | + familyName?: string; |
| 166 | + }; |
| 167 | + onchainAddress?: string; |
| 168 | + }; |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +## Example Implementation |
| 173 | + |
| 174 | +Here's a complete example of a validation API endpoint: |
| 175 | + |
| 176 | +```typescript |
| 177 | +export async function POST(request: Request) { |
| 178 | + const requestData = await request.json(); |
| 179 | + |
| 180 | + try { |
| 181 | + const { requestedInfo } = requestData.capabilities.dataCallback; |
| 182 | + const errors = {}; |
| 183 | + |
| 184 | + // Validate email |
| 185 | + if (requestedInfo.email && requestedInfo.email.endsWith("@example.com")) { |
| 186 | + errors.email = "Example.com emails are not allowed"; |
| 187 | + } |
| 188 | + |
| 189 | + // Validate physical address |
| 190 | + if (requestedInfo.physicalAddress) { |
| 191 | + const addr = requestedInfo.physicalAddress.physicalAddress; |
| 192 | + if (addr.postalCode && addr.postalCode.length < 5) { |
| 193 | + if (!errors.physicalAddress) errors.physicalAddress = {}; |
| 194 | + errors.physicalAddress.postalCode = "Invalid postal code"; |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + // Return errors if any found |
| 199 | + if (Object.keys(errors).length > 0) { |
| 200 | + return Response.json({ errors }); |
| 201 | + } |
| 202 | + |
| 203 | + // Success - return original calls |
| 204 | + return Response.json({ |
| 205 | + calls: requestData.calls, |
| 206 | + chainId: requestData.chainId, |
| 207 | + version: requestData.version, |
| 208 | + capabilities: requestData.capabilities |
| 209 | + }); |
| 210 | + |
| 211 | + } catch (error) { |
| 212 | + return Response.json({ |
| 213 | + errors: { server: "Server error validating data" } |
| 214 | + }); |
| 215 | + } |
| 216 | +} |
| 217 | +``` |
| 218 | + |
| 219 | +## Important Notes |
| 220 | + |
| 221 | +1. **HTTPS Required**: Your callback URL must use HTTPS, even for local development. Use a service like ngrok for testing. |
| 222 | + |
| 223 | +2. **Return Original or New Calls**: You MUST return the original calls or new calls in your success response. If you don't, the wallet will return an error. |
| 224 | + |
| 225 | +3. **Optional Fields**: You can make any requested field optional by setting `optional: true` in the request. Optional fields will be marked as such in the Smart Wallet interface. |
| 226 | + |
| 227 | +4. **Privacy**: Users always have full control over their data. They can choose to share or withhold any information, and they're clearly shown what data you're requesting. |
| 228 | + |
| 229 | +5. **Validation**: Smart Wallet performs basic validation before sending data to your callback URL. This includes checking that emails are valid and addresses are properly formatted. |
0 commit comments