Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getContractStorage(
api: ApiPromise,
contractAddress: Address,
storageKey: Uint8Array
): Promise {
const contractInfo = await api.query.contracts.contractInfoOf(
contractAddress
);
// Return the value of the contracts storage
const storageKeyBlake2b = blake.blake2bHex(storageKey, null, 32);
return await api.rpc.state.getChildStorage(
(contractInfo as Option).unwrap().asAlive.trieId,
'0x' + storageKeyBlake2b
);
}
_setRootKeyFromPublicKey = async (
publicKey: string
): Promise => {
try {
const blakeHash = blakejs.blake2bHex(publicKey, null, 32);
const mnemonicFromSeed = entropyToMnemonic(blakeHash);
const entropy = RustModule.Wallet.Entropy.from_english_mnemonics(mnemonicFromSeed);
this.rootKey = RustModule.Wallet.PrivateKey.new(entropy, '');
} catch (error) {
Logger.error('UtilityKeyApi::rootKeyFromPublicKey error: ' + stringifyError(error));
throw new GenericApiError();
}
};
export function createAccountPlate(accountPubHash: string): WalletAccountNumberPlate {
const hash = blakejs.blake2bHex(accountPubHash);
const [a, b, c, d] = crc32(hash);
const alpha = `ABCDEJHKLNOPSTXZ`;
const letters = x => `${alpha[Math.floor(x / 16)]}${alpha[x % 16]}`;
const numbers = `${((c << 8) + d) % 10000}`.padStart(4, '0');
const id = `${letters(a)}${letters(b)}-${numbers}`;
return { hash, id };
}
const packRawTxIdAndBody = (decodedTxBody): [TxIdHexType, TxBodyHexType] => {
if (!decodedTxBody) {
throw new Error('Cannot decode inputs from undefined transaction!')
}
try {
const [inputs, outputs, attributes] = decodedTxToBase(decodedTxBody)
const cborEncoder: CborEncoder = selectCborEncoder(outputs)
const enc = cborEncoder.encode([
new CborIndefiniteLengthArray(inputs, cborEncoder),
new CborIndefiniteLengthArray(outputs, cborEncoder),
attributes,
])
const txId = blake.blake2bHex(enc, null, 32)
const txBody = enc.toString('hex')
return [txId, txBody]
} catch (e) {
throw new Error(`Failed to convert raw transaction to ID! ${JSON.stringify(e)}`)
}
}
const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
const {
addressRoot,
addrAttr,
addressType,
} = ShelleyValidator.deconstructAddress(inputAddress)
if (addressType !== 0) {
this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
return
}
const addressRootHex = addressRoot.toString('hex')
const expectedStruct = [0, [0, sign[0]], addrAttr]
const encodedStruct = Buffer.from(sha3_256.update(
cbor.encodeCanonical(expectedStruct)).digest())
const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
if (addressRootHex !== expectedRootHex) {
throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
}
})
}
export const hash = function(input: string | Buffer): string {
return "0x" + blake.blake2bHex(input, null, 32);
};
const headerToId = (header, type: number) => {
const headerData = cbor.encode([type, header])
const id = blake.blake2bHex(headerData, null, 32)
return id
}
const grouped = _.chain(mapped).groupBy('key').mapValues((vs, key) => {
const { json: jsonEntry, sig: sigEntry } = _.keyBy(vs, 'ext')
if (!jsonEntry) {
this.logger.warn(`[GitHubLoader] No JSON found for key: ${key}! Ignoring`)
return null
} else if (!sigEntry) {
this.logger.warn(`[GitHubLoader] No SIG found for key: ${key} (JSON=${jsonEntry.text})! Ignoring`)
return null
}
const [json, sig] = [jsonEntry.text, sigEntry.text]
try {
const hash = blake.blake2bHex(`${json}:${sig}`, null, 32)
return { json: JSON.parse(json), sig, hash }
} catch (e) {
this.logger.warn(`[GitHubLoader] Failed to parse json from: ${json}`, e)
return null
}
}).pickBy(Boolean).value()
const entries = Object.entries(grouped).map(([owner, { json, sig, hash }]) => {