Skip to content
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

Merging Process #1 from sd-jwt-ts #60

Merged
merged 25 commits into from
Feb 14, 2024

Conversation

lukasjhan
Copy link
Member

I'm working on merging with https://github.com/berendsliedrecht/sd-jwt-ts which is berend's work.
Due to the huge PR, I'm going to add sd-jwt-vc & splitting into multiple package in next PR.

What's included

  • Remove jose
  • Remove node, broswer crypto dependencies
  • Include pure js base64 package
  • refactor interface for crypto function injection. (mostly followed from sd-jwt-ts package)
  • Include pure js sha256 function from '@noble/hash'
  • Fix tests & examples
  • Remove default instance in index.ts

Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
@@ -33,11 +33,13 @@
"@types/jest": "^29.5.11",
"@types/node": "^20.10.2",
"jest": "^29.7.0",
"jose": "^5.1.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jose is here for testing purpose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's devdependencies

Comment on lines 42 to +49
export type Signer = (data: string) => OrPromise<string>;
export type Verifier = (data: string, sig: string) => OrPromise<boolean>;
export type Hasher = (data: string) => Promise<string>;
export type SaltGenerator = (length: number) => string;
export type Hasher = (data: string, alg: string) => OrPromise<Uint8Array>;
export type SaltGenerator = (length: number) => OrPromise<string>;
export type HasherAndAlg = {
hasher: Hasher;
alg: string;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly I followed the type from sd-jwt-ts

Signed-off-by: Lukas.J.Han <[email protected]>
Copy link
Contributor

@berendsliedrecht berendsliedrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to get a bit more familiar with the code base but these seem like good changes! Some minor code style comments only.

"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.3.2"
},
"dependencies": {
"jose": "^5.1.3"
"@noble/hashes": "1.0.0",
"js-base64": "^3.7.6"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! Better solution IMO compared to using buffer.

src/base64url.ts Outdated
Comment on lines 5 to 7
const decode = (input: string): string => {
return Base64.decode(input);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const decode = (input: string): string => {
return Base64.decode(input);
};
const decode = (input: string): string => Base64.decode(input);

Can also do const decode = Base64.decode; but there might be some overloading that we do not want to re-expose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. But this was created for consistency in case anyone gets confused with base64.

I think it can be reduced a bit by not wrapping it in a Base64Url object. Please check the change and tell me what you think :) @berendsliedrecht

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good!

src/index.ts Outdated
if (!this.userConfig.kbSigner) {
throw new SDJWTException('Key Binding Signer not found');
}
if (!this.userConfig.kb_sign_alg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the casing of this.userConfig.kb_sign_alg different?

src/index.ts Outdated
throw new SDJWTException('SaltGenerator not found');
}

if (!this.userConfig.sign_alg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here re the casing.

disclosureFrame?: DisclosureFrame<T>,
hasher: Hasher = hash,
saltGenerator: SaltGenerator = generateSalt,
disclosureFrame: DisclosureFrame<T> | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
disclosureFrame: DisclosureFrame<T> | undefined,
disclosureFrame?: DisclosureFrame<T>,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be optional because its not the last parameter.

@lukasjhan
Copy link
Member Author

in sha256 function the text to uint8array method only works in ASCII char. we should find another way to convert.

@lukasjhan
Copy link
Member Author

in sha256 function the text to uint8array method only works in ASCII char. we should find another way to convert.

I fixed the issue

zustkeeper
zustkeeper previously approved these changes Feb 14, 2024
expect(s1).toStrictEqual(s2);
});

test('test#13', async () => {
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasjhan lukasjhan merged commit dcb76ce into openwallet-foundation-labs:main Feb 14, 2024
2 checks passed
cre8 pushed a commit to cre8/sd-jwt-js that referenced this pull request Mar 8, 2024
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
cre8 pushed a commit that referenced this pull request Mar 8, 2024
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Lukas <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants