How to use the @0x/assert.assert.isHexString 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 getTransactionReceiptIfExistsAsync(txHash: string): Promise {
        assert.isHexString('txHash', txHash);
        const transactionReceiptRpc = await this.sendRawPayloadAsync({
            method: 'eth_getTransactionReceipt',
            params: [txHash],
        });
        // HACK Parity can return a pending transaction receipt. We check for a non null
        // block number before continuing with returning a fully realised receipt.
        // ref: https://github.com/paritytech/parity-ethereum/issues/1180
        if (transactionReceiptRpc !== null && transactionReceiptRpc.blockNumber !== null) {
            transactionReceiptRpc.status = Web3Wrapper._normalizeTxReceiptStatus(transactionReceiptRpc.status);
            const transactionReceipt = marshaller.unmarshalTransactionReceipt(transactionReceiptRpc);
            return transactionReceipt;
        } else {
            return undefined;
        }
    }
    /**
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / private_key_wallet.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);
        if (address !== this._address) {
            throw new Error(
                `Requested to sign message with address: ${address}, instantiated with address: ${this._address}`,
            );
        }
        const dataBuff = ethUtil.toBuffer(data);
        const msgHashBuff = ethUtil.hashPersonalMessage(dataBuff);
        const sig = ethUtil.ecsign(msgHashBuff, this._privateKeyBuffer);
        const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s);
        return rpcSig;
    }
    /**
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / i_wallet.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
        logDecodeDependencies: { [contractName: string]: ContractAbi },
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
        const iface = new ethers.utils.Interface(abi);
        const deployInfo = iface.deployFunction;
        const txData = deployInfo.encode(bytecode, []);
        const web3Wrapper = new Web3Wrapper(provider);
        const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
            {
                data: txData,
                ...txDefaults,
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / generated-wrappers / coordinator.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
        logDecodeDependencies: { [contractName: string]: ContractAbi },
        exchange: string,
        chainId: BigNumber,
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [exchange, chainId] = BaseContract._formatABIDataItemList(
            constructorAbi.inputs,
            [exchange, chainId],
            BaseContract._bigNumberToString,
        );
        const iface = new ethers.utils.Interface(abi);
        const deployInfo = iface.deployFunction;
        const txData = deployInfo.encode(bytecode, [exchange, chainId]);
        const web3Wrapper = new Web3Wrapper(provider);
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / trezor.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);
        const fullDerivationPath = derivedKeyInfo.derivationPath;

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

        if (response.success) {
            const payload: TrezorSignMsgResponsePayload = response.payload;
            return `0x${payload.signature}`;
        } else {
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / generated-wrappers / i_asset_data.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
        logDecodeDependencies: { [contractName: string]: ContractAbi },
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
        const iface = new ethers.utils.Interface(abi);
        const deployInfo = iface.deployFunction;
        const txData = deployInfo.encode(bytecode, []);
        const web3Wrapper = new Web3Wrapper(provider);
        const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
            {
                data: txData,
                ...txDefaults,
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / asset_proxy_owner.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
            _owners: string[],
            _assetProxyContracts: string[],
            _required: BigNumber,
            _secondsTimeLocked: BigNumber,
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [_owners,
_assetProxyContracts,
_required,
_secondsTimeLocked
] = BaseContract._formatABIDataItemList(
            constructorAbi.inputs,
            [_owners,
_assetProxyContracts,
_required,
github 0xProject / 0x-monorepo / packages / asset-buyer / src / utils / assert.ts View on Github external
isValidOrderProviderRequest(variableName: string, orderFetcherRequest: OrderProviderRequest): void {
        sharedAssert.isHexString(`${variableName}.makerAssetData`, orderFetcherRequest.makerAssetData);
        sharedAssert.isHexString(`${variableName}.takerAssetData`, orderFetcherRequest.takerAssetData);
    },
    isValidPercentage(variableName: string, percentage: number): void {
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / coordinator_registry.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
        logDecodeDependencies: { [contractName: string]: ContractAbi },
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
        const iface = new ethers.utils.Interface(abi);
        const deployInfo = iface.deployFunction;
        const txData = deployInfo.encode(bytecode, []);
        const web3Wrapper = new Web3Wrapper(provider);
        const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
            {
                data: txData,
                ...txDefaults,
github 0xProject / 0x-monorepo / packages / abi-gen-wrappers / src / generated-wrappers / erc1155_mintable.ts View on Github external
public static async deployAsync(
        bytecode: string,
        abi: ContractAbi,
        supportedProvider: SupportedProvider,
        txDefaults: Partial,
        logDecodeDependencies: { [contractName: string]: ContractAbi },
    ): Promise {
        assert.isHexString('bytecode', bytecode);
        assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
            schemas.addressSchema,
            schemas.numberSchema,
            schemas.jsNumber,
        ]);
        const provider = providerUtils.standardizeOrThrow(supportedProvider);
        const constructorAbi = BaseContract._lookupConstructorAbi(abi);
        [] = BaseContract._formatABIDataItemList(constructorAbi.inputs, [], BaseContract._bigNumberToString);
        const iface = new ethers.utils.Interface(abi);
        const deployInfo = iface.deployFunction;
        const txData = deployInfo.encode(bytecode, []);
        const web3Wrapper = new Web3Wrapper(provider);
        const txDataWithDefaults = await BaseContract._applyDefaultsToContractTxDataAsync(
            {
                data: txData,
                ...txDefaults,