Skip to content

Commit

Permalink
Merge pull request #57 from leapwallet/update/btc-signer
Browse files Browse the repository at this point in the history
Update/btc signer
  • Loading branch information
baryon2 authored Jan 2, 2025
2 parents e612216 + f5f54be commit dbadc2d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@leapwallet/leap-keychain",
"version": "0.3.4-beta.0",
"version": "0.3.4-beta.1",
"description": "A javascript library for crypto key management",
"scripts": {
"test:coverage": "nyc mocha",
Expand Down
6 changes: 3 additions & 3 deletions src/key/btc-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { base64, hex } from '@scure/base';
import Container from 'typedi';
import { secp256k1Token } from '../crypto/ecc/secp256k1';
import { P2Ret } from '@scure/btc-signer/payment';
import { signSync } from '@noble/secp256k1';
import { sign } from '@noble/secp256k1';
export type BTCWalletOptions = WalletOptions & { network: typeof NETWORK };

export abstract class BtcWallet {
Expand Down Expand Up @@ -52,11 +52,11 @@ export abstract class BtcWallet {
tx.signIdx(account.privateKey, idx);
}

signECDSA(address: string, hash: Uint8Array) {
async signECDSA(address: string, hash: Uint8Array) {
const accounts = this.getAccountsWithPrivKey();
const account = accounts.find((account) => account.address === address);
if (!account) throw new Error(`No account found for ${address}`);
const [signature, recoveryParam] = signSync(hash, account.privateKey, {
const [signature, recoveryParam] = await sign(hash, account.privateKey, {
canonical: true,
recovered: true,
der: false,
Expand Down
4 changes: 2 additions & 2 deletions test/btc-wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('generate btc wallet', () => {
expect(accounts[0].address).to.be(addresses.signet);
});

it('signEcdsa: generates correct signature', () => {
it('signEcdsa: generates correct signature', async () => {
const wallet = BtcWalletHD.generateWalletFromMnemonic(mnemonic, {
addressPrefix: 'bc1q',
paths: ["m/84'/0'/0'/0/0"],
Expand All @@ -84,7 +84,7 @@ describe('generate btc wallet', () => {

const fixture = 'IBU1VH1HFZKtulCFAukOm3JP8QO4ldrqxVohbhY5Qt8YFAxG85AanlP4qPjnOfDlkWGUUTan1gAVad1KcG2FifQ=';

const { signature, recoveryParam } = wallet.signECDSA(account.address, base64.decode(testHash));
const { signature, recoveryParam } = await wallet.signECDSA(account.address, base64.decode(testHash));
const base64Signature = compressSignature(recoveryParam, signature);
expect(base64Signature).to.equal(fixture);
});
Expand Down

0 comments on commit dbadc2d

Please sign in to comment.