@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
package/src/rpc.ts ADDED
@@ -0,0 +1,257 @@
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 JSON-RPC 2.0 protocol implementation for HSuite Native Connect.
13
+ *
14
+ * This module implements a JSON-RPC 2.0 compliant protocol layer for
15
+ * structured communication between dApps and wallets. It provides:
16
+ *
17
+ * - **Request/Response Schemas**: Typed schemas for all RPC operations
18
+ * - **Version Negotiation**: Semantic versioning via {@link RpcVersionHeader}
19
+ * - **Method Definitions**: All supported RPC methods via {@link RpcMethodSchema}
20
+ * - **Envelope Wrapping**: Message envelope support for transport
21
+ *
22
+ * Supported RPC Methods:
23
+ * - `session/request` - Initiate dApp session
24
+ * - `session/approve` - Wallet approves/rejects session
25
+ * - `session/terminate` - End active session
26
+ * - `ledger/sign` - Sign transaction
27
+ * - `ledger/submit` - Submit signed transaction
28
+ * - `ledger/signAndSubmit` - Combined sign and submit
29
+ * - `wallet/accounts` - List available accounts
30
+ *
31
+ * @module types/rpc
32
+ */
33
+
34
+ import { z } from 'zod';
35
+
36
+ import {
37
+ SessionRequestSchema,
38
+ SessionApprovalSchema,
39
+ SignPayloadSchema,
40
+ SignResultSchema,
41
+ TransactionSubmissionSchema,
42
+ MessageEnvelopeSchema,
43
+ } from './messages.js';
44
+
45
+ /**
46
+ * @description Current RPC protocol version
47
+ */
48
+ export const RpcVersion = '1.1.0';
49
+
50
+ /**
51
+ * @description HTTP header name for RPC version negotiation
52
+ */
53
+ export const RpcVersionHeader = 'x-hsuite-rpc-version';
54
+
55
+ /**
56
+ * @description Schema for supported RPC method names
57
+ */
58
+ export const RpcMethodSchema = z.enum([
59
+ 'session/request',
60
+ 'session/approve',
61
+ 'session/terminate',
62
+ 'session/status',
63
+ 'session/terminated', // Real-time event: session was terminated
64
+ 'session/updated', // Real-time event: session was updated
65
+ 'ledger/sign',
66
+ 'ledger/submit',
67
+ 'ledger/signAndSubmit', // Combined sign+submit (prevents double approval)
68
+ 'ledger/signMessage', // Sign arbitrary message (e.g., for auth, DAO votes)
69
+ 'wallet/accounts',
70
+ 'wallet/register-ledger',
71
+ 'wallet/get-config',
72
+ ]);
73
+
74
+ /**
75
+ * @description Type representing RPC method name
76
+ */
77
+ export type RpcMethod = z.infer<typeof RpcMethodSchema>;
78
+
79
+ /**
80
+ * @description Schema for JSON-RPC 2.0 request
81
+ */
82
+ export const RpcRequestSchema = z.object({
83
+ jsonrpc: z.literal('2.0'),
84
+ id: z.union([z.string(), z.number()]),
85
+ method: RpcMethodSchema,
86
+ params: z.unknown().optional(),
87
+ origin: z.string().optional(),
88
+ timestamp: z.number(),
89
+ });
90
+
91
+ /**
92
+ * @description Type representing RPC request
93
+ */
94
+ export type RpcRequest = z.infer<typeof RpcRequestSchema>;
95
+
96
+ /**
97
+ * @description Schema for JSON-RPC 2.0 error response
98
+ */
99
+ export const RpcErrorSchema = z.object({
100
+ jsonrpc: z.literal('2.0'),
101
+ id: z.union([z.string(), z.number()]).nullable(),
102
+ error: z.object({
103
+ code: z.number(),
104
+ message: z.string(),
105
+ data: z.unknown().optional(),
106
+ }),
107
+ timestamp: z.number(),
108
+ });
109
+
110
+ /**
111
+ * @description Type representing RPC error response
112
+ */
113
+ export type RpcError = z.infer<typeof RpcErrorSchema>;
114
+
115
+ /**
116
+ * @description Schema for JSON-RPC 2.0 success response
117
+ */
118
+ export const RpcSuccessSchema = z.object({
119
+ jsonrpc: z.literal('2.0'),
120
+ id: z.union([z.string(), z.number()]),
121
+ result: z.unknown(),
122
+ timestamp: z.number(),
123
+ });
124
+
125
+ /**
126
+ * @description Type representing RPC success response with typed result
127
+ */
128
+ export type RpcSuccess<T = unknown> = Omit<z.infer<typeof RpcSuccessSchema>, 'result'> & {
129
+ result: T;
130
+ };
131
+
132
+ /**
133
+ * @description Type representing RPC response (success or error)
134
+ */
135
+ export type RpcResponse<T = unknown> = RpcSuccess<T> | RpcError;
136
+
137
+ /**
138
+ * @description Type for session request wrapped in message envelope
139
+ */
140
+ export type SessionRequestEnvelope = z.infer<typeof MessageEnvelopeSchema> & {
141
+ payload: z.infer<typeof SessionRequestSchema>;
142
+ };
143
+
144
+ /**
145
+ * @description Type for session approval wrapped in message envelope
146
+ */
147
+ export type SessionApprovalEnvelope = z.infer<typeof MessageEnvelopeSchema> & {
148
+ payload: z.infer<typeof SessionApprovalSchema>;
149
+ };
150
+
151
+ /**
152
+ * @description Type for sign payload wrapped in message envelope
153
+ */
154
+ export type SignPayloadEnvelope = z.infer<typeof MessageEnvelopeSchema> & {
155
+ payload: z.infer<typeof SignPayloadSchema>;
156
+ };
157
+
158
+ /**
159
+ * @description Type for sign result wrapped in message envelope
160
+ */
161
+ export type SignResultEnvelope = z.infer<typeof MessageEnvelopeSchema> & {
162
+ payload: z.infer<typeof SignResultSchema>;
163
+ };
164
+
165
+ /**
166
+ * @description Type for transaction submission wrapped in message envelope
167
+ */
168
+ export type TransactionSubmissionEnvelope = z.infer<typeof MessageEnvelopeSchema> & {
169
+ payload: z.infer<typeof TransactionSubmissionSchema>;
170
+ };
171
+
172
+ /**
173
+ * @description Schema for session request RPC call
174
+ */
175
+ export const RpcSessionRequestSchema = RpcRequestSchema.extend({
176
+ method: z.literal('session/request'),
177
+ params: SessionRequestSchema,
178
+ });
179
+
180
+ /**
181
+ * @description Schema for session approval RPC call
182
+ */
183
+ export const RpcSessionApproveSchema = RpcRequestSchema.extend({
184
+ method: z.literal('session/approve'),
185
+ params: SessionApprovalSchema,
186
+ });
187
+
188
+ /**
189
+ * @description Schema for signing RPC call
190
+ */
191
+ export const RpcSignRequestSchema = RpcRequestSchema.extend({
192
+ method: z.literal('ledger/sign'),
193
+ params: SignPayloadSchema,
194
+ });
195
+
196
+ /**
197
+ * @description Schema for signing RPC response
198
+ */
199
+ export const RpcSignResponseSchema = RpcSuccessSchema.extend({
200
+ result: SignResultSchema,
201
+ });
202
+
203
+ /**
204
+ * @description Schema for transaction submission RPC call
205
+ */
206
+ export const RpcSubmitRequestSchema = RpcRequestSchema.extend({
207
+ method: z.literal('ledger/submit'),
208
+ params: TransactionSubmissionSchema,
209
+ });
210
+
211
+ /**
212
+ * @description Type for session request RPC call
213
+ */
214
+ export type RpcSessionRequest = z.infer<typeof RpcSessionRequestSchema>;
215
+
216
+ /**
217
+ * @description Type for session approval RPC call
218
+ */
219
+ export type RpcSessionApprove = z.infer<typeof RpcSessionApproveSchema>;
220
+
221
+ /**
222
+ * @description Type for signing RPC call
223
+ */
224
+ export type RpcSignRequest = z.infer<typeof RpcSignRequestSchema>;
225
+
226
+ /**
227
+ * @description Type for signing RPC response
228
+ */
229
+ export type RpcSignResponse = z.infer<typeof RpcSignResponseSchema>;
230
+
231
+ /**
232
+ * @description Type for transaction submission RPC call
233
+ */
234
+ export type RpcSubmitRequest = z.infer<typeof RpcSubmitRequestSchema>;
235
+
236
+ /**
237
+ * @description Schema for semantic version header validation
238
+ */
239
+ export const RpcVersionHeaderSchema = z.string().regex(/^\d+\.\d+\.\d+$/);
240
+
241
+ /**
242
+ * @description Schema for RPC envelope wrapper.
243
+ * Unknown fields are stripped to prevent injection of arbitrary properties.
244
+ * The hmac field is explicitly declared for HMAC signature verification.
245
+ * @security HWA-37 / SOC2 CC6.1 — strips unknown fields to prevent property injection
246
+ */
247
+ export const RpcEnvelopeSchema = MessageEnvelopeSchema.extend({
248
+ topic: z.literal('rpc'),
249
+ version: RpcVersionHeaderSchema,
250
+ hmac: z.string().optional(), // HWA-37: HMAC signature used by RpcCodec for integrity verification
251
+ payload: z.union([RpcRequestSchema, RpcErrorSchema, RpcSuccessSchema]),
252
+ });
253
+
254
+ /**
255
+ * @description Type representing RPC envelope
256
+ */
257
+ export type RpcEnvelope = z.infer<typeof RpcEnvelopeSchema>;