How to use the @polkadot/keyring.decodeAddress function in @polkadot/keyring

To help you get started, we’ve selected a few @polkadot/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 / api / packages / types / src / Address.ts View on Github external
// This allows us to instantiate an address with a raw publicKey. Do this first before
      // we checking the first byte, otherwise we may split an already-existent valid address
      if (value.length === 32) {
        return new AccountId(value);
      } else if (value[0] === 0xff) {
        return new AccountId(value.subarray(1));
      }

      const [offset, length] = AccountIndex.readLength(value);

      return new AccountIndex(u8aToBn(value.subarray(offset, offset + length), true));
    } else if (isHex(value)) {
      return Address.decodeAddress(hexToU8a(value));
    }

    const decoded = decodeAddress(value);

    return decoded.length === 32
      ? new AccountId(decoded)
      : new AccountIndex(u8aToBn(decoded, true));
  }
github vue-polkadot / vue-ui / packages / vue-keyring / src / defaults.ts View on Github external
function toHex(address: string): string {
  return u8aToHex(
    // When saving pre-checksum changes, ensure that we can decode
    decodeAddress(address, true)
  );
}
github polkadot-js / ui / packages / ui-keyring / src / defaults.ts View on Github external
function toHex (address: string): string {
  return u8aToHex(
    // When saving pre-checksum changes, ensure that we can decode
    decodeAddress(address, true)
  );
}
github polkadot-js / apps / packages / ui-api / src / derive / balances / accountIdAndIndex.ts View on Github external
return async (address: AccountId | AccountIndex | string | null | undefined, cb: (idAndIndex: IdAndIndex) => any): PromiseSubscription => {
    try {
      // yes, this can fail, don't care too much, catch will catch it
      const decoded = decodeAddress((address as any).toString());

      if (decoded.length === 32) {
        const accountId = new AccountId(decoded);

        return accountIdToIndex(api)(accountId, (accountIndex?: AccountIndex) =>
          cb([accountId, accountIndex])
        );
      }

      const accountIndex = new AccountIndex(address as string);

      return accountIndexToId(api)(accountIndex, (accountId?: AccountId) =>
        cb([accountId, accountIndex])
      );
    } catch (error) {
      // swallow
github polkadot-js / api / packages / api-observable / src / Combined.ts View on Github external
accountIdAndIndex = (address?: AccountId | AccountIndex | string | null): Observable<[AccountId | undefined, AccountIndex | undefined]> => {
    try {
      // yes, this can fail, don't care too much, catch will catch it
      const length = decodeAddress((address as any).toString()).length;

      assert([1, 2, 4, 8, 32].indexOf(length) !== -1, `Invalid length for decoded address, found ${length}`);

      if (length === 32) {
        const accountId = new AccountId(address as string);

        return this
          .accountIndexFromId(accountId)
          .pipe(
            map((accountIndex?: AccountIndex): [AccountId, AccountIndex | undefined] =>
              [accountId, accountIndex]
            )
          );
      }

      const accountIndex = new AccountIndex(address as string);
github polkadot-js / api / packages / types / src / AccountIndex.ts View on Github external
static decodeAccountIndex (value: AnyNumber): BN | Uint8Array | number | string {
    if (value instanceof UInt) {
      return value.raw;
    } else if (value instanceof U8a) {
      return AccountIndex.decodeAccountIndex(value.raw);
    } else if (isBn(value) || isNumber(value) || isU8a(value)) {
      return value;
    } else if (isHex(value)) {
      // Here we convert via hexToU8a since we expect the LE encoded value representation. This
      // is different than UInt where we expect a BE (human-readable representation)
      return hexToU8a(value);
    }

    return AccountIndex.decodeAccountIndex(decodeAddress(value));
  }
github polkadot-js / api / packages / types / src / 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 AnyString).toString());
    }

    return value;
  }

@polkadot/keyring

Keyring management

Apache-2.0
Latest version published 8 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages