
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
@starknet-foundation/starkex-auth
Advanced tools
First, create a new React app:
npx create-react-app my-react-app
or with Vite:
npx init vite@latest my-react-app --template react
Then, install the package in your project directory:
With Yarn:
yarn add @starknet-foundation/starkex-auth
With pnpm:
pnpm add @starknet-foundation/starkex-auth
With npm:
npm install @starknet-foundation/starkex-auth
There are 2 types of authentication flow components: StarkExWalletAuth
and StarkExBasicAuth
.
StarkExWalletAuth
- This flow is used when the user is signing in with a StarkEx wallet.
StarkExBasicAuth
- This flow is used when the user is signing in with a username and password.
import {StarkExClientApp, StarkExWalletAuth} from '@starknet-foundation/starkex-auth';
function WalletApp() {
return (
<StarkExWalletAuth
onConnectWalletClick={() => {
// Show wallet modal
}}
/>
);
}
import {StarkExClientApp, StarkExWalletAuth} from '@starknet-foundation/starkex-auth';
function App() {
return (
<StarkExWalletAuth
connectWalletText="Click me"
connectWalletProps={{isDisabled: true, isLoading: false}}
onConnectWalletClick={() => {
// Show wallet modal
}}
/>
);
}
onConnectWalletClick: () => void
- Function that is called when the user clicks the connect wallet button.
connectWalletText: string
- The text that is displayed on the connect wallet button.
connectWalletProps: ButtonProps
- Possible props to pass to the connect wallet button.
import {StarkExBasicAuth, StarkExClientApp} from '@starknet-foundation/starkex-auth';
function BasicApp() {
return (
<StarkExBasicAuth
onSignInClick={() => {
// Sign in logic here
}}
/>
);
}
import {StarkExBasicAuth, StarkExClientApp} from '@starknet-foundation/starkex-auth';
function App() {
return (
<StarkExBasicAuth
usernameLabel="Email"
usernamePlaceholder="Enter your email"
usernameError={false}
usernameErrorMsg="Email is invalid"
onUsernameChange={username => {
// Username change logic here
}}
passwordLabel="Password"
passwordPlaceholder="Enter your password"
passwordError={false}
passwordErrorMsg="Password is invalid"
onPasswordChange={password => {
// Password change logic here
}}
forgotPasswordLabel="Forgot password?"
onForgotPasswordClick={username => {
// Forgot password logic here
}}
signInLabel="Sign In"
onSignInClick={async (username, password) => {
// Sign in logic here
}}
/>
);
}
onSignInClick: (username: string, password: string) => void
- Function that is called when the user clicks the sign in
button.
The StarkExAuthProvider
component is a React Context Provider that provides the StarkExAuthContext
to all of its
children.
Use the hook useStarkExAuthContext()
to access the context.
import {
StarkExAuthProvider,
StarkExClientApp,
StarkExWalletAuth,
useStarkExAuthContext
} from '@starknet-foundation/starkex-auth';
function App() {
return (
<StarkExAuthProvider appId={StarkExClientApp.RHINO} redirectUrl="https://provisions-portal.com">
...
</StarkExAuthProvider>
);
}
appId
- The StarkEx application ID. This is used to identify the application that the user is signing in to.
Possible values are:
export enum StarkExClientApp {
IMMUTABLE = 'immutablex',
DYDX = 'dydx',
SORARE = 'sorare',
RHINO = 'rhinofi'
}
redirectUrl
- The URL that the user will be redirected to after signing in. As a rule of thumb, this URL
should be the Starknet Provisions website. Please contact us to receive the correct URL based on the environment. For
testing purposes, you can use any URL.
StarkExAuthProvider
with StarkExWalletAuth
:StarkExAuthProvider
component and wrap your app with it.StarkExWalletAuth
component and add it to your app.import {
StarkExAuthProvider,
StarkExClientApp,
StarkExWalletAuth,
useStarkExAuthContext
} from '@starknet-foundation/starkex-auth';
function App() {
return (
<StarkExAuthProvider appId={StarkExClientApp.RHINO} redirectUrl="https://provisions-portal.com">
<WalletApp />
</StarkExAuthProvider>
);
}
function WalletApp() {
const {sigParams, redirect} = useStarkExAuthContext();
const [account, setAccount] = useState('');
// After the user connects their wallet
useEffect(() => {
async function signAndRedirect() {
let sig = null;
// Get stark key from wallet
const starkKey = await getStarkKeyFromWallet();
if (Array.isArray(sigParams)) {
// Sign stark key with message params
sig = await sign(starkKey, sigParams);
}
// Redirect to provisions website
redirect({starkKey, identity: account, sig});
}
if (account) {
signAndRedirect();
}
}, [account]);
return (
<StarkExWalletAuth
onConnectWalletClick={() => {
// Show wallet modal
}}
/>
);
}
StarkExAuthProvider
with StarkExBasicAuth
:StarkExAuthProvider
component and wrap your app with it.StarkExBasicAuth
component and add it to your app.import {
StarkExAuthProvider,
StarkExBasicAuth,
StarkExClientApp,
useStarkExAuthContext
} from '@starknet-foundation/starkex-auth';
function App() {
return (
<StarkExAuthProvider
appId={StarkExClientApp.SORARE}
redirectUrl="https://provisions-portal.com"
>
<BasicApp />
</StarkExAuthProvider>
);
}
function BasicApp() {
const {sigParams, redirect} = useStarkExAuthContext();
return (
<StarkExBasicAuth
onSignInClick={async (username, password) => {
let sig = null;
// Get stark key from wallet
const starkKey = await getStarkKey(username, password);
if (Array.isArray(sigParams)) {
// Sign stark key with message params
sig = await sign(starkKey, sigParams);
}
// Redirect to provisions website
redirect({starkKey, identity: username, sig});
}}
/>
);
}
Note: You must use useStarkExAuthContext
inside a nested component of StarkExAuthProvider
for it to work.
import {useStarkExAuthContext} from '@starknet-foundation/starkex-auth';
function MyComponent() {
const {sigParams} = useStarkExAuthContext();
return (
<div>
<pre>Signature params: {sigParams}</pre>
</div>
);
}
sigParams
The sigParams
array contains the parameters that you need to sign with the user's stark key. It contains the address of the Starknet account that the user is signing in with to the Provisions portal and the contract ID which is the contract that the user will claim his tokens from.
Both of these parameters are passed from the Provisions portal as query params (recipient
and contract_id
) and read and parsed automatically. To test this, you can add ?recipient=0x28c70549121&contract_id=0xbc614e
to the URL when you are building your auth page.
Note: The
sigParams
may benull
if thestarknet_address
QS is not passed from the Provisions portal. This can happen if the user is not signed in to the Provisions portal and only wants to do eligibility check.
import {useStarkExAuthContext} from '@starknet-foundation/starkex-auth';
function MyComponent() {
const {redirect} = useStarkExAuthContext();
useEffect(() => {
redirect({
starkKey: '0x...',
sig: {r: '0x...', s: '0x...'},
identity: 'username'
});
}, []);
return (
<div>
<p>Redirecting...</p>
</div>
);
}
redirect({starkKey, identity, sig})
The redirect
function is a function that you can call to redirect the user to the Provisions website.
It takes an object with the following properties:
starkKey
- The stark public key of the user.identity
- The identity of the user. This can be the username/email/ethereum address or any other identifier.sig
(optional) - The approval signature result for the stark key and the Starknet address of the user.You can also add children components to the different auth components.
import {StarkExBasicAuth, StarkExWalletAuth} from '@starknet-foundation/starkex-auth';
function BasicApp() {
return (
<StarkExBasicAuth>
<div>
<p>Some text</p>
</div>
</StarkExBasicAuth>
);
}
function WalletApp() {
return (
<StarkExWalletAuth>
<div>
<p>Some text</p>
</div>
</StarkExWalletAuth>
);
}
FAQs
StarkEx Auth React component
The npm package @starknet-foundation/starkex-auth receives a total of 0 weekly downloads. As such, @starknet-foundation/starkex-auth popularity was classified as not popular.
We found that @starknet-foundation/starkex-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.