This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
135 lines (121 loc) · 5.82 KB
/
cli.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/************************************************************************
* Copyright (c) Crater Dog Technologies(TM). All Rights Reserved. *
************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
* *
* This code is free software; you can redistribute it and/or modify it *
* under the terms of The MIT License (MIT), as published by the Open *
* Source Initiative. (See http://opensource.org/licenses/MIT) *
************************************************************************/
const debug = 0;
const crypto = require('crypto');
const bali = require('bali-component-framework').api(debug);
const account = bali.tag();
const directory = 'test/config/';
const proxy = require('./').proxy(directory, debug);
const notary = require('bali-digital-notary').notary(proxy, account, directory, debug);
exports.cli = function() {
return {
transaction: bali.catalog({
$timestamp: bali.moment(),
$consumer: bali.text('Derk Norton'),
$account: account,
$merchant: bali.reference('https://www.starbucks.com/'),
$amount: 4.95
}, {
$type: '/acme/types/Transaction/v1',
$tag: bali.tag(),
$version: bali.version(),
$permissions: '/bali/permissions/public/v1',
$previous: bali.pattern.NONE
}),
certificate: undefined,
citation: undefined,
document: undefined,
getProtocols: function() {
const protocols = notary.getProtocols();
console.log('The protocols include: ' + protocols);
},
getCitation: function() {
notary.getCitation().then(function(citation) {
console.log('The certificate citation is: ' + citation);
}).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
forgetKey: function() {
notary.forgetKey().then(function() {
console.log('The key was forgotten.');
this.certificate = undefined;
this.citation = undefined;
this.document = undefined;
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
generateKey: function() {
notary.generateKey().then(function(publicKey) {
notary.notarizeDocument(publicKey).then(function(certificate) {
console.log('The notary certificate is: ' + certificate);
this.certificate = certificate;
notary.activateKey(certificate).then(function(citation) {
console.log('The certificate citation is: ' + citation);
this.citation = citation;
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
refreshKey: function() {
notary.refreshKey().then(function(certificate) {
console.log('The new notarized certificate is: ' + certificate);
this.certificate = certificate;
notary.citeDocument(certificate).then(function(citation) {
console.log('The new certificate citation is: ' + citation);
this.citation = citation;
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
notarizeDocument: function(catalog) {
notary.notarizeDocument(catalog).then(function(document) {
console.log('The notarized document is: ' + document);
this.document = document;
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
validContract: function(document) {
const certificate = this.certificate.getValue('$content');
notary.validContract(document, certificate).then(function(isValid) {
console.log('The document is ' + (isValid ? '' : 'not ') + 'valid');
}).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
citeDocument: function(document) {
const certificate = this.certificate.getValue('$content');
notary.citeDocument(document).then(function(citation) {
console.log('The document citation is: ' + citation);
this.citation = citation;
}.bind(this)).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
},
citationMatches: function(citation, document) {
notary.citationMatches(citation, document).then(function(matches) {
console.log('The citation ' + (matches ? 'matches.' : 'does not match.'));
}).catch(function(exception) {
console.error('Received the following exception: ' + exception);
});
}
};
};