How to use the @0x/assert.assert.isETHAddressHex function in @0x/assert

To help you get started, we’ve selected a few @0x/assert 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 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async signMessageAsync(address: string, message: string): Promise {
        assert.isETHAddressHex('address', address);
        assert.isString('message', message); // TODO: Should this be stricter? Hex string?
        const signData = await this.sendRawPayloadAsync({
            method: 'eth_sign',
            params: [address, message],
        });
        return signData;
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async getBalanceInWeiAsync(owner: string, defaultBlock?: BlockParam): Promise {
        assert.isETHAddressHex('owner', owner);
        if (defaultBlock !== undefined) {
            Web3Wrapper._assertBlockParam(defaultBlock);
        }
        const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
        const encodedOwner = marshaller.marshalAddress(owner);
        const balanceInWei = await this.sendRawPayloadAsync({
            method: 'eth_getBalance',
            params: [encodedOwner, marshalledDefaultBlock],
        });
        // Rewrap in a new BigNumber
        return new BigNumber(balanceInWei);
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async getContractCodeAsync(address: string, defaultBlock?: BlockParam): Promise {
        assert.isETHAddressHex('address', address);
        if (defaultBlock !== undefined) {
            Web3Wrapper._assertBlockParam(defaultBlock);
        }
        const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
        const encodedAddress = marshaller.marshalAddress(address);
        const code = await this.sendRawPayloadAsync({
            method: 'eth_getCode',
            params: [encodedAddress, marshalledDefaultBlock],
        });
        return code;
    }
    /**
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async isSenderAddressAvailableAsync(senderAddress: string): Promise {
        assert.isETHAddressHex('senderAddress', senderAddress);
        const addresses = await this.getAvailableAddressesAsync();
        const normalizedAddress = senderAddress.toLowerCase();
        return _.includes(addresses, normalizedAddress);
    }
    /**
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / ledger.ts View on Github external
public async signPersonalMessageAsync(data: string, address: string): Promise {
        if (data === undefined) {
            throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage);
        }
        assert.isHexString('data', data);
        assert.isETHAddressHex('address', address);
        const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
        const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, address);

        this._ledgerClientIfExists = await this._createLedgerClientAsync();
        try {
            const fullDerivationPath = derivedKeyInfo.derivationPath;
            const result = await this._ledgerClientIfExists.signPersonalMessage(
                fullDerivationPath,
                ethUtil.stripHexPrefix(data),
            );
            const lowestValidV = 27;
            const v = result.v - lowestValidV;
            const hexBase = 16;
            let vHex = v.toString(hexBase);
            if (vHex.length < 2) {
                vHex = `0${v}`;
github NoahZinsmeister / web3-react / src / connectors / trezor / subprovider.ts View on Github external
public async signPersonalMessageAsync(data: string, address: string): Promise {
    if (_.isUndefined(data)) {
      throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage)
    }
    assert.isHexString('data', data)
    assert.isETHAddressHex('address', address)

    const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync()
    const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, address)
    const fullDerivationPath = derivedKeyInfo.derivationPath

    const response: TrezorConnectResponse = await this._trezorConnectClientApi.ethereumSignMessage({
      path: fullDerivationPath,
      message: data,
      hex: false
    })

    if (response.success) {
      const payload: TrezorSignMsgResponsePayload = response.payload
      return `0x${payload.signature}`
    } else {
      const payload: TrezorResponseErrorPayload = response.payload
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / private_key_wallet.ts View on Github external
public async signTypedDataAsync(address: string, typedData: EIP712TypedData): Promise {
        if (typedData === undefined) {
            throw new Error(WalletSubproviderErrors.DataMissingForSignTypedData);
        }
        assert.isETHAddressHex('address', address);
        if (address !== this._address) {
            throw new Error(
                `Requested to sign message with address: ${address}, instantiated with address: ${this._address}`,
            );
        }
        const dataBuff = signTypedDataUtils.generateTypedDataHash(typedData);
        const sig = ethUtil.ecsign(dataBuff, this._privateKeyBuffer);
        const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s);
        return rpcSig;
    }
}
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / mnemonic_wallet.ts View on Github external
public async signTypedDataAsync(address: string, typedData: EIP712TypedData): Promise {
        if (typedData === undefined) {
            throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage);
        }
        assert.isETHAddressHex('address', address);
        const privateKeyWallet = this._privateKeyWalletForAddress(address);
        const sig = await privateKeyWallet.signTypedDataAsync(address, typedData);
        return sig;
    }
    private _privateKeyWalletForAddress(address: string): PrivateKeyWalletSubprovider {
github 0xProject / 0x-monorepo / contracts / coordinator / src / client / utils / assert.ts View on Github external
async isSenderAddressAsync(
        variableName: string,
        senderAddressHex: string,
        web3Wrapper: Web3Wrapper,
    ): Promise {
        sharedAssert.isETHAddressHex(variableName, senderAddressHex);
        const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
        sharedAssert.assert(
            isSenderAddressAvailable,
            `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
        );
    },
};
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public async signTypedDataAsync(address: string, typedData: any): Promise {
        assert.isETHAddressHex('address', address);
        assert.doesConformToSchema('typedData', typedData, schemas.eip712TypedDataSchema);
        const signData = await this.sendRawPayloadAsync({
            method: 'eth_signTypedData',
            params: [address, typedData],
        });
        return signData;
    }
    /**