1
1
import {
2
- Transaction ,
3
- TransactionInstruction ,
4
2
Keypair ,
5
3
PublicKey ,
4
+ Transaction ,
5
+ TransactionInstruction ,
6
6
} from "@solana/web3.js" ;
7
7
8
- import { SolanaLedgerSigner } from "@xlabs-xyz/ledger-signer-solana" ;
9
- import { connection , getSigner } from "./env" ;
8
+ import { SolanaSigner , connection , getSigner } from "./env" ;
10
9
11
- export async function ledgerSignAndSend ( instructions : TransactionInstruction [ ] , signers : Keypair [ ] ) {
10
+ export async function ledgerSignAndSend (
11
+ instructions : TransactionInstruction [ ] ,
12
+ signers : Keypair [ ]
13
+ ) {
12
14
const deployerSigner = await getSigner ( ) ;
13
15
const deployerPk = new PublicKey ( await deployerSigner . getAddress ( ) ) ;
14
16
15
17
const tx = new Transaction ( ) ;
16
18
tx . add ( ...instructions ) ;
17
19
18
20
const recentBlockHash = await connection . getRecentBlockhash ( ) ;
19
-
21
+
20
22
tx . recentBlockhash = recentBlockHash . blockhash ;
21
23
tx . feePayer = deployerPk ;
22
-
24
+
23
25
signers . forEach ( ( signer ) => tx . partialSign ( signer ) ) ;
24
26
25
27
await addLedgerSignature ( tx , deployerSigner , deployerPk ) ;
26
28
27
29
return connection . sendRawTransaction ( tx . serialize ( ) , {
28
30
skipPreflight : true ,
29
-
30
31
} ) ;
31
32
}
32
33
33
- export async function addLedgerSignature ( tx : Transaction , signer : SolanaLedgerSigner , signerPk : PublicKey ) {
34
- const signedByPayer = await signer . signTransaction ( tx . compileMessage ( ) . serialize ( ) ) ;
34
+ export async function addLedgerSignature (
35
+ tx : Transaction ,
36
+ signer : SolanaSigner ,
37
+ signerPk : PublicKey
38
+ ) {
39
+ const signedByPayer = await signer . signTransaction (
40
+ tx . compileMessage ( ) . serialize ( )
41
+ ) ;
35
42
tx . addSignature ( signerPk , signedByPayer ) ;
36
- }
43
+ }
0 commit comments