mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-04-28 20:55:30 +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
|
# provides a virtual X display server to the process it runs, allowing
|
||||||
# processes that require a display server to run in environments where
|
# processes that require a display server to run in environments where
|
||||||
# one is not available.
|
# 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
|
- uses: actions/upload-artifact@v3
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
import { BtcAddress } from '@btckit/types';
|
import { BtcAddress } from '@btckit/types';
|
||||||
|
import { bytesToHex } from '@stacks/common';
|
||||||
|
|
||||||
import { logger } from '@shared/logger';
|
import { logger } from '@shared/logger';
|
||||||
import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';
|
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 { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
|
||||||
import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-search-params';
|
import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-search-params';
|
||||||
import { initialSearchParams } from '@app/common/initial-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 { useCurrentAccountTaprootAddressIndexZeroPayment } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
|
||||||
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
|
import { useCurrentStacksAccount } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';
|
||||||
import { useAppPermissions } from '@app/store/app-permissions/app-permissions.slice';
|
import { useAppPermissions } from '@app/store/app-permissions/app-permissions.slice';
|
||||||
@@ -30,7 +31,7 @@ export function useGetAddresses() {
|
|||||||
const permissions = useAppPermissions();
|
const permissions = useAppPermissions();
|
||||||
const { tabId, origin, requestId } = useRpcRequestParams();
|
const { tabId, origin, requestId } = useRpcRequestParams();
|
||||||
|
|
||||||
const nativeSegwitAddress = useCurrentAccountNativeSegwitAddressIndexZero();
|
const nativeSegwitSigner = useCurrentAccountNativeSegwitIndexZeroSigner();
|
||||||
const taprootPayment = useCurrentAccountTaprootAddressIndexZeroPayment();
|
const taprootPayment = useCurrentAccountTaprootAddressIndexZeroPayment();
|
||||||
const stacksAccount = useCurrentStacksAccount();
|
const stacksAccount = useCurrentStacksAccount();
|
||||||
|
|
||||||
@@ -38,12 +39,14 @@ export function useGetAddresses() {
|
|||||||
symbol: 'BTC',
|
symbol: 'BTC',
|
||||||
type: 'p2tr',
|
type: 'p2tr',
|
||||||
address: taprootPayment.address,
|
address: taprootPayment.address,
|
||||||
|
publicKey: bytesToHex(taprootPayment.publicKey),
|
||||||
};
|
};
|
||||||
|
|
||||||
const nativeSegwitAddressResponse: BtcAddress = {
|
const nativeSegwitAddressResponse: BtcAddress = {
|
||||||
symbol: 'BTC',
|
symbol: 'BTC',
|
||||||
type: 'p2wpkh',
|
type: 'p2wpkh',
|
||||||
address: nativeSegwitAddress,
|
address: nativeSegwitSigner.address,
|
||||||
|
publicKey: bytesToHex(nativeSegwitSigner.publicKey),
|
||||||
};
|
};
|
||||||
|
|
||||||
const stacksAddressResponse = {
|
const stacksAddressResponse = {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function useBitcoinScureLibNetworkConfig() {
|
|||||||
|
|
||||||
interface BitcoinSignerFactoryArgs {
|
interface BitcoinSignerFactoryArgs {
|
||||||
accountKeychain: HDKey;
|
accountKeychain: HDKey;
|
||||||
paymentFn(keychain: HDKey, network: BitcoinNetworkModes): unknown;
|
paymentFn(keychain: HDKey, network: BitcoinNetworkModes): any;
|
||||||
network: BitcoinNetworkModes;
|
network: BitcoinNetworkModes;
|
||||||
}
|
}
|
||||||
export function bitcoinSignerFactory<T extends BitcoinSignerFactoryArgs>(args: T) {
|
export function bitcoinSignerFactory<T extends BitcoinSignerFactoryArgs>(args: T) {
|
||||||
@@ -87,10 +87,23 @@ export function bitcoinSignerFactory<T extends BitcoinSignerFactoryArgs>(args: T
|
|||||||
const addressIndexKeychain =
|
const addressIndexKeychain =
|
||||||
deriveAddressIndexKeychainFromAccount(accountKeychain)(addressIndex);
|
deriveAddressIndexKeychainFromAccount(accountKeychain)(addressIndex);
|
||||||
|
|
||||||
|
const payment = paymentFn(addressIndexKeychain, network) as ReturnType<T['paymentFn']>;
|
||||||
|
|
||||||
|
const publicKeychain = HDKey.fromExtendedKey(addressIndexKeychain.publicExtendedKey);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
network,
|
||||||
|
payment,
|
||||||
addressIndex,
|
addressIndex,
|
||||||
publicKeychain: HDKey.fromExtendedKey(addressIndexKeychain.publicExtendedKey),
|
publicKeychain,
|
||||||
payment: paymentFn(addressIndexKeychain, network) as ReturnType<T['paymentFn']>,
|
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) {
|
sign(tx: btc.Transaction) {
|
||||||
if (!addressIndexKeychain.privateKey)
|
if (!addressIndexKeychain.privateKey)
|
||||||
throw new Error('Unable to sign taproot transaction, no private key found');
|
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) {
|
function useNativeSegwitSigner(accountIndex: number) {
|
||||||
const network = useCurrentNetwork();
|
const network = useCurrentNetwork();
|
||||||
const accountKeychain = useNativeSegwitActiveNetworkAccountPrivateKeychain()?.(accountIndex);
|
const accountKeychain = useNativeSegwitActiveNetworkAccountPrivateKeychain()?.(accountIndex);
|
||||||
@@ -56,22 +52,38 @@ function useNativeSegwitSigner(accountIndex: number) {
|
|||||||
network: network.chain.bitcoin.network,
|
network: network.chain.bitcoin.network,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCurrentAccountNativeSegwitSigner() {
|
export function useCurrentAccountNativeSegwitSigner() {
|
||||||
const currentAccountIndex = useCurrentAccountIndex();
|
const currentAccountIndex = useCurrentAccountIndex();
|
||||||
return useNativeSegwitSigner(currentAccountIndex);
|
return useNativeSegwitSigner(currentAccountIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCurrentAccountNativeSegwitAddressIndexZero() {
|
export function useCurrentAccountNativeSegwitIndexZeroSigner() {
|
||||||
const signer = useCurrentAccountNativeSegwitSignerIndexZero();
|
const signer = useCurrentAccountNativeSegwitSigner();
|
||||||
return signer?.payment.address as string;
|
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) {
|
export function useNativeSegwitAccountIndexAddressIndexZero(accountIndex: number) {
|
||||||
const signer = useNativeSegwitSigner(accountIndex)?.(0);
|
const signer = useNativeSegwitSigner(accountIndex)?.(0);
|
||||||
return signer?.payment.address as string;
|
return signer?.payment.address as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use signer.publicKeychain directly instead
|
||||||
|
*/
|
||||||
export function useCurrentBitcoinNativeSegwitAddressIndexPublicKeychain() {
|
export function useCurrentBitcoinNativeSegwitAddressIndexPublicKeychain() {
|
||||||
const signer = useCurrentAccountNativeSegwitSignerIndexZero();
|
const signer = useCurrentAccountNativeSegwitSigner();
|
||||||
return signer?.publicKeychain;
|
return signer?.(0).publicKeychain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ export function useCurrentAccountTaprootAddressIndexZeroPayment() {
|
|||||||
const createSigner = useCurrentAccountTaprootSigner();
|
const createSigner = useCurrentAccountTaprootSigner();
|
||||||
const indexZeroSigner = createSigner?.(0);
|
const indexZeroSigner = createSigner?.(0);
|
||||||
if (!indexZeroSigner?.payment.address) throw new Error('No address found');
|
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
|
// 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