Skip to content
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

TAP Endpoints #207

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ import {
UsersGroup,
ContractUploadRequest,
ContractTemplateDto,
PendingTokenLinkDto, Web3ConnectionFeeLevel,
PendingTokenLinkDto,
Web3ConnectionFeeLevel,
TAP,
} from "./types";
import { AxiosProxyConfig, AxiosResponse } from "axios";
import { PIIEncryption } from "./pii-client";
Expand Down Expand Up @@ -1347,7 +1349,7 @@ export class FireblocksSDK {

return await this.apiClient.issuePostRequest(path, payload, requestOptions);
}

/**
* Approve or Reject the initiated connection
* @param type The type of the connection
Expand Down Expand Up @@ -1770,6 +1772,44 @@ export class FireblocksSDK {
return this.apiClient.issueDeleteRequest(`/v1/smart-transfers/${ticketId}/terms/${termId}`);
}

/**
* Get active policy (TAP) [BETA]
*/
public async getActivePolicy(): Promise<TAP.PolicyAndValidationResponse> {
return await this.apiClient.issueGetRequest(`/v1/tap/active_policy`);
}

/**
* Get draft policy (TAP) [BETA]
*/
public async getDraft(): Promise<TAP.DraftReviewAndValidationResponse> {
return await this.apiClient.issueGetRequest(`/v1/tap/draft`);
}

/**
* Update draft policy (TAP) [BETA]
* @param rules
*/
public async updateDraft(rules: TAP.PolicyRule[]): Promise<TAP.DraftReviewAndValidationResponse> {
return await this.apiClient.issuePutRequest(`/v1/tap/draft`, { rules });
}

/**
* Publish draft policy (TAP) [BETA]
* @param draftId
*/
public async publishDraft(draftId: string): Promise<TAP.PublishResult> {
return await this.apiClient.issuePostRequest(`/v1/tap/draft`, { draftId });
}

/**
* Publish rules (TAP) [BETA]
* @param rules
*/
public async publishPolicyRules(rules: TAP.PolicyRule[]): Promise<TAP.PublishResult> {
return await this.apiClient.issuePostRequest(`/v1/tap/publish`, { rules });
}

private getCommaSeparatedList(items: Array<string>): string | undefined {
return items ? items.join(",") : undefined;
}
Expand Down
185 changes: 185 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,3 +1696,188 @@ export namespace NCW {
enabled: boolean;
}
}

export namespace TAP {
type PolicyTransactionType =
| "*"
| "CONTRACT_CALL"
| "RAW"
| "TRANSFER"
| "APPROVE"
| "MINT"
| "BURN"
| "SUPPLY"
| "REDEEM"
| "STAKE"
| "TYPED_MESSAGE";

type PolicySrcOrDestType =
| "EXCHANGE"
| "UNMANAGED"
| "VAULT"
| "NETWORK_CONNECTION"
| "COMPOUND"
| "FIAT_ACCOUNT"
| "ONE_TIME_ADDRESS"
| "*";

type PolicyType = "TRANSFER";

type PolicyAction = "ALLOW" | "BLOCK" | "2-TIER";

type PolicyDestAddressType = "*" | "WHITELISTED" | "ONE_TIME";

type PolicyAmountScope = "SINGLE_TX" | "TIMEFRAME";

type PolicySrcOrDestSubType = "*" | "EXTERNAL" | "INTERNAL" | "CONTRACT" | "EXCHANGETEST";

type PolicySrcOrDestId = string;

type AuthorizationGroup = {
users?: Array<string>;
usersGroups?: Array<string>;
th: number;
};

interface PolicyAuthorizationGroups {
logic: "AND" | "OR";
allowOperatorAsAuthorizer?: boolean;
groups: Array<AuthorizationGroup>;
}

export interface PolicyRule {
operator?: string;
operators?: {
wildcard?: "*";
users?: Array<string>;
usersGroups?: Array<string>;
services?: Array<string>;
};
transactionType?: PolicyTransactionType;
operatorServices?: Array<string>;
designatedSigner?: string;
designatedSigners?: {
users?: Array<string>;
usersGroups?: Array<string>;
};
type: PolicyType;
action: PolicyAction;
asset: string;
srcType?: PolicySrcOrDestType;
srcSubType?: PolicySrcOrDestSubType;
srcId?: PolicySrcOrDestId;
src?: {
ids?: Array<[PolicySrcOrDestId, PolicySrcOrDestType?, PolicySrcOrDestSubType?]>;
};
dstType?: PolicySrcOrDestType;
dstSubType?: PolicySrcOrDestSubType;
dstId?: PolicySrcOrDestId;
dst?: {
ids?: Array<[PolicySrcOrDestId, PolicySrcOrDestType?, PolicySrcOrDestSubType?]>;
};
dstAddressType?: PolicyDestAddressType;
amountCurrency: string;
amountScope: PolicyAmountScope;
amount: number | string;
periodSec: number;
authorizers?: Array<string>;
authorizersCount?: number;
authorizationGroups?: PolicyAuthorizationGroups;
amountAggregation?: {
operators: string;
srcTransferPeers: string;
dstTransferPeers: string;
};
rawMessageSigning?: {
derivationPath: {
path: Array<number>;
};
algorithm: string;
};
applyForApprove?: boolean;
applyForTypedMessage?: boolean;
externalDescriptor?: string;
}

interface Metadata {
editedBy?: string;
editedAt?: number;
publishedBy?: string;
publishedAt?: number;
}

enum PolicyStatus {
SUCCESS = "SUCCESS",
UNVALIDATED = "UNVALIDATED",
INVALID_CONFIGURATION = "INVALID_CONFIGURATION",
PENDING = "PENDING",
PENDING_CONSOLE_APPROVAL = "PENDING_CONSOLE_APPROVAL",
AWAITING_QUORUM = "AWAITING_QUORUM",
UNHANDLED_ERROR = "UNHANDLED_ERROR",
}

type PolicyBaseErrorField =
| "operator"
| "operators"
| "authorizationGroups"
| "designatedSigner"
| "designatedSigners"
| "contractMethods"
| "amountAggregation"
| "src"
| "dst"
| "";

interface PolicyRuleError {
errorMessage: string;
errorCodeName: string;
errorField: PolicyBaseErrorField;
errorCode: number;
}

interface PolicyRuleCheckResult {
index: number;
status: "ok" | "failure";
errors: Array<PolicyRuleError>;
}

interface PolicyCheckResult {
errors: number;
results: PolicyRuleCheckResult[];
}

interface PolicyResponse {
status?: string;
rules?: Array<PolicyRule>;
metadata?: Metadata;
}

interface ValidationResponse {
status?: PolicyStatus;
checkResult?: PolicyCheckResult;
}

interface DraftResponse {
draftId: string;
status?: PolicyStatus;
rules?: Array<PolicyRule>;
metadata?: Metadata;
}

export interface DraftReviewAndValidationResponse {
draftResponse: DraftResponse;
validation: ValidationResponse;
}

export interface PolicyAndValidationResponse {
policy: PolicyResponse;
validation: ValidationResponse;
}

export interface PublishResult {
status?: PolicyStatus;
rules?: Array<PolicyRule>;
checkResult?: PolicyCheckResult;
metadata?: Metadata;
}
}