@ethersproject/strings#toUtf8Bytes TypeScript Examples
The following examples show how to use
@ethersproject/strings#toUtf8Bytes.
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: utils.ts From evm-provider.js with Apache License 2.0 | 7 votes |
export function createClaimEvmSignature(substrateAddress: string): Bytes {
const publicKeySubstrate = decodeAddress(substrateAddress);
let message: Bytes | string =
'reef evm:' + Buffer.from(publicKeySubstrate).toString('hex');
if (typeof message === 'string') {
message = toUtf8Bytes(message);
}
return message;
}
Example #2
Source File: Signer.ts From bodhi.js with Apache License 2.0 | 6 votes |
async _signMessage(evmAddress: string, message: Bytes | string): Promise<string> {
if (!evmAddress) {
return logger.throwError('No binding evm address');
}
const messagePrefix = '\x19Ethereum Signed Message:\n';
if (typeof message === 'string') {
message = toUtf8Bytes(message);
}
const msg = u8aToHex(concat([toUtf8Bytes(messagePrefix), toUtf8Bytes(String(message.length)), message]));
if (!this.signingKey.signRaw) {
return logger.throwError('Need to implement signRaw method');
}
const result = await this.signingKey.signRaw({
address: evmAddress,
data: msg,
type: 'bytes'
});
return joinSignature(result.signature);
}
Example #3
Source File: abi.ts From ethers-multicall with MIT License | 6 votes |
public static encode(name: string, inputs: ParamType[], params: any[]) {
const functionSignature = getFunctionSignature(name, inputs);
const functionHash = keccak256(toUtf8Bytes(functionSignature));
const functionData = functionHash.substring(2, 10);
const abiCoder = new AbiCoder();
const argumentString = abiCoder.encode(inputs, params);
const argumentData = argumentString.substring(2);
const inputData = `0x${functionData}${argumentData}`;
return inputData;
}
Example #4
Source File: Signer.ts From evm-provider.js with Apache License 2.0 | 6 votes |
async _signMessage(
evmAddress: string,
message: Bytes | string
): Promise<string> {
if (!evmAddress) {
return logger.throwError('No binding evm address');
}
const messagePrefix = '\x19Ethereum Signed Message:\n';
if (typeof message === 'string') {
message = toUtf8Bytes(message);
}
const msg = u8aToHex(
concat([
toUtf8Bytes(messagePrefix),
toUtf8Bytes(String(message.length)),
message
])
);
if (!this.signingKey.signRaw) {
return logger.throwError('Need to implement signRaw method');
}
const result = await this.signingKey.signRaw({
address: evmAddress,
data: msg,
type: 'bytes'
});
return joinSignature(result.signature);
}
Example #5
Source File: string.ts From fuels-ts with Apache License 2.0 | 5 votes |
encode(value: string): Uint8Array {
let pad = (8 - this.length) % 8;
pad = pad < 0 ? pad + 8 : pad;
const str = toUtf8Bytes(value.slice(0, this.length));
return concat([str, new Uint8Array(pad)]);
}
Example #6
Source File: interface.ts From fuels-ts with Apache License 2.0 | 5 votes |
static getSighash(fragment: FunctionFragment | string): Uint8Array {
const bytes =
typeof fragment === 'string' ? toUtf8Bytes(fragment) : toUtf8Bytes(fragment.format());
return concat([new Uint8Array(4), arrayify(sha256(bytes)).slice(0, 4)]);
}
Example #7
Source File: index.ts From snapshot-plugins with MIT License | 4 votes |
/**
* scheduleAction schedules an action into a GovernQueue.
* Instead of sending the action to a disputable delay from aragonOS, we directly call this
* contract.
* the actionsFromAragonPlugin is an array of objects with the form { to, value, data }
*/
async function scheduleAction(
network,
web3,
daoName,
account,
proof,
actionsFromAragonPlugin
) {
const query = GQL_QUERY;
query.registryEntry.__args.id = daoName;
const result = await subgraphRequest(ARAGON_SUBGRAPH_URL[network], query);
const config = result.registryEntry.queue.config;
// Building the nonce for the next tx
const nonce = await call(web3, queueAbi, [
result.registryEntry.queue.address,
'nonce'
]);
const bnNonce = BigNumber.from(nonce);
const newNonce = bnNonce.add(BigNumber.from(1));
// We also need to get a timestamp bigger or equal to the current block.timestamp + config.executionDelay
// Right now + execution delay + 60 seconds into the future
const currentDate =
Math.round(Date.now() / 1000) + Number(config.executionDelay) + 60;
const allowance = await call(web3, ercAbi, [
config.scheduleDeposit.token,
'allowance',
[account, result.registryEntry.queue.address]
]);
// First, let's handle token approvals.
// There are 3 cases to check
// 1. The user has more allowance than needed, we can skip. (0 tx)
// 2. The user has less allowance than needed, and we need to raise it. (2 tx)
// 3. The user has 0 allowance, we just need to approve the needed amount. (1 tx)
if (
allowance.lt(config.scheduleDeposit.amount) &&
config.scheduleDeposit.token !== NO_TOKEN
) {
if (!allowance.isZero()) {
const resetTx = await sendTransaction(
web3,
config.scheduleDeposit.token,
ercAbi,
'approve',
[result.registryEntry.queue.address, '0']
);
await resetTx.wait(1);
}
await sendTransaction(
web3,
config.scheduleDeposit.token,
ercAbi,
'approve',
[result.registryEntry.queue.address, config.scheduleDeposit.amount]
);
}
return await sendTransaction(
web3,
result.registryEntry.queue.address,
queueAbi,
'schedule',
[
{
payload: {
nonce: newNonce.toString(),
executionTime: currentDate,
submitter: account,
executor: result.registryEntry.executor.address,
actions: actionsFromAragonPlugin,
allowFailuresMap: FAILURE_MAP,
// proof in snapshot's case, could be the proposal's IPFS CID
proof: proof ? toUtf8Bytes(proof) : EMPTY_BYTES
},
config: {
executionDelay: config.executionDelay,
scheduleDeposit: {
token: config.scheduleDeposit.token,
amount: config.scheduleDeposit.amount
},
challengeDeposit: {
token: config.challengeDeposit.token,
amount: config.challengeDeposit.amount
},
resolver: config.resolver,
rules: config.rules,
maxCalldataSize: config.maxCalldataSize
}
}
],
{
// This can probably be optimized
gasLimit: 500000
}
);
}