From cc42bcede593f698f54417a8e1f91d467085f1ad Mon Sep 17 00:00:00 2001 From: Nebulis Date: Wed, 11 Dec 2019 18:42:01 +0800 Subject: [PATCH] feat: upgrade to open attestation v2 --- package-lock.json | 71 ++++++++++++------- package.json | 8 +-- .../smartContract/documentToSmartContracts.ts | 37 ++++++++-- .../smartContract/issuerToSmartContract.ts | 5 +- src/index.ts | 8 +-- .../contractInterface.integration.test.ts | 32 +++++++-- src/issued/verify.test.ts | 6 +- src/issued/verify.ts | 4 +- .../contractInterface.integration.test.ts | 40 ++++++++--- src/revoked/verify.test.ts | 6 +- src/revoked/verify.ts | 4 +- src/types.ts | 6 -- test/fixtures/document.ts | 7 +- test/fixtures/documentMainnetValid.ts | 7 +- test/fixtures/documentRopstenValid.ts | 7 +- test/fixtures/tampered-document.ts | 7 +- test/fixtures/tokenRopstenInvalid.ts | 19 ++++- test/fixtures/tokenRopstenValid.ts | 19 ++++- 18 files changed, 203 insertions(+), 90 deletions(-) diff --git a/package-lock.json b/package-lock.json index 56bd0d32..a35425eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1532,6 +1532,12 @@ "@babel/types": "^7.3.0" } }, + "@types/eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", + "dev": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -1570,6 +1576,12 @@ "integrity": "sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA==", "dev": true }, + "@types/json-schema": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz", + "integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==", + "dev": true + }, "@types/minimatch": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz", @@ -1612,32 +1624,45 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.6.0.tgz", - "integrity": "sha512-U224c29E2lo861TQZs6GSmyC0OYeRNg6bE9UVIiFBxN2MlA0nq2dCrgIVyyRbC05UOcrgf2Wk/CF2gGOPQKUSQ==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.13.0.tgz", + "integrity": "sha512-WQHCozMnuNADiqMtsNzp96FNox5sOVpU8Xt4meaT4em8lOG1SrOv92/mUbEHQVh90sldKSfcOc/I0FOb/14G1g==", "dev": true, "requires": { - "@typescript-eslint/parser": "1.6.0", - "@typescript-eslint/typescript-estree": "1.6.0", - "requireindex": "^1.2.0", + "@typescript-eslint/experimental-utils": "1.13.0", + "eslint-utils": "^1.3.1", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^2.0.1", "tsutils": "^3.7.0" } }, + "@typescript-eslint/experimental-utils": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-1.13.0.tgz", + "integrity": "sha512-zmpS6SyqG4ZF64ffaJ6uah6tWWWgZ8m+c54XXgwFtUv0jNz8aJAVx8chMCvnk7yl6xwn8d+d96+tWp7fXzTuDg==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "1.13.0", + "eslint-scope": "^4.0.0" + } + }, "@typescript-eslint/parser": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.6.0.tgz", - "integrity": "sha512-VB9xmSbfafI+/kI4gUK3PfrkGmrJQfh0N4EScT1gZXSZyUxpsBirPL99EWZg9MmPG0pzq/gMtgkk7/rAHj4aQw==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.13.0.tgz", + "integrity": "sha512-ITMBs52PCPgLb2nGPoeT4iU3HdQZHcPaZVw+7CsFagRJHUhyeTgorEwHXhFf3e7Evzi8oujKNpHc8TONth8AdQ==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "1.6.0", - "eslint-scope": "^4.0.0", + "@types/eslint-visitor-keys": "^1.0.0", + "@typescript-eslint/experimental-utils": "1.13.0", + "@typescript-eslint/typescript-estree": "1.13.0", "eslint-visitor-keys": "^1.0.0" } }, "@typescript-eslint/typescript-estree": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.6.0.tgz", - "integrity": "sha512-A4CanUwfaG4oXobD5y7EXbsOHjCwn8tj1RDd820etpPAjH+Icjc2K9e/DQM1Hac5zH2BSy+u6bjvvF2wwREvYA==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.13.0.tgz", + "integrity": "sha512-b5rCmd2e6DCC6tCTN9GSUAuxdYwCM/k/2wdjHGrIRGPSJotWMCe/dGpi66u42bhuh8q3QBzqM4TMA1GUUCJvdw==", "dev": true, "requires": { "lodash.unescape": "4.0.1", @@ -10630,9 +10655,9 @@ "dev": true }, "prettier": { - "version": "1.16.4", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.16.4.tgz", - "integrity": "sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==", + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", "dev": true }, "prettier-linter-helpers": { @@ -11086,12 +11111,6 @@ "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "dev": true }, - "requireindex": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", - "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", - "dev": true - }, "resolve": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", @@ -12393,9 +12412,9 @@ "dev": true }, "typescript": { - "version": "3.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz", - "integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==", + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", + "integrity": "sha512-Mcr/Qk7hXqFBXMN7p7Lusj1ktCBydylfQM/FZCk5glCNQJrCUKPkMHdo9R0MTFWsC/4kPFvDS0fDPvukfCkFsw==", "dev": true }, "uglify-js": { diff --git a/package.json b/package.json index 74a8ac94..944b2ecc 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "@commitlint/prompt": "8.2.0", "@ls-age/commitlint-circle": "1.0.0", "@types/jest": "^24.0.18", - "@typescript-eslint/eslint-plugin": "1.6.0", - "@typescript-eslint/parser": "1.6.0", + "@typescript-eslint/eslint-plugin": "1.13.0", + "@typescript-eslint/parser": "1.13.0", "commitizen": "4.0.3", "eslint": "^5.16.0", "eslint-config-airbnb-base": "^13.1.0", @@ -41,10 +41,10 @@ "eslint-plugin-prettier": "^3.0.1", "git-cz": "3.2.1", "jest": "^24.7.1", - "prettier": "^1.16.4", + "prettier": "^1.19.1", "semantic-release": "^15.13.24", "ts-jest": "^24.1.0", - "typescript": "^3.6.3" + "typescript": "^3.7.3" }, "publishConfig": { "access": "public" diff --git a/src/common/smartContract/documentToSmartContracts.ts b/src/common/smartContract/documentToSmartContracts.ts index ae3ab224..5dfac814 100644 --- a/src/common/smartContract/documentToSmartContracts.ts +++ b/src/common/smartContract/documentToSmartContracts.ts @@ -1,18 +1,41 @@ -import { Document, getData } from "@govtechsg/open-attestation"; +import { getData, WrappedDocument, v3, v2 } from "@govtechsg/open-attestation"; import { issuerToSmartContract } from "./issuerToSmartContract"; -import { Issuer } from "../../types"; +import { contractInstance } from "./contractInstance"; +import documentStoreAbi from "./abi/documentStore.json"; +import { OpenAttestationContract } from "../../types"; // Given a list of issuers, convert to smart contract -const mapIssuersToSmartContracts = (issuers: Issuer[], network: string) => +const mapIssuersToSmartContracts = (issuers: v2.Issuer[], network: string) => issuers.map(issuer => issuerToSmartContract(issuer, network)); +const isV1Document = ( + document: any +): document is v2.OpenAttestationDocument => { + return !document.issuer; +}; + // Given a raw document, return list of all smart contracts export const documentToSmartContracts = ( - document: Document, + document: + | WrappedDocument + | WrappedDocument, network: string -) => { +): OpenAttestationContract[] => { const data = getData(document); - const issuers = data.issuers || []; - return mapIssuersToSmartContracts(issuers, network); + if (isV1Document(data)) { + const issuers = data.issuers || []; + return mapIssuersToSmartContracts(issuers, network); + } + return [ + { + type: data.proof.method, + address: data.proof.value, + instance: contractInstance({ + contractAddress: data.proof.value, + abi: documentStoreAbi, + network + }) + } + ]; }; diff --git a/src/common/smartContract/issuerToSmartContract.ts b/src/common/smartContract/issuerToSmartContract.ts index 340f8caa..af9177e1 100644 --- a/src/common/smartContract/issuerToSmartContract.ts +++ b/src/common/smartContract/issuerToSmartContract.ts @@ -1,12 +1,13 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ +import { v2 } from "@govtechsg/open-attestation"; import { contractInstance } from "./contractInstance"; import { TYPES } from "./constants"; import tokenRegistryAbi from "./abi/tokenRegistry.json"; import documentStoreAbi from "./abi/documentStore.json"; -import { Issuer, OpenAttestationContract } from "../../types"; +import { OpenAttestationContract } from "../../types"; export const issuerToSmartContract = ( - issuer: Issuer, + issuer: v2.Issuer, network: string ): OpenAttestationContract => { switch (true) { diff --git a/src/index.ts b/src/index.ts index 87687b17..3d7ae59d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; import { verifyHash } from "./hash/hash"; import { verifyIssued } from "./issued/verify"; import { verifyRevoked } from "./revoked/verify"; @@ -27,7 +27,7 @@ type VerificationChecksWithValidity = [ ]; const getAllChecks = ( - document: SignedDocument, + document: WrappedDocument, smartContracts: OpenAttestationContract[] ): VerificationChecks => [ verifyHash(document), @@ -47,7 +47,7 @@ const isDocumentValid = ( * @returns */ export const verify = async ( - document: SignedDocument, + document: WrappedDocument, network = "homestead" ) => { const smartContracts = documentToSmartContracts(document, network); @@ -69,7 +69,7 @@ export const verify = async ( * The last promise resolves to the overall validity based on all the checks. */ export const verifyWithIndividualChecks = ( - document: SignedDocument, + document: WrappedDocument, network = "homestead" ): VerificationChecksWithValidity => { const smartContracts = documentToSmartContracts(document, network); diff --git a/src/issued/contractInterface.integration.test.ts b/src/issued/contractInterface.integration.test.ts index cef59af7..38871bb7 100644 --- a/src/issued/contractInterface.integration.test.ts +++ b/src/issued/contractInterface.integration.test.ts @@ -9,7 +9,10 @@ import { issuerToSmartContract } from "../common/smartContract/issuerToSmartCont describe("isIssuedOnTokenRegistry", () => { it("returns true if token is created on tokenRegistry", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3" }, + { + tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3", + name: "some" + }, "ropsten" ); const issued = await isIssuedOnTokenRegistry( @@ -21,7 +24,10 @@ describe("isIssuedOnTokenRegistry", () => { it("allows error to bubble if token is nonexistent on tokenRegistry", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3" }, + { + tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3", + name: "some" + }, "ropsten" ); await expect( @@ -33,7 +39,10 @@ describe("isIssuedOnTokenRegistry", () => { describe("isIssuedOnDocumentStore", () => { it("returns true if document is issued on documentStore", async () => { const smartContract = issuerToSmartContract( - { documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6" }, + { + documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6", + name: "some" + }, "ropsten" ); const issued = await isIssuedOnDocumentStore( @@ -46,7 +55,10 @@ describe("isIssuedOnDocumentStore", () => { it("returns false if document is not issued on documentStore", async () => { const hash = constants.HashZero; const smartContract = issuerToSmartContract( - { documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6" }, + { + documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6", + name: "some" + }, "ropsten" ); const issued = await isIssuedOnDocumentStore(smartContract, hash); @@ -55,7 +67,7 @@ describe("isIssuedOnDocumentStore", () => { it("allows error to bubble if documentStore is not deployed", async () => { const smartContract = issuerToSmartContract( - { documentStore: constants.AddressZero }, + { documentStore: constants.AddressZero, name: "some" }, "ropsten" ); await expect( @@ -67,7 +79,10 @@ describe("isIssuedOnDocumentStore", () => { describe("isIssued", () => { it("works for tokenRegistry", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3" }, + { + tokenRegistry: "0x48399Fb88bcD031C556F53e93F690EEC07963Af3", + name: "some" + }, "ropsten" ); const hash = @@ -80,7 +95,10 @@ describe("isIssued", () => { const hash = "0x85df2b4e905a82cf10c317df8f4b659b5cf38cc12bd5fbaffba5fc901ef0011b"; const smartContract = issuerToSmartContract( - { documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6" }, + { + documentStore: "0x008486e2b14Cb1B5231DbA10B2170271af3196d6", + name: "some" + }, "ropsten" ); const issued = await isIssued(smartContract, hash); diff --git a/src/issued/verify.test.ts b/src/issued/verify.test.ts index 83d82846..f506c55f 100644 --- a/src/issued/verify.test.ts +++ b/src/issued/verify.test.ts @@ -81,8 +81,9 @@ describe("verifyIssued", () => { ]; const summary = await verifyIssued( { + version: "1.0", schema: "schema", - data: "data", + data: { any: "data" }, signature: { merkleRoot: "MERKLE_ROOT", type: "SHA3MerkleProof", @@ -123,8 +124,9 @@ describe("verifyIssued", () => { ]; const summary = await verifyIssued( { + version: "1.0", schema: "schema", - data: "data", + data: { any: "data" }, signature: { merkleRoot: "MERKLE_ROOT", type: "SHA3MerkleProof", diff --git a/src/issued/verify.ts b/src/issued/verify.ts index a8e1b757..e862d9d3 100644 --- a/src/issued/verify.ts +++ b/src/issued/verify.ts @@ -1,4 +1,4 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; import { isIssued } from "./contractInterface"; import { Hash, OpenAttestationContract } from "../types"; @@ -29,7 +29,7 @@ export const isIssuedOnAll = ( }; export const verifyIssued = async ( - document: SignedDocument, + document: WrappedDocument, smartContracts: OpenAttestationContract[] = [] ) => { const hash = `0x${document.signature.merkleRoot}`; diff --git a/src/revoked/contractInterface.integration.test.ts b/src/revoked/contractInterface.integration.test.ts index 278e58e5..7c895b0e 100644 --- a/src/revoked/contractInterface.integration.test.ts +++ b/src/revoked/contractInterface.integration.test.ts @@ -18,7 +18,10 @@ const TOKEN_UNMINTED = constants.AddressZero; describe("isRevokedOnTokenRegistry", () => { it("returns false if token has valid owner", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: TOKEN_REGISTRY }, + { + name: "name", + tokenRegistry: TOKEN_REGISTRY + }, "ropsten" ); const issued = await isRevokedOnTokenRegistry( @@ -30,7 +33,10 @@ describe("isRevokedOnTokenRegistry", () => { it("returns true if owner of token is the smart contract itself", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: TOKEN_REGISTRY }, + { + name: "name", + tokenRegistry: TOKEN_REGISTRY + }, "ropsten" ); const issued = await isRevokedOnTokenRegistry( @@ -42,7 +48,10 @@ describe("isRevokedOnTokenRegistry", () => { it("allow errors to bubble if token is not minted", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: TOKEN_REGISTRY }, + { + name: "name", + tokenRegistry: TOKEN_REGISTRY + }, "ropsten" ); await expect( @@ -60,7 +69,10 @@ const DOCUMENT_UNREVOKED = describe("isRevokedOnDocumentStore", () => { it("returns true if document is revoked on documentStore", async () => { const smartContract = issuerToSmartContract( - { documentStore: DOCUMENT_STORE }, + { + name: "name", + documentStore: DOCUMENT_STORE + }, "ropsten" ); const revoked = await isRevokedOnDocumentStore( @@ -72,7 +84,10 @@ describe("isRevokedOnDocumentStore", () => { it("returns false if document is not issued on documentStore", async () => { const smartContract = issuerToSmartContract( - { documentStore: DOCUMENT_STORE }, + { + name: "name", + documentStore: DOCUMENT_STORE + }, "ropsten" ); const issued = await isRevokedOnDocumentStore( @@ -84,7 +99,10 @@ describe("isRevokedOnDocumentStore", () => { it("allows error to bubble up if documentStore is not deployed", async () => { const smartContract = issuerToSmartContract( - { documentStore: constants.AddressZero }, + { + name: "name", + documentStore: constants.AddressZero + }, "ropsten" ); await expect( @@ -96,7 +114,10 @@ describe("isRevokedOnDocumentStore", () => { describe("isRevoked", () => { it("works for tokenRegistry", async () => { const smartContract = issuerToSmartContract( - { tokenRegistry: TOKEN_REGISTRY }, + { + name: "name", + tokenRegistry: TOKEN_REGISTRY + }, "ropsten" ); const issued = await isRevoked(smartContract, TOKEN_WITH_OWNER); @@ -105,7 +126,10 @@ describe("isRevoked", () => { it("works for documentStore", async () => { const smartContract = issuerToSmartContract( - { documentStore: DOCUMENT_STORE }, + { + name: "name", + documentStore: DOCUMENT_STORE + }, "ropsten" ); const revoked = await isRevoked(smartContract, DOCUMENT_REVOKED); diff --git a/src/revoked/verify.test.ts b/src/revoked/verify.test.ts index c1e38632..9f2beec3 100644 --- a/src/revoked/verify.test.ts +++ b/src/revoked/verify.test.ts @@ -206,8 +206,9 @@ describe("verifyRevoked", () => { ]; const summary = await verifyRevoked( { + version: "1.0", schema: "schema", - data: "data", + data: { any: "data" }, signature: { merkleRoot: "MERKLE_ROOT", type: "SHA3MerkleProof", @@ -256,8 +257,9 @@ describe("verifyRevoked", () => { ]; const summary = await verifyRevoked( { + version: "1.0", schema: "schema", - data: "data", + data: { any: "data" }, signature: { merkleRoot: "MERKLE_ROOT", type: "SHA3MerkleProof", diff --git a/src/revoked/verify.ts b/src/revoked/verify.ts index f36cc434..0a1f9b41 100644 --- a/src/revoked/verify.ts +++ b/src/revoked/verify.ts @@ -1,4 +1,4 @@ -import { SignedDocument, utils } from "@govtechsg/open-attestation"; +import { WrappedDocument, utils } from "@govtechsg/open-attestation"; import { Hash, OpenAttestationContract } from "../types"; import { isRevoked } from "./contractInterface"; @@ -54,7 +54,7 @@ export const getIntermediateHashes = ( }; export const verifyRevoked = async ( - document: SignedDocument, + document: WrappedDocument, smartContracts: OpenAttestationContract[] = [] ) => { const { targetHash } = document.signature; diff --git a/src/types.ts b/src/types.ts index 0ee7799d..0b504c11 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,12 +3,6 @@ import { TYPES } from "./common/smartContract/constants"; export type Hash = string; -export interface Issuer { - tokenRegistry?: Hash; - certificateStore?: Hash; - documentStore?: Hash; -} - export interface OpenAttestationContract { address: Hash; type: typeof TYPES.TOKEN_REGISTRY | typeof TYPES.DOCUMENT_STORE; diff --git a/test/fixtures/document.ts b/test/fixtures/document.ts index aad2aad2..baf60b97 100644 --- a/test/fixtures/document.ts +++ b/test/fixtures/document.ts @@ -1,7 +1,8 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; -export const document: SignedDocument = { - schema: "opencerts/v1.4", +export const document: WrappedDocument = { + version: "open-attestation/2.0", + schema: "opencerts/1.4", data: { id: "046bebd9-1c59-4d82-b70b-b6c8aa5c502d:string:2018091259", name: diff --git a/test/fixtures/documentMainnetValid.ts b/test/fixtures/documentMainnetValid.ts index 5ca618a8..bc03c378 100644 --- a/test/fixtures/documentMainnetValid.ts +++ b/test/fixtures/documentMainnetValid.ts @@ -1,7 +1,8 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; -export const documentMainnetValid: SignedDocument = { - schema: "opencerts/v1.4", +export const documentMainnetValid: WrappedDocument = { + version: "open-attestation/2.0", + schema: "opencerts/1.4", data: { id: "ab89a9ae-954f-4d28-8b48-2a534d3a3d60:string:2018-SAF-01", $template: diff --git a/test/fixtures/documentRopstenValid.ts b/test/fixtures/documentRopstenValid.ts index d904bd0b..1169fa53 100644 --- a/test/fixtures/documentRopstenValid.ts +++ b/test/fixtures/documentRopstenValid.ts @@ -1,7 +1,8 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; -export const documentRopstenValid: SignedDocument = { - schema: "opencerts/v1.4", +export const documentRopstenValid: WrappedDocument = { + version: "open-attestation/2.0", + schema: "opencerts/1.4", data: { id: "e23c59b6-da39-4460-821b-903038d46f96:string:2005:12345678A_PHARM_PHARM_2018", diff --git a/test/fixtures/tampered-document.ts b/test/fixtures/tampered-document.ts index 34accd6a..51e91bff 100644 --- a/test/fixtures/tampered-document.ts +++ b/test/fixtures/tampered-document.ts @@ -1,7 +1,8 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { WrappedDocument } from "@govtechsg/open-attestation"; -export const documentTampered: SignedDocument = { - schema: "opencerts/v1.4", +export const documentTampered: WrappedDocument = { + version: "open-attestation/2.0", + schema: "tradetrust/1.0", data: { id: "046bebd9-1c59-4d82-b70b-b6c8aa5c502d:string:2018091259", name: diff --git a/test/fixtures/tokenRopstenInvalid.ts b/test/fixtures/tokenRopstenInvalid.ts index 81c0c2c7..41a8afbd 100644 --- a/test/fixtures/tokenRopstenInvalid.ts +++ b/test/fixtures/tokenRopstenInvalid.ts @@ -1,7 +1,20 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -export const tokenRopstenInvalid: SignedDocument = { - schema: "tradetrust/v1.0", +interface CustomDocument { + recipient: { + address: { + street: string; + country: string; + }; + }; + consignment: any; // sorry I'm lazy; + declaration: any; // sorry I'm lazy; +} + +export const tokenRopstenInvalid: WrappedDocument = { + version: "open-attestation/2.0", + schema: "tradetrust/1.0", data: { id: "834a20bd-4d5c-4f3a-a080-f3f834420384:string:SGCNM21566325", $template: { diff --git a/test/fixtures/tokenRopstenValid.ts b/test/fixtures/tokenRopstenValid.ts index fd510ddb..237bd612 100644 --- a/test/fixtures/tokenRopstenValid.ts +++ b/test/fixtures/tokenRopstenValid.ts @@ -1,7 +1,20 @@ -import { SignedDocument } from "@govtechsg/open-attestation"; +import { v2, WrappedDocument } from "@govtechsg/open-attestation"; -export const tokenRopstenValid: SignedDocument = { - schema: "tradetrust/v1.0", +interface CustomDocument { + recipient: { + address: { + street: string; + country: string; + }; + }; + consignment: any; // sorry I'm lazy; + declaration: any; // sorry I'm lazy; +} + +export const tokenRopstenValid: WrappedDocument = { + version: "open-attestation/2.0", + schema: "tradetrust/1.0", data: { id: "41847724-c4b2-489e-8505-2bbb652b205c:string:SGCNM21566325", $template: {