Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add url data encoding #345

Merged
merged 46 commits into from
Mar 21, 2023
Merged

Add url data encoding #345

merged 46 commits into from
Mar 21, 2023

Conversation

felicio
Copy link
Collaborator

@felicio felicio commented Feb 13, 2023

Implements status-im/specs#169

@felicio
Copy link
Collaborator Author

felicio commented Feb 14, 2023

Relates to #327

Comment on lines 14 to 34
test('A', () => {
const data = {
displayName: 'Lorem ipsum dolor sit egestas.',
description:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus non dui vitae augue elementum laoreet ac pharetra odio. Morbi vestibulum.',
membersCount: 1_000_000,
color: '#4360DF',
}
const encodedData = encodeUrlData('community', data, {
serialization: 'csv',
compression: 'noop',
encoding: 'encodeURIComponent',
})
const characterLength = countCharacters(data)

expect(characterLength).toBe(184)
expect(encodedData).toBe(
'Lorem%20ipsum%20dolor%20sit%20egestas.%2CLorem%20ipsum%20dolor%20sit%20amet%2C%20consectetur%20adipiscing%20elit.%20Phasellus%20non%20dui%20vitae%20augue%20elementum%20laoreet%20ac%20pharetra%20odio.%20Morbi%20vestibulum.%2C1000000%2C%234360DF'
)
expect(encodedData).toHaveLength(243)
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I contemplated leaving these comparison test cases in the repo, but deciding against it.

}).toBinary()
const compressed = brotliCompressSync(serialized)
// todo?!: remove padding
// todo?!: split into 301 chars chunks with a semicolon separator
Copy link
Collaborator Author

@felicio felicio Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checksum: getChecksum(data, publicKey),
}).toBinary()
const compressed = brotliCompressSync(serialized)
// todo?!: remove padding
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the == that can be at the end of encoded results, and actual savings being max 2 chars.

@felicio felicio changed the title WIP: Add url data encoding Add url data encoding Feb 21, 2023
.prettierignore Outdated Show resolved Hide resolved
@felicio felicio marked this pull request as ready for review February 21, 2023 14:25
Copy link
Collaborator

@prichodko prichodko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My feeling is that this should be moved to a separate package. WDYT?

@prichodko
Copy link
Collaborator

Great PR otherwise. Very understandable.

@felicio
Copy link
Collaborator Author

felicio commented Feb 23, 2023

My feeling is that this should be moved to a separate package. WDYT?

@prichodko like @status-im/js/utils 🤔 ? The status-web will need this encoding fns for sharing down the road just.

@prichodko
Copy link
Collaborator

I was rather thinking something like @status-im/shareable-url-codec or omit shareable.

@felicio
Copy link
Collaborator Author

felicio commented Feb 23, 2023

I'm failing to see the benefit in splitting 😅. In short term, I see it only ever being used where @status-im/js will be. But if I should split it, I'll do so 🙂.

Copy link
Collaborator

@prichodko prichodko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amazing 🙌

@prichodko prichodko merged commit 672b7c2 into status-im:main Mar 21, 2023
felicio added a commit to felicio/status-web that referenced this pull request May 15, 2023
* add @scure/base

* add link-preview.proto

* add prototype of encode function

* add tests

* add test cases

* update proto

* more

* more

* add missing community chat description to proto

* more

* more

* add browser brotli and lz-string

* move encoding comparison

* add sinlge encoding

* split encoding

* add decoding

* update .prettierignore

* exclude comparison

* remove comparison tests

* Update packages/status-js/src/utils/encode-url-data.test.ts

* Update packages/status-js/src/utils/encode-url-data.test.ts

* remove checksum

* ensure channel is serializable

* Update .prettierignore

* update protos

* add creaet-url.ts

* set links

* comment

* update protos

* add nominal type for EncodedUrlData

* add sign/verify fns

* export fns from index

* set zlib as external module

* add tag indices

* encode channel uuid

* use `.toJson()` with type assertion

* use uppercase url

* split url creating fns

* fix typo

* describe test suite

* use getters

* fix nominal type

* remove `node:` prefix from `zlib` import

* remove todos?:

* rename URLProps to URLParams

* fix package.json after rebase
@felicio felicio self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants