-
Notifications
You must be signed in to change notification settings - Fork 18
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
62 changed files
with
1,808 additions
and
647 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
API_PUBLIC_KEY="<Turnkey API Public Key (that starts with 02 or 03)>" | ||
API_PRIVATE_KEY="<Turnkey API Private Key>" | ||
BASE_URL="https://api.turnkey.com" | ||
ORGANIZATION_ID="<Turnkey organization ID>" |
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 @@ | ||
# Kitchen Sink | ||
|
||
A playground and example bank for making Turnkey requests in various ways: | ||
|
||
- `src/http`: create Turnkey requests in the most primitive way, using `@turnkey/http` and a stamper (e.g. `@turnkey/api-key-stamper`) | ||
- `src/sdk-server`: create Turnkey requests using `@turnkey/sdk-server`, which abstracts away some of the internals in the above method | ||
- 🚧 WIP `src/sdk-browser`: create Turnkey requests using `@turnkey/sdk-browser`, which also abstracts away some of the internals from the `@turnkey/http` approach. Note that `@turnkey/sdk-browser` has an interface identical to `@turnkey/sdk-server` |
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 @@ | ||
{ | ||
"name": "@turnkey/kitchen-sink", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"start-sdk-server": "tsx sdkServerClient.ts", | ||
"start-http": "tsx httpClient.ts", | ||
"clean": "rimraf ./dist ./.cache", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@turnkey/http": "workspace:*", | ||
"@turnkey/api-key-stamper": "workspace:*", | ||
"@turnkey/sdk-server": "workspace:*", | ||
"@turnkey/sdk-react": "workspace:*", | ||
"@turnkey/sdk-browser": "workspace:*", | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
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,68 @@ | ||
import * as path from "path"; | ||
import * as dotenv from "dotenv"; | ||
|
||
// Load environment variables from `.env.local` | ||
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") }); | ||
|
||
import { TurnkeyClient, createActivityPoller } from "@turnkey/http"; | ||
import { ApiKeyStamper } from "@turnkey/api-key-stamper"; | ||
import { refineNonNull } from "../utils"; | ||
|
||
async function main() { | ||
console.log("creating a new private key on Turnkey...\n"); | ||
|
||
const turnkeyClient = new TurnkeyClient( | ||
{ baseUrl: process.env.BASE_URL! }, | ||
new ApiKeyStamper({ | ||
apiPublicKey: process.env.API_PUBLIC_KEY!, | ||
apiPrivateKey: process.env.API_PRIVATE_KEY!, | ||
}) | ||
); | ||
|
||
const activityPoller = createActivityPoller({ | ||
client: turnkeyClient, | ||
requestFn: turnkeyClient.createApiKeys, | ||
}); | ||
|
||
const userId = "<user id>"; | ||
const apiKeyName = "<API key name>"; | ||
const publicKey = "<API public key>"; | ||
const curveType = "API_KEY_CURVE_P256"; // this is the default | ||
|
||
const activity = await activityPoller({ | ||
type: "ACTIVITY_TYPE_CREATE_API_KEYS_V2", | ||
organizationId: process.env.ORGANIZATION_ID!, | ||
parameters: { | ||
userId, | ||
apiKeys: [ | ||
{ | ||
apiKeyName, | ||
publicKey, | ||
curveType, | ||
}, | ||
], | ||
}, | ||
timestampMs: String(Date.now()), // millisecond timestamp | ||
}); | ||
|
||
const newApiKeyIds = refineNonNull( | ||
activity.result.createApiKeysResult?.apiKeyIds | ||
); | ||
|
||
// Success! | ||
console.log( | ||
[ | ||
`New API key created!`, | ||
`- ID: ${newApiKeyIds[0]}`, | ||
`- Public Key: ${publicKey}`, | ||
`- Name: ${apiKeyName}`, | ||
`- User ID: ${userId}`, | ||
``, | ||
].join("\n") | ||
); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
69 changes: 69 additions & 0 deletions
69
examples/kitchen-sink/src/http/createEthereumPrivateKey.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,69 @@ | ||
import * as path from "path"; | ||
import * as dotenv from "dotenv"; | ||
|
||
// Load environment variables from `.env.local` | ||
dotenv.config({ path: path.resolve(process.cwd(), ".env.local") }); | ||
|
||
import { TurnkeyClient } from "@turnkey/http"; | ||
import { createActivityPoller } from "@turnkey/http"; | ||
import { ApiKeyStamper } from "@turnkey/api-key-stamper"; | ||
import * as crypto from "crypto"; | ||
import { refineNonNull } from "../utils"; | ||
|
||
async function main() { | ||
console.log("creating a new private key on Turnkey...\n"); | ||
|
||
const turnkeyClient = new TurnkeyClient( | ||
{ baseUrl: process.env.BASE_URL! }, | ||
new ApiKeyStamper({ | ||
apiPublicKey: process.env.API_PUBLIC_KEY!, | ||
apiPrivateKey: process.env.API_PRIVATE_KEY!, | ||
}) | ||
); | ||
|
||
const activityPoller = createActivityPoller({ | ||
client: turnkeyClient, | ||
requestFn: turnkeyClient.createPrivateKeys, | ||
}); | ||
|
||
const privateKeyName = `ETH Key ${crypto.randomBytes(2).toString("hex")}`; | ||
|
||
const activity = await activityPoller({ | ||
type: "ACTIVITY_TYPE_CREATE_PRIVATE_KEYS_V2", | ||
organizationId: process.env.ORGANIZATION_ID!, | ||
parameters: { | ||
privateKeys: [ | ||
{ | ||
privateKeyName, | ||
curve: "CURVE_SECP256K1", | ||
addressFormats: ["ADDRESS_FORMAT_ETHEREUM"], | ||
privateKeyTags: [], | ||
}, | ||
], | ||
}, | ||
timestampMs: String(Date.now()), // millisecond timestamp | ||
}); | ||
|
||
const privateKeys = refineNonNull( | ||
activity.result.createPrivateKeysResultV2?.privateKeys | ||
); | ||
const privateKeyId = refineNonNull(privateKeys?.[0]?.privateKeyId); | ||
const address = refineNonNull(privateKeys?.[0]?.addresses?.[0]?.address); | ||
|
||
// Success! | ||
console.log( | ||
[ | ||
`New Ethereum private key created!`, | ||
`- Name: ${privateKeyName}`, | ||
`- Private key ID: ${privateKeyId}`, | ||
`- Address: ${address}`, | ||
``, | ||
"Now you can take the private key ID, put it in `.env.local`, then re-run the script.", | ||
].join("\n") | ||
); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.