Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

新增 Package 的 Hasher #45

Open
zhanghongfei opened this issue May 6, 2022 · 0 comments · May be fixed by #57
Open

新增 Package 的 Hasher #45

zhanghongfei opened this issue May 6, 2022 · 0 comments · May be fixed by #57
Labels
help wanted Extra attention is needed

Comments

@zhanghongfei
Copy link
Contributor

为了方便开发者,建议添加对于 Package 的 Hasher

目前 sdk 中的 crypto_hash 中包含了 createUserTransactionHasher createUserTransactionHasher createSigningMessageHasher

讨论在这里

结论如下:
样例代码

const fs = require('fs');
const { utils, bcs, crypto_hash } = require('@starcoin/starcoin');

const module_address = "your_module_address";
const mvFile = "path_to_your_mv_file";
const payload = utils.tx.encodePackage(module_address, [fs.readFileSync(mvFile)]);

const s = (function () {
  const se = new bcs.BcsSerializer();
  payload.value.serialize(se);   // 这里要用 payload.value, 因为 payload 是 TransactionPayloadVariantPackage 结构,我们要用 Package 结构
  return se.getBytes();
})();
const package_hash = crypto_hash.createHash("Package").crypto_hash(s);  // 这里是固定的 Prefix:  Package
console.log(package_hash)
@jolestar jolestar added the help wanted Extra attention is needed label May 6, 2022
@jiangying000 jiangying000 linked a pull request Jul 31, 2022 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants