diff --git a/CHANGELOG.md b/CHANGELOG.md index d8fb34b5a..b6385b059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 3.3.0-beta.x + +- Add `addressRaw` to Keyring interface (if address encoding is different to publicKey) +- Allow for Ethereum pair signing and verification + ## 3.2.1 Aug 17, 2020 - Allow for (optional, default blake2) hasher to secp256k1 sign/verify functions diff --git a/packages/keyring/src/pair/index.spec.ts b/packages/keyring/src/pair/index.spec.ts index 035aa2904..532ec55ba 100644 --- a/packages/keyring/src/pair/index.spec.ts +++ b/packages/keyring/src/pair/index.spec.ts @@ -25,6 +25,11 @@ describe('pair', (): void => { ).toEqual( new Uint8Array([209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79]) ); + expect( + keyring.alice.addressRaw + ).toEqual( + new Uint8Array([209, 114, 167, 76, 218, 76, 134, 89, 18, 195, 43, 160, 168, 10, 87, 174, 105, 171, 174, 65, 14, 92, 203, 89, 222, 232, 78, 47, 68, 50, 219, 79]) + ); }); it('allows signing', (): void => { @@ -111,6 +116,7 @@ describe('pair', (): void => { const pair = createPair({ toSS58, type: 'ethereum' }, { publicKey: hexToU8a('0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077') }); expect(pair.address).toEqual('0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887'); + expect(pair.addressRaw).toEqual(hexToU8a('0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887')); }); }); }); diff --git a/packages/keyring/src/pair/index.ts b/packages/keyring/src/pair/index.ts index b4a7e3afb..c0856ca7e 100644 --- a/packages/keyring/src/pair/index.ts +++ b/packages/keyring/src/pair/index.ts @@ -103,15 +103,25 @@ export default function createPair ({ toSS58, type }: Setup, { publicKey, secret return encoded; }; - const encodeAddress = (): string => - type === 'ethereum' - ? ethereumEncode(TYPE_ADDRESS[type](publicKey)) - : toSS58(TYPE_ADDRESS[type](publicKey)); + const encodeAddress = (): string => { + const raw = TYPE_ADDRESS[type](publicKey); + + return type === 'ethereum' + ? ethereumEncode(raw) + : toSS58(raw); + }; return { get address (): string { return encodeAddress(); }, + get addressRaw (): Uint8Array { + const raw = TYPE_ADDRESS[type](publicKey); + + return type === 'ethereum' + ? raw.slice(-20) + : raw; + }, get isLocked (): boolean { return isLocked(secretKey); }, diff --git a/packages/keyring/src/pair/nobody.ts b/packages/keyring/src/pair/nobody.ts index 44e743900..f36f38b90 100644 --- a/packages/keyring/src/pair/nobody.ts +++ b/packages/keyring/src/pair/nobody.ts @@ -26,6 +26,7 @@ const json: KeyringPair$Json = { export default function everybody (): KeyringPair { const pair: KeyringPair = { address, + addressRaw: publicKey, // eslint-disable-next-line @typescript-eslint/no-unused-vars decodePkcs8: (passphrase?: string, encoded?: Uint8Array): void => undefined, diff --git a/packages/keyring/src/types.ts b/packages/keyring/src/types.ts index 1cf7b4d90..9b0e81daa 100644 --- a/packages/keyring/src/types.ts +++ b/packages/keyring/src/types.ts @@ -35,6 +35,7 @@ export interface SignOptions { export interface KeyringPair { readonly address: string; + readonly addressRaw: Uint8Array; readonly meta: KeyringPair$Meta; readonly isLocked: boolean; readonly publicKey: Uint8Array; diff --git a/packages/util/src/u8a/toU8a.ts b/packages/util/src/u8a/toU8a.ts index ff48a603c..6430b9d0f 100644 --- a/packages/util/src/u8a/toU8a.ts +++ b/packages/util/src/u8a/toU8a.ts @@ -13,7 +13,7 @@ import stringToU8a from '../string/toU8a'; * @name u8aToU8a * @summary Creates a Uint8Array value from a Uint8Array, Buffer, string or hex input. * @description - * `null` ior `undefined` nputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation. + * `null` or `undefined` inputs returns a `[]` result, Uint8Array values returns the value, hex strings returns a Uint8Array representation. * @example *
*