@polkadot/keyring/types#KeyringPair$Json TypeScript Examples

The following examples show how to use @polkadot/keyring/types#KeyringPair$Json. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Import.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
function parseFile (file: Uint8Array, genesisHash?: string | null): KeyringPair | null {
  try {
    return keyring.createFromJson(JSON.parse(u8aToString(file)) as KeyringPair$Json, { genesisHash });
  } catch (error) {
    console.error(error);
  }

  return null;
}
Example #2
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 6 votes vote down vote up
static async create(
    name: string,
    passphrase?: string,
  ): Promise<{
    keyring: KeyringPair;
    mnemonic: string;
    seed: string;
    json: KeyringPair$Json;
  }> {
    const mnemonic = mnemonicGenerate();
    const seed = mnemonicToMiniSecret(mnemonic);
    const keyring = await GearKeyring.fromSeed(seed, name);
    return {
      keyring,
      mnemonic: mnemonic,
      seed: u8aToHex(seed),
      json: keyring.toJson(passphrase),
    };
  }
Example #3
Source File: keyring.ts    From sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Add user's accounts to keyring incedence,
 * so user can use them to sign txs with password.
 * We use a list of ss58Formats to encode the accounts
 * into different address formats for different networks.
 */
async function initKeys(accounts: KeyringPair$Json[], ss58Formats: number[]) {
  await cryptoWaitReady();
  const res = {};
  ss58Formats.forEach((ss58) => {
    (<any>res)[ss58] = {};
  });

  accounts.forEach((i) => {
    // import account to keyring
    const keyPair = keyring.addFromJson(i);
    // then encode address into different ss58 formats
    ss58Formats.forEach((ss58) => {
      const pubKey = u8aToHex(keyPair.publicKey);
      (<any>res)[ss58][pubKey] = keyring.encodeAddress(keyPair.publicKey, ss58);
    });
  });
  return res;
}
Example #4
Source File: subscriber.ts    From polkadot-registrar-watcher with Apache License 2.0 6 votes vote down vote up
private _initKey = (): void =>{
      this.logger.debug(`init registrar with index ${this.registrarIndex} ...`)
      const keyring = new Keyring({ type: 'sr25519' });
      const keyJson = JSON.parse(fs.readFileSync(this.registrarWalletFilePath, { encoding: 'utf-8' })) as KeyringPair$Json;
      const passwordContent = fs.readFileSync(this.registrarPasswordFilePath, { encoding: 'utf-8' });
      this.registrarAccount = keyring.addFromJson(keyJson)
      this.registrarAccount.decodePkcs8(passwordContent)

      this.logger.debug(`read account with address: ${keyring.pairs[0].toJson().address}`)
      this.logger.debug(`is locked: ${this.registrarAccount.isLocked}`)

      if(this.registrarAccount.isLocked){
        this.logger.error(`problem unlocking the wallet, exiting ...`)
        process.exit(1)
      }
    }
Example #5
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 5 votes vote down vote up
static fromJson(keypairJson: KeyringPair$Json | string, passphrase?: string): KeyringPair {
    const json: KeyringPair$Json = isString(keypairJson) ? JSON.parse(keypairJson) : keypairJson;
    const keyring = new Keyring().addFromJson(json);
    return GearKeyring.unlock(keyring, passphrase);
  }
Example #6
Source File: Keyring.ts    From gear-js with GNU General Public License v3.0 5 votes vote down vote up
static toJson(keyring: KeyringPair, passphrase?: string): KeyringPair$Json {
    return keyring.toJson(passphrase);
  }