-
Notifications
You must be signed in to change notification settings - Fork 380
feat(clerk-js,clerk-react): Support Base authentication #6556
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
Changes from all commits
b262fc3
752b581
2350b05
dddefe7
59be282
582af96
2ba3e39
41eeddd
1732dca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
'@clerk/shared': minor | ||
'@clerk/clerk-react': minor | ||
'@clerk/types': minor | ||
--- | ||
|
||
Added support for authentication with Base |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
{ | ||
"files": [ | ||
{ "path": "./dist/clerk.js", "maxSize": "631KB" }, | ||
{ "path": "./dist/clerk.js", "maxSize": "818KB" }, | ||
{ "path": "./dist/clerk.browser.js", "maxSize": "78KB" }, | ||
{ "path": "./dist/clerk.legacy.browser.js", "maxSize": "120KB" }, | ||
{ "path": "./dist/clerk.headless*.js", "maxSize": "61KB" }, | ||
{ "path": "./dist/ui-common*.js", "maxSize": "117.1KB" }, | ||
{ "path": "./dist/ui-common*.legacy.*.js", "maxSize": "118KB" }, | ||
{ "path": "./dist/vendors*.js", "maxSize": "43.78KB" }, | ||
{ "path": "./dist/vendors*.js", "maxSize": "45KB" }, | ||
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. @jacekradko Is this expected ? Maybe something belongs to 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. I can dig into it, but yeah it's gotta be another transitive dependency of a transitive dependency type of thing 😂 |
||
{ "path": "./dist/coinbase*.js", "maxSize": "38KB" }, | ||
{ "path": "./dist/stripe-vendors*.js", "maxSize": "1KB" }, | ||
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,11 @@ const common = ({ mode, variant, disableRHC = false }) => { | |
name: 'zxcvbn-common', | ||
chunks: 'all', | ||
}, | ||
baseAccountSDKVendor: { | ||
test: /[\\/]node_modules[\\/](@base-org\/account|@noble\/curves|abitype|ox|preact|eventemitter3|viem|zustand)[\\/]/, | ||
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. This is needed to avoid bundling |
||
name: 'base-account-sdk', | ||
chunks: 'all', | ||
}, | ||
coinbaseWalletSDKVendor: { | ||
test: /[\\/]node_modules[\\/](@coinbase\/wallet-sdk|preact|eventemitter3|@noble\/hashes)[\\/]/, | ||
name: 'coinbase-wallet-sdk', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import type { | |
__internal_UserVerificationModalProps, | ||
APIKeysNamespace, | ||
APIKeysProps, | ||
AuthenticateWithBaseParams, | ||
AuthenticateWithCoinbaseWalletParams, | ||
AuthenticateWithGoogleOneTapParams, | ||
AuthenticateWithMetamaskParams, | ||
|
@@ -42,6 +43,7 @@ import type { | |
EnvironmentJSON, | ||
EnvironmentJSONSnapshot, | ||
EnvironmentResource, | ||
GenerateSignatureParams, | ||
GoogleOneTapProps, | ||
HandleEmailLinkVerificationParams, | ||
HandleOAuthCallbackParams, | ||
|
@@ -100,6 +102,7 @@ import { | |
disabledAPIKeysFeature, | ||
disabledOrganizationsFeature, | ||
errorThrower, | ||
generateSignatureWithBase, | ||
generateSignatureWithCoinbaseWallet, | ||
generateSignatureWithMetamask, | ||
generateSignatureWithOKXWallet, | ||
|
@@ -2148,6 +2151,13 @@ export class Clerk implements ClerkInterface { | |
}); | ||
}; | ||
|
||
public authenticateWithBase = async (props: AuthenticateWithBaseParams = {}): Promise<void> => { | ||
await this.authenticateWithWeb3({ | ||
...props, | ||
strategy: 'web3_base_signature', | ||
}); | ||
}; | ||
|
||
public authenticateWithOKXWallet = async (props: AuthenticateWithOKXWalletParams = {}): Promise<void> => { | ||
await this.authenticateWithWeb3({ | ||
...props, | ||
|
@@ -2172,12 +2182,21 @@ export class Clerk implements ClerkInterface { | |
|
||
const provider = strategy.replace('web3_', '').replace('_signature', '') as Web3Provider; | ||
const identifier = await getWeb3Identifier({ provider }); | ||
const generateSignature = | ||
provider === 'metamask' | ||
? generateSignatureWithMetamask | ||
: provider === 'coinbase_wallet' | ||
? generateSignatureWithCoinbaseWallet | ||
: generateSignatureWithOKXWallet; | ||
let generateSignature: (params: GenerateSignatureParams) => Promise<string>; | ||
switch (provider) { | ||
case 'metamask': | ||
generateSignature = generateSignatureWithMetamask; | ||
break; | ||
case 'base': | ||
generateSignature = generateSignatureWithBase; | ||
break; | ||
case 'coinbase_wallet': | ||
generateSignature = generateSignatureWithCoinbaseWallet; | ||
break; | ||
default: | ||
generateSignature = generateSignatureWithOKXWallet; | ||
break; | ||
Comment on lines
+2196
to
+2198
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. I don't think we should be falling back to OKXWallet here, but that is the pre-existing functionality |
||
} | ||
|
||
const makeNavigate = (to: string) => () => | ||
customNavigate && typeof customNavigate === 'function' ? customNavigate(to) : this.navigate(to); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,11 @@ import type { | |
} from '@clerk/types'; | ||
|
||
import { | ||
generateSignatureWithBase, | ||
generateSignatureWithCoinbaseWallet, | ||
generateSignatureWithMetamask, | ||
generateSignatureWithOKXWallet, | ||
getBaseIdentifier, | ||
getCoinbaseWalletIdentifier, | ||
getMetamaskIdentifier, | ||
getOKXWalletIdentifier, | ||
|
@@ -143,11 +145,8 @@ export class SignIn extends BaseResource implements SignInResource { | |
} as PhoneCodeConfig; | ||
break; | ||
case 'web3_metamask_signature': | ||
config = { web3WalletId: factor.web3WalletId } as Web3SignatureConfig; | ||
break; | ||
case 'web3_base_signature': | ||
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. Did a small refactor here to remove the copy-pasta |
||
case 'web3_coinbase_wallet_signature': | ||
config = { web3WalletId: factor.web3WalletId } as Web3SignatureConfig; | ||
break; | ||
case 'web3_okx_wallet_signature': | ||
config = { web3WalletId: factor.web3WalletId } as Web3SignatureConfig; | ||
break; | ||
|
@@ -361,6 +360,15 @@ export class SignIn extends BaseResource implements SignInResource { | |
}); | ||
}; | ||
|
||
public authenticateWithBase = async (): Promise<SignInResource> => { | ||
const identifier = await getBaseIdentifier(); | ||
return this.authenticateWithWeb3({ | ||
identifier, | ||
generateSignature: generateSignatureWithBase, | ||
strategy: 'web3_base_signature', | ||
}); | ||
}; | ||
|
||
public authenticateWithOKXWallet = async (): Promise<SignInResource> => { | ||
const identifier = await getOKXWalletIdentifier(); | ||
return this.authenticateWithWeb3({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ export async function getWeb3Identifier(params: GetWeb3IdentifierParams): Promis | |
} | ||
|
||
const identifiers = await ethereum.request({ method: 'eth_requestAccounts' }); | ||
// @ts-ignore | ||
// @ts-ignore -- Provider SDKs may return unknown shape; use first address if present | ||
return (identifiers && identifiers[0]) || ''; | ||
} | ||
|
||
|
@@ -58,6 +58,10 @@ export async function getOKXWalletIdentifier(): Promise<string> { | |
return await getWeb3Identifier({ provider: 'okx_wallet' }); | ||
} | ||
|
||
export async function getBaseIdentifier(): Promise<string> { | ||
return await getWeb3Identifier({ provider: 'base' }); | ||
} | ||
|
||
type GenerateSignatureParams = { | ||
identifier: string; | ||
nonce: string; | ||
|
@@ -75,6 +79,10 @@ export async function generateSignatureWithOKXWallet(params: GenerateSignaturePa | |
return await generateWeb3Signature({ ...params, provider: 'okx_wallet' }); | ||
} | ||
|
||
export async function generateSignatureWithBase(params: GenerateSignatureParams): Promise<string> { | ||
return await generateWeb3Signature({ ...params, provider: 'base' }); | ||
} | ||
|
||
async function getEthereumProvider(provider: Web3Provider) { | ||
if (provider === 'coinbase_wallet') { | ||
if (__BUILD_DISABLE_RHC__) { | ||
|
@@ -90,7 +98,27 @@ async function getEthereumProvider(provider: Web3Provider) { | |
}); | ||
return sdk.getProvider(); | ||
} | ||
if (provider === 'base') { | ||
if (__BUILD_DISABLE_RHC__) { | ||
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. Cannot include this in the no-remote-hosted-code builds |
||
clerkUnsupportedEnvironmentWarning('Base'); | ||
return null; | ||
} | ||
|
||
try { | ||
const createBaseAccountSDK = await import('@base-org/account').then(mod => mod.createBaseAccountSDK); | ||
|
||
const sdk = createBaseAccountSDK({ | ||
appName: | ||
(typeof window !== 'undefined' && | ||
(window.Clerk as any)?.__unstable__environment?.displayConfig?.applicationName) || | ||
(typeof document !== 'undefined' && document.title) || | ||
'Web3 Application', | ||
}); | ||
return sdk.getProvider(); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
const injectedWeb3Providers = getInjectedWeb3Providers(); | ||
return injectedWeb3Providers.get(provider); | ||
return getInjectedWeb3Providers().get(provider); | ||
} |
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.
Yep.
@base-org/account
is pretty massive