Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

fix: migrate tt utils modules to core #4

Merged
merged 18 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INFURA_API_KEY=
OKLINK_API_KEY=
STABILITY_API_KEY=
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm ci --ignore-scripts
- run: npm ci
- run: npm run lint

commit-lint:
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ dist/

# Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# OS generated files
.DS_Store
Expand Down
102 changes: 55 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,88 @@
# TradeTrust Core

Unified interface for interacting with TradeTrust's various services. This library contains a set of modules.

| Module | Description |
| ----------------- | ------------------------------------------------------ |
| [Verify](#verify) | Verify TradeTrust issued document |
| [Utils](#utils) | Provide utility methods for TradeTrust functionalities |
Unified interface for interacting with TradeTrust's various services such as document verification and validation of the fragments. This library contains a set of modules.

## Installation

```sh
npm i @tradetrust-tt/tradetrust-core
```

## Verify

`verify` allows you to verify issued document programmatically. After verification, use `isValid` method to answer some questions:

- Has the document been tampered with ?
- Is the issuance state of the document valid ?
- Is the document issuer identity valid ? (see [identity proof](https://docs.tradetrust.io/docs/topics/verifying-documents/issuer-identity))
## Basic Usage

Document can be either [verifiable document](https://docs.tradetrust.io/docs/tutorial/verifiable-documents/overview) or [transferrable record](https://docs.tradetrust.io/docs/tutorial/transferable-records/overview) which follows [TradeTrust document schema](https://docs.tradetrust.io/docs/topics/introduction/tradetrust-document-schema/)
This example provides how to verify tradetrust document using your own provider configurations.

```ts
// verify document using network name
import { verify, isValid } from '@tradetrust-tt/tradetrust-core/verify'
let document = {
// your tradetrust document
}
const fragments = await verify(document, {
network: 'sepolia', // can also provide other networks such as homestead
})
console.log(isValid(fragments))
```

```ts
// verify document using provider
import { ethers } from 'ethers'
import { utils } from '@tradetrust-tt/tt-verify'
import {
verify,
isValid,
interpretFragments,
generateProvider,
providerType,
} from '@tradetrust-tt/tradetrust-core'

const providerOptions = {
// modify your provider options accordingly
network: 'sepolia',
providerType: 'infura',
apiKey: 'abdfddsfe23232',
providerType: 'infura' as providerType,
apiKey: 'your-api-key',
}
const provider = utils.generateProvider(providerOptions)
// create provider object
const provider = generateProvider(providerOptions)

let document = {
// your tradetrust document
// tradetrust document
} as any

async function start() {
const fragments = await verify(document, { provider })

// to check the overall validity of the document
console.log(isValid(fragments))

// to check if the document has not been modified, has been issued and has valid issuer identity
const { hashValid, issuedValid, identityValid } =
interpretFragments(fragments)
console.log({ hashValid, issuedValid, identityValid })
}
const fragments = await verify(document, { provider })
console.log(isValid(fragments))

start()
```

## Methods

tradetrust-core provides the following methods for document verification and validations.

#### `generateProvider`

It generates receives provider options and returns the ethereum JSON RPC provider to be used for [verify](#verify) method.

#### `verify`

It allows you to verify wrapped/ issued document programmatically. Upon successful verification, it will return fragments which would collectively prove the validity of the document.

Document can be either [verifiable document](https://docs.tradetrust.io/docs/tutorial/verifiable-documents/overview) or [transferrable record](https://docs.tradetrust.io/docs/tutorial/transferable-records/overview) which follows [TradeTrust document schema](https://docs.tradetrust.io/docs/topics/introduction/tradetrust-document-schema/)

For more information about building provider, visit [tt-verify repository](https://github.com/TradeTrust/tt-verify?tab=readme-ov-file#provider)

## Utils
#### `isValid`

This module provides utility methods that supports the shared functionalities for other TradeTrust modules.
It will execute over fragments, returned from [verify](#verify) method and determine if the fragments produced a valid result. The function will return true if a document fulfill the following conditions:

#### InterpretFragments
The document has not been tampered, and
The document has been issued, and
The document has not been revoked, and
The issuer identity is valid.

`interpretFragments` allows you to extract out the verified results from the fragments.
#### `interpretFragments`

```ts
import {interpretFragments} from '@tradetrust-tt/tradetrust-core/utils`;
It allows you to extract out the verified results from the fragments.

const fragments = await verify(document, {
network: 'sepolia',
});
After verification, use `isValid` method to answer some questions:

const {hasValid, issuedValid, identityValid} = interpretFragments(fragments);
console.log({hasValid, issuedValid, identityValid});
```
- Has the document been tampered with ?
- Is the issuance state of the document valid ?
- Is the document issuer identity valid ? (see [identity proof](https://docs.tradetrust.io/docs/topics/verifying-documents/issuer-identity))

## Contributing

Expand Down
13 changes: 13 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require('@nomiclabs/hardhat-ethers')

module.exports = {
networks: {
hardhat: {
chainId: 1337,
accounts: {
mnemonic:
'indicate swing place chair flight used hammer soon photo region volume shuffle',
},
},
},
}
Loading
Loading