@notabene/javascript-sdk 2.0.0-next.10 → 2.0.0-next.12

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/src/types.ts CHANGED
@@ -1,31 +1,92 @@
1
1
  import {
2
+ Address,
2
3
  Beneficiary,
3
- DateAndPlaceOfBirth,
4
+ ISOCountryCode,
5
+ ISODate,
4
6
  IVMS101,
5
7
  NationalIdentification,
6
8
  Originator,
7
9
  } from './ivms/types';
8
10
 
11
+ /**
12
+ * Interoperable Virtual Asset Service Provider (VASP) Messaging Standard
13
+ * @public
14
+ */
9
15
  export type { IVMS101 };
10
16
 
17
+ /**
18
+ * UUID v4
19
+ * @public
20
+ */
21
+ export type UUID = string;
22
+
23
+ /**
24
+ * Chain Agnostic Blockchain Identifier
25
+ * Represents a blockchain in a chain-agnostic way
26
+ * Format: `namespace:reference`
27
+ * @example "eip155:1" for Ethereum Mainnet
28
+ * @public
29
+ */
11
30
  export type CAIP2 = `${string}:${string}`;
31
+
32
+ /**
33
+ * Chain Agnostic Account Identifier
34
+ * Represents an account on a specific blockchain
35
+ * Format: `{caip2}:{address}`
36
+ * @example "eip155:1:0x742d35Cc6634C0532925a3b844Bc454e4438f44e" for an Ethereum account
37
+ * @public
38
+ */
12
39
  export type CAIP10 = `${CAIP2}:${string}`;
40
+
41
+ /**
42
+ * Chain Agnostic Asset Identifier
43
+ * Represents an asset on a specific blockchain
44
+ * Format: `{caip2}/{asset_namespace}:{asset_reference}`
45
+ * @example "eip155:1/erc20:0x6b175474e89094c44da98b954eedeac495271d0f" for DAI on Ethereum
46
+ * @public
47
+ */
13
48
  export type CAIP19 = `${CAIP2}/${string}:${string}`;
49
+
50
+ /**
51
+ * Chain Agnostic Payload Identifier
52
+ * @public
53
+ */
14
54
  export type CAIP220 = string;
15
55
 
56
+ /**
57
+ * Digital Token Identifier
58
+ * @public
59
+ */
16
60
  export type DTI = string;
61
+
62
+ /**
63
+ * Notabene Asset Identifier
64
+ * @public
65
+ */
17
66
  export type NotabeneAsset = string;
18
67
 
19
68
  /**
20
69
  * The asset of a transaction either a Notabene asset, a CAIP-19 asset, or a DTI.
21
- *
22
70
  * @public
23
71
  */
24
-
25
72
  export type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
26
73
 
74
+ /**
75
+ * A blockchain address
76
+ * @public
77
+ */
27
78
  export type BlockchainAddress = string;
79
+
80
+ /**
81
+ * A travel address
82
+ * @public
83
+ */
28
84
  export type TravelAddress = `ta${string}`;
85
+
86
+ /**
87
+ * A crypto credential
88
+ * @public
89
+ */
29
90
  export type CryptoCredential = `${string}.${string}.mastercard`;
30
91
 
31
92
  /**
@@ -37,10 +98,37 @@ export type Destination =
37
98
  | CAIP10
38
99
  | CryptoCredential
39
100
  | TravelAddress;
101
+
102
+ /**
103
+ * The source of a transaction
104
+ * @public
105
+ */
40
106
  export type Source = BlockchainAddress | CAIP10;
107
+
108
+ /**
109
+ * A Uniform Resource Identifier
110
+ * @public
111
+ */
41
112
  export type URI = string;
113
+
114
+ /**
115
+ * A Decentralized Identifier
116
+ * @public
117
+ */
42
118
  export type DID = `did:${string}:${string}`;
43
119
 
120
+ /**
121
+ * A LEI Legal Entity Identifier
122
+ * @public
123
+ */
124
+ export type LEI = string;
125
+
126
+ /**
127
+ * 3 letter ISO currency code
128
+ * @public
129
+ */
130
+ export type ISOCurrency = string;
131
+
44
132
  /**
45
133
  * The theme of the Notabene SDK
46
134
  * @public
@@ -52,23 +140,10 @@ export type Theme = {
52
140
  logo: string;
53
141
  };
54
142
 
55
- // export type TransactionType = 'VASP_2_VASP' | 'SELF_HOSTED';
56
-
57
- // export type TransactionTypeAllowed =
58
- // | 'ALL'
59
- // | 'VASP_2_VASP_ONLY'
60
- // | 'FIRST_PARTY_ONLY';
61
-
62
- // export type NonCustodialDeclarationType =
63
- // | 'SIGNATURE'
64
- // | 'DECLARATION'
65
- // | 'SIGNATURE_AND_DECLARATION';
66
-
67
143
  /**
68
144
  * The type of Agent. Either a wallet or a VASP
69
145
  * @public
70
146
  */
71
-
72
147
  export enum AgentType {
73
148
  PRIVATE = 'WALLET',
74
149
  VASP = 'VASP',
@@ -78,28 +153,14 @@ export enum AgentType {
78
153
  * Who is the agent acting on behalf of the counterparty
79
154
  * @public
80
155
  */
81
- export declare interface Agent {
156
+ export interface Agent {
82
157
  did: DID;
83
158
  type: AgentType;
84
- logo?: string;
85
- url?: string;
159
+ logo?: URI;
160
+ url?: URI;
86
161
  name?: string;
87
162
  verified?: boolean;
88
163
  }
89
- export type OwnershipProofInput = {
90
- type?: string | null;
91
- proof?: string | null;
92
- };
93
-
94
- export type TransactionBlockchainInfo = {
95
- destination?: string | null;
96
- origin?: string | null;
97
- };
98
-
99
- export type CountryType = {
100
- id: string;
101
- name: string;
102
- };
103
164
 
104
165
  /**
105
166
  * The type of counterparty. Either a natural person or a legal person. If the customer is the same as the counterparty then the counterparty is a self.
@@ -116,9 +177,12 @@ export enum PersonType {
116
177
  * @public
117
178
  */
118
179
  export interface VASP extends Agent {
119
- url?: string;
120
- name?: string;
180
+ lei?: LEI;
181
+ logo?: URI;
182
+ website?: URI;
183
+ countryOfRegistration?: ISOCountryCode;
121
184
  }
185
+
122
186
  /**
123
187
  * A wallet agent acting on behalf of the counterparty
124
188
  * @public
@@ -135,21 +199,47 @@ export interface Wallet extends Agent {
135
199
  export interface Counterparty {
136
200
  name?: string;
137
201
  accountNumber?: string;
138
- did?: string;
139
- geographicAddress?: string;
202
+ did?: DID;
140
203
  type?: PersonType;
141
204
  verified?: boolean;
205
+ geographicAddress?: Address;
206
+ nationalIdentification?: NationalIdentification;
207
+ website?: URI;
208
+ phone?: string;
142
209
  }
210
+
143
211
  /**
144
212
  * A counterparty object representing a natural person
145
213
  * @public
146
214
  */
147
215
  export interface NaturalPerson extends Counterparty {
148
216
  type: PersonType.NATURAL;
149
- nationalIdentification?: NationalIdentification;
150
- dateAndPlaceOfBirth?: DateAndPlaceOfBirth;
217
+ dateOfBirth?: ISODate;
218
+ placeOfBirth?: string;
219
+ countryOfResidence?: ISOCountryCode;
151
220
  name: string;
152
221
  }
222
+ /**
223
+ * Field names for NaturalPerson
224
+ * @public
225
+ */
226
+ export type NaturalPersonFieldName =
227
+ | 'name' // Full legal name
228
+ | 'website' // Primary website of entity
229
+ | 'email' // Contact email
230
+ | 'phone' // Contact mobile phone
231
+ | 'geographicAddress' // Address string
232
+ | 'nationalIdentification' // National Identification number
233
+ | 'dateOfBirth' // Date of Birty YYYY-MM-DD
234
+ | 'placeOfBirth' // Place of Birth
235
+ | 'countryOfResidence'; // ISO Country code of residence of Natural Person
236
+ /**
237
+ * Field properties by field name
238
+ * @public
239
+ */
240
+ export type NaturalPersonFields = {
241
+ [name in NaturalPersonFieldName]?: FieldOptions;
242
+ };
153
243
 
154
244
  /**
155
245
  * A counterparty object representing a legal person
@@ -158,37 +248,83 @@ export interface NaturalPerson extends Counterparty {
158
248
  export interface LegalPerson extends Counterparty {
159
249
  type: PersonType.LEGAL;
160
250
  name: string;
161
- lei?: string;
162
- url?: string;
163
- logo?: string;
251
+ lei?: LEI;
252
+ logo?: URI;
253
+ countryOfRegistration?: ISOCountryCode;
164
254
  }
255
+ /**
256
+ * Field names for LegalPerson
257
+ * @public
258
+ */
259
+
260
+ export type LegalPersonFieldName =
261
+ | 'name' // Full legal name
262
+ | 'lei' // Legal Entity Identifier
263
+ | 'website' // Primary website of entity
264
+ | 'email' // Contact email
265
+ | 'phone' // Contact mobile phone
266
+ | 'geographicAddress' // Address string
267
+ | 'nationalIdentification' // National Identification number
268
+ | 'countryOfRegistration'; // ISO Country code of registration of Legal Person
269
+
270
+ /**
271
+ * Field properties by field name
272
+ * @public
273
+ */
274
+ export type LegalPersonFields = {
275
+ [name in LegalPersonFieldName]?: FieldOptions;
276
+ };
165
277
 
278
+ /**
279
+ * Fields specific to the originator of a transaction
280
+ * @public
281
+ */
166
282
  type OriginatorFields = {
167
283
  source?: Source;
168
284
  };
169
285
 
286
+ /**
287
+ * Fields specific to the beneficiary of a transaction
288
+ * @public
289
+ */
170
290
  type BeneficiaryFields = {
171
291
  destination?: Destination;
172
292
  };
173
293
 
294
+ /**
295
+ * Fields specific to a deposit request
296
+ * @public
297
+ */
174
298
  type DepositRequestFields = {
175
- destinations: Destination[];
299
+ destination: BlockchainAddress | CAIP10;
300
+ travelAddress?: TravelAddress;
301
+ cryptoCredential?: CryptoCredential;
176
302
  };
177
303
 
304
+ type RequestID = UUID;
305
+
306
+ /**
307
+ * An abstract request for communicating with a component
308
+ * @public
309
+ */
310
+ export interface ComponentRequest {
311
+ requestId?: RequestID;
312
+ customer?: Counterparty;
313
+ }
314
+
178
315
  /**
179
316
  * An abstract transaction object
180
317
  * @public
181
318
  */
182
- export interface Transaction {
319
+ export interface Transaction extends ComponentRequest {
183
320
  agent: Agent;
184
- customer?: Counterparty;
185
321
  counterparty: Counterparty;
186
322
  asset: TransactionAsset;
187
323
  amountDecimal: number;
188
- // transactionBlockchainInfo?: TransactionBlockchainInfo;
189
- customAssetPrice?: {
324
+ proof?: OwnershipProof;
325
+ assetPrice?: {
190
326
  price: number;
191
- currency: string;
327
+ currency: ISOCurrency;
192
328
  };
193
329
  }
194
330
 
@@ -211,13 +347,22 @@ export interface Deposit extends OriginatorFields, Transaction {}
211
347
  export interface DepositRequest extends DepositRequestFields, Transaction {}
212
348
 
213
349
  /**
214
- * Configuration options for Transaction components
350
+ * An object representing a connection request
215
351
  * @public
216
352
  */
353
+ export interface ConnectionRequest extends ComponentRequest {
354
+ asset: TransactionAsset;
355
+ }
217
356
 
218
- export interface TransactionOptions {
219
- microTransactionAddress?: BlockchainAddress;
220
- proofFallbacks?: ProofTypes[];
357
+ /**
358
+ * An object representing a connection response
359
+ * @public
360
+ */
361
+ export interface ConnectionResponse extends ComponentResponse {
362
+ value: ConnectionRequest;
363
+ ivms: IVMS101;
364
+ proof?: OwnershipProof;
365
+ txCreate?: V1Transaction;
221
366
  }
222
367
 
223
368
  /**
@@ -232,17 +377,11 @@ export enum Status {
232
377
  BANNED = 'banned',
233
378
  }
234
379
 
235
- type V1Asset =
236
- | {
237
- caip19: CAIP19;
238
- }
239
- | string;
240
-
380
+ type V1Asset = NotabeneAsset | { caip19: CAIP19 };
241
381
  /**
242
382
  * Transaction payload suitable for calling Notabene v1 tx/create
243
383
  * @public
244
384
  */
245
-
246
385
  export type V1Transaction = {
247
386
  transactionAsset: V1Asset;
248
387
  transactionAmount: string;
@@ -253,46 +392,69 @@ export type V1Transaction = {
253
392
  originator: Originator;
254
393
  beneficiary: Beneficiary;
255
394
  };
395
+
396
+ export interface ComponentResponse {
397
+ requestID: RequestID;
398
+ valid: boolean;
399
+ status: Status;
400
+ errors: ValidationError[];
401
+ }
256
402
  /**
257
403
  * The response of a transaction
258
404
  * @public
259
405
  */
260
-
261
- export type TransactionResponse = {
262
- value: Transaction;
406
+ export interface TransactionResponse<V> extends ComponentResponse {
407
+ value: V;
263
408
  ivms: IVMS101;
264
409
  proof?: OwnershipProof;
265
- valid: boolean;
266
- status: Status;
267
- errors: ValidationError[];
268
410
  txCreate?: V1Transaction;
269
- };
411
+ }
270
412
 
413
+ /**
414
+ * Validation error
415
+ * @public
416
+ */
271
417
  export type ValidationError = {
272
418
  attribute: string;
273
419
  message: string;
274
420
  };
275
421
 
276
- export type FieldProps = {
277
- forceDisplay?: boolean; // instead of beneficiaryDetails - defaults to false
278
- optional?: boolean; // bypass the jurisdiction rules validation - defaults to false
279
- };
280
-
281
- export type FieldName =
282
- | 'counterparty'
283
- | 'geographicAddress'
284
- | 'firstName'
285
- | 'name'
286
- | 'nationalIdentification'
287
- | 'dateAndPlaceOfBirth';
422
+ /**
423
+ * Field properties
424
+ * @public
425
+ */
426
+ export type FieldOptions =
427
+ | boolean
428
+ | {
429
+ optional: boolean; // Shown but optional
430
+ transmit: boolean; // Transmit as part of IVMS 101 to counterparty
431
+ };
288
432
 
289
- export type FieldsProps = {
290
- [name in FieldName]?: FieldProps;
433
+ export type FieldTypes = {
434
+ naturalPerson?: NaturalPersonFields;
435
+ legalPerson?: LegalPersonFields;
291
436
  };
437
+ /**
438
+ * Configuration options for Transaction components
439
+ * @public
440
+ */
441
+ export interface TransactionOptions {
442
+ proofs?: {
443
+ microTransfer?: {
444
+ destination: BlockchainAddress;
445
+ amountSubunits: string;
446
+ timeout?: number; // Time to verify in seconds
447
+ };
448
+ fallbacks?: ProofTypes[];
449
+ };
450
+ allowedAgentTypes?: AgentType[]; // Defaults to All
451
+ allowedCounterpartyTypes?: PersonType[]; // Defaults to All
452
+ fields?: FieldTypes;
453
+ }
292
454
 
293
455
  /**
294
456
  * Component Message Types
295
- * @internal
457
+ * @public
296
458
  */
297
459
  export const enum CMType {
298
460
  COMPLETE = 'complete',
@@ -306,46 +468,53 @@ export const enum CMType {
306
468
  CANCEL = 'cancel',
307
469
  }
308
470
 
471
+ /**
472
+ * Represents a completed component message
473
+ * @public
474
+ */
309
475
  export type Completed = {
310
476
  type: CMType.COMPLETE;
311
- response: TransactionResponse;
312
- };
313
-
314
- export type Result = {
315
- type: CMType.RESULT;
316
- reqid: RequestID;
317
- response: TransactionResponse;
477
+ response: ComponentResponse;
318
478
  };
319
479
 
480
+ /**
481
+ * Represents a ready component message
482
+ * @public
483
+ */
320
484
  export type Ready = {
321
485
  type: CMType.READY;
322
486
  };
323
487
 
488
+ /**
489
+ * Represents a resize request component message
490
+ * @public
491
+ */
324
492
  export type ResizeRequest = {
325
493
  type: CMType.RESIZE;
326
494
  height: number;
327
495
  };
328
496
 
497
+ /**
498
+ * Represents an error component message
499
+ * @public
500
+ */
329
501
  export type Error = {
330
502
  type: CMType.ERROR;
331
503
  message: string;
332
504
  };
333
505
 
334
- export type ModalRequest = {
335
- type: CMType.MODAL;
336
- url: string;
337
- reqid: RequestID;
338
- };
339
-
340
- export type CloseModal = {
341
- type: CMType.CLOSE;
342
- reqid: RequestID;
343
- };
344
-
506
+ /**
507
+ * Represents a cancel component message
508
+ * @public
509
+ */
345
510
  export type Cancel = {
346
511
  type: CMType.CANCEL;
347
512
  };
348
513
 
514
+ /**
515
+ * Represents an invalid value component message
516
+ * @public
517
+ */
349
518
  export type InvalidValue = {
350
519
  type: CMType.INVALID;
351
520
  value: any;
@@ -354,24 +523,19 @@ export type InvalidValue = {
354
523
 
355
524
  /**
356
525
  * Component Message
357
- * @internal
526
+ * @public
358
527
  */
359
528
  export type ComponentMessage =
360
529
  | Completed
361
530
  | Cancel
362
531
  | Error
363
- | Result
364
532
  | Ready
365
533
  | ResizeRequest
366
- | ModalRequest
367
- | InvalidValue
368
- | CloseModal;
369
-
370
- export type RequestID = string;
534
+ | InvalidValue;
371
535
 
372
536
  /**
373
537
  * Host Message Types
374
- * @internal
538
+ * @public
375
539
  */
376
540
 
377
541
  export const enum HMType {
@@ -379,23 +543,25 @@ export const enum HMType {
379
543
  REQUEST_RESPONSE = 'requestResponse',
380
544
  }
381
545
 
546
+ /**
547
+ * Represents an update value host message
548
+ * @public
549
+ */
382
550
  export type UpdateValue = {
383
551
  type: HMType.UPDATE;
384
- value: Partial<Transaction>;
385
- };
386
-
387
- export type RequestResponse = {
388
- type: HMType.REQUEST_RESPONSE;
389
- reqid: RequestID;
552
+ value: ComponentRequest;
390
553
  };
391
554
 
392
555
  /**
393
556
  * Host Messages
394
- * @internal
557
+ * @public
395
558
  */
559
+ export type HostMessage = UpdateValue;
396
560
 
397
- export type HostMessage = UpdateValue | RequestResponse;
398
-
561
+ /**
562
+ * Options for callback and redirect URIs
563
+ * @public
564
+ */
399
565
  export interface CallbackOptions {
400
566
  callback?: URI;
401
567
  redirectUri?: URI;
@@ -415,7 +581,7 @@ export enum ProofStatus {
415
581
  /**
416
582
  * The type of Proofs supported
417
583
  * @public
418
- **/
584
+ */
419
585
  export enum ProofTypes {
420
586
  SelfDeclaration = 'self-declaration',
421
587
  PersonalSignEIP191 = 'eip-191',
@@ -425,6 +591,7 @@ export enum ProofTypes {
425
591
  MicroTransfer = 'microtransfer',
426
592
  Screenshot = 'screenshot',
427
593
  }
594
+
428
595
  /**
429
596
  * Ownership Proof
430
597
  * @public
@@ -469,7 +636,7 @@ export interface MicroTransferProof extends OwnershipProof {
469
636
  type: ProofTypes.MicroTransfer;
470
637
  txhash: string;
471
638
  chain: CAIP2;
472
- amount: number;
639
+ amountSubunits: string;
473
640
  }
474
641
 
475
642
  /**
@@ -75,7 +75,7 @@ describe('MessageEventManager', () => {
75
75
  it('should send messages through the port', () => {
76
76
  const message: UpdateValue = {
77
77
  type: HMType.UPDATE,
78
- value: { asset: 'USDC' },
78
+ value: { requestId: 'id' },
79
79
  };
80
80
  messageEventManager.send(message);
81
81