use ppppp-keypair instead of ssb-keys

This commit is contained in:
Andre Staltz 2023-06-14 10:48:54 +03:00
parent 78a6f2216c
commit fa16916e82
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
25 changed files with 259 additions and 256 deletions

View File

@ -1,7 +1,9 @@
const MsgV2 = require('./msg-v2')
const base58 = require('bs58')
/**
* @typedef {import('./index').Rec} Rec
* @typedef {import('ppppp-keypair').Keypair} Keypair
*/
function ciphertextStrToBuffer(str) {
@ -9,6 +11,21 @@ function ciphertextStrToBuffer(str) {
return Buffer.from(str.slice(0, dot), 'base64')
}
/**
* TODO: eventually get rid of this
* @param {Keypair} keypair
*/
function keypairToSSBKeys(keypair) {
const public = Buffer.from(base58.decode(keypair.public)).toString('base64')
const private = Buffer.from(base58.decode(keypair.private)).toString('base64')
return {
id: `@${public}.ed25519`,
curve: keypair.curve,
public,
private,
}
}
/**
* @param {Rec} rec
* @param {any} peer
@ -25,7 +42,7 @@ function decrypt(rec, peer, config) {
// Decrypt
const ciphertextBuf = ciphertextStrToBuffer(data)
const opts = { keys: config.keys }
const opts = { keys: keypairToSSBKeys(config.keypair) }
const plaintextBuf = encryptionFormat.decrypt(ciphertextBuf, opts)
if (!plaintextBuf) return rec

View File

@ -2,6 +2,7 @@ const path = require('path')
const push = require('push-stream')
const AAOL = require('async-append-only-log')
const promisify = require('promisify-4loc')
const base58 = require('bs58')
const Obz = require('obz')
const MsgV2 = require('./msg-v2')
const { ReadyGate } = require('./utils')
@ -222,13 +223,13 @@ exports.init = function initDB(peer, config) {
}
function initializeFeed(opts, cb) {
const keys = opts.keys ?? config.keys
const keypair = opts.keypair ?? config.keypair
const { group, type } = opts
const feedRootHash = getFeedId(group, type)
if (feedRootHash) return cb(null, feedRootHash)
const feedRoot = MsgV2.createRoot(group, type, keys)
const feedRoot = MsgV2.createRoot(group, type, keypair)
add(feedRoot, MsgV2.getMsgHash(feedRoot), (err, rec) => {
// prettier-ignore
if (err) return cb(new Error('initializeFeed() failed to add root', { cause: err }));
@ -237,11 +238,11 @@ exports.init = function initDB(peer, config) {
}
function createGroup(opts, cb) {
const keys = opts?.keys ?? config.keys
const keypair = opts?.keypair ?? config.keypair
let msg
try {
msg = MsgV2.createGroup(keys, opts?._nonce)
msg = MsgV2.createGroup(keypair, opts?._nonce)
} catch (err) {
return cb(new Error('group.create() failed', { cause: err }))
}
@ -256,10 +257,10 @@ exports.init = function initDB(peer, config) {
}
function addToGroup(opts, cb) {
if (!opts?.keys) return cb(new Error('group.add() requires a `keys`'))
if (!opts?.keypair) return cb(new Error('group.add() requires a `keypair`'))
if (!opts?.group) return cb(new Error('group.add() requires a `group`'))
const addedKeys = opts.keys
const signingKeys = config.keys
const addedKeypair = opts.keypair
const signingKeypair = config.keypair
// Fill-in tangle opts:
const tangles = populateTangles([opts.group])
@ -267,8 +268,8 @@ exports.init = function initDB(peer, config) {
group: null,
groupTips: null,
tangles,
keys: signingKeys,
data: { add: addedKeys.id },
keypair: signingKeypair,
data: { add: addedKeypair.public },
type: 'group',
}
@ -290,7 +291,8 @@ exports.init = function initDB(peer, config) {
}
function publishToFeed(opts, cb) {
const keys = opts.keys ?? config.keys
if (!opts) return cb(new Error('feed.publish() requires an `opts`'))
const keypair = opts.keypair ?? config.keypair
const encryptionFormat = encryptionFormats.get(opts.encryptionFormat)
if (opts.data.recps) {
@ -313,19 +315,29 @@ exports.init = function initDB(peer, config) {
const tangles = populateTangles(tangleTemplates)
const groupTangle = new DBTangle(opts.group, records())
const groupTips = [...groupTangle.getTips()]
const fullOpts = { ...opts, tangles, groupTips, keys }
const fullOpts = { ...opts, tangles, groupTips, keypair }
// If opts ask for encryption, encrypt and put ciphertext in opts.data
const recps = fullOpts.data.recps
if (Array.isArray(recps) && recps.length > 0) {
const plaintext = MsgV2.toPlaintextBuffer(fullOpts)
const encryptOpts = { ...fullOpts, recps }
const encryptOpts = {
...fullOpts,
recps: recps.map(
(recp) =>
// TODO: temporary until our encryption formats are ppppp not SSB
`@${Buffer.from(base58.decode(recp)).toString('base64')}.ed25519`
),
}
let ciphertextBuf
try {
ciphertextBuf = encryptionFormat.encrypt(plaintext, encryptOpts)
} catch (err) {
// prettier-ignore
return cb(new Error('feed.publish() failed to encrypt data', {cause: err}));
console.log(err);
return cb(
new Error('feed.publish() failed to encrypt data', { cause: err })
)
}
if (!ciphertextBuf) {
// prettier-ignore

View File

@ -1,6 +1,6 @@
const crypto = require('crypto')
const stringify = require('json-canon')
const ed25519 = require('ssb-keys/sodium')
const Keypair = require('ppppp-keypair')
const base58 = require('bs58')
const union = require('set.prototype.union')
const { stripGroup } = require('./strip')
@ -18,6 +18,7 @@ const Tangle = require('./tangle')
/**
* @typedef {Iterator<Msg> & {values: () => Iterator<Msg>}} MsgIter
* @typedef {import('ppppp-keypair').Keypair} Keypair
*/
/**
@ -41,17 +42,11 @@ const Tangle = require('./tangle')
* @property {string} sig
*/
/**
* @typedef {Object} Keys
* @property {string} keys.id
* @property {string} keys.private
*/
/**
* @typedef {Object} CreateOpts
* @property {*} data
* @property {string} type
* @property {Keys} keys
* @property {Keypair} keypair
* @property {string | null} group
* @property {Array<string> | null} groupTips
* @property {Record<string, Tangle>} tangles
@ -122,17 +117,14 @@ function create(opts) {
type: opts.type,
v: 2,
},
pubkey: opts.keys.id,
pubkey: opts.keypair.public,
sig: '',
}
if ((err = validateData(msg))) throw err
const privateKey = Buffer.from(opts.keys.private, 'base64')
// TODO: add a label prefix to the metadata before signing
const metadataBuf = Buffer.from(stringify(msg.metadata), 'utf8')
// TODO: when signing, what's the point of a customizable hmac?
const sigBuf = ed25519.sign(privateKey, metadataBuf)
msg.sig = base58.encode(sigBuf)
msg.sig = Keypair.sign(opts.keypair, metadataBuf)
return msg
}
@ -140,10 +132,10 @@ function create(opts) {
/**
* @param {string} group
* @param {string} type
* @param {Keys} keys
* @param {Keypair} keypair
* @returns {Msg}
*/
function createRoot(group, type, keys) {
function createRoot(group, type, keypair) {
let err
if ((err = validateType(type))) throw err
@ -158,31 +150,28 @@ function createRoot(group, type, keys) {
type,
v: 2,
},
pubkey: keys.id,
pubkey: keypair.public,
sig: '',
}
const privateKey = Buffer.from(keys.private, 'base64')
// TODO: add a label prefix to the metadata before signing
const metadataBuf = Buffer.from(stringify(msg.metadata), 'utf8')
// TODO: when signing, what's the point of a customizable hmac?
const sigBuf = ed25519.sign(privateKey, metadataBuf)
msg.sig = base58.encode(sigBuf)
msg.sig = Keypair.sign(keypair, metadataBuf)
return msg
}
/**
* @param {Keys} keys
* @param {Keypair} keypair
* @param {string} nonce
* @returns {Msg}
*/
function createGroup(keys, nonce = base58.encode(crypto.randomBytes(32))) {
function createGroup(keypair, nonce = base58.encode(crypto.randomBytes(32))) {
return create({
data: { add: keys.id, nonce },
data: { add: keypair.public, nonce },
group: null,
groupTips: null,
keys,
keypair,
tangles: {},
type: 'group',
})

View File

@ -1,5 +1,5 @@
const base58 = require('bs58')
const ed25519 = require('ssb-keys/sodium')
const Keypair = require('ppppp-keypair')
const stringify = require('json-canon')
const Tangle = require('./tangle')
const representData = require('./represent-data')
@ -112,9 +112,9 @@ function validateSignature(msg) {
return `invalid message: sig "${sig}" should have been a base58 string\n` + JSON.stringify(msg)
}
const publicKeyBuf = Buffer.from(base58.decode(msg.pubkey))
const signableBuf = Buffer.from(stringify(msg.metadata), 'utf8')
const verified = ed25519.verify(publicKeyBuf, sigBuf, signableBuf)
const keypair = {curve: 'ed25519', public: msg.pubkey}
const verified = Keypair.verify(keypair, signableBuf, sig)
if (!verified) {
return 'invalid message: sig is invalid\n' + JSON.stringify(msg)
}

View File

@ -35,10 +35,10 @@
"bs58": "^5.0.0",
"json-canon": "^1.0.0",
"obz": "^1.1.0",
"ppppp-keypair": "github:staltz/ppppp-keypair",
"promisify-4loc": "^1.0.0",
"push-stream": "^11.2.0",
"set.prototype.union": "^1.0.2",
"ssb-uri2": "^2.4.1"
"set.prototype.union": "^1.0.2"
},
"devDependencies": {
"c8": "^7.11.0",
@ -46,12 +46,11 @@
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"rimraf": "^4.4.0",
"secret-stack": "^6.4.1",
"secret-stack": "^6.4.2",
"ssb-bendy-butt": "^1.0.0",
"ssb-box": "^1.0.1",
"ssb-caps": "^1.1.0",
"ssb-classic": "^1.1.0",
"ssb-keys": "^8.5.0",
"tap-arc": "^0.3.5",
"tape": "^5.6.3"
},

View File

@ -1,31 +1,31 @@
const test = require('tape')
const path = require('path')
const os = require('os')
const p = require('util').promisify
const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../lib/msg-v2')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-add')
rimraf.sync(DIR)
test('add()', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
const groupMsg0 = MsgV2.createGroup(keys)
const groupMsg0 = MsgV2.createGroup(keypair)
const group = MsgV2.getMsgHash(groupMsg0)
await p(peer.db.add)(groupMsg0, group)
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const recRoot = await p(peer.db.add)(rootMsg, rootHash)
@ -34,7 +34,7 @@ test('add()', async (t) => {
tangle.add(recRoot.hash, recRoot.msg)
const inputMsg = MsgV2.create({
keys,
keypair,
type: 'post',
data: { text: 'This is the first post!' },
group,

View File

@ -6,17 +6,17 @@ const SecretStack = require('secret-stack')
const AAOL = require('async-append-only-log')
const push = require('push-stream')
const caps = require('ssb-caps')
const Keypair = require('ppppp-keypair')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-del')
rimraf.sync(DIR)
test('del', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()

View File

@ -6,17 +6,17 @@ const SecretStack = require('secret-stack')
const AAOL = require('async-append-only-log')
const push = require('push-stream')
const caps = require('ssb-caps')
const Keypair = require('ppppp-keypair')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-erase')
rimraf.sync(DIR)
test('erase', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()

View File

@ -5,13 +5,13 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../lib/msg-v2')
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-feed-publish')
rimraf.sync(DIR)
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
let peer
let group
let rootMsg
@ -20,12 +20,12 @@ test('setup', async (t) => {
peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
group = (await p(peer.db.group.create)(null)).hash
rootMsg = MsgV2.createRoot(group, 'post', keys)
rootMsg = MsgV2.createRoot(group, 'post', keypair)
rootHash = MsgV2.getMsgHash(rootMsg)
await p(peer.db.add)(rootMsg, rootHash)

View File

@ -5,14 +5,14 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../lib/msg-v2')
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-feed-publish')
rimraf.sync(DIR)
const keys = generateKeypair('alice')
const bobKeys = generateKeypair('bob')
const keypair = Keypair.generate('ed25519', 'alice')
const bobKeypair = Keypair.generate('ed25519', 'bob')
let peer
let group
let rootMsg
@ -21,12 +21,12 @@ test('setup', async (t) => {
peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
group = (await p(peer.db.group.create)(null)).hash
rootMsg = MsgV2.createRoot(group, 'post', keys)
rootMsg = MsgV2.createRoot(group, 'post', keypair)
rootHash = MsgV2.getMsgHash(rootMsg)
})
@ -78,7 +78,7 @@ test('add() forked then feed.publish() merged', async (t) => {
tangle.add(rec1.hash, rec1.msg)
const msg3 = MsgV2.create({
keys,
keypair,
group,
groupTips: [group],
type: 'post',
@ -120,7 +120,7 @@ test('feed.publish() encrypted with box', async (t) => {
const recEncrypted = await p(peer.db.feed.publish)({
group,
type: 'post',
data: { text: 'I am chewing food', recps: [peer.id] },
data: { text: 'I am chewing food', recps: [keypair.public] },
encryptionFormat: 'box',
})
t.equal(typeof recEncrypted.msg.data, 'string')
@ -143,7 +143,7 @@ test('feed.publish() with tangles', async (t) => {
type: 'comment',
data: { text: 'I am comment 1' },
tangles: [recA.hash],
keys: bobKeys,
keypair: bobKeypair,
})
t.equal(recB.msg.metadata.tangles[recA.hash].depth, 1, 'tangle depth 1')
t.deepEquals(

View File

@ -5,13 +5,13 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../lib/msg-v2')
const { generateKeypair } = require('./util')
const DIR = path.join(os.tmpdir(), 'ppppp-db-get')
rimraf.sync(DIR)
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
let peer
let group
let msgHash1
@ -20,7 +20,7 @@ test('setup', async (t) => {
peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()

View File

@ -5,7 +5,7 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-tangle')
rimraf.sync(DIR)
@ -14,14 +14,14 @@ let peer
let rootPost, reply1Lo, reply1Hi, reply2A, reply3Lo, reply3Hi
let tangle
test('setup', async (t) => {
const keysA = generateKeypair('alice')
const keysB = generateKeypair('bob')
const keysC = generateKeypair('carol')
const keypairA = Keypair.generate('ed25519', 'alice')
const keypairB = Keypair.generate('ed25519', 'bob')
const keypairC = Keypair.generate('ed25519', 'carol')
peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys: keysA, path: DIR })
.call(null, { keypair: keypairA, path: DIR })
await peer.db.loaded()
@ -36,7 +36,7 @@ test('setup', async (t) => {
rootPost = (
await p(peer.db.feed.publish)({
group,
keys: keysA,
keypair: keypairA,
type: 'comment',
data: { text: 'root' },
})
@ -45,14 +45,14 @@ test('setup', async (t) => {
const [{ hash: reply1B }, { hash: reply1C }] = await Promise.all([
p(peer.db.feed.publish)({
group,
keys: keysB,
keypair: keypairB,
type: 'comment',
data: { text: 'reply 1B' },
tangles: [rootPost],
}),
p(peer.db.feed.publish)({
group,
keys: keysC,
keypair: keypairC,
type: 'comment',
data: { text: 'reply 1C' },
tangles: [rootPost],
@ -64,7 +64,7 @@ test('setup', async (t) => {
reply2A = (
await p(peer.db.feed.publish)({
group,
keys: keysA,
keypair: keypairA,
type: 'comment',
data: { text: 'reply 2' },
tangles: [rootPost],
@ -74,14 +74,14 @@ test('setup', async (t) => {
const [{ hash: reply3B }, { hash: reply3C }] = await Promise.all([
p(peer.db.feed.publish)({
group,
keys: keysB,
keypair: keypairB,
type: 'comment',
data: { text: 'reply 3B' },
tangles: [rootPost],
}),
p(peer.db.feed.publish)({
group,
keys: keysC,
keypair: keypairC,
type: 'comment',
data: { text: 'reply 3C' },
tangles: [rootPost],

View File

@ -5,29 +5,29 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-group-add')
rimraf.sync(DIR)
test('group.add()', async (t) => {
const keys1 = generateKeypair('alice')
const keys2 = generateKeypair('bob')
const keypair1 = Keypair.generate('ed25519', 'alice')
const keypair2 = Keypair.generate('ed25519', 'bob')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys: keys1, path: DIR })
.call(null, { keypair: keypair1, path: DIR })
await peer.db.loaded()
const groupRec0 = await p(peer.db.group.create)({ keys: keys1 })
const groupRec0 = await p(peer.db.group.create)({ keypair: keypair1 })
const group = groupRec0.hash
const groupRec1 = await p(peer.db.group.add)({ group, keys: keys2 })
const groupRec1 = await p(peer.db.group.add)({ group, keypair: keypair2 })
t.ok(groupRec1, 'groupRec1 exists')
const { hash, msg } = groupRec1
t.ok(hash, 'hash exists')
t.equals(msg.data.add, keys2.id, 'msg.data.add NEW KEY')
t.equals(msg.data.add, keypair2.public, 'msg.data.add NEW KEY')
t.equals(msg.metadata.group, null, 'msg.metadata.group')
t.equals(msg.metadata.groupTips, null, 'msg.metadata.groupTips')
t.deepEquals(
@ -35,7 +35,7 @@ test('group.add()', async (t) => {
{ [group]: { depth: 1, prev: [group] } },
'msg.metadata.tangles'
)
t.equals(msg.pubkey, keys1.id, 'msg.pubkey OLD KEY')
t.equals(msg.pubkey, keypair1.public, 'msg.pubkey OLD KEY')
await p(peer.close)()
})
@ -43,25 +43,25 @@ test('group.add()', async (t) => {
test('publish with a key in the group', async (t) => {
rimraf.sync(DIR)
const keys1 = generateKeypair('alice')
const keys2 = generateKeypair('bob')
const keypair1 = Keypair.generate('ed25519', 'alice')
const keypair2 = Keypair.generate('ed25519', 'bob')
let peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys: keys1, path: DIR })
.call(null, { keypair: keypair1, path: DIR })
await peer.db.loaded()
const groupRec0 = await p(peer.db.group.create)({ keys: keys1 })
const groupRec0 = await p(peer.db.group.create)({ keypair: keypair1 })
const group = groupRec0.hash
const groupRec1 = await p(peer.db.group.add)({ group, keys: keys2 })
const groupRec1 = await p(peer.db.group.add)({ group, keypair: keypair2 })
const postRec = await p(peer.db.feed.publish)({
group,
type: 'post',
data: { text: 'hello' },
keys: keys2,
keypair: keypair2,
})
t.equal(postRec.msg.data.text, 'hello', 'post text correct')
const postsId = peer.db.feed.getId(group, 'post')
@ -87,12 +87,12 @@ test('publish with a key in the group', async (t) => {
// Re-load as Carol, add the msgs to validate them
rimraf.sync(DIR)
const keys3 = generateKeypair('carol')
const keypair3 = Keypair.generate('ed25519', 'carol')
const carol = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys: keys3, path: DIR })
.call(null, { keypair: keypair3, path: DIR })
await carol.db.loaded()

View File

@ -5,50 +5,50 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-group-create')
rimraf.sync(DIR)
test('group.create() without args', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
const groupRec0 = await p(peer.db.group.create)({})
t.ok(groupRec0, 'groupRec0 exists')
const { hash, msg } = groupRec0
t.ok(hash, 'hash exists')
t.equals(msg.data.add, keys.id, 'msg.data.add')
t.equals(msg.data.add, keypair.public, 'msg.data.add')
t.equals(msg.metadata.group, null, 'msg.metadata.group')
t.equals(msg.metadata.groupTips, null, 'msg.metadata.groupTips')
t.deepEquals(Object.keys(msg.metadata.tangles), [], 'msg.metadata.tangles')
t.equals(msg.pubkey, keys.id, 'msg.pubkey')
t.equals(msg.pubkey, keypair.public, 'msg.pubkey')
await p(peer.close)()
})
test('group.create() with "keys" arg', async (t) => {
const keys = generateKeypair('alice')
test('group.create() with "keypair" arg', async (t) => {
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
const groupRec0 = await p(peer.db.group.create)({ keys })
const groupRec0 = await p(peer.db.group.create)({ keypair })
t.ok(groupRec0, 'groupRec0 exists')
const { hash, msg } = groupRec0
t.ok(hash, 'hash exists')
t.equals(msg.data.add, keys.id, 'msg.data.add')
t.equals(msg.data.add, keypair.public, 'msg.data.add')
t.equals(msg.metadata.group, null, 'msg.metadata.group')
t.equals(msg.metadata.groupTips, null, 'msg.metadata.groupTips')
t.deepEquals(Object.keys(msg.metadata.tangles), [], 'msg.metadata.tangles')
t.equals(msg.pubkey, keys.id, 'msg.pubkey')
t.equals(msg.pubkey, keypair.public, 'msg.pubkey')
await p(peer.close)()
})

View File

@ -1,15 +1,15 @@
const tape = require('tape')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
let group
tape('MsgV2.createGroup()', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const groupMsg0 = MsgV2.createGroup(keys, 'MYNONCE')
const groupMsg0 = MsgV2.createGroup(keypair, 'MYNONCE')
console.log(JSON.stringify(groupMsg0, null, 2))
t.equals(groupMsg0.data.add, keys.id, 'data.add')
t.equals(groupMsg0.data.add, keypair.public, 'data.add')
t.equals(groupMsg0.metadata.dataHash, 'THi3VkJeaf8aTkLSNJUdFD', 'hash')
t.equals(groupMsg0.metadata.dataSize, 72, 'size')
t.equals(groupMsg0.metadata.group, null, 'group')
@ -17,7 +17,7 @@ tape('MsgV2.createGroup()', (t) => {
t.deepEquals(groupMsg0.metadata.tangles, {}, 'tangles')
t.equals(groupMsg0.metadata.type, 'group', 'type')
t.equals(groupMsg0.metadata.v, 2, 'v')
t.equals(groupMsg0.pubkey, keys.id, 'pubkey')
t.equals(groupMsg0.pubkey, keypair.public, 'pubkey')
group = MsgV2.getMsgHash(groupMsg0)
t.equals(group, 'XKKmEBmqKGa5twQ2HNSk7t', 'group ID')
@ -28,9 +28,9 @@ tape('MsgV2.createGroup()', (t) => {
let rootMsg = null
let rootHash = null
tape('MsgV2.createRoot()', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
rootMsg = MsgV2.createRoot(group, 'post', keys)
rootMsg = MsgV2.createRoot(group, 'post', keypair)
console.log(JSON.stringify(rootMsg, null, 2))
t.equals(rootMsg.data, null, 'data')
@ -41,7 +41,7 @@ tape('MsgV2.createRoot()', (t) => {
t.deepEquals(rootMsg.metadata.tangles, {}, 'tangles')
t.equals(rootMsg.metadata.type, 'post', 'type')
t.equals(rootMsg.metadata.v, 2, 'v')
t.equals(rootMsg.pubkey, keys.id, 'pubkey')
t.equals(rootMsg.pubkey, keypair.public, 'pubkey')
rootHash = MsgV2.getMsgHash(rootMsg)
t.equals(rootHash, 'PzuT1Dwbbgn6a8NeLuHuKw', 'root hash')
@ -49,14 +49,14 @@ tape('MsgV2.createRoot()', (t) => {
})
tape('MsgV2.create()', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const data = { text: 'Hello world!' }
const tangle1 = new MsgV2.Tangle(rootHash)
tangle1.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data,
group,
groupTips: [group],
@ -116,7 +116,7 @@ tape('MsgV2.create()', (t) => {
const data2 = { text: 'Ola mundo!' }
const msg2 = MsgV2.create({
keys,
keypair,
data: data2,
group,
groupTips: [group],
@ -171,12 +171,12 @@ tape('MsgV2.create()', (t) => {
})
tape('create() handles DAG tips correctly', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: '1' },
group,
groupTips: [group],
@ -195,7 +195,7 @@ tape('create() handles DAG tips correctly', (t) => {
tangle.add(msgHash1, msg1)
const msg2A = MsgV2.create({
keys,
keypair,
data: { text: '2A' },
group,
groupTips: [group],
@ -211,7 +211,7 @@ tape('create() handles DAG tips correctly', (t) => {
)
const msg2B = MsgV2.create({
keys,
keypair,
data: { text: '2B' },
group,
groupTips: [group],
@ -230,7 +230,7 @@ tape('create() handles DAG tips correctly', (t) => {
tangle.add(msgHash2B, msg2B)
const msg3 = MsgV2.create({
keys,
keypair,
data: { text: '3' },
group,
groupTips: [group],
@ -252,7 +252,7 @@ tape('create() handles DAG tips correctly', (t) => {
t.pass('msg2A comes into awareness')
const msg4 = MsgV2.create({
keys,
keypair,
data: { text: '4' },
group,
groupTips: [group],

View File

@ -1,23 +1,23 @@
const tape = require('tape')
const base58 = require('bs58')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
const keys = generateKeypair('alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keys, 'MYNONCE'))
const pubkeys = new Set([keys.id])
const keypair = Keypair.generate('ed25519', 'alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keypair, 'MYNONCE'))
const pubkeys = new Set([keypair.public])
tape('invalid msg with non-array prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -40,16 +40,16 @@ tape('invalid msg with non-array prev', (t) => {
})
tape('invalid msg with bad prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -62,7 +62,7 @@ tape('invalid msg with bad prev', (t) => {
tangle.add(msgHash1, msg1)
const msg2 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -86,16 +86,16 @@ tape('invalid msg with bad prev', (t) => {
})
tape('invalid msg with URI in prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -108,7 +108,7 @@ tape('invalid msg with URI in prev', (t) => {
tangle.add(msgHash1, msg1)
const msg2 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -130,16 +130,16 @@ tape('invalid msg with URI in prev', (t) => {
})
tape('invalid msg with unknown prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -152,7 +152,7 @@ tape('invalid msg with unknown prev', (t) => {
tangle.add(msgHash1, msg1)
const unknownMsg = MsgV2.create({
keys,
keypair,
data: { text: 'Alien' },
group,
groupTips: [group],
@ -169,7 +169,7 @@ tape('invalid msg with unknown prev', (t) => {
tangle2.add(unknownMsgHash, unknownMsg)
const msg2 = MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -187,18 +187,18 @@ tape('invalid msg with unknown prev', (t) => {
})
tape('invalid feed msg with a different pubkey', (t) => {
const keysA = generateKeypair('alice')
const keysB = generateKeypair('bob')
const keypairA = Keypair.generate('ed25519', 'alice')
const keypairB = Keypair.generate('ed25519', 'bob')
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keysB, 'MYNONCE'))
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keypairB, 'MYNONCE'))
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const feedTangle = new MsgV2.Tangle(rootHash)
feedTangle.add(rootHash, rootMsg)
const msg = MsgV2.create({
keys: keysB,
keypair: keypairB,
data: { text: 'Hello world!' },
group: groupB,
groupTips: [groupB],
@ -219,15 +219,15 @@ tape('invalid feed msg with a different pubkey', (t) => {
})
tape('invalid feed msg with a different type', (t) => {
const keysA = generateKeypair('alice')
const keypairA = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const feedTangle = new MsgV2.Tangle(rootHash)
feedTangle.add(rootHash, rootMsg)
const msg = MsgV2.create({
keys: keysA,
keypair: keypairA,
data: { text: 'Hello world!' },
group,
groupTips: [group],
@ -248,16 +248,16 @@ tape('invalid feed msg with a different type', (t) => {
})
tape('invalid feed msg with non-alphabetical prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: '1' },
group,
groupTips: [group],
@ -269,7 +269,7 @@ tape('invalid feed msg with non-alphabetical prev', (t) => {
const msgHash1 = MsgV2.getMsgHash(msg1)
const msg2 = MsgV2.create({
keys,
keypair,
data: { text: '2' },
group,
groupTips: [group],
@ -284,7 +284,7 @@ tape('invalid feed msg with non-alphabetical prev', (t) => {
tangle.add(msgHash2, msg2)
const msg3 = MsgV2.create({
keys,
keypair,
data: { text: '3' },
group,
groupTips: [group],
@ -314,16 +314,16 @@ tape('invalid feed msg with non-alphabetical prev', (t) => {
})
tape('invalid feed msg with duplicate prev', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
const msg1 = MsgV2.create({
keys,
keypair,
data: { text: '1' },
group,
groupTips: [group],

View File

@ -1,14 +1,14 @@
const tape = require('tape')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
tape('invalid type not a string', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
t.throws(
() => {
MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
type: 123,
})
@ -20,12 +20,12 @@ tape('invalid type not a string', (t) => {
})
tape('invalid type with "/" character', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
t.throws(
() => {
MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
type: 'group/init',
})
@ -37,12 +37,12 @@ tape('invalid type with "/" character', (t) => {
})
tape('invalid type with "*" character', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
t.throws(
() => {
MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
type: 'star*',
})
@ -54,12 +54,12 @@ tape('invalid type with "*" character', (t) => {
})
tape('invalid type too short', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
t.throws(
() => {
MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
type: 'xy',
})
@ -71,12 +71,12 @@ tape('invalid type too short', (t) => {
})
tape('invalid type too long', (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
t.throws(
() => {
MsgV2.create({
keys,
keypair,
data: { text: 'Hello world!' },
type: 'a'.repeat(120),
})

View File

@ -1,13 +1,13 @@
const tape = require('tape')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
tape('lipmaa prevs', (t) => {
const keys = generateKeypair('alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keys, 'MYNONCE'))
const keypair = Keypair.generate('ed25519', 'alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keypair, 'MYNONCE'))
const data = { text: 'Hello world!' }
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
@ -20,7 +20,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash1 = MsgV2.getMsgHash(msg1)
tangle.add(msgHash1, msg1)
@ -35,7 +35,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash2 = MsgV2.getMsgHash(msg2)
tangle.add(msgHash2, msg2)
@ -50,7 +50,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash3 = MsgV2.getMsgHash(msg3)
tangle.add(msgHash3, msg3)
@ -65,7 +65,7 @@ tape('lipmaa prevs', (t) => {
group,
groupTips: [group],
type: 'post',
keys,
keypair,
tangles: {
[rootHash]: tangle,
},
@ -84,7 +84,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash5 = MsgV2.getMsgHash(msg5)
tangle.add(msgHash5, msg5)
@ -99,7 +99,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash6 = MsgV2.getMsgHash(msg6)
tangle.add(msgHash6, msg6)
@ -114,7 +114,7 @@ tape('lipmaa prevs', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash7 = MsgV2.getMsgHash(msg7)
tangle.add(msgHash7, msg7)

View File

@ -1,19 +1,19 @@
const tape = require('tape')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
tape('simple multi-author tangle', (t) => {
const keysA = generateKeypair('alice')
const keysB = generateKeypair('bob')
const groupA = MsgV2.getMsgHash(MsgV2.createGroup(keysA, 'alice'))
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keysB, 'bob'))
const keypairA = Keypair.generate('ed25519', 'alice')
const keypairB = Keypair.generate('ed25519', 'bob')
const groupA = MsgV2.getMsgHash(MsgV2.createGroup(keypairA, 'alice'))
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keypairB, 'bob'))
const rootMsgA = MsgV2.createRoot(groupA, 'post', keysA)
const rootMsgA = MsgV2.createRoot(groupA, 'post', keypairA)
const rootHashA = MsgV2.getMsgHash(rootMsgA)
const tangleA = new MsgV2.Tangle(rootHashA)
tangleA.add(rootHashA, rootMsgA)
const rootMsgB = MsgV2.createRoot(groupB, 'post', keysB)
const rootMsgB = MsgV2.createRoot(groupB, 'post', keypairB)
const rootHashB = MsgV2.getMsgHash(rootMsgB)
const tangleB = new MsgV2.Tangle(rootHashB)
tangleB.add(rootHashB, rootMsgB)
@ -26,7 +26,7 @@ tape('simple multi-author tangle', (t) => {
tangles: {
[rootHashA]: tangleA,
},
keys: keysA,
keypair: keypairA,
})
const msgHash1 = MsgV2.getMsgHash(msg1)
t.deepEquals(
@ -47,7 +47,7 @@ tape('simple multi-author tangle', (t) => {
[rootHashB]: tangleB,
[msgHash1]: tangleX,
},
keys: keysB,
keypair: keypairB,
})
t.deepEquals(
@ -73,19 +73,19 @@ tape('simple multi-author tangle', (t) => {
})
tape('lipmaa in multi-author tangle', (t) => {
const keysA = generateKeypair('alice')
const keysB = generateKeypair('bob')
const groupA = MsgV2.getMsgHash(MsgV2.createGroup(keysA, 'alice'))
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keysB, 'bob'))
const keypairA = Keypair.generate('ed25519', 'alice')
const keypairB = Keypair.generate('ed25519', 'bob')
const groupA = MsgV2.getMsgHash(MsgV2.createGroup(keypairA, 'alice'))
const groupB = MsgV2.getMsgHash(MsgV2.createGroup(keypairB, 'bob'))
const data = { text: 'Hello world!' }
const rootMsgA = MsgV2.createRoot(groupA, 'post', keysA)
const rootMsgA = MsgV2.createRoot(groupA, 'post', keypairA)
const rootHashA = MsgV2.getMsgHash(rootMsgA)
const tangleA = new MsgV2.Tangle(rootHashA)
tangleA.add(rootHashA, rootMsgA)
const rootMsgB = MsgV2.createRoot(groupB, 'post', keysB)
const rootMsgB = MsgV2.createRoot(groupB, 'post', keypairB)
const rootHashB = MsgV2.getMsgHash(rootMsgB)
const tangleB = new MsgV2.Tangle(rootHashB)
tangleB.add(rootHashB, rootMsgB)
@ -98,7 +98,7 @@ tape('lipmaa in multi-author tangle', (t) => {
tangles: {
[rootHashA]: tangleA,
},
keys: keysA,
keypair: keypairA,
})
const msgHash1 = MsgV2.getMsgHash(msg1)
tangleA.add(msgHash1, msg1)
@ -120,7 +120,7 @@ tape('lipmaa in multi-author tangle', (t) => {
[rootHashB]: tangleB,
[msgHash1]: tangleThread,
},
keys: keysB,
keypair: keypairB,
})
const msgHash2 = MsgV2.getMsgHash(msg2)
tangleB.add(msgHash2, msg2)
@ -141,7 +141,7 @@ tape('lipmaa in multi-author tangle', (t) => {
[rootHashB]: tangleB,
[msgHash1]: tangleThread,
},
keys: keysB,
keypair: keypairB,
})
const msgHash3 = MsgV2.getMsgHash(msg3)
tangleB.add(msgHash3, msg3)
@ -162,7 +162,7 @@ tape('lipmaa in multi-author tangle', (t) => {
[rootHashA]: tangleA,
[msgHash1]: tangleThread,
},
keys: keysA,
keypair: keypairA,
})
const msgHash4 = MsgV2.getMsgHash(msg4)
tangleB.add(msgHash4, msg4)

View File

@ -1,13 +1,13 @@
const tape = require('tape')
const Keypair = require('ppppp-keypair')
const MsgV2 = require('../../lib/msg-v2')
const { generateKeypair } = require('../util')
tape('validate root msg', (t) => {
const keys = generateKeypair('alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keys, 'alice'))
const pubkeys = new Set([keys.id])
const keypair = Keypair.generate('ed25519', 'alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keypair, 'alice'))
const pubkeys = new Set([keypair.public])
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
@ -19,10 +19,10 @@ tape('validate root msg', (t) => {
tape('validate group tangle', (t) => {
const pubkeys = new Set()
const keys1 = generateKeypair('alice')
pubkeys.add(keys1.id)
const keypair1 = Keypair.generate('ed25519', 'alice')
pubkeys.add(keypair1.public)
const groupMsg0 = MsgV2.createGroup(keys1, 'alice')
const groupMsg0 = MsgV2.createGroup(keypair1, 'alice')
const group = MsgV2.getMsgHash(groupMsg0)
const groupMsg0Hash = group
@ -34,17 +34,17 @@ tape('validate group tangle', (t) => {
tangle.add(group, groupMsg0)
const keys2 = generateKeypair('bob')
const keypair2 = Keypair.generate('ed25519', 'bob')
const groupMsg1 = MsgV2.create({
group: null,
groupTips: null,
type: 'group',
data: { add: keys2.id },
data: { add: keypair2.public },
tangles: {
[group]: tangle,
},
keys: keys1, // announcing keys2 but signing with keys1
keypair: keypair1, // announcing keypair2 but signing with keypair1
})
const groupMsg1Hash = MsgV2.getMsgHash(groupMsg1)
@ -55,11 +55,11 @@ tape('validate group tangle', (t) => {
})
tape('validate 2nd msg with existing root', (t) => {
const keys = generateKeypair('alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keys, 'alice'))
const pubkeys = new Set([keys.id])
const keypair = Keypair.generate('ed25519', 'alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keypair, 'alice'))
const pubkeys = new Set([keypair.public])
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
@ -72,7 +72,7 @@ tape('validate 2nd msg with existing root', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash1 = MsgV2.getMsgHash(msg1)
tangle.add(msgHash1, msg1)
@ -84,11 +84,11 @@ tape('validate 2nd msg with existing root', (t) => {
})
tape('validate 2nd forked msg', (t) => {
const keys = generateKeypair('alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keys, 'alice'))
const pubkeys = new Set([keys.id])
const keypair = Keypair.generate('ed25519', 'alice')
const group = MsgV2.getMsgHash(MsgV2.createGroup(keypair, 'alice'))
const pubkeys = new Set([keypair.public])
const rootMsg = MsgV2.createRoot(group, 'post', keys)
const rootMsg = MsgV2.createRoot(group, 'post', keypair)
const rootHash = MsgV2.getMsgHash(rootMsg)
const tangle = new MsgV2.Tangle(rootHash)
tangle.add(rootHash, rootMsg)
@ -101,7 +101,7 @@ tape('validate 2nd forked msg', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash1A = MsgV2.getMsgHash(msg1A)
@ -113,7 +113,7 @@ tape('validate 2nd forked msg', (t) => {
tangles: {
[rootHash]: tangle,
},
keys,
keypair,
})
const msgHash1B = MsgV2.getMsgHash(msg1B)

View File

@ -5,16 +5,16 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-msgs-iter')
rimraf.sync(DIR)
test('msgs() iterator', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
@ -27,7 +27,7 @@ test('msgs() iterator', async (t) => {
data:
i % 2 === 0
? { text: 'hello ' + i }
: { about: peer.id, name: 'Mr. #' + i },
: { about: keypair.public, name: 'Mr. #' + i },
})
}

View File

@ -5,16 +5,16 @@ const os = require('os')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-on-msg-added')
rimraf.sync(DIR)
test('onRecordAdded', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()

View File

@ -5,17 +5,17 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-re-open')
rimraf.sync(DIR)
test('publish some msgs, close, re-open', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
const group = (await p(peer.db.group.create)(null)).hash
@ -41,7 +41,7 @@ test('publish some msgs, close, re-open', async (t) => {
const peer2 = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.use(require('ssb-box'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
t.pass('re-opened')
await peer2.db.loaded()

View File

@ -5,16 +5,16 @@ const rimraf = require('rimraf')
const SecretStack = require('secret-stack')
const caps = require('ssb-caps')
const p = require('util').promisify
const { generateKeypair } = require('./util')
const Keypair = require('ppppp-keypair')
const DIR = path.join(os.tmpdir(), 'ppppp-db-records-iter')
rimraf.sync(DIR)
test('records() iterator', async (t) => {
const keys = generateKeypair('alice')
const keypair = Keypair.generate('ed25519', 'alice')
const peer = SecretStack({ appKey: caps.shs })
.use(require('../lib'))
.call(null, { keys, path: DIR })
.call(null, { keypair, path: DIR })
await peer.db.loaded()
const group = (await p(peer.db.group.create)(null)).hash
@ -26,7 +26,7 @@ test('records() iterator', async (t) => {
data:
i % 2 === 0
? { text: 'hello ' + i }
: { about: peer.id, name: 'Mr. #' + i },
: { about: keypair.public, name: 'Mr. #' + i },
})
}

View File

@ -1,14 +0,0 @@
const ssbKeys = require('ssb-keys')
const SSBURI = require('ssb-uri2')
const base58 = require('bs58')
function generateKeypair(seed) {
const keys = ssbKeys.generate('ed25519', seed, 'buttwoo-v1')
const { data } = SSBURI.decompose(keys.id)
keys.id = base58.encode(Buffer.from(data, 'base64'))
return keys
}
module.exports = {
generateKeypair,
}