How to use the @polkadot/util-crypto.decodeAddress function in @polkadot/util-crypto

To help you get started, we’ve selected a few @polkadot/util-crypto 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-params / src / Param / BaseBytes.tsx View on Github external
function convertInput (value: string): [boolean, Uint8Array] {
  // try hex conversion
  try {
    return [true, hexToU8a(value)];
  } catch (error) {
    // we continue...
  }

  // maybe it is an ss58?
  try {
    return [true, decodeAddress(value)];
  } catch (error) {
    // we continue
  }

  return [value === '0x', new Uint8Array([])];
}
github polkadot-js / api / packages / types / src / primitive / Generic / AccountIndex.ts View on Github external
public static decodeAccountIndex (value: AnyNumber): BN | Uint8Array | number | string {
    if (value instanceof AccountIndex) {
      // `value.toBn()` on AccountIndex returns a pure BN (i.e. not an
      // AccountIndex), which has the initial `toString()` implementation.
      return value.toBn();
    } else if (isBn(value) || isNumber(value) || isHex(value) || isU8a(value)) {
      return value;
    }

    return AccountIndex.decodeAccountIndex(decodeAddress(value));
  }
github polkadot-js / ui / packages / react-qr / src / ScanAddress.tsx View on Github external
private onScan = (data: string | null): void => {
    const { onScan } = this.props;

    if (!data || !onScan) {
      return;
    }

    try {
      const [prefix, address, genesisHash] = data.split(':');

      assert(prefix === ADDRESS_PREFIX, `Invalid address received, expected '${ADDRESS_PREFIX}', found '${prefix}'`);

      decodeAddress(address);
      onScan({ address, genesisHash });
    } catch (error) {
      console.error('@polkadot/react-qr:QrScanAddress', error.message, data);
    }
  }
}
github polkadot-js / ui / packages / react-qr / src / util.ts View on Github external
export function createSignPayload (address: string, cmd: number, payload: string | Uint8Array): Uint8Array {
  return u8aConcat(
    SUBSTRATE_ID,
    CRYPTO_SR25519,
    new Uint8Array([cmd]),
    decodeAddress(address),
    u8aToU8a(payload)
  );
}
github polkadot-js / ui / packages / reactnative-identicon / src / Identicon.tsx View on Github external
public static getDerivedStateFromProps ({ prefix = IdentityIcon.prefix, value }: Props, prevState: State): State | null {
    try {
      const address = isU8a(value) || isHex(value)
        ? encodeAddress(value, prefix)
        : (value || '');
      const publicKey = u8aToHex(decodeAddress(address, true, prefix));

      return address === prevState.address
        ? null
        : { address, publicKey };
    } catch (error) {
      return {
        address: '',
        publicKey: '0x'
      };
    }
  }
github polkadot-js / api / packages / types / src / primitive / Generic / Address.ts View on Github external
private static decodeString (registry: Registry, value: string): AccountId | AccountIndex {
    const decoded = decodeAddress(value);

    return decoded.length === 32
      ? createType(registry, 'AccountId', decoded)
      : createType(registry, 'AccountIndex', u8aToBn(decoded, true));
  }
github polkadot-js / api / packages / types / src / primitive / Generic / AccountId.ts View on Github external
private static decodeAccountId (value: AnyU8a | AnyString): Uint8Array {
    if (isU8a(value) || Array.isArray(value)) {
      return u8aToU8a(value);
    } else if (isHex(value)) {
      return hexToU8a(value.toString());
    } else if (isString(value)) {
      return decodeAddress((value as string).toString());
    }

    return value;
  }
github polkadot-js / apps / packages / app-claims / src / index.tsx View on Github external
public render (): React.ReactNode {
    const { api, systemChain = '', t } = this.props;
    const { accountId, didCopy, ethereumAddress, signature, step } = this.state;

    const payload = accountId
      ? (
        u8aToString(api.consts.claims.prefix.toU8a(true)) +
        u8aToHex(decodeAddress(accountId), -1, false)
      )
      : '';

    return (
      <main>
        <header>
        <h1>
          claim your <em>{TokenUnit.abbr}</em> tokens
        </h1>
        
          
            
              <h3>{t('1. Select your {{chain}} account', {
                replace: {
                  chain: systemChain
                }</h3></header></main>
github polkadot-js / ui / packages / ui-shared / src / polkadotIcon.ts View on Github external
function addressToId (address: string): Uint8Array {
  return blake2(decodeAddress(address)).map((x, i): number => (x + 256 - ZERO[i]) % 256);
}