Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- feat(principal): export the `base32Encode` and `base32Decode` functions

## [4.0.5] - 2025-09-30

- fix(candid): recursive type table merging preserves concrete type mapping
Expand Down
1 change: 1 addition & 0 deletions packages/principal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

export * from './principal.ts';
export { getCrc32 } from './utils/getCrc.ts';
export { base32Encode, base32Decode } from './utils/base32.ts';
22 changes: 22 additions & 0 deletions packages/principal/src/utils/base32.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { base32Encode, base32Decode } from './base32.ts';

describe('base32', () => {
it('works', () => {
// Test Vectors (without padding) from RFC 4648.
expect(base32Encode(new Uint8Array([]))).toBe('');
expect(base32Encode(new Uint8Array([102]))).toBe('my');
expect(base32Encode(new Uint8Array([102, 111]))).toBe('mzxq');
expect(base32Encode(new Uint8Array([102, 111, 111]))).toBe('mzxw6');
expect(base32Encode(new Uint8Array([102, 111, 111, 98]))).toBe('mzxw6yq');
expect(base32Encode(new Uint8Array([102, 111, 111, 98, 97]))).toBe('mzxw6ytb');
expect(base32Encode(new Uint8Array([102, 111, 111, 98, 97, 114]))).toBe('mzxw6ytboi');

expect(base32Decode('')).toEqual(new Uint8Array([]));
expect(base32Decode('my')).toEqual(new Uint8Array([102]));
expect(base32Decode('mzxq')).toEqual(new Uint8Array([102, 111]));
expect(base32Decode('mzxw6')).toEqual(new Uint8Array([102, 111, 111]));
expect(base32Decode('mzxw6yq')).toEqual(new Uint8Array([102, 111, 111, 98]));
expect(base32Decode('mzxw6ytb')).toEqual(new Uint8Array([102, 111, 111, 98, 97]));
expect(base32Decode('mzxw6ytboi')).toEqual(new Uint8Array([102, 111, 111, 98, 97, 114]));
});
});
Loading