Skip to content

Commit

Permalink
fix: Refactor to remove unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Apr 6, 2024
1 parent 496cacf commit 88fd894
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 78 deletions.
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"trailingComma": "all"
}
},
"organizeImports": {
"enabled": false
},
"files": {
"ignore": ["node_modules", "build", "coverage", ".vscode"]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/src/instantiation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ERC725 } from '@erc725/erc725.js';
import Web3 from 'web3';
import { ERC725 } from '@erc725/erc725.js';

// this is needed because node does not support `fetch` out of the box
// isomorphic-fetch is not needed in a browser environment
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc725/erc725.js",
"version": "0.24.1-dev.4",
"version": "0.24.1-dev.5",
"description": "Library to interact with ERC725 smart contracts",
"main": "build/main/src/index.js",
"typings": "build/main/src/index.d.ts",
Expand Down
4 changes: 1 addition & 3 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*/

import { arrToBufArr, bufferToHex } from 'ethereumjs-util';
/* eslint-disable @typescript-eslint/ban-types */
import { keccak256, numberToHex } from 'web3-utils';

import { Encoding, Method, MethodData } from '../types/Method';
import { MethodData, Encoding, Method } from '../types/Method';

// https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md#specification
export const ERC725Y_INTERFACE_IDS = {
Expand Down
30 changes: 12 additions & 18 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,28 @@
// Tests for the @erc725/erc725.js package
import { assert } from 'chai';

import * as sinon from 'sinon';
import Web3 from 'web3';
import * as sinon from 'sinon';
import { hexToNumber, leftPad, numberToHex } from 'web3-utils';

// examples of schemas to load (for testing)
import { LSP1Schema, LSP3Schema, LSP6Schema, LSP12Schema } from './schemas';

import ERC725, {
checkPermissions,
decodePermissions,
encodeKeyName,
encodePermissions,
supportsInterface,
} from '.';
import { EthereumProvider, HttpProvider } from '../test/mockProviders';
import { mockSchema } from '../test/mockSchema';
import {
generateAllData,
generateAllRawData,
generateAllResults,
} from '../test/testHelpers';
import { LSP1Schema, LSP12Schema, LSP3Schema, LSP6Schema } from './schemas';

import ERC725 from '.';
import {
decodeKeyValue,
encodeKey,
encodeKeyValue,
hashData,
} from './lib/utils';
import { ERC725JSONSchema } from './types/ERC725JSONSchema';
import { EthereumProvider, HttpProvider } from '../test/mockProviders';
import { mockSchema } from '../test/mockSchema';
import {
generateAllData,
generateAllRawData,
generateAllResults,
} from '../test/testHelpers';

import 'isomorphic-fetch';

Expand All @@ -56,8 +50,8 @@ import {
LSP6_DEFAULT_PERMISSIONS,
SUPPORTED_VERIFICATION_METHOD_STRINGS,
} from './constants/constants';
import { INTERFACE_IDS_0_12_0 } from './constants/interfaces';
import { decodeKey } from './lib/decodeData';
import { INTERFACE_IDS_0_12_0 } from './constants/interfaces';

const address = '0x0c03fba782b07bcf810deb3b7f0595024a444f4e';

Expand Down
30 changes: 15 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,48 @@
* @date 2020
*/

import HttpProvider from 'web3-providers-http';
import { isAddress } from 'web3-utils';
import HttpProvider from 'web3-providers-http';

import { ProviderWrapper } from './provider/providerWrapper';

import {
convertIPFSGatewayUrl,
duplicateMultiTypeERC725SchemaEntry,
encodeData,
convertIPFSGatewayUrl,
generateSchemasFromDynamicKeys,
duplicateMultiTypeERC725SchemaEntry,
} from './lib/utils';

import { isValidSignature } from './lib/isValidSignature';
import { getSchema } from './lib/schemaParser';
import { isValidSignature } from './lib/isValidSignature';

import { DEFAULT_GAS_VALUE } from './constants/constants';
import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName';

import { decodeData } from './lib/decodeData';
import { decodeMappingKey } from './lib/decodeMappingKey';
import { _supportsInterface, checkPermissions } from './lib/detector';
import { decodeValueType, encodeValueType } from './lib/encoder';
import { getData } from './lib/getData';
import { getDataFromExternalSources } from './lib/getDataFromExternalSources';
import { decodePermissions, encodePermissions } from './lib/permissions';
// Types
import { ERC725Config, ERC725Options } from './types/Config';
import { Permissions } from './types/Method';
import {
ERC725JSONSchema,
ERC725JSONSchemaKeyType,
ERC725JSONSchemaValueContent,
ERC725JSONSchemaValueType,
} from './types/ERC725JSONSchema';
import { GetDataDynamicKey, GetDataInput } from './types/GetData';
import { Permissions } from './types/Method';
import {
DecodeDataInput,
DecodeDataOutput,
EncodeDataInput,
FetchDataOutput,
} from './types/decodeData';
import { GetDataDynamicKey, GetDataInput } from './types/GetData';
import { decodeData } from './lib/decodeData';
import { getDataFromExternalSources } from './lib/getDataFromExternalSources';
import { DynamicKeyPart, DynamicKeyParts } from './types/dynamicKeys';
import { getData } from './lib/getData';
import { decodeValueType, encodeValueType } from './lib/encoder';
import { checkPermissions, internalSupportsInterface } from './lib/detector';
import { decodeMappingKey } from './lib/decodeMappingKey';
import { encodePermissions, decodePermissions } from './lib/permissions';

export {
ERC725JSONSchema,
Expand Down Expand Up @@ -121,7 +121,7 @@ export async function supportsInterface(
throw new Error('Missing RPC URL');
}

return _supportsInterface(interfaceIdOrName, {
return internalSupportsInterface(interfaceIdOrName, {
address: options.address,
provider:
options.provider ||
Expand Down Expand Up @@ -595,7 +595,7 @@ export class ERC725 {
async supportsInterface(interfaceIdOrName: string): Promise<boolean> {
const { address, provider } = this.getAddressAndProvider();

return _supportsInterface(interfaceIdOrName, {
return internalSupportsInterface(interfaceIdOrName, {
address,
provider,
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import { isHexStrict } from 'web3-utils';
import { COMPACT_BYTES_ARRAY_STRING } from '../constants/constants';

import { DecodeDataInput, DecodeDataOutput } from '../types/decodeData';
import {
ALL_VALUE_TYPES,
ERC725JSONSchema,
isValidValueType,
} from '../types/ERC725JSONSchema';
import { DecodeDataInput, DecodeDataOutput } from '../types/decodeData';
import { isDynamicKeyName } from './encodeKeyName';
import { decodeValueType, valueContentEncodingMap } from './encoder';
import { valueContentEncodingMap, decodeValueType } from './encoder';
import { getSchemaElement } from './getSchemaElement';
import { decodeKeyValue, encodeArrayKey } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/decodeMappingKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/

import { isHex, padLeft } from 'web3-utils';
import { decodeValueType } from './encoder';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
import { DynamicKeyPart } from '../types/dynamicKeys';
import { decodeValueType } from './encoder';

function isDynamicKeyPart(keyPartName: string): boolean {
return (
Expand Down
15 changes: 9 additions & 6 deletions src/lib/detector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { expect } from 'chai';
import * as sinon from 'sinon';
import { INTERFACE_IDS_0_12_0 } from '../constants/interfaces';

import { _supportsInterface, checkPermissions } from './detector';
import { internalSupportsInterface, checkPermissions } from './detector';

describe('supportsInterface', () => {
it('it should return true if the contract supports the interface with name', async () => {
Expand All @@ -37,10 +37,13 @@ describe('supportsInterface', () => {
.withArgs(contractAddress, INTERFACE_IDS_0_12_0[interfaceName])
.returns(Promise.resolve(true));

const doesSupportInterface = await _supportsInterface(interfaceName, {
address: contractAddress,
provider: providerStub,
});
const doesSupportInterface = await internalSupportsInterface(
interfaceName,
{
address: contractAddress,
provider: providerStub,
},
);

expect(doesSupportInterface).to.be.true;
});
Expand All @@ -55,7 +58,7 @@ describe('supportsInterface', () => {
.withArgs(contractAddress, interfaceId)
.returns(Promise.resolve(true));

const doesSupportInterface = await _supportsInterface(interfaceId, {
const doesSupportInterface = await internalSupportsInterface(interfaceId, {
address: contractAddress,
provider: providerStub,
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
* @param options Object with address and RPC URL.
* @returns {Promise<boolean>} if interface is supported.
*/
export const _supportsInterface = async (
export const internalSupportsInterface = async (
interfaceIdOrName: string,
options: AddressProviderOptions,
): Promise<boolean> => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/encodeKeyName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import {
padLeft,
} from 'web3-utils';

import { DynamicKeyParts } from '../types/dynamicKeys';
import { guessKeyTypeFromKeyName } from './utils';
import { DynamicKeyParts } from '../types/dynamicKeys';

// https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md#mapping

Expand Down
20 changes: 10 additions & 10 deletions src/lib/encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@

/* eslint-disable no-unused-expressions */

import { assert, expect } from 'chai';
import { expect, assert } from 'chai';

import {
keccak256,
padLeft,
utf8ToHex,
stripHexPrefix,
toBN,
toHex,
utf8ToHex,
padLeft,
} from 'web3-utils';
import {
valueContentEncodingMap,
encodeValueType,
decodeValueType,
encodeValueContent,
decodeValueContent,
} from './encoder';
import {
NONE_VERIFICATION_METHOD,
SUPPORTED_VERIFICATION_METHOD_HASHES,
SUPPORTED_VERIFICATION_METHOD_STRINGS,
} from '../constants/constants';
import { URLDataToEncode, URLDataWithHash } from '../types';
import {
decodeValueContent,
decodeValueType,
encodeValueContent,
encodeValueType,
valueContentEncodingMap,
} from './encoder';

describe('encoder', () => {
describe('valueType', () => {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,37 @@
import AbiCoder from 'web3-eth-abi';

import {
bytesToHex,
hexToBytes,
hexToNumber,
hexToUtf8,
isAddress,
isHex,
keccak256,
numberToHex,
padLeft,
stripHexPrefix,
toBN,
toChecksumAddress,
toHex,
utf8ToHex,
stripHexPrefix,
hexToBytes,
bytesToHex,
toHex,
toBN,
} from 'web3-utils';

import { URLDataToEncode, URLDataWithHash, Verification } from '../types';
import { AssetURLEncode } from '../types/encodeData';

import {
NONE_VERIFICATION_METHOD,
SUPPORTED_VERIFICATION_METHOD_STRINGS,
NONE_VERIFICATION_METHOD,
} from '../constants/constants';
import { ERC725JSONSchemaValueType } from '../types/ERC725JSONSchema';
import {
countNumberOfBytes,
countSignificantBits,
getVerificationMethod,
hashData,
countNumberOfBytes,
isValidUintSize,
countSignificantBits,
} from './utils';
import { ERC725JSONSchemaValueType } from '../types/ERC725JSONSchema';

const abiCoder = AbiCoder;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/getDataFromExternalSources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { expect } from 'chai';

import { ERC725JSONSchema } from '../types/ERC725JSONSchema';

import { DecodeDataOutput } from '../types/decodeData';
import { getDataFromExternalSources } from './getDataFromExternalSources';
import { DecodeDataOutput } from '../types/decodeData';

const IPFS_GATEWAY_MOCK = 'https://mock-ipfs.mock/ipfs/';

Expand Down
4 changes: 2 additions & 2 deletions src/lib/getDataFromExternalSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import { arrToBufArr } from 'ethereumjs-util';

import { URLDataWithHash } from '../types';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
import {
DecodeDataOutput,
GetDataExternalSourcesOutput,
} from '../types/decodeData';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
import { isDataAuthentic, patchIPFSUrlsIfApplicable } from './utils';
import { URLDataWithHash } from '../types';

export const getDataFromExternalSources = (
schemas: ERC725JSONSchema[],
Expand Down
2 changes: 1 addition & 1 deletion src/lib/getSchemaElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import { isHex, isHexStrict } from 'web3-utils';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
import { DynamicKeyParts } from '../types/dynamicKeys';
import { ERC725JSONSchema } from '../types/ERC725JSONSchema';
import {
encodeKeyName,
generateDynamicKeyName,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hexToNumber, leftPad, toHex } from 'web3-utils';
import { hexToNumber, leftPad, numberToHex } from 'web3-utils';
import { LSP6_DEFAULT_PERMISSIONS } from '../constants/constants';
import { Permissions } from '../types/Method';

Expand Down Expand Up @@ -26,7 +26,7 @@ export function encodePermissions(permissions: Permissions): string {
}
}
// Convert the final BigInt permission value back to a hex string, properly padded
return leftPad(toHex(basePermissions.toString()), 64);
return leftPad(numberToHex(basePermissions.toString()), 64);
}

export function decodePermissions(permissionHex: string) {
Expand Down
Loading

0 comments on commit 88fd894

Please sign in to comment.