Add stricter Signer interface check
This commit is contained in:
parent
969b3a5e18
commit
053d282e9d
5 changed files with 19 additions and 2 deletions
|
@ -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,
|
||||
]);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
]);
|
||||
|
|
|
@ -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
1
types/types.d.ts
vendored
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue