-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: vat-safe denomHash using noble sha256 #9576
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @ts-check | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
import { bytesToHex } from '@noble/hashes/utils'; | ||
|
||
/** | ||
* cf. https://tutorials.cosmos.network/tutorials/6-ibc-dev/ | ||
* | ||
* @param {object} opts | ||
* @param {string} [opts.portId] | ||
* @param {string} [opts.channelId] required unless `path` is supplied | ||
* @param {string} [opts.path] alternative to portId, channelId | ||
* @param {string} opts.denom base denom | ||
*/ | ||
export const denomHash = ({ | ||
portId = 'transfer', | ||
channelId = /** @type {string | undefined} */ (undefined), | ||
path = `${portId}/${channelId}`, | ||
denom, | ||
}) => { | ||
const h = sha256.create().update(`${path}/${denom}`).digest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could avoid an allocation with |
||
return bytesToHex(h).toUpperCase(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import test from '@endo/ses-ava/prepare-endo.js'; | ||
|
||
import bundleSource from '@endo/bundle-source'; | ||
import { importBundle } from '@endo/import-bundle'; | ||
import { createRequire } from 'node:module'; | ||
import { denomHash } from '../../src/utils/denomHash.js'; | ||
|
||
const nodeRequire = createRequire(import.meta.url); | ||
|
||
test('compartment use of denomHash', async t => { | ||
const bundle = await bundleSource(nodeRequire.resolve('./denomHashEx.js')); | ||
const { length } = JSON.stringify(bundle); | ||
t.log('bundle length', length); | ||
const expected = denomHash({ channelId: 'channel-0', denom: 'uatom' }); | ||
|
||
const { denomHashExample } = await importBundle(bundle); | ||
t.deepEqual(denomHashExample(), expected); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { denomHash } from '../../src/utils/denomHash.js'; | ||
|
||
export const denomHashExample = () => { | ||
const h = denomHash({ channelId: 'channel-0', denom: 'uatom' }); | ||
return h; | ||
}; |
9,910 changes: 9,910 additions & 0 deletions
9,910
patches/@agoric+orchestration++@noble+hashes+1.4.0.patch
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch out for bundler support for
"exports"
since this pattern will only work when the tools account for package exports.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an alternative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not with this package. It’s pretty narrowly prescribed:
https://github.com/paulmillr/noble-hashes/blob/main/package.json#L141-L145
That is, this package cannot be used with bundlers that have not caught up with package exports. There are very few such tools, but
node -r esm
(loadgen) is among them. Hopefully, there is no risk that this package will get caught up in that, but if you see integration errors to the tune of “I can’t import this”, this is why.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
felgercarb!
loadgen ci failed. :-/
now what do I do? sigh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could fork or PR upstream to package export package relative paths to files with
.js
extensions. I’m not against forking this into Endo. We do that for Base64. We could harden the library. We would have recourse to fall through to native on XS if that becomes available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea enough to reify it as an issue:
I'll pursue other options in parallel, so it's not necessarily critical path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loadgen fixed with 58ff687
Downstream imports won't get the patch but they don't need it.