mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
fix: required allowedSighash
This commit is contained in:
@@ -20,7 +20,7 @@ export function usePsbtSigner() {
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
signPsbtAtIndex(allowedSighash: btc.SignatureHash[], idx: number, tx: btc.Transaction) {
|
||||
signPsbtAtIndex(idx: number, tx: btc.Transaction, allowedSighash?: btc.SignatureHash[]) {
|
||||
try {
|
||||
nativeSegwitSigner?.signIndex(tx, idx, allowedSighash);
|
||||
} catch (e1) {
|
||||
|
||||
@@ -47,8 +47,8 @@ export function usePsbtRequest() {
|
||||
const indexOrIndexes = payload?.signAtIndex;
|
||||
const allowedSighash = payload?.allowedSighash;
|
||||
|
||||
if (!isUndefined(indexOrIndexes) && !isUndefined(allowedSighash)) {
|
||||
ensureArray(indexOrIndexes).forEach(idx => signPsbtAtIndex(allowedSighash, idx, tx));
|
||||
if (!isUndefined(indexOrIndexes)) {
|
||||
ensureArray(indexOrIndexes).forEach(idx => signPsbtAtIndex(idx, tx, allowedSighash));
|
||||
} else {
|
||||
signPsbt(tx);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ function useRpcSignPsbt() {
|
||||
return getDecodedPsbt(psbtHex);
|
||||
},
|
||||
onSignPsbt() {
|
||||
if (!isUndefined(signAtIndex) && !isUndefined(allowedSighash)) {
|
||||
if (!isUndefined(signAtIndex)) {
|
||||
signAtIndex.forEach(idx => {
|
||||
signPsbtAtIndex(allowedSighash, idx, tx);
|
||||
signPsbtAtIndex(idx, tx, allowedSighash);
|
||||
});
|
||||
} else {
|
||||
signPsbt(tx);
|
||||
|
||||
@@ -69,8 +69,8 @@ export async function rpcSignPsbt(message: SignPsbtRequest, port: chrome.runtime
|
||||
}
|
||||
|
||||
if (isDefined(message.params.allowedSighash))
|
||||
ensureArray(message.params.allowedSighash).forEach(hash =>
|
||||
requestParams.push(['allowedSighash', hash.toString()])
|
||||
message.params.allowedSighash.forEach(hash =>
|
||||
requestParams.push(['allowedSighash', (hash ?? btc.SignatureHash.ALL).toString()])
|
||||
);
|
||||
|
||||
if (isDefined(message.params.signAtIndex))
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { DefineRpcMethod, RpcRequest, RpcResponse } from '@btckit/types';
|
||||
import * as btc from '@scure/btc-signer';
|
||||
import * as yup from 'yup';
|
||||
|
||||
import { networkModes } from '@shared/constants';
|
||||
import { isDefined, isNumber, isUndefined } from '@shared/utils';
|
||||
import { isNumber, isUndefined } from '@shared/utils';
|
||||
|
||||
function testIsNumberOrArrayOfNumbers(value: unknown) {
|
||||
if (isUndefined(value)) return true;
|
||||
@@ -12,14 +13,7 @@ function testIsNumberOrArrayOfNumbers(value: unknown) {
|
||||
|
||||
const rpcSignPsbtValidator = yup.object().shape({
|
||||
publicKey: yup.string().required(),
|
||||
allowedSighash: yup.mixed<number | number[]>().when('signAtIndex', {
|
||||
is: (signAtIndex: unknown) => isDefined(signAtIndex),
|
||||
then: schema =>
|
||||
schema
|
||||
.test(testIsNumberOrArrayOfNumbers)
|
||||
.required('allowedSighash required when signAtIndex is provided'),
|
||||
otherwise: schema => schema.test(testIsNumberOrArrayOfNumbers),
|
||||
}),
|
||||
allowedSighash: yup.array().of(yup.mixed().oneOf(Object.values(btc.SignatureHash))),
|
||||
hex: yup.string().required(),
|
||||
signAtIndex: yup.mixed<number | number[]>().test(testIsNumberOrArrayOfNumbers),
|
||||
network: yup.string().oneOf(networkModes),
|
||||
|
||||
Reference in New Issue
Block a user