-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Use the SHA-256 implementation built into JavaScript engines #7361
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@solana/spl-type-length-value", | ||
"description": "SPL Type Length Value Library", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Solana Labs Maintainers <[email protected]>", | ||
"repository": "https://github.com/solana-labs/solana-program-library", | ||
"license": "Apache-2.0", | ||
|
@@ -43,6 +43,7 @@ | |
"watch": "tsc --build --verbose --watch tsconfig.all.json" | ||
}, | ||
"dependencies": { | ||
"@solana/assertions": "^2.0.0-rc.1", | ||
"buffer": "^6.0.3" | ||
}, | ||
"devDependencies": { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||
import { createHash } from 'crypto'; | ||||||||||||||||||||||||||||||||||||||||
import { assertDigestCapabilityIsAvailable } from '@solana/assertions'; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
export const splDiscriminate = (discriminator: string, length = 8): Buffer => { | ||||||||||||||||||||||||||||||||||||||||
const digest = createHash('sha256').update(discriminator).digest(); | ||||||||||||||||||||||||||||||||||||||||
return digest.subarray(0, length); | ||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||
export async function splDiscriminate(discriminator: string, length = 8): Promise<Uint8Array> { | ||||||||||||||||||||||||||||||||||||||||
assertDigestCapabilityIsAvailable(); | ||||||||||||||||||||||||||||||||||||||||
const bytes = new TextEncoder().encode(discriminator); | ||||||||||||||||||||||||||||||||||||||||
const digest = await crypto.subtle.digest('SHA-256', bytes); | ||||||||||||||||||||||||||||||||||||||||
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. Ugh. Our choices are:
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. I think we can keep it simple and elevate the requirement for this package to Node 19. Considering it'll become a dev dependency for the two packages that use it, I can't see any drawbacks. Are there any other potential negative consequences that I'm missing? 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. As part of that change, can you also update CI to only run the 'libraries' step for node v20? solana-program-library/.github/workflows/pull-request-js.yml Lines 43 to 61 in b1e526d
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. Totally. |
||||||||||||||||||||||||||||||||||||||||
return new Uint8Array(digest).subarray(0, length); | ||||||||||||||||||||||||||||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Breaking change.