@notabene/javascript-sdk 2.0.0-next.6 → 2.0.0-next.8

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/notabene.ts CHANGED
@@ -6,6 +6,8 @@ import type {
6
6
  ComponentMessage,
7
7
  Counterparty,
8
8
  DeclarationProof,
9
+ Deposit,
10
+ DepositRequest,
9
11
  Destination,
10
12
  HostMessage,
11
13
  IVMS101,
@@ -20,6 +22,7 @@ import type {
20
22
  Theme,
21
23
  Transaction,
22
24
  TransactionAsset,
25
+ TransactionOptions,
23
26
  VASP,
24
27
  Wallet,
25
28
  Withdrawal,
@@ -35,7 +38,9 @@ export type {
35
38
  Theme,
36
39
  Counterparty,
37
40
  Withdrawal,
41
+ Deposit,
38
42
  Transaction,
43
+ DepositRequest,
39
44
  TransactionResponse,
40
45
  Destination as destination,
41
46
  TransactionAsset,
@@ -54,6 +59,7 @@ export type {
54
59
  Agent,
55
60
  AgentType,
56
61
  OwnershipProof,
62
+ TransactionOptions,
57
63
  };
58
64
 
59
65
  /**
@@ -66,7 +72,7 @@ export interface NotabeneConfig {
66
72
  authToken?: string;
67
73
  uxUrl?: string;
68
74
  theme?: Theme;
69
- dictionary?: { [key: string]: string };
75
+ locale?: string;
70
76
  }
71
77
 
72
78
  /**
@@ -80,20 +86,20 @@ export default class Notabene {
80
86
  private authToken?: string;
81
87
  private uxUrl: string;
82
88
  private theme?: Theme;
83
- private dictionary?: { [key: string]: string };
89
+ private locale?: string;
84
90
 
85
91
  constructor(config: NotabeneConfig) {
86
92
  this.uxUrl = config.uxUrl || 'https://connect.notabene.id';
87
93
  this.nodeUrl = config.nodeUrl;
88
94
  this.authToken = config.authToken;
89
95
  this.theme = config.theme;
90
- this.dictionary = config.dictionary;
96
+ this.locale = config.locale;
91
97
  }
92
98
 
93
99
  public componentUrl(
94
100
  path: string,
95
101
  value: Partial<Transaction>,
96
- configuration?: any,
102
+ configuration?: TransactionOptions,
97
103
  callbacks?: CallbackOptions,
98
104
  ): string {
99
105
  const url = new URL(this.uxUrl);
@@ -110,8 +116,8 @@ export default class Notabene {
110
116
  if (this.theme) {
111
117
  url.searchParams.set('theme', JSON.stringify(this.theme));
112
118
  }
113
- if (this.dictionary) {
114
- url.searchParams.set('dictionary', JSON.stringify(this.dictionary));
119
+ if (this.locale) {
120
+ url.searchParams.set('locale', this.locale);
115
121
  }
116
122
  if (callbacks) {
117
123
  if (callbacks.callback)
@@ -125,7 +131,7 @@ export default class Notabene {
125
131
  public createComponent(
126
132
  path: string,
127
133
  value: Partial<Transaction>,
128
- options?: any,
134
+ options?: TransactionOptions,
129
135
  callbacks?: CallbackOptions,
130
136
  ) {
131
137
  return new EmbeddedComponent(
@@ -136,12 +142,36 @@ export default class Notabene {
136
142
 
137
143
  public createWithdrawalAssist(
138
144
  value: Partial<Withdrawal>,
139
- options?: any,
145
+ options?: TransactionOptions,
140
146
  callbacks?: CallbackOptions,
141
147
  ) {
142
148
  return this.createComponent('withdrawal-assist', value, options, callbacks);
143
149
  }
144
150
 
151
+ public createDepositAssist(
152
+ value: Partial<Deposit>,
153
+ options?: any,
154
+ callbacks?: CallbackOptions,
155
+ ) {
156
+ return this.createComponent('deposit-assist', value, options, callbacks);
157
+ }
158
+
159
+ public createConnect(
160
+ value: Partial<Withdrawal>,
161
+ options?: TransactionOptions,
162
+ callbacks?: CallbackOptions,
163
+ ) {
164
+ return this.createComponent('connect', value, options, callbacks);
165
+ }
166
+
167
+ public createDepositRequest(
168
+ value: Partial<DepositRequest>,
169
+ options?: TransactionOptions,
170
+ callbacks?: CallbackOptions,
171
+ ) {
172
+ return this.createComponent('deposit-request', value, options, callbacks);
173
+ }
174
+
145
175
  public decodeFragmentToObject(fragment: string): Record<string, string> {
146
176
  const pairs = fragment.slice(1).split('&');
147
177
  return pairs.reduce(
@@ -153,50 +183,4 @@ export default class Notabene {
153
183
  {} as Record<string, string>,
154
184
  );
155
185
  }
156
-
157
- // private openModal(url: string): void {
158
- // if (this.modal) {
159
- // this.closeModal();
160
- // }
161
- // this.modal = document.createElement('div');
162
- // this.modal.style.position = 'fixed';
163
- // this.modal.style.top = '0';
164
- // this.modal.style.left = '0';
165
- // this.modal.style.width = '100%';
166
- // this.modal.style.height = '100%';
167
- // this.modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
168
- // this.modal.style.display = 'flex';
169
- // this.modal.style.justifyContent = 'center';
170
- // this.modal.style.alignItems = 'center';
171
- // const iframe = document.createElement('iframe');
172
- // iframe.src = url;
173
- // iframe.setAttribute('allowtransparency', 'true');
174
- // // iframe.allowtransparency = true;
175
- // iframe.style.backgroundColor = 'transparent';
176
- // iframe.style.width = '90%';
177
- // iframe.style.height = '90%';
178
- // iframe.style.border = 'none';
179
- // iframe.style.overflow = 'hidden';
180
- // this.modal.appendChild(iframe);
181
- // document.body.appendChild(this.modal);
182
- // this.modal.addEventListener('click', () => {
183
- // console.log('click');
184
- // this.closeModal();
185
- // });
186
- // document.addEventListener('keydown', ({ key }) => {
187
- // console.log(`key: ${key}`);
188
- // if (key === 'Escape') {
189
- // console.log('esc');
190
- // this.closeModal();
191
- // }
192
- // });
193
- // }
194
-
195
- // private closeModal(): void {
196
- // if (this.modal) {
197
- // console.log('this.closeModal');
198
- // this.modal.remove();
199
- // this.modal = undefined;
200
- // }
201
- // }
202
186
  }
package/src/types.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import {
2
+ Beneficiary,
2
3
  DateAndPlaceOfBirth,
3
4
  IVMS101,
4
5
  NationalIdentification,
6
+ Originator,
5
7
  } from './ivms/types';
6
8
 
7
9
  export type { IVMS101 };
@@ -23,13 +25,18 @@ export type NotabeneAsset = string;
23
25
  export type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
24
26
 
25
27
  export type BlockchainAddress = string;
26
- export type TravelAddress = string;
28
+ export type TravelAddress = `ta${string}`;
29
+ export type CryptoCredential = `${string}.${string}.mastercard`;
27
30
 
28
31
  /**
29
32
  * The destination of a transaction either a blockchain address, a CAIP-19 address, or a travel address.
30
33
  * @public
31
34
  */
32
- export type Destination = BlockchainAddress | CAIP10 | TravelAddress;
35
+ export type Destination =
36
+ | BlockchainAddress
37
+ | CAIP10
38
+ | CryptoCredential
39
+ | TravelAddress;
33
40
  export type Source = BlockchainAddress | CAIP10;
34
41
  export type URI = string;
35
42
  export type DID = `did:${string}:${string}`;
@@ -45,10 +52,6 @@ export type Theme = {
45
52
  logo: string;
46
53
  };
47
54
 
48
- export enum ComponentTypes {
49
- WITHDRAW_ASSIST = 'WITHDRAW_ASSIST',
50
- }
51
-
52
55
  // export type TransactionType = 'VASP_2_VASP' | 'SELF_HOSTED';
53
56
 
54
57
  // export type TransactionTypeAllowed =
@@ -160,14 +163,18 @@ export interface LegalPerson extends Counterparty {
160
163
  logo?: string;
161
164
  }
162
165
 
163
- export type OriginatorFields = {
166
+ type OriginatorFields = {
164
167
  source?: Source;
165
168
  };
166
169
 
167
- export type BeneficiaryFields = {
170
+ type BeneficiaryFields = {
168
171
  destination?: Destination;
169
172
  };
170
173
 
174
+ type DepositRequestFields = {
175
+ destinations: Destination[];
176
+ };
177
+
171
178
  /**
172
179
  * An abstract transaction object
173
180
  * @public
@@ -190,12 +197,29 @@ export interface Transaction {
190
197
  * @public
191
198
  */
192
199
  export interface Withdrawal extends BeneficiaryFields, Transaction {}
200
+
193
201
  /**
194
202
  * An object representing a deposit transaction
195
203
  * @public
196
204
  */
197
205
  export interface Deposit extends OriginatorFields, Transaction {}
198
206
 
207
+ /**
208
+ * An object representing a request for a deposit
209
+ * @public
210
+ */
211
+ export interface DepositRequest extends DepositRequestFields, Transaction {}
212
+
213
+ /**
214
+ * Configuration options for Transaction components
215
+ * @public
216
+ */
217
+
218
+ export interface TransactionOptions {
219
+ microTransactionAddress?: BlockchainAddress;
220
+ proofFallbacks?: ProofTypes[];
221
+ }
222
+
199
223
  /**
200
224
  * The verification status of a transaction
201
225
  * @public
@@ -208,6 +232,27 @@ export enum Status {
208
232
  BANNED = 'banned',
209
233
  }
210
234
 
235
+ type V1Asset =
236
+ | {
237
+ caip19: CAIP19;
238
+ }
239
+ | string;
240
+
241
+ /**
242
+ * Transaction payload suitable for calling Notabene v1 tx/create
243
+ * @public
244
+ */
245
+
246
+ export type V1Transaction = {
247
+ transactionAsset: V1Asset;
248
+ transactionAmount: string;
249
+ originatorEqualsBeneficiary?: boolean;
250
+ originatorVASPdid: DID;
251
+ beneficiaryVASPdid: DID;
252
+ beneficiaryProof: OwnershipProof;
253
+ originator: Originator;
254
+ beneficiary: Beneficiary;
255
+ };
211
256
  /**
212
257
  * The response of a transaction
213
258
  * @public
@@ -220,6 +265,7 @@ export type TransactionResponse = {
220
265
  valid: boolean;
221
266
  status: Status;
222
267
  errors: ValidationError[];
268
+ txCreate?: V1Transaction;
223
269
  };
224
270
 
225
271
  export type ValidationError = {
@@ -244,16 +290,6 @@ export type FieldsProps = {
244
290
  [name in FieldName]?: FieldProps;
245
291
  };
246
292
 
247
- export type WalletNotSupportedFlow = {
248
- flow: 'WALLET_NOT_SUPPORTED';
249
- action: 'DECLARATION' | 'REJECT';
250
- };
251
-
252
- // This is going to be union type
253
- export type Fallback = WalletNotSupportedFlow;
254
-
255
- export type OptInFeature = 'REUSE_ADDRESS_OWNERSHIP_PROOF';
256
-
257
293
  /**
258
294
  * Component Message Types
259
295
  * @internal
@@ -47,9 +47,8 @@ export class MessageEventManager {
47
47
 
48
48
  // Method to send messages through the port
49
49
  send(message: HostMessage): void {
50
- if (!this.port) {
51
- throw new Error('No port set');
50
+ if (this.port) {
51
+ this.port.postMessage(message);
52
52
  }
53
- this.port.postMessage(message);
54
53
  }
55
54
  }
@@ -7,6 +7,8 @@ import {
7
7
  CAIP2_MATCHER,
8
8
  } from './caip';
9
9
 
10
+ const LOCALE = new RegExp(/^[a-z]{2}(-[A-Z]{2})?$/);
11
+
10
12
  // Arbitraries
11
13
  export const arbitraryCAIP10 = (): fc.Arbitrary<CAIP10> =>
12
14
  fc.stringMatching(CAIP10_MATCHER) as fc.Arbitrary<CAIP10>;
@@ -19,3 +21,6 @@ export const arbitraryCAIP19 = (): fc.Arbitrary<CAIP19> =>
19
21
 
20
22
  export const arbitraryCAIP220 = (): fc.Arbitrary<CAIP220> =>
21
23
  fc.stringMatching(CAIP220_MATCHER) as fc.Arbitrary<CAIP220>;
24
+
25
+ export const arbitraryLocale = (): fc.Arbitrary<string> =>
26
+ fc.stringMatching(LOCALE) as fc.Arbitrary<string>;