Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
243 changes: 114 additions & 129 deletions bun.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions examples/accounts/breb/activate-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const accountUrn =
process.env.BREB_ACCOUNT_URN ?? 'did:bloque:account:breb:demo-account-id';

const { data, error } = await user.accounts.breb.activateKey({
accountUrn,
});

console.log('BREB activate key response:', { data, error });

if (error || !data) {
throw new Error(error?.message ?? 'Failed to activate BRE-B key');
}

console.log('BREB key activated:', {
accountUrn: data.accountUrn,
keyId: data.keyId,
keyStatus: data.keyStatus,
status: data.status,
});
36 changes: 36 additions & 0 deletions examples/accounts/breb/create-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const { data, error } = await user.accounts.breb.createKey({
keyType: 'PHONE',
key: process.env.BREB_KEY ?? '3015550184',
displayName: process.env.BREB_DISPLAY_NAME ?? 'Camila Ortega',
metadata: {
source: 'demo',
},
});

console.log('BREB create key response:', { data, error });

if (error || !data) {
throw new Error(error?.message ?? 'Failed to create BRE-B key');
}

console.log('BREB key created:', {
urn: data.urn,
keyType: data.keyType,
key: data.key,
displayName: data.displayName,
status: data.status,
ledgerId: data.ledgerId,
});
32 changes: 32 additions & 0 deletions examples/accounts/breb/delete-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const accountUrn =
process.env.BREB_ACCOUNT_URN ?? 'did:bloque:account:breb:demo-account-id';

const { data, error } = await user.accounts.breb.deleteKey({
accountUrn,
});

console.log('BREB delete key response:', { data, error });

if (error || !data) {
throw new Error(error?.message ?? 'Failed to delete BRE-B key');
}

console.log('BREB key deleted:', {
deleted: data.deleted,
accountUrn: data.accountUrn,
keyId: data.keyId,
status: data.status,
});
59 changes: 59 additions & 0 deletions examples/accounts/breb/pay-to-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const sourceAccountUrn =
process.env.SOURCE_ACCOUNT_URN ?? 'did:bloque:account:breb:demo-account-id';
const amountSrc = process.env.AMOUNT_SRC ?? '10000000';

const resolution = await user.accounts.breb.resolveKey({
keyType: 'PHONE',
key: '3015550127',
});
console.log('BREB resolve key response 3015550127:', resolution);

if (resolution.error || !resolution.data) {
throw new Error(resolution.error?.message ?? 'Failed to resolve BRE-B key');
}

const rates = await user.swap.findRates({
fromAsset: 'COPM/2',
toAsset: 'COP/2',
fromMediums: ['kusama'],
toMediums: ['breb'],
amountSrc,
});
console.log('Swap rates result:', rates);

if (rates.rates.length === 0) {
throw new Error(
'No swap rates available for the specified assets and mediums.',
);
}

const result = await user.swap.breb.create({
rateSig: rates.rates[0].sig,
amountSrc,
depositInformation: {
resolutionId: resolution.data.resolutionId,
},
args: {
sourceAccountUrn,
},
});

console.log('BREB payment created:', {
requestId: result.requestId,
orderId: result.order.id,
status: result.order.status,
execution: result.execution,
});
38 changes: 38 additions & 0 deletions examples/accounts/breb/resolve-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const resolution = await user.accounts.breb.resolveKey({
keyType:
(process.env.BREB_KEY_TYPE as
| 'ID'
| 'PHONE'
| 'EMAIL'
| 'ALPHA'
| 'BCODE') ?? 'PHONE',
key: process.env.BREB_KEY ?? '3015550127',
});

if (resolution.error || !resolution.data) {
throw new Error(resolution.error?.message ?? 'Failed to resolve BRE-B key');
}

console.log('BRE-B key resolved:', {
resolutionId: resolution.data.resolutionId,
key: resolution.data.key,
owner: resolution.data.owner,
participant: resolution.data.participant,
account: resolution.data.account,
receptorNode: resolution.data.receptorNode,
resolvedAt: resolution.data.resolvedAt,
expiresAt: resolution.data.expiresAt,
});
32 changes: 32 additions & 0 deletions examples/accounts/breb/suspend-breb-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { SDK } from '../../../packages/sdk/src/index';

const bloque = new SDK({
origin: process.env.ORIGIN!,
auth: {
type: 'apiKey',
apiKey: process.env.API_KEY!,
},
mode: process.env.MODE as 'production' | 'sandbox',
});

const user = await bloque.connect(process.env.USER_HANDLE ?? 'demo-user');

const accountUrn =
process.env.BREB_ACCOUNT_URN ?? 'did:bloque:account:breb:demo-account-id';

const { data, error } = await user.accounts.breb.suspendKey({
accountUrn,
});

console.log('BREB suspend key response:', { data, error });

if (error || !data) {
throw new Error(error?.message ?? 'Failed to suspend BRE-B key');
}

console.log('BREB key suspended:', {
accountUrn: data.accountUrn,
keyId: data.keyId,
keyStatus: data.keyStatus,
status: data.status,
});
4 changes: 2 additions & 2 deletions packages/accounts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bloque/sdk-accounts",
"version": "0.0.48",
"version": "0.0.49",
"type": "module",
"keywords": [
"bloque",
Expand Down Expand Up @@ -53,4 +53,4 @@
"@typescript/native-preview": "catalog:",
"typescript": "catalog:"
}
}
}
12 changes: 11 additions & 1 deletion packages/accounts/src/accounts-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {
mapBancolombiaAccountFromWire,
} from './bancolombia/bancolombia-client';
import type { BancolombiaAccount } from './bancolombia/types';
import { BrebClient, mapBrebAccountFromWire } from './breb/breb-client';
import type { BrebKeyAccount } from './breb/types';
import { CardClient, mapCardAccountFromWire } from './card/card-client';
import type { CardAccount, ListMovementsParams } from './card/types';
import type {
AccountWithBalance,
BancolombiaDetails,
BatchTransferRequest,
BatchTransferResponse,
BrebDetails,
CardDetails,
GetAccountResponse,
GetBalanceResponse,
Expand Down Expand Up @@ -44,7 +47,6 @@ import type {
ListMovementsResult,
ListTransactionsParams,
ListTransactionsResult,
Movement,
TokenBalance,
TransferParams,
TransferResult,
Expand All @@ -66,6 +68,7 @@ export type MappedAccount =
| VirtualAccount
| PolygonAccount
| BancolombiaAccount
| BrebKeyAccount
| UsAccount;

/**
Expand All @@ -75,11 +78,13 @@ export type MappedAccount =
* - card: Credit/debit cards
* - virtual: Virtual accounts
* - bancolombia: Bancolombia accounts
* - breb: BRE-B key accounts
* - us: US bank accounts
* - polygon: Polygon wallets
*/
export class AccountsClient extends BaseClient {
readonly bancolombia: BancolombiaClient;
readonly breb: BrebClient;
readonly card: CardClient;
readonly polygon: PolygonClient;
readonly us: UsClient;
Expand All @@ -88,6 +93,7 @@ export class AccountsClient extends BaseClient {
constructor(httpClient: HttpClient) {
super(httpClient);
this.bancolombia = new BancolombiaClient(this.httpClient);
this.breb = new BrebClient(this.httpClient);
this.card = new CardClient(this.httpClient);
this.polygon = new PolygonClient(this.httpClient);
this.us = new UsClient(this.httpClient);
Expand Down Expand Up @@ -593,6 +599,10 @@ export class AccountsClient extends BaseClient {
return mapBancolombiaAccountFromWire(
account as AccountWithBalance<BancolombiaDetails>,
);
case 'breb':
return mapBrebAccountFromWire(
account as AccountWithBalance<BrebDetails>,
);
case 'us-account':
return mapUsAccountFromWire(account as AccountWithBalance<UsDetails>);
default:
Expand Down
Loading