Skip to content

Commit

Permalink
Merge pull request #19 from hicommonwealth/drew.idrename
Browse files Browse the repository at this point in the history
Drew.idrename: Renames identity functions, version bumps everything.
  • Loading branch information
jnaviask authored Jan 4, 2019
2 parents 50e06df + f1d4372 commit da41d98
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 200 deletions.
168 changes: 90 additions & 78 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edgeware"
version = "0.0.2"
version = "0.1.1"
authors = ["Commonwealth Labs <[email protected]>"]
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion modules/edge-delegation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edge-delegation"
version = "0.1.0"
version = "0.1.2"
authors = ["Drew Stone <[email protected]>"]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion modules/edge-governance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edge-governance"
version = "0.1.0"
version = "0.1.2"
authors = ["Jake Naviasky <[email protected]>, Drew Stone <[email protected]>"]

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion modules/edge-identity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edge-identity"
version = "0.1.1"
version = "0.1.2"
authors = ["Drew Stone <[email protected]>"]

[dependencies]
Expand Down
24 changes: 12 additions & 12 deletions modules/edge-identity/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait Trait: system::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}

pub type LinkedProof = Vec<u8>;
pub type Attestation = Vec<u8>;

#[cfg_attr(feature = "std", derive(Debug))]
#[derive(Encode, Decode, PartialEq)]
Expand All @@ -61,8 +61,8 @@ pub struct MetadataRecord {
#[derive(Encode, Decode, PartialEq)]
pub struct IdentityRecord<AccountId> {
pub account: AccountId,
pub attestation: Vec<u8>,
pub proof: Option<LinkedProof>,
pub identity: Vec<u8>,
pub proof: Option<Attestation>,
pub metadata: Option<MetadataRecord>,
}

Expand All @@ -78,9 +78,9 @@ decl_module! {
/// implementations could provide a mechanism for a trusted set of
/// authorities to delete a squatted identity OR implement storage
/// rent to disincentivize it.
pub fn attest(origin, attestation: Vec<u8>) -> Result {
pub fn register(origin, identity: Vec<u8>) -> Result {
let _sender = ensure_signed(origin)?;
let hash = T::Hashing::hash_of(&attestation);
let hash = T::Hashing::hash_of(&identity);

ensure!(!<IdentityOf<T>>::exists(hash), "Identity already exists");

Expand All @@ -90,12 +90,12 @@ decl_module! {

let record = IdentityRecord {
account: _sender.clone(),
attestation: attestation,
identity: identity,
proof: None,
metadata: None,
};
<IdentityOf<T>>::insert(hash, record);
Self::deposit_event(RawEvent::Attested(hash, _sender.into()));
Self::deposit_event(RawEvent::Register(hash, _sender.into()));
Ok(())
}

Expand All @@ -104,7 +104,7 @@ decl_module! {
///
/// Current implementation overwrites all proofs if safety checks
/// pass.
pub fn link(origin, identity_hash: T::Hash, proof_link: LinkedProof) -> Result {
pub fn attest(origin, identity_hash: T::Hash, attestation: Attestation) -> Result {
let _sender = ensure_signed(origin)?;
let record = <IdentityOf<T>>::get(&identity_hash).ok_or("Identity does not exist")?;

Expand All @@ -115,9 +115,9 @@ decl_module! {
// currently this implements no check against updating
// proof links
let mut new_record = record;
new_record.proof = Some(proof_link);
new_record.proof = Some(attestation);
<IdentityOf<T>>::insert(identity_hash, new_record);
Self::deposit_event(RawEvent::Linked(identity_hash, _sender.into()));
Self::deposit_event(RawEvent::Attest(identity_hash, _sender.into()));
Ok(())
}

Expand Down Expand Up @@ -187,8 +187,8 @@ decl_event!(
pub enum Event<T> where <T as system::Trait>::Hash,
<T as system::Trait>::AccountId,
<T as Trait>::Claim {
Attested(Hash, AccountId),
Linked(Hash, AccountId),
Register(Hash, AccountId),
Attest(Hash, AccountId),
AddedClaim(Hash, Claim, AccountId),
RemovedClaim(Hash, Claim, AccountId),
}
Expand Down
106 changes: 51 additions & 55 deletions modules/edge-identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,12 @@ mod tests {
t.into()
}

fn publish_identity_attestation(who: H256, attestation: &[u8]) -> super::Result {
Identity::attest(Origin::signed(who), attestation.to_vec())
fn register_identity(who: H256, identity: &[u8]) -> super::Result {
Identity::register(Origin::signed(who), identity.to_vec())
}

fn link_identity_with_proof(
who: H256,
identity_hash: H256,
proof_link: &[u8],
) -> super::Result {
Identity::link(Origin::signed(who), identity_hash, proof_link.to_vec())
fn attest_to_identity(who: H256, identity_hash: H256, attestation: &[u8]) -> super::Result {
Identity::attest(Origin::signed(who), identity_hash, attestation.to_vec())
}

fn add_metadata_to_account(
Expand Down Expand Up @@ -162,84 +158,84 @@ mod tests {
}

#[test]
fn propose_should_work() {
fn register_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);

let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

let public: H256 = pair.public().0.into();

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::identity(RawEvent::Attested(identity_hash, public))
event: Event::identity(RawEvent::Register(identity_hash, public))
}]
);
});
}

#[test]
fn propose_and_link_should_work() {
fn register_and_attest_should_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);

let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

let public: H256 = pair.public().0.into();

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));

let proof_link: &[u8] = b"www.proof.com/link_of_extra_proof";
assert_ok!(link_identity_with_proof(public, identity_hash, proof_link));
let attestation: &[u8] = b"www.proof.com/attest_of_extra_proof";
assert_ok!(attest_to_identity(public, identity_hash, attestation));
assert_eq!(
System::events(),
vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::identity(RawEvent::Attested(identity_hash, public))
event: Event::identity(RawEvent::Register(identity_hash, public))
},
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::identity(RawEvent::Linked(identity_hash, public))
event: Event::identity(RawEvent::Attest(identity_hash, public))
}
]
);
});
}

#[test]
fn link_without_publish_should_not_work() {
fn attest_without_register_should_not_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);

let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let public: H256 = pair.public().0.into();

let proof_link: &[u8] = b"www.proof.com/link_of_extra_proof";
let attestation: &[u8] = b"www.proof.com/attest_of_extra_proof";
assert_eq!(
link_identity_with_proof(public, identity_hash, proof_link),
attest_to_identity(public, identity_hash, attestation),
Err("Identity does not exist")
);
});
}

#[test]
fn link_from_different_account_should_not_work() {
fn attest_from_different_account_should_not_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);

Expand All @@ -249,15 +245,15 @@ mod tests {
let other: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f61"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let public: H256 = pair.public().0.into();
let other_pub: H256 = other.public().0.into();

assert_ok!(publish_identity_attestation(public, message));
let proof_link: &[u8] = b"www.proof.com/link_of_extra_proof";
assert_ok!(register_identity(public, identity));
let attestation: &[u8] = b"www.proof.com/attest_of_extra_proof";
assert_eq!(
link_identity_with_proof(other_pub, identity_hash, proof_link),
attest_to_identity(other_pub, identity_hash, attestation),
Err("Stored identity does not match sender")
);
});
Expand All @@ -270,16 +266,16 @@ mod tests {
let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

let public: H256 = pair.public().0.into();

let avatar: &[u8] = b"avatars3.githubusercontent.com/u/13153687";
let display_name: &[u8] = b"drewstone";
let tagline: &[u8] = b"hello world!";

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));
assert_ok!(add_metadata_to_account(
public,
identity_hash,
Expand All @@ -291,15 +287,15 @@ mod tests {
}

#[test]
fn add_metadata_without_publish_should_not_work() {
fn add_metadata_without_register_should_not_work() {
with_externalities(&mut new_test_ext(), || {
System::set_block_number(1);

let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let public: H256 = pair.public().0.into();

let avatar: &[u8] = b"avatars3.githubusercontent.com/u/13153687";
Expand All @@ -323,16 +319,16 @@ mod tests {
let other: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f61"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let public: H256 = pair.public().0.into();
let other_pub: H256 = other.public().0.into();

let avatar: &[u8] = b"avatars3.githubusercontent.com/u/13153687";
let display_name: &[u8] = b"drewstone";
let tagline: &[u8] = b"hello world!";

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));
assert_eq!(
add_metadata_to_account(other_pub, identity_hash, avatar, display_name, tagline),
Err("Stored identity does not match sender")
Expand All @@ -346,8 +342,8 @@ mod tests {
System::set_block_number(1);

let issuer = H256::from(1);
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let claim: &[u8] = b"is over 25 years of age";

assert_eq!(
Expand All @@ -366,8 +362,8 @@ mod tests {
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let public: H256 = pair.public().0.into();
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let claim: &[u8] = b"is over 25 years of age";

assert_eq!(
Expand All @@ -385,12 +381,12 @@ mod tests {
let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

let public: H256 = pair.public().0.into();

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));

let issuer = H256::from(1);
let claim: &[u8] = b"is over 25 years of age";
Expand All @@ -404,8 +400,8 @@ mod tests {
System::set_block_number(1);

let issuer = H256::from(1);
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

assert_eq!(
remove_claim_from_identity(issuer, identity_hash),
Expand All @@ -423,8 +419,8 @@ mod tests {
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let public: H256 = pair.public().0.into();
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());

assert_eq!(
remove_claim_from_identity(public, identity_hash),
Expand All @@ -441,11 +437,11 @@ mod tests {
let pair: Pair = Pair::from_seed(&hex!(
"9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"
));
let message: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&message.to_vec());
let identity: &[u8] = b"github.com/drewstone";
let identity_hash = BlakeTwo256::hash_of(&identity.to_vec());
let public: H256 = pair.public().0.into();

assert_ok!(publish_identity_attestation(public, message));
assert_ok!(register_identity(public, identity));

let issuer = H256::from(1);
let claim: &[u8] = b"is over 25 years of age";
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "edgeware-runtime"
version = "0.0.1"
version = "0.1.1"
authors = ["Commonwealth Labs <[email protected]>"]

[dependencies]
Expand Down
Loading

0 comments on commit da41d98

Please sign in to comment.