-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
53 lines (41 loc) · 1.79 KB
/
main.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
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
const author = require('./author');
const subscriber = require('./subscriber');
async function main() {
// Step 1: Create author with new seed
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 1');
let authorInstance = await author.createAuthor();
// Step 2: Send channel announcement
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 2');
await author.announceChannel(authorInstance.clone());
// Step 3: Create subscriber with new seed
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 3');
let subscriberInstance = await subscriber.createSubscriber();
// Step 4: Receive channel announcement and send subscription message
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 4');
await subscriber.subscribeChannel(subscriberInstance.clone());
// Step 5: Receive channel subscription
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 5');
await author.receiveSubscription(authorInstance.clone());
// Step 6: Syncronize channel state and send tagged packet
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 6');
await subscriber.sendTaggedPacket(subscriberInstance.clone());
// Step 7: Fetch new messages
console.log('\n');
console.log('\x1b[36m%s\x1b[0m', 'Step 7');
await author.fetchNewMessages(authorInstance.clone());
// Step 8: Send multiple signed packets
console.log('\x1b[36m%s\x1b[0m', 'Step 8');
await subscriber.sendMultipleSignedPackets(subscriberInstance.clone());
// Step 9: Fetch new messages
console.log('\x1b[36m%s\x1b[0m', 'Step 9');
await author.fetchNewMessages(authorInstance.clone());
}
main()