-
Notifications
You must be signed in to change notification settings - Fork 19
Fixes/partner reviews #49
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ee1a93
ft: replace node:crypto with globalThis.crypto
Pradeep-selva 4f17e82
rf: typw fixes
Pradeep-selva 7bb9d85
rf: remove logs
Pradeep-selva a295e58
rf: comments
Pradeep-selva 056fdc1
bg: fix hmac sig
Pradeep-selva 87d4ba4
version: 1.0.3
Pradeep-selva ee892e8
Merge remote-tracking branch 'origin' into fixes/partner-reviews
Pradeep-selva 27de690
ft: enforce node >=20.10; bump version: 1.0.4
Pradeep-selva 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
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
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
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
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
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,35 +1,51 @@ | ||
| import crypto from "node:crypto"; | ||
|
|
||
| function replaceAll(s: string, search: string, replace: string) { | ||
| return s.split(search).join(replace); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the canonical Polymarket CLOB HMAC signature | ||
| * @param signer | ||
| * @param key | ||
| * @param secret | ||
| * @param passphrase | ||
| * @param timestamp | ||
| * @param method | ||
| * @param requestPath | ||
| * @param body | ||
| * @returns string | ||
| */ | ||
| export const buildPolyHmacSignature = ( | ||
| export const buildPolyHmacSignature = async ( | ||
| secret: string, | ||
| timestamp: number, | ||
| method: string, | ||
| requestPath: string, | ||
| body?: string, | ||
| ): string => { | ||
| ): Promise<string> => { | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| let message = timestamp + method + requestPath; | ||
| if (body !== undefined) { | ||
| message += body; | ||
| } | ||
| const base64Secret = Buffer.from(secret, "base64"); | ||
| const hmac = crypto.createHmac("sha256", base64Secret); | ||
| const sig = hmac.update(message).digest("base64"); | ||
|
|
||
| const binarySecret = atob(secret); | ||
| const keyBytes = new Uint8Array(binarySecret.length); | ||
| for (let i = 0; i < binarySecret.length; i++) { | ||
| keyBytes[i] = binarySecret.charCodeAt(i); | ||
| } | ||
|
|
||
| const key = await globalThis.crypto.subtle.importKey( | ||
| "raw", | ||
| keyBytes, | ||
| { name: "HMAC", hash: "SHA-256" }, | ||
| false, | ||
| ["sign"], | ||
| ); | ||
|
|
||
| const sigBuffer = await globalThis.crypto.subtle.sign( | ||
| "HMAC", | ||
| key, | ||
| new TextEncoder().encode(message), | ||
| ); | ||
|
|
||
| const sigBytes = new Uint8Array(sigBuffer); | ||
| let binary = ""; | ||
| for (let i = 0; i < sigBytes.length; i++) { | ||
| binary += String.fromCharCode(sigBytes[i]); | ||
| } | ||
| // NOTE: Must be url safe base64 encoding, but keep base64 "=" suffix | ||
| // Convert '+' to '-' | ||
| // Convert '/' to '_' | ||
| const sigUrlSafe = replaceAll(replaceAll(sig, "+", "-"), "/", "_"); | ||
| return sigUrlSafe; | ||
| return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_"); | ||
| }; | ||
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.