Skip to content
Merged
Prev Previous commit
Next Next commit
ecdsa tests
  • Loading branch information
jacogr committed Feb 4, 2021
commit be8cb670b19128ab0fef24026f32d3420caae5e6
6 changes: 6 additions & 0 deletions packages/util-crypto/src/address/checksum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ describe('checkAddressChecksum', (): void => {
checkAddressChecksum(base58Decode('yGHU8YKprxHbHdEv7oUK4rzMZXtsdhcXVG2CAMyC9WhzhjH2k'))
).toEqual([true, 34, 2, 255]);
});

it('correctly extracts the info from a 2-byte-prefix address (ecdsa, from Substrate)', (): void => {
expect(
checkAddressChecksum(base58Decode('4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV'))
).toEqual([true, 35, 2, 200]);
});
});
6 changes: 6 additions & 0 deletions packages/util-crypto/src/address/decode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ describe('decodeAddress', (): void => {
);
});

it('decodes a 2-byte prefix (ecdsa, from Substrate)', (): void => {
expect(
u8aToHex(decodeAddress('4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV'))
).toEqual('0x035676109c54b9a16d271abeb4954316a40a32bcce023ac14c8e26e958aa68fba9');
});

it.skip('allows invalid prefix (in list)', (): void => {
expect(
(): Uint8Array => decodeAddress('6GfvWUvHvU8otbZ7sFhXH4eYeMcKdUkL61P3nFy52efEPVUx')
Expand Down
12 changes: 12 additions & 0 deletions packages/util-crypto/src/address/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const SUBKEY = [
publicKey: '0x3050f8456519829fe03302da802d22d3233a5f4037b9a3e2bcc403ccfcb2d735',
ss58Format: 42
},
{
// ecdsa
address: '4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV',
publicKey: '0x035676109c54b9a16d271abeb4954316a40a32bcce023ac14c8e26e958aa68fba9',
ss58Format: 200
},
{
address: 'yGF4JP7q5AK46d1FPCEm9sYQ4KooSjHMpyVAjLnsCSWVafPnf',
publicKey: '0x66cd6cf085627d6c85af1aaf2bd10cf843033e929b4e3b1c2ba8e4aa46fe111b',
Expand Down Expand Up @@ -109,6 +115,12 @@ describe('encode', (): void => {
).toEqual('yGHU8YKprxHbHdEv7oUK4rzMZXtsdhcXVG2CAMyC9WhzhjH2k');
});

it('encodes with a 2-byte prefix (from Substrate)', (): void => {
expect(
encodeAddress(new Uint8Array([116, 28, 8, 160, 111, 65, 197, 150, 96, 143, 103, 116, 37, 155, 217, 4, 51, 4, 173, 250, 93, 62, 234, 98, 118, 11, 217, 190, 151, 99, 77, 99]), 200)
).toEqual('4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV');
});

SUBKEY.forEach(({ address, publicKey, ss58Format }, index): void => {
it(`encodes with Subkey equality (${index})`, (): void => {
expect(
Expand Down