Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Do not require padding on schema #63

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/wallet-connectors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed serialization of parameters in `requestVerifiablePresentation` and parsing of the result of the request.

### Changed

- `schemaAsBuffer` and thereby `typeSchemaFromBase64` no longer requires a base64 encoded schema to be padded.

## [0.5.0] - 2024-03-13

### Added
Expand Down
14 changes: 10 additions & 4 deletions packages/wallet-connectors/src/WalletConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ export function typeSchema(schema: Buffer): TypeSchema {
};
}

function schemaAsBuffer(schemaBase64: string) {
export function schemaAsBuffer(schemaBase64: string) {
let unpaddedLen = schemaBase64.length;
if (schemaBase64.charAt(unpaddedLen - 1) === '=') {
unpaddedLen--;
}
if (schemaBase64.charAt(unpaddedLen - 1) === '=') {
unpaddedLen--;
}
orhoj marked this conversation as resolved.
Show resolved Hide resolved
const res = toBuffer(schemaBase64, 'base64');
// Check round-trip. This requires the provided schema to be properly padded.
if (res.toString('base64') !== schemaBase64) {
throw new Error(`provided schema '${schemaBase64}' is not valid base64`);
if (unpaddedLen !== Math.ceil((4 * res.length) / 3)) {
throw new Error(`The provided schema '${schemaBase64}' is not valid base64`);
}
return res;
}
Expand Down