-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from Concordium/web3Id-proof
Add function to create web3Id proof
- Loading branch information
Showing
24 changed files
with
636 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule concordium-base
updated
39 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/AccountCommitmentInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import java.util.Map; | ||
|
||
import com.concordium.sdk.responses.accountinfo.credential.AttributeType; | ||
import com.concordium.sdk.types.UInt32; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@JsonTypeName("account") | ||
public class AccountCommitmentInput extends CommitmentInput { | ||
private UInt32 issuer; | ||
private Map<AttributeType,String> values; | ||
private Map<AttributeType, String> randomness; | ||
} |
13 changes: 13 additions & 0 deletions
13
concordium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/CommitmentInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY; | ||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
|
||
|
||
@JsonTypeInfo(use = NAME, include = PROPERTY, property = "type") | ||
@JsonSubTypes ({@Type (value = AccountCommitmentInput.class), @Type (value = Web3IssuerCommitmentInput.class)}) | ||
public abstract class CommitmentInput {} |
77 changes: 77 additions & 0 deletions
77
...ordium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/CredentialAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@JsonSerialize(using = CredentialAttribute.CredentialAttributeTypeSerializer.class) | ||
@JsonDeserialize(using = CredentialAttribute.CredentialAttributieTypeDeserializer.class) | ||
@Builder | ||
@Getter | ||
public class CredentialAttribute { | ||
enum CredentialAttributeType { | ||
INT, | ||
STRING, | ||
TIMESTAMP; | ||
} | ||
|
||
private String value; | ||
private CredentialAttributeType type; | ||
|
||
static class CredentialAttributieTypeDeserializer extends JsonDeserializer<CredentialAttribute> { | ||
|
||
@Override | ||
public CredentialAttribute deserialize(JsonParser p, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
JsonNode reference = p.getCodec().readTree(p); | ||
if (reference.isNumber()) { | ||
return new CredentialAttribute(reference.asText(), CredentialAttributeType.INT); | ||
} else if (reference.isTextual()) { | ||
return new CredentialAttribute(reference.asText(), CredentialAttributeType.STRING); | ||
} else if (reference.has("type") && reference.get("type").asText().equals("date-time") | ||
&& reference.has("timestamp")) { | ||
return new CredentialAttribute(reference.get("timestamp").asText(), CredentialAttributeType.TIMESTAMP); | ||
} | ||
throw new JsonParseException(p, "Instantiation of Web3IdAtttribute failed due to invalid structure"); | ||
} | ||
} | ||
|
||
static class CredentialAttributeTypeSerializer extends JsonSerializer<CredentialAttribute> { | ||
@Override | ||
public void serialize(CredentialAttribute value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
switch (value.getType()) { | ||
case INT: | ||
gen.writeNumber(value.getValue()); | ||
break; | ||
case STRING: | ||
gen.writeString(value.getValue()); | ||
break; | ||
case TIMESTAMP: | ||
gen.writeStartObject(); | ||
gen.writeStringField("type", "date-time"); | ||
gen.writeStringField("timestamp", value.getValue()); | ||
gen.writeEndObject(); | ||
break; | ||
default: | ||
// The switch already covers every case of the given type, so this should never | ||
// happen | ||
throw new RuntimeException("Unreachable, invalid CredentialAttributeType: " + value.getType()); | ||
} | ||
} | ||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
concordium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Request.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import java.util.List; | ||
|
||
import com.concordium.sdk.crypto.wallet.web3Id.Statement.RequestStatement; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
public class Request { | ||
private final String challenge; | ||
private final List<RequestStatement> credentialStatements; | ||
} |
16 changes: 16 additions & 0 deletions
16
...-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/AtomicStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes.Type; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME; | ||
|
||
@JsonTypeInfo(use = NAME, include = As.PROPERTY, property = "type", visible = true) | ||
@JsonSubTypes ({@Type (value = RevealStatement.class), @Type (value = RangeStatement.class), @Type (value = MembershipStatement.class), @Type (value = NonMembershipStatement.class)}) | ||
public abstract class AtomicStatement { | ||
@JsonProperty("attributeTag") | ||
public abstract String getAttributeTag(); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/MembershipStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import java.util.List; | ||
|
||
import com.concordium.sdk.crypto.wallet.web3Id.CredentialAttribute; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
@JsonTypeName("AttributeInSet") | ||
public class MembershipStatement extends AtomicStatement { | ||
private String attributeTag; | ||
private List<CredentialAttribute> set; | ||
} |
15 changes: 15 additions & 0 deletions
15
...c/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/NonMembershipStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import java.util.List; | ||
|
||
import com.concordium.sdk.crypto.wallet.web3Id.CredentialAttribute; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
@JsonTypeName("AttributeNotInSet") | ||
public class NonMembershipStatement extends AtomicStatement { | ||
private String attributeTag; | ||
private List<CredentialAttribute> set; | ||
} |
19 changes: 19 additions & 0 deletions
19
...m-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/RangeStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import com.concordium.sdk.crypto.wallet.web3Id.CredentialAttribute; | ||
import com.concordium.sdk.responses.accountinfo.credential.AttributeType; | ||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@JsonTypeName("AttributeInRange") | ||
@Getter | ||
@Builder | ||
@Jacksonized | ||
public class RangeStatement extends AtomicStatement { | ||
private CredentialAttribute lower; | ||
private CredentialAttribute upper; | ||
private String attributeTag; | ||
} |
16 changes: 16 additions & 0 deletions
16
...sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/RequestStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
public class RequestStatement { | ||
private String id; | ||
private List<String> type; | ||
private List<AtomicStatement> statement; | ||
} |
11 changes: 11 additions & 0 deletions
11
...-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Statement/RevealStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id.Statement; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
@JsonTypeName("RevealAttribute") | ||
public class RevealStatement extends AtomicStatement { | ||
private String attributeTag; | ||
} |
36 changes: 36 additions & 0 deletions
36
concordium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Web3IdProof.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import com.concordium.sdk.crypto.CryptoJniNative; | ||
import com.concordium.sdk.crypto.NativeResolver; | ||
import com.concordium.sdk.crypto.wallet.StringResult; | ||
import com.concordium.sdk.exceptions.CryptoJniException; | ||
import com.concordium.sdk.serializing.JsonMapper; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
public class Web3IdProof { | ||
// Static block to load native library. | ||
static { | ||
NativeResolver.loadLib(); | ||
} | ||
|
||
/** | ||
* Creates a Presentation of a web3IdProof. | ||
* @param input the input required to generate the Presentiation | ||
* @return a Presentation serialized as JSON | ||
*/ | ||
public static String getWeb3IdProof(Web3IdProofInput input) { | ||
StringResult result = null; | ||
try { | ||
String jsonStr = CryptoJniNative.createWeb3IdProof(JsonMapper.INSTANCE.writeValueAsString(input)); | ||
result = JsonMapper.INSTANCE.readValue(jsonStr, StringResult.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
if (!result.isSuccess()) { | ||
throw CryptoJniException.from(result.getErr()); | ||
} | ||
|
||
return result.getResult(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
concordium-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Web3IdProofInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import java.util.List; | ||
|
||
import com.concordium.sdk.responses.cryptographicparameters.CryptographicParameters; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
/** | ||
* The data needed to create a web3Id Presentation. | ||
*/ | ||
@Getter | ||
@Builder | ||
@Jacksonized | ||
public class Web3IdProofInput { | ||
private final Request request; | ||
private final List<CommitmentInput> commitmentInputs; | ||
private final CryptographicParameters globalContext; | ||
} |
20 changes: 20 additions & 0 deletions
20
...-sdk/src/main/java/com/concordium/sdk/crypto/wallet/web3Id/Web3IssuerCommitmentInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.concordium.sdk.crypto.wallet.web3Id; | ||
|
||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Getter | ||
@Builder | ||
@Jacksonized | ||
@JsonTypeName("web3Issuer") | ||
public class Web3IssuerCommitmentInput extends CommitmentInput { | ||
private String signature; | ||
private String signer; | ||
private Map<String, CredentialAttribute> values; | ||
private Map<String, String> randomness; | ||
} |
Oops, something went wrong.