Skip to content

Commit

Permalink
Use blockchainAccountId VM id with did:pkh:eip155
Browse files Browse the repository at this point in the history
  • Loading branch information
clehner committed Sep 16, 2021
1 parent aceb3ed commit 26cd7c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
40 changes: 26 additions & 14 deletions did-pkh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ async fn resolve_tezos(did: &str, account_address: String, reference: &str) -> R
resolution_result(doc)
}

async fn resolve_eip155(did: &str, account_address: String, reference: &str) -> ResolutionResult {
async fn resolve_eip155(
did: &str,
account_address: String,
reference: &str,
legacy: bool,
) -> ResolutionResult {
if !account_address.starts_with("0x") {
return resolution_error(&ERROR_INVALID_DID);
}
Expand All @@ -149,9 +154,16 @@ async fn resolve_eip155(did: &str, account_address: String, reference: &str) ->
reference: reference.to_string(),
},
};
let vm_fragment = if legacy {
// Explanation of fragment differences:
// https://github.com/spruceid/ssi/issues/297
"Recovery2020"
} else {
"blockchainAccountId"
};
let vm_url = DIDURL {
did: did.to_string(),
fragment: Some("Recovery2020".to_string()),
fragment: Some(vm_fragment.to_string()),
..Default::default()
};
let vm = VerificationMethod::Map(VerificationMethodMap {
Expand Down Expand Up @@ -363,7 +375,7 @@ async fn resolve_caip10(did: &str, account_id: String) -> ResolutionResult {
let reference = account_id.chain_id.reference;
match &namespace[..] {
"tezos" => resolve_tezos(did, account_id.account_address, &reference).await,
"eip155" => resolve_eip155(did, account_id.account_address, &reference).await,
"eip155" => resolve_eip155(did, account_id.account_address, &reference, false).await,
"bip122" => resolve_bip122(did, account_id.account_address, &reference).await,
"solana" => resolve_solana(did, account_id.account_address, &reference).await,
_ => return resolution_error(&ERROR_INVALID_DID),
Expand All @@ -386,9 +398,9 @@ impl DIDResolver for DIDPKH {
match &type_[..] {
// Non-CAIP-10 (deprecated)
"tz" => resolve_tezos(did, data, REFERENCE_TEZOS_MAINNET).await,
"eth" => resolve_eip155(did, data, REFERENCE_EIP155_ETHEREUM_MAINNET).await,
"celo" => resolve_eip155(did, data, REFERENCE_EIP155_CELO_MAINNET).await,
"poly" => resolve_eip155(did, data, REFERENCE_EIP155_POLYGON_MAINNET).await,
"eth" => resolve_eip155(did, data, REFERENCE_EIP155_ETHEREUM_MAINNET, true).await,
"celo" => resolve_eip155(did, data, REFERENCE_EIP155_CELO_MAINNET, true).await,
"poly" => resolve_eip155(did, data, REFERENCE_EIP155_POLYGON_MAINNET, true).await,
"sol" => resolve_solana(did, data, REFERENCE_SOLANA_MAINNET).await,
"btc" => resolve_bip122(did, data, REFERENCE_BIP122_BITCOIN_MAINNET).await,
"doge" => resolve_bip122(did, data, REFERENCE_BIP122_DOGECOIN_MAINNET).await,
Expand Down Expand Up @@ -1024,8 +1036,8 @@ mod tests {
credential_prove_verify_did_pkh(
key_secp256k1_recovery.clone(),
other_key_secp256k1.clone(),
"eth",
"#Recovery2020",
"eip155",
"#blockchainAccountId",
&ssi::ldp::EcdsaSecp256k1RecoverySignature2020,
None,
None,
Expand All @@ -1036,8 +1048,8 @@ mod tests {
credential_prove_verify_did_pkh(
key_secp256k1_eip712sig.clone(),
other_key_secp256k1.clone(),
"eth",
"#Recovery2020",
"eip155",
"#blockchainAccountId",
&ssi::ldp::Eip712Signature2021,
None,
None,
Expand Down Expand Up @@ -1132,8 +1144,8 @@ mod tests {
credential_prove_verify_did_pkh(
key_secp256k1_eip712sig.clone(),
other_key_secp256k1.clone(),
"eth",
"#Recovery2020",
"eip155",
"#blockchainAccountId",
&ssi::ldp::EthereumEip712Signature2021,
Some(eip712_domain),
Some(vp_eip712_domain),
Expand All @@ -1144,8 +1156,8 @@ mod tests {
credential_prove_verify_did_pkh(
key_secp256k1_epsig.clone(),
other_key_secp256k1.clone(),
"eth",
"#Recovery2020",
"eip155",
"#blockchainAccountId",
&ssi::ldp::Eip712Signature2021,
None,
None,
Expand Down
6 changes: 3 additions & 3 deletions did-pkh/tests/did-celo.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"id": "did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011",
"verificationMethod": [
{
"id": "did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#Recovery2020",
"id": "did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#blockchainAccountId",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011",
"blockchainAccountId": "eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011"
}
],
"authentication": [
"did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#Recovery2020"
"did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#blockchainAccountId"
],
"assertionMethod": [
"did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#Recovery2020"
"did:pkh:eip155:42220:0xa0ae58da58dfa46fa55c3b86545e7065f90ff011#blockchainAccountId"
]
}
6 changes: 3 additions & 3 deletions did-pkh/tests/did-eth.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"id": "did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a",
"verificationMethod": [
{
"id": "did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#Recovery2020",
"id": "did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#blockchainAccountId",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a",
"blockchainAccountId": "eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a"
}
],
"authentication": [
"did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#Recovery2020"
"did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#blockchainAccountId"
],
"assertionMethod": [
"did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#Recovery2020"
"did:pkh:eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a#blockchainAccountId"
]
}
6 changes: 3 additions & 3 deletions did-pkh/tests/did-poly.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"id": "did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5",
"verificationMethod": [
{
"id": "did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#Recovery2020",
"id": "did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#blockchainAccountId",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5",
"blockchainAccountId": "eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5"
}
],
"authentication": [
"did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#Recovery2020"
"did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#blockchainAccountId"
],
"assertionMethod": [
"did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#Recovery2020"
"did:pkh:eip155:137:0x4e90e8a8191c1c23a24a598c3ab4fb47ce926ff5#blockchainAccountId"
]
}

0 comments on commit 26cd7c5

Please sign in to comment.