evm-kms-signer 1.0.0 → 1.1.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 +75 -16
- package/dist/account.d.ts +30 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +41 -1
- package/dist/account.js.map +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/gcp/client.d.ts +91 -0
- package/dist/gcp/client.d.ts.map +1 -0
- package/dist/gcp/client.js +179 -0
- package/dist/gcp/client.js.map +1 -0
- package/dist/gcp/signer.d.ts +212 -0
- package/dist/gcp/signer.d.ts.map +1 -0
- package/dist/gcp/signer.js +296 -0
- package/dist/gcp/signer.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- 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 +14 -9
- package/dist/kms/signer.js.map +1 -1
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/address.d.ts.map +1 -1
- package/dist/utils/address.js.map +1 -1
- package/dist/utils/der.d.ts.map +1 -1
- package/dist/utils/der.js +2 -2
- package/dist/utils/der.js.map +1 -1
- package/dist/utils/signature.d.ts +1 -1
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/signature.js +7 -10
- package/dist/utils/signature.js.map +1 -1
- package/package.json +26 -16
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { TypedData } from 'abitype';
|
|
2
|
+
import type { Address, Hex, SerializeTransactionFn, TransactionSerializable, TypedDataDefinition } from 'viem';
|
|
3
|
+
import type { GcpKmsConfig } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* GcpSigner provides Ethereum signing capabilities using GCP KMS.
|
|
6
|
+
*
|
|
7
|
+
* This class manages the interaction with GCP KMS for cryptographic operations
|
|
8
|
+
* required by Ethereum accounts:
|
|
9
|
+
* - Public key retrieval and caching
|
|
10
|
+
* - Ethereum address derivation from KMS public key
|
|
11
|
+
* - Message and transaction signing
|
|
12
|
+
*
|
|
13
|
+
* The signer caches expensive operations (public key retrieval, address derivation)
|
|
14
|
+
* to avoid unnecessary KMS API calls.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const signer = new GcpSigner({
|
|
19
|
+
* projectId: 'my-project',
|
|
20
|
+
* locationId: 'global',
|
|
21
|
+
* keyRingId: 'my-keyring',
|
|
22
|
+
* keyId: 'my-key',
|
|
23
|
+
* keyVersion: '1'
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* const address = await signer.getAddress()
|
|
27
|
+
* console.log('Ethereum address:', address)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class GcpSigner {
|
|
31
|
+
private gcpClient;
|
|
32
|
+
private cachedAddress?;
|
|
33
|
+
private cachedPublicKey?;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new GCP KMS signer instance.
|
|
36
|
+
*
|
|
37
|
+
* @param config - GCP KMS configuration including project, location, key ring, key, and version
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The constructor initializes the GCP KMS client but does not make any API calls.
|
|
41
|
+
* Public key retrieval and address derivation happen lazily on first use.
|
|
42
|
+
*/
|
|
43
|
+
constructor(config: GcpKmsConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves the uncompressed secp256k1 public key from GCP KMS.
|
|
46
|
+
*
|
|
47
|
+
* The public key is retrieved from KMS and extracted from the DER-encoded
|
|
48
|
+
* SubjectPublicKeyInfo format. The result is cached to avoid redundant KMS calls.
|
|
49
|
+
*
|
|
50
|
+
* @returns 65-byte uncompressed public key (0x04 + x coordinate + y coordinate)
|
|
51
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
52
|
+
* @throws {DerParsingError} If public key format is invalid
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* The public key format is:
|
|
56
|
+
* - Byte 0: 0x04 (uncompressed point indicator)
|
|
57
|
+
* - Bytes 1-32: x coordinate of the public key
|
|
58
|
+
* - Bytes 33-64: y coordinate of the public key
|
|
59
|
+
*/
|
|
60
|
+
getPublicKey(): Promise<Uint8Array>;
|
|
61
|
+
/**
|
|
62
|
+
* Derives the Ethereum address from the GCP KMS public key.
|
|
63
|
+
*
|
|
64
|
+
* The address is calculated by:
|
|
65
|
+
* 1. Retrieving the public key from KMS (cached if available)
|
|
66
|
+
* 2. Hashing the public key coordinates with keccak256
|
|
67
|
+
* 3. Taking the last 20 bytes as the address
|
|
68
|
+
*
|
|
69
|
+
* The result is cached to avoid redundant derivation.
|
|
70
|
+
*
|
|
71
|
+
* @returns Ethereum address (0x-prefixed, 40 hex characters)
|
|
72
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
73
|
+
* @throws {DerParsingError} If public key format is invalid
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* The returned address follows EIP-55 checksum encoding.
|
|
77
|
+
*/
|
|
78
|
+
getAddress(): Promise<Address>;
|
|
79
|
+
/**
|
|
80
|
+
* Signs a hash using the GCP KMS private key (internal helper method).
|
|
81
|
+
*
|
|
82
|
+
* This method is used internally by signMessage, signTransaction, and signTypedData.
|
|
83
|
+
* It converts the hash to bytes, signs with KMS, parses the DER signature,
|
|
84
|
+
* and normalizes the s value according to EIP-2.
|
|
85
|
+
*
|
|
86
|
+
* @param hash - The hash to sign (32 bytes, hex-encoded)
|
|
87
|
+
* @returns Object containing r and s as bigints
|
|
88
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
89
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
90
|
+
* @throws {SignatureNormalizationError} If s value is out of valid range
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* The s value is automatically normalized to the lower half of the curve order (EIP-2)
|
|
94
|
+
* to prevent signature malleability attacks.
|
|
95
|
+
*/
|
|
96
|
+
private signHash;
|
|
97
|
+
/**
|
|
98
|
+
* Signs a message using EIP-191 personal_sign standard.
|
|
99
|
+
*
|
|
100
|
+
* This method:
|
|
101
|
+
* 1. Hashes the message with EIP-191 prefix: "\x19Ethereum Signed Message:\n" + len(message) + message
|
|
102
|
+
* 2. Signs the hash with GCP KMS
|
|
103
|
+
* 3. Calculates the recovery ID to enable public key recovery
|
|
104
|
+
* 4. Returns the signature in the standard format: r (32 bytes) + s (32 bytes) + v (1 byte)
|
|
105
|
+
*
|
|
106
|
+
* @param params - Object containing the message string
|
|
107
|
+
* @returns The signature as a hex string (0x-prefixed, 130 characters)
|
|
108
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
109
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
110
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const signer = new GcpSigner({
|
|
115
|
+
* projectId: 'my-project',
|
|
116
|
+
* locationId: 'global',
|
|
117
|
+
* keyRingId: 'my-keyring',
|
|
118
|
+
* keyId: 'my-key',
|
|
119
|
+
* keyVersion: '1'
|
|
120
|
+
* })
|
|
121
|
+
* const signature = await signer.signMessage({ message: 'Hello, world!' })
|
|
122
|
+
* // signature: '0x...' (130 characters: 0x + 64 hex chars for r + 64 for s + 2 for v)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
signMessage({ message }: {
|
|
126
|
+
message: string;
|
|
127
|
+
}): Promise<Hex>;
|
|
128
|
+
/**
|
|
129
|
+
* Signs an Ethereum transaction.
|
|
130
|
+
*
|
|
131
|
+
* This method:
|
|
132
|
+
* 1. Serializes the transaction without signature fields (r, s, v)
|
|
133
|
+
* 2. Hashes the serialized transaction with keccak256
|
|
134
|
+
* 3. Signs the hash with GCP KMS
|
|
135
|
+
* 4. Calculates the recovery ID
|
|
136
|
+
* 5. Computes the v value (EIP-155 if chainId present, legacy otherwise)
|
|
137
|
+
* 6. Returns the fully serialized transaction with signature
|
|
138
|
+
*
|
|
139
|
+
* @param transaction - The transaction to sign
|
|
140
|
+
* @param options - Optional serializer function (defaults to viem's serializeTransaction)
|
|
141
|
+
* @returns The serialized signed transaction as a hex string
|
|
142
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
143
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
144
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const signer = new GcpSigner({
|
|
149
|
+
* projectId: 'my-project',
|
|
150
|
+
* locationId: 'global',
|
|
151
|
+
* keyRingId: 'my-keyring',
|
|
152
|
+
* keyId: 'my-key',
|
|
153
|
+
* keyVersion: '1'
|
|
154
|
+
* })
|
|
155
|
+
* const signedTx = await signer.signTransaction({
|
|
156
|
+
* to: '0x...',
|
|
157
|
+
* value: parseEther('1'),
|
|
158
|
+
* chainId: 1
|
|
159
|
+
* })
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
signTransaction(transaction: TransactionSerializable, { serializer, }?: {
|
|
163
|
+
serializer?: SerializeTransactionFn;
|
|
164
|
+
}): Promise<Hex>;
|
|
165
|
+
/**
|
|
166
|
+
* Signs typed data according to EIP-712.
|
|
167
|
+
*
|
|
168
|
+
* This method:
|
|
169
|
+
* 1. Hashes the typed data using EIP-712 (domain separator + type hash)
|
|
170
|
+
* 2. Signs the hash with GCP KMS
|
|
171
|
+
* 3. Calculates the recovery ID
|
|
172
|
+
* 4. Returns the signature in the standard format: r (32 bytes) + s (32 bytes) + v (1 byte)
|
|
173
|
+
*
|
|
174
|
+
* @param typedData - The EIP-712 typed data to sign
|
|
175
|
+
* @returns The signature as a hex string (0x-prefixed, 130 characters)
|
|
176
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
177
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
178
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const signer = new GcpSigner({
|
|
183
|
+
* projectId: 'my-project',
|
|
184
|
+
* locationId: 'global',
|
|
185
|
+
* keyRingId: 'my-keyring',
|
|
186
|
+
* keyId: 'my-key',
|
|
187
|
+
* keyVersion: '1'
|
|
188
|
+
* })
|
|
189
|
+
* const signature = await signer.signTypedData({
|
|
190
|
+
* domain: {
|
|
191
|
+
* name: 'MyApp',
|
|
192
|
+
* version: '1',
|
|
193
|
+
* chainId: 1,
|
|
194
|
+
* verifyingContract: '0x...'
|
|
195
|
+
* },
|
|
196
|
+
* types: {
|
|
197
|
+
* Person: [
|
|
198
|
+
* { name: 'name', type: 'string' },
|
|
199
|
+
* { name: 'wallet', type: 'address' }
|
|
200
|
+
* ]
|
|
201
|
+
* },
|
|
202
|
+
* primaryType: 'Person',
|
|
203
|
+
* message: {
|
|
204
|
+
* name: 'Alice',
|
|
205
|
+
* wallet: '0x...'
|
|
206
|
+
* }
|
|
207
|
+
* })
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
signTypedData<const TTypedData extends TypedData | Record<string, unknown>, TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData>(typedData: TypedDataDefinition<TTypedData, TPrimaryType>): Promise<Hex>;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/gcp/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EACX,OAAO,EACP,GAAG,EACH,sBAAsB,EACtB,uBAAuB,EACvB,m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Hex, } from 'viem';
|
|
2
|
+
import { extractPublicKeyFromDer, publicKeyToAddress } from '../utils/address';
|
|
3
|
+
import { parseDerSignature } from '../utils/der';
|
|
4
|
+
import { calculateRecoveryId, normalizeS, uint8ArrayToBigInt, } from '../utils/signature';
|
|
5
|
+
import { GcpClient } from './client';
|
|
6
|
+
/**
|
|
7
|
+
* GcpSigner provides Ethereum signing capabilities using GCP KMS.
|
|
8
|
+
*
|
|
9
|
+
* This class manages the interaction with GCP KMS for cryptographic operations
|
|
10
|
+
* required by Ethereum accounts:
|
|
11
|
+
* - Public key retrieval and caching
|
|
12
|
+
* - Ethereum address derivation from KMS public key
|
|
13
|
+
* - Message and transaction signing
|
|
14
|
+
*
|
|
15
|
+
* The signer caches expensive operations (public key retrieval, address derivation)
|
|
16
|
+
* to avoid unnecessary KMS API calls.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const signer = new GcpSigner({
|
|
21
|
+
* projectId: 'my-project',
|
|
22
|
+
* locationId: 'global',
|
|
23
|
+
* keyRingId: 'my-keyring',
|
|
24
|
+
* keyId: 'my-key',
|
|
25
|
+
* keyVersion: '1'
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* const address = await signer.getAddress()
|
|
29
|
+
* console.log('Ethereum address:', address)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class GcpSigner {
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new GCP KMS signer instance.
|
|
35
|
+
*
|
|
36
|
+
* @param config - GCP KMS configuration including project, location, key ring, key, and version
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The constructor initializes the GCP KMS client but does not make any API calls.
|
|
40
|
+
* Public key retrieval and address derivation happen lazily on first use.
|
|
41
|
+
*/
|
|
42
|
+
constructor(config) {
|
|
43
|
+
this.gcpClient = new GcpClient(config);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves the uncompressed secp256k1 public key from GCP KMS.
|
|
47
|
+
*
|
|
48
|
+
* The public key is retrieved from KMS and extracted from the DER-encoded
|
|
49
|
+
* SubjectPublicKeyInfo format. The result is cached to avoid redundant KMS calls.
|
|
50
|
+
*
|
|
51
|
+
* @returns 65-byte uncompressed public key (0x04 + x coordinate + y coordinate)
|
|
52
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
53
|
+
* @throws {DerParsingError} If public key format is invalid
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* The public key format is:
|
|
57
|
+
* - Byte 0: 0x04 (uncompressed point indicator)
|
|
58
|
+
* - Bytes 1-32: x coordinate of the public key
|
|
59
|
+
* - Bytes 33-64: y coordinate of the public key
|
|
60
|
+
*/
|
|
61
|
+
async getPublicKey() {
|
|
62
|
+
if (this.cachedPublicKey) {
|
|
63
|
+
return this.cachedPublicKey;
|
|
64
|
+
}
|
|
65
|
+
const derPublicKey = await this.gcpClient.getPublicKey();
|
|
66
|
+
const publicKey = extractPublicKeyFromDer(derPublicKey);
|
|
67
|
+
this.cachedPublicKey = publicKey;
|
|
68
|
+
return publicKey;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Derives the Ethereum address from the GCP KMS public key.
|
|
72
|
+
*
|
|
73
|
+
* The address is calculated by:
|
|
74
|
+
* 1. Retrieving the public key from KMS (cached if available)
|
|
75
|
+
* 2. Hashing the public key coordinates with keccak256
|
|
76
|
+
* 3. Taking the last 20 bytes as the address
|
|
77
|
+
*
|
|
78
|
+
* The result is cached to avoid redundant derivation.
|
|
79
|
+
*
|
|
80
|
+
* @returns Ethereum address (0x-prefixed, 40 hex characters)
|
|
81
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
82
|
+
* @throws {DerParsingError} If public key format is invalid
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* The returned address follows EIP-55 checksum encoding.
|
|
86
|
+
*/
|
|
87
|
+
async getAddress() {
|
|
88
|
+
if (this.cachedAddress) {
|
|
89
|
+
return this.cachedAddress;
|
|
90
|
+
}
|
|
91
|
+
const publicKey = await this.getPublicKey();
|
|
92
|
+
const address = publicKeyToAddress(publicKey);
|
|
93
|
+
this.cachedAddress = address;
|
|
94
|
+
return address;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Signs a hash using the GCP KMS private key (internal helper method).
|
|
98
|
+
*
|
|
99
|
+
* This method is used internally by signMessage, signTransaction, and signTypedData.
|
|
100
|
+
* It converts the hash to bytes, signs with KMS, parses the DER signature,
|
|
101
|
+
* and normalizes the s value according to EIP-2.
|
|
102
|
+
*
|
|
103
|
+
* @param hash - The hash to sign (32 bytes, hex-encoded)
|
|
104
|
+
* @returns Object containing r and s as bigints
|
|
105
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
106
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
107
|
+
* @throws {SignatureNormalizationError} If s value is out of valid range
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* The s value is automatically normalized to the lower half of the curve order (EIP-2)
|
|
111
|
+
* to prevent signature malleability attacks.
|
|
112
|
+
*/
|
|
113
|
+
async signHash(hash) {
|
|
114
|
+
// Convert Hex to Uint8Array
|
|
115
|
+
const hashBytes = fromHex(hash, 'bytes');
|
|
116
|
+
// Sign with GCP KMS
|
|
117
|
+
const derSignature = await this.gcpClient.sign(hashBytes);
|
|
118
|
+
// Parse DER signature
|
|
119
|
+
const { r: rBytes, s: sBytes } = parseDerSignature(derSignature);
|
|
120
|
+
// Convert to bigint
|
|
121
|
+
const r = uint8ArrayToBigInt(rBytes);
|
|
122
|
+
let s = uint8ArrayToBigInt(sBytes);
|
|
123
|
+
// EIP-2 normalization
|
|
124
|
+
s = normalizeS(s);
|
|
125
|
+
return { r, s };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Signs a message using EIP-191 personal_sign standard.
|
|
129
|
+
*
|
|
130
|
+
* This method:
|
|
131
|
+
* 1. Hashes the message with EIP-191 prefix: "\x19Ethereum Signed Message:\n" + len(message) + message
|
|
132
|
+
* 2. Signs the hash with GCP KMS
|
|
133
|
+
* 3. Calculates the recovery ID to enable public key recovery
|
|
134
|
+
* 4. Returns the signature in the standard format: r (32 bytes) + s (32 bytes) + v (1 byte)
|
|
135
|
+
*
|
|
136
|
+
* @param params - Object containing the message string
|
|
137
|
+
* @returns The signature as a hex string (0x-prefixed, 130 characters)
|
|
138
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
139
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
140
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const signer = new GcpSigner({
|
|
145
|
+
* projectId: 'my-project',
|
|
146
|
+
* locationId: 'global',
|
|
147
|
+
* keyRingId: 'my-keyring',
|
|
148
|
+
* keyId: 'my-key',
|
|
149
|
+
* keyVersion: '1'
|
|
150
|
+
* })
|
|
151
|
+
* const signature = await signer.signMessage({ message: 'Hello, world!' })
|
|
152
|
+
* // signature: '0x...' (130 characters: 0x + 64 hex chars for r + 64 for s + 2 for v)
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
async signMessage({ message }) {
|
|
156
|
+
// EIP-191 hashing (viem handles automatically)
|
|
157
|
+
const messageHash = hashMessage(message);
|
|
158
|
+
// Sign with GCP KMS
|
|
159
|
+
const { r, s } = await this.signHash(messageHash);
|
|
160
|
+
// Calculate recovery ID
|
|
161
|
+
const address = await this.getAddress();
|
|
162
|
+
const recoveryId = await calculateRecoveryId(messageHash, toHex(r, { size: 32 }), toHex(s, { size: 32 }), address);
|
|
163
|
+
// Calculate v value (Legacy, no chain)
|
|
164
|
+
const v = 27 + recoveryId;
|
|
165
|
+
// Serialize signature
|
|
166
|
+
return concat([
|
|
167
|
+
toHex(r, { size: 32 }),
|
|
168
|
+
toHex(s, { size: 32 }),
|
|
169
|
+
toHex(v, { size: 1 }),
|
|
170
|
+
]);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Signs an Ethereum transaction.
|
|
174
|
+
*
|
|
175
|
+
* This method:
|
|
176
|
+
* 1. Serializes the transaction without signature fields (r, s, v)
|
|
177
|
+
* 2. Hashes the serialized transaction with keccak256
|
|
178
|
+
* 3. Signs the hash with GCP KMS
|
|
179
|
+
* 4. Calculates the recovery ID
|
|
180
|
+
* 5. Computes the v value (EIP-155 if chainId present, legacy otherwise)
|
|
181
|
+
* 6. Returns the fully serialized transaction with signature
|
|
182
|
+
*
|
|
183
|
+
* @param transaction - The transaction to sign
|
|
184
|
+
* @param options - Optional serializer function (defaults to viem's serializeTransaction)
|
|
185
|
+
* @returns The serialized signed transaction as a hex string
|
|
186
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
187
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
188
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const signer = new GcpSigner({
|
|
193
|
+
* projectId: 'my-project',
|
|
194
|
+
* locationId: 'global',
|
|
195
|
+
* keyRingId: 'my-keyring',
|
|
196
|
+
* keyId: 'my-key',
|
|
197
|
+
* keyVersion: '1'
|
|
198
|
+
* })
|
|
199
|
+
* const signedTx = await signer.signTransaction({
|
|
200
|
+
* to: '0x...',
|
|
201
|
+
* value: parseEther('1'),
|
|
202
|
+
* chainId: 1
|
|
203
|
+
* })
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
async signTransaction(transaction, { serializer = serializeTransaction, } = {}) {
|
|
207
|
+
// Serialize transaction for signing (without r, s, v)
|
|
208
|
+
const serializedTx = serializeTransaction({
|
|
209
|
+
...transaction,
|
|
210
|
+
r: undefined,
|
|
211
|
+
s: undefined,
|
|
212
|
+
v: undefined,
|
|
213
|
+
});
|
|
214
|
+
const hash = keccak256(serializedTx);
|
|
215
|
+
// Sign with GCP KMS
|
|
216
|
+
const { r, s } = await this.signHash(hash);
|
|
217
|
+
// Calculate recovery ID
|
|
218
|
+
const address = await this.getAddress();
|
|
219
|
+
const recoveryId = await calculateRecoveryId(hash, toHex(r, { size: 32 }), toHex(s, { size: 32 }), address);
|
|
220
|
+
// Calculate v value
|
|
221
|
+
const chainId = transaction.chainId;
|
|
222
|
+
const v = chainId
|
|
223
|
+
? BigInt(chainId * 2 + 35 + recoveryId) // EIP-155
|
|
224
|
+
: BigInt(27 + recoveryId); // Legacy
|
|
225
|
+
// Final serialization with signature
|
|
226
|
+
return serializer({
|
|
227
|
+
...transaction,
|
|
228
|
+
r: toHex(r, { size: 32 }),
|
|
229
|
+
s: toHex(s, { size: 32 }),
|
|
230
|
+
v,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Signs typed data according to EIP-712.
|
|
235
|
+
*
|
|
236
|
+
* This method:
|
|
237
|
+
* 1. Hashes the typed data using EIP-712 (domain separator + type hash)
|
|
238
|
+
* 2. Signs the hash with GCP KMS
|
|
239
|
+
* 3. Calculates the recovery ID
|
|
240
|
+
* 4. Returns the signature in the standard format: r (32 bytes) + s (32 bytes) + v (1 byte)
|
|
241
|
+
*
|
|
242
|
+
* @param typedData - The EIP-712 typed data to sign
|
|
243
|
+
* @returns The signature as a hex string (0x-prefixed, 130 characters)
|
|
244
|
+
* @throws {KmsClientError} If KMS API call fails
|
|
245
|
+
* @throws {DerParsingError} If signature format is invalid
|
|
246
|
+
* @throws {RecoveryIdCalculationError} If recovery ID calculation fails
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const signer = new GcpSigner({
|
|
251
|
+
* projectId: 'my-project',
|
|
252
|
+
* locationId: 'global',
|
|
253
|
+
* keyRingId: 'my-keyring',
|
|
254
|
+
* keyId: 'my-key',
|
|
255
|
+
* keyVersion: '1'
|
|
256
|
+
* })
|
|
257
|
+
* const signature = await signer.signTypedData({
|
|
258
|
+
* domain: {
|
|
259
|
+
* name: 'MyApp',
|
|
260
|
+
* version: '1',
|
|
261
|
+
* chainId: 1,
|
|
262
|
+
* verifyingContract: '0x...'
|
|
263
|
+
* },
|
|
264
|
+
* types: {
|
|
265
|
+
* Person: [
|
|
266
|
+
* { name: 'name', type: 'string' },
|
|
267
|
+
* { name: 'wallet', type: 'address' }
|
|
268
|
+
* ]
|
|
269
|
+
* },
|
|
270
|
+
* primaryType: 'Person',
|
|
271
|
+
* message: {
|
|
272
|
+
* name: 'Alice',
|
|
273
|
+
* wallet: '0x...'
|
|
274
|
+
* }
|
|
275
|
+
* })
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
async signTypedData(typedData) {
|
|
279
|
+
// EIP-712 hashing (viem handles domain separator and type hash)
|
|
280
|
+
const hash = hashTypedData(typedData);
|
|
281
|
+
// Sign with GCP KMS
|
|
282
|
+
const { r, s } = await this.signHash(hash);
|
|
283
|
+
// Calculate recovery ID
|
|
284
|
+
const address = await this.getAddress();
|
|
285
|
+
const recoveryId = await calculateRecoveryId(hash, toHex(r, { size: 32 }), toHex(s, { size: 32 }), address);
|
|
286
|
+
// Calculate v value (Legacy, no chain for typed data)
|
|
287
|
+
const v = 27 + recoveryId;
|
|
288
|
+
// Serialize signature
|
|
289
|
+
return concat([
|
|
290
|
+
toHex(r, { size: 32 }),
|
|
291
|
+
toHex(s, { size: 32 }),
|
|
292
|
+
toHex(v, { size: 1 }),
|
|
293
|
+
]);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/gcp/signer.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,MAAM,EACN,OAAO,EACP,WAAW,EACX,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,KAAK,GACL,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,uBAAuB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IAAI,EAAE,EAAE,EAAE,CAAC;YACzB,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;YACzB,CAAC;SACD,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,KAAK,CAAC,aAAa,CAGjB,SAAwD;QACzD,gEAAgE;QAChE,MAAM,IAAI,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QAEtC,oBAAoB;QACpB,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE3C,wBAAwB;QACxB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,MAAM,mBAAmB,CAC3C,IAAI,EACJ,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EACtB,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EACtB,OAAO,CACP,CAAC;QAEF,sDAAsD;QACtD,MAAM,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC;QAE1B,sBAAsB;QACtB,OAAO,MAAM,CAAC;YACb,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;YACtB,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;YACtB,KAAK,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;SACrB,CAAQ,CAAC;IACX,CAAC;CACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { KmsSigner } from './kms/signer';
|
|
2
|
-
export { toKmsAccount } from './account';
|
|
3
|
-
export type { KmsConfig, DerSignature, SignatureData } from './types';
|
|
4
|
-
export { KmsSignerError, DerParsingError, KmsClientError, SignatureNormalizationError, RecoveryIdCalculationError } from './errors';
|
|
5
1
|
export type { Address, Hex } from 'viem';
|
|
2
|
+
export { toGcpKmsAccount, toKmsAccount } from './account';
|
|
3
|
+
export { DerParsingError, KmsClientError, KmsSignerError, RecoveryIdCalculationError, SignatureNormalizationError, } from './errors';
|
|
4
|
+
export { GcpSigner } from './gcp/signer';
|
|
5
|
+
export { KmsSigner } from './kms/signer';
|
|
6
|
+
export type { DerSignature, GcpKmsConfig, KmsConfig, SignatureData, } from './types';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EACN,eAAe,EACf,cAAc,EACd,cAAc,EACd,0BAA0B,EAC1B,2BAA2B,GAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,YAAY,EACX,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,GACb,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Main classes and functions
|
|
2
|
-
export {
|
|
3
|
-
export { toKmsAccount } from './account';
|
|
2
|
+
export { toGcpKmsAccount, toKmsAccount } from './account';
|
|
4
3
|
// Errors
|
|
5
|
-
export {
|
|
4
|
+
export { DerParsingError, KmsClientError, KmsSignerError, RecoveryIdCalculationError, SignatureNormalizationError, } from './errors';
|
|
5
|
+
export { GcpSigner } from './gcp/signer';
|
|
6
|
+
export { KmsSigner } from './kms/signer';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAI7B,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC1D,SAAS;AACT,OAAO,EACN,eAAe,EACf,cAAc,EACd,cAAc,EACd,0BAA0B,EAC1B,2BAA2B,GAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/kms/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/kms/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/kms/client.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAS;IAEtB;;;;;;;;;;OAUG;gBACS,MAAM,EAAE,SAAS;IAQ7B;;;;;;;;;OASG;IACG,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IAmBzC;;;;;;;;;;;OAWG;IACG,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;CAuBxD"}
|
package/dist/kms/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KMSClient,
|
|
1
|
+
import { GetPublicKeyCommand, KMSClient, MessageType, SignCommand, SigningAlgorithmSpec, } from '@aws-sdk/client-kms';
|
|
2
2
|
import { KmsClientError } from '../errors';
|
|
3
3
|
/**
|
|
4
4
|
* KmsClient wraps AWS KMS SDK operations for key management and signing.
|
package/dist/kms/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/kms/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/kms/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,mBAAmB,EACnB,SAAS,EACT,WAAW,EACX,WAAW,EACX,oBAAoB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,SAAS;IAIrB;;;;;;;;;;OAUG;IACH,YAAY,MAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC;YAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,YAAY;QACjB,IAAI,CAAC;YACJ,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YAC/D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEjD,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACzB,MAAM,IAAI,cAAc,CAAC,iCAAiC,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AAC,CAAC,SAAS,CAC1C,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
|
package/dist/kms/signer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Address, Hex, TransactionSerializable, SerializeTransactionFn, TypedDataDefinition } from 'viem';
|
|
2
1
|
import type { TypedData } from 'abitype';
|
|
2
|
+
import type { Address, Hex, SerializeTransactionFn, TransactionSerializable, TypedDataDefinition } from 'viem';
|
|
3
3
|
import type { KmsConfig } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* KmsSigner provides Ethereum signing capabilities using AWS KMS.
|
|
@@ -145,7 +145,7 @@ export declare class KmsSigner {
|
|
|
145
145
|
* })
|
|
146
146
|
* ```
|
|
147
147
|
*/
|
|
148
|
-
signTransaction(transaction: TransactionSerializable, { serializer }?: {
|
|
148
|
+
signTransaction(transaction: TransactionSerializable, { serializer, }?: {
|
|
149
149
|
serializer?: SerializeTransactionFn;
|
|
150
150
|
}): Promise<Hex>;
|
|
151
151
|
/**
|
package/dist/kms/signer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/kms/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/kms/signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EACX,OAAO,EACP,GAAG,EACH,sBAAsB,EACtB,uBAAuB,EACvB,mBAAmB,EACnB,MAAM,MAAM,CAAC;AAUd,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAU1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,aAAa,CAAC,CAA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