Comparing version 0.0.48 to 0.0.49
@@ -1,9 +0,11 @@ | ||
declare function b64ToBuf(b64: string): [Uint8Array, string | null]; | ||
import { error } from "./types.js"; | ||
declare function b64ToBuf(b64: string): [Uint8Array, error]; | ||
declare function bufToHex(buf: Uint8Array): string; | ||
declare function bufToB64(buf: Uint8Array): string; | ||
declare function bufToStr(buf: ArrayBuffer): [string, string | null]; | ||
declare function decodeBigint(buf: Uint8Array): [bigint, string | null]; | ||
declare function encodePrefixedBytes(bytes: Uint8Array): [Uint8Array, string | null]; | ||
declare function encodeU64(num: bigint): [Uint8Array, string | null]; | ||
declare function hexToBuf(hex: string): [Uint8Array, string | null]; | ||
export { b64ToBuf, bufToHex, bufToB64, bufToStr, decodeBigint, encodePrefixedBytes, encodeU64, hexToBuf }; | ||
declare function bufToStr(buf: ArrayBuffer): [string, error]; | ||
declare function decodeBigint(buf: Uint8Array): [bigint, error]; | ||
declare function decodeU64(u8: Uint8Array): [bigint, error]; | ||
declare function encodePrefixedBytes(bytes: Uint8Array): [Uint8Array, error]; | ||
declare function encodeU64(num: bigint): [Uint8Array, error]; | ||
declare function hexToBuf(hex: string): [Uint8Array, error]; | ||
export { b64ToBuf, bufToHex, bufToB64, bufToStr, decodeBigint, decodeU64, encodePrefixedBytes, encodeU64, hexToBuf }; |
@@ -58,2 +58,17 @@ import { addContextToErr } from "./err.js"; | ||
} | ||
// decodeU64 is the opposite of encodeU64, it takes a uint64 encoded as 8 bytes | ||
// and decodes them into a BigInt. | ||
function decodeU64(u8) { | ||
// Check the input. | ||
if (u8.length !== 8) { | ||
return [0n, "input should be 8 bytes"]; | ||
} | ||
// Process the input. | ||
let num = 0n; | ||
for (let i = u8.length - 1; i >= 0; i--) { | ||
num *= 256n; | ||
num += BigInt(u8[i]); | ||
} | ||
return [num, null]; | ||
} | ||
// encodePrefixedBytes takes a Uint8Array as input and returns a Uint8Array | ||
@@ -113,2 +128,2 @@ // that has the length prefixed as an 8 byte prefix. The input can be at most 4 | ||
} | ||
export { b64ToBuf, bufToHex, bufToB64, bufToStr, decodeBigint, encodePrefixedBytes, encodeU64, hexToBuf }; | ||
export { b64ToBuf, bufToHex, bufToB64, bufToStr, decodeBigint, decodeU64, encodePrefixedBytes, encodeU64, hexToBuf }; |
@@ -10,6 +10,7 @@ export { blake2b } from "./blake2b.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { decryptFile, encryptFile } from "./fileprivate.js"; | ||
export { blake2bAddLeafBytesToProofStack, blake2bMerkleRoot, blake2bProofStackRoot } from "./merkle.js"; | ||
export { parseJSON } from "./parse.js"; | ||
export { progressiveFetch, progressiveFetchResult } from "./progressivefetch.js"; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, } from "./registry.js"; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, skylinkToResolverEntryData, taggedRegistryEntryKeys, verifyRegistrySignature, } from "./registry.js"; | ||
export { verifyRegistryReadResponse, verifyRegistryWriteResponse } from "./registryverify.js"; | ||
@@ -16,0 +17,0 @@ export { deriveChildSeed, deriveMyskyRootKeypair, generateSeedPhraseDeterministic, seedPhraseToSeed, validSeedPhrase, } from "./seed.js"; |
@@ -10,6 +10,7 @@ export { blake2b } from "./blake2b.js"; | ||
export { addContextToErr, composeErr } from "./err.js"; | ||
export { decryptFile, encryptFile } from "./fileprivate.js"; | ||
export { blake2bAddLeafBytesToProofStack, blake2bMerkleRoot, blake2bProofStackRoot } from "./merkle.js"; | ||
export { parseJSON } from "./parse.js"; | ||
export { progressiveFetch } from "./progressivefetch.js"; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, } from "./registry.js"; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, skylinkToResolverEntryData, taggedRegistryEntryKeys, verifyRegistrySignature, } from "./registry.js"; | ||
export { verifyRegistryReadResponse, verifyRegistryWriteResponse } from "./registryverify.js"; | ||
@@ -16,0 +17,0 @@ export { deriveChildSeed, deriveMyskyRootKeypair, generateSeedPhraseDeterministic, seedPhraseToSeed, validSeedPhrase, } from "./seed.js"; |
@@ -6,5 +6,6 @@ import { ed25519Keypair } from "./ed25519.js"; | ||
declare function entryIDToSkylink(entryID: Uint8Array): string; | ||
declare function skylinkToResolverEntryData(skylink: string): [Uint8Array, error]; | ||
declare function resolverLink(entryID: Uint8Array): [string, string | null]; | ||
declare function taggedRegistryEntryKeys(seed: Uint8Array, keypairTagStr: string, datakeyTagStr?: string): [ed25519Keypair, Uint8Array, string | null]; | ||
declare function verifyRegistrySignature(pubkey: Uint8Array, datakey: Uint8Array, data: Uint8Array, revision: bigint, sig: Uint8Array): boolean; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, }; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, skylinkToResolverEntryData, taggedRegistryEntryKeys, verifyRegistrySignature, }; |
import { blake2b } from "./blake2b.js"; | ||
import { bufToB64, encodePrefixedBytes, encodeU64 } from "./encoding.js"; | ||
import { bufToB64, b64ToBuf, encodePrefixedBytes, encodeU64 } from "./encoding.js"; | ||
import { addContextToErr } from "./err.js"; | ||
@@ -82,2 +82,12 @@ import { ed25519KeypairFromEntropy, ed25519Sign, ed25519Verify } from "./ed25519.js"; | ||
} | ||
// skylinkToResolverEntryData will convert a skylink to the Uint8Array that can | ||
// be set as the entry data of a resolver link to create a working resolver | ||
// link. | ||
// | ||
// It's just a passthrough to b64ToBuf, but that's not obvious unless you are | ||
// familiar with the internals of how resolver skylinks work. This function is | ||
// provided as an intuitive alternative. | ||
function skylinkToResolverEntryData(skylink) { | ||
return b64ToBuf(skylink); | ||
} | ||
// resolverLink will take a registryEntryID and return the corresponding | ||
@@ -168,2 +178,2 @@ // resolver link. | ||
} | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, }; | ||
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, skylinkToResolverEntryData, taggedRegistryEntryKeys, verifyRegistrySignature, }; |
declare const sha512internal: (out: Uint8Array, m: Uint8Array, n: number) => number; | ||
export default function sha512(m: Uint8Array): Uint8Array; | ||
export { sha512, sha512internal }; | ||
declare function sha512(m: Uint8Array): Uint8Array; | ||
declare const sha512HashSize = 64; | ||
export { sha512, sha512internal, sha512HashSize }; |
@@ -391,3 +391,3 @@ const HASH_SIZE = 64; | ||
// standards use blake2b instead, so you will see both. | ||
export default function sha512(m) { | ||
function sha512(m) { | ||
const out = new Uint8Array(HASH_SIZE); | ||
@@ -397,2 +397,3 @@ sha512internal(out, m, m.length); | ||
} | ||
export { sha512, sha512internal }; | ||
const sha512HashSize = HASH_SIZE; | ||
export { sha512, sha512internal, sha512HashSize }; |
{ | ||
"name": "libskynet", | ||
"version": "0.0.48", | ||
"version": "0.0.49", | ||
"author": "Skynet Labs", | ||
"description": "helper library to interact with skynet's low level primitives", | ||
@@ -8,2 +9,5 @@ "main": "dist/index.js", | ||
"types": "dist/index.d.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
@@ -19,3 +23,2 @@ "/dist" | ||
}, | ||
"author": "David Vorick", | ||
"devDependencies": { | ||
@@ -22,0 +25,0 @@ "@types/node": "^17.0.23", |
165177
56
4946