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.
- package/README.md +82 -27
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/kms/client.d.ts.map +1 -1
- package/dist/kms/client.js +1 -1
- package/dist/kms/client.js.map +1 -1
- package/dist/kms/signer.d.ts +2 -2
- package/dist/kms/signer.d.ts.map +1 -1
- package/dist/kms/signer.js +2 -2
- package/dist/kms/signer.js.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/publicKey.js.map +1 -1
- package/package.json +17 -16
- package/src/errors/index.test.ts +185 -170
- package/src/errors/index.ts +21 -12
- package/src/index.ts +10 -14
- package/src/kms/client.test.ts +318 -255
- package/src/kms/client.ts +100 -98
- package/src/kms/signer.test.ts +415 -396
- package/src/kms/signer.ts +205 -209
- package/src/types/index.ts +27 -27
- package/src/utils/publicKey.test.ts +178 -119
- package/src/utils/publicKey.ts +34 -34
package/src/errors/index.test.ts
CHANGED
|
@@ -1,173 +1,188 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
});
|
package/src/errors/index.ts
CHANGED
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export class KmsClientError extends Error {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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';
|