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

docs: add documentation on how to decode tuple of CompactBytesArray with AddressPermissions:AllowedCalls:<address> as example #472

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 113 additions & 0 deletions docs/methods.md
Original file line number Diff line number Diff line change
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
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
Loading