@notabene/javascript-sdk 1.34.0 → 2.0.0-next.2

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.
Files changed (73) hide show
  1. package/.gitlab-ci.yml +12 -1
  2. package/.husky/commit-msg +0 -0
  3. package/.husky/pre-commit +0 -0
  4. package/.husky/pre-push +1 -1
  5. package/.vscode/extensions.json +1 -5
  6. package/.vscode/settings.json +4 -4
  7. package/.yarn/releases/yarn-berry.cjs +925 -0
  8. package/.yarnrc.yml +3 -0
  9. package/README.md +126 -69
  10. package/api-extractor.json +434 -0
  11. package/dist/notabene.cjs +1 -0
  12. package/dist/notabene.d.ts +678 -0
  13. package/dist/notabene.js +187 -0
  14. package/dist/tsdoc-metadata.json +11 -0
  15. package/eslint.config.js +24 -0
  16. package/etc/javascript-sdk.api.md +363 -0
  17. package/index.html +137 -0
  18. package/package.json +27 -53
  19. package/src/__tests__/notabene.test.ts +116 -0
  20. package/src/arbitraries.ts +13 -0
  21. package/src/components/EmbeddedComponent.ts +110 -0
  22. package/src/components/__tests__/EmbeddedComponent.test.ts +160 -0
  23. package/src/ivms/types.ts +2 -0
  24. package/src/notabene.ts +173 -289
  25. package/src/types.ts +380 -49
  26. package/src/utils/MessageEventManager.ts +55 -0
  27. package/src/utils/__tests__/MessageEventManager.test.ts +95 -0
  28. package/src/utils/arbitraries.ts +21 -0
  29. package/src/utils/caip.ts +16 -0
  30. package/src/utils/urls.ts +15 -0
  31. package/temp/javascript-sdk.api.json +3509 -0
  32. package/temp/javascript-sdk.api.md +363 -0
  33. package/ts-out/src/__tests__/notabene.test.d.ts +1 -0
  34. package/ts-out/src/__tests__/notabene.test.js +88 -0
  35. package/ts-out/src/arbitraries.d.ts +4 -0
  36. package/ts-out/src/arbitraries.js +8 -0
  37. package/ts-out/src/components/EmbeddedComponent.d.ts +25 -0
  38. package/ts-out/src/components/EmbeddedComponent.js +87 -0
  39. package/ts-out/src/components/__tests__/EmbeddedComponent.test.d.ts +1 -0
  40. package/ts-out/src/components/__tests__/EmbeddedComponent.test.js +132 -0
  41. package/ts-out/src/ivms/types.d.ts +252 -0
  42. package/ts-out/src/ivms/types.js +1 -0
  43. package/ts-out/src/notabene.d.ts +35 -0
  44. package/ts-out/src/notabene.js +59 -0
  45. package/ts-out/src/types.d.ts +357 -0
  46. package/ts-out/src/types.js +85 -0
  47. package/ts-out/src/utils/MessageEventManager.d.ts +12 -0
  48. package/ts-out/src/utils/MessageEventManager.js +45 -0
  49. package/ts-out/src/utils/__tests__/MessageEventManager.test.d.ts +1 -0
  50. package/ts-out/src/utils/__tests__/MessageEventManager.test.js +73 -0
  51. package/ts-out/src/utils/arbitraries.d.ts +6 -0
  52. package/ts-out/src/utils/arbitraries.js +7 -0
  53. package/ts-out/src/utils/caip.d.ts +13 -0
  54. package/ts-out/src/utils/caip.js +15 -0
  55. package/ts-out/src/utils/urls.d.ts +1 -0
  56. package/ts-out/src/utils/urls.js +14 -0
  57. package/ts-out/tsconfig.tsbuildinfo +1 -0
  58. package/tsconfig.json +15 -11
  59. package/tsconfig.tsbuildinfo +1 -0
  60. package/vite.config.js +13 -0
  61. package/.envrc.template +0 -1
  62. package/.eslintignore +0 -3
  63. package/.eslintrc.js +0 -13
  64. package/.nvmrc +0 -1
  65. package/.tool-versions +0 -3
  66. package/dist/es/index.js +0 -1
  67. package/dist/lib/index.js +0 -376
  68. package/jest.config.js +0 -5
  69. package/public/index.html +0 -93
  70. package/public/js/.gitkeep +0 -0
  71. package/src/lib/index.ts +0 -2
  72. package/src/module/index.ts +0 -10
  73. package/src/zoidComponentProps.ts +0 -81
@@ -0,0 +1,357 @@
1
+ import { DateAndPlaceOfBirth, IVMS101, NationalIdentification } from './ivms/types';
2
+ export type { IVMS101 };
3
+ export type CAIP2 = string;
4
+ export type CAIP10 = string;
5
+ export type CAIP19 = string;
6
+ export type CAIP220 = string;
7
+ export type DTI = string;
8
+ export type NotabeneAsset = string;
9
+ /**
10
+ * The asset of a transaction either a Notabene asset, a CAIP-19 asset, or a DTI.
11
+ *
12
+ * @public
13
+ */
14
+ export type TransactionAsset = NotabeneAsset | CAIP19 | DTI;
15
+ export type BlockchainAddress = string;
16
+ export type TravelAddress = string;
17
+ /**
18
+ * The destination of a transaction either a blockchain address, a CAIP-19 address, or a travel address.
19
+ * @public
20
+ */
21
+ export type Destination = BlockchainAddress | CAIP19 | TravelAddress;
22
+ export type Source = BlockchainAddress | CAIP19;
23
+ export type URI = string;
24
+ export type DID = string;
25
+ /**
26
+ * The theme of the Notabene SDK
27
+ * @public
28
+ */
29
+ export type Theme = {
30
+ primaryColor: string;
31
+ secondaryColor: string;
32
+ fontFamily: string;
33
+ logo: string;
34
+ };
35
+ export declare enum ComponentTypes {
36
+ WITHDRAW_ASSIST = "WITHDRAW_ASSIST"
37
+ }
38
+ export type TransactionType = 'VASP_2_VASP' | 'SELF_HOSTED';
39
+ export type TransactionTypeAllowed = 'ALL' | 'VASP_2_VASP_ONLY' | 'FIRST_PARTY_ONLY';
40
+ export type NonCustodialDeclarationType = 'SIGNATURE' | 'DECLARATION' | 'SIGNATURE_AND_DECLARATION';
41
+ /**
42
+ * The type of Agent. Either a wallet or a VASP
43
+ * @public
44
+ */
45
+ export declare enum AgentType {
46
+ PRIVATE = "WALLET",
47
+ VASP = "VASP"
48
+ }
49
+ /**
50
+ * Who is the agent acting on behalf of the counterparty
51
+ * @public
52
+ */
53
+ export declare interface Agent {
54
+ did: DID;
55
+ type: AgentType;
56
+ logo?: string;
57
+ url?: string;
58
+ name?: string;
59
+ verified?: boolean;
60
+ }
61
+ export type OwnershipProofInput = {
62
+ type?: string | null;
63
+ proof?: string | null;
64
+ };
65
+ export type TransactionBlockchainInfo = {
66
+ destination?: string | null;
67
+ origin?: string | null;
68
+ };
69
+ export type CountryType = {
70
+ id: string;
71
+ name: string;
72
+ };
73
+ /**
74
+ * 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.
75
+ * @public
76
+ */
77
+ export declare enum PersonType {
78
+ NATURAL = "natural",
79
+ LEGAL = "legal",
80
+ SELF = "self"
81
+ }
82
+ /**
83
+ * A VASP agent acting on behalf of the counterparty
84
+ * @public
85
+ */
86
+ export interface VASP extends Agent {
87
+ url?: string;
88
+ name?: string;
89
+ }
90
+ /**
91
+ * A wallet agent acting on behalf of the counterparty
92
+ * @public
93
+ */
94
+ export interface Wallet extends Agent {
95
+ proof: OwnershipProof;
96
+ wallet_connect_id?: string;
97
+ }
98
+ /**
99
+ * The counterparty of a transaction.
100
+ * @public
101
+ */
102
+ export interface Counterparty {
103
+ name?: string;
104
+ accountNumber?: string;
105
+ did?: string;
106
+ geographicAddress?: string;
107
+ type?: PersonType;
108
+ verified?: boolean;
109
+ }
110
+ /**
111
+ * A counterparty object representing a natural person
112
+ * @public
113
+ */
114
+ export interface NaturalPerson extends Counterparty {
115
+ type: PersonType.NATURAL;
116
+ nationalIdentification?: NationalIdentification;
117
+ dateAndPlaceOfBirth?: DateAndPlaceOfBirth;
118
+ name: string;
119
+ }
120
+ /**
121
+ * A counterparty object representing a legal person
122
+ * @public
123
+ */
124
+ export interface LegalPerson extends Counterparty {
125
+ type: PersonType.LEGAL;
126
+ name: string;
127
+ lei?: string;
128
+ url?: string;
129
+ logo?: string;
130
+ }
131
+ export type OriginatorFields = {
132
+ source?: Source;
133
+ };
134
+ export type BeneficiaryFields = {
135
+ destination?: Destination;
136
+ };
137
+ /**
138
+ * An abstract transaction object
139
+ * @public
140
+ */
141
+ export interface Transaction {
142
+ agent: Agent;
143
+ customer?: Counterparty;
144
+ counterparty: Counterparty;
145
+ asset: TransactionAsset;
146
+ amountDecimal: number;
147
+ customAssetPrice?: {
148
+ price: number;
149
+ currency: string;
150
+ };
151
+ }
152
+ /**
153
+ * An object representing a withdrawal transaction
154
+ * @public
155
+ */
156
+ export interface Withdrawal extends BeneficiaryFields, Transaction {
157
+ }
158
+ /**
159
+ * An object representing a deposit transaction
160
+ * @public
161
+ */
162
+ export interface Deposit extends OriginatorFields, Transaction {
163
+ }
164
+ /**
165
+ * The verification status of a transaction
166
+ * @public
167
+ */
168
+ export declare enum Status {
169
+ EMPTY = "empty",
170
+ VERIFY = "verify",
171
+ PENDING = "pending",
172
+ VERIFIED = "verified",
173
+ BANNED = "banned"
174
+ }
175
+ /**
176
+ * The response of a transaction
177
+ * @public
178
+ */
179
+ export type TransactionResponse = {
180
+ value: Transaction;
181
+ ivms: IVMS101;
182
+ proof?: OwnershipProof;
183
+ valid: boolean;
184
+ status: Status;
185
+ errors: ValidationError[];
186
+ };
187
+ export type ValidationError = {
188
+ attribute: string;
189
+ message: string;
190
+ };
191
+ export type FieldProps = {
192
+ forceDisplay?: boolean;
193
+ optional?: boolean;
194
+ };
195
+ export type FieldName = 'counterparty' | 'geographicAddress' | 'firstName' | 'name' | 'nationalIdentification' | 'dateAndPlaceOfBirth';
196
+ export type FieldsProps = {
197
+ [name in FieldName]?: FieldProps;
198
+ };
199
+ export type WalletNotSupportedFlow = {
200
+ flow: 'WALLET_NOT_SUPPORTED';
201
+ action: 'DECLARATION' | 'REJECT';
202
+ };
203
+ export type Fallback = WalletNotSupportedFlow;
204
+ export type OptInFeature = 'REUSE_ADDRESS_OWNERSHIP_PROOF';
205
+ /**
206
+ * Component Message Types
207
+ * @internal
208
+ */
209
+ export declare const enum CMType {
210
+ COMPLETE = "complete",
211
+ RESIZE = "resize",
212
+ RESULT = "result",
213
+ READY = "ready",
214
+ INVALID = "invalid",
215
+ MODAL = "openModal",
216
+ ERROR = "error",
217
+ CLOSE = "closeModal",
218
+ CANCEL = "cancel"
219
+ }
220
+ export type Completed = {
221
+ type: CMType.COMPLETE;
222
+ response: TransactionResponse;
223
+ };
224
+ export type Result = {
225
+ type: CMType.RESULT;
226
+ reqid: RequestID;
227
+ response: TransactionResponse;
228
+ };
229
+ export type Ready = {
230
+ type: CMType.READY;
231
+ };
232
+ export type ResizeRequest = {
233
+ type: CMType.RESIZE;
234
+ height: number;
235
+ };
236
+ export type Error = {
237
+ type: CMType.ERROR;
238
+ message: string;
239
+ };
240
+ export type ModalRequest = {
241
+ type: CMType.MODAL;
242
+ url: string;
243
+ reqid: RequestID;
244
+ };
245
+ export type CloseModal = {
246
+ type: CMType.CLOSE;
247
+ reqid: RequestID;
248
+ };
249
+ export type Cancel = {
250
+ type: CMType.CANCEL;
251
+ };
252
+ export type InvalidValue = {
253
+ type: CMType.INVALID;
254
+ value: any;
255
+ errors: ValidationError[];
256
+ };
257
+ /**
258
+ * Component Message
259
+ * @internal
260
+ */
261
+ export type ComponentMessage = Completed | Cancel | Error | Result | Ready | ResizeRequest | ModalRequest | InvalidValue | CloseModal;
262
+ export type RequestID = string;
263
+ /**
264
+ * Host Message Types
265
+ * @internal
266
+ */
267
+ export declare const enum HMType {
268
+ UPDATE = "update",
269
+ REQUEST_RESPONSE = "requestResponse"
270
+ }
271
+ export type UpdateValue = {
272
+ type: HMType.UPDATE;
273
+ value: Partial<Transaction>;
274
+ };
275
+ export type RequestResponse = {
276
+ type: HMType.REQUEST_RESPONSE;
277
+ reqid: RequestID;
278
+ };
279
+ /**
280
+ * Host Messages
281
+ * @internal
282
+ */
283
+ export type HostMessage = UpdateValue | RequestResponse;
284
+ export interface CallbackOptions {
285
+ callback?: URI;
286
+ redirectUri?: URI;
287
+ }
288
+ /**
289
+ * Status of the proof
290
+ * @public
291
+ */
292
+ export declare enum ProofStatus {
293
+ PENDING = "pending",// Verification is pending
294
+ FAILED = "rejected",// Rejected
295
+ FLAGGED = "flagged",// Flagged for manual review
296
+ VERIFIED = "verified"
297
+ }
298
+ /**
299
+ * The type of Proofs supported
300
+ * @public
301
+ **/
302
+ export declare enum ProofTypes {
303
+ SelfDeclaration = "self-declaration",
304
+ PersonalSignEIP191 = "eip-191",
305
+ PersonalSignEIP712 = "eip-712",
306
+ PersonalSignBIP137 = "bip-137",
307
+ PersonalSignXPUB = "xpub",
308
+ MicroTransfer = "microtransfer",
309
+ Screenshot = "screenshot"
310
+ }
311
+ /**
312
+ * Ownership Proof
313
+ * @public
314
+ */
315
+ export interface OwnershipProof {
316
+ type: ProofTypes;
317
+ status: ProofStatus;
318
+ did: DID;
319
+ address: CAIP10;
320
+ }
321
+ /**
322
+ * Ownership Proof using Message Signature
323
+ * @public
324
+ */
325
+ export interface SignatureProof extends OwnershipProof {
326
+ type: ProofTypes.PersonalSignEIP191 | ProofTypes.PersonalSignEIP712 | ProofTypes.PersonalSignBIP137 | ProofTypes.PersonalSignXPUB;
327
+ proof: string;
328
+ attestation: string;
329
+ wallet_provider: string;
330
+ }
331
+ /**
332
+ * Ownership Proof using Self Declaration
333
+ * @public
334
+ */
335
+ export interface DeclarationProof extends OwnershipProof {
336
+ type: ProofTypes.SelfDeclaration;
337
+ attestation: string;
338
+ confirmed: boolean;
339
+ }
340
+ /**
341
+ * Ownership Proof using Micro Transfer
342
+ * @public
343
+ */
344
+ export interface MicroTransferProof extends OwnershipProof {
345
+ type: ProofTypes.MicroTransfer;
346
+ txhash: string;
347
+ chain: CAIP2;
348
+ amount: number;
349
+ }
350
+ /**
351
+ * Ownership Proof using Screenshot
352
+ * @public
353
+ */
354
+ export interface ScreenshotProof extends OwnershipProof {
355
+ type: ProofTypes.Screenshot;
356
+ url: string;
357
+ }
@@ -0,0 +1,85 @@
1
+ export var ComponentTypes;
2
+ (function (ComponentTypes) {
3
+ ComponentTypes["WITHDRAW_ASSIST"] = "WITHDRAW_ASSIST";
4
+ })(ComponentTypes || (ComponentTypes = {}));
5
+ /**
6
+ * The type of Agent. Either a wallet or a VASP
7
+ * @public
8
+ */
9
+ export var AgentType;
10
+ (function (AgentType) {
11
+ AgentType["PRIVATE"] = "WALLET";
12
+ AgentType["VASP"] = "VASP";
13
+ })(AgentType || (AgentType = {}));
14
+ /**
15
+ * 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.
16
+ * @public
17
+ */
18
+ export var PersonType;
19
+ (function (PersonType) {
20
+ PersonType["NATURAL"] = "natural";
21
+ PersonType["LEGAL"] = "legal";
22
+ PersonType["SELF"] = "self";
23
+ })(PersonType || (PersonType = {}));
24
+ /**
25
+ * The verification status of a transaction
26
+ * @public
27
+ */
28
+ export var Status;
29
+ (function (Status) {
30
+ Status["EMPTY"] = "empty";
31
+ Status["VERIFY"] = "verify";
32
+ Status["PENDING"] = "pending";
33
+ Status["VERIFIED"] = "verified";
34
+ Status["BANNED"] = "banned";
35
+ })(Status || (Status = {}));
36
+ /**
37
+ * Component Message Types
38
+ * @internal
39
+ */
40
+ export var CMType;
41
+ (function (CMType) {
42
+ CMType["COMPLETE"] = "complete";
43
+ CMType["RESIZE"] = "resize";
44
+ CMType["RESULT"] = "result";
45
+ CMType["READY"] = "ready";
46
+ CMType["INVALID"] = "invalid";
47
+ CMType["MODAL"] = "openModal";
48
+ CMType["ERROR"] = "error";
49
+ CMType["CLOSE"] = "closeModal";
50
+ CMType["CANCEL"] = "cancel";
51
+ })(CMType || (CMType = {}));
52
+ /**
53
+ * Host Message Types
54
+ * @internal
55
+ */
56
+ export var HMType;
57
+ (function (HMType) {
58
+ HMType["UPDATE"] = "update";
59
+ HMType["REQUEST_RESPONSE"] = "requestResponse";
60
+ })(HMType || (HMType = {}));
61
+ /**
62
+ * Status of the proof
63
+ * @public
64
+ */
65
+ export var ProofStatus;
66
+ (function (ProofStatus) {
67
+ ProofStatus["PENDING"] = "pending";
68
+ ProofStatus["FAILED"] = "rejected";
69
+ ProofStatus["FLAGGED"] = "flagged";
70
+ ProofStatus["VERIFIED"] = "verified";
71
+ })(ProofStatus || (ProofStatus = {}));
72
+ /**
73
+ * The type of Proofs supported
74
+ * @public
75
+ **/
76
+ export var ProofTypes;
77
+ (function (ProofTypes) {
78
+ ProofTypes["SelfDeclaration"] = "self-declaration";
79
+ ProofTypes["PersonalSignEIP191"] = "eip-191";
80
+ ProofTypes["PersonalSignEIP712"] = "eip-712";
81
+ ProofTypes["PersonalSignBIP137"] = "bip-137";
82
+ ProofTypes["PersonalSignXPUB"] = "xpub";
83
+ ProofTypes["MicroTransfer"] = "microtransfer";
84
+ ProofTypes["Screenshot"] = "screenshot";
85
+ })(ProofTypes || (ProofTypes = {}));
@@ -0,0 +1,12 @@
1
+ import { ComponentMessage, HostMessage } from '../types';
2
+ export type MessageCallback = (message: ComponentMessage) => void;
3
+ export declare class MessageEventManager {
4
+ private listeners;
5
+ private port?;
6
+ constructor();
7
+ setPort(port: MessagePort): void;
8
+ on(messageType: string, callback: MessageCallback): void;
9
+ off(messageType: string, callback: MessageCallback): void;
10
+ private handleMessage;
11
+ send(message: HostMessage): void;
12
+ }
@@ -0,0 +1,45 @@
1
+ export class MessageEventManager {
2
+ listeners = new Map();
3
+ port;
4
+ constructor() {
5
+ this.handleMessage = this.handleMessage.bind(this);
6
+ }
7
+ setPort(port) {
8
+ this.port = port;
9
+ this.port.onmessage = this.handleMessage;
10
+ this.port.start();
11
+ }
12
+ on(messageType, callback) {
13
+ if (!this.listeners.has(messageType)) {
14
+ this.listeners.set(messageType, new Set());
15
+ }
16
+ this.listeners.get(messageType).add(callback);
17
+ }
18
+ off(messageType, callback) {
19
+ const callbacks = this.listeners.get(messageType);
20
+ if (callbacks) {
21
+ callbacks.delete(callback);
22
+ if (callbacks.size === 0) {
23
+ this.listeners.delete(messageType);
24
+ }
25
+ }
26
+ }
27
+ handleMessage(event) {
28
+ console.log('received message', event.data);
29
+ const message = event.data;
30
+ if (typeof message === 'object' && message !== null && 'type' in message) {
31
+ const messageType = message.type;
32
+ const callbacks = this.listeners.get(messageType);
33
+ if (callbacks) {
34
+ callbacks.forEach((callback) => callback(message));
35
+ }
36
+ }
37
+ }
38
+ // Method to send messages through the port
39
+ send(message) {
40
+ if (!this.port) {
41
+ throw new Error('No port set');
42
+ }
43
+ this.port.postMessage(message);
44
+ }
45
+ }
@@ -0,0 +1,73 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { HMType } from '../../types';
3
+ import { MessageEventManager } from '../MessageEventManager';
4
+ describe('MessageEventManager', () => {
5
+ let messageEventManager;
6
+ let mockPort;
7
+ beforeEach(() => {
8
+ mockPort = {
9
+ onmessage: null,
10
+ postMessage: vi.fn(),
11
+ start: vi.fn(),
12
+ };
13
+ messageEventManager = new MessageEventManager();
14
+ });
15
+ describe('setPort', () => {
16
+ beforeEach(() => {
17
+ messageEventManager.setPort(mockPort);
18
+ });
19
+ it('should start the port when initialized', () => {
20
+ expect(mockPort.start).toHaveBeenCalled();
21
+ });
22
+ it('should subscribe and receive messages of a specific type', () => {
23
+ const readyHandler = vi.fn();
24
+ messageEventManager.on('ready', readyHandler);
25
+ const readyMessage = { type: 'ready' };
26
+ mockPort.onmessage({ data: readyMessage });
27
+ expect(readyHandler).toHaveBeenCalledWith(readyMessage);
28
+ });
29
+ it('should not call handlers for different message types', () => {
30
+ const updateHandler = vi.fn();
31
+ const errorHandler = vi.fn();
32
+ messageEventManager.on('update', updateHandler);
33
+ messageEventManager.on('error', errorHandler);
34
+ const errorMessage = { type: 'error', message: 'Something went wrong' };
35
+ mockPort.onmessage({ data: errorMessage });
36
+ expect(updateHandler).not.toHaveBeenCalled();
37
+ expect(errorHandler).toHaveBeenCalledWith(errorMessage);
38
+ });
39
+ it('should unsubscribe handlers', () => {
40
+ const updateHandler = vi.fn();
41
+ messageEventManager.on('update', updateHandler);
42
+ messageEventManager.off('update', updateHandler);
43
+ const updateMessage = { type: 'update', data: { foo: 'bar' } };
44
+ mockPort.onmessage({ data: updateMessage });
45
+ expect(updateHandler).not.toHaveBeenCalled();
46
+ });
47
+ it('should allow multiple subscribers for the same message type', () => {
48
+ const updateHandler1 = vi.fn();
49
+ const updateHandler2 = vi.fn();
50
+ messageEventManager.on('update', updateHandler1);
51
+ messageEventManager.on('update', updateHandler2);
52
+ const updateMessage = { type: 'update', data: { foo: 'bar' } };
53
+ mockPort.onmessage({ data: updateMessage });
54
+ expect(updateHandler1).toHaveBeenCalledWith(updateMessage);
55
+ expect(updateHandler2).toHaveBeenCalledWith(updateMessage);
56
+ });
57
+ it('should send messages through the port', () => {
58
+ const message = {
59
+ type: HMType.UPDATE,
60
+ value: { asset: 'USDC' },
61
+ };
62
+ messageEventManager.send(message);
63
+ expect(mockPort.postMessage).toHaveBeenCalledWith(message);
64
+ });
65
+ it('should ignore messages without a type', () => {
66
+ const handler = vi.fn();
67
+ messageEventManager.on('update', handler);
68
+ const invalidMessage = { data: 'no type field' };
69
+ mockPort.onmessage({ data: invalidMessage });
70
+ expect(handler).not.toHaveBeenCalled();
71
+ });
72
+ });
73
+ });
@@ -0,0 +1,6 @@
1
+ import fc from 'fast-check';
2
+ import type { CAIP10, CAIP19, CAIP2, CAIP220 } from '../types';
3
+ export declare const arbitraryCAIP10: () => fc.Arbitrary<CAIP10>;
4
+ export declare const arbitraryCAIP2: () => fc.Arbitrary<CAIP2>;
5
+ export declare const arbitraryCAIP19: () => fc.Arbitrary<CAIP19>;
6
+ export declare const arbitraryCAIP220: () => fc.Arbitrary<CAIP220>;
@@ -0,0 +1,7 @@
1
+ import fc from 'fast-check';
2
+ import { CAIP10_MATCHER, CAIP19_MATCHER, CAIP220_MATCHER, CAIP2_MATCHER, } from './caip';
3
+ // Arbitraries
4
+ export const arbitraryCAIP10 = () => fc.stringMatching(CAIP10_MATCHER);
5
+ export const arbitraryCAIP2 = () => fc.stringMatching(CAIP2_MATCHER);
6
+ export const arbitraryCAIP19 = () => fc.stringMatching(CAIP19_MATCHER);
7
+ export const arbitraryCAIP220 = () => fc.stringMatching(CAIP220_MATCHER);
@@ -0,0 +1,13 @@
1
+ export declare const ACCOUNT_ADDRESS_REGEX = "[-.%a-zA-Z0-9]{1,128}";
2
+ export declare const CAIP2_REGEX = "[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}";
3
+ export declare const CAIP10_REGEX = "^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}:[-.%a-zA-Z0-9]{1,128}$";
4
+ export declare const CAIP19_REGEX = "^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}/[-a-z0-9]{3,8}:[-.%a-zA-Z0-9]{1,128}(/[-.%a-zA-Z0-9]{1,78})?$";
5
+ export declare const CAIP220_REGEX = "^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}:[block:]?tx/[-.%a-zA-Z0-9]{1,128}$";
6
+ export declare const CRYPTO_SYMBOL_REGEX = "^[A-Z0-9]{2,10}$";
7
+ export declare const DTI_REGEX = "^[A-Za-z0-9]{10}$";
8
+ export declare const COMBINED_ASSET_REGEX = "(^[A-Z0-9]{2,10}$)|(^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}/[-a-z0-9]{3,8}:[-.%a-zA-Z0-9]{1,128}(/[-.%a-zA-Z0-9]{1,78})?$)|(^[A-Za-z0-9]{10}$)";
9
+ export declare const CAIP2_MATCHER: RegExp;
10
+ export declare const CAIP10_MATCHER: RegExp;
11
+ export declare const CAIP19_MATCHER: RegExp;
12
+ export declare const CAIP220_MATCHER: RegExp;
13
+ export declare const COMBINED_ASSET_MATCHER: RegExp;
@@ -0,0 +1,15 @@
1
+ // Regexes
2
+ export const ACCOUNT_ADDRESS_REGEX = '[-.%a-zA-Z0-9]{1,128}';
3
+ export const CAIP2_REGEX = '[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}';
4
+ export const CAIP10_REGEX = `^${CAIP2_REGEX}:${ACCOUNT_ADDRESS_REGEX}$`;
5
+ export const CAIP19_REGEX = `^${CAIP2_REGEX}/[-a-z0-9]{3,8}:[-.%a-zA-Z0-9]{1,128}(/[-.%a-zA-Z0-9]{1,78})?$`;
6
+ export const CAIP220_REGEX = `^${CAIP2_REGEX}:[block:]?tx/[-.%a-zA-Z0-9]{1,128}$`;
7
+ export const CRYPTO_SYMBOL_REGEX = '^[A-Z0-9]{2,10}$';
8
+ export const DTI_REGEX = '^[A-Za-z0-9]{10}$';
9
+ export const COMBINED_ASSET_REGEX = `(${CRYPTO_SYMBOL_REGEX})|(${CAIP19_REGEX})|(${DTI_REGEX})`;
10
+ // Matchers
11
+ export const CAIP2_MATCHER = new RegExp(CAIP2_REGEX);
12
+ export const CAIP10_MATCHER = new RegExp(CAIP10_REGEX);
13
+ export const CAIP19_MATCHER = new RegExp(CAIP19_REGEX);
14
+ export const CAIP220_MATCHER = new RegExp(CAIP220_REGEX);
15
+ export const COMBINED_ASSET_MATCHER = new RegExp(COMBINED_ASSET_REGEX);
@@ -0,0 +1 @@
1
+ export declare function encodeObjectToFragment(obj: any): string;
@@ -0,0 +1,14 @@
1
+ export function encodeObjectToFragment(obj) {
2
+ return Object.entries(obj)
3
+ .map(([key, value]) => {
4
+ if (!(key && value))
5
+ return undefined;
6
+ const encodedKey = encodeURIComponent(key);
7
+ const encodedValue = encodeURIComponent(typeof value === 'object'
8
+ ? JSON.stringify(value)
9
+ : value);
10
+ return `${encodedKey}=${encodedValue}`;
11
+ })
12
+ .filter((entry) => !!entry)
13
+ .join('&');
14
+ }