From 0d67ba6564fd93286f03dbcbb2acc19a67daddf6 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Tue, 13 Sep 2022 14:37:31 +0200 Subject: [PATCH 1/7] feat: expose utility functions/types --- .gitignore | 3 +- .npmignore | 14 ---- package.json | 10 +++ src/index.ts | 7 ++ src/util.ts | 139 ++++++++++++++++++++++++++++++++ test/meta-transactions.test.ts | 6 +- test/utils.ts | 141 +-------------------------------- tsconfig.src.json | 7 ++ 8 files changed, 168 insertions(+), 159 deletions(-) delete mode 100644 .npmignore create mode 100644 src/index.ts create mode 100644 src/util.ts create mode 100644 tsconfig.src.json diff --git a/.gitignore b/.gitignore index 55c00fd..615ca28 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ test .DS_STORE .env .openzeppelin/unknown-1337.json -networks/5777.json \ No newline at end of file +networks/5777.json +dist \ No newline at end of file diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 51950bd..0000000 --- a/.npmignore +++ /dev/null @@ -1,14 +0,0 @@ -node_modules -migrations -development/ -coverage/ -coverage.json -.idea -test -migrations-ts -README.md -.solhint.json -tsconfig.migrate.json -.DS_STORE -.openzeppelin/unknown-1337.json -.env \ No newline at end of file diff --git a/package.json b/package.json index a918d24..640514f 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,8 @@ "name": "@spherity/ethr-revocation-registry", "version": "1.0.5", "description": "The Ethereum Revocation List types for smart contract interaction.", + "main": "dist/src/index.js", + "typings": "dist/src/index.d.ts", "scripts": { "prepare": "npm run types", "init": "docker-compose -f development/docker-compose.yml up -d", @@ -12,12 +14,20 @@ "compile-types": "npm run compile-truffle-types && npm run compile-ethers-types", "compile-truffle-types": "echo 'truffle types are not supported yet for distribution'", "compile-ethers-types": "tsc -p tsconfig.ethers.json --outDir ./types/ethers-v5/", + "compile-src": "tsc -p tsconfig.src.json --outDir ./dist/", "migrate": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate", "migrate-goerli": "tsc -p ./tsconfig.migrate.json --outDir ./migrations && npm run compile && truffle migrate --network goerli", "test": "npx truffle test", "test:coverage": "npx truffle run coverage", "compile": "npx truffle compile && apply-registry" }, + "files": [ + "dist", + "types", + "contracts", + "networks", + "dist" + ], "repository": { "type": "git", "url": "git+https://github.com/spherity/Ethereum-Revocation-Registry.git" diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..0085c25 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,7 @@ +export { + EIP712Domain, + generateEIP712Params, + getEIP721DomainObject, + EIP712Params, + SignedFunction +} from "./util" \ No newline at end of file diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..4b661fb --- /dev/null +++ b/src/util.ts @@ -0,0 +1,139 @@ +export interface EIP712Domain { + name: string; + version: string; + chainId: number; + verifyingContract: string; +} + +export async function getEIP721DomainObject(version: string, chainId: number, address: string): Promise { + return { + name: 'Revocation Registry', + version: version, + chainId: chainId, + verifyingContract: address, + }; +} + +export enum SignedFunction { + CHANGE_STATUS = "ChangeStatus", + CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", + CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", + CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", + CHANGE_LIST_OWNER = "ChangeListOwner", + CHANGE_LIST_STATUS = "ChangeListStatus", + ADD_LIST_DELEGATE = "AddListDelegate", + REMOVE_LIST_DELEGATE = "RemoveListDelegate", +} + +// TODO: replace any with correct type and maybe throw it into the types-ts folder? +export interface EIP712Params { + domain: any; + message: any; + primaryType: string; + types: any; +} + +export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { + const params: EIP712Params = { + domain: domainObject, + message: message, + primaryType: "", + types: { + // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on + EIP712Domain: [ + {name: 'name', type: 'string'}, + {name: 'version', type: 'string'}, + {name: 'chainId', type: 'uint256'}, + {name: 'verifyingContract', type: 'address'}, + ] + }, + } + + switch (signedFunction) { + case SignedFunction.CHANGE_STATUS: + params.primaryType = "ChangeStatus"; + params.types.ChangeStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUS_DELEGATED: + params.primaryType = "ChangeStatusDelegated"; + params.types.ChangeStatusDelegated = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST: + params.primaryType = "ChangeStatusesInList"; + params.types.ChangeStatusesInList = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: + params.primaryType = "ChangeStatusesInListDelegated"; + params.types.ChangeStatusesInListDelegated = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_OWNER: + params.primaryType = "ChangeListOwner"; + params.types.ChangeListOwner = [ + {name: 'namespace', type: 'address'}, + {name: 'newOwner', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.ADD_LIST_DELEGATE: + params.primaryType = "AddListDelegate"; + params.types.AddListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'validity', type: 'uint'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.REMOVE_LIST_DELEGATE: + params.primaryType = "RemoveListDelegate"; + params.types.RemoveListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_STATUS: + params.primaryType = "ChangeListStatus"; + params.types.ChangeListStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + } + return params; +} \ No newline at end of file diff --git a/test/meta-transactions.test.ts b/test/meta-transactions.test.ts index 1bcecbf..e50e26e 100644 --- a/test/meta-transactions.test.ts +++ b/test/meta-transactions.test.ts @@ -11,14 +11,12 @@ import { changeListOwnerSigned, changeListStatusSigned, changeStatusesInListDelegatedSigned, changeStatusesInListSigned, - generateEIP712Params, - getEIP721DomainObject, getNonce, removeListDelegateSigned, - SignedFunction, signTypedData } from "./utils"; import {deployProxy} from "@openzeppelin/truffle-upgrades"; +import {generateEIP712Params, getEIP721DomainObject, SignedFunction} from "../src/util"; const RevocationRegistry: any = artifacts.require("RevocationRegistry"); @@ -32,7 +30,7 @@ contract("Meta Transaction", function (accounts) { beforeEach(async () => { const deployedProxy: any = await deployProxy(RevocationRegistry, []); registry = deployedProxy; - domainObject = await getEIP721DomainObject(registry) + domainObject = await getEIP721DomainObject(await registry.version(), await web3.eth.getChainId(), registry.address) }) diff --git a/test/utils.ts b/test/utils.ts index 33021f9..b11f0e0 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,5 +1,6 @@ import {RevocationRegistryInstance} from "../types-ts/truffle-v5"; import {HttpProvider} from "web3-core"; +import {EIP712Params} from "../src/util"; // TODO: Let's discuss if we really want to have separate cases / fncts for revoke/ unrevoke @@ -125,144 +126,4 @@ export async function signTypedData(signer: string, params: EIP712Params): Promi resolve(result.result); }) }); -} - -interface EIP712Domain { - name: string; - version: string; - chainId: number; - verifyingContract: string; -} - -export async function getEIP721DomainObject(registry: RevocationRegistryInstance): Promise { - return { - name: 'Revocation Registry', - version: await registry.version(), - chainId: await web3.eth.getChainId(), - verifyingContract: registry.address, - }; -} - -export enum SignedFunction { - CHANGE_STATUS = "ChangeStatus", - CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", - CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", - CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", - CHANGE_LIST_OWNER = "ChangeListOwner", - CHANGE_LIST_STATUS = "ChangeListStatus", - ADD_LIST_DELEGATE = "AddListDelegate", - REMOVE_LIST_DELEGATE = "RemoveListDelegate", -} - -// TODO: replace any with correct type and maybe throw it into the types-ts folder? -interface EIP712Params { - domain: any; - message: any; - primaryType: string; - types: any; -} - -export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { - const params: EIP712Params = { - domain: domainObject, - message: message, - primaryType: "", - types: { - // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on - EIP712Domain: [ - {name: 'name', type: 'string'}, - {name: 'version', type: 'string'}, - {name: 'chainId', type: 'uint256'}, - {name: 'verifyingContract', type: 'address'}, - ] - }, - } - - switch (signedFunction) { - case SignedFunction.CHANGE_STATUS: - params.primaryType = "ChangeStatus"; - params.types.ChangeStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUS_DELEGATED: - params.primaryType = "ChangeStatusDelegated"; - params.types.ChangeStatusDelegated = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST: - params.primaryType = "ChangeStatusesInList"; - params.types.ChangeStatusesInList = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: - params.primaryType = "ChangeStatusesInListDelegated"; - params.types.ChangeStatusesInListDelegated = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_OWNER: - params.primaryType = "ChangeListOwner"; - params.types.ChangeListOwner = [ - {name: 'namespace', type: 'address'}, - {name: 'newOwner', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.ADD_LIST_DELEGATE: - params.primaryType = "AddListDelegate"; - params.types.AddListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'validity', type: 'uint'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.REMOVE_LIST_DELEGATE: - params.primaryType = "RemoveListDelegate"; - params.types.RemoveListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_STATUS: - params.primaryType = "ChangeListStatus"; - params.types.ChangeListStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - } - return params; } \ No newline at end of file diff --git a/tsconfig.src.json b/tsconfig.src.json new file mode 100644 index 0000000..82988ac --- /dev/null +++ b/tsconfig.src.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["./src/**/*.ts"], + "compilerOptions": { + "declaration": true + } +} \ No newline at end of file From 294bbeacb9f43c61cfecc7db2811fb764b26bf46 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Tue, 13 Sep 2022 14:38:19 +0200 Subject: [PATCH 2/7] chore: add compile src to prepare step --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 640514f..5c5614e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "dist/src/index.js", "typings": "dist/src/index.d.ts", "scripts": { - "prepare": "npm run types", + "prepare": "npm run types && npm run compile-src", "init": "docker-compose -f development/docker-compose.yml up -d", "types": "npm run compile && npm run generate-types && npm run compile-types", "generate-types": "npm run generate-truffle-types && npm run generate-ethers-types", From 19f4ddbb24bda65bcd24517c8f277c69e82d5381 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Wed, 14 Sep 2022 15:51:58 +0200 Subject: [PATCH 3/7] chore: preparations for eip712 initialize in contract is added just for the purpose of testing the logic contract itself in the dependencies doing integration tests (controller) --- contracts/RevocationRegistry.sol | 1 + src/index.ts | 6 +- src/util.ts | 149 +++---------------------------- 3 files changed, 13 insertions(+), 143 deletions(-) diff --git a/contracts/RevocationRegistry.sol b/contracts/RevocationRegistry.sol index 7143e73..e6b283b 100644 --- a/contracts/RevocationRegistry.sol +++ b/contracts/RevocationRegistry.sol @@ -36,6 +36,7 @@ contract RevocationRegistry is Initializable, EIP712Upgradeable, PausableUpgrade /// @custom:oz-upgrades-unsafe-allow constructor constructor() { + initialize(); _disableInitializers(); } diff --git a/src/index.ts b/src/index.ts index 0085c25..b454755 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,3 @@ export { - EIP712Domain, - generateEIP712Params, - getEIP721DomainObject, - EIP712Params, - SignedFunction + EIP712ChangeStatusType } from "./util" \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index 4b661fb..67e1e84 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,139 +1,12 @@ -export interface EIP712Domain { - name: string; - version: string; - chainId: number; - verifyingContract: string; +import {TypedDataField} from "ethers"; + +export const EIP712ChangeStatusType = { + ChangeStatus: [ + {name: 'revoked', type: 'bool'} as TypedDataField, + {name: 'namespace', type: 'address'} as TypedDataField, + {name: 'revocationList', type: 'bytes32'} as TypedDataField, + {name: 'revocationKey', type: 'bytes32'} as TypedDataField, + {name: 'signer', type: 'address'} as TypedDataField, + {name: 'nonce', type: 'uint'} as TypedDataField, + ] } - -export async function getEIP721DomainObject(version: string, chainId: number, address: string): Promise { - return { - name: 'Revocation Registry', - version: version, - chainId: chainId, - verifyingContract: address, - }; -} - -export enum SignedFunction { - CHANGE_STATUS = "ChangeStatus", - CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", - CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", - CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", - CHANGE_LIST_OWNER = "ChangeListOwner", - CHANGE_LIST_STATUS = "ChangeListStatus", - ADD_LIST_DELEGATE = "AddListDelegate", - REMOVE_LIST_DELEGATE = "RemoveListDelegate", -} - -// TODO: replace any with correct type and maybe throw it into the types-ts folder? -export interface EIP712Params { - domain: any; - message: any; - primaryType: string; - types: any; -} - -export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { - const params: EIP712Params = { - domain: domainObject, - message: message, - primaryType: "", - types: { - // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on - EIP712Domain: [ - {name: 'name', type: 'string'}, - {name: 'version', type: 'string'}, - {name: 'chainId', type: 'uint256'}, - {name: 'verifyingContract', type: 'address'}, - ] - }, - } - - switch (signedFunction) { - case SignedFunction.CHANGE_STATUS: - params.primaryType = "ChangeStatus"; - params.types.ChangeStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUS_DELEGATED: - params.primaryType = "ChangeStatusDelegated"; - params.types.ChangeStatusDelegated = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST: - params.primaryType = "ChangeStatusesInList"; - params.types.ChangeStatusesInList = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: - params.primaryType = "ChangeStatusesInListDelegated"; - params.types.ChangeStatusesInListDelegated = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_OWNER: - params.primaryType = "ChangeListOwner"; - params.types.ChangeListOwner = [ - {name: 'namespace', type: 'address'}, - {name: 'newOwner', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.ADD_LIST_DELEGATE: - params.primaryType = "AddListDelegate"; - params.types.AddListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'validity', type: 'uint'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.REMOVE_LIST_DELEGATE: - params.primaryType = "RemoveListDelegate"; - params.types.RemoveListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_STATUS: - params.primaryType = "ChangeListStatus"; - params.types.ChangeListStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - } - return params; -} \ No newline at end of file From 2ef5c2583781d68a4fda8b98921775a2b4a591c3 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Wed, 14 Sep 2022 15:53:16 +0200 Subject: [PATCH 4/7] fix: entrypoint and typing paths --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5c5614e..f5ae456 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "@spherity/ethr-revocation-registry", "version": "1.0.5", "description": "The Ethereum Revocation List types for smart contract interaction.", - "main": "dist/src/index.js", - "typings": "dist/src/index.d.ts", + "main": "dist/index.js", + "typings": "dist/index.d.ts", "scripts": { "prepare": "npm run types && npm run compile-src", "init": "docker-compose -f development/docker-compose.yml up -d", From fbcd54b912231895e94bb55b42b18a55964f0fab Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Wed, 14 Sep 2022 15:58:28 +0200 Subject: [PATCH 5/7] fix: readd stuff needed for tests --- src/util.ts | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/src/util.ts b/src/util.ts index 67e1e84..b2a3e77 100644 --- a/src/util.ts +++ b/src/util.ts @@ -10,3 +10,127 @@ export const EIP712ChangeStatusType = { {name: 'nonce', type: 'uint'} as TypedDataField, ] } + +export enum SignedFunction { + CHANGE_STATUS = "ChangeStatus", + CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", + CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", + CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", + CHANGE_LIST_OWNER = "ChangeListOwner", + CHANGE_LIST_STATUS = "ChangeListStatus", + ADD_LIST_DELEGATE = "AddListDelegate", + REMOVE_LIST_DELEGATE = "RemoveListDelegate", +} + +// TODO: replace any with correct type and maybe throw it into the types-ts folder? +export interface EIP712Params { + domain: any; + message: any; + primaryType: string; + types: any; +} + +export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { + const params: EIP712Params = { + domain: domainObject, + message: message, + primaryType: "", + types: { + // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on + EIP712Domain: [ + {name: 'name', type: 'string'}, + {name: 'version', type: 'string'}, + {name: 'chainId', type: 'uint256'}, + {name: 'verifyingContract', type: 'address'}, + ] + }, + } + + switch (signedFunction) { + case SignedFunction.CHANGE_STATUS: + params.primaryType = "ChangeStatus"; + params.types.ChangeStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUS_DELEGATED: + params.primaryType = "ChangeStatusDelegated"; + params.types.ChangeStatusDelegated = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST: + params.primaryType = "ChangeStatusesInList"; + params.types.ChangeStatusesInList = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: + params.primaryType = "ChangeStatusesInListDelegated"; + params.types.ChangeStatusesInListDelegated = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_OWNER: + params.primaryType = "ChangeListOwner"; + params.types.ChangeListOwner = [ + {name: 'namespace', type: 'address'}, + {name: 'newOwner', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.ADD_LIST_DELEGATE: + params.primaryType = "AddListDelegate"; + params.types.AddListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'validity', type: 'uint'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.REMOVE_LIST_DELEGATE: + params.primaryType = "RemoveListDelegate"; + params.types.RemoveListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_STATUS: + params.primaryType = "ChangeListStatus"; + params.types.ChangeListStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + } + return params; +} \ No newline at end of file From 5849ffaa8e44c32f51abb4243e467d30d91b8248 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Wed, 14 Sep 2022 16:10:22 +0200 Subject: [PATCH 6/7] fix: util stuff --- src/util.ts | 124 ---------------------------- test/meta-transactions.test.ts | 5 +- test/utils.ts | 143 ++++++++++++++++++++++++++++++++- 3 files changed, 144 insertions(+), 128 deletions(-) diff --git a/src/util.ts b/src/util.ts index b2a3e77..c6a8d61 100644 --- a/src/util.ts +++ b/src/util.ts @@ -9,128 +9,4 @@ export const EIP712ChangeStatusType = { {name: 'signer', type: 'address'} as TypedDataField, {name: 'nonce', type: 'uint'} as TypedDataField, ] -} - -export enum SignedFunction { - CHANGE_STATUS = "ChangeStatus", - CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", - CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", - CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", - CHANGE_LIST_OWNER = "ChangeListOwner", - CHANGE_LIST_STATUS = "ChangeListStatus", - ADD_LIST_DELEGATE = "AddListDelegate", - REMOVE_LIST_DELEGATE = "RemoveListDelegate", -} - -// TODO: replace any with correct type and maybe throw it into the types-ts folder? -export interface EIP712Params { - domain: any; - message: any; - primaryType: string; - types: any; -} - -export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { - const params: EIP712Params = { - domain: domainObject, - message: message, - primaryType: "", - types: { - // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on - EIP712Domain: [ - {name: 'name', type: 'string'}, - {name: 'version', type: 'string'}, - {name: 'chainId', type: 'uint256'}, - {name: 'verifyingContract', type: 'address'}, - ] - }, - } - - switch (signedFunction) { - case SignedFunction.CHANGE_STATUS: - params.primaryType = "ChangeStatus"; - params.types.ChangeStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUS_DELEGATED: - params.primaryType = "ChangeStatusDelegated"; - params.types.ChangeStatusDelegated = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKey', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST: - params.primaryType = "ChangeStatusesInList"; - params.types.ChangeStatusesInList = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: - params.primaryType = "ChangeStatusesInListDelegated"; - params.types.ChangeStatusesInListDelegated = [ - {name: 'revoked', type: 'bool[]'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'revocationKeys', type: 'bytes32[]'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_OWNER: - params.primaryType = "ChangeListOwner"; - params.types.ChangeListOwner = [ - {name: 'namespace', type: 'address'}, - {name: 'newOwner', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.ADD_LIST_DELEGATE: - params.primaryType = "AddListDelegate"; - params.types.AddListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'validity', type: 'uint'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.REMOVE_LIST_DELEGATE: - params.primaryType = "RemoveListDelegate"; - params.types.RemoveListDelegate = [ - {name: 'namespace', type: 'address'}, - {name: 'delegate', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - break; - case SignedFunction.CHANGE_LIST_STATUS: - params.primaryType = "ChangeListStatus"; - params.types.ChangeListStatus = [ - {name: 'revoked', type: 'bool'}, - {name: 'namespace', type: 'address'}, - {name: 'revocationList', type: 'bytes32'}, - {name: 'signer', type: 'address'}, - {name: 'nonce', type: 'uint'}, - ] - } - return params; } \ No newline at end of file diff --git a/test/meta-transactions.test.ts b/test/meta-transactions.test.ts index e50e26e..1d3d1dc 100644 --- a/test/meta-transactions.test.ts +++ b/test/meta-transactions.test.ts @@ -16,7 +16,7 @@ import { signTypedData } from "./utils"; import {deployProxy} from "@openzeppelin/truffle-upgrades"; -import {generateEIP712Params, getEIP721DomainObject, SignedFunction} from "../src/util"; +import {generateEIP712Params, getEIP721DomainObject, SignedFunction} from "./utils"; const RevocationRegistry: any = artifacts.require("RevocationRegistry"); @@ -29,8 +29,7 @@ contract("Meta Transaction", function (accounts) { beforeEach(async () => { const deployedProxy: any = await deployProxy(RevocationRegistry, []); - registry = deployedProxy; - domainObject = await getEIP721DomainObject(await registry.version(), await web3.eth.getChainId(), registry.address) + domainObject = await getEIP721DomainObject(deployedProxy) }) diff --git a/test/utils.ts b/test/utils.ts index b11f0e0..3795f45 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,6 +1,5 @@ import {RevocationRegistryInstance} from "../types-ts/truffle-v5"; import {HttpProvider} from "web3-core"; -import {EIP712Params} from "../src/util"; // TODO: Let's discuss if we really want to have separate cases / fncts for revoke/ unrevoke @@ -126,4 +125,146 @@ export async function signTypedData(signer: string, params: EIP712Params): Promi resolve(result.result); }) }); +} + + + +interface EIP712Domain { + name: string; + version: string; + chainId: number; + verifyingContract: string; +} + +export async function getEIP721DomainObject(registry: RevocationRegistryInstance): Promise { + return { + name: 'Revocation Registry', + version: await registry.version(), + chainId: await web3.eth.getChainId(), + verifyingContract: registry.address, + }; +} + +export enum SignedFunction { + CHANGE_STATUS = "ChangeStatus", + CHANGE_STATUS_DELEGATED = "ChangeStatusDelegated", + CHANGE_STATUSES_IN_LIST = "ChangeStatusesInList", + CHANGE_STATUSES_IN_LIST_DELEGATED = "ChangeStatusesInListDelegated", + CHANGE_LIST_OWNER = "ChangeListOwner", + CHANGE_LIST_STATUS = "ChangeListStatus", + ADD_LIST_DELEGATE = "AddListDelegate", + REMOVE_LIST_DELEGATE = "RemoveListDelegate", +} + +// TODO: replace any with correct type and maybe throw it into the types-ts folder? +interface EIP712Params { + domain: any; + message: any; + primaryType: string; + types: any; +} + +export function generateEIP712Params(signedFunction: SignedFunction, domainObject: any, message: any) { + const params: EIP712Params = { + domain: domainObject, + message: message, + primaryType: "", + types: { + // TODO: Clarify if EIP712Domain refers to the domain the contract is hosted on + EIP712Domain: [ + {name: 'name', type: 'string'}, + {name: 'version', type: 'string'}, + {name: 'chainId', type: 'uint256'}, + {name: 'verifyingContract', type: 'address'}, + ] + }, + } + + switch (signedFunction) { + case SignedFunction.CHANGE_STATUS: + params.primaryType = "ChangeStatus"; + params.types.ChangeStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUS_DELEGATED: + params.primaryType = "ChangeStatusDelegated"; + params.types.ChangeStatusDelegated = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKey', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST: + params.primaryType = "ChangeStatusesInList"; + params.types.ChangeStatusesInList = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_STATUSES_IN_LIST_DELEGATED: + params.primaryType = "ChangeStatusesInListDelegated"; + params.types.ChangeStatusesInListDelegated = [ + {name: 'revoked', type: 'bool[]'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'revocationKeys', type: 'bytes32[]'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_OWNER: + params.primaryType = "ChangeListOwner"; + params.types.ChangeListOwner = [ + {name: 'namespace', type: 'address'}, + {name: 'newOwner', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.ADD_LIST_DELEGATE: + params.primaryType = "AddListDelegate"; + params.types.AddListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'validity', type: 'uint'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.REMOVE_LIST_DELEGATE: + params.primaryType = "RemoveListDelegate"; + params.types.RemoveListDelegate = [ + {name: 'namespace', type: 'address'}, + {name: 'delegate', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + break; + case SignedFunction.CHANGE_LIST_STATUS: + params.primaryType = "ChangeListStatus"; + params.types.ChangeListStatus = [ + {name: 'revoked', type: 'bool'}, + {name: 'namespace', type: 'address'}, + {name: 'revocationList', type: 'bytes32'}, + {name: 'signer', type: 'address'}, + {name: 'nonce', type: 'uint'}, + ] + } + return params; } \ No newline at end of file From 9201d29bd57f603cf695b90fe3555b1a5de71251 Mon Sep 17 00:00:00 2001 From: Dennis von der Bey Date: Thu, 15 Sep 2022 11:43:50 +0200 Subject: [PATCH 7/7] fix: readd not so redundant variable :D --- test/meta-transactions.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/meta-transactions.test.ts b/test/meta-transactions.test.ts index 1d3d1dc..5d0739b 100644 --- a/test/meta-transactions.test.ts +++ b/test/meta-transactions.test.ts @@ -29,7 +29,8 @@ contract("Meta Transaction", function (accounts) { beforeEach(async () => { const deployedProxy: any = await deployProxy(RevocationRegistry, []); - domainObject = await getEIP721DomainObject(deployedProxy) + registry = deployedProxy; + domainObject = await getEIP721DomainObject(registry) })