clients: allow passing solana private key

Currently the typescript clients generate a fresh wallet and request
airdrop into them. This obviously only works on tiltnet and testnet.
Here we add an option to allow specifying a private key, which makes the
command work in mainnet.
This commit is contained in:
Csongor Kiss 2022-03-02 01:06:27 +00:00 committed by Evan Gray
parent fc1c8d28a3
commit 918a968703
2 changed files with 41 additions and 21 deletions

View File

@ -7,7 +7,7 @@ import * as ethers from "ethers";
import * as web3s from '@solana/web3.js';
import { PublicKey, TransactionInstruction, AccountMeta, Keypair, Connection } from "@solana/web3.js";
import {solidityKeccak256} from "ethers/lib/utils";
import { base58, solidityKeccak256 } from "ethers/lib/utils";
import { setDefaultWasm, importCoreWasm, importNftWasm, ixFromRust, BridgeImplementation__factory } from '@certusone/wormhole-sdk'
setDefaultWasm("node")
@ -135,6 +135,12 @@ yargs(hideBin(process.argv))
description: 'NFT Bridge address',
default: "NFTWqJR8YnRVqPDvTJrYuLrQDitTG5AScqbeghi4zSA"
})
.option('key', {
alias: 'k',
type: 'string',
description: 'Private key of the wallet',
required: false
})
}, async (argv: any) => {
const bridge = await importCoreWasm()
const nft_bridge = await importNftWasm()
@ -143,13 +149,17 @@ yargs(hideBin(process.argv))
let bridge_id = new PublicKey(argv.bridge);
let nft_bridge_id = new PublicKey(argv.nft_bridge);
// Generate a new random public key
let from = web3s.Keypair.generate();
var from: web3s.Keypair;
if (argv.key) {
from = web3s.Keypair.fromSecretKey(base58.decode(argv.key));
} else {
from = web3s.Keypair.generate();
let airdropSignature = await connection.requestAirdrop(
from.publicKey,
web3s.LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);
}
let vaa = Buffer.from(argv.vaa, "hex");
await post_vaa(connection, bridge_id, from, vaa);

View File

@ -10,7 +10,7 @@ import {fromUint8Array} from "js-base64";
import {LCDClient, MnemonicKey} from '@terra-money/terra.js';
import {MsgExecuteContract} from "@terra-money/terra.js";
import {PublicKey, TransactionInstruction, AccountMeta, Keypair, Connection} from "@solana/web3.js";
import {solidityKeccak256} from "ethers/lib/utils";
import {base58, solidityKeccak256} from "ethers/lib/utils";
import {setDefaultWasm, importCoreWasm, importTokenWasm, ixFromRust, BridgeImplementation__factory} from '@certusone/wormhole-sdk'
setDefaultWasm("node")
@ -255,6 +255,12 @@ yargs(hideBin(process.argv))
description: 'Token Bridge address',
default: "B6RHG3mfcckmrYN1UhmJzyS1XX3fZKbkeUcpJe9Sy3FE"
})
.option('key', {
alias: 'k',
type: 'string',
description: 'Private key of the wallet',
required: false
})
}, async (argv: any) => {
const bridge = await importCoreWasm()
const token_bridge = await importTokenWasm()
@ -263,13 +269,17 @@ yargs(hideBin(process.argv))
let bridge_id = new PublicKey(argv.bridge);
let token_bridge_id = new PublicKey(argv.token_bridge);
// Generate a new random public key
let from = web3s.Keypair.generate();
var from: web3s.Keypair;
if (argv.key) {
from = web3s.Keypair.fromSecretKey(base58.decode(argv.key));
} else {
from = web3s.Keypair.generate();
let airdropSignature = await connection.requestAirdrop(
from.publicKey,
web3s.LAMPORTS_PER_SOL,
);
await connection.confirmTransaction(airdropSignature);
}
let vaa = Buffer.from(argv.vaa, "hex");
await post_vaa(connection, bridge_id, from, vaa);