-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yodaplus/stability-changes
Stability changes
- Loading branch information
Showing
10 changed files
with
3,843 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,98 @@ | ||
import { CHAIN_ID } from "@govtechsg/tradetrust-utils/constants/supportedChains"; | ||
// import { CHAIN_ID } from "@govtechsg/tradetrust-utils/constants/supportedChains"; | ||
|
||
import { v4 as uuid } from "uuid"; | ||
import { generateEncryptionKey } from "@govtechsg/oa-encryption"; | ||
|
||
import { | ||
validateNetwork, | ||
validateDocument, | ||
getEncryptedDocument, | ||
validateNetwork, | ||
validateDocument, | ||
getEncryptedDocument, | ||
} from "../../utils"; | ||
import { s3Put } from "../../services/s3"; | ||
import { SUPPORTED_NETWORKS } from "../../constants"; | ||
import { s3Get } from "../../services/s3"; | ||
import * as dotenv from "dotenv"; | ||
import { generateEncryptionKey } from "@govtechsg/oa-encryption"; | ||
import { CHAIN_ID } from "@tradetrust-tt/tradetrust-utils/constants/supportedChains"; | ||
dotenv.config(); | ||
|
||
export const getDocument = async (id: string) => { | ||
const document = await s3Get({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
}); | ||
const document = await s3Get({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
}); | ||
|
||
return document; | ||
return document; | ||
}; | ||
|
||
export const uploadDocument = async (document) => { | ||
console.log("start"); | ||
// @ts-ignore | ||
const { chainId } = await validateNetwork(document); | ||
console.log("chainId", chainId); | ||
await validateDocument({ | ||
document, | ||
network: SUPPORTED_NETWORKS[chainId as CHAIN_ID].name, | ||
}); | ||
console.log("uploadDocVerified"); | ||
const { encryptedDocument, encryptedDocumentKey } = | ||
await getEncryptedDocument({ | ||
str: JSON.stringify(document), | ||
}); | ||
console.log("uploadDoc", encryptedDocument, encryptedDocumentKey); | ||
const id = uuid(); | ||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
Body: JSON.stringify({ document: encryptedDocument }), | ||
}); | ||
console.log("start"); | ||
// @ts-ignore | ||
const { chainId } = await validateNetwork(document); | ||
console.log("chainId", chainId); | ||
await validateDocument({ | ||
document, | ||
network: SUPPORTED_NETWORKS[chainId as CHAIN_ID].name, | ||
}); | ||
console.log("uploadDocVerified"); | ||
const { encryptedDocument, encryptedDocumentKey } = | ||
await getEncryptedDocument({ | ||
str: JSON.stringify(document), | ||
}); | ||
console.log("uploadDoc", encryptedDocument, encryptedDocumentKey); | ||
const id = uuid(); | ||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
Body: JSON.stringify({ document: encryptedDocument }), | ||
}); | ||
|
||
return { | ||
id, | ||
key: encryptedDocumentKey, | ||
type: encryptedDocument.type, | ||
}; | ||
return { | ||
id, | ||
key: encryptedDocumentKey, | ||
type: encryptedDocument.type, | ||
}; | ||
}; | ||
|
||
export const uploadDocumentAtId = async (document, documentId: string) => { | ||
// @ts-ignore | ||
const { chainId } = await validateNetwork(document); | ||
console.log("check in uploadDocAtId", chainId); | ||
await validateDocument({ | ||
document, | ||
network: SUPPORTED_NETWORKS[chainId as CHAIN_ID].name, | ||
}); | ||
console.log("check in uploadDocAtId validated?"); | ||
const { key: existingKey } = await getDocument(documentId); | ||
const { encryptedDocument, encryptedDocumentKey } = | ||
await getEncryptedDocument({ | ||
str: JSON.stringify(document), | ||
existingKey, | ||
}); | ||
// @ts-ignore | ||
const { chainId } = await validateNetwork(document); | ||
console.log("check in uploadDocAtId", chainId); | ||
await validateDocument({ | ||
document, | ||
network: SUPPORTED_NETWORKS[chainId as CHAIN_ID].name, | ||
}); | ||
console.log("check in uploadDocAtId validated?"); | ||
const { key: existingKey } = await getDocument(documentId); | ||
const { encryptedDocument, encryptedDocumentKey } = | ||
await getEncryptedDocument({ | ||
str: JSON.stringify(document), | ||
existingKey, | ||
}); | ||
|
||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: documentId, | ||
Body: JSON.stringify({ document: encryptedDocument }), | ||
}); | ||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: documentId, | ||
Body: JSON.stringify({ document: encryptedDocument }), | ||
}); | ||
|
||
return { | ||
id: documentId, | ||
key: encryptedDocumentKey, | ||
type: encryptedDocument.type, | ||
}; | ||
return { | ||
id: documentId, | ||
key: encryptedDocumentKey, | ||
type: encryptedDocument.type, | ||
}; | ||
}; | ||
|
||
export const getQueueNumber = async () => { | ||
const id = uuid(); | ||
const encryptionKey = generateEncryptionKey(); | ||
const id = uuid(); | ||
const encryptionKey = generateEncryptionKey(); | ||
|
||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
Body: JSON.stringify({ | ||
key: encryptionKey, | ||
}), | ||
}); | ||
await s3Put({ | ||
Bucket: process.env.TT_AWS_BUCKET_NAME, | ||
Key: id, | ||
Body: JSON.stringify({ | ||
key: encryptionKey, | ||
}), | ||
}); | ||
|
||
return { key: encryptionKey, id }; | ||
return { key: encryptionKey, id }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
import express, { Request, Response } from "express"; | ||
import { networkName } from "@govtechsg/tradetrust-utils/constants/network"; | ||
import { isValid } from "@govtechsg/oa-verify"; | ||
// import { networkName } from "@govtechsg/tradetrust-utils/constants/network"; | ||
import { networkName } from "@tradetrust-tt/tradetrust-utils/constants/network"; | ||
|
||
import { validateDocument } from "../../utils"; | ||
import { isValid } from "@tradetrust-tt/tt-verify"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/", async (req: Request, res: Response) => { | ||
const { | ||
body: { document }, | ||
query: { network = "mainnet" }, | ||
} = req; | ||
const { | ||
body: { document }, | ||
query: { network = "mainnet" }, | ||
} = req; | ||
|
||
try { | ||
console.log("start /"); | ||
const fragments = await validateDocument({ | ||
document, | ||
network: network as networkName, | ||
}); | ||
res.status(200).json({ | ||
summary: { | ||
all: isValid(fragments), | ||
documentStatus: isValid(fragments, ["DOCUMENT_STATUS"]), | ||
documentIntegrity: isValid(fragments, ["DOCUMENT_INTEGRITY"]), | ||
issuerIdentity: isValid(fragments, ["ISSUER_IDENTITY"]), | ||
}, | ||
fragments, | ||
}); | ||
} catch (err) { | ||
res.status(400).json(err); | ||
} | ||
try { | ||
console.log("start /"); | ||
const fragments = await validateDocument({ | ||
document, | ||
network: network as networkName, | ||
}); | ||
res.status(200).json({ | ||
summary: { | ||
all: isValid(fragments), | ||
documentStatus: isValid(fragments, ["DOCUMENT_STATUS"]), | ||
documentIntegrity: isValid(fragments, ["DOCUMENT_INTEGRITY"]), | ||
issuerIdentity: isValid(fragments, ["ISSUER_IDENTITY"]), | ||
}, | ||
fragments, | ||
}); | ||
} catch (err) { | ||
res.status(400).json(err); | ||
} | ||
}); | ||
|
||
export { router }; |
Oops, something went wrong.