@midnight-ntwrk/midnight-did-api 0.5.0-rc1 → 0.5.0-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +43 -2
  2. package/dist/config-profiles.d.ts +6 -6
  3. package/dist/config-profiles.js +6 -6
  4. package/dist/controller-authorization.d.ts +9 -0
  5. package/dist/controller-authorization.js +20 -0
  6. package/dist/controller-authorization.js.map +1 -0
  7. package/dist/controller-operations.js +4 -2
  8. package/dist/controller-operations.js.map +1 -1
  9. package/dist/document-operations.d.ts +4 -4
  10. package/dist/document-operations.js +10 -6
  11. package/dist/document-operations.js.map +1 -1
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +1 -0
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib.d.ts +1 -1
  16. package/dist/lib.js +1 -1
  17. package/dist/lib.js.map +1 -1
  18. package/dist/release-artifacts.d.ts +1 -1
  19. package/dist/release-artifacts.js +1 -1
  20. package/dist/release-artifacts.js.map +1 -1
  21. package/dist/resolution.d.ts +6 -9
  22. package/dist/resolution.js +17 -33
  23. package/dist/resolution.js.map +1 -1
  24. package/dist/service-operations.d.ts +4 -4
  25. package/dist/service-operations.js +12 -6
  26. package/dist/service-operations.js.map +1 -1
  27. package/dist/update.d.ts +1 -1
  28. package/dist/update.js +1 -1
  29. package/dist/update.js.map +1 -1
  30. package/dist/verification-method-operations.d.ts +4 -4
  31. package/dist/verification-method-operations.js +27 -12
  32. package/dist/verification-method-operations.js.map +1 -1
  33. package/dist/verification-method-relations.d.ts +1 -1
  34. package/dist/verification-method-relations.js +6 -3
  35. package/dist/verification-method-relations.js.map +1 -1
  36. package/dist/zk-artifacts.d.ts +91 -0
  37. package/dist/zk-artifacts.js +402 -0
  38. package/dist/zk-artifacts.js.map +1 -0
  39. package/examples/README.md +4 -0
  40. package/examples/bootstrap-issuer-did.ts +4 -4
  41. package/examples/update-did.ts +3 -2
  42. package/package.json +9 -9
@@ -1,34 +1,45 @@
1
1
  import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
2
+ import { asSchnorrJubjubDigest, createControllerAuthorization, } from "./controller-authorization.js";
2
3
  import { normalizeBoundFragmentId } from "./did-subject.js";
3
4
  import { LedgerVerificationMethodRelationMap, schnorrJubjubVerificationMethodToLedger, verificationMethodToLedger, } from "./ledger-mappers.js";
4
5
  import { requireDeployedMidnightDIDLedgerState } from "./ledger-state.js";
5
6
  import { assertVerificationMethodRelationAbsent, assertVerificationMethodRelationPresent, purgeVerificationMethodFromAllRelations, } from "./verification-method-relations.js";
6
- export const addVerificationMethod = async (didContract, verificationMethod) => {
7
- const result = await didContract.callTx.setVerificationMethod(verificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Insert);
7
+ export const addVerificationMethod = async (didContract, providers, verificationMethod) => {
8
+ const ledgerVerificationMethod = verificationMethodToLedger(didContract, verificationMethod);
9
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerVerificationMethod, DIDContract.MapMutation.Insert)));
10
+ const result = await didContract.callTx.setVerificationMethod(ledgerVerificationMethod, DIDContract.MapMutation.Insert, signature, expectedVersion);
8
11
  return result.public;
9
12
  };
10
- export const updateVerificationMethod = async (didContract, verificationMethod) => {
11
- const result = await didContract.callTx.setVerificationMethod(verificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Update);
13
+ export const updateVerificationMethod = async (didContract, providers, verificationMethod) => {
14
+ const ledgerVerificationMethod = verificationMethodToLedger(didContract, verificationMethod);
15
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerVerificationMethod, DIDContract.MapMutation.Update)));
16
+ const result = await didContract.callTx.setVerificationMethod(ledgerVerificationMethod, DIDContract.MapMutation.Update, signature, expectedVersion);
12
17
  return result.public;
13
18
  };
14
19
  export const removeVerificationMethod = async (didContract, providers, methodId) => {
15
20
  const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
16
21
  await purgeVerificationMethodFromAllRelations(didContract, providers, normalizedMethodId);
17
- const result = await didContract.callTx.removeVerificationMethod(normalizedMethodId);
22
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.removeVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, normalizedMethodId)));
23
+ const result = await didContract.callTx.removeVerificationMethod(normalizedMethodId, signature, expectedVersion);
18
24
  return result.public;
19
25
  };
20
- export const addSchnorrJubjubVerificationMethod = async (didContract, verificationMethod) => {
21
- const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Insert);
26
+ export const addSchnorrJubjubVerificationMethod = async (didContract, providers, verificationMethod) => {
27
+ const ledgerVerificationMethod = schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod);
28
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setSchnorrJubjubVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerVerificationMethod, DIDContract.MapMutation.Insert)));
29
+ const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(ledgerVerificationMethod, DIDContract.MapMutation.Insert, signature, expectedVersion);
22
30
  return result.public;
23
31
  };
24
- export const updateSchnorrJubjubVerificationMethod = async (didContract, verificationMethod) => {
25
- const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Update);
32
+ export const updateSchnorrJubjubVerificationMethod = async (didContract, providers, verificationMethod) => {
33
+ const ledgerVerificationMethod = schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod);
34
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setSchnorrJubjubVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerVerificationMethod, DIDContract.MapMutation.Update)));
35
+ const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(ledgerVerificationMethod, DIDContract.MapMutation.Update, signature, expectedVersion);
26
36
  return result.public;
27
37
  };
28
38
  export const removeSchnorrJubjubVerificationMethod = async (didContract, providers, methodId) => {
29
39
  const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
30
40
  await purgeVerificationMethodFromAllRelations(didContract, providers, normalizedMethodId);
31
- const result = await didContract.callTx.removeSchnorrJubjubVerificationMethod(normalizedMethodId);
41
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.removeSchnorrJubjubVerificationMethodAuthorizationDigest(ledgerState.id, ledgerState.version, normalizedMethodId)));
42
+ const result = await didContract.callTx.removeSchnorrJubjubVerificationMethod(normalizedMethodId, signature, expectedVersion);
32
43
  return result.public;
33
44
  };
34
45
  /**
@@ -47,14 +58,18 @@ export const addVerificationMethodRelation = async (didContract, providers, rela
47
58
  const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
48
59
  const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
49
60
  assertVerificationMethodRelationAbsent(didState, relation, normalizedMethodId);
50
- const result = await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Insert);
61
+ const ledgerRelation = LedgerVerificationMethodRelationMap[relation];
62
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setVerificationMethodRelationAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Insert)));
63
+ const result = await didContract.callTx.setVerificationMethodRelation(ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Insert, signature, expectedVersion);
51
64
  return result.public;
52
65
  };
53
66
  export const removeVerificationMethodRelation = async (didContract, providers, relation, methodId) => {
54
67
  const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
55
68
  const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
56
69
  assertVerificationMethodRelationPresent(didState, relation, normalizedMethodId);
57
- const result = await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Remove);
70
+ const ledgerRelation = LedgerVerificationMethodRelationMap[relation];
71
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setVerificationMethodRelationAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Remove)));
72
+ const result = await didContract.callTx.setVerificationMethodRelation(ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Remove, signature, expectedVersion);
58
73
  return result.public;
59
74
  };
60
75
  //# sourceMappingURL=verification-method-operations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verification-method-operations.js","sourceRoot":"","sources":["../src/verification-method-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAOpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,mCAAmC,EACnC,uCAAuC,EACvC,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAC;AAQ1E,OAAO,EACL,sCAAsC,EACtC,uCAAuC,EACvC,uCAAuC,GACxC,MAAM,oCAAoC,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,WAAwC,EACxC,kB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CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,qCAAqC,CAC1D,SAAS,EACT,WAAW,CACZ,CAAC;IACF,sCAAsC,CACpC,QAAQ,EACR,QAAQ,EACR,kBAAkB,CACnB,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,6BAA6B,CACnE,mCAAmC,CAAC,QAAQ,CAAC,EAC7C,kBAAkB,EAClB,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG,KAAK,EACnD,WAAwC,EACxC,SAA+B,EAC/B,QAAwC,EACxC,QAAgB,EACU,EAAE;IAC5B,MAAM,kBAAkB,GAAG,wBAAwB,CACjD,WAAW,EACX,QAAQ,EACR,UAAU,CACX,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,qCAAqC,CAC1D,SAAS,EACT,WAAW,CACZ,CAAC;IACF,uCAAuC,CACrC,QAAQ,EACR,QAAQ,EACR,kBAAkB,CACnB,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,6BAA6B,CACnE,mCAAmC,CAAC,QAAQ,CAAC,EAC7C,kBAAkB,EAClB,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC"}
1
+ {"version":3,"file":"verification-method-operations.js","sourceRoot":"","sources":["../src/verification-method-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAOpE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EACL,mCAAmC,EACnC,uCAAuC,EACvC,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC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,CAAC,WAAW,CAAC,MAAM,EAC9B,SAAS,EACT,eAAe,CAChB,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC"}
@@ -9,5 +9,5 @@ export type VerificationMethodRelationMembership = {
9
9
  export declare const verificationMethodRelationMemberships: (didState: DIDContract.Ledger, normalizedMethodId: string) => readonly VerificationMethodRelationMembership[];
10
10
  export declare const assertVerificationMethodRelationAbsent: (didState: DIDContract.Ledger, relation: VerificationMethodRelationType, normalizedMethodId: string) => void;
11
11
  export declare const assertVerificationMethodRelationPresent: (didState: DIDContract.Ledger, relation: VerificationMethodRelationType, normalizedMethodId: string) => void;
12
- export declare const removePresentVerificationMethodRelations: (didContract: DeployedMidnightDIDContract, memberships: readonly VerificationMethodRelationMembership[], normalizedMethodId: string) => Promise<void>;
12
+ export declare const removePresentVerificationMethodRelations: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, memberships: readonly VerificationMethodRelationMembership[], normalizedMethodId: string) => Promise<void>;
13
13
  export declare const purgeVerificationMethodFromAllRelations: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, normalizedMethodId: string) => Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
2
2
  import { VerificationMethodRelationType } from "@midnight-ntwrk/midnight-did-domain";
3
+ import { asSchnorrJubjubDigest, createControllerAuthorization, } from "./controller-authorization.js";
3
4
  import { LedgerVerificationMethodRelationMap, relationSetFromState, } from "./ledger-mappers.js";
4
5
  import { requireDeployedMidnightDIDLedgerState } from "./ledger-state.js";
5
6
  export const VerificationMethodRelations = Object.freeze([
@@ -25,16 +26,18 @@ export const assertVerificationMethodRelationPresent = (didState, relation, norm
25
26
  throw new Error(`relation ${relation} does not contain verification method ${normalizedMethodId}`);
26
27
  }
27
28
  };
28
- export const removePresentVerificationMethodRelations = async (didContract, memberships, normalizedMethodId) => {
29
+ export const removePresentVerificationMethodRelations = async (didContract, providers, memberships, normalizedMethodId) => {
29
30
  for (const { relation, member } of memberships) {
30
31
  if (!member)
31
32
  continue;
32
- await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Remove);
33
+ const ledgerRelation = LedgerVerificationMethodRelationMap[relation];
34
+ const [signature, expectedVersion] = await createControllerAuthorization(didContract, providers, (ledgerState) => asSchnorrJubjubDigest(DIDContract.pureCircuits.setVerificationMethodRelationAuthorizationDigest(ledgerState.id, ledgerState.version, ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Remove)));
35
+ await didContract.callTx.setVerificationMethodRelation(ledgerRelation, normalizedMethodId, DIDContract.SetMutation.Remove, signature, expectedVersion);
33
36
  }
34
37
  };
35
38
  export const purgeVerificationMethodFromAllRelations = async (didContract, providers, normalizedMethodId) => {
36
39
  const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
37
40
  const memberships = verificationMethodRelationMemberships(didState, normalizedMethodId);
38
- await removePresentVerificationMethodRelations(didContract, memberships, normalizedMethodId);
41
+ await removePresentVerificationMethodRelations(didContract, providers, memberships, normalizedMethodId);
39
42
  };
40
43
  //# sourceMappingURL=verification-method-relations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verification-method-relations.js","sourceRoot":"","sources":["../src/verification-method-relations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,OAAO,EACL,mCAAmC,EACnC,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAC;AAM1E,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC;IACvD,8BAA8B,CAAC,cAAc;IAC7C,8BAA8B,CAAC,eAAe;IAC9C,8BAA8B,CAAC,YAAY;IAC3C,8BAA8B,CAAC,oBAAoB;IAC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AM,CAAC,6BAA6B,CACpD,mCAAmC,CAAC,QAAQ,CAAC,EAC7C,kBAAkB,EAClB,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uCAAuC,GAAG,KAAK,EAC1D,WAAwC,EACxC,SAA+B,EAC/B,kBAA0B,EACX,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,qCAAqC,CAC1D,SAAS,EACT,WAAW,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,qCAAqC,CACvD,QAAQ,EACR,kBAAkB,CACnB,CAAC;IAEF,MAAM,wCAAwC,CAC5C,WAAW,EACX,WAAW,EACX,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"verification-method-relations.js","sourceRoot":"","sources":["../src/verification-method-relations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,OAAO,EACL,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,mCAAmC,EACnC,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qCAAqC,EAAE,MAAM,mBAAmB,CAAC;AAM1E,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC;IACvD,8BAA8B,CAAC,cAAc;IAC7C,8BAA8B,CAAC,eAAe;IAC9C,8BAA8B,CAAC,YAAY;IAC3C,8BAA8B,CAAC,oBAAoB;IACnD,8BAA8B,CAAC,oBAAoB;CACS,CAAC,CAAC;AAOhE,MAAM,CAAC,MAAM,qCAAqC,GAAG,CACnD,QAA4B,EAC5B,kBAA0B,EACuB,EAAE,CACnD,2BAA2B,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC7C,QAAQ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AgD,CACvE,WAAW,CAAC,EAAE,EACd,WAAW,CAAC,OAAO,EACnB,cAAc,EACd,kBAAkB,EAClB,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CACF,CACJ,CAAC;QACF,MAAM,WAAW,CAAC,MAAM,CAAC,6BAA6B,CACpD,cAAc,EACd,kBAAkB,EAClB,WAAW,CAAC,WAAW,CAAC,MAAM,EAC9B,SAAS,EACT,eAAe,CAChB,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uCAAuC,GAAG,KAAK,EAC1D,WAAwC,EACxC,SAA+B,EAC/B,kBAA0B,EACX,EAAE;IACjB,MAAM,QAAQ,GAAG,MAAM,qCAAqC,CAC1D,SAAS,EACT,WAAW,CACZ,CAAC;IACF,MAAM,WAAW,GAAG,qCAAqC,CACvD,QAAQ,EACR,kBAAkB,CACnB,CAAC;IAEF,MAAM,wCAAwC,CAC5C,WAAW,EACX,SAAS,EACT,WAAW,EACX,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { type MidnightDidGhcrArtifactLocation, type MidnightDidGithubReleaseArtifactLocation, type MidnightDidZkArtifactProviderLayout } from "./release-artifacts.js";
2
+ export type MidnightDidZkArtifactErrorCode = "checksum_mismatch" | "download_failed" | "ghcr_pull_failed" | "manifest_mismatch" | "missing_archive" | "missing_checksum" | "provider_path_mismatch" | "unsafe_archive";
3
+ export declare class MidnightDidZkArtifactError extends Error {
4
+ readonly code: MidnightDidZkArtifactErrorCode;
5
+ constructor(code: MidnightDidZkArtifactErrorCode, message: string);
6
+ }
7
+ export interface MidnightDidZkArtifactCircuitManifest {
8
+ readonly id: string;
9
+ readonly files: {
10
+ readonly prover: string;
11
+ readonly verifier: string;
12
+ readonly zkir: string;
13
+ };
14
+ readonly sha256: {
15
+ readonly prover: string;
16
+ readonly verifier: string;
17
+ readonly zkir: string;
18
+ };
19
+ readonly bytes: {
20
+ readonly prover: number;
21
+ readonly verifier: number;
22
+ readonly zkir: number;
23
+ };
24
+ }
25
+ export interface MidnightDidZkArtifactManifest {
26
+ readonly schema: "midnight-did-zk-artifacts";
27
+ readonly schemaVersion: 1;
28
+ readonly version: string;
29
+ readonly packageName: string;
30
+ readonly providerLayout: MidnightDidZkArtifactProviderLayout;
31
+ readonly circuits: readonly MidnightDidZkArtifactCircuitManifest[];
32
+ }
33
+ export interface MidnightDidZkArtifactProviderRoots {
34
+ readonly zkConfigPath: string;
35
+ readonly fetchBaseUrl?: string;
36
+ readonly providerLayout: MidnightDidZkArtifactProviderLayout;
37
+ }
38
+ export interface MidnightDidZkArtifactBundle {
39
+ readonly archivePath: string;
40
+ readonly manifest: MidnightDidZkArtifactManifest;
41
+ readonly providers: MidnightDidZkArtifactProviderRoots;
42
+ readonly zkConfigPath: string;
43
+ }
44
+ export interface MidnightDidUnpackZkArtifactArchiveOptions {
45
+ readonly archivePath: string;
46
+ readonly expectedManifest?: MidnightDidZkArtifactManifest;
47
+ readonly expectedManifestJson?: unknown;
48
+ readonly outputDir?: string;
49
+ readonly version?: string;
50
+ readonly fetchBaseUrl?: string;
51
+ }
52
+ export interface MidnightDidDownloadGithubReleaseZkArtifactsOptions {
53
+ readonly fetch?: MidnightDidArtifactFetch;
54
+ readonly location?: MidnightDidGithubReleaseArtifactLocation;
55
+ readonly outputDir?: string;
56
+ readonly tempDir?: string;
57
+ readonly version?: string;
58
+ readonly fetchBaseUrl?: string;
59
+ }
60
+ export interface MidnightDidPullGhcrZkArtifactsOptions {
61
+ readonly location?: MidnightDidGhcrArtifactLocation;
62
+ readonly orasCommand?: string;
63
+ readonly outputDir?: string;
64
+ readonly pullDir?: string;
65
+ readonly version?: string;
66
+ readonly fetchBaseUrl?: string;
67
+ }
68
+ export interface MidnightDidArtifactFetchResponse {
69
+ readonly ok: boolean;
70
+ readonly status: number;
71
+ readonly statusText: string;
72
+ readonly arrayBuffer: () => Promise<ArrayBuffer>;
73
+ readonly text: () => Promise<string>;
74
+ }
75
+ export type MidnightDidArtifactFetch = (input: string) => Promise<MidnightDidArtifactFetchResponse>;
76
+ export declare const createMidnightDidZkArtifactFetchBaseUrl: (baseUrl: string) => string;
77
+ export declare const createMidnightDidZkArtifactFetchUrls: (baseUrl: string, circuitId: string) => {
78
+ readonly proverKey: string;
79
+ readonly verifierKey: string;
80
+ readonly zkir: string;
81
+ };
82
+ export declare const verifyMidnightDidZkArtifactManifest: ({ expectedManifest, expectedManifestJson, manifestPath, version, zkConfigPath, }: {
83
+ readonly expectedManifest?: MidnightDidZkArtifactManifest;
84
+ readonly expectedManifestJson?: unknown;
85
+ readonly manifestPath: string;
86
+ readonly version?: string;
87
+ readonly zkConfigPath: string;
88
+ }) => MidnightDidZkArtifactManifest;
89
+ export declare const unpackMidnightDidZkArtifactArchive: (options: MidnightDidUnpackZkArtifactArchiveOptions) => MidnightDidZkArtifactBundle;
90
+ export declare const downloadMidnightDidGithubReleaseZkArtifacts: (options?: MidnightDidDownloadGithubReleaseZkArtifactsOptions) => Promise<MidnightDidZkArtifactBundle>;
91
+ export declare const pullMidnightDidGhcrZkArtifacts: (options?: MidnightDidPullGhcrZkArtifactsOptions) => MidnightDidZkArtifactBundle;
@@ -0,0 +1,402 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { createMidnightDidZkArtifactLocations, MIDNIGHT_DID_API_VERSION, } from "./release-artifacts.js";
7
+ export class MidnightDidZkArtifactError extends Error {
8
+ code;
9
+ constructor(code, message) {
10
+ super(message);
11
+ this.code = code;
12
+ this.name = "MidnightDidZkArtifactError";
13
+ }
14
+ }
15
+ const expectedProviderLayout = {
16
+ proverKey: "keys/{circuitId}.prover",
17
+ verifierKey: "keys/{circuitId}.verifier",
18
+ zkir: "zkir/{circuitId}.bzkir",
19
+ };
20
+ const artifactKinds = ["prover", "verifier", "zkir"];
21
+ const expectedPackageName = "@midnight-ntwrk/midnight-did-contract";
22
+ const sha256File = (filePath) => createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
23
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
24
+ const parseJsonText = (contents, label) => {
25
+ try {
26
+ return JSON.parse(contents);
27
+ }
28
+ catch (error) {
29
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `${label} must be valid JSON: ${error instanceof Error ? error.message : String(error)}`);
30
+ }
31
+ };
32
+ const readJsonFile = (filePath, label) => parseJsonText(fs.readFileSync(filePath, "utf8"), label);
33
+ const normalizeSha256Digest = (value, label) => {
34
+ if (!/^[0-9a-f]{64}$/iu.test(value)) {
35
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `${label} must be a SHA-256 hex digest`);
36
+ }
37
+ return value.toLowerCase();
38
+ };
39
+ const requireString = (value, label, code = "manifest_mismatch") => {
40
+ if (typeof value !== "string" || value.length === 0) {
41
+ throw new MidnightDidZkArtifactError(code, `${label} must be a string`);
42
+ }
43
+ return value;
44
+ };
45
+ const requireNumber = (value, label) => {
46
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
47
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `${label} must be a non-negative integer`);
48
+ }
49
+ return value;
50
+ };
51
+ const readManifest = (manifestPath) => parseManifest(readJsonFile(manifestPath, "ZK artifact manifest"));
52
+ const parseManifest = (value) => {
53
+ if (!isRecord(value)) {
54
+ throw new MidnightDidZkArtifactError("manifest_mismatch", "ZK artifact manifest must be an object");
55
+ }
56
+ if (value.schema !== "midnight-did-zk-artifacts") {
57
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `Unexpected ZK artifact manifest schema: ${String(value.schema)}`);
58
+ }
59
+ if (value.schemaVersion !== 1) {
60
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `Unexpected ZK artifact manifest schemaVersion: ${String(value.schemaVersion)}`);
61
+ }
62
+ if (!isRecord(value.providerLayout)) {
63
+ throw new MidnightDidZkArtifactError("provider_path_mismatch", "ZK artifact manifest is missing providerLayout");
64
+ }
65
+ const providerLayout = {
66
+ proverKey: requireString(value.providerLayout.proverKey, "providerLayout.proverKey", "provider_path_mismatch"),
67
+ verifierKey: requireString(value.providerLayout.verifierKey, "providerLayout.verifierKey", "provider_path_mismatch"),
68
+ zkir: requireString(value.providerLayout.zkir, "providerLayout.zkir", "provider_path_mismatch"),
69
+ };
70
+ if (JSON.stringify(providerLayout) !== JSON.stringify(expectedProviderLayout)) {
71
+ throw new MidnightDidZkArtifactError("provider_path_mismatch", "ZK artifact providerLayout does not match Midnight JS provider roots");
72
+ }
73
+ if (!Array.isArray(value.circuits) || value.circuits.length === 0) {
74
+ throw new MidnightDidZkArtifactError("manifest_mismatch", "ZK artifact manifest must include at least one circuit");
75
+ }
76
+ const packageName = requireString(value.packageName, "packageName");
77
+ if (packageName !== expectedPackageName) {
78
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `ZK artifact packageName ${packageName} did not match ${expectedPackageName}`);
79
+ }
80
+ return {
81
+ schema: "midnight-did-zk-artifacts",
82
+ schemaVersion: 1,
83
+ version: requireString(value.version, "version"),
84
+ packageName,
85
+ providerLayout: expectedProviderLayout,
86
+ circuits: value.circuits.map((circuit, index) => parseCircuitManifest(circuit, index)),
87
+ };
88
+ };
89
+ const parseCircuitManifest = (value, index) => {
90
+ if (!isRecord(value)) {
91
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `circuits[${index}] must be an object`);
92
+ }
93
+ if (!isRecord(value.files) ||
94
+ !isRecord(value.sha256) ||
95
+ !isRecord(value.bytes)) {
96
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `circuits[${index}] must include files, sha256, and bytes`);
97
+ }
98
+ const id = requireString(value.id, `circuits[${index}].id`);
99
+ const files = {
100
+ prover: requireString(value.files.prover, `${id}.files.prover`),
101
+ verifier: requireString(value.files.verifier, `${id}.files.verifier`),
102
+ zkir: requireString(value.files.zkir, `${id}.files.zkir`),
103
+ };
104
+ assertProviderPath(id, "prover", files.prover);
105
+ assertProviderPath(id, "verifier", files.verifier);
106
+ assertProviderPath(id, "zkir", files.zkir);
107
+ return {
108
+ id,
109
+ files,
110
+ sha256: {
111
+ prover: normalizeSha256Digest(requireString(value.sha256.prover, `${id}.sha256.prover`), `${id}.sha256.prover`),
112
+ verifier: normalizeSha256Digest(requireString(value.sha256.verifier, `${id}.sha256.verifier`), `${id}.sha256.verifier`),
113
+ zkir: normalizeSha256Digest(requireString(value.sha256.zkir, `${id}.sha256.zkir`), `${id}.sha256.zkir`),
114
+ },
115
+ bytes: {
116
+ prover: requireNumber(value.bytes.prover, `${id}.bytes.prover`),
117
+ verifier: requireNumber(value.bytes.verifier, `${id}.bytes.verifier`),
118
+ zkir: requireNumber(value.bytes.zkir, `${id}.bytes.zkir`),
119
+ },
120
+ };
121
+ };
122
+ const expectedProviderPath = (circuitId, kind) => {
123
+ switch (kind) {
124
+ case "prover":
125
+ return `keys/${circuitId}.prover`;
126
+ case "verifier":
127
+ return `keys/${circuitId}.verifier`;
128
+ case "zkir":
129
+ return `zkir/${circuitId}.bzkir`;
130
+ }
131
+ };
132
+ const assertProviderPath = (circuitId, kind, relativePath) => {
133
+ const expected = expectedProviderPath(circuitId, kind);
134
+ if (relativePath !== expected) {
135
+ throw new MidnightDidZkArtifactError("provider_path_mismatch", `${circuitId}: ${kind} path ${relativePath} must be ${expected}`);
136
+ }
137
+ };
138
+ const assertSafeArchiveEntry = (entry) => {
139
+ if (path.isAbsolute(entry) ||
140
+ entry.includes("\\") ||
141
+ entry.split("/").includes("..")) {
142
+ throw new MidnightDidZkArtifactError("unsafe_archive", `Unsafe ZK artifact archive entry: ${entry}`);
143
+ }
144
+ };
145
+ const assertAllowedArchiveEntry = (entry) => {
146
+ if (entry === "manifest.json" ||
147
+ /^keys\/[^/]+\.(prover|verifier)$/u.test(entry) ||
148
+ /^zkir\/[^/]+\.bzkir$/u.test(entry)) {
149
+ return;
150
+ }
151
+ throw new MidnightDidZkArtifactError("provider_path_mismatch", `Unexpected ZK artifact archive entry: ${entry}`);
152
+ };
153
+ const listArchiveEntries = (archivePath) => {
154
+ const typedResult = spawnSync("tar", ["-tvzf", archivePath], {
155
+ encoding: "utf8",
156
+ });
157
+ if (typedResult.status !== 0) {
158
+ throw new MidnightDidZkArtifactError("unsafe_archive", `Could not inspect ZK artifact archive ${archivePath}:\n${typedResult.stdout}${typedResult.stderr}`);
159
+ }
160
+ for (const line of typedResult.stdout.split(/\r?\n/u)) {
161
+ if (line.length === 0) {
162
+ continue;
163
+ }
164
+ const entryType = line[0];
165
+ if (entryType !== "-" && entryType !== "d") {
166
+ throw new MidnightDidZkArtifactError("unsafe_archive", `Unsafe ZK artifact archive entry type: ${line}`);
167
+ }
168
+ }
169
+ const result = spawnSync("tar", ["-tzf", archivePath], { encoding: "utf8" });
170
+ if (result.status !== 0) {
171
+ throw new MidnightDidZkArtifactError("unsafe_archive", `Could not list ZK artifact archive ${archivePath}:\n${result.stdout}${result.stderr}`);
172
+ }
173
+ const entries = result.stdout
174
+ .split(/\r?\n/u)
175
+ .map((entry) => entry.replace(/^\.\//u, ""))
176
+ .filter((entry) => entry.length > 0);
177
+ if (!entries.includes("manifest.json")) {
178
+ throw new MidnightDidZkArtifactError("manifest_mismatch", "ZK artifact archive is missing manifest.json");
179
+ }
180
+ for (const entry of entries) {
181
+ assertSafeArchiveEntry(entry);
182
+ if (!entry.endsWith("/")) {
183
+ assertAllowedArchiveEntry(entry);
184
+ }
185
+ }
186
+ return entries;
187
+ };
188
+ const extractArchive = (archivePath, outputDir) => {
189
+ fs.mkdirSync(outputDir, { recursive: true });
190
+ const result = spawnSync("tar", ["-xzf", archivePath, "-C", outputDir], {
191
+ encoding: "utf8",
192
+ });
193
+ if (result.status !== 0) {
194
+ throw new MidnightDidZkArtifactError("unsafe_archive", `Could not extract ZK artifact archive ${archivePath}:\n${result.stdout}${result.stderr}`);
195
+ }
196
+ };
197
+ const assertRegularFile = (filePath, label) => {
198
+ const stat = fs.lstatSync(filePath);
199
+ if (!stat.isFile()) {
200
+ throw new MidnightDidZkArtifactError("unsafe_archive", `${label} must be a regular file`);
201
+ }
202
+ };
203
+ const verifyManifestFiles = (manifest, zkConfigPath) => {
204
+ for (const circuit of manifest.circuits) {
205
+ for (const kind of artifactKinds) {
206
+ const relativePath = circuit.files[kind];
207
+ assertProviderPath(circuit.id, kind, relativePath);
208
+ const artifactPath = path.join(zkConfigPath, ...relativePath.split("/"));
209
+ if (!fs.existsSync(artifactPath)) {
210
+ throw new MidnightDidZkArtifactError("provider_path_mismatch", `${circuit.id}: missing ${kind} artifact at ${relativePath}`);
211
+ }
212
+ assertRegularFile(artifactPath, `${circuit.id}: ${kind} artifact`);
213
+ const actualHash = sha256File(artifactPath);
214
+ if (actualHash !== circuit.sha256[kind]) {
215
+ throw new MidnightDidZkArtifactError("checksum_mismatch", `${circuit.id}: ${kind} sha256 mismatch`);
216
+ }
217
+ const actualBytes = fs.statSync(artifactPath).size;
218
+ if (actualBytes !== circuit.bytes[kind]) {
219
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `${circuit.id}: ${kind} byte size mismatch`);
220
+ }
221
+ }
222
+ }
223
+ };
224
+ const assertManifestMatches = (actual, expected) => {
225
+ if (JSON.stringify(actual) !== JSON.stringify(expected)) {
226
+ throw new MidnightDidZkArtifactError("manifest_mismatch", "Downloaded ZK artifact manifest does not match the archive manifest");
227
+ }
228
+ };
229
+ const assertManifestJsonMatches = (actual, expected) => {
230
+ assertManifestMatches(parseManifest(actual), parseManifest(expected));
231
+ };
232
+ const parseSha256File = (contents) => {
233
+ const hash = contents.trim().split(/\s+/u)[0];
234
+ return normalizeSha256Digest(hash, "ZK artifact sha256 file");
235
+ };
236
+ const verifyArchiveSha256 = (archivePath, sha256Contents) => {
237
+ const expected = parseSha256File(sha256Contents);
238
+ const actual = sha256File(archivePath);
239
+ if (actual !== expected) {
240
+ throw new MidnightDidZkArtifactError("checksum_mismatch", `ZK artifact archive sha256 mismatch for ${path.basename(archivePath)}: expected ${expected}, got ${actual}`);
241
+ }
242
+ };
243
+ const defaultFetch = async (input) => {
244
+ const fetchImplementation = globalThis.fetch;
245
+ if (typeof fetchImplementation !== "function") {
246
+ throw new MidnightDidZkArtifactError("download_failed", "global fetch is not available; pass a fetch implementation");
247
+ }
248
+ return fetchImplementation(input);
249
+ };
250
+ const fetchBinary = async (fetchImplementation, url) => {
251
+ const response = await fetchImplementation(url);
252
+ if (!response.ok) {
253
+ throw new MidnightDidZkArtifactError("download_failed", `Could not download ZK artifact ${url}: ${response.status} ${response.statusText}`);
254
+ }
255
+ return Buffer.from(await response.arrayBuffer());
256
+ };
257
+ const fetchText = async (fetchImplementation, url) => {
258
+ const response = await fetchImplementation(url);
259
+ if (!response.ok) {
260
+ throw new MidnightDidZkArtifactError("download_failed", `Could not download ZK artifact metadata ${url}: ${response.status} ${response.statusText}`);
261
+ }
262
+ return response.text();
263
+ };
264
+ const writeDownloadedFile = (directory, fileName, contents) => {
265
+ fs.mkdirSync(directory, { recursive: true });
266
+ const filePath = path.join(directory, fileName);
267
+ fs.writeFileSync(filePath, contents);
268
+ return filePath;
269
+ };
270
+ const selectGhcrArchive = (directory, version) => {
271
+ const locations = createMidnightDidZkArtifactLocations(version);
272
+ const expectedArchive = path.join(directory, locations.archiveName);
273
+ const fallbackArchive = fs
274
+ .readdirSync(directory)
275
+ .find((fileName) => /^midnight-did-zk-artifacts-.+\.tar\.gz$/u.test(fileName));
276
+ const archivePath = fs.existsSync(expectedArchive)
277
+ ? expectedArchive
278
+ : fallbackArchive === undefined
279
+ ? undefined
280
+ : path.join(directory, fallbackArchive);
281
+ if (archivePath === undefined || !fs.existsSync(archivePath)) {
282
+ throw new MidnightDidZkArtifactError("missing_archive", `GHCR pull did not produce ${locations.archiveName}`);
283
+ }
284
+ const manifestPath = path.join(directory, locations.manifestName);
285
+ const sha256Path = path.join(directory, locations.sha256Name);
286
+ return {
287
+ archivePath,
288
+ manifestPath: fs.existsSync(manifestPath) ? manifestPath : undefined,
289
+ sha256Path: fs.existsSync(sha256Path) ? sha256Path : undefined,
290
+ };
291
+ };
292
+ export const createMidnightDidZkArtifactFetchBaseUrl = (baseUrl) => baseUrl.replace(/\/+$/u, "");
293
+ export const createMidnightDidZkArtifactFetchUrls = (baseUrl, circuitId) => {
294
+ const root = createMidnightDidZkArtifactFetchBaseUrl(baseUrl);
295
+ return {
296
+ proverKey: `${root}/keys/${encodeURIComponent(circuitId)}.prover`,
297
+ verifierKey: `${root}/keys/${encodeURIComponent(circuitId)}.verifier`,
298
+ zkir: `${root}/zkir/${encodeURIComponent(circuitId)}.bzkir`,
299
+ };
300
+ };
301
+ export const verifyMidnightDidZkArtifactManifest = ({ expectedManifest, expectedManifestJson, manifestPath, version, zkConfigPath, }) => {
302
+ assertRegularFile(manifestPath, "ZK artifact manifest");
303
+ const manifestJson = readJsonFile(manifestPath, "ZK artifact manifest");
304
+ const manifest = parseManifest(manifestJson);
305
+ if (version && manifest.version !== version) {
306
+ throw new MidnightDidZkArtifactError("manifest_mismatch", `ZK artifact manifest version ${manifest.version} did not match ${version}`);
307
+ }
308
+ if (expectedManifest) {
309
+ assertManifestMatches(manifest, expectedManifest);
310
+ }
311
+ if (expectedManifestJson !== undefined) {
312
+ assertManifestJsonMatches(manifestJson, expectedManifestJson);
313
+ }
314
+ verifyManifestFiles(manifest, zkConfigPath);
315
+ return manifest;
316
+ };
317
+ export const unpackMidnightDidZkArtifactArchive = (options) => {
318
+ const archivePath = path.resolve(options.archivePath);
319
+ if (!fs.existsSync(archivePath)) {
320
+ throw new MidnightDidZkArtifactError("missing_archive", `ZK artifact archive does not exist: ${archivePath}`);
321
+ }
322
+ listArchiveEntries(archivePath);
323
+ const outputDir = options.outputDir === undefined
324
+ ? fs.mkdtempSync(path.join(os.tmpdir(), "midnight-did-zk-"))
325
+ : path.resolve(options.outputDir);
326
+ extractArchive(archivePath, outputDir);
327
+ const manifest = verifyMidnightDidZkArtifactManifest({
328
+ expectedManifest: options.expectedManifest,
329
+ expectedManifestJson: options.expectedManifestJson,
330
+ manifestPath: path.join(outputDir, "manifest.json"),
331
+ version: options.version,
332
+ zkConfigPath: outputDir,
333
+ });
334
+ return {
335
+ archivePath,
336
+ manifest,
337
+ providers: {
338
+ zkConfigPath: outputDir,
339
+ fetchBaseUrl: options.fetchBaseUrl === undefined
340
+ ? undefined
341
+ : createMidnightDidZkArtifactFetchBaseUrl(options.fetchBaseUrl),
342
+ providerLayout: manifest.providerLayout,
343
+ },
344
+ zkConfigPath: outputDir,
345
+ };
346
+ };
347
+ export const downloadMidnightDidGithubReleaseZkArtifacts = async (options = {}) => {
348
+ const version = options.version ?? MIDNIGHT_DID_API_VERSION;
349
+ const locations = createMidnightDidZkArtifactLocations(version);
350
+ const location = options.location ?? locations.githubRelease;
351
+ if (!location) {
352
+ throw new MidnightDidZkArtifactError("missing_archive", `GitHub Release ZK artifacts are not published for ${locations.channel} version ${version}`);
353
+ }
354
+ const fetchImplementation = options.fetch ?? defaultFetch;
355
+ const tempDir = options.tempDir === undefined
356
+ ? fs.mkdtempSync(path.join(os.tmpdir(), "midnight-did-zk-download-"))
357
+ : path.resolve(options.tempDir);
358
+ const archivePath = writeDownloadedFile(tempDir, locations.archiveName, await fetchBinary(fetchImplementation, location.archiveUrl));
359
+ const sha256Contents = await fetchText(fetchImplementation, location.sha256Url);
360
+ writeDownloadedFile(tempDir, locations.sha256Name, sha256Contents);
361
+ verifyArchiveSha256(archivePath, sha256Contents);
362
+ const expectedManifestJson = parseJsonText(await fetchText(fetchImplementation, location.manifestUrl), `ZK artifact manifest ${location.manifestUrl}`);
363
+ const expectedManifest = parseManifest(expectedManifestJson);
364
+ writeDownloadedFile(tempDir, locations.manifestName, `${JSON.stringify(expectedManifest, null, 2)}\n`);
365
+ return unpackMidnightDidZkArtifactArchive({
366
+ archivePath,
367
+ expectedManifest,
368
+ expectedManifestJson,
369
+ fetchBaseUrl: options.fetchBaseUrl,
370
+ outputDir: options.outputDir,
371
+ version,
372
+ });
373
+ };
374
+ export const pullMidnightDidGhcrZkArtifacts = (options = {}) => {
375
+ const version = options.version ?? MIDNIGHT_DID_API_VERSION;
376
+ const locations = createMidnightDidZkArtifactLocations(version);
377
+ const location = options.location ?? locations.ghcr;
378
+ const pullDir = options.pullDir === undefined
379
+ ? fs.mkdtempSync(path.join(os.tmpdir(), "midnight-did-zk-ghcr-"))
380
+ : path.resolve(options.pullDir);
381
+ fs.mkdirSync(pullDir, { recursive: true });
382
+ const result = spawnSync(options.orasCommand ?? "oras", ["pull", location.reference, "--output", pullDir], { encoding: "utf8" });
383
+ if (result.status !== 0) {
384
+ throw new MidnightDidZkArtifactError("ghcr_pull_failed", `Could not pull ${location.reference} with ORAS:\n${result.stdout}${result.stderr}`);
385
+ }
386
+ const { archivePath, manifestPath, sha256Path } = selectGhcrArchive(pullDir, version);
387
+ if (sha256Path === undefined) {
388
+ throw new MidnightDidZkArtifactError("missing_checksum", `GHCR pull did not produce ${locations.sha256Name}`);
389
+ }
390
+ verifyArchiveSha256(archivePath, fs.readFileSync(sha256Path, "utf8"));
391
+ return unpackMidnightDidZkArtifactArchive({
392
+ archivePath,
393
+ expectedManifest: manifestPath === undefined ? undefined : readManifest(manifestPath),
394
+ expectedManifestJson: manifestPath === undefined
395
+ ? undefined
396
+ : readJsonFile(manifestPath, "ZK artifact manifest"),
397
+ fetchBaseUrl: options.fetchBaseUrl,
398
+ outputDir: options.outputDir,
399
+ version,
400
+ });
401
+ };
402
+ //# sourceMappingURL=zk-artifacts.js.map