Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update package dependencies #16

102 changes: 27 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"@types/jest": "^29.5.8",
"@types/libsodium-wrappers-sumo": "^0.7.8",
"@types/node": "^20.9.0",
"@types/text-encoding": "^0.0.39",
"@types/urlsafe-base64": "^1.0.31",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"depcheck": "^1.4.7",
Expand All @@ -41,14 +39,8 @@
"typescript": "^5.2.2"
},
"dependencies": {
"blake3": "^2.1.7",
"ecdsa-secp256r1": "^1.3.3",
"libsodium-wrappers-sumo": "^0.7.13",
"text-encoding": "^0.7.0",
"urlsafe-base64": "^1.0.0"
},
"overrides": {
"blake3-wasm": "^2.1.7",
"@c4312/blake3-internal": "^2.1.7"
"@noble/curves": "^1.2.0",
"@noble/hashes": "^1.3.2",
"libsodium-wrappers-sumo": "^0.7.13"
}
}
5 changes: 2 additions & 3 deletions src/bexter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BexDex, Matter, MatterArgs, MtrDex } from './matter';
import { EmptyMaterialError } from './kering';
import Base64 from 'urlsafe-base64';

const B64REX = '^[A-Za-z0-9\\-_]*$';
export const Reb64 = new RegExp(B64REX);
Expand Down Expand Up @@ -114,15 +113,15 @@ export class Bexter extends Matter {
const wad = new Array(ws);
wad.fill('A');
const base = wad.join('') + bext; // pre pad with wad of zeros in Base64 == 'A'
const raw = Base64.decode(base); // [ls:] // convert and remove leader
const raw = Buffer.from(base,'base64url'); // [ls:] // convert and remove leader

return Uint8Array.from(raw).subarray(ls); // raw binary equivalent of text
}

get bext(): string {
const sizage = Matter.Sizes.get(this.code);
const wad = Uint8Array.from(new Array(sizage?.ls).fill(0));
const bext = Base64.encode(Buffer.from([...wad, ...this.raw]));
const bext = Buffer.from([...wad, ...this.raw]).toString('base64url');

let ws = 0;
if (sizage?.ls === 0 && bext !== undefined) {
Expand Down
2 changes: 0 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// import {TextEncoder, TextDecoder} from 'util'
import { TextEncoder, TextDecoder } from 'text-encoding';
export enum Serials {
JSON = 'JSON',
}
Expand Down
14 changes: 9 additions & 5 deletions src/diger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createHash } from 'blake3';
import { blake3 } from '@noble/hashes/blake3';

import { Matter, MatterArgs, MtrDex } from './matter';

Expand All @@ -25,8 +25,10 @@ export class Diger extends Matter {
}

if (code === MtrDex.Blake3_256) {
const hasher = createHash();
const dig = hasher.update(ser).digest('');
const dig = blake3
.create({})
.update(ser)
.digest()
super({ raw: dig, code: code });
} else {
throw new Error(`Unsupported code = ${code} for digester.`);
Expand Down Expand Up @@ -74,8 +76,10 @@ export class Diger extends Matter {
}

blake3_256(ser: Uint8Array, dig: any) {
const hasher = createHash();
const digest = hasher.update(ser).digest('');
const digest = blake3
.create({})
.update(ser)
.digest()
return digest.toString() === dig.toString();
}
}
7 changes: 3 additions & 4 deletions src/indexer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EmptyMaterialError } from './kering';
import { b, b64ToInt, d, intToB64, readInt } from './core';
import Base64 from 'urlsafe-base64';
import { Buffer } from 'buffer';

export class IndexerCodex {
Expand Down Expand Up @@ -399,7 +398,7 @@ export class Indexer {
}

const full =
both + Base64.encode(Buffer.from(bytes)).slice(ps - xizage.ls);
both + Buffer.from(bytes).toString('base64url').slice(ps - xizage.ls);
if (full.length != xizage.fs) {
throw new Error(`Invalid code=${both} for raw size=${raw.length}.`);
}
Expand Down Expand Up @@ -474,7 +473,7 @@ export class Indexer {
let raw;
if (ps != 0) {
const base = new Array(ps + 1).join('A') + qb64.slice(cs);
const paw = Base64.decode(base); // decode base to leave prepadded raw
const paw = Buffer.from(base,'base64url'); // decode base to leave prepadded raw
const pi = readInt(paw.slice(0, ps)); // prepad as int
if (pi & (2 ** pbs - 1)) {
// masked pad bits non-zero
Expand All @@ -485,7 +484,7 @@ export class Indexer {
raw = paw.slice(ps); // strip off ps prepad paw bytes
} else {
const base = qb64.slice(cs);
const paw = Base64.decode(base);
const paw = Buffer.from(base,'base64url');
const li = readInt(paw.slice(0, xizage!.ls));
if (li != 0) {
if (li == 1) {
Expand Down
9 changes: 4 additions & 5 deletions src/matter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EmptyMaterialError } from './kering';

import { intToB64, readInt } from './core';
import Base64 from 'urlsafe-base64';
import { b, d } from './core';
import { Buffer } from 'buffer';

Expand Down Expand Up @@ -421,7 +420,7 @@ export class Matter {
bytes[odx] = raw[i];
}

return both + Base64.encode(Buffer.from(bytes));
return both + Buffer.from(bytes).toString('base64url');
} else {
const both = code;
const cs = both.length;
Expand All @@ -443,7 +442,7 @@ export class Matter {
bytes[odx] = raw[i];
}

return both + Base64.encode(Buffer.from(bytes)).slice(cs % 4);
return both + Buffer.from(bytes).toString('base64url').slice(cs % 4);
}
}

Expand Down Expand Up @@ -487,7 +486,7 @@ export class Matter {
let raw;
if (ps != 0) {
const base = new Array(ps + 1).join('A') + qb64.slice(cs);
const paw = Base64.decode(base); // decode base to leave prepadded raw
const paw = Buffer.from(base, 'base64url'); // decode base to leave prepadded raw
const pi = readInt(paw.subarray(0, ps)); // prepad as int
if (pi & (2 ** pbs - 1)) {
// masked pad bits non-zero
Expand All @@ -498,7 +497,7 @@ export class Matter {
raw = paw.subarray(ps); // strip off ps prepad paw bytes
} else {
const base = qb64.slice(cs);
const paw = Base64.decode(base);
const paw = Buffer.from(base,'base64url');
const li = readInt(paw.subarray(0, sizage!.ls));
if (li != 0) {
if (li == 1) {
Expand Down
8 changes: 5 additions & 3 deletions src/prefixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Dict, Ilks } from './core';
import { sizeify } from './serder';
import { Verfer } from './verfer';

import { createHash } from 'blake3';
import { blake3 } from '@noble/hashes/blake3';

const Dummy: string = '#';

Expand Down Expand Up @@ -148,8 +148,10 @@ export class Prefixer extends Matter {
kd['i'] = ''.padStart(Matter.Sizes.get(MtrDex.Blake3_256)!.fs!, Dummy);
kd['d'] = ked['i'];
const [raw] = sizeify(ked);
const hasher = createHash();
const dig = hasher.update(raw).digest('');
const dig = blake3
.create({})
.update(raw)
.digest()
return [dig, MtrDex.Blake3_256];
}

Expand Down
8 changes: 5 additions & 3 deletions src/saider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { deversify, Dict, Serials } from './core';
import { EmptyMaterialError } from './kering';
import { dumps, sizeify } from './serder';

import { createHash } from 'blake3';
import { blake3 } from '@noble/hashes/blake3'

const Dummy = '#';

Expand Down Expand Up @@ -74,8 +74,10 @@ export class Saider extends Matter {
_digest_size: number,
_length: number
) {
const hasher = createHash();
return hasher.update(ser).digest('');
return blake3
.create({})
.update(ser)
.digest();
}

private static _derive(
Expand Down
Loading