Skip to content

Commit

Permalink
feat: adding tap endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
asafs932 committed Sep 5, 2023
1 parent 48e9ca1 commit 9773132
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 2 deletions.
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)
*/
public async getTapActivePolicy(): Promise<TAP.PolicyAndValidationResponse> {
return await this.apiClient.issueGetRequest(`/v1/tap/active_policy`);
}

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

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

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

/**
* Publish rules (TAP)
* @param rules
*/
public async publishTapRules(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;
}
}

0 comments on commit 9773132

Please sign in to comment.