Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 52d72ec

Browse files
authored
feat: added support for v3 config file (#196)
* feat: added support for v3 config file * fix: validate function * feat: refactor update form to use the one in OA
1 parent 7e9998b commit 52d72ec

File tree

5 files changed

+68
-48
lines changed

5 files changed

+68
-48
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@govtechsg/document-store": "^2.2.2",
7575
"@govtechsg/oa-encryption": "^1.3.3",
7676
"@govtechsg/oa-verify": "^7.5.2",
77-
"@govtechsg/open-attestation": "^6.2.0",
77+
"@govtechsg/open-attestation": "^6.4.1",
7878
"@govtechsg/token-registry": "^2.5.3",
7979
"ajv": "^8.4.0",
8080
"ajv-formats": "^2.1.0",

src/implementations/config/create.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getTokenRegistryAddress,
1414
getDocumentStoreAddress,
1515
} from "./helpers";
16+
import { utils, v2, v3 } from "@govtechsg/open-attestation";
1617

1718
const SANDBOX_ENDPOINT_URL = "https://sandbox.fyntech.io";
1819

@@ -35,9 +36,21 @@ export const create = async ({
3536

3637
const hasTransferableRecord = forms.some((form) => form.type === "TRANSFERABLE_RECORD");
3738
const hasDocumentStore = forms.some((form) => form.type === "VERIFIABLE_DOCUMENT");
38-
const hasDid = forms.some(
39-
(form) => form.defaults.issuers.some((issuer) => issuer.identityProof?.type.includes("DID")) // TODO: v3 does not have `issuers` but `issuer` instead
40-
);
39+
const hasDid = forms.some((form) => {
40+
//check form for v2/v3
41+
const didCheckList = ["DID", "DNS-DID"];
42+
if (utils.isRawV3Document(form.defaults)) {
43+
const v3Defaults = form.defaults as v3.OpenAttestationDocument;
44+
return didCheckList.includes(v3Defaults.openAttestationMetadata.proof.method);
45+
} else {
46+
const v2Defaults = form.defaults as v2.OpenAttestationDocument;
47+
return v2Defaults.issuers.some((issuer) => {
48+
const identityProof = issuer.identityProof;
49+
if (!identityProof) return false;
50+
return didCheckList.includes(identityProof.type);
51+
});
52+
}
53+
});
4154

4255
let tokenRegistryAddress = "";
4356
let documentStoreAddress = "";

src/implementations/config/helpers.ts

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v2 } from "@govtechsg/open-attestation";
1+
import { utils, v2, v3 } from "@govtechsg/open-attestation";
22
import fetch from "node-fetch";
33
import { info, success } from "signale";
44
import { highlight } from "../../utils";
@@ -37,37 +37,28 @@ export const getConfigWithUpdatedForms = ({
3737
dnsTransferableRecord,
3838
}: UpdatedForms): ConfigFile => {
3939
const { wallet, forms } = configFile;
40-
const { encryptedJson } = wallet;
41-
const { address } = JSON.parse(encryptedJson);
4240

4341
const updatedForms = forms.map((form: Form) => {
44-
if (form.type === "VERIFIABLE_DOCUMENT") {
45-
const updatedIssuers = form.defaults.issuers.map((issuer) => {
46-
if (issuer.identityProof) {
47-
if (issuer.identityProof.type === "DNS-TXT") {
48-
issuer.documentStore = documentStoreAddress;
49-
issuer.identityProof.location = dnsVerifiable;
50-
} else if (issuer.identityProof.type === "DID" || issuer.identityProof.type === "DNS-DID") {
51-
issuer.id = `did:ethr:0x${address}`;
52-
issuer.identityProof.location = dnsDid;
53-
issuer.identityProof.key = `did:ethr:0x${address}#controller`;
54-
if (issuer.revocation) {
55-
issuer.revocation.type = "NONE" as v2.RevocationType;
56-
}
57-
}
58-
}
59-
return issuer;
42+
if (utils.isRawV3Document(form.defaults)) {
43+
utils.updateFormV3({
44+
wallet,
45+
form,
46+
documentStoreAddress,
47+
tokenRegistryAddress,
48+
dnsVerifiable: dnsVerifiable || "",
49+
dnsDid: dnsDid || "",
50+
dnsTransferableRecord: dnsTransferableRecord || "",
6051
});
61-
form.defaults.issuers = updatedIssuers;
62-
}
63-
64-
if (form.type === "TRANSFERABLE_RECORD") {
65-
const updatedIssuers = form.defaults.issuers.map((issuer) => {
66-
issuer.tokenRegistry = tokenRegistryAddress;
67-
if (issuer.identityProof?.location) issuer.identityProof.location = dnsTransferableRecord;
68-
return issuer;
52+
} else {
53+
utils.updateFormV2({
54+
wallet,
55+
form,
56+
documentStoreAddress,
57+
tokenRegistryAddress,
58+
dnsVerifiable: dnsVerifiable || "",
59+
dnsDid: dnsDid || "",
60+
dnsTransferableRecord: dnsTransferableRecord || "",
6961
});
70-
form.defaults.issuers = updatedIssuers;
7162
}
7263

7364
return form;
@@ -124,14 +115,30 @@ export const getDocumentStoreAddress = async (encryptedWalletPath: string): Prom
124115
};
125116

126117
export const validate = (forms: Form[]): boolean => {
127-
const isValidForm = forms.some((form: Form) => {
128-
const isValidFormType = form.type === "TRANSFERABLE_RECORD" && "VERIFIABLE_DOCUMENT";
129-
const isValidIdentityProofType = form.defaults.issuers.some(
130-
(issuer) => issuer.identityProof?.type === "DNS-TXT" && "DNS-DID" && "DID"
131-
);
132-
118+
const isValidForm = forms.map((form: Form) => {
119+
const formTypeCheckList = ["TRANSFERABLE_RECORD", "VERIFIABLE_DOCUMENT"];
120+
const isValidFormType = formTypeCheckList.includes(form.type);
121+
let isValidIdentityProofType: boolean;
122+
123+
const identityProofTypeCheckList = ["DNS-TXT", "DNS-DID", "DID"];
124+
// test for v2/v3 form defaults
125+
if (utils.isRawV3Document(form.defaults)) {
126+
const v3Defaults = form.defaults as v3.OpenAttestationDocument;
127+
isValidIdentityProofType = identityProofTypeCheckList.includes(
128+
v3Defaults.openAttestationMetadata.identityProof.type
129+
);
130+
} else {
131+
const v2Defaults = form.defaults as v2.OpenAttestationDocument;
132+
isValidIdentityProofType = v2Defaults.issuers.some((issuer) => {
133+
const identityProofType = issuer.identityProof?.type;
134+
if (identityProofType) {
135+
return identityProofTypeCheckList.includes(identityProofType);
136+
}
137+
return false;
138+
});
139+
}
133140
return isValidFormType && isValidIdentityProofType;
134141
});
135-
136-
return isValidForm;
142+
const anyInvalidForm = !isValidForm.some((validForm: boolean) => validForm === false);
143+
return anyInvalidForm;
137144
};

src/implementations/config/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v2 } from "@govtechsg/open-attestation";
1+
import { OpenAttestationDocument } from "@govtechsg/open-attestation";
22

33
type WalletEncryptedJson = {
44
type: "ENCRYPTED_JSON";
@@ -10,7 +10,7 @@ export type Dns = string | undefined;
1010
export type Form = {
1111
name: string;
1212
type: "VERIFIABLE_DOCUMENT" | "TRANSFERABLE_RECORD";
13-
defaults: v2.OpenAttestationDocument;
13+
defaults: OpenAttestationDocument;
1414
schema: any;
1515
uiSchema?: any;
1616
attachments?: {

0 commit comments

Comments
 (0)