Class: TorqueSDK
@torque-labs/torque-ts-sdk • Docs
@torque-labs/torque-ts-sdk / TorqueSDK
Class: TorqueSDK
The official Torque Typescript SDK.
The TorqueSDK class is used to manage the user and api clients for the Torque API.
Example
const sdk = new TorqueSDK({
signer: <wallet adapter or keypair>,
apiKey: "<your-api-key>",
publisherHandle: "<your-publisher-handle>",
rpc: "<RPC URL>",
});
// See if user is already logged in
const currentUser = await sdk.user.getCurrentUser();
// Authenticate the user if not logged in
const user = currentUser
? currentUser
: await sdk.user.initializeUser();Constructors
new TorqueSDK()
new TorqueSDK(options): TorqueSDKInitializes the TorqueSDK with the provided options.
Parameters
Returns
Throws
Throws an error if the there is no api key or publisher handle provided.
Defined in
Properties
api
undefined | TorqueAdminClient
apiKey
undefined | string
apiUrl
undefined | string
appUrl
undefined | string
audience
undefined | TorqueAudienceClient
functionsUrl
undefined | string
initialized
boolean
network
Cluster
publisherHandle
undefined | string
rpc
undefined | string
user
undefined | TorqueUserClient
Methods
initialize()
initialize(
signer,
signTransaction?,
ApiInputLogin?): Promise<void>Initializes the TorqueSDK with the provided options.
Parameters
signer
Adapter | Keypair
The signer used to sign transactions.
signTransaction?
The function used to sign transactions. If provided, it will override the default signing method.
Returns
Promise<void>
Throws
Throws an error if the there is no api key or publisher handle provided.
Defined in
logout()
logout(): Promise<void>Logout the user from the Torque API.
Returns
Promise<void>
Throws
Throws an error if the client is not initialized or if there is an error logging out the user.
Defined in
constructLoginBody()
static constructLoginBody(params): {
authType: "siws";
payload: {
input: payload.input;
output: SolanaSignInOutput;
};
pubKey: string;
} | {
authType: "basic";
payload: {
input: payload.input;
output: payload.output;
};
pubKey: string;
}Constructs the body for the login API request based on the authentication type.
Parameters
Returns
{ authType: "siws"; payload: { input: payload.input; output: SolanaSignInOutput; }; pubKey: string; } | { authType: "basic"; payload: { input: payload.input; output: payload.output; }; pubKey: string; }
The constructed body for the verify API request, formatted based on the authentication type.
Defined in
getLoginPayload()
static getLoginPayload(apiUrl): Promise<ApiIdentifyPayload>Retrieves a sample SIWS payload for logging into the Torque API.
Parameters
apiUrl
string
The API URL to use for the payload. Defaults to the Torque API URL.
Returns
Promise<ApiIdentifyPayload>
A Promise that resolves to the payload containing the identification statement, issued at time, and expiration time.
Throws
Throws an error if the API request is unsuccessful.
Defined in
verifyLogin()
static verifyLogin(loginOptions, apiUrl): Promise<ApiUser>Static method to verify the login options with the Torque API.
Parameters
loginOptions
The verification object that is required to authenticate a user with Torque.
apiUrl
string
The API URL to use for the verification. Defaults to the Torque API URL.
Returns
Promise<ApiUser>
A Promise that resolves to an object containing the user information.
Throws
Throws an error if there is an error authenticating the user.
Defined in
Last updated