Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solidity test - with signature test - working #59

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Solidity test - with signature test - working
Delegate and Attribute complete
closes #56
  • Loading branch information
jac18281828 committed Oct 3, 2023
commit 578a628db242bb048f1967c06faeb6bad3a4a9e7
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "packages/did-eth-registry/lib/forge-std"]
path = packages/did-eth-registry/lib/forge-std
url = https://github.com/foundry-rs/forge-std
branch = v1.6.1
7 changes: 7 additions & 0 deletions packages/did-eth-registry/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -7,6 +7,13 @@
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"JuanBlanco.solidity"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
2 changes: 0 additions & 2 deletions packages/did-eth-registry/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.git/
jac18281828 marked this conversation as resolved.
Show resolved Hide resolved
cache/
artifacts/
lib/
build/
typechain/
typechain-types/
6 changes: 6 additions & 0 deletions packages/did-eth-registry/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"juanblanco.solidity"
]
}
93 changes: 93 additions & 0 deletions packages/did-eth-registry/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "preinstall",
"type": "shell",
"command": "forge install",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build"
}
},
{
"label": "install",
"type": "shell",
"command": "yarn install --frozen-lockfile",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "preinstall",
"group": {
"kind": "build"
}
},
{
"label": "prettier",
"type": "shell",
"command": "yarn prettier:check",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "install",
"group": {
"kind": "build"
}
},
{
"label": "lint",
"type": "shell",
"command": "yarn lint",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "prettier",
"group": {
"kind": "build"
}
},
{
"label": "build",
"type": "shell",
"command": "forge build --sizes",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "test",
"type": "shell",
"command": "forge test -vvv",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "gas",
"type": "shell",
"command": "forge test --gas-report",
"options": {
"cwd": "${workspaceFolder}"
},
"dependsOn": "lint",
"group": {
"kind": "test",
"isDefault": false
}
}
]
}
4 changes: 2 additions & 2 deletions packages/did-eth-registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ COPY --chown=did:did . .
RUN yarn install --frozen-lockfile
RUN yarn prettier:check
RUN yarn lint
RUN yarn build
RUN yarn test
RUN forge test -v
RUN forge geiger --check contracts/*.sol

USER did
31 changes: 28 additions & 3 deletions packages/did-eth-registry/README.md
Original file line number Diff line number Diff line change
@@ -304,6 +304,30 @@ needed. The list of delegateTypes to include is still to be determined.
Iterate through `DIDAttributeChanged` events for service entries, encrypted public keys, and other public names. The
attribute names are still to be determined.

## Quick Start

### Submodules

First, init submodules from the project root

```bash
$ git submodule update --recursive --init -f
```

### Registry Development

This contract supports containerized development. From Visual Studio Code Remote Containers extension

`Reopen in Container`

or

Command line build using docker

```bash
$ docker build packages/did-eth-registry -t did-eth:1
```

## Deploy contract

First run,
@@ -324,7 +348,8 @@ Once this funding transaction is confirmed, simply send the `rawTx` to the same
## Testing the Contracts

```bash
yarn install
yarn build
yarn test
$ yarn install --frozen-lockfile
$ yarn prettier:check
$ yarn lint
$ forge test -v
```
24 changes: 12 additions & 12 deletions packages/did-eth-registry/contracts/EthereumDIDRegistry.sol
Original file line number Diff line number Diff line change
@@ -44,9 +44,9 @@ contract EthereumDIDRegistry {
uint8 sigV,
bytes32 sigR,
bytes32 sigS,
bytes32 hash
bytes32 digest
mirceanis marked this conversation as resolved.
Show resolved Hide resolved
) internal returns (address) {
address signer = ecrecover(hash, sigV, sigR, sigS);
address signer = ecrecover(digest, sigV, sigR, sigS);
require(signer == identityOwner(identity), "bad_signature");
nonce[signer]++;
return signer;
@@ -82,7 +82,7 @@ contract EthereumDIDRegistry {
bytes32 sigS,
address newOwner
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
@@ -93,7 +93,7 @@ contract EthereumDIDRegistry {
newOwner
)
);
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, hash), newOwner);
changeOwner(identity, checkSignature(identity, sigV, sigR, sigS, digest), newOwner);
}

function addDelegate(
@@ -126,7 +126,7 @@ contract EthereumDIDRegistry {
address delegate,
uint256 validity
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
@@ -139,7 +139,7 @@ contract EthereumDIDRegistry {
validity
)
);
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate, validity);
addDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate, validity);
}

function revokeDelegate(
@@ -169,7 +169,7 @@ contract EthereumDIDRegistry {
bytes32 delegateType,
address delegate
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
@@ -181,7 +181,7 @@ contract EthereumDIDRegistry {
delegate
)
);
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, hash), delegateType, delegate);
revokeDelegate(identity, checkSignature(identity, sigV, sigR, sigS, digest), delegateType, delegate);
}

function setAttribute(
@@ -213,7 +213,7 @@ contract EthereumDIDRegistry {
bytes memory value,
uint256 validity
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
@@ -226,7 +226,7 @@ contract EthereumDIDRegistry {
validity
)
);
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value, validity);
setAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value, validity);
}

function revokeAttribute(
@@ -255,7 +255,7 @@ contract EthereumDIDRegistry {
bytes32 name,
bytes memory value
) public {
bytes32 hash = keccak256(
bytes32 digest = keccak256(
abi.encodePacked(
bytes1(0x19),
bytes1(0),
@@ -267,6 +267,6 @@ contract EthereumDIDRegistry {
value
)
);
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, hash), name, value);
revokeAttribute(identity, checkSignature(identity, sigV, sigR, sigS, digest), name, value);
}
}
2 changes: 1 addition & 1 deletion packages/did-eth-registry/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[profile.default]
src = "contracts"
out = "out"
libs = ["node_modules"]
libs = ["node_modules", "lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 1 addition & 0 deletions packages/did-eth-registry/lib/forge-std
Submodule forge-std added at 1d9650
5 changes: 2 additions & 3 deletions packages/did-eth-registry/scripts/submitDeployTxs.js
Original file line number Diff line number Diff line change
@@ -5,14 +5,13 @@ const { Transaction } = require('ethereumjs-tx')
const EthUtils = require('ethereumjs-util')
const ls = require('ls')
const path = require('path')
const ethers = require('ethers')

const gasLimits = {
EthereumDIDRegistry: 2811144, // If this value needs to be recalculated, it can be done by deploying the rawTx once and looking at gasUsed in the receipt
}

const generateDeployTx = (code, name) => {
console.log("go gen.")
console.log('go gen.')
const rawTx = {
nonce: 0,
gasPrice: 100000000000, // 100 Gwei
@@ -21,7 +20,7 @@ const generateDeployTx = (code, name) => {
data: code,
v: 27,
r: '0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798',
s: '0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
s: '0x0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
}
const tx = new Transaction(rawTx)
const res = {
Loading