Add addressRaw to keyring interface (#667)

* addressRaw to keyring interface

* Typos

* nobody

* Slice -20 for Ethereum

* addressRaw tests
This commit is contained in:
Jaco Greeff
2020-08-22 13:32:14 +02:00
committed by GitHub
parent b381c09ecf
commit 3b383b97ca
6 changed files with 28 additions and 5 deletions
+5
View File
@@ -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
+6
View File
@@ -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'));
});
});
});
+14 -4
View File
@@ -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);
},
+1
View File
@@ -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,
+1
View File
@@ -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;
+1 -1
View File
@@ -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
* <BR>
*