mirror of
https://github.com/amark/gun.git
synced 2026-03-19 06:39:10 +00:00
* Thank you Murage Martin @murageyun for donating!!! * Fix opt.s3.fakes3 parsing issue (#1318) * Fix opt.s3.fakes3 parsing issue * Fix second typo within if block * Support variable number of auth retry attempts through opt.retries (#1325) Maintain default to 9 to ensure backwards compatibility * Thanks Jason Stallings @octalmage !!! * Remove unused imports (#1337) * Update README.md * yay format change * encode objects * WS ws.path fix (#1343) * Update wire.js * Update wire.js * Update wire.js * add one click deploy to readme (#1342) * update src/index (#1254) * update src/index * update * src/index fix * added src/core * is ??? this a MVP of book & rad ???? thanks to @rogowski * book & rad APIs stabilizing * RAD & Book promoted! + buggy example: test/rad/book.html * bump path * cleaned up Book results & sorting & caching * sea blobs! (#1353) * sea blobs! * and null origins * null fix * null check is last * add a way to select stats file from url (#1351) * react-native detection, and load needed shims (#1349) * react-native detection * added lib mobile * changed back to gun. for another solution * have unbuild function wrap to prevent scope leaks & allow RETURN hehehe so I can reject @bmatusiak 's lS change O:) O:) I love you you're a hero! later with @bmatusiak check sea.then for '../gun.js' vs '../' vs ... note: src/index -> core.js TODO: something about WebRTC candidates hitting ack decrement limits? * quick-fix (#1355) * Fix SEA certificate verification, allow multiple pubs (#1358) * Create SECURITY.md (#1364) * ... works (#1357) * Loading fix (#1356) * does this load better * check window.Gun too in rfs * update SECURITY.md file and change the versions to 0.2020.x (#1365) * webrtc accept getUserMedia streams as peer * Check atom exists in graph when deciding to read from disk (#1371) * fix: ERROR: Radisk needs `store.put` interface (#1374) * Update STUN servers (#1381) Commented out sipgate.net STUN server. Added Cloudflare STUN server. * universal notification system --------- Co-authored-by: ritchia1 <andrew.ritchie@estimateone.com> Co-authored-by: Anton <dev@atjn.dk> Co-authored-by: Bradley Matusiak <bmatusiak@gmail.com> Co-authored-by: Jay Byoun <jay8061@pm.me> Co-authored-by: mimiza <dev@mimiza.com> Co-authored-by: Simardeep Singh <1003simar@gmail.com> Co-authored-by: Malcolm Blaney <mblaney@gmail.com> Co-authored-by: Andreas Heissenberger <andreas@heissenberger.at> Co-authored-by: carlin978 <120719190+carlin978@users.noreply.github.com>
74 lines
4.3 KiB
JavaScript
74 lines
4.3 KiB
JavaScript
;(function(){
|
|
|
|
var SEA = require('./root');
|
|
// This is to certify that a group of "certificants" can "put" anything at a group of matched "paths" to the certificate authority's graph
|
|
SEA.certify = SEA.certify || (async (certificants, policy = {}, authority, cb, opt = {}) => { try {
|
|
/*
|
|
The Certify Protocol was made out of love by a Vietnamese code enthusiast. Vietnamese people around the world deserve respect!
|
|
IMPORTANT: A Certificate is like a Signature. No one knows who (authority) created/signed a cert until you put it into their graph.
|
|
"certificants": '*' or a String (Bob.pub) || an Object that contains "pub" as a key || an array of [object || string]. These people will have the rights.
|
|
"policy": A string ('inbox'), or a RAD/LEX object {'*': 'inbox'}, or an Array of RAD/LEX objects or strings. RAD/LEX object can contain key "?" with indexOf("*") > -1 to force key equals certificant pub. This rule is used to check against soul+'/'+key using Gun.text.match or String.match.
|
|
"authority": Key pair or priv of the certificate authority.
|
|
"cb": A callback function after all things are done.
|
|
"opt": If opt.expiry (a timestamp) is set, SEA won't sync data after opt.expiry. If opt.block is set, SEA will look for block before syncing.
|
|
*/
|
|
console.log('SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version.')
|
|
|
|
certificants = (() => {
|
|
var data = []
|
|
if (certificants) {
|
|
if ((typeof certificants === 'string' || Array.isArray(certificants)) && certificants.indexOf('*') > -1) return '*'
|
|
if (typeof certificants === 'string') return certificants
|
|
if (Array.isArray(certificants)) {
|
|
if (certificants.length === 1 && certificants[0]) return typeof certificants[0] === 'object' && certificants[0].pub ? certificants[0].pub : typeof certificants[0] === 'string' ? certificants[0] : null
|
|
certificants.map(certificant => {
|
|
if (typeof certificant ==='string') data.push(certificant)
|
|
else if (typeof certificant === 'object' && certificant.pub) data.push(certificant.pub)
|
|
})
|
|
}
|
|
|
|
if (typeof certificants === 'object' && certificants.pub) return certificants.pub
|
|
return data.length > 0 ? data : null
|
|
}
|
|
return
|
|
})()
|
|
|
|
if (!certificants) return console.log("No certificant found.")
|
|
|
|
const expiry = opt.expiry && (typeof opt.expiry === 'number' || typeof opt.expiry === 'string') ? parseFloat(opt.expiry) : null
|
|
const readPolicy = (policy || {}).read ? policy.read : null
|
|
const writePolicy = (policy || {}).write ? policy.write : typeof policy === 'string' || Array.isArray(policy) || policy["+"] || policy["#"] || policy["."] || policy["="] || policy["*"] || policy[">"] || policy["<"] ? policy : null
|
|
// The "blacklist" feature is now renamed to "block". Why ? BECAUSE BLACK LIVES MATTER!
|
|
// We can now use 3 keys: block, blacklist, ban
|
|
const block = (opt || {}).block || (opt || {}).blacklist || (opt || {}).ban || {}
|
|
const readBlock = block.read && (typeof block.read === 'string' || (block.read || {})['#']) ? block.read : null
|
|
const writeBlock = typeof block === 'string' ? block : block.write && (typeof block.write === 'string' || block.write['#']) ? block.write : null
|
|
|
|
if (!readPolicy && !writePolicy) return console.log("No policy found.")
|
|
|
|
// reserved keys: c, e, r, w, rb, wb
|
|
const data = JSON.stringify({
|
|
c: certificants,
|
|
...(expiry ? {e: expiry} : {}), // inject expiry if possible
|
|
...(readPolicy ? {r: readPolicy } : {}), // "r" stands for read, which means read permission.
|
|
...(writePolicy ? {w: writePolicy} : {}), // "w" stands for write, which means write permission.
|
|
...(readBlock ? {rb: readBlock} : {}), // inject READ block if possible
|
|
...(writeBlock ? {wb: writeBlock} : {}), // inject WRITE block if possible
|
|
})
|
|
|
|
const certificate = await SEA.sign(data, authority, null, {raw:1})
|
|
|
|
var r = certificate
|
|
if(!opt.raw){ r = 'SEA'+JSON.stringify(r) }
|
|
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
|
return r;
|
|
} catch(e) {
|
|
SEA.err = e;
|
|
if(SEA.throw){ throw e }
|
|
if(cb){ cb() }
|
|
return;
|
|
}});
|
|
|
|
module.exports = SEA.certify;
|
|
|
|
}()); |