@dynamic-labs-wallet/midnight 0.0.0 → 0.0.347

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.
package/package.json CHANGED
@@ -1 +1,42 @@
1
- { "name": "@dynamic-labs-wallet/midnight", "version": "0.0.0" }
1
+ {
2
+ "name": "@dynamic-labs-wallet/midnight",
3
+ "version": "0.0.347",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "@dynamic-labs-wallet/browser": "0.0.347",
8
+ "@dynamic-labs/sdk-api-core": "^0.0.964",
9
+ "@midnight-ntwrk/ledger-v8": "8.0.3",
10
+ "@midnight-ntwrk/wallet-sdk-address-format": "3.1.0",
11
+ "@scure/bip32": "^2.0.1",
12
+ "bs58": "^6.0.0",
13
+ "@midnight-ntwrk/wallet-sdk-facade": "3.0.0",
14
+ "@midnight-ntwrk/wallet-sdk-shielded": "2.1.0",
15
+ "@midnight-ntwrk/wallet-sdk-unshielded-wallet": "2.1.0",
16
+ "@midnight-ntwrk/wallet-sdk-dust-wallet": "3.0.0",
17
+ "bech32": "^2.0.0"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "nx": {
23
+ "sourceRoot": "packages/midnight/src",
24
+ "projectType": "library",
25
+ "name": "midnight",
26
+ "targets": {
27
+ "build": {}
28
+ }
29
+ },
30
+ "main": "./index.cjs.js",
31
+ "module": "./index.esm.js",
32
+ "types": "./index.esm.d.ts",
33
+ "exports": {
34
+ "./package.json": "./package.json",
35
+ ".": {
36
+ "types": "./index.esm.d.ts",
37
+ "import": "./index.esm.js",
38
+ "require": "./index.cjs.js",
39
+ "default": "./index.esm.js"
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,253 @@
1
+ import { DynamicWalletClient, type ClientKeyShare, type DynamicWalletClientInternalOptions, type DynamicWalletClientProps, type ThresholdSignatureScheme, type RequestWithElevatedAccessToken } from '@dynamic-labs-wallet/browser';
2
+ import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
3
+ export declare class DynamicMidnightWalletClient extends DynamicWalletClient {
4
+ readonly chainName = "MIDNIGHT";
5
+ private cachedWallet;
6
+ private readonly pendingInits;
7
+ /**
8
+ * Coerce the value returned by `wallet.submitTransaction(...)` to a string.
9
+ * Midnight's facade returns either a string txId, or a TransactionIdentifier
10
+ * object with a `.toHex()` method. We normalize so callers always see a
11
+ * string, and fall back to `String(...)` if neither shape matches.
12
+ */
13
+ private static toTxHashString;
14
+ /**
15
+ * Snapshot the current shielded + dust state to IndexedDB so the next
16
+ * init on this account resumes from this checkpoint. Fire-and-forget —
17
+ * callers shouldn't await this to avoid adding latency to user actions.
18
+ *
19
+ * Option A: ONLY persist when the wallet is in a clean resting state
20
+ * (no pending-tx entries, no pending UTXOs on any side). If the wallet
21
+ * has in-flight work, skip the write — we don't want dirty state to
22
+ * get baked into IndexedDB and trap the user on next reload.
23
+ *
24
+ * "Clean" == whatever's persisted can be restored without dragging
25
+ * stale pending entries forward. If a tx fails or a draft is abandoned,
26
+ * sync will reconcile on the next load based on what the chain actually
27
+ * shows, which is always authoritative.
28
+ */
29
+ private persistCachedWalletState;
30
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, logger, }: DynamicWalletClientProps, internalOptions?: DynamicWalletClientInternalOptions);
31
+ createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, }: {
32
+ thresholdSignatureScheme: ThresholdSignatureScheme;
33
+ password?: string;
34
+ onError?: (error: Error) => void;
35
+ signedSessionId: string;
36
+ }): Promise<{
37
+ accountAddress: string;
38
+ publicKeyHex: string;
39
+ rawPublicKey: Uint8Array;
40
+ }>;
41
+ signMessage({ message, accountAddress, password, signedSessionId, mfaToken, context, onError, }: {
42
+ message: string;
43
+ accountAddress: string;
44
+ password?: string;
45
+ signedSessionId: string;
46
+ mfaToken?: string;
47
+ context?: SignMessageContext;
48
+ onError?: (error: Error) => void;
49
+ }): Promise<string>;
50
+ /**
51
+ * Sign + finalize (prove) an unsigned Midnight transaction. Unshielded
52
+ * segments are MPC-signed via BIP-340; shielded/dust proving is delegated
53
+ * to the facade's proof server.
54
+ *
55
+ * Side effect: finalizeRecipe mutates wallet state (adds a pending-tx
56
+ * entry). If the caller never calls submitTransaction, that entry sits
57
+ * until the next re-sync drops it.
58
+ */
59
+ signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, elevatedAccessToken, networkId, context, onError, }: {
60
+ senderAddress: string;
61
+ /** Base64-encoded unsigned Midnight UnprovenTransaction (from createTransferTransaction or a caller-built tx). */
62
+ transaction: string;
63
+ password?: string;
64
+ signedSessionId: string;
65
+ mfaToken?: string;
66
+ elevatedAccessToken?: string;
67
+ /** Network ID: 0 = Testnet, 1 = Mainnet (or chainId string like "midnight:mainnet") */
68
+ networkId?: number | string;
69
+ context?: SignMessageContext;
70
+ onError?: (error: Error) => void;
71
+ }): Promise<string>;
72
+ exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: RequestWithElevatedAccessToken<{
73
+ accountAddress: string;
74
+ password?: string;
75
+ signedSessionId: string;
76
+ mfaToken?: string;
77
+ }>): Promise<string>;
78
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, signedSessionId, onError, publicAddressCheck, legacyWalletId, }: {
79
+ privateKey: string;
80
+ chainName: string;
81
+ thresholdSignatureScheme: ThresholdSignatureScheme;
82
+ password?: string;
83
+ signedSessionId: string;
84
+ onError?: (error: Error) => void;
85
+ publicAddressCheck?: string;
86
+ /** ID of the legacy embedded wallet being upgraded to v3 */
87
+ legacyWalletId?: string;
88
+ }): Promise<{
89
+ accountAddress: string;
90
+ publicKeyHex: string;
91
+ rawPublicKey: Uint8Array;
92
+ clientKeyShares: ClientKeyShare[];
93
+ }>;
94
+ getPublicKeyFromPrivateKey(privateKeyHex: string): string;
95
+ getMidnightWallets(): Promise<any>;
96
+ /**
97
+ * Get or derive Midnight role keys (cached in storage).
98
+ * Calls existing exportKey internally - no new MPC flow.
99
+ * Keys: unshielded (NightExternal), shielded (Zswap), dust.
100
+ */
101
+ private getRoleKeys;
102
+ private initMidnightWallet;
103
+ private runMidnightWalletInit;
104
+ getPrivateBalance({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
105
+ accountAddress: string;
106
+ password?: string;
107
+ signedSessionId: string;
108
+ mfaToken?: string;
109
+ elevatedAccessToken?: string;
110
+ }): Promise<{
111
+ unshielded: Record<string, string>;
112
+ shielded: Record<string, string>;
113
+ dust: string;
114
+ address: string;
115
+ }>;
116
+ registerDust({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
117
+ accountAddress: string;
118
+ password?: string;
119
+ signedSessionId: string;
120
+ mfaToken?: string;
121
+ elevatedAccessToken?: string;
122
+ }): Promise<{
123
+ /** Current dust balance at time of this call. 0 is normal for fresh
124
+ * registrations — dust generation is continuous on-chain, poll
125
+ * getPrivateBalance to observe it. */
126
+ dustBalance: string;
127
+ /** Transaction hash of the registration tx we submitted, if any. */
128
+ txId?: string;
129
+ /** Registration status:
130
+ * - 'registered' — we submitted a new registration tx this call
131
+ * - 'already_registered' — NIGHT UTXOs already marked registered, no action needed
132
+ * - 'already_has_dust' — wallet already has dust > 0, no action needed
133
+ * - 'no_utxos' — wallet has no NIGHT UTXOs to register
134
+ */
135
+ status: 'registered' | 'already_registered' | 'already_has_dust' | 'no_utxos';
136
+ /** Human-readable summary of what happened and what the caller should do next. */
137
+ message: string;
138
+ /** How many NIGHT UTXOs were registered by this call (0 if none). */
139
+ registeredCount: number;
140
+ }>;
141
+ /**
142
+ * Build an unsigned Midnight transfer (unshielded, shielded, or mixed).
143
+ * No MPC, no proof server, no broadcast — pair with signTransaction and
144
+ * submitTransaction.
145
+ */
146
+ createTransferTransaction({ accountAddress, transfers, ttlMinutes, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
147
+ accountAddress: string;
148
+ transfers: Array<{
149
+ type: 'unshielded' | 'shielded';
150
+ recipientAddress: string;
151
+ amount: string;
152
+ tokenType?: string;
153
+ }>;
154
+ /** Optional TTL in minutes. Defaults to 5. */
155
+ ttlMinutes?: number;
156
+ password?: string;
157
+ signedSessionId: string;
158
+ mfaToken?: string;
159
+ elevatedAccessToken?: string;
160
+ }): Promise<{
161
+ serializedTransaction: string;
162
+ }>;
163
+ /**
164
+ * Broadcast a finalized Midnight transaction. Pure RPC — no MPC, no proof
165
+ * server; reuses the cached wallet's node connection. Optionally blocks
166
+ * until the unshielded balance for tokenType stabilizes.
167
+ */
168
+ submitTransaction({ accountAddress, transaction, waitForBalance, tokenType, balanceBefore, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
169
+ accountAddress: string;
170
+ /** Base64-encoded FinalizedTransaction */
171
+ transaction: string;
172
+ /** If true, blocks until unshielded balance for tokenType stabilizes. */
173
+ waitForBalance?: boolean;
174
+ tokenType?: string;
175
+ balanceBefore?: string;
176
+ password?: string;
177
+ signedSessionId: string;
178
+ mfaToken?: string;
179
+ elevatedAccessToken?: string;
180
+ }): Promise<{
181
+ txHash: string;
182
+ balanceAfter?: string;
183
+ }>;
184
+ /**
185
+ * Release UTXOs reserved by drafted or signed-but-never-submitted Midnight
186
+ * transactions. Three mutually exclusive modes, resolved by priority below.
187
+ *
188
+ * Priority order:
189
+ * 1. `resetCache` — nuclear: stops cached wallet, deletes the account's
190
+ * persisted state from IndexedDB, forces next operation to cold-sync.
191
+ * Use this when reference to specific pending txs is lost, or state
192
+ * got into a stuck configuration that can't be reverted otherwise.
193
+ * This is Midnight's documented workaround for "pending coins not
194
+ * cleared after failed shielded transaction".
195
+ * 2. `transaction` — revert one specific tx by its base64 serialization.
196
+ * Accepts either UnprovenTransaction (step 1 output) or
197
+ * FinalizedTransaction (step 2 output).
198
+ * 3. `all` — iterate `state.pending.all` and revert each. Covers every
199
+ * finalized tx the SDK knows about. Does NOT cover Step-1-only drafts
200
+ * (those are never registered with the pending-tx service — by design
201
+ * per Midnight, because unproven transactions hold secret-key material).
202
+ *
203
+ * Exactly one of the three must be truthy; otherwise this throws.
204
+ */
205
+ revertTransaction(params: {
206
+ accountAddress: string;
207
+ transaction?: string;
208
+ all?: boolean;
209
+ resetCache?: boolean;
210
+ password?: string;
211
+ signedSessionId: string;
212
+ mfaToken?: string;
213
+ elevatedAccessToken?: string;
214
+ }): Promise<{
215
+ reverted: boolean;
216
+ count: number;
217
+ cacheCleared: boolean;
218
+ message: string;
219
+ }>;
220
+ private revertModeResetCache;
221
+ private revertModeSingleTransaction;
222
+ private revertModeAllPending;
223
+ private deserializeAnyMidnightTx;
224
+ private snapshotWalletState;
225
+ /**
226
+ * Sign all unshielded intents in a transaction via MPC.
227
+ * Mutates tx.intents in place with signatures attached.
228
+ * No-op for pure shielded transactions (0 unshielded segments).
229
+ *
230
+ * Each per-segment sign call carries the full unsigned tx in context so
231
+ * wallet-service policy sees the whole transaction once per signature
232
+ * (same pattern as BTC's PSBT in per-input context).
233
+ */
234
+ private mpcSignIntents;
235
+ /**
236
+ * Returns a Midnight.js-compatible WalletProvider for use with
237
+ * midnight-js-contracts. Signing goes through MPC — no private key exposed.
238
+ */
239
+ getWalletProvider({ accountAddress, password, signedSessionId, mfaToken, elevatedAccessToken, }: {
240
+ accountAddress: string;
241
+ password?: string;
242
+ signedSessionId: string;
243
+ mfaToken?: string;
244
+ elevatedAccessToken?: string;
245
+ }): Promise<{
246
+ walletProvider: any;
247
+ wallet: any;
248
+ state: any;
249
+ shieldedSecretKeys: any;
250
+ dustSecretKey: any;
251
+ }>;
252
+ }
253
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAKnB,KAAK,cAAc,EACnB,KAAK,kCAAkC,EACvC,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EACpC,MAAM,8BA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AAE,GAAG,CAAC;QACZ,KAAK,EAAE,GAAG,CAAC;QACX,kBAAkB,EAAE,GAAG,CAAC;QACxB,aAAa,EAAE,GAAG,CAAC;KACpB,CAAC;CA8DH"}
@@ -0,0 +1,31 @@
1
+ export declare const MIDNIGHT_NETWORK_IDS: {
2
+ readonly mainnet: 1;
3
+ readonly preview: 0;
4
+ readonly preprod: 0;
5
+ readonly undeployed: 0;
6
+ };
7
+ export type MidnightNetwork = keyof typeof MIDNIGHT_NETWORK_IDS;
8
+ export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
9
+ export declare const ERROR_NETWORK_ID_REQUIRED = "Network ID is required for Midnight transactions";
10
+ export declare const ERROR_UNKNOWN_NETWORK = "Unknown Midnight network";
11
+ export declare const ERROR_CREATE_WALLET_ACCOUNT = "Failed to create Midnight wallet account";
12
+ export declare const ERROR_EXPORT_PRIVATE_KEY = "Failed to export Midnight private key";
13
+ export declare const ERROR_IMPORT_PRIVATE_KEY = "Failed to import Midnight private key";
14
+ export declare const ERROR_KEYGEN_FAILED = "Key generation failed for Midnight wallet";
15
+ export declare const ERROR_SIGN_MESSAGE = "Failed to sign Midnight message";
16
+ export declare const ERROR_SIGN_TRANSACTION = "Failed to sign Midnight transaction";
17
+ /**
18
+ * Resolves a Midnight network name (or `"midnight:<network>"` chainId) to its
19
+ * numeric network ID (0 for non-mainnet, 1 for mainnet).
20
+ *
21
+ * Throws on unrecognized input rather than defaulting — silently falling back
22
+ * to mainnet would bake the wrong network ID into the transaction hash and
23
+ * break the replay-protection guarantee. Fail-loud is correct here.
24
+ *
25
+ * @param networkOrChainId `mainnet` | `preview` | `preprod` | `undeployed`,
26
+ * or the `midnight:<network>` chainId form.
27
+ * @throws {Error} ERROR_UNKNOWN_NETWORK when the input doesn't match any
28
+ * recognized network.
29
+ */
30
+ export declare const getNetworkIdFromChainId: (networkOrChainId: string) => number;
31
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAGhE,eAAO,MAAM,8BAA8B,gCAAgC,CAAC;AAC5E,eAAO,MAAM,yBAAyB,qDAAqD,CAAC;AAC5F,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,2BAA2B,6CAA6C,CAAC;AACtF,eAAO,MAAM,wBAAwB,0CAA0C,CAAC;AAChF,eAAO,MAAM,wBAAwB,0CAA0C,CAAC;AAChF,eAAO,MAAM,mBAAmB,8CAA8C,CAAC;AAC/E,eAAO,MAAM,kBAAkB,oCAAoC,CAAC;AACpE,eAAO,MAAM,sBAAsB,wCAAwC,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,qBAAsB,MAAM,KAAG,MAgBlE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { DynamicMidnightWalletClient } from './client.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * IndexedDB-backed persistence for Midnight sub-wallet sync state.
3
+ *
4
+ * Shielded and Dust sub-wallets support serialize/restore — we cache the
5
+ * serialized state per accountAddress so re-initializing a wallet (either
6
+ * after switching away and back, or after a page reload) resumes sync from
7
+ * the last checkpoint instead of re-scanning the entire chain.
8
+ *
9
+ * Storage shape (object store "state", keyed by accountAddress):
10
+ * { accountAddress, shielded, dust, updatedAt }
11
+ *
12
+ * Security: blobs are stored plaintext, matching Dynamic's existing policy
13
+ * for locally-cached key material (see the role-keys entries in
14
+ * localStorage). Protection comes from the iframe's origin isolation, not
15
+ * from at-rest encryption. If Dynamic decides to tighten the local-storage
16
+ * policy product-wide (password-derived encryption with AES-GCM), this
17
+ * module should be upgraded alongside the localStorage role-keys flow as a
18
+ * single consistent hardening pass.
19
+ */
20
+ export type PersistedWalletState = {
21
+ accountAddress: string;
22
+ shielded: string;
23
+ dust: string;
24
+ updatedAt: number;
25
+ };
26
+ export declare function toError(err: unknown, fallbackMessage: string): Error;
27
+ export declare function getWalletState(accountAddress: string): Promise<PersistedWalletState | null>;
28
+ export declare function putWalletState(accountAddress: string, state: {
29
+ shielded: string;
30
+ dust: string;
31
+ }): Promise<void>;
32
+ export declare function deleteWalletState(accountAddress: string): Promise<void>;
33
+ //# sourceMappingURL=walletStateStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletStateStorage.d.ts","sourceRoot":"","sources":["../../src/client/walletStateStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,KAAK,CAcpE;AAsCD,wBAAsB,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAUjG;AAED,wBAAsB,cAAc,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYrH;AAED,wBAAsB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7E"}
package/src/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './client/index.js';
2
+ export { MIDNIGHT_NETWORK_IDS, type MidnightNetwork } from './client/constants.js';
3
+ export { deriveMidnightAddress } from './utils/index.js';
4
+ export * as sdkApiCore from '@dynamic-labs/sdk-api-core';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,UAAU,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Address prefixes for Bech32m encoding (BIP-0350)
3
+ */
4
+ declare const ADDRESS_PREFIXES: {
5
+ readonly mainnet: "mn_addr";
6
+ readonly preview: "mn_addr_preview";
7
+ readonly preprod: "mn_addr_preprod";
8
+ readonly undeployed: "mn_addr_undeployed";
9
+ };
10
+ type Network = keyof typeof ADDRESS_PREFIXES;
11
+ /**
12
+ * Derives a Midnight unshielded address from a 32-byte address hash.
13
+ * NOTE: Midnight addresses are Poseidon hashes of the public key, not the raw key.
14
+ * The address hash should be computed server-side using ledger.addressFromKey().
15
+ * If publicKeyHex is passed, it's assumed to already be the address hash.
16
+ *
17
+ * @param publicKeyHex - The 32-byte address hash (from addressFromKey) as hex string
18
+ * @param network - The network. Defaults to preview
19
+ * @returns Bech32m encoded address (e.g., mn_addr_preview1...)
20
+ */
21
+ export declare const deriveMidnightAddress: ({ publicKeyHex, network, }: {
22
+ publicKeyHex: string;
23
+ network?: Network;
24
+ }) => string;
25
+ /**
26
+ * Validates a Midnight address
27
+ */
28
+ export declare const isValidMidnightAddress: (address: string) => boolean;
29
+ /**
30
+ * Decodes a Midnight address to raw bytes
31
+ */
32
+ export declare const decodeMidnightAddress: (address: string) => Buffer;
33
+ /**
34
+ * Gets the network from a Midnight address.
35
+ * Iterates longest-prefix-first so that `mn_addr_preview` matches before the
36
+ * shorter `mn_addr` (mainnet) — otherwise a preview address would be
37
+ * misidentified as mainnet.
38
+ */
39
+ export declare const getNetworkFromAddress: (address: string) => Network;
40
+ export {};
41
+ //# sourceMappingURL=deriveMidnightAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deriveMidnightAddress.d.ts","sourceRoot":"","sources":["../../../src/utils/deriveMidnightAddress/deriveMidnightAddress.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,QAAA,MAAM,gBAAgB;;;;;CAKZ,CAAC;AAEX,KAAK,OAAO,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAE7C;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,+BAG/B;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,KAAG,MAWH,CAAC;AAWF;;GAEG;AACH,eAAO,MAAM,sBAAsB,YAAa,MAAM,KAAG,OAWxD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,YAAa,MAAM,KAAG,MAMvD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,YAAa,MAAM,KAAG,OAOvD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { deriveMidnightAddress, isValidMidnightAddress, decodeMidnightAddress, getNetworkFromAddress, } from './deriveMidnightAddress.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/deriveMidnightAddress/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './deriveMidnightAddress/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}