@exodus/web3-ethereum-utils 3.18.1 → 3.19.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/lib/signatures.d.ts +2 -0
- package/lib/signatures.js +22 -0
- package/package.json +2 -2
package/lib/signatures.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ import type { MessageTypes, TypedDataV1, TypedMessage } from '@metamask/eth-sig-
|
|
|
5
5
|
export declare function signMessage(message: string, privateKey: Buffer): string;
|
|
6
6
|
export declare function signTypedData(typedData: TypedDataV1 | TypedMessage<MessageTypes>, privateKey: Buffer, version?: SignTypedDataVersion): string;
|
|
7
7
|
export declare function signTransaction(transactionParams: EthTransactionParams, privateKey: Buffer): Buffer;
|
|
8
|
+
export declare function hex0xStringToBuffer(hex: string): Buffer;
|
|
9
|
+
export declare function bufferToHex0xString(buf: Buffer): string;
|
package/lib/signatures.js
CHANGED
|
@@ -20,3 +20,25 @@ export function signTransaction(transactionParams, privateKey) {
|
|
|
20
20
|
const signedTransaction = transaction.sign(privateKey);
|
|
21
21
|
return signedTransaction.serialize();
|
|
22
22
|
}
|
|
23
|
+
export function hex0xStringToBuffer(hex) {
|
|
24
|
+
// Remove the 0x
|
|
25
|
+
const hexWithout0x = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
26
|
+
// Pad the value until even
|
|
27
|
+
const hexWithLeadingZeros = hexWithout0x.length % 2 === 0 ? hexWithout0x : '0' + hexWithout0x;
|
|
28
|
+
// Finally return the buffer
|
|
29
|
+
return Buffer.from(hexWithLeadingZeros, 'hex');
|
|
30
|
+
}
|
|
31
|
+
export function bufferToHex0xString(buf) {
|
|
32
|
+
if (!Buffer.isBuffer(buf)) {
|
|
33
|
+
throw new Error('expected a buffer');
|
|
34
|
+
}
|
|
35
|
+
let hex = buf.toString('hex');
|
|
36
|
+
if (typeof hex !== 'string') {
|
|
37
|
+
throw new Error('expected hex string');
|
|
38
|
+
}
|
|
39
|
+
// Remove leading zeros
|
|
40
|
+
while (hex.length > 0 && hex[0] === '0') {
|
|
41
|
+
hex = hex.slice(1);
|
|
42
|
+
}
|
|
43
|
+
return '0x' + hex;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/web3-ethereum-utils",
|
|
3
3
|
"description": "Web3 Ethereum utils.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.19.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"@exodus/web3-utils": "^1.40.0",
|
|
35
35
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "5c013e1a549fba97227b325120666139258e0020"
|
|
38
38
|
}
|