Skip to content

Commit

Permalink
Candidate 0.4.1 (#305)
Browse files Browse the repository at this point in the history
* feat: added sourcify-verify

* chore: remove stub empty line

* fix: πŸ› issue#276 fix. Added eip712 domain validations

βœ… Closes: #276

* docs: ✏️ removed commented code, added comment to explain undef

* fix: πŸ› add getters/setters for EIP712 params

* ci: 🎑 trigger tn CI after prerelease

* test: adding dumping of generated material for tests in attestation.jar (#283)

* test: implemented an object dumber and updated java tests to write object dumps, along with handling linter feedback on the touched files

* ci: 🎑 trigger tn CI after prerelease

Co-authored-by: Tore Kasper Frederiksen <[email protected]>
Co-authored-by: Feng Yu <[email protected]>

* bug: added domain validation to AttestationUsage and AttestationRequestWUsage (#285)

* ci: 🎑 trigger tn CI after prerelease

* test: adding dumping of generated material for tests in attestation.jar (#283)

* test: implemented an object dumber and updated java tests to write object dumps, along with handling linter feedback on the touched files

* ci: 🎑 trigger tn CI after prerelease

Co-authored-by: Tore Kasper Frederiksen <[email protected]>
Co-authored-by: Feng Yu <[email protected]>

* bug: added domain validation to AttestationUsage and AttestationRequestWUsage

* fix: πŸ› issue#276 fix. Added eip712 domain validations

βœ… Closes: #276

* docs: ✏️ removed commented code, added comment to explain undef

* fix: πŸ› add getters/setters for EIP712 params

Co-authored-by: Feng Yu <[email protected]>
Co-authored-by: Tore Kasper Frederiksen <[email protected]>
Co-authored-by: Oleh Hryb <[email protected]>

* fix: added domain validation to AttestationRequestWithUsage and AttestationUsage

* fix: πŸ› asn_decoding fix(patch), attestation timestamp check (#273)

Added patch to fix ASN1_schema bug for Integers, added Attestation
validate timestamp

* fix: fixed integration tests with attested object (#290)

Co-authored-by: Tore Kasper Frederiksen <[email protected]>

* fix: updated peculiar asn1 to latest version which contains the fix that is otherwise included in the patch (#294)

Co-authored-by: Tore Kasper Frederiksen <[email protected]>

* feat: signature-based UN and possibility of adding context to UN (#284)

* feat: wrote a UN based on signature and refactored things to allow an optional context for both MAC-based UNs and signature-based UNs

* test: adding dumping of generated material for tests in attestation.jar (#283)

* test: implemented an object dumber and updated java tests to write object dumps, along with handling linter feedback on the touched files

* ci: 🎑 trigger tn CI after prerelease

Co-authored-by: Tore Kasper Frederiksen <[email protected]>
Co-authored-by: Feng Yu <[email protected]>

* feat: wrote a UN based on signature and refactored things to allow an optional context for both MAC-based UNs and signature-based UNs

* docs: added comments

* fix: made some fixes and tried to get a consistent version working between TS and Java

* fix: updated java code to be able to integration test JS generated UNs

* fix: updated JS code to be able to integration test with java generated UNs and added tests

* Removed unnneeded test

* test: updated tests and ensured consistent and deterministic code when needed

* test: updated and expanded integration tests to ensure consistency with Java implementation

* fix: fixed issues related to deterministic keys

* test: fixed missing references in js test

* fix: fixed directory typo

Co-authored-by: Feng Yu <[email protected]>

* feat: ✨ safeconnect (#279)

* docs(core): adding asn1 draft for nftownership attestation and ethereum linking attestation

* docs(core): adding asn1 draft for nftownership attestation and ethereum linking attestation in asd format as well

* docs(core): fixed typos in old asd format

* docs(core): updates description to reuse old type for erc721 token

* docs(core): updated asn format description after discussion with Miccy

* docs(core): fixed bug in old asn1 notation

* docs(core): updated asd format too

* refactor:core refactored representation of erc721 tokens to fit with what we also need

* feat(core): added first draft of signed NFT Ownership Attestation

* test(core): added sunshine tests to signed NFT Ownership Attestation

* Draft JS schemas.

* Bump version - JS patch release 0.3.8

* fix(core): updated format to match the new format from Miccy

* Update JS schemas for safe connect.

* feat(core) added draft of ethereum key link attestation along with refactoring

* fix(core) added missing file

* feat(core) added draft of ethereum address attestation

* refactor(core) removed redundant decoder code

* test(core) added test to ownership attestations

* test(core) added test to key linking attestation

* Fixes for node.js support

- Fix window debug ENV check.
- Fix uint8array to base64 encoding.

* refactor: refactoring and improved testing

* test: added more testing along with file writing and reading of test data

* fix: changed to assume the issuer uses Ethereum keys and refactored OID identification

* fix: updated failing tests

* Migrate safe connect attestation and verification code WIP.

* Migrate safe connect attestation and verification code WIP.

* Migrate safe connect attestation and verification code WIP.

* Fix parsing

* Add validity checking & optional parameter validFrom.

* feat: move smart contract

* chore: Refactor test attestations to be generated using javascript lib.

* chore: Add javascript lib tests

* feature: NFT Attestation solidity library

* chore: Add test mint contract & fix attestation validity issues with tests.

* fix: added missing tag to java version

* fix: added fixes to get the MVP integration working

* test: added integration test for JS safeconnect version

* feature: JS context & various other enhancements

- Add optional context field to Javascript attestation creation.
- Move signing function to AbstractLinkedAttestation.
- Add multi-token support to JS NFT attestation creation.
- Implement test to validate Java attestation in Javascript.
- Add method to get linked attestation data from EthereumKeyLinkingAttestation.

* chore: Bump JS pre-release version to 0.3.9-sc.3

* test: added more safeconnect integration tests

* test: added integration test of JS with Java

* test: added console printing of right value

* fix: missing NFT_ADDRESS variable in test

* test: enable JS -> Java test

* feat: made chainID mandatory on ERC721 tokens

* fix: make github CI/CD pass

* fix: added schema for address linking

* refactor: improved variable naming

* feat: added support for array of tokens in java version

* feature: multi-token ID support for JS and solidity library.

* refactor: changed format of Erc721 token to have IDs at the end and always store things as an array

* test: updated java test

* chore: bump version

* fix: silly bug :-(

* fix: context field type

* test: added test for context

* test: added test for context

* fix: issuer keys being overwritten when provided in base64/PEM format
feat: return attested object in validateUseTicket function.

* fix: remove temporary patch for asn1-schema integer parsing issue

ref: ae8c45b updated peculiar asn1
to latest version which contains the fix that is otherwise included
in the patch (#294).

Co-authored-by: Michael Wallace <[email protected]>
Co-authored-by: snowwhitedev <[email protected]>

* update contracts to use standard ERC721 and in-line library to reduce gas cost. Also update tests in line with these changes (#292)

* Various fixes & enhancements for Devcon use cases (#297)

* feature: validateUseTicket - allow validation to skip ethAddress check.

Allow skipping of ethereum address by explicitly passing null
as userEthKey value.

* Bump version for devcon release

* Bump version for devcon release

* feature: add getDevconId function to Ticket class

* build: updated dependencies

* build: updated dependencies

* build: updated version

* build: updated version

* Devcon (#299)

* feature: validateUseTicket - allow validation to skip ethAddress check.

Allow skipping of ethereum address by explicitly passing null
as userEthKey value.

* Bump version for devcon release

* Bump version for devcon release

* feature: add getDevconId function to Ticket class

* feature: allow multiple keys for validation of a single conference ID

* fix/disabled blockchain enabled tests (#303)

* build: upgraded dependencies

* fix: πŸ› hotfix - updated @types/node

* Fix/breaking change erc721 (#304)

* fix: changes to use a legacy format for ERC721 for legacy alchemy NFT tokens

* fix: added missing file

* fix: fix javascript to also use legacy format in the legacy setting

* build: updated versions

* fix: reversal experiment to appease github actions

* fix: second attempt

* build: updated non-breaking dependencies

* fix: changed access of ERC721

* fix: πŸ› hotfix - updated @types/node

Co-authored-by: Oleh Hryb <[email protected]>

Co-authored-by: snowwhitedev <[email protected]>
Co-authored-by: oleggrib <[email protected]>
Co-authored-by: Feng Yu <[email protected]>
Co-authored-by: Michael Wallace <[email protected]>
Co-authored-by: James Brown <[email protected]>
  • Loading branch information
6 people authored Nov 17, 2022
1 parent dbeb1f2 commit 1b06bfd
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ You can always use this project in your own code through Maven central, by addin
<dependency>
<groupId>org.tokenscript</groupId>
<artifactId>attestation</artifactId>
<version>0.4</version>
<version>0.4.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ task testJavaScript(type: NodeTask) {

group = 'org.tokenscript'
archivesBaseName = 'attestation'
version = '0.4'
version = '0.4.1'

/** See https://docs.gradle.org/current/userguide/publishing_maven.html for details
* For actually updating the Maven repo update the version reference in README.md,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.alchemynft.attestation;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.alphawallet.ethereum.AttestationReturn;
import com.alphawallet.token.tools.Numeric;
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.tokenscript.attestation.ERC721Token;
import org.tokenscript.attestation.IdentifierAttestation;
import org.tokenscript.attestation.SignedIdentifierAttestation;
import org.tokenscript.attestation.core.SignatureUtility;
Expand Down Expand Up @@ -84,8 +88,9 @@ public void checkNFTSmartContract() throws Exception
assertTrue(atr.isValid);
for (int index = 0; index < atr.ercToken.length; index++)
{
assertEquals(atr.ercToken[index].address.toString().toLowerCase(), myNFTs[index].getAddress().toLowerCase());
assertEquals(atr.ercToken[index].tokenId.getValue(), myNFTs[index].getTokenIds().get(0));
assertEquals(atr.ercToken[index].address.toString().toLowerCase(),
myNFTs[index].getAddress().toLowerCase());
assertEquals(atr.ercToken[index].tokenId.getValue(), myNFTs[index].getTokenId());
}

//TODO: make a more comprehensive negative test, involving bad attestation subject address etc.
Expand Down
103 changes: 103 additions & 0 deletions src/main/java/io/alchemynft/attestation/ERC721Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package io.alchemynft.attestation;

import java.io.IOException;
import java.math.BigInteger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.tokenscript.attestation.core.ASNEncodable;
import org.tokenscript.attestation.core.ExceptionUtil;
import org.web3j.utils.Numeric;

/**
* Legacy class only used in Alchemy nft attestation. For any other use, use ERC721Token from
* org.tokenscript.attestation
*/
@Deprecated
public class ERC721Token implements ASNEncodable {

private static final Logger logger = LogManager.getLogger(ERC721Token.class);

private final byte[] encoding;
private final String address;
private final BigInteger tokenId;

public ERC721Token(String address, String tokenId) {
this.address = address.toLowerCase();
BigInteger tokenIdInteger;
try {
tokenIdInteger = new BigInteger(tokenId);
} catch (Exception e) {
tokenIdInteger = BigInteger.ZERO;
}
validateID(tokenIdInteger);
this.tokenId = tokenIdInteger;
this.encoding = constructEncoding();
}

public ERC721Token(String address, BigInteger tokenId) {
this.address = address.toLowerCase();
validateID(tokenId);
this.tokenId = tokenId;
this.encoding = constructEncoding();
}

public ERC721Token(byte[] derEncoding) throws IOException {
ASN1InputStream input = null;
try {
input = new ASN1InputStream(derEncoding);
ASN1Sequence asn1 = ASN1Sequence.getInstance(input.readObject());
ASN1OctetString address = DEROctetString.getInstance(asn1.getObjectAt(0));
ASN1OctetString tokenId = DEROctetString.getInstance(asn1.getObjectAt(1));
// Remove the # added by BouncyCastle
this.address = address.toString().substring(1);
this.tokenId = new BigInteger(1, tokenId.getOctets());
this.encoding = constructEncoding();
} finally {
input.close();
}
}

private void validateID(BigInteger tokenId) {
// Only allow non-negative IDs
if (tokenId.compareTo(BigInteger.ZERO) < 0) {
throw ExceptionUtil.throwException(logger,
new IllegalArgumentException("IDs cannot be negative"));
}
}

public String getAddress() {
return address;
}

public BigInteger getTokenId() {
return tokenId;
}


@Override
public byte[] getDerEncoding() {
return encoding;
}

byte[] constructEncoding() {
ASN1EncodableVector data = getTokenVector();
try {
return new DERSequence(data).getEncoded();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public ASN1EncodableVector getTokenVector() {
ASN1EncodableVector data = new ASN1EncodableVector();
data.add(new DEROctetString(Numeric.hexStringToByteArray(address)));
data.add(new DEROctetString(tokenId.toByteArray()));
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.bouncycastle.crypto.util.PublicKeyFactory;
import org.tokenscript.attestation.AttestedKeyObject;
import org.tokenscript.attestation.ERC721Token;
import org.tokenscript.attestation.SignedIdentifierAttestation;
import org.tokenscript.attestation.core.ExceptionUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import org.tokenscript.attestation.ERC721Token;
import org.tokenscript.attestation.ObjectDecoder;
import org.tokenscript.attestation.SignedIdentifierAttestation;

Expand Down
6 changes: 3 additions & 3 deletions src/main/javascript/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokenscript/attestation",
"version": "0.3.9-dc.4",
"version": "0.4.1",
"description": "A library for integrating cryptographic attestations into applications",
"type": "commonjs",
"main": "dist/index.js",
Expand Down Expand Up @@ -29,7 +29,7 @@
"@types/chai": "^4.3.4",
"@types/jest": "^27.5.2",
"@types/mocha": "^8.2.3",
"@types/node": "^17.0.45",
"@types/node": "^18.11.9",
"@types/pvutils": "^1.0.1",
"assert": "^2.0.0",
"buffer": "^6.0.3",
Expand All @@ -43,7 +43,7 @@
"ts-loader": "^9.4.1",
"ts-mockito": "^2.6.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"typescript": "^4.9.3",
"webpack": "^5.75.0",
"webpack-cli": "^4.10.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.tokenscript.attestation.ERC721Token;
import org.tokenscript.attestation.HelperTest;
import org.tokenscript.attestation.IdentifierAttestation;
import org.tokenscript.attestation.SignedIdentifierAttestation;
Expand Down

2 comments on commit 1b06bfd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report for src/main/javascript/crypto/

St.❔
Category Percentage Covered / Total
🟑 Statements 74.56% 2178/2921
πŸ”΄ Branches 47.43% 286/603
🟑 Functions 79.46% 383/482
🟑 Lines 74.77% 2137/2858

Test suite run success

56 tests passing in 2 suites.

Report generated by πŸ§ͺjest coverage report action from 1b06bfd

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage report for src/main/javascript/crypto/

St.❔
Category Percentage Covered / Total
🟑 Statements 74.53% 2177/2921
πŸ”΄ Branches 47.26% 285/603
🟑 Functions 79.46% 383/482
🟑 Lines 74.74% 2136/2858

Test suite run success

56 tests passing in 2 suites.

Report generated by πŸ§ͺjest coverage report action from 1b06bfd

Please sign in to comment.