@notabene/javascript-sdk 2.0.0-next.16 → 2.0.0-next.18

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
@@ -4,7 +4,6 @@ import type {
4
4
  CallbackOptions,
5
5
  ComponentMessage,
6
6
  ConnectionRequest,
7
- ConnectionResponse,
8
7
  Counterparty,
9
8
  DeclarationProof,
10
9
  Deposit,
@@ -35,11 +34,11 @@ import {
35
34
  } from './types';
36
35
  import { encodeObjectToFragment } from './utils/urls';
37
36
 
37
+ // Must be exported for React Native SDK to use
38
+ export { default as EmbeddedComponent } from './components/EmbeddedComponent';
38
39
  export type {
39
40
  ComponentMessage,
40
- EmbeddedComponent,
41
41
  ConnectionRequest,
42
- ConnectionResponse,
43
42
  HostMessage,
44
43
  Theme,
45
44
  Counterparty,
@@ -140,10 +139,10 @@ export default class Notabene {
140
139
  * @returns component URL
141
140
  * @internal
142
141
  */
143
- componentUrl<V>(
142
+ componentUrl<V, O>(
144
143
  path: string,
145
144
  value: V,
146
- configuration?: TransactionOptions,
145
+ configuration?: O,
147
146
  callbacks?: CallbackOptions,
148
147
  ): string {
149
148
  const url = new URL(this.uxUrl);
@@ -182,15 +181,16 @@ export default class Notabene {
182
181
  * @returns A new EmbeddedComponent instance
183
182
  * @internal
184
183
  */
185
- createComponent<V, R>(
184
+ createComponent<V, O>(
186
185
  path: string,
187
- value: V,
188
- options?: TransactionOptions,
186
+ value: Partial<V>,
187
+ options?: O,
189
188
  callbacks?: CallbackOptions,
190
189
  ) {
191
- return new EmbeddedComponent<V, R>(
190
+ return new EmbeddedComponent<V, O>(
192
191
  this.componentUrl(path, value, options, callbacks),
193
192
  value,
193
+ options,
194
194
  );
195
195
  }
196
196
 
@@ -207,10 +207,12 @@ export default class Notabene {
207
207
  options?: TransactionOptions,
208
208
  callbacks?: CallbackOptions,
209
209
  ) {
210
- return this.createComponent<
211
- Partial<Withdrawal>,
212
- TransactionResponse<Withdrawal>
213
- >('withdrawal-assist', value, options, callbacks);
210
+ return this.createComponent<Withdrawal, TransactionOptions>(
211
+ 'withdrawal-assist',
212
+ value,
213
+ options,
214
+ callbacks,
215
+ );
214
216
  }
215
217
 
216
218
  /**
@@ -227,10 +229,12 @@ export default class Notabene {
227
229
  options?: TransactionOptions,
228
230
  callbacks?: CallbackOptions,
229
231
  ) {
230
- return this.createComponent<
231
- Partial<Withdrawal>,
232
- TransactionResponse<Withdrawal>
233
- >('wallet-assist', value, options, callbacks);
232
+ return this.createComponent<Withdrawal, TransactionOptions>(
233
+ 'wallet-assist',
234
+ value,
235
+ options,
236
+ callbacks,
237
+ );
234
238
  }
235
239
 
236
240
  /**
@@ -247,7 +251,7 @@ export default class Notabene {
247
251
  options?: any,
248
252
  callbacks?: CallbackOptions,
249
253
  ) {
250
- return this.createComponent<Partial<Deposit>, TransactionResponse<Deposit>>(
254
+ return this.createComponent<Deposit, any>(
251
255
  'deposit-assist',
252
256
  value,
253
257
  options,
@@ -269,7 +273,7 @@ export default class Notabene {
269
273
  options?: TransactionOptions,
270
274
  callbacks?: CallbackOptions,
271
275
  ) {
272
- return this.createComponent<ConnectionRequest, ConnectionResponse>(
276
+ return this.createComponent<ConnectionRequest, TransactionOptions>(
273
277
  'connect',
274
278
  value,
275
279
  options,
@@ -291,10 +295,12 @@ export default class Notabene {
291
295
  options?: TransactionOptions,
292
296
  callbacks?: CallbackOptions,
293
297
  ) {
294
- return this.createComponent<
295
- DepositRequest,
296
- TransactionResponse<DepositRequest>
297
- >('deposit-request', value, options, callbacks);
298
+ return this.createComponent<DepositRequest, TransactionOptions>(
299
+ 'deposit-request',
300
+ value,
301
+ options,
302
+ callbacks,
303
+ );
298
304
  }
299
305
 
300
306
  /**
package/src/types.ts CHANGED
@@ -355,17 +355,6 @@ export interface ConnectionRequest extends ComponentRequest {
355
355
  asset: TransactionAsset;
356
356
  }
357
357
 
358
- /**
359
- * An object representing a connection response
360
- * @public
361
- */
362
- export interface ConnectionResponse extends ComponentResponse {
363
- value: ConnectionRequest;
364
- ivms: IVMS101;
365
- proof?: OwnershipProof;
366
- txCreate?: V1Transaction;
367
- }
368
-
369
358
  /**
370
359
  * The verification status of a transaction
371
360
  * @public
@@ -469,19 +458,19 @@ export const enum CMType {
469
458
  RESULT = 'result',
470
459
  READY = 'ready',
471
460
  INVALID = 'invalid',
472
- MODAL = 'openModal',
473
461
  ERROR = 'error',
474
- CLOSE = 'closeModal',
475
462
  CANCEL = 'cancel',
476
463
  }
477
464
 
478
465
  /**
479
466
  * Represents a completed component message
467
+ * @typeParam T - The overall Value type being returned
468
+ * @param response - The Response object which wraps T
480
469
  * @public
481
470
  */
482
- export type Completed = {
471
+ export type Completed<T> = {
483
472
  type: CMType.COMPLETE;
484
- response: ComponentResponse;
473
+ response: TransactionResponse<T>;
485
474
  };
486
475
 
487
476
  /**
@@ -493,8 +482,8 @@ export type Ready = {
493
482
  };
494
483
 
495
484
  /**
496
- * Represents a resize request component message
497
- * @public
485
+ * Represents a resize request component message. This is handled by the library.
486
+ * @internal
498
487
  */
499
488
  export type ResizeRequest = {
500
489
  type: CMType.RESIZE;
@@ -503,6 +492,7 @@ export type ResizeRequest = {
503
492
 
504
493
  /**
505
494
  * Represents an error component message
495
+ * @param message - Error message
506
496
  * @public
507
497
  */
508
498
  export type Error = {
@@ -512,7 +502,7 @@ export type Error = {
512
502
 
513
503
  /**
514
504
  * Represents a cancel component message
515
- * @public
505
+ * @internal
516
506
  */
517
507
  export type Cancel = {
518
508
  type: CMType.CANCEL;
@@ -520,11 +510,14 @@ export type Cancel = {
520
510
 
521
511
  /**
522
512
  * Represents an invalid value component message
523
- * @public
513
+ * @typeParam T - The overall Value type being returned
514
+ * @param value - The current Partial value
515
+ * @param errors - Array of validation errors
516
+ * @internal
524
517
  */
525
- export type InvalidValue = {
518
+ export type InvalidValue<T> = {
526
519
  type: CMType.INVALID;
527
- value: any;
520
+ value: Partial<T>;
528
521
  errors: ValidationError[];
529
522
  };
530
523
 
@@ -532,13 +525,13 @@ export type InvalidValue = {
532
525
  * Component Message
533
526
  * @public
534
527
  */
535
- export type ComponentMessage =
536
- | Completed
528
+ export type ComponentMessage<T> =
529
+ | Completed<T>
537
530
  | Cancel
538
531
  | Error
539
532
  | Ready
540
533
  | ResizeRequest
541
- | InvalidValue;
534
+ | InvalidValue<T>;
542
535
 
543
536
  /**
544
537
  * Host Message Types
@@ -551,19 +544,22 @@ export const enum HMType {
551
544
  }
552
545
 
553
546
  /**
554
- * Represents an update value host message
547
+ * Represents an update value host message. This is sent from Host to component.
548
+ * @typeParam T - The overall Value type being sent
549
+ * @typeParam O - The Option type being sent
555
550
  * @public
556
551
  */
557
- export type UpdateValue = {
552
+ export type UpdateValue<T, O> = {
558
553
  type: HMType.UPDATE;
559
- value: ComponentRequest;
554
+ value: Partial<T>;
555
+ options?: O;
560
556
  };
561
557
 
562
558
  /**
563
559
  * Host Messages
564
560
  * @public
565
561
  */
566
- export type HostMessage = UpdateValue;
562
+ export type HostMessage<T, O> = UpdateValue<T, O>;
567
563
 
568
564
  /**
569
565
  * Options for callback and redirect URIs
@@ -592,6 +588,7 @@ export enum ProofStatus {
592
588
  export enum ProofTypes {
593
589
  SelfDeclaration = 'self-declaration',
594
590
  PersonalSignEIP191 = 'eip-191',
591
+ SIWE = 'siwe',
595
592
  PersonalSignEIP712 = 'eip-712',
596
593
  PersonalSignBIP137 = 'bip-137',
597
594
  PersonalSignXPUB = 'xpub',
@@ -619,6 +616,7 @@ export interface SignatureProof extends OwnershipProof {
619
616
  | ProofTypes.PersonalSignEIP191
620
617
  | ProofTypes.PersonalSignEIP712
621
618
  | ProofTypes.PersonalSignBIP137
619
+ | ProofTypes.SIWE
622
620
  | ProofTypes.PersonalSignXPUB;
623
621
  proof: string;
624
622
  attestation: string;
@@ -1,9 +1,9 @@
1
1
  import { ComponentMessage, HostMessage } from '../types';
2
2
 
3
- export type MessageCallback = (message: ComponentMessage) => void;
3
+ export type MessageCallback<T> = (message: ComponentMessage<T>) => void;
4
4
 
5
- export class MessageEventManager {
6
- private listeners: Map<string, Set<MessageCallback>> = new Map();
5
+ export class MessageEventManager<T, O> {
6
+ private listeners: Map<string, Set<MessageCallback<T>>> = new Map();
7
7
  private port?: MessagePort;
8
8
 
9
9
  constructor() {
@@ -16,14 +16,14 @@ export class MessageEventManager {
16
16
  this.port.start();
17
17
  }
18
18
 
19
- on(messageType: string, callback: MessageCallback): void {
19
+ on(messageType: string, callback: MessageCallback<T>): void {
20
20
  if (!this.listeners.has(messageType)) {
21
21
  this.listeners.set(messageType, new Set());
22
22
  }
23
23
  this.listeners.get(messageType)!.add(callback);
24
24
  }
25
25
 
26
- off(messageType: string, callback: MessageCallback): void {
26
+ off(messageType: string, callback: MessageCallback<T>): void {
27
27
  const callbacks = this.listeners.get(messageType);
28
28
  if (callbacks) {
29
29
  callbacks.delete(callback);
@@ -33,7 +33,7 @@ export class MessageEventManager {
33
33
  }
34
34
  }
35
35
 
36
- private handleMessage(event: MessageEvent): void {
36
+ private handleMessage(event: MessageEvent<ComponentMessage<T>>): void {
37
37
  // console.log('received message', event.data);
38
38
  const message = event.data;
39
39
  if (typeof message === 'object' && message !== null && 'type' in message) {
@@ -46,7 +46,7 @@ export class MessageEventManager {
46
46
  }
47
47
 
48
48
  // Method to send messages through the port
49
- send(message: HostMessage): void {
49
+ send(message: HostMessage<T, O>): void {
50
50
  if (this.port) {
51
51
  this.port.postMessage(message);
52
52
  }
@@ -1,9 +1,14 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { HMType, UpdateValue } from '../../types';
2
+ import {
3
+ HMType,
4
+ type TransactionOptions,
5
+ type UpdateValue,
6
+ type Withdrawal,
7
+ } from '../../types';
3
8
  import { MessageEventManager } from '../MessageEventManager';
4
9
 
5
10
  describe('MessageEventManager', () => {
6
- let messageEventManager: MessageEventManager;
11
+ let messageEventManager: MessageEventManager<Withdrawal, TransactionOptions>;
7
12
  let mockPort: MessagePort;
8
13
 
9
14
  beforeEach(() => {
@@ -13,7 +18,10 @@ describe('MessageEventManager', () => {
13
18
  start: vi.fn(),
14
19
  } as unknown as MessagePort;
15
20
 
16
- messageEventManager = new MessageEventManager();
21
+ messageEventManager = new MessageEventManager<
22
+ Withdrawal,
23
+ TransactionOptions
24
+ >();
17
25
  });
18
26
 
19
27
  describe('setPort', () => {
@@ -73,7 +81,7 @@ describe('MessageEventManager', () => {
73
81
  });
74
82
 
75
83
  it('should send messages through the port', () => {
76
- const message: UpdateValue = {
84
+ const message: UpdateValue<Withdrawal, TransactionOptions> = {
77
85
  type: HMType.UPDATE,
78
86
  value: { requestId: 'id' },
79
87
  };