From cfe2ae611fe730963304fd1b75cb102ed9c56e88 Mon Sep 17 00:00:00 2001 From: noiach Date: Wed, 27 Jul 2022 10:52:24 +1000 Subject: [PATCH] feat: add pack type bytes64 --- packages/utils/src/libraries/pack/binaryMarshal.ts | 4 ++++ packages/utils/src/libraries/pack/types.ts | 5 +++++ packages/utils/src/libraries/pack/unmarshal.ts | 1 + 3 files changed, 10 insertions(+) diff --git a/packages/utils/src/libraries/pack/binaryMarshal.ts b/packages/utils/src/libraries/pack/binaryMarshal.ts index 6c4a26e07..0432230fd 100644 --- a/packages/utils/src/libraries/pack/binaryMarshal.ts +++ b/packages/utils/src/libraries/pack/binaryMarshal.ts @@ -58,6 +58,9 @@ export const encodePackType = (type: PackTypeDefinition): number => { // KindBytes65 is the kind of all 65-byte arrays. case PackPrimitive.Bytes65: return 13; + // KindBytes64 is the kind of all 64-byte arrays. + case PackPrimitive.Bytes64: + return 14; } // Complex types. @@ -219,6 +222,7 @@ export const encodePackPrimitive = ( } case PackPrimitive.Bytes32: case PackPrimitive.Bytes65: + case PackPrimitive.Bytes64: return value instanceof Uint8Array ? value : // Supports base64 url format diff --git a/packages/utils/src/libraries/pack/types.ts b/packages/utils/src/libraries/pack/types.ts index 905cc5411..c3e4db78a 100644 --- a/packages/utils/src/libraries/pack/types.ts +++ b/packages/utils/src/libraries/pack/types.ts @@ -14,6 +14,7 @@ export enum PackPrimitive { Bytes = "bytes", Bytes32 = "bytes32", Bytes65 = "bytes65", + Bytes64 = "bytes64", } export interface PackStructType< @@ -68,6 +69,8 @@ export type Marshalled< ? string : Type extends PackPrimitive.Bytes65 ? string + : Type extends PackPrimitive.Bytes64 + ? string : Type extends PackNilType ? string : Type extends { list: InnerType } @@ -101,6 +104,8 @@ export type Unmarshalled< ? Uint8Array : Type extends PackPrimitive.Bytes65 ? Uint8Array + : Type extends PackPrimitive.Bytes64 + ? Uint8Array : Type extends PackNilType ? null : Type extends { list: InnerType } diff --git a/packages/utils/src/libraries/pack/unmarshal.ts b/packages/utils/src/libraries/pack/unmarshal.ts index 85f700e63..b4f6478d6 100644 --- a/packages/utils/src/libraries/pack/unmarshal.ts +++ b/packages/utils/src/libraries/pack/unmarshal.ts @@ -42,6 +42,7 @@ export const unmarshalPackPrimitive = ( case PackPrimitive.Bytes: case PackPrimitive.Bytes32: case PackPrimitive.Bytes65: + case PackPrimitive.Bytes64: return utils.fromBase64(value) as Unmarshalled; } throw new Error(`Unknown pack type '${type}'.`);