Skip to content

Commit

Permalink
fix: Multibase encoding didn't include the prefix char
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Dec 2, 2021
1 parent a360378 commit 1be44b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/ssi-sdk-core/src/utils/__tests__/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('@sphereon/ssi-sdk-core:encoding', () => {

// Hex to multibase
it('should encode hex to multibase base58', () => {
expect(hexToMultibase(HEX_EXAMPLE, MultibaseFormat.BASE58)).toEqual({ value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58 })
expect(hexToMultibase(HEX_EXAMPLE.toUpperCase(), MultibaseFormat.BASE58)).toEqual({ value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58 })
expect(hexToMultibase(HEX_EXAMPLE, MultibaseFormat.BASE58)).toEqual({ value: MULTIBASE_EXAMPLE, format: MultibaseFormat.BASE58 })
expect(hexToMultibase(HEX_EXAMPLE.toUpperCase(), MultibaseFormat.BASE58)).toEqual({ value: MULTIBASE_EXAMPLE, format: MultibaseFormat.BASE58 })
})
it('should not encode hex to not supported multibase format', () => {
expect(() => hexToMultibase(HEX_EXAMPLE, 'e' as never)).toThrowError()
Expand Down
2 changes: 1 addition & 1 deletion packages/ssi-sdk-core/src/utils/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function hexToMultibase(hex: string, format: MultibaseFormat): { value: s
if (format !== MultibaseFormat.BASE58) {
throw new Error('Only base58 supported for now using multibase!')
}
return { value: base58.encode(hexToBytes(hex)), format }
return { value: MultibaseFormat.BASE58 + base58.encode(hexToBytes(hex)), format }

function hexToBytes(hex: string): Uint8Array {
let bytes: number[] = []
Expand Down

0 comments on commit 1be44b7

Please sign in to comment.