Skip to content

Commit

Permalink
Merge pull request #184 from docknetwork/fix/base-64-check
Browse files Browse the repository at this point in the history
fix/base 64 check
  • Loading branch information
maycon-mello authored Dec 13, 2023
2 parents fd42bce + 9e7a661 commit 0492f74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/wasm/src/services/util-crypto/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('UtilCryptoService', () => {

it('expect to not be base64', async () => {
expect(await service.isBase64('wrong value')).toBe(false);
expect(await service.isBase64('Test')).toBe(false);
});
});

Expand Down
9 changes: 7 additions & 2 deletions packages/wasm/src/services/util-crypto/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
keyExtractSuri,
mnemonicGenerate,
mnemonicValidate,
isBase64,
} from '@polkadot/util-crypto';
import assert from 'assert';
import {validation} from './configs';
Expand Down Expand Up @@ -35,7 +34,13 @@ export class UtilCryptoService {
}

isBase64(value) {
return isBase64(value);
if (typeof value !== 'string') {
return false;
}

const decoded1 = Buffer.from(value, 'base64').toString('utf8');
const encoded2 = Buffer.from(decoded1, 'binary').toString('base64');
return value === encoded2;
}

mnemonicValidate(phrase) {
Expand Down

0 comments on commit 0492f74

Please sign in to comment.