From 2bda36f4e8818b6136121c23baf9503e6e0744cd Mon Sep 17 00:00:00 2001 From: Z4karia Date: Fri, 25 Oct 2024 16:22:27 +0200 Subject: [PATCH 1/2] Expose signERC4361 in Acre.ts --- src/Acre.ts | 25 +++++++++++++++++++++++++ src/AcreBtcOld.ts | 14 ++++++++++++++ tests/newops/AcreBtcNew.test.ts | 1 - 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Acre.ts b/src/Acre.ts index 3b785f7..59d38ae 100644 --- a/src/Acre.ts +++ b/src/Acre.ts @@ -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 diff --git a/src/AcreBtcOld.ts b/src/AcreBtcOld.ts index a7f6f33..cef5d58 100644 --- a/src/AcreBtcOld.ts +++ b/src/AcreBtcOld.ts @@ -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) { diff --git a/tests/newops/AcreBtcNew.test.ts b/tests/newops/AcreBtcNew.test.ts index 45f296b..d8f9845 100644 --- a/tests/newops/AcreBtcNew.test.ts +++ b/tests/newops/AcreBtcNew.test.ts @@ -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); } From d8bf8a998abca6e87b6c2b192a81d7ffd90b35e5 Mon Sep 17 00:00:00 2001 From: Z4karia Date: Fri, 25 Oct 2024 17:03:57 +0200 Subject: [PATCH 2/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 81b4cb2..7692e08 100644 --- a/package.json +++ b/package.json @@ -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",