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

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,81 @@ 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
299
  destinations: Destination[];
176
300
  };
177
301
 
302
+ type RequestID = UUID;
303
+
304
+ /**
305
+ * An abstract request for communicating with a component
306
+ * @public
307
+ */
308
+ export interface ComponentRequest {
309
+ requestId?: RequestID;
310
+ customer?: Counterparty;
311
+ }
312
+
178
313
  /**
179
314
  * An abstract transaction object
180
315
  * @public
181
316
  */
182
- export interface Transaction {
317
+ export interface Transaction extends ComponentRequest {
183
318
  agent: Agent;
184
- customer?: Counterparty;
185
319
  counterparty: Counterparty;
186
320
  asset: TransactionAsset;
187
321
  amountDecimal: number;
188
- // transactionBlockchainInfo?: TransactionBlockchainInfo;
189
- customAssetPrice?: {
322
+ proof?: OwnershipProof;
323
+ assetPrice?: {
190
324
  price: number;
191
- currency: string;
325
+ currency: ISOCurrency;
192
326
  };
193
327
  }
194
328
 
@@ -211,13 +345,22 @@ export interface Deposit extends OriginatorFields, Transaction {}
211
345
  export interface DepositRequest extends DepositRequestFields, Transaction {}
212
346
 
213
347
  /**
214
- * Configuration options for Transaction components
348
+ * An object representing a connection request
215
349
  * @public
216
350
  */
351
+ export interface ConnectionRequest extends ComponentRequest {
352
+ asset: TransactionAsset;
353
+ }
217
354
 
218
- export interface TransactionOptions {
219
- microTransactionAddress?: BlockchainAddress;
220
- proofFallbacks?: ProofTypes[];
355
+ /**
356
+ * An object representing a connection response
357
+ * @public
358
+ */
359
+ export interface ConnectionResponse extends ComponentResponse {
360
+ value: ConnectionRequest;
361
+ ivms: IVMS101;
362
+ proof?: OwnershipProof;
363
+ txCreate?: V1Transaction;
221
364
  }
222
365
 
223
366
  /**
@@ -232,17 +375,11 @@ export enum Status {
232
375
  BANNED = 'banned',
233
376
  }
234
377
 
235
- type V1Asset =
236
- | {
237
- caip19: CAIP19;
238
- }
239
- | string;
240
-
378
+ type V1Asset = NotabeneAsset | { caip19: CAIP19 };
241
379
  /**
242
380
  * Transaction payload suitable for calling Notabene v1 tx/create
243
381
  * @public
244
382
  */
245
-
246
383
  export type V1Transaction = {
247
384
  transactionAsset: V1Asset;
248
385
  transactionAmount: string;
@@ -253,46 +390,68 @@ export type V1Transaction = {
253
390
  originator: Originator;
254
391
  beneficiary: Beneficiary;
255
392
  };
393
+
394
+ export interface ComponentResponse {
395
+ requestID: RequestID;
396
+ valid: boolean;
397
+ status: Status;
398
+ errors: ValidationError[];
399
+ }
256
400
  /**
257
401
  * The response of a transaction
258
402
  * @public
259
403
  */
260
-
261
- export type TransactionResponse = {
262
- value: Transaction;
404
+ export interface TransactionResponse<V> extends ComponentResponse {
405
+ value: V;
263
406
  ivms: IVMS101;
264
407
  proof?: OwnershipProof;
265
- valid: boolean;
266
- status: Status;
267
- errors: ValidationError[];
268
408
  txCreate?: V1Transaction;
269
- };
409
+ }
270
410
 
411
+ /**
412
+ * Validation error
413
+ * @public
414
+ */
271
415
  export type ValidationError = {
272
416
  attribute: string;
273
417
  message: string;
274
418
  };
275
419
 
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';
420
+ /**
421
+ * Field properties
422
+ * @public
423
+ */
424
+ export type FieldOptions =
425
+ | boolean
426
+ | {
427
+ optional: boolean; // Shown but optional
428
+ transmit: boolean; // Transmit as part of IVMS 101 to counterparty
429
+ };
288
430
 
289
- export type FieldsProps = {
290
- [name in FieldName]?: FieldProps;
431
+ export type FieldTypes = {
432
+ naturalPerson?: NaturalPersonFields;
433
+ legalPerson?: LegalPersonFields;
291
434
  };
435
+ /**
436
+ * Configuration options for Transaction components
437
+ * @public
438
+ */
439
+ export interface TransactionOptions {
440
+ proofs?: {
441
+ microTransfer?: {
442
+ destination: BlockchainAddress;
443
+ timeout?: number; // Time to verify in seconds
444
+ };
445
+ fallbacks?: ProofTypes[];
446
+ };
447
+ allowedAgentTypes?: AgentType[]; // Defaults to All
448
+ allowedCounterpartyTypes?: PersonType[]; // Defaults to All
449
+ fields?: FieldTypes;
450
+ }
292
451
 
293
452
  /**
294
453
  * Component Message Types
295
- * @internal
454
+ * @public
296
455
  */
297
456
  export const enum CMType {
298
457
  COMPLETE = 'complete',
@@ -306,46 +465,53 @@ export const enum CMType {
306
465
  CANCEL = 'cancel',
307
466
  }
308
467
 
468
+ /**
469
+ * Represents a completed component message
470
+ * @public
471
+ */
309
472
  export type Completed = {
310
473
  type: CMType.COMPLETE;
311
- response: TransactionResponse;
312
- };
313
-
314
- export type Result = {
315
- type: CMType.RESULT;
316
- reqid: RequestID;
317
- response: TransactionResponse;
474
+ response: ComponentResponse;
318
475
  };
319
476
 
477
+ /**
478
+ * Represents a ready component message
479
+ * @public
480
+ */
320
481
  export type Ready = {
321
482
  type: CMType.READY;
322
483
  };
323
484
 
485
+ /**
486
+ * Represents a resize request component message
487
+ * @public
488
+ */
324
489
  export type ResizeRequest = {
325
490
  type: CMType.RESIZE;
326
491
  height: number;
327
492
  };
328
493
 
494
+ /**
495
+ * Represents an error component message
496
+ * @public
497
+ */
329
498
  export type Error = {
330
499
  type: CMType.ERROR;
331
500
  message: string;
332
501
  };
333
502
 
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
-
503
+ /**
504
+ * Represents a cancel component message
505
+ * @public
506
+ */
345
507
  export type Cancel = {
346
508
  type: CMType.CANCEL;
347
509
  };
348
510
 
511
+ /**
512
+ * Represents an invalid value component message
513
+ * @public
514
+ */
349
515
  export type InvalidValue = {
350
516
  type: CMType.INVALID;
351
517
  value: any;
@@ -354,24 +520,19 @@ export type InvalidValue = {
354
520
 
355
521
  /**
356
522
  * Component Message
357
- * @internal
523
+ * @public
358
524
  */
359
525
  export type ComponentMessage =
360
526
  | Completed
361
527
  | Cancel
362
528
  | Error
363
- | Result
364
529
  | Ready
365
530
  | ResizeRequest
366
- | ModalRequest
367
- | InvalidValue
368
- | CloseModal;
369
-
370
- export type RequestID = string;
531
+ | InvalidValue;
371
532
 
372
533
  /**
373
534
  * Host Message Types
374
- * @internal
535
+ * @public
375
536
  */
376
537
 
377
538
  export const enum HMType {
@@ -379,23 +540,25 @@ export const enum HMType {
379
540
  REQUEST_RESPONSE = 'requestResponse',
380
541
  }
381
542
 
543
+ /**
544
+ * Represents an update value host message
545
+ * @public
546
+ */
382
547
  export type UpdateValue = {
383
548
  type: HMType.UPDATE;
384
- value: Partial<Transaction>;
385
- };
386
-
387
- export type RequestResponse = {
388
- type: HMType.REQUEST_RESPONSE;
389
- reqid: RequestID;
549
+ value: ComponentRequest;
390
550
  };
391
551
 
392
552
  /**
393
553
  * Host Messages
394
- * @internal
554
+ * @public
395
555
  */
556
+ export type HostMessage = UpdateValue;
396
557
 
397
- export type HostMessage = UpdateValue | RequestResponse;
398
-
558
+ /**
559
+ * Options for callback and redirect URIs
560
+ * @public
561
+ */
399
562
  export interface CallbackOptions {
400
563
  callback?: URI;
401
564
  redirectUri?: URI;
@@ -415,7 +578,7 @@ export enum ProofStatus {
415
578
  /**
416
579
  * The type of Proofs supported
417
580
  * @public
418
- **/
581
+ */
419
582
  export enum ProofTypes {
420
583
  SelfDeclaration = 'self-declaration',
421
584
  PersonalSignEIP191 = 'eip-191',
@@ -425,6 +588,7 @@ export enum ProofTypes {
425
588
  MicroTransfer = 'microtransfer',
426
589
  Screenshot = 'screenshot',
427
590
  }
591
+
428
592
  /**
429
593
  * Ownership Proof
430
594
  * @public
@@ -469,7 +633,7 @@ export interface MicroTransferProof extends OwnershipProof {
469
633
  type: ProofTypes.MicroTransfer;
470
634
  txhash: string;
471
635
  chain: CAIP2;
472
- amount: number;
636
+ amountSubunits: string;
473
637
  }
474
638
 
475
639
  /**
@@ -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