rename identity to account

This commit is contained in:
Andre Staltz 2023-08-10 10:40:11 +03:00
parent ffb8860fb8
commit f6f16bdd47
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
4 changed files with 55 additions and 55 deletions

View File

@ -41,7 +41,7 @@
"prettier": "^2.6.2", "prettier": "^2.6.2",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^4.4.0", "rimraf": "^4.4.0",
"secret-stack": "ssbc/secret-stack#bare-mode", "secret-stack": "~7.1.0",
"secret-handshake-ext": "^0.0.8", "secret-handshake-ext": "^0.0.8",
"ssb-box": "^1.0.1" "ssb-box": "^1.0.1"
}, },

View File

@ -7,48 +7,48 @@ const { createPeer } = require('./util')
const aliceKeypair = Keypair.generate('ed25519', 'alice') const aliceKeypair = Keypair.generate('ed25519', 'alice')
const bobKeys = Keypair.generate('ed25519', 'bob') const bobKeys = Keypair.generate('ed25519', 'bob')
function getIdentity(iter) { function getAccount(iter) {
return [...iter] return [...iter]
.filter((msg) => msg.metadata.identity === 'self' && msg.data) .filter((msg) => msg.metadata.account === 'self' && msg.data)
.map((msg) => msg.data.add) .map((msg) => msg.data.add.key.bytes)
} }
test('sync an identity tangle', async (t) => { test('sync an account tangle', async (t) => {
const alice = createPeer({ name: 'alice', keypair: aliceKeypair }) const alice = createPeer({ name: 'alice', keypair: aliceKeypair })
const bob = createPeer({ name: 'bob', keypair: bobKeys }) const bob = createPeer({ name: 'bob', keypair: bobKeys })
await alice.db.loaded() await alice.db.loaded()
await bob.db.loaded() await bob.db.loaded()
// Alice's identity tangle // Alice's account tangle
await alice.db.loaded() await alice.db.loaded()
const aliceID = await p(alice.db.identity.create)({ const aliceID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'alice', _nonce: 'alice',
}) })
const aliceKeypair1 = Keypair.generate('ed25519', 'alice1') const aliceKeypair1 = Keypair.generate('ed25519', 'alice1')
await p(alice.db.identity.add)({ await p(alice.db.account.add)({
identity: aliceID, account: aliceID,
keypair: aliceKeypair1, keypair: aliceKeypair1,
}) })
const aliceKeypair2 = Keypair.generate('ed25519', 'alice2') const aliceKeypair2 = Keypair.generate('ed25519', 'alice2')
await p(alice.db.identity.add)({ await p(alice.db.account.add)({
identity: aliceID, account: aliceID,
keypair: aliceKeypair2, keypair: aliceKeypair2,
}) })
assert.deepEqual( assert.deepEqual(
getIdentity(alice.db.msgs()), getAccount(alice.db.msgs()),
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public], [aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
'alice has her identity tangle' 'alice has her account tangle'
) )
assert.deepEqual( assert.deepEqual(
getIdentity(bob.db.msgs()), getAccount(bob.db.msgs()),
[], [],
"bob doesn't have alice's identity tangle" "bob doesn't have alice's account tangle"
) )
bob.tangleSync.setGoal(aliceID, 'all') bob.tangleSync.setGoal(aliceID, 'all')
@ -62,9 +62,9 @@ test('sync an identity tangle', async (t) => {
assert('tangleSync!') assert('tangleSync!')
assert.deepEqual( assert.deepEqual(
getIdentity(bob.db.msgs()), getAccount(bob.db.msgs()),
[aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public], [aliceKeypair.public, aliceKeypair1.public, aliceKeypair2.public],
"bob has alice's identity tangle" "bob has alice's account tangle"
) )
await p(remoteAlice.close)(true) await p(remoteAlice.close)(true)

View File

@ -14,7 +14,7 @@ test('sync a feed with goal=all', async (t) => {
await alice.db.loaded() await alice.db.loaded()
await bob.db.loaded() await bob.db.loaded()
const carolID = await p(alice.db.identity.create)({ const carolID = await p(alice.db.account.create)({
keypair: carolKeypair, keypair: carolKeypair,
domain: 'account', domain: 'account',
_nonce: 'carol', _nonce: 'carol',
@ -27,7 +27,7 @@ test('sync a feed with goal=all', async (t) => {
const carolMsgs = [] const carolMsgs = []
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 10; i++) {
const rec = await p(alice.db.feed.publish)({ const rec = await p(alice.db.feed.publish)({
identity: carolID, account: carolID,
domain: 'post', domain: 'post',
data: { text: 'm' + i }, data: { text: 'm' + i },
keypair: carolKeypair, keypair: carolKeypair,
@ -46,7 +46,7 @@ test('sync a feed with goal=all', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,
@ -67,7 +67,7 @@ test('sync a feed with goal=all', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,
@ -88,7 +88,7 @@ test('sync a feed with goal=newest', async (t) => {
await alice.db.loaded() await alice.db.loaded()
await bob.db.loaded() await bob.db.loaded()
const carolID = await p(alice.db.identity.create)({ const carolID = await p(alice.db.account.create)({
keypair: carolKeypair, keypair: carolKeypair,
domain: 'account', domain: 'account',
_nonce: 'carol', _nonce: 'carol',
@ -101,7 +101,7 @@ test('sync a feed with goal=newest', async (t) => {
const carolMsgs = [] const carolMsgs = []
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 10; i++) {
const rec = await p(alice.db.feed.publish)({ const rec = await p(alice.db.feed.publish)({
identity: carolID, account: carolID,
domain: 'post', domain: 'post',
data: { text: 'm' + i }, data: { text: 'm' + i },
keypair: carolKeypair, keypair: carolKeypair,
@ -120,7 +120,7 @@ test('sync a feed with goal=newest', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,
@ -141,7 +141,7 @@ test('sync a feed with goal=newest', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,
@ -162,7 +162,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
await alice.db.loaded() await alice.db.loaded()
await bob.db.loaded() await bob.db.loaded()
const carolID = await p(alice.db.identity.create)({ const carolID = await p(alice.db.account.create)({
keypair: carolKeypair, keypair: carolKeypair,
domain: 'account', domain: 'account',
_nonce: 'carol', _nonce: 'carol',
@ -175,7 +175,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
const carolMsgs = [] const carolMsgs = []
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 10; i++) {
const rec = await p(alice.db.feed.publish)({ const rec = await p(alice.db.feed.publish)({
identity: carolID, account: carolID,
domain: 'post', domain: 'post',
data: { text: 'm' + i }, data: { text: 'm' + i },
keypair: carolKeypair, keypair: carolKeypair,
@ -190,7 +190,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
await algo.pruneNewest(carolPostsRootHash, 5) await algo.pruneNewest(carolPostsRootHash, 5)
{ {
const arr = [...alice.db.msgs()] const arr = [...alice.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,
@ -206,7 +206,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol') assert.deepEqual(arr, ['m1', 'm2'], 'bob has msgs 1..2 from carol')
} }
@ -223,7 +223,7 @@ test('sync a feed with goal=newest but too far behind', async (t) => {
{ {
const arr = [...bob.db.msgs()] const arr = [...bob.db.msgs()]
.filter((msg) => msg.metadata.identity === carolID && msg.data) .filter((msg) => msg.metadata.account === carolID && msg.data)
.map((msg) => msg.data.text) .map((msg) => msg.data.text)
assert.deepEqual( assert.deepEqual(
arr, arr,

View File

@ -53,21 +53,21 @@ test('sync a thread where both peers have portions', async (t) => {
const bob = createPeer({ name: 'bob' }) const bob = createPeer({ name: 'bob' })
await alice.db.loaded() await alice.db.loaded()
const aliceID = await p(alice.db.identity.create)({ const aliceID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'alice', _nonce: 'alice',
}) })
const aliceIDMsg = alice.db.get(aliceID) const aliceIDMsg = alice.db.get(aliceID)
await bob.db.loaded() await bob.db.loaded()
const bobID = await p(bob.db.identity.create)({ const bobID = await p(bob.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'bob', _nonce: 'bob',
}) })
const bobIDMsg = bob.db.get(bobID) const bobIDMsg = bob.db.get(bobID)
// Alice created Carol // Alice created Carol
const carolID = await p(alice.db.identity.create)({ const carolID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
keypair: carolKeypair, keypair: carolKeypair,
_nonce: 'carol', _nonce: 'carol',
@ -75,7 +75,7 @@ test('sync a thread where both peers have portions', async (t) => {
const carolIDMsg = alice.db.get(carolID) const carolIDMsg = alice.db.get(carolID)
// Alice created Dave // Alice created Dave
const daveID = await p(alice.db.identity.create)({ const daveID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
keypair: daveKeypair, keypair: daveKeypair,
_nonce: 'dave', _nonce: 'dave',
@ -91,7 +91,7 @@ test('sync a thread where both peers have portions', async (t) => {
await p(bob.db.add)(daveIDMsg, daveID) await p(bob.db.add)(daveIDMsg, daveID)
const startA = await p(alice.db.feed.publish)({ const startA = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A' }, data: { text: 'A' },
}) })
@ -102,14 +102,14 @@ test('sync a thread where both peers have portions', async (t) => {
await p(bob.db.add)(startA.msg, rootHashA) await p(bob.db.add)(startA.msg, rootHashA)
const replyB1 = await p(bob.db.feed.publish)({ const replyB1 = await p(bob.db.feed.publish)({
identity: bobID, account: bobID,
domain: 'post', domain: 'post',
data: { text: 'B1' }, data: { text: 'B1' },
tangles: [startA.hash], tangles: [startA.hash],
}) })
const replyB2 = await p(bob.db.feed.publish)({ const replyB2 = await p(bob.db.feed.publish)({
identity: bobID, account: bobID,
domain: 'post', domain: 'post',
data: { text: 'B2' }, data: { text: 'B2' },
tangles: [startA.hash], tangles: [startA.hash],
@ -122,7 +122,7 @@ test('sync a thread where both peers have portions', async (t) => {
await p(alice.db.add)(replyB2.msg, rootHashB) await p(alice.db.add)(replyB2.msg, rootHashB)
const replyC1 = await p(alice.db.feed.publish)({ const replyC1 = await p(alice.db.feed.publish)({
identity: carolID, account: carolID,
domain: 'post', domain: 'post',
data: { text: 'C1' }, data: { text: 'C1' },
tangles: [startA.hash], tangles: [startA.hash],
@ -130,7 +130,7 @@ test('sync a thread where both peers have portions', async (t) => {
}) })
const replyD1 = await p(bob.db.feed.publish)({ const replyD1 = await p(bob.db.feed.publish)({
identity: daveID, account: daveID,
domain: 'post', domain: 'post',
data: { text: 'D1' }, data: { text: 'D1' },
tangles: [startA.hash], tangles: [startA.hash],
@ -181,14 +181,14 @@ test('sync a thread where initiator does not have the root', async (t) => {
const bob = createPeer({ name: 'bob' }) const bob = createPeer({ name: 'bob' })
await alice.db.loaded() await alice.db.loaded()
const aliceID = await p(alice.db.identity.create)({ const aliceID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'alice', _nonce: 'alice',
}) })
const aliceIDMsg = alice.db.get(aliceID) const aliceIDMsg = alice.db.get(aliceID)
await bob.db.loaded() await bob.db.loaded()
const bobID = await p(bob.db.identity.create)({ const bobID = await p(bob.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'bob', _nonce: 'bob',
}) })
@ -201,20 +201,20 @@ test('sync a thread where initiator does not have the root', async (t) => {
await p(bob.db.add)(aliceIDMsg, aliceID) await p(bob.db.add)(aliceIDMsg, aliceID)
const rootA = await p(alice.db.feed.publish)({ const rootA = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A' }, data: { text: 'A' },
}) })
const replyA1 = await p(alice.db.feed.publish)({ const replyA1 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A1' }, data: { text: 'A1' },
tangles: [rootA.hash], tangles: [rootA.hash],
}) })
const replyA2 = await p(alice.db.feed.publish)({ const replyA2 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A2' }, data: { text: 'A2' },
tangles: [rootA.hash], tangles: [rootA.hash],
@ -255,14 +255,14 @@ test('sync a thread where receiver does not have the root', async (t) => {
const bob = createPeer({ name: 'bob' }) const bob = createPeer({ name: 'bob' })
await alice.db.loaded() await alice.db.loaded()
const aliceID = await p(alice.db.identity.create)({ const aliceID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'alice', _nonce: 'alice',
}) })
const aliceIDMsg = alice.db.get(aliceID) const aliceIDMsg = alice.db.get(aliceID)
await bob.db.loaded() await bob.db.loaded()
const bobID = await p(bob.db.identity.create)({ const bobID = await p(bob.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'bob', _nonce: 'bob',
}) })
@ -275,20 +275,20 @@ test('sync a thread where receiver does not have the root', async (t) => {
await p(bob.db.add)(aliceIDMsg, aliceID) await p(bob.db.add)(aliceIDMsg, aliceID)
const rootA = await p(alice.db.feed.publish)({ const rootA = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A' }, data: { text: 'A' },
}) })
const replyA1 = await p(alice.db.feed.publish)({ const replyA1 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A1' }, data: { text: 'A1' },
tangles: [rootA.hash], tangles: [rootA.hash],
}) })
const replyA2 = await p(alice.db.feed.publish)({ const replyA2 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A2' }, data: { text: 'A2' },
tangles: [rootA.hash], tangles: [rootA.hash],
@ -328,14 +328,14 @@ test('sync a thread with reactions too', async (t) => {
const bob = createPeer({ name: 'bob' }) const bob = createPeer({ name: 'bob' })
await alice.db.loaded() await alice.db.loaded()
const aliceID = await p(alice.db.identity.create)({ const aliceID = await p(alice.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'alice', _nonce: 'alice',
}) })
const aliceIDMsg = alice.db.get(aliceID) const aliceIDMsg = alice.db.get(aliceID)
await bob.db.loaded() await bob.db.loaded()
const bobID = await p(bob.db.identity.create)({ const bobID = await p(bob.db.account.create)({
domain: 'account', domain: 'account',
_nonce: 'bob', _nonce: 'bob',
}) })
@ -348,27 +348,27 @@ test('sync a thread with reactions too', async (t) => {
await p(bob.db.add)(aliceIDMsg, aliceID) await p(bob.db.add)(aliceIDMsg, aliceID)
const rootA = await p(alice.db.feed.publish)({ const rootA = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A' }, data: { text: 'A' },
}) })
const replyA1 = await p(alice.db.feed.publish)({ const replyA1 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A1' }, data: { text: 'A1' },
tangles: [rootA.hash], tangles: [rootA.hash],
}) })
const replyA2 = await p(alice.db.feed.publish)({ const replyA2 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'post', domain: 'post',
data: { text: 'A2' }, data: { text: 'A2' },
tangles: [rootA.hash], tangles: [rootA.hash],
}) })
const reactionA3 = await p(alice.db.feed.publish)({ const reactionA3 = await p(alice.db.feed.publish)({
identity: aliceID, account: aliceID,
domain: 'reaction', domain: 'reaction',
data: { text: 'yes', link: replyA1.hash }, data: { text: 'yes', link: replyA1.hash },
tangles: [rootA.hash, replyA1.hash], tangles: [rootA.hash, replyA1.hash],