How to use @polkadot/ui-keyring - 10 common examples

To help you get started, we’ve selected a few @polkadot/ui-keyring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / extension / packages / extension / src / background / handlers / Extension.ts View on Github external
private seedValidate ({ suri, type }: RequestSeedValidate): ResponseSeedValidate {
    const { phrase } = keyExtractSuri(suri);

    if (isHex(phrase)) {
      assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
    } else {
      // sadly isHex detects as string, so we need a cast here
      assert(SEED_LENGTHS.includes((phrase as string).split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
      assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
    }

    return {
      address: keyring.createFromUri(suri, {}, type).address,
      suri
    };
  }
github paritytech / substrate-light-ui / packages / transfer-app / src / Transfer.tsx View on Github external
useEffect(() => {
    const allAddressessub = combineLatest([
      // eslint-disable-next-line @typescript-eslint/unbound-method
      accountObservable.subject.pipe(map(Object.values)),
      // eslint-disable-next-line @typescript-eslint/unbound-method
      addressObservable.subject.pipe(map(Object.values))
    ])
      .pipe(map(flatten))
      .subscribe(setAllAddresses);

    return (): void => {
      allAddressessub.unsubscribe();
    };
  }, []);
github polkadot-js / extension / packages / extension / src / background / index.ts View on Github external
.then((): void => {
    console.log('crypto initialized');

    // load all the keyring data
    keyring.loadAll({ store: new ExtensionStore(), type: 'sr25519' });

    console.log('initialization completed');
  })
  .catch((error): void => {
github polkadot-js / apps / packages / react-api / src / Api.tsx View on Github external
const systemChain = _systemChain
      ? _systemChain.toString()
      : '';
    const isDevelopment = isTestChain(systemChain);

    console.log('api: found chain', systemChain, JSON.stringify(properties));

    // first setup the UI helpers
    formatBalance.setDefaults({
      decimals: tokenDecimals,
      unit: tokenSymbol
    });
    TokenUnit.setAbbr(tokenSymbol);

    // finally load the keyring
    keyring.loadAll({
      addressPrefix: ss58Format,
      genesisHash: api.genesisHash,
      isDevelopment,
      ss58Format,
      type: 'ed25519'
    }, injectedAccounts);

    const defaultSection = Object.keys(api.tx)[0];
    const defaultMethod = Object.keys(api.tx[defaultSection])[0];
    const apiDefaultTx = api.tx[defaultSection][defaultMethod];
    const apiDefaultTxSudo =
      (api.tx.system && api.tx.system.setCode) || // 2.x
      (api.tx.consensus && api.tx.consensus.setCode) || // 1.x
      apiDefaultTx; // other
    const isSubstrateV2 = !!Object.keys(api.consts).length;
github paritytech / substrate-light-ui / packages / transfer-app / src / Transfer.tsx View on Github external
useEffect(() => {
    const allAddressessub = combineLatest([
      // eslint-disable-next-line @typescript-eslint/unbound-method
      accountObservable.subject.pipe(map(Object.values)),
      // eslint-disable-next-line @typescript-eslint/unbound-method
      addressObservable.subject.pipe(map(Object.values))
    ])
      .pipe(map(flatten))
      .subscribe(setAllAddresses);

    return (): void => {
      allAddressessub.unsubscribe();
    };
  }, []);
github polkadot-js / apps / packages / react-signer / src / Modal.tsx View on Github external
const unlockError = this.unlockAccount(accountId as string, password);

      if (unlockError) {
        this.setState({ unlockError });
        return;
      }
    }

    if (payload) {
      return makeExtrinsicSignature(
        {
          ...payload,
          ...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
        },
        queueTx,
        keyring.getPair(accountId as string)
      );
    }

    const submittable = extrinsic as SubmittableExtrinsic;

    assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');

    return isUnsigned
      // eslint-disable-next-line @typescript-eslint/unbound-method
      ? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
      // eslint-disable-next-line @typescript-eslint/unbound-method
      : this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
  }
github polkadot-js / apps / packages / react-signer / src / Modal.tsx View on Github external
...((isV2 && tip && !payload.tip) ? { tip: tip.toString() } : {})
        },
        queueTx,
        keyring.getPair(accountId as string)
      );
    }

    const submittable = extrinsic as SubmittableExtrinsic;

    assert(submittable, 'Expected an extrinsic to be supplied to sendExtrinsic');

    return isUnsigned
      // eslint-disable-next-line @typescript-eslint/unbound-method
      ? this.makeExtrinsicCall(submittable, queueTx, submittable.send)
      // eslint-disable-next-line @typescript-eslint/unbound-method
      : this.makeExtrinsicCall(submittable, queueTx, submittable.signAndSend, keyring.getPair(accountId as string));
  }
github paritytech / substrate-light-ui / packages / light-apps / src / Onboarding / Claim.tsx View on Github external
useEffect(() => {
    // eslint-disable-next-line @typescript-eslint/unbound-method
    const accountsSub = accounts.subject.pipe(map(Object.values)).subscribe(values => {
      const stash = values.filter(value =>
        fromNullable(value.json.meta.tags)
          .map(tags => tags.includes('stash'))
          .getOrElse(undefined)
      )[0];

      const _messageToSign = fromNullable(stash)
        .map(stash => `Pay KSMs to the Kusama account: ${stash.json.address}`)
        .getOrElse('');

      setMessageToSign(_messageToSign);
    });

    return (): void => accountsSub.unsubscribe();
  }, []);
github paritytech / substrate-light-ui / packages / light-apps / src / Onboarding / BondingSetup.tsx View on Github external
useEffect(() => {
    // eslint-disable-next-line @typescript-eslint/unbound-method
    const accountsSub = accounts.subject.pipe(map(Object.values)).subscribe(values => {
      const _controller = values.filter(value => value.json.meta.tags && value.json.meta.tags.includes('controller'))[0];
      const _stash = values.filter(value => value.json.meta.tags && value.json.meta.tags.includes('stash'))[0];

      setController(_controller);
      setStash(_stash);
    });

    return (): void => accountsSub.unsubscribe();
  }, []);
github paritytech / substrate-light-ui / packages / light-apps / src / Content / Content.tsx View on Github external
useEffect(() => {
    const accountsSub = accounts.subject
      // eslint-disable-next-line @typescript-eslint/unbound-method
      .pipe(map(Object.values), map(head))
      .subscribe(setDefaultAccount);

    return (): void => accountsSub.unsubscribe();
  }, [api]);