@hsuite/native-connect-types 1.0.0 → 2.1.1

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 (45) hide show
  1. package/dist/emoji-avatar.d.ts +37 -0
  2. package/dist/emoji-avatar.d.ts.map +1 -0
  3. package/dist/emoji-avatar.js +111 -0
  4. package/dist/emoji-avatar.js.map +1 -0
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +15 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/ipfs-cdn.d.ts +82 -0
  10. package/dist/ipfs-cdn.d.ts.map +1 -0
  11. package/dist/ipfs-cdn.js +138 -0
  12. package/dist/ipfs-cdn.js.map +1 -0
  13. package/dist/ledger.d.ts +30 -0
  14. package/dist/ledger.d.ts.map +1 -1
  15. package/dist/ledger.js +24 -0
  16. package/dist/ledger.js.map +1 -1
  17. package/dist/messages.d.ts +51 -12
  18. package/dist/messages.d.ts.map +1 -1
  19. package/dist/messages.js +19 -0
  20. package/dist/messages.js.map +1 -1
  21. package/dist/rpc.d.ts +28 -18
  22. package/dist/rpc.d.ts.map +1 -1
  23. package/dist/transaction-approval.d.ts +18 -1
  24. package/dist/transaction-approval.d.ts.map +1 -1
  25. package/dist/vault.d.ts +56 -12
  26. package/dist/vault.d.ts.map +1 -1
  27. package/dist/vault.js +25 -0
  28. package/dist/vault.js.map +1 -1
  29. package/dist/xrpl-endpoints.d.ts +48 -0
  30. package/dist/xrpl-endpoints.d.ts.map +1 -0
  31. package/dist/xrpl-endpoints.js +54 -0
  32. package/dist/xrpl-endpoints.js.map +1 -0
  33. package/package.json +1 -1
  34. package/src/index.ts +22 -0
  35. package/src/ipfs-cdn.spec.ts +163 -0
  36. package/src/ipfs-cdn.ts +152 -0
  37. package/src/ledger.spec.ts +51 -0
  38. package/src/ledger.ts +25 -0
  39. package/src/messages.ts +35 -0
  40. package/src/transaction-approval.ts +30 -0
  41. package/src/vault.spec.ts +36 -0
  42. package/src/vault.ts +31 -0
  43. package/src/xrpl-endpoints.spec.ts +46 -0
  44. package/src/xrpl-endpoints.ts +56 -0
  45. package/tsconfig.build.tsbuildinfo +1 -0
@@ -0,0 +1,152 @@
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 Shared HSuite IPFS CDN primitives.
13
+ *
14
+ * The wallet resolves all NFT media (`ipfs://…`) through HSuite's own Bunny
15
+ * CDN, which fronts an IPFS gateway and ships a built-in image optimizer.
16
+ * This module is the single source of truth for:
17
+ *
18
+ * - the CDN host / base URL (so the SDK gateway, the wallet app, and the UI
19
+ * never hardcode the domain independently and drift apart), and
20
+ * - {@link withImageOptimizer}, which appends the Bunny optimizer query
21
+ * (`?optimizer=image&width=N`) so each surface fetches a right-sized
22
+ * variant instead of downloading a full-resolution master for a thumbnail.
23
+ *
24
+ * It lives in `@hsuite/native-connect-types` because that is the only package
25
+ * the SDK, the UI library, and the app all already depend on — the UI does
26
+ * not (and should not) depend on the SDK's channel-protocol/crypto stack.
27
+ *
28
+ * @module ipfs-cdn
29
+ */
30
+
31
+ /**
32
+ * Host of HSuite's Bunny IPFS CDN. Used for an exact-match host check in
33
+ * {@link withImageOptimizer} so the optimizer is never appended to
34
+ * third-party hosts (Arweave, DaVinciGraph, public IPFS gateways).
35
+ */
36
+ export const HSUITE_IPFS_CDN_HOST = 'hsuite-wallet.b-cdn.net';
37
+
38
+ /**
39
+ * Base URL for IPFS content on the HSuite CDN. `convertIpfsUrl` rewrites
40
+ * `ipfs://CID/path` to `${HSUITE_IPFS_CDN_BASE}CID/path`. Derived from
41
+ * {@link HSUITE_IPFS_CDN_HOST} so the host and base can never drift apart.
42
+ */
43
+ export const HSUITE_IPFS_CDN_BASE = `https://${HSUITE_IPFS_CDN_HOST}/ipfs/` as const;
44
+
45
+ /**
46
+ * Logical request widths per render surface, in CSS pixels (already ~2× the
47
+ * display size to cover retina). Bunny returns a variant resized to this
48
+ * width. Tunable in one place; every surface imports from here.
49
+ *
50
+ * - `THUMB` (200): tiny previews — account-overview cover, send NFT picker,
51
+ * approval/transfer hero cards.
52
+ * - `GRID` (350): collection grids and collection cover images.
53
+ * - `DETAIL` (800): the NFT detail-page hero.
54
+ */
55
+ export const NFT_IMAGE_WIDTH = {
56
+ THUMB: 200,
57
+ GRID: 350,
58
+ DETAIL: 800,
59
+ } as const;
60
+
61
+ /**
62
+ * Raster formats the Bunny optimizer can safely resize. SVG (vector) and GIF
63
+ * (animation) are deliberately excluded — optimizing them would rasterize the
64
+ * vector or flatten the animation. Anything else (video/audio/3D, or no
65
+ * extension) is left untouched as well.
66
+ */
67
+ const OPTIMIZABLE_RASTER_EXTENSIONS: ReadonlySet<string> = new Set([
68
+ 'png',
69
+ 'jpg',
70
+ 'jpeg',
71
+ 'webp',
72
+ 'avif',
73
+ 'bmp',
74
+ ]);
75
+
76
+ /**
77
+ * Extract the lowercased file extension from a URL pathname, or `''` when the
78
+ * last path segment has none.
79
+ * @param pathname - The URL pathname (already decoded by the URL parser).
80
+ */
81
+ function fileExtension(pathname: string): string {
82
+ const lastSlash = pathname.lastIndexOf('/');
83
+ const filename = lastSlash >= 0 ? pathname.slice(lastSlash + 1) : pathname;
84
+ const lastDot = filename.lastIndexOf('.');
85
+ return lastDot >= 0 ? filename.slice(lastDot + 1).toLowerCase() : '';
86
+ }
87
+
88
+ /**
89
+ * Append the Bunny image-optimizer query to an HSuite-CDN raster image URL.
90
+ *
91
+ * The transform is intentionally conservative — it returns the input
92
+ * **unchanged** in every case where optimizing would be wrong or unsafe:
93
+ *
94
+ * - empty / `undefined` input,
95
+ * - malformed or relative URLs (cannot be parsed),
96
+ * - any host other than {@link HSUITE_IPFS_CDN_HOST} (Arweave, DaVinci,
97
+ * public IPFS gateways, base64/data URIs),
98
+ * - non-raster or extensionless paths (SVG, GIF, video, audio, 3D, …),
99
+ * - URLs that already carry an `optimizer` param (idempotent — no double
100
+ * append, so re-wrapping is a no-op).
101
+ *
102
+ * Only when the URL is a CDN-hosted raster image does it append
103
+ * `?optimizer=image&width=<width>` (joining with `&` if a query already
104
+ * exists). This makes the helper safe to call from every image getter: it is
105
+ * a guaranteed no-op for non-image media and third-party hosts.
106
+ *
107
+ * @param url - The (already gateway-resolved) image URL, or `undefined`.
108
+ * @param width - Target width in pixels; defaults to {@link NFT_IMAGE_WIDTH}.GRID.
109
+ * Non-finite or non-positive values fall back to GRID; fractional values are
110
+ * rounded.
111
+ * @returns The optimized URL, or the original input unchanged.
112
+ */
113
+ export function withImageOptimizer(
114
+ url: string | undefined,
115
+ width: number = NFT_IMAGE_WIDTH.GRID,
116
+ ): string | undefined {
117
+ // Empty string and undefined pass straight through.
118
+ if (!url) {
119
+ return url;
120
+ }
121
+
122
+ let parsed: URL;
123
+ try {
124
+ parsed = new URL(url);
125
+ } catch {
126
+ // Relative or malformed URLs are never CDN raster images.
127
+ return url;
128
+ }
129
+
130
+ // Exact host match only (host includes any port) — never rewrite
131
+ // third-party hosts, look-alike subdomains, or the CDN host reached
132
+ // on a non-standard port.
133
+ if (parsed.host !== HSUITE_IPFS_CDN_HOST) {
134
+ return url;
135
+ }
136
+
137
+ // Only resize raster formats; leave SVG/GIF/video/extensionless alone.
138
+ if (!OPTIMIZABLE_RASTER_EXTENSIONS.has(fileExtension(parsed.pathname))) {
139
+ return url;
140
+ }
141
+
142
+ // Idempotent: if it's already optimized, return the original untouched.
143
+ if (parsed.searchParams.has('optimizer')) {
144
+ return url;
145
+ }
146
+
147
+ const safeWidth = Number.isFinite(width) && width > 0 ? Math.round(width) : NFT_IMAGE_WIDTH.GRID;
148
+
149
+ parsed.searchParams.set('optimizer', 'image');
150
+ parsed.searchParams.set('width', String(safeWidth));
151
+ return parsed.toString();
152
+ }
@@ -298,6 +298,7 @@ describe('LedgerPluginManifestSchema', () => {
298
298
  displayName: 'Hedera Hashgraph',
299
299
  description: 'Hedera public ledger',
300
300
  defaultNetworkId: 'hedera:mainnet',
301
+ nativeDecimals: 8,
301
302
  capabilities: {
302
303
  supportsMultiSign: true,
303
304
  supportsScheduledTx: true,
@@ -324,6 +325,7 @@ describe('LedgerPluginManifestSchema', () => {
324
325
  displayName: 'XRP Ledger',
325
326
  description: 'XRP Ledger network',
326
327
  defaultNetworkId: 'xrpl:mainnet',
328
+ nativeDecimals: 6,
327
329
  capabilities: {
328
330
  supportsMultiSign: true,
329
331
  supportsScheduledTx: false,
@@ -350,6 +352,7 @@ describe('LedgerPluginManifestSchema', () => {
350
352
  displayName: 'Hedera',
351
353
  description: 'Test',
352
354
  defaultNetworkId: 'hedera:testnet',
355
+ nativeDecimals: 8,
353
356
  capabilities: {
354
357
  supportsMultiSign: false,
355
358
  supportsScheduledTx: false,
@@ -363,4 +366,52 @@ describe('LedgerPluginManifestSchema', () => {
363
366
  const result = LedgerPluginManifestSchema.safeParse(manifest);
364
367
  expect(result.success).toBe(true);
365
368
  });
369
+
370
+ it('rejects metadata missing the required nativeDecimals field', () => {
371
+ // nativeDecimals is the money-critical native-decimals protocol constant.
372
+ // Omitting it MUST fail validation so a missing value cannot silently
373
+ // become a value-math bug downstream.
374
+ const manifestMissingDecimals = {
375
+ metadata: {
376
+ id: 'hedera',
377
+ displayName: 'Hedera',
378
+ description: 'Test',
379
+ defaultNetworkId: 'hedera:testnet',
380
+ // nativeDecimals intentionally omitted
381
+ capabilities: {
382
+ supportsMultiSign: false,
383
+ supportsScheduledTx: false,
384
+ supportsSmartContracts: false,
385
+ },
386
+ },
387
+ networks: [],
388
+ };
389
+
390
+ const result = LedgerPluginManifestSchema.safeParse(manifestMissingDecimals);
391
+ expect(result.success).toBe(false);
392
+ });
393
+
394
+ it('accepts metadata that declares nativeDecimals', () => {
395
+ const manifestWithDecimals = {
396
+ metadata: {
397
+ id: 'xrpl',
398
+ displayName: 'XRP Ledger',
399
+ description: 'Test',
400
+ defaultNetworkId: 'xrpl:testnet',
401
+ nativeDecimals: 6,
402
+ capabilities: {
403
+ supportsMultiSign: true,
404
+ supportsScheduledTx: false,
405
+ supportsSmartContracts: false,
406
+ },
407
+ },
408
+ networks: [],
409
+ };
410
+
411
+ const result = LedgerPluginManifestSchema.safeParse(manifestWithDecimals);
412
+ expect(result.success).toBe(true);
413
+ if (result.success) {
414
+ expect(result.data.metadata.nativeDecimals).toBe(6);
415
+ }
416
+ });
366
417
  });
package/src/ledger.ts CHANGED
@@ -45,6 +45,24 @@ export const LedgerIdSchema = z.string().min(1);
45
45
  */
46
46
  export type LedgerId = z.infer<typeof LedgerIdSchema>;
47
47
 
48
+ /**
49
+ * @description Well-known ledger identifiers shipped with the SDK — a typed
50
+ * convenience layer over the open {@link LedgerId} string. Reference
51
+ * `LedgerIds.Hedera` instead of a bare `'hedera'` literal so call sites get
52
+ * compile-time typo safety, find-all-references, and safe rename.
53
+ *
54
+ * Deliberately NOT a closed set of supported ledgers, and it must not become
55
+ * one: `LedgerId` stays an open string and the ledger registry resolves
56
+ * adapters at runtime, so a future chain registers under its own id whether or
57
+ * not it is listed here. Per-ledger PROPERTIES (native decimals, symbol,
58
+ * capabilities) live on the adapter manifest ({@link LedgerMetadata}) — never
59
+ * in this map.
60
+ */
61
+ export const LedgerIds = {
62
+ Hedera: 'hedera',
63
+ Xrpl: 'xrpl',
64
+ } as const satisfies Record<string, LedgerId>;
65
+
48
66
  /**
49
67
  * @description Network identifier within a ledger ecosystem (e.g., "mainnet", "testnet")
50
68
  */
@@ -120,6 +138,13 @@ export const LedgerMetadataSchema = z.object({
120
138
  displayName: z.string(),
121
139
  description: z.string().optional(),
122
140
  defaultNetworkId: NetworkIdSchema,
141
+ // Money-critical native-decimals protocol constant (HBAR=8, XRP=6): the single
142
+ // source of truth for converting native base units to display amounts. REQUIRED
143
+ // so a missing value fails adapter registration loudly rather than silently
144
+ // defaulting and corrupting value math downstream. Upper-bounded at 18 (the
145
+ // highest real-world native-decimals, e.g. ETH) so a fat-finger like 80/800
146
+ // fails validation instead of mis-scaling every on-chain amount.
147
+ nativeDecimals: z.number().int().nonnegative().max(18),
123
148
  capabilities: LedgerCapabilitiesSchema,
124
149
  });
125
150
 
package/src/messages.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  LedgerIdSchema,
35
35
  NetworkIdSchema,
36
36
  } from './ledger.js';
37
+ import { KeyAlgorithmSchema, type KeyAlgorithm } from './vault.js';
37
38
 
38
39
  /**
39
40
  * @description Schema for dApp session request payload
@@ -97,6 +98,24 @@ export const SignPayloadSchema = z.object({
97
98
  payload: z.union([z.string(), z.instanceof(Uint8Array)]),
98
99
  derivationPath: DerivationPathSchema.optional(),
99
100
  context: z.record(z.unknown()).optional(),
101
+ /**
102
+ * Optional cryptographic-algorithm hint for raw-scalar keys (e.g. an imported
103
+ * Hedera ECDSA key). This is the typed home for the algorithm on the sign
104
+ * surface; signing chokepoints populate it from the account's VaultKey and the
105
+ * Hedera adapter prefers it over the legacy `context.keyType` fallback.
106
+ */
107
+ keyType: KeyAlgorithmSchema.optional(),
108
+ /**
109
+ * Optional account public key (raw or DER hex) for the fail-safe pre-sign
110
+ * assertion. Populated by {@link WalletCore.signDirect} from the account's
111
+ * VaultKey; the Hedera adapter refuses to sign if the reconstructed key's
112
+ * public key does not match. Best-effort — absent on legacy baselines.
113
+ * Mirrors `SignMessagePayload.expectedPublicKey` so both signing surfaces
114
+ * carry the algorithm fail-safe input in a typed field rather than `context`.
115
+ *
116
+ * @security SOC2-CC6.1 — enables wrong-algorithm signature prevention.
117
+ */
118
+ expectedPublicKey: z.string().optional(),
100
119
  nonce: z.string().uuid().optional(),
101
120
  // Batch transaction support
102
121
  isBatch: z.boolean().optional(),
@@ -171,6 +190,22 @@ export interface SignMessagePayload {
171
190
  * Must match `/^[a-z0-9]+:[a-z0-9]+$/` (CAIP-2 lower-kebab-case shape).
172
191
  */
173
192
  caipChainId: string;
193
+ /**
194
+ * Optional cryptographic-algorithm hint for raw-scalar keys (e.g. an imported
195
+ * Hedera ECDSA key). Populated by {@link WalletCore.signMessageDirect} from the
196
+ * account's VaultKey so the adapter reconstructs the correct PrivateKey instead
197
+ * of defaulting a raw 32-byte key to Ed25519. Mirrors `SignPayload.keyType`.
198
+ */
199
+ keyType?: KeyAlgorithm;
200
+ /**
201
+ * Optional account public key (raw or DER hex) for the fail-safe pre-sign
202
+ * assertion. Populated by {@link WalletCore.signMessageDirect} from the
203
+ * account's VaultKey; the adapter refuses to sign if the reconstructed key's
204
+ * public key does not match. Best-effort — absent on legacy baselines.
205
+ *
206
+ * @security SOC2-CC6.1 — enables wrong-algorithm signature prevention.
207
+ */
208
+ expectedPublicKey?: string;
174
209
  }
175
210
 
176
211
  /**
@@ -909,6 +909,19 @@ export interface RiskFactor {
909
909
  | 'unusual_pattern'
910
910
  | 'high_fee'
911
911
  | 'unknown_token'
912
+ // Scam / suspicious-transaction factor types, populated by the local,
913
+ // chain-agnostic scam-detection engine. Map 1:1 from `ScamFactorType`
914
+ // (@hsuite/native-connect-sdk security/scam-detection) so the approval and
915
+ // history surfaces can render a type-specific icon/label instead of
916
+ // collapsing every scam signal into `'custom'`.
917
+ | 'credential_solicitation'
918
+ | 'phishing_url'
919
+ | 'reward_bait'
920
+ | 'impersonation'
921
+ | 'unicode_obfuscation'
922
+ | 'dust_delivery'
923
+ | 'address_poisoning'
924
+ | 'unknown_counterparty'
912
925
  | 'custom';
913
926
  /** Severity level */
914
927
  severity: 'info' | 'warning' | 'danger';
@@ -918,6 +931,15 @@ export interface RiskFactor {
918
931
  description?: string;
919
932
  /** Help URL for more information (optional) */
920
933
  helpUrl?: string;
934
+ /**
935
+ * When true, this factor is severe enough to force the explicit
936
+ * acknowledgment gate at approval time, and to drive the `critical` banner
937
+ * styling on read-only surfaces (e.g. transaction history, which ignores
938
+ * {@link RiskAssessment.requiresAcknowledgment}). Always paired with
939
+ * `severity: 'danger'`. Optional + additive: absent on factors produced
940
+ * before the scam-detection engine existed.
941
+ */
942
+ critical?: boolean;
921
943
  }
922
944
 
923
945
  /**
@@ -933,6 +955,14 @@ export interface RiskAssessment {
933
955
  confidence?: number;
934
956
  /** Recommendation for user */
935
957
  recommendation?: string;
958
+ /**
959
+ * When true, an approval surface MUST require an explicit user acknowledgment
960
+ * before enabling the action — the tiered scam-alert enforcement gate for
961
+ * high-risk transactions (never a hard block; the wallet is non-custodial).
962
+ * Read-only surfaces such as transaction history ignore this flag. Optional +
963
+ * additive: absent on assessments produced before the scam-detection engine.
964
+ */
965
+ requiresAcknowledgment?: boolean;
936
966
  }
937
967
 
938
968
  /**
package/src/vault.spec.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  VaultKeySchema,
9
9
  VaultConfigSchema,
10
10
  VaultRecoveryBundleSchema,
11
+ KeyAlgorithmSchema,
11
12
  } from './vault.js';
12
13
 
13
14
  describe('VaultSeedSchema', () => {
@@ -266,3 +267,38 @@ describe('Schema extensibility', () => {
266
267
  // Exact behavior depends on schema definition
267
268
  });
268
269
  });
270
+
271
+ describe('keyType typed field', () => {
272
+ it('accepts ed25519 and ecdsa on VaultKey', () => {
273
+ for (const keyType of ['ed25519', 'ecdsa'] as const) {
274
+ const parsed = VaultKeySchema.parse({
275
+ id: crypto.randomUUID(),
276
+ seedId: crypto.randomUUID(),
277
+ ledgerId: 'hedera',
278
+ networkId: 'hedera:testnet',
279
+ address: '0.0.1234',
280
+ publicKey: 'ab12',
281
+ derivationPath: { purpose: 44, coinType: 3030, account: 0, change: 0, addressIndex: 0 },
282
+ protection: 'none',
283
+ keyType,
284
+ });
285
+ expect(parsed.keyType).toBe(keyType);
286
+ }
287
+ });
288
+
289
+ it('rejects an unknown algorithm token', () => {
290
+ expect(() => KeyAlgorithmSchema.parse('secp256k1')).toThrow();
291
+ });
292
+
293
+ it('keyType is optional (back-compat with existing records)', () => {
294
+ const parsed = VaultSeedSchema.parse({
295
+ id: crypto.randomUUID(),
296
+ createdAt: 0,
297
+ encryptedSeed: 'x',
298
+ kdfSalt: 'y',
299
+ derivationScheme: 'imported',
300
+ protection: { mode: 'none' },
301
+ });
302
+ expect(parsed.keyType).toBeUndefined();
303
+ });
304
+ });
package/src/vault.ts CHANGED
@@ -96,6 +96,25 @@ export const VaultRecoverySchema = z.object({
96
96
  */
97
97
  export type VaultRecovery = z.infer<typeof VaultRecoverySchema>;
98
98
 
99
+ /**
100
+ * @description Canonical key algorithm token for Hedera (and any ledger using
101
+ * raw scalar keys). The same 32-byte scalar is valid under both Ed25519 and
102
+ * ECDSA secp256k1, producing different public keys and signatures, so the
103
+ * algorithm must be carried alongside the key.
104
+ *
105
+ * The codebase also uses 'secp256k1' (export service) and 'ecdsa_secp256k1'
106
+ * (message-sign result); those are mapped at their boundaries. The
107
+ * vault/sign/import surface standardizes on this pair.
108
+ *
109
+ * @security SOC2-CC6.1 - enables fail-safe pre-sign algorithm verification.
110
+ */
111
+ export const KeyAlgorithmSchema = z.enum(['ed25519', 'ecdsa']);
112
+
113
+ /**
114
+ * @description Type representing a key algorithm
115
+ */
116
+ export type KeyAlgorithm = z.infer<typeof KeyAlgorithmSchema>;
117
+
99
118
  /**
100
119
  * @description Schema for derived vault key
101
120
  * Moved before VaultRecoveryBundleSchema to avoid forward reference.
@@ -109,6 +128,13 @@ export const VaultKeySchema = z.object({
109
128
  publicKey: z.string(),
110
129
  derivationPath: DerivationPathSchema,
111
130
  protection: VaultProtectionModeSchema,
131
+ /**
132
+ * Cryptographic algorithm of the underlying key. Optional for back-compat:
133
+ * legacy records (written before this field existed) are all Ed25519, since
134
+ * ECDSA import never worked. Read by the signing chokepoints to reconstruct
135
+ * the correct PrivateKey and to assert against the stored public key.
136
+ */
137
+ keyType: KeyAlgorithmSchema.optional(),
112
138
  metadata: z.record(z.unknown()).optional(),
113
139
  });
114
140
 
@@ -180,6 +206,11 @@ export const VaultSeedSchema = z.object({
180
206
  kdfSalt: z.string(),
181
207
  derivationScheme: z.string(),
182
208
  protection: VaultProtectionSchema,
209
+ /**
210
+ * Cryptographic algorithm of the stored seed/key when it is a raw scalar
211
+ * (imported Hedera key). Optional for back-compat. See {@link KeyAlgorithm}.
212
+ */
213
+ keyType: KeyAlgorithmSchema.optional(),
183
214
  metadata: z.record(z.unknown()).optional(),
184
215
  recovery: VaultRecoverySchema.optional(),
185
216
  });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Tests for the canonical XRPL endpoint map in @hsuite/native-connect-types.
3
+ *
4
+ * This is the single source of truth that both the ledger-xrpl adapter and the
5
+ * native-wallet-sdk consumers derive their endpoint lists from, so the ordering
6
+ * (primary first, rest are failover) and the network → list mapping are pinned
7
+ * here.
8
+ */
9
+
10
+ import { describe, it, expect } from 'vitest';
11
+
12
+ import { XRPL_ENDPOINTS, endpointsFor } from './xrpl-endpoints.js';
13
+
14
+ describe('XRPL_ENDPOINTS', () => {
15
+ it('lists mainnet endpoints primary-first (xrplcluster → s1 → s2)', () => {
16
+ expect(XRPL_ENDPOINTS['xrpl:mainnet']).toEqual([
17
+ 'wss://xrplcluster.com',
18
+ 'wss://s1.ripple.com',
19
+ 'wss://s2.ripple.com',
20
+ ]);
21
+ });
22
+
23
+ it('keeps testnet and devnet as single-entry lists', () => {
24
+ expect(XRPL_ENDPOINTS['xrpl:testnet']).toEqual(['wss://s.altnet.rippletest.net:51233']);
25
+ expect(XRPL_ENDPOINTS['xrpl:devnet']).toEqual(['wss://s.devnet.rippletest.net:51233']);
26
+ });
27
+ });
28
+
29
+ describe('endpointsFor', () => {
30
+ it('returns the ordered list for a known network', () => {
31
+ expect(endpointsFor('xrpl:mainnet')).toEqual([
32
+ 'wss://xrplcluster.com',
33
+ 'wss://s1.ripple.com',
34
+ 'wss://s2.ripple.com',
35
+ ]);
36
+ });
37
+
38
+ it('returns an empty list for an unknown or empty network id', () => {
39
+ expect(endpointsFor('xrpl:unknown')).toEqual([]);
40
+ expect(endpointsFor('')).toEqual([]);
41
+ });
42
+
43
+ it('exposes the primary endpoint at index 0', () => {
44
+ expect(endpointsFor('xrpl:mainnet')[0]).toBe('wss://xrplcluster.com');
45
+ });
46
+ });
@@ -0,0 +1,56 @@
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 Canonical, ordered XRPL endpoint lists per network.
13
+ *
14
+ * @description
15
+ * Single source of truth for the rippled endpoints the wallet talks to. The
16
+ * first entry in each list is the primary node; the rest are failover targets
17
+ * tried in order when the primary cannot be reached. Mainnet carries multiple
18
+ * endpoints so a single unreachable node (network/VPN/proxy blocking the WSS
19
+ * handshake, or a public-cluster IP rate-limit) does not take down the whole
20
+ * XRPL read path. Testnet/devnet stay single-entry.
21
+ *
22
+ * Cross-package consumers — the `ledger-xrpl` adapter (WS clients,
23
+ * account-existence checks, the ledger manifest) and the `native-wallet-sdk`
24
+ * (token discovery, account import validation) — MUST import these from
25
+ * `@hsuite/native-connect-types` rather than re-declaring the URLs, so the list
26
+ * stays in lock-step everywhere. `ledger-xrpl` re-exports them through its own
27
+ * `endpoints` module for local ergonomics.
28
+ *
29
+ * Any endpoint added here for mainnet must ALSO be whitelisted in the wallet
30
+ * app's CSP surfaces (`index.html` meta + `_headers`) or the browser blocks the
31
+ * connection — `xrplcluster.com`, `s1.ripple.com`, and `s2.ripple.com` are
32
+ * already present in both.
33
+ */
34
+
35
+ /**
36
+ * Ordered XRPL endpoints per network; primary first, the rest are failover.
37
+ *
38
+ * @constant
39
+ */
40
+ export const XRPL_ENDPOINTS: Record<string, readonly string[]> = {
41
+ 'xrpl:mainnet': ['wss://xrplcluster.com', 'wss://s1.ripple.com', 'wss://s2.ripple.com'],
42
+ 'xrpl:testnet': ['wss://s.altnet.rippletest.net:51233'],
43
+ 'xrpl:devnet': ['wss://s.devnet.rippletest.net:51233'],
44
+ };
45
+
46
+ /**
47
+ * Resolve the ordered endpoint list for a network id.
48
+ *
49
+ * @param networkId - Network identifier (e.g. `xrpl:mainnet`).
50
+ * @returns The ordered endpoint list (primary first), or an empty list when the
51
+ * network is unknown. Callers treat an empty list as "no endpoints
52
+ * configured" and surface a retryable error rather than connecting.
53
+ */
54
+ export function endpointsFor(networkId: string): readonly string[] {
55
+ return XRPL_ENDPOINTS[networkId] ?? [];
56
+ }