Skip to content

Commit

Permalink
fix: Rebase and merge support for VerifiableURL
Browse files Browse the repository at this point in the history
  • Loading branch information
richtera committed Dec 12, 2023
1 parent 8a02062 commit 44bfcc1
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 40 deletions.
117 changes: 116 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,122 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.21.3](https://github.com/ERC725Alliance/erc725.js/compare/v0.21.2...v0.21.3) (2023-11-29)


### Features

* add `encode/decodeValueType` as public callable methods ([#325](https://github.com/ERC725Alliance/erc725.js/issues/325)) ([a6fe7c8](https://github.com/ERC725Alliance/erc725.js/commit/a6fe7c8470688f573426b59fc2023a08da0cbd36))
* add more schemas available to parse via `getSchema` ([#351](https://github.com/ERC725Alliance/erc725.js/issues/351)) ([b882379](https://github.com/ERC725Alliance/erc725.js/commit/b8823796c5f99d89d56954c894dfb6964adc552a))
* add support for multi types in mappings ([#357](https://github.com/ERC725Alliance/erc725.js/issues/357)) ([ba92903](https://github.com/ERC725Alliance/erc725.js/commit/ba9290326efad0aab3855ad3f0ed2722180980ed))
* add support to encode / decode any `uint8` to `uint256` types ([#355](https://github.com/ERC725Alliance/erc725.js/issues/355)) ([417a4e8](https://github.com/ERC725Alliance/erc725.js/commit/417a4e8ff2c74f3f9e35d0018a4973c97c6ac997))
* allow to encode LSP2 Array length only ([#326](https://github.com/ERC725Alliance/erc725.js/issues/326)) ([3a6be55](https://github.com/ERC725Alliance/erc725.js/commit/3a6be551d889904b7d95e2630ab637f2a31feb50))


### Bug Fixes

* update lsp6 schema ([75c4044](https://github.com/ERC725Alliance/erc725.js/commit/75c40444e407d93076cc1e49ad706cc0055f383b))

## [0.21.2](https://github.com/ERC725Alliance/erc725.js/compare/v0.21.1...v0.21.2) (2023-11-07)


### Bug Fixes

* Add for unknown verification method to allow for null verification data in LSP2 ([f205818](https://github.com/ERC725Alliance/erc725.js/commit/f205818af348471bde8f88af2008497b8c13e258))
* Add more fixes per PR comments ([e7302e4](https://github.com/ERC725Alliance/erc725.js/commit/e7302e4504408e2f4f6304badd2024bfe05fcf47))
* Change to verification object ([ddd2ab2](https://github.com/ERC725Alliance/erc725.js/commit/ddd2ab23d1c5181745827f338d9abaea48c772f7))
* More renames _FUNCTIONS to _METHODS ([1a96be1](https://github.com/ERC725Alliance/erc725.js/commit/1a96be1dd15942d2a844bc26b9ab73e053e3b766))
* Move @types/jest and jest ([852918c](https://github.com/ERC725Alliance/erc725.js/commit/852918c72228b3839ba60730dadef66837008f5a))

## [0.21.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.21.0...v0.21.1) (2023-11-06)


### Bug Fixes

* incorrect hex for `LSP8MetadataTokenURI` ([0500a75](https://github.com/ERC725Alliance/erc725.js/commit/0500a752e3117c5c7e9df8cfed22cb5d6fee20c5))

## [0.21.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.20.1...v0.21.0) (2023-11-02)


### ⚠ BREAKING CHANGES

* update lsp3/lsp4 verificationData

### Features

* new gas parameter ([82e3833](https://github.com/ERC725Alliance/erc725.js/commit/82e383345a712619b5c6a1030b124d2625115fc1))


### Code Refactoring

* update lsp3/lsp4 verificationData ([9640d9f](https://github.com/ERC725Alliance/erc725.js/commit/9640d9fbf88c7cf694b9e82cc3a711350334b097))

## [0.20.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.20.0...v0.20.1) (2023-10-30)


### Bug Fixes

* incorrect permission value for `EXECUTE_RELAY_CALL` ([55b8f5e](https://github.com/ERC725Alliance/erc725.js/commit/55b8f5e64c29c5a85d872f605667c88c1546f6b3))

## [0.20.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.19.0...v0.20.0) (2023-10-18)


### Features

* add permission `EXECUTE_RELAY_CALL` ([6db8835](https://github.com/ERC725Alliance/erc725.js/commit/6db8835ccd9d1082d9e8184bb2f14972760bea69))

## [0.19.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.18.0...v0.19.0) (2023-10-05)


### ⚠ BREAKING CHANGES

* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307))
* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288))
* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287))

### Features

* add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3))
* add schemas for LSP8 + LSP17 ([#311](https://github.com/ERC725Alliance/erc725.js/issues/311)) ([1e8dbf7](https://github.com/ERC725Alliance/erc725.js/commit/1e8dbf765c6c5e250539b402e9bd5a395966a8c2))


### Bug Fixes

* decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540))
* dependencies & example ([#302](https://github.com/ERC725Alliance/erc725.js/issues/302)) ([9979e89](https://github.com/ERC725Alliance/erc725.js/commit/9979e89e438cd9f7cc586d7dc271de969f13b125))
* incorrect value in schema for array length in `...Map` ([#310](https://github.com/ERC725Alliance/erc725.js/issues/310)) ([0d28b13](https://github.com/ERC725Alliance/erc725.js/commit/0d28b1317dc085078090a8babacf4db517d91a87))
* Remove hardcoded require ([5279278](https://github.com/ERC725Alliance/erc725.js/commit/527927812b1a05b13f8dc6b14aecaa6d24e98d61))
* variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f))


### Code Refactoring

* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f))
* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307)) ([73f3481](https://github.com/ERC725Alliance/erc725.js/commit/73f34818fe152c3ab5299177adc0eddfed6886c5))
* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce))

## [0.18.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.2...v0.18.0) (2023-08-03)

### ⚠ BREAKING CHANGES

- new encoding for static value types (not arrays `[]`) (#288)
- change `ArrayLength` value from `uint256` to `uint128` (#287)

### Features

- add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3))
- Add new feature "Decode Mapping Key" ([8c1f1fc](https://github.com/ERC725Alliance/erc725.js/commit/8c1f1fcfb15fa43d1d3934b0b15f09d47902bb41))

### Bug Fixes

- decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540))
- variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f))

### improvement

- change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f))
- new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce))

### [0.17.2](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.1...v0.17.2) (2023-03-14)

- removed ERC725JSONSchemaKeyType duplicate value ([060ee6c](https://github.com/ERC725Alliance/erc725.js/commit/060ee6ce23bda328f727140419de7590f48fc394))
Expand Down Expand Up @@ -103,7 +219,6 @@ Minor update to update the LSP-2 schemas.

### improvement

- change fetchData output to non object ([1d4d570](https://github.com/ERC725Alliance/erc725.js/commit/1d4d57077a7766b3490477efb20f194fc4e00da4))
- fetchData as same output as decodeData ([59c3a87](https://github.com/ERC725Alliance/erc725.js/commit/59c3a879fefb2b9bfe46b9bea91ff6bd2a528df1))
- getData as same output as decodeData ([0f3b149](https://github.com/ERC725Alliance/erc725.js/commit/0f3b149f2280e6025a05e8e9ed306facfa63601a))
- use array for decodeData ([261d100](https://github.com/ERC725Alliance/erc725.js/commit/261d1007f4ff63abd9d794f4e64e5b408ce7c1a3))
Expand Down
31 changes: 29 additions & 2 deletions examples/src/decodeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import { getInstance } from './instantiation.js';
const myERC725 = getInstance();

const decodedDataOneKey = myERC725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
]);
/**
[
{
name: 'LSP3Profile',
key: '0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5',
value: {
verification: {
method: 'keccak256(utf8)',
data: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361',
},
url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx'
}
}
]
*/

const decodedDataOneKeyOld = myERC725.decodeData([
{
keyName: 'LSP3Profile',
value:
Expand All @@ -31,7 +54,7 @@ const decodedDataManyKeys = myERC725.decodeData([
{
keyName: 'LSP3Profile',
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'LSP3IssuedAssets[]',
Expand Down Expand Up @@ -76,10 +99,14 @@ const decodedDataManyKeys = myERC725.decodeData([
]
*/
console.log('/*--------------------------------------------/*');
console.log('/* decodeData - one key /*');
console.log('/* decodeData - one key (VerifiableURL) /*');
console.log('/*--------------------------------------------/*');
console.log(decodedDataOneKey);
console.log('/*--------------------------------------------/*');
console.log('/* decodeData - one key (JSONURL) /*');
console.log('/*--------------------------------------------/*');
console.log(decodedDataOneKeyOld);
console.log('/*--------------------------------------------/*');
console.log('/* decodeData - many keys /*');
console.log('/*--------------------------------------------/*');
console.log(decodedDataManyKeys);
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
35 changes: 33 additions & 2 deletions src/lib/decodeData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,31 @@ describe('decodeData', () => {
{
name: 'MyKeyName:<bytes32>:<bool>',
key: '0x',
keyType: 'Singleton',
keyType: 'MappingWithGrouping',
valueType: 'bytes',
valueContent: 'JSONURL',
},
{
name: 'MyKeyName2:<bytes32>:<bool>',
key: '0x',
keyType: 'MappingWithGrouping',
valueType: 'bytes',
valueContent: 'VerifiableURL',
},
{
name: 'MyDynamicKey:<address>',
key: '0x',
keyType: 'Singleton',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'JSONURL',
},
{
name: 'MyDynamicKey2:<address>',
key: '0x',
keyType: 'Mapping',
valueType: 'bytes',
valueContent: 'VerifiableURL',
},
];

it('decodes each key', () => {
Expand Down Expand Up @@ -160,6 +174,21 @@ describe('decodeData', () => {
value:
'0x6f357c6a820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'MyKeyName2:<bytes32>:<bool>',
dynamicKeyParts: [
'0xaaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa',
'true',
],
value:
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'MyDynamicKey2:<address>',
dynamicKeyParts: '0xcafecafecafecafecafecafecafecafecafecafe',
value:
'0x00006f357c6a0020820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361697066733a2f2f516d597231564a4c776572673670456f73636468564775676f3339706136727963455a4c6a7452504466573834554178',
},
{
keyName: 'KeyTwo',
value: '0x2222',
Expand All @@ -171,6 +200,8 @@ describe('decodeData', () => {
expect(decodedData.map(({ name }) => name)).to.eql([
'MyKeyName:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey:cafecafecafecafecafecafecafecafecafecafe',
'MyKeyName2:aaaabbbbccccddddeeeeffff111122223333444455556666777788889999aaaa:true',
'MyDynamicKey2:cafecafecafecafecafecafecafecafecafecafe',
'KeyTwo',
]);
});
Expand Down
15 changes: 12 additions & 3 deletions src/lib/encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

import { expect, assert } from 'chai';

import { keccak256, utf8ToHex, stripHexPrefix, toBN, toHex } from 'web3-utils';
import {
keccak256,
utf8ToHex,
stripHexPrefix,
toBN,
toHex,
padLeft,
} from 'web3-utils';
import {
valueContentEncodingMap,
encodeValueType,
Expand Down Expand Up @@ -899,7 +906,7 @@ describe('encoder', () => {
url: 'http://test.com/asset.glb',
},
encodedValue:
'0x6f357c6a027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d16168687474703a2f2f746573742e636f6d2f61737365742e676c62',
'0x00006f357c6a0020027547537d35728a741470df1ccf65de10b454ca0def7c5c20b257b7b8d16168687474703a2f2f746573742e636f6d2f61737365742e676c62',
},
{
valueContent: 'BitArray',
Expand Down Expand Up @@ -959,7 +966,9 @@ describe('encoder', () => {
).substring(2);
assert.deepStrictEqual(
encodedValue,
verificationMethod + jsonVerificationData + hexUrl,
`0x0000${stripHexPrefix(verificationMethod)}${stripHexPrefix(
padLeft(jsonVerificationData.length / 2, 4),
)}${jsonVerificationData}${hexUrl}`,
);

const expectedDecodedValue: URLDataWithHash = {
Expand Down
58 changes: 47 additions & 11 deletions src/lib/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,58 @@ const encodeDataSourceWithHash = (
const verificationMethod = getVerificationMethod(
verification?.method || UNKNOWN_VERIFICATION_METHOD,
);
return (
(verificationMethod
? keccak256(verificationMethod.name).slice(0, 10)
: padLeft(0, 8)) +
stripHexPrefix(verification ? verification.data : padLeft(0, 64)) +
stripHexPrefix(utf8ToHex(dataSource))
);
return [
padLeft(0, 4),
stripHexPrefix(
verificationMethod
? padLeft(keccak256(verificationMethod.name).slice(0, 10), 8)
: padLeft(0, 8),
),
stripHexPrefix(
verification?.data
? padLeft(verification.data.slice(2).length / 2, 4)
: padLeft(0, 4),
),
stripHexPrefix(
verification?.data ? stripHexPrefix(verification?.data) : '',
),
stripHexPrefix(utf8ToHex(dataSource)),
].join('');
};

const decodeDataSourceWithHash = (value: string): URLDataWithHash => {
if (value.slice(0, 6) === '0x0000') {
/*
0 1 2 3 4 5 6 7 8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
0x0000 code
6f357c6a hash fn [6]
0020 data len [14]
820464ddfac1be...[18 + data len]
[18 + data len]...696670733a2f2...[...rest]
*/
const verificationMethodSig = `0x${value.slice(6, 14)}`;
const verificationMethod = getVerificationMethod(verificationMethodSig);
if (verificationMethod !== undefined) {
const encodedLength = `0x${value.slice(14, 18)}`; // Rest of data string after function hash
const dataLength = hexToNumber(encodedLength, false) as number;
const dataHash = `0x${value.slice(18, 18 + dataLength * 2)}`; // Get jsonHash 32 bytes
const dataSource = hexToUtf8('0x' + value.slice(18 + dataLength * 2)); // Get remainder as URI
return {
verification: {
method: verificationMethod.name,
data: dataHash,
},
url: dataSource,
};
}
}

const verificationMethodSig = value.slice(0, 10);
const verificationMethod = getVerificationMethod(verificationMethodSig);

const encodedData = value.replace('0x', '').slice(8); // Rest of data string after function hash
const encodedData = value.slice(10); // Rest of data string after function hash
const dataHash = '0x' + encodedData.slice(0, 64); // Get jsonHash 32 bytes
const dataSource = hexToUtf8('0x' + encodedData.slice(64)); // Get remainder as URI

return {
verification: {
method: verificationMethod?.name || UNKNOWN_VERIFICATION_METHOD,
Expand Down Expand Up @@ -648,7 +683,8 @@ export const valueContentEncodingMap = (
};
}
// https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md#jsonurl
case 'JSONURL': {
case 'JSONURL':
case 'VerifiableURL': {
return {
type: 'custom',
encode: (dataToEncode: JSONURLDataToEncode) => {
Expand Down
Loading

0 comments on commit 44bfcc1

Please sign in to comment.