1
1
import fs from "fs" ;
2
- import { Connection , Commitment } from "@solana/web3.js" ;
3
- import { ChainId } from "@certusone/wormhole-sdk" ;
2
+ import { Connection , Commitment , Keypair , Transaction } from "@solana/web3.js" ;
3
+ import { ChainId , sign } from "@certusone/wormhole-sdk" ;
4
4
import { SolanaLedgerSigner } from "@xlabs-xyz/ledger-signer-solana" ;
5
5
import { Chain } from "@wormhole-foundation/sdk-base" ;
6
-
7
- if ( ! process . env . LEDGER_DERIVATION_PATH ) {
8
- throw new Error ( "LEDGER_DERIVATION_PATH is not set" ) ;
9
- }
6
+ import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes" ;
7
+ import nacl from "tweetnacl" ;
10
8
11
9
if ( ! process . env . ENV ) {
12
10
throw new Error ( "ENV not set" ) ;
13
11
}
14
12
15
13
const env = process . env . ENV ;
16
14
17
- const derivationPath = process . env . LEDGER_DERIVATION_PATH ! as string ;
15
+ interface SolanaSigner {
16
+ getAddress ( ) : Promise < Buffer > ;
17
+ signMessage ( message : Buffer ) : Promise < Buffer > ;
18
+ signTransaction ( transaction : Buffer ) : Promise < Buffer > ;
19
+ }
20
+
21
+ export class SolanaLocalSigner implements SolanaSigner {
22
+ readonly keypair : Keypair ;
23
+ constructor ( private privateKey : string ) {
24
+ this . keypair = Keypair . fromSecretKey ( bs58 . decode ( this . privateKey ) ) ;
25
+ }
26
+
27
+ async getAddress ( ) : Promise < Buffer > {
28
+ return this . keypair . publicKey . toBuffer ( ) ;
29
+ }
30
+
31
+ async signMessage ( message : Buffer ) : Promise < Buffer > {
32
+ return Buffer . from (
33
+ nacl . sign . detached ( new Uint8Array ( message ) , this . keypair . secretKey )
34
+ ) ;
35
+ }
36
+
37
+ async signTransaction ( transaction : Buffer ) : Promise < Buffer > {
38
+ const tx = Transaction . from ( transaction ) ;
39
+ tx . sign ( this . keypair ) ;
40
+ return tx . serialize ( ) ;
41
+ }
42
+ }
18
43
19
44
let signer ;
20
- export async function getSigner ( ) : Promise < SolanaLedgerSigner > {
21
- if ( ! signer ) {
22
- signer = await SolanaLedgerSigner . create ( derivationPath ) ;
45
+ export async function getSigner ( ) : Promise < SolanaSigner > {
46
+ if ( signer ) return signer ;
47
+
48
+ if ( process . env . LEDGER_DERIVATION_PATH ) {
49
+ signer = await SolanaLedgerSigner . create (
50
+ process . env . LEDGER_DERIVATION_PATH !
51
+ ) ;
52
+ }
53
+
54
+ if ( process . env . SOLANA_PRIVATE_KEY ) {
55
+ signer = new SolanaLocalSigner ( process . env . SOLANA_PRIVATE_KEY ! ) ;
23
56
}
24
57
58
+ if ( ! signer )
59
+ throw new Error (
60
+ "Either LEDGER_DERIVATION_PATH or SOLANA_PRIVATE_KEY must be set"
61
+ ) ;
62
+
25
63
return signer ;
26
64
}
27
65
@@ -50,11 +88,11 @@ export type NttDeployment = {
50
88
} ;
51
89
52
90
export type QuoterManagerRegistrations = {
53
- programId : string ;
54
- tokenAddress : string ;
55
- gasCost : number ;
56
- wormholeTransceiverIndex : number ;
57
- isSupported : boolean ;
91
+ programId : string ;
92
+ tokenAddress : string ;
93
+ gasCost : number ;
94
+ wormholeTransceiverIndex : number ;
95
+ isSupported : boolean ;
58
96
} [ ] ;
59
97
60
98
export type QuoterPeerQuotes = Partial < Record < Chain , QuoterPeerQuote > > ;
@@ -75,30 +113,30 @@ export type QuoterConfig = {
75
113
solPriceUsd : number ;
76
114
peerQuotes : QuoterPeerQuotes ;
77
115
managerRegistrations : QuoterManagerRegistrations ;
78
- }
116
+ } ;
79
117
80
118
export type NttConfig = {
81
119
outboundLimit : string ;
82
120
mode : "locking" | "burning" ;
83
- }
121
+ } ;
84
122
85
123
export type Programs = {
86
124
mintProgramId : string ;
87
125
nttProgramId : string ;
88
126
wormholeProgramId : string ;
89
127
quoterProgramId : string ;
90
128
governanceProgramId : string ;
91
- }
129
+ } ;
92
130
93
131
export type GovernanceVaa = {
94
132
vaa : string ;
95
- }
133
+ } ;
96
134
97
135
export function getEvmNttDeployments ( ) : NttDeployment [ ] {
98
136
return loadScriptConfig ( "evm-peers" ) ;
99
137
}
100
138
101
- export function getQuoterConfiguration ( ) : QuoterConfig {
139
+ export function getQuoterConfiguration ( ) : QuoterConfig {
102
140
return loadScriptConfig ( "quoter" ) ;
103
141
}
104
142
0 commit comments