Basic IKeyringInterface (address encoding/decoding still used) (#968)

This commit is contained in:
Jaco Greeff
2019-06-04 12:26:53 +02:00
committed by GitHub
parent a518f833a8
commit 35a59ec469
10 changed files with 35 additions and 26 deletions
+2 -3
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { AnyNumber, AnyU8a, ArgsDef, Codec, IExtrinsic, SignatureOptions } from '../types';
import { AnyNumber, AnyU8a, ArgsDef, Codec, IExtrinsic, IKeyringPair, SignatureOptions } from '../types';
import { assert, isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -177,7 +176,7 @@ export default class Extrinsic extends Struct implements IExtrinsic {
/**
* @description Sign the extrinsic with a specific keypair
*/
sign (account: KeyringPair, options: SignatureOptions): Extrinsic {
sign (account: IKeyringPair, options: SignatureOptions): Extrinsic {
this.signature.sign(this.method, account, options);
return this;
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { AnyNumber, IExtrinsicSignature, SignatureOptions } from '../types';
import { AnyNumber, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../types';
import Struct from '../codec/Struct';
import Address from '../primitive/Address';
@@ -147,7 +146,7 @@ export default class ExtrinsicSignature extends Struct implements IExtrinsicSign
/**
* @description Generate a payload and pplies the signature from a keypair
*/
sign (method: Method, account: KeyringPair, { blockHash, era, nonce, version }: SignatureOptions): ExtrinsicSignature {
sign (method: Method, account: IKeyringPair, { blockHash, era, nonce, version }: SignatureOptions): ExtrinsicSignature {
const signer = new Address(account.publicKey());
const signingPayload = new SignaturePayload({
nonce,
+4 -5
View File
@@ -2,8 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import { AnyNumber, AnyU8a } from '../types';
import { AnyNumber, AnyU8a, IKeyringPair } from '../types';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -23,7 +22,7 @@ type SignaturePayloadValue = {
};
// a helper function for both types of payloads, Raw and metadata-known
function sign (signerPair: KeyringPair, u8a: Uint8Array): Uint8Array {
function sign (signerPair: IKeyringPair, u8a: Uint8Array): Uint8Array {
const encoded = u8a.length > 256
? blake2AsU8a(u8a)
: u8a;
@@ -103,7 +102,7 @@ export default class SignaturePayload extends Struct {
/**
* @description Sign the payload with the keypair
*/
sign (signerPair: KeyringPair, version?: RuntimeVersion): Uint8Array {
sign (signerPair: IKeyringPair, version?: RuntimeVersion): Uint8Array {
this._signature = sign(signerPair, this.toU8a());
return this._signature;
@@ -128,7 +127,7 @@ export class SignaturePayloadRaw extends Struct {
/**
* @description Sign the payload with the keypair
*/
sign (signerPair: KeyringPair): Uint8Array {
sign (signerPair: IKeyringPair): Uint8Array {
return sign(signerPair, this.toU8a());
}
}
+7 -3
View File
@@ -2,8 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringPair } from '@polkadot/keyring/types';
import BN from 'bn.js';
import U8a from './codec/U8a';
@@ -11,6 +9,12 @@ import { FunctionMetadata } from './Metadata/v4/Calls';
import Method from './primitive/Method';
import Address from './primitive/Address';
export type IKeyringPair = {
address: () => string,
publicKey: () => Uint8Array,
sign: (data: Uint8Array) => Uint8Array;
};
export type CodecArg = Codec | BN | Boolean | String | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;
export type CodecCallback<T extends Codec = any> = (result: T) => any;
@@ -140,5 +144,5 @@ export interface IExtrinsic extends IMethod {
method: Method;
signature: IExtrinsicSignature;
addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era?: Uint8Array): IExtrinsic;
sign (account: KeyringPair, options: SignatureOptions): IExtrinsic;
sign (account: IKeyringPair, options: SignatureOptions): IExtrinsic;
}