Skip to content

Commit

Permalink
Merge pull request #7 from blooo-io/fix/expose-signerc4361-in-acre-ts
Browse files Browse the repository at this point in the history
Expose signERC4361 in Acre.ts
  • Loading branch information
Z4karia authored Oct 25, 2024
2 parents 07632b2 + d8bf8a9 commit 13c61df
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blooo/hw-app-acre",
"version": "1.1.0",
"version": "1.1.1",
"description": "Ledger Hardware Wallet Acre Application API",
"keywords": [
"Ledger",
Expand Down
25 changes: 25 additions & 0 deletions src/Acre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,31 @@ export default class Acre {
});
}

/**
* Signs a ERC4361 hex-formatted message with the private key at
* the provided derivation path according to the Bitcoin Signature format
* and returns v, r, s.
* @example
* const path = "m/44'/0'/0'/0/0";
* const messageHex = "48656c6c6f20576f726c64"; // "Hello World" in hex
* const result = await acre.signERC4361Message({path: path, messageHex: messageHex});
*/
signERC4361Message(
path: string,
messageHex: string,
): Promise<{
v: number;
r: string;
s: string;
}> {
return this.changeImplIfNecessary().then(impl => {
return impl.signERC4361Message({
path,
messageHex,
});
});
}

/**
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
Expand Down
14 changes: 14 additions & 0 deletions src/AcreBtcOld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ export default class AcreBtcOld {
"@blooo/hw-app-acre: Acre Withdrawal transaction is not compatible with the legacy AcreBtcOld client. Please use the AcreBtcNew client",
);
}

/**
* This function will never be called from a AcreBtcOld context, it is only declared here for compatibility with
* the current framework, throwing an error in case it is ever reached.
*/
async signERC4361Message({ path, messageHex }: { path: string; messageHex: string }): Promise<{
v: number;
r: string;
s: string;
}> {
throw new Error(
"@blooo/hw-app-acre: ERC4361 message signing is not compatible with the legacy AcreBtcOld client. Please use the AcreBtcNew client"
);
}
}

function makeFingerprint(compressedPubKey) {
Expand Down
1 change: 0 additions & 1 deletion tests/newops/AcreBtcNew.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ async function testGetWalletPublicKey(
const result = await acreBtcNew.getWalletPublicKey(path, { format: addressFormat });
log('address', result.bitcoinAddress)
verifyGetWalletPublicKeyResult(result, keyXpub, "testaddress");
console.log('notworkingforsure')
const resultAccount = await acreBtcNew.getWalletPublicKey(accountPath);
verifyGetWalletPublicKeyResult(resultAccount, accountXpub);
}
Expand Down

0 comments on commit 13c61df

Please sign in to comment.