-
Notifications
You must be signed in to change notification settings - Fork 300
feat(lazer): add utils for adding and checking ed25519 signers to solana contract #2788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3b50457
feat(lazer): add utils for adding and checking ed25519 signers to sol…
Riateche 8272ca1
refactor(lazer): move ed25519 instruction code to solana contract pac…
Riateche 95e26d9
chore: fix unrelated formatting
Riateche 463eaf4
chore: fix constant usage
Riateche 66268bf
chore: fix ci
Riateche fc0550b
chore: fix CI 2
Riateche 0200bca
fix CI
Riateche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { Program } from "@coral-xyz/anchor"; | ||
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract"; | ||
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json"; | ||
import yargs from "yargs/yargs"; | ||
import { readFileSync } from "fs"; | ||
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; | ||
|
||
// Add a trusted signer or change its expiry time. | ||
// | ||
// Example: | ||
// pnpm ts-node scripts/add_ed25519_signer.ts --url 'https://api.testnet.solana.com' \ | ||
// --keypair-path .../key.json --trusted-signer HaXscpSUcbCLSnPQB8Z7H6idyANxp1mZAXTbHeYpfrJJ \ | ||
// --expiry-time-seconds 2057930841 | ||
async function main() { | ||
let argv = await yargs(process.argv.slice(2)) | ||
.options({ | ||
url: { type: "string", demandOption: true }, | ||
"keypair-path": { type: "string", demandOption: true }, | ||
"trusted-signer": { type: "string", demandOption: true }, | ||
"expiry-time-seconds": { type: "number", demandOption: true }, | ||
}) | ||
.parse(); | ||
|
||
const keypair = anchor.web3.Keypair.fromSecretKey( | ||
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))), | ||
); | ||
|
||
const wallet = new NodeWallet(keypair); | ||
const connection = new anchor.web3.Connection(argv.url, { | ||
commitment: "confirmed", | ||
}); | ||
const provider = new anchor.AnchorProvider(connection, wallet); | ||
|
||
const program: Program<PythLazerSolanaContract> = new Program( | ||
pythLazerSolanaContractIdl as PythLazerSolanaContract, | ||
provider, | ||
); | ||
|
||
await program.methods | ||
.update( | ||
new anchor.web3.PublicKey(argv.trustedSigner), | ||
new anchor.BN(argv.expiryTimeSeconds), | ||
) | ||
.accounts({}) | ||
.rpc(); | ||
console.log("signer updated"); | ||
} | ||
|
||
main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { Program } from "@coral-xyz/anchor"; | ||
import { PythLazerSolanaContract } from "../target/types/pyth_lazer_solana_contract"; | ||
import * as pythLazerSolanaContractIdl from "../target/idl/pyth_lazer_solana_contract.json"; | ||
import yargs from "yargs/yargs"; | ||
import { readFileSync } from "fs"; | ||
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet"; | ||
import { createEd25519Instruction } from "@pythnetwork/pyth-lazer-sdk"; | ||
import { | ||
sendAndConfirmTransaction, | ||
SendTransactionError, | ||
SYSVAR_INSTRUCTIONS_PUBKEY, | ||
Transaction, | ||
} from "@solana/web3.js"; | ||
|
||
async function main() { | ||
let argv = await yargs(process.argv.slice(2)) | ||
.options({ | ||
url: { type: "string", demandOption: true }, | ||
"keypair-path": { type: "string", demandOption: true }, | ||
message: { type: "string", demandOption: true }, | ||
}) | ||
.parse(); | ||
|
||
const keypair = anchor.web3.Keypair.fromSecretKey( | ||
new Uint8Array(JSON.parse(readFileSync(argv.keypairPath, "ascii"))), | ||
); | ||
|
||
const wallet = new NodeWallet(keypair); | ||
const connection = new anchor.web3.Connection(argv.url, { | ||
commitment: "confirmed", | ||
}); | ||
const provider = new anchor.AnchorProvider(connection, wallet); | ||
|
||
const program: Program<PythLazerSolanaContract> = new Program( | ||
pythLazerSolanaContractIdl as PythLazerSolanaContract, | ||
provider, | ||
); | ||
|
||
const instructionMessage = Buffer.from(argv.message, "hex"); | ||
const ed25519Instruction = createEd25519Instruction( | ||
instructionMessage, | ||
1, | ||
12, | ||
); | ||
const lazerInstruction = await program.methods | ||
.verifyMessage(instructionMessage, 0, 0) | ||
.accounts({ | ||
payer: wallet.publicKey, | ||
instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY, | ||
}) | ||
.instruction(); | ||
|
||
const transaction = new Transaction().add( | ||
ed25519Instruction, | ||
lazerInstruction, | ||
); | ||
console.log("transaction:", transaction); | ||
|
||
try { | ||
const signature = await sendAndConfirmTransaction( | ||
connection, | ||
transaction, | ||
[wallet.payer], | ||
{ | ||
skipPreflight: true, | ||
}, | ||
); | ||
console.log("Transaction confirmed with signature:", signature); | ||
} catch (e) { | ||
console.log("error", e); | ||
console.log(e.getLogs()); | ||
} | ||
} | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually can you move this function to
@pythnetwork/pyth-lazer-solana-contract
. It makes sense to be here and we want to remove it from js-sdk to remove the solana dependencies.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well that's a bigger lift that we need to work on sometime later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed solana deps from
@pythnetwork/pyth-lazer-sdk
and moved the code to ``@pythnetwork/pyth-lazer-solana-contract. Preparing
@pythnetwork/pyth-lazer-solana-contract` for publishing is tricky, so I'll leave it for later.