@dynamic-labs/midnight 4.90.0 → 4.91.1
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/CHANGELOG.md +36 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -6
- package/src/MidnightWalletConnectors.cjs +6 -0
- package/src/MidnightWalletConnectors.js +6 -0
- package/src/connectors/MidnightWalletConnector.cjs +41 -0
- package/src/connectors/MidnightWalletConnector.d.ts +42 -1
- package/src/connectors/MidnightWalletConnector.js +41 -0
- package/src/index.cjs +8 -6
- package/src/index.d.ts +1 -1
- package/src/index.js +4 -2
- package/src/types.d.ts +11 -2
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.cjs +109 -0
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.d.ts +2 -2
- package/src/utils/MidnightUiTransaction/MidnightUiTransaction.js +105 -0
- package/src/waas/DynamicWaasMidnightConnectors.cjs +16 -0
- package/src/waas/DynamicWaasMidnightConnectors.d.ts +6 -0
- package/src/waas/DynamicWaasMidnightConnectors.js +12 -0
- package/src/waas/WaasMidnightWalletConnector.cjs +109 -0
- package/src/waas/WaasMidnightWalletConnector.d.ts +44 -0
- package/src/waas/WaasMidnightWalletConnector.js +105 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.cjs +584 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.d.ts +470 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.js +580 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.cjs +48 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.d.ts +26 -0
- package/src/waas/connector/buildMidnightWaasConnectedApi.js +42 -0
- package/src/waas/connector/index.d.ts +1 -0
- package/src/waas/index.d.ts +4 -0
- package/src/waas/isMidnightWallet.cjs +15 -0
- package/src/waas/isMidnightWallet.d.ts +7 -0
- package/src/waas/isMidnightWallet.js +11 -0
- package/src/wallet/MidnightWallet.cjs +31 -0
- package/src/wallet/MidnightWallet.d.ts +15 -0
- package/src/wallet/MidnightWallet.js +31 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import type { ConnectedAPI, TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
2
|
+
import { JwtVerifiedCredential, MFAAction, SignMessageContext, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
import { IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
4
|
+
import { IDynamicWaasConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
+
import type { DynamicWaasMidnightConnectorProps } from '../../types';
|
|
7
|
+
import { MidnightWallet } from '../../wallet/MidnightWallet';
|
|
8
|
+
import { WaasMidnightWalletConnector } from '../WaasMidnightWalletConnector';
|
|
9
|
+
declare const DynamicWaasMidnightConnector_base: (abstract new (...args: any[]) => {
|
|
10
|
+
[x: string]: any;
|
|
11
|
+
name: string;
|
|
12
|
+
overrideKey: string;
|
|
13
|
+
isEmbeddedWallet: boolean;
|
|
14
|
+
getSignedSessionId?: (() => Promise<string>) | undefined;
|
|
15
|
+
getSessionPublicKey?: (() => Promise<string | undefined>) | undefined;
|
|
16
|
+
getMfaToken?: ((props?: {
|
|
17
|
+
mfaAction?: MFAAction | undefined;
|
|
18
|
+
} | undefined) => Promise<string | undefined>) | undefined;
|
|
19
|
+
getWalletPassword?: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn | undefined;
|
|
20
|
+
getAuthToken?: (() => string) | undefined;
|
|
21
|
+
getElevatedAccessToken?: ((props: {
|
|
22
|
+
scope: TokenScope;
|
|
23
|
+
}) => Promise<string | undefined>) | undefined;
|
|
24
|
+
onUnauthorized?: (() => void | Promise<void>) | undefined;
|
|
25
|
+
environmentId?: string | undefined;
|
|
26
|
+
baseApiUrl?: string | undefined;
|
|
27
|
+
relayUrl?: string | undefined;
|
|
28
|
+
baseClientKeysharesRelayApiUrl?: string | undefined;
|
|
29
|
+
dynamicWaasClient: import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient | undefined;
|
|
30
|
+
chainName: string;
|
|
31
|
+
authMode: "cookie" | "header";
|
|
32
|
+
logger: Logger;
|
|
33
|
+
__exportHandler: import("@dynamic-labs/waas").WaasExportHandler;
|
|
34
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
35
|
+
setGetAuthTokenFunction(getAuthToken: () => string): void;
|
|
36
|
+
setOnUnauthorizedFunction(onUnauthorized: () => void | Promise<void>): void;
|
|
37
|
+
setWaasAuthMode(authMode: "cookie" | "header"): void;
|
|
38
|
+
setGetMfaTokenFunction(getMfaToken: (props?: {
|
|
39
|
+
mfaAction?: MFAAction | undefined;
|
|
40
|
+
} | undefined) => Promise<string | undefined>): void;
|
|
41
|
+
setGetElevatedAccessTokenFunction(getElevatedAccessToken: (params: {
|
|
42
|
+
scope: TokenScope;
|
|
43
|
+
}) => Promise<string | undefined>): void;
|
|
44
|
+
setGetWalletPasswordFunction(getWalletPassword: import("@dynamic-labs/wallet-connector-core").GetWalletPasswordFn): void;
|
|
45
|
+
getPasswordIfNeeded({ accountAddress, }: {
|
|
46
|
+
accountAddress: string;
|
|
47
|
+
}): Promise<string | undefined>;
|
|
48
|
+
getPassword({ accountAddress, }: {
|
|
49
|
+
accountAddress: string;
|
|
50
|
+
}): Promise<string | undefined>;
|
|
51
|
+
setEnvironmentId(environmentId: string): void;
|
|
52
|
+
setBaseApiUrl(baseApiUrl: string): void;
|
|
53
|
+
setBaseClientKeysharesRelayApiUrl(baseClientKeysharesRelayApiUrl?: string | undefined): void;
|
|
54
|
+
setRelayUrl(relayUrl: string): void;
|
|
55
|
+
setGetSignedSessionIdFunction(getSignedSessionId: () => Promise<string>): void;
|
|
56
|
+
setGetSessionPublicKeyFunction(getSessionPublicKey: () => Promise<string | undefined>): void;
|
|
57
|
+
delegateKeyShares({ accountAddress, password, }: {
|
|
58
|
+
accountAddress: string;
|
|
59
|
+
password?: string | undefined;
|
|
60
|
+
}): Promise<void>;
|
|
61
|
+
createDynamicWaasClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
62
|
+
getWaasWalletClient(traceContext?: import("dist/packages/waas/utils/instrumentation").TraceContext | undefined, { forceRebuild }?: {
|
|
63
|
+
forceRebuild?: boolean | undefined;
|
|
64
|
+
} | undefined): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
65
|
+
createWalletAccount({ thresholdSignatureScheme, password, bitcoinConfig, }?: {
|
|
66
|
+
thresholdSignatureScheme?: string | undefined;
|
|
67
|
+
password?: string | undefined;
|
|
68
|
+
bitcoinConfig?: import("@dynamic-labs-wallet/browser-wallet-client").BitcoinConfig | undefined;
|
|
69
|
+
} | undefined): Promise<{
|
|
70
|
+
/**
|
|
71
|
+
* Requires and returns the signed session ID
|
|
72
|
+
* @returns The signed session ID
|
|
73
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
74
|
+
*/
|
|
75
|
+
chainName: string;
|
|
76
|
+
accountAddress: string;
|
|
77
|
+
publicKeyHex: string;
|
|
78
|
+
rawPublicKey: string | Uint8Array | undefined;
|
|
79
|
+
}>;
|
|
80
|
+
importPrivateKey({ privateKey, thresholdSignatureScheme, publicAddressCheck, addressType, legacyWalletId, password, }: {
|
|
81
|
+
privateKey: string;
|
|
82
|
+
thresholdSignatureScheme?: string | undefined;
|
|
83
|
+
publicAddressCheck?: string | undefined;
|
|
84
|
+
addressType?: string | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Validates that the expected wallet address matches the active wallet
|
|
87
|
+
* Updates the active account address if it doesn't match
|
|
88
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
89
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
90
|
+
*/
|
|
91
|
+
legacyWalletId?: string | undefined;
|
|
92
|
+
password?: string | undefined;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
exportPrivateKey({ accountAddress, displayContainer, password, }?: {
|
|
95
|
+
accountAddress?: string | undefined;
|
|
96
|
+
displayContainer?: HTMLIFrameElement | undefined;
|
|
97
|
+
password?: string | undefined;
|
|
98
|
+
} | undefined): Promise<void>;
|
|
99
|
+
getExportHandler(): {
|
|
100
|
+
clear: () => void;
|
|
101
|
+
};
|
|
102
|
+
exportClientKeyshares({ accountAddress, password, }: {
|
|
103
|
+
accountAddress: string;
|
|
104
|
+
password?: string | undefined;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
backupKeySharesToGoogleDrive({ accountAddress, password, googleDriveAccessToken, }: {
|
|
107
|
+
accountAddress: string;
|
|
108
|
+
password?: string | undefined;
|
|
109
|
+
googleDriveAccessToken?: string | undefined;
|
|
110
|
+
}): Promise<void>;
|
|
111
|
+
exportClientKeysharesFromGoogleDrive({ accountAddress, password, }: {
|
|
112
|
+
accountAddress: string;
|
|
113
|
+
password?: string | undefined;
|
|
114
|
+
}): Promise<void>;
|
|
115
|
+
backupKeySharesToICloud({ accountAddress, password, }: {
|
|
116
|
+
accountAddress: string;
|
|
117
|
+
password?: string | undefined;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
displayICloudSignIn({ displayContainer, }: {
|
|
120
|
+
displayContainer: HTMLElement;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
hideICloudSignIn(): Promise<void>;
|
|
123
|
+
isICloudAuthenticated(): Promise<boolean>;
|
|
124
|
+
refreshWalletAccountShares({ accountAddress, password, }: {
|
|
125
|
+
accountAddress: string;
|
|
126
|
+
password?: string | undefined;
|
|
127
|
+
}): Promise<void>;
|
|
128
|
+
reshareWalletAccountShares({ accountAddress, thresholdSignatureScheme, password, }: {
|
|
129
|
+
accountAddress: string;
|
|
130
|
+
thresholdSignatureScheme: string;
|
|
131
|
+
password?: string | undefined;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
revokeDelegation({ accountAddress, password, }: {
|
|
134
|
+
accountAddress: string;
|
|
135
|
+
password?: string | undefined;
|
|
136
|
+
}): Promise<void>;
|
|
137
|
+
updatePassword({ accountAddress, existingPassword, newPassword, }: {
|
|
138
|
+
accountAddress: string; /**
|
|
139
|
+
* Connects to the WaaS wallet client
|
|
140
|
+
*/
|
|
141
|
+
existingPassword?: string | undefined;
|
|
142
|
+
newPassword: string;
|
|
143
|
+
}): Promise<void>;
|
|
144
|
+
setPassword({ accountAddress, newPassword, }: {
|
|
145
|
+
accountAddress: string;
|
|
146
|
+
newPassword: string;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
signRawMessage({ accountAddress, message, password, }: {
|
|
149
|
+
accountAddress: string;
|
|
150
|
+
message: string;
|
|
151
|
+
password?: string | undefined;
|
|
152
|
+
}): Promise<string>;
|
|
153
|
+
unlockWallet({ accountAddress, password, }: {
|
|
154
|
+
accountAddress: string;
|
|
155
|
+
password?: string | undefined;
|
|
156
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").GetWalletResponse>;
|
|
157
|
+
getWalletRecoveryState({ accountAddress, }: {
|
|
158
|
+
accountAddress: string;
|
|
159
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").WalletRecoveryState>;
|
|
160
|
+
endSession(reason?: import("@dynamic-labs-sdk/client").LogoutReason | undefined): Promise<void>;
|
|
161
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
162
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
163
|
+
generateTraceId(): string;
|
|
164
|
+
buildErrorInstrumentContext(error: unknown): {
|
|
165
|
+
errorCode: string | import("@dynamic-labs/utils").ErrorCode;
|
|
166
|
+
errorMessage: string;
|
|
167
|
+
errorType: string | undefined;
|
|
168
|
+
} | {
|
|
169
|
+
errorCode: string;
|
|
170
|
+
errorMessage?: undefined;
|
|
171
|
+
errorType?: undefined;
|
|
172
|
+
};
|
|
173
|
+
instrument(message: string, context: import("@dynamic-labs/logger").InstrumentOptions & import("dist/packages/waas/utils/instrumentation").InstrumentContext & Record<string, any>): void;
|
|
174
|
+
instrumentAsync<T_1>({ operation, resource, fn, context, }: {
|
|
175
|
+
operation: string;
|
|
176
|
+
resource: string;
|
|
177
|
+
fn: (timing: import("dist/packages/waas/utils/instrumentation").InstrumentationTimer) => Promise<T_1>;
|
|
178
|
+
context?: Record<string, any> | undefined;
|
|
179
|
+
}): Promise<T_1>;
|
|
180
|
+
getPrivateBalance(): Promise<{
|
|
181
|
+
unshielded: Record<string, string>;
|
|
182
|
+
shielded: Record<string, string>;
|
|
183
|
+
dust: {
|
|
184
|
+
balance: string;
|
|
185
|
+
cap: string;
|
|
186
|
+
};
|
|
187
|
+
address: string;
|
|
188
|
+
dustSynced: boolean;
|
|
189
|
+
}>;
|
|
190
|
+
}) & typeof WaasMidnightWalletConnector;
|
|
191
|
+
/**
|
|
192
|
+
* WaaS (Wallet-as-a-Service) connector for Midnight blockchain.
|
|
193
|
+
* Extends the WaaS-specific Midnight base with MPC wallet functionality.
|
|
194
|
+
*/
|
|
195
|
+
export declare class DynamicWaasMidnightConnector extends DynamicWaasMidnightConnector_base implements IDynamicWaasConnector {
|
|
196
|
+
ChainWallet: typeof MidnightWallet;
|
|
197
|
+
name: string;
|
|
198
|
+
overrideKey: string;
|
|
199
|
+
isEmbeddedWallet: boolean;
|
|
200
|
+
logger: Logger;
|
|
201
|
+
activeAccountAddress: string | undefined;
|
|
202
|
+
verifiedCredentials: JwtVerifiedCredential[] | undefined;
|
|
203
|
+
protected walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
204
|
+
constructor(props: DynamicWaasMidnightConnectorProps);
|
|
205
|
+
/**
|
|
206
|
+
* Signs a message with additional context information
|
|
207
|
+
* @param message - The message to sign (string or object with raw property)
|
|
208
|
+
* @param context - Additional context for the message signing
|
|
209
|
+
* @returns The signed message as a string
|
|
210
|
+
* @throws {Error} Method not implemented for Midnight
|
|
211
|
+
*/
|
|
212
|
+
signMessageWithContext({ message, context, }: {
|
|
213
|
+
message: string | {
|
|
214
|
+
raw: string;
|
|
215
|
+
};
|
|
216
|
+
context: SignMessageContext;
|
|
217
|
+
}): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Override setVerifiedCredentials to filter and set Midnight WaaS credentials
|
|
220
|
+
* Filters for credentials with walletName === 'dynamicwaas' and chain === 'midnight'
|
|
221
|
+
*/
|
|
222
|
+
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
223
|
+
/**
|
|
224
|
+
* Override setEnvironmentId to ensure it's set on the logger
|
|
225
|
+
*/
|
|
226
|
+
setEnvironmentId(environmentId: string): void;
|
|
227
|
+
/**
|
|
228
|
+
* Gets the wallet client for a specific account address and sets it as active
|
|
229
|
+
* @param accountAddress - The Midnight account address
|
|
230
|
+
* @returns The WaaS wallet client instance
|
|
231
|
+
*/
|
|
232
|
+
getWalletClientByAddress({ accountAddress, }: {
|
|
233
|
+
accountAddress: string;
|
|
234
|
+
}): Promise<import("@dynamic-labs-wallet/browser-wallet-client").DynamicWalletClient>;
|
|
235
|
+
/**
|
|
236
|
+
* Gets the currently active account address
|
|
237
|
+
* @returns The active account address or undefined if not set
|
|
238
|
+
*/
|
|
239
|
+
getActiveAccountAddress(): Promise<string | undefined>;
|
|
240
|
+
/**
|
|
241
|
+
* Sets the active account address for this connector
|
|
242
|
+
* @param accountAddress - The Midnight account address to set as active
|
|
243
|
+
*/
|
|
244
|
+
private setActiveAccountAddress;
|
|
245
|
+
/**
|
|
246
|
+
* Called when the user selects this wallet in the modal.
|
|
247
|
+
* Sets the active account so getAddress/getNetwork work correctly during network validation.
|
|
248
|
+
*/
|
|
249
|
+
afterWalletSelectHook(walletAddress: string): void;
|
|
250
|
+
/**
|
|
251
|
+
* Requires and returns the signed session ID
|
|
252
|
+
* @returns The signed session ID
|
|
253
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
254
|
+
*/
|
|
255
|
+
private requireSignedSessionId;
|
|
256
|
+
/**
|
|
257
|
+
* Validates that the expected wallet address matches the active wallet
|
|
258
|
+
* Updates the active account address if it doesn't match
|
|
259
|
+
* @param expectedAddress - The expected wallet address to validate
|
|
260
|
+
* @throws {DynamicError} If signed session ID is not available or account is not found
|
|
261
|
+
*/
|
|
262
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* When active account is not set (e.g. primary wallet restored from session),
|
|
265
|
+
* fall back to the first Midnight verified credential so signing and getAddress work.
|
|
266
|
+
*/
|
|
267
|
+
private ensureActiveAccountFromVerifiedCredentials;
|
|
268
|
+
/**
|
|
269
|
+
* Gets the active wallet address
|
|
270
|
+
* Falls back to verified credential address if no active account is set
|
|
271
|
+
* @returns The wallet address or empty string if not found
|
|
272
|
+
*/
|
|
273
|
+
getAddress(): Promise<string>;
|
|
274
|
+
/**
|
|
275
|
+
* Connects to the WaaS wallet client
|
|
276
|
+
*/
|
|
277
|
+
connect(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Disconnects from the wallet (no-op for WaaS)
|
|
280
|
+
*/
|
|
281
|
+
disconnect(): Promise<void>;
|
|
282
|
+
/**
|
|
283
|
+
* Signs a message using the wallet UI utils for user interaction
|
|
284
|
+
* @param message - The message to sign
|
|
285
|
+
* @returns The signed message as a string
|
|
286
|
+
*/
|
|
287
|
+
signMessage(message: string): Promise<string>;
|
|
288
|
+
/**
|
|
289
|
+
* Internal method to sign a message with MFA token
|
|
290
|
+
* @param message - The message to sign
|
|
291
|
+
* @returns The signed message as a string
|
|
292
|
+
* @throws {DynamicError} If active account address is not set
|
|
293
|
+
* @throws {DynamicError} If signed session ID is not available
|
|
294
|
+
*/
|
|
295
|
+
internalSignMessage(message: string): Promise<string>;
|
|
296
|
+
/**
|
|
297
|
+
* Ends the current session and clears the active account address
|
|
298
|
+
*/
|
|
299
|
+
endSession(): Promise<void>;
|
|
300
|
+
/**
|
|
301
|
+
* Signs and finalizes (ZK proves) a Midnight transaction via MPC.
|
|
302
|
+
* Step 2 of the 3-step flow: createTransferTransaction → signTransaction → submitTransaction.
|
|
303
|
+
*
|
|
304
|
+
* @param serializedTransaction - Base64-encoded unsigned UnprovenTransaction
|
|
305
|
+
* @returns Base64-encoded FinalizedTransaction, ready for submitTransaction
|
|
306
|
+
*/
|
|
307
|
+
signTransaction(serializedTransaction: string): Promise<string>;
|
|
308
|
+
/**
|
|
309
|
+
* Creates a UI transaction for the send balance flow
|
|
310
|
+
* @param from - The sender's address
|
|
311
|
+
* @returns A new IUITransaction instance
|
|
312
|
+
*/
|
|
313
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
314
|
+
/**
|
|
315
|
+
* Returns the provider.
|
|
316
|
+
* For WaaS, there is no traditional browser provider.
|
|
317
|
+
*/
|
|
318
|
+
getProvider(): undefined;
|
|
319
|
+
/**
|
|
320
|
+
* Creates a new Midnight wallet account.
|
|
321
|
+
* Midnight wallets automatically create multiple address types:
|
|
322
|
+
* - Primary: unshielded address (for public transfers)
|
|
323
|
+
* - Additional: dust address (for gas/fee management) and shielded address (for private transfers)
|
|
324
|
+
*
|
|
325
|
+
* All address types are derived from a single keygen using different BIP-44 derivation paths.
|
|
326
|
+
*
|
|
327
|
+
* @param thresholdSignatureScheme - The threshold signature scheme (default: 'TWO_OF_TWO')
|
|
328
|
+
* @param password - Optional password for the wallet
|
|
329
|
+
* @returns The created wallet account information with primary (unshielded) address
|
|
330
|
+
*/
|
|
331
|
+
createWalletAccount({ thresholdSignatureScheme, password, }?: {
|
|
332
|
+
thresholdSignatureScheme?: string;
|
|
333
|
+
password?: string;
|
|
334
|
+
}): Promise<{
|
|
335
|
+
chainName: string;
|
|
336
|
+
accountAddress: string;
|
|
337
|
+
publicKeyHex: string;
|
|
338
|
+
rawPublicKey: string | Uint8Array | undefined;
|
|
339
|
+
}>;
|
|
340
|
+
getPrivateBalance(): Promise<{
|
|
341
|
+
unshielded: Record<string, string>;
|
|
342
|
+
shielded: Record<string, string>;
|
|
343
|
+
dust: {
|
|
344
|
+
balance: string;
|
|
345
|
+
cap: string;
|
|
346
|
+
};
|
|
347
|
+
address: string;
|
|
348
|
+
dustSynced: boolean;
|
|
349
|
+
}>;
|
|
350
|
+
/**
|
|
351
|
+
* Exposes the same `ConnectedAPI` surface injected Midnight wallets provide,
|
|
352
|
+
* adapted from WaaS MPC state. This is what lets the shared
|
|
353
|
+
* `MidnightWalletConnector` balance methods (`getShieldedBalances`,
|
|
354
|
+
* `getUnshieldedBalances`, `getDustBalance`) work for WaaS wallets — they all
|
|
355
|
+
* delegate to `getConnectedAPI()`, which throws (returns undefined) by
|
|
356
|
+
* default. Address lookups and transfers stay on the WaaS-specific paths.
|
|
357
|
+
*/
|
|
358
|
+
protected getConnectedAPI(): Promise<ConnectedAPI | undefined>;
|
|
359
|
+
/**
|
|
360
|
+
* Adapts the WaaS MPC `getPrivateBalance()` result to the shape
|
|
361
|
+
* `MidnightWallet.getFormattedBalances()` expects. The base
|
|
362
|
+
* `MidnightWalletConnector.getBalances()` throws unconditionally (it does not
|
|
363
|
+
* route through `getConnectedAPI`), so WaaS still overrides it directly —
|
|
364
|
+
* here in a single `getPrivateBalance()` call.
|
|
365
|
+
*
|
|
366
|
+
* Cap-tolerant: `dust.cap` is 0n on browser-wallet-client <= 1.0.16 and the
|
|
367
|
+
* real cap once the wallet-SDK-v4 change is published (no code change needed).
|
|
368
|
+
*/
|
|
369
|
+
getBalances(): Promise<{
|
|
370
|
+
shielded: Record<TokenType, bigint>;
|
|
371
|
+
unshielded: Record<TokenType, bigint>;
|
|
372
|
+
dust: {
|
|
373
|
+
cap: bigint;
|
|
374
|
+
balance: bigint;
|
|
375
|
+
};
|
|
376
|
+
dustSyncing?: boolean;
|
|
377
|
+
}>;
|
|
378
|
+
registerDust(): Promise<{
|
|
379
|
+
dustBalance: string;
|
|
380
|
+
txId?: string;
|
|
381
|
+
status: 'registered' | 'already_registered' | 'already_has_dust' | 'no_utxos';
|
|
382
|
+
message: string;
|
|
383
|
+
registeredCount: number;
|
|
384
|
+
}>;
|
|
385
|
+
/**
|
|
386
|
+
* One-call transfer: runs the full build → sign (ZK prove) → submit flow and
|
|
387
|
+
* returns the broadcast tx hash. This is what backs `wallet.sendBalance` for
|
|
388
|
+
* embedded Midnight wallets; use the individual steps
|
|
389
|
+
* (`createTransferTransaction` / `signTransaction` / `submitTransaction`) when
|
|
390
|
+
* you need to inspect or persist the transaction between stages.
|
|
391
|
+
*/
|
|
392
|
+
createTransfer(params: {
|
|
393
|
+
transfers: Array<{
|
|
394
|
+
type: 'unshielded' | 'shielded';
|
|
395
|
+
recipientAddress: string;
|
|
396
|
+
amount: string;
|
|
397
|
+
tokenType?: string;
|
|
398
|
+
}>;
|
|
399
|
+
/** Optional TTL in minutes. Defaults to 5. */
|
|
400
|
+
ttlMinutes?: number;
|
|
401
|
+
}): Promise<string>;
|
|
402
|
+
/**
|
|
403
|
+
* Step 1 of the Midnight transfer flow.
|
|
404
|
+
* Builds an unsigned UnprovenTransaction from one or more transfer specs.
|
|
405
|
+
* Accepts any combination of unshielded / shielded transfers in a single tx.
|
|
406
|
+
* No MPC, no proof server, no broadcast.
|
|
407
|
+
*/
|
|
408
|
+
createTransferTransaction(params: {
|
|
409
|
+
transfers: Array<{
|
|
410
|
+
type: 'unshielded' | 'shielded';
|
|
411
|
+
recipientAddress: string;
|
|
412
|
+
amount: string;
|
|
413
|
+
tokenType?: string;
|
|
414
|
+
}>;
|
|
415
|
+
/** Optional TTL in minutes. Defaults to 5. */
|
|
416
|
+
ttlMinutes?: number;
|
|
417
|
+
}): Promise<{
|
|
418
|
+
serializedTransaction: string;
|
|
419
|
+
}>;
|
|
420
|
+
/**
|
|
421
|
+
* Release UTXOs reserved by an abandoned draft or signed-but-never-submitted
|
|
422
|
+
* transaction. Accepts either an unsigned (Step 1 output) or finalized
|
|
423
|
+
* (Step 2 output) serialized transaction.
|
|
424
|
+
*/
|
|
425
|
+
revertTransaction(serializedTransaction: string): Promise<{
|
|
426
|
+
reverted: boolean;
|
|
427
|
+
count: number;
|
|
428
|
+
cacheCleared: boolean;
|
|
429
|
+
message: string;
|
|
430
|
+
}>;
|
|
431
|
+
/**
|
|
432
|
+
* Revert every finalized-but-unsubmitted transaction the SDK knows about
|
|
433
|
+
* (`state.pending.all`). Does not cover unfinalized Step-1-only drafts —
|
|
434
|
+
* those are never registered with the pending-tx service by design. If
|
|
435
|
+
* UTXOs are still stuck after this, use `resetWalletCache()`.
|
|
436
|
+
*/
|
|
437
|
+
revertAllPending(): Promise<{
|
|
438
|
+
reverted: boolean;
|
|
439
|
+
count: number;
|
|
440
|
+
cacheCleared: boolean;
|
|
441
|
+
message: string;
|
|
442
|
+
}>;
|
|
443
|
+
/**
|
|
444
|
+
* Nuclear reset. Stops the cached wallet, clears its persisted IndexedDB
|
|
445
|
+
* entry, and forces the next operation to cold-sync from chain. Midnight's
|
|
446
|
+
* officially recommended workaround when UTXOs get stuck in pending state
|
|
447
|
+
* that can't be reverted through the normal API.
|
|
448
|
+
*/
|
|
449
|
+
resetWalletCache(): Promise<{
|
|
450
|
+
reverted: boolean;
|
|
451
|
+
count: number;
|
|
452
|
+
cacheCleared: boolean;
|
|
453
|
+
message: string;
|
|
454
|
+
}>;
|
|
455
|
+
private callRevertTransaction;
|
|
456
|
+
/**
|
|
457
|
+
* Step 3 of the unshielded public transfer flow.
|
|
458
|
+
* Broadcasts a finalized transaction via the wallet's NodeClient.
|
|
459
|
+
* Optionally waits for the unshielded balance to stabilize.
|
|
460
|
+
*/
|
|
461
|
+
submitTransaction(serializedFinalizedTransaction: string, options?: {
|
|
462
|
+
waitForBalance?: boolean;
|
|
463
|
+
tokenType?: string;
|
|
464
|
+
balanceBefore?: string;
|
|
465
|
+
}): Promise<{
|
|
466
|
+
txHash: string;
|
|
467
|
+
balanceAfter?: string;
|
|
468
|
+
}>;
|
|
469
|
+
}
|
|
470
|
+
export {};
|