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 #452

Merged
merged 33 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d5857d6
docs: structure erc725.js docs function by functionalities
CJ42 May 16, 2024
e3364f4
docs: fix broken links
CJ42 May 16, 2024
f6b4a9d
feat: allow to pass `number` directly in array when encoding tuples
CJ42 May 16, 2024
8b86092
feat: return `dynamicKeyName` and `dynamicKeyPart` for `getSchema` wi…
CJ42 May 16, 2024
5217fba
chore: replace incorrect reference `LSP3IssuedAssets[]` -> `LSP12Issu…
CJ42 May 16, 2024
a36f694
test: add tests for encoding array index
CJ42 May 16, 2024
a85adaa
chore: replace incorrect valueType and valueContent in tests
CJ42 May 15, 2024
ef30c6c
refactor: remove custom method in favour of web3js lib function
CJ42 May 13, 2024
63016d6
test: add extra test case for encoding number `0` as `uintN`
CJ42 May 13, 2024
08e72d6
feat: export `mapPermission` function and don't make it throw an error
CJ42 May 13, 2024
07e123a
chore: group together permissions functions in the ERC725 class
CJ42 May 13, 2024
42b8092
Merge pull request #444 from ERC725Alliance/docs/fetchData
CJ42 May 17, 2024
a378773
Merge pull request #447 from ERC725Alliance/docs/sections
CJ42 May 17, 2024
8b2bb98
refactor: move all permissions functionalities under `permissions.ts`
CJ42 May 13, 2024
5445222
chore: fix linter errors
CJ42 May 17, 2024
fca2ea5
test: move `permissions.test.ts` file
CJ42 May 17, 2024
d0ee0f7
test: fix failing tests
CJ42 May 21, 2024
b1784ef
Merge pull request #436 from ERC725Alliance/feat/map-permission-and-p…
Hugoo May 21, 2024
f426a31
feat: export function to get verification method
CJ42 May 13, 2024
0c7ba98
feat: export method `isDataAuthentic` as static, single method or mem…
CJ42 May 13, 2024
335608f
docs: remove dedicated docs page for external data source utilities
CJ42 May 17, 2024
91363c4
Merge pull request #448 from ERC725Alliance/feat/tuple-types
Hugoo May 21, 2024
622675d
Merge pull request #449 from ERC725Alliance/feat/array-index-encoding
CJ42 May 21, 2024
0420959
docs: add method docs template
CJ42 May 24, 2024
d8ce6ac
docs: add documentation for `encodeValueContent`
CJ42 May 24, 2024
e4f33ea
docs: add missing methods `getSchema` and `getDataFromExternalSources`
CJ42 May 24, 2024
fde9f5d
fix: allow to decode `0x` as `0` for keyType `Array`
CJ42 May 27, 2024
93b1c08
chore: fix linter and remove accidentally commited file
CJ42 May 28, 2024
9422444
Merge pull request #451 from ERC725Alliance/fix/array-decoding
Hugoo May 29, 2024
f16e78d
test: add mock for external data fetching test
CJ42 May 29, 2024
2a67f26
docs: add missing descriptions for parameters and return examples
CJ42 May 29, 2024
dc02ccd
Merge pull request #432 from ERC725Alliance/feat/encoding-features-wi…
Hugoo May 29, 2024
39e3cb4
Merge pull request #450 from ERC725Alliance/docs/missing-functions
CJ42 May 29, 2024
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
49 changes: 49 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# erc725.js docs

The markdown files in this folder are published on the LUKSO docs portal: <https://docs.lukso.tech/tools/erc725js/getting-started>

## Method docs template

You can use the following example below as a template to document any new methods added the library.

### methodName

```js
myErc725.methodName(param1, param2, [optionalParams]);
```

```js
ERC725.methodName(param1, param2, [optionalParams]);
```

Describe your method and how it is intended to be used, the benefits it brings, and any specific behaviour that the functions has.

#### Parameters

| Name | Type | Description |
| :------- | :--------------------------------------------------------------------------------------------------------- | :---------- |
| `param1` | `string` | ... |
| `param2` | `string` or <br/> `string[]` or <br/> `number` or <br/> `number[]` or <br/> `boolean` or <br/> `boolean[]` | ... |

#### Returns

| Name | Type | Description |
| :--- | :------- | :---------- |
| | `string` | ... |

#### Examples

```javascript
import ERC725 from '@erc725/erc725.js';

const myErc725 = new ERC725();

myErc725.methodName('hello', 5);
// show in comment the expected output of the function
```

This method is also available as a static method.

```javascript
import ERC725 from '@erc725/erc725.js';

ERC725.methodName('hello', 5);
// show in comment the expected output of the function
```
3 changes: 0 additions & 3 deletions docs/classes/_category_.yml

This file was deleted.

2,764 changes: 1,836 additions & 928 deletions docs/classes/ERC725.md → docs/methods.md

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,34 @@ describe('Running @erc725/erc725.js tests...', () => {
});
});
});

describe('for tuples', () => {
it('encode `(bytes4,uint128)`', () => {
const schema = {
name: 'LSP4CreatorsMap:<address>',
key: '0x6de85eaf5d982b4e5da00000<address>',
keyType: 'Mapping',
valueType: '(bytes4,uint128)',
valueContent: '(Bytes4,Number)',
};

const expectedEncodedValue =
'0xb3c4928f00000000000000000000000000000005';

const result = ERC725.encodeData(
[
{
keyName: 'LSP4CreatorsMap:<address>',
dynamicKeyParts: address,
value: ['0xb3c4928f', 5],
},
],
[schema],
);

assert.equal(result.values[0], expectedEncodedValue);
});
});
});

describe('Testing utility encoding & decoding functions', () => {
Expand Down Expand Up @@ -1880,6 +1908,17 @@ describe('encodeKeyName', () => {
'0x31145577efe228036af40000a4fbbfe353124e6fa6bb7f8e088a9269df552ea2',
);
});

it('works for Array keys with index as `dynamicKeyParts', () => {
assert.deepStrictEqual(
encodeKeyName('MusicPlaylist[]', 2),
'0x03573598507fc76d82171baa336b7fd700000000000000000000000000000002',
);
assert.deepStrictEqual(
erc725Instance.encodeKeyName('MusicPlaylist[]', 2),
'0x03573598507fc76d82171baa336b7fd700000000000000000000000000000002',
);
});
});

describe('supportsInterface', () => {
Expand Down
206 changes: 139 additions & 67 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @author Robert McLeod <@robertdavid010>
* @author Fabian Vogelsteller <[email protected]>
* @author Hugo Masclet <@Hugoo>
* @author Jean Cavallera <@CJ42>
* @date 2020
*/

Expand All @@ -30,12 +31,18 @@ import {
convertIPFSGatewayUrl,
generateSchemasFromDynamicKeys,
duplicateMultiTypeERC725SchemaEntry,
getVerificationMethod,
isDataAuthentic,
} from './lib/utils';

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

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

// Types
Expand Down Expand Up @@ -67,9 +74,14 @@ import {
encodeValueContent,
decodeValueContent,
} from './lib/encoder';
import { internalSupportsInterface, checkPermissions } from './lib/detector';
import { internalSupportsInterface } from './lib/detector';
import { decodeMappingKey } from './lib/decodeMappingKey';
import { encodePermissions, decodePermissions } from './lib/permissions';
import {
encodePermissions,
decodePermissions,
checkPermissions,
mapPermission,
} from './lib/permissions';
import { AssetURLEncode } from './types/encodeData';
import { URLDataToEncode, URLDataWithHash, Verification } from './types';

Expand All @@ -82,7 +94,12 @@ export {
};

export { ERC725Config, KeyValuePair, ProviderTypes } from './types';
export { encodeData, encodeArrayKey } from './lib/utils';
export {
encodeData,
encodeArrayKey,
getVerificationMethod,
isDataAuthentic,
} from './lib/utils';
export { decodeData } from './lib/decodeData';
export { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName';
export { decodeMappingKey } from './lib/decodeMappingKey';
Expand All @@ -95,8 +112,12 @@ export {
decodeValueContent,
} from './lib/encoder';
export { getDataFromExternalSources } from './lib/getDataFromExternalSources';
export { encodePermissions, decodePermissions } from './lib/permissions';
export { checkPermissions } from './lib/detector';
export {
encodePermissions,
decodePermissions,
checkPermissions,
mapPermission,
} from './lib/permissions';
export { getSchema } from './lib/schemaParser';

// PRIVATE FUNCTION
Expand Down Expand Up @@ -502,50 +523,6 @@ export class ERC725 {
);
}

/**
* Encode permissions into a hexadecimal string as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissions The permissions you want to specify to be included or excluded. Any ommitted permissions will default to false.
* @returns {*} The permissions encoded as a hexadecimal string as defined by the LSP6 Standard.
*/
static encodePermissions(permissions: Permissions): string {
return encodePermissions(permissions);
}

/**
* Encode permissions into a hexadecimal string as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissions The permissions you want to specify to be included or excluded. Any ommitted permissions will default to false.
* @returns {*} The permissions encoded as a hexadecimal string as defined by the LSP6 Standard.
*/
encodePermissions(permissions: Permissions): string {
return encodePermissions(permissions);
}

/**
* Decodes permissions from hexadecimal as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissionHex The permission hexadecimal value to be decoded.
* @returns Object specifying whether default LSP6 permissions are included in provided hexademical string.
*/
static decodePermissions(permissionHex: string) {
return decodePermissions(permissionHex);
}

/**
* Decodes permissions from hexadecimal as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissionHex The permission hexadecimal value to be decoded.
* @returns Object specifying whether default LSP6 permissions are included in provided hexademical string.
*/
decodePermissions(permissionHex: string) {
return decodePermissions(permissionHex);
}

/**
* Hashes a key name for use on an ERC725Y contract according to LSP2 ERC725Y JSONSchema standard.
*
Expand Down Expand Up @@ -634,6 +611,53 @@ export class ERC725 {
return supportsInterface(interfaceIdOrName, options);
}

// Permissions related functions
// -----------------------------

/**
* Encode permissions into a hexadecimal string as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissions The permissions you want to specify to be included or excluded. Any ommitted permissions will default to false.
* @returns {*} The permissions encoded as a hexadecimal string as defined by the LSP6 Standard.
*/
static encodePermissions(permissions: Permissions): string {
return encodePermissions(permissions);
}

/**
* Encode permissions into a hexadecimal string as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissions The permissions you want to specify to be included or excluded. Any ommitted permissions will default to false.
* @returns {*} The permissions encoded as a hexadecimal string as defined by the LSP6 Standard.
*/
encodePermissions(permissions: Permissions): string {
return encodePermissions(permissions);
}

/**
* Decodes permissions from hexadecimal as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissionHex The permission hexadecimal value to be decoded.
* @returns Object specifying whether default LSP6 permissions are included in provided hexademical string.
*/
static decodePermissions(permissionHex: string) {
return decodePermissions(permissionHex);
}

/**
* Decodes permissions from hexadecimal as defined by the LSP6 KeyManager Standard.
*
* @link https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-6-KeyManager.md LSP6 KeyManager Standard.
* @param permissionHex The permission hexadecimal value to be decoded.
* @returns Object specifying whether default LSP6 permissions are included in provided hexademical string.
*/
decodePermissions(permissionHex: string) {
return decodePermissions(permissionHex);
}

/**
* Check if the required permissions are included in the granted permissions as defined by the LSP6 KeyManager Standard.
*
Expand Down Expand Up @@ -664,27 +688,16 @@ export class ERC725 {
return checkPermissions(requiredPermissions, grantedPermissions);
}

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

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

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

static decodeDataSourceWithHash(value: string): URLDataWithHash {
return decodeDataSourceWithHash(value);
}
// Encoding methods
// ----------------

/**
* @param type The valueType to encode the value as
Expand Down Expand Up @@ -745,6 +758,65 @@ export class ERC725 {
): string | URLDataWithHash | number | boolean | null {
return decodeValueContent(valueContent, value);
}

// External Data Source utilities (`VerifiableURI` and `JSONURI`)
// ----------------------------------------------------------------

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);
}

static getVerificationMethod(nameOrSig: string):
| {
method: (data: string | object | Uint8Array | null) => string;
name: SUPPORTED_VERIFICATION_METHOD_STRINGS;
sig: SUPPORTED_VERIFICATION_METHODS;
}
| undefined {
return getVerificationMethod(nameOrSig);
}

getVerificationMethod(nameOrSig: string):
| {
method: (data: string | object | Uint8Array | null) => string;
name: SUPPORTED_VERIFICATION_METHOD_STRINGS;
sig: SUPPORTED_VERIFICATION_METHODS;
}
| undefined {
return getVerificationMethod(nameOrSig);
}

static isDataAuthentic(
data: string | Uint8Array,
verificationOptions: Verification,
): boolean {
return isDataAuthentic(data, verificationOptions);
}

isDataAuthentic(
data: string | Uint8Array,
verificationOptions: Verification,
): boolean {
return isDataAuthentic(data, verificationOptions);
}
}

export default ERC725;
Loading
Loading