@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
@@ -0,0 +1,27 @@
1
+ import * as ledger from "@midnight-ntwrk/ledger-v8";
2
+ // Manual transaction intent signing works around an upstream SDK signing bug.
3
+ // Remove this when wallet-sdk signs balanced unshielded intents directly.
4
+ export const signTransactionIntents = (tx, signFn, proofMarker) => {
5
+ if (!tx.intents || tx.intents.size === 0)
6
+ return;
7
+ for (const segment of tx.intents.keys()) {
8
+ const intent = tx.intents.get(segment);
9
+ if (!intent)
10
+ continue;
11
+ const cloned = ledger.Intent.deserialize("signature", proofMarker, "pre-binding", intent.serialize());
12
+ const sigData = cloned.signatureData(segment);
13
+ const signature = signFn(sigData);
14
+ if (cloned.fallibleUnshieldedOffer) {
15
+ const sigs = cloned.fallibleUnshieldedOffer.inputs.map((_, i) => cloned.fallibleUnshieldedOffer.signatures.at(i) ?? signature);
16
+ cloned.fallibleUnshieldedOffer =
17
+ cloned.fallibleUnshieldedOffer.addSignatures(sigs);
18
+ }
19
+ if (cloned.guaranteedUnshieldedOffer) {
20
+ const sigs = cloned.guaranteedUnshieldedOffer.inputs.map((_, i) => cloned.guaranteedUnshieldedOffer.signatures.at(i) ?? signature);
21
+ cloned.guaranteedUnshieldedOffer =
22
+ cloned.guaranteedUnshieldedOffer.addSignatures(sigs);
23
+ }
24
+ tx.intents.set(segment, cloned);
25
+ }
26
+ };
27
+ //# sourceMappingURL=transaction-intents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-intents.js","sourceRoot":"","sources":["../src/transaction-intents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAUpD,8EAA8E;AAC9E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,EAA8B,EAC9B,MAAiD,EACjD,WAAkC,EAC5B,EAAE;IACR,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO;IAEjD,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,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { ProvableCircuitId } from "@midnight-ntwrk/compact-js";
2
+ import type { JubjubPoint } from "@midnight-ntwrk/compact-runtime";
3
+ import * as ledger from "@midnight-ntwrk/ledger-v8";
4
+ import { DIDContract, type DIDPrivateState } from "@midnight-ntwrk/midnight-did-contract";
5
+ import type { DeployedContract, FoundContract } from "@midnight-ntwrk/midnight-js-contracts";
6
+ import type { MidnightProviders } from "@midnight-ntwrk/midnight-js-types";
7
+ import type { DustWallet } from "@midnight-ntwrk/wallet-sdk-dust-wallet";
8
+ import type { FacadeState, WalletFacade } from "@midnight-ntwrk/wallet-sdk-facade";
9
+ import type { ShieldedWallet } from "@midnight-ntwrk/wallet-sdk-shielded";
10
+ import type { InMemoryTransactionHistoryStorage, UnshieldedKeystore, UnshieldedWallet } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
11
+ import { type RuntimeToDomainNetworkMap } from "./network-mapping.js";
12
+ export type MidnightDIDPrivateState = DIDPrivateState;
13
+ type MidnightDIDProvableContract = DIDContract.Contract<MidnightDIDPrivateState> & {
14
+ provableCircuits: DIDContract.ImpureCircuits<MidnightDIDPrivateState>;
15
+ };
16
+ export type MidnightDIDCircuits = ProvableCircuitId<MidnightDIDProvableContract>;
17
+ export declare const MidnightDIDPrivateStateId = "midnightDIDPrivateState";
18
+ export declare const MidnightDIDPendingControllerPrivateStateId = "midnightDIDPendingControllerPrivateState";
19
+ export type MidnightDIDPrivateStateIds = typeof MidnightDIDPrivateStateId | typeof MidnightDIDPendingControllerPrivateStateId;
20
+ /**
21
+ * DID providers must expose a contract-address-aware private state provider.
22
+ * Callers should bind it to the DID contract address before restoring,
23
+ * requiring, saving, or recovering private state.
24
+ */
25
+ export type MidnightDIDProviders = MidnightProviders<MidnightDIDCircuits, MidnightDIDPrivateStateIds, MidnightDIDPrivateState>;
26
+ export type MidnightDIDContract = MidnightDIDProvableContract;
27
+ export type DeployedMidnightDIDContract = DeployedContract<MidnightDIDContract> | FoundContract<MidnightDIDContract>;
28
+ export interface SchnorrJubjubVerificationMethod {
29
+ readonly id: string;
30
+ readonly publicKey: JubjubPoint;
31
+ }
32
+ export type SchnorrJubjubDigest = [bigint, bigint, bigint, bigint];
33
+ export type SchnorrJubjubSignature = DIDContract.Schnorr_SchnorrSignature;
34
+ export interface MidnightDIDWalletContext {
35
+ wallet: WalletFacade;
36
+ shieldedWallet: ShieldedWallet;
37
+ unshieldedWallet: UnshieldedWallet;
38
+ dustWallet: DustWallet;
39
+ unshieldedHistoryStorage: InMemoryTransactionHistoryStorage;
40
+ shieldedSecretKeys: ledger.ZswapSecretKeys;
41
+ dustSecretKey: ledger.DustSecretKey;
42
+ unshieldedKeystore: UnshieldedKeystore;
43
+ }
44
+ export interface MidnightWalletStateSnapshot {
45
+ shieldedState: string;
46
+ unshieldedState: string;
47
+ dustState: string;
48
+ unshieldedHistory?: string;
49
+ }
50
+ export interface MidnightWalletBalances {
51
+ night: bigint | null;
52
+ dust: bigint | null;
53
+ }
54
+ export type MidnightWalletFacadeState = FacadeState;
55
+ /**
56
+ * @deprecated Use `RuntimeToDomain.NetworkMap` for runtime-to-domain mappings.
57
+ * This alias remains for compatibility with older API consumers.
58
+ */
59
+ export declare const NetworkMapping: RuntimeToDomainNetworkMap;
60
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ import { RUNTIME_TO_DOMAIN_NETWORK_MAP, } from "./network-mapping.js";
2
+ export const MidnightDIDPrivateStateId = "midnightDIDPrivateState";
3
+ export const MidnightDIDPendingControllerPrivateStateId = "midnightDIDPendingControllerPrivateState";
4
+ /**
5
+ * @deprecated Use `RuntimeToDomain.NetworkMap` for runtime-to-domain mappings.
6
+ * This alias remains for compatibility with older API consumers.
7
+ */
8
+ export const NetworkMapping = RUNTIME_TO_DOMAIN_NETWORK_MAP;
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAwBA,OAAO,EACL,6BAA6B,GAE9B,MAAM,sBAAsB,CAAC;AAY9B,MAAM,CAAC,MAAM,yBAAyB,GAAG,yBAAyB,CAAC;AACnE,MAAM,CAAC,MAAM,0CAA0C,GACrD,0CAA0C,CAAC;AAuD7C;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,6BAA6B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import "./polyfills.js";
2
+ export { rotateControllerKey } from "./controller-operations.js";
3
+ export { getMidnightNetwork } from "./did-subject.js";
4
+ export { addAlsoKnownAs, deactivate, removeAlsoKnownAs, } from "./document-operations.js";
5
+ export { resolve, resolveDIDResolutionResult } from "./resolution.js";
6
+ export { addService, removeService, updateService, } from "./service-operations.js";
7
+ export { addVerificationMethod, addVerificationMethodRelation, removeVerificationMethod, removeVerificationMethodRelation, updateVerificationMethod, } from "./verification-method-operations.js";
package/dist/update.js ADDED
@@ -0,0 +1,8 @@
1
+ import "./polyfills.js";
2
+ export { rotateControllerKey } from "./controller-operations.js";
3
+ export { getMidnightNetwork } from "./did-subject.js";
4
+ export { addAlsoKnownAs, deactivate, removeAlsoKnownAs, } from "./document-operations.js";
5
+ export { resolve, resolveDIDResolutionResult } from "./resolution.js";
6
+ export { addService, removeService, updateService, } from "./service-operations.js";
7
+ export { addVerificationMethod, addVerificationMethodRelation, removeVerificationMethod, removeVerificationMethodRelation, updateVerificationMethod, } from "./verification-method-operations.js";
8
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,GACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,wBAAwB,EACxB,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,qCAAqC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { VerificationMethod, VerificationMethodRelationType } from "@midnight-ntwrk/midnight-did-domain";
2
+ import { type FinalizedTxData } from "@midnight-ntwrk/midnight-js-types";
3
+ import { type DeployedMidnightDIDContract, type MidnightDIDProviders, type SchnorrJubjubDigest, type SchnorrJubjubSignature, type SchnorrJubjubVerificationMethod } from "./types.js";
4
+ export declare const addVerificationMethod: (didContract: DeployedMidnightDIDContract, verificationMethod: VerificationMethod) => Promise<FinalizedTxData>;
5
+ export declare const updateVerificationMethod: (didContract: DeployedMidnightDIDContract, verificationMethod: VerificationMethod) => Promise<FinalizedTxData>;
6
+ export declare const removeVerificationMethod: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, methodId: string) => Promise<FinalizedTxData>;
7
+ export declare const addSchnorrJubjubVerificationMethod: (didContract: DeployedMidnightDIDContract, verificationMethod: SchnorrJubjubVerificationMethod) => Promise<FinalizedTxData>;
8
+ export declare const updateSchnorrJubjubVerificationMethod: (didContract: DeployedMidnightDIDContract, verificationMethod: SchnorrJubjubVerificationMethod) => Promise<FinalizedTxData>;
9
+ export declare const removeSchnorrJubjubVerificationMethod: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, methodId: string) => Promise<FinalizedTxData>;
10
+ /**
11
+ * Submits the ledger-bound SchnorrJubjub verification circuit.
12
+ *
13
+ * This is a transaction-backed proof rather than an off-chain verifier so the
14
+ * proof is tied to the current DID ledger state while the digest and signature
15
+ * remain private circuit inputs.
16
+ */
17
+ export declare const verifySchnorrJubjubDigestSignature: (didContract: DeployedMidnightDIDContract, methodId: string, digest: SchnorrJubjubDigest, signature: SchnorrJubjubSignature) => Promise<FinalizedTxData>;
18
+ export declare const addVerificationMethodRelation: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, relation: VerificationMethodRelationType, methodId: string) => Promise<FinalizedTxData>;
19
+ export declare const removeVerificationMethodRelation: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, relation: VerificationMethodRelationType, methodId: string) => Promise<FinalizedTxData>;
@@ -0,0 +1,60 @@
1
+ import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
2
+ import { normalizeBoundFragmentId } from "./did-subject.js";
3
+ import { LedgerVerificationMethodRelationMap, schnorrJubjubVerificationMethodToLedger, verificationMethodToLedger, } from "./ledger-mappers.js";
4
+ import { requireDeployedMidnightDIDLedgerState } from "./ledger-state.js";
5
+ 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);
8
+ return result.public;
9
+ };
10
+ export const updateVerificationMethod = async (didContract, verificationMethod) => {
11
+ const result = await didContract.callTx.setVerificationMethod(verificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Update);
12
+ return result.public;
13
+ };
14
+ export const removeVerificationMethod = async (didContract, providers, methodId) => {
15
+ const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
16
+ await purgeVerificationMethodFromAllRelations(didContract, providers, normalizedMethodId);
17
+ const result = await didContract.callTx.removeVerificationMethod(normalizedMethodId);
18
+ return result.public;
19
+ };
20
+ export const addSchnorrJubjubVerificationMethod = async (didContract, verificationMethod) => {
21
+ const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Insert);
22
+ return result.public;
23
+ };
24
+ export const updateSchnorrJubjubVerificationMethod = async (didContract, verificationMethod) => {
25
+ const result = await didContract.callTx.setSchnorrJubjubVerificationMethod(schnorrJubjubVerificationMethodToLedger(didContract, verificationMethod), DIDContract.MapMutation.Update);
26
+ return result.public;
27
+ };
28
+ export const removeSchnorrJubjubVerificationMethod = async (didContract, providers, methodId) => {
29
+ const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
30
+ await purgeVerificationMethodFromAllRelations(didContract, providers, normalizedMethodId);
31
+ const result = await didContract.callTx.removeSchnorrJubjubVerificationMethod(normalizedMethodId);
32
+ return result.public;
33
+ };
34
+ /**
35
+ * Submits the ledger-bound SchnorrJubjub verification circuit.
36
+ *
37
+ * This is a transaction-backed proof rather than an off-chain verifier so the
38
+ * proof is tied to the current DID ledger state while the digest and signature
39
+ * remain private circuit inputs.
40
+ */
41
+ export const verifySchnorrJubjubDigestSignature = async (didContract, methodId, digest, signature) => {
42
+ const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
43
+ const result = await didContract.callTx.verifySchnorrJubjubDigestSignature(normalizedMethodId, digest, signature);
44
+ return result.public;
45
+ };
46
+ export const addVerificationMethodRelation = async (didContract, providers, relation, methodId) => {
47
+ const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
48
+ const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
49
+ assertVerificationMethodRelationAbsent(didState, relation, normalizedMethodId);
50
+ const result = await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Insert);
51
+ return result.public;
52
+ };
53
+ export const removeVerificationMethodRelation = async (didContract, providers, relation, methodId) => {
54
+ const normalizedMethodId = normalizeBoundFragmentId(didContract, methodId, "methodId");
55
+ const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
56
+ assertVerificationMethodRelationPresent(didState, relation, normalizedMethodId);
57
+ const result = await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Remove);
58
+ return result.public;
59
+ };
60
+ //# sourceMappingURL=verification-method-operations.js.map
@@ -0,0 +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,kBAAsC,EACZ,EAAE;IAC5B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,qBAAqB,CAC3D,0BAA0B,CAAC,WAAW,EAAE,kBAAkB,CAAC,EAC3D,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,WAAwC,EACxC,kBAAsC,EACZ,EAAE;IAC5B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,qBAAqB,CAC3D,0BAA0B,CAAC,WAAW,EAAE,kBAAkB,CAAC,EAC3D,WAAW,CAAC,WAAW,CAAC,MAAM,CAC/B,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,WAAwC,EACxC,SAA+B,EAC/B,QAAgB,EACU,EAAE;IAC5B,MAAM,kBAAkB,GAAG,wBAAwB,CACjD,WAA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nB,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"}
@@ -0,0 +1,13 @@
1
+ import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
2
+ import { VerificationMethodRelationType } from "@midnight-ntwrk/midnight-did-domain";
3
+ import { type DeployedMidnightDIDContract, type MidnightDIDProviders } from "./types.js";
4
+ export declare const VerificationMethodRelations: readonly [VerificationMethodRelationType.Authentication, VerificationMethodRelationType.AssertionMethod, VerificationMethodRelationType.KeyAgreement, VerificationMethodRelationType.CapabilityInvocation, VerificationMethodRelationType.CapabilityDelegation];
5
+ export type VerificationMethodRelationMembership = {
6
+ readonly relation: VerificationMethodRelationType;
7
+ readonly member: boolean;
8
+ };
9
+ export declare const verificationMethodRelationMemberships: (didState: DIDContract.Ledger, normalizedMethodId: string) => readonly VerificationMethodRelationMembership[];
10
+ export declare const assertVerificationMethodRelationAbsent: (didState: DIDContract.Ledger, relation: VerificationMethodRelationType, normalizedMethodId: string) => void;
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>;
13
+ export declare const purgeVerificationMethodFromAllRelations: (didContract: DeployedMidnightDIDContract, providers: MidnightDIDProviders, normalizedMethodId: string) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { DIDContract } from "@midnight-ntwrk/midnight-did-contract";
2
+ import { VerificationMethodRelationType } from "@midnight-ntwrk/midnight-did-domain";
3
+ import { LedgerVerificationMethodRelationMap, relationSetFromState, } from "./ledger-mappers.js";
4
+ import { requireDeployedMidnightDIDLedgerState } from "./ledger-state.js";
5
+ export const VerificationMethodRelations = Object.freeze([
6
+ VerificationMethodRelationType.Authentication,
7
+ VerificationMethodRelationType.AssertionMethod,
8
+ VerificationMethodRelationType.KeyAgreement,
9
+ VerificationMethodRelationType.CapabilityInvocation,
10
+ VerificationMethodRelationType.CapabilityDelegation,
11
+ ]);
12
+ export const verificationMethodRelationMemberships = (didState, normalizedMethodId) => VerificationMethodRelations.map((relation) => ({
13
+ relation,
14
+ member: relationSetFromState(didState, relation).member(normalizedMethodId),
15
+ }));
16
+ export const assertVerificationMethodRelationAbsent = (didState, relation, normalizedMethodId) => {
17
+ const relationSet = relationSetFromState(didState, relation);
18
+ if (relationSet.member(normalizedMethodId)) {
19
+ throw new Error(`relation ${relation} already contains verification method ${normalizedMethodId}`);
20
+ }
21
+ };
22
+ export const assertVerificationMethodRelationPresent = (didState, relation, normalizedMethodId) => {
23
+ const relationSet = relationSetFromState(didState, relation);
24
+ if (!relationSet.member(normalizedMethodId)) {
25
+ throw new Error(`relation ${relation} does not contain verification method ${normalizedMethodId}`);
26
+ }
27
+ };
28
+ export const removePresentVerificationMethodRelations = async (didContract, memberships, normalizedMethodId) => {
29
+ for (const { relation, member } of memberships) {
30
+ if (!member)
31
+ continue;
32
+ await didContract.callTx.setVerificationMethodRelation(LedgerVerificationMethodRelationMap[relation], normalizedMethodId, DIDContract.SetMutation.Remove);
33
+ }
34
+ };
35
+ export const purgeVerificationMethodFromAllRelations = async (didContract, providers, normalizedMethodId) => {
36
+ const didState = await requireDeployedMidnightDIDLedgerState(providers, didContract);
37
+ const memberships = verificationMethodRelationMemberships(didState, normalizedMethodId);
38
+ await removePresentVerificationMethodRelations(didContract, memberships, normalizedMethodId);
39
+ };
40
+ //# sourceMappingURL=verification-method-relations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verification-method-relations.js","sourceRoot":"","sources":["../src/verification-method-relations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW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AM,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACb,YAAY,QAAQ,yCAAyC,kBAAkB,EAAE,CAClF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wCAAwC,GAAG,KAAK,EAC3D,WAAwC,EACxC,WAA4D,EAC5D,kBAA0B,EACX,EAAE;IACjB,KAAK,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;QAC/C,IAAI,CAAC,MAAM;YAAE,SAAS;QACtB,MAAM,WAAW,CAAC,MAAM,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"}
@@ -0,0 +1,3 @@
1
+ import { type Config } from "./config.js";
2
+ import { type MidnightDIDWalletContext, type MidnightWalletStateSnapshot } from "./types.js";
3
+ export declare const createWalletContext: (config: Config, seed: string, snapshot?: MidnightWalletStateSnapshot) => Promise<MidnightDIDWalletContext>;
@@ -0,0 +1,55 @@
1
+ import * as ledger from "@midnight-ntwrk/ledger-v8";
2
+ import { DustWallet } from "@midnight-ntwrk/wallet-sdk-dust-wallet";
3
+ import { WalletFacade } from "@midnight-ntwrk/wallet-sdk-facade";
4
+ import { Roles } from "@midnight-ntwrk/wallet-sdk-hd";
5
+ import { ShieldedWallet } from "@midnight-ntwrk/wallet-sdk-shielded";
6
+ import { InMemoryTransactionHistoryStorage, PublicKey, UnshieldedWallet, } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
7
+ import { getLogger } from "./api-logger.js";
8
+ import { createUnshieldedKeystoreFromKeys, deriveMidnightWalletKeys, } from "./wallet-keys.js";
9
+ import { buildDustConfig, buildShieldedConfig, buildUnshieldedConfig, } from "./wallet-sdk-config.js";
10
+ export const createWalletContext = async (config, seed, snapshot) => {
11
+ getLogger().info(snapshot
12
+ ? "Restoring wallet from serialized state"
13
+ : "Building wallet from seed");
14
+ const keys = deriveMidnightWalletKeys(seed);
15
+ const shieldedSecretKeys = ledger.ZswapSecretKeys.fromSeed(keys[Roles.Zswap]);
16
+ const dustSecretKey = ledger.DustSecretKey.fromSeed(keys[Roles.Dust]);
17
+ const unshieldedKeystore = createUnshieldedKeystoreFromKeys(keys);
18
+ const unshieldedHistoryStorage = snapshot?.unshieldedHistory !== undefined
19
+ ? InMemoryTransactionHistoryStorage.fromSerialized(snapshot.unshieldedHistory)
20
+ : new InMemoryTransactionHistoryStorage();
21
+ const shieldedConfig = buildShieldedConfig(config);
22
+ const unshieldedConfig = buildUnshieldedConfig(config, unshieldedHistoryStorage);
23
+ const dustConfig = buildDustConfig(config);
24
+ const shieldedWallet = snapshot?.shieldedState !== undefined
25
+ ? ShieldedWallet(shieldedConfig).restore(snapshot.shieldedState)
26
+ : ShieldedWallet(shieldedConfig).startWithSecretKeys(shieldedSecretKeys);
27
+ const unshieldedWallet = snapshot?.unshieldedState !== undefined
28
+ ? UnshieldedWallet(unshieldedConfig).restore(snapshot.unshieldedState)
29
+ : UnshieldedWallet(unshieldedConfig).startWithPublicKey(PublicKey.fromKeyStore(unshieldedKeystore));
30
+ const dustWallet = snapshot?.dustState !== undefined
31
+ ? DustWallet(dustConfig).restore(snapshot.dustState)
32
+ : DustWallet(dustConfig).startWithSecretKey(dustSecretKey, ledger.LedgerParameters.initialParameters().dust);
33
+ const wallet = await WalletFacade.init({
34
+ configuration: {
35
+ ...shieldedConfig,
36
+ ...unshieldedConfig,
37
+ ...dustConfig,
38
+ },
39
+ shielded: async () => shieldedWallet,
40
+ unshielded: async () => unshieldedWallet,
41
+ dust: async () => dustWallet,
42
+ });
43
+ await wallet.start(shieldedSecretKeys, dustSecretKey);
44
+ return {
45
+ wallet,
46
+ shieldedWallet,
47
+ unshieldedWallet,
48
+ dustWallet,
49
+ unshieldedHistoryStorage,
50
+ shieldedSecretKeys,
51
+ dustSecretKey,
52
+ unshieldedKeystore,
53
+ };
54
+ };
55
+ //# sourceMappingURL=wallet-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-context.js","sourceRoot":"","sources":["../src/wallet-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EACL,iCAAiC,EACjC,SAAS,EACT,gBAAgB,GACjB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C,OAAO,EACL,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,MAAc,EACd,IAAY,EACZ,QAAsC,EACH,EAAE;IACrC,SAAS,EAAE,CAAC,IAAI,CACd,QAAQ;QACN,CAAC,CAAC,wCAAwC;QAC1C,CAAC,CAAC,2BAA2B,CAChC,CAAC;IAEF,MAAM,IAAI,GAAG,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CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;QACpD,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,kBAAkB,CACvC,aAAa,EACb,MAAM,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,CAAC,IAAI,CACjD,CAAC;IAER,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC;QACrC,aAAa,EAAE;YACb,GAAG,cAAc;YACjB,GAAG,gBAAgB;YACnB,GAAG,UAAU;SACd;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,cAAc;QACpC,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,gBAAgB;QACxC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,UAAU;KAC7B,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;IAEtD,OAAO;QACL,MAAM;QACN,cAAc;QACd,gBAAgB;QAChB,UAAU;QACV,wBAAwB;QACxB,kBAAkB;QAClB,aAAa;QACb,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type WalletFacade } from "@midnight-ntwrk/wallet-sdk-facade";
2
+ import { type UnshieldedKeystore } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
3
+ type NightCoinWithDustMetadata = {
4
+ meta?: {
5
+ registeredForDustGeneration?: boolean;
6
+ };
7
+ };
8
+ export declare const filterUnregisteredNightUtxos: <T extends NightCoinWithDustMetadata>(nightUtxos: readonly T[]) => T[];
9
+ export declare const registerForDustGeneration: (wallet: WalletFacade, unshieldedKeystore: UnshieldedKeystore) => Promise<void>;
10
+ export {};
@@ -0,0 +1,28 @@
1
+ import * as Rx from "rxjs";
2
+ import { getLogger } from "./api-logger.js";
3
+ export const filterUnregisteredNightUtxos = (nightUtxos) => nightUtxos.filter((coin) => coin.meta?.registeredForDustGeneration !== true);
4
+ const waitForDustBalance = async (wallet) => {
5
+ await Rx.firstValueFrom(wallet.state().pipe(Rx.throttleTime(5_000), Rx.filter((s) => s.dust.balance(new Date()) > 0n)));
6
+ };
7
+ export const registerForDustGeneration = async (wallet, unshieldedKeystore) => {
8
+ const state = await Rx.firstValueFrom(wallet.state().pipe(Rx.filter((s) => s.isSynced)));
9
+ if (state.dust.availableCoins.length > 0) {
10
+ const dustBal = state.dust.balance(new Date());
11
+ getLogger().info(`Dust already available: ${dustBal}`);
12
+ return;
13
+ }
14
+ const nightUtxos = filterUnregisteredNightUtxos(state.unshielded.availableCoins);
15
+ if (nightUtxos.length === 0) {
16
+ getLogger().info("Waiting for existing dust generation...");
17
+ await waitForDustBalance(wallet);
18
+ return;
19
+ }
20
+ getLogger().info(`Registering ${nightUtxos.length} NIGHT UTXOs for dust generation`);
21
+ const recipe = await wallet.registerNightUtxosForDustGeneration(nightUtxos, unshieldedKeystore.getPublicKey(), (payload) => unshieldedKeystore.signData(payload));
22
+ const finalized = await wallet.finalizeRecipe(recipe);
23
+ await wallet.submitTransaction(finalized);
24
+ getLogger().info("Waiting for dust generation...");
25
+ await waitForDustBalance(wallet);
26
+ getLogger().info("Dust generation complete");
27
+ };
28
+ //# sourceMappingURL=wallet-dust.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-dust.js","sourceRoot":"","sources":["../src/wallet-dust.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAG1C,UAAwB,EACnB,EAAE,CACP,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,2BAA2B,KAAK,IAAI,CAAC,CAAC;AAE/E,MAAM,kBAAkB,GAAG,KAAK,EAAE,MAAoB,EAAiB,EAAE;IACvE,MAAM,EAAE,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AAY,EAAE,EACjC,CAAC,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAClD,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACtD,MAAM,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE1C,SAAS,EAAE,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;IACnD,MAAM,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAEjC,SAAS,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;AAC/C,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type UnshieldedKeystore } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
2
+ export declare const deriveMidnightWalletKeys: (seed: string) => Record<0 | 2 | 3, Uint8Array<ArrayBufferLike>>;
3
+ export type MidnightWalletKeys = ReturnType<typeof deriveMidnightWalletKeys>;
4
+ export declare const createUnshieldedKeystoreFromKeys: (keys: MidnightWalletKeys) => UnshieldedKeystore;
5
+ export declare const deriveUnshieldedAddressFromSeed: (seed: string) => string;
@@ -0,0 +1,27 @@
1
+ import { getNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
2
+ import { HDWallet, Roles } from "@midnight-ntwrk/wallet-sdk-hd";
3
+ import { createKeystore, } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
4
+ import { Buffer } from "buffer";
5
+ import { parseSeed } from "./seed.js";
6
+ export const deriveMidnightWalletKeys = (seed) => {
7
+ const hdWallet = HDWallet.fromSeed(Buffer.from(parseSeed(seed), "hex"));
8
+ if (hdWallet.type !== "seedOk") {
9
+ throw new Error("Failed to initialize HDWallet from seed");
10
+ }
11
+ const derivationResult = hdWallet.hdWallet
12
+ .selectAccount(0)
13
+ .selectRoles([Roles.Zswap, Roles.NightExternal, Roles.Dust])
14
+ .deriveKeysAt(0);
15
+ if (derivationResult.type !== "keysDerived") {
16
+ throw new Error("Failed to derive keys");
17
+ }
18
+ hdWallet.hdWallet.clear();
19
+ return derivationResult.keys;
20
+ };
21
+ export const createUnshieldedKeystoreFromKeys = (keys) => {
22
+ return createKeystore(keys[Roles.NightExternal], getNetworkId());
23
+ };
24
+ export const deriveUnshieldedAddressFromSeed = (seed) => createUnshieldedKeystoreFromKeys(deriveMidnightWalletKeys(seed))
25
+ .getBech32Address()
26
+ .toString();
27
+ //# sourceMappingURL=wallet-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-keys.js","sourceRoot":"","sources":["../src/wallet-keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EACL,cAAc,GAEf,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACxE,IAAI,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,QAAQ;SACvC,aAAa,CAAC,CAAC,CAAC;SAChB,WAAW,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;SAC3D,YAAY,CAAC,CAAC,CAAC,CAAC;IACnB,IAAI,gBAAgB,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IACD,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,OAAO,gBAAgB,CAAC,IAAI,CAAC;AAC/B,CAAC,CAAC;AAIF,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAC9C,IAAwB,EACJ,EAAE;IACtB,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,IAAY,EAAU,EAAE,CACtE,gCAAgC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;KAC7D,gBAAgB,EAAE;KAClB,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type MidnightProvider, type WalletProvider } from "@midnight-ntwrk/midnight-js-types";
2
+ import { type MidnightDIDWalletContext } from "./types.js";
3
+ export declare const createWalletAndMidnightProvider: (ctx: MidnightDIDWalletContext) => Promise<WalletProvider & MidnightProvider>;
@@ -0,0 +1,29 @@
1
+ import * as Rx from "rxjs";
2
+ import { signTransactionIntents } from "./transaction-intents.js";
3
+ export const createWalletAndMidnightProvider = async (ctx) => {
4
+ const state = await Rx.firstValueFrom(ctx.wallet.state().pipe(Rx.filter((s) => s.isSynced)));
5
+ return {
6
+ getCoinPublicKey() {
7
+ return state.shielded.coinPublicKey.toHexString();
8
+ },
9
+ getEncryptionPublicKey() {
10
+ return state.shielded.encryptionPublicKey.toHexString();
11
+ },
12
+ async balanceTx(tx, ttl) {
13
+ const recipe = await ctx.wallet.balanceUnboundTransaction(tx, {
14
+ shieldedSecretKeys: ctx.shieldedSecretKeys,
15
+ dustSecretKey: ctx.dustSecretKey,
16
+ }, { ttl: ttl ?? new Date(Date.now() + 30 * 60 * 1000) });
17
+ const signFn = (payload) => ctx.unshieldedKeystore.signData(payload);
18
+ signTransactionIntents(recipe.baseTransaction, signFn, "proof");
19
+ if (recipe.balancingTransaction) {
20
+ signTransactionIntents(recipe.balancingTransaction, signFn, "pre-proof");
21
+ }
22
+ return ctx.wallet.finalizeRecipe(recipe);
23
+ },
24
+ submitTx(tx) {
25
+ return ctx.wallet.submitTransaction(tx);
26
+ },
27
+ };
28
+ };
29
+ //# sourceMappingURL=wallet-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-provider.js","sourceRoot":"","sources":["../src/wallet-provider.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAE3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,MAAM,CAAC,MAAM,+BAA+B,GAAG,KAAK,EAClD,GAA6B,EACe,EAAE;IAC9C,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,cAAc,CACnC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CACtD,CAAC;IAEF,OAAO;QACL,gBAAgB;YACd,OAAO,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;QACpD,CAAC;QACD,sBAAsB;YACpB,OAAO,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,CAAC;QAC1D,CAAC;QACD,KAAK,CAAC,SAAS,CACb,EAAsB,EACtB,GAAU;YAEV,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,yBAAyB,CACvD,EAAE,EACF;gBACE,kBAAkB,EAAE,GAAG,CAAC,kBAAkB;gBAC1C,aAAa,EAAE,GAAG,CAAC,aAAa;aACjC,EACD,EAAE,GAAG,EAAE,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE,CACtD,CAAC;YAEF,MAAM,MAAM,GAAG,CAAC,OAAmB,EAAE,EAAE,CACrC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3C,sBAAsB,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAChE,IAAI,MAAM,CAAC,oBAAoB,EAAE,CAAC;gBAChC,sBAAsB,CACpB,MAAM,CAAC,oBAAoB,EAC3B,MAAM,EACN,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,OAAO,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC;QACD,QAAQ,CAAC,EAAwB;YAC/B,OAAO,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { InMemoryTransactionHistoryStorage } from "@midnight-ntwrk/wallet-sdk-unshielded-wallet";
2
+ import { type Config } from "./config.js";
3
+ export declare const buildShieldedConfig: ({ indexer, indexerWS, node, proofServer, }: Config) => {
4
+ networkId: string;
5
+ indexerClientConnection: {
6
+ indexerHttpUrl: string;
7
+ indexerWsUrl: string;
8
+ };
9
+ provingServerUrl: import("url").URL;
10
+ relayURL: import("url").URL;
11
+ };
12
+ export declare const buildUnshieldedConfig: ({ indexer, indexerWS }: Config, txHistoryStorage: InMemoryTransactionHistoryStorage) => {
13
+ networkId: string;
14
+ indexerClientConnection: {
15
+ indexerHttpUrl: string;
16
+ indexerWsUrl: string;
17
+ };
18
+ txHistoryStorage: InMemoryTransactionHistoryStorage;
19
+ };
20
+ export declare const buildDustConfig: ({ indexer, indexerWS, node, proofServer, }: Config) => {
21
+ networkId: string;
22
+ costParameters: {
23
+ additionalFeeOverhead: bigint;
24
+ feeBlocksMargin: number;
25
+ };
26
+ indexerClientConnection: {
27
+ indexerHttpUrl: string;
28
+ indexerWsUrl: string;
29
+ };
30
+ provingServerUrl: import("url").URL;
31
+ relayURL: import("url").URL;
32
+ };
@@ -0,0 +1,23 @@
1
+ import { getNetworkId } from "@midnight-ntwrk/midnight-js-network-id";
2
+ export const buildShieldedConfig = ({ indexer, indexerWS, node, proofServer, }) => ({
3
+ networkId: getNetworkId(),
4
+ indexerClientConnection: { indexerHttpUrl: indexer, indexerWsUrl: indexerWS },
5
+ provingServerUrl: new URL(proofServer),
6
+ relayURL: new URL(node.replace(/^http/, "ws")),
7
+ });
8
+ export const buildUnshieldedConfig = ({ indexer, indexerWS }, txHistoryStorage) => ({
9
+ networkId: getNetworkId(),
10
+ indexerClientConnection: { indexerHttpUrl: indexer, indexerWsUrl: indexerWS },
11
+ txHistoryStorage,
12
+ });
13
+ export const buildDustConfig = ({ indexer, indexerWS, node, proofServer, }) => ({
14
+ networkId: getNetworkId(),
15
+ costParameters: {
16
+ additionalFeeOverhead: 300000000000000n,
17
+ feeBlocksMargin: 5,
18
+ },
19
+ indexerClientConnection: { indexerHttpUrl: indexer, indexerWsUrl: indexerWS },
20
+ provingServerUrl: new URL(proofServer),
21
+ relayURL: new URL(node.replace(/^http/, "ws")),
22
+ });
23
+ //# sourceMappingURL=wallet-sdk-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-sdk-config.js","sourceRoot":"","sources":["../src/wallet-sdk-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAKtE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,EAClC,OAAO,EACP,SAAS,EACT,IAAI,EACJ,WAAW,GACJ,EAAE,EAAE,CAAC,CAAC;IACb,SAAS,EAAE,YAAY,EAAE;IACzB,uBAAuB,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE;IAC7E,gBAAgB,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC;IACtC,QAAQ,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;CAC/C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,EAAE,OAAO,EAAE,SAAS,EAAU,EAC9B,gBAAmD,EACnD,EAAE,CAAC,CAAC;IACJ,SAAS,EAAE,YAAY,EAAE;IACzB,uBAAuB,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE;IAC7E,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,OAAO,EACP,SAAS,EACT,IAAI,EACJ,WAAW,GACJ,EAAE,EAAE,CAAC,CAAC;IACb,SAAS,EAAE,YAAY,EAAE;IACzB,cAAc,EAAE;QACd,qBAAqB,EAAE,gBAAoB;QAC3C,eAAe,EAAE,CAAC;KACnB;IACD,uBAAuB,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE;IAC7E,gBAAgB,EAAE,IAAI,GAAG,CAAC,WAAW,CAAC;IACtC,QAAQ,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;CAC/C,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { type FacadeState } from "@midnight-ntwrk/wallet-sdk-facade";
2
+ import { type MidnightDIDWalletContext, type MidnightWalletBalances, type MidnightWalletFacadeState, type MidnightWalletStateSnapshot } from "./types.js";
3
+ export declare const serializeWalletState: (ctx: Pick<MidnightDIDWalletContext, "shieldedWallet" | "unshieldedWallet" | "dustWallet" | "unshieldedHistoryStorage">) => Promise<MidnightWalletStateSnapshot>;
4
+ export declare const waitForWalletSync: (ctx: Pick<MidnightDIDWalletContext, "wallet">) => Promise<FacadeState>;
5
+ export declare const getWalletBalances: (state: MidnightWalletFacadeState) => MidnightWalletBalances;
6
+ export declare const waitForWalletFunds: (ctx: Pick<MidnightDIDWalletContext, "wallet">) => Promise<bigint>;
@@ -0,0 +1,32 @@
1
+ import { unshieldedToken } from "@midnight-ntwrk/ledger-v8";
2
+ import * as Rx from "rxjs";
3
+ import { getLogger } from "./api-logger.js";
4
+ export const serializeWalletState = async (ctx) => ({
5
+ shieldedState: await ctx.shieldedWallet.serializeState(),
6
+ unshieldedState: await ctx.unshieldedWallet.serializeState(),
7
+ dustState: await ctx.dustWallet.serializeState(),
8
+ unshieldedHistory: ctx.unshieldedHistoryStorage.serialize(),
9
+ });
10
+ export const waitForWalletSync = async (ctx) => {
11
+ getLogger().info("Waiting for wallet sync...");
12
+ return await ctx.wallet.waitForSyncedState();
13
+ };
14
+ export const getWalletBalances = (state) => {
15
+ if (!state.isSynced) {
16
+ return {
17
+ night: null,
18
+ dust: null,
19
+ };
20
+ }
21
+ return {
22
+ night: state.unshielded.balances[unshieldedToken().raw] ?? 0n,
23
+ dust: state.dust.balance(new Date()),
24
+ };
25
+ };
26
+ export const waitForWalletFunds = async (ctx) => {
27
+ getLogger().info("Waiting for funds...");
28
+ const balance = await Rx.firstValueFrom(ctx.wallet.state().pipe(Rx.throttleTime(10_000), Rx.map(getWalletBalances), Rx.map((balances) => balances.night ?? 0n), Rx.filter((currentBalance) => currentBalance > 0n)));
29
+ getLogger().info(`Wallet balance: ${balance}`);
30
+ return balance;
31
+ };
32
+ //# sourceMappingURL=wallet-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-state.js","sourceRoot":"","sources":["../src/wallet-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,GAMC,EACqC,EAAE,CAAC,CAAC;IAC1C,aAAa,EAAE,MAAM,GAAG,CAAC,cAAc,CAAC,c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AAI,EAAE,CAAC,EAC1C,EAAE,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,cAAc,GAAG,EAAE,CAAC,CACnD,CACF,CAAC;IACF,SAAS,EAAE,CAAC,IAAI,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAC;IAC/C,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import "./polyfills.js";
2
+ import { type Config } from "./config.js";
3
+ import { type MidnightDIDWalletContext, type MidnightWalletStateSnapshot } from "./types.js";
4
+ export { registerForDustGeneration } from "./wallet-dust.js";
5
+ export { getWalletBalances, serializeWalletState, waitForWalletFunds, waitForWalletSync, } from "./wallet-state.js";
6
+ export declare const buildWallet: (config: Config, seed: string, snapshot?: MidnightWalletStateSnapshot) => Promise<MidnightDIDWalletContext>;
7
+ export declare const restoreWalletFromState: (config: Config, seed: string, snapshot: MidnightWalletStateSnapshot) => Promise<MidnightDIDWalletContext>;
8
+ export declare const buildWalletAndWaitForFunds: (config: Config, seed: string) => Promise<MidnightDIDWalletContext>;
9
+ export declare const buildFreshWallet: (config: Config) => Promise<MidnightDIDWalletContext>;