Add stricter Signer interface check

This commit is contained in:
junderw 2019-06-13 13:32:21 +09:00
parent 969b3a5e18
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;

View file

@ -256,7 +256,7 @@ export 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

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

1
types/types.d.ts vendored
View file

@ -3,6 +3,7 @@ export declare function BIP32Path(value: string): boolean;
export declare namespace BIP32Path {
var toJSON: () => string;
}
export declare function Signer(obj: any): boolean;
export declare function Satoshi(value: number): boolean;
export declare const ECPoint: any;
export declare const Network: any;