ERC725Alliance / erc725.js

Package to interact with ERC725 smart contracts
Apache License 2.0
38 stars 29 forks source link

`encodeData` should handle both named keys and hash keys #134

Closed Hugoo closed 2 years ago

Hugoo commented 2 years ago

Both should work the same:

const encodedDataOneKey = erc725.encodeData({
 '5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5': {
    json: profileJson, // check instantiation.js to see the actual JSON
    url: 'ifps://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
  },
});

/**
{
  keys [ '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
  values: [ '0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d']
}
*/
const encodedDataOneKey = erc725.encodeData({
 '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5': {
    json: profileJson, // check instantiation.js to see the actual JSON
    url: 'ifps://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
  },
});

/**
{
  keys [ '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
  values: [ '0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d']
}
*/
const encodedDataOneKey = erc725.encodeData({
  LSP3Profile: {
    json: profileJson, // check instantiation.js to see the actual JSON
    url: 'ifps://QmQTqheBLZFnQUxu5RDs8tA9JtkxfZqMBcmGd9sukXxwRm',
  },
});

/**
{
  keys [ '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'],
  values: [ '0x6f357c6a2404a2866f05e53e141eb61382a045e53c2fc54831daca9d9e1e039a11f739e1696670733a2f2f516d5154716865424c5a466e5155787535524473387441394a746b78665a714d42636d47643973756b587877526d']
}
*/

NOTE: The key can be used with and without 0x

Also update the documentation accordingly with examples

Hugoo commented 2 years ago

The PR: #143 is solving the "input" part - regarding the new shape of the output, it is covered by the issue: https://github.com/ERC725Alliance/erc725.js/issues/140