@polkadot/util-crypto#addressEq TypeScript Examples

The following examples show how to use @polkadot/util-crypto#addressEq. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountSigningKey.ts    From bodhi.js with Apache License 2.0 6 votes vote down vote up
public async signPayload(payload: SigningPayloadJSON): Promise<SigningKeyResult> {
    const findKeyringPair = this.#keyringPairs.find((pair) => addressEq(pair.address, payload.address));

    if (!findKeyringPair) {
      throw new Error(`Can't find the keyringpair for ${payload.address}`);
    }

    return new Promise((resolve): void => {
      const signed = this.#registry
        .createType('ExtrinsicPayload', payload, { version: payload.version })
        .sign(findKeyringPair);

      resolve({ id: ++id, ...signed });
    });
  }
Example #2
Source File: TxSigned.tsx    From crust-apps with Apache License 2.0 6 votes vote down vote up
async function extractParams (api: ApiPromise, address: string, options: Partial<SignerOptions>, getLedger: () => Ledger, setQrState: (state: QrState) => void): Promise<['qr' | 'signing', string, Partial<SignerOptions>]> {
  const pair = keyring.getPair(address);
  const { meta: { accountOffset, addressOffset, isExternal, isHardware, isInjected, isProxied, source } } = pair;

  if (isHardware) {
    return ['signing', address, { ...options, signer: new LedgerSigner(api.registry, getLedger, accountOffset as number || 0, addressOffset as number || 0) }];
  } else if (isExternal && !isProxied) {
    return ['qr', address, { ...options, signer: new QrSigner(api.registry, setQrState) }];
  } else if (isInjected) {
    const injected = await web3FromSource(source as string);

    assert(injected, `Unable to find a signer for ${address}`);

    return ['signing', address, { ...options, signer: injected.signer }];
  }

  assert(addressEq(address, pair.address), `Unable to retrieve keypair for ${address}`);

  return ['signing', address, { ...options, signer: new AccountSigner(api.registry, pair) }];
}
Example #3
Source File: TxSigned.tsx    From subscan-multisig-react with Apache License 2.0 5 votes vote down vote up
async function extractParams(
  api: ApiPromise,
  address: string,
  options: Partial<SignerOptions>,
  getLedger: () => Ledger,
  setQrState: (state: QrState) => void
): Promise<['qr' | 'signing', string, Partial<SignerOptions>]> {
  const pair = keyring.getPair(address);
  const {
    meta: { accountOffset, addressOffset, isExternal, isHardware, isInjected, isProxied, source },
  } = pair;

  if (isHardware) {
    return [
      'signing',
      address,
      {
        ...options,
        signer: new LedgerSigner(
          api.registry,
          getLedger,
          (accountOffset as number) || 0,
          (addressOffset as number) || 0
        ),
      },
    ];
  } else if (isExternal && !isProxied) {
    return ['qr', address, { ...options, signer: new QrSigner(api.registry, setQrState) }];
  } else if (isInjected) {
    const injected = await web3FromSource(source as string);

    assert(injected, `Unable to find a signer for ${address}`);

    return ['signing', address, { ...options, signer: injected.signer }];
  }

  assert(addressEq(address, pair.address), `Unable to retrieve keypair for ${address}`);

  return ['signing', address, { ...options, signer: new AccountSigner(api.registry, pair) }];
}