@bloque/sdk-identity 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -942
- package/dist/aliases/types.d.ts +1 -1
- package/dist/{client.d.ts → identity-client.d.ts} +2 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/{api-types.d.ts → internal/wire-types.d.ts} +79 -94
- package/dist/origins/{client.d.ts → origins-client.d.ts} +3 -3
- package/dist/types.d.ts +1 -3
- package/package.json +2 -2
- /package/dist/aliases/{client.d.ts → aliases-client.d.ts} +0 -0
- /package/dist/origins/{origin.d.ts → origin-client.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,944 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@bloque/sdk-identity`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
⚠️ **Warning**: This package is intended for internal use. Its release cycle does not follow SemVer, which means we might release breaking changes (change APIs, remove functionality) without any prior warning.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- **Identity Registration**: Register individual users (KYC) and businesses (KYB) to authentication origins
|
|
8
|
-
- **Multi-Origin Support**: Register identities across blockchain, OAuth, API key, and custom origins
|
|
9
|
-
- **Origin Management**: List and discover all available authentication origins
|
|
10
|
-
- **Aliases**: Get user identity information by email or phone
|
|
11
|
-
- **OTP Origins**: Send OTP codes via WhatsApp or Email
|
|
12
|
-
- **Custom Origins**: Support for custom authentication origins
|
|
13
|
-
- **Multiple Authentication Methods**: SIGNING_CHALLENGE, API_KEY, OAUTH_REDIRECT, WEBAUTHN, OTP, PASSWORD
|
|
14
|
-
- **TypeScript First**: Built with TypeScript for complete type safety
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
bun add @bloque/sdk-identity
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
This package is typically used through the main `@bloque/sdk` package, but can be used standalone:
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
import { HttpClient } from '@bloque/sdk-core';
|
|
28
|
-
import { IdentityClient } from '@bloque/sdk-identity';
|
|
29
|
-
|
|
30
|
-
const httpClient = new HttpClient({
|
|
31
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
32
|
-
mode: 'production',
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const identity = new IdentityClient(httpClient);
|
|
36
|
-
|
|
37
|
-
// Get alias information
|
|
38
|
-
const alias = await identity.aliases.get('user@example.com');
|
|
39
|
-
console.log('User URN:', alias.urn);
|
|
40
|
-
console.log('Alias status:', alias.status);
|
|
41
|
-
|
|
42
|
-
// Send OTP via WhatsApp
|
|
43
|
-
const otpWhatsApp = await identity.origins.whatsapp.assert('+1234567890');
|
|
44
|
-
console.log('OTP sent to:', otpWhatsApp.value.phone);
|
|
45
|
-
console.log('Expires at:', otpWhatsApp.value.expires_at);
|
|
46
|
-
|
|
47
|
-
// Send OTP via Email
|
|
48
|
-
const otpEmail = await identity.origins.email.assert('user@example.com');
|
|
49
|
-
console.log('OTP sent to:', otpEmail.value.email);
|
|
50
|
-
console.log('Attempts remaining:', otpEmail.params.attempts_remaining);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## API Reference
|
|
54
|
-
|
|
55
|
-
### Aliases
|
|
56
|
-
|
|
57
|
-
#### `aliases.get(alias)`
|
|
58
|
-
|
|
59
|
-
Retrieve alias information by the alias value (email or phone):
|
|
60
|
-
|
|
61
|
-
```typescript
|
|
62
|
-
const alias = await identity.aliases.get('user@example.com');
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**Parameters**:
|
|
66
|
-
- `alias` (string): Email address or phone number
|
|
67
|
-
|
|
68
|
-
**Response**:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
interface Alias {
|
|
72
|
-
id: string; // Unique alias ID
|
|
73
|
-
alias: string; // Alias value
|
|
74
|
-
type: 'phone' | 'email' | string; // Alias type
|
|
75
|
-
urn: string; // Associated user URN
|
|
76
|
-
origin: string; // Origin identifier
|
|
77
|
-
details: {
|
|
78
|
-
phone?: string; // Phone details (if applicable)
|
|
79
|
-
};
|
|
80
|
-
metadata: {
|
|
81
|
-
alias: string; // Alias in metadata
|
|
82
|
-
[key: string]: unknown; // Additional metadata
|
|
83
|
-
};
|
|
84
|
-
status: 'active' | 'inactive' | 'revoked'; // Alias status
|
|
85
|
-
is_public: boolean; // Whether alias is public
|
|
86
|
-
is_primary: boolean; // Whether this is the primary alias
|
|
87
|
-
created_at: string; // Creation timestamp (ISO 8601)
|
|
88
|
-
updated_at: string; // Last update timestamp (ISO 8601)
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Origins
|
|
93
|
-
|
|
94
|
-
Origins provide OTP (One-Time Password) authentication flows for different channels.
|
|
95
|
-
|
|
96
|
-
#### `origins.whatsapp.assert(phone)`
|
|
97
|
-
|
|
98
|
-
Send an OTP code via WhatsApp to the specified phone number:
|
|
99
|
-
|
|
100
|
-
```typescript
|
|
101
|
-
const otp = await identity.origins.whatsapp.assert('+1234567890');
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Parameters**:
|
|
105
|
-
- `phone` (string): Phone number in international format (e.g., '+1234567890')
|
|
106
|
-
|
|
107
|
-
**Response**:
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
interface OTPAssertionWhatsApp {
|
|
111
|
-
type: 'OTP';
|
|
112
|
-
params: {
|
|
113
|
-
attempts_remaining: number; // Number of remaining OTP attempts
|
|
114
|
-
};
|
|
115
|
-
value: {
|
|
116
|
-
phone: string; // Phone number where OTP was sent
|
|
117
|
-
expires_at: number; // Unix timestamp when OTP expires
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
#### `origins.email.assert(email)`
|
|
123
|
-
|
|
124
|
-
Send an OTP code via Email to the specified email address:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
const otp = await identity.origins.email.assert('user@example.com');
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Parameters**:
|
|
131
|
-
- `email` (string): Email address
|
|
132
|
-
|
|
133
|
-
**Response**:
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
interface OTPAssertionEmail {
|
|
137
|
-
type: 'OTP';
|
|
138
|
-
params: {
|
|
139
|
-
attempts_remaining: number; // Number of remaining OTP attempts
|
|
140
|
-
};
|
|
141
|
-
value: {
|
|
142
|
-
email: string; // Email address where OTP was sent
|
|
143
|
-
expires_at: number; // Unix timestamp when OTP expires
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
#### `origins.custom(origin)`
|
|
149
|
-
|
|
150
|
-
Create a custom origin client for custom authentication origins:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
const customOrigin = identity.origins.custom('my-custom-origin');
|
|
154
|
-
const otp = await customOrigin.assert('identifier');
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
**Parameters**:
|
|
158
|
-
- `origin` (string): Custom origin identifier
|
|
159
|
-
|
|
160
|
-
**Returns**: `OriginClient<OTPAssertion>` instance with `assert()` method
|
|
161
|
-
|
|
162
|
-
#### `origins.list()`
|
|
163
|
-
|
|
164
|
-
List all available origins with their current status:
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
const origins = await identity.origins.list();
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
**Response**:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
interface Origin {
|
|
174
|
-
namespace: string; // Unique namespace identifier
|
|
175
|
-
provider: string; // Provider type (e.g., 'evm', 'auth0', 'whatsapp')
|
|
176
|
-
status: 'active' | 'inactive' | 'disabled'; // Current status
|
|
177
|
-
metadata: Record<string, unknown>; // Additional metadata
|
|
178
|
-
created_at: string; // Creation timestamp (ISO 8601)
|
|
179
|
-
updated_at: string; // Last update timestamp (ISO 8601)
|
|
180
|
-
}
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**Returns**: `Promise<Origin[]>` - Array of all registered origins
|
|
184
|
-
|
|
185
|
-
#### `origins.register(origin, params)`
|
|
186
|
-
|
|
187
|
-
Register a new user or business identity to a specific origin. Supports both individual users (KYC) and businesses (KYB) with various authentication methods:
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
// Register individual with blockchain signature
|
|
191
|
-
const individual = await identity.origins.register('ethereum-mainnet', {
|
|
192
|
-
assertionResult: {
|
|
193
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
194
|
-
challengeType: 'SIGNING_CHALLENGE',
|
|
195
|
-
value: {
|
|
196
|
-
signature: '0x1234...',
|
|
197
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
type: 'individual',
|
|
201
|
-
profile: {
|
|
202
|
-
firstName: 'John',
|
|
203
|
-
lastName: 'Doe',
|
|
204
|
-
email: 'john@example.com'
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
// Register business with API key
|
|
209
|
-
const business = await identity.origins.register('bloque-api', {
|
|
210
|
-
assertionResult: {
|
|
211
|
-
alias: 'business-123',
|
|
212
|
-
challengeType: 'API_KEY',
|
|
213
|
-
value: {
|
|
214
|
-
apiKey: 'sk_live_abc123',
|
|
215
|
-
alias: 'business-123'
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
type: 'business',
|
|
219
|
-
profile: {
|
|
220
|
-
legalName: 'Acme Corporation',
|
|
221
|
-
name: 'Acme Corp',
|
|
222
|
-
taxId: '12-3456789',
|
|
223
|
-
type: 'LLC',
|
|
224
|
-
incorporationDate: '2020-01-15',
|
|
225
|
-
addressLine1: '123 Business St',
|
|
226
|
-
city: 'New York',
|
|
227
|
-
state: 'NY',
|
|
228
|
-
postalCode: '10001',
|
|
229
|
-
country: 'United States'
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
**Parameters**:
|
|
235
|
-
- `origin` (string): Origin namespace to register to (e.g., 'ethereum-mainnet', 'bloque-api')
|
|
236
|
-
- `params` (RegisterParams): Registration parameters
|
|
237
|
-
|
|
238
|
-
**Assertion Challenge Types**:
|
|
239
|
-
- `SIGNING_CHALLENGE`: Blockchain signature verification
|
|
240
|
-
- `API_KEY`: Traditional API key authentication
|
|
241
|
-
- `OAUTH_REDIRECT`: OAuth-based flows
|
|
242
|
-
- `WEBAUTHN`: WebAuthn/passkey authentication
|
|
243
|
-
- `OTP`: One-time password verification
|
|
244
|
-
- `PASSWORD`: Password-based authentication
|
|
245
|
-
|
|
246
|
-
**Individual Profile (KYC)**:
|
|
247
|
-
```typescript
|
|
248
|
-
interface UserProfile {
|
|
249
|
-
firstName?: string;
|
|
250
|
-
lastName?: string;
|
|
251
|
-
birthdate?: string; // ISO 8601 (YYYY-MM-DD)
|
|
252
|
-
email?: string;
|
|
253
|
-
phone?: string;
|
|
254
|
-
gender?: string;
|
|
255
|
-
addressLine1?: string;
|
|
256
|
-
addressLine2?: string;
|
|
257
|
-
city?: string;
|
|
258
|
-
state?: string;
|
|
259
|
-
postalCode?: string;
|
|
260
|
-
neighborhood?: string;
|
|
261
|
-
countryOfBirthCode?: string;
|
|
262
|
-
countryOfResidenceCode?: string;
|
|
263
|
-
personalIdType?: string;
|
|
264
|
-
personalIdNumber?: string;
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
**Business Profile (KYB)**:
|
|
269
|
-
```typescript
|
|
270
|
-
interface BusinessProfile {
|
|
271
|
-
// Required fields
|
|
272
|
-
addressLine1: string;
|
|
273
|
-
city: string;
|
|
274
|
-
country: string;
|
|
275
|
-
incorporationDate: string; // YYYY-MM-DD
|
|
276
|
-
legalName: string;
|
|
277
|
-
name: string;
|
|
278
|
-
postalCode: string;
|
|
279
|
-
state: string;
|
|
280
|
-
taxId: string;
|
|
281
|
-
type: string; // LLC, Corporation, etc.
|
|
282
|
-
|
|
283
|
-
// Optional fields
|
|
284
|
-
addressLine2?: string;
|
|
285
|
-
countryCode?: string;
|
|
286
|
-
email?: string;
|
|
287
|
-
logo?: string;
|
|
288
|
-
phone?: string;
|
|
289
|
-
|
|
290
|
-
// Owner information
|
|
291
|
-
ownerName?: string;
|
|
292
|
-
ownerIdType?: string;
|
|
293
|
-
ownerIdNumber?: string;
|
|
294
|
-
ownerAddressLine1?: string;
|
|
295
|
-
ownerAddressLine2?: string;
|
|
296
|
-
ownerCity?: string;
|
|
297
|
-
ownerState?: string;
|
|
298
|
-
ownerPostalCode?: string;
|
|
299
|
-
ownerCountryCode?: string;
|
|
300
|
-
}
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
**Response**:
|
|
304
|
-
```typescript
|
|
305
|
-
interface RegisterResult {
|
|
306
|
-
accessToken: string; // JWT token for authenticated sessions
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
**Returns**: `Promise<RegisterResult>` - Registration result with access token
|
|
311
|
-
|
|
312
|
-
## Examples
|
|
313
|
-
|
|
314
|
-
### Get Email Alias
|
|
315
|
-
|
|
316
|
-
```typescript
|
|
317
|
-
try {
|
|
318
|
-
const alias = await identity.aliases.get('user@example.com');
|
|
319
|
-
|
|
320
|
-
if (alias.status === 'active') {
|
|
321
|
-
console.log('Active user:', alias.urn);
|
|
322
|
-
}
|
|
323
|
-
} catch (error) {
|
|
324
|
-
console.error('Failed to get alias:', error);
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Get Phone Alias
|
|
329
|
-
|
|
330
|
-
```typescript
|
|
331
|
-
try {
|
|
332
|
-
const phoneAlias = await identity.aliases.get('+1234567890');
|
|
333
|
-
|
|
334
|
-
console.log('Phone details:', phoneAlias.details.phone);
|
|
335
|
-
console.log('User URN:', phoneAlias.urn);
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error('Failed to get phone alias:', error);
|
|
338
|
-
}
|
|
339
|
-
```
|
|
340
|
-
|
|
341
|
-
### Send OTP via WhatsApp
|
|
342
|
-
|
|
343
|
-
```typescript
|
|
344
|
-
import { SDK } from '@bloque/sdk';
|
|
345
|
-
|
|
346
|
-
const bloque = new SDK({
|
|
347
|
-
auth: {
|
|
348
|
-
type: 'apiKey',
|
|
349
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
350
|
-
},
|
|
351
|
-
mode: 'production',
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
try {
|
|
355
|
-
const otp = await bloque.identity.origins.whatsapp.assert('+1234567890');
|
|
356
|
-
|
|
357
|
-
console.log('OTP sent to:', otp.value.phone);
|
|
358
|
-
console.log('Expires at:', new Date(otp.value.expires_at * 1000));
|
|
359
|
-
console.log('Attempts remaining:', otp.params.attempts_remaining);
|
|
360
|
-
|
|
361
|
-
// Now user can verify the OTP code they received
|
|
362
|
-
} catch (error) {
|
|
363
|
-
console.error('Failed to send OTP:', error);
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
### Send OTP via Email
|
|
368
|
-
|
|
369
|
-
```typescript
|
|
370
|
-
import { SDK } from '@bloque/sdk';
|
|
371
|
-
|
|
372
|
-
const bloque = new SDK({
|
|
373
|
-
auth: {
|
|
374
|
-
type: 'apiKey',
|
|
375
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
376
|
-
},
|
|
377
|
-
mode: 'production',
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
try {
|
|
381
|
-
const otp = await bloque.identity.origins.email.assert('user@example.com');
|
|
382
|
-
|
|
383
|
-
console.log('OTP sent to:', otp.value.email);
|
|
384
|
-
console.log('Expires at:', new Date(otp.value.expires_at * 1000));
|
|
385
|
-
console.log('Attempts remaining:', otp.params.attempts_remaining);
|
|
386
|
-
|
|
387
|
-
// Now user can verify the OTP code they received
|
|
388
|
-
} catch (error) {
|
|
389
|
-
console.error('Failed to send OTP:', error);
|
|
390
|
-
}
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
### Complete OTP Flow Example
|
|
394
|
-
|
|
395
|
-
```typescript
|
|
396
|
-
import { SDK } from '@bloque/sdk';
|
|
397
|
-
|
|
398
|
-
const bloque = new SDK({
|
|
399
|
-
auth: {
|
|
400
|
-
type: 'apiKey',
|
|
401
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
402
|
-
},
|
|
403
|
-
mode: 'production',
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
async function authenticateUser(email: string) {
|
|
407
|
-
try {
|
|
408
|
-
// Step 1: Check if user exists
|
|
409
|
-
const alias = await bloque.identity.aliases.get(email);
|
|
410
|
-
|
|
411
|
-
if (alias.status !== 'active') {
|
|
412
|
-
throw new Error('User is not active');
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// Step 2: Send OTP
|
|
416
|
-
const otp = await bloque.identity.origins.email.assert(email);
|
|
417
|
-
|
|
418
|
-
console.log('OTP sent successfully to:', otp.value.email);
|
|
419
|
-
console.log('User has', otp.params.attempts_remaining, 'attempts remaining');
|
|
420
|
-
console.log('OTP expires at:', new Date(otp.value.expires_at * 1000));
|
|
421
|
-
|
|
422
|
-
// Step 3: User would now verify the OTP code
|
|
423
|
-
// (verification would be done through your app's verification endpoint)
|
|
424
|
-
|
|
425
|
-
return {
|
|
426
|
-
userUrn: alias.urn,
|
|
427
|
-
otpSent: true,
|
|
428
|
-
expiresAt: otp.value.expires_at,
|
|
429
|
-
};
|
|
430
|
-
} catch (error) {
|
|
431
|
-
console.error('Authentication failed:', error);
|
|
432
|
-
throw error;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
// Usage
|
|
437
|
-
await authenticateUser('user@example.com');
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
### List Available Origins
|
|
441
|
-
|
|
442
|
-
```typescript
|
|
443
|
-
import { SDK } from '@bloque/sdk';
|
|
444
|
-
|
|
445
|
-
const bloque = new SDK({
|
|
446
|
-
auth: {
|
|
447
|
-
type: 'apiKey',
|
|
448
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
449
|
-
},
|
|
450
|
-
mode: 'production',
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
try {
|
|
454
|
-
const origins = await bloque.identity.origins.list();
|
|
455
|
-
|
|
456
|
-
// Filter active origins
|
|
457
|
-
const activeOrigins = origins.filter(o => o.status === 'active');
|
|
458
|
-
console.log(`Found ${activeOrigins.length} active origins`);
|
|
459
|
-
|
|
460
|
-
// Find specific origins
|
|
461
|
-
const whatsappOrigins = origins.filter(o => o.provider === 'whatsapp');
|
|
462
|
-
const evmOrigins = origins.filter(o => o.provider === 'evm');
|
|
463
|
-
|
|
464
|
-
console.log('WhatsApp origins:', whatsappOrigins.map(o => o.namespace));
|
|
465
|
-
console.log('EVM origins:', evmOrigins.map(o => o.namespace));
|
|
466
|
-
|
|
467
|
-
// Get metadata from specific origin
|
|
468
|
-
const auth0Origin = origins.find(o => o.namespace === 'bloque-auth0');
|
|
469
|
-
if (auth0Origin) {
|
|
470
|
-
console.log('Auth0 metadata:', auth0Origin.metadata);
|
|
471
|
-
}
|
|
472
|
-
} catch (error) {
|
|
473
|
-
console.error('Failed to list origins:', error);
|
|
474
|
-
}
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
### Using Custom Origin
|
|
478
|
-
|
|
479
|
-
```typescript
|
|
480
|
-
import { SDK } from '@bloque/sdk';
|
|
481
|
-
|
|
482
|
-
const bloque = new SDK({
|
|
483
|
-
auth: {
|
|
484
|
-
type: 'apiKey',
|
|
485
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
486
|
-
},
|
|
487
|
-
mode: 'production',
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
// Create a custom origin client
|
|
491
|
-
const customOrigin = bloque.identity.origins.custom('my-custom-sms-provider');
|
|
492
|
-
|
|
493
|
-
try {
|
|
494
|
-
const otp = await customOrigin.assert('+1234567890');
|
|
495
|
-
|
|
496
|
-
console.log('OTP sent via custom origin');
|
|
497
|
-
console.log('Attempts remaining:', otp.params.attempts_remaining);
|
|
498
|
-
} catch (error) {
|
|
499
|
-
console.error('Failed to send OTP via custom origin:', error);
|
|
500
|
-
}
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
### Error Handling with Rate Limiting
|
|
504
|
-
|
|
505
|
-
```typescript
|
|
506
|
-
import { SDK } from '@bloque/sdk';
|
|
507
|
-
|
|
508
|
-
const bloque = new SDK({
|
|
509
|
-
auth: {
|
|
510
|
-
type: 'apiKey',
|
|
511
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
512
|
-
},
|
|
513
|
-
mode: 'production',
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
async function sendOTPWithRetry(phone: string, maxRetries = 3) {
|
|
517
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
518
|
-
try {
|
|
519
|
-
const otp = await bloque.identity.origins.whatsapp.assert(phone);
|
|
520
|
-
|
|
521
|
-
if (otp.params.attempts_remaining === 0) {
|
|
522
|
-
console.warn('No OTP attempts remaining!');
|
|
523
|
-
return null;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
console.log('OTP sent successfully');
|
|
527
|
-
console.log('Attempts remaining:', otp.params.attempts_remaining);
|
|
528
|
-
|
|
529
|
-
return otp;
|
|
530
|
-
} catch (error) {
|
|
531
|
-
console.error(`Attempt ${attempt} failed:`, error);
|
|
532
|
-
|
|
533
|
-
if (attempt === maxRetries) {
|
|
534
|
-
throw new Error('Max retries reached');
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// Wait before retrying
|
|
538
|
-
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
await sendOTPWithRetry('+1234567890');
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### Register Individual User (KYC)
|
|
547
|
-
|
|
548
|
-
```typescript
|
|
549
|
-
import { SDK } from '@bloque/sdk';
|
|
550
|
-
|
|
551
|
-
const bloque = new SDK({
|
|
552
|
-
auth: {
|
|
553
|
-
type: 'apiKey',
|
|
554
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
555
|
-
},
|
|
556
|
-
mode: 'production',
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
try {
|
|
560
|
-
// Register individual with blockchain signature
|
|
561
|
-
const result = await bloque.identity.origins.register('ethereum-mainnet', {
|
|
562
|
-
assertionResult: {
|
|
563
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
564
|
-
challengeType: 'SIGNING_CHALLENGE',
|
|
565
|
-
value: {
|
|
566
|
-
signature: '0x1234567890abcdef...',
|
|
567
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'
|
|
568
|
-
},
|
|
569
|
-
originalChallengeParams: {
|
|
570
|
-
challenge: 'bloque-challenge-1234567890',
|
|
571
|
-
timestamp: 1640995200
|
|
572
|
-
}
|
|
573
|
-
},
|
|
574
|
-
type: 'individual',
|
|
575
|
-
profile: {
|
|
576
|
-
firstName: 'John',
|
|
577
|
-
lastName: 'Doe',
|
|
578
|
-
email: 'john.doe@example.com',
|
|
579
|
-
phone: '+1234567890',
|
|
580
|
-
birthdate: '1990-01-15',
|
|
581
|
-
city: 'New York',
|
|
582
|
-
state: 'NY',
|
|
583
|
-
postalCode: '10001',
|
|
584
|
-
addressLine1: '123 Main St',
|
|
585
|
-
countryOfBirthCode: 'USA',
|
|
586
|
-
countryOfResidenceCode: 'USA',
|
|
587
|
-
personalIdType: 'SSN',
|
|
588
|
-
personalIdNumber: '123-45-6789'
|
|
589
|
-
}
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
console.log('User registered successfully!');
|
|
593
|
-
console.log('Access token:', result.accessToken);
|
|
594
|
-
|
|
595
|
-
// Use the access token for authenticated API calls
|
|
596
|
-
// Store it securely for the user's session
|
|
597
|
-
} catch (error) {
|
|
598
|
-
console.error('Registration failed:', error);
|
|
599
|
-
}
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
### Register Business (KYB)
|
|
603
|
-
|
|
604
|
-
```typescript
|
|
605
|
-
import { SDK } from '@bloque/sdk';
|
|
606
|
-
|
|
607
|
-
const bloque = new SDK({
|
|
608
|
-
auth: {
|
|
609
|
-
type: 'apiKey',
|
|
610
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
611
|
-
},
|
|
612
|
-
mode: 'production',
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
try {
|
|
616
|
-
// Register business with API key authentication
|
|
617
|
-
const result = await bloque.identity.origins.register('bloque-api', {
|
|
618
|
-
assertionResult: {
|
|
619
|
-
alias: 'business-123',
|
|
620
|
-
challengeType: 'API_KEY',
|
|
621
|
-
value: {
|
|
622
|
-
apiKey: 'sk_live_abc123def456',
|
|
623
|
-
alias: 'business-123'
|
|
624
|
-
}
|
|
625
|
-
},
|
|
626
|
-
type: 'business',
|
|
627
|
-
profile: {
|
|
628
|
-
// Required business information
|
|
629
|
-
legalName: 'Acme Corporation',
|
|
630
|
-
name: 'Acme Corp',
|
|
631
|
-
taxId: '12-3456789',
|
|
632
|
-
type: 'LLC',
|
|
633
|
-
incorporationDate: '2020-01-15',
|
|
634
|
-
addressLine1: '123 Business St',
|
|
635
|
-
city: 'New York',
|
|
636
|
-
state: 'NY',
|
|
637
|
-
postalCode: '10001',
|
|
638
|
-
country: 'United States',
|
|
639
|
-
|
|
640
|
-
// Optional business information
|
|
641
|
-
addressLine2: 'Suite 100',
|
|
642
|
-
countryCode: 'US',
|
|
643
|
-
email: 'contact@acme.com',
|
|
644
|
-
phone: '+1-555-0123',
|
|
645
|
-
logo: 'https://acme.com/logo.png',
|
|
646
|
-
|
|
647
|
-
// Beneficial owner information
|
|
648
|
-
ownerName: 'Jane Smith',
|
|
649
|
-
ownerIdType: 'SSN',
|
|
650
|
-
ownerIdNumber: '123-45-6789',
|
|
651
|
-
ownerAddressLine1: '456 Owner Ave',
|
|
652
|
-
ownerCity: 'New York',
|
|
653
|
-
ownerState: 'NY',
|
|
654
|
-
ownerPostalCode: '10002',
|
|
655
|
-
ownerCountryCode: 'US'
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
|
|
659
|
-
console.log('Business registered successfully!');
|
|
660
|
-
console.log('Access token:', result.accessToken);
|
|
661
|
-
|
|
662
|
-
// Use the access token for authenticated API calls
|
|
663
|
-
} catch (error) {
|
|
664
|
-
console.error('Business registration failed:', error);
|
|
665
|
-
}
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
### Multi-Origin Registration Flow
|
|
669
|
-
|
|
670
|
-
```typescript
|
|
671
|
-
import { SDK } from '@bloque/sdk';
|
|
672
|
-
|
|
673
|
-
const bloque = new SDK({
|
|
674
|
-
auth: {
|
|
675
|
-
type: 'apiKey',
|
|
676
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
677
|
-
},
|
|
678
|
-
mode: 'production',
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
async function registerUserAcrossOrigins(userProfile: any) {
|
|
682
|
-
try {
|
|
683
|
-
// Step 1: List available origins
|
|
684
|
-
const origins = await bloque.identity.origins.list();
|
|
685
|
-
const activeOrigins = origins.filter(o => o.status === 'active');
|
|
686
|
-
|
|
687
|
-
console.log(`Found ${activeOrigins.length} active origins`);
|
|
688
|
-
|
|
689
|
-
// Step 2: Register on blockchain origin
|
|
690
|
-
const ethereumOrigin = activeOrigins.find(o => o.namespace === 'ethereum-mainnet');
|
|
691
|
-
|
|
692
|
-
if (ethereumOrigin) {
|
|
693
|
-
const ethereumResult = await bloque.identity.origins.register('ethereum-mainnet', {
|
|
694
|
-
assertionResult: {
|
|
695
|
-
alias: userProfile.walletAddress,
|
|
696
|
-
challengeType: 'SIGNING_CHALLENGE',
|
|
697
|
-
value: {
|
|
698
|
-
signature: userProfile.signature,
|
|
699
|
-
alias: userProfile.walletAddress
|
|
700
|
-
}
|
|
701
|
-
},
|
|
702
|
-
type: 'individual',
|
|
703
|
-
profile: userProfile.personalInfo
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
console.log('Registered on Ethereum:', ethereumResult.accessToken);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// Step 3: Register on custom origin
|
|
710
|
-
const customResult = await bloque.identity.origins.register('bloque-custom', {
|
|
711
|
-
assertionResult: {
|
|
712
|
-
alias: userProfile.customId,
|
|
713
|
-
challengeType: 'API_KEY',
|
|
714
|
-
value: {
|
|
715
|
-
apiKey: userProfile.apiKey,
|
|
716
|
-
alias: userProfile.customId
|
|
717
|
-
}
|
|
718
|
-
},
|
|
719
|
-
type: 'individual',
|
|
720
|
-
profile: userProfile.personalInfo
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
console.log('Registered on custom origin:', customResult.accessToken);
|
|
724
|
-
|
|
725
|
-
return {
|
|
726
|
-
ethereum: ethereumOrigin ? true : false,
|
|
727
|
-
custom: true,
|
|
728
|
-
tokens: {
|
|
729
|
-
ethereum: ethereumOrigin ? 'stored' : null,
|
|
730
|
-
custom: 'stored'
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
|
-
} catch (error) {
|
|
734
|
-
console.error('Multi-origin registration failed:', error);
|
|
735
|
-
throw error;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
// Usage
|
|
740
|
-
await registerUserAcrossOrigins({
|
|
741
|
-
walletAddress: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
742
|
-
signature: '0xabcdef...',
|
|
743
|
-
customId: 'user-123',
|
|
744
|
-
apiKey: 'sk_live_abc123',
|
|
745
|
-
personalInfo: {
|
|
746
|
-
firstName: 'Alice',
|
|
747
|
-
lastName: 'Johnson',
|
|
748
|
-
email: 'alice@example.com'
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
```
|
|
752
|
-
|
|
753
|
-
## TypeScript Support
|
|
754
|
-
|
|
755
|
-
This package is written in TypeScript and includes complete type definitions:
|
|
756
|
-
|
|
757
|
-
```typescript
|
|
758
|
-
import type {
|
|
759
|
-
Alias,
|
|
760
|
-
Origin,
|
|
761
|
-
OTPAssertionEmail,
|
|
762
|
-
OTPAssertionWhatsApp,
|
|
763
|
-
OTPAssertion,
|
|
764
|
-
IdentityClient,
|
|
765
|
-
AliasesClient,
|
|
766
|
-
OriginsClient,
|
|
767
|
-
OriginClient,
|
|
768
|
-
// Registration types
|
|
769
|
-
RegisterParams,
|
|
770
|
-
IndividualRegisterParams,
|
|
771
|
-
BusinessRegisterParams,
|
|
772
|
-
RegisterResult,
|
|
773
|
-
UserProfile,
|
|
774
|
-
BusinessProfile,
|
|
775
|
-
} from '@bloque/sdk-identity';
|
|
776
|
-
|
|
777
|
-
// Type-safe alias retrieval
|
|
778
|
-
const alias: Alias = await identity.aliases.get('user@example.com');
|
|
779
|
-
|
|
780
|
-
// Type-safe origins list
|
|
781
|
-
const origins: Origin[] = await identity.origins.list();
|
|
782
|
-
|
|
783
|
-
// Type-safe OTP with WhatsApp
|
|
784
|
-
const whatsappOTP: OTPAssertionWhatsApp =
|
|
785
|
-
await identity.origins.whatsapp.assert('+1234567890');
|
|
786
|
-
|
|
787
|
-
// Type-safe OTP with Email
|
|
788
|
-
const emailOTP: OTPAssertionEmail =
|
|
789
|
-
await identity.origins.email.assert('user@example.com');
|
|
790
|
-
|
|
791
|
-
// Generic OTP type
|
|
792
|
-
const otp: OTPAssertion =
|
|
793
|
-
await identity.origins.email.assert('user@example.com');
|
|
794
|
-
|
|
795
|
-
// Custom origin client
|
|
796
|
-
const customOrigin: OriginClient<OTPAssertion> =
|
|
797
|
-
identity.origins.custom('my-origin');
|
|
798
|
-
|
|
799
|
-
// Type-safe individual registration
|
|
800
|
-
const individualParams: IndividualRegisterParams = {
|
|
801
|
-
assertionResult: {
|
|
802
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
803
|
-
challengeType: 'SIGNING_CHALLENGE',
|
|
804
|
-
value: {
|
|
805
|
-
signature: '0x123...',
|
|
806
|
-
alias: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6'
|
|
807
|
-
}
|
|
808
|
-
},
|
|
809
|
-
type: 'individual',
|
|
810
|
-
profile: {
|
|
811
|
-
firstName: 'John',
|
|
812
|
-
lastName: 'Doe',
|
|
813
|
-
email: 'john@example.com'
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
const individualResult: RegisterResult =
|
|
818
|
-
await identity.origins.register('ethereum-mainnet', individualParams);
|
|
819
|
-
|
|
820
|
-
// Type-safe business registration
|
|
821
|
-
const businessParams: BusinessRegisterParams = {
|
|
822
|
-
assertionResult: {
|
|
823
|
-
alias: 'business-123',
|
|
824
|
-
challengeType: 'API_KEY',
|
|
825
|
-
value: {
|
|
826
|
-
apiKey: 'sk_live_abc123',
|
|
827
|
-
alias: 'business-123'
|
|
828
|
-
}
|
|
829
|
-
},
|
|
830
|
-
type: 'business',
|
|
831
|
-
profile: {
|
|
832
|
-
legalName: 'Acme Corp',
|
|
833
|
-
name: 'Acme',
|
|
834
|
-
taxId: '12-3456789',
|
|
835
|
-
type: 'LLC',
|
|
836
|
-
incorporationDate: '2020-01-15',
|
|
837
|
-
addressLine1: '123 Business St',
|
|
838
|
-
city: 'New York',
|
|
839
|
-
state: 'NY',
|
|
840
|
-
postalCode: '10001',
|
|
841
|
-
country: 'United States'
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
const businessResult: RegisterResult =
|
|
846
|
-
await identity.origins.register('bloque-api', businessParams);
|
|
847
|
-
```
|
|
848
|
-
|
|
849
|
-
## Use with Main SDK
|
|
850
|
-
|
|
851
|
-
When using through the main `@bloque/sdk` package:
|
|
852
|
-
|
|
853
|
-
```typescript
|
|
854
|
-
import { SDK } from '@bloque/sdk';
|
|
855
|
-
|
|
856
|
-
const bloque = new SDK({
|
|
857
|
-
auth: {
|
|
858
|
-
type: 'apiKey',
|
|
859
|
-
apiKey: process.env.BLOQUE_API_KEY!,
|
|
860
|
-
},
|
|
861
|
-
mode: 'production',
|
|
862
|
-
});
|
|
863
|
-
|
|
864
|
-
// All identity features are available under bloque.identity
|
|
865
|
-
const alias = await bloque.identity.aliases.get('user@example.com');
|
|
866
|
-
const otp = await bloque.identity.origins.whatsapp.assert('+1234567890');
|
|
867
|
-
```
|
|
868
|
-
|
|
869
|
-
## Key Features
|
|
870
|
-
|
|
871
|
-
### Identity Registration
|
|
872
|
-
|
|
873
|
-
- **Individual Registration (KYC)**: Register users with Know Your Customer compliance
|
|
874
|
-
- **Business Registration (KYB)**: Register businesses with Know Your Business compliance
|
|
875
|
-
- **Multi-Method Authentication**: Support for blockchain signatures, API keys, OAuth, WebAuthn, OTP, and passwords
|
|
876
|
-
- **Cross-Origin Support**: Register identities across multiple authentication origins
|
|
877
|
-
- **Secure Token Generation**: Receive JWT access tokens for authenticated sessions
|
|
878
|
-
|
|
879
|
-
### Origin Management
|
|
880
|
-
|
|
881
|
-
- **List Origins**: Retrieve all available authentication origins
|
|
882
|
-
- **Filter by Provider**: Find origins by provider type (evm, auth0, whatsapp, etc.)
|
|
883
|
-
- **Check Status**: Monitor origin availability and status
|
|
884
|
-
- **Custom Registration**: Register to custom authentication providers
|
|
885
|
-
|
|
886
|
-
### OTP Authentication Channels
|
|
887
|
-
|
|
888
|
-
- **WhatsApp**: Send OTP codes via WhatsApp messages
|
|
889
|
-
- **Email**: Send OTP codes via email
|
|
890
|
-
- **Custom Origins**: Integrate custom authentication providers
|
|
891
|
-
|
|
892
|
-
### Rate Limiting & Security
|
|
893
|
-
|
|
894
|
-
OTP assertions include built-in rate limiting:
|
|
895
|
-
- `attempts_remaining`: Track remaining OTP attempts
|
|
896
|
-
- `expires_at`: Unix timestamp for OTP expiration
|
|
897
|
-
- Automatic retry protection
|
|
898
|
-
|
|
899
|
-
### Alias Management
|
|
900
|
-
|
|
901
|
-
- Retrieve user information by email or phone
|
|
902
|
-
- Check user status (active, inactive, revoked)
|
|
903
|
-
- Support for primary and public aliases
|
|
904
|
-
- Rich metadata support
|
|
905
|
-
|
|
906
|
-
### Compliance Support
|
|
907
|
-
|
|
908
|
-
- **KYC (Know Your Customer)**: Complete individual profile fields including identity verification
|
|
909
|
-
- **KYB (Know Your Business)**: Business entity information with beneficial owner details
|
|
910
|
-
- **Data Privacy**: Secure handling of sensitive personal and business information
|
|
911
|
-
|
|
912
|
-
## Requirements
|
|
913
|
-
|
|
914
|
-
- Node.js 22.x or higher / Bun 1.x or higher
|
|
915
|
-
- TypeScript 5.x or higher (for TypeScript projects)
|
|
916
|
-
|
|
917
|
-
## Links
|
|
918
|
-
|
|
919
|
-
- [Homepage](https://www.bloque.app)
|
|
920
|
-
- [Main SDK Documentation](../sdk/README.md)
|
|
921
|
-
- [GitHub Repository](https://github.com/bloque-app/sdk)
|
|
922
|
-
- [Issue Tracker](https://github.com/bloque-app/sdk/issues)
|
|
923
|
-
|
|
924
|
-
## Development
|
|
925
|
-
|
|
926
|
-
```bash
|
|
927
|
-
# Build the package
|
|
928
|
-
bun run build
|
|
929
|
-
|
|
930
|
-
# Watch mode
|
|
931
|
-
bun run dev
|
|
932
|
-
|
|
933
|
-
# Type checking
|
|
934
|
-
bun run typecheck
|
|
935
|
-
|
|
936
|
-
# Code quality checks
|
|
937
|
-
bun run check
|
|
938
|
-
```
|
|
939
|
-
|
|
940
|
-
## License
|
|
941
|
-
|
|
942
|
-
[MIT](../../LICENSE)
|
|
943
|
-
|
|
944
|
-
Copyright (c) 2025-present Bloque Copilot Inc.
|
|
5
|
+
For documentation, please refer to the [main SDK documentation](../sdk/README.md).
|
package/dist/aliases/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AliasResponse } from '../
|
|
1
|
+
import type { AliasResponse } from '../internal/wire-types';
|
|
2
2
|
export type Alias = AliasResponse;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { HttpClient } from '@bloque/sdk-core';
|
|
2
|
-
import { AliasesClient } from './aliases/client';
|
|
3
|
-
import { OriginsClient } from './origins/client';
|
|
4
|
-
import type { CreateIdentityParams } from './types';
|
|
2
|
+
import { AliasesClient } from './aliases/aliases-client';
|
|
3
|
+
import { OriginsClient } from './origins/origins-client';
|
|
5
4
|
export declare class IdentityClient {
|
|
6
5
|
private readonly httpClient;
|
|
7
6
|
readonly aliases: AliasesClient;
|
|
8
7
|
readonly origins: OriginsClient;
|
|
9
8
|
constructor(httpClient: HttpClient);
|
|
10
|
-
create(params: CreateIdentityParams): Promise<import(".").RegisterResult>;
|
|
11
9
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var i in t)__webpack_require__.o(t,i)&&!__webpack_require__.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{OriginClient:()=>OriginClient,AliasesClient:()=>AliasesClient,IdentityClient:()=>IdentityClient,OriginsClient:()=>OriginsClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class AliasesClient extends sdk_core_namespaceObject.BaseClient{async get(e){return await this.httpClient.request({method:"GET",path:`/api/aliases?alias=${e}`})}}class OriginClient extends sdk_core_namespaceObject.BaseClient{origin;constructor(e,t){super(e),this.origin=t}async assert(e){return await this.httpClient.request({method:"GET",path:`/api/origins/${this.origin}/assert?alias=${e}`})}}class OriginsClient extends sdk_core_namespaceObject.BaseClient{whatsapp;email;constructor(e){super(e),this.whatsapp=new OriginClient(e,"bloque-whatsapp"),this.email=new OriginClient(e,"bloque-email")}custom(e){return new OriginClient(this.httpClient,e)}async list(){return await this.httpClient.request({method:"GET",path:"/api/origins"})}async register(e,t){let
|
|
1
|
+
"use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var i in t)__webpack_require__.o(t,i)&&!__webpack_require__.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{OriginClient:()=>OriginClient,AliasesClient:()=>AliasesClient,IdentityClient:()=>IdentityClient,OriginsClient:()=>OriginsClient});const sdk_core_namespaceObject=require("@bloque/sdk-core");class AliasesClient extends sdk_core_namespaceObject.BaseClient{async get(e){return await this.httpClient.request({method:"GET",path:`/api/aliases?alias=${e}`})}}class OriginClient extends sdk_core_namespaceObject.BaseClient{origin;constructor(e,t){super(e),this.origin=t}async assert(e){return await this.httpClient.request({method:"GET",path:`/api/origins/${this.origin}/assert?alias=${e}`})}}class OriginsClient extends sdk_core_namespaceObject.BaseClient{whatsapp;email;constructor(e){super(e),this.whatsapp=new OriginClient(e,"bloque-whatsapp"),this.email=new OriginClient(e,"bloque-email")}custom(e){return new OriginClient(this.httpClient,e)}async list(){return await this.httpClient.request({method:"GET",path:"/api/origins"})}async register(e,t,i){let r,n=i.assertionResult,a="API_KEY"===n.challengeType?{alias:n.alias,challengeType:"API_KEY",value:{api_key:n.value.apiKey,alias:e},originalChallengeParams:n.originalChallengeParams}:{alias:e,challengeType:n.challengeType,value:n.value,originalChallengeParams:n.originalChallengeParams};return r="individual"===i.type?{assertion_result:a,extra_context:i.extraContext,type:"individual",profile:this._mapUserProfile(i.profile)}:{assertion_result:a,extra_context:i.extraContext,type:"business",profile:this._mapBusinessProfile(i.profile)},{accessToken:(await this.httpClient.request({method:"POST",path:`/api/origins/${t}/register`,body:r})).result.access_token}}_mapUserProfile(e){return{first_name:e.firstName,last_name:e.lastName,birthdate:e.birthdate,email:e.email,phone:e.phone,gender:e.gender,address_line1:e.addressLine1,address_line2:e.addressLine2,city:e.city,state:e.state,postal_code:e.postalCode,neighborhood:e.neighborhood,country_of_birth_code:e.countryOfBirthCode,country_of_residence_code:e.countryOfResidenceCode,personal_id_type:e.personalIdType,personal_id_number:e.personalIdNumber}}_mapBusinessProfile(e){return{address_line1:e.addressLine1,city:e.city,country:e.country,incorporation_date:e.incorporationDate,legal_name:e.legalName,name:e.name,postal_code:e.postalCode,state:e.state,tax_id:e.taxId,type:e.type,address_line2:e.addressLine2,country_code:e.countryCode,email:e.email,logo:e.logo,owner_address_line1:e.ownerAddressLine1,owner_address_line2:e.ownerAddressLine2,owner_city:e.ownerCity,owner_country_code:e.ownerCountryCode,owner_id_number:e.ownerIdNumber,owner_id_type:e.ownerIdType,owner_name:e.ownerName,owner_postal_code:e.ownerPostalCode,owner_state:e.ownerState,phone:e.phone}}}class IdentityClient{httpClient;aliases;origins;constructor(e){this.httpClient=e,this.aliases=new AliasesClient(this.httpClient),this.origins=new OriginsClient(this.httpClient)}}for(var __rspack_i in exports.AliasesClient=__webpack_exports__.AliasesClient,exports.IdentityClient=__webpack_exports__.IdentityClient,exports.OriginClient=__webpack_exports__.OriginClient,exports.OriginsClient=__webpack_exports__.OriginsClient,__webpack_exports__)-1===["AliasesClient","IdentityClient","OriginClient","OriginsClient"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './aliases/client';
|
|
1
|
+
export * from './aliases/aliases-client';
|
|
2
2
|
export * from './aliases/types';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './client';
|
|
5
|
-
export * from './origins/client';
|
|
6
|
-
export * from './origins/origin';
|
|
3
|
+
export * from './identity-client';
|
|
4
|
+
export * from './origins/origin-client';
|
|
5
|
+
export * from './origins/origins-client';
|
|
7
6
|
export * from './origins/types';
|
|
7
|
+
export * from './types';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BaseClient as e}from"@bloque/sdk-core";class t extends e{async get(e){return await this.httpClient.request({method:"GET",path:`/api/aliases?alias=${e}`})}}class a extends e{origin;constructor(e,t){super(e),this.origin=t}async assert(e){return await this.httpClient.request({method:"GET",path:`/api/origins/${this.origin}/assert?alias=${e}`})}}class i extends e{whatsapp;email;constructor(e){super(e),this.whatsapp=new a(e,"bloque-whatsapp"),this.email=new a(e,"bloque-email")}custom(e){return new a(this.httpClient,e)}async list(){return await this.httpClient.request({method:"GET",path:"/api/origins"})}async register(e,t){let
|
|
1
|
+
import{BaseClient as e}from"@bloque/sdk-core";class t extends e{async get(e){return await this.httpClient.request({method:"GET",path:`/api/aliases?alias=${e}`})}}class a extends e{origin;constructor(e,t){super(e),this.origin=t}async assert(e){return await this.httpClient.request({method:"GET",path:`/api/origins/${this.origin}/assert?alias=${e}`})}}class i extends e{whatsapp;email;constructor(e){super(e),this.whatsapp=new a(e,"bloque-whatsapp"),this.email=new a(e,"bloque-email")}custom(e){return new a(this.httpClient,e)}async list(){return await this.httpClient.request({method:"GET",path:"/api/origins"})}async register(e,t,a){let i,s=a.assertionResult,n="API_KEY"===s.challengeType?{alias:s.alias,challengeType:"API_KEY",value:{api_key:s.value.apiKey,alias:e},originalChallengeParams:s.originalChallengeParams}:{alias:e,challengeType:s.challengeType,value:s.value,originalChallengeParams:s.originalChallengeParams};return i="individual"===a.type?{assertion_result:n,extra_context:a.extraContext,type:"individual",profile:this._mapUserProfile(a.profile)}:{assertion_result:n,extra_context:a.extraContext,type:"business",profile:this._mapBusinessProfile(a.profile)},{accessToken:(await this.httpClient.request({method:"POST",path:`/api/origins/${t}/register`,body:i})).result.access_token}}_mapUserProfile(e){return{first_name:e.firstName,last_name:e.lastName,birthdate:e.birthdate,email:e.email,phone:e.phone,gender:e.gender,address_line1:e.addressLine1,address_line2:e.addressLine2,city:e.city,state:e.state,postal_code:e.postalCode,neighborhood:e.neighborhood,country_of_birth_code:e.countryOfBirthCode,country_of_residence_code:e.countryOfResidenceCode,personal_id_type:e.personalIdType,personal_id_number:e.personalIdNumber}}_mapBusinessProfile(e){return{address_line1:e.addressLine1,city:e.city,country:e.country,incorporation_date:e.incorporationDate,legal_name:e.legalName,name:e.name,postal_code:e.postalCode,state:e.state,tax_id:e.taxId,type:e.type,address_line2:e.addressLine2,country_code:e.countryCode,email:e.email,logo:e.logo,owner_address_line1:e.ownerAddressLine1,owner_address_line2:e.ownerAddressLine2,owner_city:e.ownerCity,owner_country_code:e.ownerCountryCode,owner_id_number:e.ownerIdNumber,owner_id_type:e.ownerIdType,owner_name:e.ownerName,owner_postal_code:e.ownerPostalCode,owner_state:e.ownerState,phone:e.phone}}}class s{httpClient;aliases;origins;constructor(e){this.httpClient=e,this.aliases=new t(this.httpClient),this.origins=new i(this.httpClient)}}export{t as AliasesClient,s as IdentityClient,a as OriginClient,i as OriginsClient};
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Wire types for Identity API communication (snake_case format)
|
|
4
|
+
* These types represent the raw API request/response format
|
|
5
|
+
* and should not be used directly by SDK consumers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Alias response from API
|
|
10
|
+
*/
|
|
1
11
|
export type AliasResponse = {
|
|
2
12
|
id: string;
|
|
3
13
|
alias: string;
|
|
@@ -17,6 +27,10 @@ export type AliasResponse = {
|
|
|
17
27
|
created_at: string;
|
|
18
28
|
updated_at: string;
|
|
19
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
* Base OTP structure
|
|
33
|
+
*/
|
|
20
34
|
interface OTPBase {
|
|
21
35
|
type: 'OTP';
|
|
22
36
|
params: {
|
|
@@ -26,51 +40,61 @@ interface OTPBase {
|
|
|
26
40
|
expires_at: number;
|
|
27
41
|
};
|
|
28
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
* OTP assertion for email
|
|
46
|
+
*/
|
|
29
47
|
export interface OTPAssertionEmail extends OTPBase {
|
|
30
48
|
value: OTPBase['value'] & {
|
|
31
49
|
email: string;
|
|
32
50
|
};
|
|
33
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
* OTP assertion for WhatsApp
|
|
55
|
+
*/
|
|
34
56
|
export interface OTPAssertionWhatsApp extends OTPBase {
|
|
35
57
|
value: OTPBase['value'] & {
|
|
36
58
|
phone: string;
|
|
37
59
|
};
|
|
38
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
* Combined OTP assertion type
|
|
64
|
+
*/
|
|
39
65
|
export type OTPAssertion = OTPAssertionEmail | OTPAssertionWhatsApp;
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
* Origin from API
|
|
69
|
+
*/
|
|
40
70
|
export interface Origin {
|
|
41
|
-
/**
|
|
42
|
-
* Unique namespace identifier for the origin
|
|
43
|
-
*/
|
|
44
71
|
namespace: string;
|
|
45
|
-
/**
|
|
46
|
-
* Provider type (e.g., 'evm', 'auth0', 'whatsapp', 'email', 'api-key')
|
|
47
|
-
*/
|
|
48
72
|
provider: ' evm' | 'auth0' | 'whatsapp' | 'email' | 'api-key';
|
|
49
|
-
/**
|
|
50
|
-
* Current status of the origin
|
|
51
|
-
*/
|
|
52
73
|
status: 'active' | 'inactive' | 'disabled';
|
|
53
|
-
/**
|
|
54
|
-
* Additional metadata about the origin
|
|
55
|
-
*/
|
|
56
74
|
metadata: Record<string, unknown>;
|
|
57
|
-
/**
|
|
58
|
-
* Creation timestamp (ISO 8601)
|
|
59
|
-
*/
|
|
60
75
|
created_at: string;
|
|
61
|
-
/**
|
|
62
|
-
* Last update timestamp (ISO 8601)
|
|
63
|
-
*/
|
|
64
76
|
updated_at: string;
|
|
65
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
* Signing challenge value
|
|
81
|
+
*/
|
|
66
82
|
type SigningChallengeValue = {
|
|
67
83
|
signature: string;
|
|
68
84
|
alias: string;
|
|
69
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* @internal
|
|
88
|
+
* API key value
|
|
89
|
+
*/
|
|
70
90
|
type ApiKeyValue = {
|
|
71
91
|
api_key: string;
|
|
72
92
|
alias: string;
|
|
73
93
|
};
|
|
94
|
+
/**
|
|
95
|
+
* @internal
|
|
96
|
+
* Base assertion structure
|
|
97
|
+
*/
|
|
74
98
|
type BaseAssertion<TType extends string, TValue> = {
|
|
75
99
|
alias: string;
|
|
76
100
|
challengeType: TType;
|
|
@@ -80,15 +104,28 @@ type BaseAssertion<TType extends string, TValue> = {
|
|
|
80
104
|
timestamp: number;
|
|
81
105
|
};
|
|
82
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* @internal
|
|
109
|
+
* API key assertion
|
|
110
|
+
*/
|
|
83
111
|
type ApiKeyAssertion = BaseAssertion<'API_KEY', ApiKeyValue>;
|
|
112
|
+
/**
|
|
113
|
+
* @internal
|
|
114
|
+
* Interactive assertion (signing, oauth, webauthn, etc.)
|
|
115
|
+
*/
|
|
84
116
|
type InteractiveAssertion = BaseAssertion<'REDIRECT' | 'OAUTH_REDIRECT' | 'SIGNING_CHALLENGE' | 'WEBAUTHN' | 'OTP' | 'PASSWORD', SigningChallengeValue>;
|
|
85
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @internal
|
|
119
|
+
* Combined assertion result type
|
|
120
|
+
*/
|
|
121
|
+
export type AssertionResult = ApiKeyAssertion | InteractiveAssertion;
|
|
122
|
+
/**
|
|
123
|
+
* @internal
|
|
124
|
+
* User profile for registration (snake_case API format)
|
|
125
|
+
*/
|
|
86
126
|
export type UserProfile = {
|
|
87
127
|
first_name?: string;
|
|
88
128
|
last_name?: string;
|
|
89
|
-
/**
|
|
90
|
-
* ISO 8601 formatted date string (YYYY-MM-DD)
|
|
91
|
-
*/
|
|
92
129
|
birthdate?: string;
|
|
93
130
|
email?: string;
|
|
94
131
|
phone?: string;
|
|
@@ -104,117 +141,65 @@ export type UserProfile = {
|
|
|
104
141
|
personal_id_type?: string;
|
|
105
142
|
personal_id_number?: string;
|
|
106
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
* Business profile for registration (snake_case API format)
|
|
147
|
+
*/
|
|
107
148
|
export type BusinessProfile = {
|
|
108
|
-
/**
|
|
109
|
-
* Primary business address (street address)
|
|
110
|
-
*/
|
|
111
149
|
address_line1: string;
|
|
112
|
-
/**
|
|
113
|
-
* City where business is registered
|
|
114
|
-
*/
|
|
115
150
|
city: string;
|
|
116
|
-
/**
|
|
117
|
-
* Country of incorporation (full name)
|
|
118
|
-
*/
|
|
119
151
|
country: string;
|
|
120
|
-
/**
|
|
121
|
-
* Date of incorporation or registration (YYYY-MM-DD format)
|
|
122
|
-
*/
|
|
123
152
|
incorporation_date: string;
|
|
124
|
-
/**
|
|
125
|
-
* Official registered legal name of the business
|
|
126
|
-
*/
|
|
127
153
|
legal_name: string;
|
|
128
|
-
/**
|
|
129
|
-
* Business trading name or DBA (Doing Business As)
|
|
130
|
-
*/
|
|
131
154
|
name: string;
|
|
132
|
-
/**
|
|
133
|
-
* Postal or ZIP code
|
|
134
|
-
*/
|
|
135
155
|
postal_code: string;
|
|
136
|
-
/**
|
|
137
|
-
* State, province, or region of registration
|
|
138
|
-
*/
|
|
139
156
|
state: string;
|
|
140
|
-
/**
|
|
141
|
-
* Tax identification number (EIN, VAT, RFC, etc.)
|
|
142
|
-
*/
|
|
143
157
|
tax_id: string;
|
|
144
|
-
/**
|
|
145
|
-
* Business legal structure type (LLC, Corporation, Partnership, etc.)
|
|
146
|
-
*/
|
|
147
158
|
type: string;
|
|
148
|
-
/**
|
|
149
|
-
* Secondary address line (suite, floor, etc.)
|
|
150
|
-
*/
|
|
151
159
|
address_line2?: string;
|
|
152
|
-
/**
|
|
153
|
-
* ISO country code (2 or 3 letters)
|
|
154
|
-
*/
|
|
155
160
|
country_code?: string;
|
|
156
|
-
/**
|
|
157
|
-
* Business contact email
|
|
158
|
-
*/
|
|
159
161
|
email?: string;
|
|
160
|
-
/**
|
|
161
|
-
* URL to business logo image
|
|
162
|
-
*/
|
|
163
162
|
logo?: string;
|
|
164
|
-
/**
|
|
165
|
-
* Owner's primary address
|
|
166
|
-
*/
|
|
167
163
|
owner_address_line1?: string;
|
|
168
|
-
/**
|
|
169
|
-
* Owner's secondary address line
|
|
170
|
-
*/
|
|
171
164
|
owner_address_line2?: string;
|
|
172
|
-
/**
|
|
173
|
-
* Owner's city of residence
|
|
174
|
-
*/
|
|
175
165
|
owner_city?: string;
|
|
176
|
-
/**
|
|
177
|
-
* Owner's country code
|
|
178
|
-
*/
|
|
179
166
|
owner_country_code?: string;
|
|
180
|
-
/**
|
|
181
|
-
* Owner's identification number
|
|
182
|
-
*/
|
|
183
167
|
owner_id_number?: string;
|
|
184
|
-
/**
|
|
185
|
-
* Type of identification document for owner
|
|
186
|
-
*/
|
|
187
168
|
owner_id_type?: string;
|
|
188
|
-
/**
|
|
189
|
-
* Full name of the beneficial owner or primary representative
|
|
190
|
-
*/
|
|
191
169
|
owner_name?: string;
|
|
192
|
-
/**
|
|
193
|
-
* Owner's postal code
|
|
194
|
-
*/
|
|
195
170
|
owner_postal_code?: string;
|
|
196
|
-
/**
|
|
197
|
-
* Owner's state or province
|
|
198
|
-
*/
|
|
199
171
|
owner_state?: string;
|
|
200
|
-
/**
|
|
201
|
-
* Business contact phone number
|
|
202
|
-
*/
|
|
203
172
|
phone?: string;
|
|
204
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* @internal
|
|
176
|
+
* Individual registration request
|
|
177
|
+
*/
|
|
205
178
|
export type IndividualRegisterRequest = {
|
|
206
179
|
assertion_result: AssertionResult;
|
|
207
180
|
extra_context?: Record<string, unknown>;
|
|
208
181
|
type: 'individual';
|
|
209
182
|
profile: UserProfile;
|
|
210
183
|
};
|
|
184
|
+
/**
|
|
185
|
+
* @internal
|
|
186
|
+
* Business registration request
|
|
187
|
+
*/
|
|
211
188
|
export type BusinessRegisterRequest = {
|
|
212
189
|
assertion_result: AssertionResult;
|
|
213
190
|
extra_context?: Record<string, unknown>;
|
|
214
191
|
type: 'business';
|
|
215
192
|
profile: BusinessProfile;
|
|
216
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* @internal
|
|
196
|
+
* Combined registration request type
|
|
197
|
+
*/
|
|
217
198
|
export type RegisterRequest = IndividualRegisterRequest | BusinessRegisterRequest;
|
|
199
|
+
/**
|
|
200
|
+
* @internal
|
|
201
|
+
* Registration response from API
|
|
202
|
+
*/
|
|
218
203
|
export interface RegisterResponse {
|
|
219
204
|
result: {
|
|
220
205
|
access_token: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HttpClient } from '@bloque/sdk-core';
|
|
2
2
|
import { BaseClient } from '@bloque/sdk-core';
|
|
3
|
-
import type { Origin, OTPAssertion, OTPAssertionEmail, OTPAssertionWhatsApp } from '../
|
|
4
|
-
import { OriginClient } from './origin';
|
|
3
|
+
import type { Origin, OTPAssertion, OTPAssertionEmail, OTPAssertionWhatsApp } from '../internal/wire-types';
|
|
4
|
+
import { OriginClient } from './origin-client';
|
|
5
5
|
import type { RegisterParams, RegisterResult } from './types';
|
|
6
6
|
export declare class OriginsClient extends BaseClient {
|
|
7
7
|
readonly whatsapp: OriginClient<OTPAssertionWhatsApp>;
|
|
@@ -114,7 +114,7 @@ export declare class OriginsClient extends BaseClient {
|
|
|
114
114
|
* console.log(business.accessToken); // JWT token for business
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
|
-
register(origin: string, params: RegisterParams): Promise<RegisterResult>;
|
|
117
|
+
register(alias: string, origin: string, params: RegisterParams): Promise<RegisterResult>;
|
|
118
118
|
private _mapUserProfile;
|
|
119
119
|
private _mapBusinessProfile;
|
|
120
120
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { BusinessRegisterParams, IndividualRegisterParams } from './origins/types';
|
|
2
|
-
export type CreateIdentityParams =
|
|
3
|
-
alias: string;
|
|
4
|
-
};
|
|
2
|
+
export type CreateIdentityParams = Pick<IndividualRegisterParams, 'extraContext' | 'type' | 'profile'> | Pick<BusinessRegisterParams, 'extraContext' | 'type' | 'profile'>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bloque/sdk-identity",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloque",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"node": ">=22"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@bloque/sdk-core": "0.0.
|
|
37
|
+
"@bloque/sdk-core": "0.0.24"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
File without changes
|
|
File without changes
|