@hsuite/native-connect-types 1.0.0

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 (87) hide show
  1. package/README.md +50 -0
  2. package/dist/address-avatar.d.ts +67 -0
  3. package/dist/address-avatar.d.ts.map +1 -0
  4. package/dist/address-avatar.js +130 -0
  5. package/dist/address-avatar.js.map +1 -0
  6. package/dist/addressbook.d.ts +289 -0
  7. package/dist/addressbook.d.ts.map +1 -0
  8. package/dist/addressbook.js +82 -0
  9. package/dist/addressbook.js.map +1 -0
  10. package/dist/enrichment.d.ts +88 -0
  11. package/dist/enrichment.d.ts.map +1 -0
  12. package/dist/enrichment.js +47 -0
  13. package/dist/enrichment.js.map +1 -0
  14. package/dist/hedera-system-accounts.d.ts +49 -0
  15. package/dist/hedera-system-accounts.d.ts.map +1 -0
  16. package/dist/hedera-system-accounts.js +56 -0
  17. package/dist/hedera-system-accounts.js.map +1 -0
  18. package/dist/identity.d.ts +94 -0
  19. package/dist/identity.d.ts.map +1 -0
  20. package/dist/identity.js +190 -0
  21. package/dist/identity.js.map +1 -0
  22. package/dist/index.d.ts +43 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +52 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/ledger.d.ts +848 -0
  27. package/dist/ledger.d.ts.map +1 -0
  28. package/dist/ledger.js +152 -0
  29. package/dist/ledger.js.map +1 -0
  30. package/dist/messages.d.ts +726 -0
  31. package/dist/messages.d.ts.map +1 -0
  32. package/dist/messages.js +252 -0
  33. package/dist/messages.js.map +1 -0
  34. package/dist/multisig-account.d.ts +419 -0
  35. package/dist/multisig-account.d.ts.map +1 -0
  36. package/dist/multisig-account.js +201 -0
  37. package/dist/multisig-account.js.map +1 -0
  38. package/dist/private-key-export.d.ts +112 -0
  39. package/dist/private-key-export.d.ts.map +1 -0
  40. package/dist/private-key-export.js +11 -0
  41. package/dist/private-key-export.js.map +1 -0
  42. package/dist/rpc.d.ts +872 -0
  43. package/dist/rpc.d.ts.map +1 -0
  44. package/dist/rpc.js +143 -0
  45. package/dist/rpc.js.map +1 -0
  46. package/dist/transaction-approval.d.ts +895 -0
  47. package/dist/transaction-approval.d.ts.map +1 -0
  48. package/dist/transaction-approval.js +11 -0
  49. package/dist/transaction-approval.js.map +1 -0
  50. package/dist/transaction-parser.d.ts +93 -0
  51. package/dist/transaction-parser.d.ts.map +1 -0
  52. package/dist/transaction-parser.js +11 -0
  53. package/dist/transaction-parser.js.map +1 -0
  54. package/dist/vault.d.ts +673 -0
  55. package/dist/vault.d.ts.map +1 -0
  56. package/dist/vault.js +188 -0
  57. package/dist/vault.js.map +1 -0
  58. package/dist/widget.types.d.ts +323 -0
  59. package/dist/widget.types.d.ts.map +1 -0
  60. package/dist/widget.types.js +140 -0
  61. package/dist/widget.types.js.map +1 -0
  62. package/package.json +43 -0
  63. package/src/address-avatar.ts +181 -0
  64. package/src/addressbook.spec.ts +220 -0
  65. package/src/addressbook.ts +115 -0
  66. package/src/enrichment.ts +97 -0
  67. package/src/hedera-system-accounts.ts +60 -0
  68. package/src/identity.spec.ts +243 -0
  69. package/src/identity.ts +244 -0
  70. package/src/index.ts +197 -0
  71. package/src/ledger.spec.ts +366 -0
  72. package/src/ledger.ts +567 -0
  73. package/src/messages.ts +381 -0
  74. package/src/multisig-account.spec.ts +362 -0
  75. package/src/multisig-account.ts +310 -0
  76. package/src/private-key-export.ts +117 -0
  77. package/src/rpc.spec.ts +396 -0
  78. package/src/rpc.ts +257 -0
  79. package/src/transaction-approval.ts +1033 -0
  80. package/src/transaction-parser.ts +98 -0
  81. package/src/vault.spec.ts +268 -0
  82. package/src/vault.ts +256 -0
  83. package/src/widget.types.spec.ts +337 -0
  84. package/src/widget.types.ts +501 -0
  85. package/tsconfig.build.json +17 -0
  86. package/tsconfig.json +11 -0
  87. package/vitest.config.ts +36 -0
@@ -0,0 +1,337 @@
1
+ /**
2
+ * HSuite Native Connect
3
+ * Copyright 2024-2025 HSuite (https://hsuite.finance)
4
+ *
5
+ * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
6
+ */
7
+
8
+ import { describe, it, expect } from 'vitest';
9
+ import {
10
+ inferExecutionContext,
11
+ isManifestV2,
12
+ normalizeManifestToV2,
13
+ FREEMIUM_API_WHITELIST,
14
+ PERMISSION_METADATA,
15
+ type WidgetType,
16
+ type WidgetSize,
17
+ type WidgetCategory,
18
+ type ExperienceType,
19
+ type ExecutionContext,
20
+ type TargetAudience,
21
+ type WidgetPermission,
22
+ type WidgetManifest,
23
+ type WidgetManifestV2,
24
+ type WidgetInstallation,
25
+ type WidgetSettings,
26
+ type GridCell,
27
+ } from './widget.types';
28
+
29
+ describe('Widget Types', () => {
30
+ describe('Type definitions', () => {
31
+ it('should have valid WidgetType values', () => {
32
+ const types: WidgetType[] = ['freemium', 'free', 'subscription', 'one-time'];
33
+ expect(types).toHaveLength(4);
34
+ });
35
+
36
+ it('should have valid WidgetSize values', () => {
37
+ const sizes: WidgetSize[] = ['icon', 'small', 'medium', 'large', 'full-width'];
38
+ expect(sizes).toHaveLength(5);
39
+ });
40
+
41
+ it('should have valid WidgetCategory values', () => {
42
+ const categories: WidgetCategory[] = [
43
+ 'defi',
44
+ 'nft',
45
+ 'analytics',
46
+ 'security',
47
+ 'news',
48
+ 'tools',
49
+ 'gaming',
50
+ ];
51
+ expect(categories).toHaveLength(7);
52
+ });
53
+
54
+ it('should have valid ExperienceType values', () => {
55
+ const types: ExperienceType[] = [
56
+ 'widget',
57
+ 'smart-app',
58
+ 'app-widget',
59
+ 'external-app',
60
+ 'b2b-service',
61
+ ];
62
+ expect(types).toHaveLength(5);
63
+ });
64
+
65
+ it('should have valid ExecutionContext values', () => {
66
+ const contexts: ExecutionContext[] = [
67
+ 'wallet-embedded',
68
+ 'wallet-fullscreen',
69
+ 'external-tab',
70
+ 'api-only',
71
+ ];
72
+ expect(contexts).toHaveLength(4);
73
+ });
74
+
75
+ it('should have valid TargetAudience values', () => {
76
+ const audiences: TargetAudience[] = ['end-user', 'organization', 'developer'];
77
+ expect(audiences).toHaveLength(3);
78
+ });
79
+
80
+ it('should have valid WidgetPermission values', () => {
81
+ const permissions: WidgetPermission[] = [
82
+ 'read:accounts',
83
+ 'read:balances',
84
+ 'read:transactions',
85
+ 'read:portfolio',
86
+ 'sign:transactions',
87
+ 'sign:messages',
88
+ 'network:external',
89
+ 'storage:local',
90
+ 'notifications:send',
91
+ 'clipboard:write',
92
+ 'camera:access',
93
+ 'write:themes',
94
+ ];
95
+ expect(permissions).toHaveLength(12);
96
+ });
97
+ });
98
+
99
+ describe('inferExecutionContext', () => {
100
+ it('should return wallet-embedded for widget', () => {
101
+ expect(inferExecutionContext('widget')).toBe('wallet-embedded');
102
+ });
103
+
104
+ it('should return wallet-fullscreen for smart-app', () => {
105
+ expect(inferExecutionContext('smart-app')).toBe('wallet-fullscreen');
106
+ });
107
+
108
+ it('should return wallet-embedded for app-widget', () => {
109
+ expect(inferExecutionContext('app-widget')).toBe('wallet-embedded');
110
+ });
111
+
112
+ it('should return external-tab for external-app', () => {
113
+ expect(inferExecutionContext('external-app')).toBe('external-tab');
114
+ });
115
+
116
+ it('should return api-only for b2b-service', () => {
117
+ expect(inferExecutionContext('b2b-service')).toBe('api-only');
118
+ });
119
+ });
120
+
121
+ describe('isManifestV2', () => {
122
+ const baseManifest: WidgetManifest = {
123
+ id: 'test-widget',
124
+ name: 'Test Widget',
125
+ description: 'A test widget',
126
+ version: '1.0.0',
127
+ author: 'tester',
128
+ type: 'free',
129
+ category: 'tools',
130
+ size: 'medium',
131
+ icon: 'cube-outline',
132
+ permissions: [],
133
+ accountAccess: 'none',
134
+ apiEndpoints: [],
135
+ networkAccess: false,
136
+ previewImage: 'preview.png',
137
+ screenshots: ['screen1.png', 'screen2.png'],
138
+ tags: ['test'],
139
+ dateCreated: '2025-01-01',
140
+ themeCompatible: true,
141
+ responsive: true,
142
+ };
143
+
144
+ it('should return false for V1 manifest', () => {
145
+ expect(isManifestV2(baseManifest)).toBe(false);
146
+ });
147
+
148
+ it('should return true if experienceType is present', () => {
149
+ const v2: WidgetManifestV2 = { ...baseManifest, experienceType: 'widget' };
150
+ expect(isManifestV2(v2)).toBe(true);
151
+ });
152
+
153
+ it('should return true if executionContext is present', () => {
154
+ const v2: WidgetManifestV2 = { ...baseManifest, executionContext: 'wallet-embedded' };
155
+ expect(isManifestV2(v2)).toBe(true);
156
+ });
157
+
158
+ it('should return true if targetAudience is present', () => {
159
+ const v2: WidgetManifestV2 = { ...baseManifest, targetAudience: 'end-user' };
160
+ expect(isManifestV2(v2)).toBe(true);
161
+ });
162
+ });
163
+
164
+ describe('normalizeManifestToV2', () => {
165
+ const baseManifest: WidgetManifest = {
166
+ id: 'test-widget',
167
+ name: 'Test Widget',
168
+ description: 'A test widget',
169
+ version: '1.0.0',
170
+ author: 'tester',
171
+ type: 'free',
172
+ category: 'tools',
173
+ size: 'medium',
174
+ icon: 'cube-outline',
175
+ permissions: [],
176
+ accountAccess: 'none',
177
+ apiEndpoints: [],
178
+ networkAccess: false,
179
+ previewImage: 'preview.png',
180
+ screenshots: ['screen1.png', 'screen2.png'],
181
+ tags: ['test'],
182
+ dateCreated: '2025-01-01',
183
+ themeCompatible: true,
184
+ responsive: true,
185
+ };
186
+
187
+ it('should set experienceType to widget by default', () => {
188
+ const result = normalizeManifestToV2(baseManifest);
189
+ expect(result.experienceType).toBe('widget');
190
+ });
191
+
192
+ it('should set experienceType to smart-app if hasFullPage is true', () => {
193
+ const manifest = { ...baseManifest, hasFullPage: true };
194
+ const result = normalizeManifestToV2(manifest);
195
+ expect(result.experienceType).toBe('smart-app');
196
+ });
197
+
198
+ it('should infer executionContext from experienceType', () => {
199
+ const result = normalizeManifestToV2(baseManifest);
200
+ expect(result.executionContext).toBe('wallet-embedded');
201
+ });
202
+
203
+ it('should set executionContext to wallet-fullscreen for smart-app', () => {
204
+ const manifest = { ...baseManifest, hasFullPage: true };
205
+ const result = normalizeManifestToV2(manifest);
206
+ expect(result.executionContext).toBe('wallet-fullscreen');
207
+ });
208
+
209
+ it('should default targetAudience to end-user', () => {
210
+ const result = normalizeManifestToV2(baseManifest);
211
+ expect(result.targetAudience).toBe('end-user');
212
+ });
213
+
214
+ it('should default sortPriority to 0', () => {
215
+ const result = normalizeManifestToV2(baseManifest);
216
+ expect(result.sortPriority).toBe(0);
217
+ });
218
+
219
+ it('should default featured to false', () => {
220
+ const result = normalizeManifestToV2(baseManifest);
221
+ expect(result.featured).toBe(false);
222
+ });
223
+
224
+ it('should preserve existing V2 fields', () => {
225
+ const v2Manifest: WidgetManifestV2 = {
226
+ ...baseManifest,
227
+ experienceType: 'external-app',
228
+ executionContext: 'external-tab',
229
+ targetAudience: 'developer',
230
+ sortPriority: 10,
231
+ featured: true,
232
+ };
233
+ const result = normalizeManifestToV2(v2Manifest);
234
+ expect(result.experienceType).toBe('external-app');
235
+ expect(result.executionContext).toBe('external-tab');
236
+ expect(result.targetAudience).toBe('developer');
237
+ expect(result.sortPriority).toBe(10);
238
+ expect(result.featured).toBe(true);
239
+ });
240
+
241
+ it('should not mutate the original manifest', () => {
242
+ const original = { ...baseManifest };
243
+ normalizeManifestToV2(baseManifest);
244
+ expect(baseManifest).toEqual(original);
245
+ });
246
+ });
247
+
248
+ describe('Constants', () => {
249
+ it('should have FREEMIUM_API_WHITELIST with valid domains', () => {
250
+ expect(FREEMIUM_API_WHITELIST).toContain('api.coingecko.com');
251
+ expect(FREEMIUM_API_WHITELIST).toContain('pro-api.coinmarketcap.com');
252
+ expect(FREEMIUM_API_WHITELIST.length).toBeGreaterThan(0);
253
+ });
254
+
255
+ it('should have PERMISSION_METADATA for all permissions', () => {
256
+ const permissions: WidgetPermission[] = [
257
+ 'read:accounts',
258
+ 'read:balances',
259
+ 'read:transactions',
260
+ 'read:portfolio',
261
+ 'sign:transactions',
262
+ 'sign:messages',
263
+ 'network:external',
264
+ 'storage:local',
265
+ 'notifications:send',
266
+ 'clipboard:write',
267
+ 'camera:access',
268
+ 'write:themes',
269
+ ];
270
+
271
+ permissions.forEach((perm) => {
272
+ expect(PERMISSION_METADATA[perm]).toBeDefined();
273
+ expect(PERMISSION_METADATA[perm].label).toBeDefined();
274
+ expect(PERMISSION_METADATA[perm].icon).toBeDefined();
275
+ expect(['low', 'medium', 'high']).toContain(PERMISSION_METADATA[perm].risk);
276
+ });
277
+ });
278
+
279
+ it('should have high risk for sign:transactions', () => {
280
+ expect(PERMISSION_METADATA['sign:transactions'].risk).toBe('high');
281
+ });
282
+
283
+ it('should have medium risk for sign:messages', () => {
284
+ expect(PERMISSION_METADATA['sign:messages'].risk).toBe('medium');
285
+ });
286
+
287
+ it('should have low risk for read permissions', () => {
288
+ expect(PERMISSION_METADATA['read:accounts'].risk).toBe('low');
289
+ expect(PERMISSION_METADATA['read:balances'].risk).toBe('low');
290
+ expect(PERMISSION_METADATA['read:transactions'].risk).toBe('low');
291
+ expect(PERMISSION_METADATA['read:portfolio'].risk).toBe('low');
292
+ });
293
+ });
294
+
295
+ describe('Interface structure validation', () => {
296
+ it('should allow valid GridCell', () => {
297
+ const cell: GridCell = {
298
+ column: 0,
299
+ row: 0,
300
+ columnSpan: 2,
301
+ rowSpan: 1,
302
+ };
303
+ expect(cell.column).toBe(0);
304
+ expect(cell.columnSpan).toBe(2);
305
+ });
306
+
307
+ it('should allow valid WidgetInstallation', () => {
308
+ const installation: WidgetInstallation = {
309
+ widgetId: 'test-widget',
310
+ grantedPermissions: ['read:accounts', 'read:balances'],
311
+ allowedAccounts: ['0.0.123456'],
312
+ installedAt: Date.now(),
313
+ currentSize: 'medium',
314
+ gridPosition: { row: 0, column: 0 },
315
+ displayOrder: 1,
316
+ inDock: false,
317
+ gridSpan: { columnSpan: 2, rowSpan: 1 },
318
+ };
319
+ expect(installation.widgetId).toBe('test-widget');
320
+ expect(installation.grantedPermissions).toHaveLength(2);
321
+ });
322
+
323
+ it('should allow valid WidgetSettings', () => {
324
+ const settings: WidgetSettings = {
325
+ widgetId: 'test-widget',
326
+ settings: {
327
+ theme: 'dark',
328
+ refreshInterval: 30000,
329
+ showNotifications: true,
330
+ },
331
+ updatedAt: Date.now(),
332
+ };
333
+ expect(settings.widgetId).toBe('test-widget');
334
+ expect(settings.settings.theme).toBe('dark');
335
+ });
336
+ });
337
+ });