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

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 (135) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +218 -0
  3. package/dist/api-logger.d.ts +3 -0
  4. package/dist/api-logger.js +8 -0
  5. package/dist/api-logger.js.map +1 -0
  6. package/dist/browser.d.ts +6 -0
  7. package/dist/browser.js +6 -0
  8. package/dist/browser.js.map +1 -0
  9. package/dist/config-profiles.d.ts +75 -0
  10. package/dist/config-profiles.js +75 -0
  11. package/dist/config-profiles.js.map +1 -0
  12. package/dist/config.d.ts +37 -0
  13. package/dist/config.js +50 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/contract-instance.d.ts +7 -0
  16. package/dist/contract-instance.js +6 -0
  17. package/dist/contract-instance.js.map +1 -0
  18. package/dist/contract-lifecycle-operations.d.ts +4 -0
  19. package/dist/contract-lifecycle-operations.js +40 -0
  20. package/dist/contract-lifecycle-operations.js.map +1 -0
  21. package/dist/contract-lifecycle.d.ts +6 -0
  22. package/dist/contract-lifecycle.js +7 -0
  23. package/dist/contract-lifecycle.js.map +1 -0
  24. package/dist/controller-operations.d.ts +9 -0
  25. package/dist/controller-operations.js +49 -0
  26. package/dist/controller-operations.js.map +1 -0
  27. package/dist/deploy.d.ts +6 -0
  28. package/dist/deploy.js +7 -0
  29. package/dist/deploy.js.map +1 -0
  30. package/dist/did-operations.d.ts +6 -0
  31. package/dist/did-operations.js +7 -0
  32. package/dist/did-operations.js.map +1 -0
  33. package/dist/did-subject.d.ts +6 -0
  34. package/dist/did-subject.js +11 -0
  35. package/dist/did-subject.js.map +1 -0
  36. package/dist/document-operations.d.ts +5 -0
  37. package/dist/document-operations.js +17 -0
  38. package/dist/document-operations.js.map +1 -0
  39. package/dist/domain-to-runtime.d.ts +4 -0
  40. package/dist/domain-to-runtime.js +7 -0
  41. package/dist/domain-to-runtime.js.map +1 -0
  42. package/dist/index.d.ts +8 -0
  43. package/dist/index.js +8 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/ledger-mappers.d.ts +15 -0
  46. package/dist/ledger-mappers.js +137 -0
  47. package/dist/ledger-mappers.js.map +1 -0
  48. package/dist/ledger-state.d.ts +6 -0
  49. package/dist/ledger-state.js +24 -0
  50. package/dist/ledger-state.js.map +1 -0
  51. package/dist/lib.d.ts +15 -0
  52. package/dist/lib.js +16 -0
  53. package/dist/lib.js.map +1 -0
  54. package/dist/lightweight.d.ts +1 -0
  55. package/dist/lightweight.js +9 -0
  56. package/dist/lightweight.js.map +1 -0
  57. package/dist/logger-utils.d.ts +3 -0
  58. package/dist/logger-utils.js +26 -0
  59. package/dist/logger-utils.js.map +1 -0
  60. package/dist/network-mapping.d.ts +6 -0
  61. package/dist/network-mapping.js +20 -0
  62. package/dist/network-mapping.js.map +1 -0
  63. package/dist/package-paths.d.ts +10 -0
  64. package/dist/package-paths.js +31 -0
  65. package/dist/package-paths.js.map +1 -0
  66. package/dist/polyfills.d.ts +1 -0
  67. package/dist/polyfills.js +7 -0
  68. package/dist/polyfills.js.map +1 -0
  69. package/dist/private-state-storage.d.ts +8 -0
  70. package/dist/private-state-storage.js +18 -0
  71. package/dist/private-state-storage.js.map +1 -0
  72. package/dist/private-state.d.ts +13 -0
  73. package/dist/private-state.js +75 -0
  74. package/dist/private-state.js.map +1 -0
  75. package/dist/providers.d.ts +13 -0
  76. package/dist/providers.js +32 -0
  77. package/dist/providers.js.map +1 -0
  78. package/dist/release-artifacts.d.ts +41 -0
  79. package/dist/release-artifacts.js +60 -0
  80. package/dist/release-artifacts.js.map +1 -0
  81. package/dist/resolution.d.ts +15 -0
  82. package/dist/resolution.js +46 -0
  83. package/dist/resolution.js.map +1 -0
  84. package/dist/runtime-to-domain.d.ts +4 -0
  85. package/dist/runtime-to-domain.js +7 -0
  86. package/dist/runtime-to-domain.js.map +1 -0
  87. package/dist/seed.d.ts +1 -0
  88. package/dist/seed.js +13 -0
  89. package/dist/seed.js.map +1 -0
  90. package/dist/service-operations.d.ts +6 -0
  91. package/dist/service-operations.js +17 -0
  92. package/dist/service-operations.js.map +1 -0
  93. package/dist/transaction-intents.d.ts +9 -0
  94. package/dist/transaction-intents.js +27 -0
  95. package/dist/transaction-intents.js.map +1 -0
  96. package/dist/types.d.ts +60 -0
  97. package/dist/types.js +9 -0
  98. package/dist/types.js.map +1 -0
  99. package/dist/update.d.ts +7 -0
  100. package/dist/update.js +8 -0
  101. package/dist/update.js.map +1 -0
  102. package/dist/verification-method-operations.d.ts +19 -0
  103. package/dist/verification-method-operations.js +60 -0
  104. package/dist/verification-method-operations.js.map +1 -0
  105. package/dist/verification-method-relations.d.ts +13 -0
  106. package/dist/verification-method-relations.js +40 -0
  107. package/dist/verification-method-relations.js.map +1 -0
  108. package/dist/wallet-context.d.ts +3 -0
  109. package/dist/wallet-context.js +55 -0
  110. package/dist/wallet-context.js.map +1 -0
  111. package/dist/wallet-dust.d.ts +10 -0
  112. package/dist/wallet-dust.js +28 -0
  113. package/dist/wallet-dust.js.map +1 -0
  114. package/dist/wallet-keys.d.ts +5 -0
  115. package/dist/wallet-keys.js +27 -0
  116. package/dist/wallet-keys.js.map +1 -0
  117. package/dist/wallet-provider.d.ts +3 -0
  118. package/dist/wallet-provider.js +29 -0
  119. package/dist/wallet-provider.js.map +1 -0
  120. package/dist/wallet-sdk-config.d.ts +32 -0
  121. package/dist/wallet-sdk-config.js +23 -0
  122. package/dist/wallet-sdk-config.js.map +1 -0
  123. package/dist/wallet-state.d.ts +6 -0
  124. package/dist/wallet-state.js +32 -0
  125. package/dist/wallet-state.js.map +1 -0
  126. package/dist/wallet.d.ts +9 -0
  127. package/dist/wallet.js +17 -0
  128. package/dist/wallet.js.map +1 -0
  129. package/examples/README.md +60 -0
  130. package/examples/bootstrap-issuer-did.ts +313 -0
  131. package/examples/deploy-did.ts +40 -0
  132. package/examples/update-did.ts +84 -0
  133. package/package.json +88 -0
  134. package/tsconfig.build.json +5 -0
  135. package/tsconfig.json +23 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # @midnight-ntwrk/midnight-did-api
2
+
3
+ Programmatic API for creating, updating, deactivating, and resolving Midnight DIDs.
4
+
5
+ ## Responsibilities
6
+
7
+ - Build/connect providers (node, indexer, proof server)
8
+ - Submit contract circuits for DID operations
9
+ - Map inputs/outputs between app/domain and ledger/runtime
10
+ - Generate and persist DID controller private state for create/rotation flows
11
+ - Provide integration test topology and helpers
12
+ - Return DID resolution data (`didDocument`, `didDocumentMetadata`) for API callers
13
+
14
+ ## Use It When
15
+
16
+ - you need programmatic DID deployment or mutation flows
17
+ - you need provider bootstrap for standalone, preprod, or env-driven mainnet
18
+ - you are building a higher-level application and do not want to manage raw contract/runtime wiring
19
+
20
+ ## Architecture
21
+
22
+ ```mermaid
23
+ graph TD
24
+ App[Manager / Tests / Integrator]
25
+ API[API facade]
26
+ Domain[Domain validation]
27
+ DidPkg[DID mapper]
28
+ Contract[Contract bindings]
29
+ Providers[Providers]
30
+ Chain[(Midnight chain)]
31
+ Indexer[(Indexer)]
32
+
33
+ App --> API
34
+ API --> Domain
35
+ API --> DidPkg
36
+ API --> Contract
37
+ API --> Providers
38
+ Providers --> Chain
39
+ Providers --> Indexer
40
+ ```
41
+
42
+ ## Update Sequence
43
+
44
+ ```mermaid
45
+ sequenceDiagram
46
+ participant Caller
47
+ participant API
48
+ participant Contract
49
+ participant Indexer
50
+
51
+ Caller->>API: addService / addVerificationMethod / ...
52
+ API->>API: validate + normalize
53
+ API->>Contract: submit circuit tx
54
+ Contract-->>API: accepted tx
55
+ API->>Indexer: fetch current state
56
+ API-->>Caller: updated DID state or DID Resolution Result
57
+ ```
58
+
59
+ ## State Model
60
+
61
+ API enforces lifecycle rules around:
62
+
63
+ - active DID: allows updates
64
+ - deactivated DID: mutating operations rejected
65
+ - controller rotation: generates a new wallet-local secret, derives the next controller public key locally, submits the rotation circuit, and stores the new secret after the transaction succeeds
66
+
67
+ (Exact schema/canonicalization rules live in `domain`.)
68
+
69
+ ## Resolution Responses
70
+
71
+ The API package exposes both convenience and DID Core envelope helpers.
72
+ `resolve` returns the ledger-derived DID Document and DID Document metadata, or
73
+ `null` when the contract state is missing. `resolveDIDResolutionResult` returns
74
+ the full DID Core Resolution Result envelope with `didResolutionMetadata`.
75
+ Successful abstract `resolve` responses must not set
76
+ `didResolutionMetadata.contentType`; that field is reserved for
77
+ `resolveRepresentation` responses where the body is a DID Document byte stream.
78
+
79
+ ## Build & Test
80
+
81
+ - Build: `pnpm --filter ./packages/api build`
82
+ - Typecheck examples: `pnpm --filter ./packages/api typecheck:examples`
83
+ - API import discipline: `pnpm run check:api-source-imports`
84
+ - DID package import discipline: `pnpm run check:source-imports`
85
+ - Unit tests: `pnpm --filter ./packages/api test`
86
+ - Integration tests: `pnpm --filter ./packages/api test-api`
87
+
88
+ API TypeScript source and tests use explicit `.js` or `.json` extensions for
89
+ relative imports, including Vitest mocks. This keeps the package aligned with
90
+ the emitted ESM graph and avoids resolver-only test behavior.
91
+ The wider `check:source-imports` guard applies the same rule to all DID-owned
92
+ TypeScript package sources outside generated `src/managed` artifacts.
93
+
94
+ ## Runtime Profiles
95
+
96
+ - `StandaloneConfig`
97
+ - `TestnetLocalConfig`
98
+ - `TestnetRemoteConfig`
99
+ - `PreprodConfig`
100
+ - `MainnetConfig`
101
+ - `ProfileConfig`
102
+
103
+ Defaults:
104
+
105
+ - all profile defaults live in `src/config-profiles.ts`
106
+ - `PreprodConfig` and `MainnetConfig` use public indexer v4 endpoints (`/api/v4/graphql` + `/ws`).
107
+ - `MainnetConfig` defaults to local proof server (`http://127.0.0.1:6300`) so it can be used with local proving while targeting mainnet indexer/node.
108
+ - constructing any profile config calls `setNetworkId()` through `applyMidnightNetworkProfile()`, so wallet and contract operations see the correct Midnight network before they start.
109
+
110
+ You can still override `MainnetConfig` endpoints explicitly when needed. New
111
+ tooling should use `ProfileConfig` when the profile name is data-driven rather
112
+ than hard-coded in a class constructor. Every `ProfileConfig` instance exposes
113
+ the resolved `profileName` so logs and operator tooling can report the active
114
+ profile without inferring it from URLs.
115
+
116
+ ## Network Mapping Helpers
117
+
118
+ Use the typed mapping helpers when converting between Midnight runtime network
119
+ ids and DID-domain network names:
120
+
121
+ - `RuntimeToDomain.NetworkMap`: maps runtime `NetworkId` values to DID-domain
122
+ `MidnightNetwork` values.
123
+ - `DomainToRuntime.NetworkMap`: maps DID-domain `MidnightNetwork` values back
124
+ to runtime `NetworkId` values.
125
+ - `RuntimeToDomainNetworkMap` and `DomainToRuntimeNetworkMap`: readonly public
126
+ type aliases exported from the package barrel for downstream configuration
127
+ and test helpers.
128
+
129
+ The older `NetworkMapping` export is a compatibility alias for
130
+ `RuntimeToDomain.NetworkMap`. New code should prefer the direction-specific
131
+ helpers so map intent is visible at the call site.
132
+
133
+ Provider adapters for proof, indexer, and ZK configuration are loaded lazily by
134
+ `configureProviders()`. Importing the API package barrel for mapping helpers,
135
+ types, or examples does not load those runtime adapters.
136
+
137
+ ## Release Artifact Metadata
138
+
139
+ The package embeds ZK artifact locations for its own published version:
140
+
141
+ ```ts
142
+ import {
143
+ MIDNIGHT_DID_API_VERSION,
144
+ createMidnightDidZkArtifactLocations,
145
+ } from "@midnight-ntwrk/midnight-did-api";
146
+
147
+ const locations = createMidnightDidZkArtifactLocations(MIDNIGHT_DID_API_VERSION);
148
+ ```
149
+
150
+ Use `locations.ghcr.reference` to pull the matching GHCR OCI artifact in Node or
151
+ CI tooling. RC and final release versions also include
152
+ `locations.githubRelease.archiveUrl`; snapshot versions publish workflow
153
+ artifacts and GHCR artifacts only, so `locations.githubRelease` is `null`.
154
+
155
+ When the ZK bundle is unpacked outside the installed package, set
156
+ `MIDNIGHT_DID_ZK_CONFIG_PATH` to the directory containing `manifest.json`,
157
+ `keys/`, and `zkir/` before importing `@midnight-ntwrk/midnight-did-api`.
158
+ Without this override, the API uses the managed artifacts bundled with the
159
+ installed contract package when available.
160
+
161
+ `setLogger()` is optional for embedders. Until it is called, API helpers use a
162
+ no-op logger so wallet/provider setup can run in minimal scripts without
163
+ preconfiguring logging.
164
+
165
+ ## Main Source Files
166
+
167
+ - `src/index.ts`
168
+ - `src/lib.ts` public compatibility facade
169
+ - `src/config-profiles.ts` network profile catalog and network-id application
170
+ - `src/deploy.ts` contract deployment, join, and private-state initialization
171
+ - `src/providers.ts` provider composition for DID runtime dependencies
172
+ - `src/private-state-storage.ts` private-state storage account/password wiring
173
+ - `src/transaction-intents.ts` manual unshielded intent signing workaround
174
+ - `src/wallet-context.ts` SDK wallet construction and restore context assembly
175
+ - `src/wallet-dust.ts` dust-registration workflow helper
176
+ - `src/wallet-provider.ts` wallet facade to Midnight wallet/provider adapter
177
+ - `src/wallet-state.ts` wallet snapshot, sync, balance, and funding wait helpers
178
+ - `src/wallet.ts` wallet construction and restore facade
179
+ - `src/wallet-keys.ts` seed parsing, HD key derivation, and unshielded address helpers
180
+ - `src/wallet-sdk-config.ts` shared wallet SDK configuration builders
181
+ - `src/lightweight.ts` stateless crypto helpers only; wallet wait behavior lives
182
+ in `src/wallet-state.ts`
183
+ - `src/did-subject.ts` DID subject and bound fragment normalization
184
+ - `src/ledger-mappers.ts` DID document domain-to-ledger DTO mapping helpers
185
+ - `src/update.ts` DID document update, deactivate, and resolve orchestration
186
+ - `src/types.ts`
187
+ - `src/test/`
188
+
189
+ Type-safety policy:
190
+
191
+ - production API source must not use `as any` casts
192
+ - `as unknown as` casts must be explicitly allowlisted in
193
+ `pnpm run check:did-surface-discipline`
194
+ - keep SDK type mismatches localized behind narrow adapter helpers and update
195
+ the surface-discipline guard when an intentional compatibility escape hatch is
196
+ unavoidable
197
+
198
+ Legacy deep source files `src/contract-lifecycle.ts` and `src/did-operations.ts`
199
+ remain as short-lived deprecation shims for external deep source-path imports.
200
+ Internal code should use the split modules above, and package consumers should
201
+ import from `@midnight-ntwrk/midnight-did-api`.
202
+
203
+ ## Deploy And Update Example
204
+
205
+ See `examples/README.md`, `examples/deploy-did.ts`, and
206
+ `examples/update-did.ts` for package-local deploy/update flows that use only API
207
+ package exports. Resolver services, DID manager UI, and reusable secret storage
208
+ stay in `midnight-did-resolver`.
209
+
210
+ ## Integration Teardown
211
+
212
+ `packages/api/src/test/commons.ts` now uses:
213
+
214
+ - unique compose project names per run
215
+ - `env.down({ removeVolumes: true })`
216
+ - fallback `docker compose down --volumes --remove-orphans`
217
+
218
+ This reduces container/volume leaks when tests fail mid-run.
@@ -0,0 +1,3 @@
1
+ import { type Logger } from "pino";
2
+ export declare const getLogger: () => Logger;
3
+ export declare function setLogger(_logger: Logger): void;
@@ -0,0 +1,8 @@
1
+ import pino from "pino";
2
+ const defaultLogger = pino({ level: "silent" });
3
+ let logger = defaultLogger;
4
+ export const getLogger = () => logger;
5
+ export function setLogger(_logger) {
6
+ logger = _logger;
7
+ }
8
+ //# sourceMappingURL=api-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-logger.js","sourceRoot":"","sources":["../src/api-logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAqB,MAAM,MAAM,CAAC;AAEzC,MAAM,aAAa,GAAW,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAExD,IAAI,MAAM,GAAW,aAAa,CAAC;AAEnC,MAAM,CAAC,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,MAAM,CAAC;AAE9C,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,MAAM,GAAG,OAAO,CAAC;AACnB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { DomainToRuntime } from "./domain-to-runtime.js";
2
+ export { randomBytes } from "./lightweight.js";
3
+ export type { DomainToRuntimeNetworkMap, RuntimeToDomainNetworkMap, } from "./network-mapping.js";
4
+ export * from "./release-artifacts.js";
5
+ export { RuntimeToDomain } from "./runtime-to-domain.js";
6
+ export { parseSeed } from "./seed.js";
@@ -0,0 +1,6 @@
1
+ export { DomainToRuntime } from "./domain-to-runtime.js";
2
+ export { randomBytes } from "./lightweight.js";
3
+ export * from "./release-artifacts.js";
4
+ export { RuntimeToDomain } from "./runtime-to-domain.js";
5
+ export { parseSeed } from "./seed.js";
6
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAK/C,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type NetworkId } from "@midnight-ntwrk/midnight-js-network-id";
2
+ export interface MidnightEndpointConfig {
3
+ readonly indexer: string;
4
+ readonly indexerWS: string;
5
+ readonly node: string;
6
+ readonly proofServer: string;
7
+ }
8
+ export type MidnightEndpointOverrides = Partial<MidnightEndpointConfig>;
9
+ export interface MidnightNetworkProfile {
10
+ readonly name: string;
11
+ readonly networkId: NetworkId;
12
+ readonly endpoints: MidnightEndpointConfig;
13
+ }
14
+ export declare const MIDNIGHT_NETWORK_PROFILES: {
15
+ readonly "testnet-local": {
16
+ readonly name: "testnet-local";
17
+ readonly networkId: "testnet";
18
+ readonly endpoints: {
19
+ readonly indexer: "http://127.0.0.1:8088/api/v3/graphql";
20
+ readonly indexerWS: "ws://127.0.0.1:8088/api/v3/graphql/ws";
21
+ readonly node: "http://127.0.0.1:9944";
22
+ readonly proofServer: "http://127.0.0.1:6300";
23
+ };
24
+ };
25
+ readonly standalone: {
26
+ readonly name: "standalone";
27
+ readonly networkId: "undeployed";
28
+ readonly endpoints: {
29
+ readonly indexer: "http://127.0.0.1:8088/api/v3/graphql";
30
+ readonly indexerWS: "ws://127.0.0.1:8088/api/v3/graphql/ws";
31
+ readonly node: "http://127.0.0.1:9944";
32
+ readonly proofServer: "http://127.0.0.1:6300";
33
+ };
34
+ };
35
+ readonly "testnet-remote": {
36
+ readonly name: "testnet-remote";
37
+ readonly networkId: "testnet";
38
+ readonly endpoints: {
39
+ readonly indexer: "https://indexer.testnet-02.midnight.network/api/v3/graphql";
40
+ readonly indexerWS: "wss://indexer.testnet-02.midnight.network/api/v3/graphql/ws";
41
+ readonly node: "https://rpc.testnet-02.midnight.network";
42
+ readonly proofServer: "http://127.0.0.1:6300";
43
+ };
44
+ };
45
+ readonly preprod: {
46
+ readonly name: "preprod";
47
+ readonly networkId: "preprod";
48
+ readonly endpoints: {
49
+ readonly indexer: "https://indexer.preprod.midnight.network/api/v4/graphql";
50
+ readonly indexerWS: "wss://indexer.preprod.midnight.network/api/v4/graphql/ws";
51
+ readonly node: "https://rpc.preprod.midnight.network";
52
+ readonly proofServer: "http://127.0.0.1:6300";
53
+ };
54
+ };
55
+ readonly mainnet: {
56
+ readonly name: "mainnet";
57
+ readonly networkId: "mainnet";
58
+ readonly endpoints: {
59
+ readonly indexer: "https://indexer.mainnet.midnight.network/api/v4/graphql";
60
+ readonly indexerWS: "wss://indexer.mainnet.midnight.network/api/v4/graphql/ws";
61
+ readonly node: "https://rpc.mainnet.midnight.network";
62
+ readonly proofServer: "http://127.0.0.1:6300";
63
+ };
64
+ };
65
+ };
66
+ export type MidnightNetworkProfileName = keyof typeof MIDNIGHT_NETWORK_PROFILES;
67
+ export interface ResolvedMidnightNetworkConfig extends MidnightEndpointConfig {
68
+ readonly logDir: string;
69
+ readonly midnightDbName: string;
70
+ }
71
+ export declare const MIDNIGHT_NETWORK_PROFILE_NAMES: MidnightNetworkProfileName[];
72
+ export declare const isMidnightNetworkProfileName: (profileName: string) => profileName is MidnightNetworkProfileName;
73
+ export declare const getMidnightNetworkProfile: (profileName: string) => MidnightNetworkProfile;
74
+ export declare const applyMidnightNetworkProfile: (profileName: MidnightNetworkProfileName) => void;
75
+ export declare const resolveMidnightNetworkConfig: (currentDir: string, profileName: MidnightNetworkProfileName, endpointOverrides?: MidnightEndpointOverrides, now?: Date) => ResolvedMidnightNetworkConfig;
@@ -0,0 +1,75 @@
1
+ import path from "node:path";
2
+ import { setNetworkId, } from "@midnight-ntwrk/midnight-js-network-id";
3
+ export const MIDNIGHT_NETWORK_PROFILES = {
4
+ "testnet-local": {
5
+ name: "testnet-local",
6
+ networkId: "testnet",
7
+ endpoints: {
8
+ indexer: "http://127.0.0.1:8088/api/v3/graphql",
9
+ indexerWS: "ws://127.0.0.1:8088/api/v3/graphql/ws",
10
+ node: "http://127.0.0.1:9944",
11
+ proofServer: "http://127.0.0.1:6300",
12
+ },
13
+ },
14
+ standalone: {
15
+ name: "standalone",
16
+ networkId: "undeployed",
17
+ endpoints: {
18
+ indexer: "http://127.0.0.1:8088/api/v3/graphql",
19
+ indexerWS: "ws://127.0.0.1:8088/api/v3/graphql/ws",
20
+ node: "http://127.0.0.1:9944",
21
+ proofServer: "http://127.0.0.1:6300",
22
+ },
23
+ },
24
+ "testnet-remote": {
25
+ name: "testnet-remote",
26
+ networkId: "testnet",
27
+ endpoints: {
28
+ indexer: "https://indexer.testnet-02.midnight.network/api/v3/graphql",
29
+ indexerWS: "wss://indexer.testnet-02.midnight.network/api/v3/graphql/ws",
30
+ node: "https://rpc.testnet-02.midnight.network",
31
+ proofServer: "http://127.0.0.1:6300",
32
+ },
33
+ },
34
+ preprod: {
35
+ name: "preprod",
36
+ networkId: "preprod",
37
+ endpoints: {
38
+ indexer: "https://indexer.preprod.midnight.network/api/v4/graphql",
39
+ indexerWS: "wss://indexer.preprod.midnight.network/api/v4/graphql/ws",
40
+ node: "https://rpc.preprod.midnight.network",
41
+ proofServer: "http://127.0.0.1:6300",
42
+ },
43
+ },
44
+ mainnet: {
45
+ name: "mainnet",
46
+ networkId: "mainnet",
47
+ endpoints: {
48
+ indexer: "https://indexer.mainnet.midnight.network/api/v4/graphql",
49
+ indexerWS: "wss://indexer.mainnet.midnight.network/api/v4/graphql/ws",
50
+ node: "https://rpc.mainnet.midnight.network",
51
+ proofServer: "http://127.0.0.1:6300",
52
+ },
53
+ },
54
+ };
55
+ export const MIDNIGHT_NETWORK_PROFILE_NAMES = Object.keys(MIDNIGHT_NETWORK_PROFILES);
56
+ export const isMidnightNetworkProfileName = (profileName) => profileName in MIDNIGHT_NETWORK_PROFILES;
57
+ export const getMidnightNetworkProfile = (profileName) => {
58
+ if (!isMidnightNetworkProfileName(profileName)) {
59
+ throw new Error(`Unknown Midnight network profile "${profileName}". Expected one of: ${MIDNIGHT_NETWORK_PROFILE_NAMES.join(", ")}.`);
60
+ }
61
+ return MIDNIGHT_NETWORK_PROFILES[profileName];
62
+ };
63
+ export const applyMidnightNetworkProfile = (profileName) => {
64
+ setNetworkId(getMidnightNetworkProfile(profileName).networkId);
65
+ };
66
+ export const resolveMidnightNetworkConfig = (currentDir, profileName, endpointOverrides = {}, now = new Date()) => {
67
+ const profile = getMidnightNetworkProfile(profileName);
68
+ return {
69
+ ...profile.endpoints,
70
+ ...endpointOverrides,
71
+ logDir: path.resolve(currentDir, "logs", profile.name, `${now.toISOString()}.log`),
72
+ midnightDbName: path.resolve(currentDir, ".midnight-db", profile.name),
73
+ };
74
+ };
75
+ //# sourceMappingURL=config-profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-profiles.js","sourceRoot":"","sources":["../src/config-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAEL,YAAY,GACb,MAAM,wCAAwC,CAAC;AAiBhD,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,eAAe,EAAE;QACf,IAAI,EAAE,eAAe;QACrB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE;YACT,OAAO,EAAE,sCAAsC;YAC/C,SAAS,EAAE,uCAAuC;YAClD,IAAI,EAAE,uBAAuB;YAC7B,WAAW,EAAE,uBAAuB;SACrC;KACF;IACD,UAAU,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,SAAS,EAAE,YAAY;QACvB,SAAS,EAAE;YACT,OAAO,EAAE,sCAAsC;YAC/C,SAAS,EAAE,uCAAuC;YAClD,IAAI,EAAE,uBAAuB;YAC7B,WAAW,EAAE,uBAAuB;SACrC;KACF;IACD,gBAAgB,EAAE;QAChB,IAAI,EAAE,gBAAgB;QACtB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE;YACT,OAAO,EAAE,4DAA4D;YACrE,SAAS,EAAE,6DAA6D;YACxE,IAAI,EAAE,yCAAyC;YAC/C,WAAW,EAAE,uBAAuB;SACrC;KACF;IACD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE;YACT,OAAO,EAAE,yDAAyD;YAClE,SAAS,EAAE,0DAA0D;YACrE,IAAI,EAAE,sCAAsC;YAC5C,WAAW,EAAE,uBAAuB;SACrC;KACF;IACD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE;YACT,OAAO,EAAE,yDAAyD;YAClE,SAAS,EAAE,0DAA0D;YACrE,IAAI,EAAE,sCAAsC;YAC5C,WAAW,EAAE,uBAAuB;SACrC;KACF;CACwD,CAAC;AAS5D,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAC,IAAI,CACvD,yBAAyB,CACM,CAAC;AAElC,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,WAAmB,EACwB,EAAE,CAC7C,WAAW,IAAI,yBAAyB,CAAC;AAE3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,WAAmB,EACK,EAAE;IAC1B,IAAI,CAAC,4BAA4B,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,qCAAqC,WAAW,uBAAuB,8BAA8B,CAAC,IAAI,CACxG,IAAI,CACL,GAAG,CACL,CAAC;IACJ,CAAC;IAED,OAAO,yBAAyB,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,WAAuC,EACjC,EAAE;IACR,YAAY,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAkB,EAClB,WAAuC,EACvC,oBAA+C,EAAE,EACjD,MAAY,IAAI,IAAI,EAAE,EACS,EAAE;IACjC,MAAM,OAAO,GAAG,yBAAyB,CAAC,WAAW,CAAC,CAAC;IAEvD,OAAO;QACL,GAAG,OAAO,CAAC,SAAS;QACpB,GAAG,iBAAiB;QACpB,MAAM,EAAE,IAAI,CAAC,OAAO,CAClB,UAAU,EACV,MAAM,EACN,OAAO,CAAC,IAAI,EACZ,GAAG,GAAG,CAAC,WAAW,EAAE,MAAM,CAC3B;QACD,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC;KACvE,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type MidnightEndpointOverrides, type MidnightNetworkProfileName } from "./config-profiles.js";
2
+ import { contractConfig, currentDir } from "./package-paths.js";
3
+ export { applyMidnightNetworkProfile, getMidnightNetworkProfile, isMidnightNetworkProfileName, MIDNIGHT_NETWORK_PROFILE_NAMES, MIDNIGHT_NETWORK_PROFILES, type MidnightEndpointConfig, type MidnightEndpointOverrides, type MidnightNetworkProfile, type MidnightNetworkProfileName, type ResolvedMidnightNetworkConfig, resolveMidnightNetworkConfig, } from "./config-profiles.js";
4
+ export { contractConfig, currentDir };
5
+ export interface Config {
6
+ readonly logDir: string;
7
+ readonly indexer: string;
8
+ readonly indexerWS: string;
9
+ readonly node: string;
10
+ readonly proofServer: string;
11
+ readonly midnightDbName?: string;
12
+ }
13
+ export declare class ProfileConfig implements Config {
14
+ readonly profileName: MidnightNetworkProfileName;
15
+ readonly logDir: string;
16
+ readonly indexer: string;
17
+ readonly indexerWS: string;
18
+ readonly node: string;
19
+ readonly proofServer: string;
20
+ readonly midnightDbName: string;
21
+ constructor(profileName: MidnightNetworkProfileName, endpointOverrides?: MidnightEndpointOverrides);
22
+ }
23
+ export declare class TestnetLocalConfig extends ProfileConfig {
24
+ constructor();
25
+ }
26
+ export declare class StandaloneConfig extends ProfileConfig {
27
+ constructor();
28
+ }
29
+ export declare class TestnetRemoteConfig extends ProfileConfig {
30
+ constructor();
31
+ }
32
+ export declare class PreprodConfig extends ProfileConfig {
33
+ constructor();
34
+ }
35
+ export declare class MainnetConfig extends ProfileConfig {
36
+ constructor(input?: MidnightEndpointOverrides);
37
+ }