Skip to main content

Constructor

Creates a new instance of the Bloque SDK.
import { SDK } from '@bloque/sdk';

const sdk = new SDK(config);
config
BloqueSDKConfig
required
Configuration object for the SDK. See Configuration for details.

Example

import { SDK } from '@bloque/sdk';

const sdk = new SDK({
  auth: {
    type: 'apiKey',
    apiKey: 'your-api-key'
  },
  origin: 'your-origin',
  platform: 'node'
});

authenticate()

Authenticates the current session using JWT authentication. Retrieves the user identity and initializes all SDK clients.
async authenticate(): Promise<SDKClients>
This method is only available when using JWT authentication (auth.type === 'jwt').
accounts
AccountsClient
Client for managing accounts (cards, virtual accounts, Polygon, Bancolombia)
compliance
ComplianceClient
Client for KYC/KYB verification and compliance operations
identity
IdentityClient
Client for identity and alias management
orgs
OrgsClient
Client for organization management
swap
SwapClient
Client for swap operations
urn
string
The URN (Uniform Resource Name) of the authenticated identity
accessToken
string
The access token for the authenticated session

Example

import { SDK } from '@bloque/sdk';

const sdk = new SDK({
  auth: { type: 'jwt' },
  platform: 'browser'
});

const clients = await sdk.authenticate();

// Access various clients
const cards = await clients.accounts.card.list();
const profile = await clients.identity.me();

me()

Retrieves the identity information for the current session.
async me(): Promise<IdentityMe>
urn
string
The URN of the identity
origin
string
The origin identifier
aliases
string[]
List of aliases associated with the identity

Example

const identity = await sdk.me();

console.log(identity.urn); // did:bloque:my-origin:[email protected]
console.log(identity.origin); // my-origin
console.log(identity.aliases); // ['[email protected]', '+1234567890']

register()

Registers a new identity with the specified alias.
async register(
  alias: string,
  params: CreateIdentityParams
): Promise<SDKClients>
alias
string
required
The alias to register (email or phone number)
params
CreateIdentityParams
required
Identity creation parameters
params.extraContext
Record<string, any>
Additional context metadata for the identity
accounts
AccountsClient
Client for managing accounts
compliance
ComplianceClient
Client for compliance operations
identity
IdentityClient
Client for identity management
orgs
OrgsClient
Client for organization management
swap
SwapClient
Client for swap operations
urn
string
The URN of the newly registered identity
accessToken
string
The access token for the new session

Example

const sdk = new SDK({
  auth: {
    type: 'apiKey',
    apiKey: 'your-api-key'
  },
  origin: 'my-origin',
  platform: 'node'
});

const clients = await sdk.register('[email protected]', {
  extraContext: {
    firstName: 'John',
    lastName: 'Doe',
    country: 'US'
  }
});

console.log(clients.urn); // did:bloque:my-origin:[email protected]

connect()

Connects to an existing identity. The method signature varies based on authentication type.
async connect(alias: string): Promise<SDKClients>
alias
string
required
The alias to connect with (email or phone number)
accounts
AccountsClient
Client for managing accounts
compliance
ComplianceClient
Client for compliance operations
identity
IdentityClient
Client for identity management
orgs
OrgsClient
Client for organization management
swap
SwapClient
Client for swap operations
urn
string
The URN of the connected identity
accessToken
string
The access token for the session

Example

const sdk = new SDK({
  auth: {
    type: 'apiKey',
    apiKey: 'your-api-key'
  },
  origin: 'my-origin',
  platform: 'node'
});

const clients = await sdk.connect('[email protected]');
console.log(clients.urn); // did:bloque:my-origin:[email protected]

assert()

Initiates an OTP challenge for JWT authentication. Sends a verification code to the specified alias.
async assert(origin: string, alias: string): Promise<AssertionResponse>
This method is only available when using JWT authentication (auth.type === 'jwt').
origin
string
required
The origin identifier
alias
string
required
The alias (email or phone number) to send the OTP to
type
'OTP'
The challenge type (always ‘OTP’)
value
object
Details about the OTP challenge
value.phone
string
Phone number where OTP was sent (if applicable)
value.email
string
Email address where OTP was sent (if applicable)
value.expires_at
number
Unix timestamp when the OTP expires
params
object
Additional parameters
params.attempts_remaining
number
Number of verification attempts remaining

Example

const sdk = new SDK({
  auth: { type: 'jwt' },
  platform: 'browser'
});

const response = await sdk.assert('my-origin', '[email protected]');

console.log(`OTP sent to ${response.value.email}`);
console.log(`Expires at: ${new Date(response.value.expires_at * 1000)}`);
console.log(`Attempts remaining: ${response.params.attempts_remaining}`);

// User enters the code, then:
const clients = await sdk.connect('my-origin', '[email protected]', '123456');

SDKClients

The object returned by authenticate(), register(), and connect() contains all available API clients:
interface SDKClients {
  accounts: AccountsClient;
  compliance: ComplianceClient;
  identity: IdentityClient;
  orgs: OrgsClient;
  swap: SwapClient;
  urn: string;
  accessToken: string;
}

accounts

Provides access to account management:
const clients = await sdk.connect('[email protected]');

// Access sub-clients
const cards = await clients.accounts.card.list();
const virtualAccounts = await clients.accounts.virtual.list();
const polygonAccounts = await clients.accounts.polygon.list();
const bancolombiaAccounts = await clients.accounts.bancolombia.list();

compliance

Provides access to KYC/KYB verification:
const verification = await clients.compliance.kyc.startVerification({
  urn: clients.urn,
  webhookUrl: 'https://api.example.com/webhooks/kyc'
});

console.log(verification.url); // Direct user to this URL

identity

Provides access to identity management:
const profile = await clients.identity.me();

// Get alias information
const alias = await clients.identity.aliases.get('[email protected]');

orgs

Provides access to organization management:
const organization = await clients.orgs.create({
  profile: {
    type: 'business',
    name: 'Acme Inc',
    // ... business profile fields
  }
});

swap

Provides access to swap operations:
const rates = await clients.swap.findRates({
  fromAsset: 'COP/2',
  toAsset: 'DUSD/6',
  fromMediums: ['pse'],
  toMediums: ['kusama'],
  amountSrc: '10000000'
});

console.log(rates.rates[0].ratio);

urn

The URN (Uniform Resource Name) of the connected identity:
console.log(clients.urn); // did:bloque:my-origin:[email protected]

accessToken

The access token for the current session:
console.log(clients.accessToken); // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Build docs developers (and LLMs) love