diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d0d7e9a..e7b4e61d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,166 +4,149 @@ All notable changes to this project will be documented in this file. See [standa ## [0.24.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.23.1...v0.24.0) (2024-04-02) - ### Features -* add dynamic array encoding ([f0f495c](https://github.com/ERC725Alliance/erc725.js/commit/f0f495c69e8b4768468437cad24f1b77d53a379f)) -* replace dynamic part with hex value when parsing schemas for `Mapping` keys ([a9fdb4d](https://github.com/ERC725Alliance/erc725.js/commit/a9fdb4daa69e2aac38aca2393f94e8fe83113656)) - +- add dynamic array encoding ([f0f495c](https://github.com/ERC725Alliance/erc725.js/commit/f0f495c69e8b4768468437cad24f1b77d53a379f)) +- replace dynamic part with hex value when parsing schemas for `Mapping` keys ([a9fdb4d](https://github.com/ERC725Alliance/erc725.js/commit/a9fdb4daa69e2aac38aca2393f94e8fe83113656)) ### Bug Fixes -* Patch full pretty printed with LF and TAB. ([315fa54](https://github.com/ERC725Alliance/erc725.js/commit/315fa547ab8f2d25db4f771d818afeec0d324bdf)) +- Patch full pretty printed with LF and TAB. ([315fa54](https://github.com/ERC725Alliance/erc725.js/commit/315fa547ab8f2d25db4f771d818afeec0d324bdf)) ## [0.23.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.23.0...v0.23.1) (2024-02-23) - ### Bug Fixes -* Add check for pretty printed and non-pretty printed versions of JSON ([aa68bf1](https://github.com/ERC725Alliance/erc725.js/commit/aa68bf132d2e4793b4da784c30ae8f306560da8c)) -* Missing line ([d13be00](https://github.com/ERC725Alliance/erc725.js/commit/d13be00ba77be924f914cba1283e9c37250ec9bd)) -* Re-do PR with minimal changes ([17458d6](https://github.com/ERC725Alliance/erc725.js/commit/17458d623f214f026307184357bcf7ff75fad7ed)) -* Repair package-lock to be just as on main ([e793246](https://github.com/ERC725Alliance/erc725.js/commit/e793246e7e09bd80628f19499a5218ce70df8401)) +- Add check for pretty printed and non-pretty printed versions of JSON ([aa68bf1](https://github.com/ERC725Alliance/erc725.js/commit/aa68bf132d2e4793b4da784c30ae8f306560da8c)) +- Missing line ([d13be00](https://github.com/ERC725Alliance/erc725.js/commit/d13be00ba77be924f914cba1283e9c37250ec9bd)) +- Re-do PR with minimal changes ([17458d6](https://github.com/ERC725Alliance/erc725.js/commit/17458d623f214f026307184357bcf7ff75fad7ed)) +- Repair package-lock to be just as on main ([e793246](https://github.com/ERC725Alliance/erc725.js/commit/e793246e7e09bd80628f19499a5218ce70df8401)) ## [0.23.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.22.0...v0.23.0) (2024-01-22) - ### Features -* add permission related to 4337 ([e7fd19b](https://github.com/ERC725Alliance/erc725.js/commit/e7fd19bc27aa89fae410b9633ef5ccdf13f33f0e)) -* allow to load typed schemas from `schemas/` folder ([c54a370](https://github.com/ERC725Alliance/erc725.js/commit/c54a370c1e4f8d71ba6bb7e62122b89069f521e6)) - +- add permission related to 4337 ([e7fd19b](https://github.com/ERC725Alliance/erc725.js/commit/e7fd19bc27aa89fae410b9633ef5ccdf13f33f0e)) +- allow to load typed schemas from `schemas/` folder ([c54a370](https://github.com/ERC725Alliance/erc725.js/commit/c54a370c1e4f8d71ba6bb7e62122b89069f521e6)) ### Bug Fixes -* Add workaround to read (bytes4,URI), repair none vs unknown signature. ([204409d](https://github.com/ERC725Alliance/erc725.js/commit/204409df544825041a586865cfb6bb124288e48f)) -* Additional PR repair ([2a18f2b](https://github.com/ERC725Alliance/erc725.js/commit/2a18f2bf1a24547e71cad6953f5144761aa2cc9a)) -* BodyInit should be just string or buffer and not already Uint8Array ([08e0177](https://github.com/ERC725Alliance/erc725.js/commit/08e017778fa42ade5386b8d9e85255225a7f3195)) -* Cleanup ([038d975](https://github.com/ERC725Alliance/erc725.js/commit/038d97584075c89f93f51227666074cf11973a29)) -* Cleanup a bit with comments. ([3d6a5a6](https://github.com/ERC725Alliance/erc725.js/commit/3d6a5a65db5049b678d0d54149e9b11ea2479999)) -* Cleanup and handle situation where one of many keys fails. Return null. ([cdf4583](https://github.com/ERC725Alliance/erc725.js/commit/cdf4583c159d8c8e52a832bfe5af6b650d8945fa)) -* Cleanup error handler inside of getDataFromExternalSources ([fde2e0f](https://github.com/ERC725Alliance/erc725.js/commit/fde2e0f41df3ecee90a4dfd8248dd9c2a7a72965)) -* Debug and repair test scripts. Implement detecting of JSON inside of Uint8Array ([74c0526](https://github.com/ERC725Alliance/erc725.js/commit/74c0526e3f544400ced78f02ff4fed64bd048bfa)) -* Missing commit ([a3dd604](https://github.com/ERC725Alliance/erc725.js/commit/a3dd604964c9c9221ff421fe668faa8fd363101a)) -* More fixes ([620b606](https://github.com/ERC725Alliance/erc725.js/commit/620b60632e50ca59abedae9935f8b75d188278e0)) -* Remove .only call for testing. ([d5ef3c9](https://github.com/ERC725Alliance/erc725.js/commit/d5ef3c9965e2c5ad343f88a9c30a6281e9fa169b)) -* Remove console debugging. ([e349d57](https://github.com/ERC725Alliance/erc725.js/commit/e349d5715c7779c1eeb8d6e08c3ae3bf17eedd9e)) -* Remove unnecessary special case for 0x00000000 ([cd6152a](https://github.com/ERC725Alliance/erc725.js/commit/cd6152a88ca7a1c98184799b6fdc6982ff8a1cd6)) -* Repair and enhance test scripts ([224eb9e](https://github.com/ERC725Alliance/erc725.js/commit/224eb9ecb1b16f373f2ad17ee9d3efab08dda53b)) -* Repair as per PR review ([0a52452](https://github.com/ERC725Alliance/erc725.js/commit/0a5245230455324e9911e4e14992c50e6f645ba2)) -* Repair console.log and expand types of URLs (ar://, ipfs://, https\?://, data:) ([5c8f228](https://github.com/ERC725Alliance/erc725.js/commit/5c8f2285d2d23c59ef9707a54e419b55d25e4136)) -* Repair problems with IPFS, fetch and VerifiableURI ([44834b8](https://github.com/ERC725Alliance/erc725.js/commit/44834b8ed517e869ad99920b2853e30213a8d7b5)) -* Repair to not throw errors when data is not authentica or not accessible withing getDataFromExternalSources. ([25756d0](https://github.com/ERC725Alliance/erc725.js/commit/25756d09cecfec5d13d6e4fb6ed842c4e3d77734)) -* Repair tuples containing numeric types uintX/intX, add Number to output data type. ([01cceea](https://github.com/ERC725Alliance/erc725.js/commit/01cceeac03f719df6eb8be8c238aca4483e7a3e8)) -* Simplify buffer to string conversion. ([0bd1349](https://github.com/ERC725Alliance/erc725.js/commit/0bd1349f863283cf16cc6808bef48990ec118361)) -* Simplify creation of key to detect JSON. ([df2580d](https://github.com/ERC725Alliance/erc725.js/commit/df2580d9434dc386480f7eec2cd6e94a5b4ca7c1)) -* Use a single keccak function since ethereumjs converts it to a Buffer no matter what. ([cdc6c0a](https://github.com/ERC725Alliance/erc725.js/commit/cdc6c0a0f749209352d620db6d60865a276e072c)) +- Add workaround to read (bytes4,URI), repair none vs unknown signature. ([204409d](https://github.com/ERC725Alliance/erc725.js/commit/204409df544825041a586865cfb6bb124288e48f)) +- Additional PR repair ([2a18f2b](https://github.com/ERC725Alliance/erc725.js/commit/2a18f2bf1a24547e71cad6953f5144761aa2cc9a)) +- BodyInit should be just string or buffer and not already Uint8Array ([08e0177](https://github.com/ERC725Alliance/erc725.js/commit/08e017778fa42ade5386b8d9e85255225a7f3195)) +- Cleanup ([038d975](https://github.com/ERC725Alliance/erc725.js/commit/038d97584075c89f93f51227666074cf11973a29)) +- Cleanup a bit with comments. ([3d6a5a6](https://github.com/ERC725Alliance/erc725.js/commit/3d6a5a65db5049b678d0d54149e9b11ea2479999)) +- Cleanup and handle situation where one of many keys fails. Return null. ([cdf4583](https://github.com/ERC725Alliance/erc725.js/commit/cdf4583c159d8c8e52a832bfe5af6b650d8945fa)) +- Cleanup error handler inside of getDataFromExternalSources ([fde2e0f](https://github.com/ERC725Alliance/erc725.js/commit/fde2e0f41df3ecee90a4dfd8248dd9c2a7a72965)) +- Debug and repair test scripts. Implement detecting of JSON inside of Uint8Array ([74c0526](https://github.com/ERC725Alliance/erc725.js/commit/74c0526e3f544400ced78f02ff4fed64bd048bfa)) +- Missing commit ([a3dd604](https://github.com/ERC725Alliance/erc725.js/commit/a3dd604964c9c9221ff421fe668faa8fd363101a)) +- More fixes ([620b606](https://github.com/ERC725Alliance/erc725.js/commit/620b60632e50ca59abedae9935f8b75d188278e0)) +- Remove .only call for testing. ([d5ef3c9](https://github.com/ERC725Alliance/erc725.js/commit/d5ef3c9965e2c5ad343f88a9c30a6281e9fa169b)) +- Remove console debugging. ([e349d57](https://github.com/ERC725Alliance/erc725.js/commit/e349d5715c7779c1eeb8d6e08c3ae3bf17eedd9e)) +- Remove unnecessary special case for 0x00000000 ([cd6152a](https://github.com/ERC725Alliance/erc725.js/commit/cd6152a88ca7a1c98184799b6fdc6982ff8a1cd6)) +- Repair and enhance test scripts ([224eb9e](https://github.com/ERC725Alliance/erc725.js/commit/224eb9ecb1b16f373f2ad17ee9d3efab08dda53b)) +- Repair as per PR review ([0a52452](https://github.com/ERC725Alliance/erc725.js/commit/0a5245230455324e9911e4e14992c50e6f645ba2)) +- Repair console.log and expand types of URLs (ar://, ipfs://, https\?://, data:) ([5c8f228](https://github.com/ERC725Alliance/erc725.js/commit/5c8f2285d2d23c59ef9707a54e419b55d25e4136)) +- Repair problems with IPFS, fetch and VerifiableURI ([44834b8](https://github.com/ERC725Alliance/erc725.js/commit/44834b8ed517e869ad99920b2853e30213a8d7b5)) +- Repair to not throw errors when data is not authentica or not accessible withing getDataFromExternalSources. ([25756d0](https://github.com/ERC725Alliance/erc725.js/commit/25756d09cecfec5d13d6e4fb6ed842c4e3d77734)) +- Repair tuples containing numeric types uintX/intX, add Number to output data type. ([01cceea](https://github.com/ERC725Alliance/erc725.js/commit/01cceeac03f719df6eb8be8c238aca4483e7a3e8)) +- Simplify buffer to string conversion. ([0bd1349](https://github.com/ERC725Alliance/erc725.js/commit/0bd1349f863283cf16cc6808bef48990ec118361)) +- Simplify creation of key to detect JSON. ([df2580d](https://github.com/ERC725Alliance/erc725.js/commit/df2580d9434dc386480f7eec2cd6e94a5b4ca7c1)) +- Use a single keccak function since ethereumjs converts it to a Buffer no matter what. ([cdc6c0a](https://github.com/ERC725Alliance/erc725.js/commit/cdc6c0a0f749209352d620db6d60865a276e072c)) ## [0.22.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.21.3...v0.22.0) (2023-12-15) - ### ⚠ BREAKING CHANGES -* update new LSP7/8 interface IDs ([#367](https://github.com/ERC725Alliance/erc725.js/issues/367)) -* `JSONURL` and `AssetURL` are now deprecated and have been replaced by `VerifiableURI`. The decoding is backward compatible but if you try to encode `JSONURL` and `AssetURL` value, they will be encoded as [`VerifiableURI`](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md#verifiableuri). ([9aa87e5](https://github.com/ERC725Alliance/erc725.js/commit/9aa87e5ccc0fb1caac1f3291387370b3a980324b)) +- update new LSP7/8 interface IDs ([#367](https://github.com/ERC725Alliance/erc725.js/issues/367)) +- `JSONURL` and `AssetURL` are now deprecated and have been replaced by `VerifiableURI`. The decoding is backward compatible but if you try to encode `JSONURL` and `AssetURL` value, they will be encoded as [`VerifiableURI`](https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-2-ERC725YJSONSchema.md#verifiableuri). ([9aa87e5](https://github.com/ERC725Alliance/erc725.js/commit/9aa87e5ccc0fb1caac1f3291387370b3a980324b)) ### Bug Fixes -* Rename JSONURLDataToEncode ([808f1b3](https://github.com/ERC725Alliance/erc725.js/commit/808f1b362bd2275424cf93ac6333049cde90216e)) +- Rename JSONURLDataToEncode ([808f1b3](https://github.com/ERC725Alliance/erc725.js/commit/808f1b362bd2275424cf93ac6333049cde90216e)) ## [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)) - +- 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)) +- 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)) +- 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)) +- 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 +- update lsp3/lsp4 verificationData ### Features -* new gas parameter ([82e3833](https://github.com/ERC725Alliance/erc725.js/commit/82e383345a712619b5c6a1030b124d2625115fc1)) - +- 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)) +- 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)) +- 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)) +- 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)) +- 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)) - +- 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)) - +- 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)) +- 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) diff --git a/biome.json b/biome.json index 2a97f8ec..d274c243 100644 --- a/biome.json +++ b/biome.json @@ -7,8 +7,29 @@ "noExplicitAny": "off" }, "style": { - "useImportType": "off" + "useImportType": "off", + "useNodejsImportProtocol": "off" + }, + "complexity": { + "noForEach": "off" } } + }, + "formatter": { + "indentWidth": 2, + "indentStyle": "space" + }, + "javascript": { + "formatter": { + "semicolons": "always", + "quoteStyle": "single", + "trailingComma": "all" + } + }, + "organizeImports": { + "enabled": false + }, + "files": { + "ignore": ["node_modules", "build", "coverage", ".vscode"] } } diff --git a/package-lock.json b/package-lock.json index d67c5414..8070ac83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "web3-utils": "^1.10.0" }, "devDependencies": { + "@biomejs/biome": "^1.6.4", "@types/chai": "^4.3.4", "@types/isomorphic-fetch": "^0.0.36", "@types/jest": "^27.5.2", @@ -708,6 +709,161 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@biomejs/biome": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.6.4.tgz", + "integrity": "sha512-3groVd2oWsLC0ZU+XXgHSNbq31lUcOCBkCcA7sAQGBopHcmL+jmmdoWlY3S61zIh+f2mqQTQte1g6PZKb3JJjA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.6.4", + "@biomejs/cli-darwin-x64": "1.6.4", + "@biomejs/cli-linux-arm64": "1.6.4", + "@biomejs/cli-linux-arm64-musl": "1.6.4", + "@biomejs/cli-linux-x64": "1.6.4", + "@biomejs/cli-linux-x64-musl": "1.6.4", + "@biomejs/cli-win32-arm64": "1.6.4", + "@biomejs/cli-win32-x64": "1.6.4" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.6.4.tgz", + "integrity": "sha512-2WZef8byI9NRzGajGj5RTrroW9BxtfbP9etigW1QGAtwu/6+cLkdPOWRAs7uFtaxBNiKFYA8j/BxV5zeAo5QOQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.6.4.tgz", + "integrity": "sha512-uo1zgM7jvzcoDpF6dbGizejDLCqNpUIRkCj/oEK0PB0NUw8re/cn1EnxuOLZqDpn+8G75COLQTOx8UQIBBN/Kg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.6.4.tgz", + "integrity": "sha512-wAOieaMNIpLrxGc2/xNvM//CIZg7ueWy3V5A4T7gDZ3OL/Go27EKE59a+vMKsBCYmTt7jFl4yHz0TUkUbodA/w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.6.4.tgz", + "integrity": "sha512-Hp8Jwt6rjj0wCcYAEN6/cfwrrPLLlGOXZ56Lei4Pt4jy39+UuPeAVFPeclrrCfxyL1wQ2xPrhd/saTHSL6DoJg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.6.4.tgz", + "integrity": "sha512-qTWhuIw+/ePvOkjE9Zxf5OqSCYxtAvcTJtVmZT8YQnmY2I62JKNV2m7tf6O5ViKZUOP0mOQ6NgqHKcHH1eT8jw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.6.4.tgz", + "integrity": "sha512-wqi0hr8KAx5kBO0B+m5u8QqiYFFBJOSJVSuRqTeGWW+GYLVUtXNidykNqf1JsW6jJDpbkSp2xHKE/bTlVaG2Kg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.6.4.tgz", + "integrity": "sha512-Wp3FiEeF6v6C5qMfLkHwf4YsoNHr/n0efvoC8jCKO/kX05OXaVExj+1uVQ1eGT7Pvx0XVm/TLprRO0vq/V6UzA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.6.4.tgz", + "integrity": "sha512-mz183Di5hTSGP7KjNWEhivcP1wnHLGmOxEROvoFsIxMYtDhzJDad4k5gI/1JbmA0xe4n52vsgqo09tBhrMT/Zg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", @@ -13869,6 +14025,78 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "@biomejs/biome": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.6.4.tgz", + "integrity": "sha512-3groVd2oWsLC0ZU+XXgHSNbq31lUcOCBkCcA7sAQGBopHcmL+jmmdoWlY3S61zIh+f2mqQTQte1g6PZKb3JJjA==", + "dev": true, + "requires": { + "@biomejs/cli-darwin-arm64": "1.6.4", + "@biomejs/cli-darwin-x64": "1.6.4", + "@biomejs/cli-linux-arm64": "1.6.4", + "@biomejs/cli-linux-arm64-musl": "1.6.4", + "@biomejs/cli-linux-x64": "1.6.4", + "@biomejs/cli-linux-x64-musl": "1.6.4", + "@biomejs/cli-win32-arm64": "1.6.4", + "@biomejs/cli-win32-x64": "1.6.4" + } + }, + "@biomejs/cli-darwin-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.6.4.tgz", + "integrity": "sha512-2WZef8byI9NRzGajGj5RTrroW9BxtfbP9etigW1QGAtwu/6+cLkdPOWRAs7uFtaxBNiKFYA8j/BxV5zeAo5QOQ==", + "dev": true, + "optional": true + }, + "@biomejs/cli-darwin-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.6.4.tgz", + "integrity": "sha512-uo1zgM7jvzcoDpF6dbGizejDLCqNpUIRkCj/oEK0PB0NUw8re/cn1EnxuOLZqDpn+8G75COLQTOx8UQIBBN/Kg==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.6.4.tgz", + "integrity": "sha512-wAOieaMNIpLrxGc2/xNvM//CIZg7ueWy3V5A4T7gDZ3OL/Go27EKE59a+vMKsBCYmTt7jFl4yHz0TUkUbodA/w==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-arm64-musl": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.6.4.tgz", + "integrity": "sha512-Hp8Jwt6rjj0wCcYAEN6/cfwrrPLLlGOXZ56Lei4Pt4jy39+UuPeAVFPeclrrCfxyL1wQ2xPrhd/saTHSL6DoJg==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.6.4.tgz", + "integrity": "sha512-qTWhuIw+/ePvOkjE9Zxf5OqSCYxtAvcTJtVmZT8YQnmY2I62JKNV2m7tf6O5ViKZUOP0mOQ6NgqHKcHH1eT8jw==", + "dev": true, + "optional": true + }, + "@biomejs/cli-linux-x64-musl": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.6.4.tgz", + "integrity": "sha512-wqi0hr8KAx5kBO0B+m5u8QqiYFFBJOSJVSuRqTeGWW+GYLVUtXNidykNqf1JsW6jJDpbkSp2xHKE/bTlVaG2Kg==", + "dev": true, + "optional": true + }, + "@biomejs/cli-win32-arm64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.6.4.tgz", + "integrity": "sha512-Wp3FiEeF6v6C5qMfLkHwf4YsoNHr/n0efvoC8jCKO/kX05OXaVExj+1uVQ1eGT7Pvx0XVm/TLprRO0vq/V6UzA==", + "dev": true, + "optional": true + }, + "@biomejs/cli-win32-x64": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.6.4.tgz", + "integrity": "sha512-mz183Di5hTSGP7KjNWEhivcP1wnHLGmOxEROvoFsIxMYtDhzJDad4k5gI/1JbmA0xe4n52vsgqo09tBhrMT/Zg==", + "dev": true, + "optional": true + }, "@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index dc7ba660..6ac2cc9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.24.0", + "version": "0.24.1-dev.5", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", @@ -16,6 +16,8 @@ "build:module": "tsc -p tsconfig.module.json", "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=text --reporter=lcov mocha", "lint": "eslint . --ext .ts", + "format:fix": "prettier --write .", + "format": "prettier .", "release": "standard-version" }, "repository": { @@ -51,6 +53,7 @@ }, "homepage": "https://github.com/ERC725Alliance/erc725.js#readme", "devDependencies": { + "@biomejs/biome": "^1.6.4", "@types/chai": "^4.3.4", "@types/isomorphic-fetch": "^0.0.36", "@types/jest": "^27.5.2", diff --git a/src/index.test.ts b/src/index.test.ts index db99edaf..d5358bcd 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -27,7 +27,14 @@ import { hexToNumber, leftPad, numberToHex } from 'web3-utils'; // examples of schemas to load (for testing) import { LSP1Schema, LSP12Schema, LSP3Schema, LSP6Schema } from './schemas'; -import ERC725 from '.'; +import ERC725, { + checkPermissions, + decodeMappingKey, + decodePermissions, + encodeKeyName, + encodePermissions, + supportsInterface, +} from '.'; import { decodeKeyValue, encodeKey, @@ -988,9 +995,9 @@ describe('Running @erc725/erc725.js tests...', () => { values: [], }; - keyValuePairs.forEach((keyValuePair) => { - intendedResult.keys.push(keyValuePair.key); - intendedResult.values.push(keyValuePair.value); + keyValuePairs.forEach(({ key, value }) => { + intendedResult.keys.push(key); + intendedResult.values.push(value); }); const erc725 = new ERC725([schemaElement]); @@ -1394,7 +1401,7 @@ describe('Running @erc725/erc725.js tests...', () => { testCases.forEach((testCase) => { it(`Encodes ${testCase.hex} permission correctly`, () => { assert.deepStrictEqual( - ERC725.encodePermissions(testCase.permissions), + encodePermissions(testCase.permissions), testCase.hex, ); assert.deepStrictEqual( @@ -1406,7 +1413,7 @@ describe('Running @erc725/erc725.js tests...', () => { it('Defaults permissions to false if not passed', () => { assert.deepStrictEqual( - ERC725.encodePermissions({ + encodePermissions({ EDITPERMISSIONS: true, SETDATA: true, }), @@ -1475,7 +1482,7 @@ describe('Running @erc725/erc725.js tests...', () => { for (let i = 0; i < numberOfTests; i++) { it(`Randomized test #${i + 1}`, () => { const randomPermissions = generateRandomPermissions(); - const encoded = ERC725.encodePermissions(randomPermissions); + const encoded = encodePermissions(randomPermissions); const expectedHex = calculateExpectedHex(randomPermissions); assert.strictEqual( encoded, @@ -1489,7 +1496,7 @@ describe('Running @erc725/erc725.js tests...', () => { describe('all permissions', () => { it('should encode ALL_PERMISSIONS correctly', () => { const permissions = { ALL_PERMISSIONS: true }; - const encoded = ERC725.encodePermissions(permissions); + const encoded = encodePermissions(permissions); assert.strictEqual( encoded, @@ -1498,12 +1505,81 @@ describe('Running @erc725/erc725.js tests...', () => { ); }); + it('should decode ALL_PERMISSIONS', () => { + const permissions = { ALL_PERMISSIONS: true }; + const encoded = encodePermissions(permissions); + + const decodedPermissions = decodePermissions(encoded); + + assert.strictEqual( + decodedPermissions.ALL_PERMISSIONS, + true, + 'Decoded permissions includes ALL_PERMISSIONS', + ); + }); + + it('should not decode CALL or ALL_PERMISSIONS if perms are missing', () => { + const permissions = { ALL_PERMISSIONS: true, CALL: false }; + const encoded = encodePermissions(permissions); + + const decodedPermissions = decodePermissions(encoded); + + assert.strictEqual( + decodedPermissions.CALL, + false, + 'Decoded permissions includes CALL', + ); + assert.strictEqual( + decodedPermissions.ALL_PERMISSIONS, + false, + 'Decoded permissions includes ALL_PERMISSIONS', + ); + }); + + it('should allow editing of permissions remove from all', () => { + const permissions = { ALL_PERMISSIONS: true }; + const encoded = encodePermissions(permissions); + + const decodedPermissions = decodePermissions(encoded); + decodedPermissions.CALL = false; + const reencodePermissions = encodePermissions(decodedPermissions); + const redecodedPermissions = decodePermissions(reencodePermissions); + + assert.strictEqual( + redecodedPermissions.CALL, + false, + 'Re-reencoded permissions includes CALL', + ); + }); + + it('should allow editing of permissions add extra', () => { + const permissions = { ALL_PERMISSIONS: true }; + const encoded = encodePermissions(permissions); + + const decodedPermissions = decodePermissions(encoded); + decodedPermissions.SUPER_DELEGATECALL = true; + decodedPermissions.DELEGATECALL = true; + const reencodePermissions = encodePermissions(decodedPermissions); + const redecodedPermissions = decodePermissions(reencodePermissions); + + assert.strictEqual( + redecodedPermissions.SUPER_DELEGATECALL, + true, + 'Re-reencoded permissions includes SUPER_DELEGATECALL', + ); + assert.strictEqual( + redecodedPermissions.DELEGATECALL, + true, + 'Re-reencoded permissions includes DELEGATECALL', + ); + }); + it('should ignore individual permissions when ALL_PERMISSIONS is set', () => { const permissions = { ALL_PERMISSIONS: true, CHANGEOWNER: true, }; - const encoded = ERC725.encodePermissions(permissions); + const encoded = encodePermissions(permissions); assert.strictEqual( encoded, LSP6_DEFAULT_PERMISSIONS.ALL_PERMISSIONS, @@ -1516,8 +1592,8 @@ describe('Running @erc725/erc725.js tests...', () => { CHANGEOWNER: false, // Explicitly disable CHANGEOWNER }; - const encoded = ERC725.encodePermissions(permissions); - const decodedPermissions = ERC725.decodePermissions(encoded); + const encoded = encodePermissions(permissions); + const decodedPermissions = decodePermissions(encoded); // check that the permission is disabled assert.strictEqual( @@ -1532,7 +1608,7 @@ describe('Running @erc725/erc725.js tests...', () => { testCases.forEach((testCase) => { it(`Decodes ${testCase.hex} permission correctly`, () => { assert.deepStrictEqual( - ERC725.decodePermissions(testCase.hex), + decodePermissions(testCase.hex), testCase.permissions, ); @@ -1542,9 +1618,81 @@ describe('Running @erc725/erc725.js tests...', () => { ); }); }); - it(`Decodes 0xfff...fff admin permission correctly`, () => { + it('Decodes 0xfff...fff admin permission correctly but re-encodes only known', () => { + let decoded = erc725Instance.decodePermissions( + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + ); + let reencoded = erc725Instance.encodePermissions(decoded); + assert.deepStrictEqual( + reencoded, + '0x0000000000000000000000000000000000000000000000000000000000ffffff', + ); + assert.deepStrictEqual(erc725Instance.decodePermissions(reencoded), { + CHANGEOWNER: true, + ADDCONTROLLER: true, + EDITPERMISSIONS: true, + ADDEXTENSIONS: true, + CHANGEEXTENSIONS: true, + ADDUNIVERSALRECEIVERDELEGATE: true, + CHANGEUNIVERSALRECEIVERDELEGATE: true, + REENTRANCY: true, + SUPER_TRANSFERVALUE: true, + TRANSFERVALUE: true, + SUPER_CALL: true, + CALL: true, + SUPER_STATICCALL: true, + STATICCALL: true, + SUPER_DELEGATECALL: true, + DELEGATECALL: true, + DEPLOY: true, + SUPER_SETDATA: true, + SETDATA: true, + ENCRYPT: true, + DECRYPT: true, + SIGN: true, + EXECUTE_RELAY_CALL: true, + ERC4337_PERMISSION: true, + ALL_PERMISSIONS: true, + }); + decoded = decodePermissions( + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + ); + reencoded = encodePermissions(decoded); + assert.deepStrictEqual( + reencoded, + '0x0000000000000000000000000000000000000000000000000000000000ffffff', + ); + assert.deepStrictEqual(decodePermissions(reencoded), { + CHANGEOWNER: true, + ADDCONTROLLER: true, + EDITPERMISSIONS: true, + ADDEXTENSIONS: true, + CHANGEEXTENSIONS: true, + ADDUNIVERSALRECEIVERDELEGATE: true, + CHANGEUNIVERSALRECEIVERDELEGATE: true, + REENTRANCY: true, + SUPER_TRANSFERVALUE: true, + TRANSFERVALUE: true, + SUPER_CALL: true, + CALL: true, + SUPER_STATICCALL: true, + STATICCALL: true, + SUPER_DELEGATECALL: true, + DELEGATECALL: true, + DEPLOY: true, + SUPER_SETDATA: true, + SETDATA: true, + ENCRYPT: true, + DECRYPT: true, + SIGN: true, + EXECUTE_RELAY_CALL: true, + ERC4337_PERMISSION: true, + ALL_PERMISSIONS: true, + }); + }); + it('Decodes 0xfff...fff admin permission correctly', () => { assert.deepStrictEqual( - ERC725.decodePermissions( + decodePermissions( '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', ), { @@ -1650,7 +1798,7 @@ describe('encodeKeyName', () => { it('is available on instance and class', () => { assert.deepStrictEqual( - ERC725.encodeKeyName('MyKeyName'), + encodeKeyName('MyKeyName'), '0x35e6950bc8d21a1699e58328a3c4066df5803bb0b570d0150cb3819288e764b2', ); assert.deepStrictEqual( @@ -1661,7 +1809,7 @@ describe('encodeKeyName', () => { it('works for dynamic keys', () => { assert.deepStrictEqual( - ERC725.encodeKeyName( + encodeKeyName( 'FavouriteFood:
', '0xa4FBbFe353124E6fa6Bb7f8e088a9269dF552EA2', ), @@ -1681,7 +1829,7 @@ describe('supportsInterface', () => { const erc725Instance = new ERC725([]); it('is available on instance and class', () => { - assert.typeOf(ERC725.supportsInterface, 'function'); + assert.typeOf(supportsInterface, 'function'); assert.typeOf(erc725Instance.supportsInterface, 'function'); }); @@ -1691,7 +1839,7 @@ describe('supportsInterface', () => { it('should throw when provided address is not an address', async () => { try { - await ERC725.supportsInterface(interfaceId, { + await supportsInterface(interfaceId, { address: 'notAnAddress', rpcUrl, }); @@ -1702,7 +1850,7 @@ describe('supportsInterface', () => { it('should throw when rpcUrl is not provided on non instantiated class', async () => { try { - await ERC725.supportsInterface(interfaceId, { + await supportsInterface(interfaceId, { address: contractAddress, // @ts-ignore rpcUrl: undefined, @@ -1736,7 +1884,7 @@ describe('checkPermissions', () => { }); it('is available on class', () => { - assert.typeOf(ERC725.checkPermissions, 'function'); + assert.typeOf(checkPermissions, 'function'); const requiredPermissions = [ '0x0000000000000000000000000000000000000000000000000000000000000004', @@ -1745,10 +1893,7 @@ describe('checkPermissions', () => { const grantedPermissions = '0x000000000000000000000000000000000000000000000000000000000000ff51'; - const result = ERC725.checkPermissions( - requiredPermissions, - grantedPermissions, - ); + const result = checkPermissions(requiredPermissions, grantedPermissions); assert.equal(result, false); }); @@ -1759,7 +1904,7 @@ describe('decodeMappingKey', () => { it('is available on instance and class', () => { assert.deepStrictEqual( - ERC725.decodeMappingKey( + decodeMappingKey( '0x35e6950bc8d21a1699e50000cafecafecafecafecafecafecafecafecafecafe', 'MyKeyName:
', ), diff --git a/src/index.ts b/src/index.ts index 6006945b..948db4ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ import { getDataFromExternalSources } from './lib/getDataFromExternalSources'; import { DynamicKeyPart, DynamicKeyParts } from './types/dynamicKeys'; import { getData } from './lib/getData'; import { decodeValueType, encodeValueType } from './lib/encoder'; -import { supportsInterface, checkPermissions } from './lib/detector'; +import { internalSupportsInterface, checkPermissions } from './lib/detector'; import { decodeMappingKey } from './lib/decodeMappingKey'; import { encodePermissions, decodePermissions } from './lib/permissions'; @@ -68,6 +68,7 @@ export { ERC725JSONSchemaKeyType, ERC725JSONSchemaValueContent, ERC725JSONSchemaValueType, + Permissions, }; export { ERC725Config, KeyValuePair, ProviderTypes } from './types'; @@ -82,7 +83,54 @@ export { } from './lib/encoder'; export { getDataFromExternalSources } from './lib/getDataFromExternalSources'; export { encodePermissions, decodePermissions } from './lib/permissions'; -export { supportsInterface, checkPermissions } from './lib/detector'; +export { checkPermissions } from './lib/detector'; + +// PRIVATE FUNCTION +function initializeProvider(providerOrRpcUrl, gasInfo) { + // do not fail on no-provider + if (!providerOrRpcUrl) return undefined; + + // if provider is a string, assume it's a rpcUrl + if (typeof providerOrRpcUrl === 'string') { + return new ProviderWrapper(new HttpProvider(providerOrRpcUrl), gasInfo); + } + + if ( + typeof providerOrRpcUrl.request === 'function' || + typeof providerOrRpcUrl.send === 'function' + ) + return new ProviderWrapper(providerOrRpcUrl, gasInfo); + + throw new Error(`Incorrect or unsupported provider ${providerOrRpcUrl}`); +} + +// PUBLIC FUNCTION +export async function supportsInterface( + interfaceIdOrName: string, + options: { + address: string; + rpcUrl: string; + gas?: number; + provider?: ProviderWrapper; + }, +): Promise { + if (!isAddress(options.address)) { + throw new Error('Invalid address'); + } + if (!options.rpcUrl) { + throw new Error('Missing RPC URL'); + } + + return internalSupportsInterface(interfaceIdOrName, { + address: options.address, + provider: + options.provider || + initializeProvider( + options.rpcUrl, + options?.gas ? options?.gas : DEFAULT_GAS_VALUE, + ), + }); +} /** * This package is currently in early stages of development,
use only for testing or experimentation purposes.
@@ -181,21 +229,7 @@ export class ERC725 { } private static initializeProvider(providerOrRpcUrl, gasInfo) { - // do not fail on no-provider - if (!providerOrRpcUrl) return undefined; - - // if provider is a string, assume it's a rpcUrl - if (typeof providerOrRpcUrl === 'string') { - return new ProviderWrapper(new HttpProvider(providerOrRpcUrl), gasInfo); - } - - if ( - typeof providerOrRpcUrl.request === 'function' || - typeof providerOrRpcUrl.send === 'function' - ) - return new ProviderWrapper(providerOrRpcUrl, gasInfo); - - throw new Error(`Incorrect or unsupported provider ${providerOrRpcUrl}`); + return initializeProvider(providerOrRpcUrl, gasInfo); } private getAddressAndProvider() { @@ -561,7 +595,7 @@ export class ERC725 { async supportsInterface(interfaceIdOrName: string): Promise { const { address, provider } = this.getAddressAndProvider(); - return supportsInterface(interfaceIdOrName, { + return internalSupportsInterface(interfaceIdOrName, { address, provider, }); @@ -579,20 +613,7 @@ export class ERC725 { interfaceIdOrName: string, options: { address: string; rpcUrl: string; gas?: number }, ): Promise { - if (!isAddress(options.address)) { - throw new Error('Invalid address'); - } - if (!options.rpcUrl) { - throw new Error('Missing RPC URL'); - } - - return supportsInterface(interfaceIdOrName, { - address: options.address, - provider: ERC725.initializeProvider( - options.rpcUrl, - options?.gas ? options?.gas : DEFAULT_GAS_VALUE, - ), - }); + return supportsInterface(interfaceIdOrName, options); } /** diff --git a/src/lib/detector.test.ts b/src/lib/detector.test.ts index bfde55c0..d397feae 100644 --- a/src/lib/detector.test.ts +++ b/src/lib/detector.test.ts @@ -24,7 +24,7 @@ import { expect } from 'chai'; import * as sinon from 'sinon'; import { INTERFACE_IDS_0_12_0 } from '../constants/interfaces'; -import { supportsInterface, checkPermissions } from './detector'; +import { internalSupportsInterface, checkPermissions } from './detector'; describe('supportsInterface', () => { it('it should return true if the contract supports the interface with name', async () => { @@ -37,10 +37,13 @@ describe('supportsInterface', () => { .withArgs(contractAddress, INTERFACE_IDS_0_12_0[interfaceName]) .returns(Promise.resolve(true)); - const doesSupportInterface = await supportsInterface(interfaceName, { - address: contractAddress, - provider: providerStub, - }); + const doesSupportInterface = await internalSupportsInterface( + interfaceName, + { + address: contractAddress, + provider: providerStub, + }, + ); expect(doesSupportInterface).to.be.true; }); @@ -55,7 +58,7 @@ describe('supportsInterface', () => { .withArgs(contractAddress, interfaceId) .returns(Promise.resolve(true)); - const doesSupportInterface = await supportsInterface(interfaceId, { + const doesSupportInterface = await internalSupportsInterface(interfaceId, { address: contractAddress, provider: providerStub, }); diff --git a/src/lib/detector.ts b/src/lib/detector.ts index b60fb638..1fae16a1 100644 --- a/src/lib/detector.ts +++ b/src/lib/detector.ts @@ -36,7 +36,7 @@ import { * @param options Object with address and RPC URL. * @returns {Promise} if interface is supported. */ -export const supportsInterface = async ( +export const internalSupportsInterface = async ( interfaceIdOrName: string, options: AddressProviderOptions, ): Promise => { diff --git a/src/lib/encoder.test.ts b/src/lib/encoder.test.ts index ed170fca..3cc6dc8c 100644 --- a/src/lib/encoder.test.ts +++ b/src/lib/encoder.test.ts @@ -250,9 +250,8 @@ describe('encoder', () => { // over the max uint256 allowed, does not fit in 32 bytes input: toHex( toBN( - '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' + - 1, - ), + '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', + ).add(toBN(1)), ), }, ]; diff --git a/src/lib/permissions.ts b/src/lib/permissions.ts index ce27dc81..15647f5b 100644 --- a/src/lib/permissions.ts +++ b/src/lib/permissions.ts @@ -1,60 +1,32 @@ -import { hexToNumber, leftPad, toHex } from 'web3-utils'; -import { - LSP6_ALL_PERMISSIONS, - LSP6_DEFAULT_PERMISSIONS, -} from '../constants/constants'; +import { hexToNumber, leftPad, numberToHex } from 'web3-utils'; +import { LSP6_DEFAULT_PERMISSIONS } from '../constants/constants'; import { Permissions } from '../types/Method'; export function encodePermissions(permissions: Permissions): string { let basePermissions = BigInt(0); - // If ALL_PERMISSIONS is requested, start with that as the base - if (permissions.ALL_PERMISSIONS) { - basePermissions = BigInt( - hexToNumber(LSP6_DEFAULT_PERMISSIONS.ALL_PERMISSIONS), - ); - } - - // Explicitly add REENTRANCY, DELEGATECALL, and SUPER_DELEGATECALL if requested (they are not included in ALL_PERMISSIONS) - const additionalPermissions = [ - LSP6_DEFAULT_PERMISSIONS.REENTRANCY, - LSP6_DEFAULT_PERMISSIONS.DELEGATECALL, - LSP6_DEFAULT_PERMISSIONS.SUPER_DELEGATECALL, - ]; - // Do not use an for of loop here to not require the regenerator runtime - for (let i = 0; i < additionalPermissions.length; i += 1) { - const permission = additionalPermissions[i]; - if (permissions[permission]) { - basePermissions |= BigInt( - hexToNumber(LSP6_DEFAULT_PERMISSIONS[permission]), - ); - } - } - // Process each permission to potentially switch off permissions included in ALL_PERMISSIONS - const keys = Object.keys(permissions); + // Deal with ALL_PERMISSIONS first IMPORTANT! + const keys = Object.keys(permissions).filter( + (key) => key !== 'ALL_PERMISSIONS', + ); + keys.splice(0, 0, 'ALL_PERMISSIONS'); // Do not use an for of loop here to not require the regenerator runtime for (let i = 0; i < keys.length; i += 1) { const key = keys[i]; - const permissionValue = BigInt(hexToNumber(LSP6_DEFAULT_PERMISSIONS[key])); - - if (permissions[key]) { - // If not dealing with ALL_PERMISSIONS or additional permissions, ensure they are added - if ( - !additionalPermissions.includes(key) && - key !== LSP6_DEFAULT_PERMISSIONS.ALL_PERMISSIONS - ) { + const permissionValue = BigInt( + hexToNumber(LSP6_DEFAULT_PERMISSIONS[key], true), + ); + if (key in permissions) { + if (permissions[key]) { basePermissions |= permissionValue; + } else { + basePermissions &= ~permissionValue; } - } else if ( - LSP6_DEFAULT_PERMISSIONS[key] !== LSP6_DEFAULT_PERMISSIONS.ALL_PERMISSIONS - ) { - // If permission is set to false, remove it from the basePermissions - basePermissions &= ~permissionValue; } } // Convert the final BigInt permission value back to a hex string, properly padded - return leftPad(toHex(basePermissions.toString()), 64); + return leftPad(numberToHex(basePermissions.toString()), 64); } export function decodePermissions(permissionHex: string) { @@ -87,22 +59,16 @@ export function decodePermissions(permissionHex: string) { }; const permissionsToTest = Object.keys(LSP6_DEFAULT_PERMISSIONS); - if (permissionHex === LSP6_ALL_PERMISSIONS) { - // Do not use an for of loop here to not require the regenerator runtime - for (let i = 0; i < permissionsToTest.length; i += 1) { - const testPermission = permissionsToTest[i]; - result[testPermission] = true; - } - return result; - } - - const passedPermissionDecimal = Number(hexToNumber(permissionHex)); + const passedPermissionDecimal = BigInt(hexToNumber(permissionHex, true)); // Do not use an for of loop here to not require the regenerator runtime + // Deal with ALL_PERMISSIONS the same way. So as long as all the bits in ALL_PERMISSIONS + // are set the same way as in ALL_PERMISSIONS then this flag will return as true. + // It does not mean some extra permissions are not included. for (let i = 0; i < permissionsToTest.length; i += 1) { const testPermission = permissionsToTest[i]; - const decimalTestPermission = Number( - hexToNumber(LSP6_DEFAULT_PERMISSIONS[testPermission]), + const decimalTestPermission = BigInt( + hexToNumber(LSP6_DEFAULT_PERMISSIONS[testPermission], true), ); const isPermissionIncluded = (passedPermissionDecimal & decimalTestPermission) === diff --git a/src/types/Method.ts b/src/types/Method.ts index 6eb49bb9..677239ca 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -49,4 +49,5 @@ export interface Permissions { EXECUTE_RELAY_CALL?: boolean; ERC4337_PERMISSION?: boolean; ALL_PERMISSIONS?: boolean; + [key: string]: boolean | undefined; } diff --git a/src/types/provider.ts b/src/types/provider.ts index 0b3fd8cb..6d5d87a1 100644 --- a/src/types/provider.ts +++ b/src/types/provider.ts @@ -1,4 +1,4 @@ -export const enum ProviderTypes { +export enum ProviderTypes { ETHEREUM = 'ETHEREUM', WEB3 = 'WEB3', }