refactor: move hash types to frozen object group
This commit is contained in:
parent
7f8f35cb35
commit
a34bd1b813
|
@ -28,9 +28,12 @@ Object.freeze(REGISTRY_TYPES);
|
|||
|
||||
// ! some multicodec bytes
|
||||
// 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 encryptionAlgorithmXChaCha20Poly1305NonceSize = 24;
|
||||
|
@ -42,13 +45,6 @@ export const contentPackFileHeader = Uint8Array.from([0x5f, 0x26, 0x73, 0x35]);
|
|||
// used as the first byte of metadata files
|
||||
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 = {
|
||||
MEDIA: 0x02,
|
||||
WEBAPP: 0x03,
|
||||
|
@ -58,10 +54,6 @@ export const METADATA_TYPES = {
|
|||
};
|
||||
Object.freeze(METADATA_TYPES);
|
||||
|
||||
export const parentLinkTypeUserIdentity = 1;
|
||||
export const parentLinkTypeBoard = 5;
|
||||
export const parentLinkTypeBridgeUser = 10;
|
||||
|
||||
export const PARENT_LINK_TYPES = {
|
||||
USER_IDENTITY: 1,
|
||||
BOARD: 5,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ed25519 } from "@noble/curves/ed25519";
|
||||
import { concatBytes } from "@noble/curves/abstract/utils";
|
||||
import { mkeyEd25519 } from "./constants.js";
|
||||
import { CID_HASH_TYPES } from "./constants.js";
|
||||
|
||||
export default class KeyPairEd25519 {
|
||||
private _bytes: Uint8Array;
|
||||
|
@ -11,7 +11,7 @@ export default class KeyPairEd25519 {
|
|||
|
||||
public get publicKey(): Uint8Array {
|
||||
return concatBytes(
|
||||
Uint8Array.from([mkeyEd25519]),
|
||||
Uint8Array.from([CID_HASH_TYPES.ED25519]),
|
||||
ed25519.getPublicKey(this._bytes),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ import { Peer } from "#types.js";
|
|||
import Unpacker from "#serialization/unpack.js";
|
||||
import { Multihash } from "#multihash.js";
|
||||
import { decodeEndian } from "#util.js";
|
||||
import { mkeyEd25519 } from "#constants.js";
|
||||
import { ed25519 } from "@noble/curves/ed25519";
|
||||
import NodeId from "#nodeId.js";
|
||||
import StorageLocation from "#storage.js";
|
||||
import { CID_HASH_TYPES } from "#constants.js";
|
||||
|
||||
export default async function (
|
||||
node: S5Node,
|
||||
|
@ -34,8 +34,8 @@ export default async function (
|
|||
const publicKey = rawData.subarray(cursor, cursor + 33);
|
||||
const signature = rawData.subarray(cursor + 33);
|
||||
|
||||
if (publicKey[0] !== mkeyEd25519) {
|
||||
throw `Unsupported public key type ${mkeyEd25519}`;
|
||||
if (publicKey[0] !== CID_HASH_TYPES.ED25519) {
|
||||
throw `Unsupported public key type ${publicKey[0]}`;
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Logger, Peer, SignedRegistryEntry } from "#types.js";
|
||||
import { AbstractLevel, AbstractSublevel } from "abstract-level";
|
||||
import {
|
||||
mkeyEd25519,
|
||||
CID_HASH_TYPES,
|
||||
protocolMethodRegistryQuery,
|
||||
recordTypeRegistryEntry,
|
||||
registryMaxDataSize,
|
||||
|
@ -54,7 +54,7 @@ export class RegistryService {
|
|||
if (sre.pk.length !== 33) {
|
||||
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");
|
||||
}
|
||||
if (sre.revision < 0 || sre.revision > 281474976710656) {
|
||||
|
|
Loading…
Reference in New Issue