@exodus/web3-ethereum-utils 3.18.0 → 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
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
|
+
}
|
|
@@ -50,7 +50,7 @@ const createBalanceAmount = (amount, { decimals, symbol }) => {
|
|
|
50
50
|
});
|
|
51
51
|
return beforeAmount.sub(afterAmount);
|
|
52
52
|
};
|
|
53
|
-
const handleExpectedBalanceChange = (expectedBalanceChange, simulationResult) => {
|
|
53
|
+
const handleExpectedBalanceChange = (expectedBalanceChange, simulationResult, { network }) => {
|
|
54
54
|
const { willApprove, willSend, willReceive } = simulationResult.balanceChanges;
|
|
55
55
|
const { data, kind } = expectedBalanceChange.rawInfo;
|
|
56
56
|
const { asset } = data;
|
|
@@ -84,8 +84,10 @@ const handleExpectedBalanceChange = (expectedBalanceChange, simulationResult) =>
|
|
|
84
84
|
};
|
|
85
85
|
if (isNftTransfer) {
|
|
86
86
|
const tokenId = data.tokenId;
|
|
87
|
+
const compositeId = `${asset.address}/${tokenId}`;
|
|
87
88
|
balanceChange.nft = {
|
|
88
|
-
id:
|
|
89
|
+
id: `${network}:${compositeId}`,
|
|
90
|
+
compositeId,
|
|
89
91
|
title: asset.name,
|
|
90
92
|
};
|
|
91
93
|
}
|
|
@@ -147,6 +149,6 @@ export const simulateTransactions = async ({ transactions, apiEndpoint, origin,
|
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
149
151
|
userExpectedChanges.forEach((expectedChange) => {
|
|
150
|
-
handleExpectedBalanceChange(expectedChange, simulationResult);
|
|
152
|
+
handleExpectedBalanceChange(expectedChange, simulationResult, { network });
|
|
151
153
|
});
|
|
152
154
|
};
|
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",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"build": "yarn clean && tsc"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@exodus/web3-types": "^1.
|
|
29
|
+
"@exodus/web3-types": "^1.46.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@exodus/ethereumjs-common": "^2.4.0-exodus.6",
|
|
33
33
|
"@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
|
|
34
|
-
"@exodus/web3-utils": "^1.
|
|
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
|
}
|