Skip to content

Commit

Permalink
Removing p2s check by address, because input.address is not availab…
Browse files Browse the repository at this point in the history
…le at the moment (input is only a tx output pointer)
  • Loading branch information
vsubhuman committed Jan 26, 2022
1 parent 5be1509 commit 56e12d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 33 deletions.
Expand Up @@ -519,19 +519,23 @@ function extractWalletPkFromHexConstant(hexConstant: string): ?string {

export function extractP2sKeysFromErgoBox(box: ErgoBoxJson): Set<string> {
const res = new Set();
const tree = RustModule.SigmaRust.ErgoTree.from_base16_bytes(box.ergoTree);
const constantsLen = tree.constants_len();
for (let i = 0; i < constantsLen; i++) {
const hex = tree.get_constant(i).encode_to_base16();
const walletPk: ?string = extractWalletPkFromHexConstant(hex);
if (walletPk != null) {
res.add(walletPk);
if (box.ergoTree != null && box.ergoTree.length > 0) {
const tree = RustModule.SigmaRust.ErgoTree.from_base16_bytes(box.ergoTree);
const constantsLen = tree.constants_len();
for (let i = 0; i < constantsLen; i++) {
const hex = tree.get_constant(i).encode_to_base16();
const walletPk: ?string = extractWalletPkFromHexConstant(hex);
if (walletPk != null) {
res.add(walletPk);
}
}
}
for (const registerHex of Object.values(box.additionalRegisters||{})) {
const walletPk: ?string = extractWalletPkFromHexConstant(registerHex);
if (walletPk != null) {
res.add(walletPk);
if (box.additionalRegisters != null) {
for (const registerHex of Object.values(box.additionalRegisters)) {
const walletPk: ?string = extractWalletPkFromHexConstant(registerHex);
if (walletPk != null) {
res.add(walletPk);
}
}
}
return res;
Expand Down
37 changes: 15 additions & 22 deletions packages/yoroi-extension/chrome/extension/ergo-connector/api.js
Expand Up @@ -477,30 +477,23 @@ export async function connectorSignTx(
debug('signing', 'UTxO found, regular signature');
inputSigningKeys.add(generateKey({ addressing: utxo, keyLevel, signingKey }));
} else {
debug('signing', 'No UTxO found! Checking if input is P2S');
const isP2S =
S.Address.from_base58(input.address).address_type_prefix() ===
S.AddressTypePrefix.Pay2S;
if (isP2S) {
const matchingAddressMap = await p2sExtractor(input);
const matchedAddresses = Object.values(matchingAddressMap);
if (matchedAddresses.length > 0) {
if (matchedAddresses.some(x => !x)) {
const emptyKeys = Object.entries(matchingAddressMap)
.filter(([, v]) => !v)
.map(([k]) => k);
throw new Error(
`Input ${inputId} is a P2S, but no matching address is found
debug('signing', 'No UTxO found! Checking if input needs some P2S signatures');
const matchingAddressMap = await p2sExtractor(input);
const matchedAddresses = Object.values(matchingAddressMap);
if (matchedAddresses.length > 0) {
if (matchedAddresses.some(x => !x)) {
const emptyKeys = Object.entries(matchingAddressMap)
.filter(([, v]) => !v)
.map(([k]) => k);
throw new Error(
`Input ${inputId} is a P2S, but no matching address are found
for these keys: ${JSON.stringify(emptyKeys)}`
);
}
debug('signing', 'Input is a P2S with matching addresses:', Array.from(matchedAddresses));
matchedAddresses.forEach(({ fullAddress }) => {
inputSigningKeys.add(generateKey({ addressing: fullAddress, keyLevel, signingKey }));
});
);
}
} else {
throw new Error(`Input ${inputId} is not recognised! No matching UTxO found and is not P2S!`)
debug('signing', 'Input is a P2S with matching addresses:', Array.from(matchedAddresses));
matchedAddresses.forEach(({ fullAddress }) => {
inputSigningKeys.add(generateKey({ addressing: fullAddress, keyLevel, signingKey }));
});
}
}
}
Expand Down

0 comments on commit 56e12d8

Please sign in to comment.