fix: strip out the multibase prefix on encode, add it back if its not there on decode
This commit is contained in:
parent
0c47ef6e53
commit
4830de48b4
|
@ -22,16 +22,23 @@ export class Multihash {
|
||||||
while (hash.length % 4 !== 0) {
|
while (hash.length % 4 !== 0) {
|
||||||
hash += "=";
|
hash += "=";
|
||||||
}
|
}
|
||||||
|
if (hash[0] !== "u") {
|
||||||
|
hash = "u" + hash;
|
||||||
|
}
|
||||||
const bytes = base64url.decode(hash);
|
const bytes = base64url.decode(hash);
|
||||||
return new Multihash(new Uint8Array(bytes));
|
return new Multihash(new Uint8Array(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
toBase64Url(): string {
|
toBase64Url(): string {
|
||||||
return base64url.encode(this.fullBytes);
|
return base64url.encode(this.fullBytes).substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
toBase32(): string {
|
toBase32(): string {
|
||||||
return base32.encode(this.fullBytes).replace(/=/g, "").toLowerCase();
|
return base32
|
||||||
|
.encode(this.fullBytes)
|
||||||
|
.replace(/=/g, "")
|
||||||
|
.toLowerCase()
|
||||||
|
.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
|
|
Loading…
Reference in New Issue