Skip to content

Feat/ledger#23

Open
JoshuaAverett wants to merge 5 commits intodevelopfrom
feat/ledger
Open

Feat/ledger#23
JoshuaAverett wants to merge 5 commits intodevelopfrom
feat/ledger

Conversation

@JoshuaAverett
Copy link

No description provided.

"scripts": {
"build": "tsc --build"
"build": "tsc --build",
"build:solana": "cd ../../src/solana && anchor build",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to use the makefile here instead.

Copy link
Collaborator

@scnale scnale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a partial review. I'm still missing looking at the governance client.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be deleted, right?

"@ledgerhq/hw-transport-node-hid": "^6.28.0",
"@solana/web3.js": "^1.98.4",
"@wormhole-foundation/sdk": "^4.5.0",
"@xlabs-xyz/ledger-ethers-signer": "github:XLabs/ledger-ethers-signer",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +18 to +19
"@ledgerhq/hw-app-solana": "^7.0.0",
"@ledgerhq/hw-transport-node-hid": "^6.28.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't necessary.

"references": [
{ "path": "../peer-lib" }
{ "path": "../peer-lib" },
{ "path": "../../src/solana" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solana tests package is not a dependency so this seems unnecessary.

Comment on lines +125 to +128
// Validate basic structure
if (!config.Peers || !Array.isArray(config.Peers)) {
throw new Error('Invalid config: missing or invalid "Peers" array');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could import the schema definition in peer-lib here, right?

Comment on lines +135 to +141
const message = new (await import("@solana/web3.js")).TransactionMessage({
payerKey: PublicKey.default,
recentBlockhash: blockhash,
instructions: [ix],
}).compileToV0Message();

const tx = new (await import("@solana/web3.js")).VersionedTransaction(message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I think using an import in situ is a bit overkill given that we're importing it at the top level :P


if (result.value.err) {
const logs = result.value.logs?.join("\n") || "No logs";
return { verified: false, error: `Simulation failed: ${JSON.stringify(result.value.err)}\nLogs:\n${logs}` };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using util.inspect here. It's going to be safer if the error description is some crazy object with circular references :P
We might need an import for util.

Suggested change
return { verified: false, error: `Simulation failed: ${JSON.stringify(result.value.err)}\nLogs:\n${logs}` };
return { verified: false, error: `Simulation failed: ${util.inspect(result.value.err)}\nLogs:\n${logs}` };

console.log("Sequence:", result.sequence.toString());
console.log("Payload Offset:", result.payloadOffset);
} else {
console.log("(Solana verify_vaa does not return parsed VAA data)");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log("(Solana verify_vaa does not return parsed VAA data)");
console.log("(SVM verify_vaa does not return parsed VAA data)");

Comment on lines +103 to +104
// Solana verification via simulate
async function verifyVaaSolana(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Solana verification via simulate
async function verifyVaaSolana(
// SVM verification via simulate
async function verifyVaaSVM(


const VERIFICATION_FAILED_ERROR_SIGNATURE = "0x32629d58";

// Default Solana program ID from IDL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Default Solana program ID from IDL
// TODO: update this to a better default when the contracts are deployed.
// Default Solana program ID from IDL

Comment on lines +9 to +10
import * as TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
import * as SolanaApp from "@ledgerhq/hw-app-solana";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use @xlabs-xyz/ledger-signer-solana instead.

Comment on lines +157 to +188
class EvmLedgerSigner {
private ledgerSigner: EthersSigner;

private constructor(ledgerSigner: EthersSigner) {
this.ledgerSigner = ledgerSigner;
}

static async create(provider: ethers.Provider): Promise<EvmLedgerSigner> {
try {
// Dynamic import using Function constructor to prevent vite from analyzing it
const importLedger = new Function('specifier', 'return import(specifier)');
const ledgerModule = await importLedger("@xlabs-xyz/ledger-ethers-signer");
const LedgerSigner = ledgerModule.LedgerSigner || (ledgerModule as any).default?.LedgerSigner || (ledgerModule as any).default;
const ledgerSigner = new LedgerSigner(provider, "hid");
const address = await ledgerSigner.getAddress();
console.log(`Using Ledger EVM signer: ${address}`);
return new EvmLedgerSigner(ledgerSigner);
} catch (error) {
console.error(`Failed to initialize Ledger: ${errorMsg(error)}`);
console.error('Make sure your Ledger device is connected and the Ethereum app is open.');
throw error;
}
}

async getAddress(): Promise<string> {
return await this.ledgerSigner.getAddress();
}

getSigner(): EthersSigner {
return this.ledgerSigner;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhh, this is redundant. You can pass the ethers signer from the library directly to the ethers APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants