Skip to content
Merged
Prev Previous commit
Next Next commit
UpdateAssert of reserved
  • Loading branch information
jacogr committed Feb 4, 2021
commit ecf90adec40c3e93284c3c16d98487d81ac90b5b
15 changes: 15 additions & 0 deletions packages/util-crypto/src/address/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,19 @@ describe('encode', (): void => {
).toEqual(address);
});
});

it('does not encode for > 16,383', (): void => {
expect(
() => encodeAddress(keyring.alice.publicKey, 16384)
).toThrow(/range ss58Format specified/);
});

it('does not encode reserved', (): void => {
expect(
() => encodeAddress(keyring.alice.publicKey, 46)
).toThrow(/range ss58Format specified/);
expect(
() => encodeAddress(keyring.alice.publicKey, 47)
).toThrow(/range ss58Format specified/);
});
});
2 changes: 1 addition & 1 deletion packages/util-crypto/src/address/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function encodeAddress (_key: Uint8Array | string, ss58Format: Prefix = d
// decode it, this means we can re-encode an address
const key = decodeAddress(_key);

assert(ss58Format <= 16383, 'Out of range ss58Format specified');
assert(ss58Format <= 16383 && ![46, 47].includes(ss58Format), 'Out of range ss58Format specified');
assert(defaults.allowedDecodedLengths.includes(key.length), `Expected a valid key to convert, with length ${defaults.allowedDecodedLengths.join(', ')}`);

const isPublicKey = [32, 33].includes(key.length);
Expand Down