Compare commits

...

3 Commits

7 changed files with 17 additions and 23 deletions

View File

@ -1,3 +1,5 @@
# [0.1.0-develop.43](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.42...v0.1.0-develop.43) (2023-09-02)
# [0.1.0-develop.42](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.41...v0.1.0-develop.42) (2023-09-02) # [0.1.0-develop.42](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.41...v0.1.0-develop.42) (2023-09-02)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@lumeweb/libs5", "name": "@lumeweb/libs5",
"version": "0.1.0-develop.42", "version": "0.1.0-develop.43",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lumeweb/libs5", "name": "@lumeweb/libs5",
"version": "0.1.0-develop.42", "version": "0.1.0-develop.43",
"dependencies": { "dependencies": {
"@noble/curves": "^1.1.0", "@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1", "@noble/hashes": "^1.3.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lumeweb/libs5", "name": "@lumeweb/libs5",
"version": "0.1.0-develop.42", "version": "0.1.0-develop.43",
"type": "module", "type": "module",
"main": "lib/index.js", "main": "lib/index.js",
"repository": { "repository": {

View File

@ -28,9 +28,12 @@ Object.freeze(REGISTRY_TYPES);
// ! some multicodec bytes // ! some multicodec bytes
// BLAKE3 with default output size of 256 bits // BLAKE3 with default output size of 256 bits
export const mhashBlake3Default = 0x1f;
export const mkeyEd25519 = 0xed; export const CID_HASH_TYPES = {
BLAKE3: 0x1f,
ED25519: 0xed,
};
Object.freeze(CID_HASH_TYPES);
export const encryptionAlgorithmXChaCha20Poly1305 = 0xa6; export const encryptionAlgorithmXChaCha20Poly1305 = 0xa6;
export const encryptionAlgorithmXChaCha20Poly1305NonceSize = 24; export const encryptionAlgorithmXChaCha20Poly1305NonceSize = 24;
@ -42,13 +45,6 @@ export const contentPackFileHeader = Uint8Array.from([0x5f, 0x26, 0x73, 0x35]);
// used as the first byte of metadata files // used as the first byte of metadata files
export const metadataMagicByte = 0x5f; export const metadataMagicByte = 0x5f;
// types for metadata files
export const metadataTypeMedia = 0x02;
export const metadataTypeWebApp = 0x03;
export const metadataTypeDirectory = 0x04;
export const metadataTypeProofs = 0x05;
export const metadataTypeUserIdentity = 0x07;
export const METADATA_TYPES = { export const METADATA_TYPES = {
MEDIA: 0x02, MEDIA: 0x02,
WEBAPP: 0x03, WEBAPP: 0x03,
@ -58,10 +54,6 @@ export const METADATA_TYPES = {
}; };
Object.freeze(METADATA_TYPES); Object.freeze(METADATA_TYPES);
export const parentLinkTypeUserIdentity = 1;
export const parentLinkTypeBoard = 5;
export const parentLinkTypeBridgeUser = 10;
export const PARENT_LINK_TYPES = { export const PARENT_LINK_TYPES = {
USER_IDENTITY: 1, USER_IDENTITY: 1,
BOARD: 5, BOARD: 5,

View File

@ -1,6 +1,6 @@
import { ed25519 } from "@noble/curves/ed25519"; import { ed25519 } from "@noble/curves/ed25519";
import { concatBytes } from "@noble/curves/abstract/utils"; import { concatBytes } from "@noble/curves/abstract/utils";
import { mkeyEd25519 } from "./constants.js"; import { CID_HASH_TYPES } from "./constants.js";
export default class KeyPairEd25519 { export default class KeyPairEd25519 {
private _bytes: Uint8Array; private _bytes: Uint8Array;
@ -11,7 +11,7 @@ export default class KeyPairEd25519 {
public get publicKey(): Uint8Array { public get publicKey(): Uint8Array {
return concatBytes( return concatBytes(
Uint8Array.from([mkeyEd25519]), Uint8Array.from([CID_HASH_TYPES.ED25519]),
ed25519.getPublicKey(this._bytes), ed25519.getPublicKey(this._bytes),
); );
} }

View File

@ -3,10 +3,10 @@ import { Peer } from "#types.js";
import Unpacker from "#serialization/unpack.js"; import Unpacker from "#serialization/unpack.js";
import { Multihash } from "#multihash.js"; import { Multihash } from "#multihash.js";
import { decodeEndian } from "#util.js"; import { decodeEndian } from "#util.js";
import { mkeyEd25519 } from "#constants.js";
import { ed25519 } from "@noble/curves/ed25519"; import { ed25519 } from "@noble/curves/ed25519";
import NodeId from "#nodeId.js"; import NodeId from "#nodeId.js";
import StorageLocation from "#storage.js"; import StorageLocation from "#storage.js";
import { CID_HASH_TYPES } from "#constants.js";
export default async function ( export default async function (
node: S5Node, node: S5Node,
@ -34,8 +34,8 @@ export default async function (
const publicKey = rawData.subarray(cursor, cursor + 33); const publicKey = rawData.subarray(cursor, cursor + 33);
const signature = rawData.subarray(cursor + 33); const signature = rawData.subarray(cursor + 33);
if (publicKey[0] !== mkeyEd25519) { if (publicKey[0] !== CID_HASH_TYPES.ED25519) {
throw `Unsupported public key type ${mkeyEd25519}`; throw `Unsupported public key type ${publicKey[0]}`;
} }
if ( if (

View File

@ -1,7 +1,7 @@
import { Logger, Peer, SignedRegistryEntry } from "#types.js"; import { Logger, Peer, SignedRegistryEntry } from "#types.js";
import { AbstractLevel, AbstractSublevel } from "abstract-level"; import { AbstractLevel, AbstractSublevel } from "abstract-level";
import { import {
mkeyEd25519, CID_HASH_TYPES,
protocolMethodRegistryQuery, protocolMethodRegistryQuery,
recordTypeRegistryEntry, recordTypeRegistryEntry,
registryMaxDataSize, registryMaxDataSize,
@ -54,7 +54,7 @@ export class RegistryService {
if (sre.pk.length !== 33) { if (sre.pk.length !== 33) {
throw new Error("Invalid pubkey"); throw new Error("Invalid pubkey");
} }
if (sre.pk[0] !== mkeyEd25519) { if (sre.pk[0] !== CID_HASH_TYPES.ED25519) {
throw new Error("Only ed25519 keys are supported"); throw new Error("Only ed25519 keys are supported");
} }
if (sre.revision < 0 || sre.revision > 281474976710656) { if (sre.revision < 0 || sre.revision > 281474976710656) {