Class: TorqueSDK

@torque-labs/torque-ts-sdkDocs


@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): TorqueSDK

Initializes the TorqueSDK with the provided options.

Parameters

Returns

TorqueSDK

Throws

Throws an error if the there is no api key or publisher handle provided.

Defined in

src/classes/sdk.ts:92

Properties

Methods

initialize()

initialize(
   signer, 
   signTransaction?, 
ApiInputLogin?): Promise<void>

Initializes the TorqueSDK with the provided options.

Parameters

Returns

Promise<void>

Throws

Throws an error if the there is no api key or publisher handle provided.

Defined in

src/classes/sdk.ts:115


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

src/classes/sdk.ts:170


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

src/classes/sdk.ts:276


getLoginPayload()

static getLoginPayload(apiUrl): Promise<ApiIdentifyPayload>

Retrieves a sample SIWS payload for logging into the Torque API.

Parameters

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

src/classes/sdk.ts:244


verifyLogin()

static verifyLogin(loginOptions, apiUrl): Promise<ApiUser>

Static method to verify the login options with the Torque API.

Parameters

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

src/classes/sdk.ts:201

Last updated