UNPKG

@wharfkit/transact-plugin-resource-provider

Version:

Plugin to automatically provide network resources for transactions using the Resource Provider implementation standard.

152 lines (149 loc) 5.62 kB
/** * @wharfkit/transact-plugin-resource-provider v1.1.2 * https://github.com/wharfkit/transact-plugin-resource-provider * * @license * Copyright (c) 2021 FFF00 Agents AB & Greymass Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistribution in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE * IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY. */ import { Struct, Name, Asset, AbstractTransactPlugin, TransactContext, ChainDefinition, SigningRequest, TransactHookResponse, Transaction, AssetType } from '@wharfkit/session'; interface ResourceProviderOptions { allowFees?: boolean; endpoints?: Record<string, string>; maxFee?: AssetType; } interface ResourceProviderResponseData { request: [string, object]; signatures: string[]; version: unknown; fee?: AssetType; costs?: { cpu: AssetType; net: AssetType; ram: AssetType; }; } interface ResourceProviderResponse { code: number; data: ResourceProviderResponseData; } declare class Transfer extends Struct { from: Name; to: Name; quantity: Asset; memo: string; } declare const defaultOptions: { endpoints: { aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906: string; '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d': string; '4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11': string; '1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4': string; }; }; declare class TransactPluginResourceProvider extends AbstractTransactPlugin { id: string; translations: { en: { timeout: string; "will-continue": string; fee: { title: string; body: string; cost: string; }; rejected: { "no-fees": string; "original-modified": string; "max-fee": string; }; }; ko: { timeout: string; "will-continue": string; fee: { title: string; body: string; cost: string; }; rejected: { "no-fees": string; "original-modified": string; "max-fee": string; }; }; 'zh-Hans': { timeout: string; "will-continue": string; fee: { title: string; body: string; cost: string; }; rejected: { "no-fees": string; "original-modified": string; "max-fee": string; }; }; 'zh-Hant': { timeout: string; "will-continue": string; fee: { title: string; body: string; cost: string; }; rejected: { "no-fees": string; "original-modified": string; "max-fee": string; }; }; }; readonly allowFees: boolean; readonly maxFee?: Asset; readonly endpoints: Record<string, string>; constructor(options?: ResourceProviderOptions); register(context: TransactContext): void; getEndpoint(chain: ChainDefinition): string; request(request: SigningRequest, context: TransactContext): Promise<TransactHookResponse>; getModifiedTransaction(json: any): Transaction; createRequest(response: ResourceProviderResponse, context: TransactContext): Promise<SigningRequest>; /** * Perform validation against the request to ensure it is valid for the resource provider. */ validateRequest(request: SigningRequest, context: TransactContext): void; /** * Perform validation against the response to ensure it is valid for the session. */ validateResponseData(response: Record<string, any>): Promise<void>; } export { TransactPluginResourceProvider, Transfer, defaultOptions };