@dynamic-labs/midnight 5.0.0 → 5.2.0
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 +28 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/types.d.ts +32 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.cjs +86 -0
- package/src/waas/connector/DynamicWaasMidnightConnector.d.ts +14 -8
- package/src/waas/connector/DynamicWaasMidnightConnector.js +87 -1
- package/src/wallet/MidnightWallet.cjs +10 -0
- package/src/wallet/MidnightWallet.d.ts +3 -0
- package/src/wallet/MidnightWallet.js +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,32 @@
|
|
|
1
1
|
|
|
2
|
+
## [5.2.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.1.0...v5.2.0) (2026-08-06)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **webview-controller:** validate native SDK locale override before applying ([#12155](https://github.com/dynamic-labs/dynamic-auth/issues/12155)) ([4a9e1da](https://github.com/dynamic-labs/dynamic-auth/commit/4a9e1dafb59099c47d3678cc24f8475164c3db59))
|
|
8
|
+
|
|
9
|
+
## [5.1.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.0.0...v5.1.0) (2026-08-04)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **midnight:** expose contract wallet provider ([#12120](https://github.com/dynamic-labs/dynamic-auth/issues/12120)) ([2cecf23](https://github.com/dynamic-labs/dynamic-auth/commit/2cecf23f1f51819b99dfde4afd20264ea1abebf8))
|
|
15
|
+
* **webview-messages,webview-controller:** add waas_backupKeySharesToICloud webview message ([#12147](https://github.com/dynamic-labs/dynamic-auth/issues/12147)) ([ca4edda](https://github.com/dynamic-labs/dynamic-auth/commit/ca4edda54adf0673a9fe41c17d861a739f1b8f2e))
|
|
16
|
+
* **webview:** add business accounts message contract and controller ([#12144](https://github.com/dynamic-labs/dynamic-auth/issues/12144)) ([d9f80c1](https://github.com/dynamic-labs/dynamic-auth/commit/d9f80c10bb3c332c2f3e3dc401b95025b930fa4e))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* bump brace-expansion to latest patched maintenance releases ([#12130](https://github.com/dynamic-labs/dynamic-auth/issues/12130)) ([1b26671](https://github.com/dynamic-labs/dynamic-auth/commit/1b26671ad8e62025904e04f9dfed8b3faafb9c19))
|
|
22
|
+
* **ethereum-aa:** resolve chainId from network for ZeroDev v2 multichain projects ([#12105](https://github.com/dynamic-labs/dynamic-auth/issues/12105)) ([fe2c5d2](https://github.com/dynamic-labs/dynamic-auth/commit/fe2c5d239758ea79e8647006d9d77cc27c2ab647))
|
|
23
|
+
* **midnight:** name the missing RPCs when the wallet client is too old ([#12121](https://github.com/dynamic-labs/dynamic-auth/issues/12121)) ([3a8a77f](https://github.com/dynamic-labs/dynamic-auth/commit/3a8a77f89d368d8634497a5b49ff345b004cdffa))
|
|
24
|
+
* **midnight:** return the submission identifier from the contract provider ([#12122](https://github.com/dynamic-labs/dynamic-auth/issues/12122)) ([8aa5289](https://github.com/dynamic-labs/dynamic-auth/commit/8aa52895fbdf09a3cf481049009a95f03cddda54))
|
|
25
|
+
* remediate high-severity dependency vulnerabilities ([#12149](https://github.com/dynamic-labs/dynamic-auth/issues/12149)) ([14058ee](https://github.com/dynamic-labs/dynamic-auth/commit/14058eeed34351791ad7ab7ac1fa720eb2cf9948))
|
|
26
|
+
* **starknet:** restore Braavos L2 session after lock and unlock ([#12124](https://github.com/dynamic-labs/dynamic-auth/issues/12124)) ([ab3b11b](https://github.com/dynamic-labs/dynamic-auth/commit/ab3b11bd71fbca8d32d4f2badfa49e3b9641eecf))
|
|
27
|
+
* **wallet-book:** add App Store id for Robinhood Wallet iOS install link ([#11877](https://github.com/dynamic-labs/dynamic-auth/issues/11877)) ([ef28619](https://github.com/dynamic-labs/dynamic-auth/commit/ef28619ba4396e01046717ea7ad560870a56c78f))
|
|
28
|
+
* **wallet-book:** add universal deep link for Exodus Solana WalletConnect ([#12123](https://github.com/dynamic-labs/dynamic-auth/issues/12123)) ([cd7223e](https://github.com/dynamic-labs/dynamic-auth/commit/cd7223eb2dc21314f351b96d9a06d795d282c35d))
|
|
29
|
+
|
|
2
30
|
## [5.0.0](https://github.com/dynamic-labs/dynamic-auth/compare/v5.0.0-rc.4...v5.0.0) (2026-07-29)
|
|
3
31
|
|
|
4
32
|
## 🚀 Dynamic SDK v5 is live
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/midnight",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "5.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "5.2.0",
|
|
22
22
|
"@dynamic-labs/sdk-api-core": "0.0.1093",
|
|
23
23
|
"@midnight-ntwrk/dapp-connector-api": "4.0.1",
|
|
24
|
-
"@dynamic-labs/logger": "5.
|
|
25
|
-
"@dynamic-labs/types": "5.
|
|
26
|
-
"@dynamic-labs/utils": "5.
|
|
27
|
-
"@dynamic-labs/waas": "5.
|
|
28
|
-
"@dynamic-labs/wallet-book": "5.
|
|
29
|
-
"@dynamic-labs/wallet-connector-core": "5.
|
|
24
|
+
"@dynamic-labs/logger": "5.2.0",
|
|
25
|
+
"@dynamic-labs/types": "5.2.0",
|
|
26
|
+
"@dynamic-labs/utils": "5.2.0",
|
|
27
|
+
"@dynamic-labs/waas": "5.2.0",
|
|
28
|
+
"@dynamic-labs/wallet-book": "5.2.0",
|
|
29
|
+
"@dynamic-labs/wallet-connector-core": "5.2.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {}
|
|
32
32
|
}
|
package/src/types.d.ts
CHANGED
|
@@ -22,6 +22,38 @@ export type MidnightTransaction = {
|
|
|
22
22
|
circuitCalls: MidnightCircuitCall[];
|
|
23
23
|
fee?: number;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Minimal structural view of a ledger transaction — only what is needed to move
|
|
27
|
+
* one across the embedded-wallet boundary.
|
|
28
|
+
*/
|
|
29
|
+
export type MidnightSerializableTransaction = {
|
|
30
|
+
serialize(): Uint8Array;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* midnight-js compatible wallet and submission provider backed by an embedded
|
|
34
|
+
* wallet. Structurally equivalent to `WalletProvider & MidnightProvider` from
|
|
35
|
+
* `@midnight-ntwrk/midnight-js/types`, declared here rather than imported so
|
|
36
|
+
* this package carries no dependency on the consumer's midnight-js or
|
|
37
|
+
* ledger-v8 version.
|
|
38
|
+
*
|
|
39
|
+
* Transaction objects are deliberately structural so consumers can use their
|
|
40
|
+
* installed midnight-js/ledger version without sharing secret key state.
|
|
41
|
+
* Parameterise with the consumer's own `UnboundTransaction` and
|
|
42
|
+
* `FinalizedTransaction` to get a provider assignable to `MidnightProviders`:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* const walletProvider = await wallet.getWalletProvider<
|
|
46
|
+
* UnboundTransaction,
|
|
47
|
+
* FinalizedTransaction
|
|
48
|
+
* >();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export type MidnightContractWalletProvider<TUnboundTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction, TFinalizedTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction> = {
|
|
52
|
+
balanceTx(tx: TUnboundTransaction, ttl?: Date): Promise<TFinalizedTransaction>;
|
|
53
|
+
getCoinPublicKey(): string;
|
|
54
|
+
getEncryptionPublicKey(): string;
|
|
55
|
+
submitTx(tx: TFinalizedTransaction): Promise<string>;
|
|
56
|
+
};
|
|
25
57
|
/**
|
|
26
58
|
* Minimal interface for the Midnight wallet provider injected into window.
|
|
27
59
|
*
|
|
@@ -163,6 +163,31 @@ class DynamicWaasMidnightConnector extends waas.withDynamicWaas(WaasMidnightWall
|
|
|
163
163
|
midnightNetworkParam() {
|
|
164
164
|
return { networkId: this.getSelectedMidnightNetwork() };
|
|
165
165
|
}
|
|
166
|
+
getWalletProviderRequestParams(accountAddress, networkId) {
|
|
167
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
var _a, _b, _c;
|
|
169
|
+
if (this.activeAccountAddress !== accountAddress) {
|
|
170
|
+
throw new utils.DynamicError('The active Midnight wallet changed after the contract wallet provider was created', 'midnight_wallet_provider_account_changed');
|
|
171
|
+
}
|
|
172
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
173
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
174
|
+
mfaAction: sdkApiCore.MFAAction.WalletWaasSign,
|
|
175
|
+
}));
|
|
176
|
+
const password = yield this.getPasswordIfNeeded({ accountAddress });
|
|
177
|
+
const elevatedAccessToken = yield ((_b = this.getElevatedAccessToken) === null || _b === void 0 ? void 0 : _b.call(this, {
|
|
178
|
+
scope: sdkApiCore.TokenScope.Walletsign,
|
|
179
|
+
}));
|
|
180
|
+
return {
|
|
181
|
+
accountAddress,
|
|
182
|
+
authToken: (_c = this.getAuthToken) === null || _c === void 0 ? void 0 : _c.call(this),
|
|
183
|
+
elevatedAccessToken,
|
|
184
|
+
mfaToken,
|
|
185
|
+
networkId,
|
|
186
|
+
password,
|
|
187
|
+
signedSessionId,
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
}
|
|
166
191
|
/**
|
|
167
192
|
* Gets the active wallet address for the selected network.
|
|
168
193
|
*
|
|
@@ -370,6 +395,67 @@ class DynamicWaasMidnightConnector extends waas.withDynamicWaas(WaasMidnightWall
|
|
|
370
395
|
getProvider() {
|
|
371
396
|
return undefined;
|
|
372
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Returns a midnight-js compatible provider whose wallet-bound operations
|
|
400
|
+
* execute inside the embedded-wallet iframe. Only public keys and serialized
|
|
401
|
+
* transactions cross the iframe boundary.
|
|
402
|
+
*/
|
|
403
|
+
getWalletProvider() {
|
|
404
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
406
|
+
if (!this.activeAccountAddress) {
|
|
407
|
+
throw new utils.DynamicError('Active account address is required', 'active_account_address_is_required');
|
|
408
|
+
}
|
|
409
|
+
const accountAddress = this.activeAccountAddress;
|
|
410
|
+
const networkId = this.getSelectedMidnightNetwork();
|
|
411
|
+
const walletClient = (yield this.getWaasWalletClient());
|
|
412
|
+
// The cast above asserts RPCs that older embedded-wallet clients do not
|
|
413
|
+
// expose. Without this check the caller gets an unattributable
|
|
414
|
+
// "is not a function" TypeError instead of the actual cause.
|
|
415
|
+
const missingRpcs = ['getWalletProvider', 'balanceWalletProviderTransaction'].filter((rpc) => typeof walletClient[rpc] !== 'function');
|
|
416
|
+
if (missingRpcs.length > 0) {
|
|
417
|
+
throw new utils.DynamicError(`The embedded wallet client does not support Midnight contract wallet providers (missing: ${missingRpcs.join(', ')}). Upgrade @dynamic-labs-wallet/browser-wallet-client to a version that exposes these operations.`, 'midnight_wallet_provider_unsupported_client');
|
|
418
|
+
}
|
|
419
|
+
const initParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
420
|
+
const { coinPublicKey, encryptionPublicKey } = yield walletClient.getWalletProvider(initParams);
|
|
421
|
+
return {
|
|
422
|
+
balanceTx: (transaction, ttl) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
423
|
+
const requestParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
424
|
+
const transactionConstructor = transaction.constructor;
|
|
425
|
+
// Reached through `transaction.constructor` so this package never
|
|
426
|
+
// imports ledger-v8 and stays free of the consumer's ledger version.
|
|
427
|
+
// The type constraint only guarantees `serialize()`, so the static is
|
|
428
|
+
// checked rather than assumed — a wrapped or proxied transaction would
|
|
429
|
+
// otherwise fail with a bare "deserialize is not a function". Checked
|
|
430
|
+
// before the balance call below so a wrapper transaction fails
|
|
431
|
+
// side-effect free, rather than after UTXOs are already reserved.
|
|
432
|
+
if (typeof (transactionConstructor === null || transactionConstructor === void 0 ? void 0 : transactionConstructor.deserialize) !== 'function') {
|
|
433
|
+
throw new utils.DynamicError('The transaction passed to balanceTx has no static deserialize; pass a ledger Transaction rather than a wrapper', 'midnight_transaction_not_deserializable');
|
|
434
|
+
}
|
|
435
|
+
const response = yield walletClient.balanceWalletProviderTransaction(Object.assign(Object.assign({}, requestParams), { transaction: utils.uint8ArrayToBase64(transaction.serialize()), ttl: ttl === null || ttl === void 0 ? void 0 : ttl.toISOString() }));
|
|
436
|
+
return transactionConstructor.deserialize('signature', 'proof', 'binding', utils.uint8ArrayFromBase64(response.transaction));
|
|
437
|
+
}),
|
|
438
|
+
getCoinPublicKey: () => coinPublicKey,
|
|
439
|
+
getEncryptionPublicKey: () => encryptionPublicKey,
|
|
440
|
+
submitTx: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
441
|
+
const requestParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
442
|
+
// `txIdentifier` is newer than the published client's type, so it is
|
|
443
|
+
// read through a cast: this compiles against both, and an older client
|
|
444
|
+
// simply degrades to the hash.
|
|
445
|
+
const { txHash, txIdentifier } = (yield walletClient.submitTransaction(Object.assign(Object.assign({}, requestParams), { transaction: utils.uint8ArrayToBase64(transaction.serialize()) })));
|
|
446
|
+
// Balances changed — drop the snapshot so the next send fetches fresh.
|
|
447
|
+
this.clearSendBalanceCache();
|
|
448
|
+
// midnight-js treats this return value as a TransactionId and polls
|
|
449
|
+
// `transactions(offset: { identifier })` to observe inclusion. The
|
|
450
|
+
// canonical hash is a different value and never matches, so returning
|
|
451
|
+
// it leaves callers such as deployContract waiting on a transaction
|
|
452
|
+
// that already succeeded. Prefer the submission identifier; fall back
|
|
453
|
+
// to the hash for older wallet clients that do not return it.
|
|
454
|
+
return txIdentifier !== null && txIdentifier !== void 0 ? txIdentifier : txHash;
|
|
455
|
+
}),
|
|
456
|
+
};
|
|
457
|
+
});
|
|
458
|
+
}
|
|
373
459
|
/**
|
|
374
460
|
* Creates a new Midnight wallet account.
|
|
375
461
|
* Midnight wallets automatically create multiple address types:
|
|
@@ -3,7 +3,7 @@ import { JwtVerifiedCredential, MFAAction, SignMessageContext, TokenScope } from
|
|
|
3
3
|
import { IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
4
4
|
import { IDynamicWaasConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { Logger } from '@dynamic-labs/logger';
|
|
6
|
-
import type { DynamicWaasMidnightConnectorProps } from '../../types';
|
|
6
|
+
import type { DynamicWaasMidnightConnectorProps, MidnightContractWalletProvider, MidnightSerializableTransaction } from '../../types';
|
|
7
7
|
import { MidnightWallet } from '../../wallet/MidnightWallet';
|
|
8
8
|
import { WaasMidnightWalletConnector } from '../WaasMidnightWalletConnector';
|
|
9
9
|
declare const DynamicWaasMidnightConnector_base: (abstract new (...args: any[]) => {
|
|
@@ -108,10 +108,7 @@ declare const DynamicWaasMidnightConnector_base: (abstract new (...args: any[])
|
|
|
108
108
|
expectedAddresses: Record<string, string>;
|
|
109
109
|
coinTypes?: Record<string, number> | undefined;
|
|
110
110
|
password?: string | undefined;
|
|
111
|
-
}): Promise<Record<string, unknown>>;
|
|
112
|
-
* When active account is not set (e.g. primary wallet restored from session),
|
|
113
|
-
* fall back to the first Midnight verified credential so signing and getAddress work.
|
|
114
|
-
*/
|
|
111
|
+
}): Promise<Record<string, unknown>>;
|
|
115
112
|
exportPrivateKey({ accountAddress, displayContainer, password, }?: {
|
|
116
113
|
accountAddress?: string | undefined;
|
|
117
114
|
displayContainer?: HTMLIFrameElement | undefined;
|
|
@@ -122,6 +119,10 @@ declare const DynamicWaasMidnightConnector_base: (abstract new (...args: any[])
|
|
|
122
119
|
};
|
|
123
120
|
exportClientKeyshares({ accountAddress, password, }: {
|
|
124
121
|
accountAddress: string;
|
|
122
|
+
/**
|
|
123
|
+
* When active account is not set (e.g. primary wallet restored from session),
|
|
124
|
+
* fall back to the first Midnight verified credential so signing and getAddress work.
|
|
125
|
+
*/
|
|
125
126
|
password?: string | undefined;
|
|
126
127
|
}): Promise<void>;
|
|
127
128
|
runBackupLifecycle({ provider, accountAddress, password, performBackup, }: {
|
|
@@ -158,9 +159,7 @@ declare const DynamicWaasMidnightConnector_base: (abstract new (...args: any[])
|
|
|
158
159
|
hideICloudSignIn(): Promise<void>;
|
|
159
160
|
isICloudAuthenticated(): Promise<boolean>;
|
|
160
161
|
refreshWalletAccountShares({ accountAddress, password, }: {
|
|
161
|
-
accountAddress: string;
|
|
162
|
-
* Connects to the WaaS wallet client
|
|
163
|
-
*/
|
|
162
|
+
accountAddress: string;
|
|
164
163
|
password?: string | undefined;
|
|
165
164
|
}): Promise<void>;
|
|
166
165
|
reshareWalletAccountShares({ accountAddress, thresholdSignatureScheme, password, }: {
|
|
@@ -317,6 +316,7 @@ export declare class DynamicWaasMidnightConnector extends DynamicWaasMidnightCon
|
|
|
317
316
|
* the field and default to preview.
|
|
318
317
|
*/
|
|
319
318
|
private midnightNetworkParam;
|
|
319
|
+
private getWalletProviderRequestParams;
|
|
320
320
|
/**
|
|
321
321
|
* Gets the active wallet address for the selected network.
|
|
322
322
|
*
|
|
@@ -378,6 +378,12 @@ export declare class DynamicWaasMidnightConnector extends DynamicWaasMidnightCon
|
|
|
378
378
|
* For WaaS, there is no traditional browser provider.
|
|
379
379
|
*/
|
|
380
380
|
getProvider(): undefined;
|
|
381
|
+
/**
|
|
382
|
+
* Returns a midnight-js compatible provider whose wallet-bound operations
|
|
383
|
+
* execute inside the embedded-wallet iframe. Only public keys and serialized
|
|
384
|
+
* transactions cross the iframe boundary.
|
|
385
|
+
*/
|
|
386
|
+
getWalletProvider<TUnboundTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction, TFinalizedTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction>(): Promise<MidnightContractWalletProvider<TUnboundTransaction, TFinalizedTransaction>>;
|
|
381
387
|
/**
|
|
382
388
|
* Creates a new Midnight wallet account.
|
|
383
389
|
* Midnight wallets automatically create multiple address types:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
3
|
import { MFAAction, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
4
|
-
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
import { DynamicError, uint8ArrayToBase64, uint8ArrayFromBase64 } from '@dynamic-labs/utils';
|
|
5
5
|
import { withDynamicWaas } from '@dynamic-labs/waas';
|
|
6
6
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
7
7
|
import { Logger } from '@dynamic-labs/logger';
|
|
@@ -159,6 +159,31 @@ class DynamicWaasMidnightConnector extends withDynamicWaas(WaasMidnightWalletCon
|
|
|
159
159
|
midnightNetworkParam() {
|
|
160
160
|
return { networkId: this.getSelectedMidnightNetwork() };
|
|
161
161
|
}
|
|
162
|
+
getWalletProviderRequestParams(accountAddress, networkId) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
var _a, _b, _c;
|
|
165
|
+
if (this.activeAccountAddress !== accountAddress) {
|
|
166
|
+
throw new DynamicError('The active Midnight wallet changed after the contract wallet provider was created', 'midnight_wallet_provider_account_changed');
|
|
167
|
+
}
|
|
168
|
+
const signedSessionId = yield this.requireSignedSessionId();
|
|
169
|
+
const mfaToken = yield ((_a = this.getMfaToken) === null || _a === void 0 ? void 0 : _a.call(this, {
|
|
170
|
+
mfaAction: MFAAction.WalletWaasSign,
|
|
171
|
+
}));
|
|
172
|
+
const password = yield this.getPasswordIfNeeded({ accountAddress });
|
|
173
|
+
const elevatedAccessToken = yield ((_b = this.getElevatedAccessToken) === null || _b === void 0 ? void 0 : _b.call(this, {
|
|
174
|
+
scope: TokenScope.Walletsign,
|
|
175
|
+
}));
|
|
176
|
+
return {
|
|
177
|
+
accountAddress,
|
|
178
|
+
authToken: (_c = this.getAuthToken) === null || _c === void 0 ? void 0 : _c.call(this),
|
|
179
|
+
elevatedAccessToken,
|
|
180
|
+
mfaToken,
|
|
181
|
+
networkId,
|
|
182
|
+
password,
|
|
183
|
+
signedSessionId,
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
162
187
|
/**
|
|
163
188
|
* Gets the active wallet address for the selected network.
|
|
164
189
|
*
|
|
@@ -366,6 +391,67 @@ class DynamicWaasMidnightConnector extends withDynamicWaas(WaasMidnightWalletCon
|
|
|
366
391
|
getProvider() {
|
|
367
392
|
return undefined;
|
|
368
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Returns a midnight-js compatible provider whose wallet-bound operations
|
|
396
|
+
* execute inside the embedded-wallet iframe. Only public keys and serialized
|
|
397
|
+
* transactions cross the iframe boundary.
|
|
398
|
+
*/
|
|
399
|
+
getWalletProvider() {
|
|
400
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
this.ensureActiveAccountFromVerifiedCredentials();
|
|
402
|
+
if (!this.activeAccountAddress) {
|
|
403
|
+
throw new DynamicError('Active account address is required', 'active_account_address_is_required');
|
|
404
|
+
}
|
|
405
|
+
const accountAddress = this.activeAccountAddress;
|
|
406
|
+
const networkId = this.getSelectedMidnightNetwork();
|
|
407
|
+
const walletClient = (yield this.getWaasWalletClient());
|
|
408
|
+
// The cast above asserts RPCs that older embedded-wallet clients do not
|
|
409
|
+
// expose. Without this check the caller gets an unattributable
|
|
410
|
+
// "is not a function" TypeError instead of the actual cause.
|
|
411
|
+
const missingRpcs = ['getWalletProvider', 'balanceWalletProviderTransaction'].filter((rpc) => typeof walletClient[rpc] !== 'function');
|
|
412
|
+
if (missingRpcs.length > 0) {
|
|
413
|
+
throw new DynamicError(`The embedded wallet client does not support Midnight contract wallet providers (missing: ${missingRpcs.join(', ')}). Upgrade @dynamic-labs-wallet/browser-wallet-client to a version that exposes these operations.`, 'midnight_wallet_provider_unsupported_client');
|
|
414
|
+
}
|
|
415
|
+
const initParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
416
|
+
const { coinPublicKey, encryptionPublicKey } = yield walletClient.getWalletProvider(initParams);
|
|
417
|
+
return {
|
|
418
|
+
balanceTx: (transaction, ttl) => __awaiter(this, void 0, void 0, function* () {
|
|
419
|
+
const requestParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
420
|
+
const transactionConstructor = transaction.constructor;
|
|
421
|
+
// Reached through `transaction.constructor` so this package never
|
|
422
|
+
// imports ledger-v8 and stays free of the consumer's ledger version.
|
|
423
|
+
// The type constraint only guarantees `serialize()`, so the static is
|
|
424
|
+
// checked rather than assumed — a wrapped or proxied transaction would
|
|
425
|
+
// otherwise fail with a bare "deserialize is not a function". Checked
|
|
426
|
+
// before the balance call below so a wrapper transaction fails
|
|
427
|
+
// side-effect free, rather than after UTXOs are already reserved.
|
|
428
|
+
if (typeof (transactionConstructor === null || transactionConstructor === void 0 ? void 0 : transactionConstructor.deserialize) !== 'function') {
|
|
429
|
+
throw new DynamicError('The transaction passed to balanceTx has no static deserialize; pass a ledger Transaction rather than a wrapper', 'midnight_transaction_not_deserializable');
|
|
430
|
+
}
|
|
431
|
+
const response = yield walletClient.balanceWalletProviderTransaction(Object.assign(Object.assign({}, requestParams), { transaction: uint8ArrayToBase64(transaction.serialize()), ttl: ttl === null || ttl === void 0 ? void 0 : ttl.toISOString() }));
|
|
432
|
+
return transactionConstructor.deserialize('signature', 'proof', 'binding', uint8ArrayFromBase64(response.transaction));
|
|
433
|
+
}),
|
|
434
|
+
getCoinPublicKey: () => coinPublicKey,
|
|
435
|
+
getEncryptionPublicKey: () => encryptionPublicKey,
|
|
436
|
+
submitTx: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
437
|
+
const requestParams = yield this.getWalletProviderRequestParams(accountAddress, networkId);
|
|
438
|
+
// `txIdentifier` is newer than the published client's type, so it is
|
|
439
|
+
// read through a cast: this compiles against both, and an older client
|
|
440
|
+
// simply degrades to the hash.
|
|
441
|
+
const { txHash, txIdentifier } = (yield walletClient.submitTransaction(Object.assign(Object.assign({}, requestParams), { transaction: uint8ArrayToBase64(transaction.serialize()) })));
|
|
442
|
+
// Balances changed — drop the snapshot so the next send fetches fresh.
|
|
443
|
+
this.clearSendBalanceCache();
|
|
444
|
+
// midnight-js treats this return value as a TransactionId and polls
|
|
445
|
+
// `transactions(offset: { identifier })` to observe inclusion. The
|
|
446
|
+
// canonical hash is a different value and never matches, so returning
|
|
447
|
+
// it leaves callers such as deployContract waiting on a transaction
|
|
448
|
+
// that already succeeded. Prefer the submission identifier; fall back
|
|
449
|
+
// to the hash for older wallet clients that do not return it.
|
|
450
|
+
return txIdentifier !== null && txIdentifier !== void 0 ? txIdentifier : txHash;
|
|
451
|
+
}),
|
|
452
|
+
};
|
|
453
|
+
});
|
|
454
|
+
}
|
|
369
455
|
/**
|
|
370
456
|
* Creates a new Midnight wallet account.
|
|
371
457
|
* Midnight wallets automatically create multiple address types:
|
|
@@ -89,6 +89,16 @@ class MidnightWallet extends walletConnectorCore.Wallet {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
// Exclusive for embedded Midnight wallets
|
|
92
|
+
/** Creates a midnight-js provider backed by the embedded-wallet iframe. */
|
|
93
|
+
getWalletProvider() {
|
|
94
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const connector = this._connector;
|
|
96
|
+
if (!connector.getWalletProvider) {
|
|
97
|
+
throw new Error('Contract wallet providers are only supported for embedded Midnight wallets');
|
|
98
|
+
}
|
|
99
|
+
return connector.getWalletProvider();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
92
102
|
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
93
103
|
createTransferTransaction(...args) {
|
|
94
104
|
return this._connector.createTransferTransaction(...args);
|
|
@@ -2,6 +2,7 @@ import { TokenType } from '@midnight-ntwrk/dapp-connector-api';
|
|
|
2
2
|
import { type MidnightFormattedBalances, Wallet } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { WalletAddressType } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { MidnightWalletConnector } from '../connectors/MidnightWalletConnector';
|
|
5
|
+
import type { MidnightContractWalletProvider, MidnightSerializableTransaction } from '../types';
|
|
5
6
|
export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
6
7
|
sendBalance({ amount, toAddress, token, }: {
|
|
7
8
|
amount: string;
|
|
@@ -29,6 +30,8 @@ export declare class MidnightWallet extends Wallet<MidnightWalletConnector> {
|
|
|
29
30
|
cap: string;
|
|
30
31
|
}>;
|
|
31
32
|
getFormattedBalances(): Promise<MidnightFormattedBalances>;
|
|
33
|
+
/** Creates a midnight-js provider backed by the embedded-wallet iframe. */
|
|
34
|
+
getWalletProvider<TUnboundTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction, TFinalizedTransaction extends MidnightSerializableTransaction = MidnightSerializableTransaction>(): Promise<MidnightContractWalletProvider<TUnboundTransaction, TFinalizedTransaction>>;
|
|
32
35
|
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
33
36
|
createTransferTransaction(...args: Parameters<MidnightWalletConnector['createTransferTransaction']>): ReturnType<MidnightWalletConnector['createTransferTransaction']>;
|
|
34
37
|
/** Signs and ZK-proves an unsigned transaction via MPC (step 2). */
|
|
@@ -85,6 +85,16 @@ class MidnightWallet extends Wallet {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
// Exclusive for embedded Midnight wallets
|
|
88
|
+
/** Creates a midnight-js provider backed by the embedded-wallet iframe. */
|
|
89
|
+
getWalletProvider() {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const connector = this._connector;
|
|
92
|
+
if (!connector.getWalletProvider) {
|
|
93
|
+
throw new Error('Contract wallet providers are only supported for embedded Midnight wallets');
|
|
94
|
+
}
|
|
95
|
+
return connector.getWalletProvider();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
88
98
|
/** Builds an unsigned transaction from one or more transfer specs (step 1). */
|
|
89
99
|
createTransferTransaction(...args) {
|
|
90
100
|
return this._connector.createTransferTransaction(...args);
|