How to use the @polkadot/ui-keyring.getPair function in @polkadot/ui-keyring

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 / 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 polkadot-js / apps / packages / ui-signer / src / sign.js View on Github external
export default function signMessage (publicKey: Uint8Array, nonce: BN | number, value: Uint8Array, apiSupport: EncodingVersions): Signed {
  const message = encodeCall(publicKey, nonce, value, apiSupport);
  const signature = keyring.getPair(publicKey).sign(message);

  console.log(`signMessage :   message :: ${u8aToHex(message)}`);
  console.log(`signMessage : signature :: ${u8aToHex(signature)}`);

  return {
    data: u8aConcat(message, signature),
    message,
    signature
  };
}
github dappforce / dappforce-subsocial-ui / src / components / ui-signer / Modal.tsx View on Github external
private unlockAccount (accountId: string, password?: string): string | null {
    let publicKey;

    try {
      publicKey = keyring.decodeAddress(accountId);
    } catch (error) {
      console.error(error);

      return 'unable to decode address';
    }

    const pair = keyring.getPair(publicKey);

    if (!pair.isLocked()) {
      return null;
    }

    try {
      pair.decodePkcs8(password);
    } catch (error) {
      console.error(error);

      return error.message;
    }

    return null;
  }
github polkadot-js / apps / packages / app-accounts / src / modals / Backup.tsx View on Github external
const _doBackup = (): void => {
    try {
      const addressKeyring = address && keyring.getPair(address);
      const json = addressKeyring && keyring.backupAccount(addressKeyring, password);
      const blob = new Blob([JSON.stringify(json)], { type: 'application/json; charset=utf-8' });

      FileSaver.saveAs(blob, `${address}.json`);
    } catch (error) {
      setBackupFailed(true);
      console.error(error);
      return;
    }

    onClose();
  };
github polkadot-js / apps / packages / app-accounts / src / modals / Derive.tsx View on Github external
function Derive ({ className, from, onClose, t }: Props): React.ReactElement {
  const { queueAction } = useContext(StatusContext);
  const [source] = useState(keyring.getPair(from));
  const [{ address, deriveError }, setDerived] = useState({ address: null, deriveError: null });
  const [isConfirmationOpen, setIsConfirmationOpen] = useState(false);
  const [isLocked, setIsLocked] = useState(source.isLocked);
  const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' });
  const [{ isPassValid, password }, setPassword] = useState({ isPassValid: false, password: '' });
  const [rootPass, setRootPass] = useState('');
  const [suri, setSuri] = useState('');
  const debouncedSuri = useDebounce(suri);
  const isValid = !!address && !deriveError && isNameValid && isPassValid;

  const { cancelButtonRef, submitButtonRef, onInputEnterKey, onInputEscapeKey } = useForm();

  useEffect((): void => {
    setIsLocked(source.isLocked);
  }, [source]);
github polkadot-js / apps / packages / app-accounts / src / Account.tsx View on Github external
const _onGenesisChange = (genesisHash: string | null): void => {
    const account = keyring.getPair(address);

    account && keyring.saveAccountMeta(account, { ...account.meta, genesisHash });

    setGenesisHash(genesisHash);
  };
  const _onFavorite = (): void => toggleFavorite(address);
github polkadot-js / extension / packages / extension / src / background / handlers / Tabs.ts View on Github external
private getSigningPair (address: string): KeyringPair {
    const pair = keyring.getPair(address);
    assert(pair, 'Unable to find keypair');
    return pair;
  }
github polkadot-js / extension / packages / extension / src / background / handlers / Extension.ts View on Github external
private signingApprovePassword ({ id, password }: RequestSigningApprovePassword): boolean {
    const queued = this.state.getSignRequest(id);

    assert(queued, 'Unable to find request');

    const { request, resolve, reject } = queued;
    const pair = keyring.getPair(request.inner.address);

    if (!pair) {
      reject(new Error('Unable to find pair'));

      return false;
    }

    pair.decodePkcs8(password);
    const result = request.sign(registry, pair);
    pair.lock();

    resolve({
      id,
      ...result
    });