Skip to content

Commit

Permalink
refactor: upgrade @Scure & @noble packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jun 4, 2024
1 parent 5ea44b2 commit 03a0666
Show file tree
Hide file tree
Showing 11 changed files with 2,328 additions and 573 deletions.
14 changes: 7 additions & 7 deletions packages/bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"@leather-wallet/constants": "workspace:*",
"@leather-wallet/models": "workspace:*",
"@leather-wallet/utils": "workspace:*",
"@noble/hashes": "1.3.3",
"@noble/secp256k1": "2.0.0",
"@scure/base": "1.1.3",
"@scure/bip32": "1.3.3",
"@scure/bip39": "1.2.1",
"@scure/btc-signer": "1.2.1",
"@noble/hashes": "1.4.0",
"@noble/secp256k1": "2.1.0",
"@scure/base": "1.1.6",
"@scure/bip32": "1.4.0",
"@scure/bip39": "1.3.0",
"@scure/btc-signer": "1.3.2",
"@stacks/common": "6.8.1",
"@stacks/transactions": "6.9.0",
"bip32": "4.0.0",
Expand All @@ -41,9 +41,9 @@
"varuint-bitcoin": "1.1.2"
},
"devDependencies": {
"@btckit/types": "0.0.19",
"@leather-wallet/eslint-config": "workspace:*",
"@leather-wallet/prettier-config": "workspace:*",
"@leather-wallet/rpc": "workspace:*",
"@leather-wallet/tsconfig-config": "workspace:*",
"@vitest/coverage-istanbul": "0.34.6",
"concurrently": "8.2.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin/src/bip322/bip322-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ecc from '@bitcoinerlab/secp256k1';
import type { PaymentTypes } from '@btckit/types';
import type { PaymentTypes } from '@leather-wallet/rpc';
import { isString } from '@leather-wallet/utils';
import { sha256 } from '@noble/hashes/sha256';
import { hexToBytes, utf8ToBytes } from '@stacks/common';
Expand Down
5 changes: 3 additions & 2 deletions packages/bitcoin/src/bitcoin-signer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { SignatureHash } from '@btckit/types';
import type { BitcoinNetworkModes } from '@leather-wallet/models';
import { SignatureHash } from '@leather-wallet/rpc';
import { HDKey } from '@scure/bip32';
import * as btc from '@scure/btc-signer';
import { SigHash } from '@scure/btc-signer/transaction';

export type AllowedSighashTypes = SignatureHash | btc.SignatureHash;
export type AllowedSighashTypes = SignatureHash | SigHash;

export interface Signer<Payment> {
network: BitcoinNetworkModes;
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin/src/bitcoin.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PaymentTypes } from '@btckit/types';
import { BitcoinNetworkModes, NetworkModes } from '@leather-wallet/models';
import type { PaymentTypes } from '@leather-wallet/rpc';
import { defaultWalletKeyId, whenNetwork } from '@leather-wallet/utils';
import { hexToBytes } from '@noble/hashes/utils';
import { HDKey, Versions } from '@scure/bip32';
Expand Down
8 changes: 4 additions & 4 deletions packages/query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"@leather-wallet/models": "workspace:*",
"@leather-wallet/rpc": "workspace:*",
"@leather-wallet/utils": "workspace:*",
"@noble/hashes": "1.3.3",
"@scure/base": "1.1.3",
"@scure/bip32": "1.3.3",
"@scure/btc-signer": "1.2.1",
"@noble/hashes": "1.4.0",
"@scure/base": "1.1.6",
"@scure/bip32": "1.4.0",
"@scure/btc-signer": "1.3.2",
"@stacks/common": "6.8.1",
"@stacks/rpc-client": "0.8.18",
"@stacks/stacks-blockchain-api-types": "7.8.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useEffect } from 'react';

import type { Signer } from '@leather-wallet/bitcoin';
import { createNumArrayOfRange } from '@leather-wallet/utils';
import { P2TROut } from '@scure/btc-signer';
import { P2TROut } from '@scure/btc-signer/payment';
import { useInfiniteQuery } from '@tanstack/react-query';

import { useLeatherNetwork } from '../../../leather-query-provider';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BitcoinTx } from '@leather-wallet/models';
import { isUndefined } from '@leather-wallet/utils';
import * as btc from '@scure/btc-signer';
import { TransactionInput } from '@scure/btc-signer/psbt';

import { InscriptionResponseHiro } from '../../../types/inscription';
import { createInscriptionHiro } from './inscription.utils';
Expand All @@ -19,7 +19,7 @@ export function useInscriptionByOutput(transaction: BitcoinTx) {
});
}

export function useInscriptionsByOutputs(inputs: btc.TransactionInput[]) {
export function useInscriptionsByOutputs(inputs: TransactionInput[]) {
return useGetInscriptionsByOutputQueries(inputs)
.map(query => query.data?.results[0])
.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BitcoinTx } from '@leather-wallet/models';
import { HIRO_INSCRIPTIONS_API_URL } from '@leather-wallet/models';
import * as btc from '@scure/btc-signer';
import { TransactionInput } from '@scure/btc-signer/psbt';
import { bytesToHex } from '@stacks/common';
import { useQueries, useQuery } from '@tanstack/react-query';
import axios from 'axios';
Expand Down Expand Up @@ -49,7 +49,7 @@ const inscriptionsByOutputQueriesOptions = {
refetchOnWindowFocus: false,
} as const;

export function useGetInscriptionsByOutputQueries(inputs: btc.TransactionInput[]) {
export function useGetInscriptionsByOutputQueries(inputs: TransactionInput[]) {
return useQueries({
queries: inputs.map(input => {
const param = input.txid ? `output=${bytesToHex(input.txid)}:${input.index}` : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useState } from 'react';

import { decodeBitcoinTx } from '@leather-wallet/bitcoin';
import { delay } from '@leather-wallet/utils';
import * as btc from '@scure/btc-signer';
import { TransactionInput } from '@scure/btc-signer/psbt';

import { useBitcoinClient } from '../bitcoin-client';
import { filterOutIntentionalUtxoSpend, useCheckUnspendableUtxos } from './use-check-utxos';
Expand Down Expand Up @@ -33,7 +33,7 @@ export function useBitcoinBroadcastTransaction() {
try {
if (skipSpendableCheckUtxoIds !== 'all') {
// Filter out intentional spend inscription txid from the check list
const utxos: btc.TransactionInput[] = filterOutIntentionalUtxoSpend({
const utxos: TransactionInput[] = filterOutIntentionalUtxoSpend({
inputs: decodeBitcoinTx(tx).inputs,
intentionalSpendUtxoIds: skipSpendableCheckUtxoIds,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/query/src/bitcoin/transaction/use-check-utxos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react';

import { isUndefined } from '@leather-wallet/utils';
import * as btc from '@scure/btc-signer';
import { TransactionInput } from '@scure/btc-signer/psbt';
import { bytesToHex } from '@stacks/common';

import { useCurrentNetworkState, useIsLeatherTestingEnv } from '../../leather-query-provider';
Expand All @@ -16,14 +16,14 @@ class PreventTransactionError extends Error {
}

interface FilterOutIntentionalInscriptionsSpendArgs {
inputs: btc.TransactionInput[];
inputs: TransactionInput[];
intentionalSpendUtxoIds: string[];
}

export function filterOutIntentionalUtxoSpend({
inputs,
intentionalSpendUtxoIds,
}: FilterOutIntentionalInscriptionsSpendArgs): btc.TransactionInput[] {
}: FilterOutIntentionalInscriptionsSpendArgs): TransactionInput[] {
return inputs.filter(input => {
if (!input.txid) throw new Error('Transaction ID is missing in the input');
const inputTxid = bytesToHex(input.txid);
Expand All @@ -35,7 +35,7 @@ export function filterOutIntentionalUtxoSpend({
}

interface CheckInscribedUtxosByBestinslotArgs {
inputs: btc.TransactionInput[];
inputs: TransactionInput[];
txids: string[];
client: BitcoinClient;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export function useCheckUnspendableUtxos(blockTxAction?: () => void) {
}, [blockTxAction]);

const checkIfUtxosListIncludesInscribed = useCallback(
async (inputs: btc.TransactionInput[]) => {
async (inputs: TransactionInput[]) => {
setIsLoading(true);
const txids = inputs.map(input => {
if (!input.txid) throw new Error('Transaction ID is missing in the input');
Expand Down
Loading

0 comments on commit 03a0666

Please sign in to comment.