@dynamic-labs-sdk/solana 1.17.1 → 1.19.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/dist/addSolanaExtension/addSolanaExtension.d.ts +10 -1
- package/dist/addSolanaExtension/addSolanaExtension.d.ts.map +1 -1
- package/dist/{addSolanaWalletStandardExtension-D_WVyVEx.esm.js → addSolanaWalletStandardExtension-CbR1BbPB.esm.js} +3 -3
- package/dist/{addSolanaWalletStandardExtension-D_WVyVEx.esm.js.map → addSolanaWalletStandardExtension-CbR1BbPB.esm.js.map} +1 -1
- package/dist/{addSolanaWalletStandardExtension-Dtf-b3fq.cjs → addSolanaWalletStandardExtension-CyYa03dG.cjs} +3 -3
- package/dist/{addSolanaWalletStandardExtension-Dtf-b3fq.cjs.map → addSolanaWalletStandardExtension-CyYa03dG.cjs.map} +1 -1
- package/dist/{addWaasSolanaExtension-BwdvB_-W.esm.js → addWaasSolanaExtension-DVuz2ISz.esm.js} +2 -2
- package/dist/{addWaasSolanaExtension-BwdvB_-W.esm.js.map → addWaasSolanaExtension-DVuz2ISz.esm.js.map} +1 -1
- package/dist/{addWaasSolanaExtension-av0ucGCH.cjs → addWaasSolanaExtension-wH_cvxuL.cjs} +2 -2
- package/dist/{addWaasSolanaExtension-av0ucGCH.cjs.map → addWaasSolanaExtension-wH_cvxuL.cjs.map} +1 -1
- package/dist/{createWalletProviderFromSolanaStandardWallet-Dtio4xHn.esm.js → createWalletProviderFromSolanaStandardWallet-B7jh3I6k.esm.js} +2 -2
- package/dist/{createWalletProviderFromSolanaStandardWallet-Dtio4xHn.esm.js.map → createWalletProviderFromSolanaStandardWallet-B7jh3I6k.esm.js.map} +1 -1
- package/dist/{createWalletProviderFromSolanaStandardWallet-CN-opURQ.cjs → createWalletProviderFromSolanaStandardWallet-Bt5TP7Lt.cjs} +2 -2
- package/dist/{createWalletProviderFromSolanaStandardWallet-CN-opURQ.cjs.map → createWalletProviderFromSolanaStandardWallet-Bt5TP7Lt.cjs.map} +1 -1
- package/dist/getSolanaConnection/getSolanaConnection.d.ts +7 -1
- package/dist/getSolanaConnection/getSolanaConnection.d.ts.map +1 -1
- package/dist/index.cjs +466 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +466 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/isSolanaGasSponsorshipEnabled/isSolanaGasSponsorshipEnabled.d.ts +10 -1
- package/dist/isSolanaGasSponsorshipEnabled/isSolanaGasSponsorshipEnabled.d.ts.map +1 -1
- package/dist/isSolanaNetworkProvider/isSolanaNetworkProvider.d.ts +10 -1
- package/dist/isSolanaNetworkProvider/isSolanaNetworkProvider.d.ts.map +1 -1
- package/dist/isSolanaWalletAccount/isSolanaWalletAccount.d.ts +9 -1
- package/dist/isSolanaWalletAccount/isSolanaWalletAccount.d.ts.map +1 -1
- package/dist/metamask.cjs +2 -2
- package/dist/metamask.esm.js +2 -2
- package/dist/phantomRedirect/addPhantomRedirectSolanaExtension/addPhantomRedirectSolanaExtension.d.ts +11 -0
- package/dist/phantomRedirect/addPhantomRedirectSolanaExtension/addPhantomRedirectSolanaExtension.d.ts.map +1 -1
- package/dist/phantomRedirect/completePhantomRedirect/completePhantomRedirect.d.ts +14 -0
- package/dist/phantomRedirect/completePhantomRedirect/completePhantomRedirect.d.ts.map +1 -1
- package/dist/phantomRedirect/detectPhantomRedirect/detectPhantomRedirect.d.ts +9 -1
- package/dist/phantomRedirect/detectPhantomRedirect/detectPhantomRedirect.d.ts.map +1 -1
- package/dist/phantomRedirect/errors/PhantomInvalidEncryptionPublicKeyError.d.ts +5 -0
- package/dist/phantomRedirect/errors/PhantomInvalidEncryptionPublicKeyError.d.ts.map +1 -0
- package/dist/phantomRedirect/utils/crypto/createNaClSharedSecret/createNaClSharedSecret.d.ts +6 -1
- package/dist/phantomRedirect/utils/crypto/createNaClSharedSecret/createNaClSharedSecret.d.ts.map +1 -1
- package/dist/signAllTransactions/signAllTransactions.d.ts +17 -5
- package/dist/signAllTransactions/signAllTransactions.d.ts.map +1 -1
- package/dist/signAndSendSponsoredTransaction/signAndSendSponsoredTransaction.d.ts +16 -6
- package/dist/signAndSendSponsoredTransaction/signAndSendSponsoredTransaction.d.ts.map +1 -1
- package/dist/signAndSendTransaction/signAndSendTransaction.d.ts +15 -3
- package/dist/signAndSendTransaction/signAndSendTransaction.d.ts.map +1 -1
- package/dist/signTransaction/signTransaction.d.ts +17 -5
- package/dist/signTransaction/signTransaction.d.ts.map +1 -1
- package/dist/simulateSolanaTransaction/simulateSolanaTransaction.d.ts +3 -1
- package/dist/simulateSolanaTransaction/simulateSolanaTransaction.d.ts.map +1 -1
- package/dist/{solanaTransferAmount-CgovN61n.cjs → solanaTransferAmount-B4keau5s.cjs} +40 -5
- package/dist/solanaTransferAmount-B4keau5s.cjs.map +1 -0
- package/dist/{solanaTransferAmount-BSu_bMZ6.esm.js → solanaTransferAmount-CdkPbAES.esm.js} +40 -5
- package/dist/solanaTransferAmount-CdkPbAES.esm.js.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/calculateSolanaTransactionFee/calculateSolanaTransactionFee.d.ts +12 -1
- package/dist/utils/calculateSolanaTransactionFee/calculateSolanaTransactionFee.d.ts.map +1 -1
- package/dist/waas.cjs +2 -2
- package/dist/waas.esm.js +2 -2
- package/dist/walletConnect.cjs +1 -1
- package/dist/walletConnect.esm.js +1 -1
- package/dist/walletStandard.cjs +3 -3
- package/dist/walletStandard.esm.js +3 -3
- package/package.json +6 -6
- package/dist/solanaTransferAmount-BSu_bMZ6.esm.js.map +0 -1
- package/dist/solanaTransferAmount-CgovN61n.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
|
2
|
-
const require_solanaTransferAmount = require('./solanaTransferAmount-
|
|
2
|
+
const require_solanaTransferAmount = require('./solanaTransferAmount-B4keau5s.cjs');
|
|
3
3
|
const require_assertBufferAvailable = require('./assertBufferAvailable-BPIt9Mmr.cjs');
|
|
4
|
-
const require_addWaasSolanaExtension = require('./addWaasSolanaExtension-
|
|
5
|
-
require('./createWalletProviderFromSolanaStandardWallet-
|
|
6
|
-
const require_addSolanaWalletStandardExtension = require('./addSolanaWalletStandardExtension-
|
|
4
|
+
const require_addWaasSolanaExtension = require('./addWaasSolanaExtension-wH_cvxuL.cjs');
|
|
5
|
+
require('./createWalletProviderFromSolanaStandardWallet-Bt5TP7Lt.cjs');
|
|
6
|
+
const require_addSolanaWalletStandardExtension = require('./addSolanaWalletStandardExtension-CyYa03dG.cjs');
|
|
7
7
|
let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
|
|
8
8
|
let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
|
|
9
9
|
let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
|
|
@@ -24,7 +24,16 @@ tweetnacl = require_chunk.__toESM(tweetnacl);
|
|
|
24
24
|
* and the Dynamic WaaS Solana extension, enabling support for all Solana wallet types
|
|
25
25
|
* including standard wallets and embedded wallets managed by Dynamic's infrastructure.
|
|
26
26
|
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const client = createDynamicClient({ environmentId: 'env-123' });
|
|
30
|
+
* addSolanaExtension(client);
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
27
33
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
34
|
+
* @returns void
|
|
35
|
+
* @see isSolanaWalletAccount
|
|
36
|
+
* @see isSolanaNetworkProvider
|
|
28
37
|
* @notInstrumented
|
|
29
38
|
*/
|
|
30
39
|
const addSolanaExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
@@ -38,8 +47,17 @@ const addSolanaExtension = (client = (0, _dynamic_labs_sdk_client_core.getDefaul
|
|
|
38
47
|
/**
|
|
39
48
|
* Type guard function to check if a network provider is a Solana network provider.
|
|
40
49
|
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* if (isSolanaNetworkProvider(networkProvider)) {
|
|
53
|
+
* const connection = getSolanaConnection({ networkData });
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
41
57
|
* @param networkProvider - The network provider to check.
|
|
42
58
|
* @returns True if the network provider is a Solana network provider, false otherwise.
|
|
59
|
+
* @see isSolanaWalletAccount
|
|
60
|
+
* @see addSolanaExtension
|
|
43
61
|
* @notInstrumented
|
|
44
62
|
*/
|
|
45
63
|
const isSolanaNetworkProvider = (networkProvider) => networkProvider.chain === "SOL";
|
|
@@ -58,11 +76,22 @@ const sleep = (ms) => new Promise((resolve) => {
|
|
|
58
76
|
* and querying the network. It handles both legacy Transaction and VersionedTransaction
|
|
59
77
|
* formats and includes retry logic for network requests.
|
|
60
78
|
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const feeData = await calculateSolanaTransactionFee({
|
|
82
|
+
* transaction,
|
|
83
|
+
* networkData,
|
|
84
|
+
* nativeTokenPriceUsd: 150,
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
61
88
|
* @param params.transaction - The Solana transaction to estimate fees for.
|
|
62
89
|
* @param params.networkData - Network configuration for RPC connection.
|
|
63
90
|
* @param params.nativeTokenPriceUsd - Optional USD price of SOL for fee conversion.
|
|
64
91
|
* @returns Fee data in lamports and human-readable SOL format.
|
|
65
92
|
* @throws {FeeEstimationFailedError} If fee retrieval fails after retries.
|
|
93
|
+
* @see simulateSolanaTransaction
|
|
94
|
+
* @see getSolanaConnection
|
|
66
95
|
* @notInstrumented
|
|
67
96
|
*/
|
|
68
97
|
const calculateSolanaTransactionFee = async ({ transaction, networkData, nativeTokenPriceUsd }) => {
|
|
@@ -141,6 +170,8 @@ const calculateSolanaTransactionFee = async ({ transaction, networkData, nativeT
|
|
|
141
170
|
* @throws {InvalidParamError} If wallet account is not a Solana account.
|
|
142
171
|
* @throws {SimulationFailedError} If the simulation API call fails.
|
|
143
172
|
* @throws {FeeEstimationFailedError} If includeFees is true and fee calculation fails.
|
|
173
|
+
* @see calculateSolanaTransactionFee
|
|
174
|
+
* @see isSolanaWalletAccount
|
|
144
175
|
* @notInstrumented
|
|
145
176
|
*/
|
|
146
177
|
const simulateSolanaTransaction = async ({ walletAccount, transaction, includeFees = false }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
|
@@ -335,18 +366,368 @@ const broadcastPhantomEvent = ({ args, event }, client) => {
|
|
|
335
366
|
});
|
|
336
367
|
};
|
|
337
368
|
|
|
369
|
+
//#endregion
|
|
370
|
+
//#region src/phantomRedirect/errors/PhantomInvalidEncryptionPublicKeyError.ts
|
|
371
|
+
var PhantomInvalidEncryptionPublicKeyError = class extends _dynamic_labs_sdk_client.BaseError {
|
|
372
|
+
constructor() {
|
|
373
|
+
super({
|
|
374
|
+
cause: null,
|
|
375
|
+
code: "phantom_invalid_encryption_public_key_error",
|
|
376
|
+
docsUrl: null,
|
|
377
|
+
name: "PhantomInvalidEncryptionPublicKeyError",
|
|
378
|
+
shortMessage: "Invalid Phantom encryption public key (low-order point rejected)."
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
338
383
|
//#endregion
|
|
339
384
|
//#region src/phantomRedirect/utils/crypto/createNaClSharedSecret/createNaClSharedSecret.ts
|
|
340
385
|
/**
|
|
386
|
+
* The length, in bytes, of a Curve25519 public key.
|
|
387
|
+
*/
|
|
388
|
+
const CURVE25519_PUBLIC_KEY_LENGTH = 32;
|
|
389
|
+
/**
|
|
390
|
+
* The complete set of known Curve25519 low-order point encodings.
|
|
391
|
+
*
|
|
392
|
+
* A malicious Phantom redirect can supply one of these as
|
|
393
|
+
* `phantom_encryption_public_key`. X25519 with a low-order base point produces
|
|
394
|
+
* a small, universally-known shared secret (independent of our secret key),
|
|
395
|
+
* letting an attacker decrypt/forge the connect response and overwrite the
|
|
396
|
+
* connected wallet address. We reject them before deriving the box secret.
|
|
397
|
+
*
|
|
398
|
+
* Source: RFC 7748 / the canonical list of the 8 Curve25519 low-order points.
|
|
399
|
+
*/
|
|
400
|
+
const CURVE25519_LOW_ORDER_POINTS = [
|
|
401
|
+
new Uint8Array([
|
|
402
|
+
0,
|
|
403
|
+
0,
|
|
404
|
+
0,
|
|
405
|
+
0,
|
|
406
|
+
0,
|
|
407
|
+
0,
|
|
408
|
+
0,
|
|
409
|
+
0,
|
|
410
|
+
0,
|
|
411
|
+
0,
|
|
412
|
+
0,
|
|
413
|
+
0,
|
|
414
|
+
0,
|
|
415
|
+
0,
|
|
416
|
+
0,
|
|
417
|
+
0,
|
|
418
|
+
0,
|
|
419
|
+
0,
|
|
420
|
+
0,
|
|
421
|
+
0,
|
|
422
|
+
0,
|
|
423
|
+
0,
|
|
424
|
+
0,
|
|
425
|
+
0,
|
|
426
|
+
0,
|
|
427
|
+
0,
|
|
428
|
+
0,
|
|
429
|
+
0,
|
|
430
|
+
0,
|
|
431
|
+
0,
|
|
432
|
+
0,
|
|
433
|
+
0
|
|
434
|
+
]),
|
|
435
|
+
new Uint8Array([
|
|
436
|
+
1,
|
|
437
|
+
0,
|
|
438
|
+
0,
|
|
439
|
+
0,
|
|
440
|
+
0,
|
|
441
|
+
0,
|
|
442
|
+
0,
|
|
443
|
+
0,
|
|
444
|
+
0,
|
|
445
|
+
0,
|
|
446
|
+
0,
|
|
447
|
+
0,
|
|
448
|
+
0,
|
|
449
|
+
0,
|
|
450
|
+
0,
|
|
451
|
+
0,
|
|
452
|
+
0,
|
|
453
|
+
0,
|
|
454
|
+
0,
|
|
455
|
+
0,
|
|
456
|
+
0,
|
|
457
|
+
0,
|
|
458
|
+
0,
|
|
459
|
+
0,
|
|
460
|
+
0,
|
|
461
|
+
0,
|
|
462
|
+
0,
|
|
463
|
+
0,
|
|
464
|
+
0,
|
|
465
|
+
0,
|
|
466
|
+
0,
|
|
467
|
+
0
|
|
468
|
+
]),
|
|
469
|
+
new Uint8Array([
|
|
470
|
+
224,
|
|
471
|
+
235,
|
|
472
|
+
122,
|
|
473
|
+
124,
|
|
474
|
+
59,
|
|
475
|
+
65,
|
|
476
|
+
184,
|
|
477
|
+
174,
|
|
478
|
+
22,
|
|
479
|
+
86,
|
|
480
|
+
227,
|
|
481
|
+
250,
|
|
482
|
+
241,
|
|
483
|
+
159,
|
|
484
|
+
196,
|
|
485
|
+
106,
|
|
486
|
+
218,
|
|
487
|
+
9,
|
|
488
|
+
141,
|
|
489
|
+
235,
|
|
490
|
+
156,
|
|
491
|
+
50,
|
|
492
|
+
177,
|
|
493
|
+
253,
|
|
494
|
+
134,
|
|
495
|
+
98,
|
|
496
|
+
5,
|
|
497
|
+
22,
|
|
498
|
+
95,
|
|
499
|
+
73,
|
|
500
|
+
184,
|
|
501
|
+
0
|
|
502
|
+
]),
|
|
503
|
+
new Uint8Array([
|
|
504
|
+
95,
|
|
505
|
+
156,
|
|
506
|
+
149,
|
|
507
|
+
188,
|
|
508
|
+
163,
|
|
509
|
+
80,
|
|
510
|
+
140,
|
|
511
|
+
36,
|
|
512
|
+
177,
|
|
513
|
+
208,
|
|
514
|
+
177,
|
|
515
|
+
85,
|
|
516
|
+
156,
|
|
517
|
+
131,
|
|
518
|
+
239,
|
|
519
|
+
91,
|
|
520
|
+
4,
|
|
521
|
+
68,
|
|
522
|
+
92,
|
|
523
|
+
196,
|
|
524
|
+
88,
|
|
525
|
+
28,
|
|
526
|
+
142,
|
|
527
|
+
134,
|
|
528
|
+
216,
|
|
529
|
+
34,
|
|
530
|
+
78,
|
|
531
|
+
221,
|
|
532
|
+
208,
|
|
533
|
+
159,
|
|
534
|
+
17,
|
|
535
|
+
87
|
|
536
|
+
]),
|
|
537
|
+
new Uint8Array([
|
|
538
|
+
236,
|
|
539
|
+
255,
|
|
540
|
+
255,
|
|
541
|
+
255,
|
|
542
|
+
255,
|
|
543
|
+
255,
|
|
544
|
+
255,
|
|
545
|
+
255,
|
|
546
|
+
255,
|
|
547
|
+
255,
|
|
548
|
+
255,
|
|
549
|
+
255,
|
|
550
|
+
255,
|
|
551
|
+
255,
|
|
552
|
+
255,
|
|
553
|
+
255,
|
|
554
|
+
255,
|
|
555
|
+
255,
|
|
556
|
+
255,
|
|
557
|
+
255,
|
|
558
|
+
255,
|
|
559
|
+
255,
|
|
560
|
+
255,
|
|
561
|
+
255,
|
|
562
|
+
255,
|
|
563
|
+
255,
|
|
564
|
+
255,
|
|
565
|
+
255,
|
|
566
|
+
255,
|
|
567
|
+
255,
|
|
568
|
+
255,
|
|
569
|
+
127
|
|
570
|
+
]),
|
|
571
|
+
new Uint8Array([
|
|
572
|
+
237,
|
|
573
|
+
255,
|
|
574
|
+
255,
|
|
575
|
+
255,
|
|
576
|
+
255,
|
|
577
|
+
255,
|
|
578
|
+
255,
|
|
579
|
+
255,
|
|
580
|
+
255,
|
|
581
|
+
255,
|
|
582
|
+
255,
|
|
583
|
+
255,
|
|
584
|
+
255,
|
|
585
|
+
255,
|
|
586
|
+
255,
|
|
587
|
+
255,
|
|
588
|
+
255,
|
|
589
|
+
255,
|
|
590
|
+
255,
|
|
591
|
+
255,
|
|
592
|
+
255,
|
|
593
|
+
255,
|
|
594
|
+
255,
|
|
595
|
+
255,
|
|
596
|
+
255,
|
|
597
|
+
255,
|
|
598
|
+
255,
|
|
599
|
+
255,
|
|
600
|
+
255,
|
|
601
|
+
255,
|
|
602
|
+
255,
|
|
603
|
+
127
|
|
604
|
+
]),
|
|
605
|
+
new Uint8Array([
|
|
606
|
+
238,
|
|
607
|
+
255,
|
|
608
|
+
255,
|
|
609
|
+
255,
|
|
610
|
+
255,
|
|
611
|
+
255,
|
|
612
|
+
255,
|
|
613
|
+
255,
|
|
614
|
+
255,
|
|
615
|
+
255,
|
|
616
|
+
255,
|
|
617
|
+
255,
|
|
618
|
+
255,
|
|
619
|
+
255,
|
|
620
|
+
255,
|
|
621
|
+
255,
|
|
622
|
+
255,
|
|
623
|
+
255,
|
|
624
|
+
255,
|
|
625
|
+
255,
|
|
626
|
+
255,
|
|
627
|
+
255,
|
|
628
|
+
255,
|
|
629
|
+
255,
|
|
630
|
+
255,
|
|
631
|
+
255,
|
|
632
|
+
255,
|
|
633
|
+
255,
|
|
634
|
+
255,
|
|
635
|
+
255,
|
|
636
|
+
255,
|
|
637
|
+
127
|
|
638
|
+
]),
|
|
639
|
+
new Uint8Array([
|
|
640
|
+
205,
|
|
641
|
+
235,
|
|
642
|
+
122,
|
|
643
|
+
124,
|
|
644
|
+
59,
|
|
645
|
+
65,
|
|
646
|
+
184,
|
|
647
|
+
174,
|
|
648
|
+
22,
|
|
649
|
+
86,
|
|
650
|
+
227,
|
|
651
|
+
250,
|
|
652
|
+
241,
|
|
653
|
+
159,
|
|
654
|
+
196,
|
|
655
|
+
106,
|
|
656
|
+
218,
|
|
657
|
+
9,
|
|
658
|
+
141,
|
|
659
|
+
235,
|
|
660
|
+
156,
|
|
661
|
+
50,
|
|
662
|
+
177,
|
|
663
|
+
253,
|
|
664
|
+
134,
|
|
665
|
+
98,
|
|
666
|
+
5,
|
|
667
|
+
22,
|
|
668
|
+
95,
|
|
669
|
+
73,
|
|
670
|
+
184,
|
|
671
|
+
128
|
|
672
|
+
])
|
|
673
|
+
];
|
|
674
|
+
/**
|
|
675
|
+
* Constant-time equality check for two byte arrays. No early-exit branches so
|
|
676
|
+
* comparison duration does not leak the content being compared.
|
|
677
|
+
*/
|
|
678
|
+
const bytesEqual = ({ a, b }) => {
|
|
679
|
+
let diff = a.length ^ b.length;
|
|
680
|
+
const length = Math.min(a.length, b.length);
|
|
681
|
+
for (let i = 0; i < length; i += 1) diff |= a[i] ^ b[i];
|
|
682
|
+
return diff === 0;
|
|
683
|
+
};
|
|
684
|
+
/**
|
|
685
|
+
* Validates that a decoded Curve25519 public key is safe to use for X25519 key
|
|
686
|
+
* agreement, rejecting low-order / contributory points.
|
|
687
|
+
*
|
|
688
|
+
* Defense in depth:
|
|
689
|
+
* 1. Enforce the canonical 32-byte length.
|
|
690
|
+
* 2. Reject the known small set of low-order point encodings (blocklist).
|
|
691
|
+
* 3. Reject any input whose raw X25519 output (`nacl.scalarMult`) is all-zero,
|
|
692
|
+
* which catches low-order inputs regardless of encoding.
|
|
693
|
+
*
|
|
694
|
+
* @param params.theirPublicKey - The decoded (32-byte) peer public key
|
|
695
|
+
* @param params.ourSecretKey - The decoded (32-byte) local secret key
|
|
696
|
+
* @throws {PhantomInvalidEncryptionPublicKeyError} If the key is invalid or low-order
|
|
697
|
+
*/
|
|
698
|
+
const assertValidCurve25519PublicKey = ({ theirPublicKey, ourSecretKey }) => {
|
|
699
|
+
if (theirPublicKey.length !== CURVE25519_PUBLIC_KEY_LENGTH) throw new PhantomInvalidEncryptionPublicKeyError();
|
|
700
|
+
for (const lowOrderPoint of CURVE25519_LOW_ORDER_POINTS) if (bytesEqual({
|
|
701
|
+
a: theirPublicKey,
|
|
702
|
+
b: lowOrderPoint
|
|
703
|
+
})) throw new PhantomInvalidEncryptionPublicKeyError();
|
|
704
|
+
const scalarMultOutput = tweetnacl.default.scalarMult(ourSecretKey, theirPublicKey);
|
|
705
|
+
if (bytesEqual({
|
|
706
|
+
a: scalarMultOutput,
|
|
707
|
+
b: new Uint8Array(scalarMultOutput.length)
|
|
708
|
+
})) throw new PhantomInvalidEncryptionPublicKeyError();
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
341
711
|
* Creates a shared secret for NaCl box encryption using our secret key and their public key.
|
|
342
712
|
*
|
|
713
|
+
* Rejects low-order / invalid Curve25519 public keys before deriving the shared
|
|
714
|
+
* secret, preventing an attacker from forcing the X25519 output to a known
|
|
715
|
+
* constant via a malicious `phantom_encryption_public_key`.
|
|
716
|
+
*
|
|
343
717
|
* @param params.ourSecretKey - Our base58-encoded secret key
|
|
344
718
|
* @param params.theirPublicKey - Their base58-encoded public key
|
|
345
719
|
* @returns The base58-encoded shared secret
|
|
720
|
+
* @throws {PhantomInvalidEncryptionPublicKeyError} If their public key is invalid or a low-order point
|
|
346
721
|
* @notInstrumented
|
|
347
722
|
*/
|
|
348
723
|
const createNaClSharedSecret = ({ ourSecretKey, theirPublicKey }) => {
|
|
349
|
-
const
|
|
724
|
+
const theirPublicKeyBytes = bs58.default.decode(theirPublicKey);
|
|
725
|
+
const ourSecretKeyBytes = bs58.default.decode(ourSecretKey);
|
|
726
|
+
assertValidCurve25519PublicKey({
|
|
727
|
+
ourSecretKey: ourSecretKeyBytes,
|
|
728
|
+
theirPublicKey: theirPublicKeyBytes
|
|
729
|
+
});
|
|
730
|
+
const sharedSecret = tweetnacl.default.box.before(theirPublicKeyBytes, ourSecretKeyBytes);
|
|
350
731
|
return bs58.default.encode(sharedSecret);
|
|
351
732
|
};
|
|
352
733
|
|
|
@@ -510,6 +891,17 @@ const completeAndEmitPhantomRedirectEvent = async ({ args, event }, client) => {
|
|
|
510
891
|
* is returned to the originating tab. See the `phantomRedirectCloseTab` event
|
|
511
892
|
* JSDoc for details on how to handle tab closing.
|
|
512
893
|
*
|
|
894
|
+
* @example
|
|
895
|
+
* ```ts
|
|
896
|
+
* const url = new URL(window.location.href);
|
|
897
|
+
* if (await detectPhantomRedirect({ url })) {
|
|
898
|
+
* await completePhantomRedirect({ url });
|
|
899
|
+
* // Close this clone tab; the originating tab already received the result
|
|
900
|
+
* // via BroadcastChannel and will resolve its pending promise.
|
|
901
|
+
* window.close();
|
|
902
|
+
* }
|
|
903
|
+
* ```
|
|
904
|
+
*
|
|
513
905
|
* @param params.url - The callback URL received from Phantom
|
|
514
906
|
* @param client - The Dynamic client instance
|
|
515
907
|
* @throws {NoPendingPhantomRequestError} If no pending request is found in storage
|
|
@@ -517,6 +909,9 @@ const completeAndEmitPhantomRedirectEvent = async ({ args, event }, client) => {
|
|
|
517
909
|
* required encryption parameters (`phantom_encryption_public_key`, `data`,
|
|
518
910
|
* `nonce`) and does not carry an error code either
|
|
519
911
|
* @throws {PhantomRedirectRejectedError} If the user rejected the request in Phantom
|
|
912
|
+
* @returns void
|
|
913
|
+
* @see detectPhantomRedirect
|
|
914
|
+
* @see addPhantomRedirectSolanaExtension
|
|
520
915
|
* @notInstrumented
|
|
521
916
|
*/
|
|
522
917
|
const completePhantomRedirect = async ({ url }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
@@ -1099,9 +1494,17 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
1099
1494
|
* we fall back to checking whether a pending disconnect request exists in
|
|
1100
1495
|
* storage.
|
|
1101
1496
|
*
|
|
1497
|
+
* @example
|
|
1498
|
+
* ```ts
|
|
1499
|
+
* const url = new URL(window.location.href);
|
|
1500
|
+
* const isPhantomRedirect = await detectPhantomRedirect({ url });
|
|
1501
|
+
* ```
|
|
1502
|
+
*
|
|
1102
1503
|
* @param params.url - The URL to check for Phantom redirect parameters
|
|
1103
1504
|
* @param client - The Dynamic client instance
|
|
1104
1505
|
* @returns A promise that resolves to true if the URL is a valid Phantom redirect, false otherwise
|
|
1506
|
+
* @see completePhantomRedirect
|
|
1507
|
+
* @see addPhantomRedirectSolanaExtension
|
|
1105
1508
|
* @notInstrumented
|
|
1106
1509
|
*/
|
|
1107
1510
|
const detectPhantomRedirect = async ({ url }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
@@ -1155,10 +1558,21 @@ const PHANTOM_REDIRECT_SOLANA_EXTENSION_KEY = "phantomRedirectSolana";
|
|
|
1155
1558
|
* marker written during request initiation and does **not** emit
|
|
1156
1559
|
* `phantomRedirectCloseTab`.
|
|
1157
1560
|
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```ts
|
|
1563
|
+
* addPhantomRedirectSolanaExtension({
|
|
1564
|
+
* url: new URL(window.location.href),
|
|
1565
|
+
* onCloseTab: () => window.close(),
|
|
1566
|
+
* });
|
|
1567
|
+
* ```
|
|
1568
|
+
*
|
|
1158
1569
|
* @param params.url - The current page URL
|
|
1159
1570
|
* @param params.onCloseTab - Callback invoked when the clone tab should close
|
|
1160
1571
|
* @param params.disableAutoRedirectCompletion - Skip auto detection/completion
|
|
1161
1572
|
* @param [client] - The Dynamic client. Only required for multiple clients.
|
|
1573
|
+
* @returns void
|
|
1574
|
+
* @see completePhantomRedirect
|
|
1575
|
+
* @see detectPhantomRedirect
|
|
1162
1576
|
* @notInstrumented
|
|
1163
1577
|
*/
|
|
1164
1578
|
const addPhantomRedirectSolanaExtension = async ({ disableAutoRedirectCompletion, onCloseTab, url }, client = (0, _dynamic_labs_sdk_client_core.getDefaultClient)()) => {
|
|
@@ -1214,11 +1628,23 @@ const addPhantomRedirectSolanaExtension = async ({ disableAutoRedirectCompletion
|
|
|
1214
1628
|
//#endregion
|
|
1215
1629
|
//#region src/signAllTransactions/signAllTransactions.ts
|
|
1216
1630
|
/**
|
|
1217
|
-
* Signs multiple Solana transactions
|
|
1218
|
-
*
|
|
1219
|
-
* @
|
|
1631
|
+
* Signs multiple Solana transactions in a single call.
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* ```ts
|
|
1635
|
+
* const { signedTransactions } = await signAllTransactions({
|
|
1636
|
+
* walletAccount: solAccount,
|
|
1637
|
+
* transactions: [tx1, tx2, tx3],
|
|
1638
|
+
* });
|
|
1639
|
+
* ```
|
|
1640
|
+
*
|
|
1641
|
+
* @param params.transactions - The transactions to sign.
|
|
1642
|
+
* @param params.walletAccount - The wallet account to sign the transactions with.
|
|
1220
1643
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1221
|
-
* @returns An object containing the signed transactions
|
|
1644
|
+
* @returns An object containing the signed transactions.
|
|
1645
|
+
* @throws {NotSolanaProviderError} If the wallet provider is not a Solana provider.
|
|
1646
|
+
* @see signTransaction
|
|
1647
|
+
* @see signAndSendTransaction
|
|
1222
1648
|
* @notInstrumented
|
|
1223
1649
|
*/
|
|
1224
1650
|
const signAllTransactions = async ({ walletAccount, transactions }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
|
@@ -1236,12 +1662,22 @@ const signAllTransactions = async ({ walletAccount, transactions }, client = (0,
|
|
|
1236
1662
|
* Signs and sends a sponsored Solana transaction.
|
|
1237
1663
|
* The transaction will be sponsored via Dynamic's gas sponsorship API.
|
|
1238
1664
|
*
|
|
1239
|
-
* @
|
|
1240
|
-
*
|
|
1665
|
+
* @example
|
|
1666
|
+
* ```ts
|
|
1667
|
+
* const { signature } = await signAndSendSponsoredTransaction({
|
|
1668
|
+
* walletAccount: solAccount,
|
|
1669
|
+
* transaction,
|
|
1670
|
+
* });
|
|
1671
|
+
* ```
|
|
1672
|
+
*
|
|
1673
|
+
* @param params.transaction - The transaction to sponsor, sign, and send.
|
|
1674
|
+
* @param params.walletAccount - The wallet account to sign and send the transaction with.
|
|
1241
1675
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1242
|
-
* @returns An object containing the signature
|
|
1243
|
-
* @throws {NotSolanaProviderError} If the wallet provider is not a Solana provider
|
|
1244
|
-
* @throws {MethodNotImplementedError} If the wallet provider does not implement signAndSendSponsoredTransaction
|
|
1676
|
+
* @returns An object containing the signature.
|
|
1677
|
+
* @throws {NotSolanaProviderError} If the wallet provider is not a Solana provider.
|
|
1678
|
+
* @throws {MethodNotImplementedError} If the wallet provider does not implement signAndSendSponsoredTransaction.
|
|
1679
|
+
* @see signAndSendTransaction
|
|
1680
|
+
* @see isSolanaGasSponsorshipEnabled
|
|
1245
1681
|
* @notInstrumented
|
|
1246
1682
|
*/
|
|
1247
1683
|
const signAndSendSponsoredTransaction = async ({ walletAccount, transaction, options }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|
|
@@ -1258,11 +1694,23 @@ const signAndSendSponsoredTransaction = async ({ walletAccount, transaction, opt
|
|
|
1258
1694
|
//#endregion
|
|
1259
1695
|
//#region src/signTransaction/signTransaction.ts
|
|
1260
1696
|
/**
|
|
1261
|
-
* Signs a Solana transaction
|
|
1262
|
-
*
|
|
1263
|
-
* @
|
|
1697
|
+
* Signs a Solana transaction without sending it.
|
|
1698
|
+
*
|
|
1699
|
+
* @example
|
|
1700
|
+
* ```ts
|
|
1701
|
+
* const { signedTransaction } = await signTransaction({
|
|
1702
|
+
* walletAccount: solAccount,
|
|
1703
|
+
* transaction,
|
|
1704
|
+
* });
|
|
1705
|
+
* ```
|
|
1706
|
+
*
|
|
1707
|
+
* @param params.transaction - The transaction to sign.
|
|
1708
|
+
* @param params.walletAccount - The wallet account to sign the transaction with.
|
|
1264
1709
|
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1265
|
-
* @returns An object containing the signed transaction
|
|
1710
|
+
* @returns An object containing the signed transaction.
|
|
1711
|
+
* @throws {NotSolanaProviderError} If the wallet provider is not a Solana provider.
|
|
1712
|
+
* @see signAndSendTransaction
|
|
1713
|
+
* @see signAllTransactions
|
|
1266
1714
|
* @notInstrumented
|
|
1267
1715
|
*/
|
|
1268
1716
|
const signTransaction = async ({ walletAccount, transaction }, client = (0, _dynamic_labs_sdk_client.getDefaultClient)()) => {
|