Skip to content

Commit 13c61df

Browse files
authored
Merge pull request #7 from blooo-io/fix/expose-signerc4361-in-acre-ts
Expose signERC4361 in Acre.ts
2 parents 07632b2 + d8bf8a9 commit 13c61df

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blooo/hw-app-acre",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Ledger Hardware Wallet Acre Application API",
55
"keywords": [
66
"Ledger",

src/Acre.ts

+25
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ export default class Acre {
197197
});
198198
}
199199

200+
/**
201+
* Signs a ERC4361 hex-formatted message with the private key at
202+
* the provided derivation path according to the Bitcoin Signature format
203+
* and returns v, r, s.
204+
* @example
205+
* const path = "m/44'/0'/0'/0/0";
206+
* const messageHex = "48656c6c6f20576f726c64"; // "Hello World" in hex
207+
* const result = await acre.signERC4361Message({path: path, messageHex: messageHex});
208+
*/
209+
signERC4361Message(
210+
path: string,
211+
messageHex: string,
212+
): Promise<{
213+
v: number;
214+
r: string;
215+
s: string;
216+
}> {
217+
return this.changeImplIfNecessary().then(impl => {
218+
return impl.signERC4361Message({
219+
path,
220+
messageHex,
221+
});
222+
});
223+
}
224+
200225
/**
201226
* To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
202227
* @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where

src/AcreBtcOld.ts

+14
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ export default class AcreBtcOld {
163163
"@blooo/hw-app-acre: Acre Withdrawal transaction is not compatible with the legacy AcreBtcOld client. Please use the AcreBtcNew client",
164164
);
165165
}
166+
167+
/**
168+
* This function will never be called from a AcreBtcOld context, it is only declared here for compatibility with
169+
* the current framework, throwing an error in case it is ever reached.
170+
*/
171+
async signERC4361Message({ path, messageHex }: { path: string; messageHex: string }): Promise<{
172+
v: number;
173+
r: string;
174+
s: string;
175+
}> {
176+
throw new Error(
177+
"@blooo/hw-app-acre: ERC4361 message signing is not compatible with the legacy AcreBtcOld client. Please use the AcreBtcNew client"
178+
);
179+
}
166180
}
167181

168182
function makeFingerprint(compressedPubKey) {

tests/newops/AcreBtcNew.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ async function testGetWalletPublicKey(
183183
const result = await acreBtcNew.getWalletPublicKey(path, { format: addressFormat });
184184
log('address', result.bitcoinAddress)
185185
verifyGetWalletPublicKeyResult(result, keyXpub, "testaddress");
186-
console.log('notworkingforsure')
187186
const resultAccount = await acreBtcNew.getWalletPublicKey(accountPath);
188187
verifyGetWalletPublicKeyResult(resultAccount, accountXpub);
189188
}

0 commit comments

Comments
 (0)