-
Notifications
You must be signed in to change notification settings - Fork 18
Merging Process #1 from sd-jwt-ts #60
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d55879c
Revert "fix: the bytes of the output of the hash function must be bas…
lukasjhan d611fa7
feat: migrate base64url
lukasjhan 061c3d2
fix: restore tests
lukasjhan c0abd2e
feat: fix decoy and disclosure
lukasjhan cf7784a
feat: fix digest of encoded disclosure
lukasjhan c17a886
chore: Apply prettier
lukasjhan 716b8c7
feat: Add test for utin8array encoding
lukasjhan 4c15ffc
feat: Remove jose in jwt sign and verify
lukasjhan b29e314
feat: Remove jose in types
lukasjhan 915278b
feat: Fix sdjwt tests
lukasjhan 837b193
feat: implement new interface
lukasjhan 9a375a8
feat: Fix e2e tests and type
lukasjhan 4f7337d
feat: Fix index tests
lukasjhan 2b2874d
refactor: using constant
lukasjhan da5b16e
feat: add tests for crypto functions
lukasjhan d6b1285
feat: Add default sha256 function
lukasjhan 4511026
feat: fix sign_alg, hash_alg config
lukasjhan 162585c
feat: fix examples
lukasjhan 0168470
doc: Add dependencies
lukasjhan ce0aacc
doc: add decoding example
lukasjhan 097c4a3
refactor: Remove base64 function overloading
lukasjhan 25d0ef0
refactor: unify variable convention
lukasjhan 613f4fe
Merge branch 'main' into dev/merge1
lukasjhan 3b34b0c
feat: Add utf8 encode function and tests
lukasjhan fa6e0d7
test: Remove dup test
lukasjhan 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 hidden or 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 |
---|---|---|
@@ -1,11 +1,40 @@ | ||
import { sha256 as nobleSha256 } from '@noble/hashes/sha256'; | ||
|
||
export const sha256 = (text: string): Uint8Array => { | ||
const uint8Array = new Uint8Array(text.length); | ||
|
||
for (let i = 0; i < text.length; i++) { | ||
uint8Array[i] = text.charCodeAt(i); | ||
} | ||
const uint8Array = toUTF8Array(text); | ||
const hashBytes = nobleSha256(uint8Array); | ||
return hashBytes; | ||
}; | ||
|
||
function toUTF8Array(str: string) { | ||
const utf8 = []; | ||
for (let i = 0; i < str.length; i++) { | ||
let charcode = str.charCodeAt(i); | ||
if (charcode < 0x80) utf8.push(charcode); | ||
else if (charcode < 0x800) { | ||
utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f)); | ||
} else if (charcode < 0xd800 || charcode >= 0xe000) { | ||
utf8.push( | ||
0xe0 | (charcode >> 12), | ||
0x80 | ((charcode >> 6) & 0x3f), | ||
0x80 | (charcode & 0x3f), | ||
); | ||
} | ||
// surrogate pair | ||
else { | ||
i++; | ||
// UTF-16 encodes 0x10000-0x10FFFF by | ||
// subtracting 0x10000 and splitting the | ||
// 20 bits of 0x0-0xFFFFF into two halves | ||
charcode = | ||
0x10000 + (((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff)); | ||
utf8.push( | ||
0xf0 | (charcode >> 18), | ||
0x80 | ((charcode >> 12) & 0x3f), | ||
0x80 | ((charcode >> 6) & 0x3f), | ||
0x80 | (charcode & 0x3f), | ||
); | ||
} | ||
} | ||
return new Uint8Array(utf8); | ||
} |
This file contains hidden or 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
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.
Isn't this a duplicate test with test#14?
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.
Yes It's dup. my mistake
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.
@berendsliedrecht removed.