Skip to content

Commit

Permalink
Merge branch 'develop' into feat/array-length-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Nov 24, 2023
2 parents 839c9d1 + 7791977 commit 2ba3bb7
Show file tree
Hide file tree
Showing 35 changed files with 11,779 additions and 7,550 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ await myErc725.getData();
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3',
verification: {
method: 'keccak256(utf8)',
data: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3'
},
url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5',
},
},
Expand Down
159 changes: 51 additions & 108 deletions docs/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ myErc725.decodeData([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361'
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
Expand All @@ -165,8 +167,10 @@ myErc725.decodeData({
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361'
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
}
Expand All @@ -187,8 +191,7 @@ myErc725.decodeData([
value: [
{
key: '0x7c8c3416d6cda87cd42c71ea1843df28ac4850354f988d55ee2eaa47b6dc05cd',
value:
'0x0000000000000000000000000000000000000000000000000000000000000002',
value: '0x00000000000000000000000000000002',
},
{
key: '0x7c8c3416d6cda87cd42c71ea1843df2800000000000000000000000000000000',
Expand All @@ -207,8 +210,10 @@ myErc725.decodeData([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
hashFunction: 'keccak256(utf8)',
verification: {
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
method: 'keccak256(utf8)'
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
Expand Down Expand Up @@ -257,8 +262,10 @@ myErc725.decodeData(
name: 'MyKeyName:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
key: '0x35e6950bc8d2aaaabbbb00000000000000000000000000000000000000000001',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361'
},
url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
Expand Down Expand Up @@ -480,8 +487,10 @@ myErc725.encodeData([
{
keyName: 'LSP3Profile',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
Expand Down Expand Up @@ -565,8 +574,10 @@ myErc725.encodeData([
{
keyName: 'LSP3Profile',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
},
Expand All @@ -593,7 +604,7 @@ myErc725.encodeData([
],
values: [
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x0000000000000000000000000000000000000000000000000000000000000002',
'0x00000000000000000000000000000002',
'0xd94353d9b005b3c0a9da169b768a31c57844e490',
'0xdaea594e385fc724449e3118b2db7e86dfba1826',
'0x1183790f29be3cdfd0a102862fea1a4a30b3adab',
Expand Down Expand Up @@ -693,9 +704,9 @@ The key name or erc725y json schema associated to the key hash to decode, for in

#### Returns

| Name | Type | Description |
| :---------------- | :--------------------------------------------------- | :----------------------------------------------- |
| `dynamicKeyParts` | {type: string, value: string OR number OR boolean}[] | The dynamic key parts decoded from the key hash. |
| Name | Type | Description |
| :---------------- | :----------------------------------------------------- | :----------------------------------------------- |
| `dynamicKeyParts` | \{type: string, value: string OR number OR boolean\}[] | The dynamic key parts decoded from the key hash. |

#### Example

Expand All @@ -704,6 +715,7 @@ ERC725.decodeMappingKey(
'0x35e6950bc8d21a1699e50000cafecafecafecafecafecafecafecafecafecafe',
'MyKeyName:<address>',
);
// Decoding will checksum addresses
// [{
// type: 'address',
// value: '0xCAfEcAfeCAfECaFeCaFecaFecaFECafECafeCaFe'
Expand Down Expand Up @@ -806,6 +818,7 @@ ERC725.encodePermissions({
ENCRYPT: false,
DECRYPT: false,
SIGN: false,
EXECUTE_RELAY_CALL: false
}),
// '0x0000000000000000000000000000000000000000000000000000000000000110'

Expand Down Expand Up @@ -1062,8 +1075,10 @@ await myErc725.getData();
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3',
verification: {
method: 'keccak256(utf8)',
data: '0x70546a2accab18748420b63c63b5af4cf710848ae83afc0c51dd8ad17fb5e8b3',
},
url: 'ipfs://QmecrGejUQVXpW4zS948pNvcnQrJ1KiAoM6bdfrVcWZsn5',
},
},
Expand All @@ -1080,8 +1095,10 @@ await myErc725.getData('LSP3Profile');
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
verification: {
method: 'keccak256(utf8)',
data: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
},
url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV'
},
}
Expand All @@ -1094,8 +1111,10 @@ await myErc725.getData(['LSP3Profile']);
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
verification: {
method: 'keccak256(utf8)',
data: '0xd96ff7776660095f661d16010c4349aa7478a9129ce0670f771596a6ff2d864a',
},
url: 'ipfs://QmbTmcbp8ZW23vkQrqkasMFqNg2z1iP4e3BCUMz9PKDsSV'
},
}
Expand All @@ -1122,8 +1141,10 @@ await myErc725.getData(['LSP3Profile', 'LSP1UniversalReceiverDelegate']);
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
verification: {
method: 'keccak256(utf8)',
data: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
},
url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p'
}
},
Expand Down Expand Up @@ -1182,8 +1203,10 @@ await myErc725.getData([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
verification: {
method: 'keccak256(utf8)',
data: '0xeeafeebeb416923dfb0dcf4c66b045c72742121ce2a06f93ae044ee0efb70777',
},
url: 'ipfs://QmZnG5Z5B5Dq8iFFtsL5i7AnrgH16P4DJ8UhY7j8RzX51p'
}
},
Expand Down Expand Up @@ -1395,83 +1418,3 @@ await myErc725.isValidSignature(
[lsp6 keymanager permissions]: ../../../../../standards/universal-profile/lsp6-key-manager#permissions
[lsp6 keymanager standard]: https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager
[lsp-2 erc725yjsonschema]: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md

## supportsInterface

```js
myERC725.supportsInterface(interfaceIdOrName);
```

```js
ERC725.supportsInterface(interfaceIdOrName, options);
```

You can use this function if you need to check if the ERC725 object or a smart contract supports a specific interface (by ID or name). When you use the function on your instantiated ERC725 class, it will use the contract address and provider provided at instantiation. On non instantiated class, you need to specify them in the `options` parameter.

:::caution
The `interfaceId` is not the most secure way to check for a standard, as they could be set manually.
:::

#### Parameters

##### 1. `interfaceIdOrName` - String

Either a string of the hexadecimal `interfaceID` as defined by [ERC165](https://eips.ethereum.org/EIPS/eip-165) or one of the predefined interface names:

| interfaceName | Standard |
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------- |
| `ERC1271` | [EIP-1271: Standard Signature Validation Method for Contracts](https://eips.ethereum.org/EIPS/eip-1271) |
| `ERC725X` | [EIP-725: General execution standard](https://eips.ethereum.org/EIPS/eip-725) |
| `ERC725Y` | [EIP-725: General key-value store](https://eips.ethereum.org/EIPS/eip-725) |
| `LSP0ERC725Account` | [LSP-0: ERC725 Account](https://docs.lukso.tech/standards/universal-profile/lsp0-erc725account) |
| `LSP1UniversalReceiver` | [LSP-1: Universal Receiver](https://docs.lukso.tech/standards/generic-standards/lsp1-universal-receiver) |
| `LSP1UniversalReceiverDelegate` | [LSP-1: Universal Receiver Delegate](https://docs.lukso.tech/standards/universal-profile/lsp1-universal-receiver-delegate) |
| `LSP6KeyManager` | [LSP-6: Key Manager](https://docs.lukso.tech/standards/universal-profile/lsp6-key-manager) |
| `LSP7DigitalAsset` | [LSP-7: Digital Asset](https://docs.lukso.tech/standards/nft-2.0/LSP7-Digital-Asset) |
| `LSP8IdentifiableDigitalAsset` | [LSP-8: Identifiable Digital Asset](https://docs.lukso.tech/standards/nft-2.0/LSP8-Identifiable-Digital-Asset) |
| `LSP9Vault` | [LSP-9: Vault](https://docs.lukso.tech/standards/universal-profile/lsp9-vault) |

:::info

The `interfaceName` will only check for the latest version of the standard's `interfaceID`, which can be found in `src/constants/interfaces`. For LSPs, the `interfaceIDs` are taken from the latest release of the [@lukso/lsp-smart-contracts](https://github.com/lukso-network/lsp-smart-contracts) library.

:::info

##### 2. `options` - Object (optional)

On non instantiated class, you should provide an `options` object.

| Name | Type | Description |
| :-------- | :----- | :------------------------------------------------------------------- |
| `address` | string | Address of the smart contract to check against a certain interface. |
| `rpcUrl` | string | RPC URL to connect to the network the smart contract is deployed to. |

#### Returns

| Type | Description |
| :----------------- | :------------------------------------------------------------ |
| `Promise<boolean>` | Returns `true` if the interface was found, otherwise `false`. |

#### Examples

```javascript title="By using the interface ID"
myErc725.supportsInterface('0xfd4d5c50');
// true

ERC725.supportsInterface('0xfd4d5c50', {
address: '0xe408BDDbBAB1985006A2c481700DD473F932e5cB',
rpcUrl: 'https://rpc.testnet.lukso.network',
});
// false
```

```javascript title="By using interface name"
myErc725.supportsInterface('LSP0ERC725Account');
// false

ERC725.supportsInterface('LSP0ERC725Account', {
address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D',
rpcUrl: 'https://rpc.testnet.lukso.network',
});
// true
```
10 changes: 7 additions & 3 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const address = '0x0Dc07C77985fE31996Ed612F568eb441afe5768D';
const RPC_URL = 'https://rpc.testnet.lukso.network';
const config = {
ipfsGateway: 'https://YOUR-IPFS-GATEWAY/ipfs/',
gas: 20_000_000, // optional, default is 1_000_000
};

const erc725 = new ERC725(schemas, address, RPC_URL, config);
Expand All @@ -84,8 +85,10 @@ await erc725.getData(['LSP3Profile', 'SupportedStandards:LSP3Profile']);
{
LSP3Profile: {
url: 'ipfs://QmXybv2LdJWscy1C6yRKUjvnaj6aqKktZX4g4xmz2nyYj2',
hash: '0xb4f9d72e83bbe7e250ed9ec80332c493b7b3d73e0d72f7b2c7ab01c39216eb1a',
hashFunction: 'keccak256(utf8)'
verification: {
data: '0xb4f9d72e83bbe7e250ed9ec80332c493b7b3d73e0d72f7b2c7ab01c39216eb1a',
method: 'keccak256(utf8)'
}
},
'SupportedStandards:LSP3Profile': '0x5ef83ad9'
}
Expand All @@ -110,7 +113,7 @@ await erc725.fetchData('LSP3Profile'); // downloads and verifies the linked JSON
```

:::tip Try it out
You can run the code snippit within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js).
You can run the code snippet within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js).

:::note
Whenever you can you should import `ERC725` via the named export. However currently we are also providing a default export.
Expand All @@ -127,6 +130,7 @@ After the instance has been created, it is still possible to change settings thr
myERC725.options.schema = '<schema>' // change schema
myERC725.options.address '<address>' // change address
myERC725.options.ipfsGateway = '<url>' // used for fetchData(), default: 'https://cloudflare-ipfs.com/ipfs/'
myERC725.options.gas = 20_000_000 // change gas setting

// NOTE: ERC725.provider can not be changed
```
4 changes: 2 additions & 2 deletions docs/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const ethereumProvider = window.ethereum;
const erc725 = new ERC725([], '0x...', ethereumProvider);
```

## Web3
## Web3 (deprecated)

The following code snippet will use the web3 provider available at web3.providers from the corresponding `web3` library.
The following code snippet will use the web3 provider available at `web3.providers` from the corresponding `web3` library.

:::caution Warning

Expand Down
4 changes: 3 additions & 1 deletion docs/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ LSP4DigitalAssetLegacy.json
LSP4DigitalAsset.json
LSP5ReceivedAssets.json
LSP6KeyManager.json
LSP8IdentifiableDigitalAsset.json
LSP9Vault.json
LSP10ReceivedVaults.json
LSP12IssuedAssets.json
LSP17ContractExtension.json
```

You can import them from:
Expand All @@ -47,5 +49,5 @@ import LSP5 from '@erc725/erc725.js/schemas/LSP5ReceivedAssets.json';
const myErc725Contract = new ERC725js(LSP3, address, web3.currentProvider);

// You can retrieve the current loaded schema via
myErc725Contract.options.schemas
myErc725Contract.options.schemas;
```
12 changes: 8 additions & 4 deletions examples/src/decodeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const decodedDataOneKey = myERC725.decodeData([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx'
}
}
Expand Down Expand Up @@ -56,8 +58,10 @@ const decodedDataManyKeys = myERC725.decodeData([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
hashFunction: 'keccak256(utf8)',
hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx'
}
},
Expand Down
Loading

0 comments on commit 2ba3bb7

Please sign in to comment.