From 6db8835ccd9d1082d9e8184bb2f14972760bea69 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Tue, 17 Oct 2023 13:51:26 +0100 Subject: [PATCH 1/3] feat: add permission `EXECUTE_RELAY_CALL` --- src/constants/constants.ts | 43 +++++++++++++++++++------------------- src/index.test.ts | 8 +++++++ src/index.ts | 1 + src/types/Method.ts | 1 + 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 1c71a5c0..b2e02f1e 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -155,27 +155,28 @@ export const HASH_FUNCTIONS: { // prettier-ignore export const LSP6_DEFAULT_PERMISSIONS = { CHANGEOWNER :"0x0000000000000000000000000000000000000000000000000000000000000001", - ADDCONTROLLER :"0x0000000000000000000000000000000000000000000000000000000000000002", - EDITPERMISSIONS :"0x0000000000000000000000000000000000000000000000000000000000000004", - ADDEXTENSIONS :"0x0000000000000000000000000000000000000000000000000000000000000008", - CHANGEEXTENSIONS :"0x0000000000000000000000000000000000000000000000000000000000000010", - ADDUNIVERSALRECEIVERDELEGATE :"0x0000000000000000000000000000000000000000000000000000000000000020", - CHANGEUNIVERSALRECEIVERDELEGATE :"0x0000000000000000000000000000000000000000000000000000000000000040", - REENTRANCY :"0x0000000000000000000000000000000000000000000000000000000000000080", - SUPER_TRANSFERVALUE :"0x0000000000000000000000000000000000000000000000000000000000000100", - TRANSFERVALUE :"0x0000000000000000000000000000000000000000000000000000000000000200", - SUPER_CALL :"0x0000000000000000000000000000000000000000000000000000000000000400", - CALL :"0x0000000000000000000000000000000000000000000000000000000000000800", - SUPER_STATICCALL :"0x0000000000000000000000000000000000000000000000000000000000001000", - STATICCALL :"0x0000000000000000000000000000000000000000000000000000000000002000", - SUPER_DELEGATECALL :"0x0000000000000000000000000000000000000000000000000000000000004000", - DELEGATECALL :"0x0000000000000000000000000000000000000000000000000000000000008000", - DEPLOY :"0x0000000000000000000000000000000000000000000000000000000000010000", - SUPER_SETDATA :"0x0000000000000000000000000000000000000000000000000000000000020000", - SETDATA :"0x0000000000000000000000000000000000000000000000000000000000040000", - ENCRYPT :"0x0000000000000000000000000000000000000000000000000000000000080000", - DECRYPT :"0x0000000000000000000000000000000000000000000000000000000000100000", - SIGN :"0x0000000000000000000000000000000000000000000000000000000000200000", + ADDCONTROLLER :"0x0000000000000000000000000000000000000000000000000000000000000002", + EDITPERMISSIONS :"0x0000000000000000000000000000000000000000000000000000000000000004", + ADDEXTENSIONS :"0x0000000000000000000000000000000000000000000000000000000000000008", + CHANGEEXTENSIONS :"0x0000000000000000000000000000000000000000000000000000000000000010", + ADDUNIVERSALRECEIVERDELEGATE :"0x0000000000000000000000000000000000000000000000000000000000000020", + CHANGEUNIVERSALRECEIVERDELEGATE :"0x0000000000000000000000000000000000000000000000000000000000000040", + REENTRANCY :"0x0000000000000000000000000000000000000000000000000000000000000080", + SUPER_TRANSFERVALUE :"0x0000000000000000000000000000000000000000000000000000000000000100", + TRANSFERVALUE :"0x0000000000000000000000000000000000000000000000000000000000000200", + SUPER_CALL :"0x0000000000000000000000000000000000000000000000000000000000000400", + CALL :"0x0000000000000000000000000000000000000000000000000000000000000800", + SUPER_STATICCALL :"0x0000000000000000000000000000000000000000000000000000000000001000", + STATICCALL :"0x0000000000000000000000000000000000000000000000000000000000002000", + SUPER_DELEGATECALL :"0x0000000000000000000000000000000000000000000000000000000000004000", + DELEGATECALL :"0x0000000000000000000000000000000000000000000000000000000000008000", + DEPLOY :"0x0000000000000000000000000000000000000000000000000000000000010000", + SUPER_SETDATA :"0x0000000000000000000000000000000000000000000000000000000000020000", + SETDATA :"0x0000000000000000000000000000000000000000000000000000000000040000", + ENCRYPT :"0x0000000000000000000000000000000000000000000000000000000000080000", + DECRYPT :"0x0000000000000000000000000000000000000000000000000000000000100000", + SIGN :"0x0000000000000000000000000000000000000000000000000000000000200000", + EXECUTE_RELAY_CALL :"0x00000000000000000000000000000000000000000000000000000000004400000", }; export const LSP6_ALL_PERMISSIONS = diff --git a/src/index.test.ts b/src/index.test.ts index 568d2dc5..a96c2b01 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1060,6 +1060,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, + EXECUTE_RELAY_CALL: false }, hex: '0x00000000000000000000000000000000000000000000000000000000003f3f7f', }, @@ -1087,6 +1088,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, + EXECUTE_RELAY_CALL: false }, hex: '0x0000000000000000000000000000000000000000000000000000000000000000', }, @@ -1114,6 +1116,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: true, + EXECUTE_RELAY_CALL: false }, hex: '0x0000000000000000000000000000000000000000000000000000000000200a00', }, @@ -1141,6 +1144,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, + EXECUTE_RELAY_CALL: false }, hex: '0x0000000000000000000000000000000000000000000000000000000000040800', }, @@ -1168,6 +1172,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, + EXECUTE_RELAY_CALL: false }, hex: '0x0000000000000000000000000000000000000000000000000000000000040004', }, @@ -1195,6 +1200,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, + EXECUTE_RELAY_CALL: false }, hex: '0x0000000000000000000000000000000000000000000000000000000000000a00', }, @@ -1275,6 +1281,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, + EXECUTE_RELAY_CALL: true }, ); assert.deepStrictEqual( @@ -1304,6 +1311,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, + EXECUTE_RELAY_CALL: true }, ); }); diff --git a/src/index.ts b/src/index.ts index 2acbb8d1..67a814d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -477,6 +477,7 @@ export class ERC725 { ENCRYPT: false, DECRYPT: false, SIGN: false, + EXECUTE_RELAY_CALL: false, }; const permissionsToTest = Object.keys(LSP6_DEFAULT_PERMISSIONS); diff --git a/src/types/Method.ts b/src/types/Method.ts index 658bde75..e28b49ab 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -48,4 +48,5 @@ export interface Permissions { ENCRYPT?: boolean; DECRYPT?: boolean; SIGN?: boolean; + EXECUTE_RELAY_CALL?: boolean; } From 75ebf9a3d503cc761267926dde836b0900597456 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Tue, 17 Oct 2023 17:00:10 +0100 Subject: [PATCH 2/3] refactor: use Bitwise `OR` to toggle ON permission --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 67a814d4..6a07e404 100644 --- a/src/index.ts +++ b/src/index.ts @@ -428,7 +428,7 @@ export class ERC725 { static encodePermissions(permissions: Permissions): string { const result = Object.keys(permissions).reduce((previous, key) => { return permissions[key] - ? previous + Number(hexToNumber(LSP6_DEFAULT_PERMISSIONS[key])) + ? previous | Number(hexToNumber(LSP6_DEFAULT_PERMISSIONS[key])) : previous; }, 0); From 28a871df86e85ed6038491234a7b1d7295b952a4 Mon Sep 17 00:00:00 2001 From: CJ42 Date: Tue, 17 Oct 2023 17:01:24 +0100 Subject: [PATCH 3/3] chore: apply prettier --- examples/README.md | 8 ++++++++ src/index.test.ts | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/README.md b/examples/README.md index 4315d205..0dc1743f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,25 +1,33 @@ # Examples ## fetchData + ``` npm run fetchData ``` + [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/erc725js-fetch-data?devtoolsheight=66&file=index.js) ## getData + ``` npm run getData ``` + [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/erc725js-get-data?devtoolsheight=66&file=package.json) ## encodeData + ``` npm run encodeData ``` + [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/erc725js-encode-data?devtoolsheight=66&file=index.js) ## decodeData + ``` npm run decodeData ``` + [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/erc725js-decode-data?devtoolsheight=66) diff --git a/src/index.test.ts b/src/index.test.ts index a96c2b01..36d077e4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1060,7 +1060,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x00000000000000000000000000000000000000000000000000000000003f3f7f', }, @@ -1088,7 +1088,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x0000000000000000000000000000000000000000000000000000000000000000', }, @@ -1116,7 +1116,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: true, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x0000000000000000000000000000000000000000000000000000000000200a00', }, @@ -1144,7 +1144,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x0000000000000000000000000000000000000000000000000000000000040800', }, @@ -1172,7 +1172,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x0000000000000000000000000000000000000000000000000000000000040004', }, @@ -1200,7 +1200,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: false, DECRYPT: false, SIGN: false, - EXECUTE_RELAY_CALL: false + EXECUTE_RELAY_CALL: false, }, hex: '0x0000000000000000000000000000000000000000000000000000000000000a00', }, @@ -1281,7 +1281,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, - EXECUTE_RELAY_CALL: true + EXECUTE_RELAY_CALL: true, }, ); assert.deepStrictEqual( @@ -1311,7 +1311,7 @@ describe('Running @erc725/erc725.js tests...', () => { ENCRYPT: true, DECRYPT: true, SIGN: true, - EXECUTE_RELAY_CALL: true + EXECUTE_RELAY_CALL: true, }, ); });