How to use the @polkadot/util-crypto.setSS58Format 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 / extension / packages / extension-ui / src / Popup / index.tsx View on Github external
import Authorize from './Authorize';
import CreateAccount from './CreateAccount';
import Export from './Export';
import Forget from './Forget';
import ImportQr from './ImportQr';
import ImportSeed from './ImportSeed';
import Settings from './Settings';
import Signing from './Signing';
import Welcome from './Welcome';

// load the ui settings, actually only used for address prefix atm
// probably overkill (however can replace once we have actual others)
const { prefix } = settings.get();

// FIXME Duplicated in Settings, horrible...
setSS58Format(prefix === -1 ? 42 : prefix);

// Request permission for video, based on access we can hide/show import
async function requestMediaAccess (cameraOn: boolean): Promise {
  if (!cameraOn) {
    return false;
  }

  try {
    await navigator.mediaDevices.getUserMedia({ video: true });

    return true;
  } catch (error) {
    console.error('Permission for video declined', error.message);
  }

  return false;
github polkadot-js / apps / packages / app-accounts / src / vanitygen / cli.ts View on Github external
console.error("Invalid character found in match string, allowed is '1-9' (no '0'), 'A-H, J-N & P-Z' (no 'I' or 'O'), 'a-k & m-z' (no 'l') and '?' (wildcard)");
    process.exit(-1);
  }
});

switch (network) {
  case 'kusama':
    setSS58Format(2);
    break;

  case 'polkadot':
    setSS58Format(0);
    break;

  default:
    setSS58Format(42);
    break;
}

console.log(options);

function showProgress (): void {
  const elapsed = (Date.now() - startAt) / 1000;

  indicator++;

  if (indicator === INDICATORS.length) {
    indicator = 0;
  }

  process.stdout.write(`\r[${INDICATORS[indicator]}] ${(total.toString().match(NUMBER_REGEX) || []).join(',')} keys in ${(elapsed).toFixed(2)}s (${(total / elapsed).toFixed(0)} keys/s)`);
}
github polkadot-js / apps / packages / app-accounts / src / vanitygen / cli.ts View on Github external
const tests = options.match.split(',');

tests.forEach((test): void => {
  if (!matchRegex.test(test)) {
    console.error("Invalid character found in match string, allowed is '1-9' (no '0'), 'A-H, J-N & P-Z' (no 'I' or 'O'), 'a-k & m-z' (no 'l') and '?' (wildcard)");
    process.exit(-1);
  }
});

switch (network) {
  case 'kusama':
    setSS58Format(2);
    break;

  case 'polkadot':
    setSS58Format(0);
    break;

  default:
    setSS58Format(42);
    break;
}

console.log(options);

function showProgress (): void {
  const elapsed = (Date.now() - startAt) / 1000;

  indicator++;

  if (indicator === INDICATORS.length) {
    indicator = 0;
github polkadot-js / common / packages / keyring / src / pair / index.spec.ts View on Github external
it('allows encoding of address with different prefixes', (): void => {
    expect(keyring.alice.address).toEqual(
      '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua'
    );

    setSS58Format(68);

    expect(keyring.alice.address).toEqual(
      '7sGUeMak588SPY2YMmmuKUuLz7u2WQpf74F9dCFtSLB2td9d'
    );

    setSS58Format(42);
  });
github polkadot-js / common / packages / keyring / src / pair / index.spec.ts View on Github external
it('allows encoding of address with different prefixes', (): void => {
    expect(keyring.alice.address).toEqual(
      '5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaQua'
    );

    setSS58Format(68);

    expect(keyring.alice.address).toEqual(
      '7sGUeMak588SPY2YMmmuKUuLz7u2WQpf74F9dCFtSLB2td9d'
    );

    setSS58Format(42);
  });
github polkadot-js / common / packages / keyring / src / index.spec.ts View on Github external
it('adds from a mnemonic', (): void => {
      setSS58Format(68);

      expect(
        keypair.addFromMnemonic('moral movie very draw assault whisper awful rebuild speed purity repeat card', {}).address
      ).toEqual('7qQGarA4PWjPPVHG4USn1yuuVZvEHN7XZz8o7EbAp48jayZQ');
    });
github polkadot-js / api / packages / types / src / primitive / Generic / AccountId.spec.ts View on Github external
it('has the correct entries', (): void => {
      setSS58Format(68);

      const data = createType(registry, 'StorageData', jsonVec.params.result.changes[0][1]);
      const list = createType(registry, 'Vec', data).map((accountId): string => accountId.toString());

      expect(list).toEqual([
        '7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup',
        '7pHyqeYaJjJPgxQgCXoS2EZMhBhtpm6BLCqQ4jJZTQB2kMhw',
        '7pYLWV6PTUmLTMQfHmmuBwBNLkhcKhRAnkM36CSJtjat9ACb',
        '7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJdMX',
        '7rADc9JW5EUGFPWLjPMipH4c3bJ2GyAUedmqQHiaGucWVrsT',
        '7oK5KRH6jt4p8auipnru9ptqeuRwbLMHA2tgCViZzhmW4Lox',
        '7ndAVsHvonnzTg4AvRhpraNCKj9g4CGQXKoLrgkTZ91Na6PE',
        '7oL7VfXgLA8L3pJJwi11v3sBYc1b5R3tLrweHwzMNxgEpjxP'
      ]);
    });
  });
github polkadot-js / common / packages / keyring / src / keyring.ts View on Github external
constructor (options: KeyringOptions = {}) {
    options.type = options.type || 'ed25519';
    options.ss58Format = isNumber(options.ss58Format)
      ? options.addressPrefix
      : options.ss58Format;

    assert(options && ['ed25519', 'sr25519'].includes(options.type || 'undefined'), `Expected a keyring type of either 'ed25519' or 'sr25519', found '${options.type}`);

    this._pairs = new Pairs();
    this._type = options.type;

    if (isNumber(options.ss58Format)) {
      setSS58Format(options.ss58Format);
    }
  }
github polkadot-js / extension / packages / extension-ui / src / Popup / Settings / index.tsx View on Github external
const _onChangePrefix = (value: string): void => {
    const prefix = parseInt(value, 10);

    setSS58Format(prefix === -1 ? 42 : prefix);
    setPrefix(value);

    settings.set({ prefix });
  };