align impl and spec regarding account key purposes

This commit is contained in:
Andre Staltz 2023-11-16 14:09:55 +02:00
parent fc47a4006b
commit 3e4fe864f7
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
6 changed files with 33 additions and 28 deletions

View File

@ -311,7 +311,8 @@ function initDB(peer, config) {
/** @type {AccountData} */
const data = msg.data
if (data.action !== 'add') continue
if (data.key.purpose !== 'sig') continue
const purpose = data.key?.purpose
if (purpose !== 'sig' && purpose !== 'shs-and-sig') continue
if (data.key.algorithm !== 'ed25519') continue
pubkeys.add(data.key.bytes)
}

View File

@ -61,21 +61,25 @@ const { isEmptyObject } = require('./util')
*
* @typedef {AccountAdd | AccountDel} AccountData
*
* @typedef {'add' | 'del' | 'box'} AccountPower
* @typedef {'add' | 'del' | 'internal-encryption' | 'external-encryption'} AccountPower
*
* @typedef {{
* purpose: 'shs-and-sig';
* algorithm: 'ed25519';
* bytes: string;
* }} ShsAndSigKey
* @typedef {{
* purpose: 'sig';
* algorithm: 'ed25519';
* bytes: string;
* }} SigKey
*
* @typedef {{
* purpose: 'box';
* purpose: 'external-encryption';
* algorithm: 'x25519-xsalsa20-poly1305';
* bytes: string;
* }} BoxKey;
* }} ExternalEncryptionKey;
*
* @typedef {SigKey | BoxKey} AccountKey
* @typedef {ShsAndSigKey | SigKey | ExternalEncryptionKey} AccountKey
*
* @typedef {{
* action: 'add',
@ -234,12 +238,12 @@ function createAccount(keypair, domain, nonce = getRandomNonce) {
const data = {
action: 'add',
key: {
purpose: 'sig',
purpose: 'shs-and-sig',
algorithm: 'ed25519',
bytes: keypair.public,
},
nonce: typeof nonce === 'function' ? nonce() : nonce,
powers: ['add', 'del', 'box'],
powers: ['add', 'del', 'external-encryption', 'internal-encryption'],
}
return create({

View File

@ -70,10 +70,10 @@ interface Msg {
type AccountData = AccountAdd | AccountDel
// "add" means this shs peer can validly add more keys to the account tangle
// "del" means this shs peer can validly revoke keys from the account tangle
// "internal-encryption" means this shs peer should get access to symmetric key
// "external-encryption" means this shs peer should get access to asymmetric key
// (if key is sig) "add" means this key can validly add more keys to the account
// (if key is sig) "del" means this key can validly revoke keys from the account
// (if key is shs) "internal-encryption" means this peer can get symmetric key
// (if key is shs) "external-encryption" means this peer can get asymmetric key
type AccountPower = 'add' | 'del' | 'internal-encryption' | 'external-encryption'
type AccountAdd = {
@ -91,7 +91,7 @@ type AccountDel = {
type Key =
| {
purpose: 'shs-and-external-signature' // secret-handshake and digital signatures
purpose: 'shs-and-sig' // secret-handshake and digital signatures
algorithm: 'ed25519' // libsodium crypto_sign_detached
bytes: string // base58 encoded string for the public key
}
@ -101,8 +101,8 @@ type Key =
bytes: string // base58 encoded string of the public key
}
| {
purpose: 'internal-signature', // digital signatures of internal msgs
algorithm: 'ed25519', // libsodium crypto_sign_detached
purpose: 'sig' // secret-handshake and digital signatures
algorithm: 'ed25519' // libsodium crypto_sign_detached
bytes: string // base58 encoded string for the public key
}
```

View File

@ -31,12 +31,12 @@ test('account.create() ', async (t) => {
{
action: 'add',
key: {
purpose: 'sig',
purpose: 'shs-and-sig',
algorithm: 'ed25519',
bytes: keypair.public,
},
nonce: 'MYNONCE',
powers: ['add', 'del', 'box'],
powers: ['add', 'del', 'external-encryption', 'internal-encryption'],
},
'msg.data'
)

View File

@ -50,7 +50,7 @@ test('add()', async (t) => {
await p(peer.db._getLog().onDrain)()
const stats = await p(peer.db.logStats)()
assert.deepEqual(stats, { totalBytes: 897, deletedBytes: 0 })
assert.deepEqual(stats, { totalBytes: 943, deletedBytes: 0 })
await p(peer.close)(true)
})

View File

@ -15,17 +15,17 @@ test('MsgV3.createAccount()', (t) => {
{
action: 'add',
key: {
purpose: 'sig',
purpose: 'shs-and-sig',
algorithm: 'ed25519',
bytes: keypair.public,
},
nonce: 'MYNONCE',
powers: ['add', 'del', 'box'],
powers: ['add', 'del', 'external-encryption', 'internal-encryption'],
},
'data'
)
assert.equal(accountMsg0.metadata.dataHash, 'DQCPxgzni6UTZ5DSCms9Y', 'hash')
assert.equal(accountMsg0.metadata.dataSize, 164, 'size')
assert.equal(accountMsg0.metadata.dataHash, 'NxJZecVcVUWmUkk6cAn9JV', 'hash')
assert.equal(accountMsg0.metadata.dataSize, 210, 'size')
assert.equal(accountMsg0.metadata.account, 'self', 'account')
assert.equal(accountMsg0.metadata.accountTips, null, 'accountTips')
assert.deepEqual(accountMsg0.metadata.tangles, {}, 'tangles')
@ -34,7 +34,7 @@ test('MsgV3.createAccount()', (t) => {
assert.equal(accountMsg0.pubkey, keypair.public, 'pubkey')
account = MsgV3.getMsgID(accountMsg0)
assert.equal(account, 'Hx9Fuitrg3WQCCcBaPqpeo', 'account ID')
assert.equal(account, 'UQN1Qmxr4rr9nCMQKs9u8P', 'account ID')
})
let moot = null
@ -56,7 +56,7 @@ test('MsgV3.createMoot()', (t) => {
assert.equal(moot.pubkey, keypair.public, 'pubkey')
mootID = MsgV3.getMsgID(moot)
assert.equal(mootID, 'YYrum2aUPGLarrVnjM5o93', 'moot ID')
assert.equal(mootID, 'AP2rJSfm9TwpNcMmbUsnRa', 'moot ID')
})
test('MsgV3.create()', (t) => {
@ -116,11 +116,11 @@ test('MsgV3.create()', (t) => {
)
assert.equal(
msg1.sig,
'5wrhPju22NHuq1qFK9qMrNafUMAhCHnLurGfASCVhPTjQTVQE4SqdV9G3zmUTesxFmynn7a1P6nJFgfvWGuSw86h',
'rh8bc8QY7ju7yi4rt6y9njCyS3TVV1SBjn5dWGpKKRrC3XDMBc9KeNJgVCJLK8b8uiU5F49avAWt35P9kNaWZYH',
'sig'
)
const msgID1 = '7qfYPwQ1qYHYHLSXzGQCCy'
const msgID1 = 'MUvfNDk3gMPRy9CpTDEuvW'
assert.equal(MsgV3.getMsgID(msg1), msgID1, 'getMsgID')
@ -180,11 +180,11 @@ test('MsgV3.create()', (t) => {
)
assert.equal(
msg2.sig,
'2xsdFCPsUzmaGzoQaANJSJHkCAZt3qyVUDW88RBV3r1PCspzU3BbKdQxHoxKYKcwLrpxxi4cSd5eyfcEt3DV61ge',
'3NscyRLJZP8mtq4DhhNPfwtw8yzoWsFytxGxD2QAqjW64RMeRLP5czN5mMYm4nCqRtXvzRgRhqgN1qtz9hWW14S4',
'sig'
)
assert.deepEqual(MsgV3.getMsgID(msg2), '38GT4SxtEqfZffkCrNYLtY', 'getMsgID')
assert.deepEqual(MsgV3.getMsgID(msg2), 'XMeQ6sbW3mjLYRLR4dAmKD', 'getMsgID')
})
test('MsgV3.create() handles DAG tips correctly', (t) => {