Merge remote-tracking branch 'origin' into fix/manifest-store

This commit is contained in:
Hayden Young
2024-10-31 22:45:40 +00:00
23 changed files with 3720 additions and 5036 deletions

View File

@@ -84,7 +84,7 @@ const IPFSAccessController = ({ write, storage } = {}) => async ({ orbitdb, iden
// Allow if the write access list contain the writer's id or is '*'
if (write.includes(id) || write.includes('*')) {
// Check that the identity is valid
return identities.verifyIdentity(writerIdentity)
return await identities.verifyIdentity(writerIdentity)
}
return false
}

View File

@@ -58,7 +58,7 @@ const OrbitDBAccessController = ({ write } = {}) => async ({ orbitdb, identities
// If the ACL contains the writer's public key or it contains '*'
const hasWriteAccess = await hasCapability('write', id) || await hasCapability('admin', id)
if (hasWriteAccess) {
return identities.verifyIdentity(writerIdentity)
return await identities.verifyIdentity(writerIdentity)
}
return false

View File

@@ -52,7 +52,7 @@ const PublicKeyIdentityProvider = ({ keystore }) => async () => {
}
const key = await keystore.getKey(id) || await keystore.createKey(id)
return uint8ArrayToString(key.public.marshal(), 'base16')
return uint8ArrayToString(key.publicKey.raw, 'base16')
}
/**

View File

@@ -8,7 +8,7 @@
* const storage = await MemoryStorage()
* const keystore = await KeyStore({ storage })
*/
import * as crypto from '@libp2p/crypto'
import { privateKeyFromRaw, publicKeyFromRaw, generateKeyPair } from '@libp2p/crypto/keys'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { compare as uint8ArrayCompare } from 'uint8arrays/compare'
@@ -16,9 +16,6 @@ import ComposedStorage from './storage/composed.js'
import LevelStorage from './storage/level.js'
import LRUStorage from './storage/lru.js'
const unmarshal = crypto.keys.supportedKeys.secp256k1.unmarshalSecp256k1PrivateKey
const unmarshalPubKey = crypto.keys.supportedKeys.secp256k1.unmarshalSecp256k1PublicKey
const verifySignature = async (signature, publicKey, data) => {
if (!signature) {
throw new Error('No signature given')
@@ -38,7 +35,7 @@ const verifySignature = async (signature, publicKey, data) => {
let res = false
try {
const pubKey = unmarshalPubKey(uint8ArrayFromString(publicKey, 'base16'))
const pubKey = publicKeyFromRaw(uint8ArrayFromString(publicKey, 'base16'))
res = await isValid(pubKey, data, uint8ArrayFromString(signature, 'base16'))
} catch (e) {
// Catch error: sig length wrong
@@ -195,7 +192,7 @@ const KeyStore = async ({ storage, path } = {}) => {
const { privateKey } = key
await storage.put('private_' + id, privateKey)
// Unmarshal the key and add it to the cache
const unmarshaledPrivateKey = unmarshal(privateKey)
const unmarshaledPrivateKey = privateKeyFromRaw(privateKey)
await keyCache.put(id, unmarshaledPrivateKey)
}
@@ -213,17 +210,16 @@ const KeyStore = async ({ storage, path } = {}) => {
}
// Generate a private key
const keyPair = await crypto.keys.generateKeyPair('secp256k1')
const keys = await crypto.keys.unmarshalPrivateKey(keyPair.bytes)
const keyPair = await generateKeyPair('secp256k1')
const key = {
publicKey: keys.public.marshal(),
privateKey: keys.marshal()
publicKey: keyPair.publicKey.raw,
privateKey: keyPair.raw
}
await addKey(id, key)
return keys
return keyPair
}
/**
@@ -254,7 +250,8 @@ const KeyStore = async ({ storage, path } = {}) => {
return
}
key = unmarshal(storedKey)
key = privateKeyFromRaw(storedKey)
await keyCache.put(id, key)
}
@@ -281,7 +278,7 @@ const KeyStore = async ({ storage, path } = {}) => {
throw new Error('Supported formats are `hex` and `buffer`')
}
const pubKey = keys.public.marshal()
const pubKey = keys.publicKey.raw
return format === 'buffer' ? pubKey : uint8ArrayToString(pubKey, 'base16')
}

View File

@@ -312,6 +312,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
await _heads.remove(hash)
}
/* 6. Add new entry to entries (for pinning) */
await _entries.put(entry.hash, entry.bytes)
/* 6. Add the new entry to heads (=union with current heads) */
await _heads.add(entry)