Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add astron network #87

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,611 changes: 1,611 additions & 0 deletions build/astron/config-v2.json

Large diffs are not rendered by default.

1,102 changes: 1,102 additions & 0 deletions build/astron/config-v3.json

Large diffs are not rendered by default.

2,276 changes: 48 additions & 2,228 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"devDependencies": {
"@netlify/functions": "^1.3.0",
"@tradetrust-tt/tradetrust": "^6.9.1",
"@tradetrust-tt/tradetrust-utils": "^1.13.3",
"@tradetrust-tt/tradetrust-utils": "^1.14.0",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.10",
"@typescript-eslint/eslint-plugin": "^5.57.0",
Expand Down
6 changes: 4 additions & 2 deletions src/config-v2.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"stabilitytestnet",
"stability",
"hederatestnet",
"hederamainnet"
"hederamainnet",
"astron"
]
},
"wallet": {
Expand Down Expand Up @@ -240,7 +241,8 @@
"20180427",
"101010",
"296",
"295"
"295",
"1338"
maxufeng marked this conversation as resolved.
Show resolved Hide resolved
]
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/config-v3.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"stabilitytestnet",
"stability",
"hederatestnet",
"hederamainnet"
"hederamainnet",
"astron"
]
},
"wallet": {
Expand Down Expand Up @@ -204,7 +205,8 @@
"20180427",
"101010",
"296",
"295"
"295",
"1338"
maxufeng marked this conversation as resolved.
Show resolved Hide resolved
]
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ export const buildData = [
dnsTransferableRecord: "example.tradetrust.io",
dnsDid: "example.tradetrust.io",
},
// Astron
{
chainId: "1338" as CHAIN_ID,
documentStoreAddress: "0x94FD21A026E29E0686583b8be71Cb28a8ca1A8d4",
tokenRegistryAddress: "0x0D5da59B93e8AC9b1781CE5694fbcE626586F4c9",
dnsVerifiable: "astronlayer2.bitfactory.cn",
dnsTransferableRecord: "astronlayer2.bitfactory.cn",
dnsDid: "astronlayer2.bitfactory.cn",
},
];
1 change: 1 addition & 0 deletions src/generate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const writeSamples = () => {
case CHAIN_ID.hederatestnet:
case CHAIN_ID.stabilitytestnet:
case CHAIN_ID.stability:
case CHAIN_ID.astron:
wallet = walletSample;
break;
}
Expand Down
245 changes: 245 additions & 0 deletions test/updateFormAstron.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
import { CHAIN_ID } from "@tradetrust-tt/tradetrust-utils/constants/supportedChains";
import { Wallet } from "ethers";
import { updateFormV2, updateFormV3 } from "../src/shared/updateForm";
import v2VerifiableDocumentForm from "../fixtures/config/forms/v2/invoice.json";
import v2DnsDidForm from "../fixtures/config/forms/v2/invoice-dns-did.json";
import v2TransferableRecordForm from "../fixtures/config/forms/v2/bill-of-lading.json";
import v3VerifiableDocumentForm from "../fixtures/config/forms/v3/invoice.json";
import v3DnsDidForm from "../fixtures/config/forms/v3/invoice-dns-did.json";
import v3TransferableRecordForm from "../fixtures/config/forms/v3/bill-of-lading.json";

const v2DidForm = {
name: "A DID Verifiable Document Form",
type: "VERIFIABLE_DOCUMENT",
defaults: {
$template: {
type: "EMBEDDED_RENDERER",
name: "CHAFTA_COO",
url: "https://generic-templates.openattestation.io",
},
issuers: [
{
id: "did:ethr:0x123123123123123123123123123123123123",
name: "DEMO DID",
revocation: {
type: "NONE",
},
identityProof: {
type: "DID",
key: "did:ethr:0x123123123123123123123123123123123123#controller",
location: "demo-oa.openattestation.com",
},
},
],
},
}; // putting directly here instead of fixtures, as we don't want to provide any `DID` forms during `npm run build`

const v3DidForm = {
name: "A V3 DID Verifiable Document Form",
type: "VERIFIABLE_DOCUMENT",
defaults: {
version: "https://schema.openattestation.com/3.0/schema.json",
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://schemata.openattestation.com/com/openattestation/1.0/OpenAttestation.v3.json",
],
type: ["VerifiableCredential", "OpenAttestationCredential"],
issuanceDate: "2010-01-01T19:23:24Z",
openAttestationMetadata: {
template: {
type: "EMBEDDED_RENDERER",
name: "CHAFTA_COO",
url: "https://generic-templates.oa.io",
},
proof: {
type: "OpenAttestationProofMethod",
method: "DID",
value: "did:ethr:0x123",
revocation: {
type: "NONE",
},
},
identityProof: {
type: "DID",
identifier: "demo-oa.openattestation.com",
},
},
credentialSubject: {},
issuer: {
id: "https://example.com",
name: "DEMO DID",
type: "OpenAttestationIssuer",
},
},
}; // putting directly here instead of fixtures, as we don't want to provide any `DID` forms during `npm run build`

describe("updateFormV2", () => {
const wallet = Wallet.fromMnemonic(
"tourist quality multiply denial diary height funny calm disease buddy speed gold"
);
const walletString = JSON.stringify(wallet);

it("should update the form from a verifiable document correctly", () => {
const updatedForm = updateFormV2({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v2VerifiableDocumentForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.issuers[0].identityProof.location
).toStrictEqual("VerifiableDNS.com");
expect(updatedForm.defaults.issuers[0].documentStore).toStrictEqual(
"0xabcDocumentStore"
);
});
it("should update the form from a DID verifiable document correctly", () => {
const updatedForm = updateFormV2({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v2DidForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});

expect(updatedForm.defaults.issuers[0].id).toStrictEqual(
"did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C"
);
expect(updatedForm.defaults.issuers[0].identityProof.key).toStrictEqual(
"did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C#controller"
);
expect(
updatedForm.defaults.issuers[0].identityProof.location
).toStrictEqual(undefined);
});

it("should update the form from a DNS-DID verifiable document correctly", () => {
const updatedForm = updateFormV2({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v2DnsDidForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(updatedForm.defaults.issuers[0].id).toStrictEqual(
"did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C"
);
expect(updatedForm.defaults.issuers[0].identityProof.key).toStrictEqual(
"did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C#controller"
);
expect(
updatedForm.defaults.issuers[0].identityProof.location
).toStrictEqual("DNSDID.com");
});

it("should update the form from a transferable document correctly", () => {
const updatedForm = updateFormV2({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v2TransferableRecordForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.issuers[0].identityProof.location
).toStrictEqual("TransferableDNS.com");
expect(updatedForm.defaults.issuers[0].tokenRegistry).toStrictEqual(
"0xabcTokenRegistry"
);
});
});

describe("updateFormV3", () => {
const wallet = Wallet.fromMnemonic(
"tourist quality multiply denial diary height funny calm disease buddy speed gold"
);
const walletString = JSON.stringify(wallet);

it("should update the form from a verifiable document correctly", () => {
const updatedForm = updateFormV3({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v3VerifiableDocumentForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.openAttestationMetadata.identityProof.identifier
).toStrictEqual("VerifiableDNS.com");
expect(
updatedForm.defaults.openAttestationMetadata.proof.value
).toStrictEqual("0xabcDocumentStore");
});
it("should update the form from a DID verifiable document correctly", () => {
const updatedForm = updateFormV3({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v3DidForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.openAttestationMetadata.proof.value
).toStrictEqual("did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C");
expect(
updatedForm.defaults.openAttestationMetadata.identityProof.identifier
).toStrictEqual("did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C");
});

it("should update the form from a DNS-DID verifiable document correctly", () => {
const updatedForm = updateFormV3({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v3DnsDidForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.openAttestationMetadata.proof.value
).toStrictEqual("did:ethr:0x0x906FB815De8976b1e38D9a4C1014a3acE16Ce53C");
expect(
updatedForm.defaults.openAttestationMetadata.identityProof.identifier
).toStrictEqual("DNSDID.com");
});

it("should update the form from a transferable document correctly", () => {
const updatedForm = updateFormV3({
chain: { currency: "ASTRON", id: CHAIN_ID.astron },
wallet: { type: "ENCRYPTED_JSON", encryptedJson: walletString },
form: v3TransferableRecordForm,
documentStoreAddress: "0xabcDocumentStore",
tokenRegistryAddress: "0xabcTokenRegistry",
dnsVerifiable: "VerifiableDNS.com",
dnsDid: "DNSDID.com",
dnsTransferableRecord: "TransferableDNS.com",
});
expect(
updatedForm.defaults.openAttestationMetadata.identityProof.identifier
).toStrictEqual("TransferableDNS.com");
expect(
updatedForm.defaults.openAttestationMetadata.proof.value
).toStrictEqual("0xabcTokenRegistry");
});
});
Loading