FastAuth SDK
FastAuth is a key management system that allows users to recover or sign-up for a NEAR account using their email address. Furthermore, it allows to subsidize gas for a certain smart contract, so users can interact with it without having to fund their account.
FastAuth Components
FastAuth is comprised of 3 main elements:
- FastAuth Signer App: A module that allow FastAuth users to sign transactions.
- MPC Recovery Service: A service to create and restore user accounts, as well as signing transactions on behalf of the user.
- Transaction Relayer: A server that relays transactions to the NEAR network on behalf of the user.
Setting up Firebase
Create a project
- Go to Firebase
- Create or sign in to an account
- Go to "Get started", then "Add project"
- Call this project
my-fastauth-issuer
- Disable Google Analytics (recommended)
- Click on "Create project"
Set up passwordless authentication
- Go to "Authentication", then "Get started", and "Add new provider"
- Enable "Email/Password" and "Email link (passwordless sign-in)"
- Hit "Save"
Add user device information to Firestore
- Return to "Project Overview"
- Go to "Cloud Firestore", then "Create database"
- Select "Start in production mode", then "Next"
- Select your preferred location, then "Enable"
- Go to the "Rules" tab
- Change the rules to the following:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{document=**} {
allow create, read, update, delete: if request.auth != null && request.auth.uid == userId;
}
match /publicKeys/{publicKey} {
allow create, delete: if request.auth != null;
allow read : if true;
allow update: if false;
}
}
}
- Hit "Publish"
- Go to the "Data" tab
- Click on "Start collection"
- Set the Collection ID to
users
and hit "Next" - Add a Document ID of
root
and press "Save" - Click on "Start collection"
- Set the Collection ID to
publicKeys
and hit "Next" - Add a Document ID of
root
and press "Save"
Get the application credentials
- Press the gear button next to "Project Overview", and go to "Project settings"
- Under "Your apps", click on the
</>
button - Set the app nickname as
issuer-gcp
and hit "Register app" - You should see the code needed for initialization and authentication of Firestore, such as:
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "apikey",
authDomain: "my-fastauth-issuer-123.firebaseapp.com",
projectId: "my-fastauth-issuer-123",
storageBucket: "my-fastauth-issuer-123.appspot.com",
messagingSenderId: "12345678910",
appId: "1:12345678910:web:12345678910"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);