github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/kat/src/lib/interfaces.ts (about)

     1  // Copyright © 2021 Kaleido, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // CONFIG INTERFACE
    16  
    17  export interface IConfig {
    18    port: number
    19    assetTrailInstanceID: string
    20    protocol: 'ethereum' | 'corda'
    21    apiGateway: {
    22      apiEndpoint: string
    23      auth?: {
    24        user: string
    25        password: string
    26      }
    27    }
    28    eventStreams: {
    29      wsEndpoint: string
    30      topic: string
    31      auth?: {
    32        user: string
    33        password: string
    34      }
    35      skipSetup?: boolean
    36      config?: {
    37        batchSize: number
    38        batchTimeoutMS: number
    39        blockedRetryDelaySec: number,
    40        errorHandling: 'skip' | 'block'
    41      }
    42    }
    43    ipfs: {
    44      apiEndpoint: string
    45      gatewayEndpoint: string
    46    }
    47    app2app: {
    48      socketIOEndpoint: string
    49      destinations: {
    50        kat: string
    51        client: string
    52      }
    53    }
    54    docExchange: {
    55      apiEndpoint: string
    56      socketIOEndpoint: string
    57      destination: string
    58    }
    59    appCredentials: {
    60      user: string
    61      password: string
    62    }
    63    mongodb: {
    64      connectionUrl: string
    65      databaseName: string
    66    }
    67  }
    68  
    69  // SETTINGS
    70  
    71  export interface ISettings {
    72    clientEvents: string[]
    73  }
    74  
    75  // STORED SUBSCRIPTION CONFIG
    76  
    77  export interface IStoredSubscriptions {
    78    [sub: string]: string;
    79  }
    80  
    81  // API GATEWAY INTERFACES
    82  
    83  export interface IAPIGatewayAsyncResponse {
    84    type: 'async'
    85    id: string
    86    msg: string
    87    sent: boolean
    88  }
    89  
    90  export interface IAPIGatewaySyncResponse {
    91    type: 'sync'
    92    transactionHash: string
    93  }
    94  
    95  export interface IAPIGatewaySyncResponseEthereum extends IAPIGatewaySyncResponse {
    96    protocol: 'ethereum'
    97    blockHash: string
    98    blockNumber: string
    99    cumulativeGasUsed: string
   100    from: string
   101    gasUsed: string
   102    headers: {
   103      id: string
   104      type: 'string',
   105      timeReceived: 'string',
   106      timeElapsed: number
   107      requestOffset: string
   108    }
   109    nonce: string
   110    status: string
   111    to: string
   112    transactionIndex: string
   113  }
   114  
   115  export interface IEventStream {
   116    id: string
   117  }
   118  
   119  export interface IEventStreamSubscription {
   120    name: string
   121    stream: string
   122  }
   123  
   124  // IPFS INTERFACES
   125  
   126  export interface IIPFSAssetDefinition {
   127    assetDefinitionID: string
   128    name: string
   129    isContentPrivate: boolean
   130    isContentUnique: boolean
   131    descriptionSchema?: object
   132    contentSchema?: object
   133    indexes?: indexes
   134  }
   135  
   136  // IPFS INTERFACES
   137  
   138  export interface IIPFSAssetDefinition {
   139    assetDefinitionID: string
   140    name: string
   141    isContentPrivate: boolean
   142    isContentUnique: boolean
   143    descriptionSchema?: object
   144    contentSchema?: object
   145    indexes?: indexes
   146  }
   147  
   148  // REQUEST INTERFACES
   149  
   150  export interface IRequestMultiPartContent {
   151    author?: string
   152    assetDefinitionID?: string
   153    description?: Promise<string>
   154    contentStream: NodeJS.ReadableStream
   155    contentFileName: string
   156    isContentPrivate?: boolean
   157  }
   158  
   159  export interface IAssetDefinitionRequest {
   160    assetDefinitionID: string
   161    name: string
   162    author?: string
   163    isContentPrivate: boolean
   164    isContentUnique: boolean
   165    indexes?: indexes
   166    descriptionSchema?: object
   167    contentSchema?: object
   168  }
   169  
   170  // EVENT STREAM INTERFACES
   171  
   172  
   173  interface IStateRefCorda {
   174    txhash: string,
   175    index: number
   176  }
   177  
   178  interface IStateCorda {
   179    data: object
   180  }
   181  
   182  export interface IEventStreamRawMessageCorda {
   183    data: IStateCorda,
   184    subId: string,
   185    signature: string,
   186    stateRef: IStateRefCorda,
   187    recordedTime: string,
   188    consumedTime: string
   189  }
   190  
   191  export interface IEventStreamMessage {
   192    address?: string
   193    blockNumber?: string
   194    transactionIndex?: string
   195    transactionHash: string
   196    data: object
   197    subId: string
   198    signature: string
   199    logIndex?: string
   200  }
   201  
   202  export interface IEventMemberRegistered {
   203    member: string
   204    name: string
   205    assetTrailInstanceID: string
   206    app2appDestination: string
   207    docExchangeDestination: string
   208    timestamp: number
   209  }
   210  
   211  export interface IEventAssetDefinitionCreated {
   212    author: string
   213    assetDefinitionHash: string
   214    timestamp: string
   215  }
   216  
   217  export interface IEventPaymentDefinitionCreated {
   218    paymentDefinitionID: string
   219    author: string
   220    name: string
   221    descriptionSchemaHash?: string
   222    timestamp: string
   223  }
   224  
   225  export interface IEventAssetInstanceCreated {
   226    assetInstanceID: string
   227    assetDefinitionID: string
   228    author: string
   229    descriptionHash?: string
   230    contentHash: string
   231    timestamp: string
   232    isContentPrivate: boolean
   233    participants?: string[]
   234  }
   235  export interface IEventAssetInstanceBatchCreated {
   236    batchHash: string;
   237    author: string
   238    timestamp: string
   239    participants?: string[]
   240  }
   241  
   242  export interface IEventPaymentInstanceCreated {
   243    paymentInstanceID: string
   244    paymentDefinitionID: string
   245    author: string
   246    member: string
   247    descriptionHash?: string
   248    amount: string
   249    timestamp: string
   250    participants?: string[]
   251  }
   252  
   253  export interface IEventAssetInstancePropertySet extends IAssetInstancePropertySet {
   254    timestamp: string
   255    participants?: string[]
   256  }
   257  
   258  // DATABASE INTERFACES
   259  
   260  //TODO: figure out how to handle variable asset-instance collection names
   261  export type databaseCollectionName = 'members' | 'asset-definitions' | 'payment-definitions' | 'payment-instances' | 'batches' | customCollectionName
   262  export type customCollectionName = string
   263  
   264  export type indexes = {fields: string[], unique?: boolean}[];
   265  
   266  export interface IDatabaseProvider {
   267    init: () => Promise<void>
   268    createCollection: (collectionName: string, indexes: indexes) => Promise<void>
   269    count: (collectionName: databaseCollectionName, query: object) => Promise<number>
   270    find: <T>(collectionName: databaseCollectionName, query: object, sort: object, skip: number, limit: number) => Promise<T[]>
   271    findOne: <T>(collectionName: databaseCollectionName, query: object) => Promise<T | null>
   272    updateOne: (collectionName: databaseCollectionName, query: object, value: object, upsert: boolean) => Promise<void>
   273    shutDown: () => void
   274  }
   275  
   276  export interface IDBBlockchainData {
   277    blockNumber?: number
   278    transactionHash: string
   279    participants?: string[]
   280  }
   281  
   282  export interface IDBBlockchainPinned extends Partial<IDBBlockchainData> {
   283    submitted?: number
   284    timestamp?: number
   285    receipt?: string
   286  }
   287  
   288  export interface IDBMember extends IDBBlockchainPinned {
   289    _id?: string
   290    address: string
   291    name: string
   292    assetTrailInstanceID: string
   293    app2appDestination: string
   294    docExchangeDestination: string
   295  }
   296  
   297  export interface IDBAssetDefinition extends IIPFSAssetDefinition, IDBBlockchainPinned {
   298    _id?: string
   299    author: string
   300    assetDefinitionHash: string
   301    conflict?: boolean
   302  }
   303  
   304  export interface IDBPaymentDefinition extends IDBBlockchainPinned {
   305    _id?: string
   306    paymentDefinitionID: string
   307    author: string
   308    name: string
   309    descriptionSchema?: object
   310    descriptionSchemaHash?: string
   311    conflict?: boolean
   312  }
   313  
   314  export interface IAssetInstance {
   315    assetInstanceID: string
   316    assetDefinitionID: string
   317    author: string
   318    descriptionHash?: string
   319    description?: object
   320    content?: object
   321    contentHash?: string
   322    isContentPrivate: boolean
   323    conflict?: boolean
   324    filename?: string
   325    properties?: {
   326      [author: string]: {
   327        [key: string]: {
   328          value: string
   329          submitted?: number
   330          receipt?: string
   331          history?: {
   332            [timestamp: string]: {
   333              value: string
   334              timestamp: number
   335              blockNumber: number
   336              transactionHash: string
   337            }
   338          }
   339        } | undefined
   340      } | undefined
   341    }
   342  }
   343  
   344  export interface IDBAssetInstance extends IAssetInstance, IDBBlockchainPinned {
   345    _id?: string
   346    batchID?: string;
   347  }
   348  
   349  export interface IAssetInstancePropertySet {
   350    assetInstanceID: string
   351    assetDefinitionID: string
   352    author: string
   353    key: string
   354    value: string
   355  }
   356  
   357  export interface IDBPaymentInstance extends IDBBlockchainPinned {
   358    _id?: string
   359    paymentInstanceID: string
   360    paymentDefinitionID: string
   361    author: string
   362    member: string
   363    amount: number
   364    descriptionHash?: string
   365    description?: object
   366  }
   367  
   368  export enum BatchRecordType {
   369    assetInstance = 'instance',
   370    assetProperty = 'property',
   371  }
   372  
   373  export interface IBatchRecord {
   374    recordType: BatchRecordType,
   375    [x: string]: any, 
   376  }
   377  
   378  export interface IPinnedBatch {
   379    type: string;
   380    author: string;
   381    created: number;
   382    completed: number | null;
   383    batchID: string,
   384    records: IBatchRecord[];
   385  }
   386  
   387  export interface IDBBatch extends IPinnedBatch, IDBBlockchainPinned {
   388    _id?: string;
   389    batchHash?: string,
   390  }
   391  
   392  // APP2APP INTERFACES
   393  
   394  export interface IApp2AppMessageHeader {
   395    from: string
   396    to: string
   397  }
   398  
   399  export interface IApp2AppMessage {
   400    headers: IApp2AppMessageHeader
   401    content: string
   402  }
   403  
   404  export interface IApp2AppMessageListener {
   405    (header: IApp2AppMessageHeader, content: AssetTradeMessage): void
   406  }
   407  
   408  // DOCUMENT EXCHANGE INTERFACES
   409  
   410  export interface IDocExchangeDocumentDetails {
   411    name: string
   412    is_directory: boolean
   413    size: number
   414    hash: string
   415  }
   416  
   417  export interface IDocExchangeTransferData {
   418    transferId: string
   419    transferHash: string
   420    hash: string
   421    from: string
   422    to: string
   423    senderSignature: string
   424    memberSignature: string
   425    document: string
   426    timestamp: string
   427    status: 'sent' | 'received' | 'failed'
   428  }
   429  
   430  export interface IDocExchangeListener {
   431    (transferData: IDocExchangeTransferData): void
   432  }
   433  
   434  // ASSET TRADE INTERFACES
   435  
   436  export type AssetTradeMessage =
   437    IAssetTradePrivateAssetInstanceRequest
   438    | IAssetTradePrivateAssetInstanceResponse
   439    | IAssetTradePrivateAssetInstancePush
   440    | IAssetTradePrivateAssetInstanceAuthorizationResponse
   441  
   442  export interface IAssetTradePrivateAssetInstanceRequest {
   443    type: 'private-asset-instance-request'
   444    tradeID: string
   445    assetInstanceID: string
   446    assetDefinitionID: string
   447    requester: {
   448      assetTrailInstanceID: string
   449      address: string
   450    }
   451    metadata?: object
   452  }
   453  
   454  export interface IAssetTradePrivateAssetInstanceResponse {
   455    type: 'private-asset-instance-response'
   456    tradeID: string
   457    assetInstanceID: string
   458    rejection?: string
   459    content?: object
   460    filename?: string
   461  }
   462  
   463  export interface IAssetTradePrivateAssetInstancePush {
   464    type: 'private-asset-instance-push'
   465    assetInstanceID: string
   466    assetDefinitionID: string
   467    content?: object
   468    filename?: string
   469  }
   470  
   471  export interface IAssetTradePrivateAssetInstanceAuthorizationRequest {
   472    type: 'private-asset-instance-authorization-request'
   473    authorizationID: string
   474    assetInstance: IDBAssetInstance
   475    requester: IDBMember
   476    metadata?: object
   477  }
   478  
   479  export interface IAssetTradePrivateAssetInstanceAuthorizationResponse {
   480    type: 'private-asset-instance-authorization-response'
   481    authorizationID: string
   482    authorized: boolean
   483  }
   484  
   485  // CLIENT EVENT INTERFACES
   486  
   487  export type ClientEventType =
   488    'member-registered'
   489    | 'asset-definition-submitted'
   490    | 'asset-definition-created'
   491    | 'asset-definition-name-conflict'
   492    | 'payment-definition-submitted'
   493    | 'payment-definition-created'
   494    | 'payment-definition-name-conflict'
   495    | 'asset-instance-submitted'
   496    | 'asset-instance-created'
   497    | 'asset-instance-content-conflict'
   498    | 'payment-instance-submitted'
   499    | 'payment-instance-created'
   500    | 'private-asset-instance-content-stored'
   501    | 'asset-instance-property-submitted'
   502    | 'asset-instance-property-set'
   503  
   504  export interface IClientEventListener {
   505    (eventType: ClientEventType, content: object): void
   506  }
   507  
   508  export interface IPendingAssetInstancePrivateContentDelivery {
   509    assetInstanceID: string
   510    fromDestination: string
   511    content?: object
   512    filename?: string
   513  }