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

Commit

Permalink
fix: add docs for wrapping and signing of verifiable documents
Browse files Browse the repository at this point in the history
  • Loading branch information
MinHtet-O committed May 23, 2024
1 parent dca637e commit 4d75ee4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 24 deletions.
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@ 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 {
wrapDocumentV2,
signDocument,
isSignedWrappedV2Document,
SUPPORTED_SIGNING_ALGORITHM,
} from '@minhtetoo/tradetrust-core'

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

async function start() {
const wrappedDocument = wrapDocumentV2(document)
const signedDocument = await signDocument(
wrappedDocument,
SUPPORTED_SIGNING_ALGORITHM.Secp256k1VerificationKey2018,
{
public: 'did:ethr:<your_wallet_address>#controller',
private: '<your_private_key>',
}
)
// check is 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 @@ -69,9 +105,9 @@ It takes in array of Tradetrust v2 documents and returns the wrapped documents.

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.

#### `getData`
#### `getDataV2`

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

#### `diagnose`

Expand Down Expand Up @@ -114,6 +150,22 @@ It checks that the signature of the document corresponds to the actual content i

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.
4 changes: 2 additions & 2 deletions package-lock.json

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

37 changes: 17 additions & 20 deletions src/tradetrust/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,40 @@
// Import everything except utils from @tradetrust-tt/tradetrust
import {
SchemaId,
validateSchema,
utils,
type OpenAttestationDocument,
type WrappedDocument,
type SignedWrappedDocument,
v2,
v3,
OpenAttestationDocument,
SchemaId,
SUPPORTED_SIGNING_ALGORITHM,
validateSchema,
obfuscateDocument,
verifySignature,
signDocument,
SUPPORTED_SIGNING_ALGORITHM,
getData,
getData as getDataV2,
isSchemaValidationError,
wrapDocument as wrapDocumentV2,
WrappedDocument,
wrapDocuments as wrapDocumentsV2,
__unsafe__use__it__at__your__own__risks__wrapDocument as wrapDocumentV3,
wrapDocument as wrapDocumentV2,
__unsafe__use__it__at__your__own__risks__wrapDocuments as wrapDocumentsV3,
SignedWrappedDocument,
__unsafe__use__it__at__your__own__risks__wrapDocument as wrapDocumentV3,
} from '@tradetrust-tt/tradetrust'

// Re-export everything
export type { WrappedDocument, SignedWrappedDocument }
export {
SchemaId,
validateSchema,
utils,
v2,
v3,
OpenAttestationDocument,
obfuscateDocument,
verifySignature,
signDocument,
SUPPORTED_SIGNING_ALGORITHM,
getData,
getDataV2,
isSchemaValidationError,
wrapDocumentV2,
wrapDocumentV3,
WrappedDocument,
wrapDocumentsV2,
wrapDocumentV2,
wrapDocumentsV3,
SignedWrappedDocument,
wrapDocumentV3,
v2,
v3,
SchemaId,
SUPPORTED_SIGNING_ALGORITHM,
}
2 changes: 2 additions & 0 deletions src/utils/tradetrust/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
isSignedWrappedV2Document,
isWrappedV3Document,
isSignedWrappedV3Document,
isRawV2Document,
isRawV3Document,
isObfuscated,
getDocumentData,
Expand All @@ -22,6 +23,7 @@ export {
isSignedWrappedV2Document,
isWrappedV3Document,
isSignedWrappedV3Document,
isRawV2Document,
isRawV3Document,
isObfuscated,
getDocumentData,
Expand Down

0 comments on commit 4d75ee4

Please sign in to comment.