Skip to content

Commit

Permalink
Merge pull request #478 from ERC725Alliance/develop
Browse files Browse the repository at this point in the history
sync main to release
  • Loading branch information
CJ42 authored Oct 23, 2024
2 parents 979b634 + 6027af4 commit 1ceb7b3
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 41 deletions.
4 changes: 4 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ const verifiableURI = encodeDataSourceWithHash(
Try running the code snippets below within your browser using [StackBlitz](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js).
:::

The _erc725.js_ contains multiple functionalities such as reading and decoding data. A full list is available under the [**Methods**](./methods.md) page.

For fetching data, it is possible to query one data key (as a `string` name) or multiple data keys at once by passing an array parameter, as shown below.

```js
await erc725.getOwner();
// > '0x28D25E70819140daF65b724158D00c373D1a18ee'
Expand Down
115 changes: 114 additions & 1 deletion docs/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sidebar_position: 1
title: 'Methods'
---

import CodeSandbox from "../../../src/components/CodeSandbox";
import CodeSandbox from "@site/src/components/CodeSandbox";

<CodeSandbox />

Expand Down Expand Up @@ -508,6 +508,64 @@ ERC725.encodeData(

</details>

<details>
<summary>Encode a tuple of <code>CompactBytesArray</code></summary>

```ts title="Encode a tuple of CompactBytesArray"
import ERC725 from '@erc725/erc725.js';

const schemas = [
{
name: 'AddressPermissions:AllowedCalls:<address>',
key: '0x4b80742de2bf393a64c70000<address>',
keyType: 'MappingWithGrouping',
valueType: '(bytes4,address,bytes4,bytes4)[CompactBytesArray]',
valueContent: '(BitArray,Address,Bytes4,Bytes4)',
}
];

ERC725.encodeData(
[
{
keyName: 'AddressPermissions:AllowedCalls:<address>',
dynamicKeyParts: "0xcafecafecafecafecafecafecafecafecafecafe"
value: [
'0x00000003', // CALL and TRANSFERVALUE
'0xCA41e4ea94c8fA99889c8EA2c8948768cBaf4bc0', // addresses are decoded as checksummed
'0x3e89ad98', // LSP0 interface ID
'0xffffffff', // any function
],
[
'0x00000002', // CALL only
'0xF70Ce3b58f275A4c28d06C98615760dDe774DE57',
'0xffffffff', // any standard interface ID
'0x760d9bba', // function selector of `transfer(address,address,uint256,bool,bytes)`
],
[
'0x00000001', // TRANSFERVALUE only
'0xd3236aa1B8A4dDe5eA375fd1F2Fb5c354e686c9f',
'0xffffffff', // any standard interface ID
'0xffffffff', // any function
],
},
],
schemas,
);
/**
{
keys: [
'0x4b80742de2bf393a64c70000cafecafecafecafecafecafecafecafecafecafe', // -> data key for `AddressPermissions:AllowedCalls:0xcafecafecafecafecafecafecafecafecafecafe`
],
values: [
'0x002000000003ca41e4ea94c8fa99889c8ea2c8948768cbaf4bc03e89ad98ffffffff002000000002f70ce3b58f275a4c28d06c98615760dde774de57ffffffff760d9bba002000000001d3236aa1b8a4dde5ea375fd1f2fb5c354e686c9fffffffffffffffff', // (bytes4,address,bytes4,bytes4)[CompactBytesArray]
],
}
*/

```

</details>

---

### encodeKeyName
Expand Down Expand Up @@ -965,6 +1023,61 @@ ERC725.decodeData(
*/
```
#### Tuple of CompactBytesArray Example
```ts title="Decode a tuple of CompactBytesArray"
import ERC725 from '@erc725/erc725.js';

const schemas = [
{
name: 'AddressPermissions:AllowedCalls:<address>',
key: '0x4b80742de2bf393a64c70000<address>',
keyType: 'MappingWithGrouping',
valueType: '(bytes4,address,bytes4,bytes4)[CompactBytesArray]',
valueContent: '(BitArray,Address,Bytes4,Bytes4)',
}
];

ERC725.decodeData(
[
{
keyName: 'AddressPermissions:AllowedCalls:<address>',
dynamicKeyParts: "0xcafecafecafecafecafecafecafecafecafecafe"
value: '0x002000000003ca41e4ea94c8fa99889c8ea2c8948768cbaf4bc03e89ad98ffffffff002000000002f70ce3b58f275a4c28d06c98615760dde774de57ffffffff760d9bba002000000001d3236aa1b8a4dde5ea375fd1f2fb5c354e686c9fffffffffffffffff'
},
],
schemas,
);

/**
{
key: '0x4b80742de2bf393a64c70000cafecafecafecafecafecafecafecafecafecafe',
name: 'AddressPermissions:AllowedCalls:cafecafecafecafecafecafecafecafecafecafe',
value: [
[
'0x00000003', // CALL and TRANSFERVALUE
'0xCA41e4ea94c8fA99889c8EA2c8948768cBaf4bc0', // addresses are decoded as checksummed
'0x3e89ad98', // LSP0 interface ID
'0xffffffff', // any function
],
[
'0x00000002', // CALL only
'0xF70Ce3b58f275A4c28d06C98615760dDe774DE57',
'0xffffffff', // any standard interface ID
'0x760d9bba', // function selector of `transfer(address,address,uint256,bool,bytes)`
],
[
'0x00000001', // TRANSFERVALUE only
'0xd3236aa1B8A4dDe5eA375fd1F2Fb5c354e686c9f',
'0xffffffff', // any standard interface ID
'0xffffffff', // any function
]
]
}
*/

```
### decodeValueType
```js
Expand Down
12 changes: 8 additions & 4 deletions docs/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ sidebar_position: 2

# Schemas

The `@erc725/erc725.js` library contains a range of standard [LSP ERC725 JSON schemas](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md).
:::info 📄 Schema Specification

Schemas allow erc725.js to know how to decode and encode data written in an [ERC725Y](https://eips.ethereum.org/EIPS/eip-725) smart contract.
For more details on schemas, see the [**official specification** of the LSP2 ERC725 JSON schemas](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md) standard specification

_A quick reference for keys used in schema definitions can be seen below_
:::

The ⚒️ [erc725.js](https://npmjs.com/package/@erc725/erc725.js) library works with [ERC725Y JSON schemas](../../standards/generic-standards/lsp2-json-schema). These schemas are JSON structures that tell developers and programs how to decode and encode 🗂️ [ERC725Y data keys](../../standards/lsp-background/erc725#erc725y-generic-data-keyvalue-store) from any [ERC725Y](https://eips.ethereum.org/EIPS/eip-725) smart contract.. You need to load the required schemas of the data keys you want to fetch when initializing the `ERC725` class.

[Official Documentation](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md).
The most common and standard schemas are [available](../../tools/erc725js/schemas.md) directly within the _erc725.js_ library. But you can also create and load your own ERC725Y JSON schemas if you want to use custom data keys.

_A quick reference for keys used in schema definitions can be seen below_

- `name`: An arbitrary name
- `key`: The sha3 hash of the name
Expand Down
48 changes: 30 additions & 18 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions src/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,31 @@ describe('utils', () => {
name: 'AddressPermissions:AllowedCalls:<address>',
key: '0x4b80742de2bf393a64c70000<address>',
keyType: 'MappingWithGrouping',
valueType: '(bytes4,address,bytes4)[CompactBytesArray]',
valueContent: '(Bytes4,Address,Bytes4)',
valueType: '(bytes4,address,bytes4,bytes4)[CompactBytesArray]',
valueContent: '(BitArray,Address,Bytes4,Bytes4)',
},
decodedValue: [
[
'0xcafecafe',
'0xDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5',
'0xcafecafe',
'0x00000003', // CALL and TRANSFERVALUE
'0xCA41e4ea94c8fA99889c8EA2c8948768cBaf4bc0', // addresses are decoded as checksummed
'0x3e89ad98', // LSP0 interface ID
'0xffffffff', // any function
],
[
'0xbeefbeef',
'0xFE31320faF8Da1492Eadf8Deb79bd264D7cF2141',
'0xbeefbeef',
'0x00000002', // CALL only
'0xF70Ce3b58f275A4c28d06C98615760dDe774DE57',
'0xffffffff', // any standard interface ID
'0x760d9bba', // function selector of `transfer(address,address,uint256,bool,bytes)`
],
[
'0xf00df00d',
'0xc527702b14BF2f79F70B32e09F62B6A74cADFd80',
'0xf00df00d',
'0x00000001', // TRANSFERVALUE only
'0xd3236aa1B8A4dDe5eA375fd1F2Fb5c354e686c9f',
'0xffffffff', // any standard interface ID
'0xffffffff', // any function
],
],
encodedValue:
'0x001ccafecafeDAFEA492D9c6733ae3d56b7Ed1ADB60692c98Bc5cafecafe001cbeefbeefFE31320faF8Da1492Eadf8Deb79bd264D7cF2141beefbeef001cf00df00dc527702b14BF2f79F70B32e09F62B6A74cADFd80f00df00d'.toLowerCase(),
'0x002000000003ca41e4ea94c8fa99889c8ea2c8948768cbaf4bc03e89ad98ffffffff002000000002f70ce3b58f275a4c28d06c98615760dde774de57ffffffff760d9bba002000000001d3236aa1b8a4dde5ea375fd1f2fb5c354e686c9fffffffffffffffff',
},
];

Expand Down
6 changes: 4 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ export function isDataAuthentic(
options: Verification,
capture?: string[],
): boolean {
if (!options || !options.method) {
if (!options?.method || options?.method === '0x00000000') {
return true;
}

Expand Down Expand Up @@ -613,7 +613,9 @@ export function patchIPFSUrlsIfApplicable(
receivedData: URLDataWithHash,
ipfsGateway: string,
): URLDataWithHash {
if (receivedData?.url?.indexOf('ipfs://') !== -1) {
// Only map URL if it's indeed an ipfs:// URL and ignore if it's a data:// URL with JSON
// possibly containing an IPFS URL inside of the JSON data.
if (receivedData?.url?.startsWith('ipfs://')) {
return {
...receivedData,
url: receivedData.url.replace('ipfs://', ipfsGateway),
Expand Down
2 changes: 1 addition & 1 deletion src/types/decodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EncodeDataType, URLDataWithHash } from './encodeData/JSONURL';
export interface DataInput {
keyName: string; // can be the name or the hex/hash
value;
dynamicKeyParts?: string | string[];
dynamicKeyParts?: string | string[] | number;
totalArrayLength?: number;
startingIndex?: number;
}
Expand Down

0 comments on commit 1ceb7b3

Please sign in to comment.