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

Use @spartan-hc/holo-hash for managing holo-hashes #259

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
20 changes: 17 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@bitgo/blake2b": "^3.2.4",
"@holochain/serialization": "^0.1.0-beta-rc.3",
"@msgpack/msgpack": "^2.8.0",
"@spartan-hc/holo-hash": "^0.7.0",
"emittery": "^1.0.1",
"isomorphic-ws": "^5.0.0",
"js-base64": "^3.7.5",
Expand Down
13 changes: 8 additions & 5 deletions src/utils/base64.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Base64 } from "js-base64";
import { HoloHash, HoloHashB64 } from "../types.js";
import { HoloHashB64 } from "../types.js";
import { HoloHash } from "@spartan-hc/holo-hash";

/**
* Decodes a Base64 encoded string to a byte array hash.
Expand All @@ -9,8 +10,8 @@ import { HoloHash, HoloHashB64 } from "../types.js";
*
* @public
*/
export function decodeHashFromBase64(hash: HoloHashB64): HoloHash {
return Base64.toUint8Array(hash.slice(1));
export function decodeHashFromBase64(hash: string): HoloHash {
return new HoloHash( hash );
}

/**
Expand All @@ -21,6 +22,8 @@ export function decodeHashFromBase64(hash: HoloHashB64): HoloHash {
*
* @public
*/
export function encodeHashToBase64(hash: HoloHash): HoloHashB64 {
return `u${Base64.fromUint8Array(hash, true)}`;
export function encodeHashToBase64(hash: Uint8Array): HoloHashB64 {
return String(new HoloHash( hash ));
}

export * from "@spartan-hc/holo-hash";
mjbrisebois marked this conversation as resolved.
Show resolved Hide resolved
Loading