-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
261 additions
and
330 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
API_PUBLIC_KEY="<Turnkey API Public Key (that starts with 02 or 03)>" | ||
API_PRIVATE_KEY="<Turnkey API Private Key>" | ||
NEXT_PUBLIC_ORGANIZATION_ID="<Turnkey organization ID>" | ||
NEXT_PUBLIC_BASE_URL="https://api.turnkey.com" | ||
NEXT_PUBLIC_BASE_URL="https://api.turnkey.com" | ||
NEXT_PUBLIC_RPID="localhost" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type CreateSubOrgResponse = { | ||
subOrgId: string; | ||
wallet: TFormattedWallet; | ||
}; | ||
|
||
export type GetWalletRequest = { | ||
organizationId: string; | ||
}; | ||
|
||
export type TFormattedWallet = { | ||
id: string; | ||
name: string; | ||
accounts: TFormattedWalletAccount[]; | ||
}; | ||
|
||
export type TFormattedWalletAccount = { | ||
address: string; | ||
path: string; | ||
}; |
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
72 changes: 0 additions & 72 deletions
72
examples/with-federated-passkeys/src/pages/api/getPrivateKeys.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
examples/with-federated-passkeys/src/pages/api/getWallet.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,59 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { TurnkeyApiTypes, TurnkeyClient } from "@turnkey/http"; | ||
import { ApiKeyStamper } from "@turnkey/api-key-stamper"; | ||
import { GetWalletRequest, TFormattedWallet } from "@/app/types"; | ||
|
||
type TWalletAccount = TurnkeyApiTypes["v1WalletAccount"]; | ||
|
||
type ErrorMessage = { | ||
message: string; | ||
}; | ||
|
||
// This can be performed by the parent org since parent orgs have read-only access to all their sub-orgs | ||
export default async function getWallet( | ||
req: NextApiRequest, | ||
res: NextApiResponse<TFormattedWallet | ErrorMessage> | ||
) { | ||
const getWalletRequest = req.body as GetWalletRequest; | ||
|
||
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 = getWalletRequest.organizationId; | ||
|
||
try { | ||
const walletsResponse = await turnkeyClient.getWallets({ | ||
organizationId, | ||
}); | ||
const accountsResponse = await turnkeyClient.getWalletAccounts({ | ||
organizationId: organizationId, | ||
walletId: walletsResponse.wallets[0].walletId, | ||
}); | ||
|
||
const accounts = accountsResponse.accounts.map((acc: TWalletAccount) => { | ||
return { | ||
address: acc.address, | ||
path: acc.path, | ||
}; | ||
}); | ||
|
||
res.status(200).json({ | ||
id: walletsResponse.wallets[0].walletId, | ||
name: walletsResponse.wallets[0].walletName, | ||
accounts: accounts, | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
|
||
res.status(500).json({ | ||
message: "Something went wrong.", | ||
}); | ||
} | ||
|
||
res.json; | ||
} |
Oops, something went wrong.