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

Merged
merged 21 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
753ff52
chore(deps): bump web3-utils from 4.2.0 to 4.3.0 in /examples
dependabot[bot] Jul 9, 2024
c7af9e8
chore(deps): bump ws from 8.16.0 to 8.18.0 in /examples
dependabot[bot] Jul 9, 2024
8a9ed0d
docs: update schema docs page to latest content
CJ42 Jul 12, 2024
0cb3d0b
Merge pull request #470 from ERC725Alliance/docs-update-schema
Hugoo Jul 12, 2024
9cdb3c1
docs: move sentence from docs learn page into _erc725.js_ docs
CJ42 Jul 17, 2024
27c46d3
Merge pull request #471 from ERC725Alliance/docs/getting-started-func…
CJ42 Jul 17, 2024
cd6f240
test: refactor test to use correct tuple of CompactBytesArray for All…
CJ42 Jul 17, 2024
1b53462
docs: document how to encode / decode tuple of CompactBytesArray with…
CJ42 Jul 17, 2024
5c283dd
Merge pull request #472 from ERC725Alliance/docs/decode-compact-bytes…
CJ42 Jul 22, 2024
6d1ad6d
build(deps): bump path-to-regexp from 6.2.2 to 6.3.0
dependabot[bot] Sep 12, 2024
a39b965
fix: Make explicitely sure that method === 0x0000000 is also ignored …
richtera Sep 12, 2024
f5402b8
fix: Compile temporary patch
richtera Sep 12, 2024
27da039
fix: Repair patchIPFSUtlsIfApplication to only replace if the URL sta…
richtera Sep 17, 2024
225a0b4
fix: allow `number` in types for `dynamicKeyParts`
CJ42 Oct 23, 2024
f3be1c8
Merge pull request #477 from ERC725Alliance/fix/types-dynamicKeyParts
CJ42 Oct 23, 2024
bf6d5d5
Merge pull request #464 from ERC725Alliance/dependabot/npm_and_yarn/e…
CJ42 Oct 23, 2024
001a54c
Merge pull request #466 from ERC725Alliance/dependabot/npm_and_yarn/e…
CJ42 Oct 23, 2024
8d03cf4
Merge pull request #475 from ERC725Alliance/dependabot/npm_and_yarn/p…
CJ42 Oct 23, 2024
45b429d
Merge pull request #476 from ERC725Alliance/fix/isDataAuthentic
CJ42 Oct 23, 2024
30201af
chore: put correct latest version in `package.json`
CJ42 Oct 23, 2024
6027af4
Merge pull request #479 from ERC725Alliance/chore/version-package-json
CJ42 Oct 23, 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
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc725/erc725.js",
"version": "0.24.0",
"version": "0.27.1",
"description": "Library to interact with ERC725 smart contracts",
"main": "build/main/src/index.js",
"typings": "build/main/src/index.d.ts",
Expand Down
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
Loading