-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtypes.js
More file actions
66 lines (58 loc) · 1.7 KB
/
Copy pathtypes.js
File metadata and controls
66 lines (58 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const typeforce = require('typeforce');
// it's some sorta strange, but i saw 31 byte length keys
function PrivateKey(value) {
if (!typeforce.String(value)) {
if (!typeforce.Buffer(value)) {
return false;
} else {
return value.length >= 31 || value.length <= 32;
}
} else {
return value.length >= 62 || value.length <= 64;
}
}
function PublicKey(value) {
if (!typeforce.String(value)) {
if (!typeforce.Buffer(value)) {
return false;
} else {
return value.length === 33;
}
} else {
return value.length === 66;
}
}
function Empty(value) {
return value === undefined;
}
function Str64(value) {
return typeof value === 'string' && value.length === 64;
}
function Str40(value) {
return typeof value === 'string' && value.length === 40;
}
function Amount(value) {
return typeof value === 'number';
}
const Hash256bit = typeforce.oneOf(typeforce.BufferN(32), Str64);
module.exports = {
Str64,
Buf32: typeforce.BufferN(32),
Hash256bit,
Address: typeforce.oneOf(typeforce.BufferN(20), Str40),
StrAddress: Str40,
PrivateKey,
PublicKey,
Empty,
InvVector: typeforce.compile({type: 'Number', hash: Hash256bit}),
Coins: typeforce.quacksLike('Coins'),
Contract: typeforce.quacksLike('Contract'),
Patch: typeforce.quacksLike('PatchDB'),
Block: typeforce.quacksLike('Block'),
BlockInfo: typeforce.quacksLike('BlockInfo'),
Transaction: typeforce.quacksLike('Transaction'),
UTXO: typeforce.quacksLike('UTXO'),
Amount,
Signature: typeforce.BufferN(65),
Input: typeforce.compile({nTxOutput: 'Number', txHash: Hash256bit})
};