Skip to content

Commit

Permalink
Merge pull request #564 from lukso-network/tools-docs-sync
Browse files Browse the repository at this point in the history
Update Tools Documentation
  • Loading branch information
CJ42 authored Oct 13, 2023
2 parents b0788da + 3ef199a commit 460f9ec
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 65 deletions.
175 changes: 146 additions & 29 deletions docs/tools/erc725js/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,84 @@ sidebar_position: 1

# ERC725

## checkPermissions

```js
myErc725.checkPermissions(requiredPermissions, grantedPermissions);
```

```js
ERC725.checkPermissions(requiredPermissions, grantedPermissions);
```

Check if the required permissions are included in the granted permissions as defined by the [LSP6 KeyManager Standard](https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager).

:::info

`checkPermissions` is available as either a static or non-static method so can be called without instantiating an ERC725 object.

:::

#### Parameters

##### 1. `requiredPermissions` - String[] | String

An array of required permissions or a single required permission. (32bytes hex or the official name of the permission).

##### 2. `grantedPermissions` - String

The granted permissions. (32bytes hex).

#### Returns

| Type | Description |
| :------ | :----------------------------------------------------------------------------------------------------------------------------------------------- |
| boolean | A boolean value indicating whether the required permissions are included in the granted permissions as defined by the [LSP6 KeyManager Standard] |

#### Permission-Name Example

```javascript title="Checking permissions by name"
const requiredPermissions = 'CHANGEOWNER';
const grantedPermissions =
'0x000000000000000000000000000000000000000000000000000000000000ff51';
ERC725.checkPermissions(requiredPermissions, grantedPermissions);
// true

// This method is also available on the instance:

const requiredPermissions = ['CHANGEOWNER', 'CALL'];
const grantedPermissions =
'0x0000000000000000000000000000000000000000000000000000000000000051';
myErc725.checkPermissions(requiredPermissions, grantedPermissions);
// false
```

#### 32bytes hex Example

```javascript title="Checking permissions by 32bytes hex"
const requiredPermissions = [
'0x0000000000000000000000000000000000000000000000000000000000000001',
'0x0000000000000000000000000000000000000000000000000000000000000800',
];
const grantedPermissions =
'0x0000000000000000000000000000000000000000000000000000000000000051';

ERC725.checkPermissions(requiredPermissions, grantedPermissions);
// false

// This method is also available on the instance:

const requiredPermissions =
'0x0000000000000000000000000000000000000000000000000000000000000001';
const grantedPermissions =
'0x0000000000000000000000000000000000000000000000000000000000000051';

myErc725.checkPermissions(requiredPermissions, grantedPermissions);
// true
```

---

## decodeData

```js
Expand Down Expand Up @@ -53,7 +131,7 @@ An array of extra [LSP-2 ERC725YJSONSchema] objects that can be used to find the

:::

#### Single-Key Example
### Single-Key Example

```javascript title="Decoding an object with one key"
myErc725.decodeData([
Expand Down Expand Up @@ -95,7 +173,7 @@ myErc725.decodeData({
*/
```

#### Multi-Key Example
### Multi-Key Example

```javascript title="Decoding an object with multiple keys"
myErc725.decodeData([
Expand Down Expand Up @@ -146,7 +224,7 @@ myErc725.decodeData([
*/
```

#### Dynamic-Key Example
### Dynamic-Key Example

```javascript title="Decoding an object with dynamic key and a custom schema"
const schemas = [
Expand Down Expand Up @@ -275,11 +353,28 @@ When encoding JSON, it is possible to pass in the JSON object and the URL where

:::

:::info

When encoding some values using specific `string` or `bytesN` as `valueType`, if the data passed is a non-hex value, _erc725.js_ will convert the value
to its utf8-hex representation for you. For instance:

- If `valueType` is `string` and you provide a `number` as input.

_Example: input `42` --> will encode as `0x3432` (utf-8 hex code for `4` = `0x34`, for `2` = `0x32`)._

- If `valueType` is `bytes32` or `bytes4`, it will convert as follow:

_Example 1: input `week` encoded as `bytes4` --> will encode as `0x7765656b`._

_Example 2: input `1122334455` encoded as `bytes4` --> will encode as `0x42e576f7`._

:::

#### Parameters

##### 1. `data` - Object or array of Objects
##### 1. `data` - Array of Objects

An object or array of objects containing the following properties:
An array of objects containing the following properties:

| Name | Type | Description |
| :--------------------------- | :--------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -305,6 +400,9 @@ After the `data` is encoded, the object is ready to be stored in smart contracts

#### Examples

<details>
<summary>Encode a <code>JSONURL</code> with JSON and uploaded URL</summary>

```javascript title="Encode a JSONURL with JSON and uploaded URL"
myErc725.encodeData([
{
Expand Down Expand Up @@ -358,10 +456,12 @@ myErc725.encodeData([
```

```javascript
myErc725.encodeData({
keyName: 'LSP1UniversalReceiverDelegate',
value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb',
});
myErc725.encodeData([
{
keyName: 'LSP1UniversalReceiverDelegate',
value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb',
},
]);
/**
{
keys: ['0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47'],
Expand All @@ -370,6 +470,11 @@ myErc725.encodeData({
*/
```

</details>

<details>
<summary>Encode a <code>JSONURL</code> with hash function, hash and uploaded URL</summary>

```javascript title="Encode a JSONURL with hash function, hash and uploaded URL"
myErc725.encodeData([
{
Expand All @@ -389,6 +494,11 @@ myErc725.encodeData([
*/
```

</details>

<details>
<summary>Encode dynamic keys</summary>

```javascript title="Encode dynamic keys"
const schemas = [
{
Expand Down Expand Up @@ -445,6 +555,11 @@ myErc725.encodeData(
*/
```

</details>

<details>
<summary>Encode multiple keys at once</summary>

```javascript title="Encode multiple keys at once"
myErc725.encodeData([
{
Expand Down Expand Up @@ -487,6 +602,8 @@ myErc725.encodeData([
*/
```

</details>

---

## encodeKeyName
Expand Down Expand Up @@ -527,8 +644,8 @@ The hash must be retrievable from the ERC725Y contract via the [getData](#getdat
ERC725.encodeKeyName('LSP3Profile');
// '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'

ERC725.encodeKeyName('SupportedStandards:LSP3UniversalProfile');
// '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38'
ERC725.encodeKeyName('SupportedStandards:LSP3Profile');
// '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347'

ERC725.encodeKeyName(
'AddressPermissions:Permissions:cafecafecafecafecafecafecafecafecafecafe',
Expand Down Expand Up @@ -760,16 +877,16 @@ The name(s) (or the encoded name(s) as schema key) of the element(s) in the smar

:::

#### All-Keys Example
### All-Keys Example

```javascript title="Receiving all keys from the schema"
await myErc725.fetchData();
/**
[
{
name: 'SupportedStandards:LSP3UniversalProfile',
key: '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38',
value: '0xabe425d6'
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
value: '0x5ef83ad9'
},
{
name: 'LSP3Profile',
Expand Down Expand Up @@ -801,7 +918,7 @@ await myErc725.fetchData();
*/
```

#### Single-Key Example
### Single-Key Example

```javascript title="Receiving one key from the schema"
await myErc725.fetchData('LSP3Profile');
Expand All @@ -824,7 +941,7 @@ await myErc725.fetchData(['LSP1UniversalReceiverDelegate']);
*/
```

#### Multi-Keys / Dynamic-Keys Example
### Multi-Keys / Dynamic-Keys Example

```javascript title="Receiving multiple keys from the schema"
await myErc725.fetchData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
Expand Down Expand Up @@ -909,16 +1026,16 @@ The name(s) (or the encoded name(s) as schema key) of the element(s) in the smar

:::

#### All-Keys Example
### All-Keys Example

```javascript title="Receiving all keys from the schema"
await myErc725.getData();
/**
[
{
name: 'SupportedStandards:LSP3UniversalProfile',
key: '0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38',
value: '0xabe425d6',
name: 'SupportedStandards:LSP3Profile',
key: '0xeafec4d89fa9619884b600005ef83ad9559033e6e941db7d7c495acdce616347',
value: '0x5ef83ad9',
},
{
name: 'LSP1UniversalReceiverDelegate',
Expand Down Expand Up @@ -954,7 +1071,7 @@ await myErc725.getData();
*/
```

#### Single-Key Example
### Single-Key Example

```javascript title="Receiving one key from the schema"
await myErc725.getData('LSP3Profile');
Expand Down Expand Up @@ -995,7 +1112,7 @@ await myErc725.getData('LSP1UniversalReceiverDelegate');
*/
```

#### Multi-Key Example
### Multi-Key Example

```javascript title="Receiving multiple keys from the schema"
await myErc725.getData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
Expand All @@ -1019,7 +1136,7 @@ await myErc725.getData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
*/
```

#### Dynamic-Key Example
### Dynamic-Key Example

```javascript title="Receiving dynamic keys from the schema"
await myErc725.getData({
Expand Down Expand Up @@ -1151,7 +1268,7 @@ An array of extra [LSP-2 ERC725YJSONSchema] objects that can be used to find the
| `result` | Record string | If the parameter `keys` is a string[&nbsp;] and the schema was found. |
| `result` | null | If the schema was not found. |

#### Example using a predefined LSP3 schema
### Example using a predefined LSP3 schema

```javascript title="Parsing the hashed key from the LSP3 schema"
myErc725.getSchema(
Expand Down Expand Up @@ -1190,7 +1307,7 @@ myErc725.getSchema([
*/
```

#### Example using a custom schema
### Example using a custom schema

```javascript title="Parsing the hashed key from a custom schema"
myErc725.getSchema(
Expand Down Expand Up @@ -1343,7 +1460,7 @@ myErc725.supportsInterface('0xfd4d5c50');

ERC725.supportsInterface('0xfd4d5c50', {
address: '0xe408BDDbBAB1985006A2c481700DD473F932e5cB',
rpcUrl: 'https://rpc.l16.lukso.network',
rpcUrl: 'https://rpc.testnet.lukso.network',
});
// false
```
Expand All @@ -1353,8 +1470,8 @@ myErc725.supportsInterface('LSP0ERC725Account');
// false

ERC725.supportsInterface('LSP0ERC725Account', {
address: '0xe408BDDbBAB1985006A2c481700DD473F932e5cB',
rpcUrl: 'https://rpc.l16.lukso.network',
address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D',
rpcUrl: 'https://rpc.testnet.lukso.network',
});
// true
```
Loading

0 comments on commit 460f9ec

Please sign in to comment.