Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let functionSignature = '0x8b1d8335'; // perform
if (order.takerId === zeroAddress) {
functionSignature = '0x04aa2cb7'; // performAnyTaker
}
const recipeTuple = createRecipeTuple(gateway, order);
const signatureTuple = createSignatureTuple(claim);
const attrs = {
from: gateway.provider.accountId,
to: gateway.id,
data: functionSignature + gateway.provider.encoder.encodeParameters(inputTypes, [recipeTuple, signatureTuple]).substr(2),
};
const res = await gateway.provider.post({
method: 'eth_sendTransaction',
params: [attrs],
});
return new Mutation(gateway.provider, res.result);
}
claim.forEach((c) => {
const [kind, signature] = c.split(':');
const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`),
k,
};
if (signatureData.v < 27) {
signatureData.v = signatureData.v + 27;
}
signatures.push(signatureData);
});
return toTuple(signatures);
export function createSignatureTuple(claim: string) {
const [kind, signature] = claim.split(':');
const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`),
k,
};
if (signatureData.v < 27) {
signatureData.v = signatureData.v + 27;
}
return toTuple(signatureData);
}
export function createSignatureTuple(claim: string) {
const [kind, signature] = claim.split(':');
const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`),
k,
};
if (signatureData.v < 27) {
signatureData.v = signatureData.v + 27;
}
return toTuple(signatureData);
}
export function createSignatureTuple(claim: string) {
const [kind, signature] = claim.split(':');
const k = (parseInt(kind) == SignMethod.PERSONAL_SIGN) ? SignMethod.ETH_SIGN : kind;
const signatureData = {
r: signature.substr(0, 66),
s: `0x${signature.substr(66, 64)}`,
v: parseInt(`0x${signature.substr(130, 2)}`),
k,
};
if (signatureData.v < 27) {
signatureData.v = signatureData.v + 27;
}
return toTuple(signatureData);
}
public async init() {
let msg = 'test';
if (this.provider.signMethod === SignMethod.ETH_SIGN) {
msg = await sha(256, msg);
}
const signature = await this.provider.sign(`0x${msg}`);
const signatureType = this.provider.signMethod;
this.authentication = `${signatureType}:${signature}`;
let data = null;
try {
const accountData = await clientFetch(`${this.apiUrl}/account`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': this.authentication,
},
});
protected async installEvents() {
const networkVersion = await this.getNetworkVersion();
if (networkVersion !== this._networkVersion) {
this.emit(ProviderEvent.NETWORK_CHANGE, networkVersion, this._networkVersion);
this._networkVersion = networkVersion;
}
this.accountId = await this.getAvailableAccounts().then((a) => a[0]);
setTimeout(() => this.installEvents(), 1000);
}
export default async function(provider: GenericProvider, { name, symbol, decimals, supply }: ValueLedgerDeployRecipe) {
const contract = await fetchJson(provider.valueLedgerSource);
const source = contract.TokenMock.evm.bytecode.object;
const attrs = {
from: provider.accountId,
data: `0x${source}${provider.encoder.encodeParameters(inputTypes, [ name, symbol, decimals, supply]).substr(2)}`,
};
const res = await provider.post({
method: 'eth_sendTransaction',
params: [attrs],
});
return new Mutation(provider, res.result);
}
export default async function(provider: GenericProvider, { name, symbol, uriPrefix, uriPostfix, schemaId, capabilities }: AssetLedgerDeployRecipe) {
const contract = await fetchJson(provider.assetLedgerSource);
const source = contract.XcertMock.evm.bytecode.object;
const codes = (capabilities || []).map((c) => getInterfaceCode(c));
const attrs = {
from: provider.accountId,
data: `0x${source}${provider.encoder.encodeParameters(inputTypes, [name, symbol, uriPrefix, uriPostfix, schemaId, codes]).substr(2)}`,
};
const res = await provider.post({
method: 'eth_sendTransaction',
params: [attrs],
});
return new Mutation(provider, res.result);
}
export default async function(ledger: AssetLedger, accountId: string, assetId: string) {
const attrs = {
from: ledger.provider.accountId,
to: ledger.id,
data: functionSignature + ledger.provider.encoder.encodeParameters(inputTypes, [accountId, assetId]).substr(2),
};
const res = await ledger.provider.post({
method: 'eth_sendTransaction',
params: [attrs],
});
return new Mutation(ledger.provider, res.result, ledger);
}