Skip to content

Commit

Permalink
add spaceIdFromChannelId helper (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
texuf authored Jun 11, 2024
1 parent 2f85873 commit caddf39
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/sdk/src/id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit caddf39

Please sign in to comment.