Skip to content

Commit

Permalink
Merge pull request #23 from filip26/feat/iron-14
Browse files Browse the repository at this point in the history
v0.14.0
  • Loading branch information
filip26 authored Feb 28, 2024
2 parents adfea44 + 66bc676 commit 1a741e6
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 115 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/java17-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish JRE17 to the Maven Central
on:
release:
types: [created]

workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
environment: maven-central
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: ossrh
- name: Import GPG Key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Publish package
run: mvn -B -Pmaven-central -Dgpg.passphrase=${{secrets.MAVEN_GPG_PASSPHRASE}} -s maven-central-settings.xml deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/java8-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish JRE8 to the Maven Central
on:
release:
types: [created]

workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
environment: maven-central
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
server-id: ossrh
- name: Import GPG Key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
- name: Publish package
run: mvn -f pom_jre8.xml -B -Pmaven-central -Dgpg.passphrase=${{secrets.MAVEN_GPG_PASSPHRASE}} -s maven-central-settings.xml deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
105 changes: 57 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ An implementation of the [W3C ECDSA RDFC 2019](https://www.w3.org/TR/vc-di-ecdsa

## Features
* [W3C ECDSA Signature 2019](https://www.w3.org/TR/vc-di-ecdsa/)
* Verifying VC/VP
* Issuing VC/VP
* Verifier, Issuer,
* Key pair generator
* P-256 (secp256r1), P-384 (secp384r1)
* [VC HTTP API & Service](https://github.com/filip26/iron-vc-api)
Expand All @@ -26,13 +25,13 @@ Java 17+
<dependency>
<groupId>com.apicatalog</groupId>
<artifactId>iron-ecdsa-rdfc-2019</artifactId>
<version>0.11.0</version>
<version>0.14.0</version>
</dependency>

<dependency>
<groupId>com.apicatalog</groupId>
<artifactId>iron-verifiable-credentials</artifactId>
<version>0.11.0</version>
<version>0.14.0</version>
</dependency>
```

Expand All @@ -41,67 +40,77 @@ Java 17+
Android 12+ (API Level 31+)

```gradle
compile group: 'com.apicatalog', name: 'iron-ecdsa-rdfc-2019-jre8', version: '0.11.0'
compile group: 'com.apicatalog', name: 'iron-verifiable-credentials-jre8', version: '0.11.0'
implementation("com.apicatalog:iron-ecdsa-rdfc-2019-jre8:0.14.0")
implementation("com.apicatalog:iron-verifiable-credentials-jre8:0.14.0")
```

## Documentation

[![javadoc](https://javadoc.io/badge2/com.apicatalog/iron-ecdsa-rdfc-2019/javadoc.svg)](https://javadoc.io/doc/com.apicatalog/iron-ecdsa-rdfc-2019)

## Usage

### Verifying
### Verifier

```javascript
// create a new verifier instance
static Verifier VERIFIER = Verifier.with(new ECDSASignature2019())
// options
.loader(...)
.statusValidator(...)
.subjectValidator(...);

```java
try {
Vc.verify(credential|presentation, new ECDSASignature2019())

// optional
.base(...)
.loader(documentLoader)
.statusVerifier(...)
.useBundledContexts(true|false)

// custom | suite specific | parameters
.param(DataIntegrity.DOMAIN.name(), ....)

// assert document validity
.isValid();

} catch (VerificationError | DataError e) {
// verify the given input proof(s)
var verifiable = VERIFIER.verify(credential|presentation);

// or with runtime parameters e.g. domain, challenge, etc.
var verifiable = VERIFIER.verify(credential|presentation, parameters);

// get verified details
verifiable.subject()
verifiable.id()
verifiable.type()
// ...

} catch (VerificationError | DocumentError e) {
...
}

```

### Issuing

```java
var suite = new ECDSASignature2019();
### Issuer

var proofDraft = suite.createP256Draft(
verificationMethod,
purpose,
created,
// optional
domain,
challenge
);
```javascript

Vc.sign(credential|presentation, keys, proofDraft)
// create a signature suite static instance
static SignatureSuite SUITE = new ECDSASignature2019();

// optional
.base(...)
.loader(documentLoader)
.statusVerifier(...)
.useBundledContexts(true|false)
// create a new issuer instance
Issuer ISSUER = SUITE.createIssuer(keyPairProvider)
// options
.loader(...);

try {
// create a new proof draft using P-256
var proofDraft = SUITE.createP256Draft(verificationMethod, purpose);
// or P-384
var proofDraft = SUITE.createP384Draft(verificationMethod, purpose);

// set custom options
proofDraft.created(...);
proofDraft.domain(...);
...

// return signed document in a compacted form
.getCompacted();
// issue a new verifiable, i.e. sign the input and add a new proof
var verifiable = ISSUER.sign(credential|presentation, proofDraft).compacted();

} catch (SigningError | DocumentError e) {
...
}

```

## Documentation

[![javadoc](https://javadoc.io/badge2/com.apicatalog/iron-ecdsa-rdfc-2019/javadoc.svg)](https://javadoc.io/doc/com.apicatalog/iron-ecdsa-rdfc-2019)

## Contributing

All PR's welcome!
Expand Down Expand Up @@ -134,4 +143,4 @@ Fork and clone the project repository.

## Commercial Support
Commercial support is available at filip26@gmail.com
.

12 changes: 12 additions & 0 deletions maven-central-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>ossrh</id>
<username>${env.MAVEN_USERNAME}</username>
<password>${env.MAVEN_PASSWORD}</password>
</server>
</servers>
</settings>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>ecdsa-rdfc-2019</artifactId>
<version>0.11.0</version>
<version>0.14.0</version>
<relativePath>pom_parent.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion pom_jre8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>ecdsa-rdfc-2019</artifactId>
<version>0.11.0</version>
<version>0.14.0</version>
<relativePath>pom_parent.xml</relativePath>
</parent>

Expand Down
12 changes: 6 additions & 6 deletions pom_parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.apicatalog</groupId>
<artifactId>ecdsa-rdfc-2019</artifactId>
<version>0.11.0</version>
<version>0.14.0</version>
<packaging>pom</packaging>

<name>Iron ECDSA RDFC 2019 Signature Suite</name>
Expand Down Expand Up @@ -55,7 +55,7 @@
<carbon.version>0.3.0</carbon.version>
<copper-base.version>0.5.0</copper-base.version>
<copper-codec.version>0.1.1</copper-codec.version>
<iron.version>0.11.0</iron.version>
<iron.version>0.14.0</iron.version>

<jakarta.json.version>2.0.1</jakarta.json.version>

Expand Down Expand Up @@ -188,10 +188,10 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<flattenMode>oss</flattenMode>
</configuration>
<version>1.3.0</version>
<configuration>
<flattenMode>ossrh</flattenMode>
</configuration>
<executions>
<!-- enable flattening -->
<execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package com.apicatalog.ld.signature.ecdsa;

import java.net.URI;
import java.time.Instant;

import com.apicatalog.jsonld.loader.DocumentLoader;
import com.apicatalog.ld.DocumentError;
import com.apicatalog.ld.DocumentError.ErrorType;
import com.apicatalog.ld.signature.CryptoSuite;
import com.apicatalog.ld.signature.VerificationMethod;
import com.apicatalog.ld.signature.ecdsa.BCECDSASignatureProvider.CurveType;
import com.apicatalog.ld.signature.key.KeyPair;
import com.apicatalog.ld.signature.primitive.MessageDigest;
import com.apicatalog.ld.signature.primitive.Urdna2015;
import com.apicatalog.multibase.Multibase;
import com.apicatalog.multicodec.Multicodec;
import com.apicatalog.multicodec.MulticodecDecoder;
import com.apicatalog.multicodec.codec.KeyCodec;
import com.apicatalog.multikey.MultiKey;
import com.apicatalog.multikey.MultiKeyAdapter;
import com.apicatalog.vc.integrity.DataIntegrityProof;
import com.apicatalog.vc.integrity.DataIntegrityProofDraft;
import com.apicatalog.vc.integrity.DataIntegritySuite;
import com.apicatalog.vc.issuer.Issuer;
import com.apicatalog.vc.method.MethodAdapter;
import com.apicatalog.vc.proof.ProofValue;
import com.apicatalog.vc.solid.SolidIssuer;
import com.apicatalog.vc.solid.SolidProofValue;

public final class ECDSASignature2019 extends DataIntegritySuite {

Expand Down Expand Up @@ -68,45 +74,61 @@ protected void validate(MultiKey method) throws DocumentError {
};

public ECDSASignature2019() {
super(CRYPTOSUITE_NAME, METHOD_ADAPTER);
super(CRYPTOSUITE_NAME, Multibase.BASE_58_BTC, METHOD_ADAPTER);
}

public DataIntegrityProof createP256Draft(
public DataIntegrityProofDraft createP256Draft(
VerificationMethod verificationMethod,
URI purpose,
Instant created,
String domain,
String challenge) throws DocumentError {
return super.createDraft(CRYPTO_256, verificationMethod, purpose, created, domain, challenge);
URI purpose) throws DocumentError {
return new DataIntegrityProofDraft(this, CRYPTO_256, verificationMethod, purpose);
}

public DataIntegrityProof createP384Draft(
public DataIntegrityProofDraft createP256Draft(
URI verificationMethod,
URI purpose) throws DocumentError {
return new DataIntegrityProofDraft(this, CRYPTO_256, verificationMethod, purpose);
}

public DataIntegrityProofDraft createP384Draft(
VerificationMethod verificationMethod,
URI purpose,
Instant created,
String domain,
String challenge) throws DocumentError {
return super.createDraft(CRYPTO_384, verificationMethod, purpose, created, domain, challenge);
URI purpose) throws DocumentError {
return new DataIntegrityProofDraft(this, CRYPTO_384, verificationMethod, purpose);
}

public DataIntegrityProofDraft createP384Draft(
URI verificationMethod,
URI purpose) throws DocumentError {
return new DataIntegrityProofDraft(this, CRYPTO_384, verificationMethod, purpose);
}

@Override
protected CryptoSuite getCryptoSuite(String cryptoName, byte[] proofValue) throws DocumentError {
if (proofValue != null) {
if (proofValue.length == 64) {
return CRYPTO_256;
}
if (proofValue.length == 96) {
return CRYPTO_384;
}
}
return CRYPTO_256;
public Issuer createIssuer(KeyPair keyPair) {
return new SolidIssuer(this, keyPair, proofValueBase);
}

@Override
protected void validateProofValue(byte[] proofValue) throws DocumentError {
protected ProofValue getProofValue(byte[] proofValue, DocumentLoader loader) throws DocumentError {
if (proofValue != null && proofValue.length != 64 && proofValue.length != 96) {
throw new DocumentError(ErrorType.Invalid, "ProofValueLenght");
}
return new SolidProofValue(proofValue);
}

@Override
protected CryptoSuite getCryptoSuite(String cryptoName, ProofValue proofValue) throws DocumentError {

if (proofValue != null) {
final byte[] value = ((SolidProofValue) proofValue).toByteArray();
if (value != null) {
if (value.length == 64) {
return CRYPTO_256;
}
if (value.length == 96) {
return CRYPTO_384;
}
}
}
return CRYPTO_256;
}

}
Loading

0 comments on commit 1a741e6

Please sign in to comment.