*Move hashDataKey to a dedicated utility package
This commit is contained in:
parent
20e9511eae
commit
693081c740
|
@ -11,6 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hyperswarm/dht": "^6.0.1",
|
"@hyperswarm/dht": "^6.0.1",
|
||||||
"@hyperswarm/dht-relay": "^0.3.0",
|
"@hyperswarm/dht-relay": "^0.3.0",
|
||||||
|
"@lumeweb/kernel-utils": "https://github.com/LumeWeb/kernel-utils.git",
|
||||||
"@pokt-network/pocket-js": "^0.8.0-rc",
|
"@pokt-network/pocket-js": "^0.8.0-rc",
|
||||||
"@solana/web3.js": "^1.47.3",
|
"@solana/web3.js": "^1.47.3",
|
||||||
"@types/acme-client": "^3.3.0",
|
"@types/acme-client": "^3.3.0",
|
||||||
|
|
|
@ -5,9 +5,10 @@ import { overwriteRegistryEntry } from "libskynetnode";
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import { Parser } from "xml2js";
|
import { Parser } from "xml2js";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { errorExit, hashDataKey } from "./util.js";
|
import { errorExit } from "./util.js";
|
||||||
import { pack } from "msgpackr";
|
import { pack } from "msgpackr";
|
||||||
import config from "./config.js";
|
import config from "./config.js";
|
||||||
|
import { hashDataKey } from "@lumeweb/kernel-utils";
|
||||||
|
|
||||||
const { createHash } = await import("crypto");
|
const { createHash } = await import("crypto");
|
||||||
|
|
||||||
|
|
27
src/util.ts
27
src/util.ts
|
@ -1,6 +1,4 @@
|
||||||
import * as chainNetworks from "./networks.json" assert { type: "json" };
|
import * as chainNetworks from "./networks.json" assert { type: "json" };
|
||||||
import { Buffer } from "buffer";
|
|
||||||
import { blake2b } from "libskynet";
|
|
||||||
|
|
||||||
type networks = { [net: string]: string };
|
type networks = { [net: string]: string };
|
||||||
|
|
||||||
|
@ -39,28 +37,3 @@ export function isIp(ip: string) {
|
||||||
ip
|
ip
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hashDataKey(dataKey: string): Uint8Array {
|
|
||||||
return blake2b(encodeUtf8String(dataKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeUtf8String(str: string): Uint8Array {
|
|
||||||
const byteArray = stringToUint8ArrayUtf8(str);
|
|
||||||
const encoded = new Uint8Array(8 + byteArray.length);
|
|
||||||
encoded.set(encodeNumber(byteArray.length));
|
|
||||||
encoded.set(byteArray, 8);
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
function stringToUint8ArrayUtf8(str: string): Uint8Array {
|
|
||||||
return Uint8Array.from(Buffer.from(str, "utf-8"));
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeNumber(num: number): Uint8Array {
|
|
||||||
const encoded = new Uint8Array(8);
|
|
||||||
for (let index = 0; index < encoded.length; index++) {
|
|
||||||
encoded[index] = num & 0xff;
|
|
||||||
num = num >> 8;
|
|
||||||
}
|
|
||||||
return encoded;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue