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

Commit

Permalink
fix: export methods and types from tradetrust-tt/tradetrust (#8)
Browse files Browse the repository at this point in the history
* fix: export functions & types from tradetrust-tt/tradetrust

* docs: add methods from tradetrust/tradetrust to README for docs

* fix: add docs for wrapping and signing of verifiable documents

* fix: remove wrappedV2 and wrappedV3 document methods
  • Loading branch information
MinHtet-O authored May 27, 2024
1 parent 1b3aa0f commit 510820a
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 6 deletions.
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@ npm i @tradetrust-tt/tradetrust-core

## Basic Usage

#### Wrapping and Signing of verifiable document

This example provides how to sign tradetrust wrapped verifiable document, as well as a public/private key pair or an [Ethers.js Signer](https://docs.ethers.io/v5/api/signer/).
Replace `<your_wallet_address>` and `<your_private_key>` with your actual wallet address and private key.

```ts
import {
wrapDocumentsV2,
signDocument,
isSignedWrappedV2Document,
SUPPORTED_SIGNING_ALGORITHM,
} from '@tradetrust-tt/tradetrust-core'

const document = {
// raw v2 document with dns-did as identitify proof
} as any

async function start() {
const wrappedDocuments = wrapDocumentsV2([document])
const wrappedDocument = wrappedDocuments[0]

const signedDocument = await signDocument(
wrappedDocument,
SUPPORTED_SIGNING_ALGORITHM.Secp256k1VerificationKey2018,
{
public: 'did:ethr:<your_wallet_address>#controller',
private: '<your_private_key>',
}
)
// check if the document has already wrapped and signed
console.log(isSignedWrappedV2Document(signedDocument))
}

start()
```

#### Verifying

This example provides how to verify tradetrust document using your own provider configurations.

```ts
Expand Down Expand Up @@ -57,6 +95,30 @@ tradetrust-core provides the following methods for document verification and val

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

#### `wrapDocumentsV2`

It takes in array of Tradetrust v2 documents and returns the wrapped documents.

#### `wrapDocumentsV3`

It takes in array of Tradetrust v3 documents and returns the wrapped documents.

#### `obfuscateDocument`

It removes a key-value pair from the document's data section, without causing the file hash to change. This can be used to generate a new document containing a subset of the original data, yet allow the recipient to proof the provenance of the document.

#### `getDataV2`

It returns the original data stored in the Tradetrust v2 document, in a readable format.

#### `diagnose`

Tool to find out why a document is not a valid open attestation file (wrapped or signed document)

#### `signDocument`

It takes a wrapped document, a wallet (public and private key pair) or an Ethers.js Signer. The method will sign the merkle root from the wrapped document, append the signature to the document and return it. Currently, it supports `Secp256k1VerificationKey2018` sign algorithm.

#### `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.
Expand Down Expand Up @@ -84,6 +146,28 @@ After verification, use `isValid` method to answer some questions:
- 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))

#### `verifySignature`

It checks that the signature of the document corresponds to the actual content in the document. In addition, it checks that the target hash (hash of the document content), is part of the set of documents wrapped in the batch using the proofs.

Note that this method does not check against the blockchain or any registry if this document has been published. The merkle root of this document need to be checked against a publicly accessible document store (can be a smart contract on the blockchain).

#### `isWrappedV2Document`

type guard for wrapped v2 document

#### `isSignedWrappedV2Document`

type guard for signed v2 document

#### `isWrappedV3Document`

type guard for wrapped v3 document

#### `isSignedWrappedV3Document`

type guard for signed v3 document

## Contributing

We welcome contributions to the TradeTrust core library. Please feel free to submit a pull request or open an issue.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@
"utils/provider": [
"./dist/types/utils/provider/index.d.ts"
],
"utils/tradetrust": [
"./dist/types/utils/tradetrust/index.d.ts"
],
"verify": [
"./dist/types/verify/index.d.ts"
],
"tradetrust": [
"./dist/types/tradetrust/index.d.ts"
]
}
},
Expand Down Expand Up @@ -73,9 +79,17 @@
"require": "./dist/cjs/utils/provider/index.js",
"import": "./dist/esm/utils/provider/index.js"
},
"./utils/tradetrust": {
"require": "./dist/cjs/utils/tradetrust/index.js",
"import": "./dist/esm/utils/tradetrust/index.js"
},
"./verify": {
"require": "./dist/cjs/verify/index.js",
"import": "./dist/esm/verify/index.js"
},
"./tradetrust": {
"require": "./dist/cjs/tradetrust/index.js",
"import": "./dist/esm/tradetrust/index.js"
}
},
"author": "tradetrust",
Expand Down Expand Up @@ -109,7 +123,7 @@
"url": "https://github.com/TradeTrust/tradetrust-core.git"
},
"dependencies": {
"@tradetrust-tt/tradetrust": "^6.9.0",
"@tradetrust-tt/tradetrust": "^6.9.5",
"@tradetrust-tt/tt-verify": "^8.9.2"
},
"publishConfig": {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './verify'
export * from './utils'
export * from './tradetrust'
36 changes: 36 additions & 0 deletions src/tradetrust/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Import everything except utils from @tradetrust-tt/tradetrust
import {
type OpenAttestationDocument,
type WrappedDocument,
type SignedWrappedDocument,
v2,
v3,
SchemaId,
SUPPORTED_SIGNING_ALGORITHM,
validateSchema,
obfuscateDocument,
verifySignature,
signDocument,
getData as getDataV2,
isSchemaValidationError,
wrapDocuments as wrapDocumentsV2,
__unsafe__use__it__at__your__own__risks__wrapDocuments as wrapDocumentsV3,
} from '@tradetrust-tt/tradetrust'

// Re-export everything
export type { WrappedDocument, SignedWrappedDocument }
export {
validateSchema,
OpenAttestationDocument,
obfuscateDocument,
verifySignature,
signDocument,
getDataV2,
isSchemaValidationError,
wrapDocumentsV2,
wrapDocumentsV3,
v2,
v3,
SchemaId,
SUPPORTED_SIGNING_ALGORITHM,
}
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as CONSTANTS from './constants/VerificationErrorMessages'
export * from './fragement'
export * from './analytics'
import * as CONSTANTS from './constants/VerificationErrorMessages'
export * from './constants/supportedChains'
export * from './provider/provider'
export * from './tradetrust'

export { CONSTANTS }
34 changes: 34 additions & 0 deletions src/utils/tradetrust/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { utils } from '@tradetrust-tt/tradetrust'
import type { DiagnoseError } from '@tradetrust-tt/tradetrust/dist/types/shared/utils'

const {
isTransferableAsset,
getAssetId,
isWrappedV2Document,
isSignedWrappedV2Document,
isWrappedV3Document,
isSignedWrappedV3Document,
isRawV2Document,
isRawV3Document,
isObfuscated,
getDocumentData,
getIssuerAddress,
diagnose,
} = utils

export {
isTransferableAsset,
getAssetId,
isWrappedV2Document,
isSignedWrappedV2Document,
isWrappedV3Document,
isSignedWrappedV3Document,
isRawV2Document,
isRawV3Document,
isObfuscated,
getDocumentData,
getIssuerAddress,
diagnose,
}

export type { DiagnoseError }

0 comments on commit 510820a

Please sign in to comment.