Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add stricter Signer interface check
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Jun 13, 2019
1 parent 969b3a5 commit 053d282
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/transaction_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
8 changes: 8 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ts_src/transaction_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
Expand Down
8 changes: 8 additions & 0 deletions ts_src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 053d282

Please sign in to comment.