Skip to content

Commit

Permalink
fix: maybe????
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Dec 23, 2024
1 parent c3f3a3b commit b07f3bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export class SolanaDirectAdapter {
async getAddress(addressNList: core.BIP32Path): Promise<string> {
const nodeAdapter = await this.nodeAdapter.derivePath(core.addressNListToBIP32(addressNList));
const publicKeyBuffer = nodeAdapter.getPublicKey();
// Convert the public key to Solana format by reversing the bytes, something something Little vs. Big Endian
const solanaFormat = Buffer.from(publicKeyBuffer).reverse();

return new PublicKey(solanaFormat).toBase58();
// PublicKey constructor in Solana expects the key in big-endian format
return new PublicKey(publicKeyBuffer).toBase58();
}

async signDirect(transaction: VersionedTransaction, addressNList: core.BIP32Path): Promise<VersionedTransaction> {
const nodeAdapter = await this.nodeAdapter.derivePath(core.addressNListToBIP32(addressNList));
const pubkey = await this.getAddress(addressNList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,24 @@ export class Ed25519Node extends Revocable(class {}) implements Ed25519Key {
}

async derive(index: number): Promise<Ed25519Node> {
// Ensure hardened derivation
if (index < 0x80000000) {
index += 0x80000000;
}

const indexBuffer = Buffer.alloc(4);
indexBuffer.writeUInt32BE(index, 0);

const data = Buffer.concat([
Buffer.from([0x00]), // Hardened derivation prefix
this.#privateKey, // Private key
indexBuffer, // Index
]);
const data = Buffer.concat([Buffer.from([0x00]), this.#privateKey, indexBuffer]);

const hmac = createHmac("sha512", this.#chainCode);
hmac.update(data);
const I = hmac.digest();

const IL = I.slice(0, 32); // Private key
const IR = I.slice(32); // Chain code
const IL = I.slice(0, 32);
const IR = I.slice(32);

// ED25519 key clamping, whatever that means
// Apply clamping as per RFC 8032
IL[0] &= 0xf8;
IL[31] &= 0x7f;
IL[31] |= 0x40;
Expand Down

0 comments on commit b07f3bd

Please sign in to comment.