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

Add MetadataURL to account struct #1103

Merged
merged 6 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
26 changes: 26 additions & 0 deletions packages/protocol/contracts/identity/Attestations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ contract Attestations is IAttestations, Ownable, Initializable, UsingRegistry, R
bytes dataEncryptionKey
);

event AccountMetadataURLSet(
address indexed account,
string metadataURL
);

event AccountWalletAddressSet(
address indexed account,
address walletAddress
Expand Down Expand Up @@ -87,6 +92,9 @@ contract Attestations is IAttestations, Ownable, Initializable, UsingRegistry, R

// The ECDSA public key used to encrypt and decrypt data for this account
bytes dataEncryptionKey;

// The URL under which an account adds metadata and claims
string metadataURL;
}

// Stores attestations state for a single (identifier, account address) pair.
Expand Down Expand Up @@ -481,6 +489,24 @@ contract Attestations is IAttestations, Ownable, Initializable, UsingRegistry, R
emit AttestationExpirySecondsSet(_attestationExpirySeconds);
}

/**
* @notice Setter for the metadata of an account.
* @param metadataURL The URL to access the metadata.
*/
function setMetadataURL(string memory metadataURL) external {
accounts[msg.sender].metadataURL = metadataURL;
emit AccountMetadataURLSet(msg.sender, metadataURL);
}

/**
* @notice Getter for the metadata of an account.
* @param account The address of the account to get the metadata for.
* @return metdataURL The URL to access the metadata.
*/
function getMetadataURL(address account) external view returns (string memory) {
return accounts[account].metadataURL;
}

/**
* @notice Setter for the data encryption key and version.
* @param dataEncryptionKey secp256k1 public key for data encryption. Preferably compressed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ interface IAttestations {

// TODO: For some reason the compiler will complain about the next line
// function setAccountDataEncryptionKey(bytes) external;
// function setMetadataURL(string calldata) external;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler complained about non matching byte codee, same with setting the encryption key ...

function setWalletAddress(address) external;
function setAccount(bytes calldata, address) external;

function getDataEncryptionKey(address) external view returns (bytes memory);
function getWalletAddress(address) external view returns (address);

function getMetadataURL(address) external view returns (string memory);

function getAttestationRequestFee(address) external view returns (uint256);

Expand Down
19 changes: 19 additions & 0 deletions packages/protocol/test/identity/attestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract('Attestations', (accounts: string[]) => {
let mockValidators: MockValidatorsInstance
let registry: RegistryInstance
const provider = new Web3.providers.HttpProvider('http://localhost:8545')
const metadataURL = 'https://www.celo.org'
const web3: Web3 = new Web3(provider)
const phoneNumber: string = '+18005551212'
const caller: string = accounts[0]
Expand Down Expand Up @@ -773,4 +774,22 @@ contract('Attestations', (accounts: string[]) => {
assert.lengthOf(total, 0)
})
})

describe('#setMetadataURL', async () => {
it('should set the metadataURL', async () => {
await attestations.setMetadataURL(metadataURL)
const result = await attestations.getMetadataURL(caller)
assert.equal(result, metadataURL)
})

it('should emit the AccountMetadataURLSet event', async () => {
const response = await attestations.setMetadataURL(metadataURL)
assert.lengthOf(response.logs, 1)
const event = response.logs[0]
assertLogMatches2(event, {
event: 'AccountMetadataURLSet',
args: { account: caller, metadataURL },
})
})
})
})