Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/chilly-shrimps-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@clerk/clerk-js": minor
"@clerk/clerk-react": minor
"@clerk/types": minor
---

Add support for the Coinbase Wallet web3 provider and authentication strategy. The Coinbase Wallet provider handles both Coinbase Wallet extension and Smart Wallet
106 changes: 103 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ "path": "./dist/clerk.headless.js", "maxSize": "43kB" },
{ "path": "./dist/ui-common*.js", "maxSize": "85KB" },
{ "path": "./dist/vendors*.js", "maxSize": "70KB" },
{ "path": "./dist/coinbase*.js", "maxSize": "58KB" },
{ "path": "./dist/createorganization*.js", "maxSize": "5KB" },
{ "path": "./dist/impersonationfab*.js", "maxSize": "5KB" },
{ "path": "./dist/organizationprofile*.js", "maxSize": "12KB" },
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@clerk/localizations": "2.8.0",
"@clerk/shared": "2.6.1",
"@clerk/types": "4.18.0",
"@coinbase/wallet-sdk": "4.0.4",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: For now this is lazy loaded with the help of @panteliselef

"@emotion/cache": "11.11.0",
"@emotion/react": "11.11.1",
"@floating-ui/react": "0.25.4",
Expand Down
13 changes: 12 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
__experimental_UserVerificationProps,
ActiveSessionResource,
AuthenticateWithCoinbaseParams,
AuthenticateWithCoinbaseWalletParams,
AuthenticateWithGoogleOneTapParams,
AuthenticateWithMetamaskParams,
Clerk as ClerkInterface,
Expand Down Expand Up @@ -75,6 +76,7 @@ import {
disabledOrganizationsFeature,
errorThrower,
generateSignatureWithCoinbase,
generateSignatureWithCoinbaseWallet,
generateSignatureWithMetamask,
getClerkQueryParam,
getWeb3Identifier,
Expand Down Expand Up @@ -1403,6 +1405,10 @@ export class Clerk implements ClerkInterface {
await this.authenticateWithWeb3({ ...props, strategy: 'web3_coinbase_signature' });
};

public authenticateWithCoinbaseWallet = async (props: AuthenticateWithCoinbaseWalletParams = {}): Promise<void> => {
await this.authenticateWithWeb3({ ...props, strategy: 'web3_coinbase_wallet_signature' });
};

public authenticateWithWeb3 = async ({
redirectUrl,
signUpContinueUrl,
Expand All @@ -1415,7 +1421,12 @@ export class Clerk implements ClerkInterface {
}
const provider = strategy.replace('web3_', '').replace('_signature', '') as Web3Provider;
const identifier = await getWeb3Identifier({ provider });
const generateSignature = provider === 'metamask' ? generateSignatureWithMetamask : generateSignatureWithCoinbase;
const generateSignature =
provider === 'metamask'
? generateSignatureWithMetamask
: provider === 'coinbase'
? generateSignatureWithCoinbase
: generateSignatureWithCoinbaseWallet;
Comment on lines +1424 to +1429
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up PR this will become simpler as we are dropping the generateSignatureWithCoinbase ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, on the next PR we are dropping the Coinbase provider in favor of the new Coinbase Wallet

const navigate = (to: string) =>
customNavigate && typeof customNavigate === 'function' ? customNavigate(to) : this.navigate(to);

Expand Down
14 changes: 14 additions & 0 deletions packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import type {

import {
generateSignatureWithCoinbase,
generateSignatureWithCoinbaseWallet,
generateSignatureWithMetamask,
getCoinbaseIdentifier,
getCoinbaseWalletIdentifier,
getMetamaskIdentifier,
windowNavigate,
} from '../../utils';
Expand Down Expand Up @@ -117,6 +119,9 @@ export class SignIn extends BaseResource implements SignInResource {
case 'web3_coinbase_signature':
config = { web3WalletId: factor.web3WalletId } as Web3SignatureConfig;
break;
case 'web3_coinbase_wallet_signature':
config = { web3WalletId: factor.web3WalletId } as Web3SignatureConfig;
break;
case 'reset_password_phone_code':
config = { phoneNumberId: factor.phoneNumberId } as ResetPasswordPhoneCodeFactorConfig;
break;
Expand Down Expand Up @@ -285,6 +290,15 @@ export class SignIn extends BaseResource implements SignInResource {
});
};

public authenticateWithCoinbaseWallet = async (): Promise<SignInResource> => {
const identifier = await getCoinbaseWalletIdentifier();
return this.authenticateWithWeb3({
identifier,
generateSignature: generateSignatureWithCoinbaseWallet,
strategy: 'web3_coinbase_wallet_signature',
});
};

public authenticateWithPasskey = async (params?: AuthenticateWithPasskeyParams): Promise<SignInResource> => {
const { flow } = params || {};

Expand Down
14 changes: 14 additions & 0 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import type {

import {
generateSignatureWithCoinbase,
generateSignatureWithCoinbaseWallet,
generateSignatureWithMetamask,
getCoinbaseIdentifier,
getCoinbaseWalletIdentifier,
getMetamaskIdentifier,
windowNavigate,
} from '../../utils';
Expand Down Expand Up @@ -231,6 +233,18 @@ export class SignUp extends BaseResource implements SignUpResource {
});
};

public authenticateWithCoinbaseWallet = async (
params?: SignUpAuthenticateWithWeb3Params,
): Promise<SignUpResource> => {
const identifier = await getCoinbaseWalletIdentifier();
return this.authenticateWithWeb3({
identifier,
generateSignature: generateSignatureWithCoinbaseWallet,
unsafeMetadata: params?.unsafeMetadata,
strategy: 'web3_coinbase_wallet_signature',
});
};

public authenticateWithRedirect = async ({
redirectUrl,
redirectUrlComplete,
Expand Down
4 changes: 4 additions & 0 deletions packages/clerk-js/src/ui/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const WEB3_PROVIDERS: Web3Providers = Object.freeze({
id: 'coinbase',
name: 'Coinbase Wallet',
},
coinbase_wallet: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 SW = smart wallet

Suggested change
coinbase_wallet: {
coinbase_sw: {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coinbase prefer to use the term Coinbase Wallet rather than Coinbase Smart Wallet

id: 'coinbase_wallet',
name: 'Coinbase Wallet',
},
});

export function getWeb3ProviderData(name: Web3Provider): Web3ProviderData | undefined | null {
Expand Down
8 changes: 5 additions & 3 deletions packages/clerk-js/src/utils/injectedWeb3Providers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Web3Provider } from '@clerk/types';
import type { CoinbaseWeb3Provider, MetamaskWeb3Provider } from '@clerk/types';

//https://eips.ethereum.org/EIPS/eip-6963

interface EIP6963ProviderInfo {
Expand Down Expand Up @@ -26,10 +27,11 @@ interface EIP6963ProviderDetail {
}

type EIP6963AnnounceProviderEvent = CustomEvent;
type InjectedWeb3Provider = MetamaskWeb3Provider | CoinbaseWeb3Provider;

class InjectedWeb3Providers {
#providers: EIP6963ProviderDetail[] = [];
#providerIdMap: Record<Web3Provider, string> = {
#providerIdMap: Record<InjectedWeb3Provider, string> = {
coinbase: 'Coinbase Wallet',
metamask: 'MetaMask',
} as const;
Expand All @@ -42,7 +44,7 @@ class InjectedWeb3Providers {
window.dispatchEvent(new Event('eip6963:requestProvider'));
}

get = (provider: Web3Provider) => {
get = (provider: InjectedWeb3Provider) => {
return this.#providers.find(p => p.info.name === this.#providerIdMap[provider])?.provider;
};

Expand Down
Loading