UNPKG

1 kBPlain TextView Raw
1#!/usr/bin/env node
2
3'use strict'
4
5var eccrypto = require('eccrypto')
6
7var command = process.argv[0]
8var script = process.argv[1]
9var private_key = process.argv[2]
10var public_key = process.argv[3]
11
12if (!(private_key && public_key)) {
13 return process.stdout.write(JSON.stringify({
14 error: 'private key or public key not given'
15 }), function() {
16 process.exit(1)
17 })
18}
19
20var pka, pkb
21
22try {
23 pka = Buffer(private_key, 'hex')
24 pkb = Buffer(public_key, 'hex')
25} catch (err) {
26 return process.stdout.write(JSON.stringify({
27 error: 'public key, message or signature is not a hexadecimal string'
28 }), function() {
29 process.exit(1)
30 })
31}
32
33eccrypto.derive(pka, pkb).then(function(shared_secret) {
34 process.stdout.write(JSON.stringify({
35 shared_secret: shared_secret.toString('hex')
36 }), function() {
37 process.exit(0)
38 })
39}).catch(function(err) {
40 process.stdout.write(JSON.stringify({
41 eccrypto_error: JSON.stringify(err || true)
42 }), function() {
43 process.exit(1)
44 })
45})