12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- var SEA = require('./sea');
- var Gun = SEA.Gun;
-
- const queryGunAliases = (alias, gunRoot) => new Promise((resolve, reject) => {
-
- gunRoot.get('~@'+alias).once((data, key) => {
-
- if (!data) {
-
- const err = 'No user!'
- Gun.log(err)
- return reject({ err })
- }
-
- const aliases = []
- let c = 0
-
- Gun.obj.map(data, (at, pub) => {
- if (!pub.slice || '~' !== pub.slice(0, 1)) {
-
- return
- }
- ++c
-
- gunRoot.get(pub).once(data => {
- pub = pub.slice(1)
- --c
- if (data){
- aliases.push({ pub, put: data })
- }
- if (!c && (c = -1)) {
- resolve(aliases)
- }
- })
- })
- if (!c) {
- reject({ err: 'Public key does not exist!' })
- }
- })
- })
- module.exports = queryGunAliases
-
|