HomeGuidesRecipesAPI ReferenceChangelog
Log In

Auth Service

Reference page for the Auth Service Interface

Interface

interface IAuthService {
  generateSiweSignedMessage(params: GenerateSiweSignedMessageRequest): Promise<GenerateSiweSignedMessageResponse>;
  siweLogin(params: SiweLoginRequest): Promise<void>;
  createSiweMessage(params: CreateSiweMessageRequest): string;
  authenticateWithSiwe(params: AuthenticateWithSiweRequest): Promise<void>;
  authenticateWithEmail(params: AuthenticateWithEmailRequest): Promise<AuthenticateWithEmailResponse>;
  setUnblockSessionByEmailCode(params: SetUnblockSessionByEmailCodeRequest): Promise<void>;
}

Structures used

Union types, Literal Types, Enums and Other Interfaces

interface IEthereumProviderSigner {
  getAddress(): Promise<string>;
  signMessage(message: string): Promise<string>;
}

In theory you will be using a provider that extends this class from ethers. You will be able to get a signer that extends this class.

GenerateSiweSignedMessageRequest

Field NameType
providerSignerIEthereumProviderSigner
chainIdstring
signingUrlstring

SiweLoginRequest

Field NameType
providerSignerIEthereumProviderSigner
chainIdstring
signingUrlstring

CreateSiweMessageRequest

Field NameType
walletAddressstring
statementstring
chainIdnumber
signingUrlstring

AuthenticateWithSiweRequest

Field NameType
message*string
signature*string

* to get a message and signature fields to use in a test case you can follow the following guide: https://docs.getunblock.com/docs/unblocker

AuthenticateWithEmailRequest

Field NameType
userUuidstring

SetUnblockSessionByEmailCodeRequest

Field NameType
codestring

AuthenticateWithEmailResponse

Field NameType
messagestring

GenerateSiweSignedMessageResponse

Field NameType
messagestring
signaturestring

Service Methods

authenticateWithSiwe

authenticateWithSiwe(params: AuthenticateWithSiweRequest): Promise<void>
Overview

This method allows you to authenticate a user using the SIWE system. This will set in the SDK the data needed to execute all of the methods related to the user.

Usage
Typescript
import getunblockSDK from '@getunblock/sdk';

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.authenticateWithSiwe({
    message: '[Generated SIWE message]*',
    signature: '[Generated SIWE signature]*',
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
})();
JavaScript
const getunblockSDK = require('@getunblock/sdk').default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.authenticateWithSiwe({
    message: '[Generated SIWE message]*',
    signature: '[Generated SIWE signature]*',
  });
  // * more info at https://docs.getunblock.com/docs/unblocker
})();

authenticateWithEmail

authenticateWithEmail(params: AuthenticateWithEmailRequest): Promise<AuthenticateWithEmailResponse>
Overview

This method allows you to start the email login process. An email with a code will be sent to the user's email. After the user submits that code in your GUI you should call the setUnblockSessionByEmailCode method to finalize the login process.

Usage
Typescript
import getunblockSDK from '@getunblock/sdk';

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.authenticateWithEmail({
    userUuid: '[user uuid value]',
  });
})();
JavaScript
const getunblockSDK = require('@getunblock/sdk').default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.authenticateWithEmail({
    userUuid: '[an user uuid value]',
  });
})();

setUnblockSessionByEmailCode

setUnblockSessionByEmailCode(params: SetUnblockSessionByEmailCodeRequest): Promise<void>
Overview

After the user has submitted in your provided GUI the code generated by the authenticateWithEmail method, you should call this method to complete the Login by email process.

Usage
Typescript
import getunblockSDK from '@getunblock/sdk';

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.setUnblockSessionByEmailCode({
    code: '[The code received in the email]',
  });
})();
JavaScript
const getunblockSDK = require('@getunblock/sdk').default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.setUnblockSessionByEmailCode({
    code: '[The code received in the email]',
  });
})();

createSiweMessage

createSiweMessage(params: CreateSiweMessageRequest): string
Overview

Will generate a message to be used in a Siwe authentication.

Usage
Typescript
import getunblockSDK from "@getunblock/sdk";

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.createSiweMessage(
    address: '0xbEFcCcFC70d97884f70b41927f6D20C511F4A36C',
    statement: 'Sign in with Ethereum',
    domain: 'getunblock.com',
    chainId: 8001
  );
})();
JavaScript
const getunblockSDK = require("@getunblock/sdk").default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // SDK API call example
  const result = await sdk.auth.createSiweMessage(
    address: '0xbEFcCcFC70d97884f70b41927f6D20C511F4A36C',
    statement: 'Sign in with Ethereum',
    domain: 'getunblock.com',
    chainId: 8001
  );
})();

generateSiweSignedMessage

generateSiweSignedMessage(params: GenerateSiweSignedMessageRequest): Promise<GenerateSiweSignedMessageResponse>
Overview

Will generate a object with message and signature. It requires a provider signer to sign the message.

Usage
Typescript
import getunblockSDK from '@getunblock/sdk';

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // Ideally it must be an ethereum provider signer implementation
  const yourOwnProviderSigner = YouOwnProviderSignerFactory.get();

  // SDK API call example
  const result = await sdk.auth.generateSiweSignedMessage({
    providerSigner: yourOwnProviderSigner,
    chainId: '8001',
    signingUrl: string,
  });
})();
JavaScript
const getunblockSDK = require("@getunblock/sdk").default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // Ideally it must be an ethereum provider signer implementation
  const yourOwnProviderSigner = YouOwnProviderSignerFactory.get();

  // SDK API call example
  const result = await sdk.auth.generateSiweSignedMessage(
      providerSigner: yourOwnProviderSigner,
      chainId: '8001',
      signingUrl: string,
  );
})();

siweLogin

siweLogin(params: SiweLoginRequest): Promise<SiweLoginResponse>
Overview

When providing a provider signer this method will do the entire login process made in one run.

Usage
Typescript
import getunblockSDK from '@getunblock/sdk';

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey: 'API-Key [Some merchant Key]', // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // Ideally it must be an ethereum provider signer implementation
  const yourOwnProviderSigner = YouOwnProviderSignerFactory.get();

  // SDK API call example
  const result = await sdk.auth.siweLogin({
    providerSigner: yourOwnProviderSigner,
    chainId: '8001',
    signingUrl: string,
  });
})();
JavaScript
const getunblockSDK = require("@getunblock/sdk").default;

(async () => {
  // setup SDK
  const sdk = getunblockSDK({
    apiKey:
      "API-Key [Some merchant Key]", // Key generated at the moment the merchant was created in getunblock system
    prod: false, // If true, Production environment will be used otherwise Sandbox will be used instead
  });

  // Ideally it must be an ethereum provider signer implementation
  const yourOwnProviderSigner = YouOwnProviderSignerFactory.get();

  // SDK API call example
  const result = await sdk.auth.siweLogin(
      providerSigner: yourOwnProviderSigner,
      chainId: '8001',
      signingUrl: string,
  );
})();