This repository has been archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-cargo
executable file
·72 lines (68 loc) · 2.28 KB
/
generate-cargo
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
67
68
69
70
71
72
#!/usr/bin/env node
'use strict';
// This is a proof of concept. The code below is ugly, inefficient and has no tests.
const assert = require('assert');
const fs = require('fs');
const yargs = require('yargs');
const {CARGO_SERIALIZER, serializeCargoPayload} = require('../core/serialization');
async function main(argv) {
const parcelPaths = argv.parcel || [];
assert(parcelPaths.length, 'One or more parcels must be passed');
const parcels = parcelPaths.map(p => fs.readFileSync(p));
process.stdout.write(await CARGO_SERIALIZER.serialize(
serializeCargoPayload(...parcels),
argv.recipientCert,
fs.readFileSync(argv.senderCert),
argv.senderKey,
argv.signHashAlgo,
argv.id,
argv.date && new Date(argv.date * 1000),
argv.ttl,
));
}
function configureArgs(builder) {
builder
.option('recipient-cert', {
demandOption: true,
requiresArg: true,
description: "The recipient's X.509 certificate (chain), PEM-encoded",
normalize: true,
})
.option('sender-cert', {
demandOption: true,
requiresArg: true,
description: "The sender's X.509 certificate (chain), PEM-encoded",
normalize: true,
})
.option('sender-key', {
demandOption: true,
requiresArg: true,
description: "The sender's X.509 key (PEM-encoded) to sign the message",
normalize: true,
})
.option('sign-hash-algo', {
requiresArg: true,
description: 'The hashing algorithm to use in the signature',
})
.option('id', {
requiresArg: true,
description: "The cargo's unique id",
})
.option('date', {
requiresArg: true,
description: "The cargo's creation timestamp in UTC (defaults to now)",
})
.option('ttl', {
requiresArg: true,
description: "The cargo's TTL in seconds (defaults to 0)",
type: 'number',
})
.normalize('parcel')
;
}
// noinspection BadExpressionStatementJS
yargs
.command('$0 [parcel..]', 'Generate cargo', configureArgs, main) // noinspection JSUnresolvedFunction
.strict()
.help()
.argv;