-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
92 additions
and
47 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 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,11 @@ | ||
--- | ||
sidebar_position: 3 | ||
description: Fetching data from Turnkey | ||
slug: /api-design/queries | ||
--- | ||
|
||
# Queries | ||
|
||
Queries are read requests to Turnkey's API. Query URL paths are prefixed with `/public/v1/query`. Queries are not subject to enforcement of the policy engine. This means that there are currently no read permissions within an organization. All users within an organization can read any data within the organization. | ||
|
||
Additionally, parent organizations have the ability to query data for all of their child organizations. |
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,42 @@ | ||
--- | ||
sidebar_position: 2 | ||
description: Creating your first signed request | ||
slug: /api-design/stamps | ||
--- | ||
|
||
# Stamps | ||
|
||
Every request made to Turnkey must include a signature inside a stamp header. Our secure enclave applications use this signature to verify the integrity and authenticity of the request. | ||
|
||
### API Keys | ||
To create a valid, API key stamped request follow these steps: | ||
1. SHA256 hash the JSON-encoded POST body | ||
2. Sign the hash with your API key to produce a `signature` | ||
3. Create a JSON-encoded stamp: | ||
- `publicKey`: the public key of API key | ||
- `signature`: the signature produced by the API key | ||
- `scheme`: `SIGNATURE_SCHEME_TK_API_P256` | ||
4. Base64URL encode the stamp | ||
5. Add the encoded string to your request as a `X-Stamp` header | ||
|
||
### Webauthn | ||
To create a valid, Webauthn authenticator stamped request follow these steps: | ||
1. SHA256 hash the JSON-encoded POST body | ||
2. Sign the hash with WebAuthn credential. | ||
3. Create a JSON-encoded stamp: | ||
- `credentialId`: the id of the webauthn authenticator | ||
- `authenticatorData`: the authenticator data produced by Webauthn assertion | ||
- `clientDataJson`: the client data produced by the Webauthn assertion | ||
- `signature`: the signature produced by the Webauthn assertion | ||
4. Base64URL encode the stamp | ||
5. Add the encoded string to your request as a `X-Stamp-Webauthn` header | ||
|
||
### Stampers | ||
|
||
In practice, you should not have to worry about this step. Our [JS SDK](https://github.com/tkhq/sdk) and [CLI](https://github.com/tkhq/tkcli) take care of stamping for you. However, if you choose to use an independent client, you will need to implement this yourself. For reference, check out our implementations: | ||
- [API Key Stamper](https://github.com/tkhq/sdk/blob/main/packages/api-key-stamper) | ||
- [WebAuthn Stamper](https://github.com/tkhq/sdk/blob/main/packages/webauthn-stamper) | ||
- [React Native Stamper](https://github.com/tkhq/sdk/tree/main/packages/react-native-passkey-stamper) | ||
- [iFrame Stamper](https://github.com/tkhq/sdk/tree/main/packages/iframe-stamper) | ||
- [CLI](https://github.com/tkhq/tkcli/blob/main/src/cmd/turnkey/pkg/request.go) | ||
|
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,26 @@ | ||
--- | ||
sidebar_position: 4 | ||
description: Secure execution with Turnkey | ||
slug: /api-design/submissions | ||
--- | ||
|
||
# Submissions | ||
|
||
Submissions are requests to securely execute a workload. Submission URL paths are prefixed with `/public/v1/submit`. Submissions requests, if valid, produce an `Activity`. | ||
|
||
### Activites | ||
|
||
Activities typically create, modify, or utilize a resource within Turnkey and are subject to consensus or condition enforcement via the policy engine. Activities are executed optimistically synchronous. This means that if we can process the request synchronously, we will. Otherwise, we'll fallback to asynchronous processing. Your services or applications should account for this by checking the response for the activity state: | ||
|
||
- If `activity.state == ACTIVITY_STATUS_COMPLETED`, `activity.result` field will be populated. | ||
- If `activity.state == ACTIVITY_STATUS_FAILED`, `activity.failure` field will be populated (soon). | ||
- If `activity.state == ACTIVITY_STATUS_CONSENSUS_NEEDED`, additional signatures are required to process the request. | ||
- If `activity.state == ACTIVITY_STATUS_PENDING`, the request is processing asynchronously. | ||
|
||
You can get activity status updates by: | ||
- Re-submitting the request. See the notes on idempotency below. | ||
- Polling `get_activity` with the `activity.id` | ||
|
||
### Idempotency | ||
|
||
The submission API is idempotent. For each request, the POST body is hashed into a fingerprint. Any two requests with the same fingerprint are considered the same request. If you resubmit the request, you'll get the same activity. If you want a new activity, you should modify the request timestamp `timestampMs` to produce a new fingerprint. |