1
1
import { bytesToHex , concatBytes } from '@noble/curves/abstract/utils' ;
2
2
import { type SignatureType } from '@noble/curves/abstract/weierstrass' ;
3
3
import { secp256k1 } from '@noble/curves/secp256k1' ;
4
- import { Address , Hex , Keccak256 , Transaction , Txt } from '@vechain/sdk-core' ;
4
+ import { Address , Hex , Transaction } from '@vechain/sdk-core' ;
5
5
import { JSONRPCInvalidParams , SignerMethodError } from '@vechain/sdk-errors' ;
6
6
import {
7
7
type AvailableVeChainProviders ,
@@ -11,11 +11,6 @@ import {
11
11
VeChainAbstractSigner
12
12
} from '@vechain/sdk-network' ;
13
13
import { BitString , ObjectIdentifier , Sequence , verifySchema } from 'asn1js' ;
14
- import {
15
- type TypedDataDomain ,
16
- TypedDataEncoder ,
17
- type TypedDataField
18
- } from 'ethers' ;
19
14
import { recoverPublicKey , toHex } from 'viem' ;
20
15
import { KMSVeChainProvider } from './KMSVeChainProvider' ;
21
16
@@ -57,7 +52,7 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
57
52
throw new JSONRPCInvalidParams (
58
53
'KMSVeChainSigner.constructor' ,
59
54
'The gasPayer object is not well formed, either provider or url should be provided.' ,
60
- { gasPayer : gasPayer }
55
+ { gasPayer }
61
56
) ;
62
57
}
63
58
}
@@ -149,14 +144,14 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
149
144
throw new SignerMethodError (
150
145
'KMSVeChainSigner.getAddress' ,
151
146
'The address could not be retrieved.' ,
152
- { fromGasPayerProvider : fromGasPayerProvider } ,
147
+ { fromGasPayerProvider } ,
153
148
error
154
149
) ;
155
150
}
156
151
}
157
152
158
153
/**
159
- * It builds a VeChain signature from a bytes payload.
154
+ * It builds a VeChain signature from a bytes' payload.
160
155
* @param {Uint8Array } payload to sign.
161
156
* @param {KMSVeChainProvider } kmsProvider The provider to sign the payload.
162
157
* @returns {Uint8Array } The signature following the VeChain format.
@@ -187,12 +182,10 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
187
182
kmsProvider
188
183
) ;
189
184
190
- const decodedSignature = concatBytes (
185
+ return concatBytes (
191
186
decodedSignatureWithoutRecoveryBit . toCompactRawBytes ( ) ,
192
187
new Uint8Array ( [ recoveryBit ] )
193
188
) ;
194
-
195
- return decodedSignature ;
196
189
}
197
190
198
191
/**
@@ -313,7 +306,7 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
313
306
314
307
/**
315
308
* Submits a signed transaction to the network.
316
- * @param transactionToSend Transaction to by signed and sent to the network.
309
+ * @param transactionToSend Transaction to be signed and sent to the network.
317
310
* @returns {string } The transaction ID.
318
311
*/
319
312
public async sendTransaction (
@@ -344,68 +337,13 @@ class KMSVeChainSigner extends VeChainAbstractSigner {
344
337
* @param {Uint8Array } payload in bytes to sign.
345
338
* @returns {string } The VeChain signature in hexadecimal format.
346
339
*/
347
- private async signPayload ( payload : Uint8Array ) : Promise < string > {
340
+ public async signPayload ( payload : Uint8Array ) : Promise < string > {
348
341
const veChainSignature =
349
342
await this . buildVeChainSignatureFromPayload ( payload ) ;
350
343
// SCP256K1 encodes the recovery flag in the last byte. EIP-191 adds 27 to it.
351
344
veChainSignature [ veChainSignature . length - 1 ] += 27 ;
352
345
return Hex . of ( veChainSignature ) . toString ( ) ;
353
346
}
354
-
355
- /**
356
- * Signs a message returning the VeChain signature in hexadecimal format.
357
- * @param {string | Uint8Array } message to sign.
358
- * @returns {string } The VeChain signature in hexadecimal format.
359
- */
360
- public async signMessage ( message : string | Uint8Array ) : Promise < string > {
361
- try {
362
- const payload =
363
- typeof message === 'string' ? Txt . of ( message ) . bytes : message ;
364
- const payloadHashed = Keccak256 . of (
365
- concatBytes (
366
- this . MESSAGE_PREFIX ,
367
- Txt . of ( payload . length ) . bytes ,
368
- payload
369
- )
370
- ) . bytes ;
371
- return await this . signPayload ( payloadHashed ) ;
372
- } catch ( error ) {
373
- throw new SignerMethodError (
374
- 'KMSVeChainSigner.signMessage' ,
375
- 'The message could not be signed.' ,
376
- { message } ,
377
- error
378
- ) ;
379
- }
380
- }
381
-
382
- /**
383
- * Signs a typed data returning the VeChain signature in hexadecimal format.
384
- * @param {TypedDataDomain } domain to hash as typed data.
385
- * @param {Record<string, TypedDataField[]> } types to hash as typed data.
386
- * @param {Record<string, unknown> } value to hash as typed data.
387
- * @returns {string } The VeChain signature in hexadecimal format.
388
- */
389
- public async signTypedData (
390
- domain : TypedDataDomain ,
391
- types : Record < string , TypedDataField [ ] > ,
392
- value : Record < string , unknown >
393
- ) : Promise < string > {
394
- try {
395
- const payload = Hex . of (
396
- TypedDataEncoder . hash ( domain , types , value )
397
- ) . bytes ;
398
-
399
- return await this . signPayload ( payload ) ;
400
- } catch ( error ) {
401
- throw new SignerMethodError (
402
- 'KMSVeChainSigner.signTypedData' ,
403
- 'The typed data could not be signed.' ,
404
- { domain, types, value } ,
405
- error
406
- ) ;
407
- }
408
- }
409
347
}
410
348
411
349
export { KMSVeChainSigner } ;
0 commit comments