-
Notifications
You must be signed in to change notification settings - Fork 15
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
CreateSubOrgV3 #107
Merged
Merged
CreateSubOrgV3 #107
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
update federated passkeys demo
- Loading branch information
commit eb2d64011114324c6833855c22bfed47f6eaca95
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
51 changes: 51 additions & 0 deletions
51
examples/with-federated-passkeys/src/pages/api/getActivity.ts
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,51 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { TurnkeyApiTypes, TurnkeyClient } from "@turnkey/http"; | ||
import { ApiKeyStamper } from "@turnkey/api-key-stamper"; | ||
|
||
type TActivityResponse = TurnkeyApiTypes["v1ActivityResponse"]; | ||
|
||
type GetActivityRequest = { | ||
organizationId: string; | ||
activityId: string; | ||
}; | ||
|
||
type ErrorMessage = { | ||
message: string; | ||
}; | ||
|
||
// this getter can be performed by the parent org | ||
export default async function getActivity( | ||
req: NextApiRequest, | ||
res: NextApiResponse<TActivityResponse | ErrorMessage> | ||
) { | ||
const getActivityRequest = req.body as GetActivityRequest; | ||
|
||
const turnkeyClient = new TurnkeyClient( | ||
{ baseUrl: process.env.NEXT_PUBLIC_BASE_URL! }, | ||
new ApiKeyStamper({ | ||
apiPublicKey: process.env.API_PUBLIC_KEY!, | ||
apiPrivateKey: process.env.API_PRIVATE_KEY!, | ||
}) | ||
); | ||
|
||
const { organizationId, activityId } = getActivityRequest; | ||
|
||
try { | ||
const activityResponse = await turnkeyClient.getActivity({ | ||
organizationId, | ||
activityId, | ||
}); | ||
|
||
res.status(200).json({ | ||
activity: activityResponse.activity, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
res.status(500).json({ | ||
message: "Something went wrong.", | ||
}); | ||
} | ||
|
||
res.json; | ||
} |
72 changes: 72 additions & 0 deletions
72
examples/with-federated-passkeys/src/pages/api/getPrivateKeys.ts
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,72 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { TurnkeyApiTypes, TurnkeyClient } from "@turnkey/http"; | ||
import { ApiKeyStamper } from "@turnkey/api-key-stamper"; | ||
|
||
type TPrivateKey = TurnkeyApiTypes["v1PrivateKey"]; | ||
|
||
type TFormattedPrivateKey = { | ||
privateKeyId: string; | ||
privateKeyName: string; | ||
privateKeyAddress: string; | ||
}; | ||
|
||
type GetPrivateKeysRequest = { | ||
organizationId: string; | ||
}; | ||
|
||
type GetPrivateKeysResponse = { | ||
privateKeys: TFormattedPrivateKey[]; | ||
}; | ||
|
||
type ErrorMessage = { | ||
message: string; | ||
}; | ||
|
||
// This getter _can_ be performed by the parent org | ||
export default async function getPrivateKeys( | ||
req: NextApiRequest, | ||
res: NextApiResponse<GetPrivateKeysResponse | ErrorMessage> | ||
) { | ||
const getPrivateKeysRequest = req.body as GetPrivateKeysRequest; | ||
|
||
const turnkeyClient = new TurnkeyClient( | ||
{ baseUrl: process.env.NEXT_PUBLIC_BASE_URL! }, | ||
new ApiKeyStamper({ | ||
apiPublicKey: process.env.API_PUBLIC_KEY!, | ||
apiPrivateKey: process.env.API_PRIVATE_KEY!, | ||
}) | ||
); | ||
|
||
const organizationId = getPrivateKeysRequest.organizationId; | ||
|
||
try { | ||
const privateKeysResponse = await turnkeyClient.getPrivateKeys({ | ||
organizationId, | ||
}); | ||
|
||
// By default, the API will return private keys in descending order of create date. | ||
// We reverse it here, so that visually the most recently created private keys will be | ||
// added to the bottom of the list instead of the top. | ||
const privateKeys = privateKeysResponse.privateKeys | ||
.reverse() | ||
emostov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.map((pk: TPrivateKey) => { | ||
return { | ||
privateKeyId: pk.privateKeyId!, | ||
privateKeyName: pk.privateKeyName!, | ||
privateKeyAddress: pk.addresses[0].address!, | ||
}; | ||
}); | ||
|
||
res.status(200).json({ | ||
privateKeys, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
res.status(500).json({ | ||
message: "Something went wrong.", | ||
}); | ||
} | ||
|
||
res.json; | ||
} |
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.
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.
interpolate e?
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.
will leave it out and just handle on the server side for now. don't feel too strongly either way 🤷