Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async sign(bytes: string, _watermark?: Uint8Array) {
const prefixSig = await tezbridge.request({
method: 'raw_sign',
bytes, // Any operation bytes as string
});
const decoded = b58cdecode(prefixSig, prefix[prefixSig.substr(0, 5)]);
return {
bytes,
sig: b58cencode(decoded, prefix.sig),
prefixSig,
sbytes: bytes + buf2hex(toBuffer(decoded)),
};
}
}
async sign(bytes: string, _watermark?: Uint8Array) {
const prefixSig = await tezbridge.request({
method: 'raw_sign',
bytes, // Any operation bytes as string
});
const decoded = b58cdecode(prefixSig, prefix[prefixSig.substr(0, 5)]);
return {
bytes,
sig: b58cencode(decoded, prefix.sig),
prefixSig,
sbytes: bytes + buf2hex(toBuffer(decoded)),
};
}
}
async sign(bytes: string, _watermark?: Uint8Array) {
const prefixSig = await tezbridge.request({
method: 'raw_sign',
bytes, // Any operation bytes as string
});
const decoded = b58cdecode(prefixSig, prefix[prefixSig.substr(0, 5)]);
return {
bytes,
sig: b58cencode(decoded, prefix.sig),
prefixSig,
sbytes: bytes + buf2hex(toBuffer(decoded)),
};
}
}
delegate,
storage,
fee = DEFAULT_FEE.ORIGINATION,
gasLimit = DEFAULT_GAS_LIMIT.ORIGINATION,
storageLimit = DEFAULT_STORAGE_LIMIT.ORIGINATION,
}: OriginateParams,
publicKeyHash: string
) => {
// tslint:disable-next-line: strict-type-predicates
if (storage !== undefined && init !== undefined) {
throw new Error(
'Storage and Init cannot be set a the same time. Please either use storage or init but not both.'
);
}
const contractCode = Array.isArray(code) ? code : ml2mic(code);
let contractStorage: object;
if (storage !== undefined) {
const schema = new Schema(contractCode[1].args[0]);
contractStorage = schema.Encode(storage);
} else {
contractStorage = typeof init === 'string' ? sexp2mic(init) : init;
}
const script = {
code: Array.isArray(code) ? code : ml2mic(code),
storage: contractStorage,
};
const operation: RPCOriginationOperation = {
kind: 'origination',
) => {
// tslint:disable-next-line: strict-type-predicates
if (storage !== undefined && init !== undefined) {
throw new Error(
'Storage and Init cannot be set a the same time. Please either use storage or init but not both.'
);
}
const contractCode = Array.isArray(code) ? code : ml2mic(code);
let contractStorage: object;
if (storage !== undefined) {
const schema = new Schema(contractCode[1].args[0]);
contractStorage = schema.Encode(storage);
} else {
contractStorage = typeof init === 'string' ? sexp2mic(init) : init;
}
const script = {
code: Array.isArray(code) ? code : ml2mic(code),
storage: contractStorage,
};
const operation: RPCOriginationOperation = {
kind: 'origination',
fee,
gas_limit: gasLimit,
storage_limit: storageLimit,
balance: format('tz', 'mutez', balance).toString(),
manager_pubkey: publicKeyHash,
spendable,
delegatable,
constructor(private key: string, encrypted: boolean, decrypt: (k: any) => any) {
this._key = decrypt(b58cdecode(this.key, prefix[key.substr(0, encrypted ? 5 : 4)]));
this._publicKey = this._key.slice(32);
if (!this._key) {
throw new Error('Unable to decode key');
}
this.isInit = this.init();
}
async sign(bytes: string, bytesHash: Uint8Array) {
const key = new elliptic.ec(this.curve).keyFromPrivate(this._key);
const sig = key.sign(bytesHash, { canonical: true });
const signature = new Uint8Array(sig.r.toArray().concat(sig.s.toArray()));
const signatureBuffer = toBuffer(signature);
const sbytes = bytes + buf2hex(signatureBuffer);
return {
bytes,
sig: b58cencode(signature, prefix.sig),
prefixSig: b58cencode(signature, pref[this.curve].sig),
sbytes,
};
}
async sign(bytes: string, bytesHash: Uint8Array) {
await this.isInit;
const signature = sodium.crypto_sign_detached(
new Uint8Array(bytesHash),
new Uint8Array(this._key)
);
const signatureBuffer = toBuffer(signature);
const sbytes = bytes + buf2hex(signatureBuffer);
return {
bytes,
sig: b58cencode(signature, prefix.sig),
prefixSig: b58cencode(signature, prefix.edsig),
sbytes,
};
}
static fromFundraiser(email: string, password: string, mnemonic: string) {
let seed = mnemonicToSeedSync(mnemonic, `${email}${password}`);
const test = b58cencode(seed.slice(0, 32), prefix.edsk2);
return new InMemorySigner(test);
}
async publicKey(): Promise {
return b58cencode(this._publicKey, pref[this.curve].pk);
}