solana-kms-signer 0.1.0 → 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.
@@ -1,173 +1,188 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { KmsClientError, PublicKeyExtractionError, SignatureVerificationError } from './index.js';
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ KmsClientError,
4
+ PublicKeyExtractionError,
5
+ SignatureVerificationError,
6
+ } from './index.js';
3
7
 
4
8
  describe('Error Classes', () => {
5
- describe('KmsClientError', () => {
6
- it('should create error with message', () => {
7
- // given
8
- const message = 'Test KMS error';
9
-
10
- // when
11
- const error = new KmsClientError(message);
12
-
13
- // then
14
- expect(error).toBeInstanceOf(Error);
15
- expect(error).toBeInstanceOf(KmsClientError);
16
- expect(error.message).toBe(message);
17
- expect(error.name).toBe('KmsClientError');
18
- expect(error.cause).toBeUndefined();
19
- });
20
-
21
- it('should create error with message and cause', () => {
22
- // given
23
- const message = 'Test KMS error';
24
- const cause = new Error('Original error');
25
-
26
- // when
27
- const error = new KmsClientError(message, cause);
28
-
29
- // then
30
- expect(error.message).toBe(message);
31
- expect(error.cause).toBe(cause);
32
- expect(error.name).toBe('KmsClientError');
33
- });
34
-
35
- it('should create error with cause as object', () => {
36
- // given
37
- const message = 'Test KMS error';
38
- const cause = { code: 'AccessDeniedException', statusCode: 403 };
39
-
40
- // when
41
- const error = new KmsClientError(message, cause);
42
-
43
- // then
44
- expect(error.cause).toBe(cause);
45
- });
46
-
47
- it('should have stack trace', () => {
48
- // given
49
- const message = 'Test KMS error';
50
-
51
- // when
52
- const error = new KmsClientError(message);
53
-
54
- // then
55
- expect(error.stack).toBeDefined();
56
- expect(error.stack).toContain('KmsClientError');
57
- });
58
- });
59
-
60
- describe('PublicKeyExtractionError', () => {
61
- it('should create error with message', () => {
62
- // given
63
- const message = 'Invalid DER encoding';
64
-
65
- // when
66
- const error = new PublicKeyExtractionError(message);
67
-
68
- // then
69
- expect(error).toBeInstanceOf(Error);
70
- expect(error).toBeInstanceOf(PublicKeyExtractionError);
71
- expect(error.message).toBe(message);
72
- expect(error.name).toBe('PublicKeyExtractionError');
73
- expect(error.cause).toBeUndefined();
74
- });
75
-
76
- it('should create error with message and cause', () => {
77
- // given
78
- const message = 'Invalid DER encoding';
79
- const cause = new Error('DER parsing failed');
80
-
81
- // when
82
- const error = new PublicKeyExtractionError(message, cause);
83
-
84
- // then
85
- expect(error.message).toBe(message);
86
- expect(error.cause).toBe(cause);
87
- expect(error.name).toBe('PublicKeyExtractionError');
88
- });
89
-
90
- it('should have stack trace', () => {
91
- // given
92
- const message = 'Invalid DER encoding';
93
-
94
- // when
95
- const error = new PublicKeyExtractionError(message);
96
-
97
- // then
98
- expect(error.stack).toBeDefined();
99
- expect(error.stack).toContain('PublicKeyExtractionError');
100
- });
101
- });
102
-
103
- describe('SignatureVerificationError', () => {
104
- it('should create error with message', () => {
105
- // given
106
- const message = 'Signature verification failed';
107
-
108
- // when
109
- const error = new SignatureVerificationError(message);
110
-
111
- // then
112
- expect(error).toBeInstanceOf(Error);
113
- expect(error).toBeInstanceOf(SignatureVerificationError);
114
- expect(error.message).toBe(message);
115
- expect(error.name).toBe('SignatureVerificationError');
116
- expect(error.cause).toBeUndefined();
117
- });
118
-
119
- it('should create error with message and cause', () => {
120
- // given
121
- const message = 'Signature verification failed';
122
- const cause = { signature: new Uint8Array(64), publicKey: new Uint8Array(32) };
123
-
124
- // when
125
- const error = new SignatureVerificationError(message, cause);
126
-
127
- // then
128
- expect(error.message).toBe(message);
129
- expect(error.cause).toBe(cause);
130
- expect(error.name).toBe('SignatureVerificationError');
131
- });
132
-
133
- it('should have stack trace', () => {
134
- // given
135
- const message = 'Signature verification failed';
136
-
137
- // when
138
- const error = new SignatureVerificationError(message);
139
-
140
- // then
141
- expect(error.stack).toBeDefined();
142
- expect(error.stack).toContain('SignatureVerificationError');
143
- });
144
- });
145
-
146
- describe('Error Chaining', () => {
147
- it('should support error chaining with nested causes', () => {
148
- // given
149
- const rootCause = new Error('Root cause error');
150
- const intermediateCause = new PublicKeyExtractionError('Intermediate error', rootCause);
151
-
152
- // when
153
- const topLevelError = new KmsClientError('Top level error', intermediateCause);
154
-
155
- // then
156
- expect(topLevelError.cause).toBe(intermediateCause);
157
- expect((topLevelError.cause as PublicKeyExtractionError).cause).toBe(rootCause);
158
- });
159
-
160
- it('should preserve cause immutability', () => {
161
- // given
162
- const message = 'Test error';
163
- const cause = { code: 'TEST_ERROR' };
164
- const error = new KmsClientError(message, cause);
165
-
166
- // when/then
167
- // TypeScript should prevent reassignment:
168
- // error.cause = { code: 'DIFFERENT_ERROR' }; // This would cause TypeScript error
169
-
170
- expect(error.cause).toBe(cause);
171
- });
172
- });
9
+ describe('KmsClientError', () => {
10
+ it('should create error with message', () => {
11
+ // given
12
+ const message = 'Test KMS error';
13
+
14
+ // when
15
+ const error = new KmsClientError(message);
16
+
17
+ // then
18
+ expect(error).toBeInstanceOf(Error);
19
+ expect(error).toBeInstanceOf(KmsClientError);
20
+ expect(error.message).toBe(message);
21
+ expect(error.name).toBe('KmsClientError');
22
+ expect(error.cause).toBeUndefined();
23
+ });
24
+
25
+ it('should create error with message and cause', () => {
26
+ // given
27
+ const message = 'Test KMS error';
28
+ const cause = new Error('Original error');
29
+
30
+ // when
31
+ const error = new KmsClientError(message, cause);
32
+
33
+ // then
34
+ expect(error.message).toBe(message);
35
+ expect(error.cause).toBe(cause);
36
+ expect(error.name).toBe('KmsClientError');
37
+ });
38
+
39
+ it('should create error with cause as object', () => {
40
+ // given
41
+ const message = 'Test KMS error';
42
+ const cause = { code: 'AccessDeniedException', statusCode: 403 };
43
+
44
+ // when
45
+ const error = new KmsClientError(message, cause);
46
+
47
+ // then
48
+ expect(error.cause).toBe(cause);
49
+ });
50
+
51
+ it('should have stack trace', () => {
52
+ // given
53
+ const message = 'Test KMS error';
54
+
55
+ // when
56
+ const error = new KmsClientError(message);
57
+
58
+ // then
59
+ expect(error.stack).toBeDefined();
60
+ expect(error.stack).toContain('KmsClientError');
61
+ });
62
+ });
63
+
64
+ describe('PublicKeyExtractionError', () => {
65
+ it('should create error with message', () => {
66
+ // given
67
+ const message = 'Invalid DER encoding';
68
+
69
+ // when
70
+ const error = new PublicKeyExtractionError(message);
71
+
72
+ // then
73
+ expect(error).toBeInstanceOf(Error);
74
+ expect(error).toBeInstanceOf(PublicKeyExtractionError);
75
+ expect(error.message).toBe(message);
76
+ expect(error.name).toBe('PublicKeyExtractionError');
77
+ expect(error.cause).toBeUndefined();
78
+ });
79
+
80
+ it('should create error with message and cause', () => {
81
+ // given
82
+ const message = 'Invalid DER encoding';
83
+ const cause = new Error('DER parsing failed');
84
+
85
+ // when
86
+ const error = new PublicKeyExtractionError(message, cause);
87
+
88
+ // then
89
+ expect(error.message).toBe(message);
90
+ expect(error.cause).toBe(cause);
91
+ expect(error.name).toBe('PublicKeyExtractionError');
92
+ });
93
+
94
+ it('should have stack trace', () => {
95
+ // given
96
+ const message = 'Invalid DER encoding';
97
+
98
+ // when
99
+ const error = new PublicKeyExtractionError(message);
100
+
101
+ // then
102
+ expect(error.stack).toBeDefined();
103
+ expect(error.stack).toContain('PublicKeyExtractionError');
104
+ });
105
+ });
106
+
107
+ describe('SignatureVerificationError', () => {
108
+ it('should create error with message', () => {
109
+ // given
110
+ const message = 'Signature verification failed';
111
+
112
+ // when
113
+ const error = new SignatureVerificationError(message);
114
+
115
+ // then
116
+ expect(error).toBeInstanceOf(Error);
117
+ expect(error).toBeInstanceOf(SignatureVerificationError);
118
+ expect(error.message).toBe(message);
119
+ expect(error.name).toBe('SignatureVerificationError');
120
+ expect(error.cause).toBeUndefined();
121
+ });
122
+
123
+ it('should create error with message and cause', () => {
124
+ // given
125
+ const message = 'Signature verification failed';
126
+ const cause = {
127
+ signature: new Uint8Array(64),
128
+ publicKey: new Uint8Array(32),
129
+ };
130
+
131
+ // when
132
+ const error = new SignatureVerificationError(message, cause);
133
+
134
+ // then
135
+ expect(error.message).toBe(message);
136
+ expect(error.cause).toBe(cause);
137
+ expect(error.name).toBe('SignatureVerificationError');
138
+ });
139
+
140
+ it('should have stack trace', () => {
141
+ // given
142
+ const message = 'Signature verification failed';
143
+
144
+ // when
145
+ const error = new SignatureVerificationError(message);
146
+
147
+ // then
148
+ expect(error.stack).toBeDefined();
149
+ expect(error.stack).toContain('SignatureVerificationError');
150
+ });
151
+ });
152
+
153
+ describe('Error Chaining', () => {
154
+ it('should support error chaining with nested causes', () => {
155
+ // given
156
+ const rootCause = new Error('Root cause error');
157
+ const intermediateCause = new PublicKeyExtractionError(
158
+ 'Intermediate error',
159
+ rootCause,
160
+ );
161
+
162
+ // when
163
+ const topLevelError = new KmsClientError(
164
+ 'Top level error',
165
+ intermediateCause,
166
+ );
167
+
168
+ // then
169
+ expect(topLevelError.cause).toBe(intermediateCause);
170
+ expect((topLevelError.cause as PublicKeyExtractionError).cause).toBe(
171
+ rootCause,
172
+ );
173
+ });
174
+
175
+ it('should preserve cause immutability', () => {
176
+ // given
177
+ const message = 'Test error';
178
+ const cause = { code: 'TEST_ERROR' };
179
+ const error = new KmsClientError(message, cause);
180
+
181
+ // when/then
182
+ // TypeScript should prevent reassignment:
183
+ // error.cause = { code: 'DIFFERENT_ERROR' }; // This would cause TypeScript error
184
+
185
+ expect(error.cause).toBe(cause);
186
+ });
187
+ });
173
188
  });
@@ -12,10 +12,13 @@
12
12
  * ```
13
13
  */
14
14
  export class KmsClientError extends Error {
15
- constructor(message: string, public readonly cause?: unknown) {
16
- super(message);
17
- this.name = 'KmsClientError';
18
- }
15
+ constructor(
16
+ message: string,
17
+ public readonly cause?: unknown,
18
+ ) {
19
+ super(message);
20
+ this.name = 'KmsClientError';
21
+ }
19
22
  }
20
23
 
21
24
  /**
@@ -33,10 +36,13 @@ export class KmsClientError extends Error {
33
36
  * ```
34
37
  */
35
38
  export class PublicKeyExtractionError extends Error {
36
- constructor(message: string, public readonly cause?: unknown) {
37
- super(message);
38
- this.name = 'PublicKeyExtractionError';
39
- }
39
+ constructor(
40
+ message: string,
41
+ public readonly cause?: unknown,
42
+ ) {
43
+ super(message);
44
+ this.name = 'PublicKeyExtractionError';
45
+ }
40
46
  }
41
47
 
42
48
  /**
@@ -54,8 +60,11 @@ export class PublicKeyExtractionError extends Error {
54
60
  * ```
55
61
  */
56
62
  export class SignatureVerificationError extends Error {
57
- constructor(message: string, public readonly cause?: unknown) {
58
- super(message);
59
- this.name = 'SignatureVerificationError';
60
- }
63
+ constructor(
64
+ message: string,
65
+ public readonly cause?: unknown,
66
+ ) {
67
+ super(message);
68
+ this.name = 'SignatureVerificationError';
69
+ }
61
70
  }
package/src/index.ts CHANGED
@@ -6,22 +6,18 @@
6
6
  * @module solana-kms-signer
7
7
  */
8
8
 
9
+ // Re-export commonly used Solana types for convenience
10
+ export { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
11
+ // Error classes
12
+ export {
13
+ KmsClientError,
14
+ PublicKeyExtractionError,
15
+ SignatureVerificationError,
16
+ } from './errors/index.js';
9
17
  // Core classes
10
18
  export { KmsClient } from './kms/client.js';
11
19
  export { SolanaKmsSigner } from './kms/signer.js';
12
-
13
- // Utility functions
14
- export { extractEd25519PublicKey } from './utils/publicKey.js';
15
-
16
20
  // Type definitions
17
21
  export type { KmsConfig, SolanaKmsSignerConfig } from './types/index.js';
18
-
19
- // Error classes
20
- export {
21
- KmsClientError,
22
- PublicKeyExtractionError,
23
- SignatureVerificationError,
24
- } from './errors/index.js';
25
-
26
- // Re-export commonly used Solana types for convenience
27
- export { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
22
+ // Utility functions
23
+ export { extractEd25519PublicKey } from './utils/publicKey.js';