-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
executable file
·52 lines (36 loc) · 1.76 KB
/
example.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
import Gun from "gun";
import 'gun/lib/path.js';
import 'gun/lib/load.js';
import 'gun/lib/open.js';
import 'gun/lib/then.js';
const gun = Gun({ file: 'scopetest' });
(async () => {
console.clear();
await import('./build/index.js')
gun.scope(['src/*', 'img/*'], () => { }, { verbose: false, alias: 'bresnow', encoding: 'latin1' });
gun.unpack({ alias: 'bresnow', encoding: 'latin1' })
// Generate your keys with a string or array of strings.
// If no salt string is provided then immutable os data (username, platform, & arch) is used.
let keypair = await gun.keys(['username', 'password', 'another_secret', 'we can do this all day']);
console.log("SEA KEYPAIR \n", keypair);
// Here we start our vault context
let vault = gun.vault('VaultContextName', keypair)
// Here we start our chain. The keys stay in the vault context encrypting/decrypting when using the /
// .locker() && .value() methods.
// .locker method takes the path to the node as an array or a string separated by a solidus '/' or period '.'
let locker = gun
.locker(['newvault', 'test', 'path', 'to', 'node'])
// .put method takes the data object to be stored and a callback function is optionally passed to verify the put
// Data is automically encrypted and compressed.
locker
.put({ Lemon: 'Orange', Apple: 'Banana', Orange: 'Apple' });
//
// // .value method takes a callback function to return the decoded data
locker.value((data) => {
console.log("NODE DATA \n", data);
})
// Here we can see the data is encrypted and compressed at the specified node location.
vault.get('newvault').get('test').get('path').get('to').get('node').once((data) => {
console.log("NODE DATA 2 \n", data);
})
})()