Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions modules/sdk-coin-celo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@
"@bitgo/sdk-coin-eth": "^25.3.4",
"@bitgo/sdk-core": "^36.12.0",
"@bitgo/statics": "^58.4.0",
"@celo/connect": "^2.0.0",
"@celo/contractkit": "^2.0.0",
"@celo/wallet-base": "^2.0.0",
"@celo/wallet-local": "^2.0.0",
"@ethereumjs/common": "^2.6.5",
"bignumber.js": "^9.0.0",
"ethereumjs-abi": "^0.6.5",
"ethereumjs-util": "7.1.5",
"ethers": "^5.1.3"
"ethereumjs-util": "7.1.5"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.70.1",
Expand Down
265 changes: 0 additions & 265 deletions modules/sdk-coin-celo/src/lib/types.ts

This file was deleted.

50 changes: 1 addition & 49 deletions modules/sdk-coin-celo/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,8 @@
import { NetworkType } from '@bitgo/statics';
import EthereumCommon from '@ethereumjs/common';
import { recoverTransaction } from '@celo/wallet-base';
import * as ethers from 'ethers';
import BigNumber from 'bignumber.js';
import { ETHTransactionType, LegacyTxData } from '@bitgo/sdk-coin-eth';
import { InvalidTransactionError, ParseTransactionError } from '@bitgo/sdk-core';
import { InvalidTransactionError } from '@bitgo/sdk-core';
import { mainnetCommon, testnetCommon } from './resources';

/**
* Celo transaction deserialization based on code
* from @celo/contractkit/lib/utils/signing-utils
* github: https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit
*
* @param {string} serializedTx the serialized transaction
* @returns {LegacyTxData} the deserialized transaction
*/
export function deserialize(serializedTx: string): LegacyTxData {
try {
const decodedTx = ethers.utils.RLP.decode(serializedTx);
decodedTx.splice(3, 3); // remove unused feeCurrency, gatewayFeeRecipient and gatewayFee
const [nonce, gasPrice, gasLimit, to, value, data, v, r, s] = decodedTx;
let chainId = v;
let from;
if (r !== '0x' && s !== '0x') {
const [tx, sender] = recoverTransaction(serializedTx);
from = sender;
chainId = tx.chainId;
}
const celoTx: LegacyTxData = {
_type: ETHTransactionType.LEGACY,
nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16),
gasPrice: gasPrice.toLowerCase() === '0x' ? '0' : new BigNumber(gasPrice, 16).toString(),
gasLimit: gasLimit.toLowerCase() === '0x' ? '0' : new BigNumber(gasLimit, 16).toString(),
value: value.toLowerCase() === '0x' ? '0' : new BigNumber(value, 16).toString(),
data,
chainId,
from,
v,
r,
s,
};

if (to !== '0x') {
celoTx.to = to;
}

return celoTx;
} catch {
throw new ParseTransactionError('Invalid serialized transaction');
}
}

const commons: Map<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([
[NetworkType.MAINNET, mainnetCommon],
[NetworkType.TESTNET, testnetCommon],
Expand Down
2 changes: 0 additions & 2 deletions scripts/check-package-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const options = {
'express-serve-static-core',
// Required for sdk-coin-ada
'@emurgo/cardano-serialization-lib-browser',
// Required for sdk-coin-celo inner dependencies
'@celo/contractkit',
// Webpack - not detected by depcheck
'@testing-library/cypress',
'css-loader',
Expand Down
Loading