From 0abae0bed747a0332b3ed994353a441ef70af9e7 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs Date: Wed, 6 Jul 2022 14:42:56 -0700 Subject: [PATCH 1/2] fix: return clearer error on ContactBundle decode faliure --- src/ContactBundle.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ContactBundle.ts b/src/ContactBundle.ts index 3847202d1..c76cb573a 100644 --- a/src/ContactBundle.ts +++ b/src/ContactBundle.ts @@ -14,9 +14,7 @@ export default class ContactBundle implements proto.ContactBundleV1 { } toBytes(): Uint8Array { - return proto.ContactBundleV1.encode({ - keyBundle: this.keyBundle, - }).finish() + return this.keyBundle.toBytes() } static fromBytes(bytes: Uint8Array): ContactBundle { @@ -49,11 +47,13 @@ export default class ContactBundle implements proto.ContactBundleV1 { e instanceof RangeError || (e instanceof Error && e.message.startsWith('invalid wire type')) ) { - // Adds a default fallback for older versions of the proto - const legacyBundle = proto.ContactBundleV1.decode(bytes) - return legacyBundle.keyBundle + // Adds a default fallback for older versions of the proto (Which may also fail) + try { + return proto.PublicKeyBundle.decode(bytes) + } catch (e) { + throw new Error("Couldn't decode contact bundle:" + e) + } } - throw new Error("Couldn't decode contact bundle:" + e) } } } From 666e95ea5198ed62088b894f66509bb3fef9fe96 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs Date: Wed, 6 Jul 2022 15:35:04 -0700 Subject: [PATCH 2/2] fix: added space --- src/ContactBundle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ContactBundle.ts b/src/ContactBundle.ts index c76cb573a..501495670 100644 --- a/src/ContactBundle.ts +++ b/src/ContactBundle.ts @@ -51,7 +51,7 @@ export default class ContactBundle implements proto.ContactBundleV1 { try { return proto.PublicKeyBundle.decode(bytes) } catch (e) { - throw new Error("Couldn't decode contact bundle:" + e) + throw new Error("Couldn't decode contact bundle: " + e) } } }