Add stricter Signer interface check

This commit is contained in:
junderw 2019-06-13 13:32:21 +09:00
commit 053d282e9d
No known key found for this signature in database
GPG key ID: B256185D3A971908
5 changed files with 19 additions and 2 deletions

View file

@ -166,7 +166,7 @@ class TransactionBuilder {
`Unknown prevOutScriptType "${signParams.prevOutScriptType}"`,
);
}
typeforce(typeforce.tuple(typeforce.Number, typeforce.Object), [
typeforce(typeforce.tuple(typeforce.Number, types.Signer), [
signParams.vin,
signParams.keyPair,
]);

View file

@ -13,6 +13,14 @@ exports.BIP32Path = BIP32Path;
BIP32Path.toJSON = () => {
return 'BIP32 derivation path';
};
function Signer(obj) {
return (
(typeforce.Buffer(obj.publicKey) ||
typeof obj.getPublicKey === 'function') &&
typeof obj.sign === 'function'
);
}
exports.Signer = Signer;
const SATOSHI_MAX = 21 * 1e14;
function Satoshi(value) {
return typeforce.UInt53(value) && value <= SATOSHI_MAX;