公共场所
任何人都可以编辑。
let gun = Gun()
gun.get('foo').put({hello: 'world'})
Docs: https://gun.eco/docs/Hello-World https://gun.eco/docs/Hello-World
用户空间(或键空间)
只能放置用用户密钥签名的数据。使用SEA。
The ~
运算符用于访问用户空间。 Gun 将其解释为“只允许由以下密钥签名的数据~
放在这里"
let Bob = await SEA.pair();
await gun.user().auth(Bob)
gun.get('~'+Bob.pub).get('test').get('TestPropery').put("Hello from Bob",console.log)
let Eve = await SEA.pair()
await gun.user().auth(Eve) // comment this out and below line will fail, because authorised user Bob not Eve
gun.get('~'+Eve.pub).get('test').get('TestPropery').put("Hello from Alice",console.log)
Docs: https://gun.eco/docs/SEA#quickstart https://gun.eco/docs/SEA#quickstart
冰冻空间(哈希空间、内容 ID 空间)
The #
使用运算符。 Gun 的解释类似于“仅当数据的散列与附加的散列对象匹配时才允许将数据放在这里。"
var data = "hello world";
var hash = await SEA.work(data, null, null, {name: "SHA-256"});
gun.get('#').get(hash).put(data);
来自文档:https://gun.eco/docs/Content-Addressing https://gun.eco/docs/Content-Addressing
我还观察到,您可以在用户空间之上冻结空间,但反之则不然:
//works (content hash id enforced)
gun.get(pub).get('#').get('bR+eukWF7mYgxibHHRc6tJ+G6PIMEB91O1WVEbAYuWU=').put('NJViiTklbpVb2mmXmRel1cZ0F5lm6ZSTAjYg3RWhqkU.qbu9aOlUXGbrFwqZqeLdw2KiMlpj3QMbezmGRm4u7l0')
//you can't append data to a # obj like this
gun.get('#').get('bR+eukWF7mYgxibHHRc6tJ+G6PIMEB91O1WVEbAYuWU=').get('NJViiTklbpVb2mmXmRel1cZ0F5lm6ZSTAjYg3RWhqkU.qbu9aOlUXGbrFwqZqeLdw2KiMlpj3QMbezmGRm4u7l0').put({'something':'else'})