diff --git a/src/logic/trades/utils.ts b/src/logic/trades/utils.ts index b2f8f6f..f4c550e 100644 --- a/src/logic/trades/utils.ts +++ b/src/logic/trades/utils.ts @@ -1,15 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { - Contract, - TypedDataField, - hexlify, - TypedDataDomain, - verifyTypedData, - toBeArray, - toUtf8Bytes, - zeroPadValue, - JsonRpcProvider -} from 'ethers' +import { Contract, TypedDataField, TypedDataDomain, verifyTypedData, toBeArray, zeroPadValue, JsonRpcProvider } from 'ethers' import { ChainId, ERC721TradeAsset, Network, TradeAsset, TradeAssetType, TradeCreation } from '@dcl/schemas' import { ContractData, ContractName, getContract } from 'decentraland-transactions' import { InvalidECDSASignatureError, MarketplaceContractNotFound } from '../../ports/trades/errors' @@ -98,7 +88,8 @@ export function validateTradeSignature(trade: TradeCreation, signer: string): bo externalChecks: trade.checks.externalChecks?.map(externalCheck => ({ contractAddress: externalCheck.contractAddress, selector: externalCheck.selector, - value: hexlify(toUtf8Bytes(externalCheck.value)), + // '0x' is the default value for the value bytes (0 bytes) + value: externalCheck.value ? externalCheck.value : '0x', required: externalCheck.required })) }, @@ -106,13 +97,15 @@ export function validateTradeSignature(trade: TradeCreation, signer: string): bo assetType: asset.assetType, contractAddress: asset.contractAddress, value: getValueFromTradeAsset(asset), - extra: hexlify(toUtf8Bytes(asset.extra)) + // '0x' is the default value for extra bytes (0 bytes) + extra: asset.extra ? asset.extra : '0x' })), received: trade.received.map(asset => ({ assetType: asset.assetType, contractAddress: asset.contractAddress, value: getValueFromTradeAsset(asset), - extra: hexlify(toUtf8Bytes(asset.extra)), + // '0x' is the default value for extra bytes (0 bytes) + extra: asset.extra ? asset.extra : '0x', beneficiary: asset.beneficiary })) } diff --git a/test/unit/trades-component.spec.ts b/test/unit/trades-component.spec.ts index ab4181c..3be1a8d 100644 --- a/test/unit/trades-component.spec.ts +++ b/test/unit/trades-component.spec.ts @@ -70,7 +70,7 @@ describe('when adding a new trade', () => { assetType: TradeAssetType.ERC20, contractAddress: '0xabcdef', amount: '2', - extra: '' + extra: '0x' } ], received: [ @@ -78,7 +78,7 @@ describe('when adding a new trade', () => { assetType: TradeAssetType.ERC721, contractAddress: '0x789abc', tokenId: '1', - extra: '', + extra: '0x', beneficiary: '0x9876543210' } ] @@ -335,7 +335,7 @@ describe('when getting a trade', () => { assetType: TradeAssetType.ERC20, contractAddress: '0xabcdef', amount: '2', - extra: '' + extra: '0x' } ], received: [ @@ -343,7 +343,7 @@ describe('when getting a trade', () => { assetType: TradeAssetType.ERC721, contractAddress: '0x789abc', tokenId: '1', - extra: '', + extra: '0x', beneficiary: '0x9876543210' } ] diff --git a/test/unit/trades-logic.spec.ts b/test/unit/trades-logic.spec.ts index dee6637..e73e760 100644 --- a/test/unit/trades-logic.spec.ts +++ b/test/unit/trades-logic.spec.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { HDNodeWallet, TypedDataDomain, Wallet, zeroPadValue, toBeArray, hexlify, toUtf8Bytes } from 'ethers' +import { HDNodeWallet, TypedDataDomain, Wallet, zeroPadValue, toBeArray } from 'ethers' import { ChainId, Network, TradeAssetType, TradeCreation, TradeType } from '@dcl/schemas' import { ContractData, ContractName, getContract } from 'decentraland-transactions' import { fromMillisecondsToSeconds } from '../../src/logic/date' @@ -82,13 +82,13 @@ describe('when verifying the trade signature', () => { assetType: asset.assetType, contractAddress: asset.contractAddress, value: getValueFromTradeAsset(asset), - extra: hexlify(toUtf8Bytes(asset.extra)) + extra: asset.extra })), received: trade.received.map(asset => ({ assetType: asset.assetType, contractAddress: asset.contractAddress, value: getValueFromTradeAsset(asset), - extra: hexlify(toUtf8Bytes(asset.extra)), + extra: asset.extra, beneficiary: asset.beneficiary })) }