Skip to content

Commit

Permalink
Merge pull request #369 from ERC725Alliance/develop
Browse files Browse the repository at this point in the history
Sync main
  • Loading branch information
Hugoo authored Dec 15, 2023
2 parents 90f735c + 330c604 commit 3720b17
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const schema = [
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
valueType: 'bytes',
},
{
Expand Down
31 changes: 15 additions & 16 deletions docs/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const schemas = [
key: '0x...',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
},
];

Expand All @@ -251,7 +251,7 @@ myErc725.decodeData(
'true',
],
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
],
schemas,
Expand Down Expand Up @@ -469,9 +469,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>
<summary>Encode a <code>VerifiableURI</code> with JSON and uploaded URL</summary>
```javascript title="Encode a JSONURL with JSON and uploaded URL"
```javascript title="Encode a VerifiableURI with JSON and uploaded URL"
myErc725.encodeData([
{
keyName: 'LSP3Profile',
Expand Down Expand Up @@ -541,9 +541,9 @@ myErc725.encodeData([
</details>

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

```javascript title="Encode a JSONURL with hash function, hash and uploaded URL"
```javascript title="Encode a VerifiableURI with hash function, hash and uploaded URL"
myErc725.encodeData([
{
keyName: 'LSP3Profile',
Expand Down Expand Up @@ -1005,7 +1005,7 @@ myErc725.decodeMappingKey(
myErc725.fetchData([keys]);
```

The `fetchData` function fetches smart contract data and can additionally return [`JSONURL`](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md#jsonurl) or [`ASSETURL`](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md#asseturl) data from IPFS, HTTP, or HTTPS endpoints.
The `fetchData` function fetches smart contract data and can additionally return [`VerifiableURI`](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md#verifiableuri) data from IPFS, HTTP, or HTTPS endpoints.

:::info

Expand All @@ -1032,9 +1032,9 @@ The name(s) (or the encoded name(s) as schema key) of the element(s) in the smar

#### Returns

| Name | Type | Description |
| :--- | :------------------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| data | `Promise<Array>` or <br/> `Promise<Object>` | An array with same objects as for [`decodeData()`](./ERC725#decodedata) function but with the value being remplaced by the actual file for `JSONURL` and `ASSETURL` valueContent. If there is a hash mismatch, the value will be `null`. |
| Name | Type | Description |
| :--- | :------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| data | `Promise<Array>` or <br/> `Promise<Object>` | An array with same objects as for [`decodeData()`](./ERC725#decodedata) function but with the value being remplaced by the actual file for `VerifiableURI` valueContent. If there is a hash mismatch, the value will be `null`. |

:::info

Expand Down Expand Up @@ -1162,8 +1162,7 @@ When omitting the `keys` parameter, it will give back every key (as per `ERC725J

:::caution

- Data returned by this function does not contain external data of [`JSONURL`](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md#jsonurl)
or [`ASSETURL`](https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md#asseturl) schema elements.
- Data returned by this function does not contain external data of [`VerifiableURI`](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md#verifiableuri) schema elements.
- If you would like to receive everything in one go, you can use [`fetchData`](ERC725.md#fetchdata).

:::
Expand Down Expand Up @@ -1455,7 +1454,7 @@ myErc725.getSchema(
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
valueType: 'bytes'
}
*/
Expand All @@ -1469,7 +1468,7 @@ myErc725.getSchema([
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
valueType: 'bytes'
},
'0x3a47ab5bd3a594c3a8995f8fa58d087600000000000000000000000000000001': {
Expand All @@ -1493,7 +1492,7 @@ myErc725.getSchema(
name: 'ParameterSchema',
key: '0x777f55baf2e0c9f73d3bb456dfb8dbf6e609bf557969e3184c17ff925b3c402c',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
valueType: 'bytes',
},
],
Expand All @@ -1503,7 +1502,7 @@ myErc725.getSchema(
name: 'ParameterSchema',
key: '0x777f55baf2e0c9f73d3bb456dfb8dbf6e609bf557969e3184c17ff925b3c402c',
keyType: 'Singleton',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
valueType: 'bytes',
}
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const schemas = [
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
},
{
name: 'LSP1UniversalReceiverDelegate',
Expand Down
6 changes: 3 additions & 3 deletions examples/src/decodeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const decodedDataOneKey = myERC725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
]);
/**
Expand All @@ -31,7 +31,7 @@ const decodedDataManyKeys = myERC725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'LSP3IssuedAssets[]',
Expand Down Expand Up @@ -76,7 +76,7 @@ const decodedDataManyKeys = myERC725.decodeData([
]
*/
console.log('/*--------------------------------------------/*');
console.log('/* decodeData - one key /*');
console.log('/* decodeData - one key (VerifiableURI) /*');
console.log('/*--------------------------------------------/*');
console.log(decodedDataOneKey);
console.log('/*--------------------------------------------/*');
Expand Down
4 changes: 2 additions & 2 deletions examples/src/encodeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const encodedDataOneKeyV2 = myERC725.encodeData({
'0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'
],
values: [
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178'
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178'
]
}
*/
Expand Down Expand Up @@ -76,7 +76,7 @@ const encodedDataManyKeys = myERC725.encodeData([
'0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47'
],
values: [
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x0000000000000000000000000000000000000000000000000000000000000002',
'0xd94353d9b005b3c0a9da169b768a31c57844e490',
'0xdaea594e385fc724449e3118b2db7e86dfba1826',
Expand Down
2 changes: 1 addition & 1 deletion schemas/LSP3ProfileMetadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"key": "0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5",
"keyType": "Singleton",
"valueType": "bytes",
"valueContent": "JSONURL"
"valueContent": "VerifiableURI"
},
{
"name": "LSP12IssuedAssets[]",
Expand Down
9 changes: 8 additions & 1 deletion schemas/LSP4DigitalAsset.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@
"valueType": "string",
"valueContent": "String"
},
{
"name": "LSP4TokenType",
"key": "0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3",
"keyType": "Singleton",
"valueType": "uint256",
"valueContent": "Number"
},
{
"name": "LSP4Metadata",
"key": "0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e",
"keyType": "Singleton",
"valueType": "bytes",
"valueContent": "JSONURL"
"valueContent": "VerifiableURI"
},
{
"name": "LSP4Creators[]",
Expand Down
15 changes: 4 additions & 11 deletions schemas/LSP8IdentifiableDigitalAsset.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
[
{
"name": "LSP8TokenIdType",
"key": "0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4",
"name": "LSP8TokenIdFormat",
"key": "0xf675e9361af1c1664c1868cfa3eb97672d6b1a513aa5b81dec34c9ee330e818d",
"keyType": "Singleton",
"valueType": "uint256",
"valueContent": "Number"
},
{
"name": "LSP8MetadataTokenURI:<address|uint256|bytes32|string>",
"key": "0x1339e76a390b7b9ec9010000<address|uint256|bytes32|string>",
"keyType": "Mapping",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
},
{
"name": "LSP8TokenMetadataBaseURI",
"key": "0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843",
"keyType": "Singleton",
"valueType": "(bytes4,string)",
"valueContent": "(Bytes4,URI)"
"valueType": "bytes",
"valueContent": "VerifiableURI"
},
{
"name": "LSP8ReferenceContract",
Expand Down
4 changes: 2 additions & 2 deletions src/constants/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const INTERFACE_IDS_0_12_0 = {
LSP1UniversalReceiver: '0x6bb56a14',
LSP1UniversalReceiverDelegate: '0xa245bbda',
LSP6KeyManager: '0x23f34c62',
LSP7DigitalAsset: '0xdaa746b7',
LSP8IdentifiableDigitalAsset: '0x30dc5278',
LSP7DigitalAsset: '0xb3c4928f',
LSP8IdentifiableDigitalAsset: '0x3a271706',
LSP9Vault: '0x28af17e6',
LSP11BasicSocialRecovery: '0x049a28f1',
LSP14Ownable2Step: '0x94be5999',
Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,23 @@ export class ERC725 {
// eslint-disable-next-line class-methods-use-this
private validateSchemas(schemas: ERC725JSONSchema[]) {
return schemas.filter((schema) => {
if (
schema.valueContent === 'AssetURL' ||
schema.valueContent === 'JSONURL'
) {
console.warn(
`[Deprecation notice] The schema with keyName: ${schema.name} uses deprecated valueContent: ${schema.valueContent}. It has been replaced by VerifiableURI. Decoding is backward compatible but value will be encoded as VerifiableURI.`,
);
}

try {
const encodedKeyName = encodeKeyName(schema.name);

const isKeyValid = schema.key === encodedKeyName;

if (!isKeyValid) {
console.log(
`The schema with keyName: ${schema.key} is skipped because its key hash does not match its key name (expected: ${encodedKeyName}, got: ${schema.key}).`,
console.warn(
`The schema with keyName: ${schema.name} is skipped because its key hash does not match its key name (expected: ${encodedKeyName}, got: ${schema.key}).`,
);
}

Expand Down
84 changes: 74 additions & 10 deletions src/lib/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,30 @@ describe('decodeData', () => {
{
name: 'MyKeyName:<bytes32>:<bool>',
key: '0x',
keyType: 'Singleton',
keyType: 'MappingWithGrouping',
valueType: 'bytes',
valueContent: 'JSONURL', // Deprecated - We keep it for backward compatibility between v0.21.3 and v0.22.0
},
{
name: 'MyKeyName2:<bytes32>:<bool>',
key: '0x',
keyType: 'MappingWithGrouping',
valueType: 'bytes',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
},
{
name: 'MyDynamicKey:<address>',
key: '0x',
keyType: 'Singleton',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'JSONURL', // Deprecated - We keep it for backward compatibility between v0.21.3 and v0.22.0
},
{
name: 'MyDynamicKey2:<address>',
key: '0x',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'JSONURL',
valueContent: 'VerifiableURI',
},
];

Expand All @@ -69,6 +83,56 @@ describe('decodeData', () => {
expect(decodedData.map(({ name }) => name)).to.eql(['KeyOne', 'KeyTwo']);
});

it('is backward compatible with JSONURL and AssetURL and decodes these encoding correctly', () => {
const decodedData = decodeData(
[
{
keyName: 'JSONURLCase',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361696670733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'AssetURLCase',
value:
'0x8019f9b1d47cf10786205bb08ce508e91c424d413d0f6c48e24dbfde2920d16a9561a723697066733a2f2f516d57346e554e7933767476723344785a48754c66534c6e687a4b4d6532576d67735573454750504668385a7470',
},
],
[
{
name: 'JSONURLCase',
key: '0x9136feeb09af67b63993b586ce46a43bd3456990d3fdb39d07beab9dee8d5910',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'JSONURL', // Deprecated - We keep it for backward compatibility between v0.21.3 and v0.22.0
},
{
name: 'AssetURLCase',
key: '0xbda5878fa57d8da097bf7cfd78c28e75f2c2c7b028e4e056d16d7e4b83f98081',
keyType: 'Singleton',
valueType: 'bytes',
valueContent: 'AssetURL', // Deprecated - We keep it for backward compatibility between v0.21.3 and v0.22.0
},
],
);

expect(decodedData.map(({ value }) => value)).to.eql([
{
verification: {
method: 'keccak256(utf8)', // 0x6f357c6a
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx',
},
{
verification: {
method: 'keccak256(bytes)', // 0x8019f9b1
data: '0xd47cf10786205bb08ce508e91c424d413d0f6c48e24dbfde2920d16a9561a723',
},
url: 'ipfs://QmW4nUNy3vtvr3DxZHuLfSLnhzKMe2WmgsUsEGPPFh8Ztp',
},
]);
});

it('parses non array input correctly', () => {
const decodedData = decodeData(
{
Expand Down Expand Up @@ -146,19 +210,19 @@ describe('decodeData', () => {
const decodedData = decodeData(
[
{
keyName: 'MyKeyName:<bytes32>:<bool>',
keyName: 'MyKeyName2:<bytes32>:<bool>',
dynamicKeyParts: [
'0xaaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa',
'true',
],
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'MyDynamicKey:<address>',
keyName: 'MyDynamicKey2:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'KeyTwo',
Expand All @@ -169,8 +233,8 @@ describe('decodeData', () => {
);

expect(decodedData.map(({ name }) => name)).to.eql([
'MyKeyName:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey:cafecafecafecafecafecafecafecafecafecafe',
'MyKeyName2:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey2:cafecafecafecafecafecafecafecafecafecafe',
'KeyTwo',
]);
});
Expand Down
Loading

0 comments on commit 3720b17

Please sign in to comment.