-
Notifications
You must be signed in to change notification settings - Fork 98
Add ability to produce a request ID from a request #74
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 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
755dd3a
Use a newtype for blobs
paulyoung e3bb174
Add ability to produce a request ID from a request
paulyoung 9098bf0
Add default.nix for building within the directory
paulyoung 749d0f4
Try regenerating package-lock.json to fix CI
paulyoung 878afdd
Remove commented out canister ID implementation
paulyoung ce75067
Remove commented out import
paulyoung 8d15809
Clarify that request ID tests are from the spec
paulyoung 460c77d
Regenerate package-lock.json again to fix napalm
paulyoung 998c383
Merge branch 'master' into paulyoung/js-user-library-request-id
paulyoung acb4339
Reword comment about nonce since it matches spec
paulyoung 5aa229a
Add TODO instead of commenting out request fields
paulyoung 4ad5cc0
Rename "rest" to "fields" for clarity
paulyoung 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,7 +1,14 @@ | ||
| module.exports = { | ||
| bail: false, | ||
| setupFiles: [ | ||
| "./test-setup", | ||
| ], | ||
| setupFilesAfterEnv: [ | ||
| "jest-expect-message", | ||
| ], | ||
| testEnvironment: "jsdom" | ||
| testEnvironment: "jsdom", | ||
| testPathIgnorePatterns: [ | ||
| "/node_modules/", | ||
| "/out/", | ||
| ] | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,10 +1,14 @@ | ||
| import { Buffer } from "buffer/"; | ||
| import { Hex } from "./hex"; | ||
|
|
||
| export const fromHex = (hex: Hex): Uint8Array => { | ||
| return new Uint8Array(Buffer.from(hex, "hex").buffer); | ||
| // Named `BinaryBlob` as opposed to `Blob` so not to conflict with | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/Blob | ||
| export type BinaryBlob = Uint8Array & { __blob__: void }; | ||
|
|
||
| export const fromHex = (hex: Hex): BinaryBlob => { | ||
| return new Uint8Array(Buffer.from(hex, "hex").buffer) as BinaryBlob; | ||
| }; | ||
|
|
||
| export const toHex = (blob: Uint8Array): string => { | ||
| export const toHex = (blob: BinaryBlob): string => { | ||
| return Buffer.from(blob).toString("hex"); | ||
| }; | ||
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { Hex } from "./hex"; | ||
| import { Int } from "./int"; | ||
| import * as int from "./int"; | ||
|
|
||
| // FIXME | ||
| // The current implementation of the client expects canister IDs to be | ||
| // represented as u64. This `Int` type will not be sufficient for u64 but may be | ||
| // good enough for now. | ||
|
|
||
| // export type CanisterId = BinaryBlob & { __canisterId__: void }; | ||
| export type CanisterId = Int & { __canisterId__: void }; | ||
|
|
||
| // export const fromHex = (hex: Hex): CanisterId => { | ||
|
paulyoung marked this conversation as resolved.
Outdated
|
||
| // return blob.fromHex(hex) as CanisterId; | ||
| // }; | ||
| export const fromHex = (hex: Hex): CanisterId => int.fromHex(hex) as CanisterId; | ||
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 +1,7 @@ | ||
| import { Hex } from "./hex"; | ||
|
|
||
| export type Int = number & { __int__: void }; | ||
|
|
||
| export const fromHex = (hex: Hex) => parseInt(hex, 16); | ||
|
|
||
| export const toHex = (int: Int): Hex => int.toString(16) as Hex; |
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // The types of values allowed in the `request_type` field for read requests. | ||
| export enum ReadRequestType { | ||
| Query = "query", | ||
| RequestStatus = "request-status", | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { BinaryBlob } from "./blob"; | ||
| import { RequestType } from "./requestType"; | ||
|
|
||
| // Common request fields. | ||
| export interface Request extends Record<string, any> { | ||
| request_type: RequestType; | ||
| // expiry?:; | ||
|
paulyoung marked this conversation as resolved.
Outdated
|
||
| // NOTE: `nonce` is optional in the spec, but we provide it so that requests | ||
| // are unique and we avoid a bug in the client when the same request is | ||
| // submitted more than once: https://dfinity.atlassian.net/browse/DFN-895 | ||
| nonce?: BinaryBlob; | ||
|
Contributor
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. 👍 |
||
| // sender:; | ||
| sender_pubkey: BinaryBlob; | ||
| sender_sig: BinaryBlob; | ||
| } | ||
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.
Interesting -- thanks Paul!
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.
This is where I first read about this approach: microsoft/TypeScript#25709 (comment)