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) {
|
||||
hash += "=";
|
||||
}
|
||||
if (hash[0] !== "u") {
|
||||
hash = "u" + hash;
|
||||
}
|
||||
const bytes = base64url.decode(hash);
|
||||
return new Multihash(new Uint8Array(bytes));
|
||||
}
|
||||
|
||||
toBase64Url(): string {
|
||||
return base64url.encode(this.fullBytes);
|
||||
return base64url.encode(this.fullBytes).substring(1);
|
||||
}
|
||||
|
||||
toBase32(): string {
|
||||
return base32.encode(this.fullBytes).replace(/=/g, "").toLowerCase();
|
||||
return base32
|
||||
.encode(this.fullBytes)
|
||||
.replace(/=/g, "")
|
||||
.toLowerCase()
|
||||
.substring(1);
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
|
|
Loading…
Reference in New Issue