@exodus/web3-ethereum-utils 3.18.1 → 3.20.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.
@@ -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,21 @@ 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
+ const hex = buf.toString('hex');
36
+ if (typeof hex !== 'string') {
37
+ throw new Error('expected hex string');
38
+ }
39
+ return '0x' + hex;
40
+ }
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.18.1",
4
+ "version": "3.20.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": "556ef966fd45fe2460c861602a1c1e781171cf34"
37
+ "gitHead": "1580891fde0c2c4838f3118b7d11e1457cd7ab4b"
38
38
  }