Signer
The FastAuthSigner is the transaction handling component of the FastAuth React SDK. It manages all blockchain interactions, transaction signing, and account operations while integrating seamlessly with authentication providers, the NEAR blockchain, and the FastAuth relayer service.
Overview
The FastAuthSigner serves as the bridge between authenticated users and the NEAR blockchain. It handles the complex process of creating, signing, and submitting transactions while leveraging Multi-Party Computation (MPC) for secure key management and authentication providers for user verification. The React SDK version includes integrated relayer support for gasless transactions and simplified account creation.
Dependencies
Configuration Types
type FastAuthSignerOptions = {
mpcContractId: string; // MPC contract for key derivation
fastAuthContractId: string; // FastAuth contract for authentication
};
type CreateAccountOptions = {
algorithm?: Algorithm; // Algorithm to use (default: "ed25519")
};
type SignatureRequest = {
guardId: string; // Guard identifier
verifyPayload: string; // Verification payload
signPayload: Uint8Array; // Signing payload
algorithm?: MPCContractAlgorithm; // Optional algorithm specification
};
type Algorithm = "secp256k1" | "ed25519";
type MPCContractAlgorithm = "secp256k1" | "eddsa" | "ecdsa";
type SignAndSendTransactionOptions<P extends IFastAuthProvider> = Parameters<P["requestTransactionSignature"]> & {
algorithm?: MPCContractAlgorithm;
transaction: Transaction;
};
type SignAndSendDelegateActionOptions<P extends IFastAuthProvider> = Parameters<P["requestDelegateActionSignature"]> & {
algorithm?: MPCContractAlgorithm;
receiverId: string;
};
Constructor
constructor(
fastAuthProvider: P,
connection: Connection,
options: FastAuthSignerOptions,
relayerURL: string
)
Parameters
fastAuthProvider: An instance implementingIFastAuthProviderinterfaceconnection: NEAR network connection fromnear-api-jsoptions: Configuration object containing MPC and FastAuth contract IDs (automatically set by FastAuthClient)relayerURL: URL of the FastAuth relayer service
Initialization
init
Initializes the signer by retrieving the cryptographic path from the provider.
- Usage: Must be called before using other signer methods
- Behavior: Retrieves and stores the derivation path from the authentication provider
- Required: Yes, called automatically by
FastAuthClient.getSigner()
Account Management
createAccount
Creates a new NEAR account with the signer's derived public key via the relayer service.
async createAccount(accountId: string, options?: CreateAccountOptions): Promise<string>
- Parameters:
accountId: The desired account identifieroptions: Optional algorithm configuration (default: "ed25519")
- Returns: Promise resolving to the transaction hash
- Usage: Used for onboarding new users to the NEAR ecosystem
- Note: This method uses the relayer service, so gas and deposit are handled automatically
getPublicKey
Retrieves the derived public key for the authenticated user.
async getPublicKey(algorithm?: Algorithm): Promise<PublicKey>
- Parameters:
algorithm: Optional algorithm to use (default: "ed25519")
- Returns: Promise resolving to the user's derived public key
- Process:
- Calls MPC contract's
derived_public_keymethod - Uses the signer's path and FastAuth contract as predecessor
- Uses the specified algorithm's domain ID for key derivation
- Returns the computed public key
- Calls MPC contract's
Transaction Operations
requestTransactionSignature
Initiates a transaction signature request through the authentication provider.
async requestTransactionSignature(...args: Parameters<P["requestTransactionSignature"]>)
- Parameters: Variable arguments passed to the provider's implementation
- Usage: Delegates to the provider for user consent and signature generation
- Flow: Provider → User Interface → Signature Generation
requestDelegateActionSignature
Initiates a delegate action signature request for gasless transactions.
async requestDelegateActionSignature(...args: Parameters<P["requestDelegateActionSignature"]>)
- Parameters: Variable arguments passed to the provider's implementation
- Usage: Enables meta-transactions where gas is paid by a relayer
- Benefit: Improves user experience by removing gas payment friction
getSignatureRequest
Retrieves the current signature request from the authentication provider.
getSignatureRequest(): Promise<SignatureRequest>
- Returns: Promise resolving to the pending signature request
- Contains: Guard ID, verification payload, and signing payload
- Usage: Used to check signature request status and retrieve payloads
Signing and Submission
createSignAction
Creates a NEAR action for signing operations on the FastAuth contract.
async createSignAction(request: SignatureRequest, options?: CreateSignActionOptions): Promise<Action>
- Parameters:
request: Signature request with guard ID, payloads, and optional algorithmoptions: Optional gas and deposit configuration
- Returns: Promise resolving to a function call action
- Contract Method: Calls
signmethod on FastAuth contract - Default Values: 300TGas, 0 NEAR deposit
- Algorithm: Defaults to "eddsa" if not specified in the request
signAndSendTransaction
Signs a transaction and relays it through the FastAuth relayer service.
async signAndSendTransaction(opts: SignAndSendTransactionOptions<P>): Promise<FinalExecutionOutcome>
- Parameters:
opts: Options object containing transaction, algorithm, and provider-specific signature request parameters
- Process:
- Requests transaction signature from the provider
- Retrieves signature request
- Relays signature request to the relayer service
- Recovers signature from relayer response
- Signs and submits transaction to the NEAR network
- Returns: Final execution outcome from the network
- Usage: Simplified method for signing and sending transactions with automatic relayer integration
signAndSendDelegateAction
Signs a delegate action and relays it through the FastAuth relayer service for gasless transactions.
async signAndSendDelegateAction(opts: SignAndSendDelegateActionOptions<P>): Promise<FinalExecutionOutcome>
- Parameters:
opts: Options object containing receiverId, algorithm, and provider-specific signature request parameters
- Process:
- Requests delegate action signature from the provider
- Retrieves signature request
- Relays signature request to the relayer service
- Returns the execution outcome
- Returns: Final execution outcome from the network
- Usage: Enables gasless transactions where gas is paid by the relayer
sendTransaction
Signs and submits a transaction to the NEAR network.
async sendTransaction(transaction: Transaction, signature: FastAuthSignature, algorithm?: Algorithm): Promise<FinalExecutionOutcome>
- Parameters:
transaction: The transaction to be signed and sentsignature: FastAuth MPC signaturealgorithm: Optional algorithm to use for signature recovery (default: "ed25519")
- Process:
- Recovers the signature using the specified algorithm (ed25519 or secp256k1)
- Creates a signed transaction with the appropriate key type
- Submits to the NEAR network via the connection provider
- Returns: Transaction result from the network
Contract Interaction
viewFunction (Private)
Executes read-only contract function calls.
- Purpose: Query contract state without gas costs
- Validation: Ensures arguments are properly formatted
- Encoding: Converts arguments to base64-encoded JSON
- Usage: Internal method for contract queries