mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
fix: add public keys to getAddresses response, closes #3778
This commit is contained in:
2
.github/workflows/playwright.yml
vendored
2
.github/workflows/playwright.yml
vendored
@@ -69,7 +69,7 @@ jobs:
|
||||
# provides a virtual X display server to the process it runs, allowing
|
||||
# processes that require a display server to run in environments where
|
||||
# one is not available.
|
||||
run: xvfb-run yarn playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers=1
|
||||
run: xvfb-run yarn playwright test tests/specs --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers=1
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { BtcAddress } from '@btckit/types';
|
||||
import { bytesToHex } from '@stacks/common';
|
||||
|
||||
import { logger } from '@shared/logger';
|
||||
import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';
|
||||
@@ -8,7 +9,7 @@ import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';
|
||||
import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
|
||||
import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-search-params';
|
||||
import { initialSearchParams } from '@app/common/initial-search-params';
|
||||
import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
|
||||
import { useCurrentAccountNativeSegwitIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
|
||||
import { useCurrentAccountTaprootAddressIndexZeroPayment } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
|
||||
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
|
||||
import { useAppPermissions } from '@app/store/app-permissions/app-permissions.slice';
|
||||
@@ -30,7 +31,7 @@ export function useGetAddresses() {
|
||||
const permissions = useAppPermissions();
|
||||
const { tabId, origin, requestId } = useRpcRequestParams();
|
||||
|
||||
const nativeSegwitAddress = useCurrentAccountNativeSegwitAddressIndexZero();
|
||||
const nativeSegwitSigner = useCurrentAccountNativeSegwitIndexZeroSigner();
|
||||
const taprootPayment = useCurrentAccountTaprootAddressIndexZeroPayment();
|
||||
const stacksAccount = useCurrentStacksAccount();
|
||||
|
||||
@@ -38,12 +39,14 @@ export function useGetAddresses() {
|
||||
symbol: 'BTC',
|
||||
type: 'p2tr',
|
||||
address: taprootPayment.address,
|
||||
publicKey: bytesToHex(taprootPayment.publicKey),
|
||||
};
|
||||
|
||||
const nativeSegwitAddressResponse: BtcAddress = {
|
||||
symbol: 'BTC',
|
||||
type: 'p2wpkh',
|
||||
address: nativeSegwitAddress,
|
||||
address: nativeSegwitSigner.address,
|
||||
publicKey: bytesToHex(nativeSegwitSigner.publicKey),
|
||||
};
|
||||
|
||||
const stacksAddressResponse = {
|
||||
|
||||
@@ -78,7 +78,7 @@ export function useBitcoinScureLibNetworkConfig() {
|
||||
|
||||
interface BitcoinSignerFactoryArgs {
|
||||
accountKeychain: HDKey;
|
||||
paymentFn(keychain: HDKey, network: BitcoinNetworkModes): unknown;
|
||||
paymentFn(keychain: HDKey, network: BitcoinNetworkModes): any;
|
||||
network: BitcoinNetworkModes;
|
||||
}
|
||||
export function bitcoinSignerFactory<T extends BitcoinSignerFactoryArgs>(args: T) {
|
||||
@@ -87,10 +87,23 @@ export function bitcoinSignerFactory<T extends BitcoinSignerFactoryArgs>(args: T
|
||||
const addressIndexKeychain =
|
||||
deriveAddressIndexKeychainFromAccount(accountKeychain)(addressIndex);
|
||||
|
||||
const payment = paymentFn(addressIndexKeychain, network) as ReturnType<T['paymentFn']>;
|
||||
|
||||
const publicKeychain = HDKey.fromExtendedKey(addressIndexKeychain.publicExtendedKey);
|
||||
|
||||
return {
|
||||
network,
|
||||
payment,
|
||||
addressIndex,
|
||||
publicKeychain: HDKey.fromExtendedKey(addressIndexKeychain.publicExtendedKey),
|
||||
payment: paymentFn(addressIndexKeychain, network) as ReturnType<T['paymentFn']>,
|
||||
publicKeychain,
|
||||
get address() {
|
||||
if (!payment.address) throw new Error('Unable to get address from payment');
|
||||
return payment.address;
|
||||
},
|
||||
get publicKey() {
|
||||
if (!publicKeychain.publicKey) throw new Error('Unable to get publicKey from keychain');
|
||||
return publicKeychain.publicKey;
|
||||
},
|
||||
sign(tx: btc.Transaction) {
|
||||
if (!addressIndexKeychain.privateKey)
|
||||
throw new Error('Unable to sign taproot transaction, no private key found');
|
||||
|
||||
@@ -41,10 +41,6 @@ export function useNativeSegwitNetworkSigners() {
|
||||
);
|
||||
}
|
||||
|
||||
function useCurrentAccountNativeSegwitSignerIndexZero() {
|
||||
return useCurrentAccountNativeSegwitSigner()?.(0);
|
||||
}
|
||||
|
||||
function useNativeSegwitSigner(accountIndex: number) {
|
||||
const network = useCurrentNetwork();
|
||||
const accountKeychain = useNativeSegwitActiveNetworkAccountPrivateKeychain()?.(accountIndex);
|
||||
@@ -56,22 +52,38 @@ function useNativeSegwitSigner(accountIndex: number) {
|
||||
network: network.chain.bitcoin.network,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCurrentAccountNativeSegwitSigner() {
|
||||
const currentAccountIndex = useCurrentAccountIndex();
|
||||
return useNativeSegwitSigner(currentAccountIndex);
|
||||
}
|
||||
|
||||
export function useCurrentAccountNativeSegwitAddressIndexZero() {
|
||||
const signer = useCurrentAccountNativeSegwitSignerIndexZero();
|
||||
return signer?.payment.address as string;
|
||||
export function useCurrentAccountNativeSegwitIndexZeroSigner() {
|
||||
const signer = useCurrentAccountNativeSegwitSigner();
|
||||
if (!signer) throw new Error('No signer');
|
||||
return signer(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use signer.address instead
|
||||
*/
|
||||
export function useCurrentAccountNativeSegwitAddressIndexZero() {
|
||||
const signer = useCurrentAccountNativeSegwitSigner();
|
||||
return signer?.(0).payment.address as string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use signer.address instead
|
||||
*/
|
||||
export function useNativeSegwitAccountIndexAddressIndexZero(accountIndex: number) {
|
||||
const signer = useNativeSegwitSigner(accountIndex)?.(0);
|
||||
return signer?.payment.address as string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use signer.publicKeychain directly instead
|
||||
*/
|
||||
export function useCurrentBitcoinNativeSegwitAddressIndexPublicKeychain() {
|
||||
const signer = useCurrentAccountNativeSegwitSignerIndexZero();
|
||||
return signer?.publicKeychain;
|
||||
const signer = useCurrentAccountNativeSegwitSigner();
|
||||
return signer?.(0).publicKeychain;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,12 @@ export function useCurrentAccountTaprootAddressIndexZeroPayment() {
|
||||
const createSigner = useCurrentAccountTaprootSigner();
|
||||
const indexZeroSigner = createSigner?.(0);
|
||||
if (!indexZeroSigner?.payment.address) throw new Error('No address found');
|
||||
const publicKey = indexZeroSigner.publicKeychain.publicKey;
|
||||
if (!publicKey) throw new Error('No public key found');
|
||||
// Creating new object to have known property types
|
||||
return { address: indexZeroSigner.payment.address, type: indexZeroSigner.payment.type };
|
||||
return {
|
||||
address: indexZeroSigner.payment.address,
|
||||
publicKey,
|
||||
type: indexZeroSigner.payment.type,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user