Constructor
Creates a new instance of the Bloque SDK.
import { SDK } from '@bloque/sdk';
const sdk = new SDK(config);
Example
API Key (Backend)
JWT (Frontend)
import { SDK } from '@bloque/sdk';
const sdk = new SDK({
auth: {
type: 'apiKey',
apiKey: 'your-api-key'
},
origin: 'your-origin',
platform: 'node'
});
import { SDK } from '@bloque/sdk';
const sdk = new SDK({
auth: {
type: 'jwt'
},
platform: 'browser',
tokenStorage: {
get: () => localStorage.getItem('bloque_token'),
set: (token) => localStorage.setItem('bloque_token', token),
clear: () => localStorage.removeItem('bloque_token')
}
});
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').
Client for managing accounts (cards, virtual accounts, Polygon, Bancolombia)
Client for KYC/KYB verification and compliance operations
Client for identity and alias management
Client for organization management
Client for swap operations
The URN (Uniform Resource Name) of the authenticated identity
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>
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>
The alias to register (email or phone number)
params
CreateIdentityParams
required
Identity creation parameters
Additional context metadata for the identity
Client for managing accounts
Client for compliance operations
Client for identity management
Client for organization management
Client for swap operations
The URN of the newly registered identity
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>
The alias to connect with (email or phone number)
async connect(
origin: string,
alias: string,
code: string
): Promise<SDKClients>
The alias to connect with (email or phone number)
The OTP code received via email or SMS
Client for managing accounts
Client for compliance operations
Client for identity management
Client for organization management
Client for swap operations
The URN of the connected identity
The access token for the session
Example
API Key (Backend)
JWT (Frontend)
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]
const sdk = new SDK({
auth: { type: 'jwt' },
platform: 'browser'
});
// First, request an OTP code
await sdk.assert('my-origin', '[email protected]');
// Then connect with the code
const clients = await sdk.connect(
'my-origin',
'[email protected]',
'123456'
);
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').
The alias (email or phone number) to send the OTP to
The challenge type (always ‘OTP’)
Details about the OTP challengePhone number where OTP was sent (if applicable)
Email address where OTP was sent (if applicable)
Unix timestamp when the OTP expires
Additional parametersparams.attempts_remaining
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:
accessToken
The access token for the current session:
console.log(clients.accessToken); // eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...