This repository has been archived by the owner on Oct 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
240 lines (166 loc) · 5.74 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// Type definitions for fabric-shim 1.1.0-alpha
// Project: https://github.com/hyperledger/fabric-chaincode-node
// Definitions by: TheLedger <https://github.com/wearetheledgerr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
/* tslint:disable */
declare module 'fabric-shim' {
import { Logger } from 'log4js';
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
export function error(...args: any[]): ErrorResponse;
export function newLogger(name: string): Logger;
export function start(chaincode: ChaincodeInterface): any;
export function success(payload?: Buffer): SuccessResponse;
interface SuccessResponse extends ChaincodeReponse {
}
interface ErrorResponse extends ChaincodeReponse {
}
export class ClientIdentity {
constructor(stub: Stub);
assertAttributeValue(attrName: string, attrValue: string): boolean;
getAttributeValue(attrName: string): string | null;
getID(): string;
getMSPID(): string;
getX509Certificate(): X509;
}
interface ProposalCreator {
mspid: string;
getMspid(): string;
}
export class SignedProposal {
signature: Buffer;
proposal: Proposal;
}
type Proposal = {
header: Header;
payload: ChaincodeProposalPayload;
};
type Header = {
channel_header: ChannelHeader;
signature_header: SignatureHeader;
};
type ChannelHeader = {
type: ChannelHeaderType;
version: number;
timestamp: any;
channel_id: string;
tx_id: string;
epoch: number;
};
type SignatureHeader = {
creator: ProposalCreator;
nonce: Buffer;
};
type ChaincodeProposalPayload = {
input: Buffer;
transientMap: Map<string, Buffer>;
};
enum ChannelHeaderType {
MESSAGE = 0,
CONFIG,
CONFIG_UPDATE,
ENDORSER_TRANSACTION,
ORDERER_TRANSACTION,
DELIVER_SEEK_INFO,
CHAINCODE_PACKAGE,
}
type ChaincodeReponse = {
status: number;
message: string;
payload: Buffer;
};
export class MockStub extends Stub {
mockTransactionStart(txid: string): void
mockTransactionEnd(uuid: string): void
mockInit(uuid: string, args: string[]): Promise<ChaincodeReponse>
mockInvoke(uuid: string, args: string[]): Promise<ChaincodeReponse>
mockPeerChaincode(invokableChaincodeName: string, otherStub: MockStub): void
mockInvokeWithSignedProposal(uuid: string, args: string[], sp: SignedProposal): Promise<ChaincodeReponse>
setSignedProposal(sp: SignedProposal): void
setTxTimestamp(timestamp: Timestamp): void;
}
export class Stub {
constructor(client: any, channel_id: any, txId: any, chaincodeInput: any, signedProposal: any);
createCompositeKey(objectType: string, attributes: string[]): string;
deleteState(key: string): Promise<any>;
getArgs(): string[];
getBinding(): string;
getChannelID(): string;
getCreator(): ProposalCreator;
getFunctionAndParameters(): { params: string[], fcn: string };
getHistoryForKey(key: string): Promise<Iterators.HistoryQueryIterator>;
getQueryResult(query: string): Promise<Iterators.StateQueryIterator>;
getSignedProposal(): SignedProposal;
getState(key: string): Promise<Buffer>;
getStateByPartialCompositeKey(objectType: string, attributes: string[]): Promise<Iterators.StateQueryIterator>;
getStateByRange(startKey: string, endKey: string): Promise<Iterators.StateQueryIterator>;
getStringArgs(): string[];
getTransient(): Map<string, Buffer>;
getTxID(): string;
getTxTimestamp(): Timestamp;
invokeChaincode(chaincodeName: string, args: Buffer[], channel: string): Promise<ChaincodeReponse>;
putState(key: string, value: Buffer): Promise<any>; // TODO promise contains what?????
setEvent(name: string, payload: Buffer): void;
splitCompositeKey(compositeKey: string): SplitCompositekey;
static RESPONSE_CODE: {
ERROR: number;
ERRORTHRESHOLD: number;
OK: number;
};
}
interface SplitCompositekey {
objectType: string,
attributes: string[]
}
interface ChaincodeInterface {
Init(stub: Stub): Promise<ChaincodeReponse>
Invoke(stub: Stub): Promise<ChaincodeReponse>
}
export namespace Iterators {
interface Iterator {
close(): void;
next(): Promise<any>;
}
interface HistoryQueryIterator extends Iterator {
next(): Promise<KV>;
}
interface StateQueryIterator extends Iterator {
next(): Promise<NextResult>;
}
}
interface NextResult {
value: KV,
done: boolean
}
interface X509 {
subject: Subject;
issuer: Issuer;
notBefore: string;
notAfter: string;
altNames?: (string)[] | null;
signatureAlgorithm: string;
fingerPrint: string;
publicKey: any;
}
interface Subject {
countryName: string;
postalCode: string;
stateOrProvinceName: string;
localityName: string;
streetAddress: string;
organizationName: string;
organizationalUnitName: string;
commonName: string;
}
interface Issuer {
countryName: string;
stateOrProvinceName: string;
localityName: string;
organizationName: string;
commonName: string;
}
interface KV {
key: string;
value: any;
}
}