@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.
- package/README.md +50 -0
- package/dist/address-avatar.d.ts +67 -0
- package/dist/address-avatar.d.ts.map +1 -0
- package/dist/address-avatar.js +130 -0
- package/dist/address-avatar.js.map +1 -0
- package/dist/addressbook.d.ts +289 -0
- package/dist/addressbook.d.ts.map +1 -0
- package/dist/addressbook.js +82 -0
- package/dist/addressbook.js.map +1 -0
- package/dist/enrichment.d.ts +88 -0
- package/dist/enrichment.d.ts.map +1 -0
- package/dist/enrichment.js +47 -0
- package/dist/enrichment.js.map +1 -0
- package/dist/hedera-system-accounts.d.ts +49 -0
- package/dist/hedera-system-accounts.d.ts.map +1 -0
- package/dist/hedera-system-accounts.js +56 -0
- package/dist/hedera-system-accounts.js.map +1 -0
- package/dist/identity.d.ts +94 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +190 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/ledger.d.ts +848 -0
- package/dist/ledger.d.ts.map +1 -0
- package/dist/ledger.js +152 -0
- package/dist/ledger.js.map +1 -0
- package/dist/messages.d.ts +726 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +252 -0
- package/dist/messages.js.map +1 -0
- package/dist/multisig-account.d.ts +419 -0
- package/dist/multisig-account.d.ts.map +1 -0
- package/dist/multisig-account.js +201 -0
- package/dist/multisig-account.js.map +1 -0
- package/dist/private-key-export.d.ts +112 -0
- package/dist/private-key-export.d.ts.map +1 -0
- package/dist/private-key-export.js +11 -0
- package/dist/private-key-export.js.map +1 -0
- package/dist/rpc.d.ts +872 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +143 -0
- package/dist/rpc.js.map +1 -0
- package/dist/transaction-approval.d.ts +895 -0
- package/dist/transaction-approval.d.ts.map +1 -0
- package/dist/transaction-approval.js +11 -0
- package/dist/transaction-approval.js.map +1 -0
- package/dist/transaction-parser.d.ts +93 -0
- package/dist/transaction-parser.d.ts.map +1 -0
- package/dist/transaction-parser.js +11 -0
- package/dist/transaction-parser.js.map +1 -0
- package/dist/vault.d.ts +673 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +188 -0
- package/dist/vault.js.map +1 -0
- package/dist/widget.types.d.ts +323 -0
- package/dist/widget.types.d.ts.map +1 -0
- package/dist/widget.types.js +140 -0
- package/dist/widget.types.js.map +1 -0
- package/package.json +43 -0
- package/src/address-avatar.ts +181 -0
- package/src/addressbook.spec.ts +220 -0
- package/src/addressbook.ts +115 -0
- package/src/enrichment.ts +97 -0
- package/src/hedera-system-accounts.ts +60 -0
- package/src/identity.spec.ts +243 -0
- package/src/identity.ts +244 -0
- package/src/index.ts +197 -0
- package/src/ledger.spec.ts +366 -0
- package/src/ledger.ts +567 -0
- package/src/messages.ts +381 -0
- package/src/multisig-account.spec.ts +362 -0
- package/src/multisig-account.ts +310 -0
- package/src/private-key-export.ts +117 -0
- package/src/rpc.spec.ts +396 -0
- package/src/rpc.ts +257 -0
- package/src/transaction-approval.ts +1033 -0
- package/src/transaction-parser.ts +98 -0
- package/src/vault.spec.ts +268 -0
- package/src/vault.ts +256 -0
- package/src/widget.types.spec.ts +337 -0
- package/src/widget.types.ts +501 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.json +11 -0
- package/vitest.config.ts +36 -0
|
@@ -0,0 +1,117 @@
|
|
|
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 Private key export types for secure key extraction workflows.
|
|
13
|
+
*
|
|
14
|
+
* This module defines the type system for private key export functionality,
|
|
15
|
+
* enabling users to export their private keys in various formats while
|
|
16
|
+
* maintaining comprehensive audit trails for SOC2 compliance.
|
|
17
|
+
*
|
|
18
|
+
* Key Types:
|
|
19
|
+
* - {@link PrivateKeyExportFormat} - Supported export formats (hex, base64, der, familySeed)
|
|
20
|
+
* - {@link PrivateKeyExportRequest} - Request to export a private key
|
|
21
|
+
* - {@link PrivateKeyExportResult} - Result containing exported key in various formats
|
|
22
|
+
* - {@link PrivateKeyExportAuditEvent} - Audit event for compliance logging
|
|
23
|
+
*
|
|
24
|
+
* Export Flow:
|
|
25
|
+
* 1. User selects account and initiates export
|
|
26
|
+
* 2. User acknowledges security risks
|
|
27
|
+
* 3. System verifies authentication (PIN/biometric)
|
|
28
|
+
* 4. Private key exported in requested formats
|
|
29
|
+
* 5. Audit event logged for compliance
|
|
30
|
+
*
|
|
31
|
+
* @module types/private-key-export
|
|
32
|
+
* @security SOC2-CC7.1 - Audit logging for sensitive operations
|
|
33
|
+
*
|
|
34
|
+
* Type definitions for private key export system supporting Hedera and XRPL accounts.
|
|
35
|
+
* Used by the wallet to export keys with full audit trail for SOC2 compliance.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Supported private key export formats
|
|
40
|
+
* - `hex` - Raw hexadecimal string (always available)
|
|
41
|
+
* - `base64` - Base64 encoded (always available)
|
|
42
|
+
* - `der` - DER-encoded PKCS#8 format (Hedera only)
|
|
43
|
+
* - `familySeed` - sXXX... format (XRPL only)
|
|
44
|
+
*/
|
|
45
|
+
export type PrivateKeyExportFormat = 'hex' | 'base64' | 'der' | 'familySeed';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Request to export a private key
|
|
49
|
+
* Contains the identifiers needed to locate and export a key,
|
|
50
|
+
* along with acknowledgement of security risks.
|
|
51
|
+
*/
|
|
52
|
+
export interface PrivateKeyExportRequest {
|
|
53
|
+
/** VaultKey ID */
|
|
54
|
+
keyId: string;
|
|
55
|
+
/** Parent seed ID */
|
|
56
|
+
seedId: string;
|
|
57
|
+
/** User has acknowledged the security risks */
|
|
58
|
+
acknowledgedRisk: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Private key in various formats (ledger-dependent)
|
|
63
|
+
* Contains the private key encoded in multiple formats.
|
|
64
|
+
* Some formats are ledger-specific and will be undefined for other ledgers.
|
|
65
|
+
*/
|
|
66
|
+
export interface PrivateKeyExportFormats {
|
|
67
|
+
/** Raw hex string (always available) */
|
|
68
|
+
hex: string;
|
|
69
|
+
/** Base64 encoded (always available) */
|
|
70
|
+
base64: string;
|
|
71
|
+
/** DER-encoded PKCS#8 (Hedera only) */
|
|
72
|
+
der?: string;
|
|
73
|
+
/** Family seed sXXX... format (XRPL only) */
|
|
74
|
+
familySeed?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Result of a private key export operation
|
|
79
|
+
* Contains the exported key in various formats along with
|
|
80
|
+
* account metadata for display purposes.
|
|
81
|
+
*/
|
|
82
|
+
export interface PrivateKeyExportResult {
|
|
83
|
+
/** Account address */
|
|
84
|
+
address: string;
|
|
85
|
+
/** Public key (hex) */
|
|
86
|
+
publicKey: string;
|
|
87
|
+
/** Ledger identifier */
|
|
88
|
+
ledgerId: string;
|
|
89
|
+
/** Network identifier */
|
|
90
|
+
networkId: string;
|
|
91
|
+
/** Optional account label */
|
|
92
|
+
label?: string;
|
|
93
|
+
/** Exported key in various formats */
|
|
94
|
+
formats: PrivateKeyExportFormats;
|
|
95
|
+
/** Export timestamp (ms since epoch) */
|
|
96
|
+
exportedAt: number;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Audit event for private key export (SOC2 CC7.1)
|
|
101
|
+
* Logged when a private key is exported for compliance and security monitoring.
|
|
102
|
+
* Does not contain the actual private key material.
|
|
103
|
+
*/
|
|
104
|
+
export interface PrivateKeyExportAuditEvent {
|
|
105
|
+
/** Event type identifier */
|
|
106
|
+
type: 'private_key_exported';
|
|
107
|
+
/** VaultKey ID that was exported */
|
|
108
|
+
keyId: string;
|
|
109
|
+
/** Account address */
|
|
110
|
+
address: string;
|
|
111
|
+
/** Ledger identifier */
|
|
112
|
+
ledgerId: string;
|
|
113
|
+
/** Formats in which the key was exported */
|
|
114
|
+
formats: PrivateKeyExportFormat[];
|
|
115
|
+
/** Export timestamp (ms since epoch) */
|
|
116
|
+
timestamp: number;
|
|
117
|
+
}
|
package/src/rpc.spec.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Unit tests for RPC type schemas
|
|
3
|
+
* Tests Zod schema validation for RPC messages
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import {
|
|
7
|
+
RpcVersion,
|
|
8
|
+
RpcVersionHeader,
|
|
9
|
+
RpcMethodSchema,
|
|
10
|
+
RpcRequestSchema,
|
|
11
|
+
RpcErrorSchema,
|
|
12
|
+
RpcSuccessSchema,
|
|
13
|
+
RpcVersionHeaderSchema,
|
|
14
|
+
RpcEnvelopeSchema,
|
|
15
|
+
} from './rpc.js';
|
|
16
|
+
|
|
17
|
+
describe('RPC Constants', () => {
|
|
18
|
+
it('should have correct version', () => {
|
|
19
|
+
expect(RpcVersion).toBe('1.1.0');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should have correct version header name', () => {
|
|
23
|
+
expect(RpcVersionHeader).toBe('x-hsuite-rpc-version');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('RpcMethodSchema', () => {
|
|
28
|
+
it('should accept valid session methods', () => {
|
|
29
|
+
expect(() => RpcMethodSchema.parse('session/request')).not.toThrow();
|
|
30
|
+
expect(() => RpcMethodSchema.parse('session/approve')).not.toThrow();
|
|
31
|
+
expect(() => RpcMethodSchema.parse('session/terminate')).not.toThrow();
|
|
32
|
+
expect(() => RpcMethodSchema.parse('session/status')).not.toThrow();
|
|
33
|
+
expect(() => RpcMethodSchema.parse('session/terminated')).not.toThrow();
|
|
34
|
+
expect(() => RpcMethodSchema.parse('session/updated')).not.toThrow();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should accept valid ledger methods', () => {
|
|
38
|
+
expect(() => RpcMethodSchema.parse('ledger/sign')).not.toThrow();
|
|
39
|
+
expect(() => RpcMethodSchema.parse('ledger/submit')).not.toThrow();
|
|
40
|
+
expect(() => RpcMethodSchema.parse('ledger/signAndSubmit')).not.toThrow();
|
|
41
|
+
expect(() => RpcMethodSchema.parse('ledger/signMessage')).not.toThrow();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should accept valid wallet methods', () => {
|
|
45
|
+
expect(() => RpcMethodSchema.parse('wallet/accounts')).not.toThrow();
|
|
46
|
+
expect(() => RpcMethodSchema.parse('wallet/register-ledger')).not.toThrow();
|
|
47
|
+
expect(() => RpcMethodSchema.parse('wallet/get-config')).not.toThrow();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should reject invalid methods', () => {
|
|
51
|
+
expect(() => RpcMethodSchema.parse('invalid/method')).toThrow();
|
|
52
|
+
expect(() => RpcMethodSchema.parse('')).toThrow();
|
|
53
|
+
expect(() => RpcMethodSchema.parse(123)).toThrow();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('RpcRequestSchema', () => {
|
|
58
|
+
it('should accept valid request', () => {
|
|
59
|
+
const request = {
|
|
60
|
+
jsonrpc: '2.0',
|
|
61
|
+
id: 'test-id',
|
|
62
|
+
method: 'wallet/accounts',
|
|
63
|
+
params: { foo: 'bar' },
|
|
64
|
+
timestamp: Date.now(),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const result = RpcRequestSchema.parse(request);
|
|
68
|
+
expect(result.jsonrpc).toBe('2.0');
|
|
69
|
+
expect(result.id).toBe('test-id');
|
|
70
|
+
expect(result.method).toBe('wallet/accounts');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should accept numeric id', () => {
|
|
74
|
+
const request = {
|
|
75
|
+
jsonrpc: '2.0',
|
|
76
|
+
id: 123,
|
|
77
|
+
method: 'ledger/sign',
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const result = RpcRequestSchema.parse(request);
|
|
82
|
+
expect(result.id).toBe(123);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should accept optional origin', () => {
|
|
86
|
+
const request = {
|
|
87
|
+
jsonrpc: '2.0',
|
|
88
|
+
id: 'test',
|
|
89
|
+
method: 'session/request',
|
|
90
|
+
origin: 'https://dapp.example.com',
|
|
91
|
+
timestamp: Date.now(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const result = RpcRequestSchema.parse(request);
|
|
95
|
+
expect(result.origin).toBe('https://dapp.example.com');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should reject invalid jsonrpc version', () => {
|
|
99
|
+
const request = {
|
|
100
|
+
jsonrpc: '1.0',
|
|
101
|
+
id: 'test',
|
|
102
|
+
method: 'wallet/accounts',
|
|
103
|
+
timestamp: Date.now(),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
expect(() => RpcRequestSchema.parse(request)).toThrow();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should reject missing timestamp', () => {
|
|
110
|
+
const request = {
|
|
111
|
+
jsonrpc: '2.0',
|
|
112
|
+
id: 'test',
|
|
113
|
+
method: 'wallet/accounts',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
expect(() => RpcRequestSchema.parse(request)).toThrow();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('RpcErrorSchema', () => {
|
|
121
|
+
it('should accept valid error response', () => {
|
|
122
|
+
const error = {
|
|
123
|
+
jsonrpc: '2.0',
|
|
124
|
+
id: 'test-id',
|
|
125
|
+
error: {
|
|
126
|
+
code: -32600,
|
|
127
|
+
message: 'Invalid Request',
|
|
128
|
+
},
|
|
129
|
+
timestamp: Date.now(),
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const result = RpcErrorSchema.parse(error);
|
|
133
|
+
expect(result.error.code).toBe(-32600);
|
|
134
|
+
expect(result.error.message).toBe('Invalid Request');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should accept null id for parse errors', () => {
|
|
138
|
+
const error = {
|
|
139
|
+
jsonrpc: '2.0',
|
|
140
|
+
id: null,
|
|
141
|
+
error: {
|
|
142
|
+
code: -32700,
|
|
143
|
+
message: 'Parse error',
|
|
144
|
+
},
|
|
145
|
+
timestamp: Date.now(),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const result = RpcErrorSchema.parse(error);
|
|
149
|
+
expect(result.id).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should accept error with data', () => {
|
|
153
|
+
const error = {
|
|
154
|
+
jsonrpc: '2.0',
|
|
155
|
+
id: 'test',
|
|
156
|
+
error: {
|
|
157
|
+
code: -32000,
|
|
158
|
+
message: 'Server error',
|
|
159
|
+
data: { details: 'Additional info' },
|
|
160
|
+
},
|
|
161
|
+
timestamp: Date.now(),
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const result = RpcErrorSchema.parse(error);
|
|
165
|
+
expect(result.error.data).toEqual({ details: 'Additional info' });
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('RpcSuccessSchema', () => {
|
|
170
|
+
it('should accept valid success response', () => {
|
|
171
|
+
const success = {
|
|
172
|
+
jsonrpc: '2.0',
|
|
173
|
+
id: 'test-id',
|
|
174
|
+
result: { accounts: ['0.0.12345'] },
|
|
175
|
+
timestamp: Date.now(),
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const result = RpcSuccessSchema.parse(success);
|
|
179
|
+
expect(result.result).toEqual({ accounts: ['0.0.12345'] });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should accept any result type', () => {
|
|
183
|
+
const stringResult = {
|
|
184
|
+
jsonrpc: '2.0',
|
|
185
|
+
id: 'test',
|
|
186
|
+
result: 'success',
|
|
187
|
+
timestamp: Date.now(),
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
expect(() => RpcSuccessSchema.parse(stringResult)).not.toThrow();
|
|
191
|
+
|
|
192
|
+
const arrayResult = {
|
|
193
|
+
jsonrpc: '2.0',
|
|
194
|
+
id: 'test',
|
|
195
|
+
result: [1, 2, 3],
|
|
196
|
+
timestamp: Date.now(),
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
expect(() => RpcSuccessSchema.parse(arrayResult)).not.toThrow();
|
|
200
|
+
|
|
201
|
+
const nullResult = {
|
|
202
|
+
jsonrpc: '2.0',
|
|
203
|
+
id: 'test',
|
|
204
|
+
result: null,
|
|
205
|
+
timestamp: Date.now(),
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
expect(() => RpcSuccessSchema.parse(nullResult)).not.toThrow();
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('RpcVersionHeaderSchema', () => {
|
|
213
|
+
it('should accept valid semver versions', () => {
|
|
214
|
+
expect(() => RpcVersionHeaderSchema.parse('1.0.0')).not.toThrow();
|
|
215
|
+
expect(() => RpcVersionHeaderSchema.parse('1.1.0')).not.toThrow();
|
|
216
|
+
expect(() => RpcVersionHeaderSchema.parse('2.10.100')).not.toThrow();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should reject invalid versions', () => {
|
|
220
|
+
expect(() => RpcVersionHeaderSchema.parse('1.0')).toThrow();
|
|
221
|
+
expect(() => RpcVersionHeaderSchema.parse('1')).toThrow();
|
|
222
|
+
expect(() => RpcVersionHeaderSchema.parse('1.0.0-alpha')).toThrow();
|
|
223
|
+
expect(() => RpcVersionHeaderSchema.parse('v1.0.0')).toThrow();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe('RpcRequestSchema — HWA-37 unknown field stripping', () => {
|
|
228
|
+
it('should strip unknown fields from parsed output', () => {
|
|
229
|
+
const request = {
|
|
230
|
+
jsonrpc: '2.0' as const,
|
|
231
|
+
id: 'test-id',
|
|
232
|
+
method: 'wallet/accounts' as const,
|
|
233
|
+
timestamp: Date.now(),
|
|
234
|
+
__injected: 'malicious-value',
|
|
235
|
+
extraField: true,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const result = RpcRequestSchema.parse(request);
|
|
239
|
+
expect(result).not.toHaveProperty('__injected');
|
|
240
|
+
expect(result).not.toHaveProperty('extraField');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('RpcSuccessSchema — HWA-37 unknown field stripping', () => {
|
|
245
|
+
it('should strip unknown fields from parsed output', () => {
|
|
246
|
+
const success = {
|
|
247
|
+
jsonrpc: '2.0' as const,
|
|
248
|
+
id: 'test-id',
|
|
249
|
+
result: { data: 'ok' },
|
|
250
|
+
timestamp: Date.now(),
|
|
251
|
+
__injected: 'malicious-value',
|
|
252
|
+
extraField: true,
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const result = RpcSuccessSchema.parse(success);
|
|
256
|
+
expect(result).not.toHaveProperty('__injected');
|
|
257
|
+
expect(result).not.toHaveProperty('extraField');
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('RpcErrorSchema — HWA-37 unknown field stripping', () => {
|
|
262
|
+
it('should strip unknown fields from parsed output', () => {
|
|
263
|
+
const error = {
|
|
264
|
+
jsonrpc: '2.0' as const,
|
|
265
|
+
id: 'test-id',
|
|
266
|
+
error: { code: -32600, message: 'Invalid Request' },
|
|
267
|
+
timestamp: Date.now(),
|
|
268
|
+
__injected: 'malicious-value',
|
|
269
|
+
extraField: true,
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const result = RpcErrorSchema.parse(error);
|
|
273
|
+
expect(result).not.toHaveProperty('__injected');
|
|
274
|
+
expect(result).not.toHaveProperty('extraField');
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('RpcEnvelopeSchema', () => {
|
|
279
|
+
it('should accept valid request envelope', () => {
|
|
280
|
+
const envelope = {
|
|
281
|
+
id: '550e8400-e29b-41d4-a716-446655440002',
|
|
282
|
+
topic: 'rpc',
|
|
283
|
+
version: '1.1.0',
|
|
284
|
+
createdAt: Date.now(),
|
|
285
|
+
payload: {
|
|
286
|
+
jsonrpc: '2.0',
|
|
287
|
+
id: 'test',
|
|
288
|
+
method: 'wallet/accounts',
|
|
289
|
+
timestamp: Date.now(),
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const result = RpcEnvelopeSchema.parse(envelope);
|
|
294
|
+
expect(result.topic).toBe('rpc');
|
|
295
|
+
expect(result.version).toBe('1.1.0');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('should accept valid success envelope', () => {
|
|
299
|
+
const envelope = {
|
|
300
|
+
id: '550e8400-e29b-41d4-a716-446655440000',
|
|
301
|
+
topic: 'rpc',
|
|
302
|
+
version: '1.1.0',
|
|
303
|
+
createdAt: Date.now(),
|
|
304
|
+
payload: {
|
|
305
|
+
jsonrpc: '2.0',
|
|
306
|
+
id: 'test',
|
|
307
|
+
result: { data: 'success' },
|
|
308
|
+
timestamp: Date.now(),
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
expect(() => RpcEnvelopeSchema.parse(envelope)).not.toThrow();
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('should accept valid error envelope', () => {
|
|
316
|
+
const envelope = {
|
|
317
|
+
id: '550e8400-e29b-41d4-a716-446655440001',
|
|
318
|
+
topic: 'rpc',
|
|
319
|
+
version: '1.1.0',
|
|
320
|
+
createdAt: Date.now(),
|
|
321
|
+
payload: {
|
|
322
|
+
jsonrpc: '2.0',
|
|
323
|
+
id: 'test',
|
|
324
|
+
error: { code: -32600, message: 'Error' },
|
|
325
|
+
timestamp: Date.now(),
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
expect(() => RpcEnvelopeSchema.parse(envelope)).not.toThrow();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// HWA-37: Verify unknown fields are stripped from envelope
|
|
333
|
+
it('should strip unknown fields from envelope output', () => {
|
|
334
|
+
const envelope = {
|
|
335
|
+
id: '550e8400-e29b-41d4-a716-446655440002',
|
|
336
|
+
topic: 'rpc',
|
|
337
|
+
version: '1.1.0',
|
|
338
|
+
createdAt: Date.now(),
|
|
339
|
+
payload: {
|
|
340
|
+
jsonrpc: '2.0',
|
|
341
|
+
id: 'test',
|
|
342
|
+
method: 'wallet/accounts',
|
|
343
|
+
timestamp: Date.now(),
|
|
344
|
+
},
|
|
345
|
+
__injected: 'malicious-value',
|
|
346
|
+
extraField: true,
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const result = RpcEnvelopeSchema.parse(envelope);
|
|
350
|
+
expect(result).not.toHaveProperty('__injected');
|
|
351
|
+
expect(result).not.toHaveProperty('extraField');
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// HWA-37: Verify unknown fields are stripped from nested payload
|
|
355
|
+
it('should strip unknown fields from payload within envelope', () => {
|
|
356
|
+
const envelope = {
|
|
357
|
+
id: '550e8400-e29b-41d4-a716-446655440002',
|
|
358
|
+
topic: 'rpc',
|
|
359
|
+
version: '1.1.0',
|
|
360
|
+
createdAt: Date.now(),
|
|
361
|
+
payload: {
|
|
362
|
+
jsonrpc: '2.0',
|
|
363
|
+
id: 'test',
|
|
364
|
+
method: 'wallet/accounts',
|
|
365
|
+
timestamp: Date.now(),
|
|
366
|
+
__injected: 'malicious-value',
|
|
367
|
+
extraField: true,
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const result = RpcEnvelopeSchema.parse(envelope);
|
|
372
|
+
const payload = result.payload as Record<string, unknown>;
|
|
373
|
+
expect(payload).not.toHaveProperty('__injected');
|
|
374
|
+
expect(payload).not.toHaveProperty('extraField');
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// HWA-37: Verify hmac field is preserved (legitimate field used by RpcCodec)
|
|
378
|
+
it('should preserve the hmac field on envelope', () => {
|
|
379
|
+
const envelope = {
|
|
380
|
+
id: '550e8400-e29b-41d4-a716-446655440002',
|
|
381
|
+
topic: 'rpc',
|
|
382
|
+
version: '1.1.0',
|
|
383
|
+
createdAt: Date.now(),
|
|
384
|
+
hmac: 'kWZKQ4m9R8vH2xJ5N7pE3w==',
|
|
385
|
+
payload: {
|
|
386
|
+
jsonrpc: '2.0',
|
|
387
|
+
id: 'test',
|
|
388
|
+
method: 'wallet/accounts',
|
|
389
|
+
timestamp: Date.now(),
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const result = RpcEnvelopeSchema.parse(envelope);
|
|
394
|
+
expect(result).toHaveProperty('hmac', 'kWZKQ4m9R8vH2xJ5N7pE3w==');
|
|
395
|
+
});
|
|
396
|
+
});
|