Skip to content

Commit

Permalink
Merge pull request #5281 from BitGo/BTC-1450.impl-getKeySignatures
Browse files Browse the repository at this point in the history
feat(abstract-utxo): add getKeySignatures function
  • Loading branch information
OttoAllmendinger authored Dec 16, 2024
2 parents 29d3d55 + cbbf6e3 commit 35fdca6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion modules/abstract-utxo/src/keychains.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import assert from 'assert';
import * as t from 'io-ts';
import * as utxolib from '@bitgo/utxo-lib';
import { IRequestTracer, IWallet, KeyIndices, promiseProps, Triple } from '@bitgo/sdk-core';

import { AbstractUtxoCoin } from './abstractUtxoCoin';
import assert from 'assert';
import { UtxoWallet } from './wallet';

/*
Expand Down Expand Up @@ -64,3 +65,17 @@ export async function fetchKeychains(
assert(UtxoNamedKeychains.is(result));
return result;
}

export const KeySignatures = t.partial({
backupPub: t.string,
bitgoPub: t.string,
});

export type KeySignatures = t.TypeOf<typeof KeySignatures>;

export function getKeySignatures(wallet: UtxoWallet): KeySignatures | undefined {
if (t.partial({ keySignatures: KeySignatures }).is(wallet._wallet)) {
return wallet._wallet.keySignatures;
}
return undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ParsedTransaction,
ParseTransactionOptions,
} from '../../abstractUtxoCoin';
import { fetchKeychains, toKeychainTriple, UtxoKeychain, UtxoNamedKeychains } from '../../keychains';
import { fetchKeychains, getKeySignatures, toKeychainTriple, UtxoKeychain, UtxoNamedKeychains } from '../../keychains';

/**
* @param first
Expand Down Expand Up @@ -206,7 +206,7 @@ export async function parseTransaction<TNumber extends bigint | number>(

return {
keychains,
keySignatures: _.get(wallet, '_wallet.keySignatures', {}),
keySignatures: getKeySignatures(wallet) ?? {},
outputs: allOutputDetails,
missingOutputs,
explicitExternalOutputs,
Expand Down

0 comments on commit 35fdca6

Please sign in to comment.