diff --git a/src/fireblocks-sdk.ts b/src/fireblocks-sdk.ts index d62ec339..32126a33 100644 --- a/src/fireblocks-sdk.ts +++ b/src/fireblocks-sdk.ts @@ -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"; @@ -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 @@ -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 { + return await this.apiClient.issueGetRequest(`/v1/tap/active_policy`); + } + + /** + * Get draft policy (TAP) [BETA] + */ + public async getDraft(): Promise { + return await this.apiClient.issueGetRequest(`/v1/tap/draft`); + } + + /** + * Update draft policy (TAP) [BETA] + * @param rules + */ + public async updateDraft(rules: TAP.PolicyRule[]): Promise { + return await this.apiClient.issuePutRequest(`/v1/tap/draft`, { rules }); + } + + /** + * Publish draft policy (TAP) [BETA] + * @param draftId + */ + public async publishDraft(draftId: string): Promise { + return await this.apiClient.issuePostRequest(`/v1/tap/draft`, { draftId }); + } + + /** + * Publish rules (TAP) [BETA] + * @param rules + */ + public async publishPolicyRules(rules: TAP.PolicyRule[]): Promise { + return await this.apiClient.issuePostRequest(`/v1/tap/publish`, { rules }); + } + private getCommaSeparatedList(items: Array): string | undefined { return items ? items.join(",") : undefined; } diff --git a/src/types.ts b/src/types.ts index be3059db..5112870c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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; + usersGroups?: Array; + th: number; + }; + + interface PolicyAuthorizationGroups { + logic: "AND" | "OR"; + allowOperatorAsAuthorizer?: boolean; + groups: Array; + } + + export interface PolicyRule { + operator?: string; + operators?: { + wildcard?: "*"; + users?: Array; + usersGroups?: Array; + services?: Array; + }; + transactionType?: PolicyTransactionType; + operatorServices?: Array; + designatedSigner?: string; + designatedSigners?: { + users?: Array; + usersGroups?: Array; + }; + 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; + authorizersCount?: number; + authorizationGroups?: PolicyAuthorizationGroups; + amountAggregation?: { + operators: string; + srcTransferPeers: string; + dstTransferPeers: string; + }; + rawMessageSigning?: { + derivationPath: { + path: Array; + }; + 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; + } + + interface PolicyCheckResult { + errors: number; + results: PolicyRuleCheckResult[]; + } + + interface PolicyResponse { + status?: string; + rules?: Array; + metadata?: Metadata; + } + + interface ValidationResponse { + status?: PolicyStatus; + checkResult?: PolicyCheckResult; + } + + interface DraftResponse { + draftId: string; + status?: PolicyStatus; + rules?: Array; + metadata?: Metadata; + } + + export interface DraftReviewAndValidationResponse { + draftResponse: DraftResponse; + validation: ValidationResponse; + } + + export interface PolicyAndValidationResponse { + policy: PolicyResponse; + validation: ValidationResponse; + } + + export interface PublishResult { + status?: PolicyStatus; + rules?: Array; + checkResult?: PolicyCheckResult; + metadata?: Metadata; + } +}