-
Notifications
You must be signed in to change notification settings - Fork 5
feat: social account linking #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luciorubeens
wants to merge
7
commits into
allinbits:main
Choose a base branch
from
luciorubeens:feat/social-network-name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e70244d
feat(social): add social proof linking and verification flow
luciorubeens ea1fbdb
refactor: better ui and github implementation
luciorubeens 26a8603
Merge remote-tracking branch 'origin/main' into feat/social-network-name
luciorubeens b950685
fix: localnet leftover
luciorubeens e3c16eb
feat: polish verification UI
luciorubeens 111d559
chore: test token
luciorubeens 98dbfe7
fix: lint failing
luciorubeens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { and, eq, inArray } from 'drizzle-orm'; | ||
|
|
||
| import { getDatabase } from '../../drizzle/db'; | ||
| import { SocialLinksTable } from '../../drizzle/schema'; | ||
| import { SOCIAL_LINK_STATUS } from '../types/social-link'; | ||
|
|
||
| export type SocialByAddress = Record<string, typeof SocialLinksTable.$inferSelect[]>; | ||
|
|
||
| /** | ||
| * Fetch verified social links for a list of addresses. | ||
| * Returns a Record keyed by address. Only includes addresses that have at least one verified link. | ||
| * Returns an empty object if addresses is empty. | ||
| */ | ||
| export async function fetchSocialByAddresses(addresses: string[]): Promise<SocialByAddress> { | ||
| if (addresses.length === 0) return {}; | ||
|
|
||
| const unique = [...new Set(addresses)]; | ||
|
|
||
| const links = await getDatabase() | ||
| .select() | ||
| .from(SocialLinksTable) | ||
| .where( | ||
| and( | ||
| inArray(SocialLinksTable.address, unique), | ||
| eq(SocialLinksTable.status, SOCIAL_LINK_STATUS.VERIFIED), | ||
| ), | ||
| ); | ||
|
|
||
| const result: SocialByAddress = {}; | ||
| for (const link of links) { | ||
| if (!result[link.address]) result[link.address] = []; | ||
| result[link.address].push(link); | ||
| } | ||
| return result; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||
| import type { Gets } from '@atomone/dither-api-types'; | ||||||||||
|
|
||||||||||
| import { and, eq } from 'drizzle-orm'; | ||||||||||
|
|
||||||||||
| import { getDatabase } from '../../drizzle/db'; | ||||||||||
| import { SocialLinksTable } from '../../drizzle/schema'; | ||||||||||
| import { verifyJWT } from '../shared/jwt'; | ||||||||||
| import { SOCIAL_LINK_STATUS } from '../types/social-link'; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * GET /social/links?address=... | ||||||||||
| * | ||||||||||
| * Public callers (no auth): returns only verified links. | ||||||||||
| * Owner (valid JWT cookie matching the requested address): returns all links | ||||||||||
| */ | ||||||||||
| export async function SocialLinks(query: Gets.SocialLinksQuery, authToken: string | undefined) { | ||||||||||
| if (!query.address || query.address.length !== 44) { | ||||||||||
| return { status: 400, error: 'Valid address is required' }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const address = query.address.toLowerCase(); | ||||||||||
|
|
||||||||||
| // Determine if the caller is the owner of this address | ||||||||||
| let isOwner = false; | ||||||||||
| if (authToken) { | ||||||||||
| const tokenAddress = await verifyJWT(authToken); | ||||||||||
| if (tokenAddress && tokenAddress.toLowerCase() === address) { | ||||||||||
| isOwner = true; | ||||||||||
| } | ||||||||||
|
Comment on lines
+27
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe?
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| try { | ||||||||||
| if (isOwner) { | ||||||||||
| // Owner: all statuses, include error_reason | ||||||||||
| const rows = await getDatabase() | ||||||||||
| .select({ | ||||||||||
| id: SocialLinksTable.id, | ||||||||||
| handle: SocialLinksTable.handle, | ||||||||||
| platform: SocialLinksTable.platform, | ||||||||||
| status: SocialLinksTable.status, | ||||||||||
| error_reason: SocialLinksTable.error_reason, | ||||||||||
| proof_url: SocialLinksTable.proof_url, | ||||||||||
| created_at: SocialLinksTable.created_at, | ||||||||||
| }) | ||||||||||
| .from(SocialLinksTable) | ||||||||||
| .where(eq(SocialLinksTable.address, address)) | ||||||||||
| .orderBy(SocialLinksTable.created_at); | ||||||||||
|
|
||||||||||
| return { status: 200, rows }; | ||||||||||
| } else { | ||||||||||
| // Public: verified only, no error_reason | ||||||||||
| const rows = await getDatabase() | ||||||||||
| .select({ | ||||||||||
| id: SocialLinksTable.id, | ||||||||||
| handle: SocialLinksTable.handle, | ||||||||||
| platform: SocialLinksTable.platform, | ||||||||||
| status: SocialLinksTable.status, | ||||||||||
| created_at: SocialLinksTable.created_at, | ||||||||||
| }) | ||||||||||
| .from(SocialLinksTable) | ||||||||||
| .where( | ||||||||||
| and( | ||||||||||
| eq(SocialLinksTable.address, address), | ||||||||||
| eq(SocialLinksTable.status, SOCIAL_LINK_STATUS.VERIFIED), | ||||||||||
| ), | ||||||||||
| ) | ||||||||||
| .orderBy(SocialLinksTable.created_at); | ||||||||||
|
|
||||||||||
| return { status: 200, rows }; | ||||||||||
| } | ||||||||||
| } catch (err) { | ||||||||||
| console.error(err); | ||||||||||
| return { status: 400, error: 'failed to read data from database' }; | ||||||||||
| } | ||||||||||
| } | ||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import type { Gets } from '@atomone/dither-api-types'; | ||
|
|
||
| import { and, desc, eq, sql } from 'drizzle-orm'; | ||
|
|
||
| import { getDatabase } from '../../drizzle/db'; | ||
| import { SocialLinksTable } from '../../drizzle/schema'; | ||
| import { SOCIAL_LINK_STATUS } from '../types/social-link'; | ||
|
|
||
| const statementGetSocialResolve = getDatabase() | ||
| .select({ | ||
| address: SocialLinksTable.address, | ||
| handle: SocialLinksTable.handle, | ||
| platform: SocialLinksTable.platform, | ||
| created_at: SocialLinksTable.created_at, | ||
| }) | ||
| .from(SocialLinksTable) | ||
| .where( | ||
| and( | ||
| eq(SocialLinksTable.handle, sql.placeholder('handle')), | ||
| eq(SocialLinksTable.status, SOCIAL_LINK_STATUS.VERIFIED), | ||
| ), | ||
| ) | ||
| .orderBy(desc(SocialLinksTable.created_at)) | ||
| .limit(1) | ||
| .prepare('stmnt_get_social_resolve'); | ||
|
|
||
| /** | ||
| * GET /social/resolve?handle=alice@x | ||
| * | ||
| * Returns the wallet address associated with a verified social handle. | ||
| * Returns 404 if no verified link is found for the handle. | ||
| * If multiple verified entries exist (re-verification history), returns the most recent. | ||
| */ | ||
| export async function SocialResolve(query: Gets.SocialResolveQuery) { | ||
| if (!query.handle || !query.handle.includes('@')) { | ||
| return { status: 400, error: 'Valid handle in format "username@platform" is required' }; | ||
| } | ||
|
|
||
| const handle = query.handle.toLowerCase(); | ||
|
|
||
| try { | ||
| const [row] = await statementGetSocialResolve.execute({ handle }); | ||
|
|
||
| if (!row) { | ||
| return { status: 404, error: 'No verified link found for this handle' }; | ||
| } | ||
|
|
||
| return { status: 200, address: row.address, handle: row.handle, platform: row.platform }; | ||
| } catch (err) { | ||
| console.error(err); | ||
| return { status: 400, error: 'failed to read data from database' }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.