From caddf391e0ed4b45653bf0d3d19e2abb8ccd246d Mon Sep 17 00:00:00 2001 From: texuf Date: Tue, 11 Jun 2024 14:06:34 -0700 Subject: [PATCH] add spaceIdFromChannelId helper (#138) --- packages/sdk/src/id.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/sdk/src/id.ts b/packages/sdk/src/id.ts index 1f9130ea3..7f547f1fe 100644 --- a/packages/sdk/src/id.ts +++ b/packages/sdk/src/id.ts @@ -132,6 +132,11 @@ export const makeDefaultChannelStreamId = (spaceContractAddressOrId: string): st return makeStreamId(StreamPrefix.Channel, spaceContractAddressOrId + '0'.repeat(22)) } +export const spaceIdFromChannelId = (channelId: string): string => { + check(isChannelStreamId(channelId), 'Invalid channel id: ' + channelId) + return makeStreamId(StreamPrefix.Space, channelId.slice(2, 42) + '0'.repeat(22)) +} + export const isDefaultChannelId = (streamId: string): boolean => { const prefix = streamId.slice(0, 2) as StreamPrefix if (prefix !== StreamPrefix.Channel) {