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

Using @nobles/hashes #162

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,699 changes: 1,513 additions & 2,186 deletions package-lock.json
lenkan marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"whatwg-fetch": "^3.6.19"
},
"dependencies": {
"blake3": "^2.1.7",
"@noble/hashes": "^1.3.2",
"buffer": "^6.0.3",
"ecdsa-secp256r1": "^1.3.3",
"libsodium-wrappers-sumo": "^0.7.9",
Expand Down
12 changes: 7 additions & 5 deletions src/keri/core/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,9 @@ export class Diger extends Matter {
}

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

blake3_256(ser: Uint8Array, dig: any) {
const hasher = createHash();
const digest = hasher.update(ser).digest('');
const digest = Buffer.from(
blake3.create({ dkLen: 32 }).update(ser).digest()
);
return digest.toString() === dig.toString();
}
}
7 changes: 4 additions & 3 deletions src/keri/core/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,9 @@ 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 = Buffer.from(
blake3.create({ dkLen: 32 }).update(raw).digest()
);
return [dig, MtrDex.Blake3_256];
}

Expand Down
5 changes: 2 additions & 3 deletions src/keri/core/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,7 @@ export class Saider extends Matter {
_digest_size: number,
_length: number
) {
const hasher = createHash();
return hasher.update(ser).digest('');
return Buffer.from(blake3.create({ dkLen: 32 }).update(ser).digest());
}

private static _derive(
Expand Down
4 changes: 0 additions & 4 deletions src/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import _sodium from 'libsodium-wrappers-sumo';

export const ready: () => Promise<void> = async () => {
try {
lenkan marked this conversation as resolved.
Show resolved Hide resolved
const b3 = await import('blake3/browser-async');
await b3.default(
'https://cdn.jsdelivr.net/npm/[email protected]/dist/wasm/web/blake3_js_bg.wasm'
);
await _sodium.ready;
} catch (e) {
await _sodium.ready;
Expand Down
8 changes: 4 additions & 4 deletions test/core/diger.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Matter } from '../../src/keri/core/matter';

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

import { Diger } from '../../src/keri/core/diger';
import { MtrDex } from '../../src/keri/core/matter';
Expand All @@ -14,8 +13,9 @@ describe('Diger', () => {
'abcdefghijklmnopqrstuvwxyz0123456789',
'binary'
);
const hasher = createHash();
const digest = hasher.update(ser).digest('');
const digest = Buffer.from(
blake3.create({ dkLen: 32 }).update(ser).digest()
);

let diger = new Diger({ raw: digest });
assert.deepStrictEqual(diger.code, MtrDex.Blake3_256);
Expand Down
Loading