-
Notifications
You must be signed in to change notification settings - Fork 18
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
Chore: tidy v4 exports #278
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cced075
refactor: shift context constants into 4.0
phanshiyu d7fafc8
refactor: bring context down to root of 4.0
phanshiyu b387af1
refactor: add custom error class, change algorithm to non enum
phanshiyu 9585033
refactor: only leave the bare essentials of v4 in root index, fix tests
phanshiyu ddf4ccd
refactor: free up 4.0 from the mess of dependencies caused by importi…
phanshiyu a28d158
fix: circular dependency caused by getData
phanshiyu 4497ae2
feat: v4 utility guards
phanshiyu f2a636f
feat: export v4
phanshiyu 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,7 @@ | ||
import { unsaltData } from "./salt"; | ||
import { OpenAttestationDocument, WrappedDocument } from "./types"; | ||
|
||
type Extract<P> = P extends WrappedDocument<infer T> ? T : never; | ||
export const getData = <T extends WrappedDocument<OpenAttestationDocument>>(document: T): Extract<T> => { | ||
return unsaltData(document.data); | ||
}; |
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
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
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,6 @@ | ||
export * from "./wrap"; | ||
export * from "./sign"; | ||
export * from "./obfuscate"; | ||
export * from "./verify"; | ||
export * from "./utils"; | ||
export * from "./types"; |
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 @@ | ||
export { obfuscateVerifiableCredential as obfuscate, obfuscateErrors } from "../obfuscate"; |
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 @@ | ||
export { signDocument, signDocumentErrors } from "../sign"; |
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,5 @@ | ||
export type { | ||
V4Document as Document, | ||
V4WrappedDocument as WrappedDocument, | ||
V4SignedWrappedDocument as SignedWrappedDocument, | ||
} from "../types"; |
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 @@ | ||
export { v4Diagnose as diagnose } from "../diagnose"; | ||
export { | ||
isV4Document as isDocument, | ||
isV4WrappedDocument as isWrappedDocument, | ||
isV4SignedWrappedDocument as isSignedWrappedDocument, | ||
} from "../types"; |
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 @@ | ||
export { verify } from "../verify"; |
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 @@ | ||
export { wrapDocument, wrapDocuments, wrapDocumentErrors } from "../wrap"; |
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 |
---|---|---|
@@ -1,24 +1,41 @@ | ||
import { sign } from "../shared/signer"; | ||
import { SigningKey, SUPPORTED_SIGNING_ALGORITHM } from "../shared/@types/sign"; | ||
import { SigningKey } from "../shared/@types/sign"; | ||
import { ethers } from "ethers"; | ||
import { V4Document, V4WrappedDocument, V4SignedWrappedDocument } from "./types"; | ||
import type { ZodError } from "zod"; | ||
|
||
export const signDocument = async <T extends V4Document>( | ||
document: V4SignedWrappedDocument<T> | V4WrappedDocument<T>, | ||
algorithm: SUPPORTED_SIGNING_ALGORITHM, | ||
algorithm: "Secp256k1VerificationKey2018", | ||
keyOrSigner: SigningKey | ethers.Signer | ||
): Promise<V4SignedWrappedDocument<T>> => { | ||
const parsedResults = V4WrappedDocument.pick({ proof: true }).passthrough().safeParse(document); | ||
if (!parsedResults.success) { | ||
throw new Error("Document has not been properly wrapped " + JSON.stringify(parsedResults.error)); | ||
throw new WrappedDocumentValidationError(parsedResults.error); | ||
} | ||
|
||
if (!SigningKey.guard(keyOrSigner) && keyOrSigner.signMessage === undefined) { | ||
throw new Error(`Either a keypair or ethers.js Signer must be provided`); | ||
} | ||
|
||
const { proof: validatedProof } = parsedResults.data; | ||
const merkleRoot = `0x${validatedProof.merkleRoot}`; | ||
const signature = await sign(algorithm, merkleRoot, keyOrSigner); | ||
const proof: V4SignedWrappedDocument["proof"] = { | ||
...validatedProof, | ||
key: SigningKey.guard(keyOrSigner) ? keyOrSigner.public : `did:ethr:${await keyOrSigner.getAddress()}#controller`, | ||
key: "public" in keyOrSigner ? keyOrSigner.public : `did:ethr:${await keyOrSigner.getAddress()}#controller`, | ||
signature, | ||
}; | ||
return { ...document, proof }; | ||
}; | ||
|
||
class WrappedDocumentValidationError extends Error { | ||
constructor(public error: ZodError) { | ||
super(`Document has not been properly wrapped: \n ${JSON.stringify(error.format(), null, 2)}`); | ||
Object.setPrototypeOf(this, WrappedDocumentValidationError.prototype); | ||
} | ||
} | ||
|
||
export const signDocumentErrors = { | ||
WrappedDocumentValidationError, | ||
}; |
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 was deleted.
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
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
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.
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.
Something small:
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.
my bad, will fix HAHA