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-parcel
executable file
·81 lines (75 loc) · 2.4 KB
/
generate-parcel
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
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
'use strict';
// This is a proof of concept. The code below is ugly, inefficient and has no tests.
const fs = require('fs');
const yargs = require('yargs');
const {PARCEL_SERIALIZER, serializeServiceMessage} = require('../core/serialization');
const {ServiceMessage} = require('../core/messages');
async function main(argv) {
const messageSerialized = fs.readFileSync(process.stdin.fd);
let parcelSerialized;
try {
parcelSerialized = await PARCEL_SERIALIZER.serialize(
serializeServiceMessage(new ServiceMessage(messageSerialized, argv.type)),
argv.recipientCert,
fs.readFileSync(argv.senderCert),
argv.senderKey,
argv.signHashAlgo,
argv.id,
argv.date && new Date(argv.date * 1000),
argv.ttl,
);
} catch (error) {
console.error('Uncaught exception when serializing parcel:');
console.error(error);
return 1;
}
process.stdout.write(parcelSerialized);
}
const argv = yargs
.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('type', {
demandOption: true,
requiresArg: true,
description: "The media type of the input message (e.g., application/json)",
normalize: true,
})
.option('sign-hash-algo', {
requiresArg: true,
description: 'The hashing algorithm to use in the signature',
})
.option('id', {
requiresArg: true,
description: "The parcel's unique id",
})
.option('date', {
requiresArg: true,
description: "The parcel's creation timestamp in UTC (defaults to now)",
type: 'number',
})
.option('ttl', {
requiresArg: true,
description: "The parcel's TTL in seconds (defaults to 0)",
type: 'number',
})
.strict()
.help()
.argv;
(async () => await main(argv))();