-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add is-allowed API to JS, Python, and Go SDKs #221
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 1 commit
Commits
Show all changes
2 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
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
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { z } from "zod"; | ||
| import { defineAction } from "../../utils/define-action"; | ||
| import { IsAllowedResultSchema } from "../cvms/check_cvm_is_allowed"; | ||
|
|
||
| export const AppCvmsBatchIsAllowedResponseSchema = z.object({ | ||
| is_onchain: z.boolean(), | ||
| results: z.array(IsAllowedResultSchema.extend({ cvm_id: z.number() })).default([]), | ||
| total: z.number().default(0), | ||
| allowed_count: z.number().default(0), | ||
| denied_count: z.number().default(0), | ||
| error_count: z.number().default(0), | ||
| skipped_cvm_ids: z.array(z.number()).default([]), | ||
| }); | ||
|
|
||
| export type AppCvmsBatchIsAllowedResponse = z.infer<typeof AppCvmsBatchIsAllowedResponseSchema>; | ||
|
|
||
| export const CheckAppCvmsIsAllowedRequestSchema = z.object({ | ||
| appId: z.string().min(1), | ||
| }); | ||
|
|
||
| export type CheckAppCvmsIsAllowedRequest = z.infer<typeof CheckAppCvmsIsAllowedRequestSchema>; | ||
|
|
||
| /** | ||
| * Batch check on-chain deployment allowance for all CVMs under an app. | ||
| * | ||
| * For on-chain KMS apps, queries the blockchain via multicall3 to check | ||
| * compose hash and device allowance for each CVM. | ||
| * For offchain KMS apps, returns is_onchain=false with no results. | ||
| * | ||
| * @param client - The API client | ||
| * @param request - Request parameters | ||
| * @param request.appId - The hex app identifier | ||
| * @returns Batch allowance check results for all CVMs | ||
| */ | ||
| const { action: checkAppCvmsIsAllowed, safeAction: safeCheckAppCvmsIsAllowed } = defineAction< | ||
| CheckAppCvmsIsAllowedRequest, | ||
| typeof AppCvmsBatchIsAllowedResponseSchema, | ||
| AppCvmsBatchIsAllowedResponse | ||
| >(AppCvmsBatchIsAllowedResponseSchema, async (client, request) => { | ||
| const { appId } = CheckAppCvmsIsAllowedRequestSchema.parse(request); | ||
| return await client.post(`/apps/${appId}/cvms/is-allowed`, {}); | ||
| }); | ||
|
|
||
| export { checkAppCvmsIsAllowed, safeCheckAppCvmsIsAllowed }; |
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,38 @@ | ||
| import { z } from "zod"; | ||
| import { defineAction } from "../../utils/define-action"; | ||
| import { IsAllowedResultSchema, type IsAllowedResult } from "../cvms/check_cvm_is_allowed"; | ||
|
|
||
| export const CheckAppIsAllowedRequestSchema = z.object({ | ||
| appId: z.string().min(1), | ||
| compose_hash: z.string(), | ||
| node_id: z.number().optional(), | ||
| device_id: z.string().optional(), | ||
| chain_id: z.number().optional(), | ||
| }); | ||
|
|
||
| export type CheckAppIsAllowedRequest = z.infer<typeof CheckAppIsAllowedRequestSchema>; | ||
|
|
||
| /** | ||
| * Check if a deployment is allowed by an on-chain DStack App contract. | ||
| * | ||
| * Supports pure contract query (no DB) when all parameters including chain_id are provided. | ||
| * | ||
| * @param client - The API client | ||
| * @param request - Request parameters | ||
| * @param request.appId - App contract address | ||
| * @param request.compose_hash - Compose hash to check | ||
| * @param request.node_id - Node ID (resolves device_id from DB) | ||
| * @param request.device_id - Device ID (hex, direct) | ||
| * @param request.chain_id - Chain ID for RPC URL resolution | ||
| * @returns On-chain allowance check result | ||
| */ | ||
| const { action: checkAppIsAllowed, safeAction: safeCheckAppIsAllowed } = defineAction< | ||
| CheckAppIsAllowedRequest, | ||
| typeof IsAllowedResultSchema, | ||
| IsAllowedResult | ||
| >(IsAllowedResultSchema, async (client, request) => { | ||
| const { appId, ...body } = CheckAppIsAllowedRequestSchema.parse(request); | ||
| return await client.post(`/apps/${appId}/is-allowed`, body); | ||
| }); | ||
|
|
||
| export { checkAppIsAllowed, safeCheckAppIsAllowed }; |
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,50 @@ | ||
| import { z } from "zod"; | ||
| import { defineAction } from "../../utils/define-action"; | ||
| import { CvmIdSchema, type CvmIdInput } from "../../types/cvm_id"; | ||
|
|
||
| export const IsAllowedResultSchema = z.object({ | ||
| cvm_id: z.number().optional(), | ||
| app_contract_address: z.string(), | ||
| compose_hash: z.string(), | ||
| device_id: z.string(), | ||
| compose_hash_allowed: z.boolean(), | ||
| allow_any_device: z.boolean(), | ||
| device_id_allowed: z.boolean().nullable().optional(), | ||
| is_allowed: z.boolean(), | ||
| error: z.string().nullable().optional(), | ||
| }); | ||
|
|
||
| export type IsAllowedResult = z.infer<typeof IsAllowedResultSchema>; | ||
|
|
||
| const CheckCvmIsAllowedInputSchema = z.object({ | ||
| cvmId: z.string().min(1), | ||
| compose_hash: z.string().optional(), | ||
| node_id: z.number().optional(), | ||
| device_id: z.string().optional(), | ||
| }); | ||
|
|
||
| export const CheckCvmIsAllowedRequestSchema = CheckCvmIsAllowedInputSchema; | ||
|
|
||
| export type CheckCvmIsAllowedRequest = z.infer<typeof CheckCvmIsAllowedInputSchema>; | ||
|
|
||
| /** | ||
| * Check if a CVM deployment is allowed by its on-chain DStack App contract. | ||
| * | ||
| * @param client - The API client | ||
| * @param request - Request parameters | ||
| * @param request.cvmId - CVM identifier | ||
| * @param request.compose_hash - Optional compose hash override | ||
| * @param request.node_id - Optional node ID override (resolves device_id) | ||
| * @param request.device_id - Optional device ID override | ||
| * @returns On-chain allowance check result | ||
| */ | ||
| const { action: checkCvmIsAllowed, safeAction: safeCheckCvmIsAllowed } = defineAction< | ||
| CheckCvmIsAllowedRequest, | ||
| typeof IsAllowedResultSchema, | ||
| IsAllowedResult | ||
| >(IsAllowedResultSchema, async (client, request) => { | ||
| const { cvmId, ...body } = CheckCvmIsAllowedRequestSchema.parse(request); | ||
| return await client.post(`/cvms/${cvmId}/is-allowed`, body); | ||
| }); | ||
|
|
||
| export { checkCvmIsAllowed, safeCheckCvmIsAllowed }; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.