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

Commit f2d1cd5

Browse files
authored
feat: wrap document individually with --batched flag (#95)
1 parent 77168f4 commit f2d1cd5

13 files changed

Lines changed: 358 additions & 266 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ open-attestation wrap ./examples/raw-documents/example.0.json --output-file ./ex
8686
open-attestation wrap ./examples/wrapped-documents/example.0.json --of ./examples/wrapped-documents/example.1.json --unwrap
8787
```
8888

89+
You can disable the `--batched` option to wrap multiple documents individually (i.e. they will not have the same merkle root):
90+
91+
```bash
92+
open-attestation wrap ./examples/raw-documents/ --output-dir ./examples/wrapped-documents/ --batched false
93+
✔ success All documents have been individually wrapped
94+
```
95+
8996
By default the CLI will use open-attestation schema v2 but you can opt in for open-attestation schema v3 using `open-attestation-v3` option:
9097

9198
```bash

src/__tests__/wrap.e2e.test.ts

Lines changed: 242 additions & 236 deletions
Large diffs are not rendered by default.

src/__tests__/wrap.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ describe("batchIssue", () => {
109109
throw new Error(`unhandled ${path} in spy`);
110110
});
111111

112-
const root = await appendProofToDocuments("DIR", hashMap, Output.Directory, "DIR");
112+
const root = await appendProofToDocuments({
113+
intermediateDir: "DIR",
114+
hashMap,
115+
outputPathType: Output.Directory,
116+
digestedDocumentPath: "DIR",
117+
});
113118

114119
expect(root).toStrictEqual("e");
115120
});

src/commands/wrap.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface WrapCommand {
1313
openAttestationV3: boolean;
1414
unwrap: boolean;
1515
silent?: boolean;
16+
batched: boolean;
1617
}
1718

1819
export const command = "wrap <raw-documents-path> [options]";
@@ -61,9 +62,14 @@ export const builder = (yargs: Argv): Argv =>
6162
alias: "silent",
6263
description: "Disable console outputs when outputting to stdout",
6364
type: "boolean",
65+
})
66+
.option("batched", {
67+
description: "Indicate whether documents must be wrap together or individually",
68+
type: "boolean",
69+
default: true,
6470
});
6571

66-
export const handler = async (args: WrapCommand): Promise<string> => {
72+
export const handler = async (args: WrapCommand): Promise<string | undefined> => {
6773
try {
6874
const outputPathType = args.outputDir ? Output.Directory : args.outputFile ? Output.File : Output.StdOut;
6975
const outputPath = args.outputDir || args.outputFile; // undefined when we use std out
@@ -83,16 +89,27 @@ export const handler = async (args: WrapCommand): Promise<string> => {
8389
signale.disable();
8490
}
8591

92+
// if output to a file or stdout, we handle only one file. In that case we disable the batch mode
93+
const batched = outputPathType !== Output.Directory ? false : args.batched;
94+
if (!batched && args.batched) {
95+
signale.warn("Detected single file: batch mode disabled.");
96+
}
97+
8698
const merkleRoot = await wrap({
8799
inputPath: args.rawDocumentsPath,
88100
outputPath,
89101
schemaPath: args.schema,
90102
version: args.openAttestationV3 ? SchemaId.v3 : SchemaId.v2,
91103
unwrap: args.unwrap,
92104
outputPathType,
105+
batched,
93106
});
94107

95-
signale.success(`Batch Document Root: 0x${merkleRoot}`);
108+
if (merkleRoot) {
109+
signale.success(`Batch Document Root: 0x${merkleRoot}`);
110+
} else {
111+
signale.success("All documents have been individually wrapped");
112+
}
96113

97114
return merkleRoot;
98115
} catch (err) {

src/implementations/deploy/document-store/document-store.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe("document-store", () => {
1919
const documentStoreFactory: any = DocumentStoreFactory;
2020
const mockedDocumentStoreFactory: jest.Mock<DocumentStoreFactory> = documentStoreFactory;
2121
const mockedDeploy: jest.Mock = mockedDocumentStoreFactory.prototype.deploy;
22+
// increase timeout because ethers is throttling
23+
jest.setTimeout(30000);
2224

2325
// eslint-disable-next-line jest/no-hooks
2426
beforeEach(() => {

src/implementations/deploy/title-escrow-creator/title-escrow-creator.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ describe("token-registry", () => {
1818
const tokenFactory: any = TitleEscrowCreatorFactory;
1919
const mockedTokenFactory: jest.Mock<TitleEscrowCreatorFactory> = tokenFactory;
2020
const mockedDeploy: jest.Mock = mockedTokenFactory.prototype.deploy;
21+
// increase timeout because ethers is throttling
22+
jest.setTimeout(30000);
2123

2224
// eslint-disable-next-line jest/no-hooks
2325
beforeEach(() => {

src/implementations/deploy/title-escrow/title-escrow.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ describe("token-registry", () => {
2222
const tokenFactory: any = TitleEscrowFactory;
2323
const mockedTokenFactory: jest.Mock<TitleEscrowFactory> = tokenFactory;
2424
const mockedDeploy: jest.Mock = mockedTokenFactory.prototype.deploy;
25+
// increase timeout because ethers is throttling
26+
jest.setTimeout(30000);
2527

2628
// eslint-disable-next-line jest/no-hooks
2729
beforeEach(() => {

src/implementations/deploy/token-registry/token-registry.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe("token-registry", () => {
2020
const tokenFactory: any = TradeTrustErc721Factory;
2121
const mockedTokenFactory: jest.Mock<TradeTrustErc721Factory> = tokenFactory;
2222
const mockedDeploy: jest.Mock = mockedTokenFactory.prototype.deploy;
23+
// increase timeout because ethers is throttling
24+
jest.setTimeout(30000);
2325

2426
// eslint-disable-next-line jest/no-hooks
2527
beforeEach(() => {

src/implementations/document-store/issue.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const deployParams: DocumentStoreIssueCommand = {
1818
// TODO the following test is very fragile and might break on every interface change of DocumentStoreFactory
1919
// ideally must setup ganache, and run the function over it
2020
describe("document-store", () => {
21+
// increase timeout because ethers is throttling
22+
jest.setTimeout(30000);
2123
describe("issueDocumentStore", () => {
2224
const mockedDocumentStoreFactory: jest.Mock<DocumentStoreFactory> = DocumentStoreFactory as any;
2325
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

src/implementations/document-store/revoke.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const deployParams: DocumentStoreRevokeCommand = {
1818
// TODO the following test is very fragile and might break on every interface change of DocumentStoreFactory
1919
// ideally must setup ganache, and run the function over it
2020
describe("document-store", () => {
21+
// increase timeout because ethers is throttling
22+
jest.setTimeout(30000);
2123
describe("revokeDocumentStore", () => {
2224
const mockedDocumentStoreFactory: jest.Mock<DocumentStoreFactory> = DocumentStoreFactory as any;
2325
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

0 commit comments

Comments
 (0)