Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync main to release #417

Merged
merged 6 commits into from
Apr 18, 2024
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
64 changes: 0 additions & 64 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"enabled": false
},
"files": {
"ignore": ["node_modules", "build", "coverage", ".vscode"]
"ignore": ["node_modules", ".nyc_output", "build", "coverage", ".vscode"]
}
}
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
"main": "build/main/src/index.js",
"typings": "build/main/src/index.d.ts",
"module": "build/module/src/index.js",
"files": [
"build",
"schemas",
"docs"
],
"files": ["build", "schemas", "docs"],
"scripts": {
"build": "run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=text --reporter=lcov mocha",
"lint": "eslint . --ext .ts",
"lint": "biome check .",
"lint:fix": "biome check --apply .",
"format:fix": "prettier --write .",
"format": "prettier .",
"release": "standard-version"
Expand All @@ -24,11 +21,7 @@
"type": "git",
"url": "git+https://github.com/ERC725Alliance/erc725.js"
},
"keywords": [
"ethereum",
"erc725",
"lsp"
],
"keywords": ["ethereum", "erc725", "lsp"],
"contributors": [
{
"name": "Robert McLeod",
Expand Down
52 changes: 26 additions & 26 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,33 @@ export const HASH_METHODS: {
};

// TODO: These values can be imported from lsp-smartcontracts lib after release
// prettier-ignore
// biome-ignore format: Keep numeric alignment
export const LSP6_DEFAULT_PERMISSIONS = {
CHANGEOWNER : "0x0000000000000000000000000000000000000000000000000000000000000001",
ADDCONTROLLER : "0x0000000000000000000000000000000000000000000000000000000000000002",
EDITPERMISSIONS : "0x0000000000000000000000000000000000000000000000000000000000000004",
ADDEXTENSIONS : "0x0000000000000000000000000000000000000000000000000000000000000008",
CHANGEEXTENSIONS : "0x0000000000000000000000000000000000000000000000000000000000000010",
ADDUNIVERSALRECEIVERDELEGATE : "0x0000000000000000000000000000000000000000000000000000000000000020",
CHANGEUNIVERSALRECEIVERDELEGATE : "0x0000000000000000000000000000000000000000000000000000000000000040",
REENTRANCY : "0x0000000000000000000000000000000000000000000000000000000000000080",
SUPER_TRANSFERVALUE : "0x0000000000000000000000000000000000000000000000000000000000000100",
TRANSFERVALUE : "0x0000000000000000000000000000000000000000000000000000000000000200",
SUPER_CALL : "0x0000000000000000000000000000000000000000000000000000000000000400",
CALL : "0x0000000000000000000000000000000000000000000000000000000000000800",
SUPER_STATICCALL : "0x0000000000000000000000000000000000000000000000000000000000001000",
STATICCALL : "0x0000000000000000000000000000000000000000000000000000000000002000",
SUPER_DELEGATECALL : "0x0000000000000000000000000000000000000000000000000000000000004000",
DELEGATECALL : "0x0000000000000000000000000000000000000000000000000000000000008000",
DEPLOY : "0x0000000000000000000000000000000000000000000000000000000000010000",
SUPER_SETDATA : "0x0000000000000000000000000000000000000000000000000000000000020000",
SETDATA : "0x0000000000000000000000000000000000000000000000000000000000040000",
ENCRYPT : "0x0000000000000000000000000000000000000000000000000000000000080000",
DECRYPT : "0x0000000000000000000000000000000000000000000000000000000000100000",
SIGN : "0x0000000000000000000000000000000000000000000000000000000000200000",
EXECUTE_RELAY_CALL : "0x0000000000000000000000000000000000000000000000000000000000400000",
ERC4337_PERMISSION : "0x0000000000000000000000000000000000000000000000000000000000800000",
ALL_PERMISSIONS : "0x00000000000000000000000000000000000000000000000000000000007f3f7f" // lsp6 v0.14.0
CHANGEOWNER : '0x0000000000000000000000000000000000000000000000000000000000000001',
ADDCONTROLLER : '0x0000000000000000000000000000000000000000000000000000000000000002',
EDITPERMISSIONS : '0x0000000000000000000000000000000000000000000000000000000000000004',
ADDEXTENSIONS : '0x0000000000000000000000000000000000000000000000000000000000000008',
CHANGEEXTENSIONS : '0x0000000000000000000000000000000000000000000000000000000000000010',
ADDUNIVERSALRECEIVERDELEGATE : '0x0000000000000000000000000000000000000000000000000000000000000020',
CHANGEUNIVERSALRECEIVERDELEGATE : '0x0000000000000000000000000000000000000000000000000000000000000040',
REENTRANCY : '0x0000000000000000000000000000000000000000000000000000000000000080',
SUPER_TRANSFERVALUE : '0x0000000000000000000000000000000000000000000000000000000000000100',
TRANSFERVALUE : '0x0000000000000000000000000000000000000000000000000000000000000200',
SUPER_CALL : '0x0000000000000000000000000000000000000000000000000000000000000400',
CALL : '0x0000000000000000000000000000000000000000000000000000000000000800',
SUPER_STATICCALL : '0x0000000000000000000000000000000000000000000000000000000000001000',
STATICCALL : '0x0000000000000000000000000000000000000000000000000000000000002000',
SUPER_DELEGATECALL : '0x0000000000000000000000000000000000000000000000000000000000004000',
DELEGATECALL : '0x0000000000000000000000000000000000000000000000000000000000008000',
DEPLOY : '0x0000000000000000000000000000000000000000000000000000000000010000',
SUPER_SETDATA : '0x0000000000000000000000000000000000000000000000000000000000020000',
SETDATA : '0x0000000000000000000000000000000000000000000000000000000000040000',
ENCRYPT : '0x0000000000000000000000000000000000000000000000000000000000080000',
DECRYPT : '0x0000000000000000000000000000000000000000000000000000000000100000',
SIGN : '0x0000000000000000000000000000000000000000000000000000000000200000',
EXECUTE_RELAY_CALL : '0x0000000000000000000000000000000000000000000000000000000000400000',
ERC4337_PERMISSION : '0x0000000000000000000000000000000000000000000000000000000000800000',
ALL_PERMISSIONS : '0x00000000000000000000000000000000000000000000000000000000007f3f7f'
};

export const LSP6_ALL_PERMISSIONS =
Expand Down
14 changes: 7 additions & 7 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ describe('Running @erc725/erc725.js tests...', () => {

describe('Getting data by schema element by provider', () => {
mockSchema.forEach((schemaElement) => {
it(schemaElement.name + ' with web3.currentProvider', async () => {
it(`${schemaElement.name} with web3.currentProvider`, async () => {
const returnRawData = generateAllRawData([schemaElement], false);
const provider = new HttpProvider({ returnData: returnRawData }, [
ERC725Y_INTERFACE_IDS.legacy,
Expand All @@ -866,7 +866,7 @@ describe('Running @erc725/erc725.js tests...', () => {
});
});

it(schemaElement.name + ' with ethereumProvider EIP 1193', async () => {
it(`${schemaElement.name} with ethereumProvider EIP 1193`, async () => {
const returnRawData = generateAllRawData([schemaElement], false);
const provider = new HttpProvider({ returnData: returnRawData }, [
ERC725Y_INTERFACE_IDS.legacy,
Expand Down Expand Up @@ -898,7 +898,7 @@ describe('Running @erc725/erc725.js tests...', () => {

// ARRAY type:
if (schemaElement.keyType.toLowerCase() === 'array') {
it('Encode data values in array: ' + schemaElement.name, async () => {
it(`Encode data values in array: ${schemaElement.name}`, async () => {
const results: string[] = [];

// Encode array loop
Expand All @@ -922,7 +922,7 @@ describe('Running @erc725/erc725.js tests...', () => {
assert.deepStrictEqual(results, schemaElement.returnGraphData);
});

it('decodes data values in array: ' + schemaElement.name, async () => {
it(`decodes data values in array: ${schemaElement.name}`, async () => {
const results: any[] = [];

// decode array loop
Expand Down Expand Up @@ -1071,7 +1071,7 @@ describe('Running @erc725/erc725.js tests...', () => {
}

// SINGLETON type: This is not an array, assumed 'Singleton'
it('encodes data value for: ' + schemaElement.name, async () => {
it(`encodes data value for: ${schemaElement.name}`, async () => {
const result = encodeKeyValue(
schemaElement.valueContent,
schemaElement.valueType,
Expand All @@ -1081,7 +1081,7 @@ describe('Running @erc725/erc725.js tests...', () => {
assert.deepStrictEqual(result, schemaElement.returnGraphData);
});

it('decodes data value for: ' + schemaElement.name, async () => {
it(`decodes data value for: ${schemaElement.name}`, async () => {
const result = decodeKeyValue(
schemaElement.valueContent,
schemaElement.valueType,
Expand Down Expand Up @@ -1397,7 +1397,7 @@ describe('Running @erc725/erc725.js tests...', () => {

const erc725Instance = new ERC725([]);

describe(`encodePermissions`, () => {
describe('encodePermissions', () => {
testCases.forEach((testCase) => {
it(`Encodes ${testCase.hex} permission correctly`, () => {
assert.deepStrictEqual(
Expand Down
66 changes: 64 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ 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 {
encodeDataSourceWithHash,
decodeDataSourceWithHash,
encodeValueType,
decodeValueType,
encodeValueContent,
decodeValueContent,
} from './lib/encoder';
import { internalSupportsInterface, checkPermissions } from './lib/detector';
import { decodeMappingKey } from './lib/decodeMappingKey';
import { encodePermissions, decodePermissions } from './lib/permissions';
import { AssetURLEncode } from './types/encodeData';
import { URLDataToEncode, URLDataWithHash, Verification } from './types';

export {
ERC725JSONSchema,
Expand All @@ -77,9 +86,12 @@ export { decodeData } from './lib/decodeData';
export { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName';
export { decodeMappingKey } from './lib/decodeMappingKey';
export {
encodeDataSourceWithHash,
decodeDataSourceWithHash,
encodeValueType,
decodeValueType,
encodeValueContent,
decodeValueContent,
encodeValueType,
} from './lib/encoder';
export { getDataFromExternalSources } from './lib/getDataFromExternalSources';
export { encodePermissions, decodePermissions } from './lib/permissions';
Expand Down Expand Up @@ -646,6 +658,28 @@ export class ERC725 {
return checkPermissions(requiredPermissions, grantedPermissions);
}

encodeDataSourceWithHash(
verification: undefined | Verification,
dataSource: string,
): string {
return encodeDataSourceWithHash(verification, dataSource);
}

static encodeDataSourceWithHash(
verification: undefined | Verification,
dataSource: string,
): string {
return encodeDataSourceWithHash(verification, dataSource);
}

decodeDataSourceWithHash(value: string): URLDataWithHash {
return decodeDataSourceWithHash(value);
}

static decodeDataSourceWithHash(value: string): URLDataWithHash {
return decodeDataSourceWithHash(value);
}

/**
* @param type The valueType to encode the value as
* @param value The value to encode
Expand Down Expand Up @@ -677,6 +711,34 @@ export class ERC725 {
decodeValueType(type: string, data: string) {
return decodeValueType(type, data);
}

static encodeValueContent(
valueContent: string,
value: string | number | AssetURLEncode | URLDataToEncode | boolean,
): string | false {
return encodeValueContent(valueContent, value);
}

encodeValueContent(
valueContent: string,
value: string | number | AssetURLEncode | URLDataToEncode | boolean,
): string | false {
return encodeValueContent(valueContent, value);
}

static decodeValueContent(
valueContent: string,
value: string,
): string | URLDataWithHash | number | boolean | null {
return decodeValueContent(valueContent, value);
}

decodeValueContent(
valueContent: string,
value: string,
): string | URLDataWithHash | number | boolean | null {
return decodeValueContent(valueContent, value);
}
}

export default ERC725;
11 changes: 7 additions & 4 deletions src/lib/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('tuple', () => {
]; // TODO: add more cases? Address, etc.

testCases.forEach((testCase) => {
it(`decodes tuple values`, () => {
it('decodes tuple values', () => {
expect(
decodeTupleKeyValue(
testCase.valueContent,
Expand Down Expand Up @@ -348,19 +348,22 @@ describe('tuple', () => {
{
valueType: '(bytes4,bytes8)',
valueContent: '(Bytes4,Number,Bytes5)',
isTuple: false, // valueContent length != valueType length
// valueContent length != valueType length
isTuple: false,
shouldThrow: true,
},
{
valueType: '(bytes4,bytes8)',
valueContent: '(Bytes2,Number)',
isTuple: false, // first item in valueType does not fit inside first item in valueContent (bytes4 > bytes2)
// first item in valueType does not fit inside first item in valueContent (bytes4 > bytes2)
isTuple: false,
shouldThrow: true,
},
{
valueType: '(bytes4,bytes8)',
valueContent: '(Bytes8,Number)',
isTuple: true, // first item in valueType fit in first item of valueContent (bytes4 < bytes8)
// first item in valueType fit in first item of valueContent (bytes4 < bytes8)
isTuple: true,
},
{
valueType: '(bytes4,bytes8)',
Expand Down
11 changes: 5 additions & 6 deletions src/lib/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const isValidTuple = (valueType: string, valueContent: string) => {
// is compatible with the valueType (e.g: bytes4)
const hexLiteralLength = valueContentParts[i].length - 2;

if (parseInt(valueTypeBytesLength, 10) < hexLiteralLength) {
if (Number.parseInt(valueTypeBytesLength, 10) < hexLiteralLength) {
throw new Error(
`Invalid tuple (${valueType},${valueContent}: ${valueContent[i]} cannot fit in ${valueType[i]}`,
);
Expand Down Expand Up @@ -148,11 +148,12 @@ export const decodeTupleKeyValue = (
const regexMatch = valueTypePart.match(tupleValueTypesRegex);

// if we are dealing with `bytesN`
if (regexMatch) bytesLengths.push(parseInt(regexMatch[1], 10));
if (regexMatch) bytesLengths.push(Number.parseInt(regexMatch[1], 10));

const numericMatch = valueTypePart.match(/u?int(\d+)/);

if (numericMatch) bytesLengths.push(parseInt(numericMatch[1], 10) / 8);
if (numericMatch)
bytesLengths.push(Number.parseInt(numericMatch[1], 10) / 8);

if (valueTypePart === 'address') bytesLengths.push(20);
});
Expand Down Expand Up @@ -289,9 +290,7 @@ export function decodeKey(schema: ERC725JSONSchema, value) {
}
default: {
console.error(
'Incorrect data match or keyType in schema from decodeKey(): "' +
schema.keyType +
'"',
`Incorrect data match or keyType in schema from decodeKey(): "${schema.keyType}"`,
);
return null;
}
Expand Down
Loading
Loading