@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,98 @@
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
+ * This file is part of HSuite Native Connect. For commercial licensing,
8
+ * visit https://hsuite.finance/licensing
9
+ */
10
+
11
+ /**
12
+ * @file transaction-parser.ts
13
+ * @description Common transaction parser interfaces for ledger adapters
14
+ *
15
+ * This module defines the common contract that all ledger-specific transaction
16
+ * parsers implement. It provides a unified structure for parsed transaction
17
+ * information that can be displayed in wallet UIs regardless of the underlying
18
+ * ledger (Hedera, XRPL, etc.).
19
+ */
20
+
21
+ /**
22
+ * Risk level for security assessment of a transaction.
23
+ * Used to highlight potentially dangerous operations to users.
24
+ */
25
+ export type TransactionRiskLevel = 'low' | 'medium' | 'high';
26
+
27
+ /**
28
+ * A single field to display in the transaction details UI.
29
+ */
30
+ export interface TransactionDisplayField {
31
+ /** Human-readable label for the field */
32
+ label: string;
33
+ /** Value to display (formatted string) */
34
+ value: string;
35
+ /** Whether to highlight this field (e.g., for amounts being sent) */
36
+ highlight?: boolean;
37
+ }
38
+
39
+ /**
40
+ * Parsed transaction details for display in wallet UIs.
41
+ * This is the common output structure from all ledger-specific transaction parsers.
42
+ */
43
+ export interface ParsedTransactionInfo {
44
+ /** Transaction type (e.g., "Transfer", "Token Association", "Payment") */
45
+ type: string;
46
+ /** Human-readable transaction description */
47
+ description: string;
48
+ /** Key-value pairs of transaction fields to display */
49
+ fields: TransactionDisplayField[];
50
+ /** Estimated network fee (ledger-specific format, e.g., "0.0001 HBAR" or "0.00001 XRP") */
51
+ estimatedFee?: string;
52
+ /** Risk level for security assessment */
53
+ riskLevel: TransactionRiskLevel;
54
+ /** Human-readable risk factors to warn users about */
55
+ riskFactors: string[];
56
+ /**
57
+ * Parsed inner transaction for composite transactions (e.g., ScheduleCreate).
58
+ * When present, the UI should display both the outer and inner transaction details
59
+ * so users can see exactly what operation will execute on-chain.
60
+ */
61
+ innerTransaction?: ParsedTransactionInfo;
62
+ }
63
+
64
+ /**
65
+ * Options for transaction parsing.
66
+ * Allows customization of how addresses are displayed (e.g., for address book integration).
67
+ */
68
+ export interface TransactionParserOptions {
69
+ /**
70
+ * Function to format account/address display.
71
+ * Useful for integrating with address books to show friendly names.
72
+ *
73
+ * @param address - The raw address string
74
+ * @returns Formatted display string (e.g., "Alice (0.0.12345)" or just the address)
75
+ */
76
+ formatAccountDisplay?: (address: string) => string;
77
+ }
78
+
79
+ /**
80
+ * Interface for ledger-specific transaction parsers.
81
+ *
82
+ * Each ledger adapter (Hedera, XRPL, etc.) implements this interface to provide
83
+ * a consistent way to parse transactions into a displayable format.
84
+ *
85
+ * Note: The actual parse functions are typically exported as standalone functions
86
+ * rather than class methods (e.g., `parseHederaTransaction`, `parseXrplTransaction`).
87
+ * This interface documents the expected contract for consistency.
88
+ */
89
+ export interface TransactionParser<TInput> {
90
+ /**
91
+ * Parse a transaction into displayable information.
92
+ *
93
+ * @param input - Ledger-specific transaction input (bytes for Hedera, JSON for XRPL)
94
+ * @param options - Parser options for customization
95
+ * @returns Parsed transaction information for UI display
96
+ */
97
+ parse(input: TInput, options?: TransactionParserOptions): ParsedTransactionInfo;
98
+ }
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Tests for Vault-related Zod schemas in @hsuite/native-connect-types
3
+ */
4
+
5
+ import { describe, it, expect } from 'vitest';
6
+ import {
7
+ VaultSeedSchema,
8
+ VaultKeySchema,
9
+ VaultConfigSchema,
10
+ VaultRecoveryBundleSchema,
11
+ } from './vault.js';
12
+
13
+ describe('VaultSeedSchema', () => {
14
+ it('validates a seed with passphrase protection', () => {
15
+ const validSeed = {
16
+ id: '550e8400-e29b-41d4-a716-446655440020',
17
+ label: 'My Wallet',
18
+ createdAt: Date.now(),
19
+ encryptedSeed: 'encrypted-data-here',
20
+ kdfSalt: 'salt-value',
21
+ derivationScheme: 'bip39',
22
+ protection: {
23
+ mode: 'passphrase',
24
+ hint: 'my hint',
25
+ },
26
+ };
27
+
28
+ const result = VaultSeedSchema.safeParse(validSeed);
29
+ expect(result.success).toBe(true);
30
+ });
31
+
32
+ it('validates a seed with no protection', () => {
33
+ const validSeed = {
34
+ id: '550e8400-e29b-41d4-a716-446655440021',
35
+ label: 'My Wallet',
36
+ createdAt: Date.now(),
37
+ encryptedSeed: 'encrypted-data-here',
38
+ kdfSalt: 'salt-value',
39
+ derivationScheme: 'bip39',
40
+ protection: {
41
+ mode: 'none',
42
+ },
43
+ };
44
+
45
+ const result = VaultSeedSchema.safeParse(validSeed);
46
+ expect(result.success).toBe(true);
47
+ });
48
+
49
+ it('validates a seed with biometric protection', () => {
50
+ const validSeed = {
51
+ id: '550e8400-e29b-41d4-a716-446655440022',
52
+ label: 'My Wallet',
53
+ createdAt: Date.now(),
54
+ encryptedSeed: 'encrypted-data-here',
55
+ kdfSalt: 'salt-value',
56
+ derivationScheme: 'bip39',
57
+ protection: {
58
+ mode: 'biometric',
59
+ biometricId: 'device-123',
60
+ },
61
+ };
62
+
63
+ const result = VaultSeedSchema.safeParse(validSeed);
64
+ expect(result.success).toBe(true);
65
+ });
66
+
67
+ it('rejects seed with missing required fields', () => {
68
+ const invalidSeed = {
69
+ id: '550e8400-e29b-41d4-a716-446655440023',
70
+ label: 'My Wallet',
71
+ // missing createdAt, encryptedSeed, etc.
72
+ };
73
+
74
+ const result = VaultSeedSchema.safeParse(invalidSeed);
75
+ expect(result.success).toBe(false);
76
+ });
77
+
78
+ it('rejects seed with invalid timestamp', () => {
79
+ const invalidSeed = {
80
+ id: '550e8400-e29b-41d4-a716-446655440024',
81
+ label: 'My Wallet',
82
+ createdAt: 'not-a-timestamp',
83
+ encryptedSeed: 'encrypted-data-here',
84
+ kdfSalt: 'salt-value',
85
+ derivationScheme: 'bip39',
86
+ protection: { mode: 'none' },
87
+ };
88
+
89
+ const result = VaultSeedSchema.safeParse(invalidSeed);
90
+ expect(result.success).toBe(false);
91
+ });
92
+ });
93
+
94
+ describe('VaultKeySchema', () => {
95
+ it('validates a complete vault key', () => {
96
+ const validKey = {
97
+ id: '550e8400-e29b-41d4-a716-446655440000',
98
+ seedId: '550e8400-e29b-41d4-a716-446655440001',
99
+ ledgerId: 'hedera',
100
+ networkId: 'hedera:testnet',
101
+ address: '0.0.12345',
102
+ publicKey: '302a300506032b65700321001234567890abcdef',
103
+ derivationPath: {
104
+ purpose: 44,
105
+ coinType: 3030,
106
+ account: 0,
107
+ change: 0,
108
+ addressIndex: 0,
109
+ },
110
+ protection: 'none',
111
+ metadata: {
112
+ imported: false,
113
+ },
114
+ };
115
+
116
+ const result = VaultKeySchema.safeParse(validKey);
117
+ expect(result.success).toBe(true);
118
+ });
119
+
120
+ it('validates an imported key with custom metadata', () => {
121
+ const validKey = {
122
+ id: '550e8400-e29b-41d4-a716-446655440002',
123
+ seedId: '550e8400-e29b-41d4-a716-446655440003',
124
+ ledgerId: 'xrpl',
125
+ networkId: 'xrpl:mainnet',
126
+ address: 'rN7n7otQDd6FczFgLdllrLoov2VwWh8u9s',
127
+ publicKey: '0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020',
128
+ derivationPath: {
129
+ purpose: 44,
130
+ coinType: 144,
131
+ account: 0,
132
+ change: 0,
133
+ addressIndex: 0,
134
+ },
135
+ protection: 'passphrase',
136
+ metadata: {
137
+ imported: true,
138
+ source: 'manual-import',
139
+ },
140
+ };
141
+
142
+ const result = VaultKeySchema.safeParse(validKey);
143
+ expect(result.success).toBe(true);
144
+ });
145
+
146
+ it('rejects key with missing derivation path', () => {
147
+ const invalidKey = {
148
+ id: '550e8400-e29b-41d4-a716-446655440004',
149
+ seedId: '550e8400-e29b-41d4-a716-446655440005',
150
+ ledgerId: 'hedera',
151
+ networkId: 'hedera:testnet',
152
+ address: '0.0.12345',
153
+ publicKey: '302a300506032b65700321001234567890abcdef',
154
+ // missing derivationPath
155
+ protection: 'none',
156
+ };
157
+
158
+ const result = VaultKeySchema.safeParse(invalidKey);
159
+ expect(result.success).toBe(false);
160
+ });
161
+ });
162
+
163
+ describe('VaultConfigSchema', () => {
164
+ it('validates a basic vault configuration', () => {
165
+ // VaultConfigSchema has all optional fields with defaults
166
+ const validConfig = {};
167
+
168
+ const result = VaultConfigSchema.safeParse(validConfig);
169
+ expect(result.success).toBe(true);
170
+ });
171
+
172
+ it('validates config with KMS settings', () => {
173
+ const validConfig = {
174
+ allowKms: true,
175
+ kmsDefaultKeyId:
176
+ 'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
177
+ kmsAllowRotation: true,
178
+ };
179
+
180
+ const result = VaultConfigSchema.safeParse(validConfig);
181
+ expect(result.success).toBe(true);
182
+ });
183
+
184
+ it('validates config with custom parameters', () => {
185
+ const validConfig = {
186
+ defaultLedgerId: 'hedera',
187
+ defaultNetworkId: 'hedera:testnet',
188
+ autoLockIntervalSeconds: 600,
189
+ authAttempts: 3,
190
+ biometricRequired: true,
191
+ };
192
+
193
+ const result = VaultConfigSchema.safeParse(validConfig);
194
+ expect(result.success).toBe(true);
195
+ });
196
+
197
+ it('rejects config with invalid autoLockIntervalSeconds', () => {
198
+ const invalidConfig = {
199
+ autoLockIntervalSeconds: 10, // minimum is 30
200
+ };
201
+
202
+ const result = VaultConfigSchema.safeParse(invalidConfig);
203
+ expect(result.success).toBe(false);
204
+ });
205
+ });
206
+
207
+ describe('VaultRecoveryBundleSchema', () => {
208
+ it('validates a recovery bundle', () => {
209
+ const validBundle = {
210
+ id: '550e8400-e29b-41d4-a716-446655440010',
211
+ seedId: '550e8400-e29b-41d4-a716-446655440011',
212
+ createdAt: Date.now(),
213
+ algorithm: 'AES-GCM',
214
+ payload: 'encrypted-recovery-data',
215
+ key: 'encrypted-key-data',
216
+ };
217
+
218
+ const result = VaultRecoveryBundleSchema.safeParse(validBundle);
219
+ expect(result.success).toBe(true);
220
+ });
221
+
222
+ it('validates bundle with metadata', () => {
223
+ const validBundle = {
224
+ id: '550e8400-e29b-41d4-a716-446655440012',
225
+ seedId: '550e8400-e29b-41d4-a716-446655440013',
226
+ createdAt: Date.now(),
227
+ algorithm: 'AES-GCM',
228
+ payload: 'encrypted-recovery-data',
229
+ key: 'encrypted-key-data',
230
+ metadata: {
231
+ exportedBy: 'user@example.com',
232
+ exportMethod: 'file-download',
233
+ },
234
+ };
235
+
236
+ const result = VaultRecoveryBundleSchema.safeParse(validBundle);
237
+ expect(result.success).toBe(true);
238
+ });
239
+
240
+ it('rejects bundle with missing required fields', () => {
241
+ const invalidBundle = {
242
+ id: '550e8400-e29b-41d4-a716-446655440014',
243
+ seedId: '550e8400-e29b-41d4-a716-446655440015',
244
+ createdAt: Date.now(),
245
+ // missing algorithm, payload, key
246
+ };
247
+
248
+ const result = VaultRecoveryBundleSchema.safeParse(invalidBundle);
249
+ expect(result.success).toBe(false);
250
+ });
251
+ });
252
+
253
+ describe('Schema extensibility', () => {
254
+ it('allows additional fields not in schema (open object)', () => {
255
+ const accountWithExtra = {
256
+ ledgerId: 'hedera',
257
+ networkId: 'hedera:testnet',
258
+ address: '0.0.12345',
259
+ publicKey: '302a300506032b65700321001234567890abcdef',
260
+ metadata: {},
261
+ futureField: 'some-value',
262
+ };
263
+
264
+ const result = VaultKeySchema.safeParse(accountWithExtra);
265
+ // This tests that schemas are not overly strict
266
+ // Exact behavior depends on schema definition
267
+ });
268
+ });
package/src/vault.ts ADDED
@@ -0,0 +1,256 @@
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
+ * This file is part of HSuite Native Connect. For commercial licensing,
8
+ * visit https://hsuite.finance/licensing
9
+ */
10
+
11
+ /**
12
+ * @file Vault types for secure key storage and wallet configuration.
13
+ *
14
+ * This module defines the data structures for the wallet's secure vault system,
15
+ * which manages encrypted seed phrases, derived keys, and recovery mechanisms.
16
+ *
17
+ * Vault Architecture:
18
+ * - {@link VaultSeed} - Encrypted seed phrase storage with KDF parameters
19
+ * - {@link VaultKey} - Derived key with address and derivation path
20
+ * - {@link VaultProtection} - Protection mode (passphrase, biometric, hardware, KMS)
21
+ * - {@link VaultRecoveryBundle} - Encrypted backup for wallet restoration
22
+ * - {@link VaultConfig} - Global vault configuration and policies
23
+ *
24
+ * Protection Modes:
25
+ * - `none` - No additional protection (development only)
26
+ * - `passphrase` - User-provided passphrase with PBKDF2/Argon2
27
+ * - `biometric` - Device biometric authentication
28
+ * - `hardware` - Hardware security module (HSM/TPM)
29
+ * - `kms` - Cloud key management service
30
+ *
31
+ * @module types/vault
32
+ * @security SOC2-CC6.1 - Encryption at rest for seed phrases
33
+ */
34
+
35
+ import { z } from 'zod';
36
+
37
+ import { LedgerIdSchema, NetworkIdSchema, DerivationPathSchema } from './ledger.js';
38
+
39
+ /**
40
+ * @description Schema for vault protection mode enum
41
+ */
42
+ export const VaultProtectionModeSchema = z.enum([
43
+ 'none',
44
+ 'passphrase',
45
+ 'hardware',
46
+ 'biometric',
47
+ 'kms',
48
+ ]);
49
+
50
+ /**
51
+ * @description Type representing vault protection mode
52
+ */
53
+ export type VaultProtectionMode = z.infer<typeof VaultProtectionModeSchema>;
54
+
55
+ /**
56
+ * @description Schema for vault protection configuration
57
+ */
58
+ export const VaultProtectionSchema = z.object({
59
+ mode: VaultProtectionModeSchema,
60
+ hint: z.string().optional(),
61
+ hardwareId: z.string().optional(),
62
+ biometricId: z.string().optional(),
63
+ lastUnlockedAt: z.number().optional(),
64
+ kmsKeyId: z.string().optional(),
65
+ });
66
+
67
+ /**
68
+ * @description Type representing vault protection settings
69
+ */
70
+ export type VaultProtection = z.infer<typeof VaultProtectionSchema>;
71
+
72
+ /**
73
+ * @description Schema for recovery contact information
74
+ */
75
+ export const VaultRecoveryContactSchema = z.object({
76
+ name: z.string(),
77
+ contact: z.string(),
78
+ });
79
+
80
+ /**
81
+ * @description Type representing recovery contact
82
+ */
83
+ export type VaultRecoveryContact = z.infer<typeof VaultRecoveryContactSchema>;
84
+
85
+ /**
86
+ * @description Schema for recovery metadata and hints
87
+ */
88
+ export const VaultRecoverySchema = z.object({
89
+ hint: z.string().optional(),
90
+ contacts: z.array(VaultRecoveryContactSchema).optional(),
91
+ note: z.string().optional(),
92
+ });
93
+
94
+ /**
95
+ * @description Type representing recovery configuration
96
+ */
97
+ export type VaultRecovery = z.infer<typeof VaultRecoverySchema>;
98
+
99
+ /**
100
+ * @description Schema for derived vault key
101
+ * Moved before VaultRecoveryBundleSchema to avoid forward reference.
102
+ */
103
+ export const VaultKeySchema = z.object({
104
+ id: z.string().uuid(),
105
+ seedId: z.string().uuid(),
106
+ ledgerId: LedgerIdSchema,
107
+ networkId: NetworkIdSchema,
108
+ address: z.string(),
109
+ publicKey: z.string(),
110
+ derivationPath: DerivationPathSchema,
111
+ protection: VaultProtectionModeSchema,
112
+ metadata: z.record(z.unknown()).optional(),
113
+ });
114
+
115
+ /**
116
+ * @description Type representing vault key
117
+ */
118
+ export type VaultKey = z.infer<typeof VaultKeySchema>;
119
+
120
+ /**
121
+ * @description Schema for user preferences stored in recovery bundle
122
+ */
123
+ export const BundleUserSettingsSchema = z.object({
124
+ language: z.string().optional(),
125
+ currency: z.string().optional(),
126
+ autoLockSeconds: z.number().optional(),
127
+ navigationMode: z.enum(['menu', 'tabs']).optional(),
128
+ desktopNavMode: z.enum(['classic', 'sidebar']).optional(),
129
+ telemetryDestination: z.enum(['console', 'server', 'analytics']).optional(),
130
+ telemetryEndpoint: z.string().optional(),
131
+ });
132
+
133
+ /**
134
+ * @description Type representing bundled user settings
135
+ */
136
+ export type BundleUserSettings = z.infer<typeof BundleUserSettingsSchema>;
137
+
138
+ /**
139
+ * @description Schema for encrypted recovery bundle
140
+ * Extended to include VaultKey objects for complete wallet restoration.
141
+ * The `keys` field contains all derived and imported accounts associated with the seed.
142
+ */
143
+ export const VaultRecoveryBundleSchema = z.object({
144
+ id: z.string().uuid(),
145
+ seedId: z.string().uuid(),
146
+ createdAt: z.number(),
147
+ algorithm: z.literal('AES-GCM'),
148
+ payload: z.string(),
149
+ key: z.string(),
150
+ metadata: z.record(z.unknown()).optional(),
151
+ checksum: z.string().optional(),
152
+ /** VaultKey objects (derived and imported accounts) to restore with the seed */
153
+ keys: z.array(VaultKeySchema).optional(),
154
+ /** Address book contacts to restore with the seed */
155
+ addressBook: z.array(z.unknown()).optional(),
156
+ /** User preferences (language, currency, auto-lock, etc.) */
157
+ userSettings: BundleUserSettingsSchema.optional(),
158
+ /** Current theme ID */
159
+ currentTheme: z.string().optional(),
160
+ /** Custom imported themes (full theme objects) */
161
+ customThemes: z.array(z.unknown()).optional(),
162
+ /** Multisig party states for restoration */
163
+ multisigParties: z.array(z.unknown()).optional(),
164
+ });
165
+
166
+ /**
167
+ * @description Type representing recovery bundle
168
+ */
169
+ export type VaultRecoveryBundle = z.infer<typeof VaultRecoveryBundleSchema>;
170
+
171
+ /**
172
+ * @description Schema for encrypted seed storage
173
+ */
174
+ export const VaultSeedSchema = z.object({
175
+ id: z.string().uuid(),
176
+ label: z.string().optional(),
177
+ createdAt: z.number(),
178
+ encryptedSeed: z.string(),
179
+ encryptedMnemonic: z.string().optional(),
180
+ kdfSalt: z.string(),
181
+ derivationScheme: z.string(),
182
+ protection: VaultProtectionSchema,
183
+ metadata: z.record(z.unknown()).optional(),
184
+ recovery: VaultRecoverySchema.optional(),
185
+ });
186
+
187
+ /**
188
+ * @description Type representing vault seed
189
+ */
190
+ export type VaultSeed = z.infer<typeof VaultSeedSchema>;
191
+
192
+ /**
193
+ * @description Schema for credential mode — determines whether the vault
194
+ * is protected by a numeric PIN (legacy) or a full password.
195
+ */
196
+ export const CredentialModeSchema = z.enum(['pin', 'password']);
197
+
198
+ /**
199
+ * @description Type representing credential mode
200
+ */
201
+ export type CredentialMode = z.infer<typeof CredentialModeSchema>;
202
+
203
+ /**
204
+ * @description Schema for KDF algorithm used to derive encryption keys
205
+ * from the user credential (PIN or password).
206
+ */
207
+ export const KdfAlgorithmSchema = z.enum(['argon2id', 'pbkdf2']);
208
+
209
+ /**
210
+ * @description Type representing KDF algorithm
211
+ */
212
+ export type KdfAlgorithm = z.infer<typeof KdfAlgorithmSchema>;
213
+
214
+ /**
215
+ * @description Schema for wallet vault configuration
216
+ */
217
+ export const VaultConfigSchema = z.object({
218
+ defaultLedgerId: LedgerIdSchema.optional(),
219
+ defaultNetworkId: NetworkIdSchema.optional(),
220
+ autoLockIntervalSeconds: z.number().min(30).default(300),
221
+ allowHardware: z.boolean().default(true),
222
+ allowBiometric: z.boolean().default(true),
223
+ allowRecoveryBundles: z.boolean().default(true),
224
+ allowKms: z.boolean().default(false),
225
+ credentialMode: CredentialModeSchema.default('pin'),
226
+ encryptionSalt: z.string().optional(),
227
+ kdfAlgorithm: KdfAlgorithmSchema.default('argon2id'),
228
+ authAttempts: z.number().min(1).max(10).default(5),
229
+ authLockIntervalSeconds: z.number().min(30).default(300),
230
+ /** @deprecated Legacy alias for authAttempts — kept for migration compatibility, remove in future version */
231
+ pinAttempts: z.number().min(1).max(10).optional(),
232
+ /** @deprecated Legacy alias for authLockIntervalSeconds — kept for migration compatibility, remove in future version */
233
+ pinLockIntervalSeconds: z.number().min(30).optional(),
234
+ recoverWithPassphrase: z.boolean().default(true),
235
+ recoverWithHardware: z.boolean().default(true),
236
+ recoverWithBiometric: z.boolean().default(true),
237
+ recoveryExportFormats: z.array(z.enum(['json', 'qr', 'mnemonic'])).default(['json']),
238
+ pinDigest: z.string().optional(),
239
+ pinSalt: z.string().optional(),
240
+ pinUpdatedAt: z.number().optional(),
241
+ passphraseDigest: z.string().optional(),
242
+ passphraseSalt: z.string().optional(),
243
+ biometricRequired: z.boolean().default(false),
244
+ auditLogRetentionDays: z.number().int().positive().default(30),
245
+ metricsEnabled: z.boolean().default(true),
246
+ recoveryContactRequired: z.boolean().default(false),
247
+ defaultRecoveryContact: VaultRecoveryContactSchema.optional(),
248
+ kmsDefaultKeyId: z.string().optional(),
249
+ kmsAllowRotation: z.boolean().default(false),
250
+ kmsProviderConfig: z.record(z.unknown()).optional(),
251
+ });
252
+
253
+ /**
254
+ * @description Type representing vault configuration
255
+ */
256
+ export type VaultConfig = z.infer<typeof VaultConfigSchema>;